MaCh3  2.2.3
Reference Guide
Functions
MaCh3Factory.h File Reference

Factory methods for MaCh3 software which streamline initialisation of different objects. More...

#include "Fitters/FitterBase.h"
#include "Fitters/MR2T2.h"
#include "Fitters/DelayedMR2T2.h"
#include "Fitters/PSO.h"
#include "Fitters/LikelihoodFit.h"
#include "Parameters/ParameterHandlerGeneric.h"
Include dependency graph for MaCh3Factory.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename CovType >
std::unique_ptr< CovType > MaCh3CovarianceFactory (manager *FitManager, const std::string &PreFix)
 MaCh3 Factory initiates one of implemented fitting algorithms. More...
 
template<typename SampleType >
std::vector< SampleType * > MaCh3SampleHandlerFactory (const std::vector< std::string > &SampleConfig, ParameterHandlerGeneric *xsec)
 Factory function for creating SampleHandler and initialisation with systematic. More...
 

Detailed Description

Factory methods for MaCh3 software which streamline initialisation of different objects.

Author
Kamil Skwarczynski

Definition in file MaCh3Factory.h.

Function Documentation

◆ MaCh3CovarianceFactory()

template<typename CovType >
std::unique_ptr<CovType> MaCh3CovarianceFactory ( manager FitManager,
const std::string &  PreFix 
)

MaCh3 Factory initiates one of implemented fitting algorithms.

Parameters
FitManagerpointer to Manager class
Note
Example YAML configuration:
General:
FittingAlgorithm: ["MCMC"]
std::unique_ptr<FitterBase> MaCh3FitterFactory(manager *FitManager);
@brief Initializes the config manager class and allows overriding settings via command-line arguments.
@param argc number of arguments
@param argv name of arguments
@return A unique pointer to the initialized `manager` instance with optional overrides applied.
@example Usage examples:
```
./bin/MCMCTutorial Inputs/FitterConfig.yaml General:OutputFile:blarb.root
./bin/MCMCTutorial Inputs/FitterConfig.yaml General:OutputFile:blarb.root General:MCMC:NSteps:50000
```
std::unique_ptr<manager> MaCh3ManagerFactory(int argc, char **argv);
// ********************************************
@brief Factory function for creating a covariance class for systematic handling.
@param FitManager Pointer to the manager class that holds the configuration settings.
@param PreFix Prefix, for example Xsec, then code will look for XsecCovFile
@return Pointer to the initialized covarianceXsec matrix object.
@note Example YAML configuration:
@code
General:
Systematics:
XsecCovName: "xsec_cov"
XsecCovFile: ["inputs/blarb1.yaml",
"inputs/blarb2.yaml"]
XsecFix: ["Param_0",
"Param_1"]
XsecPCAThreshold: -1
#XsecPCAThreshold: 0.00001
XsecPCAParams: [-999, -999]
XsecStepScale: 0.0075
std::unique_ptr< FitterBase > MaCh3FitterFactory(manager *fitMan)
Definition: MaCh3Factory.cpp:5
std::unique_ptr< manager > MaCh3ManagerFactory(int argc, char **argv)
std::unique_ptr< CovType > MaCh3CovarianceFactory(manager *FitManager, const std::string &PreFix)
MaCh3 Factory initiates one of implemented fitting algorithms.
Definition: MaCh3Factory.h:67
std::string config
Definition: ProcessMCMC.cpp:29
The manager class is responsible for managing configurations and settings.
Definition: Manager.h:16
Todo:
add adaptive stuff

Definition at line 67 of file MaCh3Factory.h.

