2 #include "PlottingUtils/PlottingUtils.h"
3 #include "PlottingUtils/PlottingManager.h"
5 #pragma GCC diagnostic ignored "-Wfloat-conversion"
6 #pragma GCC diagnostic ignored "-Wconversion"
21 constexpr Color_t
Colours[
NVars] = {kRed, kGreen+1, kBlack, kBlue+1, kOrange+1};
22 constexpr ELineStyle
Style[
NVars] = {kDotted, kDashed, kSolid, kDashDotted, kDashDotted};
25 M3::Plotting::PlottingManager*
PlotMan =
nullptr;
28 void FindKnot(std::vector<double>& SigmaValues,
29 const std::string& dirname,
30 const std::string& subdirname,
31 const std::string& ProjName,
32 std::string histname) {
33 auto StripPrefix = [](std::string& str,
const std::string& prefix) {
34 if (str.find(prefix +
"_") == 0) {
35 str.erase(0, prefix.length() + 1);
36 if (str.find(prefix) == 0) {
37 MACH3LOG_ERROR(
"Failed to strip prefix '{}' from string '{}'", prefix, str);
41 MACH3LOG_ERROR(
"String '{}' does not start with expected prefix '{}'", str, prefix);
47 StripPrefix(histname, subdirname);
48 StripPrefix(histname, ProjName);
49 StripPrefix(histname, dirname);
55 size_t sig_pos = histname.find(
"_sig_");
58 std::string sigma_part = histname.substr(sig_pos + 5);
61 if (histname.find(
"nom_") != std::string::npos) {
63 PriorKnot =
static_cast<int>(SigmaValues.size());
65 }
else if (sigma_part.size() > 0 && sigma_part[0] ==
'n') {
66 sigma = -std::stod(sigma_part.substr(1));
67 }
else if (sigma_part.size() > 0 && sigma_part[0] ==
'p') {
68 sigma = std::stod(sigma_part.substr(1));
75 SigmaValues.push_back(sigma);
78 std::unique_ptr<TLegend>
MakeLegend(
double x1,
double y1,
double x2,
double y2,
79 double textSize = 0.04)
81 auto leg = std::make_unique<TLegend>(x1, y1, x2, y2);
82 leg->SetTextSize(textSize);
87 leg->SetBorderSize(0);
93 void ScanInput(std::vector<std::string>& DialNameVecr,
94 std::vector<std::string>& SampleNameVec,
95 std::vector<int>& SampleDimVec,
96 std::vector<double>& SigmaValues,
97 const std::string& filename)
100 TFile *infile =
M3::Open(filename,
"OPEN", __FILE__, __LINE__);
101 TDirectoryFile *SigmaDir = infile->Get<TDirectoryFile>(
"SigmaVar");
104 TIter next(SigmaDir->GetListOfKeys());
108 while ((key =
static_cast<TKey*
>(next()))) {
110 auto classname = std::string(key->GetClassName());
111 auto dirname = std::string(key->GetName());
113 if (classname !=
"TDirectoryFile")
continue;
114 dirname = std::string(key->GetName());
116 SigmaDir->cd(dirname.c_str());
117 TIter nextsub(gDirectory->GetListOfKeys());
118 TKey *subkey =
nullptr;
120 DialNameVecr.push_back(dirname);
123 if(SampleNameVec.size() != 0)
continue;
125 while ((subkey =
static_cast<TKey*
>(nextsub())))
127 auto subdirname = std::string(subkey->GetName());
128 SampleNameVec.push_back(subdirname);
129 SampleDimVec.push_back(0);
131 SigmaDir->cd((dirname +
"/" + subdirname).c_str());
133 TKey *subsubkey =
nullptr;
134 TIter nextsubsub(gDirectory->GetListOfKeys());
137 bool FillSigma =
false;
138 if(SigmaValues.size() == 0) FillSigma =
true;
140 while ((subsubkey =
static_cast<TKey*
>(nextsubsub())))
142 auto subsubdirname = std::string(subsubkey->GetTitle());
144 std::string histname = subsubdirname;
146 classname = std::string(subsubkey->GetClassName());
148 if (classname !=
"TH1D")
continue;
150 size_t proj_pos = histname.find(
"_1DProj");
151 int proj_number = -1;
153 if (proj_pos != std::string::npos) {
154 size_t number_start = proj_pos + 7;
155 size_t number_end = histname.find_first_not_of(
"0123456789", number_start);
156 proj_number = std::stoi(histname.substr(number_start, number_end - number_start));
158 SampleDimVec.back() = std::max(proj_number, SampleDimVec.back());
163 if(FillSigma && proj_number == 0)
FindKnot(SigmaValues, dirname, subdirname,
"1DProj" + std::to_string(proj_number), histname);
169 MACH3LOG_ERROR(
"Didn't find prior knot, something is not right...");
178 if(SampleNameVec.size() != SampleDimVec.size()) {
179 MACH3LOG_ERROR(
"Sample name vec ({}) and sample dimension vec ({}) have different sizes, something is not right");
188 bool SkipDirectory(
const std::vector<std::string>& ExcludeString,
const std::vector<std::string>& IncludeString,
const std::string& dirname)
191 for(
unsigned int i = 0; i < ExcludeString.size(); i++)
193 if (dirname.find(ExcludeString[i]) != std::string::npos){ Skip =
true;
break; }
195 for(
unsigned int i = 0; i < IncludeString.size(); i++)
197 if (!(dirname.find(IncludeString[i]) != std::string::npos)){ Skip =
true;
break; }
203 std::vector<double>
GetDialValues(
const std::vector<std::unique_ptr<TH1D>>& Poly) {
204 std::vector<double> values;
205 for (
const auto& hist : Poly) {
206 std::string title = hist->GetTitle();
207 auto pos = title.rfind(
"_val_");
208 if (pos != std::string::npos) {
209 std::string val_str = title.substr(pos + 5);
210 double val = std::stod(val_str);
211 values.push_back(val);
212 MACH3LOG_DEBUG(
"Extracted dial value {} from title '{}'", val, title);
214 MACH3LOG_DEBUG(
"Failed to extract dial value from title '{}'", title);
222 void InitializePads(TCanvas* canv, TPad*& pad1, TPad*& pad2,
double Pad1Bottom = 0.25,
double Pad2Top = 0.25)
225 if (pad1)
delete pad1;
226 if (pad2)
delete pad2;
229 pad1 =
new TPad(
"pad1",
"pad1", 0., Pad2Top, 1., 1.0);
230 pad2 =
new TPad(
"pad2",
"pad2", 0., 0., 1., Pad1Bottom);
237 pad1->SetLeftMargin(canv->GetLeftMargin());
238 pad1->SetRightMargin(canv->GetRightMargin());
239 pad1->SetTopMargin(canv->GetTopMargin());
240 pad1->SetBottomMargin(0);
243 pad2->SetLeftMargin(canv->GetLeftMargin());
244 pad2->SetRightMargin(canv->GetRightMargin());
245 pad2->SetTopMargin(0);
246 pad2->SetBottomMargin(0.30);
253 void MakeRatio(
const std::vector<std::unique_ptr<TH1D>>& Poly,
254 std::vector<std::unique_ptr<TH1D>>& Ratio) {
255 size_t ratio_index = 0;
256 for (
int i = 0; i < static_cast<int>(Poly.size()); ++i) {
258 Ratio[ratio_index] =
M3::Clone(Poly[i].get());
259 Ratio[ratio_index]->Divide(Poly[
PriorKnot].get());
263 Ratio[0]->GetYaxis()->SetTitle(
"Ratio to Prior");
264 Ratio[0]->SetBit(TH1D::kNoTitle);
266 M3::Plotting::SetSymmetricRatioRange(Ratio);
269 void PlotRatio(
const std::vector<std::unique_ptr<TH1D>>& Poly,
270 const std::unique_ptr<TCanvas>& canv,
271 const std::string& Title,
272 const std::string& outfilename)
275 gStyle->SetDrawBorder(0);
276 gStyle->SetTitleBorderSize(2);
277 gStyle->SetOptStat(0);
279 canv->SetTopMargin(0.10);
280 canv->SetBottomMargin(0.08);
281 canv->SetRightMargin(0.05);
282 canv->SetLeftMargin(0.12);
284 TPad* pad1 =
nullptr;
285 TPad* pad2 =
nullptr;
292 for(
int ik = 0; ik < static_cast<int>(
sigmaArray.size()); ++ik)
294 Poly[ik]->SetLineWidth(2.);
295 Poly[ik]->SetLineColor(
Colours[ik]);
296 Poly[ik]->SetLineStyle(
Style[ik]);
297 auto BinWidthScale =
PlotMan->style().getBinWidthScale(Poly[ik]->GetXaxis()->GetTitle());
298 Poly[ik]->GetYaxis()->SetTitle(fmt::format(
"Events/{:.0f}", BinWidthScale).c_str());
300 max = std::max(max, Poly[ik]->GetMaximum());
302 Poly[0]->SetTitle(Title.c_str());
303 Poly[0]->SetMaximum(max*1.2);
304 Poly[0]->Draw(
"HIST");
305 for(
int ik = 1; ik < static_cast<int>(
sigmaArray.size()); ++ik)
307 Poly[ik]->Draw(
"HIST SAME");
310 std::vector<double> Integral(
sigmaArray.size());
311 for(
int ik = 0; ik < static_cast<int>(
sigmaArray.size()); ++ik)
312 Integral[ik] = Poly[ik]->Integral();
314 auto leg =
MakeLegend(0.55, 0.55, 0.8, 0.88, 0.04);
315 leg->SetTextSize(0.04);
316 for (
int j = 0; j < static_cast<int>(
sigmaArray.size()); j++)
319 leg->AddEntry(Poly[j].get(), Form(
"Prior (%.2f), #int=%.2f", DialValues[j], Integral[j]),
"l");
321 leg->AddEntry(Poly[j].get(), Form(
"%.0f#sigma (%.2f), #int=%.2f",
sigmaArray[j], DialValues[j], Integral[j]),
"l");
328 TLine line(Poly[0]->GetXaxis()->GetBinLowEdge(Poly[0]->GetXaxis()->GetFirst()),
329 1.0, Poly[0]->GetXaxis()->GetBinUpEdge(Poly[0]->GetXaxis()->GetLast()), 1.0);
330 std::vector<std::unique_ptr<TH1D>> Ratio(
sigmaArray.size()-1);
334 auto PrettyX =
PlotMan->style().prettifyKinematicName(Ratio[0]->GetXaxis()->GetTitle());
335 Ratio[0]->GetXaxis()->SetTitle(PrettyX.c_str());
336 Ratio[0]->GetXaxis()->SetTitleSize(0.12);
337 Ratio[0]->GetYaxis()->SetTitleOffset(0.4);
338 Ratio[0]->GetYaxis()->SetTitleSize(0.10);
340 Ratio[0]->GetXaxis()->SetLabelSize(0.10);
341 Ratio[0]->GetYaxis()->SetLabelSize(0.10);
342 Ratio[0]->Draw(
"HIST");
343 for(
int ik = 1; ik < static_cast<int>(
sigmaArray.size())-1; ++ik)
345 Ratio[ik]->Draw(
"HIST SAME");
348 line.SetLineWidth(2);
349 line.SetLineColor(kBlack);
352 canv->Print((outfilename).c_str());
361 auto canvas = std::make_unique<TCanvas>(
"canv",
"canv", 1080, 1080);
362 TFile *infile =
M3::Open(filename,
"OPEN", __FILE__, __LINE__);
363 TDirectoryFile *SigmaDir = infile->Get<TDirectoryFile>(
"SigmaVar");
365 std::string outfilename = filename.substr(0, filename.find(
".root"));
366 outfilename = outfilename +
"_RatioPlots1d.pdf";
367 gErrorIgnoreLevel = kWarning;
368 canvas->Print((outfilename+
"[").c_str());
370 auto IncludeString = GetFromManager<std::vector<std::string>>(Settings[
"IncludeString"], {});
371 auto ExcludeString = GetFromManager<std::vector<std::string>>(Settings[
"ExcludeString"], {});
372 TDirectory *dir =
nullptr;
390 std::vector<std::unique_ptr<TH1D>> Projection;
391 TIter nextsub(dir->GetListOfKeys());
392 TKey *subsubkey =
nullptr;
395 while ((subsubkey =
static_cast<TKey*
>(nextsub())))
397 auto name = std::string(subsubkey->GetName());
398 auto classname = std::string(subsubkey->GetClassName());
400 const std::string ProjectionName =
"_1DProj" + std::to_string(iDim);
401 const bool IsProjection = (name.find(ProjectionName) != std::string::npos);
402 if (classname ==
"TH1D" && IsProjection)
405 Projection.emplace_back(
M3::Clone(SigmaDir->Get<TH1D>(name.c_str())));
411 PlotRatio(Projection, canvas, Title, outfilename);
412 gDirectory->cd(
"..");
417 canvas->Print((outfilename+
"]").c_str());
423 const std::unique_ptr<TCanvas>& canv,
424 const std::string& Title,
425 const std::string& outfilename)
428 gStyle->SetDrawBorder(0);
429 gStyle->SetTitleBorderSize(2);
430 gStyle->SetOptStat(0);
432 canv->SetTopMargin(0.10);
433 canv->SetBottomMargin(0.10);
434 canv->SetLeftMargin(0.12);
435 canv->SetRightMargin(0.20);
437 constexpr
int NRGBs = 5;
438 TColor::InitializeColors();
439 Double_t stops[NRGBs] = { 0.00, 0.25, 0.50, 0.75, 1.00 };
440 Double_t red[NRGBs] = { 0.00, 0.25, 1.00, 1.00, 0.50 };
441 Double_t green[NRGBs] = { 0.00, 0.25, 1.00, 0.25, 0.00 };
442 Double_t blue[NRGBs] = { 0.50, 1.00, 1.00, 0.25, 0.00 };
443 TColor::CreateGradientColorTable(5, stops, red, green, blue, 255);
444 gStyle->SetNumberContours(255);
446 for (
int i = 0; i < static_cast<int>(Poly.size()); ++i) {
448 std::unique_ptr<TH2> Ratio =
M3::Clone(Poly[i].get());
450 Ratio->SetTitle((Title +
" " + std::to_string(
static_cast<int>(
sigmaArray[i])) +
"sigma").c_str());
452 const double maxz = Ratio->GetMaximum();
453 const double minz = Ratio->GetMinimum();
454 if (std::fabs(1-maxz) > std::fabs(1-minz))
455 Ratio->GetZaxis()->SetRangeUser(1-std::fabs(1-maxz),1+std::fabs(1-maxz));
457 Ratio->GetZaxis()->SetRangeUser(1-std::fabs(1-minz),1+std::fabs(1-minz));
458 Ratio->GetXaxis()->SetTitleOffset(1.1);
459 Ratio->GetYaxis()->SetTitleOffset(1.1);
460 Ratio->GetZaxis()->SetTitleOffset(1.5);
461 Ratio->GetZaxis()->SetTitle(
"Ratio to Prior");
463 auto PrettyX =
PlotMan->style().prettifyKinematicName(Ratio->GetXaxis()->GetTitle());
464 Ratio->GetXaxis()->SetTitle(PrettyX.c_str());
465 auto PrettyY =
PlotMan->style().prettifyKinematicName(Ratio->GetYaxis()->GetTitle());
466 Ratio->GetYaxis()->SetTitle(PrettyY.c_str());
469 canv->Print((outfilename).c_str());
476 auto canvas = std::make_unique<TCanvas>(
"canv",
"canv", 1080, 1080);
477 TFile *infile =
M3::Open(filename,
"OPEN", __FILE__, __LINE__);
478 TDirectoryFile *SigmaDir = infile->Get<TDirectoryFile>(
"SigmaVar");
480 std::string outfilename = filename.substr(0, filename.find(
".root"));
481 outfilename = outfilename +
"_RatioPlots2d.pdf";
482 gErrorIgnoreLevel = kWarning;
483 canvas->Print((outfilename+
"[").c_str());
485 auto IncludeString = GetFromManager<std::vector<std::string>>(Settings[
"IncludeString"], {});
486 auto ExcludeString = GetFromManager<std::vector<std::string>>(Settings[
"ExcludeString"], {});
487 TDirectory *dir =
nullptr;
502 TIter nextsub(dir->GetListOfKeys());
503 TKey *subsubkey =
nullptr;
506 for (
int iDim1 = 0; iDim1 <= nDim; ++iDim1) {
507 for (
int iDim2 = iDim1 + 1; iDim2 <= nDim; ++iDim2) {
511 std::vector<std::unique_ptr<TH2>> Projection;
514 while ((subsubkey =
static_cast<TKey*
>(nextsub())))
516 auto name = std::string(subsubkey->GetName());
517 auto classname = std::string(subsubkey->GetClassName());
519 const std::string ProjectionName =
"_2DProj_" + std::to_string(iDim1) +
"_vs_" + std::to_string(iDim2);
520 const bool IsProjection = (name.find(ProjectionName) != std::string::npos);
521 if ((classname ==
"TH2D" || classname ==
"TH2Poly")&& IsProjection)
524 Projection.emplace_back(
M3::Clone(SigmaDir->Get<TH2>(name.c_str())));
533 gDirectory->cd(
"..");
536 canvas->Print((outfilename+
"]").c_str());
542 void PlotEventRate(
const std::vector<std::vector<std::unique_ptr<TH1D>>>& Poly,
543 const std::unique_ptr<TCanvas>& canv,
544 const std::string& Title,
545 const std::string& outfilename)
547 std::vector<std::unique_ptr<TH1D>> EvenRates(
sigmaArray.size());
548 for(
int ih = 0; ih < static_cast<int>(
sigmaArray.size()); ih++)
551 EvenRates[ih]->SetDirectory(
nullptr);
552 EvenRates[ih]->GetYaxis()->SetTitleOffset(1.4);
553 EvenRates[ih]->GetYaxis()->SetTitle(
"Events");
554 EvenRates[ih]->SetLineWidth(2.);
555 EvenRates[ih]->SetLineStyle(
Style[ih]);
556 EvenRates[ih]->SetLineColor(
Colours[ih]);
559 EvenRates[ih]->SetBinContent(iSample+1, Poly[iSample][ih]->Integral());
562 EvenRates[ih]->GetXaxis()->SetBinLabel(iSample+1, SamName.c_str());
566 TPad* pad1 =
nullptr;
567 TPad* pad2 =
nullptr;
569 pad2->SetBottomMargin(0.60);
573 for(
int ik = 0; ik < static_cast<int>(
sigmaArray.size()); ++ik) {
574 max = std::max(max, EvenRates[ik]->GetMaximum());
576 EvenRates[0]->SetTitle(Title.c_str());
577 EvenRates[0]->SetMaximum(max*1.2);
578 EvenRates[0]->Draw(
"HIST");
579 for(
int ik = 1; ik < static_cast<int>(
sigmaArray.size()); ++ik)
581 EvenRates[ik]->Draw(
"HIST SAME");
585 auto leg =
MakeLegend(0.55, 0.55, 0.8, 0.88, 0.04);
586 for (
int j = 0; j < static_cast<int>(
sigmaArray.size()); j++)
589 leg->AddEntry(EvenRates[j].get(), Form(
"Prior (%.2f)", DialValues[j]),
"l");
591 leg->AddEntry(EvenRates[j].get(), Form(
"%.0f#sigma (%.2f)",
sigmaArray[j], DialValues[j]),
"l");
597 TLine line(EvenRates[0]->GetXaxis()->GetBinLowEdge(EvenRates[0]->GetXaxis()->GetFirst()),
598 1.0, EvenRates[0]->GetXaxis()->GetBinUpEdge(EvenRates[0]->GetXaxis()->GetLast()), 1.0);
599 std::vector<std::unique_ptr<TH1D>> Ratio(
sigmaArray.size()-1);
601 Ratio[0]->GetXaxis()->SetTitleSize(0.08);
602 Ratio[0]->GetYaxis()->SetTitleOffset(0.4);
603 Ratio[0]->GetYaxis()->SetTitleSize(0.06);
605 Ratio[0]->GetXaxis()->SetLabelSize(0.08);
606 Ratio[0]->GetYaxis()->SetLabelSize(0.04);
607 Ratio[0]->GetXaxis()->LabelsOption(
"v");
608 Ratio[0]->Draw(
"HIST");
610 for(
int ik = 1; ik < static_cast<int>(
sigmaArray.size())-1; ++ik)
612 Ratio[ik]->Draw(
"HIST SAME");
615 line.SetLineWidth(2);
616 line.SetLineColor(kBlack);
619 canv->Print((outfilename).c_str());
629 auto canvas = std::make_unique<TCanvas>(
"canv",
"canv", 1080, 1080);
630 canvas->SetRightMargin(0.05);
631 TFile *infile =
M3::Open(filename,
"OPEN", __FILE__, __LINE__);
632 TDirectoryFile *SigmaDir = infile->Get<TDirectoryFile>(
"SigmaVar");
634 std::string outfilename = filename.substr(0, filename.find(
".root"));
635 outfilename = outfilename +
"_EventRate.pdf";
636 gErrorIgnoreLevel = kWarning;
637 canvas->Print((outfilename+
"[").c_str());
639 TDirectory *dir =
nullptr;
642 std::vector<std::vector<std::unique_ptr<TH1D>>> Projection(
SampleNameVector.size());
652 TIter nextsub(dir->GetListOfKeys());
653 TKey *subsubkey =
nullptr;
656 while ((subsubkey =
static_cast<TKey*
>(nextsub())))
658 auto name = std::string(subsubkey->GetName());
659 auto classname = std::string(subsubkey->GetClassName());
661 const std::string ProjectionName =
"_1DProj0";
662 const bool IsProjection = (name.find(ProjectionName) != std::string::npos);
663 if (classname ==
"TH1D" && IsProjection)
666 Projection[is].emplace_back(
M3::Clone(SigmaDir->Get<TH1D>(name.c_str())));
670 gDirectory->cd(
"..");
676 canvas->Print((outfilename+
"]").c_str());
681 void PlotSigVar1D(
const std::vector<std::vector<std::unique_ptr<TH1D>>>& Projection,
682 const std::unique_ptr<TCanvas>& canv,
683 const std::string& Title,
684 const std::string& outfilename,
685 const std::vector<std::string>& ParamNames,
686 const std::vector<int>& ParamColour)
689 gStyle->SetDrawBorder(0);
690 gStyle->SetTitleBorderSize(2);
691 gStyle->SetOptStat(0);
693 canv->SetTopMargin(0.10);
694 canv->SetBottomMargin(0.08);
695 canv->SetRightMargin(0.05);
696 canv->SetLeftMargin(0.12);
698 auto PriorHist = Projection[0][
PriorKnot].get();
699 PriorHist->SetTitle(Title.c_str());
701 auto BinWidthScale =
PlotMan->style().getBinWidthScale(PriorHist->GetXaxis()->GetTitle());
702 PriorHist->GetYaxis()->SetTitle(fmt::format(
"Events/{:.0f}", BinWidthScale).c_str());
703 PriorHist->Draw(
"HIST");
704 PriorHist->SetLineWidth(2.);
705 PriorHist->SetLineColor(kBlack);
708 auto PrettyX =
PlotMan->style().prettifyKinematicName(PriorHist->GetXaxis()->GetTitle());
709 PriorHist->GetXaxis()->SetTitle(PrettyX.c_str());
710 for(
int ik = 0; ik < static_cast<int>(
sigmaArray.size()); ++ik)
715 for(
size_t nParam = 0; nParam < Projection.size(); nParam++) {
716 Projection[nParam][ik]->SetLineWidth(2.);
717 Projection[nParam][ik]->SetLineColor(ParamColour[nParam]);
718 Projection[nParam][ik]->SetLineStyle(kDotted);
719 Projection[nParam][ik]->GetYaxis()->SetTitle(fmt::format(
"Events/{:.0f}", BinWidthScale).c_str());
721 max = std::max(max, Projection[nParam][ik]->GetMaximum());
723 PriorHist->SetMaximum(max*1.2);
725 PriorHist->Draw(
"HIST");
726 for(
size_t nParam = 0; nParam < Projection.size(); nParam++) {
727 Projection[nParam][ik]->Draw(
"HIST SAME");
729 auto leg =
MakeLegend(0.50, 0.55, 0.70, 0.75, 0.035);
730 leg->AddEntry(PriorHist,
"Prior",
"l");
731 for(
size_t nParam = 0; nParam < Projection.size(); nParam++) {
732 leg->AddEntry(Projection[nParam][ik].get(), Form(
"%s (%.0f#sigma)", ParamNames[nParam].c_str(),
sigmaArray[ik]),
"l");
736 canv->Print((outfilename).c_str());
743 auto ParamNames = GetFromManager<std::vector<std::string>>(Settings[
"ParamNames"], {});
744 auto SigColours = GetFromManager<std::vector<int>>(Settings[
"Coulour"], {});
746 if(ParamNames.size() == 0)
return;
748 if(ParamNames.size() != SigColours.size()){
754 auto canvas = std::make_unique<TCanvas>(
"canv",
"canv", 1080, 1080);
755 TFile *infile =
M3::Open(filename,
"OPEN", __FILE__, __LINE__);
756 TDirectoryFile *SigmaDir = infile->Get<TDirectoryFile>(
"SigmaVar");
758 std::string outfilename = filename.substr(0, filename.find(
".root"));
759 outfilename = outfilename +
"_Overlay1d.pdf";
760 gErrorIgnoreLevel = kWarning;
761 canvas->Print((outfilename+
"[").c_str());
763 TDirectory *dir =
nullptr;
770 std::vector<std::vector<std::unique_ptr<TH1D>>> Projection(ParamNames.size());
771 for(
size_t id = 0;
id < ParamNames.size();
id++)
779 TIter nextsub(dir->GetListOfKeys());
780 TKey *subsubkey =
nullptr;
783 while ((subsubkey =
static_cast<TKey*
>(nextsub())))
785 auto name = std::string(subsubkey->GetName());
786 auto classname = std::string(subsubkey->GetClassName());
788 const std::string ProjectionName =
"_1DProj" + std::to_string(iDim);
789 const bool IsProjection = (name.find(ProjectionName) != std::string::npos);
790 if (classname ==
"TH1D" && IsProjection)
793 Projection[id].emplace_back(
M3::Clone(SigmaDir->Get<TH1D>(name.c_str())));
799 PlotSigVar1D(Projection, canvas, Title, outfilename, ParamNames, SigColours);
800 gDirectory->cd(
"..");
804 canvas->Print((outfilename+
"]").c_str());
809 int main(
int argc,
char **argv)
814 MACH3LOG_ERROR(
"Need two inputs: output of sigma var and config");
817 std::string filename = argv[1];
818 std::string ConfigName = argv[2];
819 MACH3LOG_INFO(
"Running {} with {} {}", argv[0], filename, ConfigName);
824 YAML::Node settings = Config[
"PlotSigmaVariation"];
828 PlotMan =
new M3::Plotting::PlottingManager();
void SetMaCh3LoggerFormat()
Set messaging format of the logger.
void PlotRatio(const std::vector< std::unique_ptr< TH1D >> &Poly, const std::unique_ptr< TCanvas > &canv, const std::string &Title, const std::string &outfilename)
void CompareSigVar2D(const std::string &filename, const YAML::Node &Settings)
constexpr ELineStyle Style[NVars]
int main(int argc, char **argv)
void PlotRatio2D(const std::vector< std::unique_ptr< TH2 >> &Poly, const std::unique_ptr< TCanvas > &canv, const std::string &Title, const std::string &outfilename)
void OverlaySigVar1D(const std::string &filename, const YAML::Node &Settings)
constexpr Color_t Colours[NVars]
std::vector< double > GetDialValues(const std::vector< std::unique_ptr< TH1D >> &Poly)
Extracts dial value for from histogram title.
void PlotEventRate(const std::vector< std::vector< std::unique_ptr< TH1D >>> &Poly, const std::unique_ptr< TCanvas > &canv, const std::string &Title, const std::string &outfilename)
void CompareSigVar1D(const std::string &filename, const YAML::Node &Settings)
void PlotSigVar1D(const std::vector< std::vector< std::unique_ptr< TH1D >>> &Projection, const std::unique_ptr< TCanvas > &canv, const std::string &Title, const std::string &outfilename, const std::vector< std::string > &ParamNames, const std::vector< int > &ParamColour)
std::unique_ptr< TLegend > MakeLegend(double x1, double y1, double x2, double y2, double textSize=0.04)
std::vector< int > SampleMaxDim
void ScanInput(std::vector< std::string > &DialNameVecr, std::vector< std::string > &SampleNameVec, std::vector< int > &SampleDimVec, std::vector< double > &SigmaValues, const std::string &filename)
Scan inputs to figure out dial name and used sample names.
std::vector< std::string > DialNameVector
void FindKnot(std::vector< double > &SigmaValues, const std::string &dirname, const std::string &subdirname, const std::string &ProjName, std::string histname)
Histograms have name like ND_CC0pi_1DProj0_Norm_Param_0_sig_n3.00_val_0.25. This code is trying to ex...
std::vector< std::string > SampleNameVector
std::vector< double > sigmaArray
void InitializePads(TCanvas *canv, TPad *&pad1, TPad *&pad2, double Pad1Bottom=0.25, double Pad2Top=0.25)
constexpr const int NVars
void MakeRatio(const std::vector< std::unique_ptr< TH1D >> &Poly, std::vector< std::unique_ptr< TH1D >> &Ratio)
void MakeEventRatePlot(const std::string &filename, const YAML::Node &Settings)
M3::Plotting::PlottingManager * PlotMan
bool SkipDirectory(const std::vector< std::string > &ExcludeString, const std::vector< std::string > &IncludeString, const std::string &dirname)
Check whether to skip directory or not based on defined strings.
#define M3OpenConfig(filename)
Macro to simplify calling LoadYaml with file and line info.
Custom exception class used throughout MaCh3.
std::unique_ptr< ObjectType > Clone(const ObjectType *obj, const std::string &name="")
KS: Creates a copy of a ROOT-like object and wraps it in a smart pointer.
void ScaleHistogram(TH1 *Sample_Hist, const double scale)
Scale histogram to get divided by bin width.
TFile * Open(const std::string &Name, const std::string &Type, const std::string &File, const int Line)
Opens a ROOT file with the given name and mode.
constexpr static const int _BAD_INT_
Default value used for int initialisation.