LoadFromFile.cxx
Go to the documentation of this file.
2 
10 
11 #include "TObjString.h"
12 #include "TH1.h"
13 #include "TVectorD.h"
14 #include <vector>
15 
16 namespace ana
17 {
18  //----------------------------------------------------------------------
19  template<> std::unique_ptr<osc::IOscCalculator>
20  LoadFrom<osc::IOscCalculator>(TDirectory* dir)
21  {
22  TObjString* ptag = (TObjString*)dir->Get("type");
23  assert(ptag);
24  const TString tag = ptag->GetString();
25 
26  if(tag == "NoOscillations") return std::unique_ptr<osc::IOscCalculator>(new osc::NoOscillations);
27  if(tag == "OscCalculatorDumb") return std::unique_ptr<osc::IOscCalculator>(new osc::OscCalculatorDumb);
28 
29  // Otherwise it's probably an adjustable calculator
30  return LoadFrom<osc::IOscCalculatorAdjustable>(dir);
31  }
32 
33  //----------------------------------------------------------------------
34  template<> std::unique_ptr<osc::IOscCalculatorAdjustable>
35  LoadFrom<osc::IOscCalculatorAdjustable>(TDirectory* dir)
36  {
37  TObjString* ptag = (TObjString*)dir->Get("type");
38  assert(ptag);
39  const TString tag = ptag->GetString();
40 
42 
43  if(tag == "OscCalculator") ret = new osc::OscCalculator;
44  if(tag == "OscCalculatorGeneral") ret = new osc::OscCalculatorGeneral;
45  if(tag == "OscCalculatorPMNS") ret = new osc::OscCalculatorPMNS;
46  if(tag == "OscCalculatorPMNSOpt") ret = new osc::OscCalculatorPMNSOpt;
47  if(tag == "OscCalculatorSterile") ret = new osc::OscCalculatorSterile;
48  if(tag == "OscCalculatorPMNS_NSI") ret = new osc::OscCalculatorPMNS_NSI;
49 
50  if(!ret){
51  std::cout << "LoadFrom not implemented for " << tag << std::endl;
52  abort();
53  }
54 
55  TVectorD* params = (TVectorD*)dir->Get("params");
56  assert(params);
57  //special case how OscCalculatorSterile is initialized
58  if(tag == "OscCalculatorSterile") {
59  std::vector<double> state;
60  for (int i = 0; i < params->GetNrows(); ++i) {
61  state.push_back( (*params)[i] );
62  }
63  dynamic_cast<osc::OscCalculatorSterile*>(ret)->SetState(state);
64  return std::unique_ptr<osc::IOscCalculatorAdjustable>(ret);
65  }
66  //special case how OscCalculatorPMNS_NSI is initialized
67  if(tag == "OscCalculatorPMNS_NSI") {
68  std::vector<double> state;
69  for (int i = 0; i < params->GetNrows(); ++i) {
70  state.push_back( (*params)[i] );
71  }
72  dynamic_cast<osc::OscCalculatorPMNS_NSI*>(ret)->SetState(state);
73  return std::unique_ptr<osc::IOscCalculatorAdjustable>(ret);
74  }
75 
76  assert(params->GetNrows() == 8);
77 
78  ret->SetL ((*params)[0]);
79  ret->SetRho ((*params)[1]);
80  ret->SetDmsq21((*params)[2]);
81  ret->SetDmsq32((*params)[3]);
82  ret->SetTh12 ((*params)[4]);
83  ret->SetTh13 ((*params)[5]);
84  ret->SetTh23 ((*params)[6]);
85  ret->SetdCP ((*params)[7]);
86 
87  return std::unique_ptr<osc::IOscCalculatorAdjustable>(ret);
88  }
89 
90  //----------------------------------------------------------------------
91  template<> void SaveTo(const osc::IOscCalculator& x, TDirectory* dir)
92  {
93  TDirectory* tmp = gDirectory;
94 
95  dir->cd();
96 
97  if(dynamic_cast<const osc::NoOscillations*>(&x)){
98  TObjString("NoOscillations").Write("type");
99  tmp->cd();
100  return;
101  }
102 
103  if(dynamic_cast<const osc::OscCalculatorDumb*>(&x)){
104  TObjString("OscCalculatorDumb").Write("type");
105  tmp->cd();
106  return;
107  }
108 
109  const osc::IOscCalculatorAdjustable* y = dynamic_cast<const osc::IOscCalculatorAdjustable*>(&x);
110  if(!y){
111  std::cout << "Unknown calculator in SaveTo " << typeid(x).name() << std::endl;
112  abort();
113  }
114 
115  const osc::OscCalculatorSterile* tmpSterile = dynamic_cast<const osc::OscCalculatorSterile*>(&x);
116  if(tmpSterile) {
117  TObjString("OscCalculatorSterile").Write("type");
118  std::vector<double> state = tmpSterile->GetState();
119  TVectorD params(state.size());
120  for (unsigned int i = 0; i < state.size(); ++i) params[i] = state[i];
121  params.Write("params");
122  tmp->cd();
123  return;
124  }
125 
126  //for the implementation of OscCalculatorPMNS_NSI
127  const osc::OscCalculatorPMNS_NSI* tmpNSI = dynamic_cast<const osc::OscCalculatorPMNS_NSI*>(&x);
128  if(tmpNSI) {
129  TObjString("OscCalculatorPMNS_NSI").Write("type");
130  std::vector<double> state = tmpNSI->GetState();
131  TVectorD params(state.size());
132  for (unsigned int i = 0; i < state.size(); ++i) params[i] = state[i];
133  params.Write("params");
134  tmp->cd();
135  return;
136  }
137 
138  /* */if(dynamic_cast<const osc::OscCalculator*>(&x)) TObjString("OscCalculatorPMNS").Write("type");
139  else if(dynamic_cast<const osc::OscCalculatorGeneral*>(&x)) TObjString("OscCalculatorGeneral").Write("type");
140  else if(dynamic_cast<const osc::OscCalculatorPMNS*>(&x)) TObjString("OscCalculatorPMNS").Write("type");
141  else if(dynamic_cast<const osc::OscCalculatorPMNSOpt*>(&x)) TObjString("OscCalculatorPMNSOpt").Write("type");
142  else{
143  std::cout << "Unimplemented calculator in SaveTo " << typeid(x).name() << std::endl;
144  abort();
145  }
146 
147  TVectorD params(8);
148 
149  params[0] = y->GetL();
150  params[1] = y->GetRho();
151  params[2] = y->GetDmsq21();
152  params[3] = y->GetDmsq32();
153  params[4] = y->GetTh12();
154  params[5] = y->GetTh13();
155  params[6] = y->GetTh23();
156  params[7] = y->GetdCP();
157 
158  params.Write("params");
159 
160  tmp->cd();
161  }
162 }
const XML_Char * name
Definition: expat.h:151
virtual T GetDmsq21() const
virtual void SetL(double L)=0
Oscillation analysis framework, runs over CAF files outside of ART.
virtual double GetRho() const
General interface to oscillation calculators.
Definition: FwdDeclare.h:15
Adapt the PMNS_Sterile calculator to standard interface.
std::vector< double > GetState() const
virtual void SetRho(double rho)=0
Optimized version of OscCalculatorPMNS.
virtual void SetdCP(const T &dCP)=0
Float_t tmp
Definition: plot.C:36
virtual void SetDmsq21(const T &dmsq21)=0
virtual double GetL() const
_NoOscillations< double > NoOscillations
void SaveTo(const osc::IOscCalculator &x, TDirectory *dir)
General interface to any calculator that lets you set the parameters.
Simple oscillation probability calculator that has no solar term or mass hierarchy or delta so it&#39;s s...
_OscCalculatorPMNS< double > OscCalculatorPMNS
More generic (but probably slower) oscillation calculations.
virtual void SetTh23(const T &th23)=0
virtual void SetDmsq32(const T &dmsq32)=0
std::vector< double > GetState() const
OStream cout
Definition: OStream.cxx:6
virtual T GetDmsq32() const
TDirectory * dir
Definition: macro.C:5
virtual void SetTh13(const T &th13)=0
_OscCalculatorPMNSOpt< double > OscCalculatorPMNSOpt
virtual void SetTh12(const T &th12)=0