/** * Create ratios to other data * * @param ib Bin number * @param res Result * @param alice ALICE result if any * @param cms CMS result if any * @param all Stack to add ratio to */ void Ratio2Stack(Int_t ib, TH1* res, TGraph* alice, TGraph* cms, THStack* all) { if (!all || !res || !(alice || cms)) return; Int_t off = 5*ib; TGraph* gs[] = { (alice ? alice : cms), (alice ? cms : 0), 0 }; TGraph** pg = gs; while (*pg) { TGraph* g = *pg; const char* n = (g == alice ? "ALICE" : "CMS"); TH1* r = static_cast<TH1*>(res->Clone(Form("ratio%s", n))); TString tit(r->GetTitle()); tit.ReplaceAll("Corrected", Form("Ratio to %s", n)); r->SetTitle(tit); r->SetMarkerColor(g->GetMarkerColor()); r->SetLineColor(g->GetLineColor()); TObject* tst = r->FindObject("legend"); if (tst) r->GetListOfFunctions()->Remove(tst); for (Int_t i = 1; i <= r->GetNbinsX(); i++) { Double_t c = r->GetBinContent(i); Double_t e = r->GetBinError(i); Double_t o = g->Eval(r->GetBinCenter(i)); if (o < 1e-12) { r->SetBinContent(i, 0); r->SetBinError(i, 0); continue; } r->SetBinContent(i, (c - o) / o + off); r->SetBinError(i, e / o); } all->Add(r); pg++; } TLegend* leg = StackLegend(all); if (!leg) return; TString txt = res->GetTitle(); txt.ReplaceAll("Corrected P(#it{N}_{ch}) in ", ""); if (ib == 0) txt.Append(" "); // (#times1)"); // else if (ib == 1) txt.Append(" (#times10)"); else txt.Append(Form(" (+%d)", off)); TObject* dummy = 0; TLegendEntry* e = leg->AddEntry(dummy, txt, "p"); e->SetMarkerStyle(res->GetMarkerStyle()); e->SetMarkerSize(res->GetMarkerSize()); e->SetMarkerColor(kBlack); e->SetFillColor(0); e->SetFillStyle(0); e->SetLineColor(kBlack); }
//____________________________________________________________________ TH1* One(TDirectory* newDir, TDirectory* oldDir, Double_t c1, Double_t c2) { TString name; name.Form("cent%03dd%02d_%03dd%02d", Int_t(c1), Int_t(c1*100)%100, Int_t(c2), Int_t(c2*100)%100); TDirectory* newSubDir = GetD(newDir, name); TDirectory* oldSubDir = GetD(oldDir, name); if (!newSubDir || !oldSubDir) return 0; Int_t newDim = 0; if (TString(newDir->GetName()).Contains("etaipz")) newDim = 3; else if (TString(newDir->GetName()).Contains("eta")) newDim = 2; else if (TString(newDir->GetName()).Contains("const")) newDim = 1; Int_t oldDim = 0; if (TString(oldDir->GetName()).Contains("etaipz")) oldDim = 3; else if (TString(oldDir->GetName()).Contains("eta")) oldDim = 2; else if (TString(oldDir->GetName()).Contains("const")) oldDim = 1; TDirectory* newSubSubDir = GetD(newSubDir, Form("results%dd",newDim)); TDirectory* oldSubSubDir = GetD(oldSubDir, Form("results%dd",oldDim)); if (!newSubSubDir || !oldSubSubDir) return 0; TH1* newRes = GetH1(newSubSubDir, "result"); TH1* oldRes = GetH1(oldSubSubDir, "result"); if (!newRes || !oldRes) return 0; TH1* ratio = static_cast<TH1*>(newRes->Clone(name)); ratio->SetDirectory(0); ratio->SetTitle(Form("%5.1f - %5.1f%%", c1, c2)); ratio->SetYTitle("New / Old"); ratio->Divide(oldRes); fMin = TMath::Min(fMin, ratio->GetMinimum()); fMax = TMath::Max(fMax, ratio->GetMaximum()); Printf("Calculated %s/%s", newDir->GetName(), oldDir->GetName()); if (!fLegend) return ratio; TLegendEntry* e = fLegend->AddEntry("", Form("%3.0f - %3.0f%%", c1, c2), "f"); e->SetFillStyle(1001); e->SetFillColor(ratio->GetMarkerColor()); return ratio; }
/** * Draw final plot for QM2011 * * @param max * * @ingroup pwglf_forward_scripts */ void dndeta_final(Double_t max=6) { gStyle->SetOptTitle(0); gStyle->SetOptFit(0); gStyle->SetTitleFont(132, "xyz"); gStyle->SetTitleSize(0.1, "xyz"); gStyle->SetTitleOffset(0.4, "y"); gStyle->SetTitleOffset(0.8, "x"); gStyle->SetLabelFont(132, "xyz"); gStyle->SetLabelSize(0.08, "xyz"); gStyle->SetNdivisions(212, "x"); gStyle->SetNdivisions(208, "y"); gStyle->SetTextFont(132); gStyle->SetPadColor(0); gStyle->SetPadBorderMode(0); // gStyle->SetFillColor(0); // gStyle->SetFillStyle(0); TCanvas* c = new TCanvas("c", "c", 900, 900); c->SetFillColor(0); c->SetFillStyle(0); c->SetBorderSize(0); c->SetBorderMode(0); c->SetRightMargin(0.02); c->SetTopMargin(0.02); c->SetBottomMargin(0.15); c->Divide(1,3,0,0); // --- INEL -------------------------------------------------------- TVirtualPad* p = c->cd(1); p->SetGridx(); p->SetRightMargin(.01); THStack* inel = new THStack("inel", "INEL"); TLatex* inelT = new TLatex(1-p->GetRightMargin()-.01, 1-p->GetTopMargin()-.01, "INEL"); inelT->SetNDC(); inelT->SetTextAlign(33); inelT->SetTextSize(0.12); TLegend* inelL = new TLegend(.3, .02, .8, .4); inelL->SetBorderSize(0); inelL->SetNColumns(2); inelL->SetFillColor(0); inelL->SetFillStyle(0); TLegendEntry* e = inelL->AddEntry("d1", "Forward", "lp"); e->SetMarkerColor(kRed+2); e->SetMarkerStyle(29); e = inelL->AddEntry("d2", "Central", "lp"); e->SetMarkerColor(kMagenta+2); e->SetMarkerStyle(29); e = inelL->AddEntry("d3", "Data", "lp"); e->SetMarkerStyle(29); e = inelL->AddEntry("d4", "Mirrored data", "lp"); e->SetMarkerStyle(30); e = inelL->AddEntry("d5", "Systematic error", "f"); e->SetFillColor(kGray); e->SetLineColor(kGray); e->SetLineWidth(0); e->SetFillStyle(3001); gROOT->LoadMacro("export_pp_0900GeV_INEL_m10p10cm_000100000ev.C"); export_pp_0900GeV_INEL_m10p10cm_000100000ev(inel, inelL, 20); export_pp_0900GeV_INEL_m10p10cm_000100000ev(inel, inelL, 21); export_pp_0900GeV_INEL_m10p10cm_000100000ev(inel, inelL, 22); inel->Draw("nostack e1"); inel->GetHistogram()->SetYTitle("#frac{1}{N}#frac{dN_{ch}}{d#eta}"); inel->GetHistogram()->SetXTitle("#eta"); inel->GetHistogram()->GetYaxis()->SetDecimals(); inelL->Draw(); inelT->Draw(); // --- INEL>0 ------------------------------------------------------ p = c->cd(2); p->SetGridx(); p->SetRightMargin(.01); THStack* inelgt0 = new THStack("inelgt0", "INEL>0"); TLatex* inelgt0T = new TLatex(1-p->GetRightMargin()-.01, 1-p->GetTopMargin()-.01, "INEL>0"); inelgt0T->SetNDC(); inelgt0T->SetTextAlign(33); inelgt0T->SetTextSize(0.12); gROOT->LoadMacro("export_pp_0900GeV_INEL_m10p10cm_000100000ev.C"); export_pp_0900GeV_INEL_m10p10cm_000100000ev(inelgt0, 0, 20); export_pp_0900GeV_INEL_m10p10cm_000100000ev(inelgt0, 0, 21); export_pp_0900GeV_INEL_m10p10cm_000100000ev(inelgt0, 0, 22); inelgt0->Draw("nostack e1"); inelgt0->GetHistogram()->SetXTitle("#eta"); inelgt0->GetHistogram()->GetYaxis()->SetDecimals(); inelgt0T->Draw(); // --- NSD --------------------------------------------------------- p = c->cd(3); p->SetGridx(); p->SetRightMargin(.01); THStack* nsd = new THStack("nsd", "NSD"); TLatex* nsdT = new TLatex(1-p->GetRightMargin()-.01, 1-p->GetTopMargin()-.01, "NSD"); nsdT->SetNDC(); nsdT->SetTextAlign(33); nsdT->SetTextSize(0.12); gROOT->LoadMacro("export_pp_0900GeV_NSD_m10p10cm_000100000ev.C"); export_pp_0900GeV_NSD_m10p10cm_000100000ev(nsd, 0, 20); export_pp_0900GeV_NSD_m10p10cm_000100000ev(nsd, 0, 21); export_pp_0900GeV_NSD_m10p10cm_000100000ev(nsd, 0, 22); nsd->Draw("nostack e1"); nsd->GetHistogram()->SetXTitle("#eta"); nsd->GetHistogram()->GetYaxis()->SetDecimals(); nsdT->Draw(); c->cd(); c->SaveAs("dndeta_final.png"); }
/** * Extract ALICE PbPb @ 5.02TeV over |eta|<2 * * @param filename Input file name * @param outname Output file name * @param reweigh Whether it is reweighed */ void Extract(const char* filename="dndneta.pbpb502.20151124.root", const char* outname="TRACKLETS_5023_PbPb.input", Bool_t reweigh=false) { if (filename == 0) return; TFile* file = TFile::Open(filename, "READ"); TObjArray* arr = static_cast<TObjArray*>(file->Get("TObjArray")); // Now count number of bins Int_t nBins = 0; TIter next(arr); TObject* obj = 0; while ((obj = next())) { if (TString(obj->GetName()).Contains("DataCorrSignal")) nBins++; } Info("ExtractdNdeta", "Defining %d centrality bins", nBins); TArrayD c(nBins+1); if (nBins == 5) { c[0] = 0; c[1] = 10; c[2] = 20; c[3] = 40; c[4] = 60; c[5] = 80; } else if (nBins >= 9) { c[0] = 0; c[1] = 5; c[2] = 10; c[3] = 20; c[4] = 30; c[5] = 40; c[6] = 50; c[7] = 60; c[8] = 70; c[9] = 80; if (nBins >= 10) c[10] = 90; if (nBins >= 11) c[11] = 100; } THStack* all = new THStack("all","all"); std::ofstream out(outname); std::ostream& o = out; // std::cout; // std::ostream& o = std::cout; o << "*author: SHAHOYAN : 2015\n" << "*title: Full centrality dependence of the charged " << "particle pseudo-rapidity density over the widest " << "possible pseudo-rapidity range in Pb-Pb collisions " << "at 5.02 TeV\n" << "*detector: TRACKLETS\n" << "*experiment: CERN-LHC-TRACKLETS\n" << "*comment: CERN-LHC: We present the charged particle pseudo-rapidity " << "density of charged particles in Pb-Pb collisions at sqrt(s)/nucleon " "= 5.02 over the widest possible pseudo-rapidity and centrality range " << "possible.\n" << std::endl; for (Int_t i = 0; i < nBins; i++) { TString hName = Form("bin%d_DataCorrSignal_PbPb",i); TH1* h = static_cast<TH1*>(arr->FindObject(hName)); if (!h) { hName.ReplaceAll("PbPb", "PBPB"); h = static_cast<TH1*>(arr->FindObject(hName)); if (!h) { Warning("", "Histogram (%s) missing for bin %d", hName.Data(), i); arr->Print(); continue; } } Color_t col = PbPbColor(c[i], c[i+1]); h->SetLineColor(col); h->SetMarkerColor(col); h->SetFillColor(col); all->Add(h); Info("","Making GSE for %0d%% to %3d%% (%d)", Int_t(c[i]), Int_t(c[i+1]), col); MakeGSE(o, h, c[i], c[i+1], reweigh); } // all->Draw("nostack"); o << "*E" << std::endl; out.close(); TCanvas* can = new TCanvas("c","C", 1600, 800); can->SetRightMargin(0.2); can->SetTopMargin(0.01); TLegend* cl = new TLegend(1-can->GetRightMargin(), can->GetBottomMargin(),.99, 1-can->GetTopMargin()); cl->SetFillStyle(0); cl->SetBorderSize(0); gROOT->LoadMacro("$HOME/GraphSysErr/GraphSysErr.C+"); TList* ll = GraphSysErr::Import(outname); // ll->ls(); TIter next(ll); TObject* obj = 0; Bool_t first = true; TH1* frame = 0; Double_t min=100000, max=0; Int_t i = 0; while ((obj = next())) { if (c[i+1] > 80) break; GraphSysErr* g = static_cast<GraphSysErr*>(obj); Color_t col = PbPbColor(c[i], c[i+1]); TLegendEntry* e = cl->AddEntry("", Form("%4.1f-%4.1f%%", c[i], c[i+1]), "F"); e->SetFillColor(col); e->SetFillStyle(1001); g->SetLineColor(col); g->SetMarkerColor(col); g->SetFillColor(col); // g->Print("qual"); g->SetDataOption(GraphSysErr::kNoTick); g->SetSumOption(GraphSysErr::kBox); g->SetSumLineColor(col); g->SetSumFillColor(col); g->SetCommonSumOption(GraphSysErr::kBox); g->SetCommonSumLineColor(col); g->SetCommonSumFillColor(col); g->SetName(Form("tracklets%03dd%02d_%03dd%02d", Int_t(c[i]), Int_t(c[i]*100) % 100, Int_t(c[i+1]), Int_t(c[i+1]*100) % 100)); g->SetTitle(Form("%4.1f - %4.1f%%", c[i], c[i+1])); if (first) g->Draw("combine stat quad axis xbase=2.5"); else g->Draw("combine stat quad xbase=2.5"); if (!frame) frame = g->GetMulti()->GetHistogram(); first = false; Double_t mn, mx; g->GetMinMax("combine stat quad", mn, mx); FindLeastLargest(g, c[i], c[i+1]); min = TMath::Min(min, mn); max = TMath::Max(max, mx); i++; } frame->SetMinimum(min*.9); frame->SetMaximum(max*1.1); cl->Draw(); TFile* outFile = TFile::Open(Form("PbPb5023midRapidity%s.root", reweigh ? "Reweighed" : "Normal"), "RECREATE"); ll->Write("container",TObject::kSingleKey); outFile->Write(); can->SaveAs(Form("PbPb5023midRapidity%s.png", reweigh ? "Reweighed" : "Normal")); }
void plot_BSM_MCFM(int SignalOnly=0){ gROOT->ProcessLine(".x tdrstyle.cc"); double mPOLE = 125.6; TString OUTPUT_NAME; OUTPUT_NAME = "HtoZZ4l_MCFM_125p6_BSMPlots"; if (SignalOnly==0) OUTPUT_NAME.Append(".root"); else OUTPUT_NAME.Append("_SignalOnly.root"); TString coutput_common = user_TemplateswithTrees_dir + "../BSMReweight_GenLevel/Plots/"; gSystem->Exec("mkdir -p " + coutput_common); TString coutput = coutput_common + OUTPUT_NAME; TFile* foutput = new TFile(coutput, "recreate"); foutput->cd(); float ZZMass = 0; float p0plus_VAJHU; float p0hplus_VAJHU; float p0minus_VAJHU; float p0_g1prime2_VAJHU; float p0_g1prime4_VAJHU; float pg1g2_VAJHU; float pg1g4_VAJHU; float pg1g1prime2_VAJHU; float pg1g1prime4_VAJHU; TChain* tc[2][3][4]; TH1F* hfill[4][9]; int nbinsx = 73; double xlimits[2]={ 160, 1620 }; if (SignalOnly==1){ xlimits[0]=100; nbinsx = 76; } for (int t=0; t<4; t++){ for (int ac=0; ac<9; ac++){ hfill[t][ac]= new TH1F(Form("hSum_BSI%i_Hypo%i", t, ac), "", nbinsx, xlimits[0], xlimits[1]); hfill[t][ac]->SetXTitle("m_{4l} (GeV)"); hfill[t][ac]->SetYTitle(Form("Events / %.0f GeV", (xlimits[1]-xlimits[0])/nbinsx)); } } double nCounted[2][3][9]={ { { 0 } } }; double nCountedScaled[2][3][9]={ { { 0 } } }; for (int erg_tev=7; erg_tev<9; erg_tev++){ for (int folder=0; folder<3; folder++){ TString comstring; comstring.Form("%iTeV", erg_tev); TString erg_dir; erg_dir.Form("LHC_%iTeV/", erg_tev); int EnergyIndex = 1; if (erg_tev == 7) EnergyIndex = 0; TString cinput_common = user_TemplateswithTrees_dir + "../BSMReweight_GenLevel/"; cinput_common.Append(+erg_dir); cinput_common += user_folder[folder] + "/"; cout << cinput_common << endl; for (int t=0; t<4; t++){ TString INPUT_NAME; INPUT_NAME = "HtoZZ4l_MCFM_125p6_BSMTrees_"; INPUT_NAME += sample_suffix[t] + ".root"; INPUT_NAME.Prepend(cinput_common); tc[EnergyIndex][folder][t] = new TChain("GenTree"); if (t!=3) tc[EnergyIndex][folder][t]->Add(INPUT_NAME); tc[EnergyIndex][folder][t]->SetBranchAddress("ZZMass", &ZZMass); tc[EnergyIndex][folder][t]->SetBranchAddress("p0plus_VAJHU", &p0plus_VAJHU); tc[EnergyIndex][folder][t]->SetBranchAddress("p0hplus_VAJHU", &p0hplus_VAJHU); tc[EnergyIndex][folder][t]->SetBranchAddress("p0minus_VAJHU", &p0minus_VAJHU); tc[EnergyIndex][folder][t]->SetBranchAddress("p0_g1prime2_VAJHU", &p0_g1prime2_VAJHU); tc[EnergyIndex][folder][t]->SetBranchAddress("p0_g1prime4_VAJHU", &p0_g1prime4_VAJHU); tc[EnergyIndex][folder][t]->SetBranchAddress("pg1g2_VAJHU", &pg1g2_VAJHU); tc[EnergyIndex][folder][t]->SetBranchAddress("pg1g4_VAJHU", &pg1g4_VAJHU); tc[EnergyIndex][folder][t]->SetBranchAddress("pg1g1prime2_VAJHU", &pg1g1prime2_VAJHU); tc[EnergyIndex][folder][t]->SetBranchAddress("pg1g1prime4_VAJHU", &pg1g1prime4_VAJHU); } double nsig_counted[9] ={ 0 }; for (int ev=0; ev<tc[EnergyIndex][folder][0]->GetEntries(); ev++){ tc[EnergyIndex][folder][0]->GetEntry(ev); if (fabs(ZZMass-mPOLE)<0.1){ nsig_counted[0] += p0plus_VAJHU; nsig_counted[1] += p0hplus_VAJHU; nsig_counted[2] += p0minus_VAJHU; nsig_counted[3] += p0_g1prime2_VAJHU; nsig_counted[4] += p0_g1prime4_VAJHU; nsig_counted[5] += (2.*(p0plus_VAJHU+p0hplus_VAJHU)-pg1g2_VAJHU); nsig_counted[6] += pg1g4_VAJHU; nsig_counted[7] += pg1g1prime2_VAJHU; nsig_counted[8] += pg1g1prime4_VAJHU; } } for (int ac=0; ac<9; ac++) nCounted[EnergyIndex][folder][ac] = nsig_counted[ac]; } } for (int erg_tev=7; erg_tev<9; erg_tev++){ for (int folder=0; folder<3; folder++){ int EnergyIndex = 1; if (erg_tev == 7) EnergyIndex = 0; double nsig_SM = nSM_ScaledPeak[EnergyIndex][folder]; double SMscale = nsig_SM/nCounted[EnergyIndex][folder][0]; double scale=1; for (int t=0; t<4; t++){ for (int ev=0; ev<tc[EnergyIndex][folder][t]->GetEntries(); ev++){ tc[EnergyIndex][folder][t]->GetEntry(ev); if (ZZMass<xlimits[0]) continue; if (ZZMass>=xlimits[1]) ZZMass=xlimits[1]*0.999; scale = SMscale; if (t==0 && ev==0) nCountedScaled[EnergyIndex][folder][0] = nCounted[EnergyIndex][folder][0]*scale; hfill[t][0]->Fill(ZZMass, p0plus_VAJHU*scale); scale = SMscale; if (t==0 && ev==0) nCountedScaled[EnergyIndex][folder][1] = nCounted[EnergyIndex][folder][1]*scale; hfill[t][1]->Fill(ZZMass, p0hplus_VAJHU*scale); scale = SMscale; if (t==0 && ev==0) nCountedScaled[EnergyIndex][folder][2] = nCounted[EnergyIndex][folder][2]*scale; hfill[t][2]->Fill(ZZMass, p0minus_VAJHU*scale); scale = SMscale; if (t==0 && ev==0) nCountedScaled[EnergyIndex][folder][3] = nCounted[EnergyIndex][folder][3]*scale; hfill[t][3]->Fill(ZZMass, p0_g1prime2_VAJHU*scale); scale = SMscale; if (t==0 && ev==0) nCountedScaled[EnergyIndex][folder][4] = nCounted[EnergyIndex][folder][4]*scale; hfill[t][4]->Fill(ZZMass, p0_g1prime4_VAJHU*scale); scale = SMscale; if (t>0){ hfill[t][5]->Fill(ZZMass, pg1g2_VAJHU*scale); } else{ scale *= (nCounted[0][2][0]+nCounted[1][2][0])/(nCounted[0][2][5]+nCounted[1][2][5]); hfill[t][5]->Fill(ZZMass, (2.*(p0plus_VAJHU+p0hplus_VAJHU)-pg1g2_VAJHU)*scale); } if (t==0 && ev==0) nCountedScaled[EnergyIndex][folder][5] = nCounted[EnergyIndex][folder][5]*scale; scale = SMscale; if (t==0) scale *= (nCounted[0][2][0]+nCounted[1][2][0])/(nCounted[0][2][6]+nCounted[1][2][6]); if (t==0 && ev==0) nCountedScaled[EnergyIndex][folder][6] = nCounted[EnergyIndex][folder][6]*scale; hfill[t][6]->Fill(ZZMass, pg1g4_VAJHU*scale); scale = SMscale; if (t==0) scale *= (nCounted[0][2][0]+nCounted[1][2][0])/(nCounted[0][2][7]+nCounted[1][2][7]); if (t==0 && ev==0) nCountedScaled[EnergyIndex][folder][7] = nCounted[EnergyIndex][folder][7]*scale; hfill[t][7]->Fill(ZZMass, pg1g1prime2_VAJHU*scale); scale = SMscale; // if (t==0) scale *= (nCounted[0][2][0]+nCounted[1][2][0])/(nCounted[0][2][8]+nCounted[1][2][8]); if (t==0 && ev==0) nCountedScaled[EnergyIndex][folder][8] = nCounted[EnergyIndex][folder][8]*scale; hfill[t][8]->Fill(ZZMass, pg1g1prime4_VAJHU*scale); } delete tc[EnergyIndex][folder][t]; } } } for (int ac=1; ac<9; ac++){ double nTotal[2]={ 0 }; for (int erg_tev=7; erg_tev<9; erg_tev++){ for (int folder=0; folder<3; folder++){ int EnergyIndex = 1; if (erg_tev == 7) EnergyIndex = 0; nTotal[0] += nCountedScaled[EnergyIndex][folder][0]; nTotal[1] += nCountedScaled[EnergyIndex][folder][ac]; } } if (ac!=8) hfill[0][ac]->Scale(nTotal[0]/nTotal[1]); else hfill[0][ac]->Scale(0.5); } double maxplot=0; for (int t=0; t<4; t++){ for (int ac=0; ac<9; ac++){ if (SignalOnly==0 && ac<5) maxplot = max(maxplot, hfill[t][ac]->GetMaximum()); else if (SignalOnly==1 && !(ac<5 && ac>0) && t==0) maxplot = max(maxplot, hfill[t][ac]->GetMaximum()); hfill[t][ac]->SetLineWidth(2); if (t==0 && ac>=5){ hfill[t][ac]->SetLineStyle(7); // hfill[t][ac]->Add(hfill[1][ac]); } if (t==1) hfill[t][ac]->SetLineStyle(3); if (t==3) hfill[t][ac]->SetLineStyle(9); hfill[t][ac]->GetXaxis()->SetLabelFont(42); hfill[t][ac]->GetXaxis()->SetLabelOffset(0.007); hfill[t][ac]->GetXaxis()->SetLabelSize(0.04); hfill[t][ac]->GetXaxis()->SetTitleSize(0.06); hfill[t][ac]->GetXaxis()->SetTitleOffset(0.9); hfill[t][ac]->GetXaxis()->SetTitleFont(42); hfill[t][ac]->GetYaxis()->SetNdivisions(505); hfill[t][ac]->GetYaxis()->SetLabelFont(42); hfill[t][ac]->GetYaxis()->SetLabelOffset(0.007); hfill[t][ac]->GetYaxis()->SetLabelSize(0.04); hfill[t][ac]->GetYaxis()->SetTitleSize(0.06); hfill[t][ac]->GetYaxis()->SetTitleOffset(1.1); hfill[t][ac]->GetYaxis()->SetTitleFont(42); } } TPaveText* pt = new TPaveText(0.15, 0.93, 0.85, 1, "brNDC"); pt->SetBorderSize(0); pt->SetFillStyle(0); pt->SetTextAlign(12); pt->SetTextFont(42); pt->SetTextSize(0.045); TText* text = pt->AddText(0.025, 0.45, "#font[61]{CMS}"); text->SetTextSize(0.044); text = pt->AddText(0.165, 0.42, "#font[52]{Simulation}"); text->SetTextSize(0.0315); TString cErgTev = "#font[42]{19.7 fb^{-1} (8 TeV) + 5.1 fb^{-1} (7 TeV)}"; text = pt->AddText(0.537, 0.45, cErgTev); text->SetTextSize(0.0315); float lxmin = 0.22; float lxwidth = 0.38; float lymax = 0.9; float lywidth = 0.3; float lxmax = lxmin + lxwidth; float lymin = lymax; if (SignalOnly==0) lymin -= lywidth*4./5.; else lymin -= lywidth; float lxmin2 = 0.22+0.39; float lymax2 = lymax; float lxmax2 = lxmin2 + lxwidth; float lymin2 = lymax2; if (SignalOnly==0) lymin2 -= lywidth*2./5.; else lymin2 -= lywidth*4./5.; if (SignalOnly==1){ float lxmin3 = lxmin2; float lymax3 = lymax2; float lxmax3 = lxmax2; float lymin3 = lymin2; lxmin2 = lxmin; lxmax2 = lxmax; lymin2 = lymin; lymax2 = lymax; lxmin = lxmin3; lxmax = lxmax3; lymin = lymin3; lymax = lymax3; } float pxmin = 0.756; float pymin = 0.76; float pxmax = 0.85; if (SignalOnly==1){ pymin -= 0.12; } float pymax = pymin+0.05; TPaveText* ptx = new TPaveText(pxmin, pymin, pxmax, pymax, "brNDC"); ptx->SetBorderSize(0); ptx->SetTextFont(42); ptx->SetTextSize(0.04); ptx->SetLineColor(1); ptx->SetLineStyle(1); ptx->SetLineWidth(1); ptx->SetFillColor(0); ptx->SetFillStyle(0); text = ptx->AddText(0.01, 0.01, "gg#rightarrow4l"); text->SetTextSize(0.04); TString canvasname = "cCanvas_MCFMBSM_GenLevel"; if (SignalOnly==1) canvasname.Append("_SignalOnly"); TCanvas* cc = new TCanvas(canvasname, "", 8, 30, 800, 800); cc->cd(); gStyle->SetOptStat(0); cc->SetFillColor(0); cc->SetBorderMode(0); cc->SetBorderSize(2); cc->SetTickx(1); cc->SetTicky(1); cc->SetLeftMargin(0.17); cc->SetRightMargin(0.05); cc->SetTopMargin(0.07); cc->SetBottomMargin(0.13); cc->SetFrameFillStyle(0); cc->SetFrameBorderMode(0); cc->SetFrameFillStyle(0); cc->SetFrameBorderMode(0); cc->SetLogy(); TLegend* ll; TLegend* ll2; ll = new TLegend(lxmin2, lymin2, lxmax2, lymax2); ll2 = new TLegend(lxmin, lymin, lxmax, lymax); ll->SetBorderSize(0); ll->SetTextFont(42); ll->SetTextSize(0.04); ll->SetLineColor(1); ll->SetLineStyle(1); ll->SetLineWidth(1); ll->SetFillColor(0); ll->SetFillStyle(0); ll2->SetBorderSize(0); ll2->SetTextFont(42); ll2->SetTextSize(0.04); ll2->SetLineColor(1); ll2->SetLineStyle(1); ll2->SetLineWidth(1); ll2->SetFillColor(0); ll2->SetFillStyle(0); TString strACtitle[9]={ "", "f_{a2}=1", "f_{a3}=1", "f_{#Lambda1}=1", "f_{#LambdaQ}=1", "f_{a2}=0.5, #phi_{#lower[-0.2]{a2}}=#pi", "f_{a3}=0.5", "f_{#Lambda1}=0.5", "f_{#LambdaQ}=0.5" }; int iDraw = 2 - 2*SignalOnly; if (SignalOnly==0) hfill[iDraw][0]->GetYaxis()->SetRangeUser(7e-3, maxplot*15.); else{ double histmin = 7e-3; if (hfill[iDraw][0]->GetMinimum()>0) histmin = hfill[iDraw][0]->GetMinimum(); hfill[iDraw][0]->GetYaxis()->SetRangeUser(histmin, maxplot*2000.); } hfill[iDraw][0]->GetXaxis()->SetRangeUser(xlimits[0], 800.); hfill[iDraw][0]->SetLineColor(kBlack); if (SignalOnly==0){ hfill[iDraw][0]->SetFillColor(kAzure-2); hfill[iDraw][0]->SetFillStyle(1001); } hfill[iDraw][0]->Draw("hist"); hfill[iDraw][1]->SetLineColor(kBlue); hfill[iDraw][1]->Draw("histsame"); hfill[iDraw][2]->SetLineColor(kRed); hfill[iDraw][2]->Draw("histsame"); hfill[iDraw][3]->SetLineColor(kViolet); hfill[iDraw][3]->Draw("histsame"); hfill[iDraw][4]->SetLineColor(kGreen+2); hfill[iDraw][4]->Draw("histsame"); if (SignalOnly==1){ hfill[iDraw][5]->SetLineColor(kBlue); hfill[iDraw][5]->Draw("histsame"); hfill[iDraw][6]->SetLineColor(kRed); hfill[iDraw][6]->Draw("histsame"); hfill[iDraw][7]->SetLineColor(kViolet); hfill[iDraw][7]->Draw("histsame"); hfill[iDraw][8]->SetLineColor(kGreen+2); hfill[iDraw][8]->Draw("histsame"); } if (SignalOnly==0){ hfill[1][0]->SetLineColor(kBlack); hfill[1][0]->SetLineStyle(3); hfill[1][0]->Draw("histsame"); } hfill[iDraw][0]->Draw("histsame"); TLegendEntry* legendtext; if (SignalOnly==0){ legendtext = ll->AddEntry(hfill[iDraw][0], "SM total", "f"); legendtext = ll->AddEntry(hfill[1][0], "SM bkg.", "f"); legendtext->SetFillStyle(1001); legendtext->SetFillColor(hfill[1][0]->GetFillColor()); } else{ legendtext = ll->AddEntry(hfill[iDraw][0], "SM signal", "f"); legendtext->SetFillStyle(3001); } if (SignalOnly==0){ legendtext = ll2->AddEntry(hfill[iDraw][4], Form("#Gamma_{H}=#Gamma^{SM}_{H}, %s", strACtitle[4].Data()), "f"); legendtext->SetFillStyle(3001); legendtext->SetFillColor(hfill[iDraw][4]->GetFillColor()); legendtext = ll2->AddEntry(hfill[iDraw][2], Form("#Gamma_{H}=#Gamma^{SM}_{H}, %s", strACtitle[2].Data()), "f"); legendtext->SetFillStyle(3001); legendtext->SetFillColor(hfill[iDraw][2]->GetFillColor()); legendtext = ll2->AddEntry(hfill[iDraw][1], Form("#Gamma_{H}=#Gamma^{SM}_{H}, %s", strACtitle[1].Data()), "f"); legendtext->SetFillStyle(3001); legendtext->SetFillColor(hfill[iDraw][1]->GetFillColor()); legendtext = ll2->AddEntry(hfill[iDraw][3], Form("#Gamma_{H}=#Gamma^{SM}_{H}, %s", strACtitle[3].Data()), "f"); legendtext->SetFillStyle(3001); legendtext->SetFillColor(hfill[iDraw][3]->GetFillColor()); } else{ legendtext = ll->AddEntry(hfill[iDraw][4], strACtitle[4].Data(), "f"); legendtext->SetFillStyle(3001); legendtext->SetFillColor(hfill[iDraw][4]->GetFillColor()); legendtext = ll->AddEntry(hfill[iDraw][2], strACtitle[2].Data(), "f"); legendtext->SetFillStyle(3001); legendtext->SetFillColor(hfill[iDraw][2]->GetFillColor()); legendtext = ll->AddEntry(hfill[iDraw][1], strACtitle[1].Data(), "f"); legendtext->SetFillStyle(3001); legendtext->SetFillColor(hfill[iDraw][1]->GetFillColor()); legendtext = ll->AddEntry(hfill[iDraw][3], strACtitle[3].Data(), "f"); legendtext->SetFillStyle(3001); legendtext->SetFillColor(hfill[iDraw][3]->GetFillColor()); } if (SignalOnly==1){ legendtext = ll2->AddEntry(hfill[iDraw][8], strACtitle[8].Data(), "f"); legendtext->SetFillStyle(3001); legendtext->SetFillColor(hfill[iDraw][8]->GetFillColor()); legendtext = ll2->AddEntry(hfill[iDraw][5], strACtitle[5].Data(), "f"); legendtext->SetFillStyle(3001); legendtext->SetFillColor(hfill[iDraw][5]->GetFillColor()); legendtext = ll2->AddEntry(hfill[iDraw][7], strACtitle[7].Data(), "f"); legendtext->SetFillStyle(3001); legendtext->SetFillColor(hfill[iDraw][7]->GetFillColor()); legendtext = ll2->AddEntry(hfill[iDraw][6], strACtitle[6].Data(), "f"); legendtext->SetFillStyle(3001); legendtext->SetFillColor(hfill[iDraw][6]->GetFillColor()); } ll->Draw("same"); ll2->Draw("same"); ptx->Draw(); pt->Draw(); cc->RedrawAxis(); cc->Update(); canvasname.Prepend(coutput_common); TString canvasname_pdf = canvasname; TString canvasname_eps = canvasname; TString canvasname_png = canvasname; TString canvasname_root = canvasname; TString canvasname_c = canvasname; canvasname_pdf.Append(".pdf"); canvasname_eps.Append(".eps"); canvasname_png.Append(".png"); canvasname_root.Append(".root"); canvasname_c.Append(".C"); cc->SaveAs(canvasname_pdf); cc->SaveAs(canvasname_eps); cc->SaveAs(canvasname_png); cc->SaveAs(canvasname_root); cc->SaveAs(canvasname_c); foutput->WriteTObject(cc); delete ll2; delete ll; cc->Close(); delete ptx; delete pt; for (int t=0; t<4; t++){ for (int ac=0; ac<5; ac++){ foutput->WriteTObject(hfill[t][ac]); delete hfill[t][ac]; } } foutput->Close(); }
TH1* GetCentK(TDirectory* top, Double_t c1, Double_t c2, Int_t s, TLegend* l) { TString dname; dname.Form("cent%06.2f_%06.2f", c1, c2); dname.ReplaceAll(".", "d"); TDirectory* d = top->GetDirectory(dname); if (!d) { Warning("GetCetnK", "Directory %s not found in %s", dname.Data(), top->GetName()); return; } TDirectory* det = d->GetDirectory("details"); if (!det) { Warning("GetCetnK", "Directory details not found in %s", d->GetName()); d->ls(); return; } TObject* o = det->Get("scalar"); if (!o) { Warning("GetCetnK", "Object scalar not found in %s", det->GetName()); return; } if (!o->IsA()->InheritsFrom(TH1::Class())) { Warning("GetCetnK", "Object %s is not a TH1, but a %s", o->GetName(), o->ClassName()); return; } TH1* h = static_cast<TH1*>(o->Clone()); Color_t col = cc[(s-1)%10]; h->SetLineColor(col); h->SetMarkerColor(col); h->SetFillColor(col); h->SetFillStyle(1001); // h->SetTitle(Form("%5.2f-%5.2f%% #times %d", c1, c2, s)); h->SetTitle(Form("%2.0f-%2.0f%% + %d", c1, c2, s-1)); TF1* f = new TF1("", "[0]",-2.2,2.2); f->SetParameter(0,s-1); f->SetLineColor(col); f->SetLineStyle(7); f->SetLineWidth(1); // h->Scale(s); h->Add(f); h->GetListOfFunctions()->Add(f); f->SetParameter(0,s); for (Int_t i = 1; i <= h->GetNbinsX(); i++) { if (TMath::Abs(h->GetBinCenter(i)) > 2) { h->SetBinContent(i,0); h->SetBinError(i,0); } } TLegendEntry* e = l->AddEntry(h, h->GetTitle(), "f"); e->SetFillColor(col); e->SetFillStyle(1001); e->SetLineColor(col); return h; }
/** * Add the bin histograms to our summary stacks * * @param bin Bin stack * @param i Current off-set in the stacks * @param measured All measured @f$ P(N_{ch})@f$ * @param truth All MC truth @f$ P(N_{ch})@f$ * @param accepted All MC accepted @f$ P(N_{ch})@f$ * @param unfolded All unfolded @f$ P(N_{ch})@f$ * @param corrected All corrected @f$ P(N_{ch})@f$ * @param result The result in this bin */ void Bin2Stack(const THStack* bin, Int_t i, THStack* measured, THStack* truth, THStack* accepted, THStack* unfolded, THStack* corrected, TH1*& result) { Int_t open, closed; Double_t factor; Float_t size; BinAttributes(i, open, closed, size, factor); TIter next(bin->GetHists()); TH1* h = 0; while ((h = static_cast<TH1*>(next()))) { THStack* tmp = 0; Int_t col = h->GetMarkerColor(); Int_t sty = 0; switch (col) { case kColorMeasured: tmp = measured; sty = closed; break; case kColorTruth: tmp = truth; sty = open; break; case kColorAccepted: tmp = accepted; sty = open; break; case kColorUnfolded: tmp = unfolded; sty = closed; break; case kColorCorrected: tmp = corrected; sty = closed; break; default: continue; } // Now clone, and add to the appropriate stack TH1* cln = static_cast<TH1*>(h->Clone(h->GetName())); cln->SetDirectory(0); cln->SetMarkerStyle(sty); cln->SetMarkerSize(size); cln->Scale(factor); // Scale by 10^i if (col == kColorCorrected) result = cln; // Make sure we do not get the old legend TObject* tst = cln->FindObject("legend"); if (tst) cln->GetListOfFunctions()->Remove(tst); tmp->Add(cln, next.GetOption()); } // Add entries to our stacks TString txt = bin->GetTitle(); if (i == 0) txt.Append(" (#times1)"); else if (i == 1) txt.Append(" (#times10)"); else txt.Append(Form(" (#times10^{%d})", i)); THStack* stacks[] = { measured, truth, accepted, unfolded, corrected, 0 }; THStack** pstack = stacks; while (*pstack) { TLegend* leg = StackLegend(*pstack); pstack++; if (!leg) continue; TObject* dummy = 0; TLegendEntry* e = leg->AddEntry(dummy, txt, "p"); e->SetMarkerStyle(closed); e->SetMarkerSize(1.2*size); e->SetMarkerColor(kBlack); e->SetFillColor(0); e->SetFillStyle(0); e->SetLineColor(kBlack); } }
void DrawTwoInPad(TVirtualPad* p, Int_t sub, TH1* h1, TH1* h2, Bool_t ratio, Bool_t logy=false, Bool_t legend=false) { TVirtualPad* pp = p->cd(sub); pp->SetRightMargin(0.02); pp->SetLeftMargin(0.10); TVirtualPad* ppp = pp; if (ratio) { pp->Divide(1,2,0,0); ppp = pp->cd(1); ppp->SetRightMargin(0.02); } if (logy) ppp->SetLogy(); TH1* hs[] = { h1, h2, 0 }; if (h1->GetMaximum() < h2->GetMaximum()) { hs[0] = h2; hs[1] = h1; } TH1** ph = hs; Double_t size = (ratio ? 0.1 : 0.05); Double_t off = (ratio ? 0.6 : 0.5); h1->SetFillStyle(3004); h2->SetFillStyle(3005); while (*ph) { TString opt("hist"); if (ph != hs) opt.Append(" same"); TH1* copy = (*ph)->DrawCopy(opt); copy->GetXaxis()->SetLabelSize(2*size); copy->GetYaxis()->SetLabelSize(size); copy->GetYaxis()->SetTitleSize(size); copy->GetYaxis()->SetTitleOffset(off); copy->SetYTitle(copy->GetTitle()); copy->SetTitle(""); copy->SetDirectory(0); ph++; } TString s1 = h1->GetYaxis()->GetTitle(); TString s2 = h2->GetYaxis()->GetTitle(); if (legend) { TLegend* l = new TLegend(0.6, 0.1, 0.9, 0.9); l->SetBorderSize(0); TLegendEntry* e = l->AddEntry("dummy", s1, "lf"); l->SetFillColor(kWhite); e->SetFillColor(kBlack); e->SetFillStyle(h1->GetFillStyle()); e = l->AddEntry("dummy", s2, "lf"); e->SetFillColor(kBlack); e->SetFillStyle(h2->GetFillStyle()); l->Draw(); } if (!ratio) return; ppp = pp->cd(2); ppp->SetRightMargin(0.02); TH1* r = static_cast<TH1*>(h1->Clone(Form("ratio%s", h1->GetName()))); r->SetDirectory(0); r->SetTitle(""); r->GetXaxis()->SetLabelSize(size); r->GetYaxis()->SetLabelSize(size); r->GetYaxis()->SetTitleSize(0.9*size); r->GetYaxis()->SetTitleOffset(0.9*off); r->SetMarkerStyle(20); r->SetMarkerColor(h1->GetFillColor()+1); r->SetFillStyle(3007); r->SetYTitle(Form("#frac{%s}{%s}", s1.Data(), s2.Data())); // r->Add(h2, -1); // r->Divide(h1); if (!r->IsA()->InheritsFrom(TProfile::Class())) { r->GetSumw2()->Set(0); // r->Sumw2(false); h2->GetSumw2()->Set(0); // h2->Sumw2(false); } r->Divide(h2); Printf("%s", r->GetName()); for (UShort_t bin = 1; bin <= r->GetNbinsX(); bin++) { Printf(" bin # %2d: Diff=%g+/-%g", bin, r->GetBinContent(bin), r->GetBinError(bin)); r->SetBinError(bin, 0); } r->GetSumw2()->Set(0); //r->Sumw2(false); r->SetMarkerSize(4); r->SetMaximum(r->GetMaximum()*1.2); r->SetMinimum(r->GetMinimum()*0.8); r->Draw("hist text30"); p->Modified(); p->Update(); p->cd(); }