Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JDAQSummaryFrame.hh
Go to the documentation of this file.
1#ifndef __JDAQSUMMARYFRAME__
2#define __JDAQSUMMARYFRAME__
3
4#include <limits>
5#include <cmath>
6#include <vector>
7
14
15
16/**
17 * \author mdejong
18 */
19
20namespace KM3NETDAQ {
21
22
23 /**
24 * Forward declaration for friend declaration of JDAQSummaryFrame inside JDAQRate.
25 */
26 class JDAQSummaryFrame;
27
28
29 /**
30 * Data storage class for rate measurement of one PMT.
31 *
32 * Note that the rate value is compressed.
33 * The number of bins and corresponding abscissa values can be obtained with
34 * methods JDAQRare::getN and JDAQRate::getData, respectively.
35 */
36 class JDAQRate {
37 public:
38
39 friend class JDAQSummaryFrame;
40
41
42 typedef unsigned char JRate_t; // type of value to store rate
43
44
45 /**
46 * Get minimal rate (below this, value is set to zero)
47 *
48 * \return rate [Hz]
49 */
50 static double getMinimalRate()
51 {
52 return 2.0e3;
53 }
54
55
56 /**
57 * Get maximal rate (above this, value is set to maximum)
58 *
59 * \return rate [Hz]
60 */
61 static double getMaximalRate()
62 {
63 return 2.0e6;
64 }
65
66
67 /**
68 * Get value.
69 *
70 * \param numberOfHits number of hits
71 * \param frameTime_ns frame time [ns]
72 * \return value
73 */
74 static JRate_t getValue(const int numberOfHits, const double frameTime_ns)
75 {
76 return getValue(numberOfHits * 1.0e9 / frameTime_ns);
77 }
78
79
80 /**
81 * Get value.
82 *
83 * \param rate_Hz rate [Hz]
84 * \return value
85 */
86 static JRate_t getValue(const double rate_Hz)
87 {
88 if (rate_Hz <= getMinimalRate())
89 return 0;
90 else if (rate_Hz >= getMaximalRate())
91 return std::numeric_limits<JRate_t>::max();
92 else
93 return (JRate_t) (log(rate_Hz/getMinimalRate()) / getFactor() + 0.5);
94 }
95
96
97 /**
98 * Get count rate.
99 *
100 * \param value value
101 * \return rate [Hz]
102 */
103 static double getRate(const JRate_t value)
104 {
105 if (value == 0)
106 return 0.0;
107 else
108 return get_rate(value);
109 }
110
111
112 /**
113 * Get weight.
114 *
115 * \param value value
116 * \return weight [Hz^-1]
117 */
118 static double getWeight(const JRate_t value)
119 {
120 double W = 1.0;
121
122 if (value == 0)
123 W = get_rate(0.5) - getMinimalRate();
124 else if (value == std::numeric_limits<JRate_t>::max())
125 W = getMaximalRate() - get_rate(std::numeric_limits<JRate_t>::max() - 0.5);
126 else
127 W = get_rate((double) value + 0.5) - get_rate((double) value - 0.5);
128
129 return 1.0 / W;
130 }
131
132
133 /**
134 * Get number of bins.
135 *
136 * \return number of bins
137 */
138 static int getN()
139 {
140 return (int) std::numeric_limits<JRate_t>::max() + 1;
141 }
142
143
144 /**
145 * Get abscissa values.
146 *
147 * \param factor scaling factor
148 * \return abscissa values
149 */
150 static const double* getData(const double factor = 1.0)
151 {
152 static std::vector<double> buffer;
153
154 buffer.clear();
155
156 buffer.push_back(getMinimalRate() * factor);
157
158 for (int i = 1; i != JDAQRate::getN(); ++i) {
159 buffer.push_back(get_rate(i - 0.5) * factor);
160 }
161
162 buffer.push_back(getMaximalRate() * factor);
163
164 return buffer.data();
165 }
166
167
168 /**
169 * Default constructor.
170 */
172 value(0)
173 {}
174
175
176 /**
177 * Get value.
178 *
179 * \return value
180 */
182 {
183 return value;
184 }
185
186
187 /**
188 * Set value.
189 *
190 * \param numberOfHits number of hits
191 * \param frameTime_ns frame time [ns]
192 */
193 void setValue(const int numberOfHits, const double frameTime_ns)
194 {
195 value = getValue(numberOfHits, frameTime_ns);
196 }
197
198
199 /**
200 * Set value.
201 *
202 * \param rate_Hz rate [Hz]
203 */
204 void setValue(const double rate_Hz)
205 {
206 value = getValue(rate_Hz);
207 }
208
209
210 /**
211 * Get count rate.
212 *
213 * \return rate [Hz]
214 */
215 double getRate() const
216 {
217 return getRate(value);
218 }
219
220
221 /**
222 * Get weight.
223 *
224 * \return weight [Hz^-1]
225 */
226 double getWeight() const
227 {
228 return getWeight(value);
229 }
230
231
232 /**
233 * Scale rate.
234 *
235 * \param factor multiplication factor
236 * \return this rate
237 */
238 JDAQRate& mul(const double factor)
239 {
240 setValue(getRate() * factor);
241
242 return *this;
243 }
244
245
246 /**
247 * Scale rate.
248 *
249 * \param factor multiplication factor
250 * \return this rate
251 */
252 JDAQRate& div(const double factor)
253 {
254 setValue(getRate() / factor);
255
256 return *this;
257 }
258
259
260 /**
261 * Check validity of rate.
262 * The rate is considered valid if it is between the minimal and the maximal rate.
263 *
264 * \return true if valid; else false
265 */
266 bool is_valid() const
267 {
268 return (value != 0 && value != std::numeric_limits<JRate_t>::max());
269 }
270
271
272 protected:
274
275
276 private:
277 /**
278 * Get conversion factor.
279 *
280 * \return factor
281 */
282 static const double getFactor()
283 {
284 return std::log(getMaximalRate() / getMinimalRate()) / std::numeric_limits<JRate_t>::max();
285 }
286
287
288 /**
289 * Get count rate.
290 *
291 * \param value value
292 * \return rate [Hz]
293 */
294 static double get_rate(const double value)
295 {
296 return getMinimalRate() * std::exp(value * getFactor());
297 }
298 };
299
300
301 /**
302 * Equal operator for DAQ rates.
303 *
304 * \param first rate
305 * \param second rate
306 * \result true if first rate equal to second; else false
307 */
308 inline bool operator==(const JDAQRate& first,
309 const JDAQRate& second)
310 {
311 return (first.getValue() == second.getValue());
312 }
313
314
315 /**
316 * Not-equal operator for DAQ rates.
317 *
318 * \param first rate
319 * \param second rate
320 * \result true if first rate not equal to second; else false
321 */
322 inline bool operator!=(const JDAQRate& first,
323 const JDAQRate& second)
324 {
325 return (first.getValue() != second.getValue());
326 }
327
328
329 /**
330 * Data storage class for rate measurements of all PMTs in one module.
331 */
334 public JDAQFrameStatus
335 {
336 public:
337
339
342 friend JWriter& operator<<(JWriter&, const JDAQSummaryFrame&);
343
344 /**
345 * Default constructor.
346 */
351
352
353 /**
354 * Constructor.
355 *
356 * \param id module identifier
357 */
362
363
364 /**
365 * Constructor.
366 *
367 * Note that normally the rate is set to the number of hits per unit frame time
368 * but if either the high-rate veto or FIFO (almost) full bit is on,
369 * the rate is set to the number of hits divided by the time of the last hit.
370 *
371 * \param input super frame
372 */
376 {
377 using namespace std;
378
379 typedef JDAQHit::JPMT_t JPMT_t;
380 typedef JDAQHit::JTDC_t JTDC_t;
381
382 vector<int> counter(numeric_limits<JPMT_t>::max(), 0);
383
384 int n = input.size();
385
386 for (JDAQSuperFrame::const_iterator i = input.begin(); n != 0; --n, ++i) {
387 ++counter[i->getPMT()];
388 }
389
390 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
391 data[i].setValue(counter[i], getFrameTime());
392 }
393
394 if (input.testHighRateVeto() || input.testFIFOStatus()) {
395
396 // determine last hit for each PMT
397
398 vector<JTDC_t> limit(numeric_limits<JPMT_t>::max(), 0);
399
400 int n = input.size();
401
402 for (JDAQSuperFrame::const_iterator i = input.begin(); n != 0; --n, ++i) {
403 if (i->getT() > limit[i->getPMT()]) {
404 limit[i->getPMT()] = i->getT();
405 }
406 }
407
408 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
409 if (input.testHighRateVeto(i) || input.testFIFOStatus(i)) {
410 if (limit[i] != 0) {
411 data[i].setValue((double) counter[i] * 1.0e9 / (double) limit[i]);
412 }
413 }
414 }
415 }
416 }
417
418
419 /**
420 * Get DAQ rate of given PMT.
421 *
422 * \param tdc TDC
423 * \return JDAQRate
424 */
425 const JDAQRate& operator[](const int tdc) const
426 {
427 if (tdc >= 0 && tdc < NUMBER_OF_PMTS)
428 return data[tdc];
429 else
430 throw JDAQException("TDC out of range.");
431 }
432
433
434 /**
435 * Get DAQ rate of given PMT.
436 *
437 * \param tdc TDC
438 * \return JDAQRate
439 */
440 JDAQRate& operator[](const int tdc)
441 {
442 if (tdc >= 0 && tdc < NUMBER_OF_PMTS)
443 return data[tdc];
444 else
445 throw JDAQException("TDC out of range.");
446 }
447
448
449 /**
450 * Get value.
451 *
452 * \param tdc TDC
453 * \return value
454 */
455 JRate_t getValue(const int tdc) const
456 {
457 return data[tdc].getValue();
458 }
459
460
461 /**
462 * Get count rate.
463 *
464 * \param tdc TDC
465 * \param factor scaling factor
466 * \return rate x scaling factor [Hz]
467 */
468 double getRate(const int tdc, const double factor = 1.0) const
469 {
470 return data[tdc].getRate() * factor;
471 }
472
473
474 /**
475 * Get weight.
476 *
477 * \param tdc TDC
478 * \param factor scaling factor
479 * \return weight / scaling factor [Hz^-1]
480 */
481 double getWeight(const int tdc, const double factor = 1.0) const
482 {
483 return data[tdc].getWeight() / factor;
484 }
485
486
487 /**
488 * Set count rate.
489 *
490 * \param tdc TDC
491 * \param rate_Hz rate [Hz]
492 */
493 void setRate(const int tdc, const double rate_Hz)
494 {
495 return data[tdc].setValue(rate_Hz);
496 }
497
498
499 static int ROOT_IO_VERSION; //!< Streamer version of JDAQSummaryslice as obtained from ROOT file.
500
501
503
504
505 protected:
506
508 };
509
510
511 /**
512 * Equal operator for DAQ summary frames.
513 *
514 * \param first summary frame
515 * \param second summary frame
516 * \result true if first summary frame equal to second; else false
517 */
518 inline bool operator==(const JDAQSummaryFrame& first,
519 const JDAQSummaryFrame& second)
520 {
521 if (first.getModuleIdentifier() == second.getModuleIdentifier() &&
522 first.getDAQFrameStatus() == second.getDAQFrameStatus()) {
523
524 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
525 if (first[i] != second[i]) {
526 return false;
527 }
528 }
529
530 return true;
531
532 } else {
533
534 return false;
535 }
536 }
537
538
539 /**
540 * Not-equal operator for DAQ summary frames.
541 *
542 * \param first summary frame
543 * \param second summary frame
544 * \result true if first summary frame not equal to second; else false
545 */
546 inline bool operator!=(const JDAQSummaryFrame& first,
547 const JDAQSummaryFrame& second)
548 {
549 return !(first == second);
550 }
551}
552
553#endif
KM3NeT DAQ constants, bit handling, etc.
Interface for binary input.
Interface for binary output.
General exception.
bool testFIFOStatus() const
Test FIFO status.
const JDAQFrameStatus & getDAQFrameStatus() const
Get DAQ frame status.
static const JDAQFrameStatus & getInstance()
Get reference to unique instance of this class object.
bool testHighRateVeto() const
Test high-rate veto status.
const_iterator begin() const
Definition JDAQFrame.hh:165
Hit data structure.
Definition JDAQHit.hh:35
unsigned int JTDC_t
leading edge [ns]
Definition JDAQHit.hh:39
unsigned char JPMT_t
PMT channel in FPGA.
Definition JDAQHit.hh:38
int getModuleID() const
Get module identifier.
const JDAQModuleIdentifier & getModuleIdentifier() const
Get Module identifier.
Data storage class for rate measurement of one PMT.
static JRate_t getValue(const int numberOfHits, const double frameTime_ns)
Get value.
JDAQRate & div(const double factor)
Scale rate.
double getRate() const
Get count rate.
static double get_rate(const double value)
Get count rate.
JDAQRate & mul(const double factor)
Scale rate.
static JRate_t getValue(const double rate_Hz)
Get value.
JDAQRate()
Default constructor.
double getWeight() const
Get weight.
static double getRate(const JRate_t value)
Get count rate.
static int getN()
Get number of bins.
static const double * getData(const double factor=1.0)
Get abscissa values.
void setValue(const double rate_Hz)
Set value.
void setValue(const int numberOfHits, const double frameTime_ns)
Set value.
static double getMinimalRate()
Get minimal rate (below this, value is set to zero)
JRate_t getValue() const
Get value.
static const double getFactor()
Get conversion factor.
static double getMaximalRate()
Get maximal rate (above this, value is set to maximum)
static double getWeight(const JRate_t value)
Get weight.
bool is_valid() const
Check validity of rate.
Data storage class for rate measurements of all PMTs in one module.
JDAQSummaryFrame(const JDAQModuleIdentifier &id)
Constructor.
friend JWriter & operator<<(JWriter &, const JDAQSummaryFrame &)
Write DAQ summary frame to output.
JDAQRate & operator[](const int tdc)
Get DAQ rate of given PMT.
double getRate(const int tdc, const double factor=1.0) const
Get count rate.
JRate_t getValue(const int tdc) const
Get value.
static int ROOT_IO_VERSION
Streamer version of JDAQSummaryslice as obtained from ROOT file.
JDAQSummaryFrame(const JDAQSuperFrame &input)
Constructor.
void setRate(const int tdc, const double rate_Hz)
Set count rate.
double getWeight(const int tdc, const double factor=1.0) const
Get weight.
JDAQRate data[NUMBER_OF_PMTS]
friend JReader & operator>>(JReader &, JDAQSummaryFrame &)
Read DAQ summary frame from input.
ClassDefNV(JDAQSummaryFrame, 2)
JDAQSummaryFrame()
Default constructor.
const JDAQRate & operator[](const int tdc) const
Get DAQ rate of given PMT.
Data frame of one optical module.
bool operator==(const Head &first, const Head &second)
Equal operator.
Definition JHead.hh:1801
bool operator!=(const JTag &first, const JTag &second)
Not equal operator for JTag.
Definition JTag.hh:291
const int n
Definition JPolint.hh:791
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
double getFrameTime()
Get frame time duration.
Definition JDAQClock.hh:162
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition JDAQ.hh:26
size_t getSizeof< JDAQSummaryFrame >()
Get size of type.
Auxiliary class for TDC constraints.
Definition JTDC_t.hh:39