RawDigit.h
Go to the documentation of this file.
1 /** ****************************************************************************
2  * @file RawDigit.h
3  * @brief Definition of basic raw digits
4  * @author brebel@fnal.gov
5  * @see RawDigit.cxx raw.h
6  *
7  *
8  * Changes:
9  * 20141210 Gianluca Petrillo (petrillo@fnal.gov)
10  * data architecture revision changes:
11  * - fADC made private
12  * - removed constructor not assigning sample number
13  * - added flags interface
14  *
15  * 2/19/2008 Mitch Soderberg
16  * -modified RawDigit class slightly to be compatible with binary output of DAQ software,
17  * and to include #samples/channel explicity, instead of via sizeof() methods.
18  *
19  * ****************************************************************************/
20 
21 #ifndef GAR_RAWDATA_RAWDIGIT_H
22 #define GAR_RAWDATA_RAWDIGIT_H
23 
24 // C/C++ standard libraries
25 #include <stdint.h> // uint32_t
26 #include <cstdlib> // size_t
27 #include <vector>
29 #include "RtypesCore.h" // ULong64_t
30 
31 /// Raw data description and utilities
32 namespace gar {
33  namespace raw {
34 
35  typedef uint32_t Channel_t;
36 
37  /**
38  * @brief Collection of charge vs time digitized from a single readout channel
39  *
40  * This class hosts potentially compressed data.
41  * It does not provide methods to uncompress it, not the same object can
42  * become compressed/uncompressed or change compression type: to use a
43  * compressed RawDigit, one has to create a new buffer, fill and use it:
44  *
45  * raw::RawDigit::ADCvector_t ADCs(digits.Samples()); // fix the size!
46  * raw::Uncompress(digits.ADCs(), ADCs, digits.Compression());
47  *
48  * (remember that you have to provide raw::Uncompress() with a buffer large
49  * enough to contain the uncompressed data).
50  *
51  * Removed; may need to add this back later. The class provides some flags, defined in FlagIndices_t.
52  * The construction of a RawDigit should be for example in the form:
53  *
54  * raw::RawDigit::ADCvector_t ADCs;
55  * // ... fill the digits etc.
56  * raw::RawDigit saturatedDigit(
57  * channel, ADCs.size(), ADCs, raw::kNone,
58  * DefaultFlags | SaturationBit
59  * );
60  * raw::RawDigit unsaturatedDigit(
61  * channel, ADCs.size(), ADCs, raw::kNone,
62  * DefaultFlags & ~SaturationBit
63  * );
64  *
65  *
66  */
67  class RawDigit {
68 
69  public:
70  /// Type representing a (compressed) vector of ADC counts
71  typedef std::vector<short> ADCvector_t;
72 
73  /*
74  // removed waiting for a real use for flags
75  /// Type for the digit flags
76  typedef std::bitset<16> Flags_t;
77  */
78 
79  /// Default constructor: an empty raw digit with zeros put in for paraneters and an invalid channel
80  RawDigit();
81 
82 #ifndef __GCCXML__
83  public:
84 
85  /*
86  // removed waiting for a real use for flags
87  typedef enum {
88  fiSaturation, ///< saturation flag: set if saturated at any time
89  NGArSoftFlags = 8, ///< GArSoft reserves flags up to here (this excluded)
90  NFlagIndices = NGArSoftFlags ///< number of flags
91  } FlagIndices_t; ///< type of index of flags
92  */
93 
94  /**
95  * @brief Constructor: sets all the fields
96  * @param channel ID of the channel the digits were acquired from
97  * @param samples number of ADC samples in the uncompressed collection
98  * @param adclist list of ADC counts vs. time, compressed
99  * @param compression compression algorithm used in adclist
100  *
101  * Data from the adclist is copied into the raw digits.
102  * Pedestal is set to 0 by default.
103  */
104  RawDigit(Channel_t channel,
105  ULong64_t samples,
106  ADCvector_t const& adclist,
107  gar::raw::Compress_t compress,
108  ULong64_t time);
109 
110  /**
111  * @brief Constructor: sets all the fields
112  * @param channel ID of the channel the digits were acquired from
113  * @param samples number of ADC samples in the uncompressed collection
114  * @param adclist list of ADC counts vs. time, compressed
115  * @param compression compression algorithm used in adclist
116  *
117  * Data from the adclist is moved into the raw digits.
118  * Pedestal is set to 0 by default.
119  */
120  RawDigit(Channel_t channel,
121  ULong64_t samples,
122  ADCvector_t&& adclist,
123  gar::raw::Compress_t compress,
124  ULong64_t time);
125 
126  /// Set pedestal and its RMS (the latter is 0 by default)
127  void SetPedestal(float ped, float sigma = 1.);
128 
129  ///@{
130  ///@name Accessors
131 
132  /// Reference to the compressed ADC count vector
133  const ADCvector_t& ADCs() const;
134 
135  /// Number of elements in the compressed ADC sample vector
136  size_t NADC() const;
137 
138  /// ADC vector element number i; no decompression is applied
139  short ADC(int i) const;
140 
141  /// DAQ channel this raw data was read from
142  Channel_t Channel() const;
143 
144  /// Compression algorithm selector
146 
147  /// Number of samples in the uncompressed ADC data
148  ULong64_t Samples() const;
149 
150  /// Pedestal level (ADC counts)
151  /// @deprecated Might be removed soon
152  float Pedestal() const;
153 
154  /// TODO: RMS of the pedestal level?
155  float Sigma() const;
156 
157  /// Timestmap
158  ULong64_t Time() const;
159 
160  ///@}
161 
162 
163 
164 #endif // !__GCCXML__
165  private:
166  std::vector<short> fADC; ///< ADC readout per tick, before pedestal subtraction
167 
168  Channel_t fChannel; ///< channel number in the readout
169  ULong64_t fSamples; ///< number of ticks of the clock
170 
171  float fPedestal; ///< pedestal for this channel
172  float fSigma; ///< sigma of the pedestal counts for this channel
173  gar::raw::Compress_t fCompression; ///< compression scheme used for the ADC vector
174  ULong64_t fTime; ///< timestamp
175 
176  }; // class RawDigit
177 
178 
179  } // namespace raw
180 } // gar
181 
182 //------------------------------------------------------------------------------
183 //--- inline implementation
184 //---
185 #ifndef __GCCXML__
186 
187 inline size_t gar::raw::RawDigit::NADC() const { return fADC.size(); }
188 inline short gar::raw::RawDigit::ADC(int i) const { return fADC.at(i); }
191 inline ULong64_t gar::raw::RawDigit::Samples() const { return fSamples; }
192 inline float gar::raw::RawDigit::Pedestal() const { return fPedestal; }
193 inline float gar::raw::RawDigit::Sigma() const { return fSigma; }
194 inline ULong64_t gar::raw::RawDigit::Time() const { return fTime; }
196 
197 #endif // !__GCCXML__
198 
199 #endif // gar_RAWDATA_RAWDIGIT_H
200 
201 ////////////////////////////////////////////////////////////////////////
float Sigma() const
TODO: RMS of the pedestal level?
Definition: RawDigit.h:193
ULong64_t fTime
timestamp
Definition: RawDigit.h:174
Channel_t Channel() const
DAQ channel this raw data was read from.
Definition: RawDigit.h:190
enum gar::raw::_compress Compress_t
Raw data description.
size_t NADC() const
Number of elements in the compressed ADC sample vector.
Definition: RawDigit.h:187
uint8_t channel
Definition: CRTFragment.hh:201
float fPedestal
pedestal for this channel
Definition: RawDigit.h:171
gar::raw::Compress_t Compression() const
Compression algorithm selector.
Definition: RawDigit.h:195
uint32_t Channel_t
Definition: RawDigit.h:35
float fSigma
sigma of the pedestal counts for this channel
Definition: RawDigit.h:172
ULong64_t Time() const
Timestmap.
Definition: RawDigit.h:194
float Pedestal() const
Definition: RawDigit.h:192
const ADCvector_t & ADCs() const
Reference to the compressed ADC count vector.
Definition: RawDigit.h:189
short ADC(int i) const
ADC vector element number i; no decompression is applied.
Definition: RawDigit.h:188
void SetPedestal(float ped, float sigma=1.)
Set pedestal and its RMS (the latter is 0 by default)
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
Definition: RawDigit.h:71
General GArSoft Utilities.
gar::raw::Compress_t fCompression
compression scheme used for the ADC vector
Definition: RawDigit.h:173
Channel_t fChannel
channel number in the readout
Definition: RawDigit.h:168
ULong64_t fSamples
number of ticks of the clock
Definition: RawDigit.h:169
RawDigit()
Default constructor: an empty raw digit with zeros put in for paraneters and an invalid channel...
Definition: RawDigit.cxx:20
std::vector< short > fADC
ADC readout per tick, before pedestal subtraction.
Definition: RawDigit.h:166
ULong64_t Samples() const
Number of samples in the uncompressed ADC data.
Definition: RawDigit.h:191
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:67