MaCh3  2.2.3
Reference Guide
Functions | Variables
PlotMCMCDiag.cpp File Reference

KS: This script is used to analyse output form DiagMCMC. More...

#include "Fitters/MCMCProcessor.h"
#include "Samples/HistogramUtils.h"
#include "THStack.h"
#include "TGraphAsymmErrors.h"
#include "TLegend.h"
#include <TSystem.h>
Include dependency graph for PlotMCMCDiag.cpp:

Go to the source code of this file.

Functions

double GetMinimumInRange (TH1D *hist, const double minRange, const double maxRange)
 KS: function which looks for minimum in given range. More...
 
bool IsHistogramAllOnes (TH1D *hist, double tolerance=0.001, int max_failures=100)
 HW: Check if histogram is flat within a given tolerance. More...
 
void MakePlot (TString fname1, TString flabel1, TString fname2, TString flabel2, TString fname3, TString flabel3, TString fname4, TString flabel4)
 
void PlotAutoCorr (TString fname1, TString flabel1, TString fname2, TString flabel2, TString fname3, TString flabel3, TString fname4, TString flabel4)
 
std::pair< std::unique_ptr< TGraph >, std::unique_ptr< TGraph > > CreateMinMaxBand (TH1D *hist, Color_t color)
 HW: Create a band of minimum and maximum values from a histogram. More...
 
std::unique_ptr< TGraphAsymmErrors > CalculateMinMaxBand (const std::vector< TH1D * > &histograms, Color_t color)
 
std::pair< std::unique_ptr< TH1D >, std::unique_ptr< TH1D > > CalculateMinMaxHistograms (const std::vector< TH1D * > &histograms)
 
void ProcessAutoCorrelationDirectory (TDirectoryFile *autocor_dir, std::unique_ptr< TH1D > &average_hist, int &parameter_count, std::vector< TH1D * > &histograms)
 
void ProcessDiagnosticFile (const TString &file_path, std::unique_ptr< TH1D > &average_hist, int &parameter_count, std::vector< TH1D * > &histograms)
 
std::unique_ptr< TH1D > AutocorrProcessInputs (const TString &input_file, std::vector< TH1D * > &histograms)
 
void CompareAverageAC (const std::vector< std::vector< TH1D * >> &histograms, const std::vector< std::unique_ptr< TH1D >> &averages, const std::vector< TString > &hist_labels, const TString &output_name, bool draw_min_max=true, bool draw_all=false, bool draw_errors=true)
 
void PlotAverageACMult (std::vector< TString > input_files, std::vector< TString > hist_labels, const TString &output_name, bool draw_min_max=true)
 
int main (int argc, char *argv[])
 

Variables

TString DUMMYFILE = "DummyFile"
 
TString DUMMYNAME = "DummyName"
 

Detailed Description

KS: This script is used to analyse output form DiagMCMC.

Warning
This script support comparing up to 4 files, there is easy way to expand it up to five or six,
Todo:
this need serious refactor
Author
Henry Wallace
Kamil Skwarczynski

Definition in file PlotMCMCDiag.cpp.

Function Documentation

◆ AutocorrProcessInputs()

std::unique_ptr<TH1D> AutocorrProcessInputs ( const TString &  input_file,
std::vector< TH1D * > &  histograms 
)

Definition at line 428 of file PlotMCMCDiag.cpp.

429 {
430 
431  std::unique_ptr<TH1D> average_hist = nullptr;
432  int parameter_count = 0;
433 
434  try
435  {
436  ProcessDiagnosticFile(input_file, average_hist, parameter_count, histograms);
437  }
438  catch (const std::exception &e)
439  {
440  MACH3LOG_ERROR("Error processing file {} : {}", input_file, e.what());
441  }
442 
443  if (average_hist && parameter_count > 0)
444  {
445  MACH3LOG_INFO("Processed {} parameters from {} files", parameter_count, input_file);
446  average_hist->Scale(1.0 / parameter_count);
447  }
448 
449  return average_hist;
450 }
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:27
#define MACH3LOG_INFO
Definition: MaCh3Logger.h:25
void ProcessDiagnosticFile(const TString &file_path, std::unique_ptr< TH1D > &average_hist, int &parameter_count, std::vector< TH1D * > &histograms)

