Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ana::MultiExperiment Class Reference

Combine multiple component experiments. More...

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N21-04-14/CAFAna/Experiment/MultiExperiment.h"

Inheritance diagram for ana::MultiExperiment:
ana::IExperiment

Public Member Functions

 MultiExperiment (std::vector< const IExperiment * > expts={})
 
void Add (const IExperiment *expt)
 
virtual double ChiSq (osc::IOscCalcAdjustable *osc, const SystShifts &syst=SystShifts::Nominal()) const override
 
const std::vector< const IExperiment * > & GetExperiments () const
 
stan::math::var LogLikelihood (osc::IOscCalcAdjustableStan *osc, const SystShifts &syst) const override
 Sum up log-likelihoods of sub-expts. More...
 
void SetSystCorrelations (int idx, const std::vector< std::pair< const ISyst *, const ISyst * >> &corrs)
 
void Reset () const override
 
virtual void SaveTo (TDirectory *dir, const std::string &name) const override
 

Static Public Member Functions

static std::unique_ptr< MultiExperimentLoadFrom (TDirectory *dir, const std::string &name)
 

Protected Member Functions

SystShifts ApplySystCorrs (const SystShifts &shiftsIn, const std::vector< std::pair< const ISyst *, const ISyst * >> &corrs) const
 Get a new SystShifts, applying the specified correlations to it. More...
 

Protected Attributes

std::vector< const IExperiment * > fExpts
 
std::vector< std::vector< std::pair< const ISyst *, const ISyst * > > > fSystCorrelations
 

Detailed Description

Combine multiple component experiments.

Definition at line 11 of file MultiExperiment.h.

Constructor & Destructor Documentation

ana::MultiExperiment::MultiExperiment ( std::vector< const IExperiment * >  expts = {})
inline

Definition at line 14 of file MultiExperiment.h.

References fExpts, and fSystCorrelations.

Referenced by LoadFrom().

14  {}) : fExpts(expts)
15  {
16  fSystCorrelations.resize(expts.size());
17  }
std::vector< const IExperiment * > fExpts
std::vector< std::vector< std::pair< const ISyst *, const ISyst * > > > fSystCorrelations

Member Function Documentation

void ana::MultiExperiment::Add ( const IExperiment expt)
inline

Definition at line 19 of file MultiExperiment.h.

References ChiSq(), fExpts, fSystCorrelations, and ana::SystShifts::Nominal().

20  {
21  fExpts.push_back( expt );
22  fSystCorrelations.resize( fExpts.size() );
23  }
std::vector< const IExperiment * > fExpts
std::vector< std::vector< std::pair< const ISyst *, const ISyst * > > > fSystCorrelations
expt
Definition: demo5.py:34
SystShifts ana::MultiExperiment::ApplySystCorrs ( const SystShifts shiftsIn,
const std::vector< std::pair< const ISyst *, const ISyst * >> &  corrs 
) const
protected

Get a new SystShifts, applying the specified correlations to it.

Definition at line 20 of file MultiExperiment.cxx.

References ana::SystShifts::GetShift(), ana::SystShifts::HasStan(), it, ana::SystShifts::RemoveShift(), and ana::SystShifts::SetShift().

Referenced by ChiSq(), GetExperiments(), and LogLikelihood().

22  {
23  // Make a local copy we're going to rewrite into the terms this
24  // sub-experiment will accept.
25  SystShifts localShifts = shiftsIn;
26  for(auto it: corrs)
27  {
28  // We're mapping prim -> sec
29  const ISyst* prim = it.first;
30  const ISyst* sec = it.second;
31  if(shiftsIn.HasStan(prim) || shiftsIn.GetShift<double>(prim) != 0)
32  {
33  // sec can be unset, which means there's no representation needed
34  // of prim in the sub-experiment.
35  if(sec)
36  {
37  if (shiftsIn.HasStan(prim))
38  localShifts.SetShift(sec, shiftsIn.GetShift<stan::math::var>(prim));
39  else
40  localShifts.SetShift(sec, shiftsIn.GetShift<double>(prim));
41  }
42 
43  // We've either translated or discarded prim, so drop it here.
44  localShifts.RemoveShift(prim);
45  }
46  }
47 
48  return localShifts;
49  }
set< int >::iterator it
var_value< double > var
Definition: StanTypedefs.h:14
double ana::MultiExperiment::ChiSq ( osc::IOscCalcAdjustable osc,
const SystShifts syst = SystShifts::Nominal() 
) const
overridevirtual

Reimplemented from ana::IExperiment.

Definition at line 52 of file MultiExperiment.cxx.

References ApplySystCorrs(), fExpts, fSystCorrelations, runNovaSAM::ret, and SetSystCorrelations().

Referenced by Add(), and MakeSurface().

