16 #define ENERGY_WIDTH 16
21 : m_bdt(config_path), m_log(
log) {
35 unsigned int *sCellPtr) {
38 m_em0cells[
eta][
phi] = sCellPtr;
41 m_em1cells[
eta][
phi] = sCellPtr;
44 m_em2cells[
eta][
phi] = sCellPtr;
47 m_em3cells[
eta][
phi] = sCellPtr;
50 m_hadcells[
eta][
phi] = sCellPtr;
56 int index,
unsigned int *fracMultiplierPtr) {
57 m_fracMultipliers[
index] = fracMultiplierPtr;
61 int index,
unsigned int *bdtThresholdPtr) {
62 m_bdtThresholds[
index] = bdtThresholdPtr;
66 m_etThreshold = etThreshold;
70 unsigned int *maxEtThreshold) {
71 m_maxEtThreshold = maxEtThreshold;
75 unsigned int *bdtMinEtThreshold) {
76 m_bdtMinEtThreshold = bdtMinEtThreshold;
80 unsigned int *ptr = 0;
83 ptr = m_em0cells[
eta][
phi];
86 ptr = m_em1cells[
eta][
phi];
89 ptr = m_em2cells[
eta][
phi];
92 ptr = m_em3cells[
eta][
phi];
95 ptr = m_hadcells[
eta][
phi];
102 initPointers(m_bdt.getETSCells(), m_eTComputeSCellPointers);
106 initPointers(m_bdt.getEMETSCells(), m_EM_eTComputeSCellPointers);
110 initPointers(m_bdt.getHADETSCells(), m_HAD_eTComputeSCellPointers);
114 std::vector<unsigned int *> &ptr_list) {
116 for (
auto scell : scells) {
119 int layer = scell[2];
122 unsigned int *ptr = superCellToPtr(
eta,
phi,
layer);
125 <<
"Could not convert eta=" <<
eta <<
" phi=" <<
phi
126 <<
" layer=" <<
layer
127 <<
" to a pointer to supercell. Are they within range?" <<
endmsg;
128 throw std::domain_error(
131 " to a pointer to supercell. Are they within range?");
133 ptr_list.push_back(ptr);
138 m_towersComputeSCellPointers.resize(m_bdt.getNTowers());
139 for (
size_t i = 0;
i < m_towers.size();
i++) {
141 initPointers(m_bdt.getTowerSCells(
i), m_towersComputeSCellPointers[
i]);
146 for (
size_t i = 0;
i < m_bdt.getVariables().
size();
i++) {
149 m_log->msg(
MSG::DEBUG) <<
i <<
" is " <<
var.m_name <<
", sum of supercells"
151 std::vector<unsigned int *> pointersToSCells;
152 for (
size_t j = 0; j <
var.m_scells.size(); j++) {
153 int eta =
var.m_scells[j][0];
154 int phi =
var.m_scells[j][1];
158 unsigned int *ptr = superCellToPtr(
eta,
phi,
layer);
161 <<
"Could not convert eta=" <<
eta <<
" phi=" <<
phi
162 <<
" layer=" <<
layer
163 <<
" to a pointer to supercell. Are they within range?" <<
endmsg;
164 throw std::domain_error(
167 " to a pointer to supercell. Are they within range?");
169 pointersToSCells.push_back(ptr);
172 m_bdtVarComputeSCellPointers.push_back(pointersToSCells);
180 computeHADETEstimate();
181 computeEMETEstimate();
182 computeBDTCondition();
183 computeFracCondition();
184 computeIsCentralTowerSeed();
189 std::string scellValues =
"";
190 std::string em0Values =
"";
191 std::string em1Values =
"";
192 std::string em2Values =
"";
193 std::string em3Values =
"";
194 std::string hadValues =
"";
195 for (
size_t i = 0;
i < LVL1::locMap.size();
i++) {
196 int eta = LVL1::locMap[
i][0];
197 int phi = LVL1::locMap[
i][1];
198 int layer = LVL1::locMap[
i][2];
228 std::string bdtVariables =
"";
229 for (
size_t i = 0;
i < m_bdtVars.size();
i++) {
238 debugPrintSCellValues();
239 for (
size_t i = 0;
i < m_bdtVarComputeSCellPointers.size();
i++) {
241 m_bdtVars[
i] = computeEstimate(m_bdtVarComputeSCellPointers[
i], overflow,
247 debugPrintBDTVariables();
248 m_bdtVarsComputed =
true;
253 if (m_bdtVarsComputed ==
false) {
255 <<
"BDT Variables not computed. BDT score will be garbage." <<
endmsg;
258 m_bdtScore = m_bdt.getBDT().decision_function(m_bdtVars)[0];
263 m_eTEstimate = computeEstimate(m_eTComputeSCellPointers, m_eTEstimateOverflow,
269 m_EM_eTEstimate = computeEstimate(m_EM_eTComputeSCellPointers,
275 m_HAD_eTEstimate = computeEstimate(m_HAD_eTComputeSCellPointers,
277 m_log->msg(
MSG::DEBUG) <<
"HAD ET Estimate: " << m_HAD_eTEstimate <<
endmsg;
284 int flatIndex = flatTowerIndex(
eta,
phi);
286 <<
"Tower " << flatIndex <<
" ET (eta=" <<
eta <<
", phi=" <<
phi
287 <<
"): " << m_towers[flatIndex] <<
endmsg;
295 for (
size_t i = 0;
i < m_towers.size();
i++) {
297 m_towers[
i] = computeEstimate(m_towersComputeSCellPointers[
i], overflow,
308 if ((
number >> nBits) != 0) {
316 bool &overflow,
int resultNBits) {
319 for (
unsigned int *
it : ptr_list) {
321 if (isOverflow(
estimate, resultNBits)) {
342 overflow = isOverflow(
result, resultNBits);
349 if ((
number >> (totalNBits -
by)) != 0) {
350 return (1 << totalNBits) - 1;
356 int n_multipliers =
sizeof(m_fracMultipliers) /
sizeof(m_fracMultipliers[0]);
358 if ((m_eTEstimate >= *m_maxEtThreshold) or m_eTEstimateOverflow or
359 m_HAD_eTEstimateOverflow) {
361 m_fracCondition = (1 << (n_multipliers - 1)) - 1;
365 if (m_EM_eTEstimateOverflow) {
370 m_hadEstimateShifted = BitLeftShift(m_HAD_eTEstimate, 3,
ENERGY_WIDTH);
372 for (;
i < n_multipliers;
i++) {
375 m_emEtXMultiplier[
i] = multWithOverflow(
376 *(m_fracMultipliers[
i]), m_EM_eTEstimate, overflow,
ENERGY_WIDTH);
377 m_emEtXMultiplierOverflow[
i] = (
int)overflow;
379 if ((m_hadEstimateShifted < m_emEtXMultiplier[
i]) or
380 m_emEtXMultiplierOverflow[
i]) {
389 int n_thresholds =
sizeof(m_bdtThresholds) /
sizeof(m_bdtThresholds[0]);
391 int toShiftRight = m_bdt.getScorePrecision() -
PARAM_WIDTH;
394 m_bdtScoreShifted = (m_bdtScore >> toShiftRight);
396 if ((m_eTEstimate >= *m_maxEtThreshold) or m_eTEstimateOverflow or
397 m_eTEstimate < *m_bdtMinEtThreshold) {
399 m_bdtCondition = (1 << (n_thresholds - 1)) - 1;
404 for (;
i < n_thresholds;
i++) {
405 if (m_bdtScoreShifted < *(m_bdtThresholds[
i])) {
418 unsigned int centralET = m_towers[4];
422 for (
unsigned int bphi = 0; bphi < 3; bphi++) {
423 int flatIndex = flatTowerIndex(
beta, bphi);
425 if ((
beta == 1) && (bphi == 1)) {
430 if (
beta == 2 || (
beta == 1 && bphi == 2)) {
431 if (centralET <= m_towers[flatIndex]) {
437 else if (
beta == 0 || (
beta == 1 && bphi == 0)) {
438 if (centralET < m_towers[flatIndex]) {
445 if (m_eTEstimate < *m_etThreshold) {
453 if (m_eTEstimateOverflow) {
456 if (m_eTEstimate < *m_etThreshold) {