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  virtual Eigen::Matrix<T,Eigen::Dynamic,1> P(int flavBefore, int flavAfter, const std::vector<double> &E);
30 
31  /// \brief Use to check two calculators are in the same state
32  ///
33  /// \return Null means not implemented for this calculator
34  virtual TMD5* GetParamsHash() const {return 0;}
35  };
37 
38  /// Pass neutrinos through unchanged
39  template <typename T>
40  class _NoOscillations: public _IOscCalc<T>
41  {
42  public:
43  using _IOscCalc<T>::P;
44  virtual _IOscCalc<T>* Copy() const override {return new _NoOscillations<T>;}
45 
46  virtual T P(int from, int to, double /*E*/) override
47  {
48  if(from == to || to == 0) return 1;
49  return 0;
50  }
51 
52  /// Always compare equal to self
53  virtual TMD5* GetParamsHash() const override
54  {
55  TMD5* ret = new TMD5;
56  const char* txt = "NoOscillations";
57  ret->Update((unsigned char*)txt, strlen(txt));
58  ret->Final();
59  return ret;
60  }
61  };
63 
64  /// General interface to any calculator that lets you set the parameters
65  template <typename T>
66  class _IOscCalcAdjustable : public _IOscCalc<T>
67  {
68  public:
69  virtual ~_IOscCalcAdjustable();
70  virtual _IOscCalcAdjustable<T>* Copy() const = 0;
71 
72  // These setters are left unimplemented here, since calculators may want
73  // to compute additional values when these are set.
74  virtual void SetL (double L ) = 0;
75  virtual void SetRho (double rho ) = 0;
76  virtual void SetDmsq21(const T& dmsq21) = 0;
77  virtual void SetDmsq32(const T& dmsq32) = 0;
78  virtual void SetTh12 (const T& th12 ) = 0;
79  virtual void SetTh13 (const T& th13 ) = 0;
80  virtual void SetTh23 (const T& th23 ) = 0;
81  virtual void SetdCP (const T& dCP ) = 0;
82 
83  virtual double GetL () const { return fL ; }
84  virtual double GetRho () const { return fRho ; }
85  virtual T GetDmsq21() const { return fDmsq21 ; }
86  virtual T GetDmsq32() const { return fDmsq32 ; }
87  virtual T GetTh12 () const { return fTh12 ; }
88  virtual T GetTh13 () const { return fTh13 ; }
89  virtual T GetTh23 () const { return fTh23 ; }
90  virtual T GetdCP () const { return fdCP ; }
91 
92  /// \brief Invalidate any caching used internally by the calculator.
93  ///
94  /// Some calculators use a cache that can become stale in ways
95  /// that the calculator may not know about (e.g., Stan var clearing).
96  /// Default implementation does nothing.
97  virtual void InvalidateCache() {};
98 
99  protected:
100  /// \brief This is only a safe implementation if your calculator only
101  /// depends on these eight parameters
102  ///
103  /// \param txt A string to uniquely identify your calculator class
104  TMD5* GetParamsHashDefault(const std::string& txt) const;
105 
106  // Set by the user. Generally useful to derived classes
107  double fRho; // density (g/cm^3); always double since never fitted
108  double fL; // baseline (km); ditto
115  };
117 
118  //----------------------------------------------------------------------
119  /// Copy parameters from one calculator to another, irrespective of their type
120  template <typename T, typename U>
121  void CopyParams(const osc::_IOscCalcAdjustable<T> * inCalc,
122  osc::_IOscCalcAdjustable<U> * outCalc);
123 
124 } // namespace
125 
126 #endif
Pass neutrinos through unchanged.
Definition: IOscCalc.h:40
_IOscCalcAdjustable< double > IOscCalcAdjustable
Definition: IOscCalc.h:116
double th23
Definition: runWimpSim.h:98
General interface to oscillation calculators.
Definition: StanTypedefs.h:22
virtual double GetL() const
Definition: IOscCalc.h:83
virtual T GetTh23() const
Definition: IOscCalc.h:89
double th12
Definition: runWimpSim.h:98
_IOscCalc< double > IOscCalc
Definition: IOscCalc.h:36
_NoOscillations< double > NoOscillations
Definition: IOscCalc.h:62
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:46
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:57
virtual _IOscCalc< T > * Copy() const override
Definition: IOscCalc.h:44
void SetRho(const float &r)
Definition: HoughPeak.h:94
virtual T GetDmsq32() const
Definition: IOscCalc.h:86
virtual T GetTh12() const
Definition: IOscCalc.h:87
virtual void InvalidateCache()
Invalidate any caching used internally by the calculator.
Definition: IOscCalc.h:97
Oscillation probability calculators.
Definition: Calcs.h:5
virtual TMD5 * GetParamsHash() const
Use to check two calculators are in the same state.
Definition: IOscCalc.h:34
virtual T GetdCP() const
Definition: IOscCalc.h:90
virtual _IOscCalc * Copy() const =0
virtual T GetTh13() const
Definition: IOscCalc.h:88
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:85
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
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:84
double th13
Definition: runWimpSim.h:98
virtual TMD5 * GetParamsHash() const override
Always compare equal to self.
Definition: IOscCalc.h:53