// Modes: linear or log plotHistogram(const char* canvas, const char* mode, const char* title, double xlo, double xhi, int nbin, double* sig, double* sigerr, double* bgr, double* bgrerr) { TCanvas *c = new TCanvas(canvas,"SPR Classifier Output",200,10,600,400); gStyle->SetPalette(1); TLegend *leg = new TLegend(0.1,0.85,0.5,1.,"Classifier Output","NDC"); double dx = (xhi-xlo) / nbin; TH1D* hs = new TH1D("signal", title,nbin,xlo,xhi); TH1D* hb = new TH1D("background",title,nbin,xlo,xhi); leg->AddEntry(hs,"Signal","L"); leg->AddEntry(hb,"Background","L"); for( int i=0;i<nbin;i++ ) { hs->SetBinContent(i+1,sig[i]); hs->SetBinError(i+1,sigerr[i]); hb->SetBinContent(i+1,bgr[i]); hb->SetBinError(i+1,bgrerr[i]); } TPad* pad = new TPad("pad","pad",0,0,1,1); if( strcmp(mode,"log") == 0 ) pad->SetLogy(1); pad->Draw(); pad->cd(); hs->SetLineColor(2); hs->SetLineWidth(3); hb->SetLineColor(4); hb->SetLineWidth(3); hb->Draw(); hs->Draw("same"); leg->Draw(); }
void LHCHiggsExample() { #ifdef __CINT__ gROOT->LoadMacro("LHCHiggsUtils.C"); #endif SetLHCHiggsStyle(); TCanvas* c1 = new TCanvas("c1","Higgs Cross Section",50,50,600,600); TPad* thePad = (TPad*)c1->cd(); thePad->SetLogy(); Double_t ymin=1.e-2; Double_t ymax=1.e2; Double_t xmin=90.00; Double_t xmax=600.; TH1F *h1 = thePad->DrawFrame(xmin,ymin,xmax,ymax); h1->SetYTitle("#sigma_{pp #rightarrow H} [pb]"); h1->SetXTitle("M_{H} [GeV]"); h1->GetYaxis()->SetTitleOffset(1.4); h1->GetXaxis()->SetTitleOffset(1.4); //h1->GetXaxis()->SetNdivisions(5); h1->Draw(); myText(0.2,0.88,1,"#sqrt{s}= 13 TeV"); myBoxText(0.55,0.67,0.05,5,"NNLO QCD"); LHCHIGGS_LABEL(0.98,0.725); myText(0.2,0.2,1,"Preliminary"); c1->Print("LHCHiggsExample.eps"); c1->Print("LHCHiggsExample.png"); c1->Print("LHCHiggsExample.pdf"); }
/** * Draw the Poisson estimate of the occupancy in a given ring. * * @param p List * @param d Detector * @param r Ring * * @return The occupancy (in percent) * * @deprecated Use QATrender instead * @ingroup pwglf_forward_scripts_qa */ Double_t DrawRingOccupancy(TList* p, UShort_t d, Char_t r) { if (!p) return 0; TList* ring = static_cast<TList*>(p->FindObject(Form("FMD%d%c",d,r))); if (!ring) { Error("DrawOccupancy", "List FMD%d%c not found in %s",d,r,p->GetName()); return 0; } TH1* corr = static_cast<TH1*>(ring->FindObject("occupancy")); if (!corr) { Error("DrawRingOccupancy", "Histogram occupancy not found in FMD%d%c", d, r); return 0; } corr->Rebin(4); TPad* pad = static_cast<TPad*>(gPad); pad->SetGridy(); pad->SetGridx(); pad->SetLogy(); pad->SetFillColor(0); pad->SetRightMargin(0.01); #if 0 if (d == 3) { pad->SetPad(pad->GetXlowNDC(), pad->GetYlowNDC(), .99, pad->GetYlowNDC()+pad->GetHNDC()); pad->SetRightMargin(0.15); } #endif corr->Draw("hist"); TLatex* ltx = new TLatex(.95, .95, Form("FMD%d%c", d, r)); ltx->SetNDC(); ltx->SetTextAlign(33); ltx->SetTextSize(.08); ltx->Draw(); return corr->GetMean(); }
void EMCDistribution(TString gain = "CALIB", bool log_scale = false) { TText *t; TCanvas *c1 = new TCanvas( "EMCDistribution_" + gain + TString(log_scale ? "_Log" : "") + cuts, "EMCDistribution_" + gain + TString(log_scale ? "_Log" : "") + cuts, 1800, 1000); c1->Divide(8, 8, 0., 0.01); int idx = 1; TPad *p; for (int iphi = 8 - 1; iphi >= 0; iphi--) { for (int ieta = 0; ieta < 8; ieta++) { p = (TPad *) c1->cd(idx++); c1->Update(); p->SetLogy(); p->SetGridx(0); p->SetGridy(0); TString hname = Form("hEnergy_ieta%d_iphi%d", ieta, iphi) + TString(log_scale ? "_Log" : ""); TH1 *h = NULL; if (log_scale) h = new TH1F(hname, Form(";Calibrated Tower Energy Sum (GeV);Count / bin"), 300, 5e-3, 3096); else // h = new TH1F(hname, // Form(";Calibrated Tower Energy Sum (GeV);Count / bin"), 196, // 1900, 2096); h = new TH1F(hname, Form(";Calibrated Tower Energy Sum (GeV);Count / bin"), 596, -96, 500); h->SetLineWidth(0); h->SetLineColor(kBlue + 3); h->SetFillColor(kBlue + 3); h->GetXaxis()->SetTitleSize(.09); h->GetXaxis()->SetLabelSize(.08); h->GetYaxis()->SetLabelSize(.08); if (log_scale) QAHistManagerDef::useLogBins(h->GetXaxis()); T->Draw( "TOWER_" + gain + "_CEMC[].get_energy_power_law_exp()>>" + hname, Form( "TOWER_%s_CEMC[].get_bineta()==%d && TOWER_%s_CEMC[].get_binphi()==%d", gain.Data(), ieta, gain.Data(), iphi), ""); TText *t = new TText(.9, .9, Form("Col%d Row%d", ieta, iphi)); t->SetTextAlign(33); t->SetTextSize(.15); t->SetNDC(); t->Draw(); // return; } } SaveCanvas(c1, TString(_file0->GetName()) + TString("_DrawPrototype3EMCalTower_") + TString(c1->GetName()), false); }
void EMCDistribution_PeakSample_Fast(bool full_gain = false) { const TString gain = "RAW"; TString hname = "EMCDistribution_" + gain + TString(full_gain ? "_FullGain" : "") + cuts; TH2 *h2 = NULL; { if (full_gain) { h2 = new TH2F(hname, Form(";Calibrated Tower Energy Sum (ADC);Count / bin"), 100, .05 * 100, 25 * 100, 64, -.5, 63.5); QAHistManagerDef::useLogBins(h2->GetXaxis()); } else { h2 = new TH2F(hname, Form(";Calibrated Tower Energy Sum (ADC);Count / bin"), 260, -.2 * 100, 5 * 100, 64, -.5, 63.5); } T->Draw( "TOWER_" + gain + "_CEMC[].get_bineta() + 8* TOWER_" + gain + "_CEMC[].get_binphi():(TOWER_RAW_CEMC[].signal_samples[10] - TOWER_RAW_CEMC[].signal_samples[0])*(-1)>>" + hname, "", "goff"); } TText *t; TCanvas *c1 = new TCanvas( "EMCDistribution_PeakSample_Fast_" + TString(full_gain ? "_FullGain" : "") + cuts, "EMCDistribution_PeakSample_Fast_" + TString(full_gain ? "_FullGain" : "") + cuts, 1800, 950); c1->Divide(8, 8, 0., 0.01); int idx = 1; TPad *p; for (int iphi = 8 - 1; iphi >= 0; iphi--) { for (int ieta = 0; ieta < 8; ieta++) { p = (TPad *) c1->cd(idx++); c1->Update(); p->SetLogy(); if (full_gain) { p->SetLogx(); } p->SetGridx(0); p->SetGridy(0); TString hname = Form("hEnergy_ieta%d_iphi%d", ieta, iphi) + TString(full_gain ? "_FullGain" : ""); TH1 *h = h2->ProjectionX(hname, ieta + 8 * iphi + 1, ieta + 8 * iphi + 1); // axis bin number is encoded as ieta+8*iphi+1 h->SetLineWidth(0); h->SetLineColor(kBlue + 3); h->SetFillColor(kBlue + 3); h->GetXaxis()->SetTitleSize(.09); h->GetXaxis()->SetLabelSize(.08); h->GetYaxis()->SetLabelSize(.08); h->Draw(); if (full_gain) h->Fit("x*gaus", "M"); else h->Fit("landau", "M"); double peak = -1; TF1 *fit = ((TF1 *) (h->GetListOfFunctions()->At(0))); if (fit) { fit->SetLineColor(kRed); peak = fit->GetParameter(1); } cout << Form("Finished <Col%d Row%d> = %.1f", ieta, iphi, peak) << endl; TText *t = new TText(.9, .9, Form("<Col%d Row%d> = %.1f", ieta, iphi, peak)); t->SetTextAlign(33); t->SetTextSize(.15); t->SetNDC(); t->Draw(); } } SaveCanvas(c1, TString(_file0->GetName()) + TString("_DrawPrototype3EMCalTower_") + TString(c1->GetName()), false); }
void vs_PlotQCDcomp() { Bool_t saveC = false; Bool_t diJets = true; Bool_t isMC = false; TString vsSave; vsSave = "_T07w"; TString jSave; if(diJets) jSave = "2j"; else jSave = "3j"; TString sample; if(diJets) sample = "select_1ph_2jets"; else sample = "select_1ph_3jets"; TString FOtag; if(isMC) FOtag = "_FO_CorrMC"; // else FOtag = "_FO_Corr"; else FOtag = "_FO"; TString sysu = "SYSTUP_"; TString sysd = "SYSTDOWN_"; TString outDir; outDir = "Plots_PhotonSusyAnalysis/QCDweights/"; // string inputFile1 = "/data/user/vsola/CMSSW_Releases/CMSSW_5_3_9/src/Plots_PhotonSusyAnalysis/Merged_QCD_PhotonJet_T07w_PAT/mergedHistos.root"; // string inputFile1 = "/data/user/vsola/CMSSW_Releases/CMSSW_5_3_9/src/Plots_PhotonSusyAnalysis/Merged_Data_V05w_PAT/mergedHistos.root"; string inputFile1 = "/data/user/vsola/CMSSW_Releases/CMSSW_5_3_9/src/Plots_PhotonSusyAnalysis/PhotonHadReReco_22Jan2013_V05_PAT/mergedHistos.root"; setMyTDRStyle(); gROOT->SetStyle("mytdrStyle"); // gStyle->SetHistMinimumZero(); // gStyle->SetPaintTextFormat("4.2f"); gStyle->SetHistLineWidth(2); gStyle->UseCurrentStyle(); // gStyle->SetPadTopMargin(1.0); // gStyle->SetPadLeftMargin(3.2); // gStyle->SetPadRightMargin(4.5); // gStyle->SetPadBottomMargin(3.2); gROOT->ForceStyle(1); static const Int_t nHt = 7; static const Int_t nPt = 13; static const Int_t nMet = 16; static const Int_t nJet = 15; Double_t binPt[nPt+1] = {0.,75.,90.,120.,160.,210.,260.,320.,400.,500.,650.,800.,1000.,1500.}; Double_t binHt[nHt+1] = {0.,400.,450.,550.,700.,900.,1200.,1500.}; Double_t binMet[nMet+1] = {0.,10.,20.,30.,40.,50.,60.,70.,80.,90.,100.,120.,160.,200.,270.,350.,500.}; Double_t binJet[nJet+1] = {0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15}; TLatex *as = new TLatex(); as->SetNDC(true); as->SetTextColor(12); as->SetTextFont(43); as->SetTextSize(19); TLegend *legend = new TLegend(0.60, 0.70, 0.75, 0.85, ""); legend->SetFillColor(10); legend->SetFillStyle(1001); legend->SetTextSize(0.04); legend->SetBorderSize(0); legend->SetShadowColor(0); std::string outLumi = "CMS Work in Progress - QCD MC #sqrt{s} = 8 TeV - #geq 1 #gamma, #geq 2 j"; TFile* f1 = TFile::Open( inputFile1.c_str() ); //photon Pt TCanvas * cPt = new TCanvas("cPt","cPt"); TH1F* hpt = (TH1F*) f1->Get( sample+"/PreselCut_photonPt" ); TH1F* hptFO = (TH1F*) f1->Get( sample+FOtag+"/PreselCut_photonPt" ); TH1F *hptR = (TH1F*) hpt->Rebin(nPt,hpt->GetTitle(),binPt); if (hptR->GetSumw2N() == 0) hptR->Sumw2(); TH1F *hptFOR = (TH1F*) hptFO->Rebin(nPt,hptFO->GetTitle(),binPt); if (hptFOR->GetSumw2N() == 0) hptFOR->Sumw2(); TH1F* hptSU = (TH1F*) f1->Get( sample+FOtag+"/PreselCut_"+sysu+"photonPt" ); TH1F* hptSD = (TH1F*) f1->Get( sample+FOtag+"/PreselCut_"+sysd+"photonPt" ); TH1F *hptSUR = (TH1F*) hptSU->Rebin(nPt,hptSU->GetTitle(),binPt); if (hptSUR->GetSumw2N() == 0) hptSUR->Sumw2(); TH1F *hptSDR = (TH1F*) hptSD->Rebin(nPt,hptSD->GetTitle(),binPt); if (hptSDR->GetSumw2N() == 0) hptSDR->Sumw2(); if ( hptFOR != 0 ) { for (int b = 0; b < hptFOR->GetNbinsX(); b++) { Double_t mainHistoContent = hptFOR->GetBinContent(b); Double_t systUpHistoContent = hptSUR->GetBinContent(b); Double_t systDnHistoContent = hptSDR->GetBinContent(b); Double_t systDiffUp = fabs( (double) systUpHistoContent - mainHistoContent ); Double_t systDiffDn = fabs( (double) mainHistoContent - systDnHistoContent ); // use average error for histogram Double_t systDiff = ( systDiffUp + systDiffDn ) / 2.; Double_t statErr = hptFOR->GetBinError(b); Double_t combError = sqrt( systDiff * systDiff + statErr * statErr ); hptFOR->SetBinError(b, combError); } //for }//if cPt->SetLogy(1); gPad->Update(); cPt->Update(); // hptR->Scale(1,"width"); // hptR->SetMinimum(0.02); // hptR->SetMaximum(1000); hptR->GetXaxis()->SetTitle("1^{st} photon p_{T} [GeV]"); hptR->GetYaxis()->SetTitle("Number of Events / GeV"); if(isMC) hptR->SetMarkerSize(0); if(isMC) hptR->Draw("histE"); else hptR->Draw("E X0"); hptFOR->SetMarkerSize(0); hptFOR->SetLineColor(2); hptFOR->SetFillColor(2); hptFOR->SetFillStyle(3004); hptFOR->Draw("same hist ][ E2"); legend->Clear(); if(isMC) legend->SetHeader("#gamma/QCD (Sim)"); else legend->SetHeader("#gamma/QCD (Data)"); if(isMC) legend->AddEntry(hptR, "#gamma", "l"); else legend->AddEntry(hptR, "#gamma", "p"); legend->AddEntry(hptFOR, "Pred (from #gamma_{jet})", "f"); legend->Draw(); as->DrawLatex(0.17, 0.93, outLumi.c_str() ); cPt->Update(); cPt->SetBottomMargin(0.2 + 0.8 * cPt->GetBottomMargin() - 0.2 * cPt->GetTopMargin()); TPad *ratioPt = new TPad("BottomPad", "", 0, 0, 1, 1); ratioPt->SetTopMargin(0.8 - 0.8 * ratioPt->GetBottomMargin() + 0.2 * ratioPt->GetTopMargin()); ratioPt->SetFillStyle(0); ratioPt->SetFrameFillColor(10); ratioPt->SetFrameBorderMode(0); ratioPt->Draw(); ratioPt->cd(); ratioPt->SetLogy(0); TH1F *hptRat = (TH1F*) divideHistosForRatio(hptR,hptFOR); hptRat->SetMinimum(0.); hptRat->SetMaximum(10.); hptRat->GetXaxis()->SetNdivisions(505); if(isMC) hptRat->GetYaxis()->SetTitle("Sim/Pred"); else hptRat->GetYaxis()->SetTitle("Data/Pred"); hptRat->GetYaxis()->SetTitleSize(0.04); hptRat->GetYaxis()->SetLabelSize(0.03); hptRat->GetYaxis()->SetTitleOffset(1.3); hptRat->GetYaxis()->SetNdivisions(505); hptRat->SetMarkerStyle(20); hptRat->SetMarkerSize(1); hptRat->SetMarkerColor(1); hptRat->SetLineColor(1); hptRat->Draw("E X0"); TH1F *hptFRat = (TH1F*) getSystErrForRatio(hptFOR); hptFRat->SetLineColor(2); hptFRat->SetFillColor(2); hptFRat->SetFillStyle(3004); hptFRat->Draw("same hist ][ E2"); TLine * line = new TLine( hptRat->GetXaxis()->GetXmin(), 1., hptRat->GetXaxis()->GetXmax(), 1. ); line->SetLineColor(1); line->SetLineWidth(0.5); line->SetLineStyle(1); line->Draw("same"); hptR->GetXaxis()->SetLabelSize(0); hptR->GetXaxis()->SetTitle(""); cPt->RedrawAxis(); gPad->Update(); cPt->Update(); return; }
void QA_Draw_CEMC_G4Hit( const char *qa_file_name_new = "/phenix/u/jinhuang/links/ePHENIX_work/sPHENIX_work/production_analysis_updates/spacal1d/fieldmap/G4Hits_sPHENIX_pi-_eta0.30_32GeV-0000.root_qa.root", const char *qa_file_name_ref = "/phenix/u/jinhuang/links/ePHENIX_work/sPHENIX_work/production_analysis_updates/spacal1d/fieldmap/G4Hits_sPHENIX_pi+_eta0.30_32GeV-0000.root_qa.root") { SetsPhenixStyle(); TVirtualFitter::SetDefaultFitter("Minuit2"); TFile *qa_file_new = new TFile(qa_file_name_new); assert(qa_file_new->IsOpen()); TFile *qa_file_ref = NULL; if (qa_file_name_ref) { qa_file_ref = new TFile(qa_file_name_ref); assert(qa_file_ref->IsOpen()); } TCanvas *c1 = new TCanvas("QA_Draw_CEMC_G4Hit", "QA_Draw_CEMC_G4Hit", 1800, 900); c1->Divide(4, 2); int idx = 1; TPad *p; p = (TPad *) c1->cd(idx++); c1->Update(); p->SetLogz(); TH2F *h_QAG4Sim_CEMC_G4Hit_XY = (TH2F *) qa_file_new->GetObjectChecked( "h_QAG4Sim_CEMC_G4Hit_XY", "TH2F"); assert(h_QAG4Sim_CEMC_G4Hit_XY); h_QAG4Sim_CEMC_G4Hit_XY->GetYaxis()->SetTitleOffset(1.5); h_QAG4Sim_CEMC_G4Hit_XY->Draw("COLZ"); p = (TPad *) c1->cd(idx++); c1->Update(); p->SetLogz(); TH2F *h_QAG4Sim_CEMC_G4Hit_RZ = (TH2F *) qa_file_new->GetObjectChecked( "h_QAG4Sim_CEMC_G4Hit_RZ", "TH2F"); assert(h_QAG4Sim_CEMC_G4Hit_RZ); h_QAG4Sim_CEMC_G4Hit_RZ->GetYaxis()->SetTitleOffset(1.5); h_QAG4Sim_CEMC_G4Hit_RZ->Draw("COLZ"); p = (TPad *) c1->cd(idx++); c1->Update(); // p->SetLogz(); { TH2F *h_QAG4Sim_CEMC_G4Hit_LateralTruthProjection = (TH2F *) qa_file_new->GetObjectChecked( "h_QAG4Sim_CEMC_G4Hit_LateralTruthProjection", "TH2F"); assert(h_QAG4Sim_CEMC_G4Hit_LateralTruthProjection); TH1D *proj_new = h_QAG4Sim_CEMC_G4Hit_LateralTruthProjection->ProjectionX( "qa_file_new_h_QAG4Sim_CEMC_G4Hit_LateralTruthProjection_px"); proj_new->Scale(1. / proj_new->GetSum()); TH1D *proj_ref = NULL; if (qa_file_ref) { TH2F *h_QAG4Sim_CEMC_G4Hit_LateralTruthProjection = (TH2F *) qa_file_ref->GetObjectChecked( "h_QAG4Sim_CEMC_G4Hit_LateralTruthProjection", "TH2F"); assert(h_QAG4Sim_CEMC_G4Hit_LateralTruthProjection); proj_ref = h_QAG4Sim_CEMC_G4Hit_LateralTruthProjection->ProjectionX( "qa_file_ref_h_QAG4Sim_CEMC_G4Hit_LateralTruthProjection_px"); proj_ref->Scale(1. / proj_ref->GetSum()); } proj_new->GetYaxis()->SetTitle("Normalized energy distribution"); proj_new->GetXaxis()->SetRangeUser(-10, 10); DrawReference(proj_new, proj_ref); } p = (TPad *) c1->cd(idx++); c1->Update(); // p->SetLogz(); { TH2F *h_QAG4Sim_CEMC_G4Hit_LateralTruthProjection = (TH2F *) qa_file_new->GetObjectChecked( "h_QAG4Sim_CEMC_G4Hit_LateralTruthProjection", "TH2F"); assert(h_QAG4Sim_CEMC_G4Hit_LateralTruthProjection); TH1D *proj_new = h_QAG4Sim_CEMC_G4Hit_LateralTruthProjection->ProjectionY( "qa_file_new_h_QAG4Sim_CEMC_G4Hit_LateralTruthProjection_py"); proj_new->Scale(1. / proj_new->GetSum()); TH1D *proj_ref = NULL; if (qa_file_ref) { TH2F *h_QAG4Sim_CEMC_G4Hit_LateralTruthProjection = (TH2F *) qa_file_ref->GetObjectChecked( "h_QAG4Sim_CEMC_G4Hit_LateralTruthProjection", "TH2F"); assert(h_QAG4Sim_CEMC_G4Hit_LateralTruthProjection); proj_ref = h_QAG4Sim_CEMC_G4Hit_LateralTruthProjection->ProjectionY( "qa_file_ref_h_QAG4Sim_CEMC_G4Hit_LateralTruthProjection_py"); proj_ref->Scale(1. / proj_ref->GetSum()); } proj_new->GetYaxis()->SetTitle("Normalized energy distribution"); proj_new->GetXaxis()->SetRangeUser(-10, 10); DrawReference(proj_new, proj_ref); } p = (TPad *) c1->cd(idx++); c1->Update(); p->SetLogx(); p->SetLogy(); { TH1F *h_new = (TH1F *) qa_file_new->GetObjectChecked( "h_QAG4Sim_CEMC_G4Hit_HitTime", "TH1F"); assert(h_new); h_new->Rebin(5); h_new->Scale(1. / h_new->GetSum()); TH1F *h_ref = NULL; if (qa_file_ref) { h_ref = (TH1F *) qa_file_ref->GetObjectChecked( "h_QAG4Sim_CEMC_G4Hit_HitTime", "TH1F"); assert(h_ref); h_ref->Rebin(5); h_ref->Scale(1. / h_ref->GetSum()); } h_new->GetYaxis()->SetTitleOffset(1.5); h_new->GetYaxis()->SetTitle("Normalized energy per bin"); // h_new->GetXaxis()->SetRangeUser(-0, .1); DrawReference(h_new, h_ref); } p = (TPad *) c1->cd(idx++); c1->Update(); // p->SetLogx(); p->SetLogy(); { TH1F *h_new = (TH1F *) qa_file_new->GetObjectChecked( "h_QAG4Sim_CEMC_G4Hit_FractionTruthEnergy", "TH1F"); assert(h_new); h_new->Rebin(20); h_new->Sumw2(); h_new->Scale(1. / h_new->GetSum()); TH1F *h_ref = NULL; if (qa_file_ref) { h_ref = (TH1F *) qa_file_ref->GetObjectChecked( "h_QAG4Sim_CEMC_G4Hit_FractionTruthEnergy", "TH1F"); assert(h_ref); h_ref->Rebin(20); h_ref->Scale(1. / h_ref->GetSum()); } h_new->GetYaxis()->SetTitleOffset(1.5); h_new->GetYaxis()->SetTitle("Probability per bin"); // h_new->GetXaxis()->SetRangeUser(-0, .1); DrawReference(h_new, h_ref); } p = (TPad *) c1->cd(idx++); c1->Update(); // p->SetLogz(); { TH1F *h_new = (TH1F *) qa_file_new->GetObjectChecked( "h_QAG4Sim_CEMC_G4Hit_VSF", "TH1F"); assert(h_new); h_new->Rebin(2); h_new->Sumw2(); h_new->Scale(1. / h_new->GetSum()); TH1F *h_ref = NULL; if (qa_file_ref) { h_ref = (TH1F *) qa_file_ref->GetObjectChecked( "h_QAG4Sim_CEMC_G4Hit_VSF", "TH1F"); assert(h_ref); h_ref->Rebin(2); h_ref->Sumw2(); h_ref->Scale(1. / h_ref->GetSum()); } h_new->GetYaxis()->SetTitleOffset(1.5); h_new->GetYaxis()->SetTitle("Probability per bin"); h_new->GetXaxis()->SetRangeUser(-0, .1); DrawReference(h_new, h_ref); } p = (TPad *) c1->cd(idx++); c1->Update(); // p->SetLogz(); { TH1F *h_new = (TH1F *) qa_file_new->GetObjectChecked( "h_QAG4Sim_CEMC_G4Hit_FractionEMVisibleEnergy", "TH1F"); assert(h_new); h_new->Rebin(4); h_new->Sumw2(); h_new->Scale(1. / h_new->GetSum()); TH1F *h_ref = NULL; if (qa_file_ref) { h_ref = (TH1F *) qa_file_ref->GetObjectChecked( "h_QAG4Sim_CEMC_G4Hit_FractionEMVisibleEnergy", "TH1F"); assert(h_ref); h_ref->Rebin(4); h_ref->Scale(1. / h_ref->GetSum()); } h_new->GetYaxis()->SetTitleOffset(1.5); h_new->GetYaxis()->SetTitle("Probability per bin"); // h_new->GetXaxis()->SetRangeUser(-0, .1); DrawReference(h_new, h_ref); } // PutInputFileName(c1, .04, qa_file_name_new, qa_file_name_ref); SaveCanvas(c1, TString(qa_file_name_new) + TString(c1->GetName()), true); }
void QA_Draw_Calorimeter_Sum_TrackProjEP( const char * qa_file_name_new = "/phenix/u/jinhuang/links/ePHENIX_work/sPHENIX_work/production_analysis_updates/spacal1d/fieldmap/G4Hits_sPHENIX_pi-_eta0.30_32GeV-0000.root_qa.root", const char * qa_file_name_ref = "/phenix/u/jinhuang/links/ePHENIX_work/sPHENIX_work/production_analysis_updates/spacal1d/fieldmap/G4Hits_sPHENIX_pi+_eta0.30_32GeV-0000.root_qa.root") //QA_Draw_Calorimeter_Sum_TrackProjEP(const char * qa_file_name_new = // "data/G4sPHENIXCells_100e24GeV.root_qa.root", // const char * qa_file_name_ref = // "data/G4Hits_sPHENIX_e-_eta0_24GeV-0000.root_qa.root") { SetOKStyle(); gStyle->SetOptStat(0); gStyle->SetOptFit(1111); TVirtualFitter::SetDefaultFitter("Minuit2"); TFile * qa_file_new = new TFile(qa_file_name_new); assert(qa_file_new->IsOpen()); TFile * qa_file_ref = NULL; if (qa_file_name_ref) { qa_file_ref = new TFile(qa_file_name_ref); assert(qa_file_ref->IsOpen()); } // obtain normalization double Nevent_new = 1; double Nevent_ref = 1; // obtain normalization double Ntrack_new = 0; double Ntrack_ref = 0; if (qa_file_new) { TH1D * h_norm = (TH1D *) qa_file_new->GetObjectChecked( TString("h_QAG4Sim_CalorimeterSum_Normalization"), "TH1D"); assert(h_norm); Nevent_new = h_norm->GetBinContent(h_norm->GetXaxis()->FindBin("Event")); Ntrack_new = h_norm->GetBinContent(h_norm->GetXaxis()->FindBin("Track")); } if (qa_file_ref) { TH1D * h_norm = (TH1D *) qa_file_ref->GetObjectChecked( TString("h_QAG4Sim_CalorimeterSum_Normalization"), "TH1D"); assert(h_norm); Nevent_ref = h_norm->GetBinContent(h_norm->GetXaxis()->FindBin("Event")); Ntrack_ref = h_norm->GetBinContent(h_norm->GetXaxis()->FindBin("Track")); } TCanvas *c1 = new TCanvas("QA_Draw_Calorimeter_Sum_TrackProjEP", "QA_Draw_Calorimeter_Sum_TrackProjEP", 1800, 600); c1->Divide(3, 1); int idx = 1; TPad * p; p = (TPad *) c1->cd(idx++); c1->Update(); p->SetLogy(); if (Ntrack_new>0) { TH1F * h_new = (TH1F *) qa_file_new->GetObjectChecked( "h_QAG4Sim_CalorimeterSum_TrackProj_3x3Tower_EP", "TH1F"); assert(h_new); h_new->Sumw2(); h_new->Scale(1. / Ntrack_new); TH1F * h_ref = NULL; if (qa_file_ref) { TH1F * h_ref = (TH1F *) qa_file_ref->GetObjectChecked( "h_QAG4Sim_CalorimeterSum_TrackProj_3x3Tower_EP", "TH1F"); assert(h_ref); h_ref->Scale(1. / Ntrack_ref); } h_new->GetYaxis()->SetTitleOffset(1.5); h_new->GetYaxis()->SetTitle("Count / track / bin"); // h_new->GetXaxis()->SetRangeUser(-0, .1); DrawReference(h_new, h_ref); } p = (TPad *) c1->cd(idx++); c1->Update(); p->SetLogy(); if (Ntrack_new>0) { TH1F * h_new = (TH1F *) qa_file_new->GetObjectChecked( "h_QAG4Sim_CalorimeterSum_TrackProj_5x5Tower_EP", "TH1F"); assert(h_new); h_new->Sumw2(); h_new->Scale(1. / Ntrack_new); TH1F * h_ref = NULL; if (qa_file_ref) { TH1F * h_ref = (TH1F *) qa_file_ref->GetObjectChecked( "h_QAG4Sim_CalorimeterSum_TrackProj_5x5Tower_EP", "TH1F"); assert(h_ref); h_ref->Scale(1. / Ntrack_ref); } h_new->GetYaxis()->SetTitleOffset(1.5); h_new->GetYaxis()->SetTitle("Count / track / bin"); // h_new->GetXaxis()->SetRangeUser(-0, .1); DrawReference(h_new, h_ref); } p = (TPad *) c1->cd(idx++); c1->Update(); p->SetLogy(); if (Nevent_new>0) { TH1F * h_new = (TH1F *) qa_file_new->GetObjectChecked( "h_QAG4Sim_CalorimeterSum_Cluster_EP", "TH1F"); if (h_new) { h_new->Sumw2(); h_new->Scale(1. / Nevent_new); TH1F * h_ref = NULL; if (qa_file_ref) { TH1F * h_ref = (TH1F *) qa_file_ref->GetObjectChecked( "h_QAG4Sim_CalorimeterSum_Cluster_EP", "TH1F"); assert(h_ref); h_ref->Scale(1. / Nevent_ref); } h_new->GetYaxis()->SetTitleOffset(1.5); h_new->GetYaxis()->SetTitle("Count / event / bin"); // h_new->GetXaxis()->SetRangeUser(-0, .1); DrawReference(h_new, h_ref); } } PutInputFileName(c1,0.07, qa_file_name_new, qa_file_name_ref); SaveCanvas(c1, TString(qa_file_name_new) + TString(c1->GetName()), true); }
void determineWorkingPoint(TString algo="csv",TString baseURL="~/scratch0/top-nosyst/plotter.root") { float workPoint(0.244); float sfb(1.020), sfberr(0.04); //from BTV-11-003 float sflight(1.08), sflighterr(0.13); //from BTV-11-002 // float sfb(0.99), sfberr(0.099); //from BTV-11-001 // float sflight(1.07882), sflighterr(0.244); //from BTV-11-001 if(algo=="tche") { workPoint=1.7; sfb=0.95; sfberr=0.095; sflight=1.08018; sflighterr=0.1125; } TObjArray bjets=getDistributionFromPlotter(algo+"b",baseURL); TObjArray lightjets=getDistributionFromPlotter(algo+"light",baseURL); TH1F *bDisc=(TH1F *) bjets.At(1); TH1F *lightDisc=(TH1F *) lightjets.At(1); setStyle(); gStyle->SetOptFit(0); TCanvas *cnv = getNewCanvas("c","c",false); cnv->Clear(); cnv->SetCanvasSize(1200,1200); cnv->SetWindowSize(1200,1200); cnv->Divide(2,2); //draw the discriminator TPad *p = (TPad *)cnv->cd(1); bDisc->SetTitle("b"); bDisc->SetLineColor(1); bDisc->SetMarkerColor(1); bDisc->SetMarkerStyle(20); bDisc->SetFillStyle(0); bDisc->DrawNormalized("histe1"); lightDisc->SetLineColor(1); lightDisc->SetMarkerColor(1); lightDisc->SetMarkerStyle(24); lightDisc->SetFillStyle(0); lightDisc->SetTitle("udcsg"); lightDisc->DrawNormalized("histe1same"); TLegend *leg=p->BuildLegend(); formatForCmsPublic(p,leg,"CMS simulation",2); //draw the b/light efficiencies p=(TPad *)cnv->cd(2); p->SetLogy(); TGraphAsymmErrors *bEff = getEfficiencyFrom(bDisc); TGraphAsymmErrors *lightEff = getEfficiencyFrom(lightDisc); bEff->SetMarkerStyle(20); bEff->SetFillStyle(0); bEff->Draw("ap"); bEff->GetXaxis()->SetTitle(bDisc->GetXaxis()->GetTitle()); bEff->GetYaxis()->SetTitle("Efficiency"); lightEff->SetMarkerStyle(24); lightEff->SetFillStyle(0); lightEff->Draw("p"); //draw relatively to a given working point p=(TPad *)cnv->cd(3); Double_t baseBEff=bEff->Eval(workPoint); TGraphAsymmErrors *relBEff=new TGraphAsymmErrors; relBEff->SetMarkerStyle(20); relBEff->SetFillStyle(0); Double_t baseLightEff=lightEff->Eval(workPoint); TGraphAsymmErrors *relLightEff=new TGraphAsymmErrors; relLightEff->SetMarkerStyle(24); relLightEff->SetFillStyle(0); for(int ip=0; ip<bEff->GetN(); ip++) { Double_t cut, y,ey; bEff->GetPoint(ip,cut,y); ey = bEff->GetErrorY(ip); Double_t relEff(y/baseBEff); if(relEff<sfb+2*sfberr && relEff>sfb-2*sfberr) { int ipt=relBEff->GetN(); relBEff->SetPoint(ipt,cut,relEff); relBEff->SetPointError(ipt,0,0,ey/baseBEff,ey/baseBEff); } lightEff->GetPoint(ip,cut,y); ey = lightEff->GetErrorY(ip); relEff=y/baseLightEff; // if(relEff<sflight+7*sflighterr && relEff>sflight-7*sflighterr) if(relEff<sflight+3*sflighterr && relEff>sflight-3*sflighterr) { int ipt=relLightEff->GetN(); relLightEff->SetPoint(ipt,cut,relEff); relLightEff->SetPointError(ipt,0,0,ey/baseLightEff,ey/baseLightEff); } } relLightEff->Draw("ap"); relLightEff->GetXaxis()->SetTitle( bDisc->GetXaxis()->GetTitle() ); relLightEff->GetYaxis()->SetTitle( "#varepsilon/#varepsilon_{0}" ); relLightEff->Fit("expo","Q+"); TF1 *ffunc=relLightEff->GetFunction("expo"); float newLightCut=(TMath::Log(sflight)-ffunc->GetParameter(0))/ffunc->GetParameter(1); float newLightCutErrPlus=(TMath::Log(sflight+sflighterr)-ffunc->GetParameter(0))/ffunc->GetParameter(1)-newLightCut; float newLightCutErrMinus=(TMath::Log(sflight-sflighterr)-ffunc->GetParameter(0))/ffunc->GetParameter(1)-newLightCut; TArrow *lightArrow = new TArrow(newLightCut, sflight-3*sflighterr, newLightCut, sflight-3*sflighterr*0.8, 0.02, "<|"); lightArrow->SetLineColor(kGray+2); lightArrow->SetFillColor(kGray+2); lightArrow->Draw("SAME <|"); relBEff->Draw("p"); relBEff->Fit("expo","Q+"); ffunc=relBEff->GetFunction("expo"); float newBCut=(TMath::Log(sfb)-ffunc->GetParameter(0))/ffunc->GetParameter(1); float newBCutErrPlus=(TMath::Log(sfb+sfberr)-ffunc->GetParameter(0))/ffunc->GetParameter(1)-newBCut; float newBCutErrMinus=(TMath::Log(sfb-sfberr)-ffunc->GetParameter(0))/ffunc->GetParameter(1)-newBCut; cout << sfb << " " << sfb+sfberr << " " << sfb-sfberr << endl; TArrow *bArrow = new TArrow(newBCut, sflight-3*sflighterr, newBCut, sflight-3*sflighterr*0.8, 0.02, "<|"); bArrow->Draw("SAME <|"); //draw epsilon_b vs epsilon_q p=(TPad *)cnv->cd(4); p->SetLogy(); TGraphAsymmErrors *perf=new TGraphAsymmErrors; perf->SetName("algoperformance"); perf->SetMarkerStyle(20); perf->SetFillStyle(0); for(int ip=0; ip<bEff->GetN(); ip++) { Double_t cut; Double_t x,ex; bEff->GetPoint(ip,cut,x); ex = bEff->GetErrorY(ip); Double_t y,ey; lightEff->GetPoint(ip,cut,y); ey = lightEff->GetErrorY(ip); perf->SetPoint(ip,x,y); perf->SetPointError(ip,ex,ex,ey,ey); } perf->Draw("ap"); perf->GetXaxis()->SetTitle( bEff->GetTitle() ); perf->GetYaxis()->SetTitle( lightEff->GetTitle() ); //new performance expected after applying the new cuts TGraphAsymmErrors *newperf=new TGraphAsymmErrors; newperf->SetName("newalgoperformance"); newperf->SetMarkerStyle(24); newperf->SetFillStyle(0); newperf->SetLineWidth(2); newperf->SetLineColor(kRed); newperf->SetLineColor(kRed); newperf->SetPoint(0,baseBEff*sfb,baseLightEff*sflight); newperf->SetPointError(0,baseBEff*sfberr,baseBEff*sfberr,baseLightEff*sflighterr,baseLightEff*sflighterr); newperf->Draw("p"); cnv->Modified(); cnv->Update(); cnv->SaveAs("discFlavor.C"); cnv->SaveAs("discFlavor.png"); cout << "[determineWorkingPoint]" << endl << "To emulate the measured scale-factors you can use the following new cuts per jet flavor" << endl << "SF-b : " << newBCut << " +" << newBCutErrPlus << " " << newBCutErrMinus << endl << "SF-light : " << newLightCut << " +" << newLightCutErrPlus << " " << newLightCutErrMinus << endl; }
void limit() { //=========Macro generated from canvas: limit/limit //========= (Thu Apr 27 14:38:33 2017) by ROOT version6.02/05 TCanvas *limit = new TCanvas("limit", "limit",0,0,600,600); gStyle->SetOptFit(1); gStyle->SetOptStat(0); gStyle->SetOptTitle(0); limit->SetHighLightColor(2); limit->Range(0,0,1,1); limit->SetFillColor(0); limit->SetBorderMode(0); limit->SetBorderSize(2); limit->SetLeftMargin(0.16); limit->SetRightMargin(0.04); limit->SetTopMargin(0.06); limit->SetBottomMargin(0.12); limit->SetFrameFillStyle(0); limit->SetFrameBorderMode(0); // ------------>Primitives in pad: pad TPad *pad = new TPad("pad", "pad",0,0,1,1); pad->Draw(); pad->cd(); pad->Range(-59.99999,-2.046818,1565,15.01); pad->SetFillColor(0); pad->SetBorderMode(0); pad->SetLogy(); pad->SetBorderSize(2); pad->SetTickx(1); pad->SetTicky(1); pad->SetLeftMargin(0.16); pad->SetRightMargin(0.04); pad->SetTopMargin(0.06); pad->SetBottomMargin(0.12); pad->SetFrameFillStyle(0); pad->SetFrameBorderMode(0); pad->SetFrameFillStyle(0); pad->SetFrameBorderMode(0); TH1F *tmp01 = new TH1F("tmp01","Graph",100,200,1500); tmp01->SetMinimum(0.); tmp01->SetMaximum(13.98659); tmp01->SetStats(0); tmp01->SetLineStyle(0); tmp01->SetMarkerStyle(20); tmp01->GetXaxis()->SetTitle("m_{H} (GeV)"); tmp01->GetXaxis()->SetLabelFont(42); tmp01->GetXaxis()->SetLabelOffset(0.01); tmp01->GetXaxis()->SetTitleSize(0.05); tmp01->GetXaxis()->SetTickLength(0.02); tmp01->GetXaxis()->SetTitleOffset(1.08); tmp01->GetXaxis()->SetTitleFont(42); tmp01->GetYaxis()->SetTitle("95% CL limit on #sigma/#sigma_{SM}"); tmp01->GetYaxis()->SetLabelFont(42); tmp01->GetYaxis()->SetLabelOffset(0.007); tmp01->GetYaxis()->SetTitleSize(0.05); tmp01->GetYaxis()->SetTickLength(0.02); tmp01->GetYaxis()->SetTitleOffset(1.56); tmp01->GetYaxis()->SetTitleFont(42); tmp01->GetZaxis()->SetLabelFont(42); tmp01->GetZaxis()->SetLabelOffset(0.007); tmp01->GetZaxis()->SetTitleSize(0.05); tmp01->GetZaxis()->SetTickLength(0.02); tmp01->GetZaxis()->SetTitleFont(42); tmp01->Draw("AXIS"); TH1F *tmp02 = new TH1F("tmp02","Graph",100,200,1500); tmp02->SetMinimum(0); tmp02->SetMaximum(13.98659); tmp02->SetStats(0); tmp02->SetLineStyle(0); tmp02->SetMarkerStyle(20); tmp02->GetXaxis()->SetTitle("m_{H} (GeV)"); tmp02->GetXaxis()->SetLabelFont(42); tmp02->GetXaxis()->SetLabelOffset(0.01); tmp02->GetXaxis()->SetTitleSize(0.05); tmp02->GetXaxis()->SetTickLength(0.02); tmp02->GetXaxis()->SetTitleOffset(1.08); tmp02->GetXaxis()->SetTitleFont(42); tmp02->GetYaxis()->SetTitle("95% CL limit on #sigma/#sigma_{SM}"); tmp02->GetYaxis()->SetLabelFont(42); tmp02->GetYaxis()->SetLabelOffset(0.007); tmp02->GetYaxis()->SetTitleSize(0.05); tmp02->GetYaxis()->SetTickLength(0.02); tmp02->GetYaxis()->SetTitleOffset(1.56); tmp02->GetYaxis()->SetTitleFont(42); tmp02->GetZaxis()->SetLabelFont(42); tmp02->GetZaxis()->SetLabelOffset(0.007); tmp02->GetZaxis()->SetTitleSize(0.05); tmp02->GetZaxis()->SetTickLength(0.02); tmp02->GetZaxis()->SetTitleFont(42); tmp02->Draw("AXIGSAME"); Double_t Graph0_fx3001[27] = { 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1050, 1100, 1150, 1200, 1250, 1300, 1350, 1400, 1450, 1500}; Double_t Graph0_fy3001[27] = { 4.796875, 2.148438, 0.8398438, 0.3857422, 0.2001953, 0.1088867, 0.06591797, 0.04736328, 0.03564453, 0.02783203, 0.02294922, 0.01806641, 0.01513672, 0.01220703, 0.01123047, 0.009277344, 0.008300781, 0.007324219, 0.007324219, 0.006347656, 0.006347656, 0.005371094, 0.005371094, 0.004394531, 0.004394531, 0.004394531, 0.004394531}; Double_t Graph0_felx3001[27] = { 4.032346e-316, 0, 0, 0, 6.906313e-310, 4.032343e-316, 2.121996e-314, 4.032582e-316, 0, 4.032588e-316, 4.032343e-316, 0, 4.032584e-316, 1.508018e-316, 1.508219e-316, 4.032589e-316, 2.124327e-314, 4.032593e-316, 5.582942e-322, 6.906313e-310, 0, 4.032344e-316, 4.032583e-316, 4.032588e-316, 1.58101e-322, 4.032293e-316, 5.582942e-322}; Double_t Graph0_fely3001[27] = { 2.370331, 1.057434, 0.405159, 0.1845837, 0.09618759, 0.05231667, 0.03192902, 0.02331161, 0.01754379, 0.01435089, 0.01183319, 0.009315491, 0.008041382, 0.006484985, 0.005966187, 0.004928589, 0.00440979, 0.004119873, 0.004119873, 0.003570557, 0.003570557, 0.00302124, 0.00302124, 0.002471924, 0.002471924, 0.002471924, 0.002471924}; Double_t Graph0_fehx3001[27] = { 4.031643e-316, 0, 0, 0, 6.906313e-310, 4.032106e-316, 2.121996e-314, 4.032349e-316, 0, 4.032354e-316, 4.032106e-316, 0, 4.032351e-316, 1.508018e-316, 1.508219e-316, 4.032356e-316, 2.124327e-314, 4.03236e-316, 5.582942e-322, 6.906313e-310, 0, 4.032107e-316, 4.03235e-316, 4.032354e-316, 1.58101e-322, 4.032222e-316, 5.582942e-322}; Double_t Graph0_fehy3001[27] = { 5.693069, 2.47175, 0.8989364, 0.4081147, 0.2108151, 0.1170805, 0.07362081, 0.05438244, 0.04146756, 0.03243252, 0.02825768, 0.02361592, 0.01990321, 0.01752287, 0.01712826, 0.0153559, 0.01456667, 0.01341494, 0.01192601, 0.0124739, 0.01149977, 0.01055484, 0.01051202, 0.008670811, 0.008670811, 0.008635777, 0.008635777}; TGraphAsymmErrors *grae = new TGraphAsymmErrors(27,Graph0_fx3001,Graph0_fy3001,Graph0_felx3001,Graph0_fehx3001,Graph0_fely3001,Graph0_fehy3001); grae->SetName("Graph0"); grae->SetTitle("Graph"); Int_t ci; // for color index setting TColor *color; // for color definition with alpha ci = TColor::GetColor("#ffff00"); grae->SetFillColor(ci); grae->SetMarkerStyle(20); TH1F *Graph_Graph3001 = new TH1F("Graph_Graph3001","Graph",100,70,1630); Graph_Graph3001->SetMinimum(0); Graph_Graph3001->SetMaximum(11.53875); Graph_Graph3001->SetDirectory(0); Graph_Graph3001->SetStats(0); Graph_Graph3001->SetLineStyle(0); Graph_Graph3001->SetMarkerStyle(20); Graph_Graph3001->GetXaxis()->SetLabelFont(42); Graph_Graph3001->GetXaxis()->SetTitleSize(0.05); Graph_Graph3001->GetXaxis()->SetTickLength(0.02); Graph_Graph3001->GetXaxis()->SetTitleOffset(1.08); Graph_Graph3001->GetXaxis()->SetTitleFont(42); Graph_Graph3001->GetYaxis()->SetLabelFont(42); Graph_Graph3001->GetYaxis()->SetLabelOffset(0.007); Graph_Graph3001->GetYaxis()->SetTitleSize(0.05); Graph_Graph3001->GetYaxis()->SetTickLength(0.02); Graph_Graph3001->GetYaxis()->SetTitleOffset(1.56); Graph_Graph3001->GetYaxis()->SetTitleFont(42); Graph_Graph3001->GetZaxis()->SetLabelFont(42); Graph_Graph3001->GetZaxis()->SetLabelOffset(0.007); Graph_Graph3001->GetZaxis()->SetTitleSize(0.05); Graph_Graph3001->GetZaxis()->SetTickLength(0.02); Graph_Graph3001->GetZaxis()->SetTitleFont(42); grae->SetHistogram(Graph_Graph3001); grae->Draw("3"); Double_t Graph1_fx3002[27] = { 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1050, 1100, 1150, 1200, 1250, 1300, 1350, 1400, 1450, 1500}; Double_t Graph1_fy3002[27] = { 4.796875, 2.148438, 0.8398438, 0.3857422, 0.2001953, 0.1088867, 0.06591797, 0.04736328, 0.03564453, 0.02783203, 0.02294922, 0.01806641, 0.01513672, 0.01220703, 0.01123047, 0.009277344, 0.008300781, 0.007324219, 0.007324219, 0.006347656, 0.006347656, 0.005371094, 0.005371094, 0.004394531, 0.004394531, 0.004394531, 0.004394531}; Double_t Graph1_felx3002[27] = { 4.028644e-316, 2.608667e-321, 4.022558e-316, 0, 2.420922e-322, 4.028601e-316, 0, 2.11372e-314, 0, 4.940656e-323, 8.744962e-322, 0, 0, 4.940656e-323, 0, 6.906314e-310, 5.33769e+160, 0, 4.021573e-316, 6.906314e-310, 0, 1.188318e-312, 4.027998e-316, 0, 1.58101e-322, 4.027629e-316, 1.630417e-322}; Double_t Graph1_fely3002[27] = { 1.490716, 0.6650269, 0.2516418, 0.1146438, 0.05974151, 0.03228919, 0.01945674, 0.01420552, 0.01069075, 0.009417772, 0.007765532, 0.006113291, 0.005277157, 0.003647804, 0.00335598, 0.002772331, 0.002480507, 0.002317429, 0.002832413, 0.002231598, 0.002231598, 0.001888275, 0.001888275, 0.001544952, 0.001544952, 0.001544952, 0.002162933}; Double_t Graph1_fehx3002[27] = { 1.179415e-312, 2.608667e-321, 4.022558e-316, 0, 2.420922e-322, 4.028634e-316, 0, 2.113722e-314, 0, 4.940656e-323, 8.744962e-322, 0, 0, 4.940656e-323, 0, 6.906314e-310, 2.139459e+161, 0, 4.021573e-316, 6.906314e-310, 0, 1.188318e-312, 4.027998e-316, 0, 1.58101e-322, 4.027675e-316, 1.630417e-322}; Double_t Graph1_fehy3002[27] = { 2.351828, 1.053343, 0.3849801, 0.1768222, 0.09017253, 0.05078118, 0.03126747, 0.02303264, 0.01790216, 0.012869, 0.0113431, 0.009505779, 0.008205643, 0.007395977, 0.0068043, 0.006212621, 0.006088058, 0.005138258, 0.004204029, 0.005262822, 0.003643492, 0.004453157, 0.003768056, 0.004204029, 0.004204029, 0.003643492, 0.003643492}; grae = new TGraphAsymmErrors(27,Graph1_fx3002,Graph1_fy3002,Graph1_felx3002,Graph1_fehx3002,Graph1_fely3002,Graph1_fehy3002); grae->SetName("Graph1"); grae->SetTitle("Graph"); ci = TColor::GetColor("#00ff00"); grae->SetFillColor(ci); grae->SetMarkerStyle(20); TH1F *Graph_Graph3002 = new TH1F("Graph_Graph3002","Graph",100,-8.010917e+160,2.406781e+161); Graph_Graph3002->SetMinimum(0); Graph_Graph3002->SetMaximum(7.86335); Graph_Graph3002->SetDirectory(0); Graph_Graph3002->SetStats(0); Graph_Graph3002->SetLineStyle(0); Graph_Graph3002->SetMarkerStyle(20); Graph_Graph3002->GetXaxis()->SetLabelFont(42); Graph_Graph3002->GetXaxis()->SetTitleSize(0.05); Graph_Graph3002->GetXaxis()->SetTickLength(0.02); Graph_Graph3002->GetXaxis()->SetTitleOffset(1.08); Graph_Graph3002->GetXaxis()->SetTitleFont(42); Graph_Graph3002->GetYaxis()->SetLabelFont(42); Graph_Graph3002->GetYaxis()->SetLabelOffset(0.007); Graph_Graph3002->GetYaxis()->SetTitleSize(0.05); Graph_Graph3002->GetYaxis()->SetTickLength(0.02); Graph_Graph3002->GetYaxis()->SetTitleOffset(1.56); Graph_Graph3002->GetYaxis()->SetTitleFont(42); Graph_Graph3002->GetZaxis()->SetLabelFont(42); Graph_Graph3002->GetZaxis()->SetLabelOffset(0.007); Graph_Graph3002->GetZaxis()->SetTitleSize(0.05); Graph_Graph3002->GetZaxis()->SetTickLength(0.02); Graph_Graph3002->GetZaxis()->SetTitleFont(42); grae->SetHistogram(Graph_Graph3002); grae->Draw("3"); Double_t Graph2_fx1[27] = { 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1050, 1100, 1150, 1200, 1250, 1300, 1350, 1400, 1450, 1500}; Double_t Graph2_fy1[27] = { 4.796875, 2.148438, 0.8398438, 0.3857422, 0.2001953, 0.1088867, 0.06591797, 0.04736328, 0.03564453, 0.02783203, 0.02294922, 0.01806641, 0.01513672, 0.01220703, 0.01123047, 0.009277344, 0.008300781, 0.007324219, 0.007324219, 0.006347656, 0.006347656, 0.005371094, 0.005371094, 0.004394531, 0.004394531, 0.004394531, 0.004394531}; TGraph *graph = new TGraph(27,Graph2_fx1,Graph2_fy1); graph->SetName("Graph2"); graph->SetTitle("Graph"); graph->SetFillColor(1); ci = TColor::GetColor("#ff0000"); graph->SetLineColor(ci); graph->SetLineWidth(2); graph->SetMarkerStyle(20); TH1F *Graph_Graph1 = new TH1F("Graph_Graph1","Graph",100,70,1630); Graph_Graph1->SetMinimum(0); Graph_Graph1->SetMaximum(5.276123); Graph_Graph1->SetDirectory(0); Graph_Graph1->SetStats(0); Graph_Graph1->SetLineStyle(0); Graph_Graph1->SetMarkerStyle(20); Graph_Graph1->GetXaxis()->SetLabelFont(42); Graph_Graph1->GetXaxis()->SetTitleSize(0.05); Graph_Graph1->GetXaxis()->SetTickLength(0.02); Graph_Graph1->GetXaxis()->SetTitleOffset(1.08); Graph_Graph1->GetXaxis()->SetTitleFont(42); Graph_Graph1->GetYaxis()->SetLabelFont(42); Graph_Graph1->GetYaxis()->SetLabelOffset(0.007); Graph_Graph1->GetYaxis()->SetTitleSize(0.05); Graph_Graph1->GetYaxis()->SetTickLength(0.02); Graph_Graph1->GetYaxis()->SetTitleOffset(1.56); Graph_Graph1->GetYaxis()->SetTitleFont(42); Graph_Graph1->GetZaxis()->SetLabelFont(42); Graph_Graph1->GetZaxis()->SetLabelOffset(0.007); Graph_Graph1->GetZaxis()->SetTitleSize(0.05); Graph_Graph1->GetZaxis()->SetTickLength(0.02); Graph_Graph1->GetZaxis()->SetTitleFont(42); graph->SetHistogram(Graph_Graph1); graph->Draw("l"); Double_t Graph3_fx2[27] = { 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1050, 1100, 1150, 1200, 1250, 1300, 1350, 1400, 1450, 1500}; Double_t Graph3_fy2[27] = { 4.79203, 2.152691, 0.8377939, 0.3861777, 0.1995838, 0.1090425, 0.0660598, 0.04759021, 0.03596779, 0.02751563, 0.02238263, 0.01815241, 0.01512282, 0.01228406, 0.01162986, 0.009836298, 0.008643669, 0.007866618, 0.007089044, 0.006702567, 0.005960677, 0.005744891, 0.005145786, 0.004956617, 0.004917011, 0.004476165, 0.004343825}; graph = new TGraph(27,Graph3_fx2,Graph3_fy2); graph->SetName("Graph3"); graph->SetTitle("Graph"); graph->SetFillColor(1); graph->SetLineWidth(2); graph->SetMarkerStyle(20); TH1F *Graph_Graph2 = new TH1F("Graph_Graph2","Graph",100,70,1630); Graph_Graph2->SetMinimum(0); Graph_Graph2->SetMaximum(5.270799); Graph_Graph2->SetDirectory(0); Graph_Graph2->SetStats(0); Graph_Graph2->SetLineStyle(0); Graph_Graph2->SetMarkerStyle(20); Graph_Graph2->GetXaxis()->SetLabelFont(42); Graph_Graph2->GetXaxis()->SetTitleSize(0.05); Graph_Graph2->GetXaxis()->SetTickLength(0.02); Graph_Graph2->GetXaxis()->SetTitleOffset(1.08); Graph_Graph2->GetXaxis()->SetTitleFont(42); Graph_Graph2->GetYaxis()->SetLabelFont(42); Graph_Graph2->GetYaxis()->SetLabelOffset(0.007); Graph_Graph2->GetYaxis()->SetTitleSize(0.05); Graph_Graph2->GetYaxis()->SetTickLength(0.02); Graph_Graph2->GetYaxis()->SetTitleOffset(1.56); Graph_Graph2->GetYaxis()->SetTitleFont(42); Graph_Graph2->GetZaxis()->SetLabelFont(42); Graph_Graph2->GetZaxis()->SetLabelOffset(0.007); Graph_Graph2->GetZaxis()->SetTitleSize(0.05); Graph_Graph2->GetZaxis()->SetTickLength(0.02); Graph_Graph2->GetZaxis()->SetTitleFont(42); graph->SetHistogram(Graph_Graph2); graph->Draw("pl"); TH1F *tmp0_copy3 = new TH1F("tmp0_copy3","Graph",100,200,1500); tmp0_copy3->SetMinimum(0); tmp0_copy3->SetMaximum(11.53875); tmp0_copy3->SetDirectory(0); tmp0_copy3->SetStats(0); tmp0_copy3->SetLineStyle(0); tmp0_copy3->SetMarkerStyle(20); tmp0_copy3->GetXaxis()->SetLabelFont(42); tmp0_copy3->GetXaxis()->SetTitleSize(0.05); tmp0_copy3->GetXaxis()->SetTickLength(0.02); tmp0_copy3->GetXaxis()->SetTitleOffset(1.08); tmp0_copy3->GetXaxis()->SetTitleFont(42); tmp0_copy3->GetYaxis()->SetLabelFont(42); tmp0_copy3->GetYaxis()->SetLabelOffset(0.007); tmp0_copy3->GetYaxis()->SetTitleSize(0.05); tmp0_copy3->GetYaxis()->SetTickLength(0.02); tmp0_copy3->GetYaxis()->SetTitleOffset(1.56); tmp0_copy3->GetYaxis()->SetTitleFont(42); tmp0_copy3->GetZaxis()->SetLabelFont(42); tmp0_copy3->GetZaxis()->SetLabelOffset(0.007); tmp0_copy3->GetZaxis()->SetTitleSize(0.05); tmp0_copy3->GetZaxis()->SetTickLength(0.02); tmp0_copy3->GetZaxis()->SetTitleFont(42); tmp0_copy3->Draw("sameaxis"); TH1F *tmp0_copy4 = new TH1F("tmp0_copy4","Graph",100,200,1500); tmp0_copy4->SetMinimum(0); tmp0_copy4->SetMaximum(11.53875); tmp0_copy4->SetDirectory(0); tmp0_copy4->SetStats(0); tmp0_copy4->SetLineStyle(0); tmp0_copy4->SetMarkerStyle(20); tmp0_copy4->GetXaxis()->SetLabelFont(42); tmp0_copy4->GetXaxis()->SetTitleSize(0.05); tmp0_copy4->GetXaxis()->SetTickLength(0.02); tmp0_copy4->GetXaxis()->SetTitleOffset(1.08); tmp0_copy4->GetXaxis()->SetTitleFont(42); tmp0_copy4->GetYaxis()->SetLabelFont(42); tmp0_copy4->GetYaxis()->SetLabelOffset(0.007); tmp0_copy4->GetYaxis()->SetTitleSize(0.05); tmp0_copy4->GetYaxis()->SetTickLength(0.02); tmp0_copy4->GetYaxis()->SetTitleOffset(1.56); tmp0_copy4->GetYaxis()->SetTitleFont(42); tmp0_copy4->GetZaxis()->SetLabelFont(42); tmp0_copy4->GetZaxis()->SetLabelOffset(0.007); tmp0_copy4->GetZaxis()->SetTitleSize(0.05); tmp0_copy4->GetZaxis()->SetTickLength(0.02); tmp0_copy4->GetZaxis()->SetTitleFont(42); tmp0_copy4->Draw("sameaxig"); TLegend *leg = new TLegend(0.495,0.825,0.945,0.925,NULL,"NBNDC"); leg->SetBorderSize(0); leg->SetLineColor(1); leg->SetLineStyle(1); leg->SetLineWidth(1); leg->SetFillColor(0); leg->SetFillStyle(1001); TLegendEntry *entry=leg->AddEntry("Graph3","Observed","LP"); entry->SetLineColor(1); entry->SetLineStyle(1); entry->SetLineWidth(2); entry->SetMarkerColor(1); entry->SetMarkerStyle(20); entry->SetMarkerSize(1); entry->SetTextFont(42); entry=leg->AddEntry("Graph2","Expected","L"); ci = TColor::GetColor("#ff0000"); entry->SetLineColor(ci); entry->SetLineStyle(1); entry->SetLineWidth(2); entry->SetMarkerColor(1); entry->SetMarkerStyle(21); entry->SetMarkerSize(1); entry->SetTextFont(42); entry=leg->AddEntry("Graph1","#pm1#sigma Expected","F"); ci = TColor::GetColor("#00ff00"); entry->SetFillColor(ci); entry->SetFillStyle(1001); entry->SetLineColor(1); entry->SetLineStyle(1); entry->SetLineWidth(1); entry->SetMarkerColor(1); entry->SetMarkerStyle(21); entry->SetMarkerSize(1); entry->SetTextFont(42); entry=leg->AddEntry("Graph0","#pm2#sigma Expected","F"); ci = TColor::GetColor("#ffff00"); entry->SetFillColor(ci); entry->SetFillStyle(1001); entry->SetLineColor(1); entry->SetLineStyle(1); entry->SetLineWidth(1); entry->SetMarkerColor(1); entry->SetMarkerStyle(21); entry->SetMarkerSize(1); entry->SetTextFont(42); leg->Draw(); TPave *pave = new TPave(0.16,0.81,0.96,0.94,1,"brNDC"); pave->SetFillColor(0); pave->Draw(); leg = new TLegend(0.495,0.825,0.945,0.925,NULL,"NBNDC"); leg->SetBorderSize(0); leg->SetLineColor(1); leg->SetLineStyle(1); leg->SetLineWidth(1); leg->SetFillColor(0); leg->SetFillStyle(1001); entry=leg->AddEntry("Graph3","Observed","LP"); entry->SetLineColor(1); entry->SetLineStyle(1); entry->SetLineWidth(2); entry->SetMarkerColor(1); entry->SetMarkerStyle(20); entry->SetMarkerSize(1); entry->SetTextFont(42); entry=leg->AddEntry("Graph2","Expected","L"); ci = TColor::GetColor("#ff0000"); entry->SetLineColor(ci); entry->SetLineStyle(1); entry->SetLineWidth(2); entry->SetMarkerColor(1); entry->SetMarkerStyle(21); entry->SetMarkerSize(1); entry->SetTextFont(42); entry=leg->AddEntry("Graph1","#pm1#sigma Expected","F"); ci = TColor::GetColor("#00ff00"); entry->SetFillColor(ci); entry->SetFillStyle(1001); entry->SetLineColor(1); entry->SetLineStyle(1); entry->SetLineWidth(1); entry->SetMarkerColor(1); entry->SetMarkerStyle(21); entry->SetMarkerSize(1); entry->SetTextFont(42); entry=leg->AddEntry("Graph0","#pm2#sigma Expected","F"); ci = TColor::GetColor("#ffff00"); entry->SetFillColor(ci); entry->SetFillStyle(1001); entry->SetLineColor(1); entry->SetLineStyle(1); entry->SetLineWidth(1); entry->SetMarkerColor(1); entry->SetMarkerStyle(21); entry->SetMarkerSize(1); entry->SetTextFont(42); leg->Draw(); TLatex * tex = new TLatex(0.196,0.9113,"CMS"); tex->SetNDC(); tex->SetTextAlign(13); tex->SetTextSize(0.048); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.196,0.8537,"Internal"); tex->SetNDC(); tex->SetTextAlign(13); tex->SetTextFont(52); tex->SetTextSize(0.03648); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.96,0.952,""); tex->SetNDC(); tex->SetTextAlign(31); tex->SetTextFont(42); tex->SetTextSize(0.036); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.16,0.952,""); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.036); tex->SetLineWidth(2); tex->Draw(); pad->Modified(); limit->cd(); limit->Modified(); limit->cd(); limit->SetSelected(limit); }
void readroot(char* input="/gpfs/mnt/gpfs02/phenix/mpcex/liankun/Run16/Ana/offline/analysis/mpcexcode/Liankun/macro/offline_monitor/453692/Run16Ana_MinBias_NoCMN_Sub-453692-0.root"){ char input_file[5000]; strcpy(input_file,input); strtok(input_file, "-"); int runnumber = atoi(strtok(0, "-")); int segment = atoi(strtok(strtok(0, "-"), ".")); cout<<"Run Number: "<<runnumber<<" segment: "<<segment<<endl; gSystem->Load("libMyMpcEx.so"); TFile* ifile = new TFile(input,"READONLY"); if(!ifile){ cout<<"Open "<<input<<" failed !"<<endl; return; } TH2D* hkey_adc_high; TH2D* hkey_adc_low; TH2D* hkey_rawadc_high; TH2D* hkey_rawadc_low; TH2D* hHL_sensor[2][8][24]; TH2D* hHL_sensor_raw[2][8][24]; Exogram* hgrammy_high[2]; Exogram* hgrammy_low[2]; Exogram* hgrammy_combine[2]; TH2D* hadc_mpc_e[2]; TH2D* hlayer_adc_high[2]; TH2D* hlayer_adc_low[2]; TH2D* htower_e; TH2D* hbbc_adc[2]; TH2D* hbbc_adc_low[2]; TH2D* hbbc_nhits[2]; char hname[500]; vector<TH2D*> h2d_list; hkey_adc_high = (TH2D*)ifile->Get("hkey_adc_high"); h2d_list.push_back(hkey_adc_high); hkey_adc_low = (TH2D*)ifile->Get("hkey_adc_low"); h2d_list.push_back(hkey_adc_low); hkey_rawadc_high = (TH2D*)ifile->Get("hkey_rawadc_high"); h2d_list.push_back(hkey_rawadc_high); hkey_rawadc_low = (TH2D*)ifile->Get("hkey_rawadc_low"); h2d_list.push_back(hkey_rawadc_low); hbbc_nhits[0] = (TH2D*)ifile->Get("hbbc_nhits_arm0"); hbbc_nhits[1] = (TH2D*)ifile->Get("hbbc_nhits_arm1"); h2d_list.push_back(hbbc_nhits[0]); h2d_list.push_back(hbbc_nhits[1]); hbbc_adc[0] = (TH2D*)ifile->Get("hbbc_adc_arm0"); hbbc_adc[1] = (TH2D*)ifile->Get("hbbc_adc_arm1"); h2d_list.push_back(hbbc_adc[0]); h2d_list.push_back(hbbc_adc[1]); hbbc_adc_low[0] = (TH2D*)ifile->Get("hbbc_adc_low_arm0"); hbbc_adc_low[1] = (TH2D*)ifile->Get("hbbc_adc_low_arm1"); h2d_list.push_back(hbbc_adc_low[0]); h2d_list.push_back(hbbc_adc_low[1]); hlayer_adc_high[0] = (TH2D*)ifile->Get("hlayer_adc_high_arm0"); hlayer_adc_high[1] = (TH2D*)ifile->Get("hlayer_adc_high_arm1"); h2d_list.push_back(hlayer_adc_high[0]); h2d_list.push_back(hlayer_adc_high[1]); hlayer_adc_low[0] = (TH2D*)ifile->Get("hlayer_adc_low_arm0"); hlayer_adc_low[1] = (TH2D*)ifile->Get("hlayer_adc_low_arm1"); h2d_list.push_back(hlayer_adc_low[0]); h2d_list.push_back(hlayer_adc_low[1]); htower_e = (TH2D*)ifile->Get("htower_e"); h2d_list.push_back(htower_e); hadc_mpc_e[0] = (TH2D*)ifile->Get("hadc_mpc_e_arm0"); hadc_mpc_e[1] = (TH2D*)ifile->Get("hadc_mpc_e_arm1"); h2d_list.push_back(hadc_mpc_e[0]); h2d_list.push_back(hadc_mpc_e[1]); for(unsigned int i = 0;i < h2d_list.size();i++){ string s = h2d_list[i]->GetName(); stringstream ss(""); ss<<s<<"_"<<runnumber<<"_"<<segment; s=ss.str(); // cout << s <<endl; TCanvas* c = new TCanvas(s.c_str(),s.c_str(),1200,800); c->SetLogz(); h2d_list[i]->Draw("colz"); ss.str(""); ss << runnumber <<"/"<<s<<".gif"; s=ss.str(); c->Print(s.c_str(),"gif"); delete c; } vector<Exogram*> hexo_list; hgrammy_high[0] = (Exogram*)ifile->Get("hgrammy_high0"); hgrammy_high[1] = (Exogram*)ifile->Get("hgrammy_high1"); hexo_list.push_back(hgrammy_high[0]); hexo_list.push_back(hgrammy_high[1]); hgrammy_low[0] = (Exogram*)ifile->Get("hgrammy_low0"); hgrammy_low[1] = (Exogram*)ifile->Get("hgrammy_low1"); hexo_list.push_back(hgrammy_low[0]); hexo_list.push_back(hgrammy_low[1]); hgrammy_combine[0] = (Exogram*)ifile->Get("hgrammy_combine0"); hgrammy_combine[1] = (Exogram*)ifile->Get("hgrammy_combine1"); hexo_list.push_back(hgrammy_combine[0]); hexo_list.push_back(hgrammy_combine[1]); for(unsigned int i = 0;i < hexo_list.size();i++){ string s = hexo_list[i]->GetName(); stringstream ss(""); ss<<s<<"_"<<runnumber<<"_"<<segment; s=ss.str(); TCanvas* c = new TCanvas(s.c_str(),s.c_str(),1400,800); c->Divide(4,2); double max = hexo_list[i]->GetBinContent(hexo_list[i]->GetMaximumBin()); for(unsigned int j = 0;j < 8;j++){ c->cd(j+1); TPad *pd =(TPad*)c->cd(j+1); pd->SetLogz(); hexo_list[i]->SetAxisRange(j,j,"z"); TH2D* htemp = hexo_list[i]->Project3D("yx"); string tmp_s = htemp->GetName(); stringstream tmp_ss(""); tmp_ss<<tmp_s<<"_"<<"layer"<<j; tmp_s = tmp_ss.str(); htemp->SetName(tmp_s.c_str()); htemp->SetMaximum(max); htemp->Draw("colz"); } ss.str(""); ss << runnumber <<"/"<<s<<".gif"; s=ss.str(); c->Print(s.c_str(),"gif"); delete c; } for(int iarm = 0;iarm < 2;iarm++){ for(int ilayer = 0;ilayer < 8;ilayer++){ for(int isen = 0;isen< 24;isen++){ char hname[500]; sprintf(hname,"hHL_sensor_arm%d_layer%d_sensor%d",iarm,ilayer,isen); hHL_sensor[iarm][ilayer][isen] = (TH2D*)ifile->Get(hname); sprintf(hname,"hHL_sensor_raw_arm%d_layer%d_sensor%d",iarm,ilayer,isen); hHL_sensor_raw[iarm][ilayer][isen] = (TH2D*)ifile->Get(hname); } } } //sensor adc for each layer double max_sensor_x[2][8][24] = {{{0.}}}; double max_sensor_y[2][8][24] = {{{0.}}}; double min_sensor_x[2][8][24] = {{{0.}}}; double min_sensor_y[2][8][24] = {{{0.}}}; TH1D* hsensor_high[2][8][24]; TH1D* hsensor_low[2][8][24]; for(int iarm = 0;iarm < 2;iarm++){ for(int ilayer = 0;ilayer < 8;ilayer++){ for(int isen = 0;isen < 24;isen++){ char name[100]; sprintf(name,"hsensor_arm%d_layer%d_index%d_high",iarm,ilayer,isen); hsensor_high[iarm][ilayer][isen] = new TH1D(name,name,300,-40.5,259.5); sprintf(name,"hsensor_arm%d_layer%d_index%d_low",iarm,ilayer,isen); hsensor_low[iarm][ilayer][isen] = new TH1D(name,name,300,-40.5,259.5); max_sensor_x[iarm][ilayer][isen] = -9999; max_sensor_y[iarm][ilayer][isen] = -9999; min_sensor_x[iarm][ilayer][isen] = 9999; min_sensor_y[iarm][ilayer][isen] = 9999; } } } ifstream sensor_pos("sensor_position.txt"); string s; while(getline(sensor_pos,s)){ stringstream ss(s); int arm = 0; int layer = 0; int sensor = 0; double x0=0; double x1=0; double y0=0; double y1=0; ss>>arm>>layer>>sensor>>x0>>x1>>y0>>y1; // cout <<arm <<" "<<layer<<" "<<sensor<<" "<<x0<<" "<<x1<<" "<<y0<<" "<<y1<<endl; max_sensor_x[arm][layer][sensor] = x1; min_sensor_x[arm][layer][sensor] = x0; max_sensor_y[arm][layer][sensor] = y1; min_sensor_y[arm][layer][sensor] = y0; } MpcExMapper* mapper = MpcExMapper::instance(); for(unsigned int i = 0;i < 50000;i++){ hkey_adc_high->SetAxisRange(i,i,"X"); hkey_adc_low->SetAxisRange(i,i,"X"); TH1D* htemp0 = hkey_adc_high->ProjectionY(); TH1D* htemp1 = hkey_adc_low->ProjectionY(); if(htemp0->GetEntries() < 10) continue; int arm = mapper->get_arm(i); int quadrant = mapper->get_quadrant(i); int sensor = mapper->get_sensor_in_quadrant(i); int index = 6*quadrant+sensor; int layer = mapper->get_layer(i); hsensor_high[arm][layer][index]->Add(htemp0); hsensor_low[arm][layer][index]->Add(htemp1); } for(int iarm = 0;iarm < 2;iarm++){ for(int ilayer = 0;ilayer < 8;ilayer++){ char cname[100]; sprintf(cname,"csensor_arm%d_layer%d_%d_%d",iarm,ilayer,runnumber,segment); TCanvas* c = new TCanvas(cname,cname,1400,800); for(int index = 0;index < 24;index++){ char pname[100]; sprintf(pname,"sensor_arm%d_layer%d_index%d",iarm,ilayer,index); double x0 = min_sensor_x[iarm][ilayer][index]; double x1 = max_sensor_x[iarm][ilayer][index]; double y0 = min_sensor_y[iarm][ilayer][index]; double y1 = max_sensor_y[iarm][ilayer][index]; if(ilayer%2 == 0){ y0 = y0 - 0.85; y1 = y1 + 0.85; } if(ilayer%2 == 1){ x0 = x0 - 0.85; x1 = x1 + 0.85; } TPad* pad = new TPad(pname,pname,0.5+x0/40.,0.5+y0/40.,0.5+x1/40.,0.5+y1/40.); pad->cd(); pad->SetLogy(); hsensor_high[iarm][ilayer][index]->Draw(""); hsensor_low[iarm][ilayer][index]->SetLineColor(kRed); hsensor_low[iarm][ilayer][index]->Draw(""); c->cd(); pad->DrawClone("same"); delete pad; } sprintf(cname,"%d/csensor_arm%d_layer%d_%d_%d.gif",runnumber,iarm,ilayer,runnumber,segment); c->Print(cname,"gif"); delete c; } } }
void FastVsSlowSimPtRes() { Int_t plusTPC =0; gROOT->LoadMacro("~/fig_template.C"); // figure style myOptions(0); gROOT->ForceStyle(); TCanvas *myCan = new TCanvas("myCan"); myCan->Draw(); myCan->cd(); TPad *myPad = new TPad("myPad", "The pad",0,0,1,1); myPadSetUp(myPad,0.15,0.04,0.04,0.15); myPad->Draw(); myPad->cd(); myPad->SetGridx(); myPad->SetGridy(); myPad->SetLogx(); myPad->SetLogy(); TLegend *leg = new TLegend(0.44,0.13,0.1.7,0.9,"","brCDN"); leg->SetFillColor(0); TGraph *c[6]; // Current ITS +++++++++++++++++++++++++++++++++++++++++ Int_t color=1; Int_t linewidth=2; Int_t pi =0; DetectorK its("ALICE","ITS"); its.MakeAliceCurrent(0,plusTPC); its.SetMaxRadiusOfSlowDetectors(0.1); its.SolveViaBilloir(0); Int_t color=1; Int_t linewidth=2; c[pi] = its.GetGraphMomentumResolution(color,linewidth); c[pi]->Draw("AC"); leg->AddEntry(c[pi],"FastTool: Current ITS","l"); // Current ITS +++++++++++++++++++++++++++++++++++++++++ Int_t color=3; Int_t linewidth=2; Int_t pi =2; DetectorK its("ALICE","ITS"); its.MakeAliceCurrent(0,plusTPC); its.SetRadius("bpipe",2.0); its.AddLayer("spd0", 2.2,1,1,1); its.SetRadius("spd0",2.2); its.SetRadiationLength("spd0",X0); its.SetResolution("spd0",resRPhi,resZ); its.SetRadius("spd1",4.8); its.SetRadiationLength("spd1",X0); its.SetResolution("spd1",resRPhi,resZ); its.SetRadius("spd2",9.1); its.SetRadiationLength("spd2",X0); its.SetResolution("spd2",resRPhi,resZ); its.SetMaxRadiusOfSlowDetectors(0.1); its.SolveViaBilloir(0); c[pi] = its.GetGraphMomentumResolution(color,linewidth); c[pi]->Draw("C"); leg->AddEntry(c[pi],"FastTool: \"New SPDs\"","l"); // ALL NEW +++++++++++++++++++++++++++++++++++++++++++ color=2; Int_t linewidth=2; Int_t pi =1; // for a 0.8,0.2 weight configuration DetectorK *itsU = new DetectorK((char*)"ALICE",(char*)"ITS"); itsU->AddLayer((char*)"bpipe", 2.0,0.0022); // beam pipe itsU->AddLayer((char*)"vertex", 0, 0); // dummy vertex for matrix calculation itsU->AddLayer("ddd1", 2.2 , X0, resRPhi, resZ); itsU->AddLayer("ddd2", 3.8 , X0, resRPhi, resZ); itsU->AddLayer("ddd3", 6.8 , X0, resRPhi, resZ); itsU->AddLayer("ddd4", 12.4 , X0, resRPhi, resZ); itsU->AddLayer("ddd5", 23.5 , X0, resRPhi, resZ); itsU->AddLayer("ddd6", 39.6 , X0, resRPhi, resZ); itsU->AddLayer("ddd7", 43.0 , X0, resRPhi, resZ); if(plusTPC) itsU->AddTPC(0.1,0.1); itsU->SetMaxRadiusOfSlowDetectors(0.1); itsU->SolveViaBilloir(0); itsU->PrintLayout(); c[pi] = itsU->GetGraphMomentumResolution(color,linewidth); c[pi]->Draw("C"); leg->AddEntry(c[pi],"FastTool: \"All New\" ","l"); // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ TFile f1("root/FastVsSlow_CurrentITS-PbPb-fran.root"); TFile f2("root/FastVsSlow_NewSPDs-PbPb-fran.root"); TFile f3("root/FastVsSlow_AllNew-PbPb-fran.root"); TGraphErrors *gpt1 = (TGraphErrors*)f1.Get("dPt"); TGraphErrors *gpt2 = (TGraphErrors*)f2.Get("dPt"); TGraphErrors *gpt3 = (TGraphErrors*)f3.Get("dPt"); gpt1->SetMarkerStyle(21); gpt1->SetMarkerColor(1); gpt2->SetMarkerStyle(21); gpt2->SetMarkerColor(3); gpt3->SetMarkerStyle(21); gpt3->SetMarkerColor(2); leg->AddEntry(gpt1,"FullMC: Current ITS","PE"); leg->AddEntry(gpt2,"FullMC: \"New SPDs\"","PE"); leg->AddEntry(gpt3,"FullMC: \"All New\" ","PE"); gpt1->Draw("APE"); gpt1->SetMinimum(0.1); gpt1->SetMaximum(20); gpt2->Draw("PE"); gpt3->Draw("PE"); c[0]->Draw("C"); c[1]->Draw("C"); c[2]->Draw("C"); leg->Draw(); myCan->SaveAs(Form("FastVsSlowSim-PtRes-%d.pdf",plusTPC)); myCan->SaveAs(Form("FastVsSlowSim-PtRes-%d.eps",plusTPC)); }
void AtlasExample() { #ifdef __CINT__ gROOT->LoadMacro("AtlasUtils.C"); #endif SetAtlasStyle(); Int_t icol1=5; Int_t icol2=5; TCanvas* c1 = new TCanvas("c1","single inclusive jets",50,50,600,600); // TCanvas* c1 = new TCanvas("c1","single inclusive jets"); TPad* thePad = (TPad*)c1->cd(); thePad->SetLogy(); Double_t ymin=1.e-3; Double_t ymax=2e7; Double_t xmin=60.00; Double_t xmax=3500.; TH1F *h1 = thePad->DrawFrame(xmin,ymin,xmax,ymax); h1->SetYTitle("d#sigma_{jet}/dE_{T,jet} [fb/GeV]"); h1->SetXTitle("E_{T,jet} [GeV]"); h1->GetYaxis()->SetTitleOffset(1.4); h1->GetXaxis()->SetTitleOffset(1.4); //h1->GetXaxis()->SetNdivisions(5); h1->Draw(); const Int_t ncut=1; TGraphErrors *data[ncut]; for (Int_t icut=0; icut<ncut; icut++) { // loop over cuts TGraphErrors *g1[nren][ncut]; for (Int_t ir=0; ir<nren; ir++) { // loop over ren scale g1[ir][icut]= GetGraph(ir,ir,icut,0); if (g1[ir][icut]) cout << g1[ir][icut]->GetTitle() << " found " << g1[ir][icut]->GetName() << endl; else { cout << " g1 not found " << endl; return; } g1[ir][icut]->SetLineColor(1); g1[ir][icut]->SetMarkerStyle(0); //g1[ir][icut]->Draw("C"); } char daname[100]; sprintf(daname,"data_%d",icut); data[icut]=(TGraphErrors*)g1[0][icut]->Clone(daname); data[icut]->SetMarkerStyle(20); data[icut]->SetMarkerColor(1); // just invent some data for (Int_t i=0; i< data[icut]->GetN(); i++) { Double_t x1,y1,e,dx1=0.; data[icut]->GetPoint(i,x1,y1); Double_t r1 = 0.4*(gRandom->Rndm(1)+2); Double_t r2 = 0.4*(gRandom->Rndm(1)+2); //cout << " i= " << i << " x1= " << x1 << " y1= " << y1 << " r= " << r << endl; Double_t y; if (icut==0) y=r1*y1+r1*r2*r2*x1/50000.; else y=r1*y1; e=sqrt(y*1000)/200; data[icut]->SetPoint(i, x1,y); data[icut]->SetPointError(i,dx1,e); } //data[icut]->Print(); TGraphAsymmErrors* scale[ncut]; TGraphAsymmErrors* scalepdf[ncut]; scale[icut]= myMakeBand(g1[0][icut],g1[1][icut],g1[2][icut]); //printf(" band1: \n"); //scale->Print(); scalepdf[icut]=(TGraphAsymmErrors* ) scale[icut]->Clone("scalepdf"); TGraphErrors *gpdf[NUMPDF][ncut]; for (Int_t ipdf=0; ipdf<NUMPDF; ipdf++) { gpdf[ipdf][icut]= GetGraph(0,0,icut,ipdf); if (gpdf[ipdf][icut]) cout << gpdf[ipdf][icut]->GetTitle() << " found " << gpdf[ipdf][icut]->GetName() << endl; else { cout << " gpdf not found " << endl; return; } gpdf[ipdf][icut]->SetLineColor(2); gpdf[ipdf][icut]->SetLineStyle(1); gpdf[ipdf][icut]->SetMarkerStyle(0); myAddtoBand(gpdf[ipdf][icut],scalepdf[icut]); } scalepdf[icut]->SetFillColor(icol2); scalepdf[icut]->Draw("zE2"); scale[icut]->SetFillColor(icol1); scale[icut]->Draw("zE2"); g1[0][icut]->SetLineWidth(3); g1[0][icut]->Draw("z"); data[icut]->Draw("P"); } myText( 0.3, 0.85, 1, "#sqrt{s}= 14 TeV"); myText( 0.57, 0.85, 1, "|#eta_{jet}|<0.5"); myMarkerText( 0.55, 0.75, 1, 20, "Data 2009",1.3); myBoxText( 0.55, 0.67, 0.05, icol1, "NLO QCD"); //ATLAS_LABEL(0.2,0.2); myText( 0.37,0.2,1,"Preliminary"); // new method for ATLAS labels. Use this! //ATLASLabel(0.2,0.2); ATLASLabel(0.2,0.2,"Preliminary"); //ATLASLabel(0.2,0.2,"Work in progress"); c1->Print("AtlasExample.eps"); c1->Print("AtlasExample.png"); c1->Print("AtlasExample.pdf"); }
// *************************************** // // this is a function that takes a set of // // histograms and draws them on a canvas // // in a stack, returning the canvas. // // It also plots the signal as a dashed // // line and the data with a ratio at the // // the bottom of data/allBackgrounds // // // // This one is supposed to make plots for // // the paper draft // // *************************************** // TCanvas* drawPlots::plotAll_VLQ_paperStyle(std::vector<TH1D*> histos, std::vector<std::string> names, std::string axisName, std::vector<TH1D*> signal, TH1D* data, TGraphAsymmErrors* err, bool doLogAxis, std::string extraTag){ const unsigned int CANVAS_WIDTH = 720; const unsigned int CANVAS_HEIGHT = 750; const double RATIOPLOT_YAXIS_TITLE_OFFSET = 0.75; const double RATIOPLOT_YAXIS_TITLE_SIZE = 0.11; const double RATIOPLOT_YAXIS_LABEL_SIZE = 0.09; const double RATIOPLOT_XAXIS_TITLE_OFFSET = 1.6; const double RATIOPLOT_XAXIS_TITLE_SIZE = 0.11; const double RATIOPLOT_XAXIS_LABEL_SIZE = 0.09; TCanvas* canvas = new TCanvas("canvas","canvas",0,0,CANVAS_WIDTH,CANVAS_HEIGHT); canvas->SetMargin(0.,0.,0.,0.); canvas->Clear(); //canvas->cd(); SetAtlasStyle(); gStyle->SetHistLineWidth(1.); gStyle->SetErrorX(0); err->SetLineColor(kWhite); err->SetLineWidth(0); // create histogram to store all backgrounds TH1D* allBackgrounds; bool gotSomething=false; for(int c=0; c<signal.size(); c++){ if(signal[c]){ allBackgrounds = (TH1D*)signal[c]->Clone("all_backgrounds"); gotSomething=true; } } if(!gotSomething && data){ allBackgrounds = (TH1D*)data->Clone("all_backgrounds"); gotSomething=true; } if(!gotSomething){ for(int b=0; b<histos.size(); b++){ if(histos[b] && !gotSomething){ allBackgrounds = (TH1D*)histos[b]->Clone("all_backgrounds"); gotSomething=true; } } } if(!gotSomething){ std::cout << "Error: could not find any background, data, or signal for this plot" << std::endl; return canvas; } // set all bins to zero for(int i=0; i<=allBackgrounds->GetNbinsX()+1; i++) allBackgrounds->SetBinContent(i,0); // go through histos and combine the histograms that need to be combined // WZ stays separate, ttV stays separate, all others become "Other bkg" TH1D* otherBkgs=0; TH1D* ttbarX=0; TH1D* WZ_Sherpa=0; for(int cc=0; cc<histos.size(); cc++){ if(histos[cc]){ for(int j=0; j<=allBackgrounds->GetNbinsX()+1; j++){ double binContent=allBackgrounds->GetBinContent(j)+histos[cc]->GetBinContent(j); allBackgrounds->SetBinContent(j,binContent); } if(names[cc]=="ttbarX") ttbarX=(TH1D*)histos[cc]->Clone("ttbarX_new"); else if(names[cc]=="WZ_Sherpa") WZ_Sherpa=(TH1D*)histos[cc]->Clone("WZ_new"); else{ if(!otherBkgs) otherBkgs=(TH1D*)histos[cc]->Clone("other_bkg_new"); else otherBkgs->Add(histos[cc]); } } } // make stack of backgrounds, fill backgrounds histogram THStack* Stack = new THStack(); if(ttbarX){ ttbarX->SetLineColor(kGray); ttbarX->SetFillColor(kGray); Stack->Add(ttbarX); } if(WZ_Sherpa){ WZ_Sherpa->SetLineColor(kBlue-9); WZ_Sherpa->SetFillColor(kBlue-9); Stack->Add(WZ_Sherpa); } if(otherBkgs){ otherBkgs->SetLineColor(kOrange-2); otherBkgs->SetFillColor(kOrange-2); Stack->Add(otherBkgs); } TH1D* backgroundsForRatio = (TH1D*)allBackgrounds->Clone("bkgds_for_ratio"); // create main pad const double mainPad_ylow = 0.3; const double mainPad_yhigh = 0.95; const double mainPad_xlow = 0.; const double mainPad_xhigh = 0.95; const double pad_margin_left = 0.2; const double pad_margin_right = 0.02; double main_y_max = -99; double main_y_min = -99; TPad* mainPad = new TPad("main","main",mainPad_xlow,mainPad_ylow,mainPad_xhigh,mainPad_yhigh); mainPad->SetMargin(pad_margin_left,pad_margin_right,0.,.05); // left, right, bottom, top mainPad->Draw(); mainPad->cd(); // find max y if(allBackgrounds){ int maxBinBkg = allBackgrounds->GetMaximumBin(); double bkgYmax = allBackgrounds->GetBinContent(maxBinBkg); main_y_max = bkgYmax; } if(data){ int maxBinData = data->GetMaximumBin(); double dataYmax = data->GetBinContent(maxBinData); if(dataYmax > main_y_max) main_y_max = dataYmax; } if(main_y_max < .002) main_y_max = .1; if(doLogAxis){ mainPad->SetLogy(); main_y_min = 0.07; main_y_max*=60; }else{ main_y_min = 0.001; main_y_max*=1.6; } // draw axis allBackgrounds->SetMaximum(main_y_max); allBackgrounds->SetMinimum(main_y_min); std::string title = std::string(";") + axisName + ";Events"; std::stringstream binw; binw<<allBackgrounds->GetBinWidth(1); std::string width = binw.str(); if (axisName.find("GeV") != std::string::npos){ width += " GeV"; title += " / "+width; } allBackgrounds->SetTitle(title.c_str()); allBackgrounds->GetYaxis()->SetTitleOffset(1.4); allBackgrounds->GetYaxis()->SetTitleSize(0.06); allBackgrounds->GetXaxis()->SetTitleOffset(1.2); allBackgrounds->GetYaxis()->SetLabelSize(0.04); allBackgrounds->GetXaxis()->SetLabelSize(0.04); allBackgrounds->Draw("hist"); // draw stack with error Stack->Draw("hist same"); if(err){ err->Draw("E2 same"); } // make error histograms for the ratio plot TGraphAsymmErrors* ratioErr = tools::getRatio(err, backgroundsForRatio); // draw data if(data) data->Draw("e same"); // draw signal if(signal[0]){ signal[0]->SetLineStyle(2); signal[0]->SetLineColor(kRed+2);//kGreen+3 before signal[0]->SetLineWidth(5); signal[0]->Draw("hist same"); } if(signal.size() > 1){ if(signal[1]){ //signal[1]->SetLineStyle(2); signal[1]->SetLineColor(kRed+2); signal[1]->SetLineWidth(4); signal[1]->Draw("hist same"); } if(signal.size() > 2){ if(signal[2]){ //signal[2]->SetLineStyle(2); signal[2]->SetLineColor(kBlue+2); signal[2]->SetLineWidth(4); signal[2]->Draw("hist same"); } } } allBackgrounds->Draw("axis same"); // draw legend float leg_height = 0.3; float leg_width = 0.2; float leg_xoffset = 0.74; float leg_yoffset = 0.77; TLegend* leg = new TLegend(leg_xoffset,leg_yoffset-leg_height/2,leg_xoffset+leg_width,leg_yoffset+leg_height/2); leg->SetFillColor(0); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetTextFont(52); leg->SetTextSize(0.033); // currently assuming first signal is Tbq (single T production), second is TTS, third is BBS leg->AddEntry(data, "data 2012"); leg->AddEntry(otherBkgs, "Other bkg.", "f"); leg->AddEntry(WZ_Sherpa, "WZ", "f"); leg->AddEntry(ttbarX, "t#bar{t}+X", "f"); if(signal.size()>1){ if(signal[2]) leg->AddEntry(signal[2], "B#bar{B} (650 GeV)", "l"); if(signal[1]) leg->AddEntry(signal[1], "T#bar{T} (650 GeV)", "l"); } if(signal[0]) leg->AddEntry(signal[0], "T#bar{b}q (650 GeV)", "l"); leg->AddEntry( err, "Uncertainty", "f"); leg->Draw("lpe"); ATLAS_LABEL(0.24,0.86,1); myText(0.36, 0.86, 1, .05, "Internal"); char text[]="#sqrt{s}=8 TeV"; myText(0.55,0.77,1,.04, text); char text_L[]="#int L dt = 20.3 fb^{-1}"; myText(0.5, 0.84,1, .04, text_L); if(extraTag!=""){ char tag_txt[extraTag.size()]; strcpy(tag_txt, extraTag.c_str()); if(extraTag.size()>15) myText(0.7, 0.56, 1, .04, tag_txt); else myText(0.75, 0.56, 1, .04, tag_txt); } char text_tri[]="Trilepton"; myText(0.55, 0.70, 1, .04, text_tri); /* double back_int = allBackgrounds->Integral(0,allBackgrounds->GetNbinsX()+1); int t; char inText[100]; if(back_int > 10000.) t=sprintf(inText, "N_{B} = %.3e", back_int); else t=sprintf(inText, "N_{B} = %.1f", back_int); myText(0.24, 0.6, 1, .04, inText); if(data) t=sprintf(inText, "N_{D} = %.0f", data->Integral(0,data->GetNbinsX()+1)); else t=sprintf(inText, "N_{D} = %.0f", 0.); myText(0.24, 0.7, 1, .04, inText); */ canvas->cd(); // Draw Ratio plot // 1.6 and .4 are the normal ones double ratio_max = 3.2; double ratio_min = -.9; double pad_xlow = 0.; double pad_xhigh = 0.95; double pad_ylow = 0.0; double pad_yhigh = 0.3; const char* pad_name = "pad"; TPad* pad4ratio = new TPad(pad_name,pad_name,pad_xlow,pad_ylow,pad_xhigh,pad_yhigh); pad4ratio->SetMargin(pad_margin_left,pad_margin_right,0.46,0.); pad4ratio->Draw(); pad4ratio->cd(); TH1D* ratioPlot; if(data) ratioPlot = (TH1D*)data->Clone("ratio"); else if (signal[0]) ratioPlot = (TH1D*)signal[0]->Clone("ratio"); // just for getting the axis else if (signal[1]) ratioPlot = (TH1D*)signal[1]->Clone("ratio"); else return canvas; ratioPlot->SetTitle(""); ratioPlot->Divide(allBackgrounds); ratioPlot->GetYaxis()->SetTitle("Data / bkg"); ratioPlot->GetXaxis()->SetTitle(axisName.c_str()); if (data){ // here change ratio_min and ratio_max if the ratio plot is quite flat double maxDeviation=0; double minDeviation=10.; double tempDev=0; for(int ibin=1; ibin<=allBackgrounds->GetNbinsX(); ibin++){ double binContent = ratioPlot->GetBinContent(ibin); tempDev=0; if(binContent>0 && binContent < 10) tempDev = std::abs(binContent-1.); if(tempDev > maxDeviation) maxDeviation = tempDev; if(tempDev < minDeviation) minDeviation = tempDev; } if(maxDeviation < 0.6){ ratio_max = 1.6; ratio_min = 0.4; } else if(maxDeviation < 0.1){ ratio_max = 1.12; ratio_min = 0.88; } else if(maxDeviation < 0.2){ ratio_max = 1.25; ratio_min = .75; } if(minDeviation > 1.5){ if(minDeviation > 2.) ratio_max = 2.7; else ratio_max = 2.2; } ratioPlot->SetMinimum(ratio_min); ratioPlot->SetMaximum(ratio_max); } if(ratioPlot->GetXaxis()->GetNdivisions() > ratioPlot->GetNbinsX()) ratioPlot->GetXaxis()->SetNdivisions(ratioPlot->GetNbinsX()); if(ratioPlot->GetXaxis()->GetNdivisions() > 11) ratioPlot->GetXaxis()->SetNdivisions(11); ratioPlot->GetXaxis()->SetLabelSize(RATIOPLOT_XAXIS_LABEL_SIZE); ratioPlot->GetYaxis()->SetLabelSize(RATIOPLOT_YAXIS_LABEL_SIZE); ratioPlot->GetYaxis()->SetNdivisions(3); ratioPlot->GetYaxis()->SetTitleSize(RATIOPLOT_YAXIS_TITLE_SIZE); ratioPlot->GetYaxis()->SetTitleOffset(RATIOPLOT_YAXIS_TITLE_OFFSET); ratioPlot->GetXaxis()->SetTitleSize(RATIOPLOT_XAXIS_TITLE_SIZE); ratioPlot->GetXaxis()->SetTitleOffset(RATIOPLOT_XAXIS_TITLE_OFFSET); if(data){ ratioPlot->Draw(); // plot horizontal line at y=1 TF1* horizontal = new TF1("horizontal","pol1",-10000,10000); horizontal->SetParameter(0,1.); horizontal->SetParameter(1,0.); horizontal->SetLineColor(kBlack); horizontal->SetLineStyle(2); horizontal->SetLineWidth(1); horizontal->Draw("same"); ratioErr->Draw("E2 same"); }else{ // there is no data ratioPlot->Draw("axis"); char text[]="NO DATA"; myText(0.4,0.6,1,.15,text); } return canvas; }
// *************************************** // // this is a function that takes a set of // // histograms and draws them on a canvas // // in a stack, returning the canvas. // // It also plots the signal as a dashed // // line and the data with a ratio at the // // the bottom of data/allBackgrounds // // // // This one is supposed to match the plots // // make by JP // // *************************************** // TCanvas* drawPlots::plotAll_VLQ(std::vector<TH1D*> histos, std::vector<std::string> names, std::string axisName, std::vector<TH1D*> signal, TH1D* data, TGraphAsymmErrors* err, bool isSignalRegion, bool doLogAxis, std::string channel){ const unsigned int CANVAS_WIDTH = 720; const unsigned int CANVAS_HEIGHT = 750; const double RATIOPLOT_YAXIS_TITLE_OFFSET = 0.75; const double RATIOPLOT_YAXIS_TITLE_SIZE = 0.11; const double RATIOPLOT_YAXIS_LABEL_SIZE = 0.09; const double RATIOPLOT_XAXIS_TITLE_OFFSET = 1.6; const double RATIOPLOT_XAXIS_TITLE_SIZE = 0.11; const double RATIOPLOT_XAXIS_LABEL_SIZE = 0.09; TCanvas* canvas = new TCanvas("canvas","canvas",0,0,CANVAS_WIDTH,CANVAS_HEIGHT); canvas->SetMargin(0.,0.,0.,0.); canvas->Clear(); canvas->cd(); SetAtlasStyle(); gStyle->SetHistLineWidth(1.); // create histogram to store all backgrounds TH1D* allBackgrounds; bool gotSomething=false; for(int c=0; c<signal.size(); c++){ if(signal[c]){ allBackgrounds = (TH1D*)signal[c]->Clone("all_backgrounds"); gotSomething=true; } } if(!gotSomething && data) allBackgrounds = (TH1D*)data->Clone("all_backgrounds"); if(!gotSomething){ for(int b=0; b<histos.size(); b++){ if(histos[b] && !gotSomething){ allBackgrounds = (TH1D*)histos[b]->Clone("all_backgrounds"); gotSomething=true; } } } if(!gotSomething){ std::cout << "Error: could not find any background, data, or signal for this plot" << std::endl; return canvas; } // set all bins to zero for(int i=0; i<=allBackgrounds->GetNbinsX()+1; i++) allBackgrounds->SetBinContent(i,0); // make stack of backgrounds, fill backgrounds histogram THStack* Stack = new THStack(); for(int b=0; b<histos.size(); b++){ if(histos[b]){ if(histos[b]->GetEntries() > 0.){ histos[b]->SetLineColor(1); histos[b]->SetFillColor(tools::setColor(names[b])); Stack->Add(histos[b]); for(int j=0; j<=allBackgrounds->GetNbinsX()+1; j++){ double binContent=allBackgrounds->GetBinContent(j)+histos[b]->GetBinContent(j); allBackgrounds->SetBinContent(j,binContent); } } } } TH1D* backgroundsForRatio = (TH1D*)allBackgrounds->Clone("bkgds_for_ratio"); // create main pad const double mainPad_ylow = 0.3; const double mainPad_yhigh = 0.95; const double mainPad_xlow = 0.; const double mainPad_xhigh = 0.95; const double pad_margin_left = 0.2; const double pad_margin_right = 0.02; double main_y_max = -99; double main_y_min = -99; TPad* mainPad = new TPad("main","main",mainPad_xlow,mainPad_ylow,mainPad_xhigh,mainPad_yhigh); mainPad->SetMargin(pad_margin_left,pad_margin_right,0.,.05); // left, right, bottom, top mainPad->Draw(); mainPad->cd(); // find max y if(allBackgrounds){ int maxBinBkg = allBackgrounds->GetMaximumBin(); double bkgYmax = allBackgrounds->GetBinContent(maxBinBkg); main_y_max = bkgYmax; } if(data){ int maxBinData = data->GetMaximumBin(); double dataYmax = data->GetBinContent(maxBinData); if(dataYmax > main_y_max) main_y_max = dataYmax; } if(main_y_max < .002) main_y_max = .1; if(doLogAxis){ mainPad->SetLogy(); main_y_min = 0.007; main_y_max*=600; }else{ main_y_min = 0.001; main_y_max*=1.6; } // draw axis allBackgrounds->SetMaximum(main_y_max); allBackgrounds->SetMinimum(main_y_min); std::string title = std::string(";") + axisName + ";events/bin"; allBackgrounds->SetTitle(title.c_str()); allBackgrounds->GetYaxis()->SetTitleOffset(1.4); allBackgrounds->GetYaxis()->SetTitleSize(0.06); allBackgrounds->GetXaxis()->SetTitleOffset(1.2); allBackgrounds->GetYaxis()->SetLabelSize(0.04); allBackgrounds->GetXaxis()->SetLabelSize(0.04); allBackgrounds->Draw("hist"); // draw stack with error Stack->Draw("hist same"); if(err){ err->Draw("E2 same"); } // make error histograms for the ratio plot TGraphAsymmErrors* ratioErr = tools::getRatio(err, backgroundsForRatio); // draw data if(!isSignalRegion && data) data->Draw("e same"); // draw signal if(signal[0]){ signal[0]->SetLineStyle(2); signal[0]->SetLineColor(kRed); signal[0]->SetLineWidth(5); signal[0]->Draw("hist same"); } if(signal.size() > 1){ if(signal[1]){ signal[1]->SetLineStyle(2); signal[1]->SetLineColor(kOrange+7); signal[1]->SetLineWidth(4); signal[1]->Draw("hist same"); } if(signal.size() > 2){ if(signal[2]){ signal[2]->SetLineStyle(2); signal[2]->SetLineColor(kPink-6); signal[2]->SetLineWidth(4); signal[2]->Draw("hist same"); } } } allBackgrounds->Draw("axis same"); // draw legend float leg_height = 0.45; float leg_width = 0.2; float leg_xoffset = 0.74; float leg_yoffset = 0.7; TLegend* leg = new TLegend(leg_xoffset,leg_yoffset-leg_height/2,leg_xoffset+leg_width,leg_yoffset+leg_height/2); leg->SetFillColor(0); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetTextFont(52); leg->SetTextSize(0.033); // currently assuming first signal is Tbq (single T production), second is TTS, third is BBS if(signal[0]) leg->AddEntry(signal[0], "Tbq (650 GeV)", "l"); if(signal.size()>1){ if(signal[1]) leg->AddEntry(signal[1], "TT_{S} (650 GeV)", "l"); if(signal[2]) leg->AddEntry(signal[2], "BB_{S} (650 GeV)", "l"); } if(!isSignalRegion) leg->AddEntry(data, "data 2012"); for(int q=0; q<histos.size(); q++){ if(histos[q]){ if(histos[q]->GetEntries() > 0.) leg->AddEntry(histos[q], plotLists::GetLegendName(names[q]).c_str(), "f"); } } leg->Draw("lpe"); ATLAS_LABEL(0.24,0.86,1); myText(0.36, 0.86, 1, .05, "Internal"); char text[]="#sqrt{s}=8 TeV"; myText(0.55,0.77,1,.04, text); char text_L[]="#int L dt = 20.3 fb^{-1}"; myText(0.5, 0.84,1, .04, text_L); if(channel!=""){ char chan_txt[channel.size()-1]; strcpy(chan_txt, (channel.substr(1)).c_str()); myText(0.5, 0.7, 1, .06, chan_txt); } char inText[100]; int t; if(signal[0]) t=sprintf(inText, "N_{Tbq} = %.1f", signal[0]->Integral(0,signal[0]->GetNbinsX()+1)); else t=sprintf(inText, "N_{Tbq} = %.1f", 0.); myText(0.24, 0.7, 1, .04, inText); if(signal.size()>1){ if(signal[1]) t=sprintf(inText, "N_{TTS} = %.1f", signal[1]->Integral(0,signal[1]->GetNbinsX()+1)); else t=sprintf(inText, "N_{TTS} = %.1f", 0.); myText(0.24, 0.65, 1, .04, inText); if(signal.size()>2){ if(signal[2]) t=sprintf(inText, "N_{BBS} = %.1f", signal[2]->Integral(0,signal[2]->GetNbinsX()+1)); else t=sprintf(inText, "N_{BBS} = %.1f", 0.); myText(0.24, 0.6, 1, .04, inText); } } double back_int = allBackgrounds->Integral(0,allBackgrounds->GetNbinsX()+1); if(back_int > 10000.) t=sprintf(inText, "N_{B} = %.3e", back_int); else t=sprintf(inText, "N_{B} = %.1f", back_int); myText(0.24, 0.75, 1, .04, inText); if(!isSignalRegion){ if(data) t=sprintf(inText, "N_{D} = %.0f", data->Integral(0,data->GetNbinsX()+1)); else t=sprintf(inText, "N_{D} = %.0f", 0.); myText(0.24, 0.8, 1, .04, inText); } canvas->cd(); // Draw Ratio plot double ratio_max = 1.6; double ratio_min = 0.4; double pad_xlow = 0.; double pad_xhigh = 0.95; double pad_ylow = 0.0; double pad_yhigh = 0.3; const char* pad_name = "pad"; TPad* pad4ratio = new TPad(pad_name,pad_name,pad_xlow,pad_ylow,pad_xhigh,pad_yhigh); pad4ratio->SetMargin(pad_margin_left,pad_margin_right,0.46,0.); pad4ratio->Draw(); pad4ratio->cd(); TH1D* ratioPlot; if(data) ratioPlot = (TH1D*)data->Clone("ratio"); else if (signal[0]) ratioPlot = (TH1D*)signal[0]->Clone("ratio"); // just for getting the axis ratioPlot->SetTitle(""); ratioPlot->Divide(allBackgrounds); ratioPlot->GetYaxis()->SetTitle("Data/MC"); ratioPlot->GetXaxis()->SetTitle(axisName.c_str()); if (data){ // here change ratio_min and ratio_max if the ratio plot is quite flat double maxDeviation=0; double tempDev=0; for(int ibin=1; ibin<=allBackgrounds->GetNbinsX(); ibin++){ tempDev = std::abs(ratioPlot->GetBinContent(ibin)-1.); if(tempDev > maxDeviation) maxDeviation = tempDev; } if(maxDeviation < 0.1){ ratio_max = 1.12; ratio_min = 0.88; } else if(maxDeviation < 0.2){ ratio_max = 1.25; ratio_min = .75; } ratioPlot->SetMinimum(ratio_min); ratioPlot->SetMaximum(ratio_max); } if(ratioPlot->GetXaxis()->GetNdivisions() > ratioPlot->GetNbinsX()) ratioPlot->GetXaxis()->SetNdivisions(ratioPlot->GetNbinsX()); if(ratioPlot->GetXaxis()->GetNdivisions() > 11) ratioPlot->GetXaxis()->SetNdivisions(11); ratioPlot->GetXaxis()->SetLabelSize(RATIOPLOT_XAXIS_LABEL_SIZE); ratioPlot->GetYaxis()->SetLabelSize(RATIOPLOT_YAXIS_LABEL_SIZE); ratioPlot->GetYaxis()->SetNdivisions(3); ratioPlot->GetYaxis()->SetTitleSize(RATIOPLOT_YAXIS_TITLE_SIZE); ratioPlot->GetYaxis()->SetTitleOffset(RATIOPLOT_YAXIS_TITLE_OFFSET); ratioPlot->GetXaxis()->SetTitleSize(RATIOPLOT_XAXIS_TITLE_SIZE); ratioPlot->GetXaxis()->SetTitleOffset(RATIOPLOT_XAXIS_TITLE_OFFSET); if(!isSignalRegion && data){ ratioPlot->Draw(); // plot horizontal line at y=1 TF1* horizontal = new TF1("horizontal","pol1",-10000,10000); horizontal->SetParameter(0,1.); horizontal->SetParameter(1,0.); horizontal->SetLineColor(kBlack); horizontal->SetLineStyle(2); horizontal->SetLineWidth(1); horizontal->Draw("same"); ratioErr->Draw("E2 same"); }else if(isSignalRegion){ ratioPlot->Draw("axis"); char text[]="DATA IS BLIND HERE"; myText(0.4,0.6,1,.15,text); }else{ // in this case it is not the signal region but there is no data ratioPlot->Draw("axis"); char text[]="NO DATA"; myText(0.4,0.6,1,.15,text); } return canvas; }
// *************************************** // // this is a function that takes a set of // // histograms and draws them on a canvas // // in a stack, returning the canvas. // // It also plots the signal as a dashed // // line and the data with a ratio at the // // the bottom of data/allBackgrounds // // *************************************** // TCanvas* drawPlots::plotAll(std::vector<TH1D*> histos, std::vector<std::string> names, std::string axisName, TH1D* signal, TH1D* data, TH1D* errDown, TH1D* errUp, bool isSignalRegion, bool doLogAxis){ const unsigned int MAINPLOT_WIDTH = 800; const unsigned int MAINPLOT_HEIGHT = 500; const unsigned int RATIOPLOT_HEIGHT = 125; const unsigned int OFFSET = 10; //LUKE: Title offset and title size are proportional in //root, so you have to change them together, //this makes me a sad panda const double RATIOPLOT_YAXIS_TITLE_OFFSET = 0.4; const double RATIOPLOT_YAXIS_TITLE_SIZE = 0.14; const double RATIOPLOT_YAXIS_TICK_LENGTH = 0.01; const double RATIOPLOT_YAXIS_LABEL_SIZE = 0.15; const double RATIOPLOT_XAXIS_TITLE_OFFSET = 0.9; const double RATIOPLOT_XAXIS_TITLE_SIZE = 0.2; const double RATIOPLOT_XAXIS_TICK_LENGTH = 0.05; const double RATIOPLOT_XAXIS_LABEL_SIZE = 0.2; const double CANVAS_HEIGHT = MAINPLOT_HEIGHT+RATIOPLOT_HEIGHT+OFFSET; TCanvas* canvas = new TCanvas("canvas","canvas",0,0,MAINPLOT_WIDTH,CANVAS_HEIGHT); canvas->SetMargin(0.,0.,0.,0.); canvas->Clear(); canvas->cd(); // create main pad const double mainPad_ylow = (CANVAS_HEIGHT - MAINPLOT_HEIGHT)/CANVAS_HEIGHT; const double mainPad_yhigh = 1.; const double pad_margin_left = 0.15; const double pad_margin_right = 0.05; double main_y_max = -99; double main_y_min = -99; double main_x_max = -99; double main_x_min = -99; for(int a=0; a<histos.size(); a++){ if(histos[a]){ if(histos[a]->GetEntries()> 0.){ GetAxisLimits(histos[a], main_x_min, main_x_max, main_y_min, main_y_max); } } } if(data){ int maxBinData = data->GetMaximumBin(); double dataYmax = data->GetBinContent(maxBinData); if(dataYmax > main_y_max) main_y_max = dataYmax; } // create main pad TPad* mainPad = new TPad("main","main",0.,mainPad_ylow,1.,mainPad_yhigh); mainPad->SetMargin(pad_margin_left,pad_margin_right,0.,.05); // left, right, bottom, top mainPad->Draw(); mainPad->cd(); SetAtlasStyle(); if(doLogAxis)mainPad->SetLogy(); // clone signal or data because one should exist for each plot TH1D* allBackgrounds; bool gotSomething=false; if(signal) allBackgrounds = (TH1D*)signal->Clone("all_backgrounds"); else if(data) allBackgrounds = (TH1D*)data->Clone("all_backgrounds"); else{ for(int b=0; b<histos.size(); b++){ if(histos[b] && !gotSomething){ allBackgrounds = (TH1D*)histos[b]->Clone("all_backgrounds"); gotSomething=true; } } } // set all bins to zero so that you can add all histograms to it for(int i=0; i<=allBackgrounds->GetNbinsX()+1; i++) allBackgrounds->SetBinContent(i,0); THStack* Stack = new THStack(); std::string title = std::string(";") + axisName + ";Events"; Stack->SetTitle(title.c_str()); for(int b=0; b<histos.size(); b++){ if(histos[b]){ if(histos[b]->GetEntries() > 0.){ histos[b]->SetLineColor(1); histos[b]->SetFillColor(tools::setColor(names[b])); Stack->Add(histos[b]); for(int j=0; j<=allBackgrounds->GetNbinsX()+1; j++){ double binContent=allBackgrounds->GetBinContent(j)+histos[b]->GetBinContent(j); allBackgrounds->SetBinContent(j,binContent); } } } } TH1D* backgroundsForRatio = (TH1D*)allBackgrounds->Clone("bkgds_for_ratio"); if(doLogAxis){ main_y_max = main_y_max*10; if(Stack->GetMinimum()>.1) Stack->SetMinimum(.1); } else main_y_max = main_y_max*1.4; Stack->SetMaximum(main_y_max); Stack->Draw("hist"); errDown->Draw("E2same"); errUp->Draw("E2Same"); // make error histograms for the ratio plot TH1D* ratioErrDown = (TH1D*) errDown->Clone("ratio_error_down"); TH1D* ratioErrUp = (TH1D*) errUp->Clone("ratio_error_up"); ratioErrDown->Divide(backgroundsForRatio); ratioErrUp->Divide(backgroundsForRatio); if(!isSignalRegion && data) data->Draw("e same"); if(signal){ signal->SetLineStyle(2); signal->SetLineColor(kRed); signal->SetLineWidth(5); signal->Draw("hist same"); } TLegend* leg = new TLegend(0.8,0.65,0.95,0.9); leg->SetFillStyle(0); leg->SetBorderSize(0); if(signal) leg->AddEntry(signal, "Signal", "l"); if(!isSignalRegion) leg->AddEntry(data, "Data"); for(int q=0; q<histos.size(); q++){ if(histos[q]){ if(histos[q]->GetEntries() > 0.) leg->AddEntry(histos[q], names[q].c_str(), "f"); } } leg->Draw("lpe"); ATLAS_LABEL(0.2,0.85,1); char text[]="#sqrt{s}=8 TeV"; myText(0.6,0.75,1,.04, text); char text_L[]="#int L dt = 20.3 fb^{-1}"; myText(0.6, 0.85,1, .04, text_L); char inText[100]; int t; if(signal) t=sprintf(inText, "N_{Signal} = %.1f", signal->Integral(0,signal->GetNbinsX()+1)); else t=sprintf(inText, "N_{Signal} = %.1f", 0.); myText(0.2, 0.75, 1, .04, inText); double back_int = allBackgrounds->Integral(0,allBackgrounds->GetNbinsX()+1); if(back_int > 10000.) t=sprintf(inText, "N_{Bkgd} = %.3e", back_int); else t=sprintf(inText, "N_{Bkgd} = %.1f", back_int); myText(0.2, 0.7, 1, .04, inText); if(!isSignalRegion){ if(data) t=sprintf(inText, "N_{Data} = %.0f", data->Integral(0,data->GetNbinsX()+1)); else t=sprintf(inText, "N_{Data} = %.0f", 0.); myText(0.2, 0.65, 1, .04, inText); } canvas->cd(); // Draw Ratio plot double ratio_max = 1.6; double ratio_min = 0.4; const double x_axis_size = 0.4; const double ratio_pad_height = RATIOPLOT_HEIGHT/CANVAS_HEIGHT; double pad_xlow = 0.,pad_xhigh = 1.; double pad_ylow = OFFSET/CANVAS_HEIGHT,pad_yhigh = ratio_pad_height; const char* pad_name = "pad"; TPad* pad4ratio = new TPad(pad_name,pad_name,pad_xlow,pad_ylow,pad_xhigh,pad_yhigh); pad4ratio->SetMargin(pad_margin_left,pad_margin_right,x_axis_size,0.); pad4ratio->Draw(); pad4ratio->cd(); TH1D* ratioPlot; if(data) ratioPlot = (TH1D*)data->Clone("ratio"); else if(signal) ratioPlot = (TH1D*)signal->Clone("ratio"); // if there is no data then use signal for axis ratioPlot->SetTitle(""); ratioPlot->GetYaxis()->SetTitle("Data/MC"); ratioPlot->GetXaxis()->SetTitle(axisName.c_str()); if(data){ ratioPlot->Divide(allBackgrounds); // here change ratio_min and ratio_max if the ratio plot is quite flat double maxDeviation=0; double tempDev=0; for(int ibin=1; ibin<=allBackgrounds->GetNbinsX(); ibin++){ tempDev = std::abs(ratioPlot->GetBinContent(ibin)-1.); if(tempDev > maxDeviation) maxDeviation = tempDev; } if(maxDeviation < 0.1){ ratio_max = 1.12; ratio_min = 0.88; } else if(maxDeviation < 0.2){ ratio_max = 1.25; ratio_min = .75; } ratioPlot->SetMinimum(ratio_min); ratioPlot->SetMaximum(ratio_max); } ratioPlot->GetXaxis()->SetLabelSize(RATIOPLOT_XAXIS_LABEL_SIZE); ratioPlot->GetXaxis()->SetTickLength(RATIOPLOT_XAXIS_TICK_LENGTH); ratioPlot->GetYaxis()->SetLabelSize(RATIOPLOT_YAXIS_LABEL_SIZE); ratioPlot->GetYaxis()->SetTickLength(RATIOPLOT_YAXIS_TICK_LENGTH); ratioPlot->GetYaxis()->SetNdivisions(3); ratioPlot->GetYaxis()->SetTitleSize(RATIOPLOT_YAXIS_TITLE_SIZE); ratioPlot->GetYaxis()->SetTitleOffset(RATIOPLOT_YAXIS_TITLE_OFFSET); ratioPlot->GetXaxis()->SetTitleSize(RATIOPLOT_XAXIS_TITLE_SIZE); ratioPlot->GetXaxis()->SetTitleOffset(RATIOPLOT_XAXIS_TITLE_OFFSET); if(!isSignalRegion && data){ ratioPlot->Draw(); // plot horizontal line at y=1 TF1* horizontal = new TF1("horizontal","pol1",-10000,10000); horizontal->SetParameter(0,1.); horizontal->SetParameter(1,0.); horizontal->SetLineColor(kBlack); horizontal->SetLineStyle(2); horizontal->SetLineWidth(1); horizontal->Draw("same"); ratioErrDown->Draw("E2same"); ratioErrUp->Draw("E2same"); }else if(isSignalRegion){ ratioPlot->Draw("axis"); char text[]="DATA IS BLINDED HERE"; myText(0.4,0.6,1,.2,text); }else{ // in this case it is not the signal region but there is no data ratioPlot->Draw("axis"); char text[]="NO DATA"; myText(0.4,0.6,1,.2,text); } return canvas; }
// *************************************** // // this is a function that draws all // // backrounds as a grey area, and compares // // the shape of the backgrounds to that of // // the signal // // This one is supposed to match the plots // // make by JP (Fig 3 of CONF note) // // *************************************** // TCanvas* drawPlots::plotShape_VLQ(TH1D* bkgd, std::string axisName, std::vector<TH1D*> signal, bool doLogAxis, std::string channel){ // only drawing shapes so normalize histograms std::cout << "background integral: " << bkgd->Integral() << std::endl; bkgd->Scale(1./bkgd->Integral()); for(int ahist=0; ahist<signal.size(); ahist++){ if(signal[ahist]){ std::cout << "scaling signal: " << ahist << " with integral: " << signal[ahist]->Integral() << std::endl; signal[ahist]->Scale(1./signal[ahist]->Integral()); } } const unsigned int CANVAS_WIDTH = 720; const unsigned int CANVAS_HEIGHT = 750; TCanvas* canvas = new TCanvas("canvas","canvas",0,0,CANVAS_WIDTH,CANVAS_HEIGHT); canvas->SetMargin(0.,0.,0.,0.); canvas->Clear(); canvas->cd(); SetAtlasStyle(); gStyle->SetHistLineWidth(1.); // create main pad const double mainPad_ylow = 0.; const double mainPad_yhigh = 1.; const double mainPad_xlow = 0.; const double mainPad_xhigh = 1.; const double pad_margin_left = 0.16; const double pad_margin_right = 0.035; double main_y_max = -99; double main_y_min = -99; TPad* mainPad = new TPad("main","main",mainPad_xlow,mainPad_ylow,mainPad_xhigh,mainPad_yhigh); mainPad->SetMargin(pad_margin_left,pad_margin_right,0.16,.05); // left, right, bottom, top mainPad->Draw(); mainPad->cd(); // find max y int maxBinBkg = bkgd->GetMaximumBin(); double bkgYmax = bkgd->GetBinContent(maxBinBkg); main_y_max = bkgYmax; // std::cout << "background maximum: " << bkgYmax << std::endl; if(main_y_max < .002) main_y_max = .1; if(doLogAxis){ mainPad->SetLogy(); main_y_min = 0.0001; main_y_max*=500; }else{ main_y_min = 0.00001; main_y_max*=1.6; } // draw axis bkgd->SetMaximum(main_y_max); bkgd->SetMinimum(main_y_min); std::string title = std::string(";") + axisName + ";Fraction of events"; std::stringstream binw; binw<<bkgd->GetBinWidth(1); std::string width = binw.str(); if (axisName.find("GeV") != std::string::npos) width += " GeV"; if(bkgd->GetBinWidth(1) != 1) title += " / "+width; bkgd->SetTitle(title.c_str()); bkgd->GetYaxis()->SetTitleOffset(1.6); bkgd->GetXaxis()->SetTitleOffset(1.2); bkgd->GetYaxis()->SetLabelSize(0.03); bkgd->GetYaxis()->SetTitleSize(0.045); bkgd->GetXaxis()->SetTitleSize(0.045); bkgd->GetXaxis()->SetLabelSize(0.03); bkgd->SetFillStyle(3354); bkgd->SetFillColor(kGray+2); bkgd->SetLineColor(kGray+2); bkgd->Draw("histf"); // draw signal if(signal[0]){ std::cout << "printing Tbq" << std::endl; signal[0]->SetLineStyle(2); signal[0]->SetLineColor(kRed+2); // kGreen+3 was being used before signal[0]->SetLineWidth(5); signal[0]->Draw("hist same"); } if(signal.size() > 1){ if(signal[1]){ std::cout << "printing TTS" << std::endl; // signal[1]->SetLineStyle(2); signal[1]->SetLineColor(kRed+2); signal[1]->SetLineWidth(4); signal[1]->Draw("hist same"); } if(signal.size() > 2){ if(signal[2]){ std::cout << "printing BBS" << std::endl; // signal[2]->SetLineStyle(2); signal[2]->SetLineColor(kBlue+2); signal[2]->SetLineWidth(4); signal[2]->Draw("hist same"); } } } bkgd->Draw("axis same"); // draw legend float leg_height = 0.2; float leg_width = 0.4; float leg_xoffset = 0.65; float leg_yoffset = 0.8; TLegend* leg = new TLegend(leg_xoffset,leg_yoffset-leg_height/2,leg_xoffset+leg_width,leg_yoffset+leg_height/2); leg->SetFillColor(0); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetTextFont(72); leg->SetTextSize(0.026); // currently assuming first signal is single T, second is TTS leg->AddEntry(bkgd,"Background", "f"); if(signal.size()>1){ if(signal.size()>2){ if(signal[2]) leg->AddEntry(signal[2], "B#bar{B} (650 GeV)", "l"); } if(signal[1]) leg->AddEntry(signal[1], "T#bar{T} (650 GeV)", "l"); } if(signal[0]) leg->AddEntry(signal[0], "T#bar{b}q (650 GeV)", "l"); leg->Draw("lpe"); ATLAS_LABEL(0.24,0.86,1); myText(0.26, 0.81, 1, .04, "Internal"); char text[]="#sqrt{s}=8 TeV"; myText(0.48,0.82,1,.03, text); char text_L[]="Simulation"; myText(0.47, 0.87,1, .03, text_L); char text_tri[]="Trilepton"; myText(0.485, 0.77, 1, .03, text_tri); if(channel!=""){ char chan_txt[channel.size()-1]; strcpy(chan_txt, (channel.substr(1)).c_str()); if(channel.size()>10) myText(0.55, 0.56, 1, .03, chan_txt); else myText(0.65, 0.56, 1, .03, chan_txt); } canvas->cd(); return canvas; }
void QA_Draw_HCALIN_TowerCluster( const char * qa_file_name_new = "/phenix/u/jinhuang/links/ePHENIX_work/sPHENIX_work/production_analysis_updates/spacal1d/fieldmap/G4Hits_sPHENIX_pi-_eta0.30_32GeV-0000.root_qa.root", const char * qa_file_name_ref = "/phenix/u/jinhuang/links/ePHENIX_work/sPHENIX_work/production_analysis_updates/spacal1d/fieldmap/G4Hits_sPHENIX_pi+_eta0.30_32GeV-0000.root_qa.root") { SetOKStyle(); gStyle->SetOptStat(0); gStyle->SetOptFit(1111); TVirtualFitter::SetDefaultFitter("Minuit2"); TFile * qa_file_new = new TFile(qa_file_name_new); assert(qa_file_new->IsOpen()); TFile * qa_file_ref = NULL; if (qa_file_name_ref) { qa_file_ref = new TFile(qa_file_name_ref); assert(qa_file_ref->IsOpen()); } TCanvas *c1 = new TCanvas("QA_Draw_HCALIN_TowerCluster", "QA_Draw_HCALIN_TowerCluster", 1800, 900); c1->Divide(4, 2); int idx = 1; TPad * p; p = (TPad *) c1->cd(idx++); c1->Update(); p->SetLogx(); p->SetLogy(); { TH1F * h_new = (TH1F *) qa_file_new->GetObjectChecked( "h_QAG4Sim_HCALIN_Tower_1x1", "TH1F"); assert(h_new); h_new->Scale(1. / h_new->GetSum()); TH1F * h_ref = NULL; if (qa_file_ref) { TH1F * h_ref = (TH1F *) qa_file_ref->GetObjectChecked( "h_QAG4Sim_HCALIN_Tower_1x1", "TH1F"); assert(h_ref); h_ref->Scale(1. / h_ref->GetSum()); } h_new->GetYaxis()->SetTitleOffset(1.5); h_new->GetYaxis()->SetTitle("Normalized tower count per bin"); // h_new->GetXaxis()->SetRangeUser(-0, .1); DrawReference(h_new, h_ref); } p = (TPad *) c1->cd(idx++); c1->Update(); p->SetLogx(); p->SetLogy(); { TH1F * h_new = (TH1F *) qa_file_new->GetObjectChecked( "h_QAG4Sim_HCALIN_Tower_3x3", "TH1F"); assert(h_new); h_new->Scale(1. / h_new->GetSum()); TH1F * h_ref = NULL; if (qa_file_ref) { TH1F * h_ref = (TH1F *) qa_file_ref->GetObjectChecked( "h_QAG4Sim_HCALIN_Tower_3x3", "TH1F"); assert(h_ref); h_ref->Scale(1. / h_ref->GetSum()); } h_new->GetYaxis()->SetTitleOffset(1.5); h_new->GetYaxis()->SetTitle("Normalized tower count per bin"); // h_new->GetXaxis()->SetRangeUser(-0, .1); DrawReference(h_new, h_ref); } p = (TPad *) c1->cd(idx++); c1->Update(); // p->SetLogx(); p->SetLogy(); { TH1F * h_new = (TH1F *) qa_file_new->GetObjectChecked( "h_QAG4Sim_HCALIN_Tower_1x1_max", "TH1F"); assert(h_new); h_new->Rebin(40); h_new->Sumw2(); h_new->Scale(1. / h_new->GetSum()); TH1F * h_ref = NULL; if (qa_file_ref) { TH1F * h_ref = (TH1F *) qa_file_ref->GetObjectChecked( "h_QAG4Sim_HCALIN_Tower_1x1_max", "TH1F"); assert(h_ref); h_ref->Rebin(40); h_ref->Scale(1. / h_ref->GetSum()); } h_new->GetYaxis()->SetTitleOffset(1.5); h_new->GetYaxis()->SetTitle("Probability per bin"); // h_new->GetXaxis()->SetRangeUser(-0, .1); DrawReference(h_new, h_ref); } p = (TPad *) c1->cd(idx++); c1->Update(); // p->SetLogx(); p->SetLogy(); { TH1F * h_new = (TH1F *) qa_file_new->GetObjectChecked( "h_QAG4Sim_HCALIN_Tower_4x4_max", "TH1F"); assert(h_new); h_new->Rebin(40); h_new->Sumw2(); h_new->Scale(1. / h_new->GetSum()); TH1F * h_ref = NULL; if (qa_file_ref) { TH1F * h_ref = (TH1F *) qa_file_ref->GetObjectChecked( "h_QAG4Sim_HCALIN_Tower_4x4_max", "TH1F"); assert(h_ref); h_ref->Rebin(40); h_ref->Scale(1. / h_ref->GetSum()); } h_new->GetYaxis()->SetTitleOffset(1.5); h_new->GetYaxis()->SetTitle("Probability per bin"); // h_new->GetXaxis()->SetRangeUser(-0, .1); DrawReference(h_new, h_ref); } p = (TPad *) c1->cd(idx++); c1->Update(); p->SetLogz(); TH2F * h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection = (TH2F *) qa_file_new->GetObjectChecked( "h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection", "TH2F"); assert(h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection); h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection->GetYaxis()->SetTitleOffset( 1.5); // h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection->GetXaxis()->SetRangeUser(-5, // 5); // h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection->GetYaxis()->SetRangeUser(-5, // 5); h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection->Draw("COLZ"); p = (TPad *) c1->cd(idx++); c1->Update(); // p->SetLogz(); { TH2F * h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection = (TH2F *) qa_file_new->GetObjectChecked( "h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection", "TH2F"); assert(h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection); TH1D * proj_new = h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection->ProjectionX( "qa_file_new_h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection_px"); proj_new->Rebin(4); proj_new->Scale(1. / proj_new->GetSum()); TH1D * proj_ref = NULL; if (qa_file_ref) { TH2F * h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection = (TH2F *) qa_file_ref->GetObjectChecked( "h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection", "TH2F"); assert(h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection); proj_ref = h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection->ProjectionX( "qa_file_ref_h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection_px"); proj_ref->Rebin(4); proj_ref->Scale(1. / proj_ref->GetSum()); } proj_new->GetYaxis()->SetTitleOffset(1.); proj_new->GetXaxis()->SetTitleOffset(1.); proj_new->GetYaxis()->SetTitle("Normalized energy distribution"); // proj_new->GetXaxis()->SetRangeUser(-10, 10); DrawReference(proj_new, proj_ref); } p = (TPad *) c1->cd(idx++); c1->Update(); // p->SetLogz(); { TH2F * h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection = (TH2F *) qa_file_new->GetObjectChecked( "h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection", "TH2F"); assert(h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection); TH1D * proj_new = h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection->ProjectionY( "qa_file_new_h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection_py"); proj_new->Rebin(4); proj_new->Scale(1. / proj_new->GetSum()); TH1D * proj_ref = NULL; if (qa_file_ref) { TH2F * h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection = (TH2F *) qa_file_ref->GetObjectChecked( "h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection", "TH2F"); assert(h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection); proj_ref = h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection->ProjectionY( "qa_file_ref_h_QAG4Sim_HCALIN_Cluster_LateralTruthProjection_py"); proj_ref->Rebin(4); proj_ref->Scale(1. / proj_ref->GetSum()); } proj_new->GetYaxis()->SetTitleOffset(1.); proj_new->GetXaxis()->SetTitleOffset(1.); proj_new->GetYaxis()->SetTitle("Normalized energy distribution"); // proj_new->GetXaxis()->SetRangeUser(-10, 10); DrawReference(proj_new, proj_ref); } p = (TPad *) c1->cd(idx++); c1->Update(); p->SetLogy(); { TH1F * h_new = (TH1F *) qa_file_new->GetObjectChecked( "h_QAG4Sim_HCALIN_Cluster_BestMatchERatio", "TH1F"); assert(h_new); h_new->Rebin(2); h_new->Sumw2(); h_new->Scale(1. / h_new->GetSum()); TH1F * h_ref = NULL; if (qa_file_ref) { TH1F * h_ref = (TH1F *) qa_file_ref->GetObjectChecked( "h_QAG4Sim_HCALIN_Cluster_BestMatchERatio", "TH1F"); assert(h_ref); h_ref->Rebin(2); h_ref->Scale(1. / h_ref->GetSum()); } h_new->GetYaxis()->SetTitleOffset(1.5); h_new->GetYaxis()->SetTitle("Probability per bin"); // h_new->GetXaxis()->SetRangeUser(-0, .1); DrawReference(h_new, h_ref); } PutInputFileName(c1, .04, qa_file_name_new, qa_file_name_ref); SaveCanvas(c1, TString(qa_file_name_new) + TString(c1->GetName()), true); }
void goftest() { // ------------------------------------------------------------------------ // C a s e 1 : C r e a t e l o g N o r m a l r a n d o m s a m p l e // ------------------------------------------------------------------------ UInt_t nEvents1 = 1000; //ROOT::Math::Random<ROOT::Math::GSLRngMT> r; TF1 * f1 = new TF1("logNormal","ROOT::Math::lognormal_pdf(x,[0],[1])",0,500); // set the lognormal parameters (m and s) f1->SetParameters(4.0,1.0); f1->SetNpx(1000); Double_t* sample1 = new Double_t[nEvents1]; TH1D* h1smp = new TH1D("h1smp", "LogNormal distribution histogram", 100, 0, 500); h1smp->SetStats(kFALSE); for (UInt_t i = 0; i < nEvents1; ++i) { //Double_t data = f1->GetRandom(); Double_t data = gRandom->Gaus(4,1); data = TMath::Exp(data); sample1[i] = data; h1smp->Fill(data); } // normalize correctly the histogram using the entries inside h1smp->Scale( ROOT::Math::lognormal_cdf(500.,4.,1) / nEvents1, "width"); TCanvas* c = new TCanvas("c","1-Sample and 2-Samples GoF Tests"); c->Divide(1, 2); TPad * pad = (TPad *)c->cd(1); h1smp->Draw(); h1smp->SetLineColor(kBlue); pad->SetLogy(); f1->SetNpx(100); // use same points as histo for drawing f1->SetLineColor(kRed); f1->Draw("SAME"); // ----------------------------------------- // C r e a t e G o F T e s t o b j e c t // ----------------------------------------- ROOT::Math::GoFTest* goftest_1 = new ROOT::Math::GoFTest(nEvents1, sample1, ROOT::Math::GoFTest::kLogNormal); /* Possible calls for the Anderson - DarlingTest test */ /*----------------------------------------------------*/ /* a) Returning the Anderson-Darling standardized test statistic */ Double_t A2_1 = goftest_1-> AndersonDarlingTest("t"); Double_t A2_2 = (*goftest_1)(ROOT::Math::GoFTest::kAD, "t"); assert(A2_1 == A2_2); /* b) Returning the p-value for the Anderson-Darling test statistic */ Double_t pvalueAD_1 = goftest_1-> AndersonDarlingTest(); // p-value is the default choice Double_t pvalueAD_2 = (*goftest_1)(); // p-value and Anderson - Darling Test are the default choices assert(pvalueAD_1 == pvalueAD_2); /* Rebuild the test using the default 1-sample construtor */ delete goftest_1; goftest_1 = new ROOT::Math::GoFTest(nEvents1, sample1 ); // User must then input a distribution type option goftest_1->SetDistribution(ROOT::Math::GoFTest::kLogNormal); /* Possible calls for the Kolmogorov - Smirnov test */ /*--------------------------------------------------*/ /* a) Returning the Kolmogorov-Smirnov standardized test statistic */ Double_t Dn_1 = goftest_1-> KolmogorovSmirnovTest("t"); Double_t Dn_2 = (*goftest_1)(ROOT::Math::GoFTest::kKS, "t"); assert(Dn_1 == Dn_2); /* b) Returning the p-value for the Kolmogorov-Smirnov test statistic */ Double_t pvalueKS_1 = goftest_1-> KolmogorovSmirnovTest(); Double_t pvalueKS_2 = (*goftest_1)(ROOT::Math::GoFTest::kKS); assert(pvalueKS_1 == pvalueKS_2); /* Valid but incorrect calls for the 2-samples methods of the 1-samples constucted goftest_1 */ #ifdef TEST_ERROR_MESSAGE Double_t A2 = (*goftest_1)(ROOT::Math::GoFTest::kAD2s, "t"); // Issues error message Double_t pvalueKS = (*goftest_1)(ROOT::Math::GoFTest::kKS2s); // Issues error message assert(A2 == pvalueKS); #endif TPaveText* pt1 = new TPaveText(0.58, 0.6, 0.88, 0.80, "brNDC"); Char_t str1[50]; sprintf(str1, "p-value for A-D 1-smp test: %f", pvalueAD_1); pt1->AddText(str1); pt1->SetFillColor(18); pt1->SetTextFont(20); pt1->SetTextColor(4); Char_t str2[50]; sprintf(str2, "p-value for K-S 1-smp test: %f", pvalueKS_1); pt1->AddText(str2); pt1->Draw(); // ------------------------------------------------------------------------ // C a s e 2 : C r e a t e G a u s s i a n r a n d o m s a m p l e s // ------------------------------------------------------------------------ UInt_t nEvents2 = 2000; Double_t* sample2 = new Double_t[nEvents2]; TH1D* h2smps_1 = new TH1D("h2smps_1", "Gaussian distribution histograms", 100, 0, 500); h2smps_1->SetStats(kFALSE); TH1D* h2smps_2 = new TH1D("h2smps_2", "Gaussian distribution histograms", 100, 0, 500); h2smps_2->SetStats(kFALSE); TRandom3 r; for (UInt_t i = 0; i < nEvents1; ++i) { Double_t data = r.Gaus(300, 50); sample1[i] = data; h2smps_1->Fill(data); } h2smps_1->Scale(1. / nEvents1, "width"); c->cd(2); h2smps_1->Draw(); h2smps_1->SetLineColor(kBlue); for (UInt_t i = 0; i < nEvents2; ++i) { Double_t data = r.Gaus(300, 50); sample2[i] = data; h2smps_2->Fill(data); } h2smps_2->Scale(1. / nEvents2, "width"); h2smps_2->Draw("SAME"); h2smps_2->SetLineColor(kRed); // ----------------------------------------- // C r e a t e G o F T e s t o b j e c t // ----------------------------------------- ROOT::Math::GoFTest* goftest_2 = new ROOT::Math::GoFTest(nEvents1, sample1, nEvents2, sample2); /* Possible calls for the Anderson - DarlingTest test */ /*----------------------------------------------------*/ /* a) Returning the Anderson-Darling standardized test statistic */ A2_1 = goftest_2->AndersonDarling2SamplesTest("t"); A2_2 = (*goftest_2)(ROOT::Math::GoFTest::kAD2s, "t"); assert(A2_1 == A2_2); /* b) Returning the p-value for the Anderson-Darling test statistic */ pvalueAD_1 = goftest_2-> AndersonDarling2SamplesTest(); // p-value is the default choice pvalueAD_2 = (*goftest_2)(ROOT::Math::GoFTest::kAD2s); // p-value is the default choices assert(pvalueAD_1 == pvalueAD_2); /* Possible calls for the Kolmogorov - Smirnov test */ /*--------------------------------------------------*/ /* a) Returning the Kolmogorov-Smirnov standardized test statistic */ Dn_1 = goftest_2-> KolmogorovSmirnov2SamplesTest("t"); Dn_2 = (*goftest_2)(ROOT::Math::GoFTest::kKS2s, "t"); assert(Dn_1 == Dn_2); /* b) Returning the p-value for the Kolmogorov-Smirnov test statistic */ pvalueKS_1 = goftest_2-> KolmogorovSmirnov2SamplesTest(); pvalueKS_2 = (*goftest_2)(ROOT::Math::GoFTest::kKS2s); assert(pvalueKS_1 == pvalueKS_2); #ifdef TEST_ERROR_MESSAGE /* Valid but incorrect calls for the 1-sample methods of the 2-samples constucted goftest_2 */ A2 = (*goftest_2)(ROOT::Math::GoFTest::kAD, "t"); // Issues error message pvalueKS = (*goftest_2)(ROOT::Math::GoFTest::kKS); // Issues error message assert(A2 == pvalueKS); #endif TPaveText* pt2 = new TPaveText(0.13, 0.6, 0.43, 0.8, "brNDC"); sprintf(str1, "p-value for A-D 2-smps test: %f", pvalueAD_1); pt2->AddText(str1); pt2->SetFillColor(18); pt2->SetTextFont(20); pt2->SetTextColor(4); sprintf(str2, "p-value for K-S 2-smps test: %f", pvalueKS_1); pt2-> AddText(str2); pt2-> Draw(); // ------------------------------------------------------------------------ // C a s e 3 : C r e a t e L a n d a u r a n d o m s a m p l e // ------------------------------------------------------------------------ UInt_t nEvents3 = 1000; Double_t* sample3 = new Double_t[nEvents3]; for (UInt_t i = 0; i < nEvents3; ++i) { Double_t data = r.Landau(); sample3[i] = data; } // ------------------------------------------ // C r e a t e G o F T e s t o b j e c t s // ------------------------------------------ /* Possible constructors for the user input distribution */ /*-------------------------------------------------------*/ /* a) User input PDF */ ROOT::Math::Functor1D f(&TMath::Landau); double min = 3*TMath::MinElement(nEvents3, sample3); double max = 3*TMath::MaxElement(nEvents3, sample3); ROOT::Math::GoFTest* goftest_3a = new ROOT::Math::GoFTest(nEvents3, sample3, f, ROOT::Math::GoFTest::kPDF, min,max); // need to specify am interval /* b) User input CDF */ ROOT::Math::Functor1D fI(&TMath::LandauI); ROOT::Math::GoFTest* goftest_3b = new ROOT::Math::GoFTest(nEvents3, sample3, fI, ROOT::Math::GoFTest::kCDF,min,max); /* Returning the p-value for the Anderson-Darling test statistic */ pvalueAD_1 = goftest_3a-> AndersonDarlingTest(); // p-value is the default choice pvalueAD_2 = (*goftest_3b)(); // p-value and Anderson - Darling Test are the default choices /* Checking consistency between both tests */ std::cout << " \n\nTEST with LANDAU distribution:\t"; if (TMath::Abs(pvalueAD_1 - pvalueAD_2) > 1.E-1 * pvalueAD_2) { std::cout << "FAILED " << std::endl; Error("goftest","Error in comparing testing using Landau and Landau CDF"); std::cerr << " pvalues are " << pvalueAD_1 << " " << pvalueAD_2 << std::endl; } else std::cout << "OK ( pvalues = " << pvalueAD_2 << " )" << std::endl; }
void plotFinal() { double yPos, xPos, theta, energy = 0.; // NOTE: theta comes in degrees int numHit, pID = 0; TFile* file = new TFile("complete.root"); TTree* Hits_Info = (TTree *)file->Get("Signal"); Hits_Info->SetBranchAddress("numHits", &numHit); Hits_Info->SetBranchAddress("energyTot", &energy); Hits_Info->SetBranchAddress("XPosition", &xPos); Hits_Info->SetBranchAddress("YPosition", &yPos); Hits_Info->SetBranchAddress("Particle_ID", &pID); Hits_Info->SetBranchAddress("Theta", &theta); // Initialize histograms double nEnergyMin = 10; // MeV double nEnergyMax = 510; // MeV int nEnergyBins = 50; double dEnergyBinSize = (double)(nEnergyMax - nEnergyMin) / (double)nEnergyBins; double nThetaMin = 52; // mrad double nThetaMax = 70; // mrad int nThetaBins = 50; double dThetaBinSize = (nThetaMax - nThetaMin) / nThetaBins; double nM2Min = -1000; // MeV double nM2Max = 1000; // MeV int nM2Bins = 100; double dM2BinSize = (nM2Max - nM2Min)/nM2Bins; TH1D* hgammaEnergy = new TH1D("Energy" , // plot label "Gamma Energy Distribution", // title nEnergyBins, // x number of bins nEnergyMin, // x lower bound nEnergyMax); // x upper bound TH1D* hgammaTheta = new TH1D("#theta" , // plot label "Gamma #theta Distribution", // title nThetaBins, // x number of bins nThetaMin, // x lower bound nThetaMax); // x upper bound TH1D* hm2 = new TH1D("M_{A'}^{2}" , // plot label "Missing Mass Squared", // title nM2Bins, // x number of bins nM2Min, // x lower bound nM2Max); // x upper bound TH2F* henergytheta = new TH2F("scatter", // plot label "#theta vs Energy", // title nThetaBins, // x num of bins nThetaMin, // x min nThetaMax, // x max nEnergyBins, // y num of bins nEnergyMin, // y min nEnergyMax); // y max // go through all entries and fill the histograms int nentries = Hits_Info->GetEntries(); for (int i=0; i<nentries; i++) { Hits_Info->GetEntry(i); if (pID == 22) { // gammas only theta*= TMath::Pi()/180; //radians hgammaEnergy->Fill(energy,BINNING_WEIGHT / dEnergyBinSize); hgammaTheta->Fill(theta*1000, BINNING_WEIGHT / dThetaBinSize); henergytheta->Fill(theta*1000, energy); hm2->Fill(mSquared(energy, theta), BINNING_WEIGHT / dM2BinSize); } } // create canvas and draw histogram TCanvas* canvas = new TCanvas("canvas", "canvas", 700, 700); canvas->Divide(3,2); TPad* p; p = (TPad*)canvas->cd(2); p->SetLogy(); p->SetGrid(); hgammaEnergy->SetFillColor(kBlue); hgammaEnergy->SetFillStyle(3001); hgammaEnergy->Draw(); hgammaEnergy->GetXaxis()->SetTitle("Energy (MeV)"); hgammaEnergy->GetYaxis()->SetTitle("Photons per MeV per Second (MeV^{-1} s^{-1})"); hgammaEnergy->GetXaxis()->CenterTitle(); hgammaEnergy->GetYaxis()->CenterTitle(); p = (TPad*)canvas->cd(5); p->SetLogy(); p->SetGrid(); hgammaTheta->SetFillColor(kBlue); hgammaTheta->SetFillStyle(3001); hgammaTheta->Draw(); hgammaTheta->GetXaxis()->SetTitle("#theta (mrad)"); hgammaTheta->GetXaxis()->CenterTitle(); hgammaTheta->GetYaxis()->SetTitle("Photons per mrad per Second (mrad^{-1} s^{-1})"); hgammaTheta->GetYaxis()->CenterTitle(); p = (TPad*)canvas->cd(1); p->SetGrid(); hm2->SetFillColor(kBlue); hm2->SetFillStyle(3001); hm2->GetXaxis()->SetTitle("M_{A'}^{2} (MeV^{2})"); hm2->GetYaxis()->SetTitle("Photons per MeV^{2} per Second (MeV^{-2} s^{-1})"); hm2->GetXaxis()->CenterTitle(); hm2->GetYaxis()->CenterTitle(); hm2->Draw(); p = (TPad*)canvas->cd(4); p->SetLogy(); p->SetGrid(); hm2->Draw(); p = (TPad*)canvas->cd(3); henergytheta->Draw(); henergytheta->GetYaxis()->SetTitle("Energy (MeV)"); henergytheta->GetXaxis()->SetTitle("#theta (mrad)"); henergytheta->GetXaxis()->CenterTitle(); henergytheta->GetYaxis()->CenterTitle(); }
void plot1d(int hid) { gStyle->SetOptStat(0); char c[50]; c1->Clear(); if(m1dHist[hid]==0){ c1->Divide(2,2); for(int quad=0; quad<kFgtNumQuads; quad++){ TVirtualPad* pad1 = c1->cd(quad+1); pad1->SetLogy(l1dHist[hid]); double xmin, xmax, ymin=0.0, ymax=0.0; if(l1dHist[hid]==1) ymin=0.1; for(int disc=0; disc<kFgtNumDiscs; disc++){ sprintf(c,"%1d%1s-%s",disc+1,cquad[quad],c1dHist[hid]); //printf("Getting %s\n",c); TH1F *h = hist1[disc][quad][hid] = (TH1F*)file->Get(c); xmin=h->GetXaxis()->GetXmin(); xmax=h->GetXaxis()->GetXmax(); double m=h->GetMaximum(); if(ymax<m) ymax=m; printf("disc=%d max=%6.1f ymax=%6.1f xmin=%6.1f xmax=%6.1f\n",disc+1,m,ymax,xmin,xmax); } sprintf(c,"Quad%1s-%s",cquad[quad],c1dHist[hid]); TH2F *frame = new TH2F(c,c,1,xmin,xmax,1,ymin,ymax*1.2); frame->SetStats(0); frame->Draw(); for(int disc=0; disc<kFgtNumDiscs; disc++){ TH1F *h=hist1[disc][quad][hid]; h->SetLineColor(color[disc]); h->SetLineWidth(3); h->Draw("SAME"); if(f1dHist[hid]==0){ float mean=h->GetMean(); sprintf(c,"%1d%s mean=%6.2f",disc+1,cquad[quad],mean); }else if(f1dHist[hid]==1){ int res = h->Fit("gaus","0Q"); TF1 *f = h->GetFunction("gaus"); float sig = f->GetParameter(2); if(res==0 && sig>0.0001 && h->GetEntries()>5){ f->SetLineColor(color[disc]); f->SetLineWidth(2); f->Draw("SAME"); sprintf(c,"%1d%s sig=%6.3f",disc+1,cquad[quad],sig); }else{ sprintf(c,"%1d%s",disc+1,cquad[quad]); } }else if(f1dHist[hid]==2){ int res = h->Fit("landau","0Q"); TF1 *f = h->GetFunction("landau"); float peak = f->GetParameter(1); if(res==0 && peak>0 && h->GetEntries()>5){ f->SetLineColor(color[disc]); f->SetLineWidth(2); f->Draw("SAME"); sprintf(c,"%1d%s mpv=%6.0f",disc+1,cquad[quad],peak); }else{ sprintf(c,"%1d%s",disc+1,cquad[quad]); } } TText *t1; float x1= 0.2, x2= 0.55; float y1=0.8 - 0.07*disc; float y2=0.8 - 0.07*(disc-3); if(disc<3) { t1 = new TText(x1,y1,c); } else { t1 = new TText(x2,y2,c); } t1->SetNDC(); t1->SetTextSize(0.04); t1->SetTextColor(color[disc]); t1->Draw(); } } }else{ c1->Divide(4,6); gStyle->SetOptStat(0); gStyle->SetOptTitle(0); gStyle->SetOptFit(0); for(int disc=0; disc<kFgtNumDiscs; disc++){ for(int quad=0; quad<kFgtNumQuads; quad++){ TPad* pad = c1->cd(disc*4+quad+1); pad->SetRightMargin(0.01); pad->SetLeftMargin(0.1); pad->SetTopMargin(0.01); pad->SetBottomMargin(0.1); pad->SetLogy(l1dHist[hid]); sprintf(c,"%1d%1s-%s",disc+1,cquad[quad],c1dHist[hid]); TH1F *h = hist1[disc][quad][hid] = (TH1F*)file->Get(c); h->SetFillColor(color[disc]); h->GetXaxis()->SetLabelSize(0.1); h->GetYaxis()->SetLabelSize(0.1); h->GetXaxis()->SetNdivisions(205); h->Draw(); if(f1dHist[hid]==0){ float mean=h->GetMean(); sprintf(c,"%1d%s mean=%6.2f",disc+1,cquad[quad],mean); }else if(f1dHist[hid]==1){ int res = h->Fit("gaus","0Q"); TF1 *f = h->GetFunction("gaus"); float sig = f->GetParameter(2); if(res==0 && sig>0.0001 && h->GetEntries()>5){ f->SetLineColor(color[disc]); f->SetLineWidth(2); f->Draw("SAME"); sprintf(c,"%1d%s sig=%6.3f",disc+1,cquad[quad],sig); }else{ sprintf(c,"%1d%s",disc+1,cquad[quad]); } }else if(f1dHist[hid]==2){ int res = h->Fit("landau","0Q"); TF1 *f = h->GetFunction("landau"); float peak = f->GetParameter(1); if(res==0 && peak>0 && h->GetEntries()>5){ f->SetLineColor(1); f->SetLineWidth(2); f->Draw("SAME"); sprintf(c,"%1d%s mpv=%6.0f",disc+1,cquad[quad],peak); }else{ sprintf(c,"%1d%s",disc+1,cquad[quad]); } if(hid==8) {mPeakC[disc][quad]=peak;} if(hid==9) { mPeakA[disc][quad]=peak; int n=h->GetEntries(); if(n>0){ float cut=2800; int bin=h->FindBin(cut); int nbin=h->GetNbinsX(); float sat=h->Integral(bin,nbin+1); //printf("bin=%d nbin=%d sat=%f\n",bin,nbin,sat); mFracA[disc][quad]=sat/float(n); } } if(hid==11) {mPeakL[disc][quad]=peak;} // printf("LandauPeak=%f\n",peak);} } TText *t1 = new TText(0.3,0.85,c); t1->SetNDC(); t1->SetTextSize(0.15); t1->SetTextColor(color[disc]); t1->Draw(); } } } c1->Update(); save(c1dHist[hid]); }
bool createPlot(TString hname, TString dirname, TFile *V1file, TString relstring1, TFile *V2file, TString relstring2, TCanvas *canvas, int scale) { setTDRStyle(); // don't look at non-zero bin Int_t range_upper = histV1->GetXaxis()->GetLast(); histV1->GetXaxis()->SetRangeUser(1,range_upper); histV2->GetXaxis()->SetRangeUser(1,range_upper); int SetScale = scale; //IF =0 --> No scale applied ('direct' comparison) //IF =1 --> Scale INDIVIDUALLY (scale histograms individually) //IF =2 --> Scale all GLOBALLY (scale all histograms to #tracks=1) //IF =3 --> Scale all GLOBALLY nEVENTS (scale all histos to nEntries in nTracks per Event) bool DrawRatio = true; canvas->cd(); TPad* mainpad = new TPad("mainpad","mainpad",0.0,0.0,1.0,0.8); mainpad->Draw(); mainpad->cd(); // ************ Get name of histos and get histos ************* // TString basename1 = "DQMData/Run "; basename1.Append("1"); TString hnameV1 = basename1; hnameV1.Append(dirname+"/"); hnameV1.Append(hname); if (hname != "vtxNbr"){ hnameV1.Append("_GenTk"); } TH1F * histV1 = (TH1F*)V1file->Get(hnameV1); if ( histV1 == (TH1F*) NULL ) { cout << "histV1 failed on " << hnameV1 << endl << " for file " << V1file->GetName() << endl; exit(1); } TString basename2 = "DQMData/Run "; basename2.Append("1"); TString hnameV2 = basename2; hnameV2.Append(dirname+"/"); hnameV2.Append(hname); if (hname != "vtxNbr"){ hnameV2.Append("_GenTk"); } TH1F * histV2 = (TH1F*)V2file->Get(hnameV2); if ( histV2 == (TH1F*) NULL ) { cout << "histV2 failed on " << hnameV2 << endl << " for file " << V2file->GetName() << endl; exit(1); } //******************* Get histo integrals ***********************// double V1_integral = 1.0; double V2_integral = 1.0; TH1F * hTempV1 = 0; TH1F * hTempV2 = 0; if (SetScale==1){ V1_integral = histV1->Integral(); V2_integral = histV2->Integral(); } else if ( (SetScale==2) || (SetScale==3) ){ if (hname != "NumberOfTracks"){ TString hTempNameV1 = basename1; hTempNameV1.Append("/Tracking/Run summary/TrackParameters/generalTracks/GeneralProperties/NumberOfTracks_GenTk"); hTempV1 = (TH1F*)V1file->Get(hTempNameV1); TString hTempNameV2 = basename2; hTempNameV2.Append("/Tracking/Run summary/TrackParameters/generalTracks/GeneralProperties/NumberOfTracks_GenTk"); hTempV2 = (TH1F*)V2file->Get(hTempNameV2); } else{ hTempV1 = (TH1F*)histV1->Clone("hTempV1"); hTempV2 = (TH1F*)histV2->Clone("hTempV2"); } if (SetScale==2){ V1_integral = hTempV1->GetBinContent(2); V2_integral = hTempV2->GetBinContent(2); std::cout << "The number of single tracks for V1 is " << V1_integral << std::endl; std::cout << "The number of single tracks for V2 is " << V2_integral << std::endl; } else if (SetScale==3){ V1_integral = hTempV1->GetEntries(); V2_integral = hTempV2->GetEntries(); std::cout << "The number of events for V1 is " << V1_integral << std::endl; std::cout << "The number of events for V2 is " << V2_integral << std::endl; } } //*****NORMALIZING V1-V2**************************************** if(V1_integral>V2_integral) { histV1->Scale(V2_integral / V1_integral); histV2->Scale(1); } else if(V2_integral>V1_integral){ histV1->Scale(1); histV2->Scale(V1_integral / V2_integral); } //*****NORMALIZING V1-V2*end*************************************** //***Name the files under comparison*** TString V1_V1run = "Run 1 ("+relstring1+")"; TString V2_V2run = "Run 1 ("+relstring2+")"; histV1->SetName(V1_V1run); histV2->SetName(V2_V2run); TString x_title = ""; if( hname.Contains("vtxNbr")) x_title="Number of Primary Vertices per Event"; histV1->SetLineWidth(5); histV1->SetLineStyle(1); histV1->SetLineColor(kRed); histV1->GetYaxis()->SetLabelSize(0.038); histV2->SetLineWidth(3); histV2->SetLineStyle(1); histV2->SetLineColor(kBlue); if ( hname.Contains("NumberOfTracks",TString::kExact) || hname.Contains("NumberOfGoodTracks",TString::kExact) || hname.Contains("TrackPt",TString::kExact) || hname.Contains("Chi2Prob",TString::kExact) ){ mainpad->SetLogy(1); } else { mainpad->SetLogy(0); } if (hname.Contains("NumberOfGoodTracks",TString::kExact)) { histV1->GetXaxis()->SetRangeUser(0,200); histV2->GetXaxis()->SetRangeUser(0,200); } if (hname.Contains("Chi2oNDF",TString::kExact)) { histV1->GetXaxis()->SetRangeUser(0,10); histV2->GetXaxis()->SetRangeUser(0,10); } if (hname.Contains("vtxNbr")){ histV1->GetXaxis()->SetTitle(x_title); histV1->GetYaxis()->SetTitle("Number of Events"); } if ( hname.Contains("NumberOfTracks",TString::kExact)){ histV1->GetXaxis()->SetRangeUser(125,range_upper); histV2->GetXaxis()->SetRangeUser(125,range_upper); } double max = 0; double V1max = histV1->GetBinContent(histV1->GetMaximumBin()); double V2max = histV2->GetBinContent(histV2->GetMaximumBin()); max = (V1max>V2max) ? V1max : V2max; histV1->SetMaximum(max*(1.1)); histV1->Draw(); histV2->Draw("sames"); mainpad->Update(); TPaveStats *st1 = (TPaveStats*)(histV1->GetListOfFunctions()->FindObject("stats")); st1->SetX1NDC(0.77); st1->SetY1NDC(0.80); st1->SetX2NDC(0.98); st1->SetY2NDC(0.97); Double_t defaulth = st1->GetY2NDC() - st1->GetY1NDC(); Double_t gaph = 0.02; TPaveStats *st2 = (TPaveStats*)(histV2->GetListOfFunctions()->FindObject("stats")); st2->SetX1NDC(0.77); st2->SetY1NDC(st1->GetY1NDC() - 1.0*defaulth - gaph); st2->SetX2NDC(0.98); st2->SetY2NDC(st1->GetY1NDC() - gaph); TLegend *leg = new TLegend(0.32,0.86,0.76,0.97); leg->SetTextSize(0.042); leg->SetTextFont(42); leg->SetFillColor(10); leg->SetBorderSize(1); // no frame, no shadow leg->AddEntry(histV1, V1_V1run, "L" ); leg->AddEntry(histV2, V2_V2run, "L" ); leg->Draw("SAME"); // Draw ratio histogram if (DrawRatio){ canvas->cd(); TPad* respad = new TPad("respad","respad",0.0,0.78,1.0,0.95); respad->SetTopMargin(1.05); respad->Draw(); respad->cd(); TH1F* hratio = (TH1F*) histV2->Clone("hratio"); hratio->Divide(histV1); hratio->SetMaximum(hratio->GetMaximum()*1.01); //if (hratio->GetMinimum()==0.0) hratio->SetMinimum(1.0/hratio->GetMaximum()); hratio->SetMinimum(1.0/hratio->GetMaximum()); hratio->GetYaxis()->SetLabelSize(0.1); hratio->GetYaxis()->SetRangeUser(0,2); hratio->GetXaxis()->SetLabelSize(0); hratio->GetXaxis()->SetTitleSize(0); hratio->GetYaxis()->SetTitleSize(0.22); hratio->GetYaxis()->SetTitleOffset(0.26); hratio->GetYaxis()->SetLabelSize(0.2); hratio->GetYaxis()->SetNdivisions(5); hratio->GetYaxis()->SetTitle("PM/SM"); hratio->Draw(); } // Compare parameters of histograms double Entries1 = histV1->GetEntries(); double Entries2 = histV2->GetEntries(); if (Entries1 != Entries2) { std::cout<<" Difference in # of ENTRIES for " <<hname<< std::endl; std::cout<<"\t Entries1 = " << Entries1 << "\t Entries2 = " << Entries2 << std::endl; } double Mean1 = histV1->GetMean(); double Mean2 = histV2->GetMean(); if (Mean1 != Mean2) { std::cout<<" Difference in MEANS for " <<hname<< std::endl; std::cout<<"\t Mean1 = " << Mean1 << "\t Mean2 = " << Mean2 << std::endl; } double RMS1 = histV1->GetRMS(); double RMS2 = histV2->GetRMS(); if (RMS1 != RMS2) { std::cout<<" Difference in RMS for " <<hname<< std::endl; std::cout<<"\t RMS1 = " << RMS1 << "\t RMS2 = " << RMS2 << std::endl; } TString filename = hname; if (hname.Contains("vtxNbr")){ filename = "NumberOfPrimaryVertices"; } if (dirname.Contains("highPurityTracks/pt_1/GeneralProperties",TString::kExact)) filename.Prepend("RunComparison/GoodTracks_"); else filename.Prepend("RunComparison/"); filename.Append(".png"); canvas->Print(filename); if ( histV1 ) {histV1->Delete();} if ( histV2 ) {histV2->Delete();} if ( hTempV1 ) {hTempV1->Delete();} if ( hTempV2 ) {hTempV2->Delete();} return true; }
void compareInDir(TFile* f1, TFile* f2, std::string dirName,unsigned int logmod=0, unsigned int dOpt=1){ TCanvas* cv = 0; TPad* pH = 0; TPad* pD = 0; TPaveText* pt = 0; // std::cout<<"Start with "<<dirName.c_str()<<std::endl; // cv->Print("diff.ps["); TDirectory* d1 = f1->GetDirectory(dirName.c_str()); TDirectory* d2 = f2->GetDirectory(dirName.c_str()); if (d1==0 || d2 == 0){ std::cout<<"ERROR: "<<dirName.c_str()<<" not found"<<std::endl; return; } // std::cout<<"\t\t "<<d1->GetName()<<std::endl; TList* list1 = d1->GetListOfKeys(); TIterator* keyIt1 = list1->MakeIterator(); TObject* obj; while ((obj = keyIt1->Next())){ TObject* obj1 = d1->Get(obj->GetName()); if(obj1 == 0){ // std::cout<<"ERROR: failed to read in "<<d1->GetName()<<" / "<<obj->GetName()<<std::endl; continue; } // std::cout<<d1->GetName()<<"/"<<obj->GetName()<<std::endl; if (! obj1->InheritsFrom(TH1::Class())) continue; TObject* obj2 = d2->Get(obj1->GetName()); if (obj2 == 0){ // std::cout<<"WARNING: failed to get"<<d1->GetName()<<"/"<<obj1->GetName()<<std::endl; continue; } TH1* h1 = (TH1*)obj1; TH1* h2 = (TH1*)obj2; // std::cout<<"Will check "<<dirName.c_str()<<"/"<<h1->GetName()<<" dOpt "<<dOpt<<std::endl; if(h1->Integral() == 0 && h2->Integral() == 0){ // std::cout<<"Integral is 0: "<<d1->GetName()<<"/"<<obj1->GetName()<<std::endl; continue; } // if (TString(h1->GetTitle()).Index("ffic")<0) continue; bool isProf = obj1->InheritsFrom(TProfile::Class()); bool isH2 = obj1->InheritsFrom(TH2::Class()); double bDiff = 0; if(!isH2){ unsigned int nX1 = h1->GetNbinsX(); // std::cout<<"\t is 1D with nBins "<<nX1<<std::endl; for(unsigned int iB=0; iB<=nX1+1; ++iB){ if(h1->GetBinError(iB)==0 && h1->GetBinContent(iB)!=0) h1->SetBinError(iB,1e-3*fabs(h1->GetBinContent(iB))); if(h2->GetBinError(iB)==0 && h2->GetBinContent(iB)!=0) h2->SetBinError(iB,1e-3*fabs(h2->GetBinContent(iB))); bDiff +=fabs(h1->GetBinContent(iB) - h2->GetBinContent(iB)); } } else { unsigned int nX1 = h1->GetNbinsX(); unsigned int nY1 = h1->GetNbinsY(); // std::cout<<"\t is 2D with nBins "<<nX1<<" : "<<nY1<<std::endl; for(unsigned int iB=0; iB<=nX1+1; ++iB){ for(unsigned int jB=0; jB<=nY1+1; ++jB){ if(h1->GetBinError(iB,jB)==0 && h1->GetBinContent(iB,jB)!=0) h1->SetBinError(iB,jB,1e-3*fabs(h1->GetBinContent(iB,jB))); if(h2->GetBinError(iB,jB)==0 && h2->GetBinContent(iB,jB)!=0) h2->SetBinError(iB,jB,1e-3*fabs(h2->GetBinContent(iB,jB))); bDiff +=fabs(h1->GetBinContent(iB,jB) - h2->GetBinContent(iB,jB)); } } } double ksProb = 0; if (bDiff == 0) ksProb = 1; else ksProb = h1->KolmogorovTest(h2); if (dOpt%10 == 0 && bDiff ==0 ) continue; if (dOpt%10 == 1 && (bDiff ==0 || 1.-ksProb <1e-12) ) continue; if (dOpt%10 == 2 && (bDiff ==0 || ksProb >0.1 )) continue; if (dOpt%10 == 3 && (bDiff ==0 || 1.-ksProb < 0.001 )) continue; if (dOpt%10 == 4 && (bDiff ==0 || ksProb >0.9 )) continue; if (dOpt%10 == 5 && (bDiff ==0 || ksProb >0.5 )) continue; if (cv == 0){ cv = new TCanvas(dirName.c_str(),dirName.c_str()); cv->cd(); pH = new TPad("head","head", 0, 0.93, 1, 1); pH->Draw(); pH->cd(); pt = new TPaveText(0,0,1,1); pt->SetFillColor(0); pt->AddText(dirName.c_str()); pt->Draw(); cv->cd(); pD = new TPad("dis","dis", 0, 0.0, 1, 0.93); pD->Draw(); pD->cd(); } pD->Clear(); pD->cd(); std::cout<<"Save : "<<dirName.c_str()<<"/"<<h1->GetName()<<std::endl; if (! isH2){ h1->SetLineWidth(2); h1->SetLineColor(1); h1->SetMarkerColor(1); h2->SetLineColor(2); h2->SetMarkerColor(2); // if (h1->GetNbinsX() > 25) h1 = h1->Rebin(); // if (h2->GetNbinsX() > 25) h2 = h2->Rebin(); // if (h1->GetNbinsX() > 50) h1 = h1->Rebin(5); // if (h2->GetNbinsX() > 50) h2 = h2->Rebin(5); double max1 = h1->GetMaximum(); double max2 = h2->GetMaximum(); double min1 = h1->GetMinimum(); double min2 = h2->GetMinimum(); if (max2> max1) h1->SetMaximum(max2+0.15*fabs(max2)); if (min2 < min1) h1->SetMinimum(min2-0.15*fabs(min2)); // pD->SetLogy(); if ((logmod&1)) pD->SetLogx(); if ((logmod&2)) pD->SetLogy(); h1->Draw(); h2->Draw("sames"); if (std::string(h1->GetName())==std::string("reconstruction_step_module_total") || std::string(h1->GetName())==std::string("validation_step_module_total")){ TPaveText ksPt(0,0, 0.35, 0.04, "NDC"); ksPt.SetBorderSize(0); ksPt.SetFillColor(0); ksPt.AddText(Form("P(KS)=%g, diffBins=%g, eblk %g ered %g",ksProb, bDiff, h1->GetEntries(), h2->GetEntries())); // ksPt.AddText(h1->GetName()); ksPt.Draw(); cv->Print("diff.ps"); int nX = h1->GetNbinsX(); TAxis* h1Ax = h1->GetXaxis(); int nRanges = nX/20 + 1; double h1Int = h1->Integral(); float curBMargin = pD->GetBottomMargin(); pD->SetBottomMargin(0.3); for (int iR = 0; iR < nRanges; iR++){ h1Ax->SetRange(iR*20+1, iR*20+20); double bDiffL = 0; double max1L = -1; double max2L = -1; double min1L = h1->GetMaximum(); double min2L = h2->GetMaximum(); for (int iBL = iR*20+1; iBL<= iR*20+20; ++iBL){ double h1L = h1->GetBinContent(iBL); double h2L = h2->GetBinContent(iBL); bDiffL += std::abs(h1L-h2L); if (max1L < h1L) max1L = h1L; if (max2L < h2L) max2L = h2L; if (min1L > h1L) min1L = h1L; if (min2L > h2L) min2L = h2L; } if (max2L> max1L) h1->SetMaximum(max2L+0.15*std::abs(max2L)); else h1->SetMaximum(max1L+0.15*std::abs(max1L)); if (min2L < min1L) h1->SetMinimum(min2L-0.15*std::abs(min2L)); else h1->SetMinimum(min1L-0.15*std::abs(min1L)); h1->Draw(); h2->Draw("sames"); TPaveText ksPtL(0,0, 0.35, 0.04, "NDC"); ksPtL.SetBorderSize(0); ksPtL.SetFillColor(0); ksPtL.AddText(Form("P(KS)=%g, diffBinsL=%g(%g), eblk %g ered %g",ksProb, bDiffL, bDiffL/h1Int, h1->GetEntries(), h2->GetEntries())); ksPtL.Draw(); cv->Print("diff.ps"); } pD->SetBottomMargin(curBMargin); } } if (isH2){ pD->Divide(2); pD->cd(1); h1->Draw("colz"); pD->cd(2); h2->Draw("colz"); } TPaveText ksPt(0,0, 0.55, 0.06, "NDC"); ksPt.SetBorderSize(0); ksPt.SetFillColor(0); ksPt.AddText(Form("P(KS)=%g, diffBins=%g, eblk %g ered %g",ksProb, bDiff, h1->GetEntries(), h2->GetEntries())); ksPt.AddText(h1->GetName()); ksPt.Draw(); cv->Print("diff.ps"); cv->Print("diff.pdf"); } // std::cout<<"Done in "<<dirName.c_str()<<std::endl; // delete pH; delete pD; if (cv) delete cv; // cv->Print("diff.ps]"); }
bool createPlot(TString hname, TString dirname, TFile *V1file, TString runstring1, TString relstring1, TFile *V2file, TString runstring2, TString relstring2, TCanvas *canvas, int scale) { setTDRStyle(); int SetScale = scale; //IF =0 --> No scale applied ('direct' comparison) //IF =1 --> Scale INDIVIDUALLY (scale histograms individually) //IF =2 --> Scale all GLOBALLY (scale all histograms to #tracks=1) //IF =3 --> Scale all GLOBALLY nEVENTS (scale all histos to nEntries in nTracks per Event) bool DrawRatio = true; canvas->cd(); TPad* mainpad = new TPad("mainpad","mainpad",0.0,0.0,1.0,0.8); mainpad->Draw(); mainpad->cd(); // ************ Get name of histos and get histos ************* // if (dirname.Contains("GeneralProperties/GoodTracks",TString::kExact)){ if ((hname != "FractionOfGoodTracks") && (hname != "NumberOfGoodTracks")){ hname.Prepend("GoodTrack"); } } TString basename1 = "DQMData/Run "; basename1.Append(runstring1); TString hnameV1 = basename1; hnameV1.Append(dirname+"/"); hnameV1.Append(hname); if (hname != "vtxNbr"){ hnameV1.Append("_GenTk"); } TH1F * hBinTempV1 = (TH1F*)V1file->Get(hnameV1); if ( hBinTempV1 == (TH1F*) NULL ) { cout << "histV1 failed on " << hnameV1 << endl << " for file " << V1file->GetName() << endl; exit(1); } TString basename2 = "DQMData/Run "; basename2.Append(runstring2); TString hnameV2 = basename2; hnameV2.Append(dirname+"/"); hnameV2.Append(hname); if (hname != "vtxNbr"){ hnameV2.Append("_GenTk"); } TH1F * hBinTempV2 = (TH1F*)V2file->Get(hnameV2); if ( hBinTempV2 == (TH1F*) NULL ) { cout << "histV2 failed on " << hnameV2 << endl << " for file " << V2file->GetName() << endl; exit(1); } // Check that bins match for ratio plot TH1F * histV1 = 0; TH1F * histV2 = 0; Double_t h1_xlow = hBinTempV1->GetXaxis()->GetBinLowEdge(hBinTempV1->GetXaxis()->GetFirst()); Double_t h2_xlow = hBinTempV2->GetXaxis()->GetBinLowEdge(hBinTempV2->GetXaxis()->GetFirst()); Double_t h1_xup = hBinTempV1->GetXaxis()->GetBinUpEdge(hBinTempV1->GetXaxis()->GetLast()); Double_t h2_xup = hBinTempV2->GetXaxis()->GetBinUpEdge(hBinTempV2->GetXaxis()->GetLast()); Int_t h1_nbins = hBinTempV1->GetNbinsX(); Int_t h2_nbins = hBinTempV2->GetNbinsX(); Double_t h1_binWidth = (h1_xup - h1_xlow) / (Double_t)h1_nbins; Double_t h2_binWidth = (h2_xup - h2_xlow) / (Double_t)h2_nbins; if ((h1_xlow == h2_xlow) && (h1_xup == h2_xup) && (h1_binWidth == h2_binWidth)){ histV1 = (TH1F*)V1file->Get(hnameV1); histV2 = (TH1F*)V2file->Get(hnameV2); } else if((h1_xlow == h2_xlow) && (h1_xup < h2_xup) && (h1_binWidth == h2_binWidth)){ // Fill h1 from h1xlow to h1high with h1 info, and up to h2high, fill zero histV2 = (TH1F*)V2file->Get(hnameV2); // copy histV2 histV1 = new TH1F(hBinTempV1->GetName(),hBinTempV1->GetTitle(),h2_nbins,h2_xlow,h2_xup); histV1->SetXTitle(hBinTempV1->GetXaxis()->GetTitle()); histV1->SetYTitle(hBinTempV1->GetYaxis()->GetTitle()); for (Int_t ibin = 1; ibin <= h2_nbins; ibin++){ if (ibin <= h1_nbins){ histV1->SetBinContent(ibin,hBinTempV1->GetBinContent(ibin)); } else if (ibin > h1_nbins){ histV1->SetBinContent(ibin,0.0); } } } else if((h1_xlow == h2_xlow) && (h1_xup > h2_xup) && (h1_binWidth == h2_binWidth)){ // Fill h1 from h1xlow to h1high with h1 info, and up to h2high, fill zero histV1 = (TH1F*)V1file->Get(hnameV1); // copy histV1 histV2 = new TH1F(hBinTempV2->GetName(),hBinTempV2->GetTitle(),h1_nbins,h1_xlow,h1_xup); histV2->SetXTitle(hBinTempV2->GetXaxis()->GetTitle()); histV2->SetYTitle(hBinTempV2->GetYaxis()->GetTitle()); for (Int_t ibin = 1; ibin <= h1_nbins; ibin++){ if (ibin <= h2_nbins){ histV2->SetBinContent(ibin,hBinTempV2->GetBinContent(ibin)); } else if (ibin > h2_nbins){ histV2->SetBinContent(ibin,0.0); } } } else{ cout << "Bin Check Failed... here's what happened: " << endl; cout << "histV1 failed on " << hnameV1 << endl << " for file " << V1file->GetName() << endl; cout << " bin info: " << h1_xlow << " " << h1_xup << " " << h1_nbins << endl; cout << "histV2 failed on " << hnameV2 << endl << " for file " << V2file->GetName() << endl; cout << " bin info: " << h2_xlow << " " << h2_xup << " " << h2_nbins << endl; exit(1); } // Don't look at zero bin -- > Also could use this for truncation and bin setting -->Range is binlower to upper // Int_t range_upper = histV1->GetXaxis()->GetLast(); // histV1->GetXaxis()->SetRangeUser(1,range_upper); // histV2->GetXaxis()->SetRangeUser(1,range_upper); //******************* Get histo integrals ***********************// double V1_integral = 1.0; double V2_integral = 1.0; TH1F * hNormTempV1 = 0; TH1F * hNormTempV2 = 0; if (SetScale==1){ V1_integral = histV1->Integral(); V2_integral = histV2->Integral(); } else if ( (SetScale==2) || (SetScale==3) ){ if (hname != "NumberOfTracks"){ TString hTempNameV1 = basename1; hTempNameV1.Append("/Tracking/Run summary/TrackParameters/GeneralProperties/NumberOfTracks_GenTk"); hNormTempV1 = (TH1F*)V1file->Get(hTempNameV1); TString hTempNameV2 = basename2; hTempNameV2.Append("/Tracking/Run summary/TrackParameters/GeneralProperties/NumberOfTracks_GenTk"); hNormTempV2 = (TH1F*)V2file->Get(hTempNameV2); } else{ hNormTempV1 = (TH1F*)histV1->Clone("hNormTempV1"); hNormTempV2 = (TH1F*)histV2->Clone("hNormTempV2"); } if (SetScale==2){ V1_integral = hNormTempV1->GetBinContent(2); V2_integral = hNormTempV2->GetBinContent(2); std::cout << "The number of single tracks for V1 is " << V1_integral << std::endl; std::cout << "The number of single tracks for V2 is " << V2_integral << std::endl; } else if (SetScale==3){ V1_integral = hNormTempV1->GetEntries(); V2_integral = hNormTempV2->GetEntries(); std::cout << "The number of events for V1 is " << V1_integral << std::endl; std::cout << "The number of events for V2 is " << V2_integral << std::endl; } } //*****NORMALIZING V1-V2**************************************** if(V1_integral>V2_integral) { histV1->Scale(V2_integral / V1_integral); histV2->Scale(1); } else if(V2_integral>V1_integral){ histV1->Scale(1); histV2->Scale(V1_integral / V2_integral); } //*****NORMALIZING V1-V2*end*************************************** //***Name the files under comparison*** TString V1_V1run = "Run "+runstring1+" ("+relstring1+")"; TString V2_V2run = "Run "+runstring2+" ("+relstring2+")"; histV1->SetName(V1_V1run); histV2->SetName(V2_V2run); double max = 0; double V1max = histV1->GetBinContent(histV1->GetMaximumBin()); double V2max = histV2->GetBinContent(histV2->GetMaximumBin()); max = (V1max>V2max) ? V1max : V2max; histV1->Draw(); histV1->SetLineStyle(1); histV1->GetYaxis()->SetLabelSize(0.038); histV1->SetLineWidth(5); histV1->SetLineColor(kRed); histV1->SetMaximum(max*(1.1)); histV2->Draw(); histV2->SetLineWidth(3); histV2->SetLineStyle(1); histV2->SetLineColor(kBlue); if( hname.Contains("NumberOfTracks",TString::kExact) || hname.Contains("NumberOfGoodTracks",TString::kExact) || hname.Contains("TrackPt",TString::kExact) || hname.Contains("Chi2Prob",TString::kExact) ){ mainpad->SetLogy(1); } else{ mainpad->SetLogy(0); } if (hname.Contains("NumberOfTracks",TString::kExact)){ histV1->GetXaxis()->SetRangeUser(0,500); histV2->GetXaxis()->SetRangeUser(0,500); } if (hname.Contains("NumberOfGoodTracks",TString::kExact)) { histV1->GetXaxis()->SetRangeUser(0,200); histV2->GetXaxis()->SetRangeUser(0,200); } if (hname.Contains("Chi2oNDF",TString::kExact)) { histV1->GetXaxis()->SetRangeUser(0,10); histV2->GetXaxis()->SetRangeUser(0,10); } if (hname.Contains("vtxNbr")){ histV1->GetXaxis()->SetTitle("Number of Primary Vertices per Event"); histV1->GetYaxis()->SetTitle("Number of Events"); } histV1->Draw(); // Draw old histo first, ratio is new/old histV2->Draw("sames"); mainpad->Update(); TPaveStats *st1 = (TPaveStats*)(histV1->GetListOfFunctions()->FindObject("stats")); st1->SetX1NDC(0.77); st1->SetY1NDC(0.80); st1->SetX2NDC(0.98); st1->SetY2NDC(0.97); Double_t defaulth = st1->GetY2NDC() - st1->GetY1NDC(); Double_t gaph = 0.02; TPaveStats *st2 = (TPaveStats*)(histV2->GetListOfFunctions()->FindObject("stats")); st2->SetX1NDC(0.77); st2->SetY1NDC(st1->GetY1NDC() - 1.0*defaulth - gaph); st2->SetX2NDC(0.98); st2->SetY2NDC(st1->GetY1NDC() - gaph); TLegend *leg = new TLegend(0.32,0.86,0.76,0.97); leg->SetTextSize(0.042); leg->SetTextFont(42); leg->SetFillColor(10); leg->SetBorderSize(1); // no frame, no shadow leg->AddEntry(histV1, V1_V1run, "L" ); leg->AddEntry(histV2, V2_V2run, "L" ); leg->Draw("SAME"); // Draw ratio histogram if (DrawRatio){ canvas->cd(); TPad* respad = new TPad("respad","respad",0.0,0.78,1.0,0.95); respad->SetTopMargin(1.05); respad->Draw(); respad->cd(); TH1F* hratio = (TH1F*) histV2->Clone("hratio"); hratio->Divide(histV1); hratio->SetMaximum(hratio->GetMaximum()*1.1); hratio->SetMinimum(hratio->GetMinimum()/1.1); //if (hratio->GetMinimum()==0.0) hratio->SetMinimum(1.0/hratio->GetMaximum()); // hratio->SetMinimum(1.0/hratio->GetMaximum()); hratio->GetYaxis()->SetLabelSize(0.1); // hratio->GetYaxis()->SetRangeUser(0,2); hratio->GetXaxis()->SetLabelSize(0); hratio->GetXaxis()->SetTitleSize(0); hratio->GetYaxis()->SetTitleSize(0.22); hratio->GetYaxis()->SetTitleOffset(0.26); hratio->GetYaxis()->SetLabelSize(0.2); hratio->GetYaxis()->SetNdivisions(5); hratio->GetYaxis()->SetTitle("NEW/REF"); hratio->Draw(); } // Compare parameters of histograms double Entries1 = histV1->GetEntries(); double Entries2 = histV2->GetEntries(); if (Entries1 != Entries2) { std::cout<<" Difference in # of ENTRIES for " <<hname<< std::endl; std::cout<<"\t Entries1 = " << Entries1 << "\t Entries2 = " << Entries2 << std::endl; } double Mean1 = histV1->GetMean(); double Mean2 = histV2->GetMean(); if (Mean1 != Mean2) { std::cout<<" Difference in MEANS for " <<hname<< std::endl; std::cout<<"\t Mean1 = " << Mean1 << "\t Mean2 = " << Mean2 << std::endl; } double RMS1 = histV1->GetRMS(); double RMS2 = histV2->GetRMS(); if (RMS1 != RMS2) { std::cout<<" Difference in RMS for " <<hname<< std::endl; std::cout<<"\t RMS1 = " << RMS1 << "\t RMS2 = " << RMS2 << std::endl; } TString filename = hname; if (hname.Contains("vtxNbr")){ filename = "NumberOfPrimaryVertices"; } if (dirname.Contains("GeneralProperties/GoodTracks",TString::kExact)) filename.Prepend("RunComparison/GoodTracks_"); else filename.Prepend("RunComparison/"); filename.Append(".png"); canvas->Print(filename); if ( histV1 ) {histV1->Delete();} if ( histV2 ) {histV2->Delete();} if ( hNormTempV1 ) {hNormTempV1->Delete();} if ( hNormTempV2 ) {hNormTempV2->Delete();} // if ( hBinTempV1 ) {hBinTempV1->Delete();} // why cant this work?! // if ( hBinTempV2 ) {hBinTempV2->Delete();} return true; }
void plotDistribution( TChain* data , TChain *mc , TCut sel , TCut vtxweight , char* var , int nbins , float xmin , float xmax , char* xtitle , char* plottitle = "" , bool printplot = false , bool residual = false , bool log = false ){ //-------------------------------------- // define histograms and TGraphs //-------------------------------------- TH1F* hdata = new TH1F(Form("hdata_%i" , iplot),Form("hdata_%i" , iplot),nbins,xmin,xmax); TH1F* hmc = new TH1F(Form("hmc_%i" , iplot),Form("hmc_%i" , iplot),nbins,xmin,xmax); TH1F* hmc_novtx = new TH1F(Form("hmc_novtx_%i" , iplot),Form("hmc_novtx%i" , iplot),nbins,xmin,xmax); hdata->Sumw2(); hmc->Sumw2(); TGraphAsymmErrors* grdata = new TGraphAsymmErrors(); TGraphAsymmErrors* grmc = new TGraphAsymmErrors(); TH1F* hdata_denom = new TH1F(Form("hdata_denom_%i",iplot),"",nbins,xmin,xmax); TH1F* hmc_denom = new TH1F(Form("hmc_denom_%i" ,iplot),"",nbins,xmin,xmax); //-------------------------------------- // set up canvas and pads //-------------------------------------- TCanvas *can = new TCanvas(Form("can_%i",iplot),Form("can_%i",iplot),600,600); can->cd(); if( log ) gPad->SetLogy(); TPad *mainpad = new TPad("mainpad","mainpad",0.0,0.0,1.0,0.8); if( residual ){ mainpad->Draw(); mainpad->cd(); if( log ) mainpad->SetLogy(); } //-------------------------------------- // fill histos and TGraphs //-------------------------------------- data->Draw(Form("min(%s,%f)>>hdata_%i" , var,xmax-0.0001,iplot),sel); mc ->Draw(Form("min(%s,%f)>>hmc_%i" , var,xmax-0.0001,iplot),sel*vtxweight); mc ->Draw(Form("min(%s,%f)>>hmc_novtx_%i" , var,xmax-0.0001,iplot),sel); for( int ibin = 1 ; ibin <= nbins ; ibin++ ){ hdata_denom->SetBinContent(ibin,hdata->Integral()); hmc_denom->SetBinContent(ibin,hmc->Integral()); } grdata->BayesDivide(hdata,hdata_denom); grmc->BayesDivide(hmc_novtx,hmc_denom); //-------------------------------------- // get efficiencies and errors //-------------------------------------- /* float ndata1 = (float) hdata->GetBinContent(1); float ndata = (float) hdata->Integral(); float effdata = 1-ndata1 / ndata; // TGraphAsymmErrors* grdata_temp = new TGraphAsymmErrors(); // TH1F* hdata_num_temp = new TH1F(Form("hdata_num_temp_%i",iplot),"",1,0,1); // TH1F* hdata_den_temp = new TH1F(Form("hdata_den_temp_%i",iplot),"",1,0,1); // hdata_num_temp->SetBinContent(1,ndata-ndata1); // hdata_den_temp->SetBinContent(1,ndata); // grdata_temp->BayesDivide(hdata_num_temp,hdata_den_temp); //float effdataerr = sqrt(ndata1) / ndata; float effdataerr = 0.5 * ( grdata->GetErrorYlow(0) + grdata->GetErrorYhigh(0) ); //float effdataerr = 0.5 * ( grdata_temp->GetErrorYlow(0) + grdata_temp->GetErrorYhigh(0) ); float nmc1 = (float) hmc->GetBinContent(1); float nmc = (float) hmc->Integral(); float effmc = 1-nmc1 / nmc; //float effmcerr = hmc->GetBinError(1) / nmc; float effmcerr = 0.5 * ( grmc->GetErrorYlow(0) + grmc->GetErrorYhigh(0) ); float datatot = hdata->Integral(); float mctot = hmc->Integral(); cout << endl; cout << plottitle << endl; cout << "Data eff " << Form("%.2f +/- %.3f",effdata,effdataerr) << endl; cout << "MC eff " << Form("%.2f +/- %.3f",effmc ,effmcerr) << endl; cout << "Data/MC " << Form("%.2f +/- %.2f",ratio ,ratioerr) << endl; */ float ndata = hdata->Integral(); float ndata1 = hdata->Integral(2,20); float ndata2 = hdata->Integral(3,20); float ndata3 = hdata->Integral(4,20); float ndata4 = hdata->Integral(5,20); float ndata5 = hdata->Integral(6,20); float nmc = hmc->Integral(); float nmc1 = hmc->Integral(2,20); float nmc2 = hmc->Integral(3,20); float nmc3 = hmc->Integral(4,20); float nmc4 = hmc->Integral(5,20); float nmc5 = hmc->Integral(6,20); float effdata1 = ndata1/ndata; float effdata2 = ndata2/ndata; float effdata3 = ndata3/ndata; float effdata4 = ndata4/ndata; float effdata5 = ndata5/ndata; float effmc1 = nmc1/nmc; float effmc2 = nmc2/nmc; float effmc3 = nmc3/nmc; float effmc4 = nmc4/nmc; float effmc5 = nmc5/nmc; float effdata1err = getBinomialError(ndata1,ndata); float effdata2err = getBinomialError(ndata2,ndata); float effdata3err = getBinomialError(ndata3,ndata); float effdata4err = getBinomialError(ndata4,ndata); float effdata5err = getBinomialError(ndata5,ndata); float effmc1err = getBinomialError(nmc1,nmc); float effmc2err = getBinomialError(nmc2,nmc); float effmc3err = getBinomialError(nmc3,nmc); float effmc4err = getBinomialError(nmc4,nmc); float effmc5err = getBinomialError(nmc5,nmc); float ratio1 = effdata1/effmc1; float ratio2 = effdata2/effmc2; float ratio3 = effdata3/effmc3; float ratio4 = effdata4/effmc4; float ratio5 = effdata5/effmc5; float ratio1err = ratio1 * sqrt(pow(effdata1err/effdata1,2)+pow(effmc1err/effmc1,2)); float ratio2err = ratio2 * sqrt(pow(effdata2err/effdata2,2)+pow(effmc2err/effmc2,2)); float ratio3err = ratio3 * sqrt(pow(effdata3err/effdata3,2)+pow(effmc3err/effmc3,2)); float ratio4err = ratio4 * sqrt(pow(effdata4err/effdata4,2)+pow(effmc4err/effmc4,2)); float ratio5err = ratio5 * sqrt(pow(effdata5err/effdata5,2)+pow(effmc5err/effmc5,2)); cout << endl << endl << plottitle << endl; int left = 20; // char* delimstart = "|"; // char* delim = "|"; // char* delimend = "|"; // char* pm = "+/-"; char* delimstart = ""; char* delim = "&"; char* delimend = "\\\\"; char* pm = "$\\pm$"; cout << delimstart << setw(10) << "" << setw(4) << delim << setw(left) << "$>$ 1 GeV" << setw(4) << delim << setw(left) << "$>$ 2 GeV" << setw(4) << delim << setw(left) << "$>$ 3 GeV" << setw(4) << delim << setw(left) << "$>$ 4 GeV" << setw(4) << delim << setw(left) << "$>$ 5 GeV" << setw(4) << delimend << endl; cout << delimstart << setw(10) << "data" << setw(4) << delim << setw(left) << Form("%.3f %s %.4f",effdata1,pm,effdata1err) << setw(4) << delim << setw(left) << Form("%.3f %s %.4f",effdata2,pm,effdata2err) << setw(4) << delim << setw(left) << Form("%.3f %s %.4f",effdata3,pm,effdata3err) << setw(4) << delim << setw(left) << Form("%.3f %s %.4f",effdata4,pm,effdata4err) << setw(4) << delim << setw(left) << Form("%.3f %s %.4f",effdata5,pm,effdata5err) << setw(4) << delimend << endl; cout << delimstart << setw(10) << "mc" << setw(4) << delim << setw(left) << Form("%.3f %s %.4f",effmc1,pm,effmc1err) << setw(4) << delim << setw(left) << Form("%.3f %s %.4f",effmc2,pm,effmc2err) << setw(4) << delim << setw(left) << Form("%.3f %s %.4f",effmc3,pm,effmc3err) << setw(4) << delim << setw(left) << Form("%.3f %s %.4f",effmc4,pm,effmc4err) << setw(4) << delim << setw(left) << Form("%.3f %s %.4f",effmc5,pm,effmc5err) << setw(4) << delimend << endl; cout << delimstart << setw(10) << "data/mc" << setw(4) << delim << setw(left) << Form("%.2f %s %.2f",ratio1,pm,ratio1err) << setw(4) << delim << setw(left) << Form("%.2f %s %.2f",ratio2,pm,ratio2err) << setw(4) << delim << setw(left) << Form("%.2f %s %.2f",ratio3,pm,ratio3err) << setw(4) << delim << setw(left) << Form("%.2f %s %.2f",ratio4,pm,ratio4err) << setw(4) << delim << setw(left) << Form("%.2f %s %.2f",ratio5,pm,ratio5err) << setw(4) << delimend << endl; //-------------------------------------- // draw stuff //-------------------------------------- hdata->Scale(1.0/hdata->Integral()); hmc->Scale(1.0/hmc->Integral()); if( log ) hmc->GetYaxis()->SetRangeUser(0.0001,5); else hmc->GetYaxis()->SetRangeUser(0.0,1); hmc->GetXaxis()->SetTitle(xtitle); hmc->SetLineColor(2); hmc->SetMarkerColor(2); hmc->DrawNormalized("hist"); hmc->DrawNormalized("sameE1"); hdata->SetLineColor(4); hdata->SetMarkerColor(4); hdata->Draw("sameE1"); grdata->SetLineColor(6); grmc->SetLineColor(7); //grdata->Draw("sameP"); //grmc->Draw("sameP"); TLegend *leg = new TLegend(0.6,0.7,0.8,0.9); leg->AddEntry(hdata , "data" , "lp"); leg->AddEntry(hmc , "MC" , "lp"); leg->SetBorderSize(0); leg->SetFillColor(0); leg->Draw(); TLatex *t = new TLatex(); t->SetNDC(); if( TString(plottitle).Contains("el") ) t->DrawLatex(0.6,0.6,"electrons"); if( TString(plottitle).Contains("mu") ) t->DrawLatex(0.6,0.6,"muons"); if( TString(plottitle).Contains("0j") ) t->DrawLatex(0.6,0.5,"n_{jets} #geq 0"); if( TString(plottitle).Contains("1j") ) t->DrawLatex(0.6,0.5,"n_{jets} #geq 1"); if( TString(plottitle).Contains("2j") ) t->DrawLatex(0.6,0.5,"n_{jets} #geq 2"); if( TString(plottitle).Contains("3j") ) t->DrawLatex(0.6,0.5,"n_{jets} #geq 3"); if( TString(plottitle).Contains("4j") ) t->DrawLatex(0.6,0.5,"n_{jets} #geq 4"); //-------------------------------------- // draw residual plots //-------------------------------------- if( residual ){ can->cd(); TPad *respad = new TPad("respad","respad",0.0,0.8,1.0,1.0); respad->Draw(); respad->cd(); respad->SetGridy(); TH1F* hratio = (TH1F*) hdata->Clone(Form("hratio_%i",iplot)); hratio->Divide(hmc); hratio->SetMarkerColor(1); hratio->SetLineColor(1); hratio->Draw(); hratio->GetYaxis()->SetRangeUser(0.5,1.5); hratio->GetYaxis()->SetNdivisions(5); hratio->GetYaxis()->SetLabelSize(0.2); hratio->GetXaxis()->SetLabelSize(0.0); TLine line; line.DrawLine(xmin,1.0,xmax,1.0); } //data->Scan("run:lumi:event:probe->pt():probe->eta():tkisonew:met:mt:njets:nbl:nbm",sel+"tkisonew>20"); //data->Scan("run:lumi:event:probe->pt():probe->eta():tkisonew:met:mt:njets:nbl:nbm",sel); if( printplot ) can->Print(Form("plots/%s.pdf",plottitle)); iplot++; // TCanvas *c2 = new TCanvas(); // c2->cd(); // grdata->Draw("AP"); }
void QA_Draw_Jet_Spectrum( // // const char * jet = "h_QAG4SimJet_AntiKt_Tower_r07", const char *jet = "h_QAG4SimJet_AntiKt_Truth_r07", const char *qa_file_name_new = "data/G4sPHENIXCells_250jets25GeV.root_qa.root", const char *qa_file_name_ref = "data/G4sPHENIXCells_2000jets25GeV.root_qa.root") { SetsPhenixStyle(); TVirtualFitter::SetDefaultFitter("Minuit2"); TFile *qa_file_new = new TFile(qa_file_name_new); assert(qa_file_new->IsOpen()); TFile *qa_file_ref = NULL; if (qa_file_name_ref) { qa_file_ref = new TFile(qa_file_name_ref); assert(qa_file_ref->IsOpen()); } // obtain normalization double Nevent_new = 1; double Nevent_ref = 1; if (qa_file_new) { TH1D *h_norm = (TH1D *) qa_file_new->GetObjectChecked( TString(jet) + TString("_Normalization"), "TH1D"); assert(h_norm); Nevent_new = h_norm->GetBinContent(h_norm->GetXaxis()->FindBin("Event")); } if (qa_file_ref) { TH1D *h_norm = (TH1D *) qa_file_ref->GetObjectChecked( TString(jet) + TString("_Normalization"), "TH1D"); assert(h_norm); Nevent_ref = h_norm->GetBinContent(h_norm->GetXaxis()->FindBin("Event")); } TCanvas *c1 = new TCanvas(TString("QA_Draw_Jet_Spectrum_") + TString(jet), TString("QA_Draw_Jet_Spectrum_") + TString(jet), 1800, 1000); c1->Divide(4, 2); int idx = 1; TPad *p; p = (TPad *) c1->cd(idx++); c1->Update(); p->SetLogy(); { TH1F *h_new = (TH1F *) qa_file_new->GetObjectChecked( TString(jet) + TString("_Leading_eta"), "TH1F"); assert(h_new); h_new->Rebin(2); h_new->Sumw2(); h_new->Scale(1. / Nevent_new); TH1F *h_ref = NULL; if (qa_file_ref) { h_ref = (TH1F *) qa_file_ref->GetObjectChecked( TString(jet) + TString("_Leading_eta"), "TH1F"); assert(h_ref); h_ref->Rebin(2); h_ref->Scale(1. / Nevent_ref); } h_new->GetYaxis()->SetTitleOffset(1.5); h_new->GetYaxis()->SetTitle("Count / event / bin"); // h_new->GetXaxis()->SetRangeUser(-0, .1); DrawReference(h_new, h_ref); } p = (TPad *) c1->cd(idx++); c1->Update(); p->SetLogy(); { TH1F *h_new = (TH1F *) qa_file_new->GetObjectChecked( TString(jet) + TString("_Leading_phi"), "TH1F"); assert(h_new); h_new->Rebin(2); h_new->Sumw2(); h_new->Scale(1. / Nevent_new); TH1F *h_ref = NULL; if (qa_file_ref) { h_ref = (TH1F *) qa_file_ref->GetObjectChecked( TString(jet) + TString("_Leading_phi"), "TH1F"); assert(h_ref); h_ref->Rebin(2); h_ref->Scale(1. / Nevent_ref); } h_new->GetYaxis()->SetTitleOffset(1.5); h_new->GetYaxis()->SetTitle("Count / event / bin"); // h_new->GetXaxis()->SetRangeUser(-0, .1); DrawReference(h_new, h_ref); } p = (TPad *) c1->cd(idx++); c1->Update(); p->SetLogy(); { TH1F *h_new = (TH1F *) qa_file_new->GetObjectChecked( TString(jet) + TString("_Leading_Et"), "TH1F"); assert(h_new); h_new->Sumw2(); h_new->Scale(1. / Nevent_new); TH1F *h_ref = NULL; if (qa_file_ref) { h_ref = (TH1F *) qa_file_ref->GetObjectChecked( TString(jet) + TString("_Leading_Et"), "TH1F"); assert(h_ref); h_ref->Scale(1. / Nevent_ref); } h_new->GetYaxis()->SetTitleOffset(1.5); h_new->GetYaxis()->SetTitle("Count / event / bin"); // h_new->GetXaxis()->SetRangeUser(-0, .1); DrawReference(h_new, h_ref); } p = (TPad *) c1->cd(idx++); c1->Update(); p->SetLogy(); { TH1F *h_new = (TH1F *) qa_file_new->GetObjectChecked( TString(jet) + TString("_Leading_Mass"), "TH1F"); assert(h_new); h_new->Rebin(2); h_new->Sumw2(); h_new->Scale(1. / Nevent_new); TH1F *h_ref = NULL; if (qa_file_ref) { h_ref = (TH1F *) qa_file_ref->GetObjectChecked( TString(jet) + TString("_Leading_Mass"), "TH1F"); assert(h_ref); h_ref->Rebin(2); h_ref->Scale(1. / Nevent_ref); } h_new->GetYaxis()->SetTitleOffset(1.5); h_new->GetYaxis()->SetTitle("Count / event / bin"); // h_new->GetXaxis()->SetRangeUser(-0, .1); DrawReference(h_new, h_ref); } p = (TPad *) c1->cd(idx++); c1->Update(); p->SetLogx(); { TH1F *h_new = (TH1F *) qa_file_new->GetObjectChecked( TString(jet) + TString("_Leading_CompSize"), "TH1F"); assert(h_new); h_new->Rebin(2); h_new->Sumw2(); h_new->Scale(1. / Nevent_new); TH1F *h_ref = NULL; if (qa_file_ref) { h_ref = (TH1F *) qa_file_ref->GetObjectChecked( TString(jet) + TString("_Leading_CompSize"), "TH1F"); assert(h_ref); h_ref->Rebin(2); h_ref->Scale(1. / Nevent_ref); } h_new->GetYaxis()->SetTitleOffset(1.5); h_new->GetYaxis()->SetTitle("Count / event / bin"); // h_new->GetXaxis()->SetRangeUser(-0, .1); DrawReference(h_new, h_ref); } p = (TPad *) c1->cd(idx++); c1->Update(); p->SetLogy(); { TH1F *h_new = (TH1F *) qa_file_new->GetObjectChecked( TString(jet) + TString("_Leading_CEMC_Ratio"), "TH1F"); assert(h_new); h_new->Rebin(2); h_new->Sumw2(); h_new->Scale(1. / Nevent_new); TH1F *h_ref = NULL; if (qa_file_ref) { h_ref = (TH1F *) qa_file_ref->GetObjectChecked( TString(jet) + TString("_Leading_CEMC_Ratio"), "TH1F"); assert(h_ref); h_ref->Rebin(2); h_ref->Scale(1. / Nevent_ref); } h_new->GetYaxis()->SetTitleOffset(1.5); h_new->GetYaxis()->SetTitle("Count / event / bin"); // h_new->GetXaxis()->SetRangeUser(-0, .1); DrawReference(h_new, h_ref); } p = (TPad *) c1->cd(idx++); c1->Update(); p->SetLogy(); { TH1F *h_new = (TH1F *) qa_file_new->GetObjectChecked( TString(jet) + TString("_Leading_CEMC_HCalIN_Ratio"), "TH1F"); assert(h_new); h_new->Rebin(2); h_new->Sumw2(); h_new->Scale(1. / Nevent_new); TH1F *h_ref = NULL; if (qa_file_ref) { h_ref = (TH1F *) qa_file_ref->GetObjectChecked( TString(jet) + TString("_Leading_CEMC_HCalIN_Ratio"), "TH1F"); assert(h_ref); h_ref->Rebin(2); h_ref->Scale(1. / Nevent_ref); } h_new->GetYaxis()->SetTitleOffset(1.5); h_new->GetYaxis()->SetTitle("Count / event / bin"); // h_new->GetXaxis()->SetRangeUser(-0, .1); DrawReference(h_new, h_ref); } if (TString(jet).Contains("Truth")) { // truth jets p = (TPad *) c1->cd(idx++); c1->Update(); p->SetLogy(); { TH1F *h_new = (TH1F *) qa_file_new->GetObjectChecked( TString(jet) + TString("_Leading_Leakage_Ratio"), "TH1F"); assert(h_new); h_new->Rebin(2); h_new->Sumw2(); h_new->Scale(1. / Nevent_new); TH1F *h_ref = NULL; if (qa_file_ref) { h_ref = (TH1F *) qa_file_ref->GetObjectChecked( TString(jet) + TString("_Leading_Leakage_Ratio"), "TH1F"); assert(h_ref); h_ref->Rebin(2); h_ref->Scale(1. / Nevent_ref); } h_new->GetYaxis()->SetTitleOffset(1.5); h_new->GetYaxis()->SetTitle("Count / event / bin"); // h_new->GetXaxis()->SetRangeUser(-0, .1); DrawReference(h_new, h_ref); } } // PutInputFileName(c1, .04, qa_file_name_new, qa_file_name_ref); SaveCanvas(c1, TString(qa_file_name_new) + TString(c1->GetName()), true); }
void showHistograms(double canvasSizeX, double canvasSizeY, TH1* histogram_ref, const std::string& legendEntry_ref, double integral_ref, TH1* histogram2, const std::string& legendEntry2, double integral2, TH1* histogram3, const std::string& legendEntry3, double integral3, TH1* histogram4, const std::string& legendEntry4, double integral4, TH1* histogram5, const std::string& legendEntry5, double integral5, TH1* histogram6, const std::string& legendEntry6, double integral6, const std::string& xAxisTitle, double xAxisOffset, bool useLogScale, double yMin, double yMax, const std::string& yAxisTitle, double yAxisOffset, double legendX0, double legendY0, const std::string& outputFileName) { if ( !(histogram_ref && histogram2) ) return; TCanvas* canvas = new TCanvas("canvas", "canvas", canvasSizeX, canvasSizeY); canvas->SetFillColor(10); canvas->SetBorderSize(2); canvas->SetLeftMargin(0.12); canvas->SetBottomMargin(0.12); TPad* topPad = new TPad("topPad", "topPad", 0.00, 0.35, 1.00, 1.00); topPad->SetFillColor(10); topPad->SetTopMargin(0.04); topPad->SetLeftMargin(0.15); topPad->SetBottomMargin(0.03); topPad->SetRightMargin(0.05); topPad->SetLogy(useLogScale); TPad* bottomPad = new TPad("bottomPad", "bottomPad", 0.00, 0.00, 1.00, 0.35); bottomPad->SetFillColor(10); bottomPad->SetTopMargin(0.02); bottomPad->SetLeftMargin(0.15); bottomPad->SetBottomMargin(0.24); bottomPad->SetRightMargin(0.05); bottomPad->SetLogy(false); canvas->cd(); topPad->Draw(); topPad->cd(); //int colors[6] = { kBlack, kGreen - 6, kBlue - 7, kMagenta - 7, kCyan - 6, kRed - 6 }; int colors[6] = { kBlack, kRed, kBlue - 7, kMagenta - 7, kCyan - 6, kRed - 6 }; int markerStyles[6] = { 24, 25, 20, 21, 22, 23 }; int markerSizes[6] = { 1, 1, 1, 1, 1, 1 }; TLegend* legend = new TLegend(legendX0, legendY0, legendX0 + 0.61, legendY0 + 0.21, "", "brNDC"); legend->SetBorderSize(0); legend->SetFillColor(0); histogram_ref->SetTitle(""); histogram_ref->SetStats(false); histogram_ref->SetMinimum(yMin); histogram_ref->SetMaximum(yMax); histogram_ref->SetLineColor(colors[0]); histogram_ref->SetLineWidth(2); histogram_ref->SetMarkerColor(colors[0]); histogram_ref->SetMarkerStyle(markerStyles[0]); histogram_ref->SetMarkerSize(markerSizes[0]); histogram_ref->Draw("e1p"); //if ( integral_ref >= 0. ) legend->AddEntry(histogram_ref, Form("%s: %1.2f", legendEntry_ref.data(), integral_ref), "p"); //else legend->AddEntry(histogram_ref, legendEntry_ref.data(), "p"); legend->AddEntry(histogram_ref, Form("%s: %1.2f", legendEntry_ref.data(), integral_ref), "p"); TAxis* xAxis_top = histogram_ref->GetXaxis(); xAxis_top->SetTitle(xAxisTitle.data()); xAxis_top->SetTitleOffset(xAxisOffset); xAxis_top->SetLabelColor(10); xAxis_top->SetTitleColor(10); TAxis* yAxis_top = histogram_ref->GetYaxis(); yAxis_top->SetTitle(yAxisTitle.data()); yAxis_top->SetTitleOffset(yAxisOffset); if ( histogram2 ) { histogram2->SetLineColor(colors[1]); histogram2->SetLineWidth(2); histogram2->SetMarkerColor(colors[1]); histogram2->SetMarkerStyle(markerStyles[1]); histogram2->SetMarkerSize(markerSizes[1]); histogram2->Draw("e1psame"); //if ( integral2 >= 0. ) legend->AddEntry(histogram2, Form("%s: %1.2f", legendEntry2.data(), integral2), "p"); //else legend->AddEntry(histogram2, legendEntry2.data(), "p"); legend->AddEntry(histogram2, Form("%s: %1.2f", legendEntry2.data(), integral2), "p"); } if ( histogram3 ) { histogram3->SetLineColor(colors[2]); histogram3->SetLineWidth(2); histogram3->SetMarkerColor(colors[2]); histogram3->SetMarkerStyle(markerStyles[2]); histogram3->SetMarkerSize(markerSizes[2]); histogram3->Draw("e1psame"); //if ( integral3 >= 0. ) legend->AddEntry(histogram3, Form("%s: %1.2f", legendEntry3.data(), integral3), "p"); //else legend->AddEntry(histogram3, legendEntry3.data(), "p"); legend->AddEntry(histogram3, Form("%s: %1.2f", legendEntry3.data(), integral3), "p"); } if ( histogram4 ) { histogram4->SetLineColor(colors[3]); histogram4->SetLineWidth(2); histogram4->SetMarkerColor(colors[3]); histogram4->SetMarkerStyle(markerStyles[3]); histogram4->SetMarkerSize(markerSizes[3]); histogram4->Draw("e1psame"); if ( integral4 >= 0. ) legend->AddEntry(histogram4, Form("%s: %1.2f", legendEntry4.data(), integral4), "p"); else legend->AddEntry(histogram4, legendEntry4.data(), "p"); } if ( histogram5 ) { histogram5->SetLineColor(colors[4]); histogram5->SetLineWidth(2); histogram5->SetMarkerColor(colors[4]); histogram5->SetMarkerStyle(markerStyles[4]); histogram5->SetMarkerSize(markerSizes[4]); histogram5->Draw("e1psame"); if ( integral5 >= 0. ) legend->AddEntry(histogram5, Form("%s: %1.2f", legendEntry5.data(), integral5), "p"); else legend->AddEntry(histogram5, legendEntry5.data(), "p"); } if ( histogram6 ) { histogram6->SetLineColor(colors[5]); histogram6->SetLineWidth(2); histogram6->SetMarkerColor(colors[5]); histogram6->SetMarkerStyle(markerStyles[5]); histogram6->SetMarkerSize(markerSizes[5]); histogram6->Draw("e1psame"); if ( integral6 >= 0. ) legend->AddEntry(histogram6, Form("%s: %1.2f", legendEntry6.data(), integral6), "p"); else legend->AddEntry(histogram6, legendEntry6.data(), "p"); } legend->Draw(); canvas->cd(); bottomPad->Draw(); bottomPad->cd(); TH1* histogram2_div_ref = 0; if ( histogram2 ) { std::string histogramName2_div_ref = std::string(histogram2->GetName()).append("_div_").append(histogram_ref->GetName()); histogram2_div_ref = compRatioHistogram(histogramName2_div_ref, histogram2, histogram_ref); if ( histogram2_div_ref ) { histogram2_div_ref->SetTitle(""); histogram2_div_ref->SetStats(false); histogram2_div_ref->SetMinimum(-0.50); histogram2_div_ref->SetMaximum(+0.50); TAxis* xAxis_bottom = histogram2_div_ref->GetXaxis(); xAxis_bottom->SetTitle(xAxis_top->GetTitle()); xAxis_bottom->SetLabelColor(1); xAxis_bottom->SetTitleColor(1); xAxis_bottom->SetTitleOffset(1.20); xAxis_bottom->SetTitleSize(0.08); xAxis_bottom->SetLabelOffset(0.02); xAxis_bottom->SetLabelSize(0.08); xAxis_bottom->SetTickLength(0.055); TAxis* yAxis_bottom = histogram2_div_ref->GetYaxis(); yAxis_bottom->SetTitle(Form("#frac{%s - %s}{%s}", legendEntry2.data(), legendEntry_ref.data(), legendEntry_ref.data())); yAxis_bottom->SetTitleOffset(0.85); yAxis_bottom->SetNdivisions(505); yAxis_bottom->CenterTitle(); yAxis_bottom->SetTitleSize(0.08); yAxis_bottom->SetLabelSize(0.08); yAxis_bottom->SetTickLength(0.04); histogram2_div_ref->Draw("e1p"); } } TH1* histogram3_div_ref = 0; if ( histogram3 ) { std::string histogramName3_div_ref = std::string(histogram3->GetName()).append("_div_").append(histogram_ref->GetName()); histogram3_div_ref = compRatioHistogram(histogramName3_div_ref, histogram3, histogram_ref); if ( histogram3_div_ref ) { histogram3_div_ref->SetTitle(""); histogram3_div_ref->SetStats(false); histogram3_div_ref->SetMinimum(-0.50); histogram3_div_ref->SetMaximum(+0.50); TAxis* xAxis_bottom = histogram3_div_ref->GetXaxis(); xAxis_bottom->SetTitle(xAxis_top->GetTitle()); xAxis_bottom->SetLabelColor(1); xAxis_bottom->SetTitleColor(1); xAxis_bottom->SetTitleOffset(1.20); xAxis_bottom->SetTitleSize(0.08); xAxis_bottom->SetLabelOffset(0.02); xAxis_bottom->SetLabelSize(0.08); xAxis_bottom->SetTickLength(0.055); TAxis* yAxis_bottom = histogram3_div_ref->GetYaxis(); yAxis_bottom->SetTitle(Form("#frac{%s - %s}{%s}", legendEntry3.data(), legendEntry_ref.data(), legendEntry_ref.data())); yAxis_bottom->SetTitleOffset(0.85); yAxis_bottom->SetNdivisions(505); yAxis_bottom->CenterTitle(); yAxis_bottom->SetTitleSize(0.08); yAxis_bottom->SetLabelSize(0.08); yAxis_bottom->SetTickLength(0.04); if ( histogram2 ) histogram3_div_ref->Draw("e1psame"); else histogram3_div_ref->Draw("e1p"); } } TGraph* graph_line = new TGraph(2); graph_line->SetPoint(0, xAxis_top->GetXmin(), 0.); graph_line->SetPoint(1, xAxis_top->GetXmax(), 0.); graph_line->SetLineColor(8); graph_line->SetLineWidth(1); graph_line->Draw("L"); if ( histogram2_div_ref ) histogram2_div_ref->Draw("e1psame"); if ( histogram3_div_ref ) histogram3_div_ref->Draw("e1psame"); TH1* histogram4_div_ref = 0; if ( histogram4 ) { std::string histogramName4_div_ref = std::string(histogram4->GetName()).append("_div_").append(histogram_ref->GetName()); histogram4_div_ref = compRatioHistogram(histogramName4_div_ref, histogram4, histogram_ref); if ( histogram4_div_ref ) { histogram4_div_ref->Draw("e1psame"); } } TH1* histogram5_div_ref = 0; if ( histogram5 ) { std::string histogramName5_div_ref = std::string(histogram5->GetName()).append("_div_").append(histogram_ref->GetName()); histogram5_div_ref = compRatioHistogram(histogramName5_div_ref, histogram5, histogram_ref); if ( histogram5_div_ref ) { histogram5_div_ref->Draw("e1psame"); } } TH1* histogram6_div_ref = 0; if ( histogram6 ) { std::string histogramName6_div_ref = std::string(histogram6->GetName()).append("_div_").append(histogram_ref->GetName()); histogram6_div_ref = compRatioHistogram(histogramName6_div_ref, histogram6, histogram_ref); if ( histogram6_div_ref ) { histogram6_div_ref->Draw("e1psame"); } } canvas->Update(); size_t idx = outputFileName.find_last_of('.'); std::string outputFileName_plot = std::string(outputFileName, 0, idx); if ( useLogScale ) outputFileName_plot.append("_log"); else outputFileName_plot.append("_linear"); if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data()); canvas->Print(std::string(outputFileName_plot).append(".png").data()); //canvas->Print(std::string(outputFileName_plot).append(".pdf").data()); //canvas->Print(std::string(outputFileName_plot).append(".root").data()); delete legend; delete histogram2_div_ref; delete histogram3_div_ref; delete histogram4_div_ref; delete histogram5_div_ref; delete histogram6_div_ref; delete topPad; delete bottomPad; delete canvas; }
void EMCDistribution_ShowShape(TString CherenkovSignal = "C2_Inner", const double che_cut = 10) { TString cut_pass = CherenkovSignal + Form(">%.1f", che_cut); TString cut_rej = CherenkovSignal + Form("<%.1f", che_cut); const double event_pass = T->GetEntries(cut_pass); const double event_rej = T->GetEntries(cut_rej); TH2 *EnergyDist_pass = new TH2F("EnergyDist_pass", cut_pass + ";Column;Row;<Energy> / Event / Tower", 8, -.5, 7.5, 8, -.5, 7.5); TH2 *EnergyDist_rej = new TH2F("EnergyDist_rej", cut_rej + ";Column;Row;<Energy> / Event / Tower", 8, -.5, 7.5, 8, -.5, 7.5); TH2 *Hodoscope_dist = new TH2F("Hodoscope_dist", cut_rej + ";7 - Horizontal Hodoscope (5 mm);7 - Vertical Hodoscope (5 mm); Event / finger^2", 8, -.5, 7.5, 8, -.5, 7.5); TH1 *Che_full = new TH1F("Che_full", ";" + CherenkovSignal + " Signal (ADC);Count / bin", 200, 0, 2000); TH1 *Che_pass = new TH1F("Che_pass", ";" + CherenkovSignal + " Signal (ADC);Count / bin", 200, 0, 2000); TH1 *Che_rej = new TH1F("Che_rej", ";" + CherenkovSignal + " Signal (ADC);Count / bin", 200, 0, 2000); Che_full->SetLineColor(kBlue + 3); Che_full->SetLineWidth(2); Che_pass->SetLineColor(kGreen + 3); Che_pass->SetLineWidth(2); Che_pass->SetFillColor(kGreen + 3); Che_pass->SetFillStyle(1); Che_rej->SetLineColor(kBlue + 3); Che_rej->SetLineWidth(2); Che_rej->SetFillColor(kBlue + 3); Che_rej->SetFillStyle(1); T->Draw( "TOWER_CALIB_CEMC[].get_binphi():TOWER_CALIB_CEMC[].get_bineta()>>EnergyDist_pass", Form("(%s) * (TOWER_CALIB_CEMC[].get_energy())", cut_pass.Data()), "goff"); T->Draw( "TOWER_CALIB_CEMC[].get_binphi():TOWER_CALIB_CEMC[].get_bineta()>>EnergyDist_rej", Form("(%s) * (TOWER_CALIB_CEMC[].get_energy())", cut_rej.Data()), "goff"); T->Draw( "7 - Average_HODO_VERTICAL:7 - Average_HODO_HORIZONTAL>>Hodoscope_dist", "1", "goff"); T->Draw(CherenkovSignal + ">>Che_full", NULL, "goff"); T->Draw(CherenkovSignal + ">>Che_pass", cut_pass, "goff"); T->Draw(CherenkovSignal + ">>Che_rej", cut_rej, "goff"); EnergyDist_pass->Scale(1. / event_pass); EnergyDist_rej->Scale(1. / event_rej); TText *t; TCanvas *c1 = new TCanvas("EMCDistribution_ShowShape" + cuts, "EMCDistribution_ShowShape" + cuts, 1100, 950); c1->Divide(2, 2); int idx = 1; TPad *p; p = (TPad *) c1->cd(idx++); c1->Update(); p->SetLogy(); p->SetGridx(0); p->SetGridy(0); Che_full->DrawClone(); Che_pass->DrawClone("same"); Che_rej->DrawClone("same"); p = (TPad *) c1->cd(idx++); c1->Update(); // p->SetLogy(); EnergyDist_pass->DrawClone("colz"); p = (TPad *) c1->cd(idx++); c1->Update(); // p->SetLogy(); // p->SetGridx(0); // p->SetGridy(0); EnergyDist_rej->DrawClone("colz"); p = (TPad *) c1->cd(idx++); c1->Update(); // p->SetLogy(); // p->SetGridx(0); // p->SetGridy(0); Hodoscope_dist->DrawClone("colz"); SaveCanvas(c1, TString(_file0->GetName()) + TString("_DrawPrototype3EMCalTower_") + TString(c1->GetName()), false); }
void plotComparison( TH1F* h_dt , TH1F* h_mc , TH1F *h_extra, char* label, bool dolog, bool drawbkg) { TPad* fullpad = new TPad(); TPad* plotpad = new TPad(); TPad* respad = new TPad(); fullpad = new TPad("fullpad","fullpad",0,0,1,1); fullpad->Draw(); fullpad->cd(); plotpad = new TPad("plotpad","plotpad",0,0,1,0.8); plotpad->Draw(); plotpad->cd(); if (dolog) plotpad->SetLogy(); h_dt->GetYaxis()->SetTitle("Entries"); h_dt->GetXaxis()->SetTitle(Form("%s", label)); h_dt->GetYaxis()->SetTitleSize(0.05); h_dt->GetXaxis()->SetTitleSize(0.05); h_dt->GetYaxis()->SetTitleOffset(1.5); h_dt->GetXaxis()->SetTitleOffset(1.3); if (!dolog) h_dt->GetYaxis()->SetRangeUser(0., 1.4*h_dt->GetMaximum()); h_dt->SetLineColor(kBlack); h_dt->SetMarkerColor(kBlack); h_mc->SetLineColor(kBlue); h_mc->SetMarkerColor(kBlue); h_extra->SetLineColor(kRed); h_extra->SetLineWidth(2); h_mc->SetLineWidth(2); h_dt->Draw(); h_mc->Draw("HISTSAME"); if (drawbkg) h_extra->Draw("HISTSAME"); h_dt->Draw("ESAME"); TLegend *legComp = new TLegend( 0.653, 0.663, 0.944, 0.870); legComp->AddEntry(h_dt, "Data", "lp"); legComp->AddEntry(h_mc, "MC", "l"); if (drawbkg) legComp->AddEntry(h_extra, "MC Bkg", "l"); legComp->SetFillColor(0); legComp->SetBorderSize(0); legComp->Draw(); TLatex *text = new TLatex(); text->SetNDC(); text->SetTextSize(0.04); // float xtex = 0.65; // text->DrawLatex(xtex,0.88,"1 lepton + jets Sample"); fullpad->cd(); respad = new TPad("respad","respad",0,0.8,1,1); respad->Draw(); respad->cd(); //gPad->SetGridy(); TH1F* ratio = (TH1F*) h_dt->Clone("ratio"); ratio->Divide(h_mc); ratio->GetYaxis()->SetTitleOffset(0.3); ratio->GetYaxis()->SetTitleSize(0.2); ratio->GetYaxis()->SetNdivisions(5); ratio->GetYaxis()->SetLabelSize(0.2); if (dolog) ratio->GetYaxis()->SetRangeUser(0.5,1.5); else ratio->GetYaxis()->SetRangeUser(0.7,1.3); ratio->GetYaxis()->SetTitle("Ratio "); ratio->GetXaxis()->SetLabelSize(0); ratio->GetXaxis()->SetTitleSize(0); ratio->SetMarkerSize(1); ratio->SetLineWidth(2); ratio->SetLineColor(kBlue); ratio->SetMarkerColor(kBlue); ratio->SetFillColor(kBlue); ratio->SetFillStyle(3002); ratio->Draw("E2"); TLine line; line.SetLineWidth(2); line.DrawLine(h_dt->GetXaxis()->GetXmin(),1,h_dt->GetXaxis()->GetXmax(),1); }
void EMCDistribution_SUM_RawADC(TString sTOWER = "Energy_Sum_col1_row2_5x5", TString CherenkovSignal = "C2_Inner") { TH1 *EnergySum_LG_full = new TH1F("EnergySum_LG_full", ";Tower Energy Sum (ADC);Count / bin", 260, -100, 2500); TH1 *EnergySum_LG = new TH1F("EnergySum_LG", ";Tower Energy Sum (ADC);Count / bin", 260, -100, 2500); // TH1 * EnergySum_HG = new TH1F("EnergySum_HG", // ";Low range Tower Energy Sum (ADC);Count / bin", 50, 0, 500); TH1 *C2_Inner_full = new TH1F("C2_Inner_full", CherenkovSignal + ";Cherenkov Signal (ADC);Count / bin", 1000, 0, 2000); TH1 *C2_Inner = new TH1F("C2_Inner", CherenkovSignal + ";Cherenkov Inner Signal (ADC);Count / bin", 1000, 0, 2000); EnergySum_LG_full->SetLineColor(kBlue + 3); EnergySum_LG_full->SetLineWidth(2); EnergySum_LG->SetLineColor(kGreen + 3); EnergySum_LG->SetLineWidth(3); EnergySum_LG->SetMarkerColor(kGreen + 3); C2_Inner_full->SetLineColor(kBlue + 3); C2_Inner_full->SetLineWidth(2); C2_Inner->SetLineColor(kGreen + 3); C2_Inner->SetLineWidth(3); C2_Inner->SetMarkerColor(kGreen + 3); TCut c2 = CherenkovSignal + ">240"; T->Draw(sTOWER + ">>EnergySum_LG_full", "", "goff"); T->Draw(sTOWER + ">>EnergySum_LG", c2, "goff"); T->Draw(CherenkovSignal + ">>C2_Inner_full", "", "goff"); T->Draw(CherenkovSignal + ">>C2_Inner", c2, "goff"); TText *t; TCanvas *c1 = new TCanvas( "EMCDistribution_SUM_RawADC_" + sTOWER + "_" + CherenkovSignal + cuts, "EMCDistribution_SUM_RawADC_" + sTOWER + "_" + CherenkovSignal + cuts, 1800, 600); c1->Divide(3, 1); int idx = 1; TPad *p; p = (TPad *) c1->cd(idx++); c1->Update(); p->SetLogy(); p->SetGridx(0); p->SetGridy(0); C2_Inner_full->DrawClone(); C2_Inner->DrawClone("same"); p = (TPad *) c1->cd(idx++); c1->Update(); p->SetLogy(); p->SetGridx(0); p->SetGridy(0); TH1 *h = (TH1 *) EnergySum_LG_full->DrawClone(); // h->GetXaxis()->SetRangeUser(0, h->GetMean() + 5 * h->GetRMS()); (TH1 *) EnergySum_LG->DrawClone("same"); p = (TPad *) c1->cd(idx++); c1->Update(); // p->SetLogy(); p->SetGridx(0); p->SetGridy(0); TH1 *h_full = (TH1 *) EnergySum_LG_full->DrawClone(); TH1 *h = (TH1 *) EnergySum_LG->DrawClone("same"); TF1 *fgaus_g = new TF1("fgaus_LG_g", "gaus", h->GetMean() - 1 * h->GetRMS(), h->GetMean() + 4 * h->GetRMS()); fgaus_g->SetParameters(1, h->GetMean() - 2 * h->GetRMS(), h->GetMean() + 2 * h->GetRMS()); h->Fit(fgaus_g, "MR0N"); TF1 *fgaus = new TF1("fgaus_LG", "gaus", fgaus_g->GetParameter(1) - 1 * fgaus_g->GetParameter(2), fgaus_g->GetParameter(1) + 4 * fgaus_g->GetParameter(2)); fgaus->SetParameters(fgaus_g->GetParameter(0), fgaus_g->GetParameter(1), fgaus_g->GetParameter(2)); h->Fit(fgaus, "MR"); h->Sumw2(); h_full->Sumw2(); h_full->GetXaxis()->SetRangeUser(h->GetMean() - 4 * h->GetRMS(), h->GetMean() + 4 * h->GetRMS()); h->SetLineWidth(2); h->SetMarkerStyle(kFullCircle); h_full->SetTitle( Form("#DeltaE/<E> = %.1f%%", 100 * fgaus->GetParameter(2) / fgaus->GetParameter(1))); // p = (TPad *) c1->cd(idx++); // c1->Update(); // p->SetLogy(); // p->SetGridx(0); // p->SetGridy(0); // // TH1 * h = (TH1 *) EnergySum_LG->DrawClone(); // h->GetXaxis()->SetRangeUser(0,500); // h->SetLineWidth(2); // h->SetLineColor(kBlue + 3); //// h->Sumw2(); // h->GetXaxis()->SetRangeUser(0, h->GetMean() + 5 * h->GetRMS()); // // p = (TPad *) c1->cd(idx++); // c1->Update(); //// p->SetLogy(); // p->SetGridx(0); // p->SetGridy(0); // // TH1 * h = (TH1 *) EnergySum_LG->DrawClone(); // h->GetXaxis()->SetRangeUser(0,500); // // TF1 * fgaus = new TF1("fgaus_HG", "gaus", 0, 100); // fgaus->SetParameters(1, h->GetMean() - 2 * h->GetRMS(), // h->GetMean() + 2 * h->GetRMS()); // h->Fit(fgaus, "M"); // // h->Sumw2(); // h->GetXaxis()->SetRangeUser(h->GetMean() - 4 * h->GetRMS(), // h->GetMean() + 4 * h->GetRMS()); // // h->SetLineWidth(2); // h->SetMarkerStyle(kFullCircle); // // h->SetTitle( // Form("#DeltaE/<E> = %.1f%%", // 100 * fgaus->GetParameter(2) / fgaus->GetParameter(1))); SaveCanvas(c1, TString(_file0->GetName()) + TString("_DrawPrototype3EMCalTower_") + TString(c1->GetName()), false); }