Jpp  18.2.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 
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  {
37  /**
38  * Default Constructor.
39  */
42  {}
43 
44 
45  /**
46  * Constructor.
47  *
48  * \param header header
49  */
50  JEvtWeightMupage(const JHead& header) :
52  {
53  configure(header);
54  }
55 
56 
57  /**
58  * Constructor.
59  *
60  * \param header header
61  * \param factor factor
62  */
63  JEvtWeightMupage(const JHead& header,
64  const JEvtWeightFactor& factor)
65  {
66  configure(header);
68  }
69 
70 
71  /**
72  * Copy constructor.
73  *
74  * \param object original object
75  */
77  {
78  this->norm = object.norm;
79 
80  if (object.is_valid()) {
81  JEvtWeightFactorHelper::configure(*(object.get()));
82  }
83  }
84 
85 
86  /**
87  * Configuration.
88  *
89  * \param header header
90  */
91  void configure(const JHead& header) override
92  {
93  using namespace JPP;
94 
95  if (check(header)) {
96 
97  const double dt = ( header.time_interval.t2 - header.time_interval.t1 > 0.0 ?
98  header.time_interval.t2 - header.time_interval.t1 :
99  (header.livetime.numberOfSeconds > 0.0 ?
100  header.livetime.numberOfSeconds : 1.0) );
101 
102  norm = 1.0 / dt;
103 
104  } else {
105 
106  THROW(JValueOutOfRange, "JEvtWeightMupage::configure(): Provided header is inconsistent with MUPAGE.");
107  }
108  }
109 
110 
111  /**
112  * Check whether header is consistent with this event weighter.
113  *
114  * \param header header
115  * \return true if consistent; else false
116  */
117  bool check(const JHead& header) const override
118  {
119  return is_mupage(header);
120  }
121 
122 
123  /**
124  * Get rate of given event.
125  *
126  * \param evt event
127  * \return weight [1/s]
128  */
129  double getWeight(const Evt& evt) const override
130  {
131  if (is_valid()) {
132 
133  return getFactor(evt) * getNormalisation(evt);
134 
135  } else if (evt.w.size() > WEIGHTLIST_RESCALED_EVENT_RATE) {
136 
137  return evt.w[WEIGHTLIST_RESCALED_EVENT_RATE];
138 
139  } else {
140 
141  return getNormalisation(evt);
142  }
143  }
144  };
145 }
146 
147 #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
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.
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