Skip to content

Commit

Permalink
actually move most of imeplemtniton to yaml helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
KSkwarczynski committed Oct 9, 2024
1 parent 5929cdb commit b640ceb
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 57 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/CDImage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ name: Image CD
on:
push:
branches: [ develop ]
release:
types: [ published ]
push:
tags:
- 'v*'

permissions:
contents: read
Expand Down Expand Up @@ -40,16 +41,16 @@ jobs:

- name: Build Docker image
run: |
if [ "${{ github.event_name }}" == 'release' ]; then
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
if [ "${{ github.ref_type }}" == 'tag' ]; then
docker build . --file ${{ matrix.file }} --tag ghcr.io/${{ github.repository_owner }}/mach3:${{ matrix.os }}${{ github.ref_name }} --build-arg MACH3_VERSION=${{ github.ref_name }}
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.os }}v${{ github.event.release.tag_name }}
if [ "${{ github.ref_type }}" == 'tag' ]; then
docker push ghcr.io/${{ github.repository_owner }}/mach3:${{ matrix.os }}${{ github.ref_name }}
else
docker push ghcr.io/${{ github.repository_owner }}/mach3:${{ matrix.tag_latest }}
fi
1 change: 0 additions & 1 deletion covariance/covarianceBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,6 @@ void covarianceBase::SaveUpdatedMatrixConfig() {
{
//KS: Feel free to update it, if you need updated prefit value etc
param["Systematic"]["StepScale"]["MCMC"] = std::round(_fIndivStepScale[i] * 100.0) / 100.0; // Round to 2 decimal places

i++;
}
// Save the modified node to a file
Expand Down
49 changes: 49 additions & 0 deletions manager/YamlHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,52 @@ inline YAML::Node TMacroToYAML(const TMacro& macro) {
return yaml_node;
}

// **********************
/// @brief Overrides the configuration settings based on provided arguments.
///
/// This function allows you to set configuration options in a nested YAML node.
/// It accepts two, three, or four string arguments:
/// - For two arguments, the first argument is a key, and the second is the value.
/// - For three arguments, the first two arguments are keys (for nested configuration), and the third is the value.
/// - For four arguments, the first three arguments are keys (for deeper nested configuration), and the fourth is the value.
///
/// @param node YAML node that will be modified
/// @param args The arguments to override the configuration.
/// - When two arguments are provided, they represent the key and value, respectively.
/// - When three arguments are provided, they represent two keys and a value.
/// - When four arguments are provided, they represent three keys and a value.
///
/// @note Example usage:
/// @code
/// OverrideConfig(config, "General", "OutputFile", "Wooimbouttamakeanameformyselfere.root");
/// @endcode
template <typename... Args>
void OverrideConfig(YAML::Node& node, Args... args) {
// **********************
static_assert(sizeof...(args) == 2 || sizeof...(args) == 3 || sizeof...(args) == 4,
"OverrideConfig accepts either 2, 3, or 4 arguments.");

auto args_tuple = std::make_tuple(args...); // Create a tuple from the parameter pack

if constexpr (sizeof...(args) == 2) {
std::string blarb1 = std::get<0>(args_tuple); // First argument
std::string result = std::get<1>(args_tuple); // Second argument

node[blarb1] = result;
}
else if constexpr (sizeof...(args) == 3) {
std::string blarb1 = std::get<0>(args_tuple); // First argument
std::string blarb2 = std::get<1>(args_tuple); // Second argument
std::string result = std::get<2>(args_tuple); // Third argument

node[blarb1][blarb2] = result;
}
else if constexpr (sizeof...(args) == 4) {
std::string blarb1 = std::get<0>(args_tuple); // First argument
std::string blarb2 = std::get<1>(args_tuple); // Second argument
std::string blarb3 = std::get<2>(args_tuple); // Third argument
std::string result = std::get<3>(args_tuple); // Fourth argument

node[blarb1][blarb2][blarb3] = result;
}
}
34 changes: 4 additions & 30 deletions manager/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,41 +40,15 @@ class manager {
inline std::string GetName()const {return "Manager";};

/// @brief Overrides the configuration settings based on provided arguments.
///
/// This function allows you to set configuration options for the manager.
/// It accepts either two or three string arguments:
/// - For two arguments, the first argument is a key, and the second is the value.
/// - For three arguments, the first two arguments are keys, and the third is the value.
///
/// @param args The arguments to override the configuration.
/// - When two arguments are provided, they represent the key and value, respectively.
/// - When three arguments are provided, they represent two keys and a value.
///
/// @note Example usage:
/// @code
/// FitManager->OverrideConfig("General", "OutputFile", "Wooimbouttamakeanameformyselfere.root");
/// FitManager->OverrideSettings("General", "OutputFile", "Wooimbouttamakeanameformyselfere.root");
/// @endcode
template <typename... Args>
void OverrideConfig(Args... args) {
static_assert(sizeof...(args) == 2 || sizeof...(args) == 3,
"OverrideConfig accepts either 2 or 3 arguments.");

auto args_tuple = std::make_tuple(args...); // Create a tuple from the parameter pack

if constexpr (sizeof...(args) == 2) {
std::string blarb1 = std::get<0>(args_tuple); // First argument
std::string result = std::get<1>(args_tuple); // Second argument

config[blarb1] = result;
}
else if constexpr (sizeof...(args) == 3) {
std::string blarb1 = std::get<0>(args_tuple); // First argument
std::string blarb2 = std::get<1>(args_tuple); // Second argument
std::string result = std::get<2>(args_tuple); // Third argument

config[blarb1][blarb2] = result;
}
void OverrideSettings(Args&&... args) {
OverrideConfig(config, std::forward<Args>(args)...);
}

private:
/// The YAML node containing the configuration data.
YAML::Node config;
Expand Down
8 changes: 4 additions & 4 deletions mcmc/SampleSummary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ SampleSummary::SampleSummary(const int n_Samples, const std::string &Filename, s
RandomHist->GetYaxis()->SetTitle(ss.str().c_str());
RandomHist->SetLineWidth(2);
}
else RandomHist = NULL;
else RandomHist = nullptr;

for (_int_ i = 0; i < nSamples; ++i)
{
Expand Down Expand Up @@ -166,7 +166,7 @@ SampleSummary::SampleSummary(const int n_Samples, const std::string &Filename, s

DoByModePlots = false;
MeanHist_ByMode = NULL;
PosteriorHist_ByMode = NULL;
PosteriorHist_ByMode = nullptr;

nModelParams = 0;

Expand All @@ -192,7 +192,7 @@ SampleSummary::~SampleSummary() {
if(lnLDrawHist != NULL) delete lnLDrawHist;
if(lnLFlucHist != NULL) delete lnLFlucHist;
if(lnLDrawHistRate != NULL) delete lnLDrawHistRate;
if(RandomHist != NULL) delete RandomHist;
if(RandomHist != nullptr) delete RandomHist;

if(lnLFlucHist_ProjectX != NULL) delete lnLFlucHist_ProjectX;
if(DoByModePlots)
Expand All @@ -204,7 +204,7 @@ SampleSummary::~SampleSummary() {
{
for (int k = 1; k <= maxBins[i]; ++k)
{
if(PosteriorHist_ByMode[i][j][k] != NULL) delete PosteriorHist_ByMode[i][j][k];
if(PosteriorHist_ByMode[i][j][k] != nullptr) delete PosteriorHist_ByMode[i][j][k];
}
delete[] PosteriorHist_ByMode[i][j];
if(MeanHist_ByMode[i][j] != NULL) delete MeanHist_ByMode[i][j];
Expand Down
28 changes: 12 additions & 16 deletions mcmc/SampleSummary.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
#pragma once

// C++ includes
#include <iostream>
#include <vector>

// ROOT include
#include "TH1D.h"
#include "TH2D.h"
#include "TH3D.h"
#include "TH2Poly.h"
#include "THStack.h"
#include "TStyle.h"
#include "TCanvas.h"
#include "TApplication.h"

// MaCh3 includes
#include "samplePDF/samplePDFBase.h"
#include "mcmc/StatisticalUtils.h"
Expand Down Expand Up @@ -75,11 +61,18 @@ class SampleSummary {
/// @brief KS: Study how correlated are sample or kinematic bins
inline void StudyKinematicCorrelations();

// Helper functions to change titles etc of finished plots, calculate pvalues etc
/// @brief Make the cut LLH histogram
inline void MakeCutLLH();
// Make the 1D cut distribution and give the 1D p-value
inline void MakeCutLLH1D(TH1D *Histogram, double llh_ref = -999);
/// @brief Make the 2D cut distribution and give the 2D p-value
inline void MakeCutLLH2D(TH2D *Histogram);
/// @brief Make the 1D Event Rate Hist
inline void MakeCutEventRate(TH1D *Histogram, const double DataRate);
/// @brief Make the fluctuated histograms (2D and 1D) for the chi2s
/// Essentially taking the MCMC draws and calculating their LLH to the Posterior predictive distribution
/// And additionally taking the data histogram and calculating the LLH to the predictive distribution
/// Additionally we calculate the chi2 of the draws (fluctuated) of the MC with the prior/posterior predictive and plot it vs the chi2 from the draws of MCMC and the data
inline void MakeChi2Hists();

/// @brief Check the length of samples agrees
Expand Down Expand Up @@ -170,9 +163,11 @@ class SampleSummary {
TH1D **DataHist_ProjectY;
/// The nominal histogram for the selection
TH2Poly **NominalHist;
// The w2 histograms
/// Pointer to the w2 histograms (for nominal values).
TH2Poly **W2NomHist;
/// Pointer to the w2 histograms (for mean values).
TH2Poly **W2MeanHist;
/// Pointer to the w2 histograms (for mode values).
TH2Poly **W2ModeHist;

/// The histogram containing the lnL for each throw
Expand Down Expand Up @@ -326,6 +321,7 @@ class SampleSummary {
bool DoByModePlots;
/// The posterior predictive distribution in pmu cosmu using the mean
TH2Poly ***MeanHist_ByMode;
/// Histogram which corresponds to each bin in the sample's th2poly
TH1D ****PosteriorHist_ByMode;

/// Pointer to samplePDF object, mostly used to get sample names, binning etc.
Expand Down

0 comments on commit b640ceb

Please sign in to comment.