Public Member Functions | Static Public 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/N19-12-08/CAFAna/Experiment/MultiExperiment.h"

Inheritance diagram for ana::MultiExperiment:
ana::IChiSqExperiment

Public Member Functions

 MultiExperiment (std::vector< const IChiSqExperiment * > expts={})
 
void Add (const IChiSqExperiment *expt)
 
virtual double ChiSq (osc::IOscCalculatorAdjustable *osc, const SystShifts &syst=SystShifts::Nominal()) const override
 
virtual void Derivative (osc::IOscCalculator *calc, const SystShifts &shift, std::unordered_map< const ISyst *, double > &dchi) const override
 
void SetSystCorrelations (int idx, const std::vector< std::pair< const ISyst *, const ISyst * >> &corrs)
 
virtual void SaveTo (TDirectory *dir) const override
 

Static Public Member Functions

static std::unique_ptr< MultiExperimentLoadFrom (TDirectory *dir)
 

Protected Attributes

std::vector< const IChiSqExperiment * > 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 IChiSqExperiment * >  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< std::vector< std::pair< const ISyst *, const ISyst * > > > fSystCorrelations
std::vector< const IChiSqExperiment * > fExpts

Member Function Documentation

void ana::MultiExperiment::Add ( const IChiSqExperiment expt)
inline
double ana::MultiExperiment::ChiSq ( osc::IOscCalculatorAdjustable osc,
const SystShifts syst = SystShifts::Nominal() 
) const
overridevirtual

Implements ana::IChiSqExperiment.

Definition at line 14 of file MultiExperiment.cxx.

References Derivative(), fExpts, fSystCorrelations, ana::SystShifts::GetShift(), it, getGoodRuns4SAM::n, runNovaSAM::ret, ana::SystShifts::SetShift(), and plotSysts::syst.

Referenced by Add(), and MakeSurface().

16  {
17  double ret = 0;
18  for(unsigned int n = 0; n < fExpts.size(); ++n){
19  // Don't waste time fiddling with the systematics if for sure there's
20  // nothing to do.
21  if(fSystCorrelations[n].empty()){
22  ret += fExpts[n]->ChiSq(osc, syst);
23  }
24  else{
25  // Make a local copy we're going to rewrite into the terms this
26  // sub-experiment will accept.
27  SystShifts localShifts = syst;
28  for(auto it: fSystCorrelations[n]){
29  // We're mapping prim -> sec
30  const ISyst* prim = it.first;
31  const ISyst* sec = it.second;
32  if(syst.GetShift(prim) != 0){
33  // sec can be unset, which means there's no representation needed
34  // of prim in the sub-experiment.
35  if(sec) localShifts.SetShift(sec, syst.GetShift(prim));
36  // We've either translated or discarded prim, so drop it here.
37  localShifts.SetShift(prim, 0);
38  }
39  }
40  ret += fExpts[n]->ChiSq(osc, localShifts);
41  }
42  }
43  return ret;
44  }
set< int >::iterator it
std::vector< std::vector< std::pair< const ISyst *, const ISyst * > > > fSystCorrelations
std::vector< const IChiSqExperiment * > fExpts
string syst
Definition: plotSysts.py:176
void ana::MultiExperiment::Derivative ( osc::IOscCalculator calc,
const SystShifts shift,
std::unordered_map< const ISyst *, double > &  dchi 
) const
overridevirtual

Reimplemented from ana::IChiSqExperiment.

Definition at line 49 of file MultiExperiment.cxx.

References fExpts, fSystCorrelations, ana::SystShifts::GetShift(), it, getGoodRuns4SAM::n, ana::SystShifts::SetShift(), SetSystCorrelations(), and plotSysts::shift.

Referenced by Add(), and ChiSq().

