15 |
|
showLegend = false; |
16 |
|
logY = true; |
17 |
|
addTrackJets = true; |
18 |
+ |
verbose = true; |
19 |
|
|
20 |
|
} |
21 |
|
|
30 |
|
if (currChain < 0) |
31 |
|
return currChain; |
32 |
|
|
33 |
+ |
TStopwatch timer; |
34 |
+ |
timer.Start(); |
35 |
+ |
|
36 |
+ |
|
37 |
|
fileNames.clear(); |
38 |
|
|
39 |
|
//check if alternative label is different from default(searchString) |
49 |
|
TString fname; |
50 |
|
string filePath; |
51 |
|
|
52 |
< |
cout<<"Open"<<dirPath.c_str()<<" Search for .root files that contain: " |
52 |
> |
if(verbose) cout<<"Open"<<dirPath.c_str()<<" Search for .root files that contain: " |
53 |
|
<<fileName.c_str()<<endl; |
54 |
|
|
55 |
|
while ((file=(TSystemFile*)next())) { |
66 |
|
|
67 |
|
if (((TChain*) this->At(currChain))->AddFile(filePath.c_str(), -1, |
68 |
|
treeName.c_str()) ) |
69 |
< |
cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl; |
69 |
> |
if(verbose) cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl; |
70 |
|
else |
71 |
|
return -1; |
72 |
|
|
89 |
|
if (b != string::npos) { |
90 |
|
size_t c = s.find("_", b+1); |
91 |
|
if (c != string::npos) { |
92 |
+ |
string _prod =s.substr(0,a); |
93 |
|
string _label =s.substr(a+1, b-a-1); |
94 |
|
string _instance =s.substr(b+1, c-b-1); |
95 |
|
branch_alias = _label; |
96 |
|
if(_instance.length() > 0 ) { |
97 |
|
branch_alias += "_"; |
98 |
|
branch_alias += _instance; |
99 |
+ |
((TChain*) this->At(currChain))->SetAlias(_instance.c_str(), |
100 |
+ |
branch_name.c_str()); |
101 |
|
} |
102 |
+ |
string branch_alias_full = _prod + "_" + branch_alias; |
103 |
+ |
((TChain*) this->At(currChain))->SetAlias(branch_alias_full.c_str(), |
104 |
+ |
branch_name.c_str()); |
105 |
|
} |
106 |
|
} |
107 |
|
} |
116 |
|
if( addTrackJets ) { |
117 |
|
|
118 |
|
//make file for tree friends (adding additional, computed branches) |
119 |
< |
string friendFileName("/scratch/hh/lustre/cms/user/thomsen/temp/"); |
119 |
> |
string friendFileName("/scratch/hh/current/cms/user/"); |
120 |
> |
friendFileName += gSystem->GetUserInfo()->fUser; |
121 |
> |
friendFileName += "/temp/", |
122 |
|
friendFileName += fileName; |
123 |
|
friendFileName += ".root"; |
124 |
|
TFile *f = new TFile(friendFileName.c_str(),"recreate"); |
125 |
+ |
|
126 |
+ |
if( f->IsZombie() ) return -1; |
127 |
+ |
|
128 |
|
string friendTreeName("friendTree"); |
129 |
|
//char number = currChain; |
130 |
|
//friendTreeName += number; |
138 |
|
friendTree->Branch("nJetsKT", &nJetsKT, "nJetsKT/I"); |
139 |
|
friendTree->Branch("TrackJetKT", TrackJetKT, "TrackJetKT[nJetsKT]/F"); |
140 |
|
|
141 |
< |
cout<<"calculating additional variables..."<<endl; |
142 |
< |
for (ev.toBegin(); !ev.atEnd(); ++ev) { |
141 |
> |
if(verbose) cout<<"calculating additional variables..."<<endl; |
142 |
> |
|
143 |
> |
|
144 |
> |
|
145 |
> |
int tenth = ev.size() / 10; |
146 |
> |
int eventNum =0; |
147 |
> |
for (ev.toBegin(); !ev.atEnd(); ++ev, ++eventNum) { |
148 |
|
|
149 |
|
fwlite::Handle<reco::CaloJetCollection> jets; |
150 |
|
jets.getByLabel(ev, "antikt5CaloJets"); |
171 |
|
nJetsKT++; |
172 |
|
} |
173 |
|
friendTree->Fill(); |
174 |
+ |
|
175 |
+ |
if( eventNum != 0 && eventNum%tenth == 0) cout<<"Processed "<<eventNum <<" of "<<ev.size()<<" events. "<<endl; |
176 |
+ |
|
177 |
|
} |
178 |
|
f->cd(); |
179 |
|
friendTree->Write(); |
181 |
|
((TChain*) this->At(currChain))->AddFriend(friendTreeName.c_str(), |
182 |
|
friendFileName.c_str()); |
183 |
|
} |
184 |
+ |
|
185 |
+ |
timer.Stop(); |
186 |
+ |
if(verbose) timer.Print(); |
187 |
+ |
|
188 |
|
return this->GetEntries(); |
189 |
|
|
190 |
|
} |
196 |
|
if (chainIndex >= this->GetEntries() ) |
197 |
|
return -1; |
198 |
|
|
199 |
+ |
TStopwatch timer; |
200 |
+ |
timer.Start(); |
201 |
+ |
|
202 |
|
int currN = nEntries; |
203 |
|
if (nEntries < 0) |
204 |
|
currN = ((TChain*) this->At(chainIndex))->GetEntries(); //nEntries<0 : all entries are plotted! |
246 |
|
|
247 |
|
if ( !pads_[currPadName.str()] || !gROOT->GetListOfCanvases()->FindObject(currPadName.str().c_str()) ) { |
248 |
|
pads_[currPadName.str()] = new TCanvas(currPadName.str().c_str(), currPadName.str().c_str()); |
249 |
< |
if (logY) |
250 |
< |
pads_[currPadName.str()]->SetLogy(1); |
249 |
> |
// if (logY) |
250 |
> |
// pads_[currPadName.str()]->SetLogy(1); |
251 |
|
} else { |
252 |
|
pads_[currPadName.str()]->cd(); |
253 |
|
currOpt += "SAMES"; |
279 |
|
|
280 |
|
((TH1F*) pads_[currPadName.str()]->GetPrimitive("htemp"))->SetName(currHistName.str().c_str()); // Set Name of histogram |
281 |
|
|
282 |
+ |
// Update for 2D histograms |
283 |
+ |
if( pads_[currPadName.str()]->GetPrimitive(currHistName.str().c_str())->InheritsFrom("TH2") ) { |
284 |
+ |
pads_[currPadName.str()]->Draw(); |
285 |
+ |
setCanvas( pads_[currPadName.str()] ); |
286 |
+ |
} |
287 |
|
|
288 |
+ |
timer.Stop(); |
289 |
+ |
if(verbose) { |
290 |
+ |
cout<<"Done: "<<currN<<" events in "<<histName<<" "<<cutName<<" from chain "<<this->At(chainIndex)->GetName()<<endl; |
291 |
+ |
timer.Print(); |
292 |
+ |
} |
293 |
|
return draw_err; |
294 |
|
|
295 |
|
} |
309 |
|
!= _cutName.end(); ++it2) { |
310 |
|
|
311 |
|
numProcessed += plot(i, *it1, *it2, nEntries, drwOpt); |
312 |
< |
updatePads(); |
312 |
> |
|
313 |
|
|
314 |
|
} |
315 |
|
} |
330 |
|
} |
331 |
|
} |
332 |
|
|
333 |
< |
// updatePads(); |
333 |
> |
updatePads(); |
334 |
|
fillCanvases(); |
335 |
|
|
336 |
|
return numProcessed; |
386 |
|
|
387 |
|
for (map< string, TCanvas* >::iterator it=canvases_.begin() ; it |
388 |
|
!= canvases_.end(); ++it) { |
389 |
< |
const char* canvName = (*it).first.c_str(); |
390 |
< |
if (gROOT->GetListOfCanvases()->FindObject(canvName) ) { |
389 |
> |
string canvName = (*it).first; |
390 |
> |
if (gROOT->GetListOfCanvases()->FindObject(canvName.c_str()) ) { |
391 |
|
|
392 |
|
int numP = (*it).second->GetNumber()+1; |
393 |
|
|
405 |
|
y += 1; |
406 |
|
} |
407 |
|
|
408 |
+ |
|
409 |
|
(*it).second->Divide(x, y); |
410 |
|
int padIndex = 1; |
411 |
|
for (map< string, TCanvas* >::iterator it2=pads_.begin() ; it2 |
412 |
|
!= pads_.end(); ++it2) { |
413 |
|
string padName = (*it2).first; |
414 |
|
if (gROOT->GetListOfCanvases()->FindObject(padName.c_str() ) ) { |
415 |
< |
if ( (padName.find(canvName) != string::npos ) || !strcmp( |
416 |
< |
canvName, "All") ) { |
415 |
> |
string n1 = canvName.substr(0,canvName.find(":")); |
416 |
> |
string n2(""); |
417 |
> |
if(canvName.find("{") != string::npos ) n2 = canvName.substr(canvName.find("{"),canvName.find("}")); |
418 |
> |
|
419 |
> |
if ( (padName.find(canvName.c_str()) != string::npos ) || (padName.find(n1) != string::npos && padName.find(n2) != string::npos) || !strcmp( canvName.c_str(), "All") ) { |
420 |
|
(*it).second->cd(padIndex); |
421 |
|
(*it2).second->DrawClonePad(); |
422 |
|
(*it2).second->Close(); |
657 |
|
|
658 |
|
//------------------------------------------------------------------ |
659 |
|
|
660 |
< |
int PlotTool::saveCanvases(string type, string path) { |
660 |
> |
int PlotTool::saveCanvases(string name, string path) { |
661 |
|
|
662 |
|
TSystemDirectory d("", path.c_str()); |
663 |
|
if (!d.GetListOfFiles()) |
664 |
|
return -1; |
620 |
– |
if (type.find(".") == string::npos) |
621 |
– |
return -1; |
665 |
|
|
666 |
< |
int savedFiles =0; |
666 |
> |
string namePs = path +"/" + name; |
667 |
> |
string nameRt = path +"/" + name; |
668 |
> |
|
669 |
> |
if (name.find(".ps") == string::npos) |
670 |
> |
namePs += ".ps"; |
671 |
> |
|
672 |
> |
if (name.find(".root") == string::npos) |
673 |
> |
nameRt += ".root"; |
674 |
> |
|
675 |
> |
int savedCanvs =0; |
676 |
> |
|
677 |
> |
TPostScript ps(namePs.c_str(),112); |
678 |
> |
TFile rt(nameRt.c_str(),"recreate"); |
679 |
|
|
680 |
|
TIter next(gROOT->GetListOfCanvases()); |
681 |
|
TCanvas* canv; |
682 |
|
while ((canv=(TCanvas*)next())) { |
683 |
< |
|
684 |
< |
string s = ""; |
685 |
< |
s += path; |
686 |
< |
s += canv->GetName(); |
687 |
< |
s += type; |
633 |
< |
|
634 |
< |
canv->SaveAs(s.c_str()); |
635 |
< |
++savedFiles; |
683 |
> |
ps.NewPage(); |
684 |
> |
(*canv).Draw(); |
685 |
> |
(*canv).Update(); |
686 |
> |
(*canv).Write(); |
687 |
> |
++savedCanvs; |
688 |
|
|
689 |
|
} |
690 |
|
|
691 |
< |
return savedFiles; |
691 |
> |
ps.Close(); |
692 |
> |
rt.Close(); |
693 |
> |
|
694 |
> |
return savedCanvs; |
695 |
|
|
696 |
|
} |
697 |
|
//------------------------------------------------------------------ |
717 |
|
|
718 |
|
|
719 |
|
} |
720 |
+ |
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
721 |
+ |
//Draw efficiencies |
722 |
+ |
int PlotTool::plotEff(int chainIndex, string histName, string cutName, int nEntries, double fitXmin, double fitXmax, string fitFormula) |
723 |
+ |
{ |
724 |
+ |
|
725 |
+ |
if( chainIndex >= this->GetEntries() ) return -1; |
726 |
+ |
|
727 |
+ |
int currN = nEntries; |
728 |
+ |
if(nEntries < 0) currN = ((TChain*) this->At(chainIndex))->GetEntries(); //nEntries<0 : all entries are plotted! |
729 |
+ |
|
730 |
+ |
//++++ Create and name Canvases according to global variables +++++++++++++ |
731 |
+ |
ostringstream currHistName; |
732 |
+ |
if( samePad_trees) currHistName<<((TChain*) this->At(chainIndex))->GetName()<<":"; |
733 |
+ |
if( samePad_vars) currHistName<<histName; |
734 |
+ |
if( samePad_cuts) currHistName<<"{"<<cutName<<"}"; |
735 |
+ |
|
736 |
+ |
ostringstream currPadName; |
737 |
+ |
if(! samePad_trees) currPadName<<((TChain*) this->At(chainIndex))->GetName()<<":"; |
738 |
+ |
if(! samePad_vars) currPadName<<histName; |
739 |
+ |
if(! samePad_cuts) currPadName<<"{"<<cutName<<"}"; |
740 |
+ |
|
741 |
+ |
|
742 |
+ |
//Draw total histogram: |
743 |
+ |
if( ! pads_["total"] || ! gROOT->FindObject("total") ) { |
744 |
+ |
pads_["total"] = new TCanvas("total", "total"); |
745 |
+ |
} else { |
746 |
+ |
pads_["total"]->cd(); |
747 |
+ |
} |
748 |
+ |
ostringstream bins_total; |
749 |
+ |
bins_total<<histName; |
750 |
+ |
bins_total<<">>total(100,0,1000)"; |
751 |
+ |
|
752 |
+ |
|
753 |
+ |
int draw_err = ((TChain*) this->At(chainIndex))->Draw(bins_total.str().c_str(), "", "", currN); |
754 |
+ |
if( draw_err <= 0 ) return draw_err; |
755 |
+ |
|
756 |
+ |
|
757 |
+ |
TH1* total = ((TH1*) pads_["total"]->GetPrimitive("total")); |
758 |
+ |
|
759 |
+ |
ostringstream bins_bkg; |
760 |
+ |
bins_bkg<<histName; |
761 |
+ |
bins_bkg<<">>bkg("; |
762 |
+ |
bins_bkg<<total->GetNbinsX(); |
763 |
+ |
bins_bkg<<","; |
764 |
+ |
bins_bkg<<total->GetXaxis()->GetXmin(); |
765 |
+ |
bins_bkg<<","; |
766 |
+ |
bins_bkg<<total->GetXaxis()->GetXmax(); |
767 |
+ |
bins_bkg<<")"; |
768 |
+ |
|
769 |
+ |
//Draw bkg histogram: |
770 |
+ |
if( ! pads_["bkg"] || ! gROOT->FindObject("bkg") ) { |
771 |
+ |
pads_["bkg"] = new TCanvas("bkg", currPadName.str().c_str()); |
772 |
+ |
} else { |
773 |
+ |
pads_["bkg"]->cd(); |
774 |
+ |
} |
775 |
+ |
|
776 |
+ |
draw_err = ((TChain*) this->At(chainIndex))->Draw(bins_bkg.str().c_str(), cutName.c_str(),"" , currN); |
777 |
+ |
if( draw_err <= 0 ) return draw_err; |
778 |
+ |
|
779 |
+ |
|
780 |
+ |
TH1* bkg = ((TH1*) pads_["bkg"]->GetPrimitive("bkg")); |
781 |
+ |
|
782 |
+ |
//Draw pass histogram: |
783 |
+ |
ostringstream bins_pass; |
784 |
+ |
bins_pass<<histName; |
785 |
+ |
bins_pass<<">>pass("; |
786 |
+ |
bins_pass<<total->GetNbinsX(); |
787 |
+ |
bins_pass<<","; |
788 |
+ |
bins_pass<<total->GetXaxis()->GetXmin(); |
789 |
+ |
bins_pass<<","; |
790 |
+ |
bins_pass<<total->GetXaxis()->GetXmax(); |
791 |
+ |
bins_pass<<")"; |
792 |
+ |
|
793 |
+ |
ostringstream cut_pass; |
794 |
+ |
cut_pass<<"!("; |
795 |
+ |
cut_pass<<cutName; |
796 |
+ |
cut_pass<<")"; |
797 |
+ |
|
798 |
+ |
|
799 |
+ |
if( ! pads_["pass"] || ! gROOT->FindObject("pass") ) { |
800 |
+ |
pads_["pass"] = new TCanvas("pass", currPadName.str().c_str()); |
801 |
+ |
} else { |
802 |
+ |
pads_["pass"]->cd(); |
803 |
+ |
} |
804 |
+ |
|
805 |
+ |
draw_err = ((TChain*) this->At(chainIndex))->Draw(bins_pass.str().c_str(),cut_pass.str().c_str() ,"" , currN); |
806 |
+ |
if( draw_err <= 0 ) return draw_err; |
807 |
+ |
|
808 |
+ |
|
809 |
+ |
TH1* pass = ((TH1*) pads_["pass"]->GetPrimitive("pass")); |
810 |
+ |
|
811 |
+ |
|
812 |
+ |
currPadName<<"Eff"; |
813 |
+ |
//Draw Efficiency Graph: |
814 |
+ |
if( ! pads_["EffGraph"] || ! gROOT->FindObject("EffGraph") ) { |
815 |
+ |
pads_["EffGraph"] = new TCanvas("EffGraph", currPadName.str().c_str()); |
816 |
+ |
} else { |
817 |
+ |
pads_["EffGraph"]->cd(); |
818 |
+ |
} |
819 |
+ |
|
820 |
+ |
TGraphAsymmErrors* EffGraph = new TGraphAsymmErrors(bkg, total); |
821 |
+ |
EffGraph->SetName(currHistName.str().c_str()); |
822 |
+ |
|
823 |
+ |
TF1* reverse = new TF2("reverse","1/y-1",total->GetXaxis()->GetXmin(),total->GetXaxis()->GetXmax()); |
824 |
+ |
EffGraph->Apply(reverse); |
825 |
+ |
EffGraph->Draw("A*"); |
826 |
+ |
|
827 |
+ |
TF1* fitfunc = new TF1("fitfunc",fitFormula.c_str(),fitXmin,fitXmax); |
828 |
+ |
EffGraph->Fit("fitfunc","R+"); |
829 |
+ |
|
830 |
+ |
|
831 |
+ |
//Save fit function |
832 |
+ |
|
833 |
+ |
ostringstream savefuncName; |
834 |
+ |
savefuncName<<histName; |
835 |
+ |
savefuncName<<"_"; |
836 |
+ |
|
837 |
+ |
if(cutName.find("<") != std::string::npos ) cutName.replace(cutName.find("<"),1,"_"); |
838 |
+ |
if(cutName.find(">") != std::string::npos ) cutName.replace(cutName.find(">"),1,"_"); |
839 |
+ |
savefuncName<<cutName; |
840 |
+ |
|
841 |
+ |
|
842 |
+ |
TFile file("ABCDFunctions.root","UPDATE"); |
843 |
+ |
TF1* savefunc = new TF1(savefuncName.str().c_str(), fitfunc->GetExpFormula().Data(),0,10000); |
844 |
+ |
savefunc->SetParameters( fitfunc->GetParameters() ); |
845 |
+ |
savefunc->SetParErrors ( fitfunc->GetParErrors() ); |
846 |
+ |
|
847 |
+ |
//Show results |
848 |
+ |
if( ! pads_["abcd"] || ! gROOT->FindObject("abcd") ) { |
849 |
+ |
pads_["abcd"] = new TCanvas("abcd", "abcd"); |
850 |
+ |
} else { |
851 |
+ |
pads_["abcd"]->cd(); |
852 |
+ |
} |
853 |
+ |
|
854 |
+ |
bkg->Multiply(savefunc); |
855 |
+ |
bkg->Draw(); |
856 |
+ |
|
857 |
+ |
// total->Add(bkg,-1); |
858 |
+ |
pass->SetLineColor(kRed); |
859 |
+ |
pass->Draw("sames,e"); |
860 |
+ |
pads_["abcd"]->SetLogy(); |
861 |
+ |
|
862 |
+ |
|
863 |
+ |
savefunc->Write(); |
864 |
+ |
// file.Close(); |
865 |
+ |
|
866 |
+ |
|
867 |
+ |
return draw_err; |
868 |
+ |
|
869 |
+ |
} |
870 |
+ |
//------------------------------------------------------------------ |