◆ CalculateMinMaxBand()

std::unique_ptr<TGraphAsymmErrors> CalculateMinMaxBand ( const std::vector< TH1D * > &  histograms,
Color_t  color 
)

Definition at line 309 of file PlotMCMCDiag.cpp.

310 {
311  if (histograms.empty()) {
312  throw MaCh3Exception(__FILE__, __LINE__, "Empty histogram vector provided");
313  }
314 
315  int nBins = histograms[0]->GetNbinsX();
316  std::vector<double> x(nBins), ymin(nBins, 1e10), ymax(nBins, -1e10);
317 
318  for (int bin = 0; bin < nBins; bin++)
319  {
320  x[bin] = histograms[0]->GetBinCenter(bin + 1);
321 
322  for (const auto &hist : histograms)
323  {
324  double content = hist->GetBinContent(bin + 1);
325  ymin[bin] = std::min(ymin[bin], content);
326  ymax[bin] = std::max(ymax[bin], content);
327  }
328  }
329 
330  // Create a band using TGraphAsymmErrors for the shaded region
331  auto band = std::make_unique<TGraphAsymmErrors>(nBins);
332  for (int i = 0; i < nBins; ++i)
333  {
334  band->SetPoint(i, x[i], (ymax[i] + ymin[i]) / 2.0);
335  band->SetPointError(i, 0, 0, (ymax[i] - ymin[i]) / 2.0, (ymax[i] - ymin[i]) / 2.0);
336  }
337 
338  band->SetFillColorAlpha(color, 0.2f);
339  band->SetLineWidth(1);
340 
341  return band; // Return band and min graph (min graph can be used for legend)
342 }
Custom exception class for MaCh3 errors.

◆ CalculateMinMaxHistograms()

std::pair<std::unique_ptr<TH1D>, std::unique_ptr<TH1D> > CalculateMinMaxHistograms ( const std::vector< TH1D * > &  histograms)

Definition at line 344 of file PlotMCMCDiag.cpp.

345 {
346  if (histograms.empty())
347  {
348  throw MaCh3Exception(__FILE__, __LINE__, "Empty histogram vector provided");
349  }
350  auto min_hist = M3::Clone(histograms[0]);
351  auto max_hist = M3::Clone(histograms[0]);
352 
353  for (const auto &hist : histograms)
354  {
355  for (int bin = 1; bin <= min_hist->GetNbinsX(); ++bin)
356  {
357  double current_min = min_hist->GetBinContent(bin);
358  double current_max = max_hist->GetBinContent(bin);
359  double bin_content = hist->GetBinContent(bin);
360 
361  min_hist->SetBinContent(bin, std::min(current_min, bin_content));
362  max_hist->SetBinContent(bin, std::max(current_max, bin_content));
363  }
364  }
365 
366  return {std::move(min_hist), std::move(max_hist)};
367 }
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.

◆ CompareAverageAC()

void CompareAverageAC ( const std::vector< std::vector< TH1D * >> &  histograms,
const std::vector< std::unique_ptr< TH1D >> &  averages,
const std::vector< TString > &  hist_labels,
const TString &  output_name,
bool  draw_min_max = true,
bool  draw_all = false,
bool  draw_errors = true 
)

Definition at line 452 of file PlotMCMCDiag.cpp.

