IOscCalc.cxx
Go to the documentation of this file.
1 // std_isnan needs to precede IOscCalc
2 // because it injects an important Stan overload of std::isnan
3 // into the std namespace that need sto be there
4 // BEFORE the Eigen headers are seen (due to the '#pragma once').
5 // IOscCalc.h #includes Eigen/Eigen, so /shrug
6 #ifdef OSCLIB_STAN
8 #endif
9 
10 #include "OscLib/IOscCalc.h"
11 
12 namespace{
13  // Most directions are implicitly defined
14  template<class T, class U> T GetValAs(const U& x){return x;}
15 
16 #ifdef OSCLIB_STAN
17  // But not this one (since you don't want to do it by accident)
18  template<> double GetValAs<double>(const stan::math::var& x){return x.val();}
19 #endif
20 }
21 
22 #include <Eigen/Dense>
23 
24 namespace osc
25 {
26  template<class T> Eigen::Array<T, Eigen::Dynamic, 1> _IOscCalc<T>::
27  P(int flavBefore, int flavAfter, const std::vector<double>& E)
28  {
29  Eigen::Matrix<T,Eigen::Dynamic,1> ret(E.size());
30  for(auto i = 0u; i < E.size(); i++) {
31  ret(i) = this->P(flavBefore, flavAfter, E[i]);
32  }
33  return ret.array().isNaN().select(0, ret);
34  }
35 
36  template<class T> Eigen::Array<T, Eigen::Dynamic, 1> _IOscCalc<T>::
37  P(int flavBefore, int flavAfter, const Eigen::ArrayXd& E)
38  {
39  return P(flavBefore, flavAfter, std::vector<double>(&E[0], &E[0]+E.size()));
40  }
41 
42  //---------------------------------------------------------------------------
44  {
45  }
46 
47  //---------------------------------------------------------------------------
48  template <typename T>
50  {
51  TMD5* ret = new TMD5;
52  ret->Update((unsigned char*)txt.c_str(), txt.size());
53  const int kNumParams = 8;
54  T buf[kNumParams] = {fRho, fL, fDmsq21, fDmsq32,
55  fTh12, fTh13, fTh23, fdCP};
56  ret->Update((unsigned char*)buf, sizeof(T)*kNumParams);
57  ret->Final();
58  return ret;
59  }
60 
61  template <typename T, typename U>
64  {
65  assert (inCalc);
66  assert (outCalc);
67 
68  outCalc->SetL(inCalc->GetL());
69  outCalc->SetRho(inCalc->GetRho());
70 
71  outCalc->SetdCP(GetValAs<U>(inCalc->GetdCP()));
72  outCalc->SetDmsq21(GetValAs<U>(inCalc->GetDmsq21()));
73  outCalc->SetDmsq32(GetValAs<U>(inCalc->GetDmsq32()));
74  outCalc->SetTh12(GetValAs<U>(inCalc->GetTh12()));
75  outCalc->SetTh13(GetValAs<U>(inCalc->GetTh13()));
76  outCalc->SetTh23(GetValAs<U>(inCalc->GetTh23()));
77  }
78 
79  //---------------------------------------------------------------------------
80  template class _IOscCalcAdjustable<double>;
81  template class _IOscCalc<double>;
82 
83 #ifdef OSCLIB_STAN
85  template class _IOscCalc<stan::math::var>;
86  template void CopyParams(const osc::_IOscCalcAdjustable<double> * inCalc,
88  template void CopyParams(const osc::_IOscCalcAdjustable<stan::math::var> * inCalc,
90  template void CopyParams(const osc::_IOscCalcAdjustable<stan::math::var> * inCalc,
92 #endif
93 
94  template void CopyParams(const osc::_IOscCalcAdjustable<double> * inCalc,
96 }
virtual void SetL(double L)=0
virtual void SetDmsq21(const T &dmsq21)=0
General interface to oscillation calculators.
Definition: StanTypedefs.h:22
virtual double GetL() const
Definition: IOscCalc.h:88
virtual void SetTh13(const T &th13)=0
virtual T GetTh23() const
Definition: IOscCalc.h:94
virtual void SetDmsq32(const T &dmsq32)=0
T GetValAs(const stan::math::var &val)
explicit specialization for double return value
Definition: StanUtils.h:25
TMD5 * GetParamsHashDefault(const std::string &txt) const
This is only a safe implementation if your calculator only depends on these eight parameters...
Definition: IOscCalc.cxx:49
#define P(a, b, c, d, e, x)
Float_t E
Definition: plot.C:20
void CopyParams(const osc::_IOscCalcAdjustable< T > *inCalc, osc::_IOscCalcAdjustable< U > *outCalc)
Copy parameters from one calculator to another, irrespective of their type.
Definition: IOscCalc.cxx:62
virtual T GetDmsq32() const
Definition: IOscCalc.h:91
virtual T GetTh12() const
Definition: IOscCalc.h:92
Oscillation probability calculators.
Definition: Calcs.h:5
virtual T GetdCP() const
Definition: IOscCalc.h:95
virtual T GetTh13() const
Definition: IOscCalc.h:93
virtual T P(int flavBefore, int flavAfter, double E)=0
E in GeV; flavors as PDG codes (so, neg==>antinu)
virtual T GetDmsq21() const
Definition: IOscCalc.h:90
virtual void SetRho(double rho)=0
virtual Eigen::Array< T, Eigen::Dynamic, 1 > P(int flavBefore, int flavAfter, const std::vector< double > &E)
Definition: IOscCalc.cxx:27
virtual ~_IOscCalcAdjustable()
Definition: IOscCalc.cxx:43
virtual void SetTh23(const T &th23)=0
General interface to any calculator that lets you set the parameters.
assert(nhit_max >=nhit_nbins)
double T
Definition: Xdiff_gwt.C:5
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