Jpp  15.0.1-rc.2-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JHit_t.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JHIT_T__
2 #define __JAANET__JHIT_T__
3 
4 #include <vector>
5 #include <algorithm>
6 
8 
9 
10 /**
11  * \author mdejong
12  */
13 
14 namespace JAANET {}
15 namespace JPP { using namespace JAANET; }
16 
17 namespace JAANET {
18 
19  /**
20  * Auxiliary class to set-up Hit.
21  *
22  * This class is primarily used to limit the size of a Monte Carlo hit and
23  * thereby the memory usage of applications in case of large numbers of hits.
24  */
25  struct JHit_t
26  {
27  /**
28  * Constructor.
29  *
30  * \param id identifier
31  * \param pmt_id PMT identifier
32  * \param type type
33  * \param origin origin
34  * \param t time [ns]
35  * \param npe number of photo-electrons
36  */
37  JHit_t(const int id,
38  const int pmt_id,
39  const int type,
40  const int origin,
41  const double t,
42  const int npe)
43  {
44  this->id = id;
45  this->pmt_id = pmt_id;
46  this->type = type;
47  this->origin = origin;
48  this->t = t;
49  this->npe = npe;
50  }
51 
52 
53  /**
54  * Type conversion operator.
55  *
56  * \return hit
57  */
58  operator const Hit& () const
59  {
60  static Hit hit;
61 
62  hit.id = this->id;
63  hit.pmt_id = this->pmt_id;
64  hit.type = this->type;
65  hit.origin = this->origin;
66  hit.t = this->t;
67  hit.a = this->npe;
68 
69  return hit;
70  }
71 
72 
73  /**
74  * Less than operator for hits.
75  *
76  * First hit is defined as:
77  * -# smallest PMT identifier;
78  * -# earliest time if same PMT identifier;
79  *
80  * \param first first hit
81  * \param second second hit
82  * \return true if first hit earlier than second hit; else false
83  */
84  friend inline bool operator<(const JHit_t& first, const JHit_t& second)
85  {
86  if (first.pmt_id == second.pmt_id)
87  return first.t < second.t;
88  else
89  return first.pmt_id < second.pmt_id;
90  }
91 
92 
93  int id;
94  int pmt_id;
95  int type;
96  int origin;
97  double t;
98  int npe;
99  };
100 
101 
102  /**
103  * Auxiliary data structure for list of hits with hit merging capability.
104  */
105  struct JHits_t :
106  public std::vector<JHit_t>
107  {
108  /**
109  * Merge hits on same PMT that are within given time window.
110  *
111  * The earliest hit has the sum of the number of photo-electrons of all following hits within given time window.\n
112  * The hit identifiers are subsequently set in ascending order, starting at one.
113  *
114  * \param Tmax_ns maximal time difference [ns]
115  */
116  void merge(const double Tmax_ns)
117  {
118  using namespace std;
119 
120  if (!this->empty()) {
121 
122  sort(this->begin(), this->end());
123 
124  iterator in = this->begin();
125  iterator out = this->begin();
126 
127  out->id = 1; // set first hit identifier
128 
129  while (++in != this->end()) {
130 
131  if (out->pmt_id == in->pmt_id && in->t - out->t <= Tmax_ns) {
132 
133  out->npe += in->npe; // accumulate number of photo-electrons
134 
135  } else {
136 
137  int id = out->id;
138 
139  ++out; // increment desitination address
140 
141  *out = *in; // copy first new hit
142 
143  out->id = ++id; // set hit identifier
144  }
145  }
146 
147  this->erase(++out, this->end()); // remove hits
148  }
149  }
150  };
151 }
152 
153 #endif
Auxiliary class to set-up Hit.
Definition: JHit_t.hh:25
int pmt_id
global PMT identifier as found in evt files
Definition: Hit.hh:20
void merge(const double Tmax_ns)
Merge hits on same PMT that are within given time window.
Definition: JHit_t.hh:116
int origin
track id of the track that created this hit
Definition: Hit.hh:29
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
double a
hit amplitude (in p.e.)
Definition: Hit.hh:24
JHit_t(const int id, const int pmt_id, const int type, const int origin, const double t, const int npe)
Constructor.
Definition: JHit_t.hh:37
Auxiliary data structure for list of hits with hit merging capability.
Definition: JHit_t.hh:105
int id
Definition: Hit.hh:11
Definition: Hit.hh:8
friend bool operator<(const JHit_t &first, const JHit_t &second)
Less than operator for hits.
Definition: JHit_t.hh:84
double t
hit time (from tdc+calibration or MC truth)
Definition: Hit.hh:23
double t
Definition: JHit_t.hh:97
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:41
int type
particle type or parametrisation used for hit (mc only)
Definition: Hit.hh:28