MaCh3 2.2.1
Reference Guide
Loading...
Searching...
No Matches
Functions
MaCh3Factory.h File Reference

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

#include "Fitters/FitterBase.h"
#include "Fitters/mcmc.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.
 
template<typename SampleType >
std::vector< SampleType * > MaCh3SampleHandlerFactory (const std::vector< std::string > &SampleConfig, ParameterHandlerGeneric *xsec)
 Factory function for creating SampleHandler and initialisation with systematic.
 

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
fitManpointer to Manager class
Note
Example YAML configuration:
General:
FittingAlgorithm: ["MCMC"]
std::unique_ptr<FitterBase> MaCh3FitterFactory(manager *fitMan);
@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:65
std::string config
Definition: ProcessMCMC.cpp:30
The manager class is responsible for managing configurations and settings.
Definition: Manager.h:16
Todo:
add adaptive stuff

Definition at line 65 of file MaCh3Factory.h.

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

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