Jpp  16.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEvtWeightFactorHelper.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JEVTWEIGHTFACTORHELPER__
2 #define __JAANET__JEVTWEIGHTFACTORHELPER__
3 
5 
7 
9 #include "JAAnet/JFlux.hh"
10 #include "JAAnet/JDiffuseFlux.hh"
11 
12 
13 /**
14  * \author bjung
15  */
16 
17 namespace JAANET {
18 
21 
22 
23  /**
24  * Helper class for event-weight factor.
25  *
26  * The template argument corresponds to the desired event-weight factor class.
27  * This class must contain the method `getFactor(const Evt&)`.
28  */
29  template<class JEvtWeightFactor_t>
31  public JSharedPointer<JEvtWeightFactor_t>
32  {
36 
37 
38  /**
39  * Default constructor.
40  */
42  {}
43 
44 
45  /**
46  * Constructor.
47  *
48  * \param factor event-weight factor
49  */
50  JEvtWeightFactorHelper(const JEvtWeightFactor_t& factor)
51  {
52  configure(factor);
53  }
54 
55 
56  /**
57  * Configure event-weight factor.
58  *
59  * \param factor event-weight factor
60  */
61  void configure(const JEvtWeightFactor_t& factor)
62  {
63  JEvtWeightFactor_t* p = dynamic_cast<JEvtWeightFactor_t*>(factor.clone());
64 
65  if (p != NULL) {
66  reset(p);
67  } else {
68  THROW(JNullPointerException, "JEvtWeightFactorHelper::configure(): Invalid downcast to class derived from JEvtWeightFactor.");
69  }
70  }
71 
72 
73  /**
74  * Get weight-factor of given event.
75  *
76  * \param evt event
77  * \return event-weight factor
78  */
79  double getFactor(const Evt& evt) const
80  {
81  if (is_valid()) {
82  return get()->getFactor(evt);
83  } else {
84  THROW(JNullPointerException, "JEvtWeightFactorHelper::getFactor(): Unspecified event-weighting factor.");
85  }
86  }
87  };
88 
89 
90  /**
91  * Explicit emplate specialization of event-weight factor helper for diffuse flux objects.
92  */
93  template<>
95  public JSharedPointer<JDiffuseFlux>
96  {
98 
99 
100  /**
101  * Default constructor.
102  */
104  {}
105 
106 
107  /**
108  * Constructor.
109  *
110  * \param diffuseFlux diffuse flux function
111  */
113  {
114  configure(diffuseFlux);
115  }
116 
117 
118  /**
119  * Configure oscillation probability function.
120  *
121  * \param diffuseFlux diffuse flux function
122  */
123  void configure(const JDiffuseFlux& diffuseFlux)
124  {
125  JDiffuseFlux* p = dynamic_cast<JDiffuseFlux*>(diffuseFlux.clone());
126 
127  if (p != NULL) {
128  reset(p);
129  } else {
130  THROW(JNullPointerException, "JEvtWeightFactorHelper<JDiffuseFlux>::configure(): Invalid downcast from JEvtWeightFactor to JDiffuseFlux.");
131  }
132  }
133 
134 
135  /**
136  * Get diffuse flux corresponding to given neutrino type, energy and zenith angle.
137  *
138  * \param type PDG particle type
139  * \param log10E logarithmic neutrino energy
140  * \param costh cosine zenith angle
141  * \return diffuse flux [GeV^-1 * m^-2 * sr^-1 * s^-1]
142  */
143  double getFactor(const int type,
144  const double log10E,
145  const double costh) const
146  {
147  if (is_valid()) {
148  return get()->getFactor(type, log10E, costh);
149  } else {
150  THROW(JNullPointerException, "JEvtWeightFactorHelper<JDiffuseFlux>::dNdEdOmega(): Unspecified diffuse flux function.");
151  }
152  }
153 
154 
155  /**
156  * Get diffuse flux corresponding to given neutrino type, energy and zenith angle.
157  *
158  * \param evt event
159  * \return diffuse flux [GeV^-1 * m^-2 * sr^-1 * s^-1]
160  */
161  double getFactor(const Evt& evt) const
162  {
163  if (is_valid()) {
164  return get()->getFactor(evt);
165  } else {
166  THROW(JNullPointerException, "JEvtWeightFactorHelper<JDiffuseFlux>::getFactor(): Unspecified diffuse flux function.");
167  }
168  }
169  };
170 
171 
172  /** Type definition of event-weight factor helper for flux functions.*/
174 
175  /** Type definition of event-weight factor helper for diffuse flux objects. */
177 }
178 
179 #endif
JEvtWeightFactorHelper()
Default constructor.
JEvtWeightFactorHelper< JDiffuseFlux > JDiffuseFluxHelper
Type definition of event-weight factor helper for diffuse flux objects.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
bool is_valid() const
Check validity of pointer.
virtual clone_type clone() const override
Get clone of this object.
Definition: JClonable.hh:69
double getFactor(const Evt &evt) const
Get weight-factor of given event.
void configure(const JDiffuseFlux &diffuseFlux)
Configure oscillation probability function.
The template JSharedPointer class can be used to share a pointer to an object.
Exception for null pointer operation.
Definition: JException.hh:216
JEvtWeightFactorHelper< JFlux > JFluxHelper
Type definition of event-weight factor helper for flux functions.
Explicit emplate specialization of event-weight factor helper for diffuse flux objects.
Helper class for event-weight factor.
Low-level interface for diffuse fluxes.
Definition: JDiffuseFlux.hh:24
void configure(const JEvtWeightFactor_t &factor)
Configure event-weight factor.
double getFactor(const Evt &evt) const
Get diffuse flux corresponding to given neutrino type, energy and zenith angle.
JEvtWeightFactorHelper(const JEvtWeightFactor_t &factor)
Constructor.
double getFactor(const int type, const double log10E, const double costh) const
Get diffuse flux corresponding to given neutrino type, energy and zenith angle.
virtual void reset() override
Reset pointer.
JEvtWeightFactorHelper(const JDiffuseFlux &diffuseFlux)
Constructor.
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19