52  {
53  // Each one should sum into the total so far
54  for(unsigned int n = 0; n < fExpts.size(); ++n){
55  if(fSystCorrelations[n].empty()){
56  // If there are no adjustments needed it's easy
57  fExpts[n]->Derivative(calc, shift, dchi);
58  if(dchi.empty()) return;
59  continue;
60  }
61 
62  auto dchiLocal = dchi;
63  for(auto& it: dchiLocal) it.second = 0;
64  SystShifts localShifts = shift;
65  std::unordered_map<const ISyst*, const ISyst*> reverseMap;
66  for(auto it: fSystCorrelations[n]){
67  // We're mapping prim -> sec
68  const ISyst* prim = it.first;
69  const ISyst* sec = it.second;
70  if(dchi.count(prim)){
71  dchiLocal.erase(dchiLocal.find(prim));
72  if(sec){
73  dchiLocal.emplace(sec, 0);
74  reverseMap[sec] = prim;
75  }
76  }
77  if(sec) localShifts.SetShift(sec, shift.GetShift(prim));
78  // We've either translated or discarded prim, so drop it here.
79  localShifts.SetShift(prim, 0);
80  }
81 
82  fExpts[n]->Derivative(calc, localShifts, dchiLocal);
83 
84  // One of the components doesn't support derivatives, don't bother asking
85  // the rest.
86  if(dchiLocal.empty()){
87  dchi.clear();
88  return;
89  }
90 
91  // And translate back
92  for(auto it: dchiLocal){
93  if(reverseMap.count(it.first) > 0){
94  dchi[reverseMap[it.first]] += it.second;
95  }
96  else{
97  dchi[it.first] += it.second;
98  }
99  }
100  }
101  }
set< int >::iterator it
std::vector< std::vector< std::pair< const ISyst *, const ISyst * > > > fSystCorrelations
std::vector< const IChiSqExperiment * > fExpts
std::unique_ptr< MultiExperiment > ana::MultiExperiment::LoadFrom ( TDirectory *  dir)
static

Definition at line 155 of file MultiExperiment.cxx.

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

Referenced by Add(), and ana::LoadFrom< IChiSqExperiment >().

156  {
157  TObjString* ptag = (TObjString*)dir->Get("type");
158  assert(ptag);
159  assert(ptag->GetString() == "MultiExperiment");
160 
161  std::vector<const IChiSqExperiment*> expts;
162 
163  for(int i = 0; ; ++i){
164  TDirectory* subdir = dir->GetDirectory(TString::Format("expt%d", i));
165  if(!subdir) break;
166 
167  expts.push_back(ana::LoadFrom<IChiSqExperiment>(subdir).release());
168  }
169 
170  assert(!expts.empty());
171 
172  return std::unique_ptr<MultiExperiment>(new MultiExperiment(expts));
173  }
subdir
Definition: cvnie.py:7
std::unique_ptr< IChiSqExperiment > LoadFrom< IChiSqExperiment >(TDirectory *dir)
MultiExperiment(std::vector< const IChiSqExperiment * > expts={})
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::SaveTo ( TDirectory *  dir) const
overridevirtual

Reimplemented from ana::IChiSqExperiment.

Definition at line 133 of file MultiExperiment.cxx.

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

Referenced by Add().

134  {
135  bool hasCorr = false;
136  for(auto it: fSystCorrelations) if(!it.empty()) hasCorr = true;
137 
138  if(hasCorr){
139  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;
140  }
141 
142  TDirectory* tmp = dir;
143 
144  dir->cd();
145  TObjString("MultiExperiment").Write("type");
146 
147  for(unsigned int i = 0; i < fExpts.size(); ++i){
148  fExpts[i]->SaveTo(dir->mkdir(TString::Format("expt%d", i)));
149  }
150 
151  tmp->cd();
152  }
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
std::vector< const IChiSqExperiment * > fExpts
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 105 of file MultiExperiment.cxx.

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

Referenced by Add(), Derivative(), futureSig_reach_singlePOTcombo_syst(), 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_nersc_2018(), make_fc_surfaces_nersc_2018_stats(), and make_fc_surfaces_nersc_2019().

107  {
108  // Sanity-check the mapping
109  std::map<const ISyst*, const ISyst*> already;
110  for(auto it: corrs){
111  assert(it.first != it.second);
112 
113  // Don't worry if second element is null pointer
114  if (!it.second) continue;
115  if(already.find(it.second) == already.end()){
116  already[it.second] = it.first;
117  }
118  else{
119  std::cout << "MultiExperiment::SetSystCorrelations(): Warning!\n"
120  << "In experiment " << idx << " both "
121  << already[it.second]->ShortName() << " and "
122  << it.first->ShortName()
123  << " are configured to map to " << it.second->ShortName()
124  << ". That's probably not what you want." << std::endl;
125  }
126  }
127 
128  // Apply it
129  fSystCorrelations[idx] = corrs;
130  }
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 IChiSqExperiment*> ana::MultiExperiment::fExpts
protected

Definition at line 46 of file MultiExperiment.h.

Referenced by Add(), ChiSq(), Derivative(), MultiExperiment(), and SaveTo().

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

Definition at line 48 of file MultiExperiment.h.

Referenced by ChiSq(), Derivative(), MultiExperiment(), SaveTo(), and SetSystCorrelations().


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