10 #ifndef CROMBIETOOLS_PLOTTOOLS_PLOTBASE_H 11 #define CROMBIETOOLS_PLOTTOOLS_PLOTBASE_H 15 #include <type_traits> 24 #include "TGraphErrors.h" 48 inline void AddLine ( TTree *tree, TCut cut, TString expr );
53 inline void AddTreeExpr ( TTree *tree, TString expr );
58 inline void AddLegendEntry ( TString LegendEntry, Color_t ColorEntry );
60 inline void AddLegendEntry ( TString LegendEntry, Color_t ColorEntry, Int_t LineWidth, Int_t LineStyle );
63 inline void AddLine ( TTree *tree,
const char* cut, TString expr ) {
AddLine(tree, TCut(cut), expr); }
132 inline void SetLegendLimits ( Double_t lim1, Double_t lim2, Double_t lim3, Double_t lim4 )
133 {
l1 = lim1;
l2 = lim2;
l3 = lim3;
l4 = lim4; }
182 inline void AddCutLine ( Double_t loc,
bool is_vert =
true ) {
fCutLines.push_back(std::make_pair(loc, is_vert)); }
243 inline void ConvertToArray ( Int_t NumXBins, Double_t MinX, Double_t MaxX, Double_t *XBins );
246 template<
class T>
void BaseCanvas ( TString FileBase, std::vector<T*> theLines, TString XLabel,
247 TString YLabel, Bool_t logY =
false, Bool_t logX =
false );
274 template<
class T>
void LineDrawing ( std::vector<T*> theLines, Int_t index, Bool_t same );
278 template<
class T> TString
GetOpts ( T* );
315 Message(
eError,
"Default tree already set! Check configuration...");
319 Message(
eError,
"Default cut already set! Check configuration...");
323 Message(
eError,
"Default resolution expression already set! Check configuration...");
336 Message(
eError,
"Default tree already set! Check configuration...");
340 Message(
eError,
"Default cut already set! Check configuration...");
344 Message(
eError,
"Please set default resolution expression first!");
356 Message(
eError,
"Default tree already set! Check configuration...");
364 Message(
eError,
"Default resolution expression already set! Check configuration...");
380 Message(
eError,
"Default cut already set! Check configuration...");
384 Message(
eError,
"Default resolution expression already set! Check configuration...");
443 Double_t binWidth = (MaxX - MinX)/NumXBins;
444 for (Int_t i0 = 0; i0 < NumXBins + 1; i0++)
445 XBins[i0] = MinX + i0 * binWidth;
452 for (UInt_t iCut = 0; iCut !=
fCutLines.size(); ++iCut) {
466 aCutLine->Draw(
"same");
485 if (std::is_base_of<TH1, T>::value)
487 else if (std::is_base_of<TGraph, T>::value)
503 Message(
eDebug,
"There are %i lines ... Currently drawing %i",
504 theLines.size(), index);
505 Message(
eDebug,
"Drawing with same set: %s", same ?
"true" :
"false");
508 fCutYMin = theLines[index]->GetMinimum();
509 fCutYMax = theLines[index]->GetMaximum();
510 fCutXMin = theLines[index]->GetXaxis()->GetXmin();
511 fCutXMax = theLines[index]->GetXaxis()->GetXmax();
514 TString options =
GetOpts(theLines[index]);
518 Message(
eDebug,
"Line color: %i", theLines[index]->GetLineColor());
519 Message(
eDebug,
"Fill color: %i", theLines[index]->GetFillColor());
525 if (!std::is_base_of<TGraph, T>::value)
529 T* tempLine =
reinterpret_cast<T*
>(theLines[
fRatioIndex]->Clone());
531 Message(
eDebug,
"Created templine for error bars at %p from line at %p",
534 tempLine->SetFillColor(kGray);
535 tempLine->SetFillStyle(3001);
537 if (!same && index == fRatioIndex) {
538 tempLine->Draw(
"e2");
542 theLines[index]->Draw(options);
543 tempLine->Draw(
"e2,same");
550 theLines[index]->Draw(options);
562 TString XLabel, TString YLabel, Bool_t logY, Bool_t logX)
566 Message(
eInfo,
"Number of Lines : %i", theLines.size());
570 gStyle->SetOptStat(0);
574 Float_t ratioFrac = 0.7;
576 UInt_t NumPlots = theLines.size();
580 theCanvas->SetTitle(
";" + XLabel +
";" + YLabel);
581 TLegend *theLegend =
new TLegend(
l1,
l2,
l3,
l4);
583 theLegend->SetFillStyle(0);
587 UInt_t plotFirst = 0;
591 if (theLines.size() != 1 && theLines.size() !=
fLegendEntries.size()) {
593 Message(
eError,
"Number of lines and number of legend entries do not match!");
601 for (UInt_t iLine = 0; iLine != NumPlots; ++iLine) {
604 theLines[iLine]->SetTitle(
";"+XLabel+
";"+YLabel);
605 theLines[iLine]->GetYaxis()->SetTitleOffset(
fTitleOffset);
610 theLines[iLine]->SetMinimum(
fAxisMin);
611 theLines[iLine]->SetMaximum(
fAxisMax);
617 if (theLines.size() == 1 &&
fLineColors.size() == 0) {
628 if (std::is_base_of<TGraph, T>::value)
635 theLines[iLine]->SetMarkerStyle(8);
637 if (theLines.size() != 1) {
643 theLegend->AddEntry(theLines[iLine],
fLegendEntries[iLine],
"lp");
649 Double_t checkMax = theLines[iLine]->GetMaximum();
651 if (checkMax > maxValue) {
661 TPad *pad1 =
new TPad(
"pad1",
"pad1", 0, 1.0 - ratioFrac, 1, 1.0);
665 pad1->SetBottomMargin(0.025);
670 for (UInt_t iLine = 0; iLine != NumPlots; ++iLine) {
672 theLines[iLine]->GetYaxis()->SetTitleSize(
fFontSize/ratioFrac);
673 theLines[iLine]->GetYaxis()->SetLabelSize(
fFontSize/ratioFrac);
674 theLines[iLine]->GetYaxis()->SetTitleOffset(
fTitleOffset);
675 theLines[iLine]->GetXaxis()->SetTitleSize(0);
676 theLines[iLine]->GetXaxis()->SetLabelSize(0);
702 for (UInt_t iLine = 0; iLine != NumPlots; ++iLine)
711 if (theLines.size() != 1) {
723 theCanvas->SetLogx();
725 theCanvas->SetLogy();
732 TPad *pad2 =
new TPad(
"pad2",
"pad2", 0, 0, 1, 1 - ratioFrac);
736 pad2->SetTopMargin(0.05);
737 pad2->SetBottomMargin(0.4);
746 T *ratioLine =
reinterpret_cast<T*
>(theLines[
fRatioIndex]->Clone(
"ValueHolder"));
747 Message(
eDebug,
"Created ratio line at %p from ration index %i at %p",
754 Message(
eDebug,
"Ratio lines created with size %i compared to %i",
755 newLines.size(), theLines.size());
758 for (UInt_t iLine = 0; iLine != NumPlots; ++iLine) {
760 newLines[iLine]->GetXaxis()->SetTitleSize(
fFontSize/(1 - ratioFrac));
761 newLines[iLine]->GetYaxis()->SetTitleSize(
fFontSize/(1 - ratioFrac));
762 newLines[iLine]->GetXaxis()->SetLabelSize(
fFontSize/(1 - ratioFrac));
763 newLines[iLine]->GetYaxis()->SetLabelSize(
fFontSize/(1 - ratioFrac));
764 newLines[iLine]->GetYaxis()->SetTitleOffset((1 - ratioFrac)/ratioFrac *
fTitleOffset);
766 newLines[iLine]->GetYaxis()->SetTitle(
fRatioTitle);
767 newLines[iLine]->GetYaxis()->CenterTitle();
776 newLines[iLine]->SetFillColor(0);
789 for (UInt_t iLine = 0; iLine !=
fRatioLines.size(); ++iLine) {
800 for (UInt_t iLine = 0; iLine < NumPlots; iLine++)
818 TLatex* latex2 =
new TLatex();
820 latex2->SetTextSize(0.035);
821 latex2->SetTextAlign(31);
822 latex2->DrawLatex(0.90, 0.96,
fLumiLabel +
" fb^{-1} (13 TeV)");
829 TLatex* latex3 =
new TLatex();
831 latex3->SetTextSize(0.035);
832 latex3->SetTextFont(62);
833 latex3->SetTextAlign(11);
834 latex3->DrawLatex(0.19, 0.96,
"CMS");
835 latex3->SetTextSize(0.030);
836 latex3->SetTextFont(52);
837 latex3->SetTextAlign(11);
839 latex3->DrawLatex(0.27, 0.96,
fCMSLabel);
847 theCanvas->SaveAs(FileBase+
".C");
849 theCanvas->SaveAs(FileBase+
".png");
851 theCanvas->SaveAs(FileBase+
".pdf");
857 for (UInt_t iDelete = 0; iDelete !=
fDeleteThese.size(); ++iDelete)