LDMX Software
HgcrocDigiCollection.cxx
1
3
5
6namespace ldmx {
7HgcrocDigiCollection::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_ =
16 (((seconMeas > 0xfff ? 0xfff : seconMeas) & 0xfff) << 20) +
17 (((firstMeas > TEN_BIT_MASK ? TEN_BIT_MASK : firstMeas) & TEN_BIT_MASK)
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_ =
34 (tot_progress << FIRSTFLAG_POS) + (tot_complete << SECONFLAG_POS) +
35 (((firstMeas > TEN_BIT_MASK ? TEN_BIT_MASK : firstMeas) & TEN_BIT_MASK)
36 << FIRSTMEAS_POS) +
37 (((seconMeas > TEN_BIT_MASK ? TEN_BIT_MASK : seconMeas) & TEN_BIT_MASK)
38 << SECONMEAS_POS) +
40 }
41}
42
44 channel_ids_.clear();
45 samples_.clear();
46
47 return;
48}
49
50std::ostream &operator<<(std::ostream &o, const HgcrocDigiCollection &c) {
51 return o << "HgcrocDigiCollection { Num Channel IDs: "
52 << c.channel_ids_.size() << ", Num Samples: " << c.samples_.size()
53 << ", Samples Per Digi: " << c.num_samples_per_digi_
54 << ", Index for SOI: " << c.sample_of_interest_ << "}";
55}
56
58 unsigned int digiIndex) const {
60 channel_ids_.at(digiIndex),
61 samples_.begin() + digiIndex * getNumSamplesPerDigi(), *this);
62}
63
65 unsigned int id, const std::vector<HgcrocDigiCollection::Sample> &digi) {
66 if (digi.size() != this->getNumSamplesPerDigi()) {
67 std::cerr << "[ WARN ] [ HgcrocDigiCollection ] Input list of samples "
68 "has size '"
69 << digi.size()
70 << "' that does not match the number of samples per digi '"
71 << this->getNumSamplesPerDigi() << "'!." << std::endl;
72 return;
73 }
74
75 channel_ids_.push_back(id);
76 for (auto const &s : digi) samples_.push_back(s.raw());
77
78 return;
79}
80
81void HgcrocDigiCollection::addDigi(unsigned int id,
82 const std::vector<uint32_t> &digi) {
83 if (digi.size() != this->getNumSamplesPerDigi()) {
84 std::cerr << "[ WARN ] [ HgcrocDigiCollection ] Input list of samples "
85 "has size '"
86 << digi.size()
87 << "' that does not match the number of samples per digi '"
88 << this->getNumSamplesPerDigi() << "'!." << std::endl;
89 return;
90 }
91
92 channel_ids_.push_back(id);
93 for (auto const &s : digi) samples_.push_back(s);
94
95 return;
96}
97} // namespace ldmx
98
99std::ostream &operator<<(std::ostream &s,
101 s << "Sample { " << "tot prog: " << sample.isTOTinProgress() << ", "
102 << "tot comp: " << sample.isTOTComplete() << ", ";
103 if (sample.isTOTComplete() and sample.isTOTinProgress())
104 s << "adc t: " << sample.adcT() << ", " << "tot: " << sample.tot() << ", ";
105 else if (sample.isTOTComplete())
106 s << "adc t-1: " << sample.adcTm1() << ", " << "tot: " << sample.tot()
107 << ", ";
108 else
109 s << "adc t-1: " << sample.adcTm1() << ", " << "adc t: " << sample.adcT()
110 << ", ";
111
112 s << "toa: " << sample.toa() << " }";
113 return s;
114}
115
116std::ostream &operator<<(std::ostream &s,
118 s << "HgcrocDigi { ";
119
120 s << " Id: 0x" << std::hex << digi.id() << std::dec << " ";
121
122 if (digi.isADC())
123 s << "ADC Mode -> SOI: " << digi.soi() << " }";
124 else
125 s << "TOT Mode -> " << digi.tot() << " }";
126
127 return s;
128}
129
130std::ostream &operator<<(std::ostream &s,
131 const ldmx::HgcrocDigiCollection &col) {
132 s << "HgcrocDigiCollection { " << std::endl;
133 for (unsigned int i_digi = 0; i_digi < col.getNumDigis(); i_digi++)
134 s << " " << col.getDigi(i_digi) << std::endl;
135 s << "}";
136 return s;
137}
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 adcT() const
Get the ADC measurement from this sample.
int adcTm1() const
Get the last 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 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.
const HgcrocDigi getDigi(unsigned int digiIndex) const
Get samples for the input digi index.
void clear()
Clear the data in the object.
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
static const int TEN_BIT_MASK
Mask for lowest order ten bits in an int.
static const int SECONMEAS_POS
Bit position of second measurement.
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.
friend std::ostream & operator<<(std::ostream &o, const HgcrocDigiCollection &d)
Print out the object.