Jpp  18.3.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 
4 #include <memory>
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 
22  /**
23  * Helper class for event-weight factor.
24  *
25  * The template argument corresponds to the desired event-weight factor class.
26  * This class must contain the method `getFactor(const Evt&)`.
27  */
28  template<class JEvtWeightFactor_t>
30  public std::shared_ptr<JEvtWeightFactor_t>
31  {
33  typedef std::shared_ptr<JEvtWeightFactor_t> pointer_type;
34 
35 
36  /**
37  * Default constructor.
38  */
40  {}
41 
42 
43  /**
44  * Constructor.
45  *
46  * \param factor event-weight factor
47  */
48  JEvtWeightFactorHelper(const JEvtWeightFactor_t& factor)
49  {
50  configure(factor);
51  }
52 
53 
54  /**
55  * Configure event-weight factor.
56  *
57  * \param factor event-weight factor
58  */
59  void configure(const JEvtWeightFactor_t& factor)
60  {
61  using namespace JPP;
62 
63  JEvtWeightFactor_t* p = dynamic_cast<JEvtWeightFactor_t*>(factor.clone());
64 
65  if (p != NULL) {
66  this->reset(p);
67  } else {
68  THROW(JNullPointerException, "JEvtWeightFactorHelper::configure(): Invalid downcast to class derived from JEvtWeightFactor.");
69  }
70  }
71 
72 
73  /**
74  * Get reference to event-weight factor.
75  *
76  * \return reference to event-weight factor
77  */
78  JEvtWeightFactor_t& getEvtWeightFactor() const
79  {
80  using namespace JPP;
81 
82  if (static_cast<const JEvtWeightFactorHelper_t&>(*this)) {
83  return *(this->get());
84  } else {
85  THROW(JNullPointerException, "JEvtWeightFactorHelper::getEvtWeightFactor(): Event-weight factor is not set.");
86  }
87  }
88 
89 
90  /**
91  * Get weight-factor of given event.
92  *
93  * \param evt event
94  * \return event-weight factor
95  */
96  double getFactor(const Evt& evt) const
97  {
98  const JEvtWeightFactor_t& weightFactor = getEvtWeightFactor();
99 
100  return weightFactor.getFactor(evt);
101  }
102  };
103 
104 
105  /**
106  * Explicit emplate specialization of event-weight factor helper for diffuse flux objects.
107  */
108  template<>
110  public std::shared_ptr<JDiffuseFlux>
111  {
113  typedef std::shared_ptr<JDiffuseFlux> pointer_type;
114 
115 
116  /**
117  * Default constructor.
118  */
120  {}
121 
122 
123  /**
124  * Constructor.
125  *
126  * \param diffuseFlux diffuse flux function
127  */
129  {
130  configure(diffuseFlux);
131  }
132 
133 
134  /**
135  * Configure oscillation probability function.
136  *
137  * \param diffuseFlux diffuse flux function
138  */
139  void configure(const JDiffuseFlux& diffuseFlux)
140  {
141  using namespace JPP;
142 
143  JDiffuseFlux* p = dynamic_cast<JDiffuseFlux*>(diffuseFlux.clone());
144 
145  if (p != NULL) {
146  reset(p);
147  } else {
148  THROW(JNullPointerException, "JDiffuseFluxHelper::configure(): Unable to retrieve diffuse flux interface.");
149  }
150  }
151 
152 
153  /**
154  * Get reference to diffuse flux factor.
155  *
156  * \return reference to diffuse flux factor
157  */
159  {
160  using namespace JPP;
161 
162  if (static_cast<const JDiffuseFluxHelper_t&>(*this)) {
163  return *(this->get());
164  } else {
165  THROW(JNullPointerException, "JDiffuseFluxHelper::getDiffuseFlux(): Diffuse flux factor is not set.");
166  }
167  }
168 
169 
170  /**
171  * Get diffuse flux corresponding to given neutrino type, energy and zenith angle.
172  *
173  * \param type PDG particle type
174  * \param log10E logarithmic neutrino energy [GeV]
175  * \param costh cosine zenith angle
176  * \return diffuse flux [GeV^-1 * m^-2 * sr^-1 * s^-1]
177  */
178  double getFactor(const int type,
179  const double log10E,
180  const double costh) const
181  {
182  const JDiffuseFlux& diffuseFlux = getDiffuseFlux();
183 
184  return diffuseFlux.getFactor(type, log10E, costh);
185  }
186 
187 
188  /**
189  * Get diffuse flux corresponding to given neutrino type, energy and zenith angle.
190  *
191  * \param evt event
192  * \return diffuse flux [GeV^-1 * m^-2 * sr^-1 * s^-1]
193  */
194  double getFactor(const Evt& evt) const
195  {
196  const JDiffuseFlux& diffuseFlux = getDiffuseFlux();
197 
198  return diffuseFlux.getFactor(evt);
199  }
200  };
201 
202 
203  /** Type definition of event-weight factor helper for flux functions.*/
205 
206  /** Type definition of event-weight factor helper for diffuse flux objects. */
208 }
209 
210 #endif
JEvtWeightFactorHelper()
Default constructor.
double getFactor(const Evt &evt) const override
Get event-weight factor for given event.
Definition: JDiffuseFlux.hh:44
JEvtWeightFactorHelper< JEvtWeightFactor_t > JEvtWeightFactorHelper_t
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
std::shared_ptr< JEvtWeightFactor_t > pointer_type
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.
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.
JEvtWeightFactor_t & getEvtWeightFactor() const
Get reference to event-weight factor.
double getFactor(const Evt &evt) const
Get diffuse flux corresponding to given neutrino type, energy and zenith angle.
JDiffuseFlux & getDiffuseFlux() const
Get reference to diffuse flux factor.
void reset(T &value)
Reset value.
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.
JEvtWeightFactorHelper(const JDiffuseFlux &diffuseFlux)
Constructor.
JEvtWeightFactorHelper< JDiffuseFlux > JDiffuseFluxHelper_t
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20