Skip to content

Commit

Permalink
Merge pull request #91 from mach3-software/feature_BagOfTricks
Browse files Browse the repository at this point in the history
Tidy
  • Loading branch information
KSkwarczynski authored Aug 28, 2024
2 parents 9b319d2 + 9211a12 commit 86d7720
Show file tree
Hide file tree
Showing 18 changed files with 415 additions and 401 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/CDImage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@ jobs:
- os: Ubuntu22.04
file: Doc/MaCh3DockerFiles/Ubuntu22.04/Dockerfile
tag_latest: ubuntu22.04latest
tag_release: ubuntu22.04v1.1.0
- os: Alma9
file: Doc/MaCh3DockerFiles/Alma9/Dockerfile
tag_latest: alma9latest
tag_release: alma9v1.1.0
- os: Fedora32
file: Doc/MaCh3DockerFiles/Fedora32/Dockerfile
tag_latest: fedora32latest
tag_release: fedora32v1.1.0

name: Image CD ${{ matrix.os }}

Expand All @@ -43,14 +40,15 @@ jobs:
run: |
if [ "${{ github.event_name }}" == 'release' ]; then
docker build . --file ${{ matrix.file }} --tag ghcr.io/${{ github.repository_owner }}/mach3:${{ matrix.tag_release }} --build-arg MACH3_VERSION=develop
docker build . --file ${{ matrix.file }} --tag ghcr.io/${{ github.repository_owner }}/mach3:${{ matrix.os }}v${{ github.event.release.tag_name }} --build-arg MACH3_VERSION=develop
else
docker build . --file ${{ matrix.file }} --tag ghcr.io/${{ github.repository_owner }}/mach3:${{ matrix.tag_latest }} --build-arg MACH3_VERSION=develop
fi
- name: Push Docker image
run: |
if [ "${{ github.event_name }}" == 'release' ]; then
docker push ghcr.io/${{ github.repository_owner }}/mach3:${{ matrix.tag_release }}
docker push ghcr.io/${{ github.repository_owner }}/mach3:${{ matrix.os }}v${{ github.event.release.tag_name }}
else
docker push ghcr.io/${{ github.repository_owner }}/mach3:${{ matrix.tag_latest }}
fi
37 changes: 17 additions & 20 deletions Diagnostics/DiagMCMC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,10 @@

#include "manager/manager.h"


void DiagMCMC(std::string inputFile, std::string config);

int main(int argc, char *argv[]) {
SetMaCh3LoggerFormat();
if (argc != 3)
{
MACH3LOG_ERROR("How to use: DiagMCMC MCMC_Output.root config");
throw MaCh3Exception(__FILE__ , __LINE__ );
}
MACH3LOG_INFO("Producing single fit output");
std::string filename = argv[1];
std::string config = argv[2];
DiagMCMC(filename, config);

return 0;
}


void DiagMCMC(std::string inputFile, std::string config)
/// @brief Main function creating MCMCProcessor and calling MCMC Diagnostic
/// @param inputFile MCMC Chain
/// @param config Config file with settings
void DiagMCMC(const std::string& inputFile, const std::string& config)
{
MACH3LOG_INFO("File for study: {}", inputFile);

Expand All @@ -47,4 +31,17 @@ void DiagMCMC(std::string inputFile, std::string config)
delete Processor;
}

int main(int argc, char *argv[]) {
SetMaCh3LoggerFormat();
if (argc != 3)
{
MACH3LOG_ERROR("How to use: DiagMCMC MCMC_Output.root config");
throw MaCh3Exception(__FILE__ , __LINE__ );
}
MACH3LOG_INFO("Producing single fit output");
std::string filename = argv[1];
std::string config = argv[2];
DiagMCMC(filename, config);

return 0;
}
18 changes: 11 additions & 7 deletions Diagnostics/ProcessMCMC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
#include "mcmc/MCMCProcessor.h"
#include "manager/manager.h"

inline void ProcessMCMC(std::string inputFile);
/// @brief Main function processing MCMC and Producing plots
inline void ProcessMCMC(const std::string& inputFile);
/// @brief Function producing comparison of posterior and more betwen a few MCMC chains
inline void MultipleProcessMCMC();
inline void CalcBayesFactor(MCMCProcessor* Processor);
inline void CalcSavageDickey(MCMCProcessor* Processor);
inline void CalcBipolarPlot(MCMCProcessor* Processor);
inline void GetTrianglePlot(MCMCProcessor* Processor);
inline void DiagnoseCovarianceMatrix(MCMCProcessor* Processor, std::string inputFile);
inline void DiagnoseCovarianceMatrix(MCMCProcessor* Processor, const std::string& inputFile);
inline void ReweightPrior(MCMCProcessor* Processor);
inline TH2D* TMatrixIntoTH2D(TMatrixDSym* Matrix, std::string title);
/// @brief KS: Convert TMatrix to TH2D, mostly useful for making fancy plots
inline TH2D* TMatrixIntoTH2D(TMatrixDSym* Matrix, const std::string& title);
/// @brief KS: Perform KS test to check if two posteriors for the same parameter came from the same distribution
inline void KolmogorovSmirnovTest(MCMCProcessor** Processor, TCanvas* Posterior, TString canvasname);

