Jpp  15.0.4
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/JFlux.hh"
13 #include "JAAnet/JEvtWeight.hh"
14 
15 /**
16  * \author bjung
17  */
18 
19 namespace JAANET {
20 
21  using JLANG::JClonable;
24 
25 
26  /**
27  * Implementation of event weighting for KM3BUU data.
28  */
30  public JClonable<JEvtWeight, JEvtWeightKM3BUU>,
31  public JFluxHelper
32  {
33  /**
34  * Default constructor.
35  */
37  JFluxHelper(),
38  W(0.0)
39  {}
40 
41 
42  /**
43  * Constructor.
44  *
45  * \param header header
46  */
47  JEvtWeightKM3BUU(const JHead& header) :
48  JFluxHelper()
49  {
50  configure(header);
51  }
52 
53 
54  /**
55  * Constructor.
56  *
57  * \param header header
58  * \param flux flux
59  */
60  JEvtWeightKM3BUU(const JHead& header,
61  const JFlux& flux)
62  {
63  configure(header);
65  }
66 
67 
68  /**
69  * Copy constructor.
70  *
71  * \param object original object
72  */
74  {
75  this->W = object.W;
76  JFluxHelper::configure(*(object.get()));
77  }
78 
79 
80  /**
81  * Weight configuration.
82  *
83  * \param header header
84  */
85  void configure(const JHead& header) override
86  {
87  double dt = 1.0;
88 
89  if (header.DAQ.livetime_s > 0.0) {
90  dt = header.DAQ.livetime_s;
91  } else if (header.time_interval.t2 - header.time_interval.t1 > 0.0) {
92  dt = header.time_interval.t2 - header.time_interval.t1;
93  } else if (header.tgen.numberOfSeconds > 0.0) {
94  dt = header.tgen.numberOfSeconds;
95  }
96 
97  const double N = header.genvol.numberOfEvents;
98 
99  if (check(header) && N > 0.0 && dt > 0.0) {
100 
101  W = 1.0 / N / 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 W * evt.w[1] * getFlux(evt);
133 
134  } else if (evt.w.size() > 2) {
135 
136  return W * evt.w[2];
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  private:
150 
151  double W;
152  };
153 }
154 
155 #endif
JAANET::genvol genvol
Definition: JHead.hh:1408
Exceptions.
bool is_km3buu(const JHead &header)
Check for generator.
double getWeight(const Evt &evt) const override
Get weight of given event.
double t1
Start time in seconds.
Definition: JHead.hh:1043
bool check(const JHead &header) const override
Check whether header is consistent with this event weighter.
double numberOfEvents
Number of events.
Definition: JHead.hh:654
JEvtWeightKM3BUU(const JEvtWeightKM3BUU &object)
Copy constructor.
#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
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
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.
double livetime_s
Live time [s].
Definition: JHead.hh:986
bool is_valid() const
Check validity of pointer.
JEvtWeightKM3BUU()
Default constructor.
Exception for null pointer operation.
Definition: JException.hh:216
Neutrino flux.
Definition: JHead.hh:839
Template class for object cloning.
Definition: JClonable.hh:20
void configure(const JEvtWeightFactor &factor)
Configure event-weight factor.
Helper class for event-weight factor.
Monte Carlo run header.
Definition: JHead.hh:1113
double getFlux(const Evt &evt) const
Get flux of given event.
JAANET::time_interval time_interval
Definition: JHead.hh:1417
Implementation of event weighting for KM3BUU data.
JAANET::tgen tgen
Definition: JHead.hh:1416
void configure(const JHead &header) override
Weight configuration.
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
JAANET::DAQ DAQ
Definition: JHead.hh:1415
Low-level interface for retrieving a specifiable multiplication factor corresponding to a given event...
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