Jpp
 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 
7 #include "evt/Hit.hh"
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  struct JHit_t
23  {
24  /**
25  * Constructor.
26  *
27  * \param id identifier
28  * \param pmt_id PMT identifier
29  * \param type type
30  * \param origin origin
31  * \param t time [ns]
32  * \param npe number of photo-electrons
33  */
34  JHit_t(const int id,
35  const int pmt_id,
36  const int type,
37  const int origin,
38  const double t,
39  const int npe)
40  {
41  this->id = id;
42  this->pmt_id = pmt_id;
43  this->type = type;
44  this->origin = origin;
45  this->t = t;
46  this->npe = npe;
47  }
48 
49 
50  /**
51  * Type conversion operator.
52  *
53  * \return hit
54  */
55  operator const Hit& () const
56  {
57  static Hit hit;
58 
59  hit.id = this->id;
60  hit.pmt_id = this->pmt_id;
61  hit.type = this->type;
62  hit.origin = this->origin;
63  hit.pure_t = this->t;
64  hit.pure_a = this->npe;
65  hit.t = this->t;
66  hit.a = this->npe;
67 
68  return hit;
69  }
70 
71 
72  int id;
73  int pmt_id;
74  int type;
75  int origin;
76  double t;
77  int npe;
78  };
79 
80 
81  /**
82  * Less than operator for hits.
83  *
84  * First hit is defined as:
85  * -# smallest PMT identifier
86  * -# earliest time if same PMT identifier
87  *
88  * \param first first hit
89  * \param second second hit
90  * \return true if first hit earlier than second hit; else false
91  */
92  inline bool operator<(const JHit_t& first, const JHit_t& second)
93  {
94  if (first.pmt_id == second.pmt_id)
95  return first.t < second.t;
96  else
97  return first.pmt_id < second.pmt_id;
98  }
99 
100 
101  /**
102  * Auxiliary data structure for list of hits with hit merging capability.
103  */
104  struct JHits_t :
105  public std::vector<JHit_t>
106  {
107  /**
108  * Merge hits on same PMT that are within given time window.
109  *
110  * The first hit has the sum of the number of photo-electrons of all hits within given time window.
111  * The hit identifiers are reset in ascending order, starting at one.
112  *
113  * \param Tmax_ns maximal time difference [ns]
114  */
115  void merge(const double Tmax_ns)
116  {
117  using namespace std;
118 
119  if (!this->empty()) {
120 
121  sort(this->begin(), this->end());
122 
123  iterator in = this->begin();
124  iterator out = this->begin();
125 
126  out->id = 1; // set first hit identifier
127 
128  while (++in != this->end()) {
129 
130  if (out->pmt_id == in->pmt_id && in->t - out->t <= Tmax_ns) {
131 
132  out->npe += in->npe;
133 
134  } else {
135 
136  int id = out->id;
137 
138  ++out; // increment desitination address
139 
140  *out = *in; // copy first new hit
141 
142  out->id = ++id; // set hit identifier
143  }
144  }
145 
146  this->erase(++out, this->end()); // remove hits
147  }
148  }
149  };
150 }
151 
152 #endif
Auxiliary class to set-up Hit.
Definition: JHit_t.hh:22
bool operator<(const Head &first, const Head &second)
Less than operator.
Definition: JHead.hh:899
void merge(const double Tmax_ns)
Merge hits on same PMT that are within given time window.
Definition: JHit_t.hh:115
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:34
Auxiliary data structure for list of hits with hit merging capability.
Definition: JHit_t.hh:104
double t
Definition: JHit_t.hh:76