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 |
+ |
normHists = false; //scale all histos intergrals to 1 |
25 |
+ |
|
26 |
|
} |
27 |
|
|
28 |
|
//------------------------------------------------------------------ |
29 |
|
//Fill object PlotTool with Chains constructed from files from given source |
30 |
|
|
31 |
|
int PlotTool::init(string fileName, string dirPath, string treeName, |
32 |
< |
string fileLabel) { |
33 |
< |
this->New(this->GetEntries() ); |
34 |
< |
int currChain = this->GetEntries() - 1; |
32 |
> |
string fileLabel) { |
33 |
> |
this->New(this->GetEntries() ); |
34 |
> |
int currChain = this->GetEntries() - 1; |
35 |
|
|
36 |
< |
if (currChain < 0) |
37 |
< |
return currChain; |
36 |
> |
if (currChain < 0) |
37 |
> |
return currChain; |
38 |
|
|
39 |
< |
TStopwatch timer; |
40 |
< |
timer.Start(); |
39 |
> |
TStopwatch timer; |
40 |
> |
timer.Start(); |
41 |
|
|
42 |
|
|
43 |
< |
fileNames.clear(); |
43 |
> |
fileNames.clear(); |
44 |
|
|
45 |
< |
//check if alternative label is different from default(searchString) |
46 |
< |
if (fileLabel=="") { |
47 |
< |
fileLabel=fileName; |
48 |
< |
} |
49 |
< |
((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; |
45 |
> |
//check if alternative label is different from default(searchString) |
46 |
> |
if (fileLabel=="") { |
47 |
> |
fileLabel=fileName; |
48 |
> |
} |
49 |
> |
((TChain*) this->At(currChain))->SetName(fileLabel.c_str()); |
50 |
|
|
51 |
< |
filePath = dirPath; |
52 |
< |
filePath += fname.Data(); |
53 |
< |
//fwlite::ChainEvent to lop over events, jets, etc |
54 |
< |
fileNames.push_back(filePath.c_str()); |
55 |
< |
|
56 |
< |
if (((TChain*) this->At(currChain))->AddFile(filePath.c_str(), -1, |
57 |
< |
treeName.c_str()) ) |
58 |
< |
if(verbose) cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl; |
59 |
< |
else |
60 |
< |
return -1; |
51 |
> |
TList *files = new TList(); |
52 |
> |
TSystemFile* sysFile = 0; |
53 |
> |
if(fileName.find(".") != string::npos) { |
54 |
> |
ifstream f(fileName.c_str()); |
55 |
> |
if( ! f.is_open() ) return -1; |
56 |
> |
string line; |
57 |
> |
|
58 |
> |
while (!f.eof()) { |
59 |
> |
getline(f,line); |
60 |
> |
sysFile = new TSystemFile(line.c_str(),dirPath.c_str()); |
61 |
> |
files->Add(sysFile); |
62 |
> |
} |
63 |
|
|
73 |
– |
} |
74 |
– |
} else |
75 |
– |
return -1; |
64 |
|
|
65 |
< |
for (int i=0; i<((TChain*) this->At(currChain))->GetListOfBranches()->GetEntries(); ++i) { |
66 |
< |
|
67 |
< |
string s(((TChain*) this->At(currChain))->GetListOfBranches()->At(i)->GetName()); |
65 |
> |
} else { |
66 |
> |
TSystemDirectory dir("sourceDir", dirPath.c_str()); |
67 |
> |
files = dir.GetListOfFiles(); |
68 |
> |
} |
69 |
> |
if (files->GetEntries()>0) { |
70 |
> |
TIter next(files); |
71 |
> |
TSystemFile *file; |
72 |
> |
TString fname; |
73 |
> |
string filePath; |
74 |
> |
|
75 |
> |
if(verbose && fileName.find(".") == string::npos ) cout<<"Open"<<dirPath.c_str()<<" Search for .root files that contain: " |
76 |
> |
<<fileName.c_str()<<endl; |
77 |
> |
if(verbose && fileName.find(".") != string::npos ) cout<<"Open"<<dirPath.c_str()<<" Search lines with .root in: " |
78 |
> |
<<fileName.c_str()<<endl; |
79 |
> |
|
80 |
> |
|
81 |
> |
while ((file=(TSystemFile*)next())) { |
82 |
> |
fname = file->GetName(); |
83 |
> |
if (!fname.EndsWith(".root")) |
84 |
> |
continue; |
85 |
> |
if (!fname.Contains(fileName.c_str()) && fileName.find(".") == string::npos ) |
86 |
> |
continue; |
87 |
> |
|
88 |
> |
filePath = dirPath; |
89 |
> |
filePath += fname.Data(); |
90 |
> |
//fwlite::ChainEvent to lop over events, jets, etc |
91 |
> |
fileNames.push_back(filePath.c_str()); |
92 |
> |
|
93 |
> |
if (((TChain*) this->At(currChain))->AddFile(filePath.c_str(), -1, |
94 |
> |
treeName.c_str()) ) { |
95 |
> |
if(verbose) cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl; |
96 |
> |
} else { |
97 |
> |
return -1; |
98 |
> |
} |
99 |
> |
|
100 |
> |
} |
101 |
> |
} else |
102 |
> |
return -1; |
103 |
> |
|
104 |
> |
for (int i=0; i<((TChain*) this->At(currChain))->GetListOfBranches()->GetEntries(); ++i) { |
105 |
> |
|
106 |
> |
string s(((TChain*) this->At(currChain))->GetListOfBranches()->At(i)->GetName()); |
107 |
> |
|
108 |
> |
string branch_alias = s; |
109 |
> |
string branch_name = s; |
110 |
> |
if (s.find(".", s.size()-1) != string::npos) |
111 |
> |
branch_name += "obj"; |
112 |
> |
|
113 |
> |
size_t a = s.find("_"); |
114 |
> |
if (a != string::npos) { |
115 |
> |
size_t b = s.find("_", a+1); |
116 |
> |
if (b != string::npos) { |
117 |
> |
size_t c = s.find("_", b+1); |
118 |
> |
if (c != string::npos) { |
119 |
> |
string _prod =s.substr(0,a); |
120 |
> |
string _label =s.substr(a+1, b-a-1); |
121 |
> |
string _instance =s.substr(b+1, c-b-1); |
122 |
> |
branch_alias = _label; |
123 |
> |
if(_instance.length() > 0 ) { |
124 |
> |
branch_alias += "_"; |
125 |
> |
branch_alias += _instance; |
126 |
> |
((TChain*) this->At(currChain))->SetAlias(_instance.c_str(), |
127 |
> |
branch_name.c_str()); |
128 |
> |
} |
129 |
> |
string branch_alias_full = _prod + "_" + branch_alias; |
130 |
> |
((TChain*) this->At(currChain))->SetAlias(branch_alias_full.c_str(), |
131 |
> |
branch_name.c_str()); |
132 |
> |
} |
133 |
> |
} |
134 |
> |
} |
135 |
|
|
136 |
< |
string branch_alias = s; |
137 |
< |
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 |
< |
} |
136 |
> |
((TChain*) this->At(currChain))->SetAlias(branch_alias.c_str(), |
137 |
> |
branch_name.c_str()); |
138 |
|
|
139 |
< |
((TChain*) this->At(currChain))->SetAlias(branch_alias.c_str(), |
110 |
< |
branch_name.c_str()); |
139 |
> |
} |
140 |
|
|
112 |
– |
} |
141 |
|
|
114 |
– |
// add branch with track Jets |
142 |
|
|
143 |
< |
if( addTrackJets ) { |
143 |
> |
|
144 |
> |
|
145 |
> |
string friendTreeName("friendTree"); |
146 |
|
|
147 |
< |
//make file for tree friends (adding additional, computed branches) |
148 |
< |
string friendFileName("/scratch/hh/current/cms/user/"); |
149 |
< |
friendFileName += gSystem->GetUserInfo()->fUser; |
150 |
< |
friendFileName += "/temp/", |
151 |
< |
friendFileName += fileName; |
152 |
< |
friendFileName += ".root"; |
153 |
< |
TFile *f = new TFile(friendFileName.c_str(),"recreate"); |
154 |
< |
|
155 |
< |
if( f->IsZombie() ) return -1; |
156 |
< |
|
157 |
< |
string friendTreeName("friendTree"); |
158 |
< |
//char number = currChain; |
159 |
< |
//friendTreeName += number; |
160 |
< |
//TTree *friendTree = new TTree("friendTree","friendTree"); |
161 |
< |
TTree *friendTree = new TTree(friendTreeName.c_str(),friendTreeName.c_str()); |
162 |
< |
|
163 |
< |
int nJetsKT; |
164 |
< |
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(); |
147 |
> |
string friendFileName("/scratch/hh/current/cms/user/"); |
148 |
> |
friendFileName += gSystem->GetUserInfo()->fUser; |
149 |
> |
friendFileName += "/temp/"; |
150 |
> |
friendFileName += fileLabel; |
151 |
> |
friendFileName += ".root"; |
152 |
> |
string fileOpt = "update"; |
153 |
> |
if( recreateTree ) fileOpt = "recreate"; |
154 |
> |
|
155 |
> |
FWliteVariables fwVars(friendTreeName, friendFileName, fileOpt); |
156 |
> |
|
157 |
> |
if(varBlockNames.length() > 1 ) { |
158 |
> |
fwVars.loop(fileNames, varBlockNames); |
159 |
> |
if(verbose) cout<<"add friend tree with additional variables: "<<varBlockNames<<endl; |
160 |
> |
((TChain*) this->At(currChain))->AddFriend(friendTreeName.c_str(), |
161 |
> |
friendFileName.c_str()); |
162 |
> |
} else { |
163 |
> |
if(verbose) cout<<"No additional variables added."<<endl; |
164 |
> |
} |
165 |
|
|
166 |
< |
if( eventNum != 0 && eventNum%tenth == 0) cout<<"Processed "<<eventNum <<" of "<<ev.size()<<" events. "<<endl; |
166 |
> |
|
167 |
> |
|
168 |
|
|
177 |
– |
} |
178 |
– |
f->cd(); |
179 |
– |
friendTree->Write(); |
180 |
– |
f->Close(); |
181 |
– |
((TChain*) this->At(currChain))->AddFriend(friendTreeName.c_str(), |
182 |
– |
friendFileName.c_str()); |
183 |
– |
} |
169 |
|
|
170 |
< |
timer.Stop(); |
171 |
< |
if(verbose) timer.Print(); |
170 |
> |
timer.Stop(); |
171 |
> |
if(verbose) timer.Print(); |
172 |
|
|
173 |
< |
return this->GetEntries(); |
173 |
> |
return this->GetEntries(); |
174 |
|
|
175 |
|
} |
176 |
|
//------------------------------------------------------------------ |
177 |
|
//Draw given Chain with given variable and given cuts |
178 |
< |
int PlotTool::plot(int chainIndex, string histName, string cutName, |
179 |
< |
int nEntries, string drwOpt) { |
178 |
> |
TH1* PlotTool::plot(int chainIndex, string histName, string cutName, |
179 |
> |
int nEntries, string bins, string drwOpt) { |
180 |
> |
|
181 |
> |
TH1* thisHist = 0; |
182 |
|
|
183 |
|
if (chainIndex >= this->GetEntries() ) |
184 |
< |
return -1; |
184 |
> |
return thisHist; |
185 |
|
|
186 |
|
TStopwatch timer; |
187 |
< |
timer.Start(); |
187 |
> |
if(verbose) { |
188 |
> |
cout<<"Plot: "<<histName<<" "<<cutName<<" from chain "<<this->At(chainIndex)->GetName()<<endl; |
189 |
> |
timer.Start(); |
190 |
> |
} |
191 |
|
|
192 |
|
int currN = nEntries; |
193 |
|
if (nEntries < 0) |
248 |
|
|
249 |
|
|
250 |
|
//Draw histogram: |
251 |
< |
int draw_err = ((TChain*) this->At(chainIndex))->Draw(histName.c_str(), cutName.c_str(), |
251 |
> |
string cutNameWithGlobal = ""; |
252 |
> |
if(cutName!="" && globalCuts!="") cutNameWithGlobal += "("; |
253 |
> |
if(cutName!="") cutNameWithGlobal += cutName; |
254 |
> |
if(cutName!="" && globalCuts!="") cutNameWithGlobal += ")"; |
255 |
> |
if(cutName!="" && globalCuts!="") cutNameWithGlobal += "&&"; |
256 |
> |
if(cutName!="" && globalCuts!="") cutNameWithGlobal += "("; |
257 |
> |
if(globalCuts!="") cutNameWithGlobal += globalCuts; |
258 |
> |
if(cutName!="" && globalCuts!="") cutNameWithGlobal += ")"; |
259 |
> |
|
260 |
> |
histName += ">>htemp"; |
261 |
> |
if(bins != "") histName += bins; |
262 |
> |
|
263 |
> |
|
264 |
> |
|
265 |
> |
|
266 |
> |
int draw_err = ((TChain*) this->At(chainIndex))->Draw(histName.c_str(), cutNameWithGlobal.c_str(), |
267 |
|
currOpt.c_str(), currN); |
268 |
|
if (draw_err < 0) |
269 |
< |
return draw_err; |
269 |
> |
return thisHist; |
270 |
|
|
271 |
|
//++++ Fix for histos with no entries +++++++++++++ |
272 |
|
if (draw_err == 0) { |
276 |
|
if (useSubPads) |
277 |
|
canvases_[currCanvName.str()]->SetNumber(canvases_[currCanvName.str()]->GetNumber()-1); |
278 |
|
} |
279 |
< |
cout<< "Warning: "<<currHistName.str().c_str()<<" in "<<currPadName.str() |
279 |
> |
if(verbose) cout<< "Warning: "<<currHistName.str().c_str()<<" in "<<currPadName.str() |
280 |
|
<<" has no entries and is not drawn!"<<endl; |
281 |
< |
return draw_err; |
281 |
> |
return thisHist; |
282 |
|
} |
283 |
|
//++++++++++++++++++++++++++++++++++++++++++++++++++ |
284 |
|
|
285 |
< |
((TH1F*) pads_[currPadName.str()]->GetPrimitive("htemp"))->SetName(currHistName.str().c_str()); // Set Name of histogram |
285 |
> |
thisHist = (TH1*) pads_[currPadName.str()]->GetPrimitive("htemp"); |
286 |
> |
|
287 |
> |
thisHist->SetName(currHistName.str().c_str()); |
288 |
|
|
289 |
|
// Update for 2D histograms |
290 |
< |
if( pads_[currPadName.str()]->GetPrimitive(currHistName.str().c_str())->InheritsFrom("TH2") ) { |
290 |
> |
if( thisHist->InheritsFrom("TH2") ) { |
291 |
|
pads_[currPadName.str()]->Draw(); |
292 |
|
setCanvas( pads_[currPadName.str()] ); |
293 |
|
} |
294 |
|
|
295 |
< |
timer.Stop(); |
296 |
< |
if(verbose) { |
297 |
< |
cout<<"Done: "<<currN<<" events in "<<histName<<" "<<cutName<<" from chain "<<this->At(chainIndex)->GetName()<<endl; |
295 |
> |
|
296 |
> |
if(verbose && draw_err > 0) { |
297 |
> |
timer.Stop(); |
298 |
> |
cout<<"Done: Selected "<<draw_err<<" objects in "<< currN <<" processed events."<<endl; |
299 |
|
timer.Print(); |
300 |
|
} |
301 |
< |
return draw_err; |
301 |
> |
return thisHist; |
302 |
|
|
303 |
|
} |
304 |
|
//------------------------------------------------------------------ |
305 |
|
//Standard loop to draw all chains and multiple variables and cuts |
306 |
|
int PlotTool::loop(vector<string> _histName, vector<string> _cutName, |
307 |
< |
int nEntries, string drwOpt, bool correspond) { |
307 |
> |
int nEntries, string bins, string drwOpt, bool correspond) { |
308 |
|
|
309 |
|
int numProcessed = 0; |
310 |
|
|
311 |
+ |
TH1* currHist = 0; |
312 |
+ |
|
313 |
+ |
|
314 |
|
if (correspond == false) { |
315 |
|
|
316 |
|
for (int i=0; i<this->GetEntries(); ++i) { |
319 |
|
for (vector<string>::iterator it2 =_cutName.begin(); it2 |
320 |
|
!= _cutName.end(); ++it2) { |
321 |
|
|
322 |
< |
numProcessed += plot(i, *it1, *it2, nEntries, drwOpt); |
322 |
> |
currHist = plot(i, *it1, *it2, nEntries, bins, drwOpt); |
323 |
> |
if(currHist) numProcessed += int(currHist->GetEntries()); |
324 |
|
|
325 |
|
|
326 |
|
} |
336 |
|
_cutName.begin(); it1 != _cutName.end()&&it2 |
337 |
|
!= _cutName.end(); ++it1, ++it2) { |
338 |
|
|
339 |
< |
numProcessed += plot(i, *it1, *it2, nEntries, drwOpt); |
339 |
> |
currHist = plot(i, *it1, *it2, nEntries, bins, drwOpt); |
340 |
> |
if(currHist) numProcessed += int(currHist->GetEntries()); |
341 |
|
|
342 |
|
} |
343 |
|
} |
350 |
|
} |
351 |
|
|
352 |
|
//Helper methods to allow for using simple strings as input |
353 |
< |
int PlotTool::loop(string histName, string cutName, int nEntries, string drwOpt) { |
353 |
> |
int PlotTool::loop(string histName, string cutName, int nEntries, string bins, string drwOpt) { |
354 |
|
|
355 |
|
vector<string> _histName; |
356 |
|
_histName.push_back(histName); |
357 |
|
vector<string> _cutName; |
358 |
|
_cutName.push_back(cutName); |
359 |
|
|
360 |
< |
return loop(_histName, _cutName, nEntries, drwOpt); |
360 |
> |
return loop(_histName, _cutName, nEntries, bins, drwOpt); |
361 |
|
|
362 |
|
} |
363 |
|
|
364 |
< |
int PlotTool::loop(vector<string> _histName, string cutName, int nEntries, |
364 |
> |
int PlotTool::loop(vector<string> _histName, string cutName, int nEntries, string bins, |
365 |
|
string drwOpt) { |
366 |
|
|
367 |
|
vector<string> _cutName; |
368 |
|
_cutName.push_back(cutName); |
369 |
|
|
370 |
< |
return loop(_histName, _cutName, nEntries, drwOpt); |
370 |
> |
return loop(_histName, _cutName, nEntries, bins, drwOpt); |
371 |
|
|
372 |
|
} |
373 |
|
|
374 |
< |
int PlotTool::loop(string histName, vector<string> _cutName, int nEntries, |
374 |
> |
int PlotTool::loop(string histName, vector<string> _cutName, int nEntries, string bins, |
375 |
|
string drwOpt) { |
376 |
|
|
377 |
|
vector<string> _histName; |
378 |
|
_histName.push_back(histName); |
379 |
|
|
380 |
< |
return loop(_histName, _cutName, nEntries, drwOpt); |
380 |
> |
return loop(_histName, _cutName, nEntries, bins, drwOpt); |
381 |
|
} |
382 |
|
//------------------------------------------------------------------ |
383 |
|
//redraw the canvas to make changes in style visible |
384 |
|
int PlotTool::updatePads() { |
385 |
|
|
386 |
|
for (map< string, TCanvas* >::iterator it=pads_.begin() ; it != pads_.end(); ++it) { |
387 |
< |
if (gROOT->GetListOfCanvases()->FindObject((*it).first.c_str() ) ) { |
388 |
< |
(*it).second->Draw(); |
389 |
< |
setCanvas((*it).second); |
390 |
< |
} else |
391 |
< |
pads_.erase(it); |
387 |
> |
if ( ! gROOT->GetListOfCanvases()->FindObject((*it).first.c_str() ) ) { |
388 |
> |
pads_.erase(it); |
389 |
> |
continue; |
390 |
> |
} |
391 |
> |
if( (*it).second->GetListOfPrimitives()->GetEntries() == 0 ) { |
392 |
> |
(*it).second->Close(); |
393 |
> |
pads_.erase(it); |
394 |
> |
continue; |
395 |
> |
} |
396 |
> |
(*it).second->Draw(); |
397 |
> |
setCanvas((*it).second); |
398 |
> |
|
399 |
|
} |
400 |
|
|
401 |
|
return pads_.size(); |
458 |
|
//------------------------------------------------------------------ |
459 |
|
void PlotTool::setCanvas(TCanvas* thisCanvas) { |
460 |
|
|
461 |
+ |
|
462 |
|
TH1* thisHist = 0; |
463 |
|
TPaveStats* thisStatsBox = 0; |
464 |
|
TPaletteAxis* palette =0; |
484 |
|
|
485 |
|
for (int i = 0; i != thisCanvas->GetListOfPrimitives()->GetSize(); ++i) { |
486 |
|
|
487 |
+ |
|
488 |
+ |
|
489 |
|
if ( !thisCanvas->GetListOfPrimitives()->At(i)->InheritsFrom("TH1")) |
490 |
|
continue; |
491 |
|
|
492 |
+ |
|
493 |
|
thisHist = ((TH1*) thisCanvas->GetListOfPrimitives()->At(i)); |
494 |
+ |
|
495 |
+ |
TString testString( thisHist->GetName() ); |
496 |
+ |
if( testString.BeginsWith("frame_") ) continue; |
497 |
+ |
|
498 |
|
setColor(thisHist, counter); |
499 |
|
setMathLabels(thisHist); |
500 |
|
|
501 |
+ |
if(normHists) thisHist->Scale(1/thisHist->GetSumOfWeights()); |
502 |
+ |
|
503 |
|
if (thisHist->GetMaximum() > maxEntry) |
504 |
|
maxEntry = thisHist->GetMaximum(); |
505 |
|
|
550 |
|
string x = thisHist->GetXaxis()->GetTitle(); |
551 |
|
string y = thisHist->GetYaxis()->GetTitle(); |
552 |
|
|
553 |
< |
if (t.find(".phi()") != string::npos) |
554 |
< |
t.replace(t.find(".phi()"), 6, " #phi"); |
553 |
> |
// if (x.find("__") != string::npos) |
554 |
> |
// x = x.substr(0,x.find("__")); |
555 |
> |
// if (y.find("__") != string::npos) |
556 |
> |
// y = y.substr(0,y.find("__")); |
557 |
> |
|
558 |
|
if (x.find(".phi()") != string::npos) |
559 |
|
x.replace(x.find(".phi()"), 6, " #phi"); |
560 |
|
if (y.find(".phi()") != string::npos) |
561 |
|
y.replace(y.find(".phi()"), 6, " #phi"); |
562 |
|
|
530 |
– |
if (t.find(".eta()") != string::npos) |
531 |
– |
t.replace(t.find(".eta()"), 6, " #eta"); |
563 |
|
if (x.find(".eta()") != string::npos) |
564 |
|
x.replace(x.find(".eta()"), 6, " #eta"); |
565 |
|
if (y.find(".eta()") != string::npos) |
566 |
|
y.replace(y.find(".eta()"), 6, " #eta"); |
567 |
|
|
568 |
< |
if (t.find(".pt()") != string::npos) |
569 |
< |
t.replace(t.find(".pt()"), 5, " p_{T}"); |
568 |
> |
if (x.find(".theta()") != string::npos) |
569 |
> |
x.replace(x.find(".theta()"), 6, " #theta"); |
570 |
> |
if (y.find(".theta()") != string::npos) |
571 |
> |
y.replace(y.find(".theta()"), 6, " #theta"); |
572 |
> |
|
573 |
> |
if (x.find(".chi2()") != string::npos) |
574 |
> |
x.replace(x.find(".chi2()"), 7, " #chi^{2}"); |
575 |
> |
if (y.find(".chi2()") != string::npos) |
576 |
> |
y.replace(y.find(".chi2()"), 7, " #chi^{2}"); |
577 |
> |
|
578 |
|
if (x.find(".pt()") != string::npos) |
579 |
< |
x.replace(x.find(".pt()"), 5, " p_{T}"); |
579 |
> |
x.replace(x.find(".pt()"), 5, " p_{T} [GeV]"); |
580 |
|
if (y.find(".pt()") != string::npos) |
581 |
< |
y.replace(y.find(".pt()"), 5, " p_{T}"); |
581 |
> |
y.replace(y.find(".pt()"), 5, " p_{T} [GeV]"); |
582 |
> |
|
583 |
> |
if (x.find(".et()") != string::npos) |
584 |
> |
x.replace(x.find(".et()"), 5, " E_{T} [GeV]"); |
585 |
> |
if (y.find(".et()") != string::npos) |
586 |
> |
y.replace(y.find(".et()"), 5, " E_{T} [GeV]"); |
587 |
> |
|
588 |
> |
//splitlines for many cuts |
589 |
> |
string test1= "{" + globalCuts + "}"; |
590 |
> |
string test2= "&&(" + globalCuts + ")"; |
591 |
> |
|
592 |
> |
if(t.find(test1) != string::npos) t.replace(t.find(test1),test1.length(),""); |
593 |
> |
if(t.find(test2) != string::npos) t.replace(t.find(test2),test2.length(),""); |
594 |
> |
|
595 |
> |
if (t.find("{") != string::npos && t.find("#splitline") == string::npos) { |
596 |
> |
t.replace(t.find_last_of("{"), 1, "}{"); |
597 |
> |
string t_old = t; |
598 |
> |
t = "#splitline{"; |
599 |
> |
t += t_old; |
600 |
> |
} |
601 |
|
|
602 |
|
thisHist ->SetTitle(t.c_str()); |
603 |
|
thisHist->GetXaxis()->SetTitle(x.c_str()); |
607 |
|
|
608 |
|
void PlotTool::setColor(TH1* thisHist, int counter) { |
609 |
|
|
610 |
+ |
thisHist->SetLineWidth(gStyle->GetLineWidth()); |
611 |
+ |
|
612 |
|
if (counter == 0) { |
613 |
|
|
614 |
|
thisHist->SetLineColor(kRed+1); |
653 |
|
|
654 |
|
} |
655 |
|
|
656 |
+ |
|
657 |
|
} |
658 |
|
|
659 |
|
void PlotTool::setPalette(TCanvas* thisCanvas, TPaletteAxis* palette) { |
735 |
|
|
736 |
|
int savedCanvs =0; |
737 |
|
|
677 |
– |
TPostScript ps(namePs.c_str(),112); |
678 |
– |
TFile rt(nameRt.c_str(),"recreate"); |
738 |
|
|
739 |
|
TIter next(gROOT->GetListOfCanvases()); |
740 |
|
TCanvas* canv; |
741 |
|
while ((canv=(TCanvas*)next())) { |
742 |
< |
ps.NewPage(); |
743 |
< |
(*canv).Draw(); |
744 |
< |
(*canv).Update(); |
686 |
< |
(*canv).Write(); |
687 |
< |
++savedCanvs; |
742 |
> |
string modName = (*canv).GetName(); |
743 |
> |
if(modName.find("{") != string::npos) modName = modName.substr(0,modName.find("{")); |
744 |
> |
(*canv).SetTitle( modName.c_str() ); |
745 |
|
|
746 |
|
} |
747 |
|
|
691 |
– |
ps.Close(); |
692 |
– |
rt.Close(); |
693 |
– |
|
694 |
– |
return savedCanvs; |
748 |
|
|
749 |
< |
} |
750 |
< |
//------------------------------------------------------------------ |
698 |
< |
void PlotTool::showChainInfo() |
699 |
< |
{ |
749 |
> |
TPostScript ps(namePs.c_str(),112); |
750 |
> |
TFile rt(nameRt.c_str(),"recreate"); |
751 |
|
|
752 |
+ |
next.Reset(); |
753 |
+ |
while ((canv=(TCanvas*)next())) { |
754 |
+ |
ps.NewPage(); |
755 |
|
|
702 |
– |
cout<<endl; |
703 |
– |
cout<<"****** Show Chain Information:"<<endl; |
756 |
|
|
757 |
+ |
(*canv).Write(); |
758 |
+ |
(*canv).Draw(); |
759 |
+ |
(*canv).Update(); |
760 |
|
|
706 |
– |
this->ls(); |
761 |
|
|
762 |
< |
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(); |
762 |
> |
++savedCanvs; |
763 |
|
|
764 |
|
} |
765 |
|
|
766 |
+ |
ps.Close(); |
767 |
+ |
rt.Close(); |
768 |
|
|
769 |
|
|
770 |
+ |
if(verbose && savedCanvs) { |
771 |
+ |
cout<<"Saved file "<<rt.GetName()<<" with "<<savedCanvs<<" canvases."<<endl; |
772 |
+ |
cout<<"Saved file "<<ps.GetName()<<" with "<<savedCanvs<<" pages."<<endl; |
773 |
|
} |
774 |
< |
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
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; |
774 |
> |
return savedCanvs; |
775 |
|
|
776 |
+ |
} |
777 |
+ |
//------------------------------------------------------------------ |
778 |
|
|
779 |
< |
TFile file("ABCDFunctions.root","UPDATE"); |
780 |
< |
TF1* savefunc = new TF1(savefuncName.str().c_str(), fitfunc->GetExpFormula().Data(),0,10000); |
844 |
< |
savefunc->SetParameters( fitfunc->GetParameters() ); |
845 |
< |
savefunc->SetParErrors ( fitfunc->GetParErrors() ); |
779 |
> |
int PlotTool::clearCanvases() |
780 |
> |
{ |
781 |
|
|
782 |
< |
//Show results |
783 |
< |
if( ! pads_["abcd"] || ! gROOT->FindObject("abcd") ) { |
784 |
< |
pads_["abcd"] = new TCanvas("abcd", "abcd"); |
785 |
< |
} else { |
851 |
< |
pads_["abcd"]->cd(); |
852 |
< |
} |
782 |
> |
while(gROOT->GetListOfCanvases()->GetEntries()) ((TCanvas*) gROOT->GetListOfCanvases()->At(0))->Close(); |
783 |
> |
pads_.clear(); |
784 |
> |
autoVars.clear(); |
785 |
> |
return pads_.size() + gROOT->GetListOfCanvases()->GetEntries(); |
786 |
|
|
787 |
< |
bkg->Multiply(savefunc); |
788 |
< |
bkg->Draw(); |
787 |
> |
} |
788 |
> |
//------------------------------------------------------------------ |
789 |
> |
int PlotTool::setVariables(string label) |
790 |
> |
{ |
791 |
|
|
792 |
< |
// total->Add(bkg,-1); |
793 |
< |
pass->SetLineColor(kRed); |
794 |
< |
pass->Draw("sames,e"); |
795 |
< |
pads_["abcd"]->SetLogy(); |
792 |
> |
for (int i=0; i< this->GetEntries(); ++i) { |
793 |
> |
cout<<"--------------------------------"<<endl; |
794 |
> |
cout<<((TChain*) this->At(i))->GetName()<<endl; |
795 |
> |
cout<<"------------"<<endl; |
796 |
|
|
797 |
+ |
TList* leaves = (TList*) ((TChain*) this->At(i))->GetListOfLeaves(); |
798 |
+ |
for (int j=0; j< leaves->GetEntries(); ++j) { |
799 |
+ |
TString leafName ( leaves->At(j)->GetName() ); |
800 |
+ |
if(! leafName.EndsWith(".") ) continue; |
801 |
+ |
if(! leafName.Contains(label.c_str() ) ) continue; |
802 |
+ |
|
803 |
+ |
TClass cl( ( (TLeafElement*) leaves->At(j) )->GetTypeName() ); |
804 |
+ |
cout<<"++++++"<<endl; |
805 |
+ |
cout<< leafName.Data() <<endl; |
806 |
+ |
for(int k=0;k<cl.GetListOfAllPublicMethods()->GetEntries();++k) { |
807 |
+ |
string typeName ( ((TMethod*) cl.GetListOfAllPublicMethods()->At(k))->GetReturnTypeName() ); |
808 |
+ |
string methName ( cl.GetListOfAllPublicMethods()->At(k)->GetName() ); |
809 |
+ |
if( methName != "product") continue; |
810 |
+ |
cout<< typeName <<endl; |
811 |
+ |
string _type; |
812 |
+ |
TString testString( typeName.c_str() ); |
813 |
+ |
if( testString.BeginsWith("vector<") ) { |
814 |
+ |
_type = typeName.substr(typeName.find("<")+1,typeName.find(">")-typeName.find("<")-1); |
815 |
+ |
string _varSize = leafName.Data(); |
816 |
+ |
_varSize += "obj@.size()"; |
817 |
+ |
autoVars.push_back( _varSize ); |
818 |
+ |
} |
819 |
+ |
else _type = typeName.substr(0,typeName.find("*")); |
820 |
+ |
TClass _cl( _type.c_str() ); |
821 |
+ |
for(int l=0;l<_cl.GetListOfAllPublicMethods()->GetEntries();++l) { |
822 |
+ |
string _typeName ( ((TMethod*) _cl.GetListOfAllPublicMethods()->At(l))->GetReturnTypeName() ); |
823 |
+ |
string _methName ( _cl.GetListOfAllPublicMethods()->At(l)->GetName() ); |
824 |
+ |
// if(_typeName.find("void") != string::npos ) continue; |
825 |
+ |
// cout<<" "<<_typeName<<" "<<_methName<<endl; |
826 |
+ |
|
827 |
+ |
cout<<" "<<_typeName<<" "<<_methName<<endl; |
828 |
+ |
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")) { |
829 |
+ |
|
830 |
+ |
cout<<"--> "<<_typeName<<" "<<_methName<<endl; |
831 |
+ |
|
832 |
+ |
string _varName = leafName.Data(); |
833 |
+ |
_varName += "obj."; |
834 |
+ |
_varName += _methName; |
835 |
+ |
_varName += "()"; |
836 |
+ |
autoVars.push_back( _varName ); |
837 |
+ |
} |
838 |
+ |
} |
839 |
+ |
|
840 |
+ |
|
841 |
+ |
} |
842 |
|
|
843 |
< |
savefunc->Write(); |
864 |
< |
// file.Close(); |
843 |
> |
} |
844 |
|
|
845 |
+ |
} |
846 |
|
|
847 |
< |
return draw_err; |
847 |
> |
return autoVars.size(); |
848 |
|
|
849 |
|
} |
850 |
+ |
|
851 |
|
//------------------------------------------------------------------ |