MaCh3 2.2.1
Reference Guide
Loading...
Searching...
No Matches
MaCh3Factory.h
Go to the documentation of this file.
1#pragma once
2
3// MaCh3 includes
5#include "Fitters/mcmc.h"
6#include "Fitters/PSO.h"
8#ifdef MaCh3_MINUIT2
9#include "Fitters/MinuitFit.h"
10#endif
11
13
17
25std::unique_ptr<FitterBase> MaCh3FitterFactory(manager *fitMan);
26
36std::unique_ptr<manager> MaCh3ManagerFactory(int argc, char **argv);
37
38// ********************************************
64template <typename CovType>
65std::unique_ptr<CovType> MaCh3CovarianceFactory(manager *FitManager, const std::string& PreFix){
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}
110
111// ********************************************
123template <typename SampleType>
124std::vector<SampleType*> MaCh3SampleHandlerFactory(const std::vector<std::string>& SampleConfig,
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}
std::unique_ptr< FitterBase > MaCh3FitterFactory(manager *fitMan)
Definition: MaCh3Factory.cpp:5
std::unique_ptr< manager > MaCh3ManagerFactory(int argc, char **argv)
std::vector< SampleType * > MaCh3SampleHandlerFactory(const std::vector< std::string > &SampleConfig, ParameterHandlerGeneric *xsec)
Factory function for creating SampleHandler and initialisation with systematic.
Definition: MaCh3Factory.h:124
std::unique_ptr< CovType > MaCh3CovarianceFactory(manager *FitManager, const std::string &PreFix)
MaCh3 Factory initiates one of implemented fitting algorithms.
Definition: MaCh3Factory.h:65
#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
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