ROOT
master
Reference Guide
Loading...
Searching...
No Matches
tree110_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
5
///
6
/// The input file has been generated by the program in `$ROOTSYS/test/Event`
7
/// with `Event 1000 1 1 1`.
8
///
9
/// \macro_code
10
///
11
/// \author Rene Brun
12
13
#ifdef ACTUAL_RUN
// -------- Second pass: dictionary already built --------
14
15
#include "
./Event.h
"
// now safe to include Event, its dictionary is loaded
16
17
void
run()
18
{
19
TFile
oldfile
(
"tree108.root"
);
20
TTree
*
oldtree
;
21
oldfile
.GetObject(
"t4"
,
oldtree
);
22
23
// Deactivate all branches
24
oldtree
->SetBranchStatus(
"*"
, 0);
25
26
// Activate only four of them
27
for
(
auto
activeBranchName
: {
"event_split"
,
"fNtrack"
,
"fNseg"
,
"fH"
})
28
oldtree
->SetBranchStatus(
activeBranchName
, 1);
29
30
// Create a new file + a clone of old tree in new file
31
TFile
newfile
(
"tree110.root"
,
"recreate"
);
32
auto
newtree
=
oldtree
->CloneTree();
33
34
newtree
->Print();
35
newfile
.Write();
36
}
37
38
#else
// -------- First pass: build dictionary + rerun macro --------
39
40
void
tree110_copy
()
41
{
42
TString
tutdir
=
gROOT
->GetTutorialDir();
43
gROOT
->ProcessLine(
".L "
+
tutdir
+
"/io/tree/Event.cxx+"
);
44
gROOT
->ProcessLine(
"#define ACTUAL_RUN yes"
);
45
gROOT
->ProcessLine(
"#include \""
__FILE__
"\""
);
46
gROOT
->ProcessLine(
"run()"
);
47
}
48
49
#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
tree110_copy.C
ROOT master - Reference Guide Generated on Tue Sep 2 2025 15:10:37 (GVA Time) using Doxygen 1.10.0