Jpp  19.1.0-rc.1
the software that should make you happy
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  * \file
22  * Toolkit for JSirene.
23  *
24  * \author mdejong
25  */
26 
27 /**
28  * Detector simulations.
29  */
30 namespace JSIRENE {}
31 namespace JPP { using namespace JSIRENE; }
32 
33 namespace JSIRENE {
34 
35  using JPHYSICS::JGeane;
36  using JPHYSICS::gWater;
37  using JPHYSICS::MASS_MUON;
41 
43  using JGEOMETRY3D::JTime;
46 
47  using JAANET::JHitType_t;
48 
49 
50  /**
51  * Auxiliary data structure for determination of number of photo-electrons.
52  */
53  const struct {
54  /**
55  * Get numbers of photo-electrons for PMTs given the expectation
56  * values of the number of photo-electrons on a module and PMTs.
57  *
58  * The number of photo-electrons on the PMTs are evaluated by pick-and-drop statistics
59  * from the generated number of photo-electrons when the option is set to <tt>true</tt>.
60  * Otherwise, the numbers are directly evaluated using Poisson statistics
61  * from the expectation values of the number of photo-electrons on the PMTs.
62  *
63  * It is recommended to set the option to <tt>true</tt> when the expectation value
64  * of number of photo-electrons in the module is less than 25 or so,
65  * which corresponds to a 5-sigma probability for zero photo-electrons in the module.
66  *
67  * \param NPE expectation value of number of photo-electrons in module
68  * \param N generated number of photo-electrons in module
69  * \param npe list of expectation values of number of photo-electrons in PMTs
70  * \param option option
71  * \return list of number of photo-electrons in PMTs
72  */
73  const std::vector<size_t>& operator()(const double NPE, const int N, const std::vector<double>& npe, const bool option) const
74  {
75  using namespace std;
76 
77  ns.resize(npe.size());
78  vs.resize(npe.size());
79 
80  if (option) {
81 
82  ns[0] = 0;
83  vs[0] = npe[0];
84 
85  for (size_t i = 1; i != npe.size(); ++i) {
86  ns[i] = 0;
87  vs[i] = vs[i-1] + npe[i];
88  }
89 
90  for (int i = N; i != 0; --i) {
91 
92  const double x = gRandom->Rndm() * NPE;
93 
94  if (x < *vs.rbegin()) {
95  ns[distance(vs.begin(), lower_bound(vs.begin(), vs.end(), x))] += 1;
96  }
97  }
98 
99  } else {
100 
101  for (size_t i = 0; i != npe.size(); ++i) {
102  ns[i] = gRandom->Poisson(npe[i]);
103  }
104  }
105 
106  return ns;
107  }
108 
109 
110  /**
111  * Get number of photo-electrons of a hit given number of photo-electrons on PMT.
112  *
113  * The number of photo-electrons of a hit may be larger than unity
114  * to limit the overall number of hits and consequently the memory coonsumption as well as
115  * the number of times the arrival time needs to be evaluated which is CPU intensive.
116  *
117  * \param npe number of photo-electrons on PMT
118  * \return number of photo-electrons of hit
119  */
120  inline size_t operator()(const size_t npe) const
121  {
122  static const size_t NPE = 20;
123 
124  if (npe > NPE) {
125 
126  const size_t n = (size_t) (NPE * log10((double) npe / (double) NPE));
127 
128  if (n == 0)
129  return 1;
130  else
131  return n;
132  }
133 
134  return 1;
135  }
136 
137  private:
140 
142 
143 
144  /**
145  * Get hit type corresponding to given PDF type.
146  *
147  * \param pdf PDF type
148  * \param shower force origin from neutrino interaction shower
149  * \return hit type
150  */
151  inline JHitType_t getHitType(const JPDFType_t pdf, const bool shower = false)
152  {
153  using namespace JAANET;
154  using namespace JPHYSICS;
155 
156  switch (pdf) {
157 
159  return HIT_TYPE_MUON_DIRECT;
160 
163 
166 
169 
172 
175 
176  default:
177  return HIT_TYPE_UNKNOWN;
178  }
179  }
180 
181 
182  /**
183  * Point along muon trajectory.
184  */
185  struct JPoint :
186  JPosition3D,
187  JTime
188  {
189  /**
190  * Default constructor.
191  */
192  JPoint() :
193  JPosition3D(),
194  JTime(),
195  __E (0.0),
196  __Es(0.0)
197  {}
198 
199 
200  /**
201  * Constructor.
202  *
203  * \param z position [m]
204  * \param t time [ns]
205  * \param E energy [GeV]
206  */
207  JPoint(const double z,
208  const double t,
209  const double E) :
210  JPosition3D(0.0, 0.0, z),
211  JTime(t),
212  __E (E),
213  __Es(0.0)
214  {}
215 
216 
217  /**
218  * Get muon energy.
219  *
220  * \return energy [GeV]
221  */
222  double getE() const
223  {
224  return __E;
225  }
226 
227 
228  /**
229  * Get shower energy.
230  *
231  * \return energy [GeV]
232  */
233  double getEs() const
234  {
235  return __Es;
236  }
237 
238  protected:
239  double __E;
240  double __Es;
241  };
242 
243 
244  /**
245  * Muon trajectory.
246  */
247  struct JTrack :
248  public std::vector<JPoint>
249  {
250  /**
251  * Constructor.
252  *
253  * \param point muon starting point
254  */
255  JTrack(const JPoint& point) :
256  std::vector<JPoint>(1, point)
257  {}
258 
259 
260  /**
261  * Get muon energy at given position along trajectory.
262  *
263  * \param z position [m]
264  * \return energy [GeV]
265  */
266  double getE(const double z) const
267  {
268  if (!this->empty()) {
269 
270  const_iterator p = lower_bound(this->begin(), this->end(), z, JLANG::make_comparator(&JPoint::getZ));
271 
272  if (p != this->end() && p != this->begin()) {
273 
274  --p;
275 
276  return p->getE() - (z - p->getZ()) * gWater.getA();
277  }
278  }
279 
280  return MASS_MUON;
281  }
282 
283 
284  /**
285  * Get muon position at given position along trajectory.
286  *
287  * \param z position [m]
288  * \return position
289  */
290  JVector2D getPosition(const double z) const
291  {
292  using namespace JPP;
293 
294  const double precision = 1.0e-2;
295 
296  if (!this->empty()) {
297 
298  const_iterator p = lower_bound(this->begin(), this->end(), z, JLANG::make_comparator(&JPoint::getZ));
299 
300  if (p == this->end()) {
301  --p;
302  }
303 
304  if (p == this->begin()) {
305 
306  return JVector2D(p->getX(),
307  p->getY());
308 
309  } else {
310 
311  JVector3D pos;
312 
313  pos = p->getPosition();
314 
315  --p;
316 
317  pos -= p->getPosition();
318 
319  const double u = (pos.getZ() > precision ? (z - p->getZ()) / pos.getZ() : 0.0);
320 
321  return JVector2D(p->getX() + u * pos.getX(),
322  p->getY() + u * pos.getY());
323  }
324  }
325 
326  return JVector2D(0.0, 0.0);
327  }
328  };
329 
330 
331  /**
332  * Vertex of energy loss of muon.
333  */
334  struct JVertex :
335  JPoint,
336  JVersor3Z
337  {
338  /**
339  * Default constructor.
340  */
342  JPoint(),
343  JVersor3Z()
344  {}
345 
346 
347  /**
348  * Constructor.
349  *
350  * \param z position [m]
351  * \param t time [ns]
352  * \param E energy [GeV]
353  */
354  JVertex(const double z,
355  const double t,
356  const double E) :
357  JPoint(z, t, E),
358  JVersor3Z()
359  {}
360 
361 
362  /**
363  * Get visible range of muon using default ionisation energy loss.
364  * This method applies only ionisation energy loss.
365  *
366  * \return range [m]
367  */
368  double getRange() const
369  {
370  return getRange(gWater.getA());
371  }
372 
373 
374  /**
375  * Get visible range of muon using given ionisation energy loss.
376  * This method applies only ionisation energy loss.
377  *
378  * \param a ionization parameter [GeV/m]
379  * \return range [m]
380  */
381  double getRange(double a) const
382  {
383  static const double Ethreshold = MASS_MUON / getSinThetaC();
384 
385  if (__E > Ethreshold)
386  return (__E - Ethreshold) / a;
387  else
388  return 0.0;
389  }
390 
391 
392  /**
393  * Get range of muon using given energy loss function.
394  *
395  * \param geane energy loss function
396  * \return range [m]
397  */
398  double getRange(const JGeane& geane) const
399  {
400  return geane(__E);
401  }
402 
403 
404  /**
405  * Apply shower energy loss.
406  *
407  * \param Ts scattering angles
408  * \param Es shower energy [GeV]
409  */
410  void applyEloss(const JVersor3Z& Ts, const double Es)
411  {
412  static_cast<JVersor3Z&>(*this).add(Ts);
413 
414  this->__E -= Es;
415  this->__Es = Es;
416  }
417 
418 
419  /**
420  * Step using default ionisation energy loss.
421  * This method applies only ionisation energy loss.
422  *
423  * \param ds step [m]
424  * \return this vertex
425  */
426  JVertex& step(const double ds)
427  {
428  return step(gWater.getA(), ds);
429  }
430 
431 
432  /**
433  * Step using given ionisation energy loss.
434  * This method applies only given ionisation energy loss.
435  *
436  * \param a ionization parameter [GeV/m]
437  * \param ds step [m]
438  * \return this vertex
439  */
440  JVertex& step(const double a, const double ds)
441  {
442  __x += this->getDX() * ds;
443  __y += this->getDY() * ds;
444  __z += this->getDZ() * ds;
445  __t += ds / getSpeedOfLight();
446  __E -= ds * a;
447 
448  return *this;
449  }
450 
451 
452  /**
453  * Step using given energy loss function.
454  *
455  * \param geane energy loss function
456  * \param ds step [m]
457  * \return this vertex
458  */
459  JVertex& step(const JGeane& geane, const double ds)
460  {
461  __x += this->getDX() * ds;
462  __y += this->getDY() * ds;
463  __z += this->getDZ() * ds;
464  __t += ds / getSpeedOfLight();
465  __E = geane(__E, ds);
466 
467  return *this;
468  }
469  };
470 }
471 
472 #endif
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
Energy loss of muon.
Numbering scheme for PDF types.
Physics constants.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Data structure for vector in two dimensions.
Definition: JVector2D.hh:34
Data structure for position in three dimensions.
Definition: JPosition3D.hh:38
Data structure for vector in three dimensions.
Definition: JVector3D.hh:36
double getY() const
Get y position.
Definition: JVector3D.hh:104
double getZ() const
Get z position.
Definition: JVector3D.hh:115
double getX() const
Get x position.
Definition: JVector3D.hh:94
Data structure for normalised vector in positive z-direction.
Definition: JVersor3Z.hh:41
JVersor3Z & add(const JVersor3Z &value)
Addition operator.
Definition: JVersor3Z.hh:200
virtual double getA() const override
Get energy loss constant.
Definition: JGeane.hh:231
Interface for muon energy loss.
Definition: JGeane.hh:39
const double a
Definition: JQuadrature.cc:42
Extensions to Evt data format.
JHitType_t
Enumeration of hit types based on km3 codes.
@ HIT_TYPE_UNKNOWN
Unknown source.
@ HIT_TYPE_DELTARAYS_DIRECT
Direct light from delta-rays.
@ HIT_TYPE_MUON_DIRECT
Direct light from muon.
@ HIT_TYPE_DELTARAYS_SCATTERED
Scattered light from delta-rays.
@ HIT_TYPE_MUON_SCATTERED
Scattered light from muon.
@ HIT_TYPE_SHOWER_DIRECT
Direct light from primary shower.
@ HIT_TYPE_BREMSSTRAHLUNG_SCATTERED
Scattered light from Bremsstrahlung.
@ HIT_TYPE_SHOWER_SCATTERED
Scattered light from primary shower.
@ HIT_TYPE_BREMSSTRAHLUNG_DIRECT
Direct light from Bremsstrahlung.
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
Auxiliary methods for light properties of deep-sea water.
static const double MASS_MUON
muon mass [GeV]
static const JGeaneWater gWater
Function object for energy loss of muon in sea water.
Definition: JGeane.hh:381
double getSinThetaC()
Get average sine of Cherenkov angle of water corresponding to group velocity.
JPDFType_t
PDF types.
Definition: JPDFTypes.hh:24
@ SCATTERED_LIGHT_FROM_EMSHOWER
scattered light from EM shower
Definition: JPDFTypes.hh:38
@ SCATTERED_LIGHT_FROM_DELTARAYS
scattered light from delta-rays
Definition: JPDFTypes.hh:33
@ SCATTERED_LIGHT_FROM_MUON
scattered light from muon
Definition: JPDFTypes.hh:27
@ DIRECT_LIGHT_FROM_EMSHOWER
direct light from EM shower
Definition: JPDFTypes.hh:37
@ DIRECT_LIGHT_FROM_DELTARAYS
direct light from delta-rays
Definition: JPDFTypes.hh:32
@ DIRECT_LIGHT_FROM_MUON
direct light from muon
Definition: JPDFTypes.hh:26
const double getSpeedOfLight()
Get speed of light.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
range_type getRange(TAxis *pAxis)
Get range of given axis.
Definition: JRootfit.hh:52
Detector simulations.
JHitType_t getHitType(const JPDFType_t pdf, const bool shower=false)
Get hit type corresponding to given PDF type.
std::vector< double > vs
std::vector< size_t > ns
const struct JSIRENE::@64 getNumberOfPhotoElectrons
Auxiliary data structure for determination of number of photo-electrons.
const int n
Definition: JPolint.hh:786
double u[N+1]
Definition: JPolint.hh:865
Definition: JSTDTypes.hh:14
Point along muon trajectory.
double getE() const
Get muon energy.
JPoint(const double z, const double t, const double E)
Constructor.
JPoint()
Default constructor.
double getEs() const
Get shower energy.
Muon trajectory.
JVector2D getPosition(const double z) const
Get muon position at given position along trajectory.
JTrack(const JPoint &point)
Constructor.
double getE(const double z) const
Get muon energy at given position along trajectory.
Vertex of energy loss of muon.
double getRange(const JGeane &geane) const
Get range of muon using given energy loss function.
JVertex & step(const double a, const double ds)
Step using given ionisation energy loss.
double getRange() const
Get visible range of muon using default ionisation energy loss.
JVertex & step(const double ds)
Step using default ionisation energy loss.
double getRange(double a) const
Get visible range of muon using given ionisation energy loss.
void applyEloss(const JVersor3Z &Ts, const double Es)
Apply shower energy loss.
JVertex & step(const JGeane &geane, const double ds)
Step using given energy loss function.
JVertex(const double z, const double t, const double E)
Constructor.
JVertex()
Default constructor.