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 |
|
|
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; |
35 |
< |
|
36 |
< |
if (currChain < 0) |
37 |
< |
return currChain; |
38 |
< |
|
39 |
< |
fileNames.clear(); |
40 |
< |
|
41 |
< |
//check if alternative label is different from default(searchString) |
42 |
< |
if (fileLabel=="") { |
43 |
< |
fileLabel=fileName; |
44 |
< |
} |
45 |
< |
((TChain*) this->At(currChain))->SetName(fileLabel.c_str()); |
46 |
< |
TSystemDirectory dir("sourceDir", dirPath.c_str()); |
47 |
< |
TList *files = dir.GetListOfFiles(); |
48 |
< |
if (files) { |
49 |
< |
TIter next(files); |
50 |
< |
TSystemFile *file; |
51 |
< |
TString fname; |
52 |
< |
string filePath; |
53 |
< |
|
54 |
< |
cout<<"Open"<<dirPath.c_str()<<" Search for .root files that contain: " |
55 |
< |
<<fileName.c_str()<<endl; |
56 |
< |
|
57 |
< |
while ((file=(TSystemFile*)next())) { |
58 |
< |
fname = file->GetName(); |
59 |
< |
if (!fname.EndsWith(".root")) |
60 |
< |
continue; |
61 |
< |
if (!fname.Contains(fileName.c_str())) |
62 |
< |
continue; |
32 |
> |
string fileLabel) { |
33 |
> |
this->New(this->GetEntries() ); |
34 |
> |
int currChain = this->GetEntries() - 1; |
35 |
> |
|
36 |
> |
if (currChain < 0) |
37 |
> |
return currChain; |
38 |
> |
|
39 |
> |
TStopwatch timer; |
40 |
> |
timer.Start(); |
41 |
> |
|
42 |
> |
|
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()); |
50 |
> |
|
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 |
> |
|
64 |
> |
|
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 |
< |
filePath = dirPath; |
137 |
< |
filePath += fname.Data(); |
59 |
< |
//fwlite::ChainEvent to lop over events, jets, etc |
60 |
< |
fileNames.push_back(filePath.c_str()); |
61 |
< |
|
62 |
< |
if (((TChain*) this->At(currChain))->AddFile(filePath.c_str(), -1, |
63 |
< |
treeName.c_str()) ) |
64 |
< |
cout<<"Chained "<<((TChain*) this->At(currChain))->GetNtrees()<<" file(s) with "<<((TChain*) this->At(currChain))->GetEntries()<<" events."<<endl; |
65 |
< |
else |
66 |
< |
return -1; |
136 |
> |
((TChain*) this->At(currChain))->SetAlias(branch_alias.c_str(), |
137 |
> |
branch_name.c_str()); |
138 |
|
|
139 |
< |
} |
69 |
< |
} else |
70 |
< |
return -1; |
139 |
> |
} |
140 |
|
|
72 |
– |
for (int i=0; i<((TChain*) this->At(currChain))->GetListOfBranches()->GetEntries(); ++i) { |
141 |
|
|
74 |
– |
string s(((TChain*) this->At(currChain))->GetListOfBranches()->At(i)->GetName()); |
142 |
|
|
143 |
< |
string branch_alias = s; |
144 |
< |
string branch_name = s; |
145 |
< |
if (s.find(".", s.size()-1) != string::npos) |
79 |
< |
branch_name += "obj"; |
80 |
< |
|
81 |
< |
size_t a = s.find("_"); |
82 |
< |
if (a != string::npos) { |
83 |
< |
size_t b = s.find("_", a+1); |
84 |
< |
if (b != string::npos) { |
85 |
< |
size_t c = s.find("_", b+1); |
86 |
< |
if (c != string::npos) { |
87 |
< |
string _label =s.substr(a+1, b-a-1); |
88 |
< |
string _instance =s.substr(b+1, c-b-1); |
89 |
< |
branch_alias = _label; |
90 |
< |
if(_instance.length() > 0 ) { |
91 |
< |
branch_alias += "_"; |
92 |
< |
branch_alias += _instance; |
93 |
< |
} |
94 |
< |
} |
95 |
< |
} |
96 |
< |
} |
143 |
> |
|
144 |
> |
|
145 |
> |
string friendTreeName("friendTree"); |
146 |
|
|
147 |
< |
((TChain*) this->At(currChain))->SetAlias(branch_alias.c_str(), |
148 |
< |
branch_name.c_str()); |
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 |
< |
} |
155 |
> |
FWliteVariables fwVars(friendTreeName, friendFileName, fileOpt); |
156 |
|
|
157 |
< |
// add branch with track Jets |
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( addTrackJets ) { |
166 |
> |
|
167 |
> |
|
168 |
|
|
169 |
< |
//make file for tree friends (adding additional, computed branches) |
170 |
< |
string friendFileName("/scratch/hh/lustre/cms/user/thomsen/temp/"); |
171 |
< |
friendFileName += fileName; |
172 |
< |
friendFileName += ".root"; |
173 |
< |
TFile *f = new TFile(friendFileName.c_str(),"recreate"); |
112 |
< |
string friendTreeName("friendTree"); |
113 |
< |
//char number = currChain; |
114 |
< |
//friendTreeName += number; |
115 |
< |
//TTree *friendTree = new TTree("friendTree","friendTree"); |
116 |
< |
TTree *friendTree = new TTree(friendTreeName.c_str(),friendTreeName.c_str()); |
117 |
< |
|
118 |
< |
int nJetsKT; |
119 |
< |
TrackJetKT = new float [100]; |
120 |
< |
fwlite::ChainEvent ev(fileNames); |
121 |
< |
|
122 |
< |
friendTree->Branch("nJetsKT", &nJetsKT, "nJetsKT/I"); |
123 |
< |
friendTree->Branch("TrackJetKT", TrackJetKT, "TrackJetKT[nJetsKT]/F"); |
124 |
< |
|
125 |
< |
cout<<"calculating additional variables..."<<endl; |
126 |
< |
for (ev.toBegin(); !ev.atEnd(); ++ev) { |
127 |
< |
|
128 |
< |
fwlite::Handle<reco::CaloJetCollection> jets; |
129 |
< |
jets.getByLabel(ev, "antikt5CaloJets"); |
130 |
< |
|
131 |
< |
fwlite::Handle<reco::TrackCollection> tracks; |
132 |
< |
tracks.getByLabel(ev, "generalTracks"); |
133 |
< |
|
134 |
< |
if (!jets.isValid()) |
135 |
< |
continue; |
136 |
< |
if (!tracks.isValid()) |
137 |
< |
continue; |
138 |
< |
double trackSum; |
139 |
< |
nJetsKT = 0; |
140 |
< |
for (reco::CaloJetCollection::const_iterator jet = jets->begin(); jet |
141 |
< |
!=jets->end(); jet++) { |
142 |
< |
trackSum = 0; |
143 |
< |
for (reco::TrackCollection::const_iterator track = tracks->begin(); track |
144 |
< |
!=tracks->end(); track++) { |
145 |
< |
if (deltaR(jet->eta(), jet->phi(), track->eta(), track->phi()) |
146 |
< |
< 0.5) |
147 |
< |
trackSum += track->pt(); |
148 |
< |
} |
149 |
< |
TrackJetKT[nJetsKT] = trackSum; |
150 |
< |
nJetsKT++; |
151 |
< |
} |
152 |
< |
friendTree->Fill(); |
153 |
< |
} |
154 |
< |
f->cd(); |
155 |
< |
friendTree->Write(); |
156 |
< |
f->Close(); |
157 |
< |
((TChain*) this->At(currChain))->AddFriend(friendTreeName.c_str(), |
158 |
< |
friendFileName.c_str()); |
159 |
< |
} |
160 |
< |
return this->GetEntries(); |
169 |
> |
|
170 |
> |
timer.Stop(); |
171 |
> |
if(verbose) timer.Print(); |
172 |
> |
|
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 |
> |
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) |
236 |
|
|
237 |
|
if ( !pads_[currPadName.str()] || !gROOT->GetListOfCanvases()->FindObject(currPadName.str().c_str()) ) { |
238 |
|
pads_[currPadName.str()] = new TCanvas(currPadName.str().c_str(), currPadName.str().c_str()); |
239 |
< |
if (logY) |
240 |
< |
pads_[currPadName.str()]->SetLogy(1); |
239 |
> |
// if (logY) |
240 |
> |
// pads_[currPadName.str()]->SetLogy(1); |
241 |
|
} else { |
242 |
|
pads_[currPadName.str()]->cd(); |
243 |
|
currOpt += "SAMES"; |
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 |
< |
return draw_err; |
289 |
> |
// Update for 2D histograms |
290 |
> |
if( thisHist->InheritsFrom("TH2") ) { |
291 |
> |
pads_[currPadName.str()]->Draw(); |
292 |
> |
setCanvas( pads_[currPadName.str()] ); |
293 |
> |
} |
294 |
> |
|
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 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); |
323 |
< |
updatePads(); |
322 |
> |
currHist = plot(i, *it1, *it2, nEntries, bins, drwOpt); |
323 |
> |
if(currHist) numProcessed += int(currHist->GetEntries()); |
324 |
> |
|
325 |
|
|
326 |
|
} |
327 |
|
} |
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 |
|
} |
344 |
|
} |
345 |
|
|
346 |
< |
// updatePads(); |
346 |
> |
updatePads(); |
347 |
|
fillCanvases(); |
348 |
|
|
349 |
|
return numProcessed; |
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(); |
406 |
|
|
407 |
|
for (map< string, TCanvas* >::iterator it=canvases_.begin() ; it |
408 |
|
!= canvases_.end(); ++it) { |
409 |
< |
const char* canvName = (*it).first.c_str(); |
410 |
< |
if (gROOT->GetListOfCanvases()->FindObject(canvName) ) { |
409 |
> |
string canvName = (*it).first; |
410 |
> |
if (gROOT->GetListOfCanvases()->FindObject(canvName.c_str()) ) { |
411 |
|
|
412 |
|
int numP = (*it).second->GetNumber()+1; |
413 |
|
|
425 |
|
y += 1; |
426 |
|
} |
427 |
|
|
428 |
+ |
|
429 |
|
(*it).second->Divide(x, y); |
430 |
|
int padIndex = 1; |
431 |
|
for (map< string, TCanvas* >::iterator it2=pads_.begin() ; it2 |
432 |
|
!= pads_.end(); ++it2) { |
433 |
|
string padName = (*it2).first; |
434 |
|
if (gROOT->GetListOfCanvases()->FindObject(padName.c_str() ) ) { |
435 |
< |
if ( (padName.find(canvName) != string::npos ) || !strcmp( |
436 |
< |
canvName, "All") ) { |
435 |
> |
string n1 = canvName.substr(0,canvName.find(":")); |
436 |
> |
string n2(""); |
437 |
> |
if(canvName.find("{") != string::npos ) n2 = canvName.substr(canvName.find("{"),canvName.find("}")); |
438 |
> |
|
439 |
> |
if ( (padName.find(canvName.c_str()) != string::npos ) || (padName.find(n1) != string::npos && padName.find(n2) != string::npos) || !strcmp( canvName.c_str(), "All") ) { |
440 |
|
(*it).second->cd(padIndex); |
441 |
|
(*it2).second->DrawClonePad(); |
442 |
|
(*it2).second->Close(); |
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 |
|
|
485 |
– |
if (t.find(".eta()") != string::npos) |
486 |
– |
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) { |
718 |
|
|
719 |
|
//------------------------------------------------------------------ |
720 |
|
|
721 |
< |
int PlotTool::saveCanvases(string type, string path) { |
721 |
> |
int PlotTool::saveCanvases(string name, string path) { |
722 |
|
|
723 |
|
TSystemDirectory d("", path.c_str()); |
724 |
|
if (!d.GetListOfFiles()) |
725 |
|
return -1; |
620 |
– |
if (type.find(".") == string::npos) |
621 |
– |
return -1; |
726 |
|
|
727 |
< |
int savedFiles =0; |
727 |
> |
string namePs = path +"/" + name; |
728 |
> |
string nameRt = path +"/" + name; |
729 |
> |
|
730 |
> |
if (name.find(".ps") == string::npos) |
731 |
> |
namePs += ".ps"; |
732 |
> |
|
733 |
> |
if (name.find(".root") == string::npos) |
734 |
> |
nameRt += ".root"; |
735 |
> |
|
736 |
> |
int savedCanvs =0; |
737 |
> |
|
738 |
|
|
739 |
|
TIter next(gROOT->GetListOfCanvases()); |
740 |
|
TCanvas* canv; |
741 |
|
while ((canv=(TCanvas*)next())) { |
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 |
+ |
|
748 |
+ |
|
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 |
+ |
|
756 |
|
|
757 |
< |
string s = ""; |
758 |
< |
s += path; |
759 |
< |
s += canv->GetName(); |
632 |
< |
s += type; |
757 |
> |
(*canv).Write(); |
758 |
> |
(*canv).Draw(); |
759 |
> |
(*canv).Update(); |
760 |
|
|
761 |
< |
canv->SaveAs(s.c_str()); |
762 |
< |
++savedFiles; |
761 |
> |
|
762 |
> |
++savedCanvs; |
763 |
|
|
764 |
|
} |
765 |
|
|
766 |
< |
return savedFiles; |
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 |
< |
//------------------------------------------------------------------ |
643 |
< |
void PlotTool::showChainInfo() |
644 |
< |
{ |
774 |
> |
return savedCanvs; |
775 |
|
|
776 |
+ |
} |
777 |
+ |
//------------------------------------------------------------------ |
778 |
|
|
779 |
< |
cout<<endl; |
780 |
< |
cout<<"****** Show Chain Information:"<<endl; |
779 |
> |
int PlotTool::clearCanvases() |
780 |
> |
{ |
781 |
|
|
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 |
< |
this->ls(); |
787 |
> |
} |
788 |
> |
//------------------------------------------------------------------ |
789 |
> |
int PlotTool::setVariables(string label) |
790 |
> |
{ |
791 |
|
|
653 |
– |
cout<<endl; |
654 |
– |
cout<<"We have "<<this->GetEntries()<<" TChains with following aliases set:"<<endl; |
792 |
|
for (int i=0; i< this->GetEntries(); ++i) { |
793 |
< |
cout<<endl; |
793 |
> |
cout<<"--------------------------------"<<endl; |
794 |
|
cout<<((TChain*) this->At(i))->GetName()<<endl; |
795 |
< |
((TChain*) this->At(i))->GetListOfAliases()->ls(); |
795 |
> |
cout<<"------------"<<endl; |
796 |
|
|
797 |
< |
} |
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 |
+ |
} |
844 |
+ |
|
845 |
+ |
} |
846 |
|
|
847 |
+ |
return autoVars.size(); |
848 |
|
|
849 |
|
} |
850 |
+ |
|
851 |
+ |
//------------------------------------------------------------------ |