Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
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
10#include "JPhysics/JPDFTypes.hh"
11#include "JPhysics/JGeane.hh"
14#include "JGeometry3D/JTime.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 */
30namespace JSIRENE {}
31namespace JPP { using namespace JSIRENE; }
32
33namespace JSIRENE {
34
35 using JPHYSICS::JGeane;
36 using JPHYSICS::gWater;
41
46
48
49
50 /**
51 * Auxiliary data structure for determination of number of photo-electrons.
52 */
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
158 case DIRECT_LIGHT_FROM_MUON:
159 return HIT_TYPE_MUON_DIRECT;
160
161 case SCATTERED_LIGHT_FROM_MUON:
162 return HIT_TYPE_MUON_SCATTERED;
163
164 case DIRECT_LIGHT_FROM_DELTARAYS:
165 return HIT_TYPE_DELTARAYS_DIRECT;
166
167 case SCATTERED_LIGHT_FROM_DELTARAYS:
168 return HIT_TYPE_DELTARAYS_SCATTERED;
169
170 case DIRECT_LIGHT_FROM_EMSHOWER:
171 return (shower ? HIT_TYPE_SHOWER_DIRECT : HIT_TYPE_BREMSSTRAHLUNG_DIRECT );
172
173 case SCATTERED_LIGHT_FROM_EMSHOWER:
174 return (shower ? HIT_TYPE_SHOWER_SCATTERED : HIT_TYPE_BREMSSTRAHLUNG_SCATTERED);
175
176 default:
177 return HIT_TYPE_UNKNOWN;
178 }
179 }
180
181
182 /**
183 * Point along muon trajectory.
184 */
185 struct JPoint :
187 JTime
188 {
189 /**
190 * Default constructor.
191 */
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,
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.
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
double getDZ() const
Get z direction.
Definition JVersor3Z.hh:169
double getDY() const
Get y direction.
Definition JVersor3Z.hh:158
double getDX() const
Get x direction.
Definition JVersor3Z.hh:147
Interface for muon energy loss.
Definition JGeane.hh:39
Extensions to Evt data format.
JHitType_t
Enumeration of hit types based on km3 codes.
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
const double getSpeedOfLight()
Get speed of light.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Detector simulations.
JHitType_t getHitType(const JPDFType_t pdf, const bool shower=false)
Get hit type corresponding to given PDF type.
const struct JSIRENE::number_of_photo_electrons_type getNumberOfPhotoElectrons
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 ds)
Step using default ionisation energy loss.
double getRange() const
Get visible range of muon using default ionisation energy loss.
JVertex & step(const double a, const double ds)
Step using given 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(const double z, const double t, const double E)
Constructor.
JVertex & step(const JGeane &geane, const double ds)
Step using given energy loss function.
JVertex()
Default constructor.
Auxiliary data structure for determination of number of photo-electrons.
const std::vector< size_t > & operator()(const double NPE, const int N, const std::vector< double > &npe, const bool option) const
Get numbers of photo-electrons for PMTs given the expectation values of the number of photo-electrons...
size_t operator()(const size_t npe) const
Get number of photo-electrons of a hit given number of photo-electrons on PMT.