All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MultiExperiment.cxx
Go to the documentation of this file.
2 
4 
5 #include "TDirectory.h"
6 #include "TObjString.h"
7 
8 #include <cassert>
9 
10 namespace ana
11 {
12  //----------------------------------------------------------------------
14  const SystShifts& syst) const
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  }
44 
45  //----------------------------------------------------------------------
48  const std::vector<std::pair<const ISyst*, const ISyst*>>& corrs)
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  }
73 
74  //----------------------------------------------------------------------
75  void MultiExperiment::SaveTo(TDirectory* dir) const
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  }
95 
96  //----------------------------------------------------------------------
97  std::unique_ptr<MultiExperiment> MultiExperiment::LoadFrom(TDirectory* dir)
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  }
116 }
std::vector< const IExperiment * > fExpts
void SetShift(const ISyst *syst, double shift)
Shifts are 0=nominal, -1,+1 = 1 sigma shifts.
Definition: SystShifts.cxx:47
BEGIN_PROLOG could also be cerr
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:16
process_name opflashCryoW ana
static std::unique_ptr< MultiExperiment > LoadFrom(TDirectory *dir)
Encapsulate code to systematically shift a caf::StandardRecord.
Definition: ISyst.h:14
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
std::vector< std::vector< std::pair< const ISyst *, const ISyst * > > > fSystCorrelations
double GetShift(const ISyst *syst) const
Definition: SystShifts.cxx:56
tuple dir
Definition: dropbox.py:28
virtual void SaveTo(TDirectory *dir) const override
bool empty(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:555
std::unique_ptr< IExperiment > LoadFrom< IExperiment >(TDirectory *dir)
Definition: IExperiment.cxx:22
BEGIN_PROLOG could also be cout
MultiExperiment(std::vector< const IExperiment * > expts={})
void SetSystCorrelations(int idx, const std::vector< std::pair< const ISyst *, const ISyst * >> &corrs)
virtual double ChiSq(osc::IOscCalcAdjustable *osc, const SystShifts &syst=SystShifts::Nominal()) const override