IOscCalc.h
Go to the documentation of this file.
1 #ifndef IOSCCALCULATOR_H
2 #define IOSCCALCULATOR_H
3 
4 #include "TMD5.h"
5 #include <Eigen/Eigen>
6 //////////////////////////////////////////////////////////////////////////
7 // //
8 // \file IOscCalc.h //
9 // //
10 // \brief General interface to oscillation calculators //
11 // \author Christopher Backhouse - c.backhouse@ucl.ac.uk //
12 // //
13 //////////////////////////////////////////////////////////////////////////
14 
15 /// Oscillation probability calculators
16 namespace osc
17 {
18  /// General interface to oscillation calculators
19  template <typename T>
20  class _IOscCalc
21  {
22  public:
23  virtual ~_IOscCalc() {}
24 
25  virtual _IOscCalc* Copy() const = 0;
26 
27  /// E in GeV; flavors as PDG codes (so, neg==>antinu)
28  virtual T P(int flavBefore, int flavAfter, double E) = 0;
29  /// Default implementation forwards to non-vector version using a simple
30  /// loop. Override if your calculator has a more efficient implementation.
31  virtual Eigen::Array<T, Eigen::Dynamic, 1> P(int flavBefore, int flavAfter, const std::vector<double>& E);
32  /// Default implementation forawrds to vector<double> version. Override if
33  /// your calculator has a more efficient implementation.
34  virtual Eigen::Array<T, Eigen::Dynamic, 1> P(int flavBefore, int flavAfter, const Eigen::ArrayXd& E);
35 
36  /// \brief Use to check two calculators are in the same state
37  ///
38  /// \return Null means not implemented for this calculator
39  virtual TMD5* GetParamsHash() const {return 0;}
40  };
42 
43  /// Pass neutrinos through unchanged
44  template <typename T>
45  class _NoOscillations: public _IOscCalc<T>
46  {
47  public:
48  using _IOscCalc<T>::P;
49  virtual _IOscCalc<T>* Copy() const override {return new _NoOscillations<T>;}
50 
51  virtual T P(int from, int to, double /*E*/) override
52  {
53  if(from == to || to == 0) return 1;
54  return 0;
55  }
56 
57  /// Always compare equal to self
58  virtual TMD5* GetParamsHash() const override
59  {
60  TMD5* ret = new TMD5;
61  const char* txt = "NoOscillations";
62  ret->Update((unsigned char*)txt, strlen(txt));
63  ret->Final();
64  return ret;
65  }
66  };
68 
69  /// General interface to any calculator that lets you set the parameters
70  template <typename T>
71  class _IOscCalcAdjustable : public _IOscCalc<T>
72  {
73  public:
74  virtual ~_IOscCalcAdjustable();
75  virtual _IOscCalcAdjustable<T>* Copy() const = 0;
76 
77  // These setters are left unimplemented here, since calculators may want
78  // to compute additional values when these are set.
79  virtual void SetL (double L ) = 0;
80  virtual void SetRho (double rho ) = 0;
81  virtual void SetDmsq21(const T& dmsq21) = 0;
82  virtual void SetDmsq32(const T& dmsq32) = 0;
83  virtual void SetTh12 (const T& th12 ) = 0;
84  virtual void SetTh13 (const T& th13 ) = 0;
85  virtual void SetTh23 (const T& th23 ) = 0;
86  virtual void SetdCP (const T& dCP ) = 0;
87 
88  virtual double GetL () const { return fL ; }
89  virtual double GetRho () const { return fRho ; }
90  virtual T GetDmsq21() const { return fDmsq21 ; }
91  virtual T GetDmsq32() const { return fDmsq32 ; }
92  virtual T GetTh12 () const { return fTh12 ; }
93  virtual T GetTh13 () const { return fTh13 ; }
94  virtual T GetTh23 () const { return fTh23 ; }
95  virtual T GetdCP () const { return fdCP ; }
96 
97  /// \brief Invalidate any caching used internally by the calculator.
98  ///
99  /// Some calculators use a cache that can become stale in ways
100  /// that the calculator may not know about (e.g., Stan var clearing).
101  /// Default implementation does nothing.
102  virtual void InvalidateCache() {};
103 
104  protected:
105  /// \brief This is only a safe implementation if your calculator only
106  /// depends on these eight parameters
107  ///
108  /// \param txt A string to uniquely identify your calculator class
109  TMD5* GetParamsHashDefault(const std::string& txt) const;
110 
111  // Set by the user. Generally useful to derived classes
112  double fRho; // density (g/cm^3); always double since never fitted
113  double fL; // baseline (km); ditto
120  };
122 
123  //----------------------------------------------------------------------
124  /// Copy parameters from one calculator to another, irrespective of their type
125  template <typename T, typename U>
126  void CopyParams(const osc::_IOscCalcAdjustable<T> * inCalc,
127  osc::_IOscCalcAdjustable<U> * outCalc);
128 
129 } // namespace
130 
131 #endif
Pass neutrinos through unchanged.
Definition: IOscCalc.h:45
_IOscCalcAdjustable< double > IOscCalcAdjustable
Definition: IOscCalc.h:121
double th23
Definition: runWimpSim.h:98
General interface to oscillation calculators.
Definition: StanTypedefs.h:22
virtual double GetL() const
Definition: IOscCalc.h:88
virtual T GetTh23() const
Definition: IOscCalc.h:94
double th12
Definition: runWimpSim.h:98
_IOscCalc< double > IOscCalc
Definition: IOscCalc.h:41
_NoOscillations< double > NoOscillations
Definition: IOscCalc.h:67
virtual ~_IOscCalc()
Definition: IOscCalc.h:23
virtual T P(int from, int to, double) override
E in GeV; flavors as PDG codes (so, neg==>antinu)
Definition: IOscCalc.h:51
static constexpr double L
Float_t E
Definition: plot.C:20
double dCP
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 _IOscCalc< T > * Copy() const override
Definition: IOscCalc.h:49
void SetRho(const float &r)
Definition: HoughPeak.h:94
virtual T GetDmsq32() const
Definition: IOscCalc.h:91
virtual T GetTh12() const
Definition: IOscCalc.h:92
virtual void InvalidateCache()
Invalidate any caching used internally by the calculator.
Definition: IOscCalc.h:102
Oscillation probability calculators.
Definition: Calcs.h:5
virtual TMD5 * GetParamsHash() const
Use to check two calculators are in the same state.
Definition: IOscCalc.h:39
virtual T GetdCP() const
Definition: IOscCalc.h:95
virtual _IOscCalc * Copy() const =0
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
double dmsq32
General interface to any calculator that lets you set the parameters.
double T
Definition: Xdiff_gwt.C:5
virtual double GetRho() const
Definition: IOscCalc.h:89
double th13
Definition: runWimpSim.h:98
virtual TMD5 * GetParamsHash() const override
Always compare equal to self.
Definition: IOscCalc.h:58
enum BeamMode string