MaCh3  2.8.0
Reference Guide
MaCh3Factory.h
Go to the documentation of this file.
1 #pragma once
2 
3 // MaCh3 includes
5 #include "Algorithms/MR2T2.h"
7 #include "Algorithms/PSO.h"
9 #ifdef MaCh3_MINUIT2
10 #include "Algorithms/MinuitFit.h"
11 #endif
12 
14 
18 
29 std::unique_ptr<FitterBase> MaCh3FitterFactory(Manager *FitManager);
30 
40 std::unique_ptr<Manager> MaCh3ManagerFactory(int argc, char **argv);
41 
42 // ********************************************
68 template <typename CovType>
69 std::unique_ptr<CovType> MaCh3CovarianceFactory(Manager *FitManager, const std::string& PreFix) {
70 // ********************************************
71  // config for our matrix
72  YAML::Node Settings = FitManager->raw()["General"]["Systematics"];
73  auto CovMatrixName = Get<std::string>(Settings[std::string(PreFix) + "CovName"], __FILE__, __LINE__);
74  MACH3LOG_INFO("Initialising {} matrix", CovMatrixName);
75 
76  // yaml files initialising out matrix
77  auto CovMatrixFile = Get<std::vector<std::string>>(Settings[std::string(PreFix) + "CovFile"], __FILE__, __LINE__);
78 
79  // PCA threshold, -1 means no pca
80  auto PCAThreshold = GetFromManager<int>(Settings[std::string(PreFix) + "PCAThreshold"], -1, __FILE__ , __LINE__);
81  // do we pca whole matrix or only submatrix
82  auto PCAParamRegion = GetFromManager<std::vector<int>>(Settings[std::string(PreFix) + "PCAParams"], {-999, -999}, __FILE__ , __LINE__);
83 
84  auto CovObject = std::make_unique<CovType>(CovMatrixFile, CovMatrixName, PCAThreshold, PCAParamRegion[0], PCAParamRegion[1]);
85 
86  // Fill the parameter values with their nominal values
87  // should _ALWAYS_ be done before overriding with fix or flat
88  CovObject->SetParameters();
89 
90  auto FixParams = GetFromManager<std::vector<std::string>>(Settings[std::string(PreFix) + "Fix"], {}, __FILE__ , __LINE__);
91 
92  // Fixed CovObject parameters loop
93  if (FixParams.size() == 1 && FixParams.at(0) == "All") {
94  CovObject->SetFixAllParameters();
95  } else {
96  for (unsigned int j = 0; j < FixParams.size(); j++) {
97  CovObject->SetFixParameter(FixParams.at(j));
98  }
99  }
100 
101  if (CheckNodeExists(Settings, std::string(PreFix) + "Tune"))
102  {
103  CovObject->SetTune(Get<std::string>(Settings[std::string(PreFix) + "Tune"], __FILE__, __LINE__));
104  }
105 
106  //Global step scale for matrix
107  auto StepScale = Get<double>(Settings[std::string(PreFix) + "StepScale"], __FILE__, __LINE__);
108 
109  CovObject->SetStepScale(StepScale);
110 
111  // Adaptive MCMC stuff
112  if (CheckNodeExists(FitManager->raw(), "AdaptionOptions")) {
113  CovObject->InitialiseAdaption(FitManager->raw());
114  }
115 
116  return CovObject;
117 }
118 
119 // ********************************************
131 template <typename SampleType>
132 std::vector<SampleType*> MaCh3SampleHandlerFactory(const std::vector<std::string>& SampleConfig,
133  ParameterHandlerGeneric* xsec) {
134 // ********************************************
135  std::vector<SampleType*> Handlers(SampleConfig.size());
136  for (size_t i = 0; i < SampleConfig.size(); ++i)
137  {
138  // Instantiate the sample using the specified class type
139  SampleType* Sample = new SampleType(SampleConfig[i], xsec);
140  Handlers[i] = Sample;
141  }
142  return Handlers;
143 }
std::unique_ptr< CovType > MaCh3CovarianceFactory(Manager *FitManager, const std::string &PreFix)
Factory function for creating a covariance class for systematic handling.
Definition: MaCh3Factory.h:69
std::vector< SampleType * > MaCh3SampleHandlerFactory(const std::vector< std::string > &SampleConfig, ParameterHandlerGeneric *xsec)
Factory function for creating SampleHandler and initialisation with systematic.
Definition: MaCh3Factory.h:132
std::unique_ptr< Manager > MaCh3ManagerFactory(int argc, char **argv)
Initializes the config Manager class and allows overriding settings via command-line arguments.
#define MACH3LOG_INFO
Definition: MaCh3Logger.h:35
bool CheckNodeExists(const YAML::Node &node, Args... args)
KS: Wrapper function to call the recursive helper.
Definition: YamlHelper.h:59
The manager class is responsible for managing configurations and settings.
Definition: Manager.h:17
YAML::Node const & raw() const
Return config.
Definition: Manager.h:48
Class responsible for handling of systematic error parameters with different types defined in the con...
std::unique_ptr< FitterBase > MaCh3FitterFactory(Manager *FitManager)
MaCh3 Factory initiates one of implemented fitting algorithms.
Definition: MaCh3Factory.cpp:5