#include "TCanvas.h" #include "TROOT.h" #include "TGraphErrors.h" #include #include "TF1.h" #include "TLegend.h" #include "TArrow.h" #include "TLatex.h" #include "TBranch.h" #include "TFile.h" #include "TTree.h" #include "Riostream.h" #include "TError.h" #include "TMath.h" #include "TMultiGraph.h" #include "TGraph.h" #include "TPave.h" #include #include #include #include #include #include #include #include #include using namespace std; vector Histos; vector Graphs; void THStackTest(){ const int Nplots = 5; Color_t HistoColor[Nplots] = {1,2,3,4,5}; double HistoAlpha[Nplots] = {.2,.2,.2,.2,.2}; double StatCoords[Nplots][2] = {{.15,.65},{.25,.775},{.35,.65},{.45,.775},{.55,.65}}; //Generates and plots 'Nplots' worth of random gaussian histograms TCanvas *c0 = new TCanvas("c0","c0",0,0,600,400); for(int a=0;aFillRandom("gaus",10000/(a+1)); Histos.at(a)->Draw(); string HistoFile = "Histo"+to_string(a)+".pdf"; c0->Print(HistoFile.c_str()); } TCanvas *c1 = new TCanvas("c1","c1",0,0,600,400); THStack *StackTest = new THStack("StackTest","StackTest"); for(int b=0;bFindObject("stats"); st->SetTextSize(0.023); st->SetX1NDC(StatCoords[b][0]); st->SetX2NDC(StatCoords[b][0]+.195); st->SetY1NDC(StatCoords[b][1]); st->SetY2NDC(StatCoords[b][1]+.1); st->SetFillColorAlpha(HistoColor[b],HistoAlpha[b]); Histos.at(b)->SetFillColorAlpha(HistoColor[b],HistoAlpha[b]); Histos.at(b)->SetMarkerColor(HistoColor[b]); Histos.at(b)->SetMarkerStyle(21); StackTest->Add(Histos.at(b)); c1->Update(); } StackTest->Draw("nostack"); string NoStackFile = "NoStack.pdf"; c1->Print(NoStackFile.c_str()); StackTest->Draw(""); string StackFile = "Stack.pdf"; c1->Print(StackFile.c_str()); }