Jpp test-rotations-old-57-g407471f53
the software that should make you happy
Loading...
Searching...
No Matches
JEvtWeightFactorConstant.hh
Go to the documentation of this file.
1#ifndef __JAANET__JEVTWEIGHTFACTORCONSTANT__
2#define __JAANET__JEVTWEIGHTFACTORCONSTANT__
3
4#include "JLang/JManip.hh"
5#include "JLang/JClonable.hh"
7
8#include "Jeep/JProperties.hh"
9
11
12
13/**
14 * \author bjung
15 */
16
17namespace JAANET {}
18namespace JPP { using namespace JAANET; }
19
20namespace JAANET {
21
22 using JLANG::JClonable;
24
25 using JEEP::JProperties;
26
27
28 /**
29 * Class for constant event-weight factors.
30 *
31 * The template argument refers to the type of event-weighter.
32 */
33 template<class JEvtWeightFactor_t>
35 public JComparable<JEvtWeightFactorConstant<JEvtWeightFactor_t> >,
36 public JClonable<JEvtWeightFactor_t, JEvtWeightFactorConstant<JEvtWeightFactor_t> >
37 {
39
40
41 /**
42 * Default constructor.
43 */
47
48
49 /**
50 * Constructor.
51 *
52 * \param constant constant
53 */
56 {
57 this->check_validity();
58 }
59
60
61 /**
62 * Check whether this constant event-weight factor is valid.
63 *
64 * \return true if valid; else false
65 */
66 bool is_valid() const override final
67 {
68 return constant > 0.0;
69 }
70
71
72 /**
73 * Get event-weight factor of given event.
74 *
75 * \param evt event
76 * \return event-weight factor
77 */
78 double getFactor(const Evt& evt) const override final
79 {
80 return constant;
81 }
82
83
84 /**
85 * Check if this event-weight constant is less than given event-weight constant.
86 *
87 * \param object event-weight constant
88 * \return true if this event-weight constant is less than given event-weight constant; else false
89 */
90 bool less(const JEvtWeightFactorConstant_t& object) const
91 {
92 return this->constant < object.constant;
93 }
94
95
96 /**
97 * Get properties of this class.
98 *
99 * \param eqpars equation parameters
100 */
102 {
103 return JEvtWeightFactorConstantHelper(*this, eqpars);
104 }
105
106
107 /**
108 * Get properties of this class.
109 *
110 * \param eqpars equation parameters
111 */
113 {
114 return JEvtWeightFactorConstantHelper(*this, eqpars);
115 }
116
117
118 /**
119 * Stream input.
120 *
121 * \param in input stream
122 * \return input stream
123 */
124 std::istream& read(std::istream& in) override final
125 {
126 using namespace std;
127
128 const streampos pos = in.tellg();
129 const ios_base::iostate state = in.rdstate();
130
131 if (!(in >> constant)) {
132
133 in.clear(state);
134 in.seekg(pos);
135
136 JProperties properties = getProperties();
137
138 in >> properties;
139 }
140
141 this->check_validity();
142
143 return in;
144 }
145
146
147 /**
148 * Write event-weight factor to output
149 *
150 * \param out output stream
151 * \return output stream
152 */
153 std::ostream& write(std::ostream& out) const override final
154 {
155 using namespace JPP;
156
157 return out << FIXED(10,3) << constant;
158 }
159
160
161 private:
162
163 /**
164 * Auxiliary class for I/O of constant event-weight factor.
165 */
167 public JProperties
168 {
169 /**
170 * Constructor.
171 *
172 * \param factor constant event-weight factor
173 * \param eqpars equation parameters
174 */
175 template<class JEvtWeightFactorConstant_T>
176 JEvtWeightFactorConstantHelper(JEvtWeightFactorConstant_T& factor,
177 const JEquationParameters& eqpars) :
178 JProperties(eqpars, 1)
179 {
180 (*this)[JEvtWeightFactor::getTypeKey()] = "constant";
181
182 this->insert(gmake_property(factor.constant));
183 }
184 };
185
186
187 double constant; //!< constant value
188 };
189}
190
191#endif
I/O manipulators.
Utility class to parse parameter values.
#define gmake_property(A)
macros to convert (template) parameter to JPropertiesElement object
Utility class to parse parameter values.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
Extensions to Evt data format.
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
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Auxiliary class for I/O of constant event-weight factor.
JEvtWeightFactorConstantHelper(JEvtWeightFactorConstant_T &factor, const JEquationParameters &eqpars)
Constructor.
Class for constant event-weight factors.
double getFactor(const Evt &evt) const override final
Get event-weight factor of given event.
JEvtWeightFactorConstant(const double constant)
Constructor.
JEvtWeightFactorConstant< JEvtWeightFactor_t > JEvtWeightFactorConstant_t
JProperties getProperties(const JEquationParameters &eqpars=JEvtWeightFactor::getEquationParameters()) const override final
Get properties of this class.
bool less(const JEvtWeightFactorConstant_t &object) const
Check if this event-weight constant is less than given event-weight constant.
std::ostream & write(std::ostream &out) const override final
Write event-weight factor to output.
JProperties getProperties(const JEquationParameters &eqpars=JEvtWeightFactor::getEquationParameters()) override final
Get properties of this class.
bool is_valid() const override final
Check whether this constant event-weight factor is valid.
std::istream & read(std::istream &in) override final
Stream input.
static const char *const getTypeKey()
Get type keyword.
static JEquationParameters & getEquationParameters()
Get equation parameters.
Template class for object cloning.
Definition JClonable.hh:59
Template definition of auxiliary base class for comparison of data structures.