CRTTrigger.h
Go to the documentation of this file.
1 //File: CRTTrigger.h
2 //Brief: A CRT::Trigger stores the activity in a single ProtoDUNE-SP CRT module when the module triggered itself to be read out. CRT modules
3 // trigger a readout when there is activity on a channel that is above some threshold. When a CRT module triggers a readout, all channels'
4 // activity is read out, regardless of ADC counts. A channel with above-baseline(?) activity at the time of readout is represented as a
5 // CRT::Hit stored by the owned CRT::Trigger. So, a CRT::Trigger can only have 0 CRT::Hits if it was default-constructed.
6 //
7 // I don't yet know whether it is possible to recover which hit caused the readout. Based
8 // this preliminary CRT data format on Matt Strait's artdaq-core code for handling the Double Chooz outer veto modules as the ProtoDUNE-SP
9 // Cosmic Ray Tagger: https://github.com/straitm/artdaq_core_demo/blob/crt/artdaq-core-demo/Overlays/CRTFragment.hh
10 //Author: Andrew Olivier aolivier@ur.rochester.edu
11 
12 //Include guards so that this file doesn't interfere with itself when included multiple times
13 #ifndef CRT_TRIGGER_H
14 #define CRT_TRIGGER_H
15 
16 //c++ includes
17 #include <cstdint>
18 #include <vector>
19 #include <limits>
20 
21 namespace CRT
22 {
23  class Hit
24  {
25  public:
26  //Constructor from information in CRT::Fragment plus detector name for LArSoft
27  Hit(uint8_t channel, /*const std::string& detName,*/ uint16_t adc): fChannel(channel), /*fAuxDetname(detName),*/ fADC(adc)
28  {
29  }
30 
31  //Default constructor to make ROOT happy. Set ADC peak to -1 and everything else to largest possible value so that default-constructed
32  //hits are obvious.
33  Hit(): fChannel(std::numeric_limits<decltype(fChannel)>::max()), /*fAuxDetName("NULL"),*/ fADC(std::numeric_limits<decltype(fADC)>::max()) {}
34 
35  //No resources managed by a CRT::Hit, so use default destructor
36  virtual ~Hit() = default;
37 
38  //Public access to stored information
39  inline size_t Channel() const { return fChannel; }
40 
41  //inline std::string AuxDetName() const { return fAuxDetName; }
42 
43  inline short ADC() const { return fADC; }
44 
45  //Check whether this Hit was default-constructed
46  inline bool IsDefault() const { return fADC == std::numeric_limits<decltype(fADC)>::max(); }
47 
48  //Print out to some ostream-like object for debugging
49  template <class STREAM>
50  void dump(STREAM& stream) const
51  {
52  stream << "CRT::Hit Dump:\n"
53  << "Channel: " << fChannel << "\n"
54  //<< "AuxDetName: " << fAuxDetName << "\n"
55  << "ADC: " << fADC << "\n"
56  << "Was this CRT::Hit default-constructed? " << (IsDefault()?"true":"false") << "\n";
57  return stream;
58  }
59 
60  private: //The last thing I read about LArSoft data products and polymorphism told me not to make polymorphic data products.
61  //Information for identifying which CRT module strip this hit was recorded on
62  //TODO: Should there be some kind of AuxDetID for storing this detector-sensitive pair in the Geometry service? Probably not worth the effort
63  // just for this class.
64  //TODO: Modify/write AuxDetGeo channel mapping such that AuxDetGeo index IS CRT module label from documentation
65  size_t fChannel; //The index of the AuxDetSensitiveGeo that represents this strip in a CRT module
66  //std::string fAuxDetName; //The name of the volume from the geometry that represents the CRT module strip this hit was recorded in.
67  //LArSoft sometimes needs this information to look up AuxDetSensitiveGeos.
68 
69  short fADC; //Baseline-subtracted Analog to Digital Converter value at time when this hit was read out.
70  //TODO: Is this ADC value the integral over some time period? The result of a fit?
71  };
72 
73  //Also overload operator << for std::ostream to make debugging CRT::Hits as easy as possible. Really just call dump() internally.
74  template <class STREAM>
75  STREAM& operator << (STREAM& lhs, const CRT::Hit& hit)
76  {
77  return hit.dump(lhs);
78  }
79 
80  class Trigger
81  {
82  public:
83  //Constructor from information that comes from Matt's artdaq::Fragments. Takes ownership of the CRT::Hits given. Note that this
84  //is the only time that CRT::Hits can be added to a Trigger in accordance with some data product design notes I found.
85  //TODO: Should timestamp assembly be handled here or elsewhere?
86  Trigger(const unsigned short channel, /*const std::string& detName,*/ const unsigned long long timestamp,
87  std::vector<CRT::Hit>&& hits): fChannel(channel), /*fDetName(detName),*/ fTimestamp(timestamp), fHits(hits)
88  {}
89 
90  Trigger(): fChannel(std::numeric_limits<decltype(fChannel)>::max()), /*fDetName(""),*/
91  fTimestamp(std::numeric_limits<decltype(fTimestamp)>::max()), fHits() {} //Default constructor to satisfy ROOT.
92 
93  //User access to stored information. See member variables for explanation
94  inline unsigned short Channel() const { return fChannel; }
95  //const std::string& DetName() const { return fDetName; }
96  inline unsigned long long Timestamp() const { return fTimestamp; }
97  inline const std::vector<CRT::Hit>& Hits() const { return fHits; }
98 
99  //Check whether this Hit was default-constructed
101 
102  //Dumping an object is also helpful for debugging.
103  template <class STREAM>
104  void dump(STREAM& stream) const
105  {
106  stream << "CRT::Trigger dump:\n"
107  << "Channel: " << fChannel << "\n"
108  //<< "Detector Name: " << fDetName << "\n"
109  << "Timestamp: " << fTimestamp << "\n"
110  << "Hits:\n";
111  for(const auto& hit: fHits) hit.dump(stream);
112 
113  return stream;
114  }
115 
116  private:
117  unsigned short fChannel; //Mapping to CRT module that was Triggered. Index into the Geometry service's array of AuxDetGeos
118  //that returns the representation of this module. Module AuxDetGeo shown contain strips as AuxDetSensitiveGeos
119  //(see CRT::Hit::fChannel).
120  //TODO: Ideally, this will correspond to CRT electronics channel one day.
121  //std::string fDetName; //Name of the geometry representation for the module that Triggered itself. Needed sometimes by the Geometry service.
122 
123  unsigned long long fTimestamp; //Timestamp when this Trigger occurred. First 32 bits are Linux time since epoch; last 32 bits are time in
124  //ns.
125  std::vector<CRT::Hit> fHits; //All activity in CRT strips within this module when it was read out
126  };
127 
128  //ostream operator overload so users can do mf::LogWarning("CRTTriggerError") << /*stuff*/ << trigger << "\n".
129  template <class STREAM>
130  STREAM& operator <<(STREAM& lhs, const CRT::Trigger& trigger)
131  {
132  return trigger.dump(lhs);
133  }
134 }
135 
136 #endif //CRT_TRIGGER_H
bool IsDefault() const
Definition: CRTTrigger.h:100
void dump(STREAM &stream) const
Definition: CRTTrigger.h:104
unsigned long long fTimestamp
Definition: CRTTrigger.h:123
unsigned short fChannel
Definition: CRTTrigger.h:117
unsigned long long Timestamp() const
Definition: CRTTrigger.h:96
int16_t adc
Definition: CRTFragment.hh:202
STL namespace.
uint8_t channel
Definition: CRTFragment.hh:201
short ADC() const
Definition: CRTTrigger.h:43
bool IsDefault() const
Definition: CRTTrigger.h:46
STREAM & operator<<(STREAM &lhs, const CRT::Hit &hit)
Definition: CRTTrigger.h:75
unsigned short Channel() const
Definition: CRTTrigger.h:94
static int max(int a, int b)
Trigger(const unsigned short channel, const unsigned long long timestamp, std::vector< CRT::Hit > &&hits)
Definition: CRTTrigger.h:86
Detector simulation of raw signals on wires.
size_t fChannel
Definition: CRTTrigger.h:65
Hit(uint8_t channel, uint16_t adc)
Definition: CRTTrigger.h:27
virtual ~Hit()=default
size_t Channel() const
Definition: CRTTrigger.h:39
std::vector< CRT::Hit > fHits
Definition: CRTTrigger.h:125
const std::vector< CRT::Hit > & Hits() const
Definition: CRTTrigger.h:97
void dump(STREAM &stream) const
Definition: CRTTrigger.h:50
short fADC
Definition: CRTTrigger.h:69