LDMX Software
HgcrocDigiCollection.h
Go to the documentation of this file.
1
9#ifndef RECON_EVENT_HGCROCDIGICOLLECTION_H_
10#define RECON_EVENT_HGCROCDIGICOLLECTION_H_
11
12// ROOT
13#include "TObject.h" //for ClassDef
14
15// STL
16#include <stdint.h> //32bit words
17
18#include <iostream> //Print method
19#include <vector> //vector lists
20
21namespace ldmx {
22
44 public:
71 class Sample {
72 public:
82 Sample(bool tot_progress, bool tot_complete, int firstMeas, int seconMeas,
83 int toa, int version = 3);
84
91 Sample(uint32_t w, int version = 3) : word_(w), version_{version} {}
92
98 Sample() {}
99
106 bool isTOTinProgress() const {
107 return (ONE_BIT_MASK & (word_ >> FIRSTFLAG_POS));
108 }
109
117 bool isTOTComplete() const {
118 return (ONE_BIT_MASK & (word_ >> SECONFLAG_POS));
119 }
120
127 int toa() const {
128 if (version_ == 2) {
129 return secon();
130 } else {
131 return third();
132 }
133 }
134
145 int tot() const {
146 if (version_ == 2) {
147 return 0xfff & (word_ >> FIRSTMEAS_POS);
148 }
149
150 int meas = secon();
151 if (meas > 512) meas = (meas - 512) * 8;
152 return meas;
153 }
154
162 int adc_tm1() const { return first(); }
163
172 int adc_t() const {
173 if (version_ == 2) {
174 return third();
175 }
176
177 if (not isTOTComplete())
178 return secon(); // running modes
179 else
180 return first(); // calibration mode
181 }
182
188 uint32_t raw() const { return word_; }
189
190 private:
196 int first() const { return TEN_BIT_MASK & (word_ >> FIRSTMEAS_POS); }
197
203 int secon() const { return TEN_BIT_MASK & (word_ >> SECONMEAS_POS); }
204
209 int third() const { return TEN_BIT_MASK & word_; }
210
211 private:
213 uint32_t word_;
216 }; // Sample
217
218 public:
228 public:
240 HgcrocDigi(unsigned int id, std::vector<uint32_t>::const_iterator first,
241 const HgcrocDigiCollection& collection)
242 : id_(id), first_(first), collection_(collection) {}
243
249 unsigned int id() const { return id_; }
250
259 bool isADC() const {
260 return !(soi().isTOTinProgress() or soi().isTOTComplete());
261 }
262
271 bool isTOT() const { return !isADC(); }
272
282 int tot() const {
283 if (not isTOT()) return -1;
284 if (soi().isTOTinProgress()) return -2;
285 return soi().tot();
286 }
287
289 HgcrocDigiCollection::Sample at(unsigned int i_sample) const {
290 return Sample(*(first_ + i_sample), collection_.getVersion());
291 }
292
301
302 unsigned int size() const { return collection_.getNumSamplesPerDigi(); }
303
304 private:
306 unsigned int id_;
307
309 std::vector<uint32_t>::const_iterator first_;
310
313
314 }; // HgcrocDigi
315
316 public:
321
326
333 void Clear();
334
341 void Print() const;
342
347 int getVersion() const { return version_; }
348
352 void setVersion(int v) {
353 version_ = v;
354 return;
355 }
356
361 unsigned int getNumSamplesPerDigi() const { return numSamplesPerDigi_; }
362
367 void setNumSamplesPerDigi(unsigned int n) {
369 return;
370 }
371
376 unsigned int getSampleOfInterestIndex() const { return sampleOfInterest_; }
377
386 void setSampleOfInterestIndex(unsigned int n) {
388 return;
389 }
390
404 const HgcrocDigi getDigi(unsigned int digiIndex) const;
405
410 unsigned int getNumDigis() const { return channelIDs_.size(); }
411
416 unsigned int size() const { return channelIDs_.size(); }
417
426 void addDigi(unsigned int id, const std::vector<Sample>& digi);
427 void addDigi(unsigned int id, const std::vector<uint32_t>& digi);
428
429 public:
441 : public std::iterator<std::input_iterator_tag, HgcrocDigi, long> {
442 public:
444 explicit iterator(HgcrocDigiCollection& c, long index = 0)
445 : digi_index_{index}, coll_{c} {}
448 digi_index_++;
449 return *this;
450 }
453 iterator retval = *this;
454 ++(*this);
455 return retval;
456 }
458 bool operator==(iterator other) const {
459 return digi_index_ == other.digi_index_;
460 }
462 bool operator!=(iterator other) const { return !(*this == other); }
467 const HgcrocDigi operator*() const { return coll_.getDigi(digi_index_); }
468
469 private:
471 long digi_index_{0};
474 }; // iterator
475
476 public:
482 iterator begin() { return iterator(*this, 0); }
483
490 iterator end() { return iterator(*this, getNumDigis()); }
491
492 private:
494 static const int ONE_BIT_MASK = 1;
495
497 static const int TEN_BIT_MASK = (1 << 10) - 1;
498
500 static const int FIRSTFLAG_POS = 31;
501
503 static const int SECONFLAG_POS = 30;
504
506 static const int FIRSTMEAS_POS = 20;
507
509 static const int SECONMEAS_POS = 10;
510
511 private:
513 std::vector<unsigned int> channelIDs_;
514
516 std::vector<uint32_t> samples_;
517
519 unsigned int numSamplesPerDigi_;
520
522 unsigned int sampleOfInterest_;
523
526
531};
532} // namespace ldmx
533
543std::ostream& operator<<(std::ostream& s,
545
555std::ostream& operator<<(std::ostream& s,
557
567std::ostream& operator<<(std::ostream& s,
568 const ldmx::HgcrocDigiCollection& col);
569
570#endif /* RECON_EVENT_ECALDIGI_H_ */
std::ostream & operator<<(std::ostream &s, const ldmx::HgcrocDigiCollection::Sample &sample)
Streamer for the HgcrocDigiCollection::Sample.
One DIGI signal coming from the HGC ROC.
bool isADC() const
Check if this DIGI is an ADC measurement.
bool isTOT() const
Check if this DIGI is a TOT measurement.
unsigned int id_
channel ID where this signal is coming from
unsigned int id() const
Get the ID for this DIGI.
int tot() const
Get the 12-bit decoded TOT measurement from this DIGI.
HgcrocDigiCollection::Sample soi() const
Get the sample of interest from this DIGI.
const HgcrocDigiCollection & collection_
Reference to collection that owns this DIGI.
std::vector< uint32_t >::const_iterator first_
the location of the first sample that are in this digi
HgcrocDigi(unsigned int id, std::vector< uint32_t >::const_iterator first, const HgcrocDigiCollection &collection)
Constructor.
HgcrocDigiCollection::Sample at(unsigned int i_sample) const
get the sample at a specific index in the digi
One sample of a digi channel corresponding to one clock of the HGCROC chip.
Sample(bool tot_progress, bool tot_complete, int firstMeas, int seconMeas, int toa, int version=3)
Helpful alternative constructor.
int adc_t() const
Get the ADC measurement from this sample.
int secon() const
Get the second 10-bit measurement out of the sample.
int tot() const
Get the TOT measurement from this sample.
Sample(uint32_t w, int version=3)
Basic constructor.
int version_
version to use for {de,en}coding
uint32_t word_
The actual 32-bit word spit out by the chip.
int adc_tm1() const
Get the last ADC measurement from this sample.
int first() const
Get the first 10-bit measurement out of the sample.
int third() const
Get the third 10-bit measurement out of the smaple.
int toa() const
Get the Time Of Arrival of this sample which is always the third position in all readout modes.
uint32_t raw() const
Get the raw value of this sample.
bool isTOTinProgress() const
Get the first flag from the sample checking if TOT is in progress during this sample.
bool isTOTComplete() const
Get the second flag from the sample checking if TOT is complete at this sample.
iterator class so we can do range-based loops over digi collections
iterator(HgcrocDigiCollection &c, long index=0)
Connect the parent collection with an index to this iterator.
iterator & operator++()
Increment the digi index and return the iterator afterwards.
iterator operator++(int)
Increment the digi index and return the iterator before.
bool operator!=(iterator other) const
Check if two iterators are not on the same index.
long digi_index_
the index of the digi this iterator represents
const HgcrocDigi operator*() const
De-reference this iterator by using the parent collection to get the actual digi at the index.
bool operator==(iterator other) const
Check if two iterators are on the same index.
HgcrocDigiCollection & coll_
the parent collection this iterator is looping over
Represents a collection of the digi hits readout by an HGCROC.
std::vector< uint32_t > samples_
list of samples that we have been given
static const int SECONFLAG_POS
Bit position of second flag.
static const int FIRSTFLAG_POS
Bit position of first flag.
int version_
version of the ROC we have read
int getVersion() const
Get the version of ROC we have read.
unsigned int numSamplesPerDigi_
number of samples for each digi
unsigned int getNumSamplesPerDigi() const
Get number of samples per digi.
static const int FIRSTMEAS_POS
Bit position of first measurement.
iterator end()
The end of this collection.
void setNumSamplesPerDigi(unsigned int n)
Set number of samples for each digi.
void Print() const
Print out the object.
static const int TEN_BIT_MASK
Mask for lowest order ten bits in an int.
void setSampleOfInterestIndex(unsigned int n)
Set index of sample of interest.
std::vector< unsigned int > channelIDs_
list of channel IDs that we have digis for
static const int ONE_BIT_MASK
Mask for lowest order bit in an int.
unsigned int getSampleOfInterestIndex() const
Get index of sample of interest.
void setVersion(int v)
Set the version of the ROC we have read.
static const int SECONMEAS_POS
Bit position of second measurement.
HgcrocDigiCollection()
Class constructor.
void addDigi(unsigned int id, const std::vector< Sample > &digi)
Add samples to collection.
const HgcrocDigi getDigi(unsigned int digiIndex) const
Get samples for the input digi index.
unsigned int getNumDigis() const
Get total number of digis.
unsigned int sampleOfInterest_
index for the sample of interest in the samples list
iterator begin()
The beginning of this collection.
unsigned int size() const
Get total number of digis.
virtual ~HgcrocDigiCollection()
Class destructor.
ClassDef(HgcrocDigiCollection, 4)
The ROOT class definition.
void Clear()
Clear the data in the object.