MaCh3  2.6.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 1301 of file FitterBase.cpp.

1301  {
1302 // *************************
1303  if (!hist) return;
1304  hist->SetTitle(baseName.c_str());
1305  // Get the class name of the histogram
1306  TString className = hist->ClassName();
1307 
1308  // Set the appropriate axis title based on the histogram type
1309  if (className.Contains("TH1")) {
1310  hist->GetYaxis()->SetTitle("Events");
1311  } else if (className.Contains("TH2")) {
1312  hist->GetZaxis()->SetTitle("Events");
1313  }
1314  hist->Write(baseName.c_str());
1315 }

◆ 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 1319 of file FitterBase.cpp.

1323  {
1324 // *************************
1325  MaCh3Modes *modes = sample->GetMaCh3Modes();
1326  for (int iSample = 0; iSample < sample->GetNSamples(); ++iSample) {
1327  SampleDir[iSample]->cd();
1328  const std::string sampleName = sample->GetSampleTitle(iSample);
1329  for(int iDim1 = 0; iDim1 < sample->GetNDim(iSample); iDim1++) {
1330  std::string ProjectionName = sample->GetKinVarName(iSample, iDim1);
1331  std::string ProjectionSuffix = "_1DProj" + std::to_string(iDim1);
1332 
1333  // Probably a better way of handling this logic
1334  if (by_mode) {
1335  for (int iMode = 0; iMode < modes->GetNModes(); ++iMode) {
1336  auto modeHist = sample->Get1DVarHistByModeAndChannel(iSample, ProjectionName, iMode);
1337  WriteHistograms(modeHist.get(), sampleName + "_" + modes->GetMaCh3ModeName(iMode) + ProjectionSuffix + suffix);
1338  }
1339  }
1340 
1341  if (by_channel) {
1342  for (int iChan = 0; iChan < sample->GetNOscChannels(iSample); ++iChan) {
1343  auto chanHist = sample->Get1DVarHistByModeAndChannel(iSample, ProjectionName, -1, iChan); // -1 skips over mode plotting
1344  WriteHistograms(chanHist.get(), sampleName + "_" + sample->GetFlavourName(iSample, iChan) + ProjectionSuffix + suffix);
1345  }
1346  }
1347 
1348  if (by_mode && by_channel) {
1349  for (int iMode = 0; iMode < modes->GetNModes(); ++iMode) {
1350  for (int iChan = 0; iChan < sample->GetNOscChannels(iSample); ++iChan) {
1351  auto hist = sample->Get1DVarHistByModeAndChannel(iSample, ProjectionName, iMode, iChan);
1352  WriteHistograms(hist.get(), sampleName + "_" + modes->GetMaCh3ModeName(iMode) + "_" + sample->GetFlavourName(iSample, iChan) + ProjectionSuffix + suffix);
1353  }
1354  }
1355  }
1356 
1357  if (!by_mode && !by_channel) {
1358  auto hist = sample->Get1DVarHist(iSample, ProjectionName);
1359  WriteHistograms(hist.get(), sampleName + ProjectionSuffix + suffix);
1360  // Only for 2D and Beyond
1361  for (int iDim2 = iDim1 + 1; iDim2 < sample->GetNDim(iSample); ++iDim2) {
1362  // Get the names for the two dimensions
1363  std::string XVarName = sample->GetKinVarName(iSample, iDim1);
1364  std::string YVarName = sample->GetKinVarName(iSample, iDim2);
1365 
1366  // Get the 2D histogram for this pair
1367  auto hist2D = sample->Get2DVarHist(iSample, XVarName, YVarName);
1368 
1369  // Write the histogram
1370  std::string suffix2D = "_2DProj_" + std::to_string(iDim1) + "_vs_" + std::to_string(iDim2) + suffix;
1371  WriteHistograms(hist2D.get(), sampleName + suffix2D);
1372  }
1373  }
1374  }
1375  }
1376 }
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:142
int GetNModes() const
KS: Get number of modes, keep in mind actual number is +1 greater due to unknown category.
Definition: MaCh3Modes.h:155
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
Build a 1D histogram for a given variable, optionally filtered by mode and channel.
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
Return 1D projection of MC into given 1D variable (doesn't have to be variable used in the fit)
virtual std::string GetFlavourName(const int iSample, const int iChannel) const =0
Get the flavour name for a given sample and oscillation channel.
MaCh3Modes * GetMaCh3Modes() const
Return pointer to MaCh3 modes.
virtual int GetNOscChannels(const int iSample) const =0
Get number of oscillation channels for a single sample.
virtual M3::int_t GetNSamples()
returns total number of samples
virtual std::string GetSampleTitle(const int iSample) const =0
Get fancy title for specified samples.
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::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
Build a 2D projection of MC events into specified variables.
virtual int GetNDim(const int Sample) const =0
DB Get what dimensionality binning for given sample has.