Jpp
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 
8 #include "JDAQ/JDAQException.hh"
9 #include "JDAQ/JDAQ.hh"
10 #include "JDAQ/JDAQClock.hh"
12 #include "JDAQ/JDAQFrameStatus.hh"
13 #include "JDAQ/JDAQSuperFrame.hh"
14 
15 
16 /**
17  * \author mdejong
18  */
19 
20 namespace 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  protected:
262 
263 
264  private:
265  /**
266  * Get conversion factor.
267  *
268  * \return factor
269  */
270  static const double getFactor()
271  {
272  return std::log(getMaximalRate() / getMinimalRate()) / std::numeric_limits<JRate_t>::max();
273  }
274 
275 
276  /**
277  * Get count rate.
278  *
279  * \param value value
280  * \return rate [Hz]
281  */
282  static double get_rate(const double value)
283  {
284  return getMinimalRate() * std::exp(value * getFactor());
285  }
286  };
287 
288 
289  /**
290  * Equal operator for DAQ rates.
291  *
292  * \param first rate
293  * \param second rate
294  * \result true if first rate equal to second; else false
295  */
296  inline bool operator==(const JDAQRate& first,
297  const JDAQRate& second)
298  {
299  return (first.getValue() == second.getValue());
300  }
301 
302 
303  /**
304  * Not-equal operator for DAQ rates.
305  *
306  * \param first rate
307  * \param second rate
308  * \result true if first rate not equal to second; else false
309  */
310  inline bool operator!=(const JDAQRate& first,
311  const JDAQRate& second)
312  {
313  return (first.getValue() != second.getValue());
314  }
315 
316 
317  /**
318  * Data storage class for rate measurements of all PMTs in one module.
319  */
321  public JDAQModuleIdentifier,
322  public JDAQFrameStatus
323  {
324  public:
325 
327 
328 
329  /**
330  * Default constructor.
331  */
335  {}
336 
337 
338  /**
339  * Constructor.
340  *
341  * \param id module identifier
342  */
346  {}
347 
348 
349  /**
350  * Constructor.
351  *
352  * Note that normally the rate is set to the number of hits per unit frame time
353  * but if either the high-rate veto or FIFO (almost) full bit is on,
354  * the rate is set to the number of hits divided by the time of the last hit.
355  *
356  * \param input super frame
357  */
361  {
362  using namespace std;
363 
364  typedef JDAQHit::JPMT_t JPMT_t;
365  typedef JDAQHit::JTDC_t JTDC_t;
366 
367  vector<int> counter(numeric_limits<JPMT_t>::max(), 0);
368 
369  int n = input.size();
370 
371  for (JDAQSuperFrame::const_iterator i = input.begin(); n != 0; --n, ++i) {
372  ++counter[i->getPMT()];
373  }
374 
375  for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
376  data[i].setValue(counter[i], getFrameTime());
377  }
378 
379  if (input.testHighRateVeto() || input.testFIFOStatus()) {
380 
381  // determine last hit for each PMT
382 
383  vector<JTDC_t> limit(numeric_limits<JPMT_t>::max(), 0);
384 
385  int n = input.size();
386 
387  for (JDAQSuperFrame::const_iterator i = input.begin(); n != 0; --n, ++i) {
388  if (i->getT() > limit[i->getPMT()]) {
389  limit[i->getPMT()] = i->getT();
390  }
391  }
392 
393  for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
394  if (input.testHighRateVeto(i) || input.testFIFOStatus(i)) {
395  if (limit[i] != 0) {
396  data[i].setValue((double) counter[i] * 1.0e9 / (double) limit[i]);
397  }
398  }
399  }
400  }
401  }
402 
403 
404  /**
405  * Get DAQ rate of given PMT.
406  *
407  * \param tdc TDC
408  * \return JDAQRate
409  */
410  const JDAQRate& operator[](const int tdc) const
411  {
412  if (tdc >= 0 && tdc < NUMBER_OF_PMTS)
413  return data[tdc];
414  else
415  throw JDAQException("TDC out of range.");
416  }
417 
418 
419  /**
420  * Get DAQ rate of given PMT.
421  *
422  * \param tdc TDC
423  * \return JDAQRate
424  */
425  JDAQRate& operator[](const int tdc)
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 value.
436  *
437  * \param tdc TDC
438  * \return value
439  */
440  double getValue(const int tdc) const
441  {
442  return data[tdc].getValue();
443  }
444 
445 
446  /**
447  * Get count rate.
448  *
449  * \param tdc TDC
450  * \param factor scaling factor
451  * \return rate x scaling factor [Hz]
452  */
453  double getRate(const int tdc, const double factor = 1.0) const
454  {
455  return data[tdc].getRate() * factor;
456  }
457 
458 
459  /**
460  * Get weight.
461  *
462  * \param tdc TDC
463  * \param factor scaling factor
464  * \return weight / scaling factor [Hz^-1]
465  */
466  double getWeight(const int tdc, const double factor = 1.0) const
467  {
468  return data[tdc].getWeight() / factor;
469  }
470 
471 
472  /**
473  * Set count rate.
474  *
475  * \param tdc TDC
476  * \param rate_Hz rate [Hz]
477  */
478  void setRate(const int tdc, const double rate_Hz)
479  {
480  return data[tdc].setValue(rate_Hz);
481  }
482 
483 
484  /**
485  * Read DAQ summary frame from input.
486  *
487  * \param in JReader
488  * \param summary JDAQSummaryFrame
489  * \return JReader
490  */
491  friend inline JReader& operator>>(JReader& in, JDAQSummaryFrame& summary)
492  {
493  in >> static_cast<JDAQModuleIdentifier&>(summary);
494  in >> static_cast<JDAQFrameStatus&> (summary);
495 
496  in.read((char*) summary.data, NUMBER_OF_PMTS * sizeof(JRate_t));
497 
498  return in;
499  }
500 
501 
502  /**
503  * Write DAQ summary frame to output.
504  *
505  * \param out JWriter
506  * \param summary DAQSummaryFrame
507  * \return JWriter
508  */
509  friend inline JWriter& operator<<(JWriter& out, const JDAQSummaryFrame& summary)
510  {
511  out << static_cast<const JDAQModuleIdentifier&>(summary);
512  out << static_cast<const JDAQFrameStatus&> (summary);
513 
514  out.write((char*) summary.data, NUMBER_OF_PMTS * sizeof(JRate_t));
515 
516  return out;
517  }
518 
519 
520  /**
521  * Get size of object.
522  *
523  * \return number of bytes
524  */
525  static int sizeOf()
526  {
527  return (JDAQModuleIdentifier::sizeOf() +
529  NUMBER_OF_PMTS * sizeof(JDAQRate));
530  }
531 
532 
533  static int ROOT_IO_VERSION; //!< Streamer version of JDAQSummaryslice as obtained from ROOT file.
534 
535 
537 
538 
539  protected:
540 
542  };
543 
544 
545  /**
546  * Equal operator for DAQ summary frames.
547  *
548  * \param first summary frame
549  * \param second summary frame
550  * \result true if first summary frame equal to second; else false
551  */
552  inline bool operator==(const JDAQSummaryFrame& first,
553  const JDAQSummaryFrame& second)
554  {
555  if (first.getModuleIdentifier() == second.getModuleIdentifier() &&
556  first.getDAQFrameStatus() == second.getDAQFrameStatus()) {
557 
558  for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
559  if (first[i] != second[i]) {
560  return false;
561  }
562  }
563 
564  return true;
565 
566  } else {
567 
568  return false;
569  }
570  }
571 
572 
573  /**
574  * Not-equal operator for DAQ summary frames.
575  *
576  * \param first summary frame
577  * \param second summary frame
578  * \result true if first summary frame not equal to second; else false
579  */
580  inline bool operator!=(const JDAQSummaryFrame& first,
581  const JDAQSummaryFrame& second)
582  {
583  return !(first == second);
584  }
585 }
586 
587 #endif
JDAQ.hh
JIO::JReader
Interface for binary input.
Definition: JSerialisable.hh:62
KM3NETDAQ::JDAQFrameStatus::testHighRateVeto
bool testHighRateVeto() const
Test high-rate veto status.
Definition: JDAQFrameStatus.hh:202
KM3NETDAQ::JDAQSummaryFrame::operator[]
JDAQRate & operator[](const int tdc)
Get DAQ rate of given PMT.
Definition: JDAQSummaryFrame.hh:425
KM3NETDAQ::JDAQRate::getN
static int getN()
Get number of bins.
Definition: JDAQSummaryFrame.hh:138
KM3NETDAQ::JDAQModuleIdentifier::sizeOf
static int sizeOf()
Get size of object.
Definition: JDAQModuleIdentifier.hh:143
KM3NETDAQ::JDAQSummaryFrame::JDAQSummaryFrame
JDAQSummaryFrame()
Default constructor.
Definition: JDAQSummaryFrame.hh:332
KM3NETDAQ::JDAQRate::getMinimalRate
static double getMinimalRate()
Get minimal rate (below this, value is set to zero)
Definition: JDAQSummaryFrame.hh:50
KM3NETDAQ::JDAQRate::getValue
static JRate_t getValue(const double rate_Hz)
Get value.
Definition: JDAQSummaryFrame.hh:86
KM3NETDAQ::JDAQSummaryFrame::operator>>
friend JReader & operator>>(JReader &in, JDAQSummaryFrame &summary)
Read DAQ summary frame from input.
Definition: JDAQSummaryFrame.hh:491
KM3NETDAQ::JDAQSummaryFrame::JDAQSummaryFrame
JDAQSummaryFrame(const JDAQModuleIdentifier &id)
Constructor.
Definition: JDAQSummaryFrame.hh:343
KM3NETDAQ::JDAQFrame::size
int size() const
Definition: JDAQFrame.hh:157
KM3NETDAQ::JDAQSummaryFrame::data
JDAQRate data[NUMBER_OF_PMTS]
Definition: JDAQSummaryFrame.hh:541
KM3NETDAQ::JDAQRate::getWeight
static double getWeight(const JRate_t value)
Get weight.
Definition: JDAQSummaryFrame.hh:118
JTOOLS::n
const int n
Definition: JPolint.hh:628
std::vector< double >
KM3NETDAQ::JDAQRate::div
JDAQRate & div(const double factor)
Scale rate.
Definition: JDAQSummaryFrame.hh:252
KM3NETDAQ::JDAQFrameStatus
DAQ frame status.
Definition: JDAQFrameStatus.hh:23
KM3NETDAQ::JDAQSummaryFrame::getWeight
double getWeight(const int tdc, const double factor=1.0) const
Get weight.
Definition: JDAQSummaryFrame.hh:466
KM3NETDAQ::JDAQRate::value
JRate_t value
Definition: JDAQSummaryFrame.hh:261
KM3NETDAQ::NUMBER_OF_PMTS
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
KM3NETDAQ::JDAQModuleIdentifier::getModuleID
int getModuleID() const
Get module identifier.
Definition: JDAQModuleIdentifier.hh:72
JDAQClock.hh
KM3NETDAQ::JDAQModuleIdentifier::id
int id
Definition: JDAQModuleIdentifier.hh:153
KM3NETDAQ::JDAQSummaryFrame::ROOT_IO_VERSION
static int ROOT_IO_VERSION
Streamer version of JDAQSummaryslice as obtained from ROOT file.
Definition: JDAQSummaryFrame.hh:533
KM3NETDAQ::JDAQRate::getWeight
double getWeight() const
Get weight.
Definition: JDAQSummaryFrame.hh:226
KM3NETDAQ::getFrameTime
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
KM3NETDAQ::JDAQSummaryFrame::getRate
double getRate(const int tdc, const double factor=1.0) const
Get count rate.
Definition: JDAQSummaryFrame.hh:453
KM3NETDAQ::JDAQRate::getData
static const double * getData(const double factor=1.0)
Get abscissa values.
Definition: JDAQSummaryFrame.hh:150
KM3NETDAQ::JDAQSummaryFrame::ClassDefNV
ClassDefNV(JDAQSummaryFrame, 2)
KM3NETDAQ::JDAQSuperFrame::const_iterator
JDAQFrame::const_iterator const_iterator
Definition: JDAQSuperFrame.hh:34
KM3NETDAQ::JDAQModuleIdentifier::getModuleIdentifier
const JDAQModuleIdentifier & getModuleIdentifier() const
Get Module identifier.
Definition: JDAQModuleIdentifier.hh:50
KM3NETDAQ::JDAQSummaryFrame::getValue
double getValue(const int tdc) const
Get value.
Definition: JDAQSummaryFrame.hh:440
JLANG::JBinaryOutput::write
virtual int write(const char *buffer, const int length)=0
Write byte array.
KM3NETDAQ::JDAQSummaryFrame
Data storage class for rate measurements of all PMTs in one module.
Definition: JDAQSummaryFrame.hh:320
KM3NETDAQ::JDAQRate::JRate_t
unsigned char JRate_t
Definition: JDAQSummaryFrame.hh:42
KM3NETDAQ::JDAQRate::getFactor
static const double getFactor()
Get conversion factor.
Definition: JDAQSummaryFrame.hh:270
KM3NETDAQ::JDAQRate::getRate
static double getRate(const JRate_t value)
Get count rate.
Definition: JDAQSummaryFrame.hh:103
KM3NETDAQ::JDAQRate::getValue
JRate_t getValue() const
Get value.
Definition: JDAQSummaryFrame.hh:181
KM3NETDAQ::operator!=
bool operator!=(const JDAQChronometer &first, const JDAQChronometer &second)
Not-equal operator for DAQ chronometers.
Definition: JDAQChronometer.hh:303
KM3NETDAQ::JDAQSummaryFrame::JDAQSummaryFrame
JDAQSummaryFrame(const JDAQSuperFrame &input)
Constructor.
Definition: JDAQSummaryFrame.hh:358
JLANG::JBinaryInput::read
virtual int read(char *buffer, const int length)=0
Read byte array.
JIO::JWriter
Interface for binary output.
Definition: JSerialisable.hh:130
KM3NETDAQ::JDAQHit::JPMT_t
unsigned char JPMT_t
PMT channel in FPGA.
Definition: JDAQHit.hh:44
KM3NETDAQ::JDAQRate::JDAQRate
JDAQRate()
Default constructor.
Definition: JDAQSummaryFrame.hh:171
KM3NETDAQ::JDAQModuleIdentifier
Module identifier.
Definition: JDAQModuleIdentifier.hh:24
KM3NETDAQ::JDAQRate
Data storage class for rate measurement of one PMT.
Definition: JDAQSummaryFrame.hh:36
KM3NETDAQ::JDAQFrameStatus::testFIFOStatus
bool testFIFOStatus() const
Test FIFO status.
Definition: JDAQFrameStatus.hh:246
KM3NETDAQ::JDAQRate::setValue
void setValue(const int numberOfHits, const double frameTime_ns)
Set value.
Definition: JDAQSummaryFrame.hh:193
KM3NETDAQ::JDAQException
General exception.
Definition: JDAQException.hh:18
KM3NETDAQ::JDAQFrameStatus::getInstance
static const JDAQFrameStatus & getInstance()
Get reference to unique instance of this class object.
Definition: JDAQFrameStatus.hh:66
KM3NETDAQ::operator==
bool operator==(const JDAQChronometer &first, const JDAQChronometer &second)
Equal operator for DAQ chronometers.
Definition: JDAQChronometer.hh:286
KM3NETDAQ::JDAQRate::getValue
static JRate_t getValue(const int numberOfHits, const double frameTime_ns)
Get value.
Definition: JDAQSummaryFrame.hh:74
JDAQFrameStatus.hh
KM3NETDAQ::JDAQSummaryFrame::operator<<
friend JWriter & operator<<(JWriter &out, const JDAQSummaryFrame &summary)
Write DAQ summary frame to output.
Definition: JDAQSummaryFrame.hh:509
KM3NETDAQ::JDAQHit::JTDC_t
unsigned int JTDC_t
leading edge [ns]
Definition: JDAQHit.hh:45
KM3NETDAQ::JDAQSummaryFrame::sizeOf
static int sizeOf()
Get size of object.
Definition: JDAQSummaryFrame.hh:525
std
Definition: jaanetDictionary.h:36
JDAQSuperFrame.hh
KM3NETDAQ
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
KM3NETDAQ::JDAQSuperFrame
Data frame of one optical module.
Definition: JDAQSuperFrame.hh:27
KM3NETDAQ::JDAQFrameStatus::sizeOf
static int sizeOf()
Get size of object.
Definition: JDAQFrameStatus.hh:371
KM3NETDAQ::JDAQRate::get_rate
static double get_rate(const double value)
Get count rate.
Definition: JDAQSummaryFrame.hh:282
KM3NETDAQ::JDAQRate::setValue
void setValue(const double rate_Hz)
Set value.
Definition: JDAQSummaryFrame.hh:204
JDAQModuleIdentifier.hh
KM3NETDAQ::JDAQRate::getRate
double getRate() const
Get count rate.
Definition: JDAQSummaryFrame.hh:215
KM3NETDAQ::JDAQFrame::begin
const_iterator begin() const
Definition: JDAQFrame.hh:139
KM3NETDAQ::JDAQRate::getMaximalRate
static double getMaximalRate()
Get maximal rate (above this, value is set to maximum)
Definition: JDAQSummaryFrame.hh:61
KM3NETDAQ::JDAQFrameStatus::getDAQFrameStatus
const JDAQFrameStatus & getDAQFrameStatus() const
Get DAQ frame status.
Definition: JDAQFrameStatus.hh:81
JDAQException.hh
KM3NETDAQ::JDAQSummaryFrame::operator[]
const JDAQRate & operator[](const int tdc) const
Get DAQ rate of given PMT.
Definition: JDAQSummaryFrame.hh:410
KM3NETDAQ::JDAQSummaryFrame::setRate
void setRate(const int tdc, const double rate_Hz)
Set count rate.
Definition: JDAQSummaryFrame.hh:478
KM3NETDAQ::JDAQSummaryFrame::JRate_t
JDAQRate::JRate_t JRate_t
Definition: JDAQSummaryFrame.hh:326
KM3NETDAQ::JDAQRate::mul
JDAQRate & mul(const double factor)
Scale rate.
Definition: JDAQSummaryFrame.hh:238