Jpp  18.1.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 
26  using JLANG::JClonable;
29 
30 
31  /**
32  * Implementation of event weighting for Corsika data.
33  */
35  public JFluxHelper,
36  public JClonable<JEvtWeight, JEvtWeightCorsika>
37  {
38  /**
39  * Default Constructor.
40  */
42  JFluxHelper()
43  {}
44 
45 
46  /**
47  * Constructor.
48  *
49  * \param header header
50  */
51  JEvtWeightCorsika(const JHead& header) :
52  JFluxHelper()
53  {
54  configure(header);
55  }
56 
57 
58  /**
59  * Constructor.
60  *
61  * \param header header
62  * \param flux flux
63  */
64  JEvtWeightCorsika(const JHead& header,
65  const JFlux& flux)
66  {
67  configure(header);
69  }
70 
71 
72  /**
73  * Copy constructor.
74  *
75  * \param object original object
76  */
78  {
79  this->norm = object.norm;
80 
81  if (object.is_valid()) {
82  JFluxHelper::configure(*(object.get()));
83  }
84  }
85 
86 
87  /**
88  * Weight configuration.
89  *
90  * \param header header
91  */
92  void configure(const JHead& header) override
93  {
94  const double N = header.genvol.numberOfEvents;
95 
96  if (check(header) && N > 0.0) {
97 
98  norm = 1.0 / N;
99 
100  } else {
101 
102  THROW(JValueOutOfRange, "JEvtWeightCorsika::configure(): Provided header is inconsistent with Corsika.");
103  }
104  }
105 
106 
107  /**
108  * Check whether header is consistent with this event weighter.
109  *
110  * \param header header
111  * \return true if consistent; else false
112  */
113  bool check(const JHead& header) const override
114  {
115  return is_gseagen(header);
116  }
117 
118 
119  /**
120  * Get weight of given event.
121  *
122  * \param evt event
123  * \return weight [Hz]
124  */
125  double getWeight(const Evt& evt) const override
126  {
127  const double& Nretries = evt.w2list[W2LIST_GSEAGEN_N_RETRIES];
128 
129  if (is_valid() && evt.w.size() > WEIGHTLIST_DIFFERENTIAL_EVENT_RATE) {
130 
131  return evt.w[WEIGHTLIST_DIFFERENTIAL_EVENT_RATE] * getFactor(evt) * getNormalisation(evt) / (1 + Nretries);
132 
133  } else if (evt.w.size() > WEIGHTLIST_RESCALED_EVENT_RATE) {
134 
135  return evt.w[WEIGHTLIST_RESCALED_EVENT_RATE];
136 
137  } else if (evt.w.size() > WEIGHTLIST_EVENT_RATE) {
138 
139  return evt.w[WEIGHTLIST_EVENT_RATE] * getNormalisation(evt) / (1 + Nretries);
140 
141  } else {
142 
143  if (!is_valid()) {
144  THROW(JNullPointerException, "JEvtWeightCorsika::getWeight(): Unspecified flux function.");
145  } else {
146  THROW(JIndexOutOfRange, "JEvtWeightCorsika::getWeight(): Empty " << (evt.w.size() < 3 ? "w2-" : "w3-") << "weight.");
147  }
148  }
149  }
150  };
151 }
152 
153 #endif
JAANET::genvol genvol
Definition: JHead.hh:1582
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:708
#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
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:232
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 JEvtWeightFactor_t &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:1221
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
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.