Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JWeightKM3BUU.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JWEIGHTKM3BUU__
2 #define __JAANET__JWEIGHTKM3BUU__
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/JWeightEvent.hh"
13 
14 /**
15  * \author bjung
16  */
17 
18 namespace JAANET {
19 
20  using JLANG::JClonable;
23 
24 
25  /**
26  * Implementation of event weighing for KM3BUU data.
27  */
28  struct JWeightKM3BUU :
29  public JClonable<JWeightEvent, JWeightKM3BUU>
30  {
31  /**
32  * Default constructor.
33  */
34  JWeightKM3BUU() : W(0.0)
35  {}
36 
37 
38  /**
39  * Constructor.
40  *
41  * \param header header
42  */
43  JWeightKM3BUU(const JHead& header)
44  {
45  configure(header);
46  }
47 
48 
49  /**
50  * Configuration.
51  *
52  * \param header header
53  * \return true if okay; else false
54  */
55  virtual void configure(const JHead& header) override
56  {
57  if (check(header) && (header.tgen.numberOfSeconds > 0.0 &&
58  header.genvol.numberOfEvents > 0.0)) {
59 
60  W = 1.0 / header.genvol.numberOfEvents / header.tgen.numberOfSeconds;
61 
62  } else {
63 
64  THROW(JValueOutOfRange, "JWeightKM3BUU::configure(): Provided header is inconsistent with KM3BUU.");
65  }
66  }
67 
68 
69  /**
70  * Check whether header is consistent with this event weighter.
71  *
72  * \param header header
73  * \return true if consistent; else false
74  */
75  virtual bool check(const JHead& header) const override
76  {
77  return is_km3buu(header);
78  }
79 
80 
81  /**
82  * Get weight of given event.
83  *
84  * \param evt event
85  * \return weight [Hz]
86  */
87  virtual double getWeight(const Evt& evt) const override
88  {
89  if (evt.w.size() > 2 && evt.w[2] > 0.0) {
90 
91  return W * evt.w[2];
92 
93  } else {
94 
95  if (evt.w.size() < 3) {
96  THROW(JIndexOutOfRange, "JWeightKM3BUU::getWeight(): w3-weight is empty.");
97  } else {
98  THROW(JValueOutOfRange, "JWeightKM3BUU::getWeight(): w3-weight is negative.");
99  }
100  }
101  }
102 
103 
104  /**
105  * Get weight of given event.
106  *
107  * \param evt event
108  * \param flux neutrino flux [m^-2 s^-1 sr^-1 GeV^-1]
109  * \return weight [Hz]
110  */
111  virtual double getWeight(const Evt& evt,
112  const double flux) const override
113  {
114  if (evt.w.size() > 1 && !(evt.w[1] < 0.0 || flux < 0.0)) {
115 
116  return W * evt.w[1] * flux;
117 
118  } else {
119 
120  if (evt.w.size() < 2) {
121  THROW(JIndexOutOfRange, "JWeightKM3BUU::getWeight(): w2-weight is empty.");
122  } else {
123  THROW(JValueOutOfRange, "JWeightKM3BUU::getWeight(): w2-weight or flux is negative.");
124  }
125  }
126  }
127 
128  private:
129  double W;
130  };
131 }
132 
133 #endif
JWeightKM3BUU()
Default constructor.
JWeightKM3BUU(const JHead &header)
Constructor.
JAANET::genvol genvol
Definition: JHead.hh:1341
Exceptions.
bool is_km3buu(const JHead &header)
Check for generator.
double numberOfEvents
Number of events.
Definition: JHead.hh:654
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
std::vector< double > w
MC: Weights w[0]=w1, w[1]=w2, w[2]]=w3 (see e.g. Tag list)
Definition: Evt.hh:39
virtual double getWeight(const Evt &evt) const override
Get weight of given event.
Neutrino flux.
Definition: JHead.hh:839
Template class for object cloning.
Definition: JClonable.hh:20
virtual double getWeight(const Evt &evt, const double flux) const override
Get weight of given event.
virtual void configure(const JHead &header) override
Configuration.
Monte Carlo run header.
Definition: JHead.hh:1050
Implementation of event weighing for KM3BUU data.
JAANET::tgen tgen
Definition: JHead.hh:1349
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
virtual bool check(const JHead &header) const override
Check whether header is consistent with this event weighter.
double numberOfSeconds
Time in seconds.
Definition: JHead.hh:981
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19