/** * 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); }
/** * 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 fixStats() { TH1* ratioHist = (TH1*) gROOT->FindObject("data"); TPaveStats* stats = (TPaveStats*) ratioHist->FindObject("stats"); if(stats)stats->SetTextSize(0.040209); }