54  {
55  double ret = 0;
56  for(unsigned int n = 0; n < fExpts.size(); ++n){
57  // Don't waste time fiddling with the systematics if for sure there's
58  // nothing to do.
59  if(fSystCorrelations[n].empty())
60  ret += fExpts[n]->ChiSq(osc, syst);
61  else
62  ret += fExpts[n]->ChiSq(osc, ApplySystCorrs(syst, fSystCorrelations[n]));
63  }
64  return ret;
65  }
std::vector< const IExperiment * > fExpts
std::vector< std::vector< std::pair< const ISyst *, const ISyst * > > > fSystCorrelations
std::void_t< T > n
virtual double ChiSq(osc::IOscCalcAdjustable *osc, const SystShifts &syst=SystShifts::Nominal()) const override
SystShifts ApplySystCorrs(const SystShifts &shiftsIn, const std::vector< std::pair< const ISyst *, const ISyst * >> &corrs) const
Get a new SystShifts, applying the specified correlations to it.
const std::vector<const IExperiment*>& ana::MultiExperiment::GetExperiments ( ) const
inline

Definition at line 28 of file MultiExperiment.h.

References ApplySystCorrs(), dir, fExpts, compare_h5_caf::idx, LoadFrom(), LogLikelihood(), Reset(), SaveTo(), SetSystCorrelations(), and string.

28 { return fExpts; }
std::vector< const IExperiment * > fExpts
std::unique_ptr< MultiExperiment > ana::MultiExperiment::LoadFrom ( TDirectory *  dir,
const std::string name 
)
static

Definition at line 150 of file MultiExperiment.cxx.

References ana::assert(), dir, genie::utils::style::Format(), MECModelEnuComparisons::i, ana::LoadFrom< IExperiment >(), MultiExperiment(), runNovaSAM::release, string, and cvnie::subdir.

Referenced by GetExperiments().

151  {
152  dir = dir->GetDirectory(name.c_str()); // switch to subdir
153  assert(dir);
154 
155  TObjString* ptag = (TObjString*)dir->Get("type");
156  assert(ptag);
157  assert(ptag->GetString() == "MultiExperiment");
158  delete ptag;
159 
160  std::vector<const IExperiment*> expts;
161 
162  for(int i = 0; ; ++i){
163  const std::string subname = TString::Format("expt%d", i).Data();
164  TDirectory* subdir = dir->GetDirectory(subname.c_str());
165  if(!subdir) break;
166  delete subdir;
167 
168  expts.push_back(ana::LoadFrom<IExperiment>(dir, name).release());
169  }
170 
171  assert(!expts.empty());
172 
173  delete dir;
174 
175  return std::unique_ptr<MultiExperiment>(new MultiExperiment(expts));
176  }
const XML_Char * name
Definition: expat.h:151
subdir
Definition: cvnie.py:7
TDirectory * dir
Definition: macro.C:5
assert(nhit_max >=nhit_nbins)
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
std::unique_ptr< IExperiment > LoadFrom< IExperiment >(TDirectory *dir, const std::string &label)
Definition: IExperiment.cxx:16
MultiExperiment(std::vector< const IExperiment * > expts={})
enum BeamMode string
stan::math::var ana::MultiExperiment::LogLikelihood ( osc::IOscCalcAdjustableStan osc,
const SystShifts syst 
) const
overridevirtual

Sum up log-likelihoods of sub-expts.

Reimplemented from ana::IExperiment.

Definition at line 109 of file MultiExperiment.cxx.

References ApplySystCorrs(), fExpts, fSystCorrelations, compare_h5_caf::idx, and runNovaSAM::ret.

Referenced by GetExperiments().

110  {
111  stan::math::var ret = 0.;
112  for (unsigned int idx = 0; idx < fExpts.size(); ++idx)
113  {
114  if(fSystCorrelations[idx].empty())
115  ret += fExpts[idx]->LogLikelihood(osc, syst);
116  else
117  ret += fExpts[idx]->LogLikelihood(osc, ApplySystCorrs(syst, fSystCorrelations[idx]));
118  }
119  return ret;
120  }
std::vector< const IExperiment * > fExpts
var_value< double > var
Definition: StanTypedefs.h:14
std::vector< std::vector< std::pair< const ISyst *, const ISyst * > > > fSystCorrelations
stan::math::var LogLikelihood(osc::IOscCalcAdjustableStan *osc, const SystShifts &syst) const override
Sum up log-likelihoods of sub-expts.
SystShifts ApplySystCorrs(const SystShifts &shiftsIn, const std::vector< std::pair< const ISyst *, const ISyst * >> &corrs) const
Get a new SystShifts, applying the specified correlations to it.
void ana::MultiExperiment::Reset ( ) const
overridevirtual

Reimplemented from ana::IExperiment.

Definition at line 103 of file MultiExperiment.cxx.

References demo5::expt, and fExpts.

Referenced by GetExperiments().

