Jpp master_rocky-44-g75b7c4f75
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 */
55
56
57 /**
58 * Check whether this power-law flux is valid.
59 *
60 * \return true if valid; else false
61 */
62 bool is_valid() const override final
63 {
64 return normalisation > 0.0;
65 }
66
67
68 /**
69 * Get flux of given event.
70 *
71 * \param evt event
72 * \return flux [GeV * m^-2 * sr^-1 * s^-1]
73 */
74 double getFactor(const Evt& evt) const override final
75 {
76 using namespace std;
77 using namespace JPP;
78
79 const Trk& primary = get_primary(evt);
80
81 return normalisation * pow(primary.E, -spectralIndex);
82 }
83
84
85 /**
86 * Check if this flux is identical to the given flux.
87 *
88 * \param object power-law flux object
89 * \return true if this flux is identical to given flux; else flase
90 */
91 bool equals(const JPowerLawFlux& object) const
92 {
93 return (object.normalisation == this->normalisation &&
94 object.spectralIndex == this->spectralIndex);
95 }
96
97
98 /**
99 * Get properties of this class.
100 *
101 * \param eqpars equation parameters
102 */
104 {
105 return JPowerLawFluxHelper(*this, eqpars);
106 }
107
108
109 /**
110 * Get properties of this class.
111 *
112 * \param eqpars equation parameters
113 */
115 {
116 return JPowerLawFluxHelper(*this, eqpars);
117 }
118
119
120 /**
121 * Stream input.
122 *
123 * \param in input stream
124 * \return input stream
125 */
126 std::istream& read(std::istream& in) override final
127 {
128 using namespace std;
129
130 streampos pos = in.tellg();
131
132 if (!(in >> normalisation >> spectralIndex)) {
133
134 in.clear();
135 in.seekg(pos);
136
137 JProperties properties = getProperties();
138
139 in >> properties;
140 }
141
142 check_validity();
143
144 return in;
145 }
146
147
148 private:
149
150 /**
151 * Auxiliary class for I/O of power-law flux.
152 */
154 public JProperties
155 {
156 /**
157 * Constructor.
158 *
159 * \param flux power-law flux
160 * \param eqpars equation parameters
161 */
162 template<class JPowerLawFlux_t>
163 JPowerLawFluxHelper(JPowerLawFlux_t& flux,
164 const JEquationParameters& eqpars) :
165 JProperties(eqpars, 1)
166 {
167 (*this)[JEvtWeightFactor::getTypeKey()] = "power-law flux";
168
169 this->insert(gmake_property(flux.normalisation));
170 this->insert(gmake_property(flux.spectralIndex));
171 }
172 };
173
174
175 double normalisation; //!< normalisation [GeV * m^-2 * sr^-1 * s^-1]
176 double spectralIndex; //!< spectral index >= 0
177 };
178}
179
180#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)
Get primary.
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