int nFiles;
Expand Down Expand Up @@ -59,7 +63,7 @@ int main(int argc, char *argv[])
return 0;
}

void ProcessMCMC(std::string inputFile)
void ProcessMCMC(const std::string& inputFile)
{
MACH3LOG_INFO("File for study: {} with config {}", inputFile, config);
// Make the processor)
Expand Down Expand Up @@ -391,8 +395,8 @@ void GetTrianglePlot(MCMCProcessor* Processor) {
}
}

//KS: You validate stability of posterior covariance matrix, you set burn calc cov matrix increase burn calc again and compare. By performing such operation several hundred times we can check when matrix becomes stable
void DiagnoseCovarianceMatrix(MCMCProcessor* Processor, std::string inputFile)
/// @brief KS: You validate stability of posterior covariance matrix, you set burn calc cov matrix increase burn calc again and compare. By performing such operation several hundred times we can check when matrix becomes stable
void DiagnoseCovarianceMatrix(MCMCProcessor* Processor, const std::string& inputFile)
{
//Turn of plots from Processor
Processor->SetPrintToPDF(false);
Expand Down Expand Up @@ -584,7 +588,7 @@ void ReweightPrior(MCMCProcessor* Processor)
}

//KS: Convert TMatrix to TH2D, mostly useful for making fancy plots
TH2D* TMatrixIntoTH2D(TMatrixDSym* Matrix, std::string title)
TH2D* TMatrixIntoTH2D(TMatrixDSym* Matrix, const std::string& title)
{
TH2D* hMatrix = new TH2D(title.c_str(), title.c_str(), Matrix->GetNrows(), 0.0, Matrix->GetNrows(), Matrix->GetNcols(), 0.0, Matrix->GetNcols());
for(int i = 0; i < Matrix->GetNrows(); i++)
Expand Down
4 changes: 2 additions & 2 deletions Diagnostics/RHat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
#include "manager/manager.h"


//KS: This exe is meant to calculate R hat estimator. For a well converged this distribution should be centred at one.
//Based on Gelman et. al. arXiv:1903.08008v5
/// KS: This exe is meant to calculate R hat estimator. For a well converged this distribution should be centred at one.
/// Based on Gelman et. al. arXiv:1903.08008v5

// *******************
int Ntoys;
Expand Down
14 changes: 11 additions & 3 deletions Doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ ABBREVIATE_BRIEF =
# description.
# The default value is: NO.

ALWAYS_DETAILED_SEC = NO
ALWAYS_DETAILED_SEC = YES

# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
# inherited members of a class in the documentation of that class as if those
Expand Down Expand Up @@ -189,6 +189,14 @@ QT_AUTOBRIEF = NO

MULTILINE_CPP_IS_BRIEF = NO

# By default Python docstrings are displayed as preformatted text and doxygen's
# special commands cannot be used. By setting PYTHON_DOCSTRING to NO the
# doxygen's special commands can be used and the contents of the docstring
# documentation blocks is shown as doxygen documentation.
# The default value is: YES.

PYTHON_DOCSTRING = YES

# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the
# documentation from any documented member that it re-implements.
# The default value is: YES.
Expand Down Expand Up @@ -1897,7 +1905,7 @@ ENABLE_PREPROCESSING = YES
# The default value is: NO.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

MACRO_EXPANSION = NO
MACRO_EXPANSION = YES

# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then
# the macro expansion is limited to the macros specified with the PREDEFINED and
Expand Down Expand Up @@ -2044,7 +2052,7 @@ HIDE_UNDOC_RELATIONS = YES
# set to NO
# The default value is: NO.

HAVE_DOT = NO
HAVE_DOT = YES

# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed
# to run in parallel. When set to 0 doxygen will base this on the number of
Expand Down
14 changes: 11 additions & 3 deletions cmake/Templates/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ ABBREVIATE_BRIEF =
# description.
# The default value is: NO.

ALWAYS_DETAILED_SEC = NO
ALWAYS_DETAILED_SEC = YES

# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
# inherited members of a class in the documentation of that class as if those
Expand Down Expand Up @@ -189,6 +189,14 @@ QT_AUTOBRIEF = NO

MULTILINE_CPP_IS_BRIEF = NO

# By default Python docstrings are displayed as preformatted text and doxygen's
# special commands cannot be used. By setting PYTHON_DOCSTRING to NO the
# doxygen's special commands can be used and the contents of the docstring
# documentation blocks is shown as doxygen documentation.
# The default value is: YES.

PYTHON_DOCSTRING = YES

# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the
# documentation from any documented member that it re-implements.
# The default value is: YES.
Expand Down Expand Up @@ -1897,7 +1905,7 @@ ENABLE_PREPROCESSING = YES
# The default value is: NO.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

MACRO_EXPANSION = NO
MACRO_EXPANSION = YES

# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then
# the macro expansion is limited to the macros specified with the PREDEFINED and
Expand Down Expand Up @@ -2044,7 +2052,7 @@ HIDE_UNDOC_RELATIONS = YES
# set to NO
# The default value is: NO.

HAVE_DOT = NO
HAVE_DOT = YES

# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed
# to run in parallel. When set to 0 doxygen will base this on the number of
Expand Down
17 changes: 8 additions & 9 deletions covariance/covarianceOsc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ covarianceOsc::covarianceOsc(const char* name, const char *file)

TVectorD* osc_baseline = (TVectorD*)infile->Get("osc_baseline");
TVectorD* osc_density = (TVectorD*)infile->Get("osc_density");
double fScale = 1.0;

//KS: Save all necessary information from covariance
for(int io = 0; io < _fNumPar; io++)
Expand All @@ -27,7 +26,7 @@ covarianceOsc::covarianceOsc(const char* name, const char *file)
_fCurrVal[io] = _fPropVal[io] = _fPreFitValue[io];
_fError[io] = (*osc_sigma)(io);

_fIndivStepScale[io] = fScale * (*osc_stepscale)(io);
_fIndivStepScale[io] = (*osc_stepscale)(io);

//KS: Set flat prior
//HW: Might as well set it for everything in case default behaviour changes
Expand Down Expand Up @@ -243,13 +242,13 @@ void covarianceOsc::CheckOrderOfParams() {

std::vector<int> wrongParam;
bool wrongMatrix = false;
if(strcmp( _fNames[0].c_str(),"sin2th_12") != 0 ){wrongParam.push_back(0); wrongMatrix = true;};
if(strcmp( _fNames[1].c_str(),"sin2th_23") != 0 ){wrongParam.push_back(1); wrongMatrix = true;};
if(strcmp( _fNames[2].c_str(),"sin2th_13") != 0 ){wrongParam.push_back(2); wrongMatrix = true;};
if(strcmp( _fNames[3].c_str(),"delm2_12") != 0 ){wrongParam.push_back(3); wrongMatrix = true;};
if(strcmp( _fNames[4].c_str(),"delm2_23") != 0 ){wrongParam.push_back(4); wrongMatrix = true;};
if(strcmp( _fNames[5].c_str(),"delta_cp") != 0 ){wrongParam.push_back(5); wrongMatrix = true;};
if(PerformBetaStudy && strcmp( _fNames[6].c_str(),"beta") != 0 ){wrongParam.push_back(6); wrongMatrix = true;};
if(_fNames[0] != "sin2th_12"){wrongParam.push_back(0); wrongMatrix = true;};
if(_fNames[1] != "sin2th_23"){wrongParam.push_back(1); wrongMatrix = true;};
if(_fNames[2] != "sin2th_13"){wrongParam.push_back(2); wrongMatrix = true;};
if(_fNames[3] != "delm2_12"){wrongParam.push_back(3); wrongMatrix = true;};
if(_fNames[4] != "delm2_23"){wrongParam.push_back(4); wrongMatrix = true;};
if(_fNames[5] != "delta_cp"){wrongParam.push_back(5); wrongMatrix = true;};
if(PerformBetaStudy && _fNames[6] != "beta"){wrongParam.push_back(6); wrongMatrix = true;};

if(wrongMatrix)
{
Expand Down
1 change: 0 additions & 1 deletion covariance/covarianceOsc.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,3 @@ class covarianceOsc : public covarianceBase
/// Enum for special treatment of beta.
int kBeta;
};

5 changes: 3 additions & 2 deletions manager/MaCh3Exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ class MaCh3Exception : public std::exception {
std::string fileName = (lastSlashPos != std::string::npos) ? File.substr(lastSlashPos + 1) : File;

errorMessage = ((Message.empty()) ? "Terminating MaCh3" : Message);

MACH3LOG_ERROR("Find me here: {}::{}", fileName, Line);
// KS: Set logger format where we only have have "information type", line would be confusing
spdlog::set_pattern("[%^%l%$] %v");
MACH3LOG_ERROR("Find me here: {}::{}", fileName, Line);
}

/// @brief Returns the error message associated with this exception.
Expand Down
13 changes: 5 additions & 8 deletions manager/Monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ std::string GetMaCh3Version() {
// Check if the file is opened successfully
if (!versionFile.is_open()) {
MACH3LOG_ERROR("Error: Couldn't open version.h {}", file);
throw;
throw MaCh3Exception(__FILE__, __LINE__);
}

std::string line;
Expand Down Expand Up @@ -100,7 +100,7 @@ void GetOSInfo() {

// ************************
//KS: Simple function retrieving CPU info
void GetCPUInfo(){
void GetCPUInfo() {
// ************************

//KS: Use -m 1 to limit to only one grep because in one computing node there is a lot of CPU which are the same
Expand Down Expand Up @@ -162,7 +162,7 @@ std::string TerminalToString(const char* cmd) {
std::string result;
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
if (!pipe) {
throw std::runtime_error("popen() failed!");
throw MaCh3Exception(__FILE__, __LINE__, "popen() failed!");
}
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
result += buffer.data();
Expand Down Expand Up @@ -259,9 +259,8 @@ int getValue(std::string Type){ //Note: this value is in KB!
}
else
{
std::cerr << "Not supported getValue: " << Type << std::endl;
std::cerr << __FILE__ << ":" << __LINE__ << std::endl;
throw;
MACH3LOG_ERROR("Not supported getValue: {}", Type);
throw MaCh3Exception(__FILE__, __LINE__);
}

return result;
Expand Down Expand Up @@ -293,6 +292,4 @@ void PrintConfig(const YAML::Node& node){
}
}



}
11 changes: 5 additions & 6 deletions mcmc/FitterBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ FitterBase::FitterBase(manager * const man) : fitMan(man) {
stepClock = new TStopwatch;
#ifdef DEBUG
// Fit summary and debug info
debug = fitMan->raw()["General"]["Debug"].as<bool>();
debug = GetFromManager<bool>(fitMan->raw()["General"]["Debug"], false);
#endif

std::string outfile = fitMan->raw()["General"]["OutputFile"].as<std::string>();
Expand Down Expand Up @@ -73,7 +73,7 @@ FitterBase::FitterBase(manager * const man) : fitMan(man) {
syst_llh = nullptr;

TotalNSamples = 0;
fTestLikelihood = GetFromManager<bool>(fitMan->raw()["General"]["Fitter"]["FitTestLikelihood"], false);;
fTestLikelihood = GetFromManager<bool>(fitMan->raw()["General"]["Fitter"]["FitTestLikelihood"], false);
}

// *************************
Expand Down Expand Up @@ -113,12 +113,12 @@ void FitterBase::SaveSettings() {
if (std::getenv("MaCh3_ROOT") == NULL) {
MACH3LOG_ERROR("Need MaCh3_ROOT environment variable");
MACH3LOG_ERROR("Please remember about source bin/setup.MaCh3.sh");
throw;
throw MaCh3Exception(__FILE__ , __LINE__ );
}

if (std::getenv("MACH3") == NULL) {
MACH3LOG_ERROR("Need MACH3 environment variable");
throw;
throw MaCh3Exception(__FILE__ , __LINE__ );
}

std::string header_path = std::string(std::getenv("MACH3"));
Expand Down Expand Up @@ -176,8 +176,7 @@ void FitterBase::PrepareOutput() {
// Check that we have added samples
if (!samples.size()) {
MACH3LOG_CRITICAL("No samples Found! If this is what you want find me here");
MACH3LOG_CRITICAL("{}:{}", __FILE__, __LINE__);
throw;
throw MaCh3Exception(__FILE__ , __LINE__ );
}

// Prepare the output trees
Expand Down
2 changes: 1 addition & 1 deletion mcmc/LikelihoodFit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LikelihoodFit::LikelihoodFit(manager *man) : FitterBase(man) {
// *******************
NPars = 0;
NParsPCA = 0;
fMirroring = true;
fMirroring = GetFromManager<bool>(fitMan->raw()["General"]["Fitter"]["Mirroring"], false);
}


Expand Down
Loading

0 comments on commit 86d7720

Please sign in to comment.