459 {
460  auto canvas = std::make_unique<TCanvas>("AverageAC", "Average Auto Correlation", 800, 600);
461  canvas->SetGrid();
462 
463  // Setup colour palette
464  constexpr Int_t nb = 255.0;
465  Double_t stops[8] = {0.0, 0.25, 0.5, 0.75};
466  Double_t red[8] = {0.83203125, 0.796875, 0.0, 0.9375};
467  Double_t green[8] = {0.3671875, 0.47265625, 0.4453125, 0.890625};
468  Double_t blue[8] = {0.0, 0.65234375, 0.6953125, 0.2578125};
469  TColor::CreateGradientColorTable(8, stops, red, green, blue, nb);
470 
471  auto leg = std::make_unique<TLegend>(0.5, 0.7, 0.9, 0.9);
472  leg->SetFillColorAlpha(kWhite, 0.7f);
473  if (draw_min_max)
474  {
475  for (size_t i = 0; i < histograms.size(); ++i)
476  {
477  auto colour = static_cast<Color_t>(TColor::GetColorPalette(static_cast<Int_t>(i * nb / histograms.size())));
478 
479  {
480  auto band = CalculateMinMaxBand(histograms[i], colour);
481  band->SetLineWidth(0);
482  band->SetTitle("Average Auto Correlation");
483  band->GetXaxis()->SetTitle("lag");
484  band->GetYaxis()->SetTitle("Autocorrelation Function");
485  if (i == 0) {
486  band->Draw("A3");
487  } else {
488  band->Draw("3 SAME");
489  }
490  }
491  }
492  }
493 
494  for (size_t i = 0; i < averages.size(); ++i)
495  {
496  auto colour = static_cast<Color_t>(TColor::GetColorPalette(static_cast<Int_t>(i * nb / histograms.size())));
497 
498  if (draw_errors)
499  {
500  auto error_hist = M3::Clone(averages[i].get());
501  error_hist->SetFillColorAlpha(colour, 0.3f);
502  error_hist->SetLineWidth(0);
503  error_hist->SetTitle("Average Auto Correlation");
504  error_hist->GetXaxis()->SetTitle("lag");
505  error_hist->GetYaxis()->SetTitle("Autocorrelation Function");
506  error_hist->Draw("E3 SAME");
507  }
508  if (draw_all)
509  {
510  for (const auto &hist : histograms[i])
511  {
512  hist->SetLineColorAlpha(colour, 0.05f);
513  hist->SetLineWidth(1);
514  hist->Draw("HIST SAME");
515  }
516  }
517  averages[i]->SetLineColor(colour);
518  averages[i]->SetLineWidth(2);
519  averages[i]->SetTitle("Average Auto Correlation");
520  averages[i]->GetXaxis()->SetTitle("lag");
521  averages[i]->GetYaxis()->SetTitle("Autocorrelation Function");
522  averages[i]->Draw("HIST SAME");
523 
524  TString int_str = TString::Format("Average integrated autocorrelation %.2f", averages[i]->Integral());
525  leg->AddEntry(averages[i].get(), hist_labels[i] + int_str, "l");
526  }
527 
528  if (averages.size() > 1)
529  {
530  leg->Draw();
531  }
532 
533  canvas->SaveAs(output_name + ".pdf");
534 }
std::unique_ptr< TGraphAsymmErrors > CalculateMinMaxBand(const std::vector< TH1D * > &histograms, Color_t color)

◆ CreateMinMaxBand()

std::pair<std::unique_ptr<TGraph>, std::unique_ptr<TGraph> > CreateMinMaxBand ( TH1D *  hist,
Color_t  color 
)

HW: Create a band of minimum and maximum values from a histogram.

Definition at line 286 of file PlotMCMCDiag.cpp.

287 {
288  int nBins = hist->GetNbinsX();
289  std::vector<double> x(nBins), ymin(nBins), ymax(nBins);
290 
291  for (int i = 0; i < nBins; ++i)
292  {
293  x[i] = hist->GetBinCenter(i + 1);
294  ymin[i] = hist->GetBinContent(i + 1);
295  ymax[i] = hist->GetBinContent(i + 1);
296  }
297 
298  auto minGraph = std::make_unique<TGraph>(nBins, x.data(), ymin.data());
299  auto maxGraph = std::make_unique<TGraph>(nBins, x.data(), ymax.data());
300 
301  minGraph->SetLineColor(color);
302  maxGraph->SetLineColor(color);
303  minGraph->SetFillColorAlpha(color, 0.3f);
304  maxGraph->SetFillColorAlpha(color, 0.3f);
305 
306  return {std::move(minGraph), std::move(maxGraph)};
307 }

