Jpp  18.1.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEvtWeightMupage.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JWEIGHTMUPAGE__
2 #define __JAANET__JWEIGHTMUPAGE__
3 
5 
8 
9 #include "JLang/JException.hh"
10 #include "JLang/JClonable.hh"
11 
12 #include "JAAnet/JHead.hh"
13 #include "JAAnet/JHeadToolkit.hh"
14 #include "JAAnet/JEvtWeight.hh"
17 
18 /**
19  * \author mdejong
20  */
21 
22 namespace JAANET {
23 
24  using JLANG::JClonable;
26 
27 
28  /**
29  * Implementation of event weighing for MUPAGE data.
30  */
32  public JClonable<JEvtWeight, JEvtWeightMupage>,
33  public JEvtWeightFactorHelper<JEvtWeightFactor>
34  {
35  /**
36  * Default Constructor.
37  */
40  {}
41 
42 
43  /**
44  * Constructor.
45  *
46  * \param header header
47  */
48  JEvtWeightMupage(const JHead& header) :
50  {
51  configure(header);
52  }
53 
54 
55  /**
56  * Constructor.
57  *
58  * \param header header
59  * \param factor factor
60  */
61  JEvtWeightMupage(const JHead& header,
62  const JEvtWeightFactor& factor)
63  {
64  configure(header);
66  }
67 
68 
69  /**
70  * Copy constructor.
71  *
72  * \param object original object
73  */
75  {
76  this->norm = object.norm;
77 
78  if (object.is_valid()) {
79  JEvtWeightFactorHelper::configure(*(object.get()));
80  }
81  }
82 
83 
84  /**
85  * Configuration.
86  *
87  * \param header header
88  */
89  void configure(const JHead& header) override
90  {
91  const double dt = (header.time_interval.t2 - header.time_interval.t1 > 0.0 ?
92  header.time_interval.t2 - header.time_interval.t1 :
93  header.livetime.numberOfSeconds);
94 
95  if (check(header) && dt > 0.0) {
96 
97  norm = 1.0 / dt;
98 
99  } else {
100 
101  THROW(JValueOutOfRange, "JEvtWeightMupage::configure(): Provided header is inconsistent with MUPAGE.");
102  }
103  }
104 
105 
106  /**
107  * Check whether header is consistent with this event weighter.
108  *
109  * \param header header
110  * \return true if consistent; else false
111  */
112  bool check(const JHead& header) const override
113  {
114  return is_mupage(header);
115  }
116 
117 
118  /**
119  * Get rate of given event.
120  *
121  * \param evt event
122  * \return weight [1/s]
123  */
124  double getWeight(const Evt& evt) const override
125  {
126  if (is_valid()) {
127 
128  return getFactor(evt) * getNormalisation(evt);
129 
130  } else if (evt.w.size() > WEIGHTLIST_RESCALED_EVENT_RATE) {
131 
132  return evt.w[WEIGHTLIST_RESCALED_EVENT_RATE];
133 
134  } else {
135 
136  return getNormalisation(evt);
137  }
138  }
139  };
140 }
141 
142 #endif
bool is_mupage(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:85
Exceptions.
static const int WEIGHTLIST_RESCALED_EVENT_RATE
Rescaled event rate [s-1].
Definition: weightlist.hh:17
double t1
Start time in seconds.
Definition: JHead.hh:1151
JEvtWeightMupage()
Default Constructor.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
double t2
Stop time in seconds.
Definition: JHead.hh:1152
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
bool is_valid() const
Check validity of pointer.
void configure(const JHead &header) override
Configuration.
double getFactor(const Evt &evt) const
Get weight-factor of given event.
JAANET::livetime livetime
Definition: JHead.hh:1586
Template class for object cloning.
Definition: JClonable.hh:20
JEvtWeightMupage(const JHead &header)
Constructor.
Helper class for event-weight factor.
void configure(const JEvtWeightFactor_t &factor)
Configure event-weight factor.
Monte Carlo run header.
Definition: JHead.hh:1221
JAANET::time_interval time_interval
Definition: JHead.hh:1592
Implementation of event weighing for MUPAGE data.
bool check(const JHead &header) const override
Check whether header is consistent with this event weighter.
double getWeight(const Evt &evt) const override
Get rate of given event.
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:178
JEvtWeightMupage(const JHead &header, const JEvtWeightFactor &factor)
Constructor.
Low-level interface for retrieving a specifiable multiplication factor corresponding to a given event...
double numberOfSeconds
Live time [s].
Definition: JHead.hh:883
JEvtWeightMupage(const JEvtWeightMupage &object)
Copy constructor.
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20