MaCh3  2.2.3
Reference Guide
MaCh3Factory.h
Go to the documentation of this file.
1 #pragma once
2 
3 // MaCh3 includes
4 #include "Fitters/FitterBase.h"
5 #include "Fitters/MR2T2.h"
6 #include "Fitters/DelayedMR2T2.h"
7 #include "Fitters/PSO.h"
9 #ifdef MaCh3_MINUIT2
10 #include "Fitters/MinuitFit.h"
11 #endif
12 
13 
15 
19 
27 std::unique_ptr<FitterBase> MaCh3FitterFactory(manager *FitManager);
28 
38 std::unique_ptr<manager> MaCh3ManagerFactory(int argc, char **argv);
39 
40 // ********************************************
66 template <typename CovType>
67 std::unique_ptr<CovType> MaCh3CovarianceFactory(manager *FitManager, const std::string& PreFix){
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 }
112 
113 // ********************************************
125 template <typename SampleType>
126 std::vector<SampleType*> MaCh3SampleHandlerFactory(const std::vector<std::string>& SampleConfig,
127  ParameterHandlerGeneric* xsec) {
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 }
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::vector< SampleType * > MaCh3SampleHandlerFactory(const std::vector< std::string > &SampleConfig, ParameterHandlerGeneric *xsec)
Factory function for creating SampleHandler and initialisation with systematic.
Definition: MaCh3Factory.h:126
#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
Class responsible for handling of systematic error parameters with different types defined in the con...
The manager class is responsible for managing configurations and settings.
Definition: Manager.h:16
YAML::Node const & raw()
Return config.
Definition: Manager.h:41