15 MACH3LOG_ERROR(
"MCMC chain length must be at least 10 steps, otherwise this will result in a floating point exception.");
19 AnnealTemp = GetFromManager<double>(
fitMan->
raw()[
"General"][
"MCMC"][
"AnnealTemp"], -999, __FILE__ , __LINE__);
93 if (syst->GetDoAdaption())
95 auto adaptive_handler = syst->GetAdaptiveHandler();
96 adaptive_handler->SaveAdaptiveToFile(adaptive_handler->GetOutFileName(), syst->GetName(),
true);
129 int originalErrorLevel = gErrorIgnoreLevel;
130 gErrorIgnoreLevel = kFatal;
144 gErrorIgnoreLevel = originalErrorLevel;
154 for (
size_t i = 0; i <
samples.size(); ++i) {
159 cov->PrintPreFitCurrPropValues();
164 debugFile <<
"\n-------------------------------------------------------" << std::endl;
177 TFile *infile =
M3::Open(FitName,
"READ", __FILE__, __LINE__);
178 TTree *posts = infile->Get<TTree>(
"posteriors");
179 unsigned int step_val = 0;
181 posts->SetBranchAddress(
"step", &step_val);
182 posts->GetEntry(posts->GetEntries() - 1);
186 for (
unsigned int i = 0; i <
systematics.size(); ++i) {
201 if (syst->GetDoAdaption()){
202 syst->UpdateAdaptiveCovariance();
211 const double fRandom =
random->Rndm();
214 debugFile <<
" logLProp: " <<
logLProp <<
" logLCurr: " <<
logLCurr <<
" acc_prob: " << acc_prob <<
" fRandom: " << fRandom << std::endl;
217 if (fRandom > acc_prob)
Base class for implementing fitting algorithms.
std::unique_ptr< TRandom3 > random
Random number.
double logLProp
proposed likelihood
void ProcessMCMC()
Process MCMC output.
int accCount
counts accepted steps
void SaveOutput()
Save output and close files.
void SaveSettings()
Save the settings that the MCMC was run with.
unsigned int step
current state
void PrepareOutput()
Prepare the output file.
virtual void StartFromPreviousFit(const std::string &FitName)
Allow to start from previous fit/chain.
std::string AlgorithmName
Name of fitting algorithm that is being used.
std::vector< SampleHandlerInterface * > samples
Sample holder.
double stepTime
Time of single step.
Manager * fitMan
The manager for configuration handling.
unsigned int stepStart
step start, by default 0 if we start from previous chain then it will be different
std::unique_ptr< TStopwatch > stepClock
tells how long single step/fit iteration took
double logLCurr
current likelihood
int auto_save
auto save every N steps
TTree * outTree
Output tree with posteriors.
void SanitiseInputs()
Remove obsolete memory and make other checks before fit starts.
std::vector< ParameterHandlerBase * > systematics
Systematic holder.
std::unique_ptr< MulticanonicalMCMCHandler > multicanonicalHandler
multicanonical handler for umbrella sampling
MCMCBase(Manager *const fitMan)
Constructor.
bool anneal
simulated annealing
void RunMCMC() final
Actual implementation of MCMC fitting algorithm.
unsigned int chainLength
number of steps in chain
void StartFromPreviousFit(const std::string &FitName) final
Allow to start from previous fit/chain.
void AcceptStep()
Accept a step.
double AnnealTemp
simulated annealing temperature
bool out_of_bounds
Do we reject based on hitting boundaries in systs.
bool IsStepAccepted(const double acc_prob)
Is step accepted?
void DoMCMCStep()
The full StartStep->DoStep->EndStep chain.
void PreStepProcess()
Actions before step proposal [start stopwatch].
bool multicanonical
multi-canonical method toggle on/off
virtual void ProposeStep()=0
Propose a step.
void PrintProgress(const bool StepsPrint=true)
Print the progress.
virtual void DoStep()=0
The MCMC step proposal and acceptance.
void PostStepProcess()
Actions after step proposal [end stopwatch, fill tree].
void AdaptiveStep()
Adaptive MCMC step.
Custom exception class used throughout MaCh3.
The manager class is responsible for managing configurations and settings.
YAML::Node const & raw() const
Return config.
Base class for handling systematic uncertainty parameters.
TFile * Open(const std::string &Name, const std::string &Type, const std::string &File, const int Line)
Opens a ROOT file with the given name and mode.