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/N20-10-28/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::Matrix< T, Eigen::Dynamic, 1 > P (int flavBefore, int flavAfter, const std::vector< double > &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 31 of file StanTypedefs.h.

Constructor & Destructor Documentation

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

Definition at line 7 of file OscCalcPMNSOpt.cxx.

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

Definition at line 14 of file OscCalcPMNSOpt.cxx.

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

15  {
16  for(int i = 0; i < 2; ++i)
17  for(auto it: fPMNSOpt[i])
18  delete it.second.pmns;
19  }
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 23 of file OscCalcPMNSOpt.cxx.

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

24  {
25  _OscCalcPMNSOpt<T>* ret = new _OscCalcPMNSOpt<T>(*this);
26  // Raw pointers were blindly copied, so we'd be in trouble when the
27  // destructors are called. More importantly, having two calculators sharing
28  // one PMNS object will lead to both of them getting confused as to whether
29  // they're up-to-date or not. Just clear out the cache entirely in the copy
30  // and let it be repopulated.
31  ret->fPMNSOpt[0].clear();
32  ret->fPMNSOpt[1].clear();
33  return ret;
34  }
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:44
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 44 of file IOscCalc.cxx.

References runNovaSAM::ret, and T.

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

45  {
46  TMD5* ret = new TMD5;
47  ret->Update((unsigned char*)txt.c_str(), txt.size());
48  const int kNumParams = 8;
49  T buf[kNumParams] = {fRho, fL, fDmsq21, fDmsq32,
50  fTh12, fTh13, fTh23, fdCP};
51  ret->Update((unsigned char*)buf, sizeof(T)*kNumParams);
52  ret->Final();
53  return ret;
54  }
double T
Definition: Xdiff_gwt.C:5
template<typename T>
virtual double osc::_IOscCalcAdjustable< T >::GetRho ( ) const
inlinevirtualinherited
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 97 of file IOscCalc.h.

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

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

Definition at line 28 of file IOscCalc.cxx.

References MECModelEnuComparisons::i, P, runNovaSAM::ret, and submit_hadd::u.

29  {
30  Eigen::Matrix<T,Eigen::Dynamic,1> ret(E.size());
31  for(auto i = 0u; i < E.size(); i++) {
32  ret(i) = this->P(flavBefore, flavAfter, E[i]);
33  }
34  return ret.array().isNaN().select(0, ret);
35  }
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 38 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_flatrecord::size.

Referenced by fnex::ShifterAndWeighter::OscillationWeight(), fnex::CompareFNEXCAFEventListFiles::ReadCAFMCTextFile(), and Toy_analyses().

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