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
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 friend std::ostream& operator<<(std::ostream& o,
342 const HgcrocDigiCollection& d);
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 num_samples_per_digi_; }
362
367 void setNumSamplesPerDigi(unsigned int n) {
369 return;
370 }
371
376 unsigned int getSampleOfInterestIndex() const { return sample_of_interest_; }
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 channel_ids_.size(); }
411
416 unsigned int size() const { return channel_ids_.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:
440 class Iterator {
441 public:
443 explicit Iterator(HgcrocDigiCollection& c, long index = 0)
444 : digi_index_{index}, coll_{c} {}
447 digi_index_++;
448 return *this;
449 }
452 Iterator retval = *this;
453 ++(*this);
454 return retval;
455 }
457 bool operator==(Iterator other) const {
458 return digi_index_ == other.digi_index_;
459 }
461 bool operator!=(Iterator other) const { return !(*this == other); }
466 const HgcrocDigi operator*() const { return coll_.getDigi(digi_index_); }
467
468 private:
470 long digi_index_{0};
473 }; // iterator
474
475 public:
481 Iterator begin() { return Iterator(*this, 0); }
482
489 Iterator end() { return Iterator(*this, getNumDigis()); }
490
491 private:
493 static const int ONE_BIT_MASK = 1;
494
496 static const int TEN_BIT_MASK = (1 << 10) - 1;
497
499 static const int FIRSTFLAG_POS = 31;
500
502 static const int SECONFLAG_POS = 30;
503
505 static const int FIRSTMEAS_POS = 20;
506
508 static const int SECONMEAS_POS = 10;
509
510 private:
512 std::vector<unsigned int> channel_ids_;
513
515 std::vector<uint32_t> samples_;
516
519
522
525
530};
531} // namespace ldmx
532
542std::ostream& operator<<(std::ostream& s,
544
554std::ostream& operator<<(std::ostream& s,
556
566std::ostream& operator<<(std::ostream& s,
567 const ldmx::HgcrocDigiCollection& col);
568
569#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
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.