MaCh3  2.8.0
Reference Guide
UmbrellaModule.hpp
Go to the documentation of this file.
1 #pragma once
6 #include "CLI/API/plugin.hpp"
8 #include <vector>
9 #include <string>
11 
12 
14 #include "TSystem.h"
15 #include "TChain.h"
16 #include "TSystemDirectory.h"
18 
19 namespace M3{
20 bool debug_mode = false;
23 struct WindowConfig {
24  std::string name;
26  double center;
27  double width;
28  std::string input_file;
31 };
32 
36  std::vector<WindowConfig> windows;
37  std::string output_file;
38  std::string variable_of_interest;
40  std::string dynamic_pattern;
43  double tolerance;
45 };
46 
53  public:
55  virtual ~UmbrellaModule();
56 
59  MaCh3ArgumentParser* get_parser() override;
60 
63  int Run() override;
64  private:
66  UmbrellaConfig parseYAMLConfig(const std::string &filename);
67  // Gaussian window function
68  double gaussianWindow(double x, double center, double width);
69  // von Mises window function (circular analog of Gaussian)
70  double vonMisesWindow(double x, double center, double kappa);
71  // Generalised Gaussian window allows harsher constraints on the tails of the distribution,
72  // better for controlling windows in highly disfavoured regions
73  double generalisedGaussian2(double x, double mean, double width);
75  double GetMulticanonicalWeightGenGaussian(double deltacp, double mean, double width, double multicanonicalBeta);
76  // A sub calculation for the overlap matrix
77  // Sum of all windows weighted by z values
78  double summedWindowsWeighted(double x,
79  const std::vector<WindowConfig> &windows,
80  const std::vector<double> &z_values);
81  size_t calculateWindowCacheSizeBytes(const std::vector<WindowConfig> &windows,
82  const std::vector<std::vector<double>> &samples);
83  // Precompute all window evaluations once: cache[i][j][s] = window_j evaluated
84  // at samples[i][s]
85  // Memory heavy depending on number of steps/cores/windows
86  std::vector<std::vector<std::vector<double>>> buildWindowCache(const std::vector<WindowConfig> &windows,
87  const std::vector<std::vector<double>> &samples);
88  // Main function to calculate the F matrix from a given set of samples plus weights
89  std::vector<std::vector<double>> calcFmatrix(const std::vector<double> &z_current,
90  const std::vector<WindowConfig> &windows,
91  const std::vector<std::vector<double>> &samples,
92  const std::vector<std::vector<std::vector<double>>> &window_cache);
93  // Z-solver function implementing the fixed point matrix iteration algorithm
94  std::vector<double> zSolver(const std::vector<double> &z_current,
95  const std::vector<WindowConfig> &windows,
96  const std::vector<std::vector<double>> &samples,
97  const std::vector<std::vector<std::vector<double>>> &window_cache,
98  [[maybe_unused]] bool verbose = false,
99  [[maybe_unused]] int *total_lines = nullptr);
101  // Check convergence
102  bool checkConvergence(const std::vector<double> &z_current, const std::vector<double> &z_prev, double tolerance);
103  std::vector<double> getZDiffs(const std::vector<double> &z_current, const std::vector<double> &z_prev);
104  // This implements a check on stalling of the evolution of the window weights. Seems to be a
105  // better definition for convergence that above
106  // moving-average stalled-convergence check on z values
107  bool checkConvergenceStalled(const std::vector<double> &z_current,
108  const std::vector<double> &z_prev,
109  double tolerance);
110  void LoadFiles(std::vector<std::vector<double>>& samples,
111  UmbrellaConfig& config,
112  std::vector<TFile *>& input_files,
113  std::vector<TTree *>& input_trees);
114  void DiagnoseUmbrella(const UmbrellaConfig& config,
115  TFile * output_file,
116  const std::vector<std::vector<double>>& z_evolution,
117  TTree *combined_tree);
118  // Main function to run the umbrella sampling solver
119  void UmbrellaSolver(const std::string &config_file);
120 
121  std::unique_ptr<MaCh3ArgumentParser> m_default_parser;
123 };
124 }
#define _MaCh3_Safe_Include_Start_
KS: Avoiding warning checking for headers.
Definition: Core.h:126
#define _MaCh3_Safe_Include_End_
Module for Umbrella sampling plot analysis.
Extended ArgumentParser with MaCh3-specific functionality.
Definition: m3argparse.hpp:17
Base class for core modules in MaCh3.
Definition: plugin.hpp:41
Module for performing Umbrella sampling.
bool checkConvergence(const std::vector< double > &z_current, const std::vector< double > &z_prev, double tolerance)
A few different convergence checks.
double generalisedGaussian2(double x, double mean, double width)
void UmbrellaSolver(const std::string &config_file)
size_t calculateWindowCacheSizeBytes(const std::vector< WindowConfig > &windows, const std::vector< std::vector< double >> &samples)
std::vector< std::vector< double > > calcFmatrix(const std::vector< double > &z_current, const std::vector< WindowConfig > &windows, const std::vector< std::vector< double >> &samples, const std::vector< std::vector< std::vector< double >>> &window_cache)
std::vector< double > zSolver(const std::vector< double > &z_current, const std::vector< WindowConfig > &windows, const std::vector< std::vector< double >> &samples, const std::vector< std::vector< std::vector< double >>> &window_cache, [[maybe_unused]] bool verbose=false, [[maybe_unused]] int *total_lines=nullptr)
void DiagnoseUmbrella(const UmbrellaConfig &config, TFile *output_file, const std::vector< std::vector< double >> &z_evolution, TTree *combined_tree)
double GetMulticanonicalWeightGenGaussian(double deltacp, double mean, double width, double multicanonicalBeta)
bool checkConvergenceStalled(const std::vector< double > &z_current, const std::vector< double > &z_prev, double tolerance)
UmbrellaPlotModule m_plotModule
void LoadFiles(std::vector< std::vector< double >> &samples, UmbrellaConfig &config, std::vector< TFile * > &input_files, std::vector< TTree * > &input_trees)
int Run() override
Execute the Umbrella sampling.
std::unique_ptr< MaCh3ArgumentParser > m_default_parser
std::vector< double > getZDiffs(const std::vector< double > &z_current, const std::vector< double > &z_prev)
double vonMisesWindow(double x, double center, double kappa)
virtual ~UmbrellaModule()
Destructor.
double gaussianWindow(double x, double center, double width)
UmbrellaConfig parseYAMLConfig(const std::string &filename)
YAML-based config parser using yaml-cpp library.
MaCh3ArgumentParser * get_parser() override
Get the argument parser for this module.
double summedWindowsWeighted(double x, const std::vector< WindowConfig > &windows, const std::vector< double > &z_values)
std::vector< std::vector< std::vector< double > > > buildWindowCache(const std::vector< WindowConfig > &windows, const std::vector< std::vector< double >> &samples)
Module for Umbrella sampling plot analysis.
Main namespace for MaCh3 software.
bool debug_mode
Plugin interface and registration macros for MaCh3.
std::string output_file
std::string variable_of_interest
std::vector< WindowConfig > windows
std::string dynamic_pattern
std::string input_file
M3::BiasFunction umbrellaBiasFunction