ROOT
master
Reference Guide
Loading...
Searching...
No Matches
tree111_copy.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_tree
3
/// \notebook -nodraw
4
/// Copy a subset of a Tree to a new Tree, one branch in a separate file.
5
///
6
/// One branch of the new Tree is written to a separate file
7
/// The input file has been generated by the program in `$ROOTSYS/test/Event`
8
/// with the command `Event 1000 1 1 1`
9
///
10
/// \macro_code
11
///
12
/// \author Rene Brun
13
14
#ifdef ACTUAL_RUN
// -------- Second pass: dictionary already built --------
15
16
#include "
./Event.h
"
// now safe to include Event, its dictionary is loaded
17
18
void
run()
19
{
20
TFile
oldfile
(
"tree108.root"
);
21
TTree
*
oldtree
;
22
oldfile
.GetObject(
"t4"
,
oldtree
);
23
24
// Activate only four of them
25
for
(
auto
activeBranchName
: {
"event_split"
,
"fNtrack"
,
"fNseg"
,
"fH"
}) {
26
oldtree
->SetBranchStatus(
activeBranchName
, 1);
27
}
28
29
// Create a new file + a clone of old tree header. Do not copy events
30
TFile
newfile
(
"tree111.root"
,
"recreate"
);
31
auto
newtree
=
oldtree
->CloneTree(0);
32
33
// Divert branch fH to a separate file and copy all events
34
newtree
->GetBranch(
"fH"
)->SetFile(
"small_fH.root"
);
35
newtree
->CopyEntries(
oldtree
);
36
37
newtree
->Print();
38
newfile
.Write();
39
}
40
41
#else
// -------- First pass: build dictionary + rerun macro --------
42
43
void
tree111_copy
()
44
{
45
TString
tutdir
=
gROOT
->GetTutorialDir();
46
gROOT
->ProcessLine(
".L "
+
tutdir
+
"/io/tree/Event.cxx+"
);
47
gROOT
->ProcessLine(
"#define ACTUAL_RUN yes"
);
48
gROOT
->ProcessLine(
"#include \""
__FILE__
"\""
);
49
gROOT
->ProcessLine(
"run()"
);
50
}
51
52
#endif
Event.h
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
gROOT
#define gROOT
Definition
TROOT.h:411
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
TFile
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition
TFile.h:131
TString
Basic string class.
Definition
TString.h:138
TTree
A TTree represents a columnar dataset.
Definition
TTree.h:89
tutorials
io
tree
tree111_copy.C
ROOT master - Reference Guide Generated on Tue Sep 2 2025 15:10:37 (GVA Time) using Doxygen 1.10.0