Jpp 21.0.0
the software that should make you happy
Loading...
Searching...
No Matches
JAAnetToolkit.hh
Go to the documentation of this file.
1#ifndef __JAANET__JAANETTOOLKIT__
2#define __JAANET__JAANETTOOLKIT__
3
4#include <cstdlib>
5#include <algorithm>
6
16
17#include "Jeep/JPrint.hh"
18
19#include "JLang/JException.hh"
20#include "JLang/JPredicate.hh"
21
31
35#include "JPhysics/JGeane.hh"
36
38#include "JAAnet/JGENIETypes.hh"
39#include "JAAnet/JPDB.hh"
40
41
42/**
43 * \file
44 *
45 * Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
46 * \author mdejong, bjjung
47 */
48namespace JAANET {}
49namespace JPP { using namespace JAANET; }
50
51/**
52 * Extensions to Evt data format.
53 */
54namespace JAANET {
55
60
70
71 using JPHYSICS::gWater;
77
78 /**
79 * AAnet shower fit reconstruction type.
80 */
81 static const int AASHOWER_RECONSTRUCTION_TYPE = 101;
82
83
84 /**
85 * Enumeration of hit types based on km3 codes.
86 */
88 HIT_TYPE_MUON_DIRECT = +5, //!< Direct light from muon
89 HIT_TYPE_MUON_SCATTERED = -5, //!< Scattered light from muon
90 HIT_TYPE_DELTARAYS_DIRECT = +4, //!< Direct light from delta-rays
91 HIT_TYPE_DELTARAYS_SCATTERED = -4, //!< Scattered light from delta-rays
92 HIT_TYPE_BREMSSTRAHLUNG_DIRECT = +3, //!< Direct light from Bremsstrahlung
93 HIT_TYPE_BREMSSTRAHLUNG_SCATTERED = -3, //!< Scattered light from Bremsstrahlung
94 HIT_TYPE_SHOWER_DIRECT = +99, //!< Direct light from primary shower
95 HIT_TYPE_SHOWER_SCATTERED = -99, //!< Scattered light from primary shower
96 HIT_TYPE_NOISE = -1, //!< Random noise
97 HIT_TYPE_UNKNOWN = 0 //!< Unknown source
98 };
99
100
101 /**
102 * Get true time of hit.
103 *
104 * \param hit hit
105 * \return true time of hit
106 */
107 inline double getTime(const Hit& hit)
108 {
109 return hit.t;
110 }
111
112
113 /**
114 * Get true charge of hit.
115 *
116 * \param hit hit
117 * \return true charge of hit
118 */
119 inline double getNPE(const Hit& hit)
120 {
121 return hit.a;
122 }
123
124
125 /**
126 * Verify hit origin.
127 *
128 * \param hit hit
129 * \return true if noise; else false
130 */
131 inline bool is_noise(const Hit& hit)
132 {
133 return hit.type == HIT_TYPE_NOISE;
134 }
135
136
137 /**
138 * Get time range (i.e.\ time between earliest and latest hit) of Monte Carlo event.\n
139 * Note that the global event time in not taken into account.
140 *
141 * \param event event
142 * \return time range
143 */
144 inline JTimeRange getTimeRange(const Evt& event)
145 {
147
148 for (std::vector<Hit>::const_iterator hit = event.mc_hits.begin(); hit != event.mc_hits.end(); ++hit) {
149 if (!is_noise(*hit)) {
150 time_range.include(getTime(*hit));
151 }
152 }
153
154 return time_range;
155 }
156
157
158 /**
159 * Get time range (i.e.\ time between earliest and latest hit) of Monte Carlo event.\n
160 * The resulting time range is larger than or equal to the given time window.\n
161 * Note that the global event time in not taken into account.
162 *
163 * \param event event
164 * \param T_ns time window [ns]
165 * \return time range
166 */
167 inline JTimeRange getTimeRange(const Evt& event, const JTimeRange& T_ns)
168 {
169 JTimeRange time_range = getTimeRange(event);
170
171 if (!time_range.is_valid()) {
172 time_range = T_ns;
173 }
174
175 if (time_range.getLength() < T_ns.getLength()) {
176 time_range.setLength(T_ns.getLength());
177 }
178
179 return time_range;
180 }
181
182
183 /**
184 * Get position.
185 *
186 * \param pos position
187 * \return position
188 */
189 inline JPosition3D getPosition(const Vec& pos)
190 {
191 return JPosition3D(pos.x, pos.y, pos.z);
192 }
193
194
195 /**
196 * Get position.
197 *
198 * \param pos position
199 * \return position
200 */
201 inline Vec getPosition(const JPosition3D& pos)
202 {
203 return Vec(pos.getX(), pos.getY(), pos.getZ());
204 }
205
206
207 /**
208 * Get position.
209 *
210 * \param track track
211 * \return position
212 */
213 inline JPosition3D getPosition(const Trk& track)
214 {
215 return getPosition(track.pos);
216 }
217
218
219 /**
220 * Get direction.
221 *
222 * \param dir direction
223 * \return direction
224 */
225 inline JDirection3D getDirection(const Vec& dir)
226 {
227 return JDirection3D(dir.x, dir.y, dir.z);
228 }
229
230
231 /**
232 * Get direction.
233 *
234 * \param dir direction
235 * \return direction
236 */
237 inline Vec getDirection(const JDirection3D& dir)
238 {
239 return Vec(dir.getDX(), dir.getDY(), dir.getDZ());
240 }
241
242
243 /**
244 * Get direction.
245 *
246 * \param track track
247 * \return direction
248 */
249 inline JDirection3D getDirection(const Trk& track)
250 {
251 return getDirection(track.dir);
252 }
253
254
255 /**
256 * Get vertex.
257 *
258 * \param track track
259 * \return vertex
260 */
261 inline JVertex3D getVertex(const Trk& track)
262 {
263 return JVertex3D(getPosition(track), track.t);
264 }
265
266
267 /**
268 * Get axis.
269 *
270 * \param track track
271 * \return axis
272 */
273 inline JAxis3D getAxis(const Trk& track)
274 {
275 return JAxis3D(getPosition(track), getDirection(track));
276 }
277
278
279 /**
280 * Get track.
281 *
282 * \param track track
283 * \return track
284 */
285 inline JTrack3E getTrack(const Trk& track)
286 {
287 return JTrack3E(JTrack3D(getAxis(track), track.t), track.E);
288 }
289
290
291 /**
292 * Get shower.
293 *
294 * \param shower shower
295 * \return shower
296 */
297 inline JShower3E getShower(const Trk& shower)
298 {
299 return JShower3E(JShower3D(getVertex(shower), getDirection(shower)), shower.E);
300 }
301
302
303 /**
304 * Get transformation.
305 *
306 * \param track track
307 * \return transformation
308 */
310 {
311 return JTransformation3D(getPosition(track), getDirection(track));
312 }
313
314
315 /**
316 * Get track information.
317 *
318 * \param track track
319 * \param index index
320 * \param value default value
321 * \return actual value
322 */
323 inline double getW(const Trk& track, const size_t index, const double value)
324 {
325 if (index < track.fitinf.size())
326 return track.fitinf[index];
327 else
328 return value;
329 }
330
331
332 /**
333 * Test whether given track is a photon or neutral pion.
334 *
335 * \param track track
336 * \return true if photon or neutral pion; else false
337 */
338 inline bool is_photon (const Trk& track) { return (track.type == TRACK_TYPE_PHOTON ||
339 abs(track.type) == TRACK_TYPE_NEUTRAL_PION); }
340
341
342 /**
343 * Test whether given track is a (anti-)muon.
344 *
345 * \param track track
346 * \return true if (anti-)muon; else false
347 */
348 inline bool is_muonbundle(const Trk& track) { return (abs(track.type) == PDG_MUONBUNDLE); }
349
350
351 /**
352 * Test whether given track is a neutrino.
353 *
354 * \param track track
355 * \return true if neutrino; else false
356 */
357 inline bool is_neutrino(const Trk& track) { return (abs(track.type) == TRACK_TYPE_NUE ||
358 abs(track.type) == TRACK_TYPE_NUMU ||
359 abs(track.type) == TRACK_TYPE_NUTAU); }
360
361
362 /**
363 * Test whether given track is a (anti-)electron.
364 *
365 * \param track track
366 * \return true if (anti-)electron; else false
367 */
368 inline bool is_electron(const Trk& track) { return (abs(track.type) == TRACK_TYPE_ELECTRON); }
369
370
371 /**
372 * Test whether given track is a (anti-)muon.
373 *
374 * \param track track
375 * \return true if (anti-)muon; else false
376 */
377 inline bool is_muon (const Trk& track) { return (abs(track.type) == TRACK_TYPE_MUON); }
378
379
380 /**
381 * Test whether given track is a (anti-)tau.
382 *
383 * \param track track
384 * \return true if (anti-)tau; else false
385 */
386 inline bool is_tau (const Trk& track) { return (abs(track.type) == TRACK_TYPE_TAU); }
387
388
389 /**
390 * Test whether given track is a charged pion.
391 *
392 * \param track track
393 * \return true if charged pion; else false
394 */
395 inline bool is_pion (const Trk& track) { return (abs(track.type) == TRACK_TYPE_CHARGED_PION_PLUS); }
396
397
398 /**
399 * Test whether given track is a (anti-)proton.
400 *
401 * \param track track
402 * \return true if (anti-)proton; else false
403 */
404 inline bool is_proton (const Trk& track) { return (abs(track.type) == TRACK_TYPE_PROTON); }
405
406
407 /**
408 * Test whether given track is a (anti-)neutron.
409 *
410 * \param track track
411 * \return true if (anti-)neutron; else false
412 */
413 inline bool is_neutron (const Trk& track) { return (abs(track.type) == TRACK_TYPE_NEUTRON); }
414
415
416 /**
417 * Test whether given track is a charged lepton
418 *
419 * \param track track
420 * \return true if lepton; else fails
421 */
422 inline bool is_charged_lepton (const Trk& track) { return (is_electron(track) ||
423 is_muon (track) ||
424 is_tau (track)); }
425
426
427 /**
428 * Test whether given track is a lepton
429 *
430 * \param track track
431 * \return true if lepton; else fails
432 */
433 inline bool is_lepton (const Trk& track) { return (is_neutrino (track) ||
434 is_charged_lepton(track)); }
435
436
437 /**
438 * Test whether given track is a nucleus
439 *
440 * \param track track
441 * \return true if hadron; else fails
442 */
443 inline bool is_nucleus (const Trk& track)
444 {
445 const int abstype = abs(track.type);
446
447 if (abstype / int(1e8) == 10) { // Check if abstype follows 10-digit scheme (10LZZZAAAI) for composite nuclei
448
449 const int Z = (abstype / 10000) % 1000;
450 const int A = (abstype / 10) % 1000;
451
452 return A >= 1 && A >= Z;
453
454 } else { // Check if track corresponds to a hydrogen nucleus
455
456 return track.type == TRACK_TYPE_PROTON;
457 }
458 }
459
460
461 /**
462 * Test whether given track is a hadron
463 *
464 * \param track track
465 * \return true if hadron; else fails
466 */
467 inline bool is_hadron (const Trk& track) { return (abs(track.type) != TRACK_TYPE_PHOTON &&
468 abs(track.type) / int(1e8) != 10 && // not a composite nucleus
469 !is_muonbundle(track) &&
470 !is_lepton (track)); }
471
472
473 /**
474 * Test whether given track is a baryon
475 *
476 * \param track track
477 * \return true if hadron; else fails
478 */
479 inline bool is_baryon (const Trk& track)
480 {
481 auto is_quark = [](const int pdg) { // Auxiliary function to check if given pdg corresponds to a quark
482 return (abs(pdg) >= QUARK_TYPE_UP && abs(pdg) <= QUARK_TYPE_TOP);
483 };
484
485 const int abstype = abs(track.type);
486
487 if (!is_hadron(track)) { return false; }
488
489 // Check whether abstype follows the 7-digit scheme (n nr nL nq1 nq2 nq3 nJ) for a baryon
490
491 const int n = abstype / int(1e6);
492
493 return ((n == 0 || n == 9) && // n equals 9 for pentaquarks, otherwise 0
494 abstype % 10 > 0 && // nJ = 2J + 1 > 0, where J is the total spin
495 is_quark((abstype / 10) % 10) && // nq1 corresponds to a quark
496 is_quark((abstype / 100) % 10) && // nq2 corresponds to a quark
497 is_quark((abstype / 1000) % 10)); // nq3 corresponds to a quark
498 }
499
500
501 /**
502 * Test whether given track is a meson (is hadron and third digit of PDG code is zero)
503 *
504 * \param track track
505 * \return true if hadron; else fails
506 */
507 inline bool is_meson (const Trk& track) { return (is_hadron(track) && !is_baryon(track)); }
508
509
510 /**
511 * Test whether given track corresponds to given particle type.
512 *
513 * \param track track
514 * \param type particle type
515 * \return true if matches the corresponding particle; else false
516 */
517 inline bool has_particleID (const Trk& track, const int type) { return (track.type == type); }
518
519
520 /**
521 * Test whether given track corresponds to an initial state particle.
522 *
523 * \param track track
524 * \return true if track corresponds to an initial state particle; else false
525 */
526 inline bool is_initialstate(const Trk& track)
527 {
528 if (Evt::ROOT_IO_VERSION >= 14) {
529
530 const int absstat = abs(track.status); // Depending upon the generator version, tracks outside of the can may have a negative status flag
531
532 return (absstat == TRK_ST_PRIMARYNEUTRINO ||
533 absstat == TRK_ST_PRIMARYCOSMIC ||
534 absstat == TRK_ST_MUONBUNDLE ||
535 absstat == TRK_ST_ININUCLEI);
536
537 } else if (Evt::ROOT_IO_VERSION >= 11) {
538
539 return (track.mother_id == TRK_MOTHER_UNDEFINED ||
540 track.mother_id == TRK_MOTHER_NONE);
541
542 } else {
543
544 return is_neutrino(track) && track.id == 0;
545 }
546 }
547
548
549 /**
550 * Test whether given track corresponds to a final state particle.
551 *
552 * \param track track
553 * \return true if track corresponds to a final state particle; else false
554 */
555 inline bool is_finalstate(const Trk& track)
556 {
557 if (Evt::ROOT_IO_VERSION >= 15) {
558 return abs(track.status) == TRK_ST_FINALSTATE; // Depending upon the generator version, tracks outside of the can may have a negative status flag
559 } else {
560 return !is_initialstate(track);
561 }
562 }
563
564
565 /**
566 * Test whether given event has an incoming neutrino.
567 *
568 * \param evt event
569 * \return true if neutrino; else false
570 */
571 inline bool has_neutrino(const Evt& evt)
572 {
573 if (Evt::ROOT_IO_VERSION >= 14) {
574
575 for (std::vector<Trk>::const_iterator i = evt.mc_trks.cbegin(); i != evt.mc_trks.cend(); ++i) {
576 if (abs(i->status) == TRK_ST_PRIMARYNEUTRINO) { return true; } // Depending upon the generator version, tracks outside of the can may have a negative status flag
577 }
578
579 return false;
580
581 } else {
582
583 return !evt.mc_trks.empty() && is_neutrino(evt.mc_trks[0]);
584 }
585 }
586
587
588 /**
589 * Get incoming neutrino.
590 *
591 * \param evt event
592 * \return neutrino
593 */
594 inline const Trk& get_neutrino(const Evt& evt)
595 {
596 if (Evt::ROOT_IO_VERSION >= 14) {
597
598 for (std::vector<Trk>::const_iterator i = evt.mc_trks.cbegin(); i != evt.mc_trks.cend(); ++i) {
599 if (abs(i->status) == TRK_ST_PRIMARYNEUTRINO) { return *i; } // Depending upon the generator version, tracks outside of the can may have a negative status flag
600 }
601
602 } else if (!evt.mc_trks.empty() && is_neutrino(evt.mc_trks[0])) {
603
604 return evt.mc_trks[0];
605 }
606
607 THROW(JIndexOutOfRange, "JAANET::get_neutrino(): Event " << evt.id << " has no neutrino.");
608 }
609
610
611 /**
612 * Test whether given event has an incoming muonbundle.
613 *
614 * \param evt event
615 * \return true if muonbundle; else false
616 */
617 inline bool has_muonbundle(const Evt& evt)
618 {
619 std::vector<Trk>::const_iterator i = find_if(evt.mc_trks.cbegin(), evt.mc_trks.cend(), is_muonbundle);
620
621 return i != evt.mc_trks.cend();
622 }
623
624
625 /**
626 * Get incoming muonbundle.
627 *
628 * \param evt event
629 * \return muonbundle
630 */
631 inline const Trk& get_muonbundle(const Evt& evt)
632 {
633 std::vector<Trk>::const_iterator i = find_if(evt.mc_trks.cbegin(), evt.mc_trks.cend(), is_muonbundle);
634
635 if (i != evt.mc_trks.cend()) { return *i; }
636
637 THROW(JIndexOutOfRange, "JAANET::get_muonbundle(): Event " << evt.id << " has no muonbundle.");
638 }
639
640
641 /**
642 * Test whether given event contains target nucleus.
643 *
644 * \param evt event
645 * \return true if target nucleus is defined; else false
646 */
647 inline bool has_target_nucleus(const Evt& evt)
648 {
649 if (Evt::ROOT_IO_VERSION >= 14) {
650
651 for (std::vector<Trk>::const_iterator i = evt.mc_trks.cbegin(); i != evt.mc_trks.cend(); ++i) {
652 if (abs(i->status) == TRK_ST_ININUCLEI) { return true; } // Depending upon the generator version, tracks outside of the can may have a negative status flag
653 }
654
655 return false;
656
657 } else {
658
659 return false;
660 }
661 }
662
663
664 /**
665 * Get target nucleus.
666 *
667 * \param evt event
668 * \return target nucleus
669 */
670 inline const Trk& get_target_nucleus(const Evt& evt)
671 {
672 if (Evt::ROOT_IO_VERSION >= 14) {
673
674 for (std::vector<Trk>::const_iterator i = evt.mc_trks.cbegin(); i != evt.mc_trks.cend(); ++i) {
675 if (abs(i->status) == TRK_ST_ININUCLEI) { return *i; } // Depending upon the generator version, tracks outside of the can may have a negative status flag
676 }
677 }
678
679 THROW(JIndexOutOfRange, "JAANET::get_target_nucleus(): Target nucleus not stored for event " << evt.id << ".");
680 }
681
682
683 /**
684 * Test whether given event contains target nucleon.
685 *
686 * \param evt event
687 * \return true if target nucleon is defined; else false
688 */
689 inline bool has_target_nucleon(const Evt& evt)
690 {
691 if (Evt::ROOT_IO_VERSION >= 14) {
692
693 for (std::vector<Trk>::const_iterator i = evt.mc_trks.cbegin(); i != evt.mc_trks.cend(); ++i) {
694
695 const int absstat = abs(i->status); // Depending upon the generator version, tracks outside of the can may have a negative status flag
696
697 if ((absstat == TRK_ST_NUCTGT) || // Check for target nucleon or for proton target nucleus
698 (absstat == TRK_ST_ININUCLEI && i->type == TRACK_TYPE_PROTON)) { return true; }
699 }
700
701 return false;
702
703 } else {
704
705 return false;
706 }
707 }
708
709
710 /**
711 * Get target nucleon.
712 *
713 * \param evt event
714 * \return target nucleon
715 */
716 inline const Trk& get_target_nucleon(const Evt& evt)
717 {
718 if (Evt::ROOT_IO_VERSION >= 14) {
719
720 for (std::vector<Trk>::const_iterator i = evt.mc_trks.cbegin(); i != evt.mc_trks.cend(); ++i) {
721
722 const int absstat = abs(i->status); // Depending upon the generator version, tracks outside of the can may have a negative status flag
723
724 if ((absstat == TRK_ST_NUCTGT) || // Check for target nucleon or for proton target nucleus
725 (absstat == TRK_ST_ININUCLEI && i->type == TRACK_TYPE_PROTON)) { return *i; }
726 }
727 }
728
729 THROW(JIndexOutOfRange, "JAANET::get_target_nucleon(): Target nucleon not stored for event " << evt.id << ".");
730 }
731
732
733 /**
734 * Auxiliary function to check if an event contains a primary track.
735 *
736 * \param evt event
737 * \return true if event has primary track; else false
738 */
739 inline bool has_primary(const Evt& evt)
740 {
741 for (std::vector<Trk>::const_iterator i = evt.mc_trks.cbegin(); i != evt.mc_trks.cend(); ++i) {
742 if (is_initialstate(*i) && abs(i->status) != TRK_ST_ININUCLEI) { // Depending upon the generator version, tracks outside of the can may have a negative status flag
743 return true;
744 }
745 }
746
747 return false;
748 }
749
750
751 /**
752 * Auxiliary function to retrieve the primary track of an event.
753 *
754 * \param evt event
755 * \return primary track
756 */
757 inline const Trk& get_primary(const Evt& evt)
758 {
759 for (std::vector<Trk>::const_iterator i = evt.mc_trks.cbegin(); i != evt.mc_trks.cend(); ++i) {
760 if (is_initialstate(*i) && abs(i->status) != TRK_ST_ININUCLEI) { // Depending upon the generator version, tracks outside of the can may have a negative status flag
761 return *i;
762 }
763 }
764
765 THROW(JIndexOutOfRange, "JAANET::get_primary(): Cannot retrieve primary track for event " << evt.id << ".");
766 }
767
768
769 /**
770 * Auxiliary function to check if an event contains the leading lepton of a neutrino interaction.
771 *
772 * \param event event
773 * \return true if event has the leading lepton; else false
774 */
775 inline bool has_leading_lepton(const Evt& event)
776 {
777 if (has_neutrino(event)) {
778
779 const Trk& neutrino = get_neutrino(event);
780
781 for (std::vector<Trk>::const_iterator i = event.mc_trks.cbegin(); i != event.mc_trks.cend(); ++i) {
782 if (is_lepton(*i) && i->mother_id == neutrino.id) {
783 return true;
784 }
785 }
786 }
787
788 return false;
789 }
790
791
792 /**
793 * Auxiliary function to retrieve the leading lepton of a neutrino interaction.
794 *
795 * \param event event
796 * \return leading lepton
797 */
798 inline const Trk& get_leading_lepton(const Evt& event)
799 {
800 if (has_neutrino(event)) {
801
802 const Trk& neutrino = get_neutrino(event);
803
804 for (std::vector<Trk>::const_iterator i = event.mc_trks.cbegin(); i != event.mc_trks.cend(); ++i) {
805 if (is_lepton(*i) && i->mother_id == neutrino.id) {
806 return *i;
807 }
808 }
809
810 THROW(JIndexOutOfRange, "JAANET::get_leading_lepton(): Event " << event.id << " does not have a leading lepton.");
811
812 } else {
813
814 THROW(JIndexOutOfRange, "JAANET::get_leading_lepton(): Event " << event.id << " has no neutrino.");
815 }
816 }
817
818
819 /**
820 * Get event vertex.
821 *
822 * \param event event
823 * \return event vertex
824 */
825 inline JVertex3D getVertex(const Evt& event)
826 {
827 if (has_neutrino(event)) {
828
829 const Trk& neutrino = get_neutrino(event);
830
831 return getVertex(neutrino);
832
833 } else if (!event.mc_trks.empty()) {
834
835 std::vector<Trk>::const_iterator i = find_if(event.mc_trks.begin(), event.mc_trks.end(), is_initialstate);
836
837 if (i != event.mc_trks.end()) {
838 return getVertex(*i);
839 } else {
840 THROW(JIndexOutOfRange, "JAANET::getVertex(): No initial state track found for event " << event.id);
841 }
842
843 } else if (!event.trks.empty()) { // For reconstructed DAQ events
844
846
847 return getVertex(track);
848
849 } else {
850
851 THROW(JEmptyCollection, "JAANET::getVertex(): Track lists of event " << event.id << " are empty.");
852 }
853 }
854
855
856 /**
857 * Count the number of electrons in a given event
858 *
859 * \param evt event
860 * \return number of electrons
861 */
862 inline int count_electrons(const Evt& evt)
863 {
864 return std::count_if(evt.mc_trks.begin(), evt.mc_trks.end(), is_electron);
865 }
866
867
868 /**
869 * Test whether given event has an electron.
870 *
871 * \param evt event
872 * \return true if event has electron; else false
873 */
874 inline bool has_electron(const Evt& evt)
875 {
876 return count_electrons(evt) != 0;
877 }
878
879
880 /**
881 * Get first electron from the event tracklist
882 *
883 * \param evt event
884 * \return electron
885 */
886 inline const Trk& get_electron(const Evt& evt)
887 {
888 if (count_electrons(evt) > 0)
889 return *std::find_if(evt.mc_trks.begin(), evt.mc_trks.end(), is_electron);
890 else
891 THROW(JIndexOutOfRange, "JAANET::get_electron(): Event " << evt.id << " has no electron.");
892 }
893
894
895 /**
896 * Test whether given hit was produced by an electron
897 *
898 * Warning: This method will only work with the output of KM3Sim.
899 * For JSirene or KM3, you should check if <tt>track.id == hit.origin</tt> instead.
900 *
901 * \param hit hit
902 * \return true if hit was produced by an electron; else false
903 */
904 inline bool from_electron(const Hit& hit)
905 {
907 }
908
909
910 /**
911 * Count the number of muons in a given event
912 *
913 * \param evt event
914 * \return number of muons
915 */
916 inline int count_muons(const Evt& evt)
917 {
918 return std::count_if(evt.mc_trks.begin(), evt.mc_trks.end(), is_muon);
919 }
920
921
922 /**
923 * Test whether given event has a muon.
924 *
925 * \param evt event
926 * \return true if event has muon; else false
927 */
928 inline bool has_muon(const Evt& evt)
929 {
930 return count_muons(evt) != 0;
931 }
932
933
934 /**
935 * Get first muon from the event tracklist
936 *
937 * \param evt event
938 * \return muon
939 */
940 inline const Trk& get_muon(const Evt& evt)
941 {
942 if (count_muons(evt) > 0)
943 return *std::find_if(evt.mc_trks.begin(), evt.mc_trks.end(), is_muon);
944 else
945 THROW(JIndexOutOfRange, "JAANET::get_muon(): Event " << evt.id << " has no muon.");
946 }
947
948
949 /**
950 * Test whether given hit was produced by a muon
951 *
952 * Warning: This method will only work with the output of KM3Sim.
953 * For JSirene or KM3, you should check if <tt>track.id == hit.origin</tt> instead.
954 *
955 * \param hit hit
956 * \return true if hit was produced by a muon; else false
957 */
958 inline bool from_muon(const Hit& hit)
959 {
960 return hit.type == GEANT4_TYPE_MUON || hit.type == GEANT4_TYPE_ANTIMUON;
961 }
962
963
964 /**
965 * Count the number of taus in a given event
966 *
967 * \param evt event
968 * \return number of taus
969 */
970 inline int count_taus(const Evt& evt)
971 {
972 return std::count_if(evt.mc_trks.begin(), evt.mc_trks.end(), is_tau);
973 }
974
975
976 /**
977 * Test whether given event has a tau.
978 *
979 * \param evt event
980 * \return true if event has tau; else false
981 */
982 inline bool has_tau(const Evt& evt)
983 {
984 return count_taus(evt) > 0;
985 }
986
987
988 /**
989 * Get first tau from the event tracklist
990 *
991 * \param evt event
992 * \return tau
993 */
994 inline const Trk& get_tau(const Evt& evt)
995 {
996 if (has_tau(evt))
997 return *std::find_if(evt.mc_trks.begin(), evt.mc_trks.end(), is_tau);
998 else
999 THROW(JIndexOutOfRange, "JAANET::get_tau(): Event " << evt.id << " has no tau.");
1000 }
1001
1002
1003 /**
1004 * Test whether given event contains a tau-lepton decay into a muon.
1005 *
1006 * \param event event
1007 * \return true if event contains a muonic tau-lepton decay; else false
1008 */
1009 inline bool has_muonic_taudecay(const Evt& event)
1010 {
1011 for (std::vector<Trk>::const_iterator i = event.mc_trks.cbegin(); i != event.mc_trks.cend(); ++i) {
1012
1013 if (is_tau(*i)) {
1014
1015 const Trk& tau = *i;
1016
1017 for (std::vector<Trk>::const_iterator j = event.mc_trks.cbegin(); j != event.mc_trks.cend(); ++j) {
1018 if (is_muon(*j) && j->mother_id == tau.id) {
1019 return true;
1020 }
1021 }
1022 }
1023 }
1024
1025 return false;
1026 }
1027
1028
1029 /**
1030 * Test whether given event contains a leptonic tau-decay.
1031 *
1032 * \param event event
1033 * \return true if event contains a leptonic tau-decay; else false
1034 */
1035 inline bool has_leptonic_taudecay(const Evt& event)
1036 {
1037 for (std::vector<Trk>::const_iterator i = event.mc_trks.cbegin(); i != event.mc_trks.cend(); ++i) {
1038
1039 if (is_tau(*i)) {
1040
1041 const Trk& tau = *i;
1042
1043 for (std::vector<Trk>::const_iterator j = event.mc_trks.cbegin(); j != event.mc_trks.cend(); ++j) {
1044 if ((is_electron(*j) || is_muon(*j)) && j->mother_id == tau.id) {
1045 return true;
1046 }
1047 }
1048 }
1049 }
1050
1051 return false;
1052 }
1053
1054
1055 /**
1056 * Test whether given event contains a hadronic tau-decay.
1057 *
1058 * \param event event
1059 * \return true if event contains a hadronic tau-decay; else false
1060 */
1061 inline bool has_hadronic_taudecay(const Evt& event)
1062 {
1063 return has_tau(event) && !has_leptonic_taudecay(event);
1064 }
1065
1066
1067 /**
1068 * Count the number of tau-lepton decay prongs for the given tau lepton.
1069 * The number of prongs is defined as the number of charged tau-lepton decay products.
1070 *
1071 * \param event event
1072 * \param tauID track ID of tau lepton
1073 * \return number of tau-lepton decay prongs
1074 */
1075 inline int count_taudecay_prongs(const Evt& event,
1076 const int tauID)
1077 {
1078 std::vector<Trk>::const_iterator i = std::find_if(event.mc_trks.begin(), event.mc_trks.end(),
1079 make_predicate(&Trk::id, tauID));
1080
1081 if (i != event.mc_trks.end()) {
1082
1083 if (is_tau(*i)) {
1084
1085 int n = 0;
1086
1087 const Trk& tau = *i;
1088
1089 for (std::vector<Trk>::const_iterator i = event.mc_trks.cbegin(); i != event.mc_trks.cend(); ++i) {
1090 if (i->mother_id == tau.id && JPDB::getInstance().getPDG(i->type).charge != 0) {
1091 ++n;
1092 }
1093 }
1094
1095 return n;
1096
1097 } else {
1098
1099 THROW(JValueOutOfRange, "JAANET::count_taudecay_prongs(): Track " << tauID << " of event " << event.id << " does not correspond to a tau lepton.");
1100 }
1101
1102 } else {
1103
1104 THROW(JIndexOutOfRange, "JAANET::count_taudecay_prongs(): No track with ID " << tauID << " in event " << event.id << ".");
1105 }
1106 }
1107
1108
1109 /**
1110 * Count the number of tau-lepton decay prongs for the first tau among the event tracklist.
1111 * The number of prongs is defined as the number of charged tau-lepton decay products.
1112 *
1113 * \param event event
1114 * \return number of tau-lepton decay prongs
1115 */
1116 inline int count_taudecay_prongs(const Evt& event)
1117 {
1118 if (has_tau(event)) {
1119
1120 int n = 0;
1121
1122 const Trk& tau = get_tau(event);
1123
1124 for (std::vector<Trk>::const_iterator i = event.mc_trks.cbegin(); i != event.mc_trks.cend(); ++i) {
1125 if (i->mother_id == tau.id && JPDB::getInstance().getPDG(i->type).charge != 0) {
1126 ++n;
1127 }
1128 }
1129
1130 return n;
1131
1132 } else {
1133
1134 THROW(JIndexOutOfRange, "JAANET::count_taudecay_prongs(): Event " << event.id << " does not contain a tau lepton.");
1135 }
1136 }
1137
1138
1139 /**
1140 * Test whether given hit was produced by a tau
1141 *
1142 * Warning: This method will only work with the output of KM3Sim.
1143 * For JSirene or KM3, you should check if <tt>track.id == hit.origin</tt> instead.
1144 *
1145 * \param hit hit
1146 * \return true if hit was produced by a tau; else false
1147 */
1148 inline bool from_tau(const Hit& hit)
1149 {
1150 return hit.type == GEANT4_TYPE_TAU || hit.type == GEANT4_TYPE_ANTITAU;
1151 }
1152
1153
1154 /**
1155 * Count the number of hadrons in a given event (not including neutral pions)
1156 *
1157 * \param evt event
1158 * \return number of hadrons
1159 */
1160 inline int count_hadrons(const Evt& evt)
1161 {
1162 return std::count_if(evt.mc_trks.begin(), evt.mc_trks.end(), is_hadron);
1163 }
1164
1165
1166 /**
1167 * Test whether given hit was produced by a hadronic shower
1168 *
1169 * Warning: This method will only work with the output of KM3Sim.
1170 * For JSirene or KM3, you should check if <tt>track.id == hit.origin</tt> instead.
1171 *
1172 * \param hit hit
1173 * \return true if hit was produced by a hadron; else false
1174 */
1175 inline bool from_hadron(const Hit& hit)
1176 {
1177 return (!from_electron(hit) && !from_muon(hit) && !from_tau(hit));
1178 }
1179
1180
1181 /**
1182 * Add time offset to mc event;
1183 * according to current definition, the absolute time of the event is defined by the track "t" attribute;
1184 * this could change in the future if the global attribute mc_t is assigned to this purpose.
1185 *
1186 * \param evt event
1187 * \param tOff time offset [ns]
1188 */
1189 inline void add_time_offset(Evt& evt, const double tOff)
1190 {
1191 for (std::vector<Trk>::iterator p = evt.mc_trks.begin(); p != evt.mc_trks.end(); p++) {
1192 p->t += tOff;
1193 }
1194 }
1195
1196
1197 /**
1198 * Get track kinetic energy.
1199 *
1200 * \param trk track
1201 * \return kinetic energy [GeV]
1202 */
1203 inline double getKineticEnergy(const Trk& trk)
1204 {
1205 const double energy = trk.E;
1206 const double mass = JPDB::getInstance().getPDG(trk.type).mass;
1207
1208 return getKineticEnergy(energy, mass);
1209 }
1210
1211
1212 /**
1213 * Get initial state energy of a neutrino interaction.
1214 * This method includes baryon number conservation.
1215 *
1216 * \param evt event
1217 * \return energy [GeV]
1218 */
1219 inline double getE0(const Evt& evt)
1220 {
1221 const Trk& neutrino = get_neutrino(evt);
1222
1223 if (has_target_nucleon(evt)) {
1224
1225 const Trk& target = get_target_nucleon(evt);
1226
1227 return neutrino.E + target.E;
1228
1229 } else {
1230
1231 // Default to calculation based on baryon number conservation and stationary target
1232 // if target nucleon information is unavailable
1233
1234 double E0 = neutrino.E;
1235
1236 for (std::vector<Trk>::const_iterator track = evt.mc_trks.cbegin(); track != evt.mc_trks.end(); ++track) {
1237
1238 if (is_finalstate(*track)) {
1239
1240 if (track->type == TRACK_TYPE_NEUTRON ||
1241 track->type == TRACK_TYPE_SIGMA_MINUS ||
1242 track->type == TRACK_TYPE_NEUTRAL_SIGMA) {
1243
1244 E0 += MASS_NEUTRON;
1245
1246 } else if (track->type == TRACK_TYPE_PROTON ||
1247 track->type == TRACK_TYPE_LAMBDA ||
1248 track->type == TRACK_TYPE_SIGMA_PLUS) {
1249
1250 E0 += MASS_PROTON;
1251
1252 } else if (track->type == TRACK_TYPE_ANTINEUTRON) {
1253
1254 E0 -= MASS_NEUTRON;
1255
1256 } else if (track->type == TRACK_TYPE_ANTIPROTON ||
1257 track->type == TRACK_TYPE_ANTILAMBDA) {
1258
1259 E0 -= MASS_PROTON;
1260 }
1261 }
1262 }
1263
1264 return E0;
1265 }
1266 }
1267
1268
1269 /**
1270 * Get final state energy of a neutrino interaction.
1271 * This method includes muon energy loss.
1272 *
1273 * \param evt event
1274 * \return energy [GeV]
1275 */
1276 inline double getE1(const Evt& evt)
1277 {
1278 double E1 = 0.0;
1279
1280 const Trk& neutrino = get_neutrino(evt);
1281
1282 for (std::vector<Trk>::const_iterator track = evt.mc_trks.cbegin(); track != evt.mc_trks.cend(); ++track) {
1283
1284 if (is_finalstate(*track)) {
1285
1286 if (is_muon(*track)) {
1287
1288 const Trk& mother= (track->mother_id > TRK_MOTHER_UNDEFINED ? evt.mc_trks[track->mother_id] : neutrino);
1289
1290 if (is_muon(mother))
1291 E1 += mother.E;
1292 else
1293 E1 += gWater(track->E, -(track->pos - mother.pos).len());
1294
1295 } else {
1296
1297 E1 += track->E;
1298 }
1299 }
1300 }
1301
1302 return E1;
1303 }
1304
1305
1306 /**
1307 * Get target nucleon mass.
1308 *
1309 * \param evt event
1310 * \return target nucleon mass [GeV]
1311 */
1312 inline double get_target_nucleon_mass(const Evt& evt)
1313 {
1314 if (has_target_nucleon(evt)) {
1315
1316 const Trk& target = get_target_nucleon(evt);
1317
1318 return get_target_nucleon_mass(target.type);
1319
1320 } else if (has_neutrino(evt)) { // Compute target nucleon mass from initial state energy and neutrino energy if nucleon track unavailable
1321
1322 const Trk& neutrino = get_neutrino(evt);
1323
1324 const double E0 = getE0(evt);
1325
1326 return E0 - neutrino.E;
1327
1328 } else {
1329
1331 "JAANET::get_target_nucleon_mass(): Unable to compute target nucleon mass for event " << evt.id << " without target nucleon or neutrino.");
1332 }
1333 }
1334
1335
1336 /**
1337 * Get momentum vector of the initial state of a neutrino interaction.
1338 * Fermi motion is accounted for if the target nucleon information is available.
1339 *
1340 * \param evt event
1341 * \return initial state momentum vector [GeV]
1342 */
1343 inline Vec getP0(const Evt& evt)
1344 {
1345 const Trk& neutrino = get_neutrino(evt);
1346
1347 Vec P0 = neutrino.E * neutrino.dir;
1348
1349 if (has_target_nucleon(evt)) { // Account for Fermi motion
1350
1351 const Trk& target = get_target_nucleon(evt);
1352
1353 const double mN = get_target_nucleon_mass(target.type);
1354
1355 P0 += getKineticEnergy(target.E, mN) * target.dir;
1356 }
1357
1358 return P0;
1359 }
1360
1361
1362 /**
1363 * Get momentum vector of the final state of a neutrino interaction.
1364 * This method includes muon energy losses.
1365 *
1366 * \param evt event
1367 * \return final state momentum vector [GeV]
1368 */
1369 inline Vec getP1(const Evt& evt)
1370 {
1371 Vec P1(0,0,0);
1372
1373 const Trk& neutrino = get_neutrino(evt);
1374
1375 for (std::vector<Trk>::const_iterator track = evt.mc_trks.cbegin(); track != evt.mc_trks.cend(); ++track) {
1376
1377 if (is_finalstate(*track)) {
1378
1379 Vec dir = track->dir;
1380 double kineticEnergy = 0.0;
1381
1382 if (is_muon(*track)) {
1383
1384 const Trk& mother = (track->mother_id > TRK_MOTHER_UNDEFINED ? evt.mc_trks[track->mother_id] : neutrino);
1385
1386 double energy = 0.0;
1387
1388 if (is_muon(mother)) {
1389 dir = mother.dir;
1390 energy = mother.E;
1391 } else {
1392 energy = gWater(track->E, -(track->pos - mother.pos).len());
1393 }
1394
1395 kineticEnergy = getKineticEnergy(energy, MASS_MUON);
1396
1397 } else {
1398
1399 kineticEnergy = getKineticEnergy(*track);
1400 }
1401
1402 P1 += kineticEnergy * dir;
1403 }
1404 }
1405
1406 return P1;
1407 }
1408
1409
1410 /**
1411 * Get negative squared momentum transfer (Q^2 = -q^2 >= 0) of a neutrino interaction.
1412 *
1413 * \param event event
1414 * \return negative squared momentum transfer [GeV^2]
1415 */
1416 inline double getQ2(const Evt& event)
1417 {
1418 const Trk& neutrino = get_neutrino(event);
1419 const Trk& LL = get_leading_lepton(event);
1420
1421 const double dE = (neutrino.E - LL.E);
1422 const Vec dp = (neutrino.E * neutrino.dir - getKineticEnergy(LL) * LL.dir);
1423
1424 return -dE*dE + dp.dot(dp);
1425 }
1426
1427
1428 /**
1429 * Get initial state squared invariant mass of a neutrino interaction.
1430 *
1431 * \param event event
1432 * \return squared invariant mass [GeV^2]
1433 */
1434 inline double getS0(const Evt& event)
1435 {
1436 const double E0 = getE0(event);
1437 const Vec p0 = getP0(event);
1438
1439 return E0*E0 - p0.dot(p0);
1440 }
1441
1442
1443 /**
1444 * Get final state squared invariant mass of a neutrino interaction.
1445 *
1446 * \param event event
1447 * \return squared invariant mass [GeV^2]
1448 */
1449 inline double getS1(const Evt& event)
1450 {
1451 const double E1 = getE1(event);
1452 const Vec p1 = getP1(event);
1453
1454 return E1*E1 - p1.dot(p1);
1455 }
1456
1457
1458 /**
1459 * Retrieve interaction identifier.
1460 *
1461 * The interaction identifier is defined as a 7 digit number.
1462 * The first two digits indicate PDG code of the primary particle in the interaction.
1463 * For neutrino-interactions, the 3rd digit differentiates the interaction type (CC: 2, NC: 3),
1464 * whilst the 4th and 5th digits differentiate the scattering type (QE: 01, DIS: 03, RES: 04, COH: 05, DIFF: 06, MEC: 10).
1465 * For tau-neutrino interactions, the last two digits are used to differentiate between tau-decay modes:
1466 * - 21, for muonic tau-decays
1467 * - 11, for electronic tau-decays
1468 * - the number of prongs, for hadronic tau-decays.
1469 *
1470 * \param event event
1471 * \param useScatteringType toggle distinction between different scattering types
1472 * \param useDecayType toggle distinction between different tau-decays
1473 * \return interaction identifier
1474 */
1475 inline int getInteractionID(const Evt& event,
1476 const bool useScatteringType = true,
1477 const bool useDecayType = true)
1478 {
1479 const Trk& primary = get_primary(event);
1480
1481 int interactionType = 0;
1482 int scatteringType = 0;
1483 int decayType = 0;
1484
1485 if (is_neutrino(primary)) {
1486
1487 interactionType = event.w2list[W2LIST_GSEAGEN_CC];
1488
1489 if (useScatteringType) {
1490 scatteringType = event.w2list[W2LIST_GSEAGEN_ICHAN];
1491 }
1492
1493 if (abs(primary.type) == TRACK_TYPE_NUTAU && useDecayType) {
1494
1495 if (has_muonic_taudecay(event)) {
1496 decayType = 21;
1497 } else if (has_leptonic_taudecay(event)) {
1498 decayType = 11;
1499 } else {
1500 decayType = count_taudecay_prongs(event);
1501 }
1502 }
1503 }
1504
1505 const std::string IDstring = MAKE_STRING(FILL(2,'0') << primary.type <<
1506 FILL(1,'0') << interactionType <<
1507 FILL(2,'0') << scatteringType <<
1508 FILL(2,'0') << decayType);
1509
1510 return std::stoi(IDstring);
1511 }
1512}
1513
1514#endif
TPaveText * p1
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition of GENIE neutrino interaction types.
Energy loss of muon.
Definition of particle types.
Auxiliary methods for physics calculations.
Physics constants.
I/O formatting auxiliaries.
#define MAKE_STRING(A)
Make string.
Definition JPrint.hh:48
Axis object.
Definition JAxis3D.hh:41
Data structure for direction in three dimensions.
Data structure for position in three dimensions.
3D shower with energy.
Definition JShower3E.hh:31
3D track with energy.
Definition JTrack3E.hh:34
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
double getDY() const
Get y direction.
Definition JVersor3D.hh:106
double getDX() const
Get x direction.
Definition JVersor3D.hh:95
double getDZ() const
Get z direction.
Definition JVersor3D.hh:117
Exception for an empty collection.
Exception for accessing an index in a collection that is outside of its range.
Definition JException.hh:92
Exception for accessing a value in a collection that is outside of its range.
bool is_valid() const
Check validity of range.
Definition JRange.hh:311
void setLength(argument_type length)
Set length (difference between upper and lower limit).
Definition JRange.hh:300
T getLength() const
Get length (difference between upper and lower limit).
Definition JRange.hh:289
static JRange< double, std::less< double > > DEFAULT_RANGE()
Definition JRange.hh:555
range_type & include(argument_type x)
Include given value to range.
Definition JRange.hh:397
Extensions to Evt data format.
const Trk & get_electron(const Evt &evt)
Get first electron from the event tracklist.
double getS1(const Evt &event)
Get final state squared invariant mass of a neutrino interaction.
JAxis3D getAxis(const Trk &track)
Get axis.
const Trk & get_tau(const Evt &evt)
Get first tau from the event tracklist.
bool is_neutron(const Trk &track)
Test whether given track is a (anti-)neutron.
bool is_charged_lepton(const Trk &track)
Test whether given track is a charged lepton.
bool is_photon(const Trk &track)
Test whether given track is a photon or neutral pion.
bool has_primary(const Evt &evt)
Auxiliary function to check if an event contains a primary track.
JDirection3D getDirection(const Vec &dir)
Get direction.
bool has_target_nucleon(const Evt &evt)
Test whether given event contains target nucleon.
int count_muons(const Evt &evt)
Count the number of muons in a given event.
bool from_tau(const Hit &hit)
Test whether given hit was produced by a tau.
bool has_target_nucleus(const Evt &evt)
Test whether given event contains target nucleus.
JTrack3E getTrack(const Trk &track)
Get track.
const Trk & get_muonbundle(const Evt &evt)
Get incoming muonbundle.
bool is_electron(const Trk &track)
Test whether given track is a (anti-)electron.
double getS0(const Evt &event)
Get initial state squared invariant mass of a neutrino interaction.
bool has_tau(const Evt &evt)
Test whether given event has a tau.
bool is_nucleus(const Trk &track)
Test whether given track is a nucleus.
bool from_muon(const Hit &hit)
Test whether given hit was produced by a muon.
void add_time_offset(Evt &evt, const double tOff)
Add time offset to mc event; according to current definition, the absolute time of the event is defin...
Vec getP0(const Evt &evt)
Get momentum vector of the initial state of a neutrino interaction.
JShower3E getShower(const Trk &shower)
Get shower.
double getKineticEnergy(const Trk &trk)
Get track kinetic energy.
bool from_hadron(const Hit &hit)
Test whether given hit was produced by a hadronic shower.
const Trk & get_target_nucleus(const Evt &evt)
Get target nucleus.
JVertex3D getVertex(const Trk &track)
Get vertex.
int count_taus(const Evt &evt)
Count the number of taus in a given event.
JTimeRange getTimeRange(const Evt &event)
Get time range (i.e. time between earliest and latest hit) of Monte Carlo event.
const Trk & get_leading_lepton(const Evt &event)
Auxiliary function to retrieve the leading lepton of a neutrino interaction.
bool is_muonbundle(const Trk &track)
Test whether given track is a (anti-)muon.
bool has_leading_lepton(const Evt &event)
Auxiliary function to check if an event contains the leading lepton of a neutrino interaction.
JTransformation3D getTransformation(const Trk &track)
Get transformation.
bool has_muon(const Evt &evt)
Test whether given event has a muon.
bool is_pion(const Trk &track)
Test whether given track is a charged pion.
const Trk & get_primary(const Evt &evt)
Auxiliary function to retrieve the primary track of an event.
static const int AASHOWER_RECONSTRUCTION_TYPE
AAnet shower fit reconstruction type.
bool has_neutrino(const Evt &evt)
Test whether given event has an incoming neutrino.
bool is_finalstate(const Trk &track)
Test whether given track corresponds to a final state particle.
bool has_electron(const Evt &evt)
Test whether given event has an electron.
bool is_neutrino(const Trk &track)
Test whether given track is a neutrino.
double getE1(const Evt &evt)
Get final state energy of a neutrino interaction.
double getTime(const Hit &hit)
Get true time of hit.
double getE0(const Evt &evt)
Get initial state energy of a neutrino interaction.
double get_target_nucleon_mass(const Evt &evt)
Get target nucleon mass.
const Trk & get_muon(const Evt &evt)
Get first muon from the event tracklist.
bool is_initialstate(const Trk &track)
Test whether given track corresponds to an initial state particle.
double getW(const Trk &track, const size_t index, const double value)
Get track information.
int count_electrons(const Evt &evt)
Count the number of electrons in a given event.
JPosition3D getPosition(const Vec &pos)
Get position.
bool is_muon(const Trk &track)
Test whether given track is a (anti-)muon.
int count_taudecay_prongs(const Evt &event, const int tauID)
Count the number of tau-lepton decay prongs for the given tau lepton.
JHitType_t
Enumeration of hit types based on km3 codes.
@ HIT_TYPE_UNKNOWN
Unknown source.
@ HIT_TYPE_NOISE
Random noise.
@ 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.
bool is_noise(const Hit &hit)
Verify hit origin.
bool is_lepton(const Trk &track)
Test whether given track is a lepton.
int getInteractionID(const Evt &event, const bool useScatteringType=true, const bool useDecayType=true)
Retrieve interaction identifier.
bool from_electron(const Hit &hit)
Test whether given hit was produced by an electron.
bool is_proton(const Trk &track)
Test whether given track is a (anti-)proton.
bool is_baryon(const Trk &track)
Test whether given track is a baryon.
@ GEANT4_TYPE_ANTIMUON
@ GEANT4_TYPE_ANTITAU
@ GEANT4_TYPE_ANTIELECTRON
@ GEANT4_TYPE_ELECTRON
double getNPE(const Hit &hit)
Get true charge of hit.
Vec getP1(const Evt &evt)
Get momentum vector of the final state of a neutrino interaction.
double getQ2(const Evt &event)
Get negative squared momentum transfer (Q^2 = -q^2 >= 0) of a neutrino interaction.
bool is_meson(const Trk &track)
Test whether given track is a meson (is hadron and third digit of PDG code is zero)
bool has_muonbundle(const Evt &evt)
Test whether given event has an incoming muonbundle.
bool has_particleID(const Trk &track, const int type)
Test whether given track corresponds to given particle type.
bool has_leptonic_taudecay(const Evt &event)
Test whether given event contains a leptonic tau-decay.
bool has_hadronic_taudecay(const Evt &event)
Test whether given event contains a hadronic tau-decay.
const Trk & get_neutrino(const Evt &evt)
Get incoming neutrino.
const Trk & get_target_nucleon(const Evt &evt)
Get target nucleon.
bool has_muonic_taudecay(const Evt &event)
Test whether given event contains a tau-lepton decay into a muon.
bool is_hadron(const Trk &track)
Test whether given track is a hadron.
@ TRACK_TYPE_ANTINEUTRON
@ TRACK_TYPE_SIGMA_PLUS
@ TRACK_TYPE_CHARGED_PION_PLUS
@ TRACK_TYPE_ANTIPROTON
@ TRACK_TYPE_ANTILAMBDA
@ TRACK_TYPE_NEUTRAL_PION
@ TRACK_TYPE_ELECTRON
@ TRACK_TYPE_NEUTRAL_SIGMA
@ TRACK_TYPE_SIGMA_MINUS
bool is_tau(const Trk &track)
Test whether given track is a (anti-)tau.
int count_hadrons(const Evt &evt)
Count the number of hadrons in a given event (not including neutral pions)
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
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
static const double MASS_NEUTRON
neutron mass [GeV]
double getKineticEnergy(const double E, const double m)
Get kinetic energy of particle with given energy and mass.
static const double MASS_PROTON
proton mass [GeV]
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition Evt.hh:21
std::vector< Hit > mc_hits
MC: list of MC truth hits.
Definition Evt.hh:48
std::vector< Trk > mc_trks
MC: list of MC truth tracks.
Definition Evt.hh:49
int id
offline event identifier
Definition Evt.hh:22
static int ROOT_IO_VERSION
Streamer version as obtained from ROOT file.
Definition Evt.hh:274
std::vector< Trk > trks
list of reconstructed tracks (can be several because of prefits,showers, etc).
Definition Evt.hh:39
Auxiliary data structure for sequence of same character.
Definition JManip.hh:330
Definition Hit.hh:10
double a
hit amplitude (in p.e.)
Definition Hit.hh:24
int type
particle type or parametrisation used for hit (mc only)
Definition Hit.hh:28
double t
hit time (from tdc+calibration or MC truth)
Definition Hit.hh:23
static const JPDB & getInstance()
Get particle data book.
Definition JPDB.hh:126
const JParticle & getPDG(const int pdg) const
Get particle corresponding to given PDG code.
Definition JPDB.hh:235
JElectricCharge charge
electric charge of particle [|e|/3]
Definition JPDB.hh:93
double mass
mass of particle [GeV]
Definition JPDB.hh:92
Primary particle.
Definition JHead.hh:1174
int type
Particle type.
Definition JHead.hh:1204
Target.
Definition JHead.hh:300
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition Trk.hh:15
int status
MC or reconstruction status code, see km3net-dataformat/definitions/trkmembers.csv for values.
Definition Trk.hh:28
int type
MC: particle type in PDG encoding.
Definition Trk.hh:24
int id
track identifier
Definition Trk.hh:16
std::vector< double > fitinf
place to store additional fit info, see km3net-dataformat/definitions/fitparameters....
Definition Trk.hh:32
Vec dir
track direction
Definition Trk.hh:18
double E
Energy [GeV] (either MC truth or reconstructed)
Definition Trk.hh:20
double t
track time [ns] (when the particle is at pos )
Definition Trk.hh:19
int mother_id
id of the parent MC particle or of the reconstructed track at the previous stage
Definition Trk.hh:29
Vec pos
postion [m] of the track at time t
Definition Trk.hh:17
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition Vec.hh:13
double dot(const Vec &v) const
Get dot product.
Definition Vec.hh:36
double z
Definition Vec.hh:14
double x
Definition Vec.hh:14
double y
Definition Vec.hh:14
Auxiliary methods for selection of reconstructed tracks.
const Trk & get_best_reconstructed_track(const Evt &evt, JTrackSelector_t selector, JQualitySorter_t comparator)
Get best reconstructed track.
static const int PDG_MUONBUNDLE
muon bundle reached the can level (mupage)
Definition trkmembers.hh:40
static const int TRK_ST_FINALSTATE
for MC: the particle must be processed by detector simulation ('track_in' tag in evt files)....
Definition trkmembers.hh:17
static const int TRK_ST_NUCTGT
Nucleon target (gseagen)
Definition trkmembers.hh:24
static const int TRK_MOTHER_UNDEFINED
mother id was not defined for this track
Definition trkmembers.hh:14
static const int TRK_ST_MUONBUNDLE
initial state muon bundle (mupage)
Definition trkmembers.hh:20
static const int TRK_ST_PRIMARYCOSMIC
initial state cosmic ray ('track_primary' tag in evt files from corant).
Definition trkmembers.hh:19
static const int TRK_ST_PRIMARYNEUTRINO
initial state neutrino ('neutrino' tag in evt files from gseagen and genhen).
Definition trkmembers.hh:18
static const int TRK_ST_ININUCLEI
Initial state nuclei (gseagen)
Definition trkmembers.hh:21
static const int TRK_MOTHER_NONE
mother id of a particle if it has no parent
Definition trkmembers.hh:15
static const int W2LIST_GSEAGEN_CC
Charged current interaction flag.
static const int W2LIST_GSEAGEN_ICHAN
Interaction channel.