67  {
68 // ********************************************
69  // config for our matrix
70  YAML::Node Settings = FitManager->raw()["General"]["Systematics"];
71  auto CovMatrixName = Get<std::string>(Settings[std::string(PreFix) + "CovName"], __FILE__, __LINE__);
72  MACH3LOG_INFO("Initialising {} matrix", CovMatrixName);
73 
74  // yaml files initialising out matrix
75  auto CovMatrixFile = Get<std::vector<std::string>>(Settings[std::string(PreFix) + "CovFile"], __FILE__, __LINE__);
76 
77  // PCA threshold, -1 means no pca
78  auto PCAThreshold = GetFromManager<int>(Settings[std::string(PreFix) + "PCAThreshold"], -1);
79  // do we pca whole matrix or only submatrix
80  auto PCAParamRegion = GetFromManager<std::vector<int>>(Settings[std::string(PreFix) + "PCAParams"], {-999, -999});
81 
82  auto CovObject = std::make_unique<CovType>(CovMatrixFile, CovMatrixName, PCAThreshold, PCAParamRegion[0], PCAParamRegion[1]);
83 
84  // Fill the parameter values with their nominal values
85  // should _ALWAYS_ be done before overriding with fix or flat
86  CovObject->SetParameters();
87 
88  auto FixParams = GetFromManager<std::vector<std::string>>(Settings[std::string(PreFix) + "Fix"], {});
89 
90  // Fixed CovObject parameters loop
91  if (FixParams.size() == 1 && FixParams.at(0) == "All") {
92  for (int j = 0; j < CovObject->GetNumParams(); j++) {
93  CovObject->ToggleFixParameter(j);
94  }
95  } else {
96  for (unsigned int j = 0; j < FixParams.size(); j++) {
97  CovObject->ToggleFixParameter(FixParams.at(j));
98  }
99  }
100  //Global step scale for matrix
101  auto StepScale = Get<double>(Settings[std::string(PreFix) + "StepScale"], __FILE__, __LINE__);
102 
103  CovObject->SetStepScale(StepScale);
104 
105  // Adaptive MCMC stuff
106  if (CheckNodeExists(FitManager->raw(), "AdaptionOptions")) {
107  CovObject->InitialiseAdaption(FitManager->raw());
108  }
109 
110  return CovObject;
111 }
#define MACH3LOG_INFO
Definition: MaCh3Logger.h:25
bool CheckNodeExists(const YAML::Node &node, Args... args)
KS: Wrapper function to call the recursive helper.
Definition: YamlHelper.h:55
YAML::Node const & raw()
Return config.
Definition: Manager.h:41

◆ MaCh3SampleHandlerFactory()

template<typename SampleType >
std::vector<SampleType*> MaCh3SampleHandlerFactory ( const std::vector< std::string > &  SampleConfig,
ParameterHandlerGeneric xsec 
)

Factory function for creating SampleHandler and initialisation with systematic.

Template Parameters
SampleTypeThe class type of the sample to create, e.g., SampleHandlerTutorial.
Parameters
SampleConfigPath to sample config.
xsecA pointer to a ParameterHandlerGeneric object for cross-section systematic settings.
Returns
Vector of SampleType object, initialized and ready for use.
Note
Example
auto mySamples = MaCh3SampleHandlerFactory<SampleHandlerTutorial>(SampleConfig, xsec);

Definition at line 126 of file MaCh3Factory.h.

127  {
128 // ********************************************
129  std::vector<SampleType*> Handlers(SampleConfig.size());
130  for (size_t i = 0; i < SampleConfig.size(); ++i)
131  {
132  // Instantiate the sample using the specified class type
133  SampleType* Sample = new SampleType(SampleConfig[i], xsec);
134  Sample->Reweight();
135 
136  // Obtain sample name and create a TString version for histogram naming
137  std::string name = Sample->GetTitle();
138  TString NameTString = TString(name.c_str());
139 
140  // Clone the 1D histogram with a modified name
141  if (Sample->GetNDim() == 1) {
142  auto hist = static_cast<TH1D*>(Sample->GetMCHist(1));
143  Sample->AddData(hist);
144  } else {
145  auto hist = static_cast<TH2D*>(Sample->GetMCHist(2));
146  Sample->AddData(hist);
147  }
148  Handlers[i] = Sample;
149  }
150  return Handlers;
151 }