Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
osc::_OscCalcPMNSOpt< T > Class Template Reference

Optimized version of OscCalcPMNS. More...

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N21-04-18/CAFAna/Core/StanTypedefs.h"

Inheritance diagram for osc::_OscCalcPMNSOpt< T >:
osc::_IOscCalcAdjustable< T > osc::_IOscCalc< T >

Classes

struct  Val_t
 

Public Member Functions

 _OscCalcPMNSOpt ()
 
virtual ~_OscCalcPMNSOpt ()
 
_IOscCalcAdjustable< T > * Copy () const override
 
T P (int flavBefore, int flavAfter, double E) override
 E in GeV; flavors as PDG codes (so, neg==>antinu) More...
 
void SetL (double L) override
 
void SetRho (double rho) override
 
void SetDmsq21 (const T &dmsq21) override
 
void SetDmsq32 (const T &dmsq32) override
 
void SetTh13 (const T &th13) override
 
void SetTh12 (const T &th12) override
 
void SetTh23 (const T &th23) override
 
void SetdCP (const T &dCP) override
 
TMD5 * GetParamsHash () const override
 Use to check two calculators are in the same state. More...
 
virtual double GetL () const
 
virtual double GetRho () const
 
virtual T GetDmsq21 () const
 
virtual T GetDmsq32 () const
 
virtual T GetTh12 () const
 
virtual T GetTh13 () const
 
virtual T GetTh23 () const
 
virtual T GetdCP () const
 
virtual void InvalidateCache ()
 Invalidate any caching used internally by the calculator. More...
 
virtual Eigen::Array< T, Eigen::Dynamic, 1 > P (int flavBefore, int flavAfter, const std::vector< double > &E)
 
virtual Eigen::Array< T, Eigen::Dynamic, 1 > P (int flavBefore, int flavAfter, const Eigen::ArrayXd &E)
 

Protected Member Functions

TMD5 * GetParamsHashDefault (const std::string &txt) const
 This is only a safe implementation if your calculator only depends on these eight parameters. More...
 

Protected Attributes

long fMixIdx
 
long fDmIdx
 
long fLRIdx
 
std::unordered_map< double, Val_tfPMNSOpt [2]
 
double fRho
 
double fL
 
T fDmsq21
 
T fDmsq32
 
T fTh12
 
T fTh13
 
T fTh23
 
T fdCP
 

Detailed Description

template<typename T>
class osc::_OscCalcPMNSOpt< T >

Optimized version of OscCalcPMNS.

Adapt the PMNSOpt calculator to standard interface

Definition at line 32 of file StanTypedefs.h.

Constructor & Destructor Documentation

template<typename T >
osc::_OscCalcPMNSOpt< T >::_OscCalcPMNSOpt ( )

Definition at line 14 of file OscCalcPMNSOpt.cxx.

15  : fMixIdx(0), fDmIdx(0), fLRIdx(0)
16  {
17  }
template<typename T >
osc::_OscCalcPMNSOpt< T >::~_OscCalcPMNSOpt ( )
virtual

Definition at line 21 of file OscCalcPMNSOpt.cxx.

References osc::_OscCalcPMNSOpt< T >::fPMNSOpt, MECModelEnuComparisons::i, and it.

22  {
23  for(int i = 0; i < 2; ++i)
24  for(auto it: fPMNSOpt[i])
25  delete it.second.pmns;
26  }
set< int >::iterator it
std::unordered_map< double, Val_t > fPMNSOpt[2]

Member Function Documentation

template<typename T >
_IOscCalcAdjustable< T > * osc::_OscCalcPMNSOpt< T >::Copy ( ) const
overridevirtual

Implements osc::_IOscCalcAdjustable< T >.

Definition at line 30 of file OscCalcPMNSOpt.cxx.

References osc::_OscCalcPMNSOpt< T >::fPMNSOpt, and runNovaSAM::ret.

