Jpp  17.2.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 
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/JEvtWeight.hh"
15 #include "JAAnet/JFlux.hh"
16 
17 
18 /**
19  * \author bjung
20  */
21 
22 namespace JAANET {
23 
24  using JLANG::JClonable;
27 
28 
29  /**
30  * Implementation of event weighting for Corsika data.
31  */
33  public JClonable<JEvtWeight, JEvtWeightCorsika>,
34  public JEvtWeightFactorHelper<JFlux>
35  {
37 
38 
39  /**
40  * Default Constructor.
41  */
44  {}
45 
46 
47  /**
48  * Constructor.
49  *
50  * \param header header
51  */
52  JEvtWeightCorsika(const JHead& header) :
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 (object.is_valid()) {
83  JFluxHelper_t::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  const double N = header.genvol.numberOfEvents;
96 
97  if (check(header) && N > 0.0) {
98 
99  norm = 1.0 / N;
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  const double Nretries = evt.w2list[W2LIST_GSEAGEN_N_RETRIES];
129 
130  if (is_valid() && evt.w.size() > 1) {
131 
132  return evt.w[1] * getFactor(evt) / (1 + Nretries) * norm;
133 
134  } else if (evt.w.size() > 2) {
135 
136  return evt.w[2] / (1 + Nretries) * norm;
137 
138  } else {
139 
140  if (!is_valid()) {
141  THROW(JNullPointerException, "JEvtWeightCorsika::getWeight(): Unspecified flux function.");
142  } else {
143  THROW(JIndexOutOfRange, "JEvtWeightCorsika::getWeight(): Empty " << (evt.w.size() < 3 ? "w2-" : "w3-") << "weight.");
144  }
145  }
146  }
147  };
148 }
149 
150 #endif
JAANET::genvol genvol
Definition: JHead.hh:1525
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:708
#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 or km3net-dataformat/definitions) ...
Definition: Evt.hh:42
JEvtWeightFactorHelper< JFlux > JFluxHelper_t
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.
double getFactor(const Evt &evt) const
Get weight-factor of given event.
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:893
Template class for object cloning.
Definition: JClonable.hh:20
Helper class for event-weight factor.
void configure(const JFlux &factor)
Configure event-weight factor.
Low-level interface for retrieving the flux corresponding to a given event.
Definition: JFlux.hh:18
Monte Carlo run header.
Definition: JHead.hh:1167
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
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.