14 |
|
|
15 |
|
showLegend = false; |
16 |
|
logY = true; |
17 |
– |
addTrackJets = true; |
17 |
|
verbose = true; |
18 |
|
|
19 |
+ |
globalCuts=""; |
20 |
+ |
|
21 |
+ |
varBlockNames = ""; //Set to "ALL" or add Names, i.e. varBlockNames += "CaloTower" |
22 |
+ |
recreateTree = false; //force recreation of friend tree |
23 |
+ |
|
24 |
|
} |
25 |
|
|
26 |
|
//------------------------------------------------------------------ |
27 |
|
//Fill object PlotTool with Chains constructed from files from given source |
28 |
|
|
29 |
|
int PlotTool::init(string fileName, string dirPath, string treeName, |
30 |
< |
string fileLabel) { |
31 |
< |
this->New(this->GetEntries() ); |
32 |
< |
int currChain = this->GetEntries() - 1; |
30 |
> |
string fileLabel) { |
31 |
> |
this->New(this->GetEntries() ); |
32 |
> |
int currChain = this->GetEntries() - 1; |
33 |
|
|
34 |
< |
if (currChain < 0) |
35 |
< |
return currChain; |
34 |
> |
if (currChain < 0) |
35 |
> |
return currChain; |
36 |
|
|
37 |
< |
TStopwatch timer; |
38 |
< |
timer.Start(); |
37 |
> |
TStopwatch timer; |
38 |
> |
timer.Start(); |
39 |
|
|
40 |
|
|
41 |
< |
fileNames.clear(); |
41 |
> |
fileNames.clear(); |
42 |
|
|
43 |
< |
//check if alternative label is different from default(searchString) |
44 |
< |
if (fileLabel=="") { |
45 |
< |
fileLabel=fileName; |
46 |
< |
} |
47 |
< |
((TChain*) this->At(currChain))->SetName(fileLabel.c_str()); |
44 |
< |
TSystemDirectory dir("sourceDir", dirPath.c_str()); |
45 |
< |
TList *files = dir.GetListOfFiles(); |
46 |
< |
if (files) { |
47 |
< |
TIter next(files); |
48 |
< |
TSystemFile *file; |
49 |
< |
TString fname; |
50 |
< |
string filePath; |
51 |
< |
|
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())) { |
56 |
< |
fname = file->GetName(); |
57 |
< |
if (!fname.EndsWith(".root")) |
58 |
< |
continue; |
59 |
< |
if (!fname.Contains(fileName.c_str())) |
60 |
< |
continue; |
43 |
> |
//check if alternative label is different from default(searchString) |
44 |
> |
if (fileLabel=="") { |
45 |
> |
fileLabel=fileName; |
46 |
> |
} |
47 |
> |
((TChain*) this->At(currChain))->SetName(fileLabel.c_str()); |
48 |
|
|
49 |
< |
filePath = dirPath; |
50 |
< |
filePath += fname.Data(); |
51 |
< |
//fwlite::ChainEvent to lop over events, jets, etc |
52 |
< |
fileNames.push_back(filePath.c_str()); |
53 |
< |
|
54 |
< |
if (((TChain*) this->At(currChain))->AddFile(filePath.c_str(), -1, |
55 |
< |
treeName.c_str()) ) |
56 |
< |
if(verbose) cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl; |
57 |
< |
else |
58 |
< |
return -1; |
49 |
> |
TList *files = new TList(); |
50 |
> |
TSystemFile* sysFile = 0; |
51 |
> |
if(fileName.find(".") != string::npos) { |
52 |
> |
ifstream f(fileName.c_str()); |
53 |
> |
if( ! f.is_open() ) return -1; |
54 |
> |
string line; |
55 |
> |
|
56 |
> |
while (!f.eof()) { |
57 |
> |
getline(f,line); |
58 |
> |
sysFile = new TSystemFile(line.c_str(),dirPath.c_str()); |
59 |
> |
files->Add(sysFile); |
60 |
> |
} |
61 |
|
|
73 |
– |
} |
74 |
– |
} else |
75 |
– |
return -1; |
62 |
|
|
63 |
< |
for (int i=0; i<((TChain*) this->At(currChain))->GetListOfBranches()->GetEntries(); ++i) { |
63 |
> |
} else { |
64 |
> |
TSystemDirectory dir("sourceDir", dirPath.c_str()); |
65 |
> |
files = dir.GetListOfFiles(); |
66 |
> |
} |
67 |
> |
if (files->GetEntries()>0) { |
68 |
> |
TIter next(files); |
69 |
> |
TSystemFile *file; |
70 |
> |
TString fname; |
71 |
> |
string filePath; |
72 |
> |
|
73 |
> |
if(verbose && fileName.find(".") == string::npos ) cout<<"Open"<<dirPath.c_str()<<" Search for .root files that contain: " |
74 |
> |
<<fileName.c_str()<<endl; |
75 |
> |
if(verbose && fileName.find(".") != string::npos ) cout<<"Open"<<dirPath.c_str()<<" Search lines with .root in: " |
76 |
> |
<<fileName.c_str()<<endl; |
77 |
> |
|
78 |
> |
|
79 |
> |
while ((file=(TSystemFile*)next())) { |
80 |
> |
fname = file->GetName(); |
81 |
> |
if (!fname.EndsWith(".root")) |
82 |
> |
continue; |
83 |
> |
if (!fname.Contains(fileName.c_str()) && fileName.find(".") == string::npos ) |
84 |
> |
continue; |
85 |
> |
|
86 |
> |
filePath = dirPath; |
87 |
> |
filePath += fname.Data(); |
88 |
> |
//fwlite::ChainEvent to lop over events, jets, etc |
89 |
> |
fileNames.push_back(filePath.c_str()); |
90 |
> |
|
91 |
> |
if (((TChain*) this->At(currChain))->AddFile(filePath.c_str(), -1, |
92 |
> |
treeName.c_str()) ) { |
93 |
> |
if(verbose) cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl; |
94 |
> |
} else { |
95 |
> |
return -1; |
96 |
> |
} |
97 |
> |
|
98 |
> |
} |
99 |
> |
} else |
100 |
> |
return -1; |
101 |
> |
|
102 |
> |
for (int i=0; i<((TChain*) this->At(currChain))->GetListOfBranches()->GetEntries(); ++i) { |
103 |
> |
|
104 |
> |
string s(((TChain*) this->At(currChain))->GetListOfBranches()->At(i)->GetName()); |
105 |
> |
|
106 |
> |
string branch_alias = s; |
107 |
> |
string branch_name = s; |
108 |
> |
if (s.find(".", s.size()-1) != string::npos) |
109 |
> |
branch_name += "obj"; |
110 |
> |
|
111 |
> |
size_t a = s.find("_"); |
112 |
> |
if (a != string::npos) { |
113 |
> |
size_t b = s.find("_", a+1); |
114 |
> |
if (b != string::npos) { |
115 |
> |
size_t c = s.find("_", b+1); |
116 |
> |
if (c != string::npos) { |
117 |
> |
string _prod =s.substr(0,a); |
118 |
> |
string _label =s.substr(a+1, b-a-1); |
119 |
> |
string _instance =s.substr(b+1, c-b-1); |
120 |
> |
branch_alias = _label; |
121 |
> |
if(_instance.length() > 0 ) { |
122 |
> |
branch_alias += "_"; |
123 |
> |
branch_alias += _instance; |
124 |
> |
((TChain*) this->At(currChain))->SetAlias(_instance.c_str(), |
125 |
> |
branch_name.c_str()); |
126 |
> |
} |
127 |
> |
string branch_alias_full = _prod + "_" + branch_alias; |
128 |
> |
((TChain*) this->At(currChain))->SetAlias(branch_alias_full.c_str(), |
129 |
> |
branch_name.c_str()); |
130 |
> |
} |
131 |
> |
} |
132 |
> |
} |
133 |
|
|
134 |
< |
string s(((TChain*) this->At(currChain))->GetListOfBranches()->At(i)->GetName()); |
134 |
> |
((TChain*) this->At(currChain))->SetAlias(branch_alias.c_str(), |
135 |
> |
branch_name.c_str()); |
136 |
|
|
137 |
< |
string branch_alias = s; |
82 |
< |
string branch_name = s; |
83 |
< |
if (s.find(".", s.size()-1) != string::npos) |
84 |
< |
branch_name += "obj"; |
85 |
< |
|
86 |
< |
size_t a = s.find("_"); |
87 |
< |
if (a != string::npos) { |
88 |
< |
size_t b = s.find("_", a+1); |
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 |
< |
} |
108 |
< |
|
109 |
< |
((TChain*) this->At(currChain))->SetAlias(branch_alias.c_str(), |
110 |
< |
branch_name.c_str()); |
137 |
> |
} |
138 |
|
|
112 |
– |
} |
139 |
|
|
114 |
– |
// add branch with track Jets |
140 |
|
|
141 |
< |
if( addTrackJets ) { |
141 |
> |
|
142 |
> |
|
143 |
> |
string friendTreeName("friendTree"); |
144 |
|
|
145 |
< |
//make file for tree friends (adding additional, computed branches) |
146 |
< |
string friendFileName("/scratch/hh/current/cms/user/"); |
147 |
< |
friendFileName += gSystem->GetUserInfo()->fUser; |
148 |
< |
friendFileName += "/temp/", |
149 |
< |
friendFileName += fileName; |
150 |
< |
friendFileName += ".root"; |
151 |
< |
TFile *f = new TFile(friendFileName.c_str(),"recreate"); |
152 |
< |
|
153 |
< |
if( f->IsZombie() ) return -1; |
154 |
< |
|
155 |
< |
string friendTreeName("friendTree"); |
156 |
< |
//char number = currChain; |
157 |
< |
//friendTreeName += number; |
158 |
< |
//TTree *friendTree = new TTree("friendTree","friendTree"); |
159 |
< |
TTree *friendTree = new TTree(friendTreeName.c_str(),friendTreeName.c_str()); |
160 |
< |
|
161 |
< |
int nJetsKT; |
162 |
< |
TrackJetKT = new float [100]; |
136 |
< |
fwlite::ChainEvent ev(fileNames); |
137 |
< |
|
138 |
< |
friendTree->Branch("nJetsKT", &nJetsKT, "nJetsKT/I"); |
139 |
< |
friendTree->Branch("TrackJetKT", TrackJetKT, "TrackJetKT[nJetsKT]/F"); |
140 |
< |
|
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"); |
151 |
< |
|
152 |
< |
fwlite::Handle<reco::TrackCollection> tracks; |
153 |
< |
tracks.getByLabel(ev, "generalTracks"); |
154 |
< |
|
155 |
< |
if (!jets.isValid()) |
156 |
< |
continue; |
157 |
< |
if (!tracks.isValid()) |
158 |
< |
continue; |
159 |
< |
double trackSum; |
160 |
< |
nJetsKT = 0; |
161 |
< |
for (reco::CaloJetCollection::const_iterator jet = jets->begin(); jet |
162 |
< |
!=jets->end(); jet++) { |
163 |
< |
trackSum = 0; |
164 |
< |
for (reco::TrackCollection::const_iterator track = tracks->begin(); track |
165 |
< |
!=tracks->end(); track++) { |
166 |
< |
if (deltaR(jet->eta(), jet->phi(), track->eta(), track->phi()) |
167 |
< |
< 0.5) |
168 |
< |
trackSum += track->pt(); |
169 |
< |
} |
170 |
< |
TrackJetKT[nJetsKT] = trackSum; |
171 |
< |
nJetsKT++; |
172 |
< |
} |
173 |
< |
friendTree->Fill(); |
145 |
> |
string friendFileName("/scratch/hh/current/cms/user/"); |
146 |
> |
friendFileName += gSystem->GetUserInfo()->fUser; |
147 |
> |
friendFileName += "/temp/"; |
148 |
> |
friendFileName += fileLabel; |
149 |
> |
friendFileName += ".root"; |
150 |
> |
string fileOpt = "update"; |
151 |
> |
if( recreateTree ) fileOpt = "recreate"; |
152 |
> |
|
153 |
> |
FWliteVariables fwVars(friendTreeName, friendFileName, fileOpt); |
154 |
> |
|
155 |
> |
if(varBlockNames.length() > 1 ) { |
156 |
> |
fwVars.loop(fileNames, varBlockNames); |
157 |
> |
if(verbose) cout<<"add friend tree with additional variables: "<<varBlockNames<<endl; |
158 |
> |
((TChain*) this->At(currChain))->AddFriend(friendTreeName.c_str(), |
159 |
> |
friendFileName.c_str()); |
160 |
> |
} else { |
161 |
> |
if(verbose) cout<<"No additional variables added."<<endl; |
162 |
> |
} |
163 |
|
|
164 |
< |
if( eventNum != 0 && eventNum%tenth == 0) cout<<"Processed "<<eventNum <<" of "<<ev.size()<<" events. "<<endl; |
164 |
> |
|
165 |
> |
|
166 |
|
|
177 |
– |
} |
178 |
– |
f->cd(); |
179 |
– |
friendTree->Write(); |
180 |
– |
f->Close(); |
181 |
– |
((TChain*) this->At(currChain))->AddFriend(friendTreeName.c_str(), |
182 |
– |
friendFileName.c_str()); |
183 |
– |
} |
167 |
|
|
168 |
< |
timer.Stop(); |
169 |
< |
if(verbose) timer.Print(); |
168 |
> |
timer.Stop(); |
169 |
> |
if(verbose) timer.Print(); |
170 |
|
|
171 |
< |
return this->GetEntries(); |
171 |
> |
return this->GetEntries(); |
172 |
|
|
173 |
|
} |
174 |
|
//------------------------------------------------------------------ |
180 |
|
return -1; |
181 |
|
|
182 |
|
TStopwatch timer; |
183 |
< |
timer.Start(); |
183 |
> |
if(verbose) { |
184 |
> |
cout<<"Plot: "<<histName<<" "<<cutName<<" from chain "<<this->At(chainIndex)->GetName()<<endl; |
185 |
> |
timer.Start(); |
186 |
> |
} |
187 |
|
|
188 |
|
int currN = nEntries; |
189 |
|
if (nEntries < 0) |
244 |
|
|
245 |
|
|
246 |
|
//Draw histogram: |
247 |
< |
int draw_err = ((TChain*) this->At(chainIndex))->Draw(histName.c_str(), cutName.c_str(), |
247 |
> |
string cutNameWithGlobal = cutName; |
248 |
> |
if(cutName!="" && globalCuts!="") cutNameWithGlobal += "&&"; |
249 |
> |
if(globalCuts!="") cutNameWithGlobal += globalCuts; |
250 |
> |
|
251 |
> |
int draw_err = ((TChain*) this->At(chainIndex))->Draw(histName.c_str(), cutNameWithGlobal.c_str(), |
252 |
|
currOpt.c_str(), currN); |
253 |
|
if (draw_err < 0) |
254 |
|
return draw_err; |
275 |
|
setCanvas( pads_[currPadName.str()] ); |
276 |
|
} |
277 |
|
|
278 |
< |
timer.Stop(); |
279 |
< |
if(verbose) { |
280 |
< |
cout<<"Done: "<<currN<<" events in "<<histName<<" "<<cutName<<" from chain "<<this->At(chainIndex)->GetName()<<endl; |
278 |
> |
|
279 |
> |
if(verbose && draw_err > 0) { |
280 |
> |
timer.Stop(); |
281 |
> |
cout<<"Done: Selected "<<draw_err<<" objects in "<< currN <<" processed events."<<endl; |
282 |
|
timer.Print(); |
283 |
|
} |
284 |
|
return draw_err; |
362 |
|
int PlotTool::updatePads() { |
363 |
|
|
364 |
|
for (map< string, TCanvas* >::iterator it=pads_.begin() ; it != pads_.end(); ++it) { |
365 |
< |
if (gROOT->GetListOfCanvases()->FindObject((*it).first.c_str() ) ) { |
366 |
< |
(*it).second->Draw(); |
367 |
< |
setCanvas((*it).second); |
368 |
< |
} else |
369 |
< |
pads_.erase(it); |
365 |
> |
if ( ! gROOT->GetListOfCanvases()->FindObject((*it).first.c_str() ) ) { |
366 |
> |
pads_.erase(it); |
367 |
> |
continue; |
368 |
> |
} |
369 |
> |
if( (*it).second->GetListOfPrimitives()->GetEntries() == 0 ) { |
370 |
> |
(*it).second->Close(); |
371 |
> |
pads_.erase(it); |
372 |
> |
continue; |
373 |
> |
} |
374 |
> |
(*it).second->Draw(); |
375 |
> |
setCanvas((*it).second); |
376 |
> |
|
377 |
|
} |
378 |
|
|
379 |
|
return pads_.size(); |
518 |
|
string x = thisHist->GetXaxis()->GetTitle(); |
519 |
|
string y = thisHist->GetYaxis()->GetTitle(); |
520 |
|
|
521 |
< |
if (t.find(".phi()") != string::npos) |
522 |
< |
t.replace(t.find(".phi()"), 6, " #phi"); |
521 |
> |
// if (x.find("__") != string::npos) |
522 |
> |
// x = x.substr(0,x.find("__")); |
523 |
> |
// if (y.find("__") != string::npos) |
524 |
> |
// y = y.substr(0,y.find("__")); |
525 |
> |
|
526 |
|
if (x.find(".phi()") != string::npos) |
527 |
|
x.replace(x.find(".phi()"), 6, " #phi"); |
528 |
|
if (y.find(".phi()") != string::npos) |
529 |
|
y.replace(y.find(".phi()"), 6, " #phi"); |
530 |
|
|
530 |
– |
if (t.find(".eta()") != string::npos) |
531 |
– |
t.replace(t.find(".eta()"), 6, " #eta"); |
531 |
|
if (x.find(".eta()") != string::npos) |
532 |
|
x.replace(x.find(".eta()"), 6, " #eta"); |
533 |
|
if (y.find(".eta()") != string::npos) |
534 |
|
y.replace(y.find(".eta()"), 6, " #eta"); |
535 |
|
|
536 |
< |
if (t.find(".pt()") != string::npos) |
537 |
< |
t.replace(t.find(".pt()"), 5, " p_{T}"); |
536 |
> |
if (x.find(".theta()") != string::npos) |
537 |
> |
x.replace(x.find(".theta()"), 6, " #theta"); |
538 |
> |
if (y.find(".theta()") != string::npos) |
539 |
> |
y.replace(y.find(".theta()"), 6, " #theta"); |
540 |
> |
|
541 |
> |
if (x.find(".chi2()") != string::npos) |
542 |
> |
x.replace(x.find(".chi2()"), 7, " #chi^{2}"); |
543 |
> |
if (y.find(".chi2()") != string::npos) |
544 |
> |
y.replace(y.find(".chi2()"), 7, " #chi^{2}"); |
545 |
> |
|
546 |
|
if (x.find(".pt()") != string::npos) |
547 |
< |
x.replace(x.find(".pt()"), 5, " p_{T}"); |
547 |
> |
x.replace(x.find(".pt()"), 5, " p_{T} [GeV]"); |
548 |
|
if (y.find(".pt()") != string::npos) |
549 |
< |
y.replace(y.find(".pt()"), 5, " p_{T}"); |
549 |
> |
y.replace(y.find(".pt()"), 5, " p_{T} [GeV]"); |
550 |
> |
|
551 |
> |
if (x.find(".et()") != string::npos) |
552 |
> |
x.replace(x.find(".et()"), 5, " E_{T} [GeV]"); |
553 |
> |
if (y.find(".et()") != string::npos) |
554 |
> |
y.replace(y.find(".et()"), 5, " E_{T} [GeV]"); |
555 |
> |
|
556 |
> |
//splitlines for many cuts |
557 |
> |
string test1= "{" + globalCuts + "}"; |
558 |
> |
string test2= "&&" + globalCuts; |
559 |
> |
|
560 |
> |
if(t.find(test1) != string::npos) t.replace(t.find(test1),test1.length(),""); |
561 |
> |
if(t.find(test2) != string::npos) t.replace(t.find(test2),test2.length(),""); |
562 |
> |
|
563 |
> |
if (t.find("{") != string::npos && t.find("#splitline") == string::npos) { |
564 |
> |
t.replace(t.find_last_of("{"), 1, "}{"); |
565 |
> |
string t_old = t; |
566 |
> |
t = "#splitline{"; |
567 |
> |
t += t_old; |
568 |
> |
} |
569 |
|
|
570 |
|
thisHist ->SetTitle(t.c_str()); |
571 |
|
thisHist->GetXaxis()->SetTitle(x.c_str()); |
700 |
|
|
701 |
|
int savedCanvs =0; |
702 |
|
|
677 |
– |
TPostScript ps(namePs.c_str(),112); |
678 |
– |
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(); |
686 |
< |
(*canv).Write(); |
687 |
< |
++savedCanvs; |
707 |
> |
string modName = (*canv).GetName(); |
708 |
> |
if(modName.find("{") != string::npos) modName = modName.substr(0,modName.find("{")); |
709 |
> |
(*canv).SetTitle( modName.c_str() ); |
710 |
|
|
711 |
|
} |
712 |
|
|
691 |
– |
ps.Close(); |
692 |
– |
rt.Close(); |
713 |
|
|
714 |
< |
return savedCanvs; |
715 |
< |
|
696 |
< |
} |
697 |
< |
//------------------------------------------------------------------ |
698 |
< |
void PlotTool::showChainInfo() |
699 |
< |
{ |
714 |
> |
TPostScript ps(namePs.c_str(),112); |
715 |
> |
TFile rt(nameRt.c_str(),"recreate"); |
716 |
|
|
717 |
+ |
next.Reset(); |
718 |
+ |
while ((canv=(TCanvas*)next())) { |
719 |
+ |
ps.NewPage(); |
720 |
|
|
702 |
– |
cout<<endl; |
703 |
– |
cout<<"****** Show Chain Information:"<<endl; |
721 |
|
|
722 |
+ |
(*canv).Write(); |
723 |
+ |
(*canv).Draw(); |
724 |
+ |
(*canv).Update(); |
725 |
|
|
706 |
– |
this->ls(); |
726 |
|
|
727 |
< |
cout<<endl; |
709 |
< |
cout<<"We have "<<this->GetEntries()<<" TChains with following aliases set:"<<endl; |
710 |
< |
for (int i=0; i< this->GetEntries(); ++i) { |
711 |
< |
cout<<endl; |
712 |
< |
cout<<((TChain*) this->At(i))->GetName()<<endl; |
713 |
< |
((TChain*) this->At(i))->GetListOfAliases()->ls(); |
727 |
> |
++savedCanvs; |
728 |
|
|
729 |
|
} |
730 |
|
|
731 |
+ |
ps.Close(); |
732 |
+ |
rt.Close(); |
733 |
|
|
734 |
|
|
735 |
+ |
if(verbose && savedCanvs) { |
736 |
+ |
cout<<"Saved file "<<rt.GetName()<<" with "<<savedCanvs<<" canvases."<<endl; |
737 |
+ |
cout<<"Saved file "<<ps.GetName()<<" with "<<savedCanvs<<" pages."<<endl; |
738 |
|
} |
739 |
< |
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
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; |
739 |
> |
return savedCanvs; |
740 |
|
|
741 |
+ |
} |
742 |
+ |
//------------------------------------------------------------------ |
743 |
|
|
744 |
< |
TFile file("ABCDFunctions.root","UPDATE"); |
745 |
< |
TF1* savefunc = new TF1(savefuncName.str().c_str(), fitfunc->GetExpFormula().Data(),0,10000); |
844 |
< |
savefunc->SetParameters( fitfunc->GetParameters() ); |
845 |
< |
savefunc->SetParErrors ( fitfunc->GetParErrors() ); |
744 |
> |
int PlotTool::clearCanvases() |
745 |
> |
{ |
746 |
|
|
747 |
< |
//Show results |
748 |
< |
if( ! pads_["abcd"] || ! gROOT->FindObject("abcd") ) { |
749 |
< |
pads_["abcd"] = new TCanvas("abcd", "abcd"); |
750 |
< |
} else { |
851 |
< |
pads_["abcd"]->cd(); |
852 |
< |
} |
747 |
> |
while(gROOT->GetListOfCanvases()->GetEntries()) ((TCanvas*) gROOT->GetListOfCanvases()->At(0))->Close(); |
748 |
> |
pads_.clear(); |
749 |
> |
autoVars.clear(); |
750 |
> |
return pads_.size() + gROOT->GetListOfCanvases()->GetEntries(); |
751 |
|
|
752 |
< |
bkg->Multiply(savefunc); |
753 |
< |
bkg->Draw(); |
752 |
> |
} |
753 |
> |
//------------------------------------------------------------------ |
754 |
> |
int PlotTool::setVariables(string label) |
755 |
> |
{ |
756 |
|
|
757 |
< |
// total->Add(bkg,-1); |
758 |
< |
pass->SetLineColor(kRed); |
759 |
< |
pass->Draw("sames,e"); |
760 |
< |
pads_["abcd"]->SetLogy(); |
757 |
> |
for (int i=0; i< this->GetEntries(); ++i) { |
758 |
> |
cout<<"--------------------------------"<<endl; |
759 |
> |
cout<<((TChain*) this->At(i))->GetName()<<endl; |
760 |
> |
cout<<"------------"<<endl; |
761 |
|
|
762 |
+ |
TList* leaves = (TList*) ((TChain*) this->At(i))->GetListOfLeaves(); |
763 |
+ |
for (int j=0; j< leaves->GetEntries(); ++j) { |
764 |
+ |
TString leafName ( leaves->At(j)->GetName() ); |
765 |
+ |
if(! leafName.EndsWith(".") ) continue; |
766 |
+ |
if(! leafName.Contains(label.c_str() ) ) continue; |
767 |
+ |
|
768 |
+ |
TClass cl( ( (TLeafElement*) leaves->At(j) )->GetTypeName() ); |
769 |
+ |
cout<<"++++++"<<endl; |
770 |
+ |
cout<< leafName.Data() <<endl; |
771 |
+ |
for(int k=0;k<cl.GetListOfAllPublicMethods()->GetEntries();++k) { |
772 |
+ |
string typeName ( ((TMethod*) cl.GetListOfAllPublicMethods()->At(k))->GetReturnTypeName() ); |
773 |
+ |
string methName ( cl.GetListOfAllPublicMethods()->At(k)->GetName() ); |
774 |
+ |
if( methName != "product") continue; |
775 |
+ |
cout<< typeName <<endl; |
776 |
+ |
string _type; |
777 |
+ |
TString testString( typeName.c_str() ); |
778 |
+ |
if( testString.BeginsWith("vector<") ) { |
779 |
+ |
_type = typeName.substr(typeName.find("<")+1,typeName.find(">")-typeName.find("<")-1); |
780 |
+ |
string _varSize = leafName.Data(); |
781 |
+ |
_varSize += "obj@.size()"; |
782 |
+ |
autoVars.push_back( _varSize ); |
783 |
+ |
} |
784 |
+ |
else _type = typeName.substr(0,typeName.find("*")); |
785 |
+ |
TClass _cl( _type.c_str() ); |
786 |
+ |
for(int l=0;l<_cl.GetListOfAllPublicMethods()->GetEntries();++l) { |
787 |
+ |
string _typeName ( ((TMethod*) _cl.GetListOfAllPublicMethods()->At(l))->GetReturnTypeName() ); |
788 |
+ |
string _methName ( _cl.GetListOfAllPublicMethods()->At(l)->GetName() ); |
789 |
+ |
// if(_typeName.find("void") != string::npos ) continue; |
790 |
+ |
// cout<<" "<<_typeName<<" "<<_methName<<endl; |
791 |
+ |
|
792 |
+ |
cout<<" "<<_typeName<<" "<<_methName<<endl; |
793 |
+ |
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")) { |
794 |
+ |
|
795 |
+ |
cout<<"--> "<<_typeName<<" "<<_methName<<endl; |
796 |
+ |
|
797 |
+ |
string _varName = leafName.Data(); |
798 |
+ |
_varName += "obj."; |
799 |
+ |
_varName += _methName; |
800 |
+ |
_varName += "()"; |
801 |
+ |
autoVars.push_back( _varName ); |
802 |
+ |
} |
803 |
+ |
} |
804 |
+ |
|
805 |
+ |
|
806 |
+ |
} |
807 |
|
|
808 |
< |
savefunc->Write(); |
864 |
< |
// file.Close(); |
808 |
> |
} |
809 |
|
|
810 |
+ |
} |
811 |
|
|
812 |
< |
return draw_err; |
812 |
> |
return autoVars.size(); |
813 |
|
|
814 |
|
} |
815 |
+ |
|
816 |
|
//------------------------------------------------------------------ |