From 082a44a2d8b46935d00c924af8f14ca7f33b4807 Mon Sep 17 00:00:00 2001 From: Kamil Skwarczynski Date: Mon, 18 Nov 2024 12:35:24 +0000 Subject: [PATCH] minor tweaks to factory --- mcmc/MaCh3Factory.cpp | 61 +------------------------------------------ mcmc/MaCh3Factory.h | 58 +++++++++++++++++++++++++++++++++++----- 2 files changed, 53 insertions(+), 66 deletions(-) diff --git a/mcmc/MaCh3Factory.cpp b/mcmc/MaCh3Factory.cpp index 56ef9fcb..e257bc58 100644 --- a/mcmc/MaCh3Factory.cpp +++ b/mcmc/MaCh3Factory.cpp @@ -3,7 +3,7 @@ // ******************************************** -std::unique_ptr MaCh3FitterFactory(manager *fitMan, std::vector& Samples, std::vector& Covariances) { +std::unique_ptr MaCh3FitterFactory(manager *fitMan) { // ******************************************** std::unique_ptr MaCh3Fitter = nullptr; @@ -24,68 +24,9 @@ std::unique_ptr MaCh3FitterFactory(manager *fitMan, std::vectoraddSamplePDF(Samples[i]); - for(unsigned int i = 0; Covariances.size(); i++) - MaCh3Fitter->addSystObj(Covariances[i]); - return MaCh3Fitter; } -// ******************************************** -template -CovType* MaCh3CovarianceFactory(manager *FitManager, const std::string& PreFix){ -// ******************************************** - - // config for our matrix - YAML::Node Settings = FitManager->raw()["General"]["Systematics"]; - auto CovMatrixName = Settings[std::string(PreFix) + "CovName"].as(); - MACH3LOG_INFO("Initialising {} matrix", CovMatrixName); - - // yaml files initialising out matrix - auto CovMatrixFile = Settings[std::string(PreFix) + "CovFile"].as>(); - - // PCA threshold, -1 means no pca - auto PCAThreshold = GetFromManager(Settings[std::string(PreFix) + "PCAThreshold"], -1); - // do we pca whole matrix or only submatrix - auto PCAParamRegion = GetFromManager>(Settings[std::string(PreFix) + "PCAParams"], {-999, -999}); - - /// @todo this massive hack with "xsec_cov" is because we have const char * ... will have to fix it later... - CovType* CovObject = new CovType(CovMatrixFile, "xsec_cov", PCAThreshold, PCAParamRegion[0], PCAParamRegion[1]); - - // Fill the parameter values with their nominal values - // should _ALWAYS_ be done before overriding with fix or flat - CovObject->setParameters(); - - auto FixParams = GetFromManager>(Settings[std::string(PreFix) + "FixParams"], {}); - - // Fixed CovObject parameters loop - if (FixParams.size() == 1 && FixParams.at(0) == "All") { - for (int j = 0; j < CovObject->GetNumParams(); j++) { - CovObject->toggleFixParameter(j); - } - } else { - for (unsigned int j = 0; j < FixParams.size(); j++) { - CovObject->toggleFixParameter(FixParams.at(j)); - } - } - //Global step scale for matrix - auto StepScale = Settings[std::string(PreFix) + "StepScale"].as(); - - CovObject->setStepScale(StepScale); - - // Adaptive MCMC stuff - if(FitManager->raw()["AdaptionOptions"]) - CovObject->initialiseAdaption(FitManager->raw()); - - MACH3LOG_INFO("Factory successful"); - - return CovObject; -} - - // ******************************************** covarianceXsec* MaCh3CovarianceFactory(manager *FitManager, const std::string& PreFix) { // ******************************************** diff --git a/mcmc/MaCh3Factory.h b/mcmc/MaCh3Factory.h index 6d9276dd..0ce1be88 100644 --- a/mcmc/MaCh3Factory.h +++ b/mcmc/MaCh3Factory.h @@ -22,9 +22,13 @@ /// @code /// General: /// FittingAlgorithm: ["MCMC"] -std::unique_ptr MaCh3FitterFactory(manager *fitMan, std::vector& Samples, std::vector& Covariances); +std::unique_ptr MaCh3FitterFactory(manager *fitMan); +/// @brief Factory function for creating a covariance class for systematic handling. +covarianceXsec* MaCh3CovarianceFactory(manager *FitManager, const std::string& PreFix); + +// ******************************************** /// @brief Factory function for creating a covariance class for systematic handling. /// /// @param fitMan Pointer to the manager class that holds the configuration settings. @@ -51,12 +55,54 @@ std::unique_ptr MaCh3FitterFactory(manager *fitMan, std::vector -CovType* MaCh3CovarianceFactory(manager *FitManager, const std::string& PreFix); +CovType* MaCh3CovarianceFactory(manager *FitManager, const std::string& PreFix){ +// ******************************************** + // config for our matrix + YAML::Node Settings = FitManager->raw()["General"]["Systematics"]; + auto CovMatrixName = Settings[std::string(PreFix) + "CovName"].as(); + MACH3LOG_INFO("Initialising {} matrix", CovMatrixName); -/// @brief Factory function for creating a covariance class for systematic handling. -covarianceXsec* MaCh3CovarianceFactory(manager *FitManager, const std::string& PreFix); + // yaml files initialising out matrix + auto CovMatrixFile = Settings[std::string(PreFix) + "CovFile"].as>(); + + // PCA threshold, -1 means no pca + auto PCAThreshold = GetFromManager(Settings[std::string(PreFix) + "PCAThreshold"], -1); + // do we pca whole matrix or only submatrix + auto PCAParamRegion = GetFromManager>(Settings[std::string(PreFix) + "PCAParams"], {-999, -999}); + + CovType* CovObject = new CovType(CovMatrixFile, CovMatrixName, PCAThreshold, PCAParamRegion[0], PCAParamRegion[1]); + + // Fill the parameter values with their nominal values + // should _ALWAYS_ be done before overriding with fix or flat + CovObject->setParameters(); + auto FixParams = GetFromManager>(Settings[std::string(PreFix) + "FixParams"], {}); + + // Fixed CovObject parameters loop + if (FixParams.size() == 1 && FixParams.at(0) == "All") { + for (int j = 0; j < CovObject->GetNumParams(); j++) { + CovObject->toggleFixParameter(j); + } + } else { + for (unsigned int j = 0; j < FixParams.size(); j++) { + CovObject->toggleFixParameter(FixParams.at(j)); + } + } + //Global step scale for matrix + auto StepScale = Settings[std::string(PreFix) + "StepScale"].as(); + + CovObject->setStepScale(StepScale); + + // Adaptive MCMC stuff + if(FitManager->raw()["AdaptionOptions"]) + CovObject->initialiseAdaption(FitManager->raw()); + + MACH3LOG_INFO("Factory successful"); + + return CovObject; +} +// ******************************************** /// @brief Factory function for creating SamplePDF and initialisation with systematic. /// /// @tparam SampleType The class type of the sample to create, e.g., `samplePDFTutorial`. @@ -72,8 +118,8 @@ covarianceXsec* MaCh3CovarianceFactory(manager *FitManager, const std::string& P template std::vector MaCh3SamplePDFFactory(const std::vector& SampleConfig, covarianceXsec* xsec, - covarianceOsc* osc = nullptr) -{ + covarianceOsc* osc = nullptr) { +// ******************************************** std::vector PDFs(SampleConfig.size()); for (size_t i = 0; i < SampleConfig.size(); ++i) {