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