7 #include "TObjString.h"
15 int FileROOTVersion = file->GetVersion();
16 int MainFileROOTVersion = FileROOTVersion;
20 while (MainFileROOTVersion >= 10)
21 MainFileROOTVersion /= 10;
23 std::string SystemROOTVersion = std::string(ROOT_RELEASE);
24 int MainSystemROOTVersion = SystemROOTVersion.at(0) -
'0';
26 if(MainFileROOTVersion != MainSystemROOTVersion)
28 MACH3LOG_ERROR(
"File was produced with: {} ROOT version", FileROOTVersion);
29 MACH3LOG_ERROR(
"Found: {} ROOT version in the system", SystemROOTVersion);
41 for(
int iOverflow = -1; iOverflow > -10; iOverflow--)
43 overflow += poly->GetBinContent(iOverflow);
55 for(
int i = 1; i < poly->GetNumberOfBins()+1; i++)
57 integral += poly->GetBinContent(i);
65 TH1D*
PolyProjectionX(TObject* poly,
const std::string& TempName,
const std::vector<double>& xbins,
const bool computeErrors) {
67 TH1D* hProjX =
new TH1D((TempName+
"_x").c_str(),(TempName+
"_x").c_str(),
int(xbins.size()-1), &xbins[0]);
70 std::vector<double> hProjX_Error(hProjX->GetXaxis()->GetNbins() + 1, 0.0);
71 double xlow, xup, frac = 0.;
74 for (
int i = 0; i < static_cast<TH2Poly*>(poly)->GetNumberOfBins(); i++)
77 TH2PolyBin* bin =
static_cast<TH2PolyBin*
>(
static_cast<TH2Poly*
>(poly)->GetBins()->At(i));
78 xlow = bin->GetXMin();
82 for(
int dx = 0; dx < int(xbins.size()); dx++)
84 if(xbins[dx+1] <= xlow || xbins[dx] >= xup)
88 else if(xbins[dx] <= xlow && xbins[dx+1] >= xup)
92 else if(xbins[dx] <= xlow && xbins[dx+1] <= xup)
94 frac = (xbins[dx+1]-xlow)/(xup-xlow);
96 else if(xbins[dx] >= xlow && xbins[dx+1] >= xup)
98 frac = (xup-xbins[dx])/(xup-xlow);
100 else if(xbins[dx] >= xlow && xbins[dx+1] <= xup)
102 frac = (xbins[dx+1]-xbins[dx])/(xup-xlow);
108 hProjX->SetBinContent(dx+1,hProjX->GetBinContent(dx+1)+frac*bin->GetContent());
114 const double Temp_Err = frac*
static_cast<TH2Poly*
>(poly)->GetBinError(i+1)*frac*
static_cast<TH2Poly*
>(poly)->GetBinError(i+1);
115 hProjX_Error[dx+1] += Temp_Err;
122 for (
int i = 1; i <= hProjX->GetXaxis()->GetNbins(); ++i)
124 const double Error = std::sqrt(hProjX_Error[i]);
125 hProjX->SetBinError(i, Error);
133 TH1D*
PolyProjectionY(TObject* poly,
const std::string& TempName,
const std::vector<double>& ybins,
const bool computeErrors) {
135 TH1D* hProjY =
new TH1D((TempName+
"_y").c_str(),(TempName+
"_y").c_str(),
int(ybins.size()-1),&ybins[0]);
137 std::vector<double> hProjY_Error(hProjY->GetXaxis()->GetNbins() + 1, 0.0);
138 double ylow, yup, frac = 0.;
141 for (
int i = 0; i < static_cast<TH2Poly*>(poly)->GetNumberOfBins(); i++)
144 TH2PolyBin* bin =
static_cast<TH2PolyBin*
>(
static_cast<TH2Poly*
>(poly)->GetBins()->At(i));
145 ylow = bin->GetYMin();
146 yup = bin->GetYMax();
149 for(
int dy = 0; dy < int(ybins.size()); dy++)
151 if(ybins[dy+1]<=ylow || ybins[dy] >= yup)
155 else if(ybins[dy] <= ylow && ybins[dy+1] >= yup)
159 else if(ybins[dy] <= ylow && ybins[dy+1] <= yup)
161 frac = (ybins[dy+1]-ylow)/(yup-ylow);
163 else if(ybins[dy] >= ylow && ybins[dy+1] >= yup)
165 frac = (yup-ybins[dy])/(yup-ylow);
167 else if(ybins[dy] >= ylow && ybins[dy+1] <= yup)
169 frac = (ybins[dy+1]-ybins[dy])/(yup-ylow);
175 hProjY->SetBinContent(dy+1,hProjY->GetBinContent(dy+1)+frac*bin->GetContent());
181 const double Temp_Err = frac*
static_cast<TH2Poly*
>(poly)->GetBinError(i+1)*frac*
static_cast<TH2Poly*
>(poly)->GetBinError(i+1);
182 hProjY_Error[dy+1] += Temp_Err;
189 for (
int i = 1; i <= hProjY->GetXaxis()->GetNbins(); ++i)
191 const double Error = std::sqrt(hProjY_Error[i]);
192 hProjY->SetBinError(i, Error);
202 TH2Poly* HistCopy =
static_cast<TH2Poly*
>(Histogram->Clone());
205 std::string title = std::string(HistCopy->GetName())+
"_norm";
206 HistCopy->SetNameTitle(title.c_str(), title.c_str());
216 for(
int j = 1; j < Histogram->GetNumberOfBins()+1; j++)
218 Histogram->SetBinContent(j, Histogram->GetBinContent(j)/Integral);
224 template<
class HistType>
225 HistType*
RatioHists(HistType *NumHist, HistType *DenomHist) {
227 HistType *NumCopy =
static_cast<HistType*
>(NumHist->Clone());
228 std::string title = std::string(DenomHist->GetName()) +
"_ratio";
229 NumCopy->SetNameTitle(title.c_str(), title.c_str());
230 NumCopy->Divide(DenomHist);
239 TH2Poly *NumCopy =
static_cast<TH2Poly*
>(NumHist->Clone());
240 std::string title = std::string(DenomHist->GetName()) +
"_ratio";
241 NumCopy->SetNameTitle(title.c_str(), title.c_str());
243 for(
int i = 1; i < NumCopy->GetNumberOfBins()+1; ++i) {
244 NumCopy->SetBinContent(i,NumHist->GetBinContent(i)/DenomHist->GetBinContent(i));
252 double xlow, xup, ylow, yup;
253 std::string HistTempName = poly->GetName();
257 TH2D *hist =
static_cast<TH2D*
>(h2dhist->Clone());
258 hist->SetNameTitle(HistTempName.c_str(), HistTempName.c_str());
260 for(
int ix = 0; ix < hist->GetNbinsX() + 2; ix++) {
261 for(
int iy = 0; iy < hist->GetNbinsY() + 2; iy++) {
262 hist->SetBinContent(ix, iy, 0);
266 for(
int i = 0; i< poly->GetNumberOfBins(); i++){
267 TH2PolyBin & polybin =
static_cast<TH2PolyBin &
>(*poly->GetBins()->At(i));
268 xlow = polybin.GetXMin();
269 xup = polybin.GetXMax();
270 ylow = polybin.GetYMin();
271 yup = polybin.GetYMax();
274 xbin = hist->GetXaxis()->FindBin(xlow+(xup-xlow)/2);
275 ybin = hist->GetYaxis()->FindBin(ylow+(yup-ylow)/2);
277 MACH3LOG_TRACE(
"Poly bin {}, xlow: {}, xup: {}, ylow: {}, yup: {}. Finding bin for ({}, {}). Found Bin ({}, {}) with content {}. But Poly content: {}",
278 i, xlow, xup, ylow, yup, (xlow + (xup - xlow) / 2), (ylow + (yup - ylow) / 2), xbin, ybin, polybin.GetContent(), poly->GetBinContent(i));
279 hist->SetBinContent(xbin, ybin, polybin.GetContent());
287 TAxis* xaxis = hist->GetXaxis();
289 TAxis* yaxis = hist->GetYaxis();
291 TString histname = hist->GetName();
293 TH2Poly* poly =
new TH2Poly();
294 poly->SetName(histname);
295 poly->SetTitle(histname);
298 poly->GetXaxis()->SetTitle(xaxis->GetTitle());
299 poly->GetYaxis()->SetTitle(yaxis->GetTitle());
301 double xmax, xmin, ymax, ymin;
302 for (
int iy = 1; iy <= yaxis->GetNbins(); iy++) {
303 ymax = yaxis->GetBinUpEdge(iy);
304 ymin = yaxis->GetBinLowEdge(iy);
305 for (
int ix = 1; ix <= xaxis->GetNbins(); ix++) {
306 xmax = xaxis->GetBinUpEdge(ix);
307 xmin = xaxis->GetBinLowEdge(ix);
308 double binofx[] = {xmin, xmax, xmax, xmin};
309 double binofy[] = {ymin, ymin, ymax, ymax};
310 poly->AddBin(4, binofx, binofy);
314 for (
int iy = 1; iy <= yaxis->GetNbins(); iy++) {
315 ymax = yaxis->GetBinUpEdge(iy);
316 ymin = yaxis->GetBinLowEdge(iy);
317 for (
int ix = 1; ix <= xaxis->GetNbins(); ix++) {
318 xmax = xaxis->GetBinUpEdge(ix);
319 xmin = xaxis->GetBinLowEdge(ix);
322 int bin = hist->GetBin(ix, iy);
323 double content = hist->GetBinContent(bin);
324 poly->SetBinContent(poly->FindBin((xmin + xmax) / 2, (ymin + ymax) / 2), content);
335 TH2Poly* HistCopy =
static_cast<TH2Poly*
>(Histogram->Clone());
336 double xlow, xup, ylow, yup, area;
338 for(
int i = 1; i < HistCopy->GetNumberOfBins()+1; i++)
340 TH2PolyBin* bin =
static_cast<TH2PolyBin*
>(Histogram->GetBins()->At(i - 1));
341 xlow = bin->GetXMin();
342 xup = bin->GetXMax();
343 ylow = bin->GetYMin();
344 yup = bin->GetYMax();
345 area = (xup-xlow)*(yup-ylow);
346 HistCopy->SetBinContent(i, Histogram->GetBinContent(i)/(area*scale));
356 double xlow, xup, ylow, yup, area;
358 for(
int i = 1; i < Histogram->GetNumberOfBins()+1; i++)
360 TH2PolyBin* bin =
static_cast<TH2PolyBin*
>(Histogram->GetBins()->At(i - 1));
361 xlow = bin->GetXMin();
362 xup = bin->GetXMax();
363 ylow = bin->GetYMin();
364 yup = bin->GetYMax();
365 area = (xup-xlow)*(yup-ylow);
366 integral += Histogram->GetBinContent(i)*area;
372 TH2Poly*
MakePolyHist(
const std::string& name,
const std::vector<double>& BinArray_x,
const std::vector<double>& BinArray_y) {
374 TH2Poly* poly =
new TH2Poly();
375 poly->SetName(name.c_str());
376 poly->SetTitle(name.c_str());
377 double xmax, xmin, ymax, ymin;
378 for(
unsigned int iy = 0; iy < BinArray_y.size()-1; iy++)
380 ymax = BinArray_y[iy+1];
381 ymin = BinArray_y[iy];
382 for(
unsigned int ix = 0; ix < BinArray_x.size()-1; ix++)
384 xmax = BinArray_x[ix+1];
385 xmin = BinArray_x[ix];
386 double binofx[] = {xmin, xmax, xmax, xmin};
387 double binofy[] = {ymin, ymin, ymax, ymax};
388 poly->AddBin(4,binofx,binofy);
398 TList *listOfFunctions = hist->GetListOfFunctions();
399 TF1 *fitter =
dynamic_cast<TF1*
>(listOfFunctions->FindObject(name.c_str()));
401 listOfFunctions->Remove(fitter);
410 FluctHist->Reset(
"");
411 FluctHist->Fill(0.0, 0.0);
413 for (
int i = 1; i <= PolyHist->GetXaxis()->GetNbins(); ++i)
416 const double MeanContent = PolyHist->GetBinContent(i);
420 FluctHist->SetBinContent(i,Random);
429 FluctHist->Reset(
"");
430 FluctHist->Fill(0.0, 0.0, 0.0);
432 for (
int i = 1; i < FluctHist->GetNumberOfBins()+1; ++i)
435 const double MeanContent = PolyHist->GetBinContent(i);
439 FluctHist->SetBinContent(i,Random);
448 FluctHist->Reset(
"");
449 FluctHist->Fill(0.0, 0.0, 0.0);
452 const int nBinsX = Hist->GetXaxis()->GetNbins();
453 const int nBinsY = Hist->GetYaxis()->GetNbins();
454 for (
int ix = 1; ix <= nBinsX; ++ix) {
455 for (
int iy = 1; iy <= nBinsY; ++iy) {
457 const double MeanContent = Hist->GetBinContent(ix, iy);
461 FluctHist->SetBinContent(ix, iy, Random);
471 FluctHist->Reset(
"");
472 FluctHist->Fill(0.0, 0.0);
474 const double evrate = PolyHist->Integral();
479 const double candidate = PolyHist->GetRandom();
480 FluctHist->Fill(candidate);
490 FluctHist->Fill(0.0, 0.0, 0.0);
492 const double evrate = PolyHist->Integral();
496 for (
int count = 0; count < num; ++count) {
497 PolyHist->GetRandom2(x, y);
498 FluctHist->Fill(x, y);
506 const int nbins = PolyHist->GetNumberOfBins();
509 std::vector<double> fIntegral(nbins+2);
513 for (
int i = 1; i < nbins+1; ++i)
516 const double content = PolyHist->GetBinContent(i);
517 fIntegral[i] += fIntegral[i - 1] + content;
519 for (Int_t bin = 1; bin < nbins+1; ++bin) fIntegral[bin] /= fIntegral[nbins];
520 fIntegral[nbins+1] = PolyHist->GetEntries();
523 int iBin = int(TMath::BinarySearch(nbins, fIntegral.data(), r1));
535 FluctHist->Reset(
"");
536 FluctHist->Fill(0.0, 0.0, 0.0);
544 FluctHist->SetBinContent(iBin, FluctHist->GetBinContent(iBin) + 1);
553 for (
int x = 0; x < violin->GetXaxis()->GetNbins(); ++x)
555 const int y = violin->GetYaxis()->FindBin(hist_1d->GetBinContent(x+1));
556 violin->SetBinContent(x+1, y, violin->GetBinContent(x+1, y)+1);
565 constexpr
double refractiveIndex = 1.334;
567 double momentumThreshold = mass/sqrt(refractiveIndex*refractiveIndex-1.);
568 return momentumThreshold;
573 double CalculateQ2(
double PLep,
double PUpd,
double EnuTrue,
double InitialQ2){
575 constexpr
double MLep = 0.10565837;
576 constexpr
double MLep2 = MLep * MLep;
579 double ELep = sqrt((MLep2)+(PLep*PLep));
581 double CosTh = (2*EnuTrue*ELep - MLep2 - InitialQ2)/(2*EnuTrue*PLep);
583 ELep = sqrt((MLep2)+(PUpd*PUpd));
586 double Q2Upd = -(MLep2) + 2.0*EnuTrue*(ELep - PUpd*CosTh);
588 return Q2Upd - InitialQ2;
593 double CalculateEnu(
double PLep,
double costh,
double Eb,
bool neutrino){
595 double mNeff = 0.93956536 - Eb / 1000.;
596 double mNoth = 0.93827203;
599 mNeff = 0.93827203 - Eb / 1000.;
603 constexpr
double mLep = 0.10565837;
604 constexpr
double mLep2 = mLep * mLep;
606 const double eLep = sqrt(PLep * PLep + mLep2);
607 double Enu = (2 * mNeff * eLep - mLep2 + mNoth * mNoth - mNeff * mNeff) /(2 * (mNeff - eLep + PLep * costh));
614 const std::string& name) {
616 const int nBinsX = Spectra->GetNbinsX();
618 std::vector<double> edges(nBinsX + 1);
619 for (
int i = 0; i < nBinsX; ++i) {
620 edges[i] = Spectra->GetXaxis()->GetBinLowEdge(i+1);
622 edges[nBinsX] = Spectra->GetXaxis()->GetBinUpEdge(nBinsX);
624 auto h1 = std::make_unique<TH1D>(name.c_str(), name.c_str(), nBinsX, edges.data());
625 h1->SetDirectory(
nullptr);
629 for (
int ix = 1; ix <= nBinsX; ++ix) {
631 std::unique_ptr<TH1D> slice(Spectra->ProjectionY(Form(
"_py_%d", ix), ix, ix));
632 slice->SetDirectory(
nullptr);
633 if (slice->GetEntries() == 0) {
634 h1->SetBinContent(ix, 0.0);
635 h1->SetBinError(ix, 0.0);
639 const double mean = slice->GetMean();
640 const double rms = slice->GetRMS();
642 h1->SetBinContent(ix, mean);
643 h1->SetBinError(ix, rms);
646 h1->GetXaxis()->SetTitle(Spectra->GetXaxis()->GetTitle());
647 h1->GetYaxis()->SetTitle(
"Events");
656 YAML::Node bin_range_specifier;
657 if (bin_range[
"linspace"]) {
658 bin_range_specifier = bin_range[
"linspace"];
659 }
else if (bin_range[
"logspace"]) {
661 bin_range_specifier = bin_range[
"logspace"];
663 std::stringstream ss;
665 MACH3LOG_ERROR(
"When parsing binning, expected bin range specifier with "
666 "key linspace or logspace, but found,\n{}",
671 auto nb = Get<int>(bin_range_specifier[
"nb"], __FILE__, __LINE__);
672 auto low = Get<double>(bin_range_specifier[
"low"], __FILE__, __LINE__);
673 auto up = Get<double>(bin_range_specifier[
"up"], __FILE__, __LINE__);
675 std::vector<double> edges(nb + 1, low);
683 double bw = (up - low) / nb;
684 for (
int i = 0; i < (nb - 1); ++i) {
685 edges[i + 1] = edges[i] + bw;
688 double llow = std::log10(low);
689 double lup = std::log10(up);
690 double lbw = (lup - llow) / nb;
691 for (
int i = 0; i < (nb - 1); ++i) {
692 edges[i + 1] = std::pow(10, llow + (i + 1) * lbw);
708 bool &found_range_specifier) {
710 if (bin_edges_node.IsMap()) {
711 found_range_specifier =
true;
714 std::vector<double> edges_builder;
715 if (!bin_edges_node.IsSequence()) {
716 std::stringstream ss;
717 ss << bin_edges_node;
719 "When parsing binning, expected to find a YAML map or sequence, "
724 for (
auto const &it : bin_edges_node) {
726 edges_builder.push_back(it.as<
double>());
727 }
else if (it.IsMap()) {
728 found_range_specifier =
true;
730 std::copy(range_edges.begin(), range_edges.end(),
731 std::back_inserter(edges_builder));
733 std::stringstream ss;
734 ss << bin_edges_node;
736 "When parsing binning, expected elements in outer sequence to all be "
737 "either scalars or maps, but found:\n{}",
744 std::vector<double> edges;
745 for (
size_t eb_it = 0; eb_it < edges_builder.size(); ++eb_it) {
747 if (edges_builder[eb_it] == edges.back()) {
749 }
else if (edges_builder[eb_it] < edges.back()) {
750 std::stringstream ss;
752 for(
auto const & e : edges_builder){
753 ss << fmt::format(
"{:.3g} ", e);
757 "When parsing binning, found edges that were not monotonically "
758 "increasing, problem bin at index: {}:\n{}",
763 edges.push_back(edges_builder[eb_it]);
771 TFile*
Open(
const std::string& Name,
const std::string& Type,
const std::string& File,
const int Line) {
773 TFile* OutFile =
new TFile(Name.c_str(), Type.c_str());
776 if (OutFile->IsZombie()) {
778 std::string lowerType = Type;
779 std::transform(lowerType.begin(), lowerType.end(), lowerType.begin(), ::tolower);
780 if (lowerType ==
"recreate") {
792 for (
int j = 0; j <= Sample_Hist->GetNbinsX(); ++j)
794 double num = Sample_Hist->GetBinContent(j);
795 double numErr = Sample_Hist->GetBinError(j);
796 double den = Sample_Hist->GetBinWidth(j);
798 double valueErr = 0.;
801 value = num/(den/scale);
802 valueErr = numErr/(den/scale);
803 Sample_Hist->SetBinContent(j,value);
804 Sample_Hist->SetBinError(j,valueErr);
810 void CheckBinningMatch(
const TH1D* Hist1,
const TH1D* Hist2,
const std::string& File,
const int Line) {
812 if (Hist1->GetNbinsX() != Hist2->GetNbinsX()) {
813 MACH3LOG_ERROR(
"Number of bins does not match for TH1D: {} vs {}", Hist1->GetNbinsX(), Hist2->GetNbinsX());
816 for (
int i = 1; i <= Hist1->GetNbinsX(); ++i) {
817 if (std::fabs(Hist1->GetXaxis()->GetBinLowEdge(i) - Hist2->GetXaxis()->GetBinLowEdge(i)) > 0.001 ||
818 std::fabs(Hist1->GetXaxis()->GetBinUpEdge(i) - Hist2->GetXaxis()->GetBinUpEdge(i)) > 0.001) {
826 void CheckBinningMatch(
const TH2D* Hist1,
const TH2D* Hist2,
const std::string& File,
const int Line) {
828 if (Hist1->GetNbinsX() != Hist2->GetNbinsX() || Hist1->GetNbinsY() != Hist2->GetNbinsY()) {
833 for (
int i = 1; i <= Hist1->GetNbinsX(); ++i) {
834 if (std::fabs(Hist1->GetXaxis()->GetBinLowEdge(i) - Hist2->GetXaxis()->GetBinLowEdge(i)) > 0.001 ||
835 std::fabs(Hist1->GetXaxis()->GetBinUpEdge(i) - Hist2->GetXaxis()->GetBinUpEdge(i)) > 0.001) {
840 for (
int j = 1; j <= Hist1->GetNbinsY(); ++j) {
841 if (std::fabs(Hist1->GetYaxis()->GetBinLowEdge(j) - Hist2->GetYaxis()->GetBinLowEdge(j)) > 0.001 ||
842 std::fabs(Hist1->GetYaxis()->GetBinUpEdge(j) - Hist2->GetYaxis()->GetBinUpEdge(j)) > 0.001) {
851 void CheckBinningMatch(TH2Poly* Hist1, TH2Poly* Hist2,
const std::string& File,
const int Line) {
853 int NBins1 = Hist1->GetNumberOfBins();
854 int NBins2 = Hist2->GetNumberOfBins();
855 if (NBins1 != NBins2) {
856 MACH3LOG_ERROR(
"Number of bins does not match for TH2Poly: {} vs {}", NBins1, NBins2);
859 for (
int j = 1; j <= NBins1; j++)
862 TH2PolyBin* polybin1 =
static_cast<TH2PolyBin*
>(Hist1->GetBins()->At(j - 1));
863 TH2PolyBin* polybin2 =
static_cast<TH2PolyBin*
>(Hist2->GetBins()->At(j - 1));
865 if( std::fabs(polybin2->GetXMin() - polybin1->GetXMin()) > 0.001 ||
866 std::fabs(polybin2->GetXMax() - polybin1->GetXMax()) > 0.001 ||
867 std::fabs(polybin2->GetYMin() - polybin1->GetYMin()) > 0.001 ||
868 std::fabs(polybin2->GetYMax() - polybin1->GetYMax()) > 0.001 )
871 MACH3LOG_ERROR(
"data x min {} x max {} y min {} y max {}", polybin2->GetXMin(), polybin2->GetXMax(), polybin2->GetYMin(), polybin2->GetYMax());
872 MACH3LOG_ERROR(
"mc x min {} x max {} y min {} y max {}", polybin1->GetXMin(), polybin1->GetXMax(), polybin1->GetYMin(), polybin1->GetYMax());
880 YAML::Node
PolyToYaml(TH2Poly* Hist,
const std::string& YamlName,
const std::string& File,
const int Line) {
887 YAML::Node bins(YAML::NodeType::Sequence);
888 bins.SetStyle(YAML::EmitterStyle::Flow);
889 const int NBins = Hist->GetNumberOfBins();
891 for (
int j = 1; j <= NBins; j++)
893 TH2PolyBin* polybin =
static_cast<TH2PolyBin*
>(Hist->GetBins()->At(j - 1));
895 double xmin = polybin->GetXMin();
896 double xmax = polybin->GetXMax();
897 double ymin = polybin->GetYMin();
898 double ymax = polybin->GetYMax();
900 YAML::Node xNode(YAML::NodeType::Sequence);
901 xNode.SetStyle(YAML::EmitterStyle::Flow);
902 xNode.push_back(xmin);
903 xNode.push_back(xmax);
905 YAML::Node yNode(YAML::NodeType::Sequence);
906 yNode.SetStyle(YAML::EmitterStyle::Flow);
907 yNode.push_back(ymin);
908 yNode.push_back(ymax);
910 YAML::Node bin(YAML::NodeType::Sequence);
911 bin.SetStyle(YAML::EmitterStyle::Flow);
912 bin.push_back(xNode);
913 bin.push_back(yNode);
919 result[YamlName] = bins;
#define _MaCh3_Safe_Include_Start_
KS: Avoiding warning checking for headers.
#define _MaCh3_Safe_Include_End_
int GetRandomPoly2(const TH2Poly *PolyHist)
KS: ROOT developers were too lazy do develop getRanom2 for TH2Poly, this implementation is based on l...
void MakeFluctuatedHistogramStandard(TH1D *FluctHist, TH1D *PolyHist)
Make Poisson fluctuation of TH1D hist using default fast method.
TH2D * ConvertTH2PolyToTH2D(TH2Poly *poly, TH2D *h2dhist)
KS: Convert TH2D to TH2Poly.
void NormaliseTH2Poly(TH2Poly *Histogram)
Helper to Normalise histograms.
double returnCherenkovThresholdMomentum(const int PDG)
DB Get the Cherenkov momentum threshold in MeV.
double OverflowIntegral(TH2Poly *poly)
WP: Helper function for calculating unbinned Integral of TH2Poly i.e including overflow.
TH1D * PolyProjectionX(TObject *poly, const std::string &TempName, const std::vector< double > &xbins, const bool computeErrors)
WP: Poly Projectors.
std::vector< double > BuildBinEdgesFromNode(YAML::Node const &bin_edges_node, bool &found_range_specifier)
Builds a single dimension's bin edges from YAML::Node.
void FastViolinFill(TH2D *violin, TH1D *hist_1d)
KS: Fill Violin histogram with entry from a toy.
TH2Poly * NormalisePoly(TH2Poly *Histogram)
WP: Helper to Normalise histograms.
HistType * RatioHists(HistType *NumHist, HistType *DenomHist)
Helper to make ratio histograms.
std::vector< double > BinRangeToBinEdges(YAML::Node const &bin_range)
Converts a range (linspace/logspace) to a std::vector<double>
TH2Poly * RatioPolys(TH2Poly *NumHist, TH2Poly *DenomHist)
Helper to make ratio of TH2Polys.
TH2Poly * PolyScaleWidth(TH2Poly *Histogram, double scale)
WP: Helper to scale th2poly analogous to th2d scale with option "width".
void RemoveFitter(TH1D *hist, const std::string &name)
KS: Remove fitted TF1 from hist to make comparison easier.
double CalculateEnu(double PLep, double costh, double Eb, bool neutrino)
Recalculate Enu after Eb shift. Takes in shifted lepton momentum, lepton angle, and binding energy ch...
double PolyIntegralWidth(TH2Poly *Histogram)
WP: Helper to calc integral of th2poly analogous to th2d integra; with option "width".
_MaCh3_Safe_Include_Start_ _MaCh3_Safe_Include_End_ void CheckTH2PolyFileVersion(TFile *file)
KS: ROOT changes something with binning when moving from ROOT 5 to ROOT 6. If you open ROOT5 produced...
double NoOverflowIntegral(TH2Poly *poly)
WP: Helper function for calculating binned Integral of TH2Poly i.e not including overflow.
TH2Poly * ConvertTH2DtoTH2Poly(TH2D *hist)
KS: Convert TH2Poly to TH2D.
TH2Poly * MakePolyHist(const std::string &name, const std::vector< double > &BinArray_x, const std::vector< double > &BinArray_y)
WP: Helper function to create TH2Poly histogram with uniform binning.
TH1D * PolyProjectionY(TObject *poly, const std::string &TempName, const std::vector< double > &ybins, const bool computeErrors)
WP: Poly Projectors.
std::unique_ptr< TH1D > MakeSummaryFromSpectra(const TH2D *Spectra, const std::string &name)
Build a 1D posterior-predictive summary from a violin spectrum.
double CalculateQ2(double PLep, double PUpd, double EnuTrue, double InitialQ2)
Recalculate Q^2 after Eb shift. Takes in shifted lepton momentum, lepton angle, and true neutrino ene...
void MakeFluctuatedHistogramAlternative(TH1D *FluctHist, TH1D *PolyHist)
Make Poisson fluctuation of TH1D hist using slow method which is only for cross-check.
Custom exception class used throughout MaCh3.
constexpr double GetMassFromPDG(const int PDG)
Return mass for given PDG.
double PoissonD(const double mean)
Generate a Poisson-distributed random number with the given mean.
double Uniform(const double min=0.0, const double max=1.0)
Generate a uniform random number in [min, max).
int Poisson(const double mean)
Generate a Poisson-distributed integer with the given mean.
Main namespace for MaCh3 software.
void CheckBinningMatch(const TH1D *Hist1, const TH1D *Hist2, const std::string &File, const int Line)
KS: Helper function check if data and MC binning matches.
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.
YAML::Node PolyToYaml(TH2Poly *Hist, const std::string &YamlName, const std::string &File, const int Line)
KS: Convert TH2Poly into yaml config accepted by MaCh3.