Jpp  16.0.1
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  */
42  JFluxHelper_t(),
43  W(0.0)
44  {}
45 
46 
47  /**
48  * Constructor.
49  *
50  * \param header header
51  */
52  JEvtWeightKM3BUU(const JHead& header) :
53  JFluxHelper_t(),
54  W(0.0)
55  {
56  configure(header);
57  }
58 
59 
60  /**
61  * Constructor.
62  *
63  * \param header header
64  * \param flux flux
65  */
66  JEvtWeightKM3BUU(const JHead& header,
67  const JFlux& flux) :
68  JFluxHelper_t(),
69  W(0.0)
70  {
71  configure(header);
73  }
74 
75 
76  /**
77  * Copy constructor.
78  *
79  * \param object original object
80  */
82  {
83  this->W = object.W;
84  JFluxHelper_t::configure(*(object.get()));
85  }
86 
87 
88  /**
89  * Weight configuration.
90  *
91  * \param header header
92  */
93  void configure(const JHead& header) override
94  {
95  const size_t Ntypes = header.flux.size();
96  const double Nevents = header.genvol.numberOfEvents / ((double) Ntypes);
97  const double dt = (header.tgen.numberOfSeconds > 0.0 ?
98  header.tgen.numberOfSeconds : 1.0);
99 
100  if (check(header) && Nevents > 0.0 && dt > 0.0) {
101 
102  W = 1.0 / Nevents / dt;
103 
104  } else {
105 
106  THROW(JValueOutOfRange, "JEvtWeightKM3BUU::configure(): Provided header is inconsistent with KM3BUU.");
107  }
108  }
109 
110 
111  /**
112  * Check whether header is consistent with this event weighter.
113  *
114  * \param header header
115  * \return true if consistent; else false
116  */
117  bool check(const JHead& header) const override
118  {
119  return is_km3buu(header);
120  }
121 
122 
123  /**
124  * Get weight of given event.
125  *
126  * \param evt event
127  * \return weight [Hz]
128  */
129  double getWeight(const Evt& evt) const override
130  {
131  if (is_valid() && evt.w.size() > 1) {
132 
133  return W * evt.w[1] * getFactor(evt);
134 
135  } else if (evt.w.size() > 2) {
136 
137  return W * evt.w[2];
138 
139  } else {
140 
141  if (!is_valid()) {
142  THROW(JNullPointerException, "JEvtWeightKM3BUU::getWeight(): Unspecified flux function.");
143  } else {
144  THROW(JIndexOutOfRange, "JEvtWeightKM3BUU::getWeight(): Empty " << (evt.w.size() < 3 ? "w2-" : "w3-") << "weight.");
145  }
146  }
147  }
148 
149 
150  private:
151 
152  double W;
153  };
154 }
155 
156 #endif
JAANET::genvol genvol
Definition: JHead.hh:1469
Exceptions.
bool is_km3buu(const JHead &header)
Check for generator.
std::vector< JAANET::flux > flux
Definition: JHead.hh:1480
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:705
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)
Definition: Evt.hh:39
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:890
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:1164
Implementation of event weighting for KM3BUU data.
JAANET::tgen tgen
Definition: JHead.hh:1477
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:1065
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:19