Jpp  18.5.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPowerLawFlux.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JPOWERLAWFLUX__
2 #define __JAANET__JPOWERLAWFLUX__
3 
4 #include "JLang/JEquals.hh"
5 
7 
8 
9 /**
10  * \author bjung
11  */
12 
13 namespace JAANET {}
14 namespace JPP { using namespace JAANET; }
15 
16 namespace JAANET {
17 
18  /**
19  * Example function object for computing power-law flux.
20  */
21  struct JPowerLawFlux :
22  public JLANG::JEquals<JPowerLawFlux>
23  {
24  /**
25  * Default constructor.
26  */
28  normalisation(1.0),
29  spectralIndex(0.0)
30  {}
31 
32 
33  /**
34  * Constructor.
35  *
36  * \param normalisation normalisation [GeV * m^-2 * sr^-1 * s^-1]
37  * \param spectralIndex spectral index
38  */
40  const double spectralIndex) :
41  normalisation(normalisation),
42  spectralIndex(spectralIndex)
43  {}
44 
45 
46  /**
47  * Get flux of given event.
48  *
49  * \param evt event
50  * \return flux [GeV * m^-2 * sr^-1 * s^-1]
51  */
52  double operator()(const Evt& evt) const
53  {
54  using namespace std;
55  using namespace JPP;
56 
57  if (has_neutrino(evt)) {
58 
59  const Trk& neutrino = get_neutrino(evt);
60 
61  return normalisation * pow(neutrino.E, -spectralIndex);
62 
63  } else {
64 
65  THROW(JNullPointerException, "JPowerLawFlux::operator(): No neutrino for event " << evt.id << '.' << endl);
66  }
67  }
68 
69 
70  /**
71  * Check if this flux is identical to the given flux.
72  *
73  * \param object power-law flux object
74  * \return true if this flux is identical to given flux; else flase
75  */
76  bool equals(const JPowerLawFlux& object) const
77  {
78  return (object.normalisation == this->normalisation &&
79  object.spectralIndex == this->spectralIndex);
80  }
81 
82 
83  /**
84  * Stream input.
85  *
86  * \param in input stream
87  * \param object power-law flux
88  * \return input stream
89  */
90  inline friend std::istream& operator>>(std::istream& in,
91  JPowerLawFlux& object)
92  {
93  return in >> object.normalisation
94  >> object.spectralIndex;
95  }
96 
97 
98  /**
99  * Write power-law parameters to output stream.
100  *
101  * \param out output stream
102  * \param object power-law flux
103  * \return output stream
104  */
105  inline friend std::ostream& operator<<(std::ostream& out,
106  const JPowerLawFlux& object)
107  {
108  const JFormat format(out);
109 
110  out << FIXED(5,3) << object.normalisation << ' '
111  << FIXED(5,3) << object.spectralIndex;
112 
113  return out;
114  }
115 
116 
117  double normalisation; //!< normalisation [GeV * m^-2 * sr^-1 * s^-1]
118  double spectralIndex; //!< spectral index >= 0
119  };
120 
121 
122  /**
123  * Auxiliary method for creating an interface to a power-law flux function.
124  *
125  * \param normalisation normalisation [GeV * m^-2 * sr^-1 * s^-1]
126  * \param spectralIndex spectral index
127  */
129  const double spectralIndex) {
130 
131  const JPowerLawFlux flux(normalisation, spectralIndex);
132 
133  return make_fluxFunction(flux);
134  }
135 }
136 
137 #endif
double normalisation
normalisation [GeV * m^-2 * sr^-1 * s^-1]
bool has_neutrino(const Evt &evt)
Test whether given event has an incoming neutrino.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
Implementation of event-weight factor interface.
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
JEvtWeightFactorFunction< JFunction_t, JFlux > make_fluxFunction(const JFunction_t &flux)
Auxiliary method for creating an interface to a flux function.
double E
Energy [GeV] (either MC truth or reconstructed)
Definition: Trk.hh:20
friend std::istream & operator>>(std::istream &in, JPowerLawFlux &object)
Stream input.
double spectralIndex
spectral index &gt;= 0
Auxiliary class to temporarily define format specifications.
Definition: JManip.hh:634
bool equals(const JPowerLawFlux &object) const
Check if this flux is identical to the given flux.
friend std::ostream & operator<<(std::ostream &out, const JPowerLawFlux &object)
Write power-law parameters to output stream.
Neutrino flux.
Definition: JHead.hh:906
Template definition of auxiliary base class for comparison of data structures.
Definition: JEquals.hh:24
T pow(const T &x, const double y)
Power .
Definition: JMath.hh:97
Example function object for computing power-law flux.
JEvtWeightFactorFunction< JPowerLawFlux, JFlux > make_powerLawFluxFunction(const double normalisation, const double spectralIndex)
Auxiliary method for creating an interface to a power-law flux function.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
double operator()(const Evt &evt) const
Get flux of given event.
int id
offline event identifier
Definition: Evt.hh:22
const Trk & get_neutrino(const Evt &evt)
Get incoming neutrino.
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:14
JPowerLawFlux()
Default constructor.
JPowerLawFlux(const double normalisation, const double spectralIndex)
Constructor.
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20