◆ GetMinimumInRange()

double GetMinimumInRange ( TH1D *  hist,
const double  minRange,
const double  maxRange 
)

KS: function which looks for minimum in given range.

Definition at line 21 of file PlotMCMCDiag.cpp.

22 {
23  double MinVale = 1234567890.;
24  TAxis *xaxis = hist->GetXaxis();
25  for (int x = 1; x <= hist->GetNbinsX(); x++)
26  {
27  if (xaxis->GetBinLowEdge(x) > minRange && xaxis->GetBinUpEdge(x) < maxRange)
28  {
29  if (MinVale > hist->GetBinContent(x))
30  MinVale = hist->GetBinContent(x);
31  }
32  }
33  return MinVale;
34 }

◆ IsHistogramAllOnes()

bool IsHistogramAllOnes ( TH1D *  hist,
double  tolerance = 0.001,
int  max_failures = 100 
)

HW: Check if histogram is flat within a given tolerance.

Definition at line 38 of file PlotMCMCDiag.cpp.

39 {
40  int failure_count = 0;
41 
42  for (int bin = 2; bin <= hist->GetNbinsX(); ++bin)
43  {
44  if (std::fabs(hist->GetBinContent(bin) - 1.0) > tolerance)
45  {
46  if (++failure_count > max_failures)
47  {
48  return false;
49  }
50  }
51  }
52  return true;
53 }

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 566 of file PlotMCMCDiag.cpp.

567 {
569  if (argc != 3 && argc != 5 && argc != 7 && argc != 9)
570  {
571  MACH3LOG_ERROR("Wrong number of arguments ({}) provided", argc);
572  MACH3LOG_ERROR("How to use: {} DiagMCMC_Output.root Plot Name", argv[0]);
573  MACH3LOG_ERROR("Up to 4 files");
574  throw MaCh3Exception(__FILE__, __LINE__);
575  }
576 
577  if (argc == 3)
578  {
581  PlotAverageACMult({argv[1]}, {argv[2]}, Form("%s_Average_Auto_Corr", argv[2]), true);
582  }
583  else if (argc == 5)
584  {
585  MakePlot(argv[1], argv[2], argv[3], argv[4], DUMMYFILE, DUMMYNAME, DUMMYFILE, DUMMYNAME);
586  PlotAutoCorr(argv[1], argv[2], argv[3], argv[4], DUMMYFILE, DUMMYNAME, DUMMYFILE, DUMMYNAME);
587  PlotAverageACMult({argv[1], argv[3]}, {argv[2], argv[4]}, Form("%s_Average_Auto_Corr", argv[2]), true);
588  }
589  else if (argc == 7)
590  {
591  MakePlot(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], DUMMYFILE, DUMMYNAME);
592  PlotAutoCorr(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], DUMMYFILE, DUMMYNAME);
593  PlotAverageACMult({argv[1], argv[3], argv[5]}, {argv[2], argv[4], argv[6]}, Form("%s_Average_Auto_Corr", argv[2]), true);
594  }
595  else if (argc == 9)
596  {
597  MakePlot(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]);
598  PlotAutoCorr(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]);
599  PlotAverageACMult({argv[1], argv[3], argv[5], argv[7]}, {argv[2], argv[4], argv[6], argv[8]}, Form("%s_Average_Auto_Corr", argv[2]), true);
600  }
601  return 0;
602 }
void SetMaCh3LoggerFormat()
Set messaging format of the logger.
Definition: MaCh3Logger.h:51
void MakePlot(TString fname1, TString flabel1, TString fname2, TString flabel2, TString fname3, TString flabel3, TString fname4, TString flabel4)
TString DUMMYNAME
void PlotAverageACMult(std::vector< TString > input_files, std::vector< TString > hist_labels, const TString &output_name, bool draw_min_max=true)
void PlotAutoCorr(TString fname1, TString flabel1, TString fname2, TString flabel2, TString fname3, TString flabel3, TString fname4, TString flabel4)
TString DUMMYFILE

