Jpp  17.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JSireneToolkit.hh
Go to the documentation of this file.
1 #ifndef __JSIRENE__JSIRENETOOLKIT__
2 #define __JSIRENE__JSIRENETOOLKIT__
3 
4 #include <vector>
5 #include <cmath>
6 
7 #include "TRandom3.h"
8 
9 #include "JPhysics/JConstants.hh"
10 #include "JPhysics/JPDFTypes.hh"
11 #include "JPhysics/JGeane.hh"
12 #include "JAAnet/JAAnetToolkit.hh"
14 #include "JGeometry3D/JTime.hh"
15 #include "JGeometry3D/JVersor3Z.hh"
16 #include "JGeometry2D/JVector2D.hh"
17 #include "JLang/JComparator.hh"
18 
19 
20 /**
21  * \author mdejong
22  */
23 
24 
25 /**
26  * Detector simulations.
27  */
28 namespace JSIRENE {}
29 namespace JPP { using namespace JSIRENE; }
30 
31 namespace JSIRENE {
32 
33  using JPHYSICS::JGeane;
34  using JPHYSICS::gWater;
35  using JPHYSICS::MASS_MUON;
39 
41  using JGEOMETRY3D::JTime;
44 
45  using JAANET::JHitType_t;
46 
47 
48  /**
49  * Get number of photo-electrons of a hit given the expectation
50  * values of the number of photo-electrons on a module and PMT.
51  *
52  * The return value is evaluated by pick-and-drop statistics from
53  * the generated number of photo-electrons when the expectation
54  * value of the number of photo-electrons on a module deviates
55  * less than 5 sigmas from 0 (i.e.\ when it is less than 25).
56  * Otherwise, the return value is evaluated by Poisson statistics
57  * from the expectation value of the number of photo-electrons on PMT.
58  *
59  * \param NPE expectation value of npe on module
60  * \param N generated value of npe on module
61  * \param npe expectation value of npe on PMT
62  * \return number of photo-electrons on PMT
63  */
64  inline int getNumberOfPhotoElectrons(const double NPE,
65  const int N,
66  const double npe)
67  {
68  if (NPE < 25.0) {
69 
70  int n = 0;
71 
72  for (int i = N; i != 0; --i) {
73  if (gRandom->Rndm() * NPE < npe) {
74  ++n;
75  }
76  }
77 
78  return n;
79 
80  } else {
81 
82  return gRandom->Poisson(npe);
83  }
84  }
85 
86 
87  /**
88  * Get number of photo-electrons of a hit given number of photo-electrons on PMT.
89  *
90  * The number of photo-electrons of a hit may be larger than unity
91  * to limit the overall number of hits and consequently the memory coonsumption as well as
92  * the number of times the arrival time needs to be evaluated which is CPU intensive.
93  *
94  * \param npe number of photo-electrons on PMT
95  * \return number of photo-electrons of hit
96  */
97  inline int getNumberOfPhotoElectrons(const int npe)
98  {
99  static const int NPE = 20;
100 
101  if (npe > NPE) {
102 
103  const int n = (int) (NPE * log10((double) npe / (double) NPE));
104 
105  if (n == 0)
106  return 1;
107  else
108  return n;
109  }
110 
111  return 1;
112  }
113 
114 
115  /**
116  * Get hit type corresponding to given PDF type.
117  *
118  * \param pdf PDF type
119  * \param shower force origin from neutrino interaction shower
120  * \return hit type
121  */
122  inline JHitType_t getHitType(const JPDFType_t pdf, const bool shower = false)
123  {
124  using namespace JAANET;
125  using namespace JPHYSICS;
126 
127  switch (pdf) {
128 
130  return HIT_TYPE_MUON_DIRECT;
131 
134 
137 
140 
143 
146 
147  default:
148  return HIT_TYPE_UNKNOWN;
149  }
150  }
151 
152 
153  /**
154  * Point along muon trajectory.
155  */
156  struct JPoint :
157  JPosition3D,
158  JTime
159  {
160  /**
161  * Default constructor.
162  */
163  JPoint() :
164  JPosition3D(),
165  JTime(),
166  __E (0.0),
167  __Es(0.0)
168  {}
169 
170 
171  /**
172  * Constructor.
173  *
174  * \param z position [m]
175  * \param t time [ns]
176  * \param E energy [GeV]
177  */
178  JPoint(const double z,
179  const double t,
180  const double E) :
181  JPosition3D(0.0, 0.0, z),
182  JTime(t),
183  __E (E),
184  __Es(0.0)
185  {}
186 
187 
188  /**
189  * Get muon energy.
190  *
191  * \return energy [GeV]
192  */
193  double getE() const
194  {
195  return __E;
196  }
197 
198 
199  /**
200  * Get shower energy.
201  *
202  * \return energy [GeV]
203  */
204  double getEs() const
205  {
206  return __Es;
207  }
208 
209  protected:
210  double __E;
211  double __Es;
212  };
213 
214 
215  /**
216  * Muon trajectory.
217  */
218  struct JTrack :
219  public std::vector<JPoint>
220  {
221  /**
222  * Constructor.
223  *
224  * \param point muon starting point
225  */
226  JTrack(const JPoint& point) :
227  std::vector<JPoint>(1, point)
228  {}
229 
230 
231  /**
232  * Get muon energy at given position along trajectory.
233  *
234  * \param z position [m]
235  * \return energy [GeV]
236  */
237  double getE(const double z) const
238  {
239  if (!this->empty()) {
240 
241  const_iterator p = lower_bound(this->begin(), this->end(), z, JLANG::make_comparator(&JPoint::getZ));
242 
243  if (p != this->end() && p != this->begin()) {
244 
245  --p;
246 
247  return p->getE() - (z - p->getZ()) * gWater.getA();
248  }
249  }
250 
251  return MASS_MUON;
252  }
253 
254 
255  /**
256  * Get muon position at given position along trajectory.
257  *
258  * \param z position [m]
259  * \return position
260  */
261  JVector2D getPosition(const double z) const
262  {
263  using namespace JPP;
264 
265  const double precision = 1.0e-2;
266 
267  if (!this->empty()) {
268 
269  const_iterator p = lower_bound(this->begin(), this->end(), z, JLANG::make_comparator(&JPoint::getZ));
270 
271  if (p == this->end()) {
272  --p;
273  }
274 
275  if (p == this->begin()) {
276 
277  return JVector2D(p->getX(),
278  p->getY());
279 
280  } else {
281 
282  JVector3D pos;
283 
284  pos = p->getPosition();
285 
286  --p;
287 
288  pos -= p->getPosition();
289 
290  const double u = (pos.getZ() > precision ? (z - p->getZ()) / pos.getZ() : 0.0);
291 
292  return JVector2D(p->getX() + u * pos.getX(),
293  p->getY() + u * pos.getY());
294  }
295  }
296 
297  return JVector2D(0.0, 0.0);
298  }
299  };
300 
301 
302  /**
303  * Vertex of energy loss of muon.
304  */
305  struct JVertex :
306  JPoint,
307  JVersor3Z
308  {
309  /**
310  * Default constructor.
311  */
313  JPoint(),
314  JVersor3Z()
315  {}
316 
317 
318  /**
319  * Constructor.
320  *
321  * \param z position [m]
322  * \param t time [ns]
323  * \param E energy [GeV]
324  */
325  JVertex(const double z,
326  const double t,
327  const double E) :
328  JPoint(z, t, E),
329  JVersor3Z()
330  {}
331 
332 
333  /**
334  * Get visible range of muon using default ionisation energy loss.
335  * This method applies only ionisation energy loss.
336  *
337  * \return range [m]
338  */
339  double getRange() const
340  {
341  return getRange(gWater.getA());
342  }
343 
344 
345  /**
346  * Get visible range of muon using given ionisation energy loss.
347  * This method applies only ionisation energy loss.
348  *
349  * \param a ionization parameter [GeV/m]
350  * \return range [m]
351  */
352  double getRange(double a) const
353  {
354  static const double Ethreshold = MASS_MUON / getSinThetaC();
355 
356  if (__E > Ethreshold)
357  return (__E - Ethreshold) / a;
358  else
359  return 0.0;
360  }
361 
362 
363  /**
364  * Get range of muon using given energy loss function.
365  *
366  * \param geane energy loss function
367  * \return range [m]
368  */
369  double getRange(const JGeane& geane) const
370  {
371  return geane(__E);
372  }
373 
374 
375  /**
376  * Apply shower energy loss.
377  *
378  * \param Ts scattering angles
379  * \param Es shower energy [GeV]
380  */
381  void applyEloss(const JVersor3Z& Ts, const double Es)
382  {
383  static_cast<JVersor3Z&>(*this).add(Ts);
384 
385  this->__E -= Es;
386  this->__Es = Es;
387  }
388 
389 
390  /**
391  * Step using default ionisation energy loss.
392  * This method applies only ionisation energy loss.
393  *
394  * \param ds step [m]
395  * \return this vertex
396  */
397  JVertex& step(const double ds)
398  {
399  return step(gWater.getA(), ds);
400  }
401 
402 
403  /**
404  * Step using given ionisation energy loss.
405  * This method applies only given ionisation energy loss.
406  *
407  * \param a ionization parameter [GeV/m]
408  * \param ds step [m]
409  * \return this vertex
410  */
411  JVertex& step(const double a, const double ds)
412  {
413  __x += this->getDX() * ds;
414  __y += this->getDY() * ds;
415  __z += this->getDZ() * ds;
416  __t += ds / getSpeedOfLight();
417  __E -= ds * a;
418 
419  return *this;
420  }
421 
422 
423  /**
424  * Step using given energy loss function.
425  *
426  * \param geane energy loss function
427  * \param ds step [m]
428  * \return this vertex
429  */
430  JVertex& step(const JGeane& geane, const double ds)
431  {
432  __x += this->getDX() * ds;
433  __y += this->getDY() * ds;
434  __z += this->getDZ() * ds;
435  __t += ds / getSpeedOfLight();
436  __E = geane(__E, ds);
437 
438  return *this;
439  }
440  };
441 }
442 
443 #endif
Data structure for vector in two dimensions.
Definition: JVector2D.hh:32
JHitType_t
Enumeration of hit types based on km3 codes.
Scattered light from primary shower.
Point along muon trajectory.
double getE() const
Get muon energy.
JVertex & step(const double ds)
Step using default ionisation energy loss.
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
Definition: JComparator.hh:185
then usage E
Definition: JMuonPostfit.sh:35
double getRange(double a) const
Get visible range of muon using given ionisation energy loss.
Direct light from delta-rays.
Scattered light from muon.
Energy loss of muon.
scattered light from EM shower
Definition: JPDFTypes.hh:38
JHitType_t getHitType(const JPDFType_t pdf, const bool shower=false)
Get hit type corresponding to given PDF type.
static const double MASS_MUON
muon mass [GeV]
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
Scattered light from Bremsstrahlung.
JTrack(const JPoint &point)
Constructor.
static const JGeaneWater gWater
Function object for energy loss of muon in sea water.
Definition: JGeane.hh:381
Direct light from Bremsstrahlung.
Direct light from primary shower.
JVersor3Z & add(const JVersor3Z &value)
Addition operator.
Definition: JVersor3Z.hh:200
JVertex & step(const double a, const double ds)
Step using given ionisation energy loss.
direct light from muon
Definition: JPDFTypes.hh:26
JPoint()
Default constructor.
JVertex()
Default constructor.
JVertex(const double z, const double t, const double E)
Constructor.
Numbering scheme for PDF types.
JVertex & step(const JGeane &geane, const double ds)
Step using given energy loss function.
const int n
Definition: JPolint.hh:676
scattered light from muon
Definition: JPDFTypes.hh:27
set_variable E_E log10(E_{fit}/E_{#mu})"
double getE(const double z) const
Get muon energy at given position along trajectory.
scattered light from delta-rays
Definition: JPDFTypes.hh:33
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
Physics constants.
direct light from EM shower
Definition: JPDFTypes.hh:37
Muon trajectory.
JPDFType_t
PDF types.
Definition: JPDFTypes.hh:24
Interface for muon energy loss.
Definition: JGeane.hh:39
double getRange(const JGeane &geane) const
Get range of muon using given energy loss function.
double getEs() const
Get shower energy.
Vertex of energy loss of muon.
direct light from delta-rays
Definition: JPDFTypes.hh:32
void applyEloss(const JVersor3Z &Ts, const double Es)
Apply shower energy loss.
int getNumberOfPhotoElectrons(const double NPE, const int N, const double npe)
Get number of photo-electrons of a hit given the expectation values of the number of photo-electrons ...
const double getSpeedOfLight()
Get speed of light.
Direct light from muon.
then JCalibrateToT a
Definition: JTuneHV.sh:116
JVector2D getPosition(const double z) const
Get muon position at given position along trajectory.
Scattered light from delta-rays.
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
JPoint(const double z, const double t, const double E)
Constructor.
double u[N+1]
Definition: JPolint.hh:755
double getRange() const
Get visible range of muon using default ionisation energy loss.
Data structure for normalised vector in positive z-direction.
Definition: JVersor3Z.hh:39
double getZ() const
Get z position.
Definition: JVector3D.hh:115
double getSinThetaC()
Get average sine of Cherenkov angle of water corresponding to group velocity.
virtual double getA() const override
Get energy loss constant.
Definition: JGeane.hh:231