15 MACH3LOG_ERROR(
"MCMC chain length must be at least 10 steps, otherwise this will result in a floating point exception.");
71 if (syst->GetDoAdaption())
73 auto adaptive_handler = syst->GetAdaptiveHandler();
74 adaptive_handler->SaveAdaptiveToFile(adaptive_handler->GetOutFileName(), syst->GetName(),
true);
107 int originalErrorLevel = gErrorIgnoreLevel;
108 gErrorIgnoreLevel = kFatal;
122 gErrorIgnoreLevel = originalErrorLevel;
132 for (
size_t i = 0; i <
samples.size(); ++i) {
137 cov->PrintNominalCurrProp();
142 debugFile <<
"\n-------------------------------------------------------" << std::endl;
155 TFile *infile =
M3::Open(FitName,
"READ", __FILE__, __LINE__);
156 TTree *posts = infile->Get<TTree>(
"posteriors");
157 unsigned int step_val = 0;
159 posts->SetBranchAddress(
"step", &step_val);
160 posts->GetEntry(posts->GetEntries() - 1);
164 for (
unsigned int i = 0; i <
systematics.size(); ++i)
181 if (syst->GetDoAdaption()){
182 syst->UpdateAdaptiveCovariance();
191 const double fRandom =
random->Rndm();
194 debugFile <<
" logLProp: " <<
logLProp <<
" logLCurr: " <<
logLCurr <<
" acc_prob: " << acc_prob <<
" fRandom: " << fRandom << std::endl;
197 if (fRandom > acc_prob)
Base class for implementing fitting algorithms.
std::unique_ptr< TRandom3 > random
Random number.
std::vector< SampleHandlerBase * > samples
Sample holder.
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.
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.
void RunMCMC() override
Actual implementation of MCMC fitting algorithm.
MCMCBase(Manager *const fitMan)
Constructor.
bool anneal
simulated annealing
unsigned int chainLength
number of steps in chain
void AcceptStep()
Accept a step.
double AnnealTemp
simulated annealing temperature
void StartFromPreviousFit(const std::string &FitName) override
Allow to start from previous fit/chain.
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].
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 responsible for handling of systematic error parameters. Capable of using PCA or using ada...
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.