31  {
32  _OscCalcPMNSOpt<T>* ret = new _OscCalcPMNSOpt<T>(*this);
33  // Raw pointers were blindly copied, so we'd be in trouble when the
34  // destructors are called. More importantly, having two calculators sharing
35  // one PMNS object will lead to both of them getting confused as to whether
36  // they're up-to-date or not. Just clear out the cache entirely in the copy
37  // and let it be repopulated.
38  ret->fPMNSOpt[0].clear();
39  ret->fPMNSOpt[1].clear();
40  return ret;
41  }
template<typename T>
virtual T osc::_IOscCalcAdjustable< T >::GetdCP ( ) const
inlinevirtualinherited
template<typename T>
virtual T osc::_IOscCalcAdjustable< T >::GetDmsq21 ( ) const
inlinevirtualinherited
template<typename T>
virtual T osc::_IOscCalcAdjustable< T >::GetDmsq32 ( ) const
inlinevirtualinherited
template<typename T>
virtual double osc::_IOscCalcAdjustable< T >::GetL ( ) const
inlinevirtualinherited
template<typename T>
TMD5* osc::_OscCalcPMNSOpt< T >::GetParamsHash ( ) const
inlineoverridevirtual

Use to check two calculators are in the same state.

Returns
Null means not implemented for this calculator

Reimplemented from osc::_IOscCalc< T >.

Definition at line 45 of file OscCalcPMNSOpt.h.

References osc::_IOscCalcAdjustable< T >::GetParamsHashDefault().

46  {
48  }
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:47
template<typename T >
TMD5 * osc::_IOscCalcAdjustable< T >::GetParamsHashDefault ( const std::string txt) const
protectedinherited

This is only a safe implementation if your calculator only depends on these eight parameters.

Parameters
txtA string to uniquely identify your calculator class

Definition at line 47 of file IOscCalc.cxx.

References runNovaSAM::ret, and T.

Referenced by osc::_OscCalcPMNS< T >::GetParamsHash(), osc::_OscCalcPMNSOpt< T >::GetParamsHash(), and osc::analytic::_OscCalc< T >::GetParamsHash().

48  {
49  TMD5* ret = new TMD5;
50  ret->Update((unsigned char*)txt.c_str(), txt.size());
51  const int kNumParams = 8;
52  T buf[kNumParams] = {fRho, fL, fDmsq21, fDmsq32,
53  fTh12, fTh13, fTh23, fdCP};
54  ret->Update((unsigned char*)buf, sizeof(T)*kNumParams);
55  ret->Final();
56  return ret;
57  }
double T
Definition: Xdiff_gwt.C:5
template<typename T>
virtual double osc::_IOscCalcAdjustable< T >::GetRho ( ) const
inlinevirtualinherited

Reimplemented in osc::OscCalcCPT, and osc::OscCalcSterile.

Definition at line 89 of file IOscCalc.h.

Referenced by osc::CopyParams(), osc::OscCalcCPT::GetRho(), ana::ResetSterileCalcToDefault(), and ana::SaveTo().

89 { return fRho ; }
template<typename T>
virtual T osc::_IOscCalcAdjustable< T >::GetTh12 ( ) const
inlinevirtualinherited
template<typename T>
virtual T osc::_IOscCalcAdjustable< T >::GetTh13 ( ) const
inlinevirtualinherited
template<typename T>
virtual T osc::_IOscCalcAdjustable< T >::GetTh23 ( ) const
inlinevirtualinherited
template<typename T>
virtual void osc::_IOscCalcAdjustable< T >::InvalidateCache ( )
inlinevirtualinherited

Invalidate any caching used internally by the calculator.

Some calculators use a cache that can become stale in ways that the calculator may not know about (e.g., Stan var clearing). Default implementation does nothing.

Reimplemented in osc::_OscCalcDMP< T >.

Definition at line 102 of file IOscCalc.h.

102 {};
template<class T >
Eigen::Array< T, Eigen::Dynamic, 1 > osc::_IOscCalc< T >::P ( int  flavBefore,
int  flavAfter,
const std::vector< double > &  E 
)
virtualinherited

Default implementation forwards to non-vector version using a simple loop. Override if your calculator has a more efficient implementation.

Reimplemented in osc::analytic::_OscCalc< T >, osc::OscCalcPMNSOptEigen, and osc::_OscCalcDMP< T >.

Definition at line 25 of file IOscCalc.cxx.

References MECModelEnuComparisons::i, osc::_IOscCalc< T >::P(), P, runNovaSAM::ret, and submit_hadd::u.

