Jpp  18.6.0-rc.1
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 
7 
9 #include "JDetector/JModule.hh"
10 #include "JPhysics/JConstants.hh"
12 #include "Jeep/JStatus.hh"
13 
14 
15 /**
16  * \author mdejong
17  */
18 
19 namespace JTRIGGER {}
20 namespace JPP { using namespace JTRIGGER; }
21 
22 /**
23  * Trigger algorithms, support classes and auxiliary methods.
24  */
25 namespace JTRIGGER {
26 
30  using JDETECTOR::JModule;
31  using JEEP::JStatus;
32 
33 
34  /**
35  * Get time range of snapshot.
36  *
37  * \param parameters trigger parameters
38  * \return time range [ns]
39  */
41  {
42  return JTimeRange(-parameters.TMaxEvent_ns,
43  +parameters.TMaxEvent_ns);
44  }
45 
46  /**
47  * Get time range of snapshot.
48  *
49  * \param parameters trigger parameters
50  * \return time range [ns]
51  */
53  {
54  using namespace JPP;
55 
56  return JTimeRange(0.0, parameters.DMax_m * getIndexOfRefraction() * getInverseSpeedOfLight());
57  }
58 
59 
60  /**
61  * Test status of DAQ.
62  *
63  * The DAQ test passes if the assembly of UDP packets is complete.\n
64  * The test can be bypassed using the PMT control status.
65  *
66  * \param frame data frame status
67  * \param status PMT control status
68  * \return true if test passes; else false
69  */
70  inline bool getDAQStatus(const JDAQFrameStatus& frame, const JStatus& status)
71  {
72  return ((status.has(UDP_COUNTER_DISABLE) || (frame.getUDPNumberOfReceivedPackets() == frame.getUDPMaximalSequenceNumber() + 1)) &&
73  (status.has(UDP_TRAILER_DISABLE) || (frame.hasUDPTrailer())));
74  }
75 
76 
77  /**
78  * Test status of DAQ.
79  *
80  * The DAQ test passes if the assembly of UDP packets is complete.\n
81  * The test can be bypassed using the PMT control status.
82  *
83  * \param frame data frame status
84  * \param module module
85  * \param pmt PMT number
86  * \return true if test passes; else false
87  */
88  inline bool getDAQStatus(const JDAQFrameStatus& frame, const JModule& module, const int pmt)
89  {
90  return getDAQStatus(frame, module.getPMT(pmt));
91  }
92 
93 
94  /**
95  * Test status of PMT.
96  *
97  * The PMT test passes if it is not disabled.
98  *
99  * \param status PMT control status
100  * \return true if test passes; else false
101  */
102  inline bool getPMTStatus(const JStatus& status)
103  {
104  return !status.has(PMT_DISABLE);
105  }
106 
107 
108  /**
109  * Test status of PMT.
110  *
111  * The PMT test passes if it is not disabled and no high-rate veto or FIFO (almost) full.\n
112  * The test can be bypassed using the PMT control status.
113  *
114  * \param frame data frame
115  * \param status PMT control status
116  * \param pmt PMT number
117  * \return true if test passes; else false
118  */
119  inline bool getPMTStatus(const JDAQFrameStatus& frame, const JStatus& status, const int pmt)
120  {
121  return ((status.has(HIGH_RATE_VETO_DISABLE) || !frame.testHighRateVeto(pmt)) &&
122  (status.has(FIFO_FULL_DISABLE) || !frame.testFIFOStatus (pmt)) &&
123  (getPMTStatus(status)));
124  }
125 
126 
127  /**
128  * Test status of PMT.
129  *
130  * The PMT test passes if it is not disabled and no high-rate veto or FIFO (almost) full.\n
131  * The test can be bypassed using the PMT control status.
132  *
133  * \param frame data frame
134  * \param module module
135  * \param pmt PMT number
136  * \return true if test passes; else false
137  */
138  inline bool getPMTStatus(const JDAQFrameStatus& frame, const JModule& module, const int pmt)
139  {
140  return getPMTStatus(frame, module.getPMT(pmt), pmt);
141  }
142 
143 
144  /**
145  * Get corrected rate of PMT.
146  *
147  * The measured rate is corrected for the possible loss of UDP packets.
148  *
149  * \param frame data frame
150  * \param pmt PMT number
151  * \param factor scaling factor
152  * \return rate x scaling factor [Hz]
153  */
154  inline double getRate(const JDAQSummaryFrame& frame, const int pmt, const double factor = 1.0)
155  {
156  double rate_Hz = frame.getRate(pmt, factor);
157 
158  // correct measured rate for UDP packet loss
159 
160  const int n1 = frame.getUDPNumberOfReceivedPackets();
161  const int n2 = frame.getUDPMaximalSequenceNumber ();
162 
163  if (n1 < n2 + 1) {
164  rate_Hz *= (double) (n2 + 1) / (double) n1;
165  }
166 
167  return rate_Hz;
168  }
169 }
170 
171 #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:67
bool hasUDPTrailer() const
Get UDP trailer status.
double getIndexOfRefraction()
Get average index of refraction of water corresponding to group velocity.
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
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.
bool has(const int bit) const
Test PMT status.
Definition: JStatus.hh:120
Data storage class for rate measurements of all PMTs in one module.
Auxiliary class for handling status.
Definition: JStatus.hh:37
static const int PMT_DISABLE
KM3NeT Data Definitions v3.3.0-2-g5cc95cf 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:172
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 getPMTStatus(const JStatus &status)
Test status of PMT.
JTOOLS::JRange< double > JTimeRange
Type definition for time range (unit [ns]).
const double getInverseSpeedOfLight()
Get inverse speed of light.
bool getDAQStatus(const JDAQFrameStatus &frame, const JStatus &status)
Test status of DAQ.
JTOOLS::JRange< double > JTimeRange
Type definition for time range (unit [s]).
Data structure for 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