MaCh3  2.5.0
Reference Guide
Functions
FitterBase.cpp File Reference
#include "FitterBase.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 (SampleHandlerInterface *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 1315 of file FitterBase.cpp.

1315  {
1316 // *************************
1317  if (!hist) return;
1318  hist->SetTitle(baseName.c_str());
1319  // Get the class name of the histogram
1320  TString className = hist->ClassName();
1321 
1322  // Set the appropriate axis title based on the histogram type
1323  if (className.Contains("TH1")) {
1324  hist->GetYaxis()->SetTitle("Events");
1325  } else if (className.Contains("TH2")) {
1326  hist->GetZaxis()->SetTitle("Events");
1327  }
1328  hist->Write(baseName.c_str());
1329 }

◆ WriteHistogramsByMode()

void WriteHistogramsByMode ( SampleHandlerInterface 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 1333 of file FitterBase.cpp.

1337  {
1338 // *************************
1339  MaCh3Modes *modes = sample->GetMaCh3Modes();
1340  for (int iSample = 0; iSample < sample->GetNSamples(); ++iSample) {
1341  SampleDir[iSample]->cd();
1342  const std::string sampleName = sample->GetSampleTitle(iSample);
1343  for(int iDim1 = 0; iDim1 < sample->GetNDim(iSample); iDim1++) {
1344  std::string ProjectionName = sample->GetKinVarName(iSample, iDim1);
1345  std::string ProjectionSuffix = "_1DProj" + std::to_string(iDim1);
1346 
1347  // Probably a better way of handling this logic
1348  if (by_mode) {
1349  for (int iMode = 0; iMode < modes->GetNModes(); ++iMode) {
1350  auto modeHist = sample->Get1DVarHistByModeAndChannel(iSample, ProjectionName, iMode);
1351  WriteHistograms(modeHist.get(), sampleName + "_" + modes->GetMaCh3ModeName(iMode) + ProjectionSuffix + suffix);
1352  }
1353  }
1354 
1355  if (by_channel) {
1356  for (int iChan = 0; iChan < sample->GetNOscChannels(iSample); ++iChan) {
1357  auto chanHist = sample->Get1DVarHistByModeAndChannel(iSample, ProjectionName, -1, iChan); // -1 skips over mode plotting
1358  WriteHistograms(chanHist.get(), sampleName + "_" + sample->GetFlavourName(iSample, iChan) + ProjectionSuffix + suffix);
1359  }
1360  }
1361 
1362  if (by_mode && by_channel) {
1363  for (int iMode = 0; iMode < modes->GetNModes(); ++iMode) {
1364  for (int iChan = 0; iChan < sample->GetNOscChannels(iSample); ++iChan) {
1365  auto hist = sample->Get1DVarHistByModeAndChannel(iSample, ProjectionName, iMode, iChan);
1366  WriteHistograms(hist.get(), sampleName + "_" + modes->GetMaCh3ModeName(iMode) + "_" + sample->GetFlavourName(iSample, iChan) + ProjectionSuffix + suffix);
1367  }
1368  }
1369  }
1370 
1371  if (!by_mode && !by_channel) {
1372  auto hist = sample->Get1DVarHist(iSample, ProjectionName);
1373  WriteHistograms(hist.get(), sampleName + ProjectionSuffix + suffix);
1374  // Only for 2D and Beyond
1375  for (int iDim2 = iDim1 + 1; iDim2 < sample->GetNDim(iSample); ++iDim2) {
1376  // Get the names for the two dimensions
1377  std::string XVarName = sample->GetKinVarName(iSample, iDim1);
1378  std::string YVarName = sample->GetKinVarName(iSample, iDim2);
1379 
1380  // Get the 2D histogram for this pair
1381  auto hist2D = sample->Get2DVarHist(iSample, XVarName, YVarName);
1382 
1383  // Write the histogram
1384  std::string suffix2D = "_2DProj_" + std::to_string(iDim1) + "_vs_" + std::to_string(iDim2) + suffix;
1385  WriteHistograms(hist2D.get(), sampleName + suffix2D);
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::unique_ptr< TH1 > Get1DVarHistByModeAndChannel(const int iSample, const std::string &ProjectionVar_Str, const int kModeToFill=-1, const int kChannelToFill=-1, const int WeightStyle=0)=0
virtual std::unique_ptr< TH1 > Get1DVarHist(const int iSample, const std::string &ProjectionVar, const std::vector< KinematicCut > &EventSelectionVec={}, int WeightStyle=0, const std::vector< KinematicCut > &SubEventSelectionVec={})=0
virtual std::string GetFlavourName(const int iSample, const int iChannel) const =0
MaCh3Modes * GetMaCh3Modes() const
Return pointer to MaCh3 modes.
virtual int GetNOscChannels(const int iSample) const =0
virtual M3::int_t GetNSamples()
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...
virtual std::string GetSampleTitle(const int Sample) const =0
virtual std::unique_ptr< TH2 > Get2DVarHist(const int iSample, const std::string &ProjectionVarX, const std::string &ProjectionVarY, const std::vector< KinematicCut > &EventSelectionVec={}, const int WeightStyle=0, const std::vector< KinematicCut > &SubEventSelectionVec={})=0
virtual int GetNDim(const int Sample) const =0
DB Function to differentiate 1D or 2D binning.