Jpp  15.0.1-rc.2-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
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  friend size_t getSizeof<JDAQSummaryFrame>();
330  friend JWriter& operator<<(JWriter&, const JDAQSummaryFrame&);
331 
332  /**
333  * Default constructor.
334  */
338  {}
339 
340 
341  /**
342  * Constructor.
343  *
344  * \param id module identifier
345  */
349  {}
350 
351 
352  /**
353  * Constructor.
354  *
355  * Note that normally the rate is set to the number of hits per unit frame time
356  * but if either the high-rate veto or FIFO (almost) full bit is on,
357  * the rate is set to the number of hits divided by the time of the last hit.
358  *
359  * \param input super frame
360  */
364  {
365  using namespace std;
366 
367  typedef JDAQHit::JPMT_t JPMT_t;
368  typedef JDAQHit::JTDC_t JTDC_t;
369 
370  vector<int> counter(numeric_limits<JPMT_t>::max(), 0);
371 
372  int n = input.size();
373 
374  for (JDAQSuperFrame::const_iterator i = input.begin(); n != 0; --n, ++i) {
375  ++counter[i->getPMT()];
376  }
377 
378  for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
379  data[i].setValue(counter[i], getFrameTime());
380  }
381 
382  if (input.testHighRateVeto() || input.testFIFOStatus()) {
383 
384  // determine last hit for each PMT
385 
386  vector<JTDC_t> limit(numeric_limits<JPMT_t>::max(), 0);
387 
388  int n = input.size();
389 
390  for (JDAQSuperFrame::const_iterator i = input.begin(); n != 0; --n, ++i) {
391  if (i->getT() > limit[i->getPMT()]) {
392  limit[i->getPMT()] = i->getT();
393  }
394  }
395 
396  for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
397  if (input.testHighRateVeto(i) || input.testFIFOStatus(i)) {
398  if (limit[i] != 0) {
399  data[i].setValue((double) counter[i] * 1.0e9 / (double) limit[i]);
400  }
401  }
402  }
403  }
404  }
405 
406 
407  /**
408  * Get DAQ rate of given PMT.
409  *
410  * \param tdc TDC
411  * \return JDAQRate
412  */
413  const JDAQRate& operator[](const int tdc) const
414  {
415  if (tdc >= 0 && tdc < NUMBER_OF_PMTS)
416  return data[tdc];
417  else
418  throw JDAQException("TDC out of range.");
419  }
420 
421 
422  /**
423  * Get DAQ rate of given PMT.
424  *
425  * \param tdc TDC
426  * \return JDAQRate
427  */
428  JDAQRate& operator[](const int tdc)
429  {
430  if (tdc >= 0 && tdc < NUMBER_OF_PMTS)
431  return data[tdc];
432  else
433  throw JDAQException("TDC out of range.");
434  }
435 
436 
437  /**
438  * Get value.
439  *
440  * \param tdc TDC
441  * \return value
442  */
443  double getValue(const int tdc) const
444  {
445  return data[tdc].getValue();
446  }
447 
448 
449  /**
450  * Get count rate.
451  *
452  * \param tdc TDC
453  * \param factor scaling factor
454  * \return rate x scaling factor [Hz]
455  */
456  double getRate(const int tdc, const double factor = 1.0) const
457  {
458  return data[tdc].getRate() * factor;
459  }
460 
461 
462  /**
463  * Get weight.
464  *
465  * \param tdc TDC
466  * \param factor scaling factor
467  * \return weight / scaling factor [Hz^-1]
468  */
469  double getWeight(const int tdc, const double factor = 1.0) const
470  {
471  return data[tdc].getWeight() / factor;
472  }
473 
474 
475  /**
476  * Set count rate.
477  *
478  * \param tdc TDC
479  * \param rate_Hz rate [Hz]
480  */
481  void setRate(const int tdc, const double rate_Hz)
482  {
483  return data[tdc].setValue(rate_Hz);
484  }
485 
486 
487  static int ROOT_IO_VERSION; //!< Streamer version of JDAQSummaryslice as obtained from ROOT file.
488 
489 
491 
492 
493  protected:
494 
496  };
497 
498 
499  /**
500  * Equal operator for DAQ summary frames.
501  *
502  * \param first summary frame
503  * \param second summary frame
504  * \result true if first summary frame equal to second; else false
505  */
506  inline bool operator==(const JDAQSummaryFrame& first,
507  const JDAQSummaryFrame& second)
508  {
509  if (first.getModuleIdentifier() == second.getModuleIdentifier() &&
510  first.getDAQFrameStatus() == second.getDAQFrameStatus()) {
511 
512  for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
513  if (first[i] != second[i]) {
514  return false;
515  }
516  }
517 
518  return true;
519 
520  } else {
521 
522  return false;
523  }
524  }
525 
526 
527  /**
528  * Not-equal operator for DAQ summary frames.
529  *
530  * \param first summary frame
531  * \param second summary frame
532  * \result true if first summary frame not equal to second; else false
533  */
534  inline bool operator!=(const JDAQSummaryFrame& first,
535  const JDAQSummaryFrame& second)
536  {
537  return !(first == second);
538  }
539 }
540 
541 #endif
static double get_rate(const double value)
Get count rate.
bool operator==(const JDAQChronometer &first, const JDAQChronometer &second)
Equal operator for DAQ chronometers.
JDAQSummaryFrame()
Default constructor.
JDAQRate & mul(const double factor)
Scale rate.
Interface for binary output.
JDAQSummaryFrame(const JDAQModuleIdentifier &id)
Constructor.
int getModuleID() const
Get module identifier.
double getRate(const int tdc, const double factor=1.0) const
Get count rate.
JDAQRate data[NUMBER_OF_PMTS]
static JRate_t getValue(const double rate_Hz)
Get value.
static const JDAQFrameStatus & getInstance()
Get reference to unique instance of this class object.
const JDAQRate & operator[](const int tdc) const
Get DAQ rate of given PMT.
JDAQRate & operator[](const int tdc)
Get DAQ rate of given PMT.
Auxiliary class for TDC constraints.
Definition: JTDC_t.hh:37
static double getMinimalRate()
Get minimal rate (below this, value is set to zero)
static int getN()
Get number of bins.
static int ROOT_IO_VERSION
Streamer version of JDAQSummaryslice as obtained from ROOT file.
unsigned int JTDC_t
leading edge [ns]
Definition: JDAQHit.hh:39
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable STRING $argv[2] set_array QUANTILES set_variable FORMULA *[0] exp(-0.5 *(x-[1])*(x-[1])/([2]*[2]))" set_variable MODULE `getModule -a $DETECTOR -L "$STRING 0"` typeset -Z 4 STRING JOpera1D -f hydrophone.root
JDAQSummaryFrame(const JDAQSuperFrame &input)
Constructor.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
static double getRate(const JRate_t value)
Get count rate.
void setValue(const double rate_Hz)
Set value.
const int n
Definition: JPolint.hh:660
JDAQRate & div(const double factor)
Scale rate.
static double getWeight(const JRate_t value)
Get weight.
static const double * getData(const double factor=1.0)
Get abscissa values.
ClassDefNV(JDAQSummaryFrame, 2)
Hit data structure.
Definition: JDAQHit.hh:34
const_iterator begin() const
Definition: JDAQFrame.hh:136
JRate_t getValue() const
Get value.
double getFrameTime()
Get frame time duration.
Definition: JDAQClock.hh:162
Data storage class for rate measurements of all PMTs in one module.
friend JReader & operator>>(JReader &, JDAQSummaryFrame &)
Read DAQ summary frame from input.
double getWeight() const
Get weight.
size_t getSizeof< JDAQSummaryFrame >()
Get size of type.
Interface for binary input.
double getRate() const
Get count rate.
static double getMaximalRate()
Get maximal rate (above this, value is set to maximum)
bool testHighRateVeto() const
Test high-rate veto status.
Data storage class for rate measurement of one PMT.
JDAQRate()
Default constructor.
General exception.
void setValue(const int numberOfHits, const double frameTime_ns)
Set value.
friend JWriter & operator<<(JWriter &, const JDAQSummaryFrame &)
Write DAQ summary frame to output.
static JRate_t getValue(const int numberOfHits, const double frameTime_ns)
Get value.
static const double getFactor()
Get conversion factor.
const JDAQModuleIdentifier & getModuleIdentifier() const
Get Module identifier.
void setRate(const int tdc, const double rate_Hz)
Set count rate.
KM3NeT DAQ constants, bit handling, etc.
bool operator!=(const JDAQChronometer &first, const JDAQChronometer &second)
Not-equal operator for DAQ chronometers.
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
const JDAQFrameStatus & getDAQFrameStatus() const
Get DAQ frame status.
int size() const
Definition: JDAQFrame.hh:154
Data frame of one optical module.
unsigned char JPMT_t
PMT channel in FPGA.
Definition: JDAQHit.hh:38
double getValue(const int tdc) const
Get value.
double getWeight(const int tdc, const double factor=1.0) const
Get weight.
bool testFIFOStatus() const
Test FIFO status.