Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTriggerToolkit.hh
Go to the documentation of this file.
1 #ifndef __JTRIGGER__JTRIGGERTOOLKIT__
2 #define __JTRIGGER__JTRIGGERTOOLKIT__
3 
6 
8 #include "JDetector/JStatus.hh"
9 #include "JDetector/JModule.hh"
10 #include "JPhysics/JConstants.hh"
12 
13 
14 /**
15  * \author mdejong
16  */
17 
18 namespace JTRIGGER {}
19 namespace JPP { using namespace JTRIGGER; }
20 
21 /**
22  * Trigger algorithms, support classes and auxiliary methods.
23  */
24 namespace JTRIGGER {
25 
29  using JDETECTOR::JStatus;
30  using JDETECTOR::JModule;
31 
32 
33  /**
34  * Get time range of snapshot.
35  *
36  * \param parameters trigger parameters
37  * \return time range [ns]
38  */
40  {
41  return JTimeRange(-parameters.TMaxEvent_ns,
42  +parameters.TMaxEvent_ns);
43  }
44 
45  /**
46  * Get time range of snapshot.
47  *
48  * \param parameters trigger parameters
49  * \return time range [ns]
50  */
52  {
53  using namespace JPP;
54 
55  return JTimeRange(0.0, parameters.DMax_m * getIndexOfRefraction() * getInverseSpeedOfLight());
56  }
57 
58 
59  /**
60  * Test status of DAQ.
61  *
62  * The DAQ test passes if the assembly of UDP packets is complete.\n
63  * The test can be bypassed using the PMT control status.
64  *
65  * \param frame data frame status
66  * \param status PMT control status
67  * \return true if test passes; else false
68  */
69  inline bool getDAQStatus(const JDAQFrameStatus& frame, const JStatus& status)
70  {
71  return ((status.has(UDP_COUNTER_DISABLE) || (frame.getUDPNumberOfReceivedPackets() == frame.getUDPMaximalSequenceNumber() + 1)) &&
72  (status.has(UDP_TRAILER_DISABLE) || (frame.hasUDPTrailer())));
73  }
74 
75 
76  /**
77  * Test status of DAQ.
78  *
79  * The DAQ test passes if the assembly of UDP packets is complete.\n
80  * The test can be bypassed using the PMT control status.
81  *
82  * \param frame data frame status
83  * \param module module
84  * \param pmt PMT number
85  * \return true if test passes; else false
86  */
87  inline bool getDAQStatus(const JDAQFrameStatus& frame, const JModule& module, const int pmt)
88  {
89  return getDAQStatus(frame, module.getPMT(pmt));
90  }
91 
92 
93  /**
94  * Test status of PMT.
95  *
96  * The PMT test passes if it is not disabled.
97  *
98  * \param status PMT control status
99  * \return true if test passes; else false
100  */
101  inline bool getPMTStatus(const JStatus& status)
102  {
103  return !status.has(PMT_DISABLE);
104  }
105 
106 
107  /**
108  * Test status of PMT.
109  *
110  * The PMT test passes if it is not disabled and no high-rate veto or FIFO (almost) full.\n
111  * The test can be bypassed using the PMT control status.
112  *
113  * \param frame data frame
114  * \param status PMT control status
115  * \param pmt PMT number
116  * \return true if test passes; else false
117  */
118  inline bool getPMTStatus(const JDAQFrameStatus& frame, const JStatus& status, const int pmt)
119  {
120  return ((status.has(HIGH_RATE_VETO_DISABLE) || !frame.testHighRateVeto(pmt)) &&
121  (status.has(FIFO_FULL_DISABLE) || !frame.testFIFOStatus (pmt)) &&
122  (getPMTStatus(status)));
123  }
124 
125 
126  /**
127  * Test status of PMT.
128  *
129  * The PMT test passes if it is not disabled and no high-rate veto or FIFO (almost) full.\n
130  * The test can be bypassed using the PMT control status.
131  *
132  * \param frame data frame
133  * \param module module
134  * \param pmt PMT number
135  * \return true if test passes; else false
136  */
137  inline bool getPMTStatus(const JDAQFrameStatus& frame, const JModule& module, const int pmt)
138  {
139  return getPMTStatus(frame, module.getPMT(pmt), pmt);
140  }
141 
142 
143  /**
144  * Get corrected rate of PMT.
145  *
146  * The measured rate is corrected for the possible loss of UDP packets.
147  *
148  * \param frame data frame
149  * \param pmt PMT number
150  * \param factor scaling factor
151  * \return rate x scaling factor [Hz]
152  */
153  inline double getRate(const JDAQSummaryFrame& frame, const int pmt, const double factor = 1.0)
154  {
155  double rate_Hz = frame.getRate(pmt, factor);
156 
157  // correct measured rate for UDP packet loss
158 
159  const int n1 = frame.getUDPNumberOfReceivedPackets();
160  const int n2 = frame.getUDPMaximalSequenceNumber ();
161 
162  if (n1 < n2 + 1) {
163  rate_Hz *= (double) (n2 + 1) / (double) n1;
164  }
165 
166  return rate_Hz;
167  }
168 }
169 
170 #endif
Data structure for all trigger parameters.
double getRate(const int tdc, const double factor=1.0) const
Get count rate.
double DMax_m
maximal distance between PMTs [m]
Definition: JTriggerNB_t.hh:87
Data structure for a composite optical module.
Definition: JModule.hh:57
bool hasUDPTrailer() const
Get UDP trailer status.
double getIndexOfRefraction()
Get average index of refraction of water corresponding to group velocity.
JTOOLS::JRange< double > JTimeRange
Type definition for time range (unit [ns]).
static const int HIGH_RATE_VETO_DISABLE
Enable (disable) use of high-rate veto test if this status bit is 0 (1);.
Definition: pmt_status.hh:13
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
Auxiliary class for controlling PMT status.
Definition: JStatus.hh:42
int getUDPNumberOfReceivedPackets() const
Get number of received UDP packets.
JTimeRange getTimeRange(const Evt &event)
Get time range (i.e. time between earliest and latest hit) of Monte Carlo event.
double TMaxEvent_ns
maximal time before and after event for snapshot
int getUDPMaximalSequenceNumber() const
Get maximal sequence number of UDP packet.
double getRate(const JDAQSummaryFrame &frame, const int pmt, const double factor=1.0)
Get corrected rate of PMT.
Data storage class for rate measurements of all PMTs in one module.
static const int PMT_DISABLE
KM3NeT Data Definitions v2.0.0-15-g59d2e2b https://git.km3net.de/common/km3net-dataformat.
Definition: pmt_status.hh:12
static const int UDP_TRAILER_DISABLE
Enable (disable) use of UDP packet trailer test if this status bit is 0 (1);.
Definition: pmt_status.hh:16
Physics constants.
const JPMT & getPMT(const int index) const
Get PMT.
Definition: JModule.hh:211
static const int FIFO_FULL_DISABLE
Enable (disable) use of FIFO (almost) full test if this status bit is 0 (1);.
Definition: pmt_status.hh:14
bool testHighRateVeto() const
Test high-rate veto status.
bool has(const int bit) const
Test PMT status.
Definition: JStatus.hh:113
bool getPMTStatus(const JStatus &status)
Test status of PMT.
const double getInverseSpeedOfLight()
Get inverse speed of light.
bool getDAQStatus(const JDAQFrameStatus &frame, const JStatus &status)
Test status of DAQ.
Data structure for a composite optical module.
bool testFIFOStatus() const
Test FIFO status.
static const int UDP_COUNTER_DISABLE
Enable (disable) use of UDP packet counter test if this status bit is 0 (1);.
Definition: pmt_status.hh:15