All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MultiExperimentSBN.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  assert(fExpts.size() == fExptNames.size());
17 
18  double ret = 0;
19 
20  for(unsigned int n = 0; n < fExpts.size(); ++n){
21  // Set baseline for each of the experiments
22  osc->SetL(kBLs[fExptNames[n]]);
23 
24  // Don't waste time fiddling with the systematics if for sure there's
25  // nothing to do.
26  if(fSystCorrelations[n].empty()){
27  ret += fExpts[n]->ChiSq(osc, syst);
28  }
29  else{
30  // Make a local copy we're going to rewrite into the terms this
31  // sub-experiment will accept.
32  SystShifts localShifts = syst;
33  for(auto it: fSystCorrelations[n]){
34  // We're mapping prim -> sec
35  const ISyst* prim = it.first;
36  const ISyst* sec = it.second;
37  if(syst.GetShift(prim) != 0){
38  // sec can be unset, which means there's no representation needed
39  // of prim in the sub-experiment.
40  if(sec) localShifts.SetShift(sec, syst.GetShift(prim));
41  // We've either translated or discarded prim, so drop it here.
42  localShifts.SetShift(prim, 0);
43  }
44  }
45  ret += fExpts[n]->ChiSq(osc, localShifts);
46  }
47  }
48  return ret;
49  }
50 
51  //----------------------------------------------------------------------
54  const std::vector<std::pair<const ISyst*, const ISyst*>>& corrs)
55  {
56  // Sanity-check the mapping
57  std::map<const ISyst*, const ISyst*> already;
58  for(auto it: corrs){
59  assert(it.first != it.second);
60 
61  // Don't worry if second element is null pointer
62  if (!it.second) continue;
63  if(already.find(it.second) == already.end()){
64  already[it.second] = it.first;
65  }
66  else{
67  std::cout << "MultiExperimentSBN::SetSystCorrelations(): Warning!\n"
68  << "In experiment " << idx << " both "
69  << already[it.second]->ShortName() << " and "
70  << it.first->ShortName()
71  << " are configured to map to " << it.second->ShortName()
72  << ". That's probably not what you want." << std::endl;
73  }
74  }
75 
76  // Apply it
77  fSystCorrelations[idx] = corrs;
78  }
79 
80  //----------------------------------------------------------------------
81  void MultiExperimentSBN::SaveTo(TDirectory* dir) const
82  {
83  bool hasCorr = false;
84  for(auto it: fSystCorrelations) if(!it.empty()) hasCorr = true;
85 
86  if(hasCorr){
87  std::cerr << "Warning in MultiExperimentSBN: 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;
88  }
89 
90  TDirectory* tmp = dir;
91 
92  dir->cd();
93  TObjString("MultiExperimentSBN").Write("type");
94 
95  for(unsigned int i = 0; i < fExpts.size(); ++i){
96  fExpts[i]->SaveTo(dir->mkdir(TString::Format("expt%d", i)));
97  }
98 
99  tmp->cd();
100  }
101 
102  //----------------------------------------------------------------------
103  std::unique_ptr<MultiExperimentSBN> MultiExperimentSBN::LoadFrom(TDirectory* dir)
104  {
105  TObjString* ptag = (TObjString*)dir->Get("type");
106  assert(ptag);
107  assert(ptag->GetString() == "MultiExperimentSBN");
108 
109  std::vector<const IExperiment*> expts;
110 
111  for(int i = 0; ; ++i){
112  TDirectory* subdir = dir->GetDirectory(TString::Format("expt%d", i));
113  if(!subdir) break;
114 
115  expts.push_back(ana::LoadFrom<IExperiment>(subdir).release());
116  }
117 
118  assert(!expts.empty());
119 
120  return std::unique_ptr<MultiExperimentSBN>(new MultiExperimentSBN(expts));
121  }
122 }
static std::unique_ptr< MultiExperimentSBN > LoadFrom(TDirectory *dir)
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
MultiExperimentSBN(std::vector< const IExperiment * > expts={}, std::vector< int > exptnames={})
std::vector< std::vector< std::pair< const ISyst *, const ISyst * > > > fSystCorrelations
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:16
process_name opflashCryoW ana
Encapsulate code to systematically shift a caf::StandardRecord.
Definition: ISyst.h:14
virtual double ChiSq(osc::IOscCalcAdjustable *osc, const SystShifts &syst=SystShifts::Nominal()) const override
virtual void SaveTo(TDirectory *dir) const override
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
std::vector< const IExperiment * > fExpts
void SetSystCorrelations(int idx, const std::vector< std::pair< const ISyst *, const ISyst * >> &corrs)
double GetShift(const ISyst *syst) const
Definition: SystShifts.cxx:56
std::vector< int > fExptNames
tuple dir
Definition: dropbox.py:28
const std::vector< double > kBLs
Definition: ExpInfo.h:14
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