LoadFromFile.cxx
Go to the documentation of this file.
2 
3 #include "OscLib/OscCalc.h"
5 #include "OscLib/OscCalcDMP.h"
6 #include "OscLib/OscCalcDumb.h"
8 #include "OscLib/OscCalcPMNS.h"
10 #include "OscLib/OscCalcSterile.h"
11 #include "OscLib/OscCalcPMNS_NSI.h"
12 
13 #include "TObjString.h"
14 #include "TVectorD.h"
15 
16 #include <iostream>
17 #include <vector>
18 
19 namespace ana
20 {
21  //----------------------------------------------------------------------
22  template<> std::unique_ptr<osc::IOscCalc>
23  LoadFrom<osc::IOscCalc>(TDirectory* dir, const std::string& name)
24  {
25  TDirectory* subdir(dir->GetDirectory(name.c_str()));
26  assert(subdir);
27 
28  TObjString* ptag = (TObjString*)subdir->Get("type");
29  assert(ptag);
30  const TString tag = ptag->GetString();
31  delete ptag;
32  delete subdir;
33 
34  if(tag == "NoOscillations") return std::unique_ptr<osc::IOscCalc>(new osc::NoOscillations);
35  if(tag == "OscCalculatorDumb") return std::unique_ptr<osc::IOscCalc>(new osc::OscCalcDumb);
36 
37  // Otherwise it's probably an adjustable calculator
38  return LoadFrom<osc::IOscCalcAdjustable>(dir, name);
39  }
40 
41  //----------------------------------------------------------------------
42  template<> std::unique_ptr<osc::IOscCalcAdjustable>
43  LoadFrom<osc::IOscCalcAdjustable>(TDirectory* topdir, const std::string& name)
44  {
45  std::unique_ptr<TDirectory> dir(topdir->GetDirectory(name.c_str())); // switch to subdir
46  assert(dir);
47 
48  TObjString* ptag = (TObjString*)dir->Get("type");
49  assert(ptag);
50  const TString tag = ptag->GetString();
51  delete ptag;
52 
54 
55  if(tag == "OscCalculator") ret = new osc::OscCalc;
56  if(tag == "OscCalculatorGeneral") ret = new osc::OscCalcGeneral;
57  if(tag == "OscCalculatorPMNS") ret = new osc::OscCalcPMNS;
58  if(tag == "OscCalculatorPMNSOpt") ret = new osc::OscCalcPMNSOpt;
59  if(tag == "OscCalculatorSterile") ret = new osc::OscCalcSterile;
60  if(tag == "OscCalculatorPMNS_NSI") ret = new osc::OscCalcPMNS_NSI;
61  if(tag == "OscCalculatorDMP") ret = new osc::OscCalcDMP;
62  if(tag == "OscCalculatorAnalytic") ret = new osc::OscCalcAnalytic;
63 
64  if(!ret){
65  std::cout << "LoadFrom not implemented for " << tag << std::endl;
66  abort();
67  }
68 
69  TVectorD* params = (TVectorD*)dir->Get("params");
70  assert(params);
71  //special case how OscCalcSterile is initialized
72  if(tag == "OscCalculatorSterile") {
73  std::vector<double> state;
74  for (int i = 0; i < params->GetNrows(); ++i) {
75  state.push_back( (*params)[i] );
76  }
77  dynamic_cast<osc::OscCalcSterile*>(ret)->SetState(state);
78  return std::unique_ptr<osc::IOscCalcAdjustable>(ret);
79  }
80  //special case how OscCalcPMNS_NSI is initialized
81  if(tag == "OscCalculatorPMNS_NSI") {
82  std::vector<double> state;
83  for (int i = 0; i < params->GetNrows(); ++i) {
84  state.push_back( (*params)[i] );
85  }
86  dynamic_cast<osc::OscCalcPMNS_NSI*>(ret)->SetState(state);
87  return std::unique_ptr<osc::IOscCalcAdjustable>(ret);
88  }
89 
90  assert(params->GetNrows() == 8);
91 
92  ret->SetL ((*params)[0]);
93  ret->SetRho ((*params)[1]);
94  ret->SetDmsq21((*params)[2]);
95  ret->SetDmsq32((*params)[3]);
96  ret->SetTh12 ((*params)[4]);
97  ret->SetTh13 ((*params)[5]);
98  ret->SetTh23 ((*params)[6]);
99  ret->SetdCP ((*params)[7]);
100 
101  return std::unique_ptr<osc::IOscCalcAdjustable>(ret);
102  }
103 
104  //----------------------------------------------------------------------
105  template<> void SaveTo(const osc::IOscCalc& x, TDirectory* dir, const std::string& name)
106  {
107  TDirectory* tmp = gDirectory;
108 
109  dir = dir->mkdir(name.c_str()); // switch to subdir
110  dir->cd();
111 
112  // There are a lot of ways to exit this function. Make sure they all write
113  // and delete the directory.
114  struct DirCleaner
115  {
116  ~DirCleaner(){fDir->Write(); delete fDir;}
117  TDirectory* fDir;
118  } cleaner{dir};
119 
120 
121  if(dynamic_cast<const osc::NoOscillations*>(&x)){
122  TObjString("NoOscillations").Write("type");
123  tmp->cd();
124  return;
125  }
126 
127  if(dynamic_cast<const osc::OscCalcDumb*>(&x)){
128  TObjString("OscCalculatorDumb").Write("type");
129  tmp->cd();
130  return;
131  }
132 
133  const osc::IOscCalcAdjustable* y = dynamic_cast<const osc::IOscCalcAdjustable*>(&x);
134  if(!y){
135  std::cout << "Unknown calculator in SaveTo " << typeid(x).name() << std::endl;
136  abort();
137  }
138 
139  const osc::OscCalcSterile* tmpSterile = dynamic_cast<const osc::OscCalcSterile*>(&x);
140  if(tmpSterile) {
141  TObjString("OscCalculatorSterile").Write("type");
142  std::vector<double> state = tmpSterile->GetState();
143  TVectorD params(state.size());
144  for (unsigned int i = 0; i < state.size(); ++i) params[i] = state[i];
145  params.Write("params");
146  tmp->cd();
147  return;
148  }
149 
150  //for the implementation of OscCalcPMNS_NSI
151  const osc::OscCalcPMNS_NSI* tmpNSI = dynamic_cast<const osc::OscCalcPMNS_NSI*>(&x);
152  if(tmpNSI) {
153  TObjString("OscCalculatorPMNS_NSI").Write("type");
154  std::vector<double> state = tmpNSI->GetState();
155  TVectorD params(state.size());
156  for (unsigned int i = 0; i < state.size(); ++i) params[i] = state[i];
157  params.Write("params");
158  tmp->cd();
159  return;
160  }
161 
162  /* */if(dynamic_cast<const osc::OscCalc*>(&x)) TObjString("OscCalculatorPMNS").Write("type");
163  else if(dynamic_cast<const osc::OscCalcGeneral*>(&x)) TObjString("OscCalculatorGeneral").Write("type");
164  else if(dynamic_cast<const osc::OscCalcPMNS*>(&x)) TObjString("OscCalculatorPMNS").Write("type");
165  else if(dynamic_cast<const osc::OscCalcPMNSOpt*>(&x)) TObjString("OscCalculatorPMNSOpt").Write("type");
166  else if(dynamic_cast<const osc::OscCalcDMP*>(&x)) TObjString("OscCalculatorDMP").Write("type");
167  else if(dynamic_cast<const osc::OscCalcAnalytic*>(&x)) TObjString("OscCalculatorAnalytic").Write("type");
168  else{
169  std::cout << "Unimplemented calculator in SaveTo " << typeid(x).name() << std::endl;
170  abort();
171  }
172 
173  TVectorD params(8);
174 
175  params[0] = y->GetL();
176  params[1] = y->GetRho();
177  params[2] = y->GetDmsq21();
178  params[3] = y->GetDmsq32();
179  params[4] = y->GetTh12();
180  params[5] = y->GetTh13();
181  params[6] = y->GetTh23();
182  params[7] = y->GetdCP();
183 
184  params.Write("params");
185 
186  tmp->cd();
187  }
188 }
Optimized version of OscCalcPMNS.
const XML_Char * name
Definition: expat.h:151
virtual void SetL(double L)=0
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
More generic (but probably slower) oscillation calculations.
_OscCalcPMNSOpt< double > OscCalcPMNSOpt
void SaveTo(const osc::IOscCalc &x, TDirectory *dir, const std::string &name)
virtual void SetDmsq21(const T &dmsq21)=0
subdir
Definition: cvnie.py:7
std::vector< double > GetState() const
General interface to oscillation calculators.
Definition: StanTypedefs.h:22
virtual double GetL() const
Definition: IOscCalc.h:88
virtual void SetTh13(const T &th13)=0
Adapt the PMNS_Sterile calculator to standard interface.
virtual T GetTh23() const
Definition: IOscCalc.h:94
Float_t tmp
Definition: plot.C:36
virtual void SetDmsq32(const T &dmsq32)=0
_NoOscillations< double > NoOscillations
Definition: IOscCalc.h:67
std::vector< double > GetState() const
_OscCalcDMP< double > OscCalcDMP
Definition: OscCalcDMP.h:85
Simple oscillation probability calculator that has no solar term or mass hierarchy or delta so it&#39;s s...
Definition: OscCalcDumb.h:16
virtual T GetDmsq32() const
Definition: IOscCalc.h:91
virtual T GetTh12() const
Definition: IOscCalc.h:92
virtual T GetdCP() const
Definition: IOscCalc.h:95
OStream cout
Definition: OStream.cxx:6
virtual T GetTh13() const
Definition: IOscCalc.h:93
virtual T GetDmsq21() const
Definition: IOscCalc.h:90
virtual void SetRho(double rho)=0
_OscCalcPMNS< double > OscCalcPMNS
Definition: OscCalcPMNS.h:57
TDirectory * dir
Definition: macro.C:5
virtual void SetTh23(const T &th23)=0
assert(nhit_max >=nhit_nbins)
_OscCalcAnalytic< double > OscCalcAnalytic
virtual double GetRho() const
Definition: IOscCalc.h:89
virtual void SetTh12(const T &th12)=0
virtual void SetdCP(const T &dCP)=0
enum BeamMode string