Jpp  18.0.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEvtWeightKM3BUU.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JEVTWEIGHTKM3BUU__
2 #define __JAANET__JEVTWEIGHTKM3BUU__
3 
6 
7 #include "JLang/JException.hh"
8 #include "JLang/JClonable.hh"
9 
10 #include "JAAnet/JHead.hh"
11 #include "JAAnet/JHeadToolkit.hh"
12 #include "JAAnet/JEvtWeight.hh"
14 #include "JAAnet/JFlux.hh"
15 
16 
17 /**
18  * \author bjung
19  */
20 
21 namespace JAANET {
22 
23  using JLANG::JClonable;
26 
27 
28  /**
29  * Implementation of event weighting for KM3BUU data.
30  */
32  public JClonable<JEvtWeight, JEvtWeightKM3BUU>,
33  public JEvtWeightFactorHelper<JFlux>
34  {
36 
37 
38  /**
39  * Default constructor.
40  */
43  {}
44 
45 
46  /**
47  * Constructor.
48  *
49  * \param header header
50  */
51  JEvtWeightKM3BUU(const JHead& header) :
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) :
67  {
68  configure(header);
70  }
71 
72 
73  /**
74  * Copy constructor.
75  *
76  * \param object original object
77  */
79  {
80  this->norm = object.norm;
81 
82  if (object.is_valid()) {
83  JFluxHelper_t::configure(*(object.get()));
84  }
85  }
86 
87 
88  /**
89  * Weight configuration.
90  *
91  * \param header header
92  */
93  void configure(const JHead& header) override
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  if (check(header) && Nevents > 0.0 && dt > 0.0) {
100 
101  norm = 1.0 / Nevents / dt;
102 
103  } else {
104 
105  THROW(JValueOutOfRange, "JEvtWeightKM3BUU::configure(): Provided header is inconsistent with KM3BUU.");
106  }
107  }
108 
109 
110  /**
111  * Check whether header is consistent with this event weighter.
112  *
113  * \param header header
114  * \return true if consistent; else false
115  */
116  bool check(const JHead& header) const override
117  {
118  return is_km3buu(header);
119  }
120 
121 
122  /**
123  * Get weight of given event.
124  *
125  * \param evt event
126  * \return weight [Hz]
127  */
128  double getWeight(const Evt& evt) const override
129  {
130  if (is_valid() && evt.w.size() > 1) {
131 
132  return evt.w[1] * getFactor(evt) * norm;
133 
134  } else if (evt.w.size() > 2) {
135 
136  return evt.w[2] * norm;
137 
138  } else {
139 
140  if (!is_valid()) {
141  THROW(JNullPointerException, "JEvtWeightKM3BUU::getWeight(): Unspecified flux function.");
142  } else {
143  THROW(JIndexOutOfRange, "JEvtWeightKM3BUU::getWeight(): Empty " << (evt.w.size() < 3 ? "w2-" : "w3-") << "weight.");
144  }
145  }
146  }
147  };
148 }
149 
150 #endif
JAANET::genvol genvol
Definition: JHead.hh:1582
Exceptions.
bool is_km3buu(const JHead &header)
Check for generator.
double getWeight(const Evt &evt) const override
Get weight of given event.
bool check(const JHead &header) const override
Check whether header is consistent with this event weighter.
double numberOfEvents
Number of events.
Definition: JHead.hh:708
JEvtWeightKM3BUU(const JEvtWeightKM3BUU &object)
Copy constructor.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
std::vector< double > w
MC: Weights w[0]=w1, w[1]=w2, w[2]=w3 (see e.g. Tag list or km3net-dataformat/definitions) ...
Definition: Evt.hh:42
JEvtWeightKM3BUU(const JHead &header)
Constructor.
bool is_valid() const
Check validity of pointer.
JEvtWeightKM3BUU()
Default constructor.
double getFactor(const Evt &evt) const
Get weight-factor of given event.
Exception for null pointer operation.
Definition: JException.hh:216
Neutrino flux.
Definition: JHead.hh:893
Template class for object cloning.
Definition: JClonable.hh:20
Helper class for event-weight factor.
void configure(const JFlux &factor)
Configure event-weight factor.
Low-level interface for retrieving the flux corresponding to a given event.
Definition: JFlux.hh:18
Monte Carlo run header.
Definition: JHead.hh:1221
Implementation of event weighting for KM3BUU data.
JAANET::tgen tgen
Definition: JHead.hh:1591
void configure(const JHead &header) override
Weight configuration.
JEvtWeightFactorHelper< JFlux > JFluxHelper_t
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
Exception for accessing an index in a collection that is outside of its range.
Definition: JException.hh:90
double numberOfSeconds
Time in seconds.
Definition: JHead.hh:1122
JEvtWeightKM3BUU(const JHead &header, const JFlux &flux)
Constructor.
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20