-
Notifications
You must be signed in to change notification settings - Fork 0
/
SplitTree.cxx
48 lines (39 loc) · 1.58 KB
/
SplitTree.cxx
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
// root -l -b -q SplitTree.cxx'("AjResults/Tow0_Eff0_Fresh_NicksList_HC100_ppAj.root","AjResults/Tow0_Eff0_ppAj",12)'
// root -l -b -q SplitTree.cxx'("AjResults/Tow1_Eff0_Fresh_NicksList_HC100_ppAj.root","AjResults/Tow1_Eff0_ppAj",12)'
// root -l -b -q SplitTree.cxx'("AjResults/Tow-1_Eff0_Fresh_NicksList_HC100_ppAj.root","AjResults/Tow-1_Eff0_ppAj",12)'
// root -l -b -q SplitTree.cxx'("AjResults/Tow0_Eff1_Fresh_NicksList_HC100_ppAj.root","AjResults/Tow0_Eff1_ppAj",12)'
// root -l -b -q SplitTree.cxx'("AjResults/Tow0_Eff-1_Fresh_NicksList_HC100_ppAj.root","AjResults/Tow0_Eff-1_ppAj",12)'
int SplitTree( TString in = "AjResults/Tow0_Eff0_Fresh_NicksList_HC100_ppAj.root", TString outbase = "AjResults/Tow0_Eff0_ppAj", int split=12){
TChain* inchain = new TChain ( "TriggeredTree" );
inchain->Add ( in );
Long64_t Norig = inchain->GetEntries();
Long64_t Nsplit = Norig / split;
int oldfile = 0;
TFile * out=0;
TTree * newtree = inchain->CloneTree ( 0 );
for ( Long64_t i=0; i<Norig; ++i ){
int currfile = i / Nsplit + 1;
if ( currfile != oldfile && currfile <= split ){
// Last one soaks up the remainder
TString name = outbase + "_";
name += currfile;
name += "_of_";
name += split;
name += ".root";
cout << "Now saving to " << name << endl;
oldfile = currfile;
if ( out ){
out->Write();
out->Close();
}
out = new TFile( name, "recreate");
newtree = inchain->CloneTree ( 0 );
}
inchain->GetEntry( i );
newtree->Fill();
}
if ( out ){
out->Write();
out->Close();
}
}