ATLAS Offline Software
JetEnergyModuleKey.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  JetEnergyModuleKey.cpp - description
6  -------------------
7  begin : Tue Sep 26 2000
8  email : e.moyse@qmw.ac.uk
9  ***************************************************************************/
10 
11 #ifndef TRIGGERSPACE
12 // running in Athena
15 // #include "TrigT1CaloUtils/ICoordinate.h"
17 
19 
20 #else
21 #include "JetEnergyModuleKey.h"
23 #include "TrigT1CaloDefs.h"
24 #include "ICoordinate.h"
25 #include "JetElementKey.h"
26 #include "CoordToHardware.h"
27 
28 //
29 #endif
30 
31 #include <math.h>
32 
33 namespace LVL1 {
34 
36 JetEnergyModuleKey::JetEnergyModuleKey() : KeyUtilities(), m_debugModuleKey(false){
37  if (m_debugModuleKey) std::cout << "JetEnergyModuleKey: m_debugModuleKey output turned on...."<<std::endl;
38 }
39 
40 JetEnergyModuleKey::~JetEnergyModuleKey(){
41 }
42 
44 unsigned int JetEnergyModuleKey::jemKey(const xAOD::JetElement* jetElement) {
45  return key(jetElement->phi(), jetElement->eta());
46 }
47 
48 
49 
51 unsigned int JetEnergyModuleKey::jemKey(unsigned int crate, unsigned int module) {
52  double eta = ((module%8)+0.5)*TrigT1CaloDefs::jemEtaSize - 3.2;
53  int quadrant = crate + ((module>7) ? 2 : 0);
54  double phi = (quadrant+0.5)*TrigT1CaloDefs::jemPhiSize;
55  return key(phi, eta);
56 }
57 
59 std::vector<unsigned int> JetEnergyModuleKey::jeKeys(unsigned int crate, unsigned int module) {
60  std::vector<unsigned int> keys;
61 
62  // Protection
63  if (crate > 1 || module > 15) return keys;
64 
65  // First get coordinates
66  std::vector<Coordinate> coords = jeCoords(crate, module);
67 
68  // Then calculate keys
69  JetElementKey get(0.,0.);
70  for (const Coordinate& c : coords) {
71  keys.push_back(get.jeKey(c));
72  }
73 
74  return keys;
75 }
76 
77 
79 std::vector<Coordinate> JetEnergyModuleKey::jeCoords(unsigned int crate, unsigned int module) {
80  std::vector<Coordinate> coords;
81 
82  // Protection
83  if (crate > 1 || module > 15) return coords;
84 
91  int top = ( module < 8 ? 0 : 1 );
92  double phiStart = crate*TrigT1CaloDefs::jemPhiSize
93  + 2.*top*TrigT1CaloDefs::jemPhiSize
94  + 0.5*TrigT1CaloDefs::Region0Height;
95  double etaStart;
96  // Central JEMs are easy
97  if ( (module%8) > 0) {
98  etaStart = (module%8)*TrigT1CaloDefs::jemEtaSize - 3.1;
99  }
100  // -ive eta end
101  else {
102  etaStart = -TrigT1CaloDefs::Region5EtaCentre;
103  }
104 
105  // First coordinate for this JEM
106  Coordinate startCol(phiStart, etaStart);
107  // Nested incrementation of eta and phi
108  CoordToHardware cth;
109  JetElementKey get(0.,0.);
110  while (cth.jepModule( startCol ) == module) {
111  Coordinate next = get.getCentre(startCol);
112  while (cth.jepCrate( next ) == crate) {
113  coords.push_back(next);
114  next = get.upPhi(next);
115  }
116  startCol = get.rightEta(startCol);
117  if (startCol.eta() == TrigT1CaloDefs::RegionERROREtaCentre) break;
118  }
119 
120  return coords;
121 }
122 
124 unsigned int LVL1::JetEnergyModuleKey::row(const Coordinate& coord) const{
125  double phi=coord.phi();
126  double rowHeight=TrigT1CaloDefs::jemPhiSize/8.0;
127 
128  unsigned int rowsPerJEM = 8u;
129  int rowNum=static_cast<int>(phi/rowHeight);
130  rowNum=rowNum%rowsPerJEM;
131  return rowNum;
132 }
133 
136 unsigned int LVL1::JetEnergyModuleKey::row(const xAOD::JetElement* JE) const{
137  Coordinate coord(JE->phi(), JE->eta());
138  return row( coord );
139 }
140 
141 
143 double LVL1::JetEnergyModuleKey::rowPhiCoord(unsigned int rowNum, const Coordinate& jemCoord){
144  //not sure how to do this.
145  //should really reuse code, but above is tied to KU stuff. Probably way to go though.
146 
147  ICoordinate* iCoord = convertCoordsToIntegers(jemCoord.phi(), jemCoord.eta());
148  int etaBin=0; unsigned int phiBin=0;
149  setBins(iCoord,phiBin,etaBin);
150  // now work out row coord.
151 
152  if (rowNum>7){
153  std::cerr << "ERROR!!! JetEnergyModuleKey::rowPhiCoord exceeds allowed range. Row, "<<rowNum
154  <<" will be set to zero"<<std::endl;
155  rowNum=0;
156  }
157  double phi =( (static_cast<double>(phiBin))*TrigT1CaloDefs::jemPhiSize ); //bot of JEM
158  phi+= static_cast<double>( rowNum )*0.2+0.1; //mid of row
159  delete iCoord;
160  if (m_debugModuleKey){
161  if ( (phi<(jemCoord.phi()-0.8))||(phi>(jemCoord.phi()+0.8) ) ){
162  std::cerr << "ERROR!!! JetEnergyModuleKey::rowPhiCoord phi of row is "<<phi
163  <<" in a JEM at ("<<jemCoord.phi()<<", "<<jemCoord.eta()<<")"<<std::endl;
164  }//endif phi sensible
165  }//endif debug
166  return phi;
167 }
168 
170 double JetEnergyModuleKey::dPhi(const Coordinate& /*coord*/) const{
171  return M_PI/2;// one quadrant
172 }
173 
176  if (region(coord) == MidJEM) return 0.8;
177  if ((region(coord) == LeftEndJEM)||(region(coord) == RightEndJEM))
178  return 2.5;//end JEMs cover 2.4-4.9
179  return 0.0;
180 }
181 
182 } //end of ns
183 
184 
188  double absEta=fabs(coord.eta());
189  if (absEta<=2.4) return MidJEM;
190  if ((coord.eta()>2.4)&&(coord.eta()<=4.9))return RightEndJEM;
191  if ((coord.eta()>=-4.9)&&(coord.eta()<-2.4))return LeftEndJEM;
192  std::cerr << "JetEnergyModuleKey::region ... Unknown region!"<<std::endl
193  << "Coordinate is ("<<coord.phi()<<", "<<coord.eta()<<")"
194  <<std::endl;
195  return JEMRegionERROR;
196 }
197 
198 
199 
201 void LVL1::JetEnergyModuleKey::setBins(ICoordinate* iCoord, unsigned int& phiBin, int& etaBin){
202  unsigned int iPhiSize=16 ; // =PI/2 * 10
203  phiBin=( iCoord->phi() )/(iPhiSize);
204  int iEtaSize=8;// JEMs are 0.8 in eta, i.e ietaSize=8
205  etaBin=sharpRound2(iCoord->eta(),iEtaSize);
206  // the above calculation fails since end JEMs are larger, so ....
207  etaBin=(etaBin < -4 ? -4 : etaBin); // etaBin=-5
208  etaBin=(etaBin > 4 ? 4 : etaBin); // belongs to the JEM in etaBin=-4
209 
210  return;
211 }
212 
215  switch (region(coord)){
216  case MidJEM :
217  return midJEMEtaCol(coord);
218  case LeftEndJEM :
219  return leftEndJEMEtaCol(coord);
220  case RightEndJEM :
221  return rightEndJEMEtaCol(coord);
222  default:
223  std::cerr << "JetEnergyModuleKey::etaColumn UNKNOWN REGION"<<std::endl;
224  }
225  return static_cast<unsigned int>(JEMRegionERROR);
226 }
227 
229 unsigned int LVL1::JetEnergyModuleKey::jem(const Coordinate & coord) const {
230  double min=3.2; double jemEtaWidth=0.8;
231  unsigned int crateModifier=(phiQuadrant(coord.phi())/2);
232  //=0 for quad 0&1, =1 for quad 2&3
233 
234  double temp = (coord.eta()+min)/jemEtaWidth;
235  int jem = static_cast<int>(temp);
236  jem=(jem < 0 ? 0 : jem);
237  jem=(jem > 7 ? 7 : jem);
238 
239  jem+=(8*crateModifier);
240  return static_cast<unsigned int>(jem);
241 }
242 
247 // double phiBinWidth=((2*M_PI)/64.0);
248  int abs_ieta=abs(iCoord->eta() );
249  int sign=( iCoord->eta() )/abs_ieta;
250 
251  int etaBin=0; unsigned int phiBin=0;
252  setBins(iCoord,phiBin,etaBin);
253 
254  double centralPhi=( (static_cast<double>(phiBin))*TrigT1CaloDefs::jemPhiSize )
256  double centralEta=0.0;
257  if ((etaBin>-4)&&(etaBin<4)){
258  centralEta=(static_cast<double>(etaBin)*(TrigT1CaloDefs::jemEtaSize) )
260  }else{
261  centralEta=3.65*sign;//centre of end JEMs
262  }
263  if (m_debugModuleKey){
264  std::cout << "JetEnergyModuleKey: start calcTrigBin"<<std::endl;
265  std::cout << "phi, eta : ("<<m_phi<<", "<<m_eta<<")"<<std::endl;
266  std::cout << "iphi, ieta : ("<<( iCoord->phi() )<<", "<<( iCoord->eta() )<<")"<<std::endl;
267  std::cout << "abs_ieta : ("<<abs_ieta<<" and sign : "<<sign<<std::endl;
268  std::cout << "central : ("<<centralPhi<<", "<<centralEta<<")"
269  << "bin : ("<<phiBin<<","<<etaBin<<")"<<std::endl;
270  }
271 
272  Coordinate* centralCoords = new Coordinate(centralPhi, centralEta);
273  if (m_debugModuleKey) std::cout <<" JetEnergyModuleKey : created coord "<<(*centralCoords)<<std::endl;
274  return new BinAndCoord(phiBin,etaBin,centralCoords);
275 }
276 
279  double etaWidth=0.2;//only true for middle JEMS
280  double JEMEtaSize=0.8;
281 // unsigned int columnsPerJEM= 4;
282  int etaBin=( jem(coord)%8)-4;//bins range from -4 to +3
283  double etaMin=(etaBin*JEMEtaSize);
284 
285  double temp =(coord.eta()-etaMin)/etaWidth;
286  int colNum=sharpRound(temp);
287 
288  colNum=(colNum < 0 ? 0 : colNum);//sorts out any rounding errors
289  colNum=(colNum > 3 ? 3 : colNum);
290 
291  return colNum;
292 }
295  // left hand end first
297  switch (get.jeRegion( coord )){
299  return 3;
300  break;
302  return 2;
303  break;
305  return 1;
306  break;
307  case JetElementKey::FCAL :
308  return 0;
309  break;
310  case JetElementKey::Barrel :
311  // here to stop compiler warnings
312  break;
314  // here to stop compiler warnings
315  break;
316  }
317  return static_cast<unsigned int>(JEMRegionERROR);
318 }
319 
322  // left hand end first
324  switch (get.jeRegion( coord )){
326  return 0;
327  break;
329  return 1;
330  break;
332  return 2;
333  break;
334  case JetElementKey::FCAL :
335  return 3;
336  break;
337  case JetElementKey::Barrel :
338  // here to stop compiler warnings
339  break;
341  // here to stop compiler warnings
342  break;
343  }
344  return static_cast<unsigned int>(JEMRegionERROR);
345 }
346 
347 
348 
354 unsigned int LVL1::JetEnergyModuleKey::phiQuadrant(const double phi) const {
355  double temp = phi/(M_PI/2);
356  unsigned int quad = static_cast<unsigned int>(temp);
357  quad=(quad > 3 ? 0 : quad);
358 
359  return static_cast<unsigned int>(quad);
360 }
LVL1::KeyUtilities::phi
virtual double phi() const
returns phi coordinate of centre of relevant trigger tower.
Definition: KeyUtilities.cxx:159
query_example.row
row
Definition: query_example.py:24
LVL1::JetEnergyModuleKey::dPhi
double dPhi(const Coordinate &coord) const
height
Definition: JetEnergyModuleKey.cxx:175
top
TopConfig A simple configuration that is NOT a singleton.
Definition: AnalysisTrackingHelper.cxx:58
LVL1::Coordinate::phi
double phi() const
return phi
Definition: Coordinate.cxx:50
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
LVL1::JetElementKeyBase::FCAL
@ FCAL
Definition: JetElementKeyBase.h:78
LVL1::JetEnergyModuleKey::rowPhiCoord
double rowPhiCoord(unsigned int row, const Coordinate &jemCoord)
returns the phi coord of the row of the JEM at the coordinates passed
Definition: JetEnergyModuleKey.cxx:148
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
JetElementKey.h
xAOD::JetElement_v2
Description of JetElement_v2.
Definition: JetElement_v2.h:26
LVL1::JetElementKeyBase::EndCap3
@ EndCap3
Definition: JetElementKeyBase.h:77
LVL1::TrigT1CaloDefs::jemEtaSize
static const double jemEtaSize
Definition: TrigT1CaloDefs.h:139
M_PI
#define M_PI
Definition: ActiveFraction.h:11
LVL1::JetEnergyModuleKey::setBins
void setBins(ICoordinate *iCoord, unsigned int &phiBin, int &etaBin)
sets the eta and phi bins
Definition: JetEnergyModuleKey.cxx:201
LVL1::JetEnergyModuleKey::phiQuadrant
unsigned int phiQuadrant(const double phi) const
returns the quadrant number associated with the phi coordinate, 0 - 90 = 0 90 - 180 = 1 180-270 = 2 2...
Definition: JetEnergyModuleKey.cxx:354
LVL1::JetEnergyModuleKey::col
unsigned int col(const Coordinate &coord)
return row of passed coordinate
Definition: JetEnergyModuleKey.cxx:214
CoordToHardware.h
LVL1
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
Definition: ICMMCPHitsCnvTool.h:18
xAOD::JetElement_v2::eta
float eta() const
get eta
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:83
LVL1::JetEnergyModuleKey::RightEndJEM
@ RightEndJEM
Definition: JetEnergyModuleKey.h:56
LVL1::ICoordinate
Used by Key Classes, returns and integer coorginate for the bin Eta-Phi.
Definition: ICoordinate.h:31
python.PyAthena.module
module
Definition: PyAthena.py:134
xAOD::etaBin
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap etaBin
Definition: L2StandAloneMuon_v1.cxx:148
LVL1::KeyUtilities::coord
Coordinate coord() const
return central coords of current key value.
Definition: KeyUtilities.cxx:199
LVL1::Coordinate
Coordinate class declaration.
Definition: TrigT1/TrigT1Interfaces/TrigT1Interfaces/Coordinate.h:50
fillPileUpNoiseLumi.next
next
Definition: fillPileUpNoiseLumi.py:52
LVL1::JetEnergyModuleKey::leftEndJEMEtaCol
unsigned int leftEndJEMEtaCol(const Coordinate &coord) const
returns eta row of JEMs 0, or 8
Definition: JetEnergyModuleKey.cxx:294
LVL1::JetEnergyModuleKey::jem
unsigned int jem(const Coordinate &coord) const
returns ID of JEP module (i.e.
Definition: JetEnergyModuleKey.cxx:229
LVL1::JetEnergyModuleKey::rightEndJEMEtaCol
unsigned int rightEndJEMEtaCol(const Coordinate &coord) const
returns eta row of JEMs 7 or 15
Definition: JetEnergyModuleKey.cxx:321
LVL1::JetEnergyModuleKey::JetEnergyModuleKey
JetEnergyModuleKey()
constructs a JetEnergyModuleKey object
Definition: JetEnergyModuleKey.cxx:41
LVL1::BinAndCoord
Used to pass data between the methods of the Key Classes: Returns the Eta and Phi bins,...
Definition: BinAndCoord.h:40
sign
int sign(int a)
Definition: TRT_StrawNeighbourSvc.h:127
LVL1::ICoordinate::phi
int phi() const
return phi
Definition: ICoordinate.cxx:56
min
#define min(a, b)
Definition: cfImp.cxx:40
LVL1::JetElementKey
The JetElementKey object provides the key for each JetElement depending on its eta,...
Definition: JetElementKey.h:51
LVL1::JetEnergyModuleKey::calculateTriggerBin
BinAndCoord * calculateTriggerBin(ICoordinate *iCoord)
converts integer phi, eta coordinates to phi, eta trigger bins, and central coords
Definition: JetEnergyModuleKey.cxx:246
xAOD::phiBin
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setPhiMap phiBin
Definition: L2StandAloneMuon_v2.cxx:144
LVL1::JetEnergyModuleKey::dEta
double dEta(const Coordinate &coord) const
width
Definition: JetEnergyModuleKey.cxx:180
LVL1::JetEnergyModuleKey::JEMRegionERROR
@ JEMRegionERROR
Definition: JetEnergyModuleKey.h:57
LVL1::JetEnergyModuleKey::MidJEM
@ MidJEM
Definition: JetEnergyModuleKey.h:54
LVL1::JetElementKeyBase::EndCap2
@ EndCap2
Definition: JetElementKeyBase.h:76
TrigT1CaloDefs.h
LVL1::JetEnergyModuleKey::region
JEMRegion region(const Coordinate &coord) const
region
Definition: JetEnergyModuleKey.cxx:187
JetVoronoiDiagramHelpers::coord
double coord
Definition: JetVoronoiDiagramHelpers.h:45
LVL1::Coordinate::eta
double eta() const
return eta
Definition: Coordinate.cxx:45
JetEnergyModuleKey.h
LArCellBinning.etaMin
etaMin
Definition: LArCellBinning.py:84
LVL1::JetEnergyModuleKey::LeftEndJEM
@ LeftEndJEM
Definition: JetEnergyModuleKey.h:55
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
TauGNNUtils::Variables::absEta
bool absEta(const xAOD::TauJet &tau, double &out)
Definition: TauGNNUtils.cxx:232
LVL1::ICoordinate::eta
int eta() const
return eta
Definition: ICoordinate.cxx:51
xAOD::JetElement_v2::phi
float phi() const
get phi (note that for L1Calo phi runs from 0 to 2pi)
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:790
LVL1::JetEnergyModuleKey::row
unsigned int row(const Coordinate &coord) const
returns the phi row of a coord within the JEM that contains it.
Definition: JetEnergyModuleKey.cxx:129
LVL1::TrigT1CaloDefs::jemPhiSize
static const double jemPhiSize
Definition: TrigT1CaloDefs.h:138
LVL1::JetEnergyModuleKey::JEMRegion
JEMRegion
Definition: JetEnergyModuleKey.h:48
LVL1::JetElementKeyBase::Barrel
@ Barrel
Definition: JetElementKeyBase.h:73
LVL1::JetEnergyModuleKey::midJEMEtaCol
unsigned int midJEMEtaCol(const Coordinate &coord) const
No descriptions.
Definition: JetEnergyModuleKey.cxx:278
python.compressB64.c
def c
Definition: compressB64.py:93
ICoordinate.h
LVL1::JetElementKeyBase::EndCap1
@ EndCap1
Definition: JetElementKeyBase.h:75
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
LVL1::JetElementKeyBase::EndBarrel
@ EndBarrel
Definition: JetElementKeyBase.h:74
dumpNswErrorDb.quad
def quad
Definition: dumpNswErrorDb.py:24