2 #include "PlottingUtils/PlottingUtils.h"
3 #include "PlottingUtils/PlottingManager.h"
5 #pragma GCC diagnostic ignored "-Wfloat-conversion"
6 #pragma GCC diagnostic ignored "-Wconversion"
23 constexpr Color_t
Colours[
NVars] = {kRed, kGreen+1, kBlack, kBlue+1, kOrange+1};
24 constexpr ELineStyle
Style[
NVars] = {kDotted, kDashed, kSolid, kDashDotted, kDashDotted};
30 void FindKnot(std::vector<double>& SigmaValues,
31 const std::string& dirname,
32 const std::string& subdirname,
33 const std::string& ProjName,
34 std::string histname) {
35 auto StripPrefix = [](std::string& str,
const std::string& prefix) {
36 if (str.find(prefix +
"_") == 0) {
37 str.erase(0, prefix.length() + 1);
38 if (str.find(prefix) == 0) {
39 MACH3LOG_ERROR(
"Failed to strip prefix '{}' from string '{}'", prefix, str);
43 MACH3LOG_ERROR(
"String '{}' does not start with expected prefix '{}'", str, prefix);
49 StripPrefix(histname, subdirname);
50 StripPrefix(histname, ProjName);
51 StripPrefix(histname, dirname);
57 size_t sig_pos = histname.find(
"_sig_");
59 std::string sigma_part = histname.substr(sig_pos + 5);
62 if (histname.find(
"nom_") != std::string::npos) {
64 PriorKnot =
static_cast<int>(SigmaValues.size());
66 }
else if (sigma_part.size() > 0 && sigma_part[0] ==
'n') {
67 sigma = -std::stod(sigma_part.substr(1));
68 }
else if (sigma_part.size() > 0 && sigma_part[0] ==
'p') {
69 sigma = std::stod(sigma_part.substr(1));
76 SigmaValues.push_back(sigma);
79 std::unique_ptr<TLegend>
MakeLegend(
double x1,
double y1,
double x2,
double y2,
80 double textSize = 0.04)
82 auto leg = std::make_unique<TLegend>(x1, y1, x2, y2);
83 leg->SetTextSize(textSize);
88 leg->SetBorderSize(0);
94 void ScanInput(std::vector<std::string>& DialNameVecr,
95 std::vector<std::string>& SampleNameVec,
96 std::vector<int>& SampleDimVec,
97 std::vector<double>& SigmaValues,
98 const std::string& filename)
101 TFile *infile =
M3::Open(filename,
"OPEN", __FILE__, __LINE__);
102 TDirectoryFile *SigmaDir = infile->Get<TDirectoryFile>(
"SigmaVar");
105 TIter next(SigmaDir->GetListOfKeys());
109 while ((key =
static_cast<TKey*
>(next()))) {
111 auto classname = std::string(key->GetClassName());
112 auto dirname = std::string(key->GetName());
114 if (classname !=
"TDirectoryFile")
continue;
115 dirname = std::string(key->GetName());
117 SigmaDir->cd(dirname.c_str());
118 TIter nextsub(gDirectory->GetListOfKeys());
119 TKey *subkey =
nullptr;
121 DialNameVecr.push_back(dirname);
124 if(SampleNameVec.size() != 0)
continue;
126 while ((subkey =
static_cast<TKey*
>(nextsub())))
128 auto subdirname = std::string(subkey->GetName());
129 SampleNameVec.push_back(subdirname);
130 SampleDimVec.push_back(0);
132 SigmaDir->cd((dirname +
"/" + subdirname).c_str());
134 TKey *subsubkey =
nullptr;
135 TIter nextsubsub(gDirectory->GetListOfKeys());
138 bool FillSigma =
false;
139 if(SigmaValues.size() == 0) FillSigma =
true;
141 while ((subsubkey =
static_cast<TKey*
>(nextsubsub())))
143 auto subsubdirname = std::string(subsubkey->GetTitle());
145 std::string histname = subsubdirname;
147 classname = std::string(subsubkey->GetClassName());
149 if (classname !=
"TH1D")
continue;
151 size_t proj_pos = histname.find(
"_1DProj");
152 int proj_number = -1;
154 if (proj_pos != std::string::npos) {
155 size_t number_start = proj_pos + 7;
156 size_t number_end = histname.find_first_not_of(
"0123456789", number_start);
157 proj_number = std::stoi(histname.substr(number_start, number_end - number_start));
159 SampleDimVec.back() = std::max(proj_number, SampleDimVec.back());
164 if(FillSigma && proj_number == 0)
FindKnot(SigmaValues, dirname, subdirname,
"1DProj" + std::to_string(proj_number), histname);
170 MACH3LOG_ERROR(
"Didn't find prior knot, something is not right...");
179 if(SampleNameVec.size() != SampleDimVec.size()) {
180 MACH3LOG_ERROR(
"Sample name vec ({}) and sample dimension vec ({}) have different sizes, something is not right");
189 bool SkipDirectory(
const std::vector<std::string>& ExcludeString,
const std::vector<std::string>& IncludeString,
const std::string& dirname)
192 for(
unsigned int i = 0; i < ExcludeString.size(); i++)
194 if (dirname.find(ExcludeString[i]) != std::string::npos){ Skip =
true;
break; }
196 for(
unsigned int i = 0; i < IncludeString.size(); i++)
198 if (!(dirname.find(IncludeString[i]) != std::string::npos)){ Skip =
true;
break; }
204 std::vector<double>
GetDialValues(
const std::vector<std::unique_ptr<TH1D>>& Poly) {
205 std::vector<double> values;
206 for (
const auto& hist : Poly) {
207 std::string title = hist->GetTitle();
208 auto pos = title.rfind(
"_val_");
209 if (pos != std::string::npos) {
210 std::string val_str = title.substr(pos + 5);
211 double val = std::stod(val_str);
212 values.push_back(val);
213 MACH3LOG_DEBUG(
"Extracted dial value {} from title '{}'", val, title);
215 MACH3LOG_DEBUG(
"Failed to extract dial value from title '{}'", title);
223 void InitializePads(TCanvas*
canv, TPad*& pad1, TPad*& pad2,
double Pad1Bottom = 0.25,
double Pad2Top = 0.25)
226 if (pad1)
delete pad1;
227 if (pad2)
delete pad2;
230 pad1 =
new TPad(
"pad1",
"pad1", 0., Pad2Top, 1., 1.0);
231 pad2 =
new TPad(
"pad2",
"pad2", 0., 0., 1., Pad1Bottom);
238 pad1->SetLeftMargin(
canv->GetLeftMargin());
239 pad1->SetRightMargin(
canv->GetRightMargin());
240 pad1->SetTopMargin(
canv->GetTopMargin());
241 pad1->SetBottomMargin(0);
244 pad2->SetLeftMargin(
canv->GetLeftMargin());
245 pad2->SetRightMargin(
canv->GetRightMargin());
246 pad2->SetTopMargin(0);
247 pad2->SetBottomMargin(0.30);
254 void MakeRatio(
const std::vector<std::unique_ptr<TH1D>>& Poly,
255 std::vector<std::unique_ptr<TH1D>>& Ratio) {
256 size_t ratio_index = 0;
257 for (
int i = 0; i < static_cast<int>(Poly.size()); ++i) {
259 Ratio[ratio_index] =
M3::Clone(Poly[i].get());
260 Ratio[ratio_index]->Divide(Poly[
PriorKnot].get());
264 Ratio[0]->GetYaxis()->SetTitle(
"Ratio to Prior");
265 Ratio[0]->SetBit(TH1D::kNoTitle);
266 Ratio[0]->SetBit(TH1D::kNoTitle);
270 for (
int j = 0; j < static_cast<int>(
sigmaArray.size())-1; j++)
272 for (
int i = 1; i < Ratio[0]->GetXaxis()->GetNbins(); i++)
274 maxz = std::max(maxz, Ratio[j]->GetBinContent(i));
275 minz = std::min(minz, Ratio[j]->GetBinContent(i));
281 if (std::fabs(1 - maxz) > std::fabs(1-minz))
282 Ratio[0]->GetYaxis()->SetRangeUser(1-std::fabs(1-maxz),1+std::fabs(1-maxz));
284 Ratio[0]->GetYaxis()->SetRangeUser(1-std::fabs(1-minz),1+std::fabs(1-minz));
288 void PlotRatio(
const std::vector<std::unique_ptr<TH1D>>& Poly,
289 const std::unique_ptr<TCanvas>&
canv,
290 const std::string& Title,
291 const std::string& outfilename)
294 gStyle->SetDrawBorder(0);
295 gStyle->SetTitleBorderSize(2);
296 gStyle->SetOptStat(0);
298 canv->SetTopMargin(0.10);
299 canv->SetBottomMargin(0.08);
300 canv->SetRightMargin(0.05);
301 canv->SetLeftMargin(0.12);
303 TPad* pad1 =
nullptr;
304 TPad* pad2 =
nullptr;
311 for(
int ik = 0; ik < static_cast<int>(
sigmaArray.size()); ++ik)
313 Poly[ik]->SetLineWidth(2.);
314 Poly[ik]->SetLineColor(
Colours[ik]);
315 Poly[ik]->SetLineStyle(
Style[ik]);
316 Poly[ik]->GetYaxis()->SetTitle(fmt::format(
"Events/{:.0f}",
ScalingFactor).c_str());
318 max = std::max(max, Poly[ik]->GetMaximum());
320 Poly[0]->SetTitle(Title.c_str());
321 Poly[0]->SetMaximum(max*1.2);
322 Poly[0]->Draw(
"HIST");
323 for(
int ik = 1; ik < static_cast<int>(
sigmaArray.size()); ++ik)
325 Poly[ik]->Draw(
"HIST SAME");
328 std::vector<double> Integral(
sigmaArray.size());
329 for(
int ik = 0; ik < static_cast<int>(
sigmaArray.size()); ++ik)
330 Integral[ik] = Poly[ik]->Integral();
332 auto leg =
MakeLegend(0.55, 0.55, 0.8, 0.88, 0.04);
333 leg->SetTextSize(0.04);
334 for (
int j = 0; j < static_cast<int>(
sigmaArray.size()); j++)
337 leg->AddEntry(Poly[j].get(), Form(
"Prior (%.2f), #int=%.2f", DialValues[j], Integral[j]),
"l");
339 leg->AddEntry(Poly[j].get(), Form(
"%.0f#sigma (%.2f), #int=%.2f",
sigmaArray[j], DialValues[j], Integral[j]),
"l");
346 TLine line(Poly[0]->GetXaxis()->GetBinLowEdge(Poly[0]->GetXaxis()->GetFirst()),
347 1.0, Poly[0]->GetXaxis()->GetBinUpEdge(Poly[0]->GetXaxis()->GetLast()), 1.0);
348 std::vector<std::unique_ptr<TH1D>> Ratio(
sigmaArray.size()-1);
352 auto PrettyX =
PlotMan->style().prettifyKinematicName(Ratio[0]->GetXaxis()->GetTitle());
353 Ratio[0]->GetXaxis()->SetTitle(PrettyX.c_str());
354 Ratio[0]->GetXaxis()->SetTitleSize(0.12);
355 Ratio[0]->GetYaxis()->SetTitleOffset(0.4);
356 Ratio[0]->GetYaxis()->SetTitleSize(0.10);
358 Ratio[0]->GetXaxis()->SetLabelSize(0.10);
359 Ratio[0]->GetYaxis()->SetLabelSize(0.10);
360 Ratio[0]->Draw(
"HIST");
361 for(
int ik = 1; ik < static_cast<int>(
sigmaArray.size())-1; ++ik)
363 Ratio[ik]->Draw(
"HIST SAME");
366 line.SetLineWidth(2);
367 line.SetLineColor(kBlack);
370 canv->Print((outfilename).c_str());
379 auto canvas = std::make_unique<TCanvas>(
"canv",
"canv", 1080, 1080);
380 TFile *infile =
M3::Open(filename,
"OPEN", __FILE__, __LINE__);
381 TDirectoryFile *SigmaDir = infile->Get<TDirectoryFile>(
"SigmaVar");
383 std::string outfilename = filename.substr(0, filename.find(
".root"));
384 outfilename = outfilename +
"_RatioPlots1d.pdf";
385 gErrorIgnoreLevel = kWarning;
386 canvas->Print((outfilename+
"[").c_str());
388 auto IncludeString = GetFromManager<std::vector<std::string>>(Settings[
"IncludeString"], {});
389 auto ExcludeString = GetFromManager<std::vector<std::string>>(Settings[
"ExcludeString"], {});
390 TDirectory *dir =
nullptr;
408 std::vector<std::unique_ptr<TH1D>> Projection;
409 TIter nextsub(dir->GetListOfKeys());
410 TKey *subsubkey =
nullptr;
413 while ((subsubkey =
static_cast<TKey*
>(nextsub())))
415 auto name = std::string(subsubkey->GetName());
416 auto classname = std::string(subsubkey->GetClassName());
418 const std::string ProjectionName =
"_1DProj" + std::to_string(iDim);
419 const bool IsProjection = (name.find(ProjectionName) != std::string::npos);
420 if (classname ==
"TH1D" && IsProjection)
423 Projection.emplace_back(
M3::Clone(SigmaDir->Get<TH1D>(name.c_str())));
429 PlotRatio(Projection, canvas, Title, outfilename);
430 gDirectory->cd(
"..");
435 canvas->Print((outfilename+
"]").c_str());
441 const std::unique_ptr<TCanvas>&
canv,
442 const std::string& Title,
443 const std::string& outfilename)
446 gStyle->SetDrawBorder(0);
447 gStyle->SetTitleBorderSize(2);
448 gStyle->SetOptStat(0);
450 canv->SetTopMargin(0.10);
451 canv->SetBottomMargin(0.10);
452 canv->SetLeftMargin(0.12);
453 canv->SetRightMargin(0.20);
455 constexpr
int NRGBs = 5;
456 TColor::InitializeColors();
457 Double_t stops[NRGBs] = { 0.00, 0.25, 0.50, 0.75, 1.00 };
458 Double_t red[NRGBs] = { 0.00, 0.25, 1.00, 1.00, 0.50 };
459 Double_t green[NRGBs] = { 0.00, 0.25, 1.00, 0.25, 0.00 };
460 Double_t blue[NRGBs] = { 0.50, 1.00, 1.00, 0.25, 0.00 };
461 TColor::CreateGradientColorTable(5, stops, red, green, blue, 255);
462 gStyle->SetNumberContours(255);
464 for (
int i = 0; i < static_cast<int>(Poly.size()); ++i) {
466 std::unique_ptr<TH2> Ratio =
M3::Clone(Poly[i].get());
468 Ratio->SetTitle((Title +
" " + std::to_string(
static_cast<int>(
sigmaArray[i])) +
"sigma").c_str());
470 const double maxz = Ratio->GetMaximum();
471 const double minz = Ratio->GetMinimum();
472 if (std::fabs(1-maxz) > std::fabs(1-minz))
473 Ratio->GetZaxis()->SetRangeUser(1-std::fabs(1-maxz),1+std::fabs(1-maxz));
475 Ratio->GetZaxis()->SetRangeUser(1-std::fabs(1-minz),1+std::fabs(1-minz));
476 Ratio->GetXaxis()->SetTitleOffset(1.1);
477 Ratio->GetYaxis()->SetTitleOffset(1.1);
478 Ratio->GetZaxis()->SetTitleOffset(1.5);
479 Ratio->GetZaxis()->SetTitle(
"Ratio to Prior");
481 auto PrettyX =
PlotMan->style().prettifyKinematicName(Ratio->GetXaxis()->GetTitle());
482 Ratio->GetXaxis()->SetTitle(PrettyX.c_str());
483 auto PrettyY =
PlotMan->style().prettifyKinematicName(Ratio->GetYaxis()->GetTitle());
484 Ratio->GetYaxis()->SetTitle(PrettyY.c_str());
487 canv->Print((outfilename).c_str());
494 auto canvas = std::make_unique<TCanvas>(
"canv",
"canv", 1080, 1080);
495 TFile *infile =
M3::Open(filename,
"OPEN", __FILE__, __LINE__);
496 TDirectoryFile *SigmaDir = infile->Get<TDirectoryFile>(
"SigmaVar");
498 std::string outfilename = filename.substr(0, filename.find(
".root"));
499 outfilename = outfilename +
"_RatioPlots2d.pdf";
500 gErrorIgnoreLevel = kWarning;
501 canvas->Print((outfilename+
"[").c_str());
503 auto IncludeString = GetFromManager<std::vector<std::string>>(Settings[
"IncludeString"], {});
504 auto ExcludeString = GetFromManager<std::vector<std::string>>(Settings[
"ExcludeString"], {});
505 TDirectory *dir =
nullptr;
520 TIter nextsub(dir->GetListOfKeys());
521 TKey *subsubkey =
nullptr;
524 for (
int iDim1 = 0; iDim1 <= nDim; ++iDim1) {
525 for (
int iDim2 = iDim1 + 1; iDim2 <= nDim; ++iDim2) {
529 std::vector<std::unique_ptr<TH2>> Projection;
532 while ((subsubkey =
static_cast<TKey*
>(nextsub())))
534 auto name = std::string(subsubkey->GetName());
535 auto classname = std::string(subsubkey->GetClassName());
537 const std::string ProjectionName =
"_2DProj_" + std::to_string(iDim1) +
"_vs_" + std::to_string(iDim2);
538 const bool IsProjection = (name.find(ProjectionName) != std::string::npos);
539 if ((classname ==
"TH2D" || classname ==
"TH2Poly")&& IsProjection)
542 Projection.emplace_back(
M3::Clone(SigmaDir->Get<TH2>(name.c_str())));
551 gDirectory->cd(
"..");
554 canvas->Print((outfilename+
"]").c_str());
560 void PlotEventRate(
const std::vector<std::vector<std::unique_ptr<TH1D>>>& Poly,
561 const std::unique_ptr<TCanvas>&
canv,
562 const std::string& Title,
563 const std::string& outfilename)
565 std::vector<std::unique_ptr<TH1D>> EvenRates(
sigmaArray.size());
566 for(
int ih = 0; ih < static_cast<int>(
sigmaArray.size()); ih++)
569 EvenRates[ih]->SetDirectory(
nullptr);
570 EvenRates[ih]->GetYaxis()->SetTitleOffset(1.4);
571 EvenRates[ih]->GetYaxis()->SetTitle(
"Events");
572 EvenRates[ih]->SetLineWidth(2.);
573 EvenRates[ih]->SetLineStyle(
Style[ih]);
574 EvenRates[ih]->SetLineColor(
Colours[ih]);
577 EvenRates[ih]->SetBinContent(iSample+1, Poly[iSample][ih]->Integral());
580 EvenRates[ih]->GetXaxis()->SetBinLabel(iSample+1, SamName.c_str());
584 TPad* pad1 =
nullptr;
585 TPad* pad2 =
nullptr;
587 pad2->SetBottomMargin(0.60);
591 for(
int ik = 0; ik < static_cast<int>(
sigmaArray.size()); ++ik) {
592 max = std::max(max, EvenRates[ik]->GetMaximum());
594 EvenRates[0]->SetTitle(Title.c_str());
595 EvenRates[0]->SetMaximum(max*1.2);
596 EvenRates[0]->Draw(
"HIST");
597 for(
int ik = 1; ik < static_cast<int>(
sigmaArray.size()); ++ik)
599 EvenRates[ik]->Draw(
"HIST SAME");
603 auto leg =
MakeLegend(0.55, 0.55, 0.8, 0.88, 0.04);
604 for (
int j = 0; j < static_cast<int>(
sigmaArray.size()); j++)
607 leg->AddEntry(EvenRates[j].get(), Form(
"Prior (%.2f)", DialValues[j]),
"l");
609 leg->AddEntry(EvenRates[j].get(), Form(
"%.0f#sigma (%.2f)",
sigmaArray[j], DialValues[j]),
"l");
615 TLine line(EvenRates[0]->GetXaxis()->GetBinLowEdge(EvenRates[0]->GetXaxis()->GetFirst()),
616 1.0, EvenRates[0]->GetXaxis()->GetBinUpEdge(EvenRates[0]->GetXaxis()->GetLast()), 1.0);
617 std::vector<std::unique_ptr<TH1D>> Ratio(
sigmaArray.size()-1);
619 Ratio[0]->GetXaxis()->SetTitleSize(0.08);
620 Ratio[0]->GetYaxis()->SetTitleOffset(0.4);
621 Ratio[0]->GetYaxis()->SetTitleSize(0.06);
623 Ratio[0]->GetXaxis()->SetLabelSize(0.08);
624 Ratio[0]->GetYaxis()->SetLabelSize(0.04);
625 Ratio[0]->GetXaxis()->LabelsOption(
"v");
626 Ratio[0]->Draw(
"HIST");
628 for(
int ik = 1; ik < static_cast<int>(
sigmaArray.size())-1; ++ik)
630 Ratio[ik]->Draw(
"HIST SAME");
633 line.SetLineWidth(2);
634 line.SetLineColor(kBlack);
637 canv->Print((outfilename).c_str());
647 auto canvas = std::make_unique<TCanvas>(
"canv",
"canv", 1080, 1080);
648 TFile *infile =
M3::Open(filename,
"OPEN", __FILE__, __LINE__);
649 TDirectoryFile *SigmaDir = infile->Get<TDirectoryFile>(
"SigmaVar");
651 std::string outfilename = filename.substr(0, filename.find(
".root"));
652 outfilename = outfilename +
"_EventRate.pdf";
653 gErrorIgnoreLevel = kWarning;
654 canvas->Print((outfilename+
"[").c_str());
656 TDirectory *dir =
nullptr;
659 std::vector<std::vector<std::unique_ptr<TH1D>>> Projection(
SampleNameVector.size());
669 TIter nextsub(dir->GetListOfKeys());
670 TKey *subsubkey =
nullptr;
673 while ((subsubkey =
static_cast<TKey*
>(nextsub())))
675 auto name = std::string(subsubkey->GetName());
676 auto classname = std::string(subsubkey->GetClassName());
678 const std::string ProjectionName =
"_1DProj0";
679 const bool IsProjection = (name.find(ProjectionName) != std::string::npos);
680 if (classname ==
"TH1D" && IsProjection)
683 Projection[is].emplace_back(
M3::Clone(SigmaDir->Get<TH1D>(name.c_str())));
687 gDirectory->cd(
"..");
693 canvas->Print((outfilename+
"]").c_str());
698 void PlotSigVar1D(
const std::vector<std::vector<std::unique_ptr<TH1D>>>& Projection,
699 const std::unique_ptr<TCanvas>&
canv,
700 const std::string& Title,
701 const std::string& outfilename,
702 const std::vector<std::string>& ParamNames,
703 const std::vector<int>& ParamColour)
706 gStyle->SetDrawBorder(0);
707 gStyle->SetTitleBorderSize(2);
708 gStyle->SetOptStat(0);
710 canv->SetTopMargin(0.10);
711 canv->SetBottomMargin(0.08);
712 canv->SetRightMargin(0.05);
713 canv->SetLeftMargin(0.12);
715 auto PriorHist = Projection[0][
PriorKnot].get();
716 PriorHist->SetTitle(Title.c_str());
717 PriorHist->GetYaxis()->SetTitle(fmt::format(
"Events/{:.0f}",
ScalingFactor).c_str());
718 PriorHist->Draw(
"HIST");
719 PriorHist->SetLineWidth(2.);
720 PriorHist->SetLineColor(kBlack);
723 auto PrettyX =
PlotMan->style().prettifyKinematicName(PriorHist->GetXaxis()->GetTitle());
724 PriorHist->GetXaxis()->SetTitle(PrettyX.c_str());
725 for(
int ik = 0; ik < static_cast<int>(
sigmaArray.size()); ++ik)
730 for(
size_t nParam = 0; nParam < Projection.size(); nParam++) {
731 Projection[nParam][ik]->SetLineWidth(2.);
732 Projection[nParam][ik]->SetLineColor(ParamColour[nParam]);
733 Projection[nParam][ik]->SetLineStyle(kDotted);
734 Projection[nParam][ik]->GetYaxis()->SetTitle(fmt::format(
"Events/{:.0f}",
ScalingFactor).c_str());
736 max = std::max(max, Projection[nParam][ik]->GetMaximum());
738 PriorHist->SetMaximum(max*1.2);
740 PriorHist->Draw(
"HIST");
741 for(
size_t nParam = 0; nParam < Projection.size(); nParam++) {
742 Projection[nParam][ik]->Draw(
"HIST SAME");
744 auto leg =
MakeLegend(0.50, 0.55, 0.70, 0.75, 0.035);
745 leg->AddEntry(PriorHist,
"Prior",
"l");
746 for(
size_t nParam = 0; nParam < Projection.size(); nParam++) {
747 leg->AddEntry(Projection[nParam][ik].get(), Form(
"%s (%.0f#sigma)", ParamNames[nParam].c_str(),
sigmaArray[ik]),
"l");
751 canv->Print((outfilename).c_str());
758 auto ParamNames = GetFromManager<std::vector<std::string>>(Settings[
"ParamNames"], {});
759 auto SigColours = GetFromManager<std::vector<int>>(Settings[
"Coulour"], {});
761 if(ParamNames.size() == 0)
return;
763 if(ParamNames.size() != SigColours.size()){
769 auto canvas = std::make_unique<TCanvas>(
"canv",
"canv", 1080, 1080);
770 TFile *infile =
M3::Open(filename,
"OPEN", __FILE__, __LINE__);
771 TDirectoryFile *SigmaDir = infile->Get<TDirectoryFile>(
"SigmaVar");
773 std::string outfilename = filename.substr(0, filename.find(
".root"));
774 outfilename = outfilename +
"_Overlay1d.pdf";
775 gErrorIgnoreLevel = kWarning;
776 canvas->Print((outfilename+
"[").c_str());
778 TDirectory *dir =
nullptr;
785 std::vector<std::vector<std::unique_ptr<TH1D>>> Projection(ParamNames.size());
786 for(
size_t id = 0;
id < ParamNames.size();
id++)
794 TIter nextsub(dir->GetListOfKeys());
795 TKey *subsubkey =
nullptr;
798 while ((subsubkey =
static_cast<TKey*
>(nextsub())))
800 auto name = std::string(subsubkey->GetName());
801 auto classname = std::string(subsubkey->GetClassName());
803 const std::string ProjectionName =
"_1DProj" + std::to_string(iDim);
804 const bool IsProjection = (name.find(ProjectionName) != std::string::npos);
805 if (classname ==
"TH1D" && IsProjection)
808 Projection[id].emplace_back(
M3::Clone(SigmaDir->Get<TH1D>(name.c_str())));
814 PlotSigVar1D(Projection, canvas, Title, outfilename, ParamNames, SigColours);
815 gDirectory->cd(
"..");
819 canvas->Print((outfilename+
"]").c_str());
824 int main(
int argc,
char **argv)
829 MACH3LOG_ERROR(
"Need two inputs: output of sigma var and config");
832 std::string filename = argv[1];
833 std::string ConfigName = argv[2];
834 MACH3LOG_INFO(
"Running {} with {} {}", argv[0], filename, ConfigName);
839 YAML::Node settings = Config[
"PlotSigmaVariation"];
843 PlotMan =
new MaCh3Plotting::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]
constexpr const double ScalingFactor
int main(int argc, char **argv)
MaCh3Plotting::PlottingManager * PlotMan
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)
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.