-
Notifications
You must be signed in to change notification settings - Fork 9
/
cloneTree.C
51 lines (43 loc) · 1.21 KB
/
cloneTree.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
cloneTree.C
Extract the nominal tree from your HistFitter inputs -- you can run on your laptop easily this way!
This script is a bit dumb, but it was written very quickly and it does the job I need ... it's
mostly provided as an example.
MLB <[email protected]>
Based on a script from Matt Gignac <[email protected]>
Usage: root -l -b -q 'cloneTree.C("path/to/input.root","path/to/output.root")'
*/
void cloneTree(TString inFile, TString outFile)
{
//TString inputTree ="allTrees.full.merge_v18.root";
TFile* in = new TFile(inFile,"READ");
if( !in->IsOpen() )
{
cout << "Error opening files! Exiting!" << endl;
return;
}
TIter nextkey(in->GetListOfKeys());
TKey *key;
while ((key = (TKey*)nextkey()))
{
in->cd();
TTree *tree = (TTree*)key->ReadObj();
if(!tree)
{
cout << "Could not read tree!" << endl;
continue;
}
TString oldTreeName = tree->GetName();
//
if(oldTreeName.Contains("nominal"))
{
cout << "Tree name: " << oldTreeName << endl;
TFile* out = new TFile(outFile,"RECREATE");
TTree* outTree = tree->CloneTree();
outTree->SetDirectory(out);
outTree->Write();
out->Close();
}
}
in->Close();
}