Public Member Functions | Private Attributes | List of all members
ana::MCMCSample Class Reference

A single MCMC sample. More...

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-11-28/CAFAna/Fit/MCMCSample.h"

Public Member Functions

 MCMCSample (double LL, const std::vector< double > &diagVals, const std::vector< double > &entryVals, const std::vector< std::string > &diagBranchNames, const std::vector< const IFitVar * > &vars, const std::vector< const ISyst * > &systs)
 
 MCMCSample (const TMap &map, const std::vector< const ana::IFitVar * > &vars, const std::vector< const ana::ISyst * > &systs)
 
 MCMCSample (const MCMCSample &other)=default
 
 MCMCSample (MCMCSample &&other)=default
 
double DiagnosticVal (const std::string &brName) const
 
const std::vector< std::string > & DiagnosticValNames () const
 
double LL () const
 
const std::vector< const ana::ISyst * > & Systs () const
 
std::unique_ptr< TMap > ToTMap () const
 Mostly for serialization. More...
 
double Val (const ana::IFitVar *var) const
 
double Val (const ana::ISyst *syst) const
 
const std::vector< const ana::IFitVar * > & Vars () const
 

Private Attributes

std::vector< std::stringfDiagBranches
 
std::vector< const ana::IFitVar * > fVars
 
std::vector< const ana::ISyst * > fSysts
 
std::vector< double > fVals
 

Detailed Description

A single MCMC sample.

Definition at line 14 of file MCMCSample.h.

Constructor & Destructor Documentation

ana::MCMCSample::MCMCSample ( double  LL,
const std::vector< double > &  diagVals,
const std::vector< double > &  entryVals,
const std::vector< std::string > &  diagBranchNames,
const std::vector< const IFitVar * > &  vars,
const std::vector< const ISyst * > &  systs 
)

Definition at line 9 of file MCMCSample.cxx.

References om::cerr, allTimeWatchdog::endl, fDiagBranches, fSysts, fVals, and fVars.

12  : fDiagBranches(std::move(diagBranchNames)), fVars(std::move(vars)), fSysts(std::move(systs))
13  {
14  if(diagVals.size() != fDiagBranches.size() || entryVals.size() != fVars.size() + fSysts.size())
15  {
16  std::cerr << "MCMCSample::MCMCSample(): branch sizes don't match." << std::endl;
17  abort();
18  }
19  fVals.reserve(1 + diagVals.size() + entryVals.size());
20  fVals.push_back(LL);
21  fVals.insert(fVals.end(), diagVals.begin(), diagVals.end());
22  fVals.insert(fVals.end(), entryVals.begin(), entryVals.end());
23  }
std::vector< std::string > fDiagBranches
Definition: MCMCSample.h:66
std::vector< SystGroupDef > systs
Definition: syst_header.h:385
std::vector< const ana::IFitVar * > fVars
Definition: MCMCSample.h:67
OStream cerr
Definition: OStream.cxx:7
const std::map< std::pair< std::string, std::string >, Variable > vars
std::vector< double > fVals
Definition: MCMCSample.h:70
std::vector< const ana::ISyst * > fSysts
Definition: MCMCSample.h:68
double LL() const
Definition: MCMCSample.h:38
ana::MCMCSample::MCMCSample ( const TMap &  map,
const std::vector< const ana::IFitVar * > &  vars,
const std::vector< const ana::ISyst * > &  systs 
)

Definition at line 26 of file MCMCSample.cxx.

References distance(), fDiagBranches, srt_file_template::find_if, fVals, genie::utils::xml::GetString(), string, and registry_explorer::v.

