Jpp  15.0.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEvtWeightFactorFunction.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JEVTWEIGHTFACTORFUNCTION__
2 #define __JAANET__JEVTWEIGHTFACTORFUNCTION__
3 
5 
6 #include "JLang/JClonable.hh"
7 
9 
10 /**
11  * \author bjung
12  */
13 
14 namespace JAANET {
15 
16  using JLANG::JClonable;
17 
18 
19  /**
20  * Implementation of event-weight factor interface.\n
21  * Note that the template argument refers to a function of which the copy constuctor needs to be defined.
22  */
23  template<class JFunction_t>
25  public JClonable<JEvtWeightFactor, JEvtWeightFactorFunction<JFunction_t> >
26  {
27  /**
28  * Constructor.
29  *
30  * \param function function for event-weight factor
31  */
32  JEvtWeightFactorFunction(const JFunction_t& function) :
34  {}
35 
36 
37  /**
38  * Get weight-factor for given event.
39  *
40  * \param evt event
41  * \return event-weight factor
42  */
43  double getFactor(const Evt& evt) const override
44  {
45  return function(evt);
46  }
47 
48  private:
49 
50  JFunction_t function;
51  };
52 
53 
54  /**
55  * Type definition of pointer to event-weight factor.
56  */
57  typedef double (*pEvtWeightFactor)(const Evt&);
58 
59 
60  /**
61  * Implementation of C-style event-weight factor.
62  */
63  template<>
65  public JClonable<JEvtWeightFactor, JEvtWeightFactorFunction<pEvtWeightFactor> >
66  {
67  /**
68  * Constructor.
69  *
70  * \param function event-weight factor
71  */
74  {}
75 
76 
77  /**
78  * Get weight-factor for given event.
79  *
80  * \param evt event
81  * \return event-weight factor
82  */
83  double getFactor(const Evt& evt) const override
84  {
85  return (*function)(evt);
86  }
87 
88  private:
89 
90  pEvtWeightFactor function;
91  };
92 
93 
94  /**
95  * Auxiliary method for creating an interface to an event-weight factor.
96  *
97  * \param function function object
98  * \return event-weight factor interface
99  */
100  template<class JFunction_t>
101  inline JEvtWeightFactorFunction<JFunction_t> make_weightFactor(const JFunction_t& function) {
102  return JEvtWeightFactorFunction<JFunction_t>(function);
103  }
104 
105 
106  /**
107  * Auxiliary method for creating an interface to an event-weight factor.
108  *
109  * \param function function pointer
110  * \return event-weight factor interface
111  */
114  }
115 }
116 
117 #endif
Implementation of C-style event-weight factor.
double getFactor(const Evt &evt) const override
Get weight-factor for given event.
double getFactor(const Evt &evt) const override
Get weight-factor for given event.
Implementation of event-weight factor interface.
JEvtWeightFactorFunction(pEvtWeightFactor function)
Constructor.
JEvtWeightFactorFunction(const JFunction_t &function)
Constructor.
Template class for object cloning.
Definition: JClonable.hh:20
JEvtWeightFactorFunction< JFunction_t > make_weightFactor(const JFunction_t &function)
Auxiliary method for creating an interface to an event-weight factor.
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19
double(* pEvtWeightFactor)(const Evt &)
Type definition of pointer to event-weight factor.