#include "TFile.h" #include "TCanvas.h" #include "TH1D.h" #include "TH1F.h" #include "TROOT.h" #include "TPad.h" #include "TText.h" #include "TStyle.h" #include "TPaveStats.h" #include #include using namespace std ; inline void WriteStats( char* txt, Double_t s, Double_t posx, Double_t posy ) { char text[100] ; sprintf( text , "%s Entries %f" , txt, s ) ; cout << text << " " << posx << " " << posy<< endl ; TText t(posx,posy,text ) ; t.SetTextSize(0.5) ; t.Draw() ; } inline TH1D* GetHist( char* hname, char* str, char* HistFile ) { TFile f( HistFile ) ; cout << " Open File " << HistFile << endl ; gROOT->cd() ; char histName[100] ; strcpy( histName, hname ) ; std::strcat( histName,str ) ; cout << " Get Histogram " << histName << endl ; TH1D* h = dynamic_cast( f.Get(histName)->Clone() ) ; f.Close(); h->SetLineWidth( 2 ) ; h->SetMarkerSize( 0.75 ) ; // if( strcmp( str,"p" ) >= 0 || strcmp( str,"p_sel") >0 ) if( strcmp( str,"p" ) >= 0 ) { h->SetMarkerStyle( 20 ) ; h->SetMarkerColor( 36 ) ; h->SetLineColor( 36 ) ; } else { h->SetMarkerStyle( 20 ) ; h->SetMarkerColor( 46 ) ; h->SetLineColor( 46 ) ; } return h ; } void PlotHisto( char* hname, char* RootFile ="" , bool LogScale=false ) { gStyle->SetOptStat(10) ; TCanvas *TC = new TCanvas("TC","Charged Tracks") ; TPad* p1 = new TPad("p1","No Cut",0.01,0.20,0.49,0.99) ; TPad* p2 = new TPad("p2","Selected",0.51,0.20,0.99,0.99) ; TPad* p3 = new TPad("p3","Ratio No Cut",0.01,0.01,0.49,0.19) ; TPad* p4 = new TPad("p4","Ratio Selected",0.51,0.01,0.99,0.19) ; p1->Draw() ; p2->Draw() ; p3->Draw() ; p4->Draw() ; if( LogScale ) { p1->SetLogy() ; p2->SetLogy() ; } p1->cd() ; TH1D* hm = GetHist( hname ,"m", RootFile ) ; if( hm == 0 ) { cout << hname << " not found . Stop execution " << endl ; return ; } hm->Draw("error") ; // WriteStats( "-",hm->GetSum(), 0.5 , 0.90*hm->GetMaximum() ) ; TPaveStats *stt = (TPaveStats*) hm->GetListOfFunctions()->FindObject("stats") ; // cout << stt->GetX1() << endl ; TH1D* hp = GetHist( hname ,"p", RootFile ) ; hp->DrawCopy("sameserror") ; // WriteStats( "+",hp->GetSum(), 0.5, 0.95*hp->GetMaximum() ) ; TH1D* r = (TH1D*) hp->Clone() ; r->Sumw2() ; r->SetStats( kFALSE ) ; r->Divide( hm ) ; r->SetMaximum(1.2) ; r->SetMinimum(0.8) ; p3->cd() ; r->SetMarkerSize(0.5) ; r->DrawCopy("error") ; p2->cd() ; TH1D* hms = GetHist( hname ,"m_sel", RootFile ) ; hms->DrawCopy("error") ; TH1D* hps = GetHist( hname ,"p_sel", RootFile ) ; hps->DrawCopy("sameserror") ; TH1D* rs = (TH1D*) hps->Clone("Ratio") ; rs->SetMarkerSize(0.5) ; rs->Sumw2() ; rs->SetStats( kFALSE ) ; rs->Divide( hms ) ; rs->SetMaximum(1.2) ; rs->SetMinimum(0.8) ; p4->cd() ; rs->DrawCopy("error") ; }