14 |
|
|
15 |
|
showLegend = false; |
16 |
|
logY = true; |
17 |
+ |
addTrackJets = false; |
18 |
+ |
verbose = true; |
19 |
|
|
20 |
|
} |
21 |
|
|
22 |
|
//------------------------------------------------------------------ |
23 |
|
//Fill object PlotTool with Chains constructed from files from given source |
24 |
+ |
|
25 |
|
int PlotTool::init(string fileName, string dirPath, string treeName, |
26 |
|
string fileLabel) { |
27 |
|
this->New(this->GetEntries() ); |
29 |
|
|
30 |
|
if (currChain < 0) |
31 |
|
return currChain; |
32 |
< |
//make file for tree friends (adding additional, computed branches) |
33 |
< |
string friendFileName("/scratch/hh/lustre/cms/user/thomsen/temp/"); |
34 |
< |
friendFileName += fileName; |
35 |
< |
friendFileName += ".root"; |
33 |
< |
TFile *f = new TFile(friendFileName.c_str(),"recreate"); |
34 |
< |
string friendTreeName("friendTree"); |
35 |
< |
//char number = currChain; |
36 |
< |
//friendTreeName += number; |
37 |
< |
//TTree *friendTree = new TTree("friendTree","friendTree"); |
38 |
< |
TTree *friendTree = new TTree(friendTreeName.c_str(),friendTreeName.c_str()); |
32 |
> |
|
33 |
> |
TStopwatch timer; |
34 |
> |
timer.Start(); |
35 |
> |
|
36 |
|
|
37 |
|
fileNames.clear(); |
38 |
|
|
41 |
|
fileLabel=fileName; |
42 |
|
} |
43 |
|
((TChain*) this->At(currChain))->SetName(fileLabel.c_str()); |
44 |
+ |
|
45 |
+ |
TList *files = new TList(); |
46 |
+ |
TSystemFile* sysFile = 0; |
47 |
+ |
if(fileName.find(".") != string::npos) { |
48 |
+ |
ifstream f(fileName.c_str()); |
49 |
+ |
if( ! f.is_open() ) return -1; |
50 |
+ |
string line; |
51 |
+ |
|
52 |
+ |
while (!f.eof()) { |
53 |
+ |
getline(f,line); |
54 |
+ |
sysFile = new TSystemFile(line.c_str(),dirPath.c_str()); |
55 |
+ |
files->Add(sysFile); |
56 |
+ |
} |
57 |
+ |
|
58 |
+ |
|
59 |
+ |
} else { |
60 |
|
TSystemDirectory dir("sourceDir", dirPath.c_str()); |
61 |
< |
TList *files = dir.GetListOfFiles(); |
62 |
< |
if (files) { |
61 |
> |
files = dir.GetListOfFiles(); |
62 |
> |
} |
63 |
> |
if (files->GetEntries()>0) { |
64 |
|
TIter next(files); |
65 |
|
TSystemFile *file; |
66 |
|
TString fname; |
67 |
|
string filePath; |
68 |
|
|
69 |
< |
cout<<"Open"<<dirPath.c_str()<<" Search for .root files that contain: " |
69 |
> |
if(verbose && fileName.find(".") == string::npos ) cout<<"Open"<<dirPath.c_str()<<" Search for .root files that contain: " |
70 |
> |
<<fileName.c_str()<<endl; |
71 |
> |
if(verbose && fileName.find(".") != string::npos ) cout<<"Open"<<dirPath.c_str()<<" Search lines with .root in: " |
72 |
|
<<fileName.c_str()<<endl; |
73 |
|
|
74 |
+ |
|
75 |
|
while ((file=(TSystemFile*)next())) { |
76 |
|
fname = file->GetName(); |
77 |
|
if (!fname.EndsWith(".root")) |
78 |
|
continue; |
79 |
< |
if (!fname.Contains(fileName.c_str())) |
79 |
> |
if (!fname.Contains(fileName.c_str()) && fileName.find(".") == string::npos ) |
80 |
|
continue; |
81 |
|
|
82 |
|
filePath = dirPath; |
86 |
|
|
87 |
|
if (((TChain*) this->At(currChain))->AddFile(filePath.c_str(), -1, |
88 |
|
treeName.c_str()) ) |
89 |
< |
cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl; |
89 |
> |
if(verbose) cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl; |
90 |
|
else |
91 |
|
return -1; |
92 |
|
|
97 |
|
for (int i=0; i<((TChain*) this->At(currChain))->GetListOfBranches()->GetEntries(); ++i) { |
98 |
|
|
99 |
|
string s(((TChain*) this->At(currChain))->GetListOfBranches()->At(i)->GetName()); |
100 |
< |
size_t a = s.find("_"); |
101 |
< |
if (a == string::npos) |
85 |
< |
a = 0; |
86 |
< |
size_t b = s.find("_", a+1); |
87 |
< |
if (b == string::npos) |
88 |
< |
b = 50; |
89 |
< |
string branch_alias = s.substr(a+1, b-a-1); |
100 |
> |
|
101 |
> |
string branch_alias = s; |
102 |
|
string branch_name = s; |
103 |
|
if (s.find(".", s.size()-1) != string::npos) |
104 |
|
branch_name += "obj"; |
105 |
+ |
|
106 |
+ |
size_t a = s.find("_"); |
107 |
+ |
if (a != string::npos) { |
108 |
+ |
size_t b = s.find("_", a+1); |
109 |
+ |
if (b != string::npos) { |
110 |
+ |
size_t c = s.find("_", b+1); |
111 |
+ |
if (c != string::npos) { |
112 |
+ |
string _prod =s.substr(0,a); |
113 |
+ |
string _label =s.substr(a+1, b-a-1); |
114 |
+ |
string _instance =s.substr(b+1, c-b-1); |
115 |
+ |
branch_alias = _label; |
116 |
+ |
if(_instance.length() > 0 ) { |
117 |
+ |
branch_alias += "_"; |
118 |
+ |
branch_alias += _instance; |
119 |
+ |
((TChain*) this->At(currChain))->SetAlias(_instance.c_str(), |
120 |
+ |
branch_name.c_str()); |
121 |
+ |
} |
122 |
+ |
string branch_alias_full = _prod + "_" + branch_alias; |
123 |
+ |
((TChain*) this->At(currChain))->SetAlias(branch_alias_full.c_str(), |
124 |
+ |
branch_name.c_str()); |
125 |
+ |
} |
126 |
+ |
} |
127 |
+ |
} |
128 |
+ |
|
129 |
|
((TChain*) this->At(currChain))->SetAlias(branch_alias.c_str(), |
130 |
|
branch_name.c_str()); |
131 |
|
|
133 |
|
|
134 |
|
// add branch with track Jets |
135 |
|
|
136 |
< |
int nJetsKT; |
101 |
< |
TrackJetKT = new float [100]; |
102 |
< |
fwlite::ChainEvent ev(fileNames); |
103 |
< |
|
104 |
< |
friendTree->Branch("nJetsKT", &nJetsKT, "nJetsKT/I"); |
105 |
< |
friendTree->Branch("TrackJetKT", TrackJetKT, "TrackJetKT[nJetsKT]/F"); |
106 |
< |
|
107 |
< |
cout<<"calculating additional variables..."<<endl; |
108 |
< |
for (ev.toBegin(); !ev.atEnd(); ++ev) { |
109 |
< |
|
110 |
< |
fwlite::Handle<reco::CaloJetCollection> jets; |
111 |
< |
jets.getByLabel(ev, "antikt5CaloJets"); |
112 |
< |
|
113 |
< |
fwlite::Handle<reco::TrackCollection> tracks; |
114 |
< |
tracks.getByLabel(ev, "generalTracks"); |
115 |
< |
|
116 |
< |
if (!jets.isValid()) |
117 |
< |
continue; |
118 |
< |
if (!tracks.isValid()) |
119 |
< |
continue; |
120 |
< |
double trackSum; |
121 |
< |
nJetsKT = 0; |
122 |
< |
for (reco::CaloJetCollection::const_iterator jet = jets->begin(); jet |
123 |
< |
!=jets->end(); jet++) { |
124 |
< |
trackSum = 0; |
125 |
< |
for (reco::TrackCollection::const_iterator track = tracks->begin(); track |
126 |
< |
!=tracks->end(); track++) { |
127 |
< |
if (deltaR(jet->eta(), jet->phi(), track->eta(), track->phi()) |
128 |
< |
< 0.5) |
129 |
< |
trackSum += track->pt(); |
130 |
< |
} |
131 |
< |
TrackJetKT[nJetsKT] = trackSum; |
132 |
< |
nJetsKT++; |
133 |
< |
} |
134 |
< |
friendTree->Fill(); |
135 |
< |
} |
136 |
< |
f->cd(); |
137 |
< |
friendTree->Write(); |
138 |
< |
f->Close(); |
139 |
< |
((TChain*) this->At(currChain))->AddFriend(friendTreeName.c_str(), |
140 |
< |
friendFileName.c_str()); |
136 |
> |
if( addTrackJets ) { |
137 |
|
|
138 |
+ |
//make file for tree friends (adding additional, computed branches) |
139 |
+ |
string friendFileName("/scratch/hh/current/cms/user/"); |
140 |
+ |
friendFileName += gSystem->GetUserInfo()->fUser; |
141 |
+ |
friendFileName += "/temp/", |
142 |
+ |
friendFileName += fileName; |
143 |
+ |
friendFileName += ".root"; |
144 |
+ |
TFile *f = new TFile(friendFileName.c_str(),"recreate"); |
145 |
+ |
|
146 |
+ |
if( f->IsZombie() ) return -1; |
147 |
+ |
|
148 |
+ |
string friendTreeName("friendTree"); |
149 |
+ |
//char number = currChain; |
150 |
+ |
//friendTreeName += number; |
151 |
+ |
//TTree *friendTree = new TTree("friendTree","friendTree"); |
152 |
+ |
TTree *friendTree = new TTree(friendTreeName.c_str(),friendTreeName.c_str()); |
153 |
+ |
|
154 |
+ |
int nJetsKT; |
155 |
+ |
TrackJetKT = new float [100]; |
156 |
+ |
fwlite::ChainEvent ev(fileNames); |
157 |
+ |
|
158 |
+ |
friendTree->Branch("nJetsKT", &nJetsKT, "nJetsKT/I"); |
159 |
+ |
friendTree->Branch("TrackJetKT", TrackJetKT, "TrackJetKT[nJetsKT]/F"); |
160 |
+ |
|
161 |
+ |
if(verbose) cout<<"calculating additional variables..."<<endl; |
162 |
+ |
|
163 |
+ |
|
164 |
+ |
|
165 |
+ |
int tenth = ev.size() / 10; |
166 |
+ |
int eventNum =0; |
167 |
+ |
for (ev.toBegin(); !ev.atEnd(); ++ev, ++eventNum) { |
168 |
+ |
|
169 |
+ |
fwlite::Handle<reco::CaloJetCollection> jets; |
170 |
+ |
jets.getByLabel(ev, "antikt5CaloJets"); |
171 |
+ |
|
172 |
+ |
fwlite::Handle<reco::TrackCollection> tracks; |
173 |
+ |
tracks.getByLabel(ev, "generalTracks"); |
174 |
+ |
|
175 |
+ |
if (!jets.isValid()) |
176 |
+ |
continue; |
177 |
+ |
if (!tracks.isValid()) |
178 |
+ |
continue; |
179 |
+ |
double trackSum; |
180 |
+ |
nJetsKT = 0; |
181 |
+ |
for (reco::CaloJetCollection::const_iterator jet = jets->begin(); jet |
182 |
+ |
!=jets->end(); jet++) { |
183 |
+ |
trackSum = 0; |
184 |
+ |
for (reco::TrackCollection::const_iterator track = tracks->begin(); track |
185 |
+ |
!=tracks->end(); track++) { |
186 |
+ |
if (deltaR(jet->eta(), jet->phi(), track->eta(), track->phi()) |
187 |
+ |
< 0.5) |
188 |
+ |
trackSum += track->pt(); |
189 |
+ |
} |
190 |
+ |
TrackJetKT[nJetsKT] = trackSum; |
191 |
+ |
nJetsKT++; |
192 |
+ |
} |
193 |
+ |
friendTree->Fill(); |
194 |
+ |
|
195 |
+ |
if( eventNum != 0 && eventNum%tenth == 0) cout<<"Processed "<<eventNum <<" of "<<ev.size()<<" events. "<<endl; |
196 |
+ |
|
197 |
+ |
} |
198 |
+ |
f->cd(); |
199 |
+ |
friendTree->Write(); |
200 |
+ |
f->Close(); |
201 |
+ |
((TChain*) this->At(currChain))->AddFriend(friendTreeName.c_str(), |
202 |
+ |
friendFileName.c_str()); |
203 |
+ |
} |
204 |
+ |
|
205 |
+ |
timer.Stop(); |
206 |
+ |
if(verbose) timer.Print(); |
207 |
+ |
|
208 |
|
return this->GetEntries(); |
209 |
|
|
210 |
|
} |
216 |
|
if (chainIndex >= this->GetEntries() ) |
217 |
|
return -1; |
218 |
|
|
219 |
+ |
TStopwatch timer; |
220 |
+ |
if(verbose) { |
221 |
+ |
cout<<"Plot: "<<histName<<" "<<cutName<<" from chain "<<this->At(chainIndex)->GetName()<<endl; |
222 |
+ |
timer.Start(); |
223 |
+ |
} |
224 |
+ |
|
225 |
|
int currN = nEntries; |
226 |
|
if (nEntries < 0) |
227 |
|
currN = ((TChain*) this->At(chainIndex))->GetEntries(); //nEntries<0 : all entries are plotted! |
260 |
|
&& !samePad_vars) || (sameCanv_cuts && !samePad_cuts); |
261 |
|
|
262 |
|
if (useSubPads) { |
263 |
< |
if ( !canvases_[currCanvName.str()] || !gROOT->FindObject(currCanvName.str().c_str()) ) { |
263 |
> |
if ( !canvases_[currCanvName.str()] || !gROOT->GetListOfCanvases()->FindObject(currCanvName.str().c_str()) ) { |
264 |
|
canvases_[currCanvName.str()] = new TCanvas(currCanvName.str().c_str(), currCanvName.str().c_str()); |
265 |
|
} else if (canvases_[currCanvName.str()]->GetNumber() >= 0) { |
266 |
|
canvases_[currCanvName.str()]->SetNumber(canvases_[currCanvName.str()]->GetNumber()+1); |
267 |
|
} |
268 |
|
} |
269 |
|
|
270 |
< |
if ( !pads_[currPadName.str()] || !gROOT->FindObject(currPadName.str().c_str()) ) { |
270 |
> |
if ( !pads_[currPadName.str()] || !gROOT->GetListOfCanvases()->FindObject(currPadName.str().c_str()) ) { |
271 |
|
pads_[currPadName.str()] = new TCanvas(currPadName.str().c_str(), currPadName.str().c_str()); |
272 |
< |
if (logY) |
273 |
< |
pads_[currPadName.str()]->SetLogy(1); |
272 |
> |
// if (logY) |
273 |
> |
// pads_[currPadName.str()]->SetLogy(1); |
274 |
|
} else { |
275 |
|
pads_[currPadName.str()]->cd(); |
276 |
|
currOpt += "SAMES"; |
302 |
|
|
303 |
|
((TH1F*) pads_[currPadName.str()]->GetPrimitive("htemp"))->SetName(currHistName.str().c_str()); // Set Name of histogram |
304 |
|
|
305 |
+ |
// Update for 2D histograms |
306 |
+ |
if( pads_[currPadName.str()]->GetPrimitive(currHistName.str().c_str())->InheritsFrom("TH2") ) { |
307 |
+ |
pads_[currPadName.str()]->Draw(); |
308 |
+ |
setCanvas( pads_[currPadName.str()] ); |
309 |
+ |
} |
310 |
+ |
|
311 |
|
|
312 |
+ |
if(verbose) { |
313 |
+ |
timer.Stop(); |
314 |
+ |
cout<<"Done: "<<currN<<" events."<<endl; |
315 |
+ |
timer.Print(); |
316 |
+ |
} |
317 |
|
return draw_err; |
318 |
|
|
319 |
|
} |
333 |
|
!= _cutName.end(); ++it2) { |
334 |
|
|
335 |
|
numProcessed += plot(i, *it1, *it2, nEntries, drwOpt); |
336 |
< |
updatePads(); |
336 |
> |
|
337 |
|
|
338 |
|
} |
339 |
|
} |
354 |
|
} |
355 |
|
} |
356 |
|
|
357 |
< |
// updatePads(); |
357 |
> |
updatePads(); |
358 |
|
fillCanvases(); |
359 |
|
|
360 |
|
return numProcessed; |
395 |
|
int PlotTool::updatePads() { |
396 |
|
|
397 |
|
for (map< string, TCanvas* >::iterator it=pads_.begin() ; it != pads_.end(); ++it) { |
398 |
< |
if (gROOT->FindObject((*it).first.c_str() ) ) { |
398 |
> |
if (gROOT->GetListOfCanvases()->FindObject((*it).first.c_str() ) ) { |
399 |
|
(*it).second->Draw(); |
400 |
|
setCanvas((*it).second); |
401 |
|
} else |
410 |
|
|
411 |
|
for (map< string, TCanvas* >::iterator it=canvases_.begin() ; it |
412 |
|
!= canvases_.end(); ++it) { |
413 |
< |
const char* canvName = (*it).first.c_str(); |
414 |
< |
if (gROOT->FindObject(canvName) ) { |
413 |
> |
string canvName = (*it).first; |
414 |
> |
if (gROOT->GetListOfCanvases()->FindObject(canvName.c_str()) ) { |
415 |
|
|
416 |
|
int numP = (*it).second->GetNumber()+1; |
417 |
|
|
429 |
|
y += 1; |
430 |
|
} |
431 |
|
|
432 |
+ |
|
433 |
|
(*it).second->Divide(x, y); |
434 |
|
int padIndex = 1; |
435 |
|
for (map< string, TCanvas* >::iterator it2=pads_.begin() ; it2 |
436 |
|
!= pads_.end(); ++it2) { |
437 |
|
string padName = (*it2).first; |
438 |
< |
if (gROOT->FindObject(padName.c_str() ) ) { |
439 |
< |
if ( (padName.find(canvName) != string::npos ) || !strcmp( |
440 |
< |
canvName, "All") ) { |
438 |
> |
if (gROOT->GetListOfCanvases()->FindObject(padName.c_str() ) ) { |
439 |
> |
string n1 = canvName.substr(0,canvName.find(":")); |
440 |
> |
string n2(""); |
441 |
> |
if(canvName.find("{") != string::npos ) n2 = canvName.substr(canvName.find("{"),canvName.find("}")); |
442 |
> |
|
443 |
> |
if ( (padName.find(canvName.c_str()) != string::npos ) || (padName.find(n1) != string::npos && padName.find(n2) != string::npos) || !strcmp( canvName.c_str(), "All") ) { |
444 |
|
(*it).second->cd(padIndex); |
445 |
|
(*it2).second->DrawClonePad(); |
446 |
|
(*it2).second->Close(); |
681 |
|
|
682 |
|
//------------------------------------------------------------------ |
683 |
|
|
684 |
< |
int PlotTool::saveCanvases(string type, string path) { |
684 |
> |
int PlotTool::saveCanvases(string name, string path) { |
685 |
|
|
686 |
|
TSystemDirectory d("", path.c_str()); |
687 |
|
if (!d.GetListOfFiles()) |
688 |
|
return -1; |
602 |
– |
if (type.find(".") == string::npos) |
603 |
– |
return -1; |
689 |
|
|
690 |
< |
int savedFiles =0; |
690 |
> |
string namePs = path +"/" + name; |
691 |
> |
string nameRt = path +"/" + name; |
692 |
> |
|
693 |
> |
if (name.find(".ps") == string::npos) |
694 |
> |
namePs += ".ps"; |
695 |
> |
|
696 |
> |
if (name.find(".root") == string::npos) |
697 |
> |
nameRt += ".root"; |
698 |
> |
|
699 |
> |
int savedCanvs =0; |
700 |
> |
|
701 |
> |
TPostScript ps(namePs.c_str(),112); |
702 |
> |
TFile rt(nameRt.c_str(),"recreate"); |
703 |
|
|
704 |
|
TIter next(gROOT->GetListOfCanvases()); |
705 |
|
TCanvas* canv; |
706 |
|
while ((canv=(TCanvas*)next())) { |
707 |
+ |
ps.NewPage(); |
708 |
+ |
(*canv).Draw(); |
709 |
+ |
(*canv).Update(); |
710 |
+ |
(*canv).Write(); |
711 |
+ |
++savedCanvs; |
712 |
|
|
713 |
< |
string s = ""; |
612 |
< |
s += path; |
613 |
< |
s += canv->GetName(); |
614 |
< |
s += type; |
713 |
> |
} |
714 |
|
|
715 |
< |
canv->SaveAs(s.c_str()); |
716 |
< |
++savedFiles; |
715 |
> |
ps.Close(); |
716 |
> |
rt.Close(); |
717 |
> |
|
718 |
> |
return savedCanvs; |
719 |
> |
|
720 |
> |
} |
721 |
> |
//------------------------------------------------------------------ |
722 |
> |
|
723 |
> |
int PlotTool::clearCanvases() |
724 |
> |
{ |
725 |
> |
|
726 |
> |
while(gROOT->GetListOfCanvases()->GetEntries()) ((TCanvas*) gROOT->GetListOfCanvases()->At(0))->Close(); |
727 |
> |
pads_.clear(); |
728 |
> |
autoVars.clear(); |
729 |
> |
return pads_.size() + gROOT->GetListOfCanvases()->GetEntries(); |
730 |
> |
|
731 |
> |
} |
732 |
> |
//------------------------------------------------------------------ |
733 |
> |
int PlotTool::setVariables(string label) |
734 |
> |
{ |
735 |
> |
|
736 |
> |
cout<<endl; |
737 |
> |
cout<<"****** Show Chain Information:"<<endl; |
738 |
> |
|
739 |
> |
|
740 |
> |
this->ls(); |
741 |
> |
|
742 |
> |
cout<<endl; |
743 |
> |
cout<<"We have "<<this->GetEntries()<<" TChains with following aliases set:"<<endl; |
744 |
> |
for (int i=0; i< this->GetEntries(); ++i) { |
745 |
> |
cout<<"--------------------------------"<<endl; |
746 |
> |
cout<<((TChain*) this->At(i))->GetName()<<endl; |
747 |
> |
cout<<"------------"<<endl; |
748 |
> |
|
749 |
> |
TList* leaves = (TList*) ((TChain*) this->At(i))->GetListOfLeaves(); |
750 |
> |
for (int j=0; j< leaves->GetEntries(); ++j) { |
751 |
> |
TString leafName ( leaves->At(j)->GetName() ); |
752 |
> |
if(! leafName.EndsWith(".") ) continue; |
753 |
> |
if(! leafName.Contains(label.c_str() ) ) continue; |
754 |
> |
|
755 |
> |
TClass cl( ( (TLeafElement*) leaves->At(j) )->GetTypeName() ); |
756 |
> |
cout<<"++++++"<<endl; |
757 |
> |
cout<< leafName.Data() <<endl; |
758 |
> |
for(int k=0;k<cl.GetListOfAllPublicMethods()->GetEntries();++k) { |
759 |
> |
string typeName ( ((TMethod*) cl.GetListOfAllPublicMethods()->At(k))->GetReturnTypeName() ); |
760 |
> |
string methName ( cl.GetListOfAllPublicMethods()->At(k)->GetName() ); |
761 |
> |
if( methName != "product") continue; |
762 |
> |
cout<< typeName <<endl; |
763 |
> |
string _type; |
764 |
> |
TString testString( typeName.c_str() ); |
765 |
> |
if( testString.BeginsWith("vector<") ) { |
766 |
> |
_type = typeName.substr(typeName.find("<")+1,typeName.find(">")-typeName.find("<")-1); |
767 |
> |
string _varSize = leafName.Data(); |
768 |
> |
_varSize += "obj@.size()"; |
769 |
> |
autoVars.push_back( _varSize ); |
770 |
> |
} |
771 |
> |
else _type = typeName.substr(0,typeName.find("*")); |
772 |
> |
TClass _cl( _type.c_str() ); |
773 |
> |
for(int l=0;l<_cl.GetListOfAllPublicMethods()->GetEntries();++l) { |
774 |
> |
string _typeName ( ((TMethod*) _cl.GetListOfAllPublicMethods()->At(l))->GetReturnTypeName() ); |
775 |
> |
string _methName ( _cl.GetListOfAllPublicMethods()->At(l)->GetName() ); |
776 |
> |
// if(_typeName.find("void") != string::npos ) continue; |
777 |
> |
// cout<<" "<<_typeName<<" "<<_methName<<endl; |
778 |
> |
|
779 |
> |
cout<<" "<<_typeName<<" "<<_methName<<endl; |
780 |
> |
if(_methName.find("operator")==string::npos&&(_typeName=="float"||_typeName=="double"||_typeName=="int"||_typeName=="unsigned int"||_typeName=="bool"||_typeName=="unsigned short"||_typeName=="unsigned long"||_typeName=="unsigned long long")) { |
781 |
> |
|
782 |
> |
cout<<"--> "<<_typeName<<" "<<_methName<<endl; |
783 |
> |
|
784 |
> |
string _varName = leafName.Data(); |
785 |
> |
_varName += "obj."; |
786 |
> |
_varName += _methName; |
787 |
> |
_varName += "()"; |
788 |
> |
autoVars.push_back( _varName ); |
789 |
> |
} |
790 |
> |
} |
791 |
> |
|
792 |
> |
|
793 |
> |
} |
794 |
> |
|
795 |
> |
} |
796 |
> |
|
797 |
> |
} |
798 |
> |
|
799 |
> |
return autoVars.size(); |
800 |
> |
|
801 |
> |
} |
802 |
> |
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
803 |
> |
//Draw efficiencies |
804 |
> |
int PlotTool::plotEff(int chainIndex, string histName, string cutName, int nEntries, double fitXmin, double fitXmax, string fitFormula) |
805 |
> |
{ |
806 |
> |
|
807 |
> |
if( chainIndex >= this->GetEntries() ) return -1; |
808 |
> |
|
809 |
> |
int currN = nEntries; |
810 |
> |
if(nEntries < 0) currN = ((TChain*) this->At(chainIndex))->GetEntries(); //nEntries<0 : all entries are plotted! |
811 |
> |
|
812 |
> |
//++++ Create and name Canvases according to global variables +++++++++++++ |
813 |
> |
ostringstream currHistName; |
814 |
> |
if( samePad_trees) currHistName<<((TChain*) this->At(chainIndex))->GetName()<<":"; |
815 |
> |
if( samePad_vars) currHistName<<histName; |
816 |
> |
if( samePad_cuts) currHistName<<"{"<<cutName<<"}"; |
817 |
> |
|
818 |
> |
ostringstream currPadName; |
819 |
> |
if(! samePad_trees) currPadName<<((TChain*) this->At(chainIndex))->GetName()<<":"; |
820 |
> |
if(! samePad_vars) currPadName<<histName; |
821 |
> |
if(! samePad_cuts) currPadName<<"{"<<cutName<<"}"; |
822 |
> |
|
823 |
> |
|
824 |
> |
//Draw total histogram: |
825 |
> |
if( ! pads_["total"] || ! gROOT->FindObject("total") ) { |
826 |
> |
pads_["total"] = new TCanvas("total", "total"); |
827 |
> |
} else { |
828 |
> |
pads_["total"]->cd(); |
829 |
> |
} |
830 |
> |
ostringstream bins_total; |
831 |
> |
bins_total<<histName; |
832 |
> |
bins_total<<">>total(100,0,1000)"; |
833 |
> |
|
834 |
> |
|
835 |
> |
int draw_err = ((TChain*) this->At(chainIndex))->Draw(bins_total.str().c_str(), "", "", currN); |
836 |
> |
if( draw_err <= 0 ) return draw_err; |
837 |
> |
|
838 |
> |
|
839 |
> |
TH1* total = ((TH1*) pads_["total"]->GetPrimitive("total")); |
840 |
> |
|
841 |
> |
ostringstream bins_bkg; |
842 |
> |
bins_bkg<<histName; |
843 |
> |
bins_bkg<<">>bkg("; |
844 |
> |
bins_bkg<<total->GetNbinsX(); |
845 |
> |
bins_bkg<<","; |
846 |
> |
bins_bkg<<total->GetXaxis()->GetXmin(); |
847 |
> |
bins_bkg<<","; |
848 |
> |
bins_bkg<<total->GetXaxis()->GetXmax(); |
849 |
> |
bins_bkg<<")"; |
850 |
> |
|
851 |
> |
//Draw bkg histogram: |
852 |
> |
if( ! pads_["bkg"] || ! gROOT->FindObject("bkg") ) { |
853 |
> |
pads_["bkg"] = new TCanvas("bkg", currPadName.str().c_str()); |
854 |
> |
} else { |
855 |
> |
pads_["bkg"]->cd(); |
856 |
> |
} |
857 |
> |
|
858 |
> |
draw_err = ((TChain*) this->At(chainIndex))->Draw(bins_bkg.str().c_str(), cutName.c_str(),"" , currN); |
859 |
> |
if( draw_err <= 0 ) return draw_err; |
860 |
> |
|
861 |
> |
|
862 |
> |
TH1* bkg = ((TH1*) pads_["bkg"]->GetPrimitive("bkg")); |
863 |
> |
|
864 |
> |
//Draw pass histogram: |
865 |
> |
ostringstream bins_pass; |
866 |
> |
bins_pass<<histName; |
867 |
> |
bins_pass<<">>pass("; |
868 |
> |
bins_pass<<total->GetNbinsX(); |
869 |
> |
bins_pass<<","; |
870 |
> |
bins_pass<<total->GetXaxis()->GetXmin(); |
871 |
> |
bins_pass<<","; |
872 |
> |
bins_pass<<total->GetXaxis()->GetXmax(); |
873 |
> |
bins_pass<<")"; |
874 |
> |
|
875 |
> |
ostringstream cut_pass; |
876 |
> |
cut_pass<<"!("; |
877 |
> |
cut_pass<<cutName; |
878 |
> |
cut_pass<<")"; |
879 |
> |
|
880 |
> |
|
881 |
> |
if( ! pads_["pass"] || ! gROOT->FindObject("pass") ) { |
882 |
> |
pads_["pass"] = new TCanvas("pass", currPadName.str().c_str()); |
883 |
> |
} else { |
884 |
> |
pads_["pass"]->cd(); |
885 |
> |
} |
886 |
> |
|
887 |
> |
draw_err = ((TChain*) this->At(chainIndex))->Draw(bins_pass.str().c_str(),cut_pass.str().c_str() ,"" , currN); |
888 |
> |
if( draw_err <= 0 ) return draw_err; |
889 |
> |
|
890 |
> |
|
891 |
> |
TH1* pass = ((TH1*) pads_["pass"]->GetPrimitive("pass")); |
892 |
> |
|
893 |
> |
|
894 |
> |
currPadName<<"Eff"; |
895 |
> |
//Draw Efficiency Graph: |
896 |
> |
if( ! pads_["EffGraph"] || ! gROOT->FindObject("EffGraph") ) { |
897 |
> |
pads_["EffGraph"] = new TCanvas("EffGraph", currPadName.str().c_str()); |
898 |
> |
} else { |
899 |
> |
pads_["EffGraph"]->cd(); |
900 |
> |
} |
901 |
> |
|
902 |
> |
TGraphAsymmErrors* EffGraph = new TGraphAsymmErrors(bkg, total); |
903 |
> |
EffGraph->SetName(currHistName.str().c_str()); |
904 |
> |
|
905 |
> |
TF1* reverse = new TF2("reverse","1/y-1",total->GetXaxis()->GetXmin(),total->GetXaxis()->GetXmax()); |
906 |
> |
EffGraph->Apply(reverse); |
907 |
> |
EffGraph->Draw("A*"); |
908 |
> |
|
909 |
> |
TF1* fitfunc = new TF1("fitfunc",fitFormula.c_str(),fitXmin,fitXmax); |
910 |
> |
EffGraph->Fit("fitfunc","R+"); |
911 |
> |
|
912 |
> |
|
913 |
> |
//Save fit function |
914 |
> |
|
915 |
> |
ostringstream savefuncName; |
916 |
> |
savefuncName<<histName; |
917 |
> |
savefuncName<<"_"; |
918 |
> |
|
919 |
> |
if(cutName.find("<") != std::string::npos ) cutName.replace(cutName.find("<"),1,"_"); |
920 |
> |
if(cutName.find(">") != std::string::npos ) cutName.replace(cutName.find(">"),1,"_"); |
921 |
> |
savefuncName<<cutName; |
922 |
> |
|
923 |
> |
|
924 |
> |
TFile file("ABCDFunctions.root","UPDATE"); |
925 |
> |
TF1* savefunc = new TF1(savefuncName.str().c_str(), fitfunc->GetExpFormula().Data(),0,10000); |
926 |
> |
savefunc->SetParameters( fitfunc->GetParameters() ); |
927 |
> |
savefunc->SetParErrors ( fitfunc->GetParErrors() ); |
928 |
> |
|
929 |
> |
//Show results |
930 |
> |
if( ! pads_["abcd"] || ! gROOT->FindObject("abcd") ) { |
931 |
> |
pads_["abcd"] = new TCanvas("abcd", "abcd"); |
932 |
> |
} else { |
933 |
> |
pads_["abcd"]->cd(); |
934 |
> |
} |
935 |
> |
|
936 |
> |
bkg->Multiply(savefunc); |
937 |
> |
bkg->Draw(); |
938 |
> |
|
939 |
> |
// total->Add(bkg,-1); |
940 |
> |
pass->SetLineColor(kRed); |
941 |
> |
pass->Draw("sames,e"); |
942 |
> |
pads_["abcd"]->SetLogy(); |
943 |
> |
|
944 |
> |
|
945 |
> |
savefunc->Write(); |
946 |
> |
// file.Close(); |
947 |
|
|
619 |
– |
} |
948 |
|
|
949 |
< |
return savedFiles; |
949 |
> |
return draw_err; |
950 |
|
|
951 |
|
} |
952 |
|
//------------------------------------------------------------------ |