All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
ana::MultiExperiment Class Reference

Combine multiple component experiments. More...

#include <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
 
void SetSystCorrelations (int idx, const std::vector< std::pair< const ISyst *, const ISyst * >> &corrs)
 
virtual void SaveTo (TDirectory *dir) const override
 
- Public Member Functions inherited from ana::IExperiment
virtual ~IExperiment ()
 

Static Public Member Functions

static std::unique_ptr
< MultiExperiment
LoadFrom (TDirectory *dir)
 

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.

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.

19 {fExpts.push_back(expt);}
std::vector< const IExperiment * > fExpts
double ana::MultiExperiment::ChiSq ( osc::IOscCalcAdjustable osc,
const SystShifts syst = SystShifts::Nominal() 
) const
overridevirtual

Implements ana::IExperiment.

Definition at line 13 of file MultiExperiment.cxx.

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

Definition at line 97 of file MultiExperiment.cxx.

98  {
99  TObjString* ptag = (TObjString*)dir->Get("type");
100  assert(ptag);
101  assert(ptag->GetString() == "MultiExperiment");
102 
103  std::vector<const IExperiment*> expts;
104 
105  for(int i = 0; ; ++i){
106  TDirectory* subdir = dir->GetDirectory(TString::Format("expt%d", i));
107  if(!subdir) break;
108 
109  expts.push_back(ana::LoadFrom<IExperiment>(subdir).release());
110  }
111 
112  assert(!expts.empty());
113 
114  return std::unique_ptr<MultiExperiment>(new MultiExperiment(expts));
115  }
tuple dir
Definition: dropbox.py:28
std::unique_ptr< IExperiment > LoadFrom< IExperiment >(TDirectory *dir)
Definition: IExperiment.cxx:22
MultiExperiment(std::vector< const IExperiment * > expts={})
void ana::MultiExperiment::SaveTo ( TDirectory *  dir) const
overridevirtual

Reimplemented from ana::IExperiment.

Definition at line 75 of file MultiExperiment.cxx.

76  {
77  bool hasCorr = false;
78  for(auto it: fSystCorrelations) if(!it.empty()) hasCorr = true;
79 
80  if(hasCorr){
81  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;
82  }
83 
84  TDirectory* tmp = dir;
85 
86  dir->cd();
87  TObjString("MultiExperiment").Write("type");
88 
89  for(unsigned int i = 0; i < fExpts.size(); ++i){
90  fExpts[i]->SaveTo(dir->mkdir(TString::Format("expt%d", i)));
91  }
92 
93  tmp->cd();
94  }
std::vector< const IExperiment * > fExpts
BEGIN_PROLOG could also be cerr
std::vector< std::vector< std::pair< const ISyst *, const ISyst * > > > fSystCorrelations
tuple dir
Definition: dropbox.py:28
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 47 of file MultiExperiment.cxx.

49  {
50  // Sanity-check the mapping
51  std::map<const ISyst*, const ISyst*> already;
52  for(auto it: corrs){
53  assert(it.first != it.second);
54 
55  // Don't worry if second element is null pointer
56  if (!it.second) continue;
57  if(already.find(it.second) == already.end()){
58  already[it.second] = it.first;
59  }
60  else{
61  std::cout << "MultiExperiment::SetSystCorrelations(): Warning!\n"
62  << "In experiment " << idx << " both "
63  << already[it.second]->ShortName() << " and "
64  << it.first->ShortName()
65  << " are configured to map to " << it.second->ShortName()
66  << ". That's probably not what you want." << std::endl;
67  }
68  }
69 
70  // Apply it
71  fSystCorrelations[idx] = corrs;
72  }
std::vector< std::vector< std::pair< const ISyst *, const ISyst * > > > fSystCorrelations
BEGIN_PROLOG could also be cout

Member Data Documentation

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

Definition at line 42 of file MultiExperiment.h.

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

Definition at line 44 of file MultiExperiment.h.


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