15 #define ENERGY_WIDTH 16
20 : m_bdt(config_path), m_log(
log) {
34 unsigned int *sCellPtr) {
37 m_em0cells[eta][phi] = sCellPtr;
40 m_em1cells[eta][phi] = sCellPtr;
43 m_em2cells[eta][phi] = sCellPtr;
46 m_em3cells[eta][phi] = sCellPtr;
49 m_hadcells[eta][phi] = sCellPtr;
55 int index,
unsigned int *fracMultiplierPtr) {
56 m_fracMultipliers[
index] = fracMultiplierPtr;
60 int index,
unsigned int *bdtThresholdPtr) {
61 m_bdtThresholds[
index] = bdtThresholdPtr;
65 m_etThreshold = etThreshold;
69 unsigned int *maxEtThreshold) {
70 m_maxEtThreshold = maxEtThreshold;
74 unsigned int *bdtMinEtThreshold) {
75 m_bdtMinEtThreshold = bdtMinEtThreshold;
79 unsigned int *
ptr = 0;
82 ptr = m_em0cells[eta][phi];
85 ptr = m_em1cells[eta][phi];
88 ptr = m_em2cells[eta][phi];
91 ptr = m_em3cells[eta][phi];
94 ptr = m_hadcells[eta][phi];
101 initPointers(m_bdt.getETSCells(), m_eTComputeSCellPointers);
105 initPointers(m_bdt.getEMETSCells(), m_EM_eTComputeSCellPointers);
109 initPointers(m_bdt.getHADETSCells(), m_HAD_eTComputeSCellPointers);
113 std::vector<unsigned int *> &ptr_list) {
115 for (
auto scell : scells) {
118 int layer = scell[2];
119 m_log->msg(
MSG::DEBUG) <<
"\teta=" << eta <<
"\tphi=" << phi
121 unsigned int *
ptr = superCellToPtr(eta, phi,
layer);
124 <<
"Could not convert eta=" << eta <<
" phi=" << phi
125 <<
" layer=" <<
layer
126 <<
" to a pointer to supercell. Are they within range?" <<
endmsg;
127 throw std::domain_error(
130 " to a pointer to supercell. Are they within range?");
132 ptr_list.push_back(
ptr);
137 m_towersComputeSCellPointers.resize(m_bdt.getNTowers());
138 for (
size_t i = 0;
i < m_towers.size();
i++) {
140 initPointers(m_bdt.getTowerSCells(
i), m_towersComputeSCellPointers[
i]);
145 for (
size_t i = 0;
i < m_bdt.getVariables().
size();
i++) {
148 m_log->msg(
MSG::DEBUG) <<
i <<
" is " <<
var.m_name <<
", sum of supercells"
150 std::vector<unsigned int *> pointersToSCells;
151 for (
size_t j = 0; j <
var.m_scells.size(); j++) {
152 int eta =
var.m_scells[j][0];
153 int phi =
var.m_scells[j][1];
155 m_log->msg(
MSG::DEBUG) <<
"\teta=" << eta <<
"\tphi=" << phi
157 unsigned int *
ptr = superCellToPtr(eta, phi,
layer);
160 <<
"Could not convert eta=" << eta <<
" phi=" << phi
161 <<
" layer=" <<
layer
162 <<
" to a pointer to supercell. Are they within range?" <<
endmsg;
163 throw std::domain_error(
166 " to a pointer to supercell. Are they within range?");
168 pointersToSCells.push_back(
ptr);
171 m_bdtVarComputeSCellPointers.push_back(pointersToSCells);
179 computeHADETEstimate();
180 computeEMETEstimate();
181 computeBDTCondition();
182 computeFracCondition();
183 computeIsCentralTowerSeed();
187 std::string bdtVariables =
"";
188 for (
size_t i = 0;
i < m_bdtVars.size();
i++) {
197 for (
size_t i = 0;
i < m_bdtVarComputeSCellPointers.size();
i++) {
199 m_bdtVars[
i] = computeEstimate(m_bdtVarComputeSCellPointers[
i], overflow,
205 debugPrintBDTVariables();
206 m_bdtVarsComputed =
true;
211 if (m_bdtVarsComputed ==
false) {
213 <<
"BDT Variables not computed. BDT score will be garbage." <<
endmsg;
216 m_bdtScore = m_bdt.getBDT().decision_function(m_bdtVars)[0];
221 m_eTEstimate = computeEstimate(m_eTComputeSCellPointers, m_eTEstimateOverflow,
227 m_EM_eTEstimate = computeEstimate(m_EM_eTComputeSCellPointers,
233 m_HAD_eTEstimate = computeEstimate(m_HAD_eTComputeSCellPointers,
235 m_log->msg(
MSG::DEBUG) <<
"HAD ET Estimate: " << m_HAD_eTEstimate <<
endmsg;
240 for (
int eta = 0; eta < 3; eta++) {
241 for (
int phi = 0; phi < 3; phi++) {
242 int flatIndex = flatTowerIndex(eta, phi);
244 <<
"Tower " << flatIndex <<
" ET (eta=" << eta <<
", phi=" << phi
245 <<
"): " << m_towers[flatIndex] <<
endmsg;
253 for (
size_t i = 0;
i < m_towers.size();
i++) {
255 m_towers[
i] = computeEstimate(m_towersComputeSCellPointers[
i], overflow,
266 if ((
number >> nBits) != 0) {
274 bool &overflow,
int resultNBits) {
277 for (
unsigned int *
it : ptr_list) {
279 if (isOverflow(
estimate, resultNBits)) {
300 overflow = isOverflow(
result, resultNBits);
307 if ((
number >> (totalNBits -
by)) != 0) {
308 return (1 << totalNBits) - 1;
314 int n_multipliers =
sizeof(m_fracMultipliers) /
sizeof(m_fracMultipliers[0]);
316 if ((m_eTEstimate >= *m_maxEtThreshold) or m_eTEstimateOverflow or
317 m_HAD_eTEstimateOverflow) {
319 m_fracCondition = (1 << (n_multipliers - 1)) - 1;
323 if (m_EM_eTEstimateOverflow) {
328 m_hadEstimateShifted = BitLeftShift(m_HAD_eTEstimate, 3,
ENERGY_WIDTH);
330 for (;
i < n_multipliers;
i++) {
333 m_emEtXMultiplier[
i] = multWithOverflow(
334 *(m_fracMultipliers[
i]), m_EM_eTEstimate, overflow,
ENERGY_WIDTH);
335 m_emEtXMultiplierOverflow[
i] = (
int)overflow;
337 if ((m_hadEstimateShifted < m_emEtXMultiplier[
i]) or
338 m_emEtXMultiplierOverflow[
i]) {
347 int n_thresholds =
sizeof(m_bdtThresholds) /
sizeof(m_bdtThresholds[0]);
349 int toShiftRight = m_bdt.getScorePrecision() -
PARAM_WIDTH;
352 m_bdtScoreShifted = (m_bdtScore >> toShiftRight);
354 if ((m_eTEstimate >= *m_maxEtThreshold) or m_eTEstimateOverflow or
355 m_eTEstimate < *m_bdtMinEtThreshold) {
357 m_bdtCondition = (1 << (n_thresholds - 1)) - 1;
362 for (;
i < n_thresholds;
i++) {
363 if (m_bdtScoreShifted < *(m_bdtThresholds[
i])) {
376 unsigned int centralET = m_towers[4];
380 for (
unsigned int bphi = 0; bphi < 3; bphi++) {
381 int flatIndex = flatTowerIndex(
beta, bphi);
383 if ((
beta == 1) && (bphi == 1)) {
388 if (
beta == 2 || (
beta == 1 && bphi == 2)) {
389 if (centralET <= m_towers[flatIndex]) {
395 else if (
beta == 0 || (
beta == 1 && bphi == 0)) {
396 if (centralET < m_towers[flatIndex]) {
403 if (m_eTEstimate < *m_etThreshold) {
411 if (m_eTEstimateOverflow) {
414 if (m_eTEstimate < *m_etThreshold) {