Jpp  19.0.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  setNormalisation(object.getNormalisation());
82 
83  if (static_cast<const JEvtWeightFactorHelper&>(object)) {
84  JEvtWeightFactorHelper::configure(*(object.get()));
85  }
86  }
87 
88 
89  /**
90  * Get name.
91  *
92  * \return name
93  */
94  virtual const char* const getName() const override
95  {
96  return "MUPAGE";
97  }
98 
99 
100  /**
101  * Configuration.
102  *
103  * \param header header
104  */
105  void configure(const JHead& header) override
106  {
107  using namespace JPP;
108 
109  if (check(header)) {
110 
111  const double dt = ( header.time_interval.t2 - header.time_interval.t1 > 0.0 ?
112  header.time_interval.t2 - header.time_interval.t1 :
113  (header.livetime.numberOfSeconds > 0.0 ?
114  header.livetime.numberOfSeconds : 1.0) );
115 
116  setNormalisation(1.0 / dt);
117 
118  } else {
119 
120  THROW(JValueOutOfRange, "JEvtWeightMupage::configure(): Provided header is inconsistent with MUPAGE.");
121  }
122  }
123 
124 
125  /**
126  * Check whether header is consistent with this event weighter.
127  *
128  * \param header header
129  * \return true if consistent; else false
130  */
131  bool check(const JHead& header) const override
132  {
133  return is_mupage(header);
134  }
135 
136 
137  /**
138  * Get rate of given event.
139  *
140  * \param evt event
141  * \return weight [1/s]
142  */
143  double getWeight(const Evt& evt) const override
144  {
145  if (static_cast<const JEvtWeightFactorHelper_t&>(*this)) {
146 
147  return getFactor(evt) * getNormalisation(evt);
148 
149  } else if (evt.w.size() > WEIGHTLIST_RESCALED_EVENT_RATE) {
150 
151  return evt.w[WEIGHTLIST_RESCALED_EVENT_RATE];
152 
153  } else {
154 
155  return getNormalisation(evt);
156  }
157  }
158  };
159 }
160 
161 #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
virtual const char *const getName() const override
Get name.
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:1610
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:1604