#include "ptdrHistogramStyle.h" #include "TStyle.h" #include "TString.h" #include "THStack.h" #include "TLegend.h" #include "TSystem.h" #include "TTree.h" #include "TFile.h" #include "TH1F.h" #include "TCanvas.h" #include #include ClassImp(TPTDRHistogramStyle); TPTDRHistogramStyle::TPTDRHistogramStyle(bool colored):colored(colored) { gSystem->Load("libExRootAnalysisReader"); int hatchesSpacing=0;//hatches density 1=max,9=min hatchStyles.push_back(3008+hatchesSpacing); hatchStyles.push_back(3007+hatchesSpacing); hatchStyles.push_back(3004+hatchesSpacing); hatchStyles.push_back(3006+hatchesSpacing); hatchStyles.push_back(3005+hatchesSpacing); hatchStyles.push_back(1001+hatchesSpacing); hatchStyles.push_back(3003+hatchesSpacing); hatchStyles.push_back(3001+hatchesSpacing); for(Int_t i=9;i<21;i++) hatchStyles.push_back(3000+i); nHists=0; } TH1F* TPTDRHistogramStyle::AddHistogram(TString variableName, TString fileName, TString lName, Int_t nBins, Double_t min, Double_t max, Double_t weight, TString treeName) { TFile f(fileName); TTree *t=(TTree*)f.Get(treeName); Double_t variable; t->SetBranchAddress(variableName,&variable); TH1F* hist = new TH1F(variableName, variableName, nBins, min, max);//bins,min,max if(min==0 && max==0) hist->SetBit(TH1::kCanRebin); Int_t nEntries = (Int_t)t->GetEntries(); for(Int_t i=0; iGetEntry(i); hist->Fill(variable); if(variable>max) max=variable; if(variableSetFillStyle(hatchStyles[nHists]); if(colored) hist->SetFillColor(nHists+101); else hist->SetFillColor(1); hist->Scale(weight); hist->SetDirectory(0);//avoid removing the histograms from the memory THStack::Add(hist); legendNames.push_back(lName); nHists++; return hist; } void TPTDRHistogramStyle::DrawHistograms(TString option) { THStack::Draw(option); } void TPTDRHistogramStyle::DrawLegend() { legend=new TLegend(0.6,0.35,0.9,0.9,"Samples","brNDC"); for(Int_t i=0;iGetSize();i++){ legend->AddEntry(GetHists()->At(i),legendNames[i]); // cout << legendNames[i] << " " << GetHists()->At(i) << endl; } legend->Draw(); }