Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JPowerLawFlux.hh
Go to the documentation of this file.
1#ifndef __JAANET__JPOWERLAWFLUX__
2#define __JAANET__JPOWERLAWFLUX__
3
4#include "JLang/JEquals.hh"
5#include "JLang/JClonable.hh"
6
7#include "Jeep/JProperties.hh"
8
9#include "JAAnet/JFlux.hh"
11
12
13/**
14 * \author bjung
15 */
16
17namespace JAANET {}
18namespace JPP { using namespace JAANET; }
19
20namespace JAANET {
21
22 using JLANG::JEquals;
23 using JLANG::JClonable;
24
26
27
28 /**
29 * Example function object for computing power-law flux.
30 */
31 struct JPowerLawFlux final :
32 public JEquals<JPowerLawFlux>,
33 public JClonable<JFlux, JPowerLawFlux>
34 {
35 /**
36 * Default constructor.
37 */
39 normalisation(1.0),
40 spectralIndex(0.0)
41 {}
42
43
44 /**
45 * Constructor.
46 *
47 * \param normalisation normalisation [GeV * m^-2 * sr^-1 * s^-1]
48 * \param spectralIndex spectral index
49 */
51 const double spectralIndex) :
54 {
55 check_validity();
56 }
57
58
59 /**
60 * Check whether this power-law flux is valid.
61 *
62 * \return true if valid; else false
63 */
64 bool is_valid() const override final
65 {
66 return normalisation > 0.0;
67 }
68
69
70 /**
71 * Get flux of given event.
72 *
73 * \param evt event
74 * \return flux [GeV * m^-2 * sr^-1 * s^-1]
75 */
76 double getFactor(const Evt& evt) const override final
77 {
78 using namespace std;
79 using namespace JPP;
80
81 const Trk& primary = get_primary(evt);
82
83 return normalisation * pow(primary.E, -spectralIndex);
84 }
85
86
87 /**
88 * Check if this flux is identical to the given flux.
89 *
90 * \param object power-law flux object
91 * \return true if this flux is identical to given flux; else flase
92 */
93 bool equals(const JPowerLawFlux& object) const
94 {
95 return (object.normalisation == this->normalisation &&
96 object.spectralIndex == this->spectralIndex);
97 }
98
99
100 /**
101 * Get properties of this class.
102 *
103 * \param eqpars equation parameters
104 */
106 {
107 return JPowerLawFluxHelper(*this, eqpars);
108 }
109
110
111 /**
112 * Get properties of this class.
113 *
114 * \param eqpars equation parameters
115 */
117 {
118 return JPowerLawFluxHelper(*this, eqpars);
119 }
120
121
122 /**
123 * Stream input.
124 *
125 * \param in input stream
126 * \return input stream
127 */
128 std::istream& read(std::istream& in) override final
129 {
130 using namespace std;
131
132 streampos pos = in.tellg();
133
134 if (!(in >> normalisation >> spectralIndex)) {
135
136 in.clear();
137 in.seekg(pos);
138
139 JProperties properties = getProperties();
140
141 in >> properties;
142 }
143
144 check_validity();
145
146 return in;
147 }
148
149
150 private:
151
152 /**
153 * Auxiliary class for I/O of power-law flux.
154 */
156 public JProperties
157 {
158 /**
159 * Constructor.
160 *
161 * \param flux power-law flux
162 * \param eqpars equation parameters
163 */
164 template<class JPowerLawFlux_t>
165 JPowerLawFluxHelper(JPowerLawFlux_t& flux,
166 const JEquationParameters& eqpars) :
167 JProperties(eqpars, 1)
168 {
169 (*this)[JEvtWeightFactor::getTypeKey()] = "power-law flux";
170
171 this->insert(gmake_property(flux.normalisation));
172 this->insert(gmake_property(flux.spectralIndex));
173 }
174 };
175
176
177 double normalisation; //!< normalisation [GeV * m^-2 * sr^-1 * s^-1]
178 double spectralIndex; //!< spectral index >= 0
179 };
180}
181
182#endif
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
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.
const Trk & get_primary(const Evt &evt)
Auxiliary function to retrieve the primary track of an event.
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
static const char *const getTypeKey()
Get type keyword.
static JEquationParameters & getEquationParameters()
Get equation parameters.
Auxiliary class for I/O of power-law flux.
JPowerLawFluxHelper(JPowerLawFlux_t &flux, const JEquationParameters &eqpars)
Constructor.
Example function object for computing power-law flux.
double spectralIndex
spectral index >= 0
double normalisation
normalisation [GeV * m^-2 * sr^-1 * s^-1]
JProperties getProperties(const JEquationParameters &eqpars=JEvtWeightFactor::getEquationParameters()) const override final
Get properties of this class.
double getFactor(const Evt &evt) const override final
Get flux of given event.
bool equals(const JPowerLawFlux &object) const
Check if this flux is identical to the given flux.
JPowerLawFlux()
Default constructor.
JPowerLawFlux(const double normalisation, const double spectralIndex)
Constructor.
bool is_valid() const override final
Check whether this power-law flux is valid.
JProperties getProperties(const JEquationParameters &eqpars=JEvtWeightFactor::getEquationParameters()) override final
Get properties of this class.
std::istream & read(std::istream &in) override final
Stream input.
Neutrino flux.
Definition JHead.hh:906
Primary particle.
Definition JHead.hh:1174
Template class for object cloning.
Definition JClonable.hh:59
Template definition of auxiliary base class for comparison of data structures.
Definition JEquals.hh:84
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition Trk.hh:15