All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  * Compression/uncompression utilities are declared in lardata/RawData/raw.h .
8  *
9  * Changes:
10  * 20141210 Gianluca Petrillo (petrillo@fnal.gov)
11  * data architecture revision changes:
12  * - fADC made private
13  * - removed constructor not assigning sample number
14  * - added flags interface
15  *
16  * 2/19/2008 Mitch Soderberg
17  * -modified RawDigit class slightly to be compatible with binary output of DAQ software,
18  * and to include \# samples/channel explicity, instead of via sizeof() methods.
19  *
20  * ****************************************************************************/
21 
22 #ifndef RAWDATA_RAWDIGIT_H
23 #define RAWDATA_RAWDIGIT_H
24 
25 // C/C++ standard libraries
26 #include <cstdlib> // size_t
27 #include <vector>
28 
29 // LArSoft libraries
30 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::Compress_t, raw::Channel_t
31 
32 // ROOT includes
33 #include "RtypesCore.h"
34 
35 
36 /// Raw data description and utilities
37 namespace raw {
38 
39  /**
40  * @brief Collection of charge vs time digitized from a single readout channel
41  *
42  * This class hosts potentially compressed data.
43  * It does not provide methods to uncompress it, not the same object can
44  * become compressed/uncompressed or change compression type: to use a
45  * compressed RawDigit, one has to create a new buffer, fill and use it:
46  *
47  * raw::RawDigit::ADCvector_t ADCs(digits.Samples()); // fix the size!
48  * raw::Uncompress(digits.ADCs(), ADCs, digits.Compression());
49  *
50  * (remember that you have to provide raw::Uncompress() with a buffer large
51  * enough to contain the uncompressed data).
52  *
53  * The class provides some flags, defined in FlagIndices_t.
54  * The construction of a RawDigit should be for example in the form:
55  *
56  * raw::RawDigit::ADCvector_t ADCs;
57  * // ... fill the digits etc.
58  * raw::RawDigit saturatedDigit(
59  * channel, ADCs.size(), ADCs, raw::kNone,
60  * DefaultFlags | SaturationBit
61  * );
62  * raw::RawDigit unsaturatedDigit(
63  * channel, ADCs.size(), ADCs, raw::kNone,
64  * DefaultFlags & ~SaturationBit
65  * );
66  *
67  *
68  */
69  class RawDigit {
70 
71  public:
72  /// Type representing a (compressed) vector of ADC counts
73  typedef std::vector<short> ADCvector_t;
74 
75 /*
76 // removed waiting for a real use for flags
77  /// Type for the digit flags
78  typedef std::bitset<16> Flags_t;
79 */
80 
81  /// Default constructor: an empty raw digit
82  RawDigit();
83 
84  public:
85 
86  /*
87  // removed waiting for a real use for flags
88  typedef enum {
89  fiSaturation, ///< saturation flag: set if saturated at any time
90  NLArSoftFlags = 8, ///< LArSoft reserves flags up to here (this excluded)
91  NFlagIndices = NLArSoftFlags ///< number of flags
92  } FlagIndices_t; ///< type of index of flags
93  */
94 
95  /**
96  * @brief Constructor: sets all the fields
97  * @param channel ID of the channel the digits were acquired from
98  * @param samples number of ADC samples in the uncompressed collection
99  * @param adclist list of ADC counts vs. time, compressed
100  * @param compression compression algorithm used in adclist
101  *
102  * Data from the adclist is copied into the raw digits.
103  * Pedestal is set to 0 by default.
104  */
105  RawDigit(ChannelID_t channel,
106  ULong64_t samples,
107  ADCvector_t const& adclist,
109  const Flags_t& flags = DefaultFlags */
110  );
111 
112  /**
113  * @brief Constructor: sets all the fields
114  * @param channel ID of the channel the digits were acquired from
115  * @param samples number of ADC samples in the uncompressed collection
116  * @param adclist list of ADC counts vs. time, compressed
117  * @param compression compression algorithm used in adclist
118  *
119  * Data from the adclist is moved into the raw digits.
120  * Pedestal is set to 0 by default.
121  */
122  RawDigit(ChannelID_t channel,
123  ULong64_t samples,
124  ADCvector_t&& adclist,
126  const Flags_t& flags = DefaultFlags */
127  );
128 
129  /// Set pedestal and its RMS (the latter is 0 by default)
130  void SetPedestal(float ped, float sigma = 1.);
131 
132  ///@{
133  ///@name Accessors
134 
135  /// Reference to the compressed ADC count vector
136  const ADCvector_t& ADCs() const;
137 
138  /// Number of elements in the compressed ADC sample vector
139  size_t NADC() const;
140 
141  /// ADC vector element number i; no decompression is applied
142  short ADC(int i) const;
143 
144  /// DAQ channel this raw data was read from
145  ChannelID_t Channel() const;
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 GetPedestal() const;
153 
154  /// TODO RMS of the pedestal level?
155  float GetSigma() const;
156 
157  /// Compression algorithm used to store the ADC counts
159  ///@}
160 
161  /*
162  // removed waiting for a real use for flags
163  ///@{
164  ///@name Raw digit flag interface
165  /// Flag set
166  const Flags_t& Flags() const;
167 
168  /// Returns if saturation bit is set
169  bool isSaturated() const;
170 
171  // the unsigned long long thing is from std::bitset<> constructors
172  /// Bit for saturation
173  static const unsigned long long SaturationBit = 1ULL << fiSaturation;
174 
175  /// Flags for a digit constructred by default
176  static const unsigned long long DefaultFlags = 0ULL;
177 
178  ///@}
179  */
180 
181 
182  private:
183  std::vector<short> fADC; ///< ADC readout per tick, before pedestal subtraction
184 
185  ChannelID_t fChannel; ///< channel number in the readout
186  ULong64_t fSamples; ///< number of ticks of the clock
187 
188  float fPedestal; ///< pedestal for this channel
189  float fSigma; ///< sigma of the pedestal counts for this channel
190 
191  Compress_t fCompression; ///< compression scheme used for the ADC vector
192 
193 
194  // removed waiting for a real use for flags
195  // Flags_t fFlags; ///< set of digit flags
196 
197  }; // class RawDigit
198 
199 
200 } // namespace raw
201 
202 
203 //------------------------------------------------------------------------------
204 //--- inline implementation
205 //---
206 
207 inline size_t raw::RawDigit::NADC() const { return fADC.size(); }
208 inline short raw::RawDigit::ADC(int i) const { return fADC.at(i); }
209 inline const raw::RawDigit::ADCvector_t&
210  raw::RawDigit::ADCs() const { return fADC; }
211 inline raw::ChannelID_t
212  raw::RawDigit::Channel() const { return fChannel; }
213 inline ULong64_t raw::RawDigit::Samples() const { return fSamples; }
214 inline float raw::RawDigit::GetPedestal() const { return fPedestal; }
215 inline float raw::RawDigit::GetSigma() const { return fSigma; }
217 /*
218 // removed waiting for a real use for flags
219 inline const raw::RawDigit::Flags_t&
220  raw::RawDigit::Flags() const { return fFlags; }
221 inline bool raw::RawDigit::isSaturated() const { return fFlags.test(fiSaturation); }
222 */
223 
224 
225 #endif // RAWDATA_RAWDIGIT_H
226 
227 ////////////////////////////////////////////////////////////////////////
float GetPedestal() const
Definition: RawDigit.h:214
std::vector< short > fADC
ADC readout per tick, before pedestal subtraction.
Definition: RawDigit.h:183
const ADCvector_t & ADCs() const
Reference to the compressed ADC count vector.
Definition: RawDigit.h:210
TString compression(pset.get< std::string >("CompressionType"))
enum raw::_compress Compress_t
ULong64_t Samples() const
Number of samples in the uncompressed ADC data.
Definition: RawDigit.h:213
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
short ADC(int i) const
ADC vector element number i; no decompression is applied.
Definition: RawDigit.h:208
float fSigma
sigma of the pedestal counts for this channel
Definition: RawDigit.h:189
ChannelID_t Channel() const
DAQ channel this raw data was read from.
Definition: RawDigit.h:212
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
Definition: RawDigit.h:73
no compression
Definition: RawTypes.h:9
size_t NADC() const
Number of elements in the compressed ADC sample vector.
Definition: RawDigit.h:207
Compress_t fCompression
compression scheme used for the ADC vector
Definition: RawDigit.h:191
RawDigit()
Default constructor: an empty raw digit.
Definition: RawDigit.cxx:20
ULong64_t fSamples
number of ticks of the clock
Definition: RawDigit.h:186
raw::Compress_t Compression() const
Compression algorithm used to store the ADC counts.
Definition: RawDigit.h:216
void SetPedestal(float ped, float sigma=1.)
Set pedestal and its RMS (the latter is 0 by default)
Definition: RawDigit.cxx:68
float fPedestal
pedestal for this channel
Definition: RawDigit.h:188
ChannelID_t fChannel
channel number in the readout
Definition: RawDigit.h:185
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
float GetSigma() const
TODO RMS of the pedestal level?
Definition: RawDigit.h:215