All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LoadFromFile.cxx
Go to the documentation of this file.
2 
4 
5 #include "OscLib/OscCalc.h"
6 #include "OscLib/OscCalcDumb.h"
7 #include "OscLib/OscCalcGeneral.h"
8 #include "OscLib/OscCalcPMNS.h"
9 #include "OscLib/OscCalcPMNSOpt.h"
10 #include "OscLib/OscCalcSterile.h"
11 #include "OscLib/OscCalcPMNS_NSI.h"
12 
13 #include "TObjString.h"
14 #include "TH1.h"
15 #include "TVectorD.h"
16 #include <vector>
17 
18 namespace ana
19 {
20  //----------------------------------------------------------------------
21  template<> std::unique_ptr<osc::IOscCalc>
22  LoadFrom<osc::IOscCalc>(TDirectory* dir)
23  {
24  TObjString* ptag = (TObjString*)dir->Get("type");
25  assert(ptag);
26  const TString tag = ptag->GetString();
27 
28  if(tag == "NoOscillations") return std::unique_ptr<osc::IOscCalc>(new osc::NoOscillations);
29  if(tag == "OscCalculatorDumb") return std::unique_ptr<osc::IOscCalc>(new osc::OscCalcDumb);
30 
31  TVectorD* params = (TVectorD*)dir->Get("params");
32  assert(params);
33 
34  osc::IOscCalcAdjustable* ret = 0;
35 
36  if(tag == "OscCalculator") ret = new osc::OscCalc;
37  if(tag == "OscCalculatorGeneral") ret = new osc::OscCalcGeneral;
38  if(tag == "OscCalculatorPMNS") ret = new osc::OscCalcPMNS;
39  if(tag == "OscCalculatorPMNSOpt") ret = new osc::OscCalcPMNSOpt;
40  if(tag == "OscCalculatorSterile") ret = new osc::OscCalcSterile;
41  if(tag == "OscCalculatorPMNS_NSI") ret = new osc::OscCalcPMNS_NSI;
42  if(tag == "OscCalcSterileApprox"){
43  assert(params->GetNrows() == 4);
44  auto ret = new OscCalcSterileApproxAdjustable;
45  ret->calc.SetDmsq((*params)[0]);
46  ret->calc.SetSinSq2ThetaMuMu((*params)[1]);
47  ret->calc.SetSinSq2ThetaMuE((*params)[2]);
48  ret->calc.SetL((*params)[3]);
49  return std::unique_ptr<osc::IOscCalcAdjustable>(ret);
50  }
51 
52  if(!ret){
53  std::cout << "LoadFrom not implemented for " << tag << std::endl;
54  abort();
55  }
56 
57  //special case how OscCalcSterile 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::OscCalcSterile*>(ret)->SetState(state);
64  return std::unique_ptr<osc::IOscCalcAdjustable>(ret);
65  }
66  //special case how OscCalcPMNS_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::OscCalcPMNS_NSI*>(ret)->SetState(state);
73  return std::unique_ptr<osc::IOscCalcAdjustable>(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::IOscCalcAdjustable>(ret);
88  }
89 
90  //----------------------------------------------------------------------
91  template<> void SaveTo(const osc::IOscCalc& 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::OscCalcDumb*>(&x)){
104  TObjString("OscCalculatorDumb").Write("type");
105  tmp->cd();
106  return;
107  }
108 
109  const OscCalcSterileApproxAdjustable* approx = dynamic_cast<const OscCalcSterileApproxAdjustable*>(&x);
110  if(approx){
111  TObjString("OscCalcSterileApprox").Write("type");
112  TVectorD params(4);
113  params[0] = approx->calc.GetDmsq();
114  params[1] = approx->calc.GetSinSq2ThetaMuMu();
115  params[2] = approx->calc.GetSinSq2ThetaMuE();
116  params[3] = approx->calc.GetL();
117  params.Write("params");
118  tmp->cd();
119  return;
120  }
121 
122  const osc::IOscCalcAdjustable* y = dynamic_cast<const osc::IOscCalcAdjustable*>(&x);
123  if(!y){
124  std::cout << "Unknown calculator in SaveTo " << typeid(x).name() << std::endl;
125  abort();
126  }
127 
128  const osc::OscCalcSterile* tmpSterile = dynamic_cast<const osc::OscCalcSterile*>(&x);
129  if(tmpSterile) {
130  TObjString("OscCalculatorSterile").Write("type");
131  std::vector<double> state = tmpSterile->GetState();
132  TVectorD params(state.size());
133  for (unsigned int i = 0; i < state.size(); ++i) params[i] = state[i];
134  params.Write("params");
135  tmp->cd();
136  return;
137  }
138 
139  //for the implementation of OscCalcPMNS_NSI
140  const osc::OscCalcPMNS_NSI* tmpNSI = dynamic_cast<const osc::OscCalcPMNS_NSI*>(&x);
141  if(tmpNSI) {
142  TObjString("OscCalcPMNS_NSI").Write("type");
143  std::vector<double> state = tmpNSI->GetState();
144  TVectorD params(state.size());
145  for (unsigned int i = 0; i < state.size(); ++i) params[i] = state[i];
146  params.Write("params");
147  tmp->cd();
148  return;
149  }
150 
151  /* */if(dynamic_cast<const osc::OscCalc*>(&x)) TObjString("OscCalculatorPMNS").Write("type");
152  else if(dynamic_cast<const osc::OscCalcGeneral*>(&x)) TObjString("OscCalculatorGeneral").Write("type");
153  else if(dynamic_cast<const osc::OscCalcPMNS*>(&x)) TObjString("OscCalculatorPMNS").Write("type");
154  else if(dynamic_cast<const osc::OscCalcPMNSOpt*>(&x)) TObjString("OscCalculatorPMNSOpt").Write("type");
155  else{
156  std::cout << "Unimplemented calculator in SaveTo " << typeid(x).name() << std::endl;
157  abort();
158  }
159 
160  TVectorD params(8);
161 
162  params[0] = y->GetL();
163  params[1] = y->GetRho();
164  params[2] = y->GetDmsq21();
165  params[3] = y->GetDmsq32();
166  params[4] = y->GetTh12();
167  params[5] = y->GetTh13();
168  params[6] = y->GetTh23();
169  params[7] = y->GetdCP();
170 
171  params.Write("params");
172 
173  tmp->cd();
174  }
175 }
process_name opflash particleana ie x
process_name opflashCryoW ana
process_name opflash particleana ie ie y
tuple dir
Definition: dropbox.py:28
then echo fcl name
void SaveTo(const osc::IOscCalc &x, TDirectory *dir)
BEGIN_PROLOG could also be cout