All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExtraTriggerInfo.h
Go to the documentation of this file.
1 /**
2  * @file sbnobj/Common/Trigger/ExtraTriggerInfo.h
3  * @brief Data product holding additional trigger information.
4  * @authors Gianluca Petrillo (petrillo@slac.stanford.edu),
5  * Jacob Zettlemoyer (jzettle@fnal.gov>)
6  * @date June 18, 2021
7  * @see sbnobj/Common/Trigger/ExtraTriggerInfo.cxx
8  */
9 
10 #ifndef SBNOBJ_COMMON_TRIGGER_EXTRATRIGGERINFO_H
11 #define SBNOBJ_COMMON_TRIGGER_EXTRATRIGGERINFO_H
12 
13 
14 // SBN libraries
16 
17 // C/C++ standard libraries
18 #include <array>
19 #include <iosfwd> // std::ostream
20 #include <limits> // std::numeric_limits<>
21 #include <cstdint> // std::uint64_t
22 
23 
24 // -----------------------------------------------------------------------------
25 namespace sbn { struct ExtraTriggerInfo; }
26 /**
27  * @brief Additional information on trigger.
28  *
29  * This data structure holds information from the trigger that has no place in
30  * the standard LArSoft data products (`raw::Trigger` and
31  * `raw::ExternalTrigger`).
32  *
33  * Absolute times are counted since The Epoch and are in UTC time.
34  *
35  * Some "historical" information is available:
36  * * count of gates and triggers from the start of the run;
37  * * count of gates and triggers from the previous trigger;
38  * * timestamps of previous gates and triggers.
39  *
40  * Some historical information is available for different gate selections:
41  * * including only triggers and gates the same source as this trigger source;
42  * * including triggers and gates from any source (tagged as "any").
43  *
44  */
46 
47  /// Special ID value indicating the absence of an ID.
48  static constexpr unsigned int NoID = std::numeric_limits<unsigned int>::max();
49 
50  /// Special timestamp value indicating the absence of timestamp.
51  static constexpr std::uint64_t NoTimestamp
52  = std::numeric_limits<std::uint64_t>::max();
53 
54  /// Special timestamp correction value indicating an unknown correction.
55  static constexpr std::int64_t UnknownCorrection
56  = std::numeric_limits<std::int64_t>::max();
57 
58 
59  /// Type of this gate (`sbn::triggerSource::NBits` marks this object invalid).
60  sbn::triggerSource sourceType { sbn::triggerSource::NBits };
61 
62  /// Type of this trigger (see `sbn::triggerType`).
63  sbn::triggerType triggerType { sbn::triggerType::NBits };
64 
65  /// Absolute timestamp of the opening of the enable gate [ns]
66  std::uint64_t enableGateTimestamp { NoTimestamp };
67 
68 
69  // --- BEGIN -- Since the beginning of the run -------------------------------
70  /// @name Counters and times since the beginning of the run.
71  /// @{
72 
73  /// Absolute timestamp of this trigger [ns]
74  std::uint64_t triggerTimestamp { NoTimestamp };
75 
76  /// Absolute timestamp of the opening of this beam gate [ns]
77  std::uint64_t beamGateTimestamp { NoTimestamp };
78 
79  /// The identifier of this trigger (usually matching the event number).
80  unsigned int triggerID { NoID };
81 
82  /// Incremental counter of gates from any source opened from start of the run.
83  unsigned int gateID { 0 };
84 
85  /// Incremental counter of triggers from this source from start of the run.
86  unsigned int triggerCount { 0 };
87 
88  /// Incremental counter of gates from this source opened from start of the run.
89  unsigned int gateCount { 0 };
90 
91  /// @}
92  // --- END ---- Since the beginning of the run -------------------------------
93 
94 
95 
96  // --- BEGIN -- Since the previous trigger from this same source -------------
97  /// @name Counters since the previous trigger from this same source
98  /// @{
99 
100  /// Gates from this source since the previous trigger also of this source
101  /// (minimum is `1`: the current gate).
102  unsigned int gateCountFromPreviousTrigger { 0 };
103 
104  /// Triggers from any source since the previous trigger also of this source
105  /// (minimum is `1`: the current trigger).
107 
108  /// Gates from any source since the previous trigger also of this source
109  /// (minimum is `1`: the current trigger).
111 
112  /// @}
113  // --- END ---- Since the previous trigger from this same source -------------
114 
115 
116  // --- BEGIN -- Since the previous trigger from any source -------------------
117  /// @name Counters since the previous trigger from any source
118  /// @{
119 
120  /// Type of the previous trigger.
122  { sbn::triggerSource::Unknown };
123 
124  /// Gates from any source since the previous trigger also from any source
125  /// (minimum is `1`: the current gate).
127 
128  /// @}
129  // --- END ---- Since the previous trigger from any source -------------------
130 
131 
132  // --- BEGIN -- Additional timestamps ----------------------------------------
133  /// @name Additional timestamps
134  /// @{
135 
136  // we do not have timestamps of gates not associated to triggers
137 
138  /// Absolute timestamp of the previous trigger from this same source [ns]
140 
141  /// Absolute timestamp of the previous trigger from any source [ns]
143 
144  /// @}
145  // --- END ---- Additional timestamps ----------------------------------------
146 
147 
148  // --- BEGIN -- Decoding information -----------------------------------------
149  /// @name Decoding information
150  /// @{
151 
152  /// Correction added to the White Rabbit time to get the trigger time.
154 
155  /// @}
156  // --- END ---- Decoding information -----------------------------------------
157 
158  // --- BEGIN -- Trigger topology ---------------------------------------------
159  /**
160  * @name Trigger topology
161  *
162  * The information is represented in groups of cryostats and, within each of
163  * them, of PMT "walls", that is groups of PMT lying on the same geometric
164  * plane (in SBN detectors that is behind each anode).
165  *
166  * Currently the information is represented by fixed size arrays, because the
167  * overhead of a variable length container (`std::vector`) is comparable to
168  * the data itself.
169  */
170  /// @{
171 
172  /// Maximum number of cryostats in the detector.
173  static constexpr std::size_t MaxCryostats { 2 };
174 
175  /// Maximum number of PMT "walls" in a cryostat.
176  static constexpr std::size_t MaxWalls { 2 };
177 
178  /// Mnemonic index for the east cryostat.
179  static constexpr std::size_t EastCryostat { 0 };
180 
181  /// Mnemonic index for the west cryostat.
182  static constexpr std::size_t WestCryostat { 1 };
183 
184  /// Mnemonic index for the east PMT wall within a cryostat.
185  static constexpr std::size_t EastPMTwall { 0 };
186 
187  /// Mnemonic index for the west PMT wall within a cryostat.
188  static constexpr std::size_t WestPMTwall { 1 };
189 
190 
191  /// Trigger data pertaining a single cryostat.
192  struct CryostatInfo {
193  /// Count of triggers in this cryostat.
194  unsigned long int triggerCount { 0 };
195 
196  /**
197  * @brief Status of LVDS signals from PMT pairs at the time of the trigger.
198  *
199  * There is one status per PMT wall (index mnemonic constants: `EastPMTwall`
200  * and `WestPMTwall`).
201  *
202  *
203  * ICARUS
204  * -------
205  *
206  * Bits are 48 per wall, 8 pairs from each on 6 PMT readout boards.
207  * For the position of the PMT generating a LVDS channel, refer to the
208  * configuration of the trigger emulation.
209  *
210  * The 48 bits are distributed in the value as follow:
211  * * the south part (lower _z_, lower channel number) is in the first 32-bit
212  * * the north part (upper _z_, higher channel number) is in the last 32-bit
213  *
214  * The 8 most significant bits of each 32-bit half-word are zeroed.
215  * Then the most significant bits match the lowest channel numbers (lower
216  * _z_). Splitting the detector in six regions (of 15 PMT each) so that it
217  * looks, from south to north: `AA|BB|CC|DD|EE|FF`, the bit mask of the six
218  * parts (each with 15 PMT, 8 LVDS channels, 8 bits) looks like:
219  * `00AABBCC'00DDEEFF`.
220  */
221  std::array<std::uint64_t, MaxWalls> LVDSstatus { 0U, 0U };
222 
223  /// Returns whether there is some recorded LVDS activity.
224  constexpr bool hasLVDS() const;
225 
226  }; // CryostatInfo
227 
228 
229  /// Bits for the trigger location (@see `triggerLocation()`).
230  unsigned int triggerLocationBits { 0U };
231  //sbn::triggerLocation triggerLocationBits { sbn::triggerSource::NBits }
232  /// Status of each LVDS channel in each PMT wall at trigger time.
233  std::array<CryostatInfo, MaxCryostats> cryostats;
234 
235  /**
236  * @brief Returns the location of the trigger.
237  *
238  * The returned value is a mask of `sbn::bits::triggerLocation` bits.
239  * To test the state of a bit, it needs to be converted into a mask, e.g.:
240  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
241  * bool onTPCEE
242  * = extraTriggerInfo.triggerLocation() & mask(sbn::triggerLocation::TPCEE);
243  * bool onTPCxE = extraTriggerInfo.triggerLocation()
244  * & mask(sbn::triggerLocation::TPCEE, sbn::triggerLocation::TPCWE);
245  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
246  */
248  { return { triggerLocationBits }; }
249 
250 
251  /// @}
252  // --- END ---- Trigger topology ---------------------------------------------
253 
254 
255 
256  /// Returns whether this object contains any valid information.
257  constexpr bool isValid() const noexcept
258  { return sourceType != sbn::triggerSource::NBits; }
259 
260 
261  /// Returns whether the specified `ID` is valid (i.e. is not `NoID`).
262  static constexpr bool isValidID(unsigned int ID) noexcept
263  { return ID != NoID; }
264 
265  /// Returns whether the timestamp `ts` is valid (i.e. is not `NoTimestamp`).
266  static constexpr bool isValidTimestamp(std::uint64_t ts) noexcept
267  { return ts != NoTimestamp; }
268 
269  /// Returns whether the `count` is valid (i.e. is not `0`).
270  static constexpr bool isValidCount(unsigned int count) noexcept
271  { return count != 0U; }
272 
273 
274 }; // sbn::ExtraTriggerInfo
275 
276 
277 namespace sbn {
278  std::ostream& operator<< (std::ostream& out, ExtraTriggerInfo const& info);
279 }
280 
281 // -----------------------------------------------------------------------------
282 
284  // C++20:
285  // return std::ranges::any_of(LVDSstatus, std::identity{});
286  for (std::uint64_t bits: LVDSstatus) if (bits) return true;
287  return false;
288 } // sbn::ExtraTriggerInfo::CryostatInfo::empty()
289 
290 
291 
292 
293 #endif // SBNOBJ_COMMON_TRIGGER_EXTRATRIGGERINFO_H
Definitions of the trigger bits for SBN.
unsigned int gateID
Incremental counter of gates from any source opened from start of the run.
constexpr bool hasLVDS() const
Returns whether there is some recorded LVDS activity.
static constexpr std::size_t MaxWalls
Maximum number of PMT &quot;walls&quot; in a cryostat.
unsigned int anyTriggerCountFromPreviousTrigger
std::ostream & operator<<(std::ostream &out, sbn::PMTconfiguration const &config)
Prints the configuration into a stream with default verbosity.
unsigned int gateCount
Incremental counter of gates from this source opened from start of the run.
static constexpr std::size_t EastCryostat
Mnemonic index for the east cryostat.
static constexpr std::int64_t UnknownCorrection
Special timestamp correction value indicating an unknown correction.
sbn::bits::triggerLocationMask triggerLocation() const
Returns the location of the trigger.
static constexpr bool isValidID(unsigned int ID) noexcept
Returns whether the specified ID is valid (i.e. is not NoID).
std::array< std::uint64_t, MaxWalls > LVDSstatus
Status of LVDS signals from PMT pairs at the time of the trigger.
std::uint64_t beamGateTimestamp
Absolute timestamp of the opening of this beam gate [ns].
Additional information on trigger.
triggerType
Type representing the type(s) of this trigger.
Definition: BeamBits.h:128
sbn::triggerSource anyPreviousTriggerSourceType
Type of the previous trigger.
static constexpr std::size_t WestPMTwall
Mnemonic index for the west PMT wall within a cryostat.
unsigned int triggerCount
Incremental counter of triggers from this source from start of the run.
unsigned int triggerLocationBits
Bits for the trigger location (.
static constexpr std::size_t WestCryostat
Mnemonic index for the west cryostat.
std::array< CryostatInfo, MaxCryostats > cryostats
Status of each LVDS channel in each PMT wall at trigger time.
std::uint64_t enableGateTimestamp
Absolute timestamp of the opening of the enable gate [ns].
sbn::triggerSource sourceType
Type of this gate (sbn::triggerSource::NBits marks this object invalid).
unsigned int anyGateCountFromPreviousTrigger
constexpr bool isValid() const noexcept
Returns whether this object contains any valid information.
sbn::triggerType triggerType
Type of this trigger (see sbn::triggerType).
static constexpr bool isValidTimestamp(std::uint64_t ts) noexcept
Returns whether the timestamp ts is valid (i.e. is not NoTimestamp).
static constexpr std::size_t MaxCryostats
Maximum number of cryostats in the detector.
static constexpr std::uint64_t NoTimestamp
Special timestamp value indicating the absence of timestamp.
std::uint64_t anyPreviousTriggerTimestamp
Absolute timestamp of the previous trigger from any source [ns].
unsigned int anyGateCountFromAnyPreviousTrigger
triggerSource
Type of beam or beam gate or other trigger source.
Definition: BeamBits.h:97
unsigned int gateCountFromPreviousTrigger
std::size_t count(Cont const &cont)
Trigger data pertaining a single cryostat.
std::uint64_t previousTriggerTimestamp
Absolute timestamp of the previous trigger from this same source [ns].
std::uint64_t triggerTimestamp
Absolute timestamp of this trigger [ns].
unsigned int triggerID
The identifier of this trigger (usually matching the event number).
static constexpr unsigned int NoID
Special ID value indicating the absence of an ID.
static constexpr std::size_t EastPMTwall
Mnemonic index for the east PMT wall within a cryostat.
static constexpr bool isValidCount(unsigned int count) noexcept
Returns whether the count is valid (i.e. is not 0).
unsigned long int triggerCount
Count of triggers in this cryostat.
std::int64_t WRtimeToTriggerTime
Correction added to the White Rabbit time to get the trigger time.