Jpp  17.3.0-rc.1
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 
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"
15 
16 /**
17  * \author mdejong
18  */
19 
20 namespace JAANET {
21 
22  using JLANG::JClonable;
24 
25 
26  /**
27  * Implementation of event weighing for MUPAGE data.
28  */
30  public JClonable<JEvtWeight, JEvtWeightMupage>,
31  public JEvtWeightFactorHelper<JEvtWeightFactor>
32  {
33  /**
34  * Default Constructor.
35  */
38  {}
39 
40 
41  /**
42  * Constructor.
43  *
44  * \param header header
45  */
46  JEvtWeightMupage(const JHead& header) :
48  {
49  configure(header);
50  }
51 
52 
53  /**
54  * Constructor.
55  *
56  * \param header header
57  * \param factor factor
58  */
59  JEvtWeightMupage(const JHead& header,
60  const JEvtWeightFactor& factor)
61  {
62  configure(header);
64  }
65 
66 
67  /**
68  * Copy constructor.
69  *
70  * \param object original object
71  */
73  {
74  this->norm = object.norm;
75 
76  if (object.is_valid()) {
77  JEvtWeightFactorHelper::configure(*(object.get()));
78  }
79  }
80 
81 
82  /**
83  * Configuration.
84  *
85  * \param header header
86  */
87  void configure(const JHead& header) override
88  {
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.livetime.numberOfSeconds);
92 
93  if (check(header) && dt > 0.0) {
94 
95  norm = 1.0 / dt;
96 
97  } else {
98 
99  THROW(JValueOutOfRange, "JEvtWeightMupage::configure(): Provided header is inconsistent with MUPAGE.");
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_mupage(header);
113  }
114 
115 
116  /**
117  * Get rate of given event.
118  *
119  * \param evt event
120  * \return weight [1/s]
121  */
122  double getWeight(const Evt& evt) const override
123  {
124  if (is_valid()) {
125 
126  return getFactor(evt) * norm;
127 
128  } else {
129 
130  return norm;
131  }
132  }
133  };
134 }
135 
136 #endif
bool is_mupage(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:84
Exceptions.
double t1
Start time in seconds.
Definition: JHead.hh:1097
JEvtWeightMupage()
Default Constructor.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
double t2
Stop time in seconds.
Definition: JHead.hh:1098
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:1529
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:1167
JAANET::time_interval time_interval
Definition: JHead.hh:1534
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:162
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