Jpp  16.0.0-rc.1
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 
7 
8 #include "JLang/JException.hh"
9 #include "JLang/JClonable.hh"
10 
11 #include "JAAnet/JHead.hh"
12 #include "JAAnet/JHeadToolkit.hh"
13 #include "JAAnet/JFlux.hh"
14 #include "JAAnet/JEvtWeight.hh"
15 
16 /**
17  * \author bjung
18  */
19 
20 namespace JAANET {
21 
22  using JLANG::JClonable;
25 
26 
27  /**
28  * Implementation of event weighting for Corsika data.
29  */
31  public JClonable<JEvtWeight, JEvtWeightCorsika>,
32  public JFluxHelper
33  {
34  /**
35  * Default Constructor.
36  */
38  JFluxHelper(),
39  W(0.0)
40  {}
41 
42 
43  /**
44  * Constructor.
45  *
46  * \param header header
47  */
48  JEvtWeightCorsika(const JHead& header) :
49  JFluxHelper()
50  {
51  configure(header);
52  }
53 
54 
55  /**
56  * Constructor.
57  *
58  * \param header header
59  * \param flux flux
60  */
61  JEvtWeightCorsika(const JHead& header,
62  const JFlux& flux)
63  {
64  configure(header);
66  }
67 
68 
69  /**
70  * Copy constructor.
71  *
72  * \param object original object
73  */
75  {
76  this->W = object.W;
77 
78  if (object.is_valid()) {
79  JFluxHelper::configure(*(object.get()));
80  }
81  }
82 
83 
84  /**
85  * Weight configuration.
86  *
87  * \param header header
88  */
89  void configure(const JHead& header) override
90  {
91  const double N = header.genvol.numberOfEvents;
92 
93  if (check(header) && N > 0.0) {
94 
95  W = 1.0 / N;
96 
97  } else {
98 
99  THROW(JValueOutOfRange, "JEvtWeightCorsika::configure(): Provided header is inconsistent with Corsika.");
100  }
101  }
102 
103 
104  /**
105  * Check whether header is consistent with this event weighter.
106  *
107  * \param header header
108  * \return true if consistent; else false
109  */
110  bool check(const JHead& header) const override
111  {
112  return is_gseagen(header);
113  }
114 
115 
116  /**
117  * Get weight of given event.
118  *
119  * \param evt event
120  * \return weight [Hz]
121  */
122  double getWeight(const Evt& evt) const override
123  {
124  const double Nretries = evt.w2list[W2LIST_GSEAGEN_N_RETRIES];
125 
126  if (is_valid() && evt.w.size() > 1) {
127 
128  return W * evt.w[1] * getFlux(evt) / (1 + Nretries);
129 
130  } else if (evt.w.size() > 2) {
131 
132  return W * evt.w[2] / (1 + Nretries);
133 
134  } else {
135 
136  if (!is_valid()) {
137  THROW(JNullPointerException, "JEvtWeightCorsika::getWeight(): Unspecified flux function.");
138  } else {
139  THROW(JIndexOutOfRange, "JEvtWeightCorsika::getWeight(): Empty " << (evt.w.size() < 3 ? "w2-" : "w3-") << "weight.");
140  }
141  }
142  }
143 
144 
145  private:
146 
147  double W;
148  };
149 }
150 
151 #endif
JAANET::genvol genvol
Definition: JHead.hh:1469
Exceptions.
void configure(const JHead &header) override
Weight configuration.
bool is_gseagen(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:60
double numberOfEvents
Number of events.
Definition: JHead.hh:705
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
JEvtWeightCorsika(const JHead &header)
Constructor.
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
std::vector< double > w
MC: Weights w[0]=w1, w[1]=w2, w[2]]=w3 (see e.g. Tag list)
Definition: Evt.hh:39
bool is_valid() const
Check validity of pointer.
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.
Exception for null pointer operation.
Definition: JException.hh:216
bool check(const JHead &header) const override
Check whether header is consistent with this event weighter.
Neutrino flux.
Definition: JHead.hh:890
Template class for object cloning.
Definition: JClonable.hh:20
void configure(const JEvtWeightFactor &factor)
Configure event-weight factor.
Helper class for event-weight factor.
Monte Carlo run header.
Definition: JHead.hh:1164
double getFlux(const Evt &evt) const
Get flux of given event.
Implementation of event weighting for Corsika data.
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
Exception for accessing an index in a collection that is outside of its range.
Definition: JException.hh:90
Low-level interface for retrieving a specifiable multiplication factor corresponding to a given event...
std::vector< double > w2list
MC: factors that make up w[1]=w2 (see e.g. Tag list)
Definition: Evt.hh:40
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19
JEvtWeightCorsika(const JEvtWeightCorsika &object)
Copy constructor.