Jpp  19.1.0
the software that should make you happy
JTrigger/JHit.hh
Go to the documentation of this file.
1 #ifndef __JTRIGGER__JHIT__
2 #define __JTRIGGER__JHIT__
3 
5 
6 
7 /**
8  * \file
9  *
10  * Basic data structure for time and time over threshold information of hit.
11  * \author mdejong
12  */
13 namespace JTRIGGER {}
14 namespace JPP { using namespace JTRIGGER; }
15 
16 namespace JTRIGGER {
17 
18 
19  /**
20  * %Hit data structure.
21  */
22  class JHit
23  {
24  public:
25  /**
26  * Default constructor.
27  */
28  JHit() :
29  t(0.0),
30  tot(0.0)
31  {}
32 
33 
34  /**
35  * Constructor.
36  *
37  * \param t_ns calibrated time of hit [ns]
38  */
39  JHit(const double t_ns) :
40  t(t_ns),
41  tot(0.0)
42  {}
43 
44  /**
45  * Constructor.
46  *
47  * \param t_ns calibrated time of hit [ns]
48  * \param tot_ns time over threshold of hit [ns]
49  */
50  JHit(const double t_ns, const double tot_ns) :
51  t(t_ns),
52  tot(tot_ns)
53  {}
54 
55 
56  /**
57  * Get combined hit.
58  *
59  * Note that:
60  * - leading edge of this hit is set to the earliest leading edge of the all hits;
61  * - trailing edge of this hit is set to the latest trailing edge of the all hits;
62  *
63  * It is assumed that the template class has the following methods:
64  * <pre>
65  * %getT();
66  * %getToT();
67  * </pre>
68  * which should return the time and time over threshold, respectively.
69  *
70  * \param __begin begin of hits
71  * \param __end end of hits
72  */
73  template<class T>
74  JHit(T __begin, T __end) :
75  t(0.0),
76  tot(0.0)
77  {
78  if (__begin != __end) {
79 
80  double t1 = __begin->getT1();
81  double t2 = __begin->getT2();
82 
83  for (T i = __begin; ++i != __end; ) {
84  if (t1 > i->getT1()) { t1 = i->getT1(); }
85  if (t2 < i->getT2()) { t2 = i->getT2(); }
86  }
87 
88  this->t = t1;
89  this->tot = t2 - t1;
90  }
91  }
92 
93 
94  /**
95  * Get hit.
96  *
97  * \return hit
98  */
99  const JHit& getHit() const
100  {
101  return static_cast<const JHit&>(*this);
102  }
103 
104 
105  /**
106  * Get slewing option.
107  *
108  * \return slewing option
109  */
110  static bool getSlewing()
111  {
112  return get_slewing();
113  }
114 
115 
116  /**
117  * Set slewing option.
118  *
119  * \param slewing slewing option
120  */
121  static void setSlewing(const bool slewing)
122  {
123  get_slewing() = slewing;
124  }
125 
126 
127  /**
128  * Type conversion.
129  *
130  * \return time [ns]
131  */
132  inline operator double() const
133  {
134  return t;
135  }
136 
137 
138  /**
139  * Get calibrated time of hit.
140  *
141  * \return time [ns]
142  */
143  inline double getT() const
144  {
145  if (!getSlewing())
146  return t;
147  else
148  return t - getRiseTime(tot);
149  }
150 
151 
152  /**
153  * Get calibrated time over threshold of hit.
154  *
155  * \return time over threshold [ns]
156  */
157  inline double getToT() const
158  {
159  return tot;
160  }
161 
162 
163  /**
164  * Get leading edge of hit.
165  *
166  * Note that no slewing correction is applied.
167  *
168  * \return time [ns]
169  */
170  inline double getT1() const
171  {
172  return t;
173  }
174 
175 
176  /**
177  * Get trailing edge of hit.
178  *
179  * Note that no slewing correction is applied.
180  *
181  * \return time [ns]
182  */
183  inline double getT2() const
184  {
185  return t + tot;
186  }
187 
188 
189  /**
190  * Join hit.
191  *
192  * Note that:
193  * - leading edge of this hit is maintained;
194  * - time over threshold of this hit is set to the difference between the trailing edge of given hit and leading edge of this hit;
195  *
196  * \param hit hit
197  */
198  void join(const JHit& hit)
199  {
200  this->tot = hit.getT2() - this->getT1();
201  }
202 
203  protected:
204  double t; //!< time of leading edge [ns]
205  double tot; //!< time-over-threshold [ns]
206 
207 
208  /**
209  * Get reference to slewing parameter.
210  *
211  * \return reference to slewing parameter
212  */
213  static bool& get_slewing()
214  {
215  static bool slewing = true;
216 
217  return slewing;
218  }
219  };
220 
221 
222  /**
223  * Less than operator for hits.
224  *
225  * The less than operator is applied to the time of the hits.
226  *
227  * \param first first hit
228  * \param second second hit
229  * \result true if first hit earlier; else false
230  */
231  inline bool operator<(const JHit& first, const JHit& second)
232  {
233  return first.getT() < second.getT();
234  }
235 
236 
237  /**
238  * Less than operator for hits.
239  *
240  * The less than operator is applied to the time of the hits.
241  *
242  * \param hit hit
243  * \param t1 time [ns]
244  * \result true if hit earlier than t; else false
245  */
246  inline bool operator<(const JHit& hit, const double t1)
247  {
248  return hit.getT() < t1;
249  }
250 
251 
252  /**
253  * Equal operator for hits.
254  *
255  * The equal operator is applied to the time of the hits.
256  *
257  * \param first hit
258  * \param second hit
259  * \result true if first hit time equal to second hit time; else false
260  */
261  inline bool operator==(const JHit& first, const JHit& second)
262  {
263  return first.getT() == second.getT();
264  }
265 
266 
267  /**
268  * Get hit count.
269  *
270  * The hit refers to a data structure which should have the following member method:
271  * - int %getN();
272  *
273  * \param hit hit
274  * \return count
275  */
276  template<class T>
277  inline int getCount(const T& hit)
278  {
279  return hit.getN();
280  }
281 
282 
283  /**
284  * Get hit count.
285  *
286  * The hit iterator refers to a data structure which should have the following member method:
287  * - int %getN();
288  *
289  * \param __begin begin of data
290  * \param __end end of data
291  * \return count
292  */
293  template<class T>
294  inline int getCount(T __begin, T __end)
295  {
296  int count = 0;
297 
298  for (T hit = __begin; hit !=__end; ++hit) {
299  count += getCount(*hit);
300  }
301 
302  return count;
303  }
304 }
305 
306 #endif
Rise time evaluation.
Hit data structure.
static bool & get_slewing()
Get reference to slewing parameter.
void join(const JHit &hit)
Join hit.
double getT1() const
Get leading edge of hit.
static bool getSlewing()
Get slewing option.
JHit(const double t_ns, const double tot_ns)
Constructor.
JHit(T __begin, T __end)
Get combined hit.
JHit(const double t_ns)
Constructor.
const JHit & getHit() const
Get hit.
double getT2() const
Get trailing edge of hit.
JHit()
Default constructor.
static void setSlewing(const bool slewing)
Set slewing option.
double t
time of leading edge [ns]
double tot
time-over-threshold [ns]
double getToT() const
Get calibrated time over threshold of hit.
double getT() const
Get calibrated time of hit.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for triggering.
int getCount(T __begin, T __end)
Get hit count.
bool operator<(const JHit &hit, const double t1)
Less than operator for hits.
static const JGetRiseTime getRiseTime
Function object for rise time evaluation.
bool operator==(const JHit &first, const JHit &second)
Equal operator for hits.