Jpp  19.1.0
the software that should make you happy
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  */
33  struct JEvtWeightMupage final :
35  public JClonable<JEvtWeight, JEvtWeightMupage>
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  * Get name.
73  *
74  * \return name
75  */
76  const char* const getName() const override final
77  {
78  return "MUPAGE";
79  }
80 
81 
82  /**
83  * Configuration.
84  *
85  * \param header header
86  */
87  void configure(const JHead& header) override final
88  {
89  using namespace JPP;
90 
91  if (check(header)) {
92 
93  const double dt = ( header.time_interval.t2 - header.time_interval.t1 > 0.0 ?
94  header.time_interval.t2 - header.time_interval.t1 :
95  (header.livetime.numberOfSeconds > 0.0 ?
96  header.livetime.numberOfSeconds : 1.0) );
97 
98  setNormalisation(1.0 / dt);
99 
100  } else {
101 
102  THROW(JValueOutOfRange, "JEvtWeightMupage::configure(): Provided header is inconsistent with MUPAGE.");
103  }
104  }
105 
106 
107  /**
108  * Check whether header is consistent with this event weighter.
109  *
110  * \param header header
111  * \return true if consistent; else false
112  */
113  bool check(const JHead& header) const override final
114  {
115  return is_mupage(header);
116  }
117 
118 
119  /**
120  * Get rate of given event.
121  *
122  * \param evt event
123  * \return weight [1/s]
124  */
125  double getWeight(const Evt& evt) const override final
126  {
127  if (static_cast<const JEvtWeightFactorHelper&>(*this)) {
128 
129  return getFactor(evt) * getNormalisation(evt);
130 
131  } else if (evt.w.size() > WEIGHTLIST_RESCALED_EVENT_RATE) {
132 
133  return evt.w[WEIGHTLIST_RESCALED_EVENT_RATE];
134 
135  } else {
136 
137  return getNormalisation(evt);
138  }
139  }
140  };
141 }
142 
143 #endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
Monte Carlo run header.
Definition: JHead.hh:1236
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:180
Extensions to Evt data format.
bool is_mupage(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:85
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:21
Helper class for event-weight factor.
void configure(const pointer_type &p)
Configure event-weight factor.
JEvtWeightFactor & getFactor() const
Get reference to event-weight factor.
Abstract base class for specifiable event-weight factors.
Implementation of event weighing for MUPAGE data.
JEvtWeightMupage(const JHead &header, const JEvtWeightFactor &factor)
Constructor.
JEvtWeightMupage()
Default Constructor.
const char *const getName() const override final
Get name.
void configure(const JHead &header) override final
Configuration.
JEvtWeightMupage(const JHead &header)
Constructor.
bool check(const JHead &header) const override final
Check whether header is consistent with this event weighter.
double getWeight(const Evt &evt) const override final
Get rate of given event.
Template class for object cloning.
Definition: JClonable.hh:59
static const int WEIGHTLIST_RESCALED_EVENT_RATE
Rescaled event rate [s-1].
Definition: weightlist.hh:17