Jpp  16.0.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/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  */
43  JFluxHelper_t(),
44  W(0.0)
45  {}
46 
47 
48  /**
49  * Constructor.
50  *
51  * \param header header
52  */
53  JEvtWeightCorsika(const JHead& header) :
55  {
56  configure(header);
57  }
58 
59 
60  /**
61  * Constructor.
62  *
63  * \param header header
64  * \param flux flux
65  */
66  JEvtWeightCorsika(const JHead& header,
67  const JFlux& flux)
68  {
69  configure(header);
71  }
72 
73 
74  /**
75  * Copy constructor.
76  *
77  * \param object original object
78  */
80  {
81  this->W = object.W;
82 
83  if (object.is_valid()) {
84  JFluxHelper_t::configure(*(object.get()));
85  }
86  }
87 
88 
89  /**
90  * Weight configuration.
91  *
92  * \param header header
93  */
94  void configure(const JHead& header) override
95  {
96  const double N = header.genvol.numberOfEvents;
97 
98  if (check(header) && N > 0.0) {
99 
100  W = 1.0 / N;
101 
102  } else {
103 
104  THROW(JValueOutOfRange, "JEvtWeightCorsika::configure(): Provided header is inconsistent with Corsika.");
105  }
106  }
107 
108 
109  /**
110  * Check whether header is consistent with this event weighter.
111  *
112  * \param header header
113  * \return true if consistent; else false
114  */
115  bool check(const JHead& header) const override
116  {
117  return is_gseagen(header);
118  }
119 
120 
121  /**
122  * Get weight of given event.
123  *
124  * \param evt event
125  * \return weight [Hz]
126  */
127  double getWeight(const Evt& evt) const override
128  {
129  const double Nretries = evt.w2list[W2LIST_GSEAGEN_N_RETRIES];
130 
131  if (is_valid() && evt.w.size() > 1) {
132 
133  return W * evt.w[1] * getFactor(evt) / (1 + Nretries);
134 
135  } else if (evt.w.size() > 2) {
136 
137  return W * evt.w[2] / (1 + Nretries);
138 
139  } else {
140 
141  if (!is_valid()) {
142  THROW(JNullPointerException, "JEvtWeightCorsika::getWeight(): Unspecified flux function.");
143  } else {
144  THROW(JIndexOutOfRange, "JEvtWeightCorsika::getWeight(): Empty " << (evt.w.size() < 3 ? "w2-" : "w3-") << "weight.");
145  }
146  }
147  }
148 
149 
150  private:
151 
152  double W;
153  };
154 }
155 
156 #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
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:890
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:1164
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)
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.