Jpp  master_rocky
the software that should make you happy
JEvtWeightKM3BUU.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JEVTWEIGHTKM3BUU__
2 #define __JAANET__JEVTWEIGHTKM3BUU__
3 
5 
8 
9 #include "JLang/JException.hh"
10 #include "JLang/JClonable.hh"
11 
12 #include "JAAnet/JHead.hh"
13 #include "JAAnet/JHeadToolkit.hh"
14 #include "JAAnet/JEvtWeight.hh"
16 #include "JAAnet/JFlux.hh"
17 
18 
19 /**
20  * \author bjung
21  */
22 
23 namespace JAANET {}
24 namespace JPP { using namespace JAANET; }
25 
26 namespace JAANET {
27 
28  using JLANG::JClonable;
29 
30 
31  /**
32  * Implementation of event weighting for KM3BUU data.
33  */
34  struct JEvtWeightKM3BUU final :
35  public JFluxHelper,
36  public JClonable<JEvtWeight, JEvtWeightKM3BUU>
37  {
38  /**
39  * Default constructor.
40  */
42  JFluxHelper()
43  {}
44 
45 
46  /**
47  * Constructor.
48  *
49  * \param header header
50  */
51  JEvtWeightKM3BUU(const JHead& header) :
52  JFluxHelper()
53  {
54  configure(header);
55  }
56 
57 
58  /**
59  * Constructor.
60  *
61  * \param header header
62  * \param flux flux
63  */
64  JEvtWeightKM3BUU(const JHead& header,
65  const JFlux& flux) :
66  JFluxHelper()
67  {
68  configure(header);
70  }
71 
72 
73  /**
74  * Get name.
75  *
76  * \return name
77  */
78  const char* const getName() const override final
79  {
80  return "KM3BUU";
81  }
82 
83 
84  /**
85  * Weight configuration.
86  *
87  * \param header header
88  */
89  void configure(const JHead& header) override final
90  {
91  using namespace JPP;
92 
93  if (check(header)) {
94 
95  const double Nevents = header.genvol.numberOfEvents;
96  const double dt = (header.tgen.numberOfSeconds > 0.0 ?
97  header.tgen.numberOfSeconds : 1.0);
98 
99  setNormalisation(1.0 / Nevents / dt);
100 
101  } else {
102 
103  THROW(JValueOutOfRange, "JEvtWeightKM3BUU::configure(): Provided header is inconsistent with KM3BUU.");
104  }
105  }
106 
107 
108  /**
109  * Check whether header is consistent with this event weighter.
110  *
111  * \param header header
112  * \return true if consistent; else false
113  */
114  bool check(const JHead& header) const override final
115  {
116  return is_km3buu(header);
117  }
118 
119 
120  /**
121  * Get weight of given event.
122  *
123  * \param evt event
124  * \return weight [Hz]
125  */
126  double getWeight(const Evt& evt) const override final
127  {
128  using namespace JPP;
129 
130  if (static_cast<const JFluxHelper&>(*this) &&
131  evt.w.size() > WEIGHTLIST_DIFFERENTIAL_EVENT_RATE) {
132 
133  return evt.w[WEIGHTLIST_DIFFERENTIAL_EVENT_RATE] * getFactor(evt) * getNormalisation(evt);
134 
135  } else if (evt.w.size() > WEIGHTLIST_RESCALED_EVENT_RATE) {
136 
137  return evt.w[WEIGHTLIST_RESCALED_EVENT_RATE];
138 
139  } else if (evt.w.size() > WEIGHTLIST_EVENT_RATE) {
140 
141  return evt.w[WEIGHTLIST_EVENT_RATE] * getNormalisation(evt);
142 
143  } else {
144 
145  if (!static_cast<const JFluxHelper&>(*this)) {
146  THROW(JNullPointerException, "JEvtWeightKM3BUU::getWeight(): Unspecified flux function.");
147  } else {
148  THROW(JIndexOutOfRange, "JEvtWeightKM3BUU::getWeight(): Empty " << (evt.w.size() < 3 ? "w2-" : "w3-") << "weight.");
149  }
150  }
151  }
152  };
153 }
154 
155 #endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
Monte Carlo run header.
Definition: JHead.hh:1236
Exception for accessing an index in a collection that is outside of its range.
Definition: JException.hh:108
Exception for null pointer operation.
Definition: JException.hh:234
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:180
Extensions to Evt data format.
bool is_km3buu(const JHead &header)
Check for generator.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:21
void configure(const pointer_type &p)
Configure event-weight factor.
JEvtWeightFactor & getFactor() const
Get reference to event-weight factor.
Implementation of event weighting for KM3BUU data.
JEvtWeightKM3BUU()
Default constructor.
const char *const getName() const override final
Get name.
bool check(const JHead &header) const override final
Check whether header is consistent with this event weighter.
JEvtWeightKM3BUU(const JHead &header)
Constructor.
double getWeight(const Evt &evt) const override final
Get weight of given event.
void configure(const JHead &header) override final
Weight configuration.
JEvtWeightKM3BUU(const JHead &header, const JFlux &flux)
Constructor.
Helper class for flux function.
Definition: JFluxHelper.hh:25
Low-level interface for retrieving the flux corresponding to a given event.
Definition: JFlux.hh:23
Neutrino flux.
Definition: JHead.hh:906
Template class for object cloning.
Definition: JClonable.hh:59
static const int WEIGHTLIST_DIFFERENTIAL_EVENT_RATE
Event rate per unit of flux (c.f. taglist document) [GeV m2 sr].
Definition: weightlist.hh:14
static const int WEIGHTLIST_RESCALED_EVENT_RATE
Rescaled event rate [s-1].
Definition: weightlist.hh:17
static const int WEIGHTLIST_EVENT_RATE
Event rate [s-1].
Definition: weightlist.hh:15