Jpp - the software that should make you happy
 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/JFlux.hh"
12 #include "JAAnet/JFluxHelper.hh"
13 #include "JAAnet/JHeadToolkit.hh"
14 #include "JAAnet/JWeightEvent.hh"
15 
16 /**
17  * \author bjung
18  */
19 
20 namespace JAANET {
21 
22  using JLANG::JClonable;
25 
26 
27  /**
28  * Implementation of event weighting for KM3BUU data.
29  */
30  struct JWeightKM3BUU :
31  public JClonable<JWeightEvent, JWeightKM3BUU>,
32  public JFluxHelper
33  {
34  /**
35  * Default constructor.
36  */
38  JFluxHelper(),
39  W(0.0)
40  {}
41 
42 
43  /**
44  * Constructor.
45  *
46  * \param header header
47  */
48  JWeightKM3BUU(const JHead& header) :
49  JFluxHelper()
50  {
51  configure(header);
52  }
53 
54 
55  /**
56  * Constructor.
57  *
58  * \param header header
59  * \param flux flux
60  */
61  JWeightKM3BUU(const JHead& header,
62  const JFlux& flux)
63  {
64  configure(header);
66  }
67 
68 
69  /**
70  * Copy constructor.
71  *
72  * \param object original object
73  */
75  {
76  this->W = object.W;
77  JFluxHelper::configure(*(object.get()));
78  }
79 
80 
81  /**
82  * Weight configuration.
83  *
84  * \param header header
85  */
86  void configure(const JHead& header) override
87  {
88  const double N = header.genvol.numberOfEvents;
89  const double dt = (header.time_interval.t2 - header.time_interval.t1 > 0.0 ?
90  header.time_interval.t2 - header.time_interval.t1 :
91  header.tgen.numberOfSeconds);
92 
93  if (check(header) && N > 0.0 && dt > 0.0) {
94 
95  W = 1.0 / N / dt;
96 
97  } else {
98 
99  THROW(JValueOutOfRange, "JWeightKM3BUU::configure(): Provided header is inconsistent with KM3BUU.");
100  }
101  }
102 
103 
104  /**
105  * Check whether header is consistent with this event weighter.
106  *
107  * \param header header
108  * \return true if consistent; else false
109  */
110  bool check(const JHead& header) const override
111  {
112  return is_km3buu(header);
113  }
114 
115 
116  /**
117  * Get weight of given event.
118  *
119  * \param evt event
120  * \return weight [Hz]
121  */
122  double getWeight(const Evt& evt) const override
123  {
124  if (is_valid() && evt.w.size() > 1) {
125 
126  return W * evt.w[1] * getFlux(evt);
127 
128  } else if (evt.w.size() > 2) {
129 
130  return W * evt.w[2];
131 
132  } else {
133 
134  if (!is_valid()) {
135  THROW(JNullPointerException, "JWeightKM3BUU::getWeight(): Unspecified flux function.");
136  } else {
137  THROW(JIndexOutOfRange, "JWeightKM3BUU::getWeight(): Empty " << (evt.w.size() < 3 ? "w2-" : "w3-") << "weight.");
138  }
139  }
140  }
141 
142 
143  private:
144 
145  double W;
146  };
147 }
148 
149 #endif
JWeightKM3BUU()
Default constructor.
JWeightKM3BUU(const JHead &header)
Constructor.
JAANET::genvol genvol
Definition: JHead.hh:1408
Exceptions.
bool is_km3buu(const JHead &header)
Check for generator.
double t1
Start time in seconds.
Definition: JHead.hh:1043
void configure(const JFlux &function)
Flux configuration.
Definition: JFluxHelper.hh:51
void configure(const JHead &header) override
Weight configuration.
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
double t2
Stop time in seconds.
Definition: JHead.hh:1044
std::vector< double > w
MC: Weights w[0]=w1, w[1]=w2, w[2]]=w3 (see e.g. Tag list)
Definition: Evt.hh:39
JWeightKM3BUU(const JHead &header, const JFlux &flux)
Constructor.
bool is_valid() const
Check validity of pointer.
Exception for null pointer operation.
Definition: JException.hh:216
Neutrino flux.
Definition: JHead.hh:839
Helper class for event weighing.
Definition: JFluxHelper.hh:23
Template class for object cloning.
Definition: JClonable.hh:20
double getFlux(const Evt &evt) const
Get flux of given event.
Definition: JFluxHelper.hh:63
bool check(const JHead &header) const override
Check whether header is consistent with this event weighter.
Low-level interface for retrieving flux corresponding to an event.
Definition: JFlux.hh:22
Monte Carlo run header.
Definition: JHead.hh:1113
JAANET::time_interval time_interval
Definition: JHead.hh:1417
Implementation of event weighting for KM3BUU data.
JAANET::tgen tgen
Definition: JHead.hh:1416
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:1014
then usage $script[input file[working directory[option]]] nWhere option can be N
Definition: JMuonPostfit.sh:35
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19
JWeightKM3BUU(const JWeightKM3BUU &object)
Copy constructor.
double getWeight(const Evt &evt) const override
Get weight of given event.