Jpp  15.0.2
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>,
32  {
33  /**
34  * Default Constructor.
35  */
38  W(0.0)
39  {}
40 
41 
42  /**
43  * Constructor.
44  *
45  * \param header header
46  */
47  JEvtWeightMupage(const JHead& header) :
49  {
50  configure(header);
51  }
52 
53 
54  /**
55  * Constructor.
56  *
57  * \param header header
58  * \param factor factor
59  */
60  JEvtWeightMupage(const JHead& header,
61  const JEvtWeightFactor& factor)
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 
77  if (object.is_valid()) {
78  JEvtWeightFactorHelper::configure(*(object.get()));
79  }
80  }
81 
82 
83  /**
84  * Configuration.
85  *
86  * \param header header
87  */
88  void configure(const JHead& header) override
89  {
90  const double dt = (header.time_interval.t2 - header.time_interval.t1 > 0.0 ?
91  header.time_interval.t2 - header.time_interval.t1 :
92  header.livetime.numberOfSeconds);
93 
94  if (check(header) && dt > 0.0) {
95 
96  W = 1.0 / dt;
97 
98  } else {
99 
100  THROW(JValueOutOfRange, "JEvtWeightMupage::configure(): Provided header is inconsistent with MUPAGE.");
101  }
102  }
103 
104 
105  /**
106  * Check whether header is consistent with this event weighter.
107  *
108  * \param header header
109  * \return true if consistent; else false
110  */
111  bool check(const JHead& header) const override
112  {
113  return is_mupage(header);
114  }
115 
116 
117  /**
118  * Get weight of given event.
119  *
120  * \param evt event
121  * \return weight [1/s]
122  */
123  double getWeight(const Evt& evt) const override
124  {
125  if (is_valid()) {
126 
127  return W * getFactor(evt);
128 
129  } else {
130 
131  return W;
132  }
133  }
134 
135  private:
136  double W;
137  };
138 }
139 
140 #endif
bool is_mupage(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:78
Exceptions.
double t1
Start time in seconds.
Definition: JHead.hh:1043
JEvtWeightMupage()
Default 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
bool is_valid() const
Check validity of pointer.
void configure(const JHead &header) override
Configuration.
JAANET::livetime livetime
Definition: JHead.hh:1412
double getFactor(const Evt &evt) const
Get weight-factor of given event.
Template class for object cloning.
Definition: JClonable.hh:20
JEvtWeightMupage(const JHead &header)
Constructor.
void configure(const JEvtWeightFactor &factor)
Configure event-weight factor.
Helper class for event-weight factor.
Monte Carlo run header.
Definition: JHead.hh:1113
JAANET::time_interval time_interval
Definition: JHead.hh:1417
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 weight 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:829
JEvtWeightMupage(const JEvtWeightMupage &object)
Copy constructor.
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19