Jpp  master_rocky
the software that should make you happy
JEvtWeightFactorHelper.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JEVTWEIGHTFACTORHELPER__
2 #define __JAANET__JEVTWEIGHTFACTORHELPER__
3 
4 #include <memory>
5 
7 
8 #include "Jeep/JProperties.hh"
9 
11 
12 
13 /**
14  * \author bjung
15  */
16 
17 namespace JAANET {}
18 namespace JPP { using namespace JAANET; }
19 
20 namespace JAANET {
21 
22  using JEEP::JProperties;
23 
24 
25  /**
26  * Helper class for event-weight factor.
27  */
29  public std::shared_ptr<JEvtWeightFactor>
30  {
31  typedef std::shared_ptr<JEvtWeightFactor> pointer_type;
32 
33 
34  /**
35  * Default constructor.
36  */
38  pointer_type()
39  {}
40 
41 
42  /**
43  * Constructor.
44  *
45  * \param p shared pointer to event-weight factor
46  */
48  pointer_type(p)
49  {}
50 
51 
52  /**
53  * Constructor.
54  *
55  * \param factor event-weight factor
56  */
58  {
59  configure(factor);
60  }
61 
62 
63  /**
64  * Configure event-weight factor.
65  *
66  * \param p pointer to event-weight factor
67  */
68  void configure(const pointer_type& p)
69  {
70  static_cast<pointer_type&>(*this) = p;
71  }
72 
73 
74  /**
75  * Configure event-weight factor.
76  *
77  * \param factor event-weight factor
78  */
79  void configure(const JEvtWeightFactor& factor)
80  {
81  using namespace JPP;
82 
83  JEvtWeightFactor* p = dynamic_cast<JEvtWeightFactor*>(factor.clone());
84 
85  if (p != NULL) {
86  this->reset(p);
87  } else {
88  THROW(JNullPointerException, "JEvtWeightFactorHelper::configure(): Could not retrieve event-weight factor interface.");
89  }
90  }
91 
92 
93  /**
94  * Get reference to event-weight factor.
95  *
96  * \return reference to event-weight factor
97  */
99  {
100  using namespace JPP;
101 
102  if (static_cast<const JEvtWeightFactorHelper&>(*this)) {
103  return *(this->get());
104  } else {
105  THROW(JNullPointerException, "JEvtWeightFactorHelper::getFactor(): Event-weight factor is not set.");
106  }
107  }
108 
109 
110  /**
111  * Check whether this event-weight factor is valid.
112  *
113  * \return true if valid; else false
114  */
115  bool is_valid() const
116  {
117  const JEvtWeightFactorHelper& helper = static_cast<const JEvtWeightFactorHelper&>(*this);
118 
119  return (helper && helper->is_valid());
120  }
121 
122 
123  /**
124  * Get weight-factor of given event.
125  *
126  * \param evt event
127  * \return event-weight factor
128  */
129  double getFactor(const Evt& evt) const
130  {
131  const JEvtWeightFactor& weightFactor = getFactor();
132 
133  return weightFactor.getFactor(evt);
134  }
135 
136 
137  /**
138  * Get weight-factor of given event.
139  *
140  * \param evt event
141  * \return event-weight factor
142  */
143  double operator()(const Evt& evt) const
144  {
145  return getFactor(evt);
146  }
147 
148 
149  /**
150  * Get properties of this class.
151  *
152  * \param eqpars equation parameters
153  */
155  {
156  const JEvtWeightFactor& weightFactor = getFactor();
157 
158  return weightFactor.getProperties(eqpars);
159  }
160 
161 
162  /**
163  * Get properties of this class.
164  *
165  * \param eqpars equation parameters
166  */
168  {
169  const JEvtWeightFactor& weightFactor = getFactor();
170 
171  return weightFactor.getProperties(eqpars);
172  }
173  };
174 }
175 
176 #endif
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
Utility class to parse parameter values.
Utility class to parse parameter values.
Definition: JProperties.hh:501
Simple data structure to support I/O of equations (see class JLANG::JEquation).
Exception for null pointer operation.
Definition: JException.hh:234
Extensions to Evt data format.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
void reset(T &value)
Reset value.
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.
JEvtWeightFactorHelper(const pointer_type &p)
Constructor.
double operator()(const Evt &evt) const
Get weight-factor of given event.
JEvtWeightFactorHelper()
Default constructor.
void configure(const pointer_type &p)
Configure event-weight factor.
void configure(const JEvtWeightFactor &factor)
Configure event-weight factor.
double getFactor(const Evt &evt) const
Get weight-factor of given event.
JProperties getProperties(const JEquationParameters &eqpars=JEvtWeightFactor::getEquationParameters()) const
Get properties of this class.
JProperties getProperties(const JEquationParameters &eqpars=JEvtWeightFactor::getEquationParameters())
Get properties of this class.
std::shared_ptr< JEvtWeightFactor > pointer_type
JEvtWeightFactor & getFactor() const
Get reference to event-weight factor.
JEvtWeightFactorHelper(const JEvtWeightFactor &factor)
Constructor.
bool is_valid() const
Check whether this event-weight factor is valid.
Abstract base class for specifiable event-weight factors.
static JEquationParameters & getEquationParameters()
Get equation parameters.
virtual JProperties getProperties(const JEquationParameters &eqpars=JEvtWeightFactor::getEquationParameters())
Get properties of this class.
virtual double getFactor(const Evt &evt) const =0
Get event-weight factor of given event.
virtual clone_type clone() const override
Get clone of this object.
Definition: JClonable.hh:69