26  {
27  Eigen::Matrix<T,Eigen::Dynamic,1> ret(E.size());
28  for(auto i = 0u; i < E.size(); i++) {
29  ret(i) = this->P(flavBefore, flavAfter, E[i]);
30  }
31  return ret.array().isNaN().select(0, ret);
32  }
Float_t E
Definition: plot.C:20
virtual T P(int flavBefore, int flavAfter, double E)=0
E in GeV; flavors as PDG codes (so, neg==>antinu)
template<class T >
Eigen::Array< T, Eigen::Dynamic, 1 > osc::_IOscCalc< T >::P ( int  flavBefore,
int  flavAfter,
const Eigen::ArrayXd &  E 
)
virtualinherited

Default implementation forawrds to vector<double> version. Override if your calculator has a more efficient implementation.

Reimplemented in osc::analytic::_OscCalc< T >.

Definition at line 35 of file IOscCalc.cxx.

References P.

36  {
37  return P(flavBefore, flavAfter, std::vector<double>(&E[0], &E[0]+E.size()));
38  }
Float_t E
Definition: plot.C:20
virtual T P(int flavBefore, int flavAfter, double E)=0
E in GeV; flavors as PDG codes (so, neg==>antinu)
template<typename T >
T osc::_OscCalcPMNSOpt< T >::P ( int  flavBefore,
int  flavAfter,
double  E 
)
overridevirtual

E in GeV; flavors as PDG codes (so, neg==>antinu)

Implements osc::_IOscCalc< T >.

Definition at line 45 of file OscCalcPMNSOpt.cxx.

References abs(), ana::assert(), calc, osc::_OscCalcPMNSOpt< T >::Val_t::dmIdx, osc::_IOscCalcAdjustable< T >::fdCP, osc::_OscCalcPMNSOpt< T >::fDmIdx, osc::_IOscCalcAdjustable< T >::fDmsq21, osc::_IOscCalcAdjustable< T >::fDmsq32, osc::_IOscCalcAdjustable< T >::fL, osc::_OscCalcPMNSOpt< T >::fLRIdx, osc::_OscCalcPMNSOpt< T >::fMixIdx, osc::_OscCalcPMNSOpt< T >::fPMNSOpt, osc::_IOscCalcAdjustable< T >::fRho, osc::_IOscCalcAdjustable< T >::fTh12, osc::_IOscCalcAdjustable< T >::fTh13, osc::_IOscCalcAdjustable< T >::fTh23, MECModelEnuComparisons::i, it, calib::j, osc::_OscCalcPMNSOpt< T >::Val_t::lrIdx, osc::_OscCalcPMNSOpt< T >::Val_t::mixIdx, osc::_OscCalcPMNSOpt< T >::Val_t::P, osc::_OscCalcPMNSOpt< T >::Val_t::pmns, and gen_hdf5record::size.

Referenced by Toy_analyses().

