MaCh3  2.4.2
Reference Guide
Functions
FitterBase.cpp File Reference
#include "FitterBase.h"
#include "Samples/SampleHandlerFD.h"
#include "TRandom.h"
#include "TStopwatch.h"
#include "TTree.h"
#include "TGraphAsymmErrors.h"
Include dependency graph for FitterBase.cpp:

Go to the source code of this file.

Functions

void WriteHistograms (TH1 *hist, const std::string &baseName)
 Helper to write histograms. More...
 
void WriteHistogramsByMode (SampleHandlerBase *sample, const std::string &suffix, const bool by_mode, const bool by_channel, const std::vector< TDirectory * > &SampleDir)
 Generic histogram writer - should make main code more palatable. More...
 

Function Documentation

◆ WriteHistograms()

void WriteHistograms ( TH1 *  hist,
const std::string &  baseName 
)

Helper to write histograms.

Definition at line 1307 of file FitterBase.cpp.

1307  {
1308 // *************************
1309  if (!hist) return;
1310  hist->SetTitle(baseName.c_str());
1311  // Get the class name of the histogram
1312  TString className = hist->ClassName();
1313 
1314  // Set the appropriate axis title based on the histogram type
1315  if (className.Contains("TH1")) {
1316  hist->GetYaxis()->SetTitle("Events");
1317  } else if (className.Contains("TH2")) {
1318  hist->GetZaxis()->SetTitle("Events");
1319  }
1320  hist->SetDirectory(nullptr);
1321  hist->Write(baseName.c_str());
1322 }

◆ WriteHistogramsByMode()

void WriteHistogramsByMode ( SampleHandlerBase sample,
const std::string &  suffix,
const bool  by_mode,
const bool  by_channel,
const std::vector< TDirectory * > &  SampleDir 
)

Generic histogram writer - should make main code more palatable.

Definition at line 1326 of file FitterBase.cpp.

1330  {
1331 // *************************
1332  MaCh3Modes *modes = sample->GetMaCh3Modes();
1333  for (int iSample = 0; iSample < sample->GetNsamples(); ++iSample) {
1334  SampleDir[iSample]->cd();
1335  const std::string sampleName = sample->GetSampleTitle(iSample);
1336  for(int iDim1 = 0; iDim1 < sample->GetNDim(iSample); iDim1++) {
1337  std::string ProjectionName = sample->GetKinVarName(iSample, iDim1);
1338  std::string ProjectionSuffix = "_1DProj" + std::to_string(iDim1);
1339 
1340  // Probably a better way of handling this logic
1341  if (by_mode) {
1342  for (int iMode = 0; iMode < modes->GetNModes(); ++iMode) {
1343  auto modeHist = sample->Get1DVarHistByModeAndChannel(iSample, ProjectionName, iMode);
1344  WriteHistograms(modeHist, sampleName + "_" + modes->GetMaCh3ModeName(iMode) + ProjectionSuffix + suffix);
1345  delete modeHist;
1346  }
1347  }
1348 
1349  if (by_channel) {
1350  for (int iChan = 0; iChan < sample->GetNOscChannels(iSample); ++iChan) {
1351  auto chanHist = sample->Get1DVarHistByModeAndChannel(iSample, ProjectionName, -1, iChan); // -1 skips over mode plotting
1352  WriteHistograms(chanHist, sampleName + "_" + sample->GetFlavourName(iSample, iChan) + ProjectionSuffix + suffix);
1353  delete chanHist;
1354  }
1355  }
1356 
1357  if (by_mode && by_channel) {
1358  for (int iMode = 0; iMode < modes->GetNModes(); ++iMode) {
1359  for (int iChan = 0; iChan < sample->GetNOscChannels(iSample); ++iChan) {
1360  auto hist = sample->Get1DVarHistByModeAndChannel(iSample, ProjectionName, iMode, iChan);
1361  WriteHistograms(hist, sampleName + "_" + modes->GetMaCh3ModeName(iMode) + "_" + sample->GetFlavourName(iSample, iChan) + ProjectionSuffix + suffix);
1362  delete hist;
1363  }
1364  }
1365  }
1366 
1367  if (!by_mode && !by_channel) {
1368  auto hist = sample->Get1DVarHist(iSample, ProjectionName);
1369  WriteHistograms(hist, sampleName + ProjectionSuffix + suffix);
1370  delete hist;
1371  // Only for 2D and Beyond
1372  for (int iDim2 = iDim1 + 1; iDim2 < sample->GetNDim(iSample); ++iDim2) {
1373  // Get the names for the two dimensions
1374  std::string XVarName = sample->GetKinVarName(iSample, iDim1);
1375  std::string YVarName = sample->GetKinVarName(iSample, iDim2);
1376 
1377  // Get the 2D histogram for this pair
1378  auto hist2D = sample->Get2DVarHist(iSample, XVarName, YVarName);
1379 
1380  // Write the histogram
1381  std::string suffix2D = "_2DProj_" + std::to_string(iDim1) + "_vs_" + std::to_string(iDim2) + suffix;
1382  WriteHistograms(hist2D, sampleName + suffix2D);
1383 
1384  // Clean up
1385  delete hist2D;
1386  }
1387  }
1388  }
1389  }
1390 }
void WriteHistograms(TH1 *hist, const std::string &baseName)
Helper to write histograms.
KS: Class describing MaCh3 modes used in the analysis, it is being initialised from config.
Definition: MaCh3Modes.h:135
int GetNModes() const
KS: Get number of modes, keep in mind actual number is +1 greater due to unknown category.
Definition: MaCh3Modes.h:148
std::string GetMaCh3ModeName(const int Index) const
KS: Get normal name of mode, if mode not known you will get UNKNOWN_BAD.
Definition: MaCh3Modes.cpp:156
virtual std::string GetKinVarName(const int iSample, const int Dimension) const =0
Return Kinematic Variable name for specified sample and dimension for example "Reconstructed_Neutrino...
MaCh3Modes * GetMaCh3Modes() const
Return pointer to MaCh3 modes.
virtual std::string GetFlavourName(const int iSample, const int iChannel) const =0
virtual TH2 * Get2DVarHist(const int iSample, const std::string &ProjectionVarX, const std::string &ProjectionVarY, const std::vector< KinematicCut > &EventSelectionVec={}, int WeightStyle=0, TAxis *AxisX=nullptr, TAxis *AxisY=nullptr, const std::vector< KinematicCut > &SubEventSelectionVec={})=0
virtual TH1 * Get1DVarHistByModeAndChannel(const int iSample, const std::string &ProjectionVar_Str, int kModeToFill=-1, int kChannelToFill=-1, int WeightStyle=0, TAxis *Axis=nullptr)=0
virtual TH1 * Get1DVarHist(const int iSample, const std::string &ProjectionVar, const std::vector< KinematicCut > &EventSelectionVec={}, int WeightStyle=0, TAxis *Axis=nullptr, const std::vector< KinematicCut > &SubEventSelectionVec={})=0
virtual int GetNOscChannels(const int iSample) const =0
virtual M3::int_t GetNsamples()
virtual std::string GetSampleTitle(const int Sample) const =0
virtual int GetNDim(const int Sample) const =0
DB Function to differentiate 1D or 2D binning.