21 #include <unordered_map>
33 declareInterface<IeFEXFPGA>(
this);
55 return StatusCode::SUCCESS;
64 return StatusCode::SUCCESS;
81 return StatusCode::FAILURE;
105 for(
int ieta =
min_eta; ieta < overflow_eta; ieta++) {
106 for(
int iphi = 1; iphi < 9; iphi++) {
132 unsigned int ptMinToTopoCounts = thr_eEM.ptMinToTopoCounts();
144 std::vector<unsigned int> threshReta;
145 threshReta.push_back(iso_loose.reta_fw());
146 threshReta.push_back(iso_medium.reta_fw());
147 threshReta.push_back(iso_tight.reta_fw());
149 std::vector<unsigned int> threshRhad;
150 threshRhad.push_back(iso_loose.rhad_fw());
151 threshRhad.push_back(iso_medium.rhad_fw());
152 threshRhad.push_back(iso_tight.rhad_fw());
154 std::vector<unsigned int> threshWstot;
155 threshWstot.push_back(iso_loose.wstot_fw());
156 threshWstot.push_back(iso_medium.wstot_fw());
157 threshWstot.push_back(iso_tight.wstot_fw());
159 ATH_MSG_DEBUG(
"ieta=" << ieta <<
" loose => reta_fw=" << threshReta[0] <<
", rhad_fw=" << threshRhad[0] <<
", wstot_fw=" << threshWstot[0]);
160 ATH_MSG_DEBUG(
"ieta=" << ieta <<
" medium => reta_fw=" << threshReta[1] <<
", rhad_fw=" << threshRhad[1] <<
", wstot_fw=" << threshWstot[1]);
161 ATH_MSG_DEBUG(
"ieta=" << ieta <<
" tight => reta_fw=" << threshReta[2] <<
", rhad_fw=" << threshRhad[2] <<
", wstot_fw=" << threshWstot[2]);
164 std::vector<unsigned int> RetaCoreEnv;
166 std::vector<unsigned int> RhadEMHad;
168 std::vector<unsigned int> WstotDenNum;
172 unsigned int RetaWP = 0;
173 unsigned int RhadWP = 0;
174 unsigned int WstotWP = 0;
177 unsigned int RetaBitS = 3;
178 unsigned int RhadBitS = 3;
179 unsigned int WstotBitS = 5;
181 unsigned int maxEtCountsEm = thr_eEM.maxEtCounts(
m_eFexStep);
182 if (eEMTobEt >= maxEtCountsEm){
188 SetIsoWP(RetaCoreEnv,threshReta,RetaWP,RetaBitS);
189 SetIsoWP(RhadEMHad,threshRhad,RhadWP,RhadBitS);
190 SetIsoWP(WstotDenNum,threshWstot,WstotWP,WstotBitS);
193 int phi_ind = iphi - 1;
197 std::vector<uint32_t> xtobwords =
m_eFEXFormTOBsTool->formEmxTOBWords(
m_efexid,
m_id,eta_ind,phi_ind,RhadWP,WstotWP,RetaWP,seed,und,eEMTobEt,ptMinToTopoCounts);
201 tmp_tob->setFPGAID(
m_id);
203 tmp_tob->setEta(ieta);
204 tmp_tob->setPhi(iphi);
205 tmp_tob->setTobword(tobword);
206 tmp_tob->setxTobword0(xtobwords[0]);
207 tmp_tob->setxTobword1(xtobwords[1]);
210 if (inputOutputCollection->
getdooutput() && (tobword != 0) && (eEMTobEt != 0)) {
212 inputOutputCollection->
addEMtob(tobword);
213 inputOutputCollection->
addValue_eg(
"WstotNum", tmp_tob->getWstotNum());
214 inputOutputCollection->
addValue_eg(
"WstotDen", tmp_tob->getWstotDen());
215 inputOutputCollection->
addValue_eg(
"RetaNum", tmp_tob->getRetaCore());
216 inputOutputCollection->
addValue_eg(
"RetaDen", tmp_tob->getRetaEnv());
217 inputOutputCollection->
addValue_eg(
"RhadNum", tmp_tob->getRhadEM());
218 inputOutputCollection->
addValue_eg(
"RhadDen", tmp_tob->getRhadHad());
227 unsigned int em_et = 9999;
230 unsigned int had_et = 9999;
233 inputOutputCollection->
fill_eg();
237 if ( (tobword != 0) && (eEMTobEt != 0) )
m_emTobObjects.push_back(std::move(tmp_tob));
243 for(
int ieta =
min_eta; ieta < overflow_eta; ieta++)
245 for(
int iphi = 1; iphi < 9; iphi++)
268 ATH_MSG_FATAL(
"BDT tau algo and heuristic tau algo should agree on seeding for all TOBs");
269 return StatusCode::FAILURE;
275 unsigned int ptTauMinToTopoCounts = thr_eTAU.ptMinToTopoCounts();
290 std::vector<unsigned int> threshRCore;
291 threshRCore.push_back(iso_loose.rCore_fw());
292 threshRCore.push_back(iso_medium.rCore_fw());
293 threshRCore.push_back(iso_tight.rCore_fw());
295 std::vector<unsigned int> threshRHad;
296 threshRHad.push_back(iso_loose.rHad_fw());
297 threshRHad.push_back(iso_medium.rHad_fw());
298 threshRHad.push_back(iso_tight.rHad_fw());
301 std::vector<unsigned int> rCoreVec;
304 std::vector<unsigned int> rHadVec;
308 unsigned int bdtScore = 0;
309 unsigned int bdtCondition = 0;
310 unsigned int bdtRHadWP = 0;
313 unsigned int rCoreWP = 0;
314 unsigned int rHadWP = 0;
317 unsigned int RcoreBitS = 3;
318 unsigned int RhadBitS = 3;
320 unsigned int maxEtCountsTau = thr_eTAU.maxEtCounts(
m_eFexStep);
321 unsigned int bdtMinEtCounts = thr_eTAU.minIsoEtCounts(
m_eFexStep);
322 if (eTauTobEt >= maxEtCountsTau) {
326 SetIsoWP(rCoreVec,threshRCore,rCoreWP,RcoreBitS);
327 SetIsoWP(rHadVec,threshRHad,rHadWP,RhadBitS);
332 std::vector<unsigned int> threshBDT;
333 threshBDT.push_back(iso_loose.rCore_fw());
334 threshBDT.push_back(iso_medium.rCore_fw());
335 threshBDT.push_back(iso_tight.rCore_fw());
336 m_eFEXtauBDTAlgoTool->setThresholds(threshRHad, threshBDT, ptTauMinToTopoInEfexCounts, maxEtCountsTau, bdtMinEtCounts);
354 int phi_ind = iphi - 1;
357 std::vector<uint32_t> xtobwords;
358 std::vector<uint32_t> xtobwordsBDT;
361 << phi_ind <<
", eTauBDTTobEt: " << eTauBDTTobEt
362 <<
", eTauTobEt: " << eTauTobEt <<
", ptTauMinToTopoCounts: "
363 << ptTauMinToTopoCounts <<
", maxEtCountsTau: " << maxEtCountsTau
364 <<
", bdtScore: " << bdtScore <<
" bdtMinEtCounts: " << bdtMinEtCounts <<
" bdtRHadWP " << bdtRHadWP);
366 uint32_t tobwordBDT =
m_eFEXFormTOBsTool->formTauBDTTOBWord(
m_id, eta_ind, phi_ind, eTauBDTTobEt, bdtRHadWP, bdtCondition, bdtSeed, ptTauMinToTopoCounts);
367 xtobwordsBDT =
m_eFEXFormTOBsTool->formTauBDTxTOBWords(
m_efexid,
m_id, eta_ind, phi_ind, eTauBDTTobEt, bdtRHadWP, bdtCondition, bdtSeed, ptTauMinToTopoCounts, bdtScore);
372 tmp_tau_tob->setFPGAID(
m_id);
374 tmp_tau_tob->setEta(ieta);
375 tmp_tau_tob->setPhi(iphi);
376 tmp_tau_tob->setTobword(tobword);
377 tmp_tau_tob->setxTobword0(xtobwords[0]);
378 tmp_tau_tob->setxTobword1(xtobwords[1]);
381 tmp_tau_tob_bdt->setFPGAID(
m_id);
382 tmp_tau_tob_bdt->seteFEXID(
m_efexid);
383 tmp_tau_tob_bdt->setEta(ieta);
384 tmp_tau_tob_bdt->setPhi(iphi);
385 tmp_tau_tob_bdt->setTobword(tobwordBDT);
386 tmp_tau_tob_bdt->setxTobword0(xtobwordsBDT[0]);
387 tmp_tau_tob_bdt->setxTobword1(xtobwordsBDT[1]);
390 if ((inputOutputCollection->
getdooutput()) && ( tobword != 0 )) {
400 inputOutputCollection->
addValue_tau(
"OneOffEtaTowerEt", oneOffEtaTower ? oneOffEtaTower->
getTotalET() : 0);
401 inputOutputCollection->
addValue_tau(
"OneBelowEtaTowerEt", oneBelowEtaTower ? oneBelowEtaTower->
getTotalET() : 0);
404 inputOutputCollection->
addValue_tau(
"RCoreCore", rCoreVec[0]);
405 inputOutputCollection->
addValue_tau(
"RCoreEnv", rCoreVec[1]);
407 inputOutputCollection->
addValue_tau(
"RCoreWP", rCoreWP);
408 inputOutputCollection->
addValue_tau(
"RHadCore", rHadVec[0]);
409 inputOutputCollection->
addValue_tau(
"RHadEnv", rHadVec[1]);
415 inputOutputCollection->
addValue_tau(
"BDTScore", bdtScore);
416 inputOutputCollection->
addValue_tau(
"BDTCondition", bdtCondition);
430 return StatusCode::SUCCESS;
457 std::vector<std::unique_ptr<eFEXegTOB>> tobsSort;
459 tobsSort.push_back(std::move(j));
465 std::vector<std::unique_ptr<eFEXtauTOB>>
eFEXFPGA::getTauTOBs(std::vector< std::unique_ptr<eFEXtauTOB> >& tauTobObjects)
487 std::vector<std::unique_ptr<eFEXtauTOB>> tobsSort;
488 for(
auto &j : tauTobObjects){
489 tobsSort.push_back(std::move(j));
508 int cols =
sizeof tmp_eTowersIDs_subset[0] /
sizeof tmp_eTowersIDs_subset[0][0];
513 ATH_MSG_DEBUG(
"\n---- eFEXFPGA --------- eFEX (" <<
m_efexid <<
" ----- FPGA (" <<
m_id <<
") IS RESPONSIBLE FOR eTOWERS :");
514 for (
int thisRow=
rows-1; thisRow>=0; thisRow--){
515 for (
int thisCol=0; thisCol<
cols; thisCol++){
531 std::ofstream tower_fpga_efex_map;
532 tower_fpga_efex_map.open (
"./tower_fpga_efex_map.csv", std::ios_base::app);
534 for (
int thisRow=
rows-1; thisRow>=0; thisRow--){
535 for (
int thisCol=0; thisCol<
cols; thisCol++){
539 tower_fpga_efex_map <<
m_efexid <<
"," <<
m_id <<
"," <<
m_eTowersIDs[thisRow][thisCol] <<
"," << tmpTower->
eta() <<
"," << tmpTower->
phi() <<
"\n";
550 void eFEXFPGA::SetIsoWP(
const std::vector<unsigned int>& CoreEnv,
const std::vector<unsigned int>& thresholds,
unsigned int & workingPoint,
unsigned int bitshift)
const {
552 std::unordered_map<unsigned int, unsigned int> bsmap { {3, 8}, {5, 32}};
555 if (CoreEnv[0] > 0xffff) {
560 unsigned int large = CoreEnv[0]*bsmap[bitshift];
561 unsigned int small = CoreEnv[1];
564 if (large > 0xffff ) large = 0xffff;
565 if (small > 0xffff ) small = 0xffff;
568 if (small == 0xffff) {
575 if ( large < small*thresholds[0] ) {
579 if ( large < small*thresholds[1] ) {
583 if ( large < small*thresholds[2] ) {