From 7d2d8879229ff21cf5195451f6dc3fb2cf87c0f6 Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Mon, 1 May 2023 13:22:22 -0400 Subject: [PATCH] feat: draw PID limit boxes on eta vs. P plot in CI --- macro/ci/postprocess_eta_vs_p_forPID.C | 43 ++++++++++++++++++++++++-- src/PostProcessor.cxx | 15 ++++++++- src/PostProcessor.h | 10 +++++- 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/macro/ci/postprocess_eta_vs_p_forPID.C b/macro/ci/postprocess_eta_vs_p_forPID.C index f6479e71..2a529637 100644 --- a/macro/ci/postprocess_eta_vs_p_forPID.C +++ b/macro/ci/postprocess_eta_vs_p_forPID.C @@ -6,9 +6,46 @@ R__LOAD_LIBRARY(EpicAnalysis) // plot eta vs. p in one bin, for PID coverage requests void postprocess_eta_vs_p_forPID(TString infile="out/coverage.fastsim.root") { PostProcessor *P = new PostProcessor(infile); - P->Op()->Payload( [&P](Histos *H) { - P->DrawSingle(H,"etaVsP","COLZ"); - }); + auto draw_payload = [&P] (Histos *H) { + auto draw_formatting = [] (auto hist, auto canv) { + gStyle->SetPalette(kBird); + std::vector> limits; + limits.push_back({ + "#splitline{dRICH}{gas}", + new TBox( + 9.5, // p min + 1.3, // eta min + 50.0, // p max + 3.7 // eta max + ), + kRed + }); + limits.push_back({ + "#splitline{dRICH}{aerogel}", + new TBox( + 2.0, // p min + 1.3, // eta min + 10.3, // p max + 3.7 // eta max + ), + kBlue + }); + for(auto [name,box,color] : limits) { + auto box_line = (TBox*) box->Clone(); + box->SetFillColorAlpha(color,0.3); + box->Draw(); + box_line->SetLineWidth(3); + box_line->SetFillStyle(kFEmpty); + box_line->SetLineColor(color); + box_line->Draw(); + auto text = new TLatex(1.1*box->GetX1(), (box->GetY1()+box->GetY2())/2, name); + text->SetTextColor(color); + text->Draw(); + } + }; + P->DrawSingle(H, "etaVsP", "COLZ", 0, false, draw_formatting); + }; + P->Op()->Payload(draw_payload); P->Execute(); P->Finish(); } diff --git a/src/PostProcessor.cxx b/src/PostProcessor.cxx index 9fa0d33d..9c8800c9 100644 --- a/src/PostProcessor.cxx +++ b/src/PostProcessor.cxx @@ -222,8 +222,17 @@ void PostProcessor::FinishDumpAve(TString datFile) { * - `profileAxis` will draw a TProfile on the specified axis, for 2D dists * - 0=disabled(default), 1=x-axis, 2=y-axis * - `profileOnly` draw only the TProfile, for 2D dists + * - `extra_lambda` can be used to apply additional custom formatting, etc. */ -void PostProcessor::DrawSingle(Histos *H, TString histName, TString drawFormat, Int_t profileAxis, Bool_t profileOnly) { +void PostProcessor::DrawSingle( + Histos *H, + TString histName, + TString drawFormat, + Int_t profileAxis, + Bool_t profileOnly, + std::function extra_lambda + ) +{ cout << "draw single plot " << histName << "..." << endl; TH1 *hist = H->Hist(histName); if(hist==nullptr) { @@ -275,6 +284,10 @@ void PostProcessor::DrawSingle(Histos *H, TString histName, TString drawFormat, prof->Write(); } + // apply custom formatting + extra_lambda(hist, canv); + + // print and write canv->Print(pngDir+"/"+canvN+".png"); outfile->cd("/"); canv->Write(); diff --git a/src/PostProcessor.h b/src/PostProcessor.h index 89c72353..53eef4dd 100644 --- a/src/PostProcessor.h +++ b/src/PostProcessor.h @@ -5,6 +5,7 @@ #include #include +#include // root #include "TFile.h" @@ -69,7 +70,14 @@ class PostProcessor // - you are welcome to add your own algorithms void DumpHist(TString datFile, TString histSet, TString varName); void DumpAve(TString datFile, Histos *H, TString cutName); - void DrawSingle(Histos *H, TString histName, TString drawFormat="", Int_t profileAxis=0, Bool_t profileOnly=false); + void DrawSingle( + Histos *H, + TString histName, + TString drawFormat = "", + Int_t profileAxis = 0, + Bool_t profileOnly = false, + std::function extra_lambda = [] (TH1* h, TCanvas *c) {} + ); void DrawSingle(TString histSet, TString histName); void DrawRatios( TString outName, Histos *numerSet, Histos *denomSet, Bool_t plotRatioOnly=false