LDMX Software
HgcrocTriggerCalculations.cxx
2
3#include <iostream>
4
5#include "Recon/Event/HgcrocTrigDigi.h"
6
7namespace ldmx {
8
10 const conditions::IntegerTableCondition &ict, bool validate)
11 : ict_{ict} {
12 if (!validate) return;
13 if (ict_.getColumnCount() < 5) {
14 EXCEPTION_RAISE(
15 "ConditionsException",
16 "Inconsistent condition for HgcrocTriggerConditions :" + ict.getName());
17 }
18 std::vector<std::string> expected_colnames;
19 expected_colnames.push_back("ADC_PEDESTAL");
20 expected_colnames.push_back("ADC_THRESHOLD");
21 expected_colnames.push_back("TOT_PEDESTAL");
22 expected_colnames.push_back("TOT_THRESHOLD");
23 expected_colnames.push_back("TOT_GAIN");
24
25 for (size_t i = 0; i < 5; i++) {
26 if (ict_.getColumnNames()[i] != expected_colnames[i]) {
27 EXCEPTION_RAISE("ConditionsException",
28 "Expected column '" + expected_colnames[i] + "', got '" +
29 ict_.getColumnNames()[i] + "'");
30 }
31 }
32}
33
35 int adc, int tot, int adc_ped, int adc_thresh, int tot_ped, int tot_thresh,
36 int tot_gain) {
37 unsigned int charge_adc = 0;
38
39 if (adc > (adc_ped + adc_thresh))
40 charge_adc = adc - adc_ped; // otherwise zero
41
42 unsigned int eff_tot{0};
43 if (tot > tot_thresh && tot > tot_ped)
44 eff_tot = tot - tot_ped;
45 else
46 eff_tot = tot_thresh - tot_ped;
47
48 unsigned int charge_tot{0};
49 charge_tot = eff_tot * tot_gain;
50
51 unsigned int charge_final = (tot != 0) ? (charge_tot) : (charge_adc);
52
53 return charge_final;
54}
55
59
60void HgcrocTriggerCalculations::addDigi(unsigned int id, unsigned int tid,
61 int adc, int tot) {
62 unsigned int charge = singleChannelCharge(
66 if (charge > 0) {
67 std::map<unsigned int, unsigned int>::iterator ic = linearCharge_.find(tid);
68 if (ic == linearCharge_.end())
69 linearCharge_[tid] = charge;
70 else
71 ic->second += charge;
72 }
73}
74
76 int shift;
77 if (cells_per_trig == 4)
78 shift = 1;
79 else if (cells_per_trig == 9)
80 shift = 3;
81 else {
82 EXCEPTION_RAISE("HgcrocTriggerException",
83 "Invalid number of precision cells per trigger cell: " +
84 std::to_string(cells_per_trig));
85 }
86
87 for (auto ilinear : linearCharge_) {
88 unsigned int lcharge = ilinear.second;
89 lcharge = lcharge >> shift;
90 uint8_t ccharge = ldmx::HgcrocTrigDigi::linear2Compressed(lcharge);
91 compressedCharge_[ilinear.first] = ccharge;
92 }
93}
94
95} // namespace ldmx
Class that contains the Hgcroc Trigger algorithms, used for both Ecal and Hcal.
unsigned int getColumnCount() const
Get the number of columns.
const std::vector< std::string > & getColumnNames() const
Get the names of the columns.
std::string getName() const
Get the name of this object.
static uint8_t linear2Compressed(uint32_t lin)
Static conversion from 18b linear -> compressed.
void addDigi(unsigned int id, unsigned int tid, int adc, int tot)
Determine the linear charge for the given channel, using the calibration information,...
std::map< unsigned int, uint8_t > compressedCharge_
A map of trigger channel id to compressed charge.
void compressDigis(int cells_per_trig)
Convert the linear charges to compressed charges, with a division depending on the number of cells su...
static unsigned int singleChannelCharge(int adc, int tot, int adc_ped, int adc_thresh, int tot_ped, int tot_thresh, int tot_gain)
Calculates the linear trigger charge for a single precision channel (before 2x2 or 3x3 summing)
std::map< unsigned int, unsigned int > linearCharge_
A map of trigger channel id to linear charge.
HgcrocTriggerCalculations(const conditions::IntegerTableCondition &ict)
Construct the chip trigger calculator.
HgcrocTriggerConditions conditions_
The conditions to be used.
int totThreshold(unsigned int id) const
get the TOT threshold
int totGain(unsigned int id) const
get the TOT gain
int adcPedestal(unsigned int id) const
get the ADC pedestal
int adcThreshold(unsigned int id) const
get the ADC threshold
int totPedestal(unsigned int id) const
get the TOT pedestal
const conditions::IntegerTableCondition & ict_
reference to the table of conditions storing the chip conditions
HgcrocTriggerConditions(const conditions::IntegerTableCondition &, bool validate=true)
Constructor.