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-01-18/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)
 
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 18 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().

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

Reimplemented from ana::IExperiment.

Definition at line 50 of file MultiExperiment.cxx.

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

Referenced by Add(), and MakeSurface().

52  {
53  double ret = 0;
54  for(unsigned int n = 0; n < fExpts.size(); ++n){
55  // Don't waste time fiddling with the systematics if for sure there's
56  // nothing to do.
57  if(fSystCorrelations[n].empty())
58  ret += fExpts[n]->ChiSq(osc, syst);
59  else
60  ret += fExpts[n]->ChiSq(osc, ApplySystCorrs(syst, fSystCorrelations[n]));
61  }
62  return ret;
63  }
std::vector< const IExperiment * > fExpts
std::vector< std::vector< std::pair< const ISyst *, const ISyst * > > > fSystCorrelations
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(), 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 143 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().

144  {
145  dir = dir->GetDirectory(name.c_str()); // switch to subdir
146  assert(dir);
147 
148  TObjString* ptag = (TObjString*)dir->Get("type");
149  assert(ptag);
150  assert(ptag->GetString() == "MultiExperiment");
151  delete ptag;
152 
153  std::vector<const IExperiment*> expts;
154 
155  for(int i = 0; ; ++i){
156  const std::string subname = TString::Format("expt%d", i).Data();
157  TDirectory* subdir = dir->GetDirectory(subname.c_str());
158  if(!subdir) break;
159  delete subdir;
160 
161  expts.push_back(ana::LoadFrom<IExperiment>(dir, name).release());
162  }
163 
164  assert(!expts.empty());
165 
166  delete dir;
167 
168  return std::unique_ptr<MultiExperiment>(new MultiExperiment(expts));
169  }
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 102 of file MultiExperiment.cxx.

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

Referenced by GetExperiments().

103  {
104  stan::math::var ret = 0.;
105  for (unsigned int idx = 0; idx < fExpts.size(); ++idx)
106  {
107  if(fSystCorrelations[idx].empty())
108  ret += fExpts[idx]->LogLikelihood(osc, syst);
109  else
110  ret += fExpts[idx]->LogLikelihood(osc, ApplySystCorrs(syst, fSystCorrelations[idx]));
111  }
112  return ret;
113  }
std::vector< const IExperiment * > fExpts
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::SaveTo ( TDirectory *  dir,
const std::string name 
) const
overridevirtual

Reimplemented from ana::IExperiment.

Definition at line 116 of file MultiExperiment.cxx.

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

Referenced by GetExperiments().

117  {
118  bool hasCorr = false;
119  for(auto it: fSystCorrelations) if(!it.empty()) hasCorr = true;
120 
121  if(hasCorr){
122  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;
123  }
124 
125  TDirectory* tmp = dir;
126 
127  dir = dir->mkdir(name.c_str()); // switch to subdir
128  dir->cd();
129 
130  TObjString("MultiExperiment").Write("type");
131 
132  for(unsigned int i = 0; i < fExpts.size(); ++i){
133  fExpts[i]->SaveTo(dir, TString::Format("expt%d", i).Data());
134  }
135 
136  dir->Write();
137  delete dir;
138 
139  tmp->cd();
140  }
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 67 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().

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

Referenced by Add(), ChiSq(), GetExperiments(), LogLikelihood(), MultiExperiment(), 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: