ATLAS Offline Software
jFEXtauAlgo.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 //***************************************************************************
5 // jFEXtauAlgo - Algorithm for Tau Algorithm in jFEX
6 // -------------------
7 // begin : 18 02 2021
8 // email : Sergi.Rodriguez@cern.ch
9 //***************************************************************************
10 
11 #include "jFEXtauAlgo.h"
12 #include "L1CaloFEXSim/jTower.h"
15 #include <fstream>
16 #include <sstream>
17 namespace LVL1{
18 
19 //Default Constructor
20 LVL1::jFEXtauAlgo::jFEXtauAlgo(const std::string& type, const std::string& name, const IInterface* parent): AthAlgTool(type, name, parent) {
21  declareInterface<IjFEXtauAlgo>(this);
22 }
23 
26 }
27 
29  ATH_CHECK(m_jTowerContainerKey.initialize());
30 
31  ATH_CHECK(ReadfromFile(PathResolver::find_calib_file(m_IsoRingStr) , m_IsoRingMap ));
32  ATH_CHECK(ReadfromFile(PathResolver::find_calib_file(m_SearchGStr) , m_SearchGMap ));
33  ATH_CHECK(ReadfromFile(PathResolver::find_calib_file(m_SearchGeStr) , m_SearchGeMap ));
34 
35  return StatusCode::SUCCESS;
36 }
37 
38 //calls container for TT
40 
41  m_jTowerContainer = SG::ReadHandle<jTowerContainer>(m_jTowerContainerKey);
42  if(! m_jTowerContainer.isValid()) {
43  ATH_MSG_ERROR("Could not retrieve jTowerContainer " << m_jTowerContainerKey.key());
44  return StatusCode::FAILURE;
45  }
46 
47  return StatusCode::SUCCESS;
48 }
49 
50 void LVL1::jFEXtauAlgo::setup(int seed[3][3]) {
51 
52  ATH_MSG_DEBUG(m_color.BLUE<<"---------------- jFEXtauAlgo::setup ----------------"<<m_color.END);
53 
54  m_TauSaturation = false;
55  for(int phi=0; phi<3; phi++) {
56  for (int eta=0; eta<3; eta++) {
57  m_TTwindow[phi][eta] = seed[2-phi][eta]; // We need to flip the matrix for an increasing phi order: [0, 2Phi]
58  m_TauSaturation = m_TauSaturation || getTTowerSat(seed[2-phi][eta]);
59  }
60  }
61 
62 }
63 
64 //check if central TT is a local maxima
66 
67  m_ClusterEt = 0;
68  int central_seed = getTTowerET(m_TTwindow[1][1]);
69 
70  for (int iphi = 0; iphi < 3; iphi++) {
71  for (int ieta = 0; ieta < 3; ieta++) {
72 
73  int ttEt = getTTowerET(m_TTwindow[iphi][ieta]);
74  m_ClusterEt += ttEt;
75  //avoid comparing central seed to itself
76  if ((iphi == 1) && (ieta == 1)) {
77  continue;
78  }
79  else if( (iphi > ieta) || (iphi==0 && ieta==0) ) { //less than or equal to central
80  if(central_seed<ttEt) {
81  return false;
82  }
83  }
84  else if( (iphi < ieta) || (iphi == 2 && ieta == 2)) { //strictly less than central
85  if(central_seed<=ttEt) {
86  return false;
87  }
88  }
89  }
90  }
91 
92  ATH_MSG_DEBUG("Tau Local Maxima found. with ClusterET = "<<m_ClusterEt);
93  return true;
94 }
95 
97 
98  m_TauSaturation = false;
99 
100  int centreEt = getTTowerET(TTID);
101  m_ClusterEt = centreEt;
102  m_TauSaturation = m_TauSaturation || getTTowerSat(TTID);
103  //centreEt greater than ?
104  auto it_map = m_SearchGMap.find(TTID);
105  if(it_map == m_SearchGMap.end()) {
106  ATH_MSG_ERROR("Could not find TT" << TTID << " in the (greater than) file for Taus.");
107  }
108 
109  for(const auto& lTT : it_map->second){
110  int seachTTET = getTTowerET(lTT);
111  if(centreEt <= seachTTET ){
112  return false;
113  }
114  m_ClusterEt += seachTTET;
115  m_TauSaturation = m_TauSaturation || getTTowerSat(lTT);
116  }
117 
118  //centreEt greater or equal than ?
119  it_map = m_SearchGeMap.find(TTID);
120  if(it_map == m_SearchGeMap.end()) {
121  ATH_MSG_ERROR("Could not find TT" << TTID << " in the (greater or equal than) file for Taus.");
122  }
123 
124  for(const auto& lTT : it_map->second){
125  int seachTTET = getTTowerET(lTT);
126  if(centreEt < seachTTET ){
127  return false;
128  }
129  m_ClusterEt += seachTTET;
130  m_TauSaturation = m_TauSaturation || getTTowerSat(lTT);
131  }
132 
133  // If we never returned false above.. we have a local maxima!
134  //Calculating now all the Tau iso
135 
136  m_TauIsolation = 0;
137  it_map = m_IsoRingMap.find(TTID);
138  if(it_map == m_IsoRingMap.end()) {
139  ATH_MSG_ERROR("Could not find TT" << TTID << " in the isolation file for Taus.");
140  }
141 
142  for(const auto& lTT : it_map->second){
143  m_TauIsolation += getTTowerET(lTT);
144  m_TauSaturation = m_TauSaturation || getTTowerSat(lTT);
145  }
146 
147  return true;
148 }
149 
150 //getter for tower saturation
151 bool LVL1::jFEXtauAlgo::getTTowerSat(unsigned int TTID ) {
152  if(TTID == 0) {
153  return false;
154  }
155 
156  const LVL1::jTower * tmpTower = m_jTowerContainer->findTower(TTID);
157  return tmpTower->getTowerSat();
158 }
159 
160 //Gets the ET for the TT. This ET is EM + HAD
161 int LVL1::jFEXtauAlgo::getTTowerET(unsigned int TTID ) const {
162  if(TTID == 0) {
163  return 0;
164  }
165 
166  auto itr = m_map_Etvalues.find(TTID);
167  if( itr == m_map_Etvalues.end()) {
168  return 0;
169  }
170  return (itr->second).at(0);
171 }
172 
173 //Gets the seed total ET
175  return m_ClusterEt;
176 }
177 
178 //Gets the Isolation/FirstEtRing of jFEX Tau
179 
180 void LVL1::jFEXtauAlgo::setFirstEtRing(int First_ETring[36]) {
181 
182  ATH_MSG_DEBUG("Calculating the jFEXTau ISO");
183 
184  m_TauIsolation=0;
185  for(int i=0; i<36; i++) {
186  m_TauIsolation += getTTowerET(First_ETring[i]);
187  m_TauSaturation = m_TauSaturation || getTTowerSat(First_ETring[i]);
188  }
189 }
190 
192  return m_TauIsolation;
193 }
194 
196  return m_TauSaturation;
197 }
198 
199 void LVL1::jFEXtauAlgo::setFPGAEnergy(const std::unordered_map<int,std::vector<int> >& et_map){
200  m_map_Etvalues=et_map;
201 }
202 
203 
204 StatusCode LVL1::jFEXtauAlgo::ReadfromFile(const std::string & fileName, std::unordered_map<unsigned int, std::vector<unsigned int> >& fillingMap) const {
205 
206  std::string myline;
207 
208  //openning file with ifstream
209  std::ifstream myfile(fileName);
210 
211  if ( !myfile.is_open() ){
212  ATH_MSG_ERROR("Could not open file:" << fileName);
213  return StatusCode::FAILURE;
214  }
215 
216  //loading the mapping information
217  while ( std::getline (myfile, myline) ) {
218 
219  //removing the header of the file (it is just information!)
220  if(myline[0] == '#') continue;
221 
222  //Splitting myline in different substrings
223  std::stringstream oneLine(myline);
224 
225  //reading elements
226  std::vector<unsigned int> elements;
227  std::string element;
228  while(std::getline(oneLine, element, ' '))
229  {
230  elements.push_back(std::stoi(element));
231  }
232 
233  // We should have at least two elements! Central TT and (at least) itself
234  if(elements.size() < 1){
235  ATH_MSG_ERROR("Unexpected number of elemennts (<1 expected) in file: "<< fileName);
236  return StatusCode::FAILURE;
237  }
238  //Central TiggerTower
239  unsigned int TTID = elements.at(0);
240  // rest of TTs that need to be check
241  elements.erase(elements.begin());
242  fillingMap[TTID] = std::move(elements);
243  }
244  myfile.close();
245 
246  return StatusCode::SUCCESS;
247 }
248 
249 
250 
251 }// end of namespace LVL1
LVL1::jFEXtauAlgo::getTTowerET
int getTTowerET(unsigned int TTID) const
Definition: jFEXtauAlgo.cxx:161
LVL1::jFEXtauAlgo::getTauSat
virtual bool getTauSat() const override
Definition: jFEXtauAlgo.cxx:195
PathResolver::find_calib_file
static std::string find_calib_file(const std::string &logical_file_name)
Definition: PathResolver.cxx:235
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
jFEXtauAlgo.h
LVL1::jFEXtauAlgo::setFirstEtRing
virtual void setFirstEtRing(int First_ETring[36]) override
Definition: jFEXtauAlgo.cxx:180
LVL1
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
Definition: ICMMCPHitsCnvTool.h:18
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
LVL1::jFEXtauAlgo::getTTowerSat
bool getTTowerSat(unsigned int TTID)
Definition: jFEXtauAlgo.cxx:151
LVL1::jFEXtauAlgo::setFPGAEnergy
virtual void setFPGAEnergy(const std::unordered_map< int, std::vector< int > > &et_map) override
Definition: jFEXtauAlgo.cxx:199
LVL1::jTower::getTowerSat
bool getTowerSat() const
Definition: jTower.h:61
LVL1::jFEXtauAlgo::initialize
virtual StatusCode initialize() override
standard Athena-Algorithm method
Definition: jFEXtauAlgo.cxx:28
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
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::jFEXtauAlgo::jFEXtauAlgo
jFEXtauAlgo(const std::string &type, const std::string &name, const IInterface *parent)
Constructors.
Definition: jFEXtauAlgo.cxx:20
LVL1::jFEXtauAlgo::getFirstEtRing
virtual int getFirstEtRing() const override
Definition: jFEXtauAlgo.cxx:191
LVL1::jFEXtauAlgo::isSeedLocalMaxima
virtual bool isSeedLocalMaxima() override
Definition: jFEXtauAlgo.cxx:65
LVL1::jFEXtauAlgo::getClusterEt
virtual int getClusterEt() const override
Definition: jFEXtauAlgo.cxx:174
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LVL1::jFEXtauAlgo::setup
virtual void setup(int seed[3][3]) override
Definition: jFEXtauAlgo.cxx:50
TrigConf::name
Definition: HLTChainList.h:35
LVL1::jFEXtauAlgo::safetyTest
virtual StatusCode safetyTest() override
Definition: jFEXtauAlgo.cxx:39
jTowerContainer.h
PathResolver.h
LVL1::jFEXtauAlgo::~jFEXtauAlgo
virtual ~jFEXtauAlgo()
Destructor.
Definition: jFEXtauAlgo.cxx:25
LVL1::jFEXtauAlgo::ReadfromFile
StatusCode ReadfromFile(const std::string &, std::unordered_map< unsigned int, std::vector< unsigned int > > &) const
Definition: jFEXtauAlgo.cxx:204
LVL1::jFEXtauAlgo::isSeedLocalMaxima_fwd
virtual bool isSeedLocalMaxima_fwd(unsigned int TTID) override
Definition: jFEXtauAlgo.cxx:96
LVL1::jTower
The jTower class is an interface object for jFEX trigger algorithms The purposes are twofold:
Definition: jTower.h:36
jobOptions.fileName
fileName
Definition: jobOptions.SuperChic_ALP2.py:39
AthAlgTool
Definition: AthAlgTool.h:26
jTower.h