LDMX Software
HgcrocDigiCollection.cxx
1
3
5
6 namespace ldmx {
7 HgcrocDigiCollection::Sample::Sample(bool tot_progress, bool tot_complete,
8 int firstMeas, int seconMeas, int toa,
9 int version) {
10 version_ = version;
11 if (version_ == 2) {
12 // version 2 HGC ROC had a much simpler word structure
13 // 12-bit TOT | 10-bit TOA | 10-bit ADCt
14 // we assume that firstMeas is adct and secondMeas is tot
15 word_ = (((seconMeas > 0xfff ? 0xfff : seconMeas) & 0xfff) << 20) +
16 (((firstMeas > TEN_BIT_MASK ? TEN_BIT_MASK : firstMeas) &
18 << 10) +
20
21 } else {
22 if (not tot_progress and tot_complete) {
23 // the 12 bit internal tot measurement needs to
24 // be packed into a 10 bit int
25 if (seconMeas > 512)
26 seconMeas =
27 512 + seconMeas / 8; // lost some precision but can go higher
28 }
29
30 // check if over largest number possible ==> set to largest if over (don't
31 // want wrapping) and then do bit shifting nonsense to code the
32 // measurements into the 32-bit word set last measurement to TOA
33 word_ = (tot_progress << FIRSTFLAG_POS) +
34 (tot_complete << SECONFLAG_POS) +
35 (((firstMeas > TEN_BIT_MASK ? TEN_BIT_MASK : firstMeas) &
37 << FIRSTMEAS_POS) +
38 (((seconMeas > TEN_BIT_MASK ? TEN_BIT_MASK : seconMeas) &
40 << SECONMEAS_POS) +
42 }
43 }
44
46 channelIDs_.clear();
47 samples_.clear();
48
49 return;
50 }
51
52 void HgcrocDigiCollection::Print() const {
53 std::cout << "HgcrocDigiCollection { Num Channel IDs: "
54 << channelIDs_.size() << ", Num Samples: " << samples_.size()
55 << ", Samples Per Digi: " << numSamplesPerDigi_
56 << ", Index for SOI: " << sampleOfInterest_ << "}" << std::endl;
57
58 return;
59 }
60
61 const HgcrocDigiCollection::HgcrocDigi HgcrocDigiCollection::getDigi(
62 unsigned int digiIndex) const {
63 return HgcrocDigiCollection::HgcrocDigi(
64 channelIDs_.at(digiIndex),
65 samples_.begin() + digiIndex * getNumSamplesPerDigi(), *this);
66 }
67
69 unsigned int id, const std::vector<HgcrocDigiCollection::Sample> &digi) {
70 if (digi.size() != this->getNumSamplesPerDigi()) {
71 std::cerr << "[ WARN ] [ HgcrocDigiCollection ] Input list of samples "
72 "has size '"
73 << digi.size()
74 << "' that does not match the number of samples per digi '"
75 << this->getNumSamplesPerDigi() << "'!." << std::endl;
76 return;
77 }
78
79 channelIDs_.push_back(id);
80 for (auto const &s : digi) samples_.push_back(s.raw());
81
82 return;
83 }
84
85 void HgcrocDigiCollection::addDigi(unsigned int id,
86 const std::vector<uint32_t> &digi) {
87 if (digi.size() != this->getNumSamplesPerDigi()) {
88 std::cerr << "[ WARN ] [ HgcrocDigiCollection ] Input list of samples "
89 "has size '"
90 << digi.size()
91 << "' that does not match the number of samples per digi '"
92 << this->getNumSamplesPerDigi() << "'!." << std::endl;
93 return;
94 }
95
96 channelIDs_.push_back(id);
97 for (auto const &s : digi) samples_.push_back(s);
98
99 return;
100 }
101} // namespace ldmx
102
103std::ostream &operator<<(std::ostream &s,
105 s << "Sample { "
106 << "tot prog: " << sample.isTOTinProgress() << ", "
107 << "tot comp: " << sample.isTOTComplete() << ", ";
108 if (sample.isTOTComplete() and sample.isTOTinProgress())
109 s << "adc t: " << sample.adc_t() << ", "
110 << "tot: " << sample.tot() << ", ";
111 else if (sample.isTOTComplete())
112 s << "adc t-1: " << sample.adc_tm1() << ", "
113 << "tot: " << sample.tot() << ", ";
114 else
115 s << "adc t-1: " << sample.adc_tm1() << ", "
116 << "adc t: " << sample.adc_t() << ", ";
117
118 s << "toa: " << sample.toa() << " }";
119 return s;
120}
121
122std::ostream &operator<<(std::ostream &s,
124 s << "HgcrocDigi { ";
125
126 s << " Id: 0x" << std::hex << digi.id() << std::dec << " ";
127
128 if (digi.isADC())
129 s << "ADC Mode -> SOI: " << digi.soi() << " }";
130 else
131 s << "TOT Mode -> " << digi.tot() << " }";
132
133 return s;
134}
135
136std::ostream &operator<<(std::ostream &s,
137 const ldmx::HgcrocDigiCollection &col) {
138 s << "HgcrocDigiCollection { " << std::endl;
139 for (unsigned int iDigi = 0; iDigi < col.getNumDigis(); iDigi++)
140 s << " " << col.getDigi(iDigi) << std::endl;
141 s << "}";
142 return s;
143}
Class that represents a digitized hit in a calorimeter cell readout by an HGCROC.
One DIGI signal coming from the HGC ROC.
bool isADC() const
Check if this DIGI is an ADC 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.
One sample of a digi channel corresponding to one clock of the HGCROC chip.
int adc_t() const
Get the ADC measurement from this sample.
int tot() const
Get the TOT measurement from this sample.
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 toa() const
Get the Time Of Arrival of this sample which is always the third position in all readout modes.
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
static const int SECONFLAG_POS
Bit position of second flag.
static const int FIRSTFLAG_POS
Bit position of first flag.
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.
void Print() const
Print out the object.
static const int TEN_BIT_MASK
Mask for lowest order ten bits in an int.
std::vector< unsigned int > channelIDs_
list of channel IDs that we have digis for
static const int SECONMEAS_POS
Bit position of second measurement.
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
void Clear()
Clear the data in the object.