21 #include <unordered_map>
33 declareInterface<IeFEXFPGA>(
this);
55 return StatusCode::SUCCESS;
64 return StatusCode::SUCCESS;
81 return StatusCode::FAILURE;
92 auto tauAlgoVersion = thr_eTAU.algoVersion();
109 for(
int ieta =
min_eta; ieta < overflow_eta; ieta++) {
110 for(
int iphi = 1; iphi < 9; iphi++) {
136 unsigned int ptMinToTopoCounts = thr_eEM.ptMinToTopoCounts();
148 std::vector<unsigned int> threshReta;
149 threshReta.push_back(iso_loose.reta_fw());
150 threshReta.push_back(iso_medium.reta_fw());
151 threshReta.push_back(iso_tight.reta_fw());
153 std::vector<unsigned int> threshRhad;
154 threshRhad.push_back(iso_loose.rhad_fw());
155 threshRhad.push_back(iso_medium.rhad_fw());
156 threshRhad.push_back(iso_tight.rhad_fw());
158 std::vector<unsigned int> threshWstot;
159 threshWstot.push_back(iso_loose.wstot_fw());
160 threshWstot.push_back(iso_medium.wstot_fw());
161 threshWstot.push_back(iso_tight.wstot_fw());
163 ATH_MSG_DEBUG(
"ieta=" << ieta <<
" loose => reta_fw=" << threshReta[0] <<
", rhad_fw=" << threshRhad[0] <<
", wstot_fw=" << threshWstot[0]);
164 ATH_MSG_DEBUG(
"ieta=" << ieta <<
" medium => reta_fw=" << threshReta[1] <<
", rhad_fw=" << threshRhad[1] <<
", wstot_fw=" << threshWstot[1]);
165 ATH_MSG_DEBUG(
"ieta=" << ieta <<
" tight => reta_fw=" << threshReta[2] <<
", rhad_fw=" << threshRhad[2] <<
", wstot_fw=" << threshWstot[2]);
168 std::vector<unsigned int> RetaCoreEnv;
170 std::vector<unsigned int> RhadEMHad;
172 std::vector<unsigned int> WstotDenNum;
176 unsigned int RetaWP = 0;
177 unsigned int RhadWP = 0;
178 unsigned int WstotWP = 0;
181 unsigned int RetaBitS = 3;
182 unsigned int RhadBitS = 3;
183 unsigned int WstotBitS = 5;
185 unsigned int maxEtCountsEm = thr_eEM.maxEtCounts(
m_eFexStep);
186 if (eEMTobEt >= maxEtCountsEm){
192 SetIsoWP(RetaCoreEnv,threshReta,RetaWP,RetaBitS);
193 SetIsoWP(RhadEMHad,threshRhad,RhadWP,RhadBitS);
194 SetIsoWP(WstotDenNum,threshWstot,WstotWP,WstotBitS);
197 int phi_ind = iphi - 1;
200 uint32_t tobword =
m_eFEXFormTOBsTool->formEmTOBWord(
m_id,eta_ind,phi_ind,RhadWP,WstotWP,RetaWP,seed,und,eEMTobEt,ptMinToTopoCounts, emAlgoVersion);
201 std::vector<uint32_t> xtobwords =
m_eFEXFormTOBsTool->formEmxTOBWords(
m_efexid,
m_id,eta_ind,phi_ind,RhadWP,WstotWP,RetaWP,seed,und,eEMTobEt,ptMinToTopoCounts, emAlgoVersion);
205 tmp_tob->setFPGAID(
m_id);
207 tmp_tob->setEta(ieta);
208 tmp_tob->setPhi(iphi);
209 tmp_tob->setTobword(tobword);
210 tmp_tob->setxTobword0(xtobwords[0]);
211 tmp_tob->setxTobword1(xtobwords[1]);
214 if (inputOutputCollection->
getdooutput() && (tobword != 0) && (eEMTobEt != 0)) {
216 inputOutputCollection->
addEMtob(tobword);
217 inputOutputCollection->
addValue_eg(
"WstotNum", tmp_tob->getWstotNum());
218 inputOutputCollection->
addValue_eg(
"WstotDen", tmp_tob->getWstotDen());
219 inputOutputCollection->
addValue_eg(
"RetaNum", tmp_tob->getRetaCore());
220 inputOutputCollection->
addValue_eg(
"RetaDen", tmp_tob->getRetaEnv());
221 inputOutputCollection->
addValue_eg(
"RhadNum", tmp_tob->getRhadEM());
222 inputOutputCollection->
addValue_eg(
"RhadDen", tmp_tob->getRhadHad());
231 unsigned int em_et = 9999;
234 unsigned int had_et = 9999;
237 inputOutputCollection->
fill_eg();
241 if ( (tobword != 0) && (eEMTobEt != 0) )
m_emTobObjects.push_back(std::move(tmp_tob));
247 for(
int ieta =
min_eta; ieta < overflow_eta; ieta++)
249 for(
int iphi = 1; iphi < 9; iphi++)
272 ATH_MSG_FATAL(
"BDT tau algo and heuristic tau algo should agree on seeding for all TOBs");
273 return StatusCode::FAILURE;
279 unsigned int ptTauMinToTopoCounts = thr_eTAU.ptMinToTopoCounts();
294 std::vector<unsigned int> threshRCore;
295 threshRCore.push_back(iso_loose.rCore_fw());
296 threshRCore.push_back(iso_medium.rCore_fw());
297 threshRCore.push_back(iso_tight.rCore_fw());
299 std::vector<unsigned int> threshRHad;
300 threshRHad.push_back(iso_loose.rHad_fw());
301 threshRHad.push_back(iso_medium.rHad_fw());
302 threshRHad.push_back(iso_tight.rHad_fw());
305 std::vector<unsigned int> rCoreVec;
308 std::vector<unsigned int> rHadVec;
312 unsigned int bdtScore = 0;
313 unsigned int bdtCondition = 0;
314 unsigned int bdtRHadWP = 0;
317 unsigned int rCoreWP = 0;
318 unsigned int rHadWP = 0;
321 unsigned int RcoreBitS = 3;
322 unsigned int RhadBitS = 3;
324 unsigned int maxEtCountsTau = thr_eTAU.maxEtCounts(
m_eFexStep);
325 unsigned int bdtMinEtCounts = thr_eTAU.minIsoEtCounts(
m_eFexStep);
326 if (eTauTobEt >= maxEtCountsTau) {
330 SetIsoWP(rCoreVec,threshRCore,rCoreWP,RcoreBitS);
331 SetIsoWP(rHadVec,threshRHad,rHadWP,RhadBitS);
336 std::vector<unsigned int> threshBDT;
337 threshBDT.push_back(iso_loose.rCore_fw());
338 threshBDT.push_back(iso_medium.rCore_fw());
339 threshBDT.push_back(iso_tight.rCore_fw());
340 m_eFEXtauBDTAlgoTool->setThresholds(threshRHad, threshBDT, ptTauMinToTopoInEfexCounts, maxEtCountsTau, bdtMinEtCounts);
358 int phi_ind = iphi - 1;
361 std::vector<uint32_t> xtobwords;
362 std::vector<uint32_t> xtobwordsBDT;
365 << phi_ind <<
", eTauBDTTobEt: " << eTauBDTTobEt
366 <<
", eTauTobEt: " << eTauTobEt <<
", ptTauMinToTopoCounts: "
367 << ptTauMinToTopoCounts <<
", maxEtCountsTau: " << maxEtCountsTau
368 <<
", bdtScore: " << bdtScore <<
" bdtMinEtCounts: " << bdtMinEtCounts <<
" bdtRHadWP " << bdtRHadWP);
370 uint32_t tobwordBDT =
m_eFEXFormTOBsTool->formTauTOBWord(
m_id, eta_ind, phi_ind, eTauBDTTobEt, bdtRHadWP, bdtCondition, bdtSeed,0, ptTauMinToTopoCounts, tauAlgoVersion);
371 xtobwordsBDT =
m_eFEXFormTOBsTool->formTauxTOBWords(
m_efexid,
m_id, eta_ind, phi_ind, eTauBDTTobEt, bdtRHadWP, bdtCondition, bdtSeed, 0, ptTauMinToTopoCounts, tauAlgoVersion, bdtScore);
373 xtobwords =
m_eFEXFormTOBsTool->formTauxTOBWords(
m_efexid,
m_id, eta_ind, phi_ind, eTauTobEt, rHadWP, rCoreWP, seed, und, ptTauMinToTopoCounts, 0, 0);
376 tmp_tau_tob->setFPGAID(
m_id);
378 tmp_tau_tob->setEta(ieta);
379 tmp_tau_tob->setPhi(iphi);
380 tmp_tau_tob->setTobword(tobword);
381 tmp_tau_tob->setxTobword0(xtobwords[0]);
382 tmp_tau_tob->setxTobword1(xtobwords[1]);
385 tmp_tau_tob_bdt->setFPGAID(
m_id);
386 tmp_tau_tob_bdt->seteFEXID(
m_efexid);
387 tmp_tau_tob_bdt->setEta(ieta);
388 tmp_tau_tob_bdt->setPhi(iphi);
389 tmp_tau_tob_bdt->setTobword(tobwordBDT);
390 tmp_tau_tob_bdt->setxTobword0(xtobwordsBDT[0]);
391 tmp_tau_tob_bdt->setxTobword1(xtobwordsBDT[1]);
394 if ((inputOutputCollection->
getdooutput()) && ( tobword != 0 )) {
404 inputOutputCollection->
addValue_tau(
"OneOffEtaTowerEt", oneOffEtaTower ? oneOffEtaTower->
getTotalET() : 0);
405 inputOutputCollection->
addValue_tau(
"OneBelowEtaTowerEt", oneBelowEtaTower ? oneBelowEtaTower->
getTotalET() : 0);
408 inputOutputCollection->
addValue_tau(
"RCoreCore", rCoreVec[0]);
409 inputOutputCollection->
addValue_tau(
"RCoreEnv", rCoreVec[1]);
411 inputOutputCollection->
addValue_tau(
"RCoreWP", rCoreWP);
412 inputOutputCollection->
addValue_tau(
"RHadCore", rHadVec[0]);
413 inputOutputCollection->
addValue_tau(
"RHadEnv", rHadVec[1]);
419 inputOutputCollection->
addValue_tau(
"BDTScore", bdtScore);
420 inputOutputCollection->
addValue_tau(
"BDTCondition", bdtCondition);
434 return StatusCode::SUCCESS;
461 std::vector<std::unique_ptr<eFEXegTOB>> tobsSort;
463 tobsSort.push_back(std::move(j));
469 std::vector<std::unique_ptr<eFEXtauTOB>>
eFEXFPGA::getTauTOBs(std::vector< std::unique_ptr<eFEXtauTOB> >& tauTobObjects)
491 std::vector<std::unique_ptr<eFEXtauTOB>> tobsSort;
492 for(
auto &j : tauTobObjects){
493 tobsSort.push_back(std::move(j));
512 int cols =
sizeof tmp_eTowersIDs_subset[0] /
sizeof tmp_eTowersIDs_subset[0][0];
517 ATH_MSG_DEBUG(
"\n---- eFEXFPGA --------- eFEX (" <<
m_efexid <<
" ----- FPGA (" <<
m_id <<
") IS RESPONSIBLE FOR eTOWERS :");
518 for (
int thisRow=
rows-1; thisRow>=0; thisRow--){
519 for (
int thisCol=0; thisCol<
cols; thisCol++){
535 std::ofstream tower_fpga_efex_map;
536 tower_fpga_efex_map.open (
"./tower_fpga_efex_map.csv", std::ios_base::app);
538 for (
int thisRow=
rows-1; thisRow>=0; thisRow--){
539 for (
int thisCol=0; thisCol<
cols; thisCol++){
543 tower_fpga_efex_map <<
m_efexid <<
"," <<
m_id <<
"," <<
m_eTowersIDs[thisRow][thisCol] <<
"," << tmpTower->
eta() <<
"," << tmpTower->
phi() <<
"\n";
554 void eFEXFPGA::SetIsoWP(
const std::vector<unsigned int>& CoreEnv,
const std::vector<unsigned int>& thresholds,
unsigned int & workingPoint,
unsigned int bitshift)
const {
556 std::unordered_map<unsigned int, unsigned int> bsmap { {3, 8}, {5, 32}};
559 if (CoreEnv[0] > 0xffff) {
564 unsigned int large = CoreEnv[0]*bsmap[bitshift];
565 unsigned int small = CoreEnv[1];
568 if (large > 0xffff ) large = 0xffff;
569 if (small > 0xffff ) small = 0xffff;
572 if (small == 0xffff) {
579 if ( large < small*thresholds[0] ) {
583 if ( large < small*thresholds[1] ) {
587 if ( large < small*thresholds[2] ) {