103  {
104  for (auto expt : fExpts) expt->Reset();
105  }
std::vector< const IExperiment * > fExpts
expt
Definition: demo5.py:34
void ana::MultiExperiment::SaveTo ( TDirectory *  dir,
const std::string name 
) const
overridevirtual

Reimplemented from ana::IExperiment.

Definition at line 123 of file MultiExperiment.cxx.

References om::cerr, dir, allTimeWatchdog::endl, fExpts, genie::utils::style::Format(), fSystCorrelations, MECModelEnuComparisons::i, it, and tmp.

Referenced by GetExperiments().

124  {
125  bool hasCorr = false;
126  for(auto it: fSystCorrelations) if(!it.empty()) hasCorr = true;
127 
128  if(hasCorr){
129  std::cerr << "Warning in MultiExperiment: systematic correlations are set and will not be serialized by this call to SaveTo(). You will have to re-set them once you load the experiment back in." << std::endl;
130  }
131 
132  TDirectory* tmp = dir;
133 
134  dir = dir->mkdir(name.c_str()); // switch to subdir
135  dir->cd();
136 
137  TObjString("MultiExperiment").Write("type");
138 
139  for(unsigned int i = 0; i < fExpts.size(); ++i){
140  fExpts[i]->SaveTo(dir, TString::Format("expt%d", i).Data());
141  }
142 
143  dir->Write();
144  delete dir;
145 
146  tmp->cd();
147  }
const XML_Char * name
Definition: expat.h:151
std::vector< const IExperiment * > fExpts
set< int >::iterator it
OStream cerr
Definition: OStream.cxx:7
Float_t tmp
Definition: plot.C:36
std::vector< std::vector< std::pair< const ISyst *, const ISyst * > > > fSystCorrelations
TDirectory * dir
Definition: macro.C:5
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
void ana::MultiExperiment::SetSystCorrelations ( int  idx,
const std::vector< std::pair< const ISyst *, const ISyst * >> &  corrs 
)

For the subexperiment idx, set up a mapping between systematics

Each element in the vector is a pair from a "primary" systematic to a "secondary". When this MultiExperiment is called with a primary systematic shifted, the sub-experiment will be called with the secondary systematic set to the same value (and the primary unset).

You can pass NULL for a secondary to indicate that the systematic simply has no effect on the experiment in question and should be filtered out.

Definition at line 69 of file MultiExperiment.cxx.

References om::cout, allTimeWatchdog::endl, fSystCorrelations, compare_h5_caf::idx, and it.

Referenced by ChiSq(), futureSig_reach_singlePOTcombo_syst(), GetExperiments(), joint_fit_2017_make_fc_slice(), joint_fit_2017_make_fc_surf(), make_fc_mass_and_oct_nersc_2018(), make_fc_mass_and_oct_nersc_2019(), make_fc_mh_nersc_2018(), make_fc_mh_nersc_2019(), make_fc_oct_nersc_2018(), make_fc_oct_nersc_2019(), make_fc_slices_nersc_2018(), make_fc_slices_nersc_2018_stats(), make_fc_slices_nersc_2019(), make_fc_surfaces_2020(), make_fc_surfaces_nersc_2018(), make_fc_surfaces_nersc_2018_stats(), and make_fc_surfaces_nersc_2019().

71  {
72  // Sanity-check the mapping
73  std::map<const ISyst*, const ISyst*> already;
74  for(auto it: corrs){
75  if(it.first == it.second)
76  {
77  std::cout << "MultiExperiment::SetSystCorrelations(): You're trying to map a syst to itself: " << std::endl;
78  auto name = it.first ? it.first->ShortName() : "nullptr";
79  std::cout << name << " --> " << name << std::endl;
80  abort();
81  }
82 
83  // Don't worry if second element is null pointer
84  if (!it.second) continue;
85  if(already.find(it.second) == already.end()){
86  already[it.second] = it.first;
87  }
88  else{
89  std::cout << "MultiExperiment::SetSystCorrelations(): Warning!\n"
90  << "In experiment " << idx << " both "
91  << already[it.second]->ShortName() << " and "
92  << it.first->ShortName()
93  << " are configured to map to " << it.second->ShortName()
94  << ". That's probably not what you want." << std::endl;
95  }
96  }
97 
98  // Apply it
99  fSystCorrelations[idx] = corrs;
100  }
const XML_Char * name
Definition: expat.h:151
set< int >::iterator it
std::vector< std::vector< std::pair< const ISyst *, const ISyst * > > > fSystCorrelations
OStream cout
Definition: OStream.cxx:6

Member Data Documentation

std::vector<const IExperiment*> ana::MultiExperiment::fExpts
protected

Definition at line 58 of file MultiExperiment.h.

Referenced by Add(), ChiSq(), GetExperiments(), LogLikelihood(), MultiExperiment(), Reset(), and SaveTo().

std::vector<std::vector<std::pair<const ISyst*, const ISyst*> > > ana::MultiExperiment::fSystCorrelations
protected

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