Jpp test-rotations-old-533-g2bdbdb559
the software that should make you happy
Loading...
Searching...
No Matches
JTriggerToolkit.hh
Go to the documentation of this file.
1#ifndef __JTRIGGER__JTRIGGERTOOLKIT__
2#define __JTRIGGER__JTRIGGERTOOLKIT__
3
7
12#include "Jeep/JStatus.hh"
14
15
16/**
17 * \author mdejong
18 */
19
20namespace JTRIGGER {}
21namespace JPP { using namespace JTRIGGER; }
22
23/**
24 * Trigger algorithms, support classes and auxiliary methods.
25 */
26namespace JTRIGGER {
27
32 using JEEP::JStatus;
33
34
35 /**
36 * Get time range of snapshot.
37 *
38 * \param parameters trigger parameters
39 * \return time range [ns]
40 */
41 inline JTimeRange getTimeRange(const JTriggerParameters& parameters)
42 {
43 return JTimeRange(-parameters.TMaxEvent_ns,
44 +parameters.TMaxEvent_ns);
45 }
46
47 /**
48 * Get time range of snapshot.
49 *
50 * \param parameters trigger parameters
51 * \return time range [ns]
52 */
54 {
55 using namespace JPP;
56
57 return JTimeRange(0.0, parameters.DMax_m * getIndexOfRefraction() * getInverseSpeedOfLight());
58 }
59
60
61 /**
62 * Test status of DAQ.
63 *
64 * The DAQ test passes if the assembly of UDP packets is complete.\n
65 * The test can be bypassed using the PMT control status.
66 *
67 * \param frame data frame status
68 * \param status PMT control status
69 * \return true if test passes; else false
70 */
71 inline bool getDAQStatus(const JDAQFrameStatus& frame, const JStatus& status)
72 {
73 return ((status.has(UDP_COUNTER_DISABLE) || (frame.getUDPNumberOfReceivedPackets() == frame.getUDPMaximalSequenceNumber() + 1)) &&
74 (status.has(UDP_TRAILER_DISABLE) || (frame.hasUDPTrailer())));
75 }
76
77
78 /**
79 * Test status of DAQ.
80 *
81 * The DAQ test passes if the assembly of UDP packets is complete.\n
82 * The test can be bypassed using the PMT control status.
83 *
84 * \param frame data frame status
85 * \param module module
86 * \param pmt PMT number
87 * \return true if test passes; else false
88 */
89 inline bool getDAQStatus(const JDAQFrameStatus& frame, const JModule& module, const int pmt)
90 {
91 return getDAQStatus(frame, module.getPMT(pmt));
92 }
93
94
95 /**
96 * Test status of PMT.
97 *
98 * The PMT test passes if it is not disabled.
99 *
100 * \param status PMT control status
101 * \return true if test passes; else false
102 */
103 inline bool getPMTStatus(const JStatus& status)
104 {
105 return !status.has(PMT_DISABLE);
106 }
107
108
109 /**
110 * Test status of PMT.
111 *
112 * The PMT test passes if it is not disabled and no high-rate veto or FIFO (almost) full.\n
113 * The test can be bypassed using the PMT control status.
114 *
115 * \param frame data frame
116 * \param status PMT control status
117 * \param pmt PMT number
118 * \return true if test passes; else false
119 */
120 inline bool getPMTStatus(const JDAQFrameStatus& frame, const JStatus& status, const int pmt)
121 {
122 return ((status.has(HIGH_RATE_VETO_DISABLE) || !frame.testHighRateVeto(pmt)) &&
123 (status.has(FIFO_FULL_DISABLE) || !frame.testFIFOStatus (pmt)) &&
124 (getPMTStatus(status)));
125 }
126
127
128 /**
129 * Test status of PMT.
130 *
131 * The PMT test passes if it is not disabled and no high-rate veto or FIFO (almost) full.\n
132 * The test can be bypassed using the PMT control status.
133 *
134 * \param frame data frame
135 * \param module module
136 * \param pmt PMT number
137 * \return true if test passes; else false
138 */
139 inline bool getPMTStatus(const JDAQFrameStatus& frame, const JModule& module, const int pmt)
140 {
141 return getPMTStatus(frame, module.getPMT(pmt), pmt);
142 }
143
144
145 /**
146 * Get corrected rate of PMT.
147 *
148 * The measured rate is corrected for the possible loss of UDP packets.
149 *
150 * \param frame data frame
151 * \param pmt PMT number
152 * \param factor scaling factor
153 * \return rate x scaling factor [Hz]
154 */
155 inline double getRate(const JDAQSummaryFrame& frame, const int pmt, const double factor = 1.0)
156 {
157 using namespace JMATH;
158
159 double rate_Hz = frame.getRate(pmt, factor);
160
161 // correct measured rate for UDP packet loss
162
163 const int n1 = frame.getUDPNumberOfReceivedPackets();
164 const int n2 = frame.getUDPMaximalSequenceNumber ();
165
166 if (n1 < n2 + 1) {
167 rate_Hz *= (double) getBayesianMedian(n2 , n1, 0) / (double) n1;
168 }
169
170 return rate_Hz;
171 }
172}
173
174#endif
Auxiliary methods for mathematics.
Data structure for optical module.
Physics constants.
Data structure for a composite optical module.
Definition JModule.hh:75
const JPMT & getPMT(const int index) const
Get PMT.
Definition JModule.hh:172
double DMax_m
maximal distance between PMTs [m]
Data structure for all trigger parameters.
double TMaxEvent_ns
maximal time before and after event for snapshot
bool testFIFOStatus() const
Test FIFO status.
int getUDPNumberOfReceivedPackets() const
Get number of received UDP packets.
bool hasUDPTrailer() const
Get UDP trailer status.
bool testHighRateVeto() const
Test high-rate veto status.
int getUDPMaximalSequenceNumber() const
Get maximal sequence number of UDP packet.
Data storage class for rate measurements of all PMTs in one module.
double getRate(const int tdc, const double factor=1.0) const
Get count rate.
JTOOLS::JRange< double > JTimeRange
Type definition for time range (unit [ns]).
size_t getBayesianMedian(const size_t m, const size_t k)
Get estimate of maximum number.
const double getInverseSpeedOfLight()
Get inverse speed of light.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for triggering.
bool getDAQStatus(const JDAQFrameStatus &frame, const JStatus &status)
Test status of DAQ.
double getRate(const JDAQSummaryFrame &frame, const int pmt, const double factor=1.0)
Get corrected rate of PMT.
JTimeRange getTimeRange(const JEvent &event)
Get time range (i.e. earlist and latest hit time) of triggered event.
bool getPMTStatus(const JStatus &status)
Test status of PMT.
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
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
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
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
static const int PMT_DISABLE
KM3NeT Data Definitions v3.6.1-21-g1b37f88 https://git.km3net.de/common/km3net-dataformat.
Definition pmt_status.hh:12
Auxiliary class for handling status.
Definition JStatus.hh:39
bool has(const int bit) const
Test PMT status.
Definition JStatus.hh:120