Skip to content

Commit

Permalink
Actually try something which will not break everything
Browse files Browse the repository at this point in the history
  • Loading branch information
KSkwarczynski committed Oct 11, 2024
1 parent 1643481 commit a3ac236
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 42 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

#KS: Enable language, necessary when using CUDA
enable_language(CXX)
set(MaCh3_VERSION 1.1.8)
set(MaCh3_VERSION 1.2.0)

# Try to find CUDA
find_package(CUDAToolkit QUIET)
Expand Down
2 changes: 1 addition & 1 deletion Doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "MaCh3"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 1.1.8
PROJECT_NUMBER = 1.2.0

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
3 changes: 0 additions & 3 deletions manager/YamlHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,10 @@ inline TMacro YAMLtoTMacro(const YAML::Node& yaml_node, const std::string& name)
// Convert the YAML node to a string representation
std::string macro_string = YAMLtoSTRING(yaml_node);

std::cout<<macro_string<<std::endl;
// Create a TMacro object with the collected lines
TMacro macro(name.c_str(), name.c_str());
macro.AddLine(macro_string.c_str());

macro.Print();

return macro;
}

Expand Down
5 changes: 0 additions & 5 deletions mcmc/FitterBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,7 @@ void FitterBase::addSystObj(covarianceBase * const cov) {
// Similar to systematic really, but handles the oscillation weights
void FitterBase::addOscHandler(covarianceOsc * const oscf) {
// *************************

osc = oscf;

if (save_nominal) {
CovFolder->cd();
std::vector<double> vec = oscf->getNominalArray();
Expand All @@ -339,15 +337,13 @@ void FitterBase::addOscHandler(covarianceOsc * const oscf) {
TMacro ConfigSave = YAMLtoTMacro(Config, (std::string("Config_") + oscf->getName()));
ConfigSave.Write();
}

return;
}

// *******************
// Process the MCMC output to get postfit etc
void FitterBase::ProcessMCMC() {
// *******************

if (fitMan == NULL) return;

// Process the MCMC
Expand Down Expand Up @@ -383,7 +379,6 @@ void FitterBase::ProcessMCMC() {
MACH3LOG_INFO("Opening output again to update with means..");
outputFile = new TFile(fitMan->raw()["General"]["Output"]["Filename"].as<std::string>().c_str(), "UPDATE");
}

Central->Write("PDF_Means");
Errors->Write("PDF_Errors");
Central_Gauss->Write("Gauss_Means");
Expand Down
9 changes: 1 addition & 8 deletions mcmc/MCMCProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ MCMCProcessor::MCMCProcessor(const std::string &InputFile) :
AccProbValues = nullptr;
AccProbBatchedAverages = nullptr;

//KS: Warning this only work when you project from Chain, will nor work when you try SetBranchAddress etc. Turn it on only if you know how to use it
//KS: WARNING this only work when you project from Chain, will nor work when you try SetBranchAddress etc. Turn it on only if you know how to use it
PlotJarlskog = false;

//KS:Hardcoded should be a way to get it via config or something
Expand Down Expand Up @@ -2485,13 +2485,6 @@ void MCMCProcessor::FindInputFiles() {
bool InputNotFound = false;
//CW: Get the xsec Covariance matrix
CovPos[kXSecPar] = GetFromManager<std::vector<std::string>>(Settings["General"]["Systematics"]["XsecCovFile"], {"none"});
// If someone used factory approach have this option here
if(CovPos[kXSecPar].back() == "none") {
// Check if xsec_cov exists first before accessing CovFile
if(Settings["General"]["Systematics"]["xsec_cov"]) {
CovPos[kXSecPar] = GetFromManager<std::vector<std::string>>(Settings["General"]["Systematics"]["xsec_cov"]["CovFile"], {"none"});
}
}
if(CovPos[kXSecPar].back() == "none")
{
MACH3LOG_WARN("Couldn't find XsecCov branch in output");
Expand Down
26 changes: 13 additions & 13 deletions mcmc/MaCh3Factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,29 @@ std::unique_ptr<FitterBase> MaCh3FitterFactory(manager *fitMan, std::vector<samp
}

// ********************************************
covarianceXsec* MaCh3CovarianceFactory(manager *fitMan, const std::string& name) {
covarianceXsec* MaCh3CovarianceFactory(manager *FitManager, const std::string& PreFix) {
// ********************************************
MACH3LOG_INFO("Initialising {} matrix", name);

// config for our matrix
YAML::Node Settings = fitMan->raw()["General"]["Systematics"][name];
YAML::Node Settings = FitManager->raw()["General"]["Systematics"];
auto CovMatrixName = Settings[std::string(PreFix) + "CovName"].as<std::string>();
MACH3LOG_INFO("Initialising {} matrix", CovMatrixName);

// yaml files initialising out matrix
auto CovMatrixFile = Settings["CovFile"].as<std::vector<std::string>>();
auto CovMatrixFile = Settings[std::string(PreFix) + "CovFile"].as<std::vector<std::string>>();

// PCA threshold, -1 means no pca
auto PCAThreshold = GetFromManager<double>(Settings["PCAThreshold"], -1);
auto PCAThreshold = GetFromManager<double>(Settings[std::string(PreFix) + "PCAThreshold"], -1);
// do we pca whole matrix or only submatrix
auto PCAParamRegion = GetFromManager<std::vector<double>>(Settings["PCAParams"], {-999, -999});
auto PCAParamRegion = GetFromManager<std::vector<double>>(Settings[std::string(PreFix) + "PCAParams"], {-999, -999});

// create our glorious matrix
/// @todo this massive hack with "xsec_cov" is because we have const char * ... will have to fix it later...
covarianceXsec* xsec = new covarianceXsec(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
xsec->setParameters();

auto FixParams = GetFromManager<std::vector<std::string>>(Settings["FixParams"], {});
auto FixParams = GetFromManager<std::vector<std::string>>(Settings[std::string(PreFix) + "FixParams"], {});

// Fixed xsec parameters loop
if (FixParams.size() == 1 && FixParams.at(0) == "All") {
Expand All @@ -69,14 +70,13 @@ covarianceXsec* MaCh3CovarianceFactory(manager *fitMan, const std::string& name)
}
}
//Global step scale for matrix
auto StepScale = Settings["StepScale"].as<double>();
auto StepScale = Settings[std::string(PreFix) + "StepScale"].as<double>();

MACH3LOG_INFO("With Step Scale {:.4f}", StepScale);
xsec->setStepScale(StepScale);

// TODO
// Adaptive MCMC stuff
//xsec->initialiseAdaption(FitManager->raw());
if(FitManager->raw()["AdaptionOptions"])
xsec->initialiseAdaption(FitManager->raw());

MACH3LOG_INFO("Factory successful");

Expand Down
26 changes: 15 additions & 11 deletions mcmc/MaCh3Factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,28 @@ std::unique_ptr<FitterBase> MaCh3FitterFactory(manager *fitMan, std::vector<samp
/// @brief Factory function for creating a covariance matrix for systematic handling.
///
/// @param fitMan Pointer to the manager class that holds the configuration settings.
/// @param name Name of the systematic matrix to initialize. This corresponds to a key in the YAML configuration.
/// @param name Prefix, for example Xsec, then code will look for XsecCovFile
/// @return Pointer to the initialized covarianceXsec matrix object.
///
/// @note Example YAML configuration:
/// @code
///MaCh3CovarianceFactory(, Xsec)
///
/// General:
/// Systematics:
/// xsec_cov:
/// CovFile: ["inputs/blarb1.yaml",
/// "inputs/blarb2.yaml"]
/// FixParams: ["Param_0",
/// "Param_1"]
/// PCAThreshold: -1
/// #PCAThreshold: 0.00001
/// XsecCovName: "xsec_cov"
/// XsecCovFile: ["inputs/blarb1.yaml",
/// "inputs/blarb2.yaml"]
/// XsecFix: ["Param_0",
/// "Param_1"]
/// XsecPCAThreshold: -1
/// #XsecPCAThreshold: 0.00001
///
/// PCAParams: [-999, -999]
/// StepScale: 0.0075
/// XsecPCAParams: [-999, -999]
/// XsecStepScale: 0.0075
/// @endcode
///
/// @todo add adaptive stuff
covarianceXsec* MaCh3CovarianceFactory(manager *fitMan, const std::string& name);
covarianceXsec* MaCh3CovarianceFactory(manager *fitMan, const std::string& PreFix);


0 comments on commit a3ac236

Please sign in to comment.