Jpp  18.3.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 namespace JPP { using namespace JAANET; }
24 
25 namespace JAANET {
26 
27  using JLANG::JClonable;
28 
29 
30  /**
31  * Implementation of event weighing for MUPAGE data.
32  */
34  public JClonable<JEvtWeight, JEvtWeightMupage>,
35  public JEvtWeightFactorHelper<JEvtWeightFactor>
36  {
38 
39 
40  /**
41  * Default Constructor.
42  */
45  {}
46 
47 
48  /**
49  * Constructor.
50  *
51  * \param header header
52  */
53  JEvtWeightMupage(const JHead& header) :
55  {
56  configure(header);
57  }
58 
59 
60  /**
61  * Constructor.
62  *
63  * \param header header
64  * \param factor factor
65  */
66  JEvtWeightMupage(const JHead& header,
67  const JEvtWeightFactor& factor)
68  {
69  configure(header);
71  }
72 
73 
74  /**
75  * Copy constructor.
76  *
77  * \param object original object
78  */
80  {
81  this->norm = object.norm;
82 
83  if (static_cast<const JEvtWeightFactorHelper&>(object)) {
84  JEvtWeightFactorHelper::configure(*(object.get()));
85  }
86  }
87 
88 
89  /**
90  * Configuration.
91  *
92  * \param header header
93  */
94  void configure(const JHead& header) override
95  {
96  using namespace JPP;
97 
98  if (check(header)) {
99 
100  const double dt = ( header.time_interval.t2 - header.time_interval.t1 > 0.0 ?
101  header.time_interval.t2 - header.time_interval.t1 :
102  (header.livetime.numberOfSeconds > 0.0 ?
103  header.livetime.numberOfSeconds : 1.0) );
104 
105  norm = 1.0 / dt;
106 
107  } else {
108 
109  THROW(JValueOutOfRange, "JEvtWeightMupage::configure(): Provided header is inconsistent with MUPAGE.");
110  }
111  }
112 
113 
114  /**
115  * Check whether header is consistent with this event weighter.
116  *
117  * \param header header
118  * \return true if consistent; else false
119  */
120  bool check(const JHead& header) const override
121  {
122  return is_mupage(header);
123  }
124 
125 
126  /**
127  * Get rate of given event.
128  *
129  * \param evt event
130  * \return weight [1/s]
131  */
132  double getWeight(const Evt& evt) const override
133  {
134  if (static_cast<const JEvtWeightFactorHelper_t&>(*this)) {
135 
136  return getFactor(evt) * getNormalisation(evt);
137 
138  } else if (evt.w.size() > WEIGHTLIST_RESCALED_EVENT_RATE) {
139 
140  return evt.w[WEIGHTLIST_RESCALED_EVENT_RATE];
141 
142  } else {
143 
144  return getNormalisation(evt);
145  }
146  }
147  };
148 }
149 
150 #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:1164
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:1165
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
JAANET::time_interval time_interval
Definition: JHead.hh:1607
JEvtWeightFactorHelper< JEvtWeightFactor > JEvtWeightFactorHelper_t
void configure(const JHead &header) override
Configuration.
double getFactor(const Evt &evt) const
Get weight-factor of given event.
Monte Carlo run header.
Definition: JHead.hh:1234
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.
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:896
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
JAANET::livetime livetime
Definition: JHead.hh:1601