Jpp  18.2.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 namespace JPP { using namespace JAANET; }
19 
20 namespace JAANET {
21 
23 
24 
25  /**
26  * Helper class for event-weight factor.
27  *
28  * The template argument corresponds to the desired event-weight factor class.
29  * This class must contain the method `getFactor(const Evt&)`.
30  */
31  template<class JEvtWeightFactor_t>
33  public JSharedPointer<JEvtWeightFactor_t>
34  {
38 
39 
40  /**
41  * Default constructor.
42  */
44  {}
45 
46 
47  /**
48  * Constructor.
49  *
50  * \param factor event-weight factor
51  */
52  JEvtWeightFactorHelper(const JEvtWeightFactor_t& factor)
53  {
54  configure(factor);
55  }
56 
57 
58  /**
59  * Configure event-weight factor.
60  *
61  * \param factor event-weight factor
62  */
63  void configure(const JEvtWeightFactor_t& factor)
64  {
65  using namespace JPP;
66 
67  JEvtWeightFactor_t* p = dynamic_cast<JEvtWeightFactor_t*>(factor.clone());
68 
69  if (p != NULL) {
70  reset(p);
71  } else {
72  THROW(JNullPointerException, "JEvtWeightFactorHelper::configure(): Invalid downcast to class derived from JEvtWeightFactor.");
73  }
74  }
75 
76 
77  /**
78  * Get weight-factor of given event.
79  *
80  * \param evt event
81  * \return event-weight factor
82  */
83  double getFactor(const Evt& evt) const
84  {
85  using namespace JPP;
86 
87  if (is_valid()) {
88  return get()->getFactor(evt);
89  } else {
90  THROW(JNullPointerException, "JEvtWeightFactorHelper::getFactor(): Unspecified event-weighting factor.");
91  }
92  }
93  };
94 
95 
96  /**
97  * Explicit emplate specialization of event-weight factor helper for diffuse flux objects.
98  */
99  template<>
101  public JSharedPointer<JDiffuseFlux>
102  {
104 
105 
106  /**
107  * Default constructor.
108  */
110  {}
111 
112 
113  /**
114  * Constructor.
115  *
116  * \param diffuseFlux diffuse flux function
117  */
119  {
120  configure(diffuseFlux);
121  }
122 
123 
124  /**
125  * Configure oscillation probability function.
126  *
127  * \param diffuseFlux diffuse flux function
128  */
129  void configure(const JDiffuseFlux& diffuseFlux)
130  {
131  using namespace JPP;
132 
133  JDiffuseFlux* p = dynamic_cast<JDiffuseFlux*>(diffuseFlux.clone());
134 
135  if (p != NULL) {
136  reset(p);
137  } else {
138  THROW(JNullPointerException, "JEvtWeightFactorHelper<JDiffuseFlux>::configure(): Invalid downcast from JEvtWeightFactor to JDiffuseFlux.");
139  }
140  }
141 
142 
143  /**
144  * Get diffuse flux corresponding to given neutrino type, energy and zenith angle.
145  *
146  * \param type PDG particle type
147  * \param log10E logarithmic neutrino energy [GeV]
148  * \param costh cosine zenith angle
149  * \return diffuse flux [GeV^-1 * m^-2 * sr^-1 * s^-1]
150  */
151  double getFactor(const int type,
152  const double log10E,
153  const double costh) const
154  {
155  using namespace JPP;
156 
157  if (is_valid()) {
158  return get()->getFactor(type, log10E, costh);
159  } else {
160  THROW(JNullPointerException, "JEvtWeightFactorHelper<JDiffuseFlux>::dNdEdOmega(): Unspecified diffuse flux function.");
161  }
162  }
163 
164 
165  /**
166  * Get diffuse flux corresponding to given neutrino type, energy and zenith angle.
167  *
168  * \param evt event
169  * \return diffuse flux [GeV^-1 * m^-2 * sr^-1 * s^-1]
170  */
171  double getFactor(const Evt& evt) const
172  {
173  using namespace JPP;
174 
175  if (is_valid()) {
176  return get()->getFactor(evt);
177  } else {
178  THROW(JNullPointerException, "JEvtWeightFactorHelper<JDiffuseFlux>::getFactor(): Unspecified diffuse flux function.");
179  }
180  }
181  };
182 
183 
184  /** Type definition of event-weight factor helper for flux functions.*/
186 
187  /** Type definition of event-weight factor helper for diffuse flux objects. */
189 }
190 
191 #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:712
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.
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:27
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:20