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 |
|
//------------------------------------------------------------------ |
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) { |
248 |
|
|
249 |
|
|
250 |
|
//Draw histogram: |
251 |
< |
string cutNameWithGlobal = cutName; |
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 |
|
} |
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 |
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 |
|
|
587 |
|
|
588 |
|
//splitlines for many cuts |
589 |
|
string test1= "{" + globalCuts + "}"; |
590 |
< |
string test2= "&&" + 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(),""); |
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) { |