28  {
29  fVals.resize(map.GetSize());
30  std::size_t diagBranchSize = map.GetSize() - vars.size() - systs.size() - 1;
31 
32  for (const auto &mapPair : map)
33  {
34  auto pair = dynamic_cast<TPair *>(mapPair);
35  std::string name(dynamic_cast<TObjString *>(pair->Key())->GetString());
36  double value = dynamic_cast<TParameter<double> *>(pair->Value())->GetVal();
37 
38  auto itVar = std::find_if(vars.begin(), vars.end(), [&name](const IFitVar* v){ return v->ShortName() == name; });
39  auto itSyst = (itVar == vars.end()) ? systs.end() : std::find_if(systs.begin(), systs.end(), [&name](const ISyst* s){ return s->ShortName() == name; });
40 
41  // find out whether this is a Var, a Syst, or diagnostic branch
42  if (itVar != vars.end())
43  fVals[1 + diagBranchSize + std::distance(vars.begin(), itVar)] = value;
44  else if (itSyst != systs.end())
45  fVals[1 + diagBranchSize + vars.size() + std::distance(systs.begin(), itSyst)] = value;
46  else if (name == "logprob")
47  fVals[0] = value;
48  else
49  {
50  fVals[1 + fDiagBranches.size()] = value;
51  fDiagBranches.push_back(name);
52  }
53  }
54  }
const XML_Char * name
Definition: expat.h:151
std::vector< std::string > fDiagBranches
Definition: MCMCSample.h:66
std::vector< SystGroupDef > systs
Definition: syst_header.h:385
unsigned distance(const T &t1, const T &t2)
const XML_Char * s
Definition: expat.h:262
const XML_Char int const XML_Char * value
Definition: expat.h:331
const std::map< std::pair< std::string, std::string >, Variable > vars
string GetString(xmlDocPtr xml_doc, string node_path)
std::vector< double > fVals
Definition: MCMCSample.h:70
enum BeamMode string
ana::MCMCSample::MCMCSample ( const MCMCSample other)
default
ana::MCMCSample::MCMCSample ( MCMCSample &&  other)
default

Member Function Documentation

double ana::MCMCSample::DiagnosticVal ( const std::string brName) const

Definition at line 57 of file MCMCSample.cxx.

References ana::assert(), distance(), fDiagBranches, fVals, and it.

Referenced by ToTMap().

58  {
59  auto it = std::find(fDiagBranches.begin(), fDiagBranches.end(), brName);
60  assert(it != fDiagBranches.end() && ("This MCMCSample does not contain a value called '" + brName + "'").c_str());
61 
62  return fVals[1 + std::distance(fDiagBranches.begin(), it)];
63  }
std::vector< std::string > fDiagBranches
Definition: MCMCSample.h:66
set< int >::iterator it
unsigned distance(const T &t1, const T &t2)
assert(nhit_max >=nhit_nbins)
std::vector< double > fVals
Definition: MCMCSample.h:70
const std::vector<std::string>& ana::MCMCSample::DiagnosticValNames ( ) const
inline

Definition at line 32 of file MCMCSample.h.

References fDiagBranches.

33  {
34  return fDiagBranches;
35  }
std::vector< std::string > fDiagBranches
Definition: MCMCSample.h:66
double ana::MCMCSample::LL ( ) const
inline

Definition at line 38 of file MCMCSample.h.

References fVals.

39  {
40  return fVals[0];
41  }
std::vector< double > fVals
Definition: MCMCSample.h:70
const std::vector<const ana::ISyst *>& ana::MCMCSample::Systs ( ) const
inline

Definition at line 44 of file MCMCSample.h.

References fSysts, ToTMap(), Val(), and PandAna.Demos.tute_pid_validation::var.

45  {
46  return fSysts;
47  }
std::vector< const ana::ISyst * > fSysts
Definition: MCMCSample.h:68
std::unique_ptr< TMap > ana::MCMCSample::ToTMap ( ) const

Mostly for serialization.

Definition at line 66 of file MCMCSample.cxx.

References DiagnosticVal(), fDiagBranches, fSysts, fVals, fVars, runNovaSAM::ret, registry_explorer::v, and Val().

Referenced by Systs().