◆ MakePlot()

void MakePlot ( TString  fname1,
TString  flabel1,
TString  fname2,
TString  flabel2,
TString  fname3,
TString  flabel3,
TString  fname4,
TString  flabel4 
)

Definition at line 55 of file PlotMCMCDiag.cpp.

56 {
57  auto c1 = std::make_unique<TCanvas>("c1", " ", 0, 0, 800, 630);
58  gStyle->SetOptStat(0); // Set 0 to disable statistic box
59  // To avoid TCanvas::Print> messages
60  gErrorIgnoreLevel = kWarning;
61 
62  TKey *key;
63  TFile *infile = M3::Open(fname1.Data(), "UPDATE", __FILE__, __LINE__);
64 
65  bool add_legend = false;
66  TFile *infile2 = nullptr;
67  if (fname2 != DUMMYFILE)
68  {
69  infile2 = M3::Open(fname2.Data(), "UPDATE", __FILE__, __LINE__);
70  add_legend = true;
71  }
72  TFile *infile3 = nullptr;
73  if (fname3 != DUMMYFILE)
74  {
75  infile3 = M3::Open(fname3.Data(), "UPDATE", __FILE__, __LINE__);
76  add_legend = true;
77  }
78  TFile *infile4 = nullptr;
79  if (fname4 != DUMMYFILE)
80  {
81  infile4 = M3::Open(fname4.Data(), "UPDATE", __FILE__, __LINE__);
82  add_legend = true;
83  }
84 
85  TIter next(infile->GetListOfKeys());
86  while ((key = static_cast<TKey *>(next())))
87  {
88  std::string dirname = std::string(key->GetName());
89  if (std::string(key->GetClassName()) != "TDirectoryFile")
90  continue;
91  // KS: Script will work with LogL and Batched_means, you can comment it if you are interested in it
92  if ((dirname == "LogL") || (dirname == "Batched_means") || (dirname == "PowerSpectrum"))
93  continue;
94  // KS: Trace wo longer chains is super big, the way to avoid is to plot as png but I don't like png,
95  // keep possibility to skip it
96  // if( (dirname == "Trace") ) continue;
97  infile->cd(dirname.c_str());
98  TIter nextsub(gDirectory->GetListOfKeys());
99  c1->Print(Form("%s_%s.pdf[", flabel1.Data(), dirname.c_str()), "pdf");
100  TKey *subkey;
101  while ((subkey = static_cast<TKey *>(nextsub())))
102  {
103  auto leg = std::make_unique<TLegend>(0.7, 0.7, 0.9, 0.9);
104  leg->SetFillColorAlpha(kWhite, 0.7f);
105  std::string name = std::string(subkey->GetName());
106  name = dirname + "/" + name;
107  MACH3LOG_INFO("{}", name);
108  if (std::string(subkey->GetClassName()) != "TH1D") {
109  continue;
110  } else {
111  MACH3LOG_WARN("continuing along my way for {}", dirname);
112  }
113 
114  std::unique_ptr<TH1D> blarb[4];
115  MACH3LOG_INFO("Looking for {} from file {}", name.c_str(), fname1.Data());
116  blarb[0] = M3::Clone(static_cast<TH1D *>(infile->Get(name.c_str())));
117  // KS: Some fixe params can go crazy
118  if (std::isnan(blarb[0]->GetBinContent(1)))
119  continue;
120 
121  RemoveFitter(blarb[0].get(), "Fitter");
122  blarb[0]->SetLineStyle(kSolid);
123  blarb[0]->SetLineColor(kRed);
124  blarb[0]->Draw();
125 
126  leg->AddEntry(blarb[0].get(), flabel1.Data(), "l");
127 
128  if (dirname == "AccProb")
129  blarb[0]->GetYaxis()->SetRangeUser(0, 1.0);
130  if (name == "AccProb/AcceptanceProbability")
131  continue;
132  if (infile2 != nullptr)
133  {
134  blarb[1] = M3::Clone(static_cast<TH1D *>(infile2->Get(name.c_str())));
135  RemoveFitter(blarb[1].get(), "Fitter");
136  blarb[1]->SetLineStyle(kDashed);
137  blarb[1]->SetLineColor(kBlue);
138  blarb[1]->Draw("same");
139  leg->AddEntry(blarb[1].get(), flabel2.Data(), "l");
140  }
141  if (infile3 != nullptr)
142  {
143  blarb[2] = M3::Clone(static_cast<TH1D *>(infile3->Get(name.c_str())));
144  RemoveFitter(blarb[2].get(), "Fitter");
145  blarb[2]->SetLineStyle(kDotted);
146  blarb[2]->SetLineColor(kGreen);
147  blarb[2]->Draw("same");
148  leg->AddEntry(blarb[2].get(), flabel3.Data(), "l");
149  }
150  if (infile4 != nullptr)
151  {
152  blarb[3] = M3::Clone(static_cast<TH1D *>(infile4->Get(name.c_str())));
153  RemoveFitter(blarb[3].get(), "Fitter");
154  blarb[3]->SetLineStyle(kDashDotted);
155  blarb[3]->SetLineColor(kOrange);
156  blarb[3]->Draw("same");
157  leg->AddEntry(blarb[3].get(), flabel4.Data(), "l");
158  }
159  if (add_legend)
160  {
161  leg->Draw();
162  }
163  c1->Print(Form("%s_%s.pdf", flabel1.Data(), dirname.c_str()), "pdf");
164  }
165  gDirectory->cd("..");
166  c1->Print(Form("%s_%s.pdf]", flabel1.Data(), dirname.c_str()), "pdf");
167  }
168 
169  infile->Close();
170  if (infile2 != nullptr)
171  infile2->Close();
172  if (infile3 != nullptr)
173  infile3->Close();
174  if (infile4 != nullptr)
175  infile4->Close();
176 }
void RemoveFitter(TH1D *hist, const std::string &name)
KS: Remove fitted TF1 from hist to make comparison easier.
#define MACH3LOG_WARN
Definition: MaCh3Logger.h:26
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.

◆ PlotAutoCorr()

void PlotAutoCorr ( TString  fname1,
TString  flabel1,
TString  fname2,
TString  flabel2,
TString  fname3,
TString  flabel3,
TString  fname4,
TString  flabel4 
)

Definition at line 178 of file PlotMCMCDiag.cpp.

179 {
180  TString fname[4];
181  fname[0] = fname1;
182  fname[1] = fname2;
183  fname[2] = fname3;
184  fname[3] = fname4;
185  // Color_t PlotColor[4]={kRed, kBlue, kGreen, kOrange};
186  std::vector<TString> flabel = {flabel1, flabel2, flabel3, flabel4};
187 
188  TFile *infile[4];
189  infile[0] = TFile::Open(fname[0].Data());
190  // KS" We need to check number of files to loop over in very lazy way
191  int Nfiles = 1;
192 
193  if (fname[1] != DUMMYFILE)
194  {
195  infile[1] = TFile::Open(fname[1].Data());
196  Nfiles++;
197  }
198  if (fname[2] != DUMMYFILE)
199  {
200  infile[2] = TFile::Open(fname[2].Data());
201  Nfiles++;
202  }
203  if (fname[3] != DUMMYFILE)
204  {
205  infile[3] = TFile::Open(fname[3].Data());
206  Nfiles++;
207  }
208 
209  auto c1 = std::make_unique<TCanvas>("c1", " ", 0, 0, 800, 630);
210  gStyle->SetOptStat(0); // Set 0 to disable statistic box
211  // To avoid TCanvas::Print> messages
212  gErrorIgnoreLevel = kWarning;
213 
214  c1->Print("Auto_Corr_PerFile.pdf[", "pdf");
215  for (int ik = 0; ik < Nfiles; ik++)
216  {
217  TIter next(infile[ik]->GetListOfKeys());
218 
219  TKey *key;
220  // KS: Keep track of histos to delete them
221  std::vector<std::unique_ptr<TH1D>> histos;
222  while ((key = static_cast<TKey *>(next())))
223  {
224  std::string dirname = std::string(key->GetName());
225 
226  // KS: Script We are only interested in auto corr
227  if ((dirname != "Auto_corr"))
228  continue;
229 
230  infile[ik]->cd(dirname.c_str());
231  TIter nextsub(gDirectory->GetListOfKeys());
232 
233  TKey *subkey;
234  bool FirstTime = true;
235  while ((subkey = static_cast<TKey *>(nextsub())))
236  {
237  std::string name = std::string(subkey->GetName());
238  name = dirname + "/" + name;
239 
240  if (std::string(subkey->GetClassName()) != "TH1D")
241  continue;
242  MACH3LOG_DEBUG("{}", name.c_str());
243  histos.push_back(M3::Clone(static_cast<TH1D *>(infile[ik]->Get(name.c_str()))));
244  // KS: Some fixe pramas can go crazy
245  if (std::isnan(histos.back()->GetBinContent(1)))
246  continue;
247  // KS: This is unfortunately hardcoded, need to find better way to write this
248  // histos.back()->GetListOfFunctions()->ls();
249  RemoveFitter(histos.back().get(), "Fitter");
250  double MinValue = GetMinimumInRange(histos.back().get(), 0, 24000);
251 
252  if (MinValue >= 0.80)
253  histos.back()->SetLineColor(kRed);
254  else if (MinValue >= 0.40 && MinValue < 0.80)
255  histos.back()->SetLineColor(kOrange);
256  else if (MinValue > 0.20 && MinValue < 0.40)
257  histos.back()->SetLineColor(kYellow);
258  else if (MinValue <= 0.20)
259  histos.back()->SetLineColor(kGreen);
260  histos.back()->GetXaxis()->UnZoom();
261 
262  if (FirstTime)
263  histos.back()->SetTitle(Form("Auto_Corr_%s.pdf", fname[ik].Data()));
264 
265  histos.back()->SetLineStyle(kDashed);
266 
267  if (FirstTime)
268  histos.back()->Draw();
269 
270  TString integral = Form("Integral: %.2f", histos.back()->Integral());
271 
272  if (!FirstTime)
273  histos.back()->Draw("same");
274  FirstTime = false;
275  }
276  gDirectory->cd("..");
277  }
278  c1->Print("Auto_Corr_PerFile.pdf", "pdf");
279  }
280  c1->Print("Auto_Corr_PerFile.pdf]", "pdf");
281 }
#define MACH3LOG_DEBUG
Definition: MaCh3Logger.h:24
double GetMinimumInRange(TH1D *hist, const double minRange, const double maxRange)
KS: function which looks for minimum in given range.
Type Get(const YAML::Node &node, const std::string File, const int Line)
Get content of config file.
Definition: YamlHelper.h:266

◆ PlotAverageACMult()

void PlotAverageACMult ( std::vector< TString >  input_files,
std::vector< TString >  hist_labels,
const TString &  output_name,
bool  draw_min_max = true 
)

Definition at line 536 of file PlotMCMCDiag.cpp.

542 {
543  // Process first folder
544  std::vector<std::vector<TH1D *>> histograms;
545  std::vector<std::unique_ptr<TH1D>> averages;
546 
547  for (int i = 0; i < static_cast<int>(input_files.size()); i++)
548  {
549  TString folder = input_files[i];
550  MACH3LOG_INFO("Folder : {}", folder);
551 
552  if (folder.IsNull() || folder == DUMMYFILE)
553  {
554  MACH3LOG_WARN("Skipping empty or dummy folder: {}", folder.Data());
555  continue;
556  }
557 
558  std::vector<TH1D *> histograms_i;
559  averages.push_back((AutocorrProcessInputs(folder, histograms_i)));
560  histograms.push_back(histograms_i);
561  }
562 
563  CompareAverageAC(histograms, averages, hist_labels, output_name, draw_min_max); // draw_all, draw_errors);
564 }
void CompareAverageAC(const std::vector< std::vector< TH1D * >> &histograms, const std::vector< std::unique_ptr< TH1D >> &averages, const std::vector< TString > &hist_labels, const TString &output_name, bool draw_min_max=true, bool draw_all=false, bool draw_errors=true)
std::unique_ptr< TH1D > AutocorrProcessInputs(const TString &input_file, std::vector< TH1D * > &histograms)

◆ ProcessAutoCorrelationDirectory()

void ProcessAutoCorrelationDirectory ( TDirectoryFile *  autocor_dir,
std::unique_ptr< TH1D > &  average_hist,
int &  parameter_count,
std::vector< TH1D * > &  histograms 
)

Definition at line 370 of file PlotMCMCDiag.cpp.

374 {
375  TIter next(autocor_dir->GetListOfKeys());
376  TKey *key;
377 
378  while ((key = dynamic_cast<TKey *>(next())))
379  {
380  TH1D *current_hist = nullptr;
381  autocor_dir->GetObject(key->GetName(), current_hist);
382 
383  if (!current_hist ||
384  current_hist->GetMaximum() <= 0 ||
385  IsHistogramAllOnes(current_hist))
386  {
387  continue;
388  }
389 
390  current_hist->SetDirectory(nullptr); // Detach from file
391  histograms.push_back(current_hist);
392 
393  if (!average_hist)
394  {
395  average_hist = M3::Clone(current_hist);
396  }
397  else
398  {
399  average_hist->Add(current_hist);
400  }
401  parameter_count++;
402  }
403 }
bool IsHistogramAllOnes(TH1D *hist, double tolerance=0.001, int max_failures=100)
HW: Check if histogram is flat within a given tolerance.

◆ ProcessDiagnosticFile()

void ProcessDiagnosticFile ( const TString &  file_path,
std::unique_ptr< TH1D > &  average_hist,
int &  parameter_count,
std::vector< TH1D * > &  histograms 
)

Definition at line 405 of file PlotMCMCDiag.cpp.

409 {
410  std::unique_ptr<TFile> input_file(TFile::Open(file_path));
411  if (!input_file || input_file->IsZombie())
412  {
413  throw MaCh3Exception(__FILE__, __LINE__, "Could not open file: " + std::string(file_path.Data()));
414  }
415 
416  TDirectoryFile *autocor_dir = nullptr;
417  input_file->GetObject("Auto_corr", autocor_dir);
418 
419  if (!autocor_dir)
420  {
421  throw MaCh3Exception(__FILE__, __LINE__,
422  "Auto_corr directory not found in file: " + std::string(file_path.Data()));
423  }
424 
425  ProcessAutoCorrelationDirectory(autocor_dir, average_hist, parameter_count, histograms);
426 }
void ProcessAutoCorrelationDirectory(TDirectoryFile *autocor_dir, std::unique_ptr< TH1D > &average_hist, int &parameter_count, std::vector< TH1D * > &histograms)

Variable Documentation

◆ DUMMYFILE

TString DUMMYFILE = "DummyFile"

Definition at line 16 of file PlotMCMCDiag.cpp.

◆ DUMMYNAME

TString DUMMYNAME = "DummyName"

Definition at line 17 of file PlotMCMCDiag.cpp.