5 #include "utilities.hh" 20 #include "TDirectory.h" 28 int main(
int argc,
char *argv[]){
31 cout<<endl<<
"Required at least 2 arguments: " 32 <<
"./plot/skim_ntuples.exe infolder outfolder [cuts=\"\"] " 33 <<
"[njobs=-1] [ijob=-1]"<<endl<<endl;;
37 if(argc >= 4) cuts = argv[3];
40 njobs = atoi(argv[4]);
46 if(ijob<1 || ijob>
njobs){
47 cout<<endl<<
"You need to set the 5th argument between 1 and "<<njobs<<endl<<endl;
50 unsigned jobfiles = (
nfiles+njobs-1)/njobs;
51 unsigned nbigjobs = (
nfiles+njobs-1)%njobs+1;
53 ini = jobfiles*(ijob-1);
56 ini = nbigjobs*jobfiles+(jobfiles-1)*(ijob-1-nbigjobs);
57 end = ini + jobfiles-1;
60 cout<<
"Doing files "<<ini+1<<
" to "<<end<<
" out of "<<
nfiles<<endl;
61 for(
unsigned file(ini); file < end; file++){
69 int nfiles = tree.Add(infiles);
70 TChain treeglobal(
"treeglobal");
71 treeglobal.Add(infiles);
74 TH2F * mass_plane =
new TH2F(
"mglu_vs_mlsp",
"mglu_vs_mlsp",3000,-0.5,2999.5,3000,-0.5,2999.5);
75 tree.Project(
"mglu_vs_mlsp",
"mgluino:mlsp",
"",
"colz");
78 int ini_x = mass_plane->FindFirstBinAbove(0,1);
79 int last_x = mass_plane->FindLastBinAbove(0,1);
80 int ini_y = mass_plane->FindFirstBinAbove(0,2);
81 int last_y = mass_plane->FindLastBinAbove(0,2);
84 vector<TString> pair_cuts;
85 for(
int iy=ini_y; iy<=last_y; iy++){
86 for(
int ix=ini_x; ix<=last_x; ix++){
87 if(mass_plane->GetBinContent(ix,iy) > 0){
88 int mglui =
static_cast<int>(mass_plane->GetYaxis()->GetBinCenter(iy));
89 int mlsp =
static_cast<int>(mass_plane->GetXaxis()->GetBinCenter(ix));
90 if(cuts ==
"") pair_cuts.push_back(Form(
"mgluino==%i&&mlsp==%i",mglui,mlsp));
91 else pair_cuts.push_back(Form(
"mgluino==%i&&mlsp==%i&&",mglui,mlsp)+cuts);
98 vector<TString > outfiles;
99 folder.Remove(folder.Last(
'/')+1, folder.Length());
100 gSystem->mkdir(outfolder, kTRUE);
102 for(
unsigned int ip = 0; ip<pair_cuts.size(); ip++){
105 outfile.Remove(0, outfile.Last(
'/')); outfile.ReplaceAll(
"*",
"");
106 if(outfile.Contains(
".root")) outfile.ReplaceAll(
".root",
"_"+pair_cuts.at(ip)+
".root");
107 else outfile += (
"_"+pair_cuts.at(ip)+
".root");
108 outfile.ReplaceAll(
">=",
"ge"); outfile.ReplaceAll(
"<=",
"se"); outfile.ReplaceAll(
"&&",
"_");
109 outfile.ReplaceAll(
">",
"g"); outfile.ReplaceAll(
"<",
"s"); outfile.ReplaceAll(
"=",
"");
110 outfile.ReplaceAll(
"(",
""); outfile.ReplaceAll(
")",
""); outfile.ReplaceAll(
"+",
"");
111 outfile.ReplaceAll(
"[",
""); outfile.ReplaceAll(
"]",
""); outfile.ReplaceAll(
"|",
"_");
117 outname.ReplaceAll(outfolder,
""); outname.ReplaceAll(
"/",
"");
118 vector<TString> existing_outfiles =
dirlist(outfolder, outname);
119 if(existing_outfiles.size()>0) {
120 cout<<
"File "<<outfile<<
" exists. Skipping"<<endl;
126 TFile out_rootfile(outfile,
"CREATE");
127 if(out_rootfile.IsZombie() || !out_rootfile.IsOpen())
return;
132 long nentries(tree.GetEntries());
133 TTree * ctree = tree.CopyTree(pair_cuts.at(ip));
134 TTree * ctreeglobal = treeglobal.CopyTree(
"1");
135 if(ctree) ctree->Write();
136 else cout<<
"Could not find tree in "<<infiles<<endl;
137 if(ctreeglobal) ctreeglobal->Write();
138 else cout<<
"Could not find treeglobal in "<<infiles<<endl;
139 cout<<
"Written "<<outfile<<
" from "<<nfiles<<
" files and "<<nentries<<
" entries."<<endl;
140 out_rootfile.Close();
tuple infiles
Finding tags for each dataset.
int main(int argc, char *argv[])
void onefile_skim(TString infiles, TString outfolder, TString cuts)
std::vector< TString > dirlist(const TString &folder, const TString &inname="dir", const TString &tag="")