67  {
68  auto ret = std::make_unique<TMap>();
69  ret->Add(new TObjString("logprob"), new TParameter<double>("", fVals[0]));
70 
71  for (const auto & brName : fDiagBranches)
72  ret->Add(new TObjString(brName.c_str()), new TParameter<double>("", DiagnosticVal(brName)));
73  for (const auto & v : fVars)
74  ret->Add(new TObjString(v->ShortName().c_str()), new TParameter<double>("", Val(v)));
75  for (const auto & s : fSysts)
76  ret->Add(new TObjString(s->ShortName().c_str()), new TParameter<double>("", Val(s)));
77 
78  return std::move(ret);
79  }
std::vector< std::string > fDiagBranches
Definition: MCMCSample.h:66
std::vector< const ana::IFitVar * > fVars
Definition: MCMCSample.h:67
double DiagnosticVal(const std::string &brName) const
Definition: MCMCSample.cxx:57
const XML_Char * s
Definition: expat.h:262
double Val(const ana::IFitVar *var) const
Definition: MCMCSample.cxx:82
std::vector< double > fVals
Definition: MCMCSample.h:70
std::vector< const ana::ISyst * > fSysts
Definition: MCMCSample.h:68
double ana::MCMCSample::Val ( const ana::IFitVar var) const

Definition at line 82 of file MCMCSample.cxx.

References ana::assert(), distance(), fDiagBranches, fVals, fVars, it, ana::IFitVar::ShortName(), and PandAna.Demos.tute_pid_validation::var.

Referenced by Systs(), and ToTMap().

83  {
84  auto it = std::find(fVars.begin(), fVars.end(), var);
85  assert(it != fVars.end() && ("This MCMCSample does not contain Var: '" + var->ShortName() + "'").c_str());
86 
87  return fVals[1 + fDiagBranches.size() + std::distance(fVars.begin(), it)];
88  }
std::vector< std::string > fDiagBranches
Definition: MCMCSample.h:66
set< int >::iterator it
std::vector< const ana::IFitVar * > fVars
Definition: MCMCSample.h:67
unsigned distance(const T &t1, const T &t2)
const std::string & ShortName() const
Definition: IFitVar.h:36
assert(nhit_max >=nhit_nbins)
std::vector< double > fVals
Definition: MCMCSample.h:70
double ana::MCMCSample::Val ( const ana::ISyst syst) const

Definition at line 91 of file MCMCSample.cxx.

References ana::assert(), distance(), fDiagBranches, fSysts, fVals, fVars, it, and ana::ISyst::ShortName().

92  {
93  auto it = std::find(fSysts.begin(), fSysts.end(), syst);
94  assert(it != fSysts.end() && ("This MCMCSample does not contain Syst: '" + syst->ShortName() + "'").c_str());
95 
96  return fVals[1 + fDiagBranches.size() + fVars.size() + std::distance(fSysts.begin(), it)];
97  }
std::vector< std::string > fDiagBranches
Definition: MCMCSample.h:66
set< int >::iterator it
virtual const std::string & ShortName() const final
The name printed out to the screen.
Definition: ISyst.h:27
std::vector< const ana::IFitVar * > fVars
Definition: MCMCSample.h:67
unsigned distance(const T &t1, const T &t2)
assert(nhit_max >=nhit_nbins)
std::vector< double > fVals
Definition: MCMCSample.h:70
std::vector< const ana::ISyst * > fSysts
Definition: MCMCSample.h:68
const std::vector<const ana::IFitVar *>& ana::MCMCSample::Vars ( ) const
inline

Definition at line 60 of file MCMCSample.h.

References fVars.

61  {
62  return fVars;
63  }
std::vector< const ana::IFitVar * > fVars
Definition: MCMCSample.h:67

Member Data Documentation

std::vector<std::string> ana::MCMCSample::fDiagBranches
private

Definition at line 66 of file MCMCSample.h.

Referenced by DiagnosticVal(), DiagnosticValNames(), MCMCSample(), ToTMap(), and Val().

std::vector<const ana::ISyst *> ana::MCMCSample::fSysts
private

Definition at line 68 of file MCMCSample.h.

Referenced by MCMCSample(), Systs(), ToTMap(), and Val().

std::vector<double> ana::MCMCSample::fVals
private

Definition at line 70 of file MCMCSample.h.

Referenced by DiagnosticVal(), LL(), MCMCSample(), ToTMap(), and Val().

std::vector<const ana::IFitVar *> ana::MCMCSample::fVars
private

Definition at line 67 of file MCMCSample.h.

Referenced by MCMCSample(), ToTMap(), Val(), and Vars().


The documentation for this class was generated from the following files: