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 adcTm1() const { return first(); }
163
172 int adcT() 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
297 int totSampleIndex() const {
298 for (unsigned int i_sample{0}; i_sample < size(); i_sample++)
299 if (at(i_sample).isTOTComplete()) return i_sample;
300 return -1;
301 }
302
304 HgcrocDigiCollection::Sample at(unsigned int i_sample) const {
305 return Sample(*(first_ + i_sample), collection_.getVersion());
306 }
307
316
317 unsigned int size() const { return collection_.getNumSamplesPerDigi(); }
318
319 private:
321 unsigned int id_;
322
324 std::vector<uint32_t>::const_iterator first_;
325
328
329 }; // HgcrocDigi
330
331 public:
336
341
348 void clear();
349
356 friend std::ostream& operator<<(std::ostream& o,
357 const HgcrocDigiCollection& d);
362 int getVersion() const { return version_; }
363
367 void setVersion(int v) {
368 version_ = v;
369 return;
370 }
371
376 unsigned int getNumSamplesPerDigi() const { return num_samples_per_digi_; }
377
382 void setNumSamplesPerDigi(unsigned int n) {
384 return;
385 }
386
391 unsigned int getSampleOfInterestIndex() const { return sample_of_interest_; }
392
401 void setSampleOfInterestIndex(unsigned int n) {
403 return;
404 }
405
419 const HgcrocDigi getDigi(unsigned int digiIndex) const;
420
425 unsigned int getNumDigis() const { return channel_ids_.size(); }
426
431 unsigned int size() const { return channel_ids_.size(); }
432
441 void addDigi(unsigned int id, const std::vector<Sample>& digi);
442 void addDigi(unsigned int id, const std::vector<uint32_t>& digi);
443
444 public:
455 class Iterator {
456 public:
458 explicit Iterator(HgcrocDigiCollection& c, long index = 0)
459 : digi_index_{index}, coll_{c} {}
462 digi_index_++;
463 return *this;
464 }
467 Iterator retval = *this;
468 ++(*this);
469 return retval;
470 }
472 bool operator==(Iterator other) const {
473 return digi_index_ == other.digi_index_;
474 }
476 bool operator!=(Iterator other) const { return !(*this == other); }
481 const HgcrocDigi operator*() const { return coll_.getDigi(digi_index_); }
482
483 private:
485 long digi_index_{0};
488 }; // iterator
489
490 public:
496 Iterator begin() { return Iterator(*this, 0); }
497
504 Iterator end() { return Iterator(*this, getNumDigis()); }
505
506 private:
508 static const int ONE_BIT_MASK = 1;
509
511 static const int TEN_BIT_MASK = (1 << 10) - 1;
512
514 static const int FIRSTFLAG_POS = 31;
515
517 static const int SECONFLAG_POS = 30;
518
520 static const int FIRSTMEAS_POS = 20;
521
523 static const int SECONMEAS_POS = 10;
524
525 private:
527 std::vector<unsigned int> channel_ids_;
528
530 std::vector<uint32_t> samples_;
531
534
537
540
545};
546} // namespace ldmx
547
557std::ostream& operator<<(std::ostream& s,
559
569std::ostream& operator<<(std::ostream& s,
571
581std::ostream& operator<<(std::ostream& s,
582 const ldmx::HgcrocDigiCollection& col);
583
584#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
int totSampleIndex() const
Get the index of the sample holding the completed TOT measurement.
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
iterator class so we can do range-based loops over digi collections
const HgcrocDigi operator*() const
De-reference this iterator by using the parent collection to get the actual digi at the index.
Iterator(HgcrocDigiCollection &c, long index=0)
Connect the parent collection with an index to this iterator.
HgcrocDigiCollection & coll_
the parent collection this iterator is looping over
bool operator!=(Iterator other) const
Check if two iterators are not on the same index.
Iterator & operator++()
Increment the digi index and return the iterator afterwards.
long digi_index_
the index of the digi this iterator represents
bool operator==(Iterator other) const
Check if two iterators are on the same index.
Iterator operator++(int)
Increment the digi index and return the iterator before.
One sample of a digi channel corresponding to one clock of the HGCROC chip.
int adcT() const
Get the ADC measurement from this sample.
int adcTm1() const
Get the last 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 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.
Represents a collection of the digi hits readout by an HGCROC.
std::vector< uint32_t > samples_
list of samples that we have been given
Iterator begin()
The beginning of this collection.
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
const HgcrocDigi getDigi(unsigned int digiIndex) const
Get samples for the input digi index.
void clear()
Clear the data in the object.
int getVersion() const
Get the version of ROC we have read.
std::vector< unsigned int > channel_ids_
list of channel IDs that we have digis for
unsigned int getNumSamplesPerDigi() const
Get number of samples per digi.
static const int FIRSTMEAS_POS
Bit position of first measurement.
unsigned int num_samples_per_digi_
number of samples for each digi
void setNumSamplesPerDigi(unsigned int n)
Set number of samples for each digi.
static const int TEN_BIT_MASK
Mask for lowest order ten bits in an int.
Iterator end()
The end of this collection.
void setSampleOfInterestIndex(unsigned int n)
Set index of sample of interest.
static const int ONE_BIT_MASK
Mask for lowest order bit in an int.
unsigned int getSampleOfInterestIndex() const
Get index of sample of interest.
ClassDef(HgcrocDigiCollection, 6)
The ROOT class definition.
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.
unsigned int sample_of_interest_
index for the sample of interest in the samples list
unsigned int getNumDigis() const
Get total number of digis.
unsigned int size() const
Get total number of digis.
friend std::ostream & operator<<(std::ostream &o, const HgcrocDigiCollection &d)
Print out the object.
virtual ~HgcrocDigiCollection()
Class destructor.