#ifndef __PLOT_RECO_TRKS__ #define __PLOT_RECO_TRKS__ #include #include #include #include #include #include "TH1D.h" #include "TH2D.h" #include "TH3D.h" #include "TProfile.h" #include "TString.h" #include "TTree.h" #include "TTreeReader.h" #include "TTreeReaderValue.h" #include "TFile.h" #include "TCanvas.h" #include "TStyle.h" #include "TLatex.h" #include "TLine.h" #include "TF1.h" using namespace std; inline double get_median(TH1D* h, double percentile = 0.5); inline vector< double > plot_2poisson(TCanvas* c1, string outname, TH1D* h0, TH1D* h1, string x_title = "", string y_title = "", bool logx = false, bool logy = false); inline vector< double > plot_2gauss(TCanvas* c1, string outname, TH1D* h0, TH1D* h1, string x_title = "", string y_title = "", bool logx = false, bool logy = false, bool err = false); inline void plot_tprofile(TCanvas* c1, string outname, TProfile* t0, TProfile* t1, string x_title = "", string y_title = "", bool logx = false, bool logy = false); inline void plot_th1(TCanvas* c1, string outname, TH1* h0, TH1* h1, string x_title = "", string y_title = "", bool logx = false, bool logy = false, bool one_sided = true); inline void plot_th2(TCanvas* c1, string outname, TH1* h, string x_title = "", string y_title = "", bool logx = false, bool logy = false); inline double get_median(TH1D* h, double percentile){ uint n_events_under = 0; uint ibin = 0; while(n_events_under < h->GetEntries()*percentile){ n_events_under += h->GetBinContent(ibin++); } return h->GetBinCenter(ibin); } inline vector< double > plot_2poisson(TCanvas* c1, string outname, TH1D* h0, TH1D* h1, string x_title, string y_title, bool logx, bool logy){ c1->cd(); h0->SetLineWidth(2); h1->SetLineWidth(3); h1->SetLineColor(2); h0->GetXaxis()->SetTitle(x_title.c_str()); h0->GetYaxis()->SetTitle(y_title.c_str()); h0->Draw(); h1->Draw("same"); const double medianh0 = get_median( h0 ); const double medianh1 = get_median( h1 ); TLine* Lmedianh0 = new TLine(); TLine* Lmedianh1 = new TLine(); Lmedianh0->SetLineColor(1); Lmedianh1->SetLineColor(2); Lmedianh0->SetLineWidth(2); Lmedianh1->SetLineWidth(3); h0->Rebin(2); h1->Rebin(2); h0->GetXaxis()->SetRangeUser(0, 20); h0->SetMinimum( 0 ); if( h0->GetMaximum() > h1->GetMaximum() ){ h0->SetMaximum( h0->GetMaximum() * 1.1 ); }else{ h0->SetMaximum( h1->GetMaximum() * 1.1 ); } Lmedianh0->DrawLine( medianh0, 0.0, medianh0, h0->GetMaximum() ); Lmedianh1->DrawLine( medianh1, 0.0, medianh1, h0->GetMaximum() ); c1->SetLogx( logx ); c1->SetLogy( logy ); c1->SaveAs( ("rec_plots/" + outname + ".root").c_str() ); c1->SaveAs( ("rec_plots/" + outname + ".pdf" ).c_str() ); c1->SaveAs( ("rec_plots/" + outname + ".png" ).c_str() ); c1->Clear(); delete Lmedianh0; delete Lmedianh1; vector< double > medians = { medianh0, medianh1 }; return medians; } inline vector< double > plot_2gauss(TCanvas* c1, string outname, TH1D* h0, TH1D* h1, string x_title, string y_title, bool logx, bool logy, bool err){ c1->cd(); h0->SetLineWidth(2); h1->SetLineWidth(3); h1->SetLineColor(2); h0->GetXaxis()->SetTitle(x_title.c_str()); h0->GetYaxis()->SetTitle(y_title.c_str()); h0->Draw(); h1->Draw("same"); TF1* f0 = new TF1( "f0", "gaus" ); TF1* f1 = new TF1( "f1", "gaus" ); h0->Fit( f0, "0"); h1->Fit( f1, "0"); double meanf0 = f0->GetParameter( 1 ); double sigmaf0 = f0->GetParameter( 2 ); double meanf1 = f1->GetParameter( 1 ); double sigmaf1 = f1->GetParameter( 2 ); if( err){ double meanf0 = f0->GetParameter( 2 ); double sigmaf0 = f0->GetParError( 2 ); double meanf1 = f1->GetParameter( 2 ); double sigmaf1 = f1->GetParError( 2 ); } cout << "meanf0 : " << meanf0 << endl; cout << "sigmaf0 : " << sigmaf0 << endl; cout << "meanf1 : " << meanf1 << endl; cout << "sigmaf1 : " << sigmaf1 << endl; TLine* Lmeanf0 = new TLine(); TLine* Lmeanf1 = new TLine(); Lmeanf0->SetLineColor(1); Lmeanf1->SetLineColor(2); Lmeanf0->SetLineWidth(2); Lmeanf1->SetLineWidth(3); h0->Rebin(2); h1->Rebin(2); //h0->GetXaxis()->SetRangeUser(-20, 20); h0->SetMinimum( 0 ); if( h0->GetMaximum() > h1->GetMaximum() ){ h0->SetMaximum( h0->GetMaximum() * 1.1 ); }else{ h0->SetMaximum( h1->GetMaximum() * 1.1 ); } Lmeanf0->DrawLine( meanf0, 0.0, meanf0, h0->GetMaximum() ); Lmeanf1->DrawLine( meanf1, 0.0, meanf1, h0->GetMaximum() ); c1->SetLogx( logx ); c1->SetLogy( logy ); c1->SaveAs( ("rec_plots/" + outname + ".root").c_str() ); c1->SaveAs( ("rec_plots/" + outname + ".pdf" ).c_str() ); c1->SaveAs( ("rec_plots/" + outname + ".png" ).c_str() ); c1->Clear(); delete Lmeanf0; delete Lmeanf1; delete f0; delete f1; vector< double > params = { meanf0, sigmaf0, meanf1, sigmaf1 }; return params; } inline void plot_tprofile(TCanvas* c1, string outname, TProfile* t0, TProfile* t1, string x_title, string y_title, bool logx, bool logy){ c1->cd(); t0->SetLineWidth(2); t1->SetLineWidth(3); t1->SetLineColor(2); //t0->GetXaxis()->SetRangeUser(0, 100); t0->GetXaxis()->SetTitle(x_title.c_str()); t0->GetYaxis()->SetTitle(y_title.c_str()); t0->SetMinimum( 0 ); if( t0->GetMaximum() > t1->GetMaximum() ){ t0->SetMaximum( t0->GetMaximum() * 1.1 ); }else{ t0->SetMaximum( t1->GetMaximum() * 1.1 ); } c1->SetLogx( logx ); c1->SetLogy( logy ); t0->Draw(); t1->Draw("same"); c1->SaveAs(("rec_plots/" + outname + ".root").c_str()); c1->SaveAs(("rec_plots/" + outname + ".pdf" ).c_str()); c1->SaveAs(("rec_plots/" + outname + ".png" ).c_str()); c1->Clear(); } inline void plot_th1(TCanvas* c1, string outname, TH1* h0, TH1* h1, string x_title, string y_title, bool logx, bool logy, bool one_sided){ c1->cd(); h0->SetLineWidth(2); h1->SetLineWidth(3); h1->SetLineColor(2); //h0->GetXaxis()->SetRangeUser(0, 100); h0->GetXaxis()->SetTitle(x_title.c_str()); h0->GetYaxis()->SetTitle(y_title.c_str()); if( logy ) h0->SetMinimum( 1e-3 ); else if( one_sided ) h0->SetMinimum( 0 ); if( h0->GetMaximum() > h1->GetMaximum() ){ h0->SetMaximum( h0->GetMaximum() * 1.1 ); }else{ h0->SetMaximum( h1->GetMaximum() * 1.1 ); } if( h0->GetMaximum() < 1 ){ h0->SetMaximum( 1 ); } c1->SetLogx( logx ); c1->SetLogy( logy ); h0->Draw(); h1->Draw("same"); c1->SaveAs(("rec_plots/" + outname + ".root").c_str()); c1->SaveAs(("rec_plots/" + outname + ".pdf" ).c_str()); c1->SaveAs(("rec_plots/" + outname + ".png" ).c_str()); c1->Clear(); } inline void plot_th2(TCanvas* c1, string outname, TH1* h, string x_title, string y_title, bool logx, bool logy){ c1->cd(); h->GetXaxis()->SetTitle(x_title.c_str()); h->GetYaxis()->SetTitle(y_title.c_str()); c1->SetLogx( logx ); c1->SetLogy( logy ); h->Draw( "colz" ); c1->SaveAs(("rec_plots/" + outname + ".root").c_str()); c1->SaveAs(("rec_plots/" + outname + ".pdf" ).c_str()); c1->SaveAs(("rec_plots/" + outname + ".png" ).c_str()); c1->Clear(); } #endif