Jpp  18.5.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEvtWeightCorsika.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JEVTWEIGHTCORSIKA__
2 #define __JAANET__JEVTWEIGHTCORSIKA__
3 
6 
9 
10 #include "JLang/JException.hh"
11 #include "JLang/JClonable.hh"
12 
13 #include "JAAnet/JHead.hh"
14 #include "JAAnet/JHeadToolkit.hh"
15 #include "JAAnet/JEvtWeight.hh"
17 #include "JAAnet/JFlux.hh"
18 
19 
20 /**
21  * \author bjung
22  */
23 
24 namespace JAANET {}
25 namespace JPP { using namespace JAANET; }
26 
27 namespace JAANET {
28 
29  using JLANG::JClonable;
30 
31 
32  /**
33  * Implementation of event weighting for Corsika data.
34  */
36  public JFluxHelper,
37  public JClonable<JEvtWeight, JEvtWeightCorsika>
38  {
39  /**
40  * Default Constructor.
41  */
43  JFluxHelper()
44  {}
45 
46 
47  /**
48  * Constructor.
49  *
50  * \param header header
51  */
52  JEvtWeightCorsika(const JHead& header) :
53  JFluxHelper()
54  {
55  configure(header);
56  }
57 
58 
59  /**
60  * Constructor.
61  *
62  * \param header header
63  * \param flux flux
64  */
65  JEvtWeightCorsika(const JHead& header,
66  const JFlux& flux)
67  {
68  configure(header);
70  }
71 
72 
73  /**
74  * Copy constructor.
75  *
76  * \param object original object
77  */
79  {
80  this->norm = object.norm;
81 
82  if (static_cast<const JFluxHelper&>(object)) {
83  JFluxHelper::configure(*(object.get()));
84  }
85  }
86 
87 
88  /**
89  * Weight configuration.
90  *
91  * \param header header
92  */
93  void configure(const JHead& header) override
94  {
95  using namespace JPP;
96 
97  if (check(header)) {
98 
99  norm = 1.0 / header.genvol.numberOfEvents;
100 
101  } else {
102 
103  THROW(JValueOutOfRange, "JEvtWeightCorsika::configure(): Provided header is inconsistent with Corsika.");
104  }
105  }
106 
107 
108  /**
109  * Check whether header is consistent with this event weighter.
110  *
111  * \param header header
112  * \return true if consistent; else false
113  */
114  bool check(const JHead& header) const override
115  {
116  return is_gseagen(header);
117  }
118 
119 
120  /**
121  * Get weight of given event.
122  *
123  * \param evt event
124  * \return weight [Hz]
125  */
126  double getWeight(const Evt& evt) const override
127  {
128  using namespace JPP;
129 
130  const double& Nretries = evt.w2list[W2LIST_GSEAGEN_N_RETRIES];
131 
132  if (static_cast<const JFluxHelper&>(*this) &&
133  evt.w.size() > WEIGHTLIST_DIFFERENTIAL_EVENT_RATE) {
134 
135  return evt.w[WEIGHTLIST_DIFFERENTIAL_EVENT_RATE] * getFactor(evt) * getNormalisation(evt) / (1 + Nretries);
136 
137  } else if (evt.w.size() > WEIGHTLIST_RESCALED_EVENT_RATE) {
138 
139  return evt.w[WEIGHTLIST_RESCALED_EVENT_RATE];
140 
141  } else if (evt.w.size() > WEIGHTLIST_EVENT_RATE) {
142 
143  return evt.w[WEIGHTLIST_EVENT_RATE] * getNormalisation(evt) / (1 + Nretries);
144 
145  } else {
146 
147  if (!static_cast<const JFluxHelper&>(*this)) {
148  THROW(JNullPointerException, "JEvtWeightCorsika::getWeight(): Unspecified flux function.");
149  } else {
150  THROW(JIndexOutOfRange, "JEvtWeightCorsika::getWeight(): Empty " << (evt.w.size() < 3 ? "w2-" : "w3-") << "weight.");
151  }
152  }
153  }
154  };
155 }
156 
157 #endif
Exceptions.
void configure(const JHead &header) override
Weight configuration.
static const int WEIGHTLIST_RESCALED_EVENT_RATE
Rescaled event rate [s-1].
Definition: weightlist.hh:17
bool is_gseagen(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:61
double numberOfEvents
Number of events.
Definition: JHead.hh:721
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
JEvtWeightCorsika(const JHead &header)
Constructor.
std::vector< double > w
MC: Weights w[0]=w1, w[1]=w2, w[2]=w3 (see e.g. Tag list or km3net-dataformat/definitions) ...
Definition: Evt.hh:42
static const int WEIGHTLIST_EVENT_RATE
Event rate [s-1].
Definition: weightlist.hh:15
JEvtWeightCorsika()
Default Constructor.
JEvtWeightCorsika(const JHead &header, const JFlux &flux)
Constructor.
double getWeight(const Evt &evt) const override
Get weight of given event.
static const int W2LIST_GSEAGEN_N_RETRIES
Number of extra chances given to each CORSIKA shower to hit the can.
double getFactor(const Evt &evt) const
Get weight-factor of given event.
Monte Carlo run header.
Definition: JHead.hh:1234
bool check(const JHead &header) const override
Check whether header is consistent with this event weighter.
Neutrino flux.
Definition: JHead.hh:906
Template class for object cloning.
Definition: JClonable.hh:20
Helper class for event-weight factor.
void configure(const JEvtWeightFactor_t &factor)
Configure event-weight factor.
Low-level interface for retrieving the flux corresponding to a given event.
Definition: JFlux.hh:21
JAANET::genvol genvol
Definition: JHead.hh:1597
static const int WEIGHTLIST_DIFFERENTIAL_EVENT_RATE
Event rate per unit of flux (c.f. taglist document) [GeV m2 sr].
Definition: weightlist.hh:14
Implementation of event weighting for Corsika data.
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:178
Exception for accessing an index in a collection that is outside of its range.
Definition: JException.hh:106
std::vector< double > w2list
MC: factors that make up w[1]=w2 (see e.g. Tag list or km3net-dataformat/definitions) ...
Definition: Evt.hh:43
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20
JEvtWeightCorsika(const JEvtWeightCorsika &object)
Copy constructor.