Jpp  15.0.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEvtWeightHelper.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JEVTWEIGHTHELPER__
2 #define __JAANET__JEVTWEIGHTHELPER__
3 
6 
8 
9 #include "JAAnet/JHead.hh"
10 #include "JAAnet/JEvtWeight.hh"
11 // #include "JAAnet/JEvtWeightDAQ.hh"
12 // #include "JAAnet/JEvtWeightMupage.hh"
13 // #include "JAAnet/JEvtWeightGSeaGen.hh"
14 // #include "JAAnet/JEvtWeightKM3BUU.hh"
15 
16 /**
17  * \author mdejong
18  */
19 
20 namespace JAANET {
21 
25 
26 
27  /**
28  * Helper class for event weighing.
29  */
31  public JSharedPointer<JEvtWeight>,
32  public JHead
33  {
35 
36  /**
37  * Default constructor.
38  */
40  counter(0)
41  {}
42 
43 
44  /**
45  * Constructor.
46  *
47  * \param weighter event weighter
48  */
49  JEvtWeightHelper(const JEvtWeight& weighter) :
50  counter(0)
51  {
52  this->configure(weighter);
53  }
54 
55 
56  /**
57  * Configuration.
58  *
59  * \param weighter event weighter
60  */
61  void configure(const JEvtWeight& weighter)
62  {
63  counter = 0;
64 
65  reset(weighter.clone());
66  }
67 
68 
69  /**
70  * Check if a given header is consistent with this event weighter.
71  *
72  * \param header header
73  * \return true if header is consistent with this event weighter; else false.
74  */
75  bool check(const JHead& header) const
76  {
77  return (is_valid() ? get()->check(header) : false);
78  }
79 
80 
81  /**
82  * Add header.
83  *
84  * \param header header
85  */
86  void add(const JHead& header)
87  {
88  if (check(header)) {
89 
90  if (counter == 0) {
91  JHead::setHeader(header);
92  } else {
93  JHead::add(header);
94  }
95 
96  ++counter;
97 
98  get()->configure(getHeader());
99 
100  } else {
101 
102  THROW(JNullPointerException, "JEvtWeightHelper::add(): headers do not match.");
103  }
104  }
105 
106 
107  /**
108  * Get weight of given event.
109  *
110  * \param evt event
111  * \return weight [Hz]
112  */
113  double getWeight(const Evt& evt) const
114  {
115  if (is_valid()) {
116  return get()->getWeight(evt);
117  } else {
118  THROW(JNullPointerException, "JEvtWeightHelper::getWeight(): Event weighter is null.");
119  }
120  }
121 
122  private:
123  int counter;
124  };
125 }
126 
127 #endif
void configure(const JEvtWeight &weighter)
Configuration.
void setHeader(const JHead &header)
Set header.
Definition: JHead.hh:1168
const JHead & getHeader() const
Get header.
Definition: JHead.hh:1146
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
JEvtWeightHelper()
Default constructor.
bool check(const JHead &header) const
Check if a given header is consistent with this event weighter.
JHead & add(const JHead &header)
Addition of headers.
Definition: JHead.hh:1345
bool is_valid() const
Check validity of pointer.
virtual clone_type clone() const override
Get clone of this object.
Definition: JClonable.hh:69
The template JSharedPointer class can be used to share a pointer to an object.
Low-level interface for event weighing.
Definition: JEvtWeight.hh:24
Exception for null pointer operation.
Definition: JException.hh:216
Monte Carlo run header.
Definition: JHead.hh:1113
double getWeight(const Evt &evt) const
Get weight of given event.
JEvtWeightHelper(const JEvtWeight &weighter)
Constructor.
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
virtual void reset() override
Reset pointer.
Helper class for event weighing.
void add(const JHead &header)
Add header.
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19