Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
eFEXFPGA.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //***************************************************************************
6 // eFEXFPGA - description
7 // -------------------
8 // begin : 15 10 2019
9 // email : jacob.julian.kempster@cern.ch
10 // ***************************************************************************/
11 #include "L1CaloFEXSim/eFEXFPGA.h"
14 #include "L1CaloFEXSim/eFEXegTOB.h"
18 #include <vector>
19 #include "StoreGate/ReadHandle.h"
20 #include "TrigConfData/L1Menu.h"
21 #include <unordered_map>
22 
23 #include <iostream>
24 #include <fstream>
25 
26 namespace LVL1 {
27 
28  // default constructor for persistency
29 
30 eFEXFPGA::eFEXFPGA(const std::string& type,const std::string& name,const IInterface* parent):
32 {
33  declareInterface<IeFEXFPGA>(this);
34 }
35 
36 
39  {
40  }
41 
42 //---------------- Initialisation -------------------------------------------------
43 
45 {
46 
48  ATH_CHECK( m_eFEXegAlgoTool.retrieve() );
49  ATH_CHECK( m_eFEXtauAlgoTool.retrieve() );
50  ATH_CHECK( m_eFEXtauBDTAlgoTool.retrieve() );
51 
52 
54 
55  return StatusCode::SUCCESS;
56 }
57 
58 
59 StatusCode eFEXFPGA::init(int id, int efexid)
60 {
61  m_id = id;
62  m_efexid = efexid;
63 
64  return StatusCode::SUCCESS;
65 }
66 
68 
69  m_id = -1;
70  m_efexid = -1;
71 }
72 
74  m_emTobObjects.clear();
76  m_tauBDTTobObjects.clear();
77 
79  if(!eTowerContainer.isValid()){
80  ATH_MSG_FATAL("Could not retrieve container " << m_eTowerContainerKey.key() );
81  return StatusCode::FAILURE;
82  }
83 
84  // Retrieve the L1 menu configuration
86  ATH_CHECK(l1Menu.isValid());
87 
88  auto & thr_eEM = l1Menu->thrExtraInfo().eEM();
89  auto & thr_eTAU = l1Menu->thrExtraInfo().eTAU();
90 
91  auto emAlgoVersion = thr_eEM.algoVersion();
92  auto tauAlgoVersion = thr_eTAU.algoVersion();
93 
94 
95  // Define eta range to consider extra towers in edge cases
96  int min_eta;
97  int overflow_eta;
98  if ((m_efexid%3 == 0) && (m_id == 0)) {
99  min_eta = 0;
100  } else {
101  min_eta = 1;
102  }
103  if ((m_efexid%3 == 2) && (m_id == 3)) {
104  overflow_eta = 6;
105  } else {
106  overflow_eta = 5;
107  }
108 
109  for(int ieta = min_eta; ieta < overflow_eta; ieta++) {
110  for(int iphi = 1; iphi < 9; iphi++) {
111 
112  int tobtable[3][3]={
113  {ieta > 0 ? m_eTowersIDs[iphi-1][ieta-1] : 0,
114  m_eTowersIDs[iphi-1][ieta],
115  ieta < 5 ? m_eTowersIDs[iphi-1][ieta+1] : 0},
116 
117  {ieta > 0 ? m_eTowersIDs[iphi][ieta-1] : 0,
118  m_eTowersIDs[iphi][ieta],
119  ieta < 5 ? m_eTowersIDs[iphi][ieta+1] : 0},
120 
121  {ieta > 0 ? m_eTowersIDs[iphi+1][ieta-1] : 0,
122  m_eTowersIDs[iphi+1][ieta],
123  ieta < 5 ? m_eTowersIDs[iphi+1][ieta+1] : 0},
124  };
125 
126 
127  ATH_CHECK( m_eFEXegAlgoTool->safetyTest() );
128  m_eFEXegAlgoTool->setup(tobtable, m_efexid, m_id, ieta);
129 
130  // ignore any tobs without a seed, move on to the next window
131  if (m_eFEXegAlgoTool->hasSeed() == false) continue;
132  unsigned int seed = m_eFEXegAlgoTool->getSeed();
133  unsigned int und = (m_eFEXegAlgoTool->getUnD() ? 1 : 0);
134 
135  // the minimum energy to send to topo (not eta dependent yet, but keep inside loop as it will be eventually?)
136  unsigned int ptMinToTopoCounts = thr_eEM.ptMinToTopoCounts();
137 
138  //returns a unsigned integer et value corresponding to the... eFEX EM cluster in 25 MeV internal calculation scale
139  unsigned int eEMTobEt = m_eFEXegAlgoTool->getET();
140 
141  // thresholds from Trigger menu
142  // the menu eta runs from -25 to 24
143  int menuEta = m_id*4 + (m_efexid%3)*16 + ieta - 25;
144  auto iso_loose = thr_eEM.isolation(TrigConf::Selection::WP::LOOSE, menuEta);
145  auto iso_medium = thr_eEM.isolation(TrigConf::Selection::WP::MEDIUM, menuEta);
146  auto iso_tight = thr_eEM.isolation(TrigConf::Selection::WP::TIGHT, menuEta);
147 
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());
152 
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());
157 
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());
162 
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]);
166 
167  // Get Reta and Rhad outputs
168  std::vector<unsigned int> RetaCoreEnv;
169  m_eFEXegAlgoTool->getReta(RetaCoreEnv);
170  std::vector<unsigned int> RhadEMHad;
171  m_eFEXegAlgoTool->getRhad(RhadEMHad);
172  std::vector<unsigned int> WstotDenNum;
173  m_eFEXegAlgoTool->getWstot(WstotDenNum);
174 
175  // Set Reta, Rhad and Wstot WP
176  unsigned int RetaWP = 0;
177  unsigned int RhadWP = 0;
178  unsigned int WstotWP = 0;
179 
180  // bitshifts for the different iso vars
181  unsigned int RetaBitS = 3;
182  unsigned int RhadBitS = 3;
183  unsigned int WstotBitS = 5;
184 
185  unsigned int maxEtCountsEm = thr_eEM.maxEtCounts(m_eFexStep);
186  if (eEMTobEt >= maxEtCountsEm){
187  RetaWP = 3;
188  RhadWP = 3;
189  WstotWP = 3;
190  }
191  else{
192  SetIsoWP(RetaCoreEnv,threshReta,RetaWP,RetaBitS);
193  SetIsoWP(RhadEMHad,threshRhad,RhadWP,RhadBitS);
194  SetIsoWP(WstotDenNum,threshWstot,WstotWP,WstotBitS);
195  }
196  int eta_ind = ieta; // No need to offset eta index with new 0-5 convention
197  int phi_ind = iphi - 1;
198 
199  //form the egamma tob word and xTOB words
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);
202 
203  std::unique_ptr<eFEXegTOB> tmp_tob = m_eFEXegAlgoTool->geteFEXegTOB();
204 
205  tmp_tob->setFPGAID(m_id);
206  tmp_tob->seteFEXID(m_efexid);
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]);
212 
213  // for plotting
214  if (inputOutputCollection->getdooutput() && (tobword != 0) && (eEMTobEt != 0)) {
215  inputOutputCollection->addeFexNumber(m_efexid);
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());
223  inputOutputCollection->addValue_eg("haveSeed", m_eFEXegAlgoTool->hasSeed());
224  inputOutputCollection->addValue_eg("ET", m_eFEXegAlgoTool->getET());
225  float eta = 9999;
226  m_eFEXegAlgoTool->getRealEta(eta);
227  inputOutputCollection->addValue_eg("eta", eta);
228  float phi = 9999;
229  m_eFEXegAlgoTool->getRealPhi(phi);
230  inputOutputCollection->addValue_eg("phi", phi);
231  unsigned int em_et = 9999;
232  m_eFEXegAlgoTool->getCoreEMTowerET(em_et);
233  inputOutputCollection->addValue_eg("em", em_et);
234  unsigned int had_et = 9999;
235  m_eFEXegAlgoTool->getCoreHADTowerET(had_et);
236  inputOutputCollection->addValue_eg("had", had_et);
237  inputOutputCollection->fill_eg();
238  }
239 
240  // Now we've finished with that object we can move it into the class results store
241  if ( (tobword != 0) && (eEMTobEt != 0) ) m_emTobObjects.push_back(std::move(tmp_tob));
242 
243  }
244  }
245 
246  // --------------- TAU -------------
247  for(int ieta = min_eta; ieta < overflow_eta; ieta++)
248  {
249  for(int iphi = 1; iphi < 9; iphi++)
250  {
251  int tobtable[3][3]={
252  {ieta > 0 ? m_eTowersIDs[iphi-1][ieta-1] : 0,
253  m_eTowersIDs[iphi-1][ieta],
254  ieta < 5 ? m_eTowersIDs[iphi-1][ieta+1] : 0},
255 
256  {ieta > 0 ? m_eTowersIDs[iphi][ieta-1] : 0,
257  m_eTowersIDs[iphi][ieta],
258  ieta < 5 ? m_eTowersIDs[iphi][ieta+1] : 0},
259 
260  {ieta > 0 ? m_eTowersIDs[iphi+1][ieta-1] : 0,
261  m_eTowersIDs[iphi+1][ieta],
262  ieta < 5 ? m_eTowersIDs[iphi+1][ieta+1] : 0},
263  };
264 
265  ATH_CHECK( m_eFEXtauAlgoTool->safetyTest() );
266  ATH_CHECK( m_eFEXtauBDTAlgoTool->safetyTest() );
267  m_eFEXtauAlgoTool->setup(tobtable, m_efexid, m_id, ieta);
268  m_eFEXtauBDTAlgoTool->setup(tobtable, m_efexid, m_id, ieta);
269 
270  if ( m_eFEXtauAlgoTool->isCentralTowerSeed() != m_eFEXtauBDTAlgoTool->isCentralTowerSeed() )
271  {
272  ATH_MSG_FATAL("BDT tau algo and heuristic tau algo should agree on seeding for all TOBs");
273  return StatusCode::FAILURE;
274  }
275 
276  if (!m_eFEXtauAlgoTool->isCentralTowerSeed()){ continue; }
277 
278  // the minimum energy to send to topo (not eta dependent yet, but keep inside loop as it will be eventually?)
279  unsigned int ptTauMinToTopoCounts = thr_eTAU.ptMinToTopoCounts();
280 
281  unsigned int ptTauMinToTopoInEfexCounts = TrigConf::energyInCounts(thr_eTAU.ptMinToTopoMeV(), m_eFexStep);
282 
283  // Get Et of eFEX tau object in internal units (25 MeV)
284  unsigned int eTauTobEt = m_eFEXtauAlgoTool->getEt();
285  unsigned int eTauBDTTobEt = m_eFEXtauBDTAlgoTool->getEt();
286 
287  // thresholds from Trigger menu
288  // the menu eta runs from -25 to 24
289  int menuEta = m_id*4 + (m_efexid%3)*16 + ieta - 25;
290  auto iso_loose = thr_eTAU.isolation(TrigConf::Selection::WP::LOOSE, menuEta);
291  auto iso_medium = thr_eTAU.isolation(TrigConf::Selection::WP::MEDIUM, menuEta);
292  auto iso_tight = thr_eTAU.isolation(TrigConf::Selection::WP::TIGHT, menuEta);
293 
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());
298 
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());
303 
304  // Get isolation values
305  std::vector<unsigned int> rCoreVec;
306  m_eFEXtauAlgoTool->getRCore(rCoreVec);
307 
308  std::vector<unsigned int> rHadVec;
309  m_eFEXtauAlgoTool->getRHad(rHadVec);
310 
311  // BDT-based tau algorithm outputs (both 0 for heuristic algorithm)
312  unsigned int bdtScore = 0;
313  unsigned int bdtCondition = 0;
314  unsigned int bdtRHadWP = 0;
315 
316  // Set isolation WP
317  unsigned int rCoreWP = 0;
318  unsigned int rHadWP = 0;
319 
320  // Isolation bitshift value
321  unsigned int RcoreBitS = 3;
322  unsigned int RhadBitS = 3;
323 
324  unsigned int maxEtCountsTau = thr_eTAU.maxEtCounts(m_eFexStep);
325  unsigned int bdtMinEtCounts = thr_eTAU.minIsoEtCounts(m_eFexStep);
326  if (eTauTobEt >= maxEtCountsTau) {
327  rCoreWP = 3;
328  rHadWP = 3;
329  } else {
330  SetIsoWP(rCoreVec,threshRCore,rCoreWP,RcoreBitS);
331  SetIsoWP(rHadVec,threshRHad,rHadWP,RhadBitS);
332  }
333 
334  // Only one tau algorithm may be active and this is controlled by the L1 menu.
335  // When the BDT algorithm is active, the rCore field contains the BDT L/M/T thresholds.
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);
341  // Re-compute after setting thresholds.
342  // Threshold bits in the BDT algorithm's implementation are computed inside the algorithm class
343  m_eFEXtauBDTAlgoTool->compute();
344  eTauBDTTobEt = m_eFEXtauBDTAlgoTool->getEt();
345  bdtScore = m_eFEXtauBDTAlgoTool->getBDTScore();
346  bdtCondition = m_eFEXtauBDTAlgoTool->getBDTCondition();
347  bdtRHadWP = m_eFEXtauBDTAlgoTool->getBDTHadFracCondition();
348 
349  unsigned int seed = m_eFEXtauAlgoTool->getSeed();
350  // Heuristic seed as returned is supercell value within 3x3 area, here want it within central cell
351  seed = seed - 4;
352 
353  unsigned int und = (m_eFEXtauAlgoTool->getUnD() ? 1 : 0);
354 
355  unsigned int bdtSeed = m_eFEXtauBDTAlgoTool->getSeed();
356 
357  int eta_ind = ieta; // No need to offset eta index with new 0-5 convention
358  int phi_ind = iphi - 1;
359 
360  // Form the tau TOB word and xTOB words
361  std::vector<uint32_t> xtobwords;
362  std::vector<uint32_t> xtobwordsBDT;
363 
364  ATH_MSG_DEBUG("m_id: " << m_id << ", eta_ind: " << eta_ind << ", phi_ind: "
365  << phi_ind << ", eTauBDTTobEt: " << eTauBDTTobEt
366  << ", eTauTobEt: " << eTauTobEt << ", ptTauMinToTopoCounts: "
367  << ptTauMinToTopoCounts << ", maxEtCountsTau: " << maxEtCountsTau
368  << ", bdtScore: " << bdtScore << " bdtMinEtCounts: " << bdtMinEtCounts << " bdtRHadWP " << bdtRHadWP);
369 
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);
372  uint32_t tobword = m_eFEXFormTOBsTool->formTauTOBWord(m_id, eta_ind, phi_ind, eTauTobEt, rHadWP, rCoreWP, seed, und, ptTauMinToTopoCounts, 0);
373  xtobwords = m_eFEXFormTOBsTool->formTauxTOBWords(m_efexid, m_id, eta_ind, phi_ind, eTauTobEt, rHadWP, rCoreWP, seed, und, ptTauMinToTopoCounts, 0, 0);
374 
375  std::unique_ptr<eFEXtauTOB> tmp_tau_tob = m_eFEXtauAlgoTool->getTauTOB();
376  tmp_tau_tob->setFPGAID(m_id);
377  tmp_tau_tob->seteFEXID(m_efexid);
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]);
383 
384  std::unique_ptr<eFEXtauTOB> tmp_tau_tob_bdt = m_eFEXtauBDTAlgoTool->getTauTOB();
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]);
392 
393  // for plotting
394  if ((inputOutputCollection->getdooutput()) && ( tobword != 0 )) {
395  inputOutputCollection->addValue_tau("isCentralTowerSeed", m_eFEXtauAlgoTool->isCentralTowerSeed());
396  inputOutputCollection->addValue_tau("Et", m_eFEXtauAlgoTool->getEt());
397  inputOutputCollection->addValue_tau("EtBDT", m_eFEXtauBDTAlgoTool->getEt());
398  inputOutputCollection->addValue_tau("Eta", ieta);
399  inputOutputCollection->addValue_tau("Phi", iphi);
400  const LVL1::eTower * centerTower = eTowerContainer->findTower(m_eTowersIDs[iphi][ieta]);
401  const LVL1::eTower * oneOffEtaTower = ieta < 5 ? eTowerContainer->findTower(m_eTowersIDs[iphi][ieta+1]) : nullptr;
402  const LVL1::eTower * oneBelowEtaTower = ieta > 0 ? eTowerContainer->findTower(m_eTowersIDs[iphi][ieta-1]) : nullptr;
403  inputOutputCollection->addValue_tau("CenterTowerEt", centerTower->getTotalET());
404  inputOutputCollection->addValue_tau("OneOffEtaTowerEt", oneOffEtaTower ? oneOffEtaTower->getTotalET() : 0);
405  inputOutputCollection->addValue_tau("OneBelowEtaTowerEt", oneBelowEtaTower ? oneBelowEtaTower->getTotalET() : 0);
406  inputOutputCollection->addValue_tau("FloatEta", centerTower->eta() * centerTower->getPosNeg());
407  inputOutputCollection->addValue_tau("FloatPhi", centerTower->phi());
408  inputOutputCollection->addValue_tau("RCoreCore", rCoreVec[0]);
409  inputOutputCollection->addValue_tau("RCoreEnv", rCoreVec[1]);
410  inputOutputCollection->addValue_tau("RealRCore", m_eFEXtauAlgoTool->getRealRCore());
411  inputOutputCollection->addValue_tau("RCoreWP", rCoreWP);
412  inputOutputCollection->addValue_tau("RHadCore", rHadVec[0]);
413  inputOutputCollection->addValue_tau("RHadEnv", rHadVec[1]);
414  inputOutputCollection->addValue_tau("RealRHad", m_eFEXtauAlgoTool->getRealRHad());
415  inputOutputCollection->addValue_tau("RealRHadBDT", m_eFEXtauBDTAlgoTool->getRealRHad());
416  inputOutputCollection->addValue_tau("RHadWP", rHadWP);
417  inputOutputCollection->addValue_tau("Seed", seed);
418  inputOutputCollection->addValue_tau("UnD", und);
419  inputOutputCollection->addValue_tau("BDTScore", bdtScore);
420  inputOutputCollection->addValue_tau("BDTCondition", bdtCondition);
421  inputOutputCollection->addValue_tau("eFEXID", m_efexid);
422  inputOutputCollection->addValue_tau("FPGAID", m_id);
423 
424 
425  inputOutputCollection->fill_tau();
426  }
427  // Now we've finished with that object we can move it into the class results store
428  if ( tobword != 0 ) m_tauHeuristicTobObjects.push_back(std::move(tmp_tau_tob));
429  if ( tobwordBDT != 0 ) m_tauBDTTobObjects.push_back(std::move(tmp_tau_tob_bdt));
430 
431  }
432  }
433 
434  return StatusCode::SUCCESS;
435 }
436 
437 
438 
439 std::vector<std::unique_ptr<eFEXegTOB>> eFEXFPGA::getEmTOBs()
440 {
441  // TOB sorting moved to eFEXSysSim to simplify xTOB production
442  // But leave this here in case more subtle requirement is uncovered in future
443  /*
444  auto tobsSort = m_emTobObjects;
445 
446  ATH_MSG_DEBUG("number of tobs: " <<tobsSort.size() << " in FPGA: " << m_id << " before truncation");
447 
448  // sort tobs by their et (last 12 bits of the 32 bit tob word)
449  std::sort (tobsSort.begin(), tobsSort.end(), TOBetSort<eFEXegTOB>);
450 
451  // return the top 6 highest ET TOBs from the FPGA
452  if (tobsSort.size() > 6) tobsSort.resize(6);
453  return tobsSort;
454  */
455 
456  /* Returning a vector of unique_pointers means this class will lose ownership.
457  This shouldn't be an issue since all this class does is create and return the
458  objects, but you should bear it in mind if you make changes */
459 
460  // This copy seems to be needed - it won't let me pass m_emTobOjects directly (to do with being a class member?)
461  std::vector<std::unique_ptr<eFEXegTOB>> tobsSort;
462  for(auto &j : m_emTobObjects){
463  tobsSort.push_back(std::move(j));
464  }
465 
466  return tobsSort;
467 }
468 
469 std::vector<std::unique_ptr<eFEXtauTOB>> eFEXFPGA::getTauTOBs(std::vector< std::unique_ptr<eFEXtauTOB> >& tauTobObjects)
470 {
471  // TOB sorting moved to eFEXSysSim to simplify xTOB production
472  // But leave this here in case more subtle requirement is uncovered in future
473  /*
474  auto tobsSort = tauTobObjects;
475 
476  ATH_MSG_DEBUG("number of tobs: " <<tobsSort.size() << " in FPGA: " << m_id << " before truncation");
477 
478  // sort tobs by their et (last 12 bits of the 32 bit tob word)
479  std::sort (tobsSort.begin(), tobsSort.end(), TOBetSort<eFEXtauTOB>);
480 
481  // return the top 6 highest ET TOBs from the FPGA
482  if (tobsSort.size() > 6) tobsSort.resize(6);
483  return tobsSort;
484  */
485 
486  /* Returning a vector of unique_pointers means this class will lose ownership.
487  This shouldn't be an issue since all this class does is create and return the
488  objects, but you should bear it in mind if you make changes */
489 
490  // This copy seems to be needed - it won't let me pass m_tauTobOjects directly (to do with being a class member?)
491  std::vector<std::unique_ptr<eFEXtauTOB>> tobsSort;
492  for(auto &j : tauTobObjects){
493  tobsSort.push_back(std::move(j));
494  }
495 
496  return tobsSort;
497 }
498 
499 std::vector<std::unique_ptr<eFEXtauTOB>> eFEXFPGA::getTauHeuristicTOBs()
500 {
502 }
503 
504 std::vector<std::unique_ptr<eFEXtauTOB>> eFEXFPGA::getTauBDTTOBs()
505 {
507 }
508 
509 void eFEXFPGA::SetTowersAndCells_SG(int tmp_eTowersIDs_subset[][6]){
510 
511  int rows = 10;
512  int cols = sizeof tmp_eTowersIDs_subset[0] / sizeof tmp_eTowersIDs_subset[0][0];
513 
514  std::copy(&tmp_eTowersIDs_subset[0][0], &tmp_eTowersIDs_subset[0][0]+(10*6),&m_eTowersIDs[0][0]);
515 
516  if(false){ //this prints out the eTower IDs that each FPGA is responsible for
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++){
520  if(thisCol != cols-1){ ATH_MSG_DEBUG("| " << m_eTowersIDs[thisRow][thisCol] << " "); }
521  else { ATH_MSG_DEBUG("| " << m_eTowersIDs[thisRow][thisCol] << " |"); }
522  }
523  }
524  }
525 
526 
527  //-----------------------------------------------------------
528  // Set up a the second CSV file if necessary (should only need to be done if the mapping changes, which should never happen unless major changes to the simulation are required)
529  if(false){ // CSV CODE TO BE RE-INTRODUCED VERY SOON
531  if(!eTowerContainer.isValid()){
532  ATH_MSG_FATAL("Could not retrieve container " << m_eTowerContainerKey.key() );
533  }
534 
535  std::ofstream tower_fpga_efex_map;
536  tower_fpga_efex_map.open ("./tower_fpga_efex_map.csv", std::ios_base::app);
537 
538  for (int thisRow=rows-1; thisRow>=0; thisRow--){
539  for (int thisCol=0; thisCol<cols; thisCol++){
540 
541  const LVL1::eTower * tmpTower = eTowerContainer->findTower(m_eTowersIDs[thisRow][thisCol]);
542 
543  tower_fpga_efex_map << m_efexid << "," << m_id << "," << m_eTowersIDs[thisRow][thisCol] << "," << tmpTower->eta() << "," << tmpTower->phi() << "\n";
544 
545  }
546  }
547  }
548  //------------------------------------------------------------
549 
550 
551 }
552 
553 
554 void eFEXFPGA::SetIsoWP(const std::vector<unsigned int>& CoreEnv, const std::vector<unsigned int>& thresholds, unsigned int & workingPoint, unsigned int bitshift) const {
555  // Working point evaluted by Core * 2^bitshift > Threshold * Environment conditions
556  std::unordered_map<unsigned int, unsigned int> bsmap { {3, 8}, {5, 32}};
557 
558  // if core (denom) has overflowed, automatically pass all thresholds
559  if (CoreEnv[0] > 0xffff) {
560  workingPoint = 3;
561  return;
562  }
563 
564  unsigned int large = CoreEnv[0]*bsmap[bitshift]; // core
565  unsigned int small = CoreEnv[1]; // env
566 
567  // Word length conditions
568  if (large > 0xffff ) large = 0xffff;
569  if (small > 0xffff ) small = 0xffff;
570 
571  // Fail all if env sum overflows
572  if (small == 0xffff) {
573  workingPoint = 0;
574  return;
575  }
576 
577  // Otherwise test thresholds in firmware order
578  // i.e. check lowest threshold failed rather than highest passed
579  if ( large < small*thresholds[0] ) {
580  workingPoint = 0;
581  return;
582  }
583  if ( large < small*thresholds[1] ) {
584  workingPoint = 1;
585  return;
586  }
587  if ( large < small*thresholds[2] ) {
588  workingPoint = 2;
589  return;
590  }
591  workingPoint = 3;
592  return;
593 }
594 
595 } // end of namespace bracket
TrigConf::Selection::WP::LOOSE
@ LOOSE
eFEXOutputCollection.h
create ntuples output
LVL1::eFEXFPGA::init
virtual StatusCode init(int id, int efexid) override
Definition: eFEXFPGA.cxx:59
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
eTowerContainer.h
LVL1::eFEXFPGA::getTauHeuristicTOBs
virtual std::vector< std::unique_ptr< eFEXtauTOB > > getTauHeuristicTOBs() override
Definition: eFEXFPGA.cxx:499
LVL1::eTower::getTotalET
int getTotalET() const
Get ET sum of all cells in the eTower in MeV.
Definition: eTower.cxx:194
LVL1::eFEXOutputCollection::addValue_eg
void addValue_eg(const std::string &key, float value)
add a value related to the e-gamma algorithm for a TOB
Definition: eFEXOutputCollection.cxx:33
LVL1::eTower
The eTower class is an interface object for eFEX trigger algorithms The purposes are twofold:
Definition: eTower.h:38
LVL1::eFEXFPGA::m_eFEXegAlgoTool
ToolHandle< IeFEXegAlgo > m_eFEXegAlgoTool
Definition: eFEXFPGA.h:92
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
LVL1::eFEXFPGA::getTauTOBs
std::vector< std::unique_ptr< eFEXtauTOB > > getTauTOBs(std::vector< std::unique_ptr< eFEXtauTOB > > &tauTobObjects)
Definition: eFEXFPGA.cxx:469
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
TrigConf::L1ThrExtraInfo::eTAU
const L1ThrExtraInfo_eTAU & eTAU() const
Definition: L1ThrExtraInfo.cxx:133
LVL1::eFEXFPGA::m_eFEXtauBDTAlgoTool
ToolHandle< IeFEXtauAlgo > m_eFEXtauBDTAlgoTool
Definition: eFEXFPGA.h:88
LVL1::eFEXOutputCollection::addeFexNumber
void addeFexNumber(int)
add the eEFX number of a TOB
Definition: eFEXOutputCollection.cxx:77
LVL1::eFEXFPGA::getTauBDTTOBs
virtual std::vector< std::unique_ptr< eFEXtauTOB > > getTauBDTTOBs() override
Definition: eFEXFPGA.cxx:504
eFEXtauTOB.h
TrigConf::L1Menu::thrExtraInfo
const L1ThrExtraInfo & thrExtraInfo() const
Access to extra info for threshold types.
Definition: L1Menu.cxx:307
LVL1::eFEXFPGA::m_id
int m_id
Definition: eFEXFPGA.h:69
LVL1::eTower::getPosNeg
int getPosNeg() const
Definition: eTower.h:121
LVL1::eFEXFPGA::m_tauBDTTobObjects
std::vector< std::unique_ptr< eFEXtauTOB > > m_tauBDTTobObjects
Definition: eFEXFPGA.h:73
TrigConf::L1ThrExtraInfo::eEM
const L1ThrExtraInfo_eEM & eEM() const
Definition: L1ThrExtraInfo.cxx:123
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
LVL1
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
Definition: ICMMCPHitsCnvTool.h:18
LVL1::eFEXFPGA::m_l1MenuKey
SG::ReadHandleKey< TrigConf::L1Menu > m_l1MenuKey
Definition: eFEXFPGA.h:76
LVL1::eFEXFPGA::m_emTobObjects
std::vector< std::unique_ptr< eFEXegTOB > > m_emTobObjects
Definition: eFEXFPGA.h:71
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
LVL1::eFEXFPGA::m_eFEXtauAlgoTool
ToolHandle< IeFEXtauAlgo > m_eFEXtauAlgoTool
Definition: eFEXFPGA.h:84
LVL1::eFEXFPGA::m_eFexStep
const unsigned int m_eFexStep
Internal data.
Definition: eFEXFPGA.h:67
beamspotnt.cols
list cols
Definition: bin/beamspotnt.py:1114
LVL1::eFEXFPGA::~eFEXFPGA
virtual ~eFEXFPGA()
Destructor.
Definition: eFEXFPGA.cxx:38
LVL1::eTower::phi
float phi() const
Definition: eTower.h:65
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
LVL1::eFEXFPGA::m_eFEXFormTOBsTool
ToolHandle< IeFEXFormTOBs > m_eFEXFormTOBsTool
Definition: eFEXFPGA.h:96
eFEXegAlgo.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
LVL1::eFEXFPGA::getEmTOBs
virtual std::vector< std::unique_ptr< eFEXegTOB > > getEmTOBs() override
Definition: eFEXFPGA.cxx:439
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
beamspotnt.rows
list rows
Definition: bin/beamspotnt.py:1112
LVL1::eFEXOutputCollection::fill_tau
void fill_tau()
Save all tau values. Use only after finishing defining all tau values for one TOB.
Definition: eFEXOutputCollection.cxx:50
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
LVL1::eFEXOutputCollection::getdooutput
bool getdooutput() const
return to true if ntuple output is needed
Definition: eFEXOutputCollection.cxx:102
eFEXegTOB.h
LVL1::eTowerContainer
Definition: eTowerContainer.h:35
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TrigConf::name
Definition: HLTChainList.h:35
LVL1::eFEXFPGA::SetTowersAndCells_SG
virtual void SetTowersAndCells_SG(int[][6]) override
Definition: eFEXFPGA.cxx:509
LVL1::eFEXFPGA::m_eTowersIDs
int m_eTowersIDs[10][6]
Definition: eFEXFPGA.h:74
TrigConf::energyInCounts
unsigned int energyInCounts(unsigned int energyMeV, unsigned int energyResolutionMeV)
helper funtion to translate energies into counts
Definition: L1ThresholdBase.cxx:18
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:227
TrigConf::L1ThrExtraInfo_eTAU::algoVersion
unsigned int algoVersion() const
Definition: L1ThrExtraInfo.h:285
LVL1::eFEXFPGA::m_eTowerContainerKey
SG::ReadHandleKey< LVL1::eTowerContainer > m_eTowerContainerKey
Definition: eFEXFPGA.h:80
eFEXFPGA.h
LVL1::eFEXOutputCollection::fill_eg
void fill_eg()
Save all e-gamma values. Use only after finishing defining all e-gamma values for one TOB.
Definition: eFEXOutputCollection.cxx:43
TrigConf::Selection::WP::MEDIUM
@ MEDIUM
TrigConf::Selection::WP::TIGHT
@ TIGHT
LVL1::eFEXFPGA::m_efexid
int m_efexid
Definition: eFEXFPGA.h:70
LVL1::eFEXFPGA::eFEXFPGA
eFEXFPGA(const std::string &type, const std::string &name, const IInterface *parent)
Constructors.
Definition: eFEXFPGA.cxx:30
LVL1::eFEXFPGA::SetIsoWP
virtual void SetIsoWP(const std::vector< unsigned int > &, const std::vector< unsigned int > &, unsigned int &, unsigned int) const override
Definition: eFEXFPGA.cxx:554
module_driven_slicing.min_eta
min_eta
Definition: module_driven_slicing.py:166
LVL1::eTower::eta
float eta() const
Definition: eTower.h:64
calibdata.copy
bool copy
Definition: calibdata.py:27
ReadHandle.h
Handle class for reading from StoreGate.
AthAlgTool
Definition: AthAlgTool.h:26
L1Menu.h
LVL1::eTowerContainer::findTower
const LVL1::eTower * findTower(int towerID) const
fast find method given identifier.
Definition: eTowerContainer.cxx:29
LVL1::eFEXOutputCollection
Definition: eFEXOutputCollection.h:23
LVL1::eFEXFPGA::initialize
virtual StatusCode initialize() override
standard Athena-Algorithm method
Definition: eFEXFPGA.cxx:44
LVL1::eFEXOutputCollection::addValue_tau
void addValue_tau(const std::string &key, float value)
define a value related to the tau algorithm for a TOB
Definition: eFEXOutputCollection.cxx:38
LVL1::eFEXFPGA::execute
virtual StatusCode execute(eFEXOutputCollection *inputOutputCollection) override
Definition: eFEXFPGA.cxx:73
LVL1::eFEXFPGA::reset
virtual void reset() override
Definition: eFEXFPGA.cxx:67
LVL1::eFEXFPGA::m_tauHeuristicTobObjects
std::vector< std::unique_ptr< eFEXtauTOB > > m_tauHeuristicTobObjects
Definition: eFEXFPGA.h:72
LVL1::eFEXOutputCollection::addEMtob
void addEMtob(uint32_t)
add a 32-bit e-gamma TOB word
Definition: eFEXOutputCollection.cxx:87
eFEXtauAlgo.h