46  {
47  // Normal usage of a calculator in a fit is to configure one set of
48  // oscillation parameters and then calculate probabilities for all flavours
49  // and for a range of energies. The underlying PMNSOpt object has to redo
50  // its expensive diagonalization every time the energy changes, but not
51  // when simply switching to a different flavour. Unfortunately callers in
52  // CAFAna wind up making the calls in the wrong order to take advantage of
53  // this. So, we maintain a map of calculators for different energies (also
54  // for neutrinos and antineutrinos) and select the right one if available,
55  // on the hope that it's already configured to do what we're asked, since
56  // it might already have done a different flavour. This works because
57  // callers often pass the same set of energies (bin centers) over and over
58  // again.
59 
60  // If the caches get too large clear them. The caller is probably giving
61  // the precise energy of each event?
62  for(int i = 0; i < 2; ++i){
63  if(fPMNSOpt[i].size() > 10000){
64  for(auto it: fPMNSOpt[i]) delete it.second.pmns;
65  fPMNSOpt[i].clear();
66  }
67  }
68 
69  const int anti = (flavBefore > 0) ? +1 : -1;
70  assert(flavAfter/anti > 0);
71 
72  Val_t& calc = fPMNSOpt[(1+anti)/2][E];
73  if(!calc.pmns) calc.pmns = new _PMNSOpt<T>;
74 
75  int i = -1, j = -1;
76  if(abs(flavBefore) == 12) i = 0;
77  if(abs(flavBefore) == 14) i = 1;
78  if(abs(flavBefore) == 16) i = 2;
79  if(abs(flavAfter) == 12) j = 0;
80  if(abs(flavAfter) == 14) j = 1;
81  if(abs(flavAfter) == 16) j = 2;
82  assert(i >= 0 && j >= 0);
83 
84  const bool dirty = (fMixIdx > calc.mixIdx ||
85  fDmIdx > calc.dmIdx ||
86  fLRIdx > calc.lrIdx);
87 
88  // If the calculator has out of date parameters update them
89  if(fMixIdx > calc.mixIdx){
90  calc.pmns->SetMix(this->fTh12, this->fTh23, this->fTh13, this->fdCP);
91  calc.mixIdx = fMixIdx;
92  }
93  if(fDmIdx > calc.dmIdx){
94  calc.pmns->SetDeltaMsqrs(this->fDmsq21, this->fDmsq32);
95  calc.dmIdx = fDmIdx;
96  }
97 
98  if(dirty){
99  // Cache results for all nine flavour combinations
100  for(int ii = 0; ii < 3; ++ii){
101  calc.pmns->ResetToFlavour(ii);
102  // Assume Z/A=0.5
103  const double Ne = this->fRho/2;
104  calc.pmns->PropMatter(this->fL, E, Ne, anti);
105  for(int jj = 0; jj < 3; ++jj){
106  calc.P[ii][jj] = calc.pmns->P(jj);
107  }
108  }
109 
110  calc.lrIdx = fLRIdx;
111  }
112 
113  return calc.P[i][j];
114  }
set< int >::iterator it
void abs(TH1 *hist)
osc::OscCalcDumb calc
Float_t E
Definition: plot.C:20
Implementation of oscillations of neutrinos in matter in a three-neutrino framework.
const double j
Definition: BetheBloch.cxx:29
assert(nhit_max >=nhit_nbins)
std::unordered_map< double, Val_t > fPMNSOpt[2]
template<typename T>
void osc::_OscCalcPMNSOpt< T >::SetdCP ( const T dCP)
inlineoverridevirtual
template<typename T>
void osc::_OscCalcPMNSOpt< T >::SetDmsq21 ( const T dmsq21)
inlineoverridevirtual
template<typename T>
void osc::_OscCalcPMNSOpt< T >::SetDmsq32 ( const T dmsq32)
inlineoverridevirtual
template<typename T>
void osc::_OscCalcPMNSOpt< T >::SetL ( double  L)
inlineoverridevirtual
template<typename T>
void osc::_OscCalcPMNSOpt< T >::SetRho ( double  rho)
inlineoverridevirtual
template<typename T>
void osc::_OscCalcPMNSOpt< T >::SetTh12 ( const T th12)
inlineoverridevirtual
template<typename T>
void osc::_OscCalcPMNSOpt< T >::SetTh13 ( const T th13)
inlineoverridevirtual
template<typename T>
void osc::_OscCalcPMNSOpt< T >::SetTh23 ( const T th23)
inlineoverridevirtual

Member Data Documentation

template<typename T>
T osc::_IOscCalcAdjustable< T >::fdCP
protectedinherited
template<typename T>
long osc::_OscCalcPMNSOpt< T >::fDmIdx
protected
template<typename T>
T osc::_IOscCalcAdjustable< T >::fDmsq21
protectedinherited
template<typename T>
T osc::_IOscCalcAdjustable< T >::fDmsq32
protectedinherited
template<typename T>
double osc::_IOscCalcAdjustable< T >::fL
protectedinherited
template<typename T>
long osc::_OscCalcPMNSOpt< T >::fLRIdx
protected
template<typename T>
long osc::_OscCalcPMNSOpt< T >::fMixIdx
protected
template<typename T>
std::unordered_map<double, Val_t> osc::_OscCalcPMNSOpt< T >::fPMNSOpt[2]
protected
template<typename T>
double osc::_IOscCalcAdjustable< T >::fRho
protectedinherited
template<typename T>
T osc::_IOscCalcAdjustable< T >::fTh12
protectedinherited
template<typename T>
T osc::_IOscCalcAdjustable< T >::fTh13
protectedinherited
template<typename T>
T osc::_IOscCalcAdjustable< T >::fTh23
protectedinherited

The documentation for this class was generated from the following files: