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 
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.pure_t = this->t;
67  hit.pure_a = this->npe;
68  hit.t = this->t;
69  hit.a = this->npe;
70 
71  return hit;
72  }
73 
74 
75  /**
76  * Less than operator for hits.
77  *
78  * First hit is defined as:
79  * -# smallest PMT identifier;
80  * -# earliest time if same PMT identifier;
81  *
82  * \param first first hit
83  * \param second second hit
84  * \return true if first hit earlier than second hit; else false
85  */
86  friend inline bool operator<(const JHit_t& first, const JHit_t& second)
87  {
88  if (first.pmt_id == second.pmt_id)
89  return first.t < second.t;
90  else
91  return first.pmt_id < second.pmt_id;
92  }
93 
94 
95  int id;
96  int pmt_id;
97  int type;
98  int origin;
99  double t;
100  int npe;
101  };
102 
103 
104  /**
105  * Auxiliary data structure for list of hits with hit merging capability.
106  */
107  struct JHits_t :
108  public std::vector<JHit_t>
109  {
110  /**
111  * Merge hits on same PMT that are within given time window.
112  *
113  * The earliest hit has the sum of the number of photo-electrons of all following hits within given time window.\n
114  * The hit identifiers are subsequently set in ascending order, starting at one.
115  *
116  * \param Tmax_ns maximal time difference [ns]
117  */
118  void merge(const double Tmax_ns)
119  {
120  using namespace std;
121 
122  if (!this->empty()) {
123 
124  sort(this->begin(), this->end());
125 
126  iterator in = this->begin();
127  iterator out = this->begin();
128 
129  out->id = 1; // set first hit identifier
130 
131  while (++in != this->end()) {
132 
133  if (out->pmt_id == in->pmt_id && in->t - out->t <= Tmax_ns) {
134 
135  out->npe += in->npe; // accumulate number of photo-electrons
136 
137  } else {
138 
139  int id = out->id;
140 
141  ++out; // increment desitination address
142 
143  *out = *in; // copy first new hit
144 
145  out->id = ++id; // set hit identifier
146  }
147  }
148 
149  this->erase(++out, this->end()); // remove hits
150  }
151  }
152  };
153 }
154 
155 #endif
Auxiliary class to set-up Hit.
Definition: JHit_t.hh:25
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
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:118
int origin
track id of the track that created this hit
Definition: Hit.hh:31
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
double pure_t
photon time before pmt simultion (MC only)
Definition: Hit.hh:28
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
double pure_a
amptitude before pmt simution (MC only)
Definition: Hit.hh:29
Auxiliary data structure for list of hits with hit merging capability.
Definition: JHit_t.hh:107
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:86
double t
hit time (from calibration or MC truth)
Definition: Hit.hh:23
double t
Definition: JHit_t.hh:99
int type
particle type or parametrisation used for hit (mc only)
Definition: Hit.hh:30