ATLAS Offline Software
CoordToHardware.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3 */
4 /***************************************************************************
5  CoordToHardware.cxx - description
6  -------------------
7  begin : Fri Apr 19 2002
8  email : moyse@ph.qmw.ac.uk
9  ***************************************************************************/
10 
11 #ifndef TRIGGERSPACE
13 #else
14 #include "CoordToHardware.h"
15 #endif
16 
17 #include <cmath>
18 #include <iostream>
19 
21  m_cpmEtaWidth(0.4), m_cpmEtaMax(2.8),
22  m_cpFPGAPhiWidth(M_PI/16.0), m_cpEtaMax(2.5), m_debug(false)
23 {
25 }
26 
28 }
29 
32 unsigned int LVL1::CoordToHardware::jepCrate(const Coordinate& Coord){
33  unsigned int quad=phiQuadrant( Coord.phi() );
34  return (quad%2);
35 }
36 
40 
41  return ( phiQuadrant(coord.phi()) );
42 }
43 
44 
48  return ( phiQuadrant(coord.phi()) );
49 }
50 
53  if ( cpCoordIsValid(coord) ) {
54  // CPM1 is at -2.6 to -2.4 (here set it to -2.8)
55  // CPM8 is at 0.0 to 0.4
56  double eta=coord.eta();
57  unsigned int cpm = static_cast<unsigned int>( (eta+m_cpmEtaMax)/m_cpmEtaWidth )+1;
58  return cpm;
59  }
60  return m_error;
61 }
68  JetEnergyModuleKey jemKey;
69  return static_cast<unsigned int>(jemKey.jem(coord));
70 }
71 
75  if ( cpCoordIsValid(coord) ) {
76  double phi=coord.phi();
77  // should be 32 FPGAs in 2*PI
78  double temp = phi/m_cpFPGAPhiWidth;
79  // so temp mod 8 returns FPGA #
80  return ( (static_cast<unsigned int>(temp))%8);
81  }
82  // not a valid coord
83  return m_error;
84 }
92 
93  m_roiLocalMap[0][0]=0;
94  m_roiLocalMap[0][1]=1;
95  m_roiLocalMap[0][2]=4;
96  m_roiLocalMap[0][3]=5;
97  m_roiLocalMap[1][0]=2;
98  m_roiLocalMap[1][1]=3;
99  m_roiLocalMap[1][2]=6;
100  m_roiLocalMap[1][3]=7;
101 }
102 
105  if ( cpCoordIsValid(coord) ) {
106  double phi=coord.phi();
107  double eta=coord.eta();
108  // should be 32 FPGAs in 2*PI, and there are 2 local RoI locations in phi per FPGA
109  // so "temp" ranges from 0-63
110  unsigned int temp = static_cast<unsigned int>( (phi/m_cpFPGAPhiWidth)*2);
111  // so this (below) gives us the integer phi coordinate WITHIN the FPGA
112  unsigned int iLocalPhi= temp%2;
113  // There are 14 CPMs, each with 8 FPGAs that each span it completely in eta
114  // (i.e. one eta position for FPGAs in CPM) and there are 4 local RoI
115  // locations in eta per FPGA
116 
117  temp=static_cast<unsigned int>( (eta+2.8)/0.1 );
118 
119  //temp = static_cast<unsigned int>( (eta+(m_cpmEtaMax+m_cpmEtaWidth)/m_cpmEtaWidth ) * 4);
120  unsigned int iLocalEta = temp%4;
121  return m_roiLocalMap[iLocalPhi][iLocalEta];
122  }
123  // invalid coord
124  return m_error;
125 }
126 
129  double eta= coord.eta();
130  if ( (eta>=-m_cpEtaMax) && (eta <=m_cpEtaMax) ) return true;
131  std::cerr << "CoordToHardware::cpCoordIsValid: Coordinate outside permitted range of eta = "
132  <<-m_cpEtaMax<<" to "<<m_cpEtaMax<<std::endl;
133  return false;
134 }
135 
141  unsigned int crate =jepCrate(coord);
142  unsigned int jem=jepModule(coord);
143  unsigned int PJ=jepLocalCoordinate(coord);
144 
145  unsigned int word=0;
146  if ((crate==m_error)||(jem==m_error)||(PJ==m_error)){
147  std::cerr << "CPCoordinateWord ERROR: "<< std::endl;
148  }else{
149  word = crate; // put 1 bit crate number
150  word = (word<<4) + jem; // followed by 4 bit JEM number
151  word = (word<<5) + PJ; // JP
152  }
153  if (m_debug) std::cout << " Coords set to ("<<coord.phi()<<", "<<coord.eta()<<") giving : "<<word
154  << " from crate "<<crate
155  << " JEM "<<jem<<" PJ : "<<PJ<< std::endl;
156  return word;
157 }
158 
164 unsigned int LVL1::CoordToHardware::phiQuadrant(const double phi) const {
165  double temp = phi/(M_PI/2);
166  return static_cast<unsigned int>(temp);
167 }
168 
175  unsigned int crate =cpCrate(coord);
176  unsigned int cpm=cpModule(coord);
177  unsigned int fpga=cpModuleFPGA(coord);
178  unsigned int lc=cpModuleLocalRoI(coord);
179 
180  unsigned int word=0;
181  if ((crate==m_error)||(cpm==m_error)||(fpga==m_error)||(lc==m_error)){
182  std::cerr << "CPCoordinateWord ERROR: "<< std::endl;
183  }else{
184  word= crate; // put 2 bit crate number
185  word = (word<<4) + cpm; // followed by 4 bit CPM number
186  word = (word<<3) + fpga; // 3 bit FPGA number
187  word = (word<<3) + lc; //2 bit local coord
188  }
189  if (m_debug) std::cout << " Coords set to ("<<coord.phi()<<", "<<coord.eta()<<") giving : "<<word
190  << " from crate "<<crate
191  << " CPM "<<cpm<<" fpga : "<<fpga<<" LC : "<<lc<< std::endl;
192  return word;
193 }
196  JetEnergyModuleKey jemKey;
197  unsigned int row=jemKey.row(coord);
198  unsigned int col=jemKey.col(coord);
199  unsigned int frame = 4*(col>>1) + (row>>1);
200  unsigned int rl = 2*(row%2) + (col%2);
201  return (frame<<2)+rl;
202 }
203 
206 
207  const double phi = cpPhiOverlap(coord);
208  return (phi == coord.phi()) ? m_error
209  : cpCrate(Coordinate(phi, coord.eta()));
210 }
211 
214 
215  const double phi = cpPhiOverlap(coord);
216  return (phi == coord.phi()) ? m_error
217  : cpModule(Coordinate(phi, coord.eta()));
218 }
219 
222 
223  const double phi = jepPhiOverlap(coord);
224  return (phi == coord.phi()) ? m_error
225  : jepCrate(Coordinate(phi, coord.eta()));
226 }
227 
230 
231  const double phi = jepPhiOverlap(coord);
232  return (phi == coord.phi()) ? m_error
233  : jepModule(Coordinate(phi, coord.eta()));
234 }
235 
238 
239  double phi = coord.phi();
240  const double twoPi = 2.*M_PI;
241  const double piByTwo = M_PI/2.;
242  const double twoPhiBins = M_PI/16.;
243  const double phiLoc = std::fmod(phi, piByTwo);
244  if (phiLoc < twoPhiBins) {
245  phi -= twoPhiBins;
246  if (phi < 0.) phi += twoPi;
247  } else if (phiLoc > piByTwo - twoPhiBins) {
248  phi += twoPhiBins;
249  if (phi >= twoPi) phi -= twoPi;
250  }
251  return phi;
252 }
253 
256 
257  double phi = coord.phi();
258  const double eta = coord.eta();
259  const bool fcal = eta < -3.2 || eta > 3.2;
260  const double twoPi = 2.*M_PI;
261  const double piByTwo = M_PI/2.;
262  const double twoPhiBins = M_PI/8.;
263  const double onePhiBin = (fcal) ? twoPhiBins : twoPhiBins/2.;
264  const double phiLoc = std::fmod(phi, piByTwo);
265  if (phiLoc < twoPhiBins) {
266  phi -= twoPhiBins;
267  if (phi < 0.) phi += twoPi;
268  } else if (phiLoc > piByTwo - onePhiBin) {
269  phi += onePhiBin;
270  if (phi >= twoPi) phi -= twoPi;
271  }
272  return phi;
273 }
LVL1::CoordToHardware::cpModuleOverlap
unsigned int cpModuleOverlap(const Coordinate &coord)
return ID of CP module for overlap coord
Definition: CoordToHardware.cxx:213
query_example.row
row
Definition: query_example.py:24
LVL1::CoordToHardware::cpCoordinateWord
unsigned int cpCoordinateWord(const Coordinate &coord)
return CP (Cluster Processing) hardware coordinate word for this coordinate.
Definition: CoordToHardware.cxx:174
LVL1::JetEnergyModuleKey
The JetEnergyModuleKey object provides the key for each trigger tower depending on its eta-phi coords...
Definition: JetEnergyModuleKey.h:40
LVL1::Coordinate::phi
double phi() const
return phi
Definition: Coordinate.cxx:50
LVL1::CoordToHardware::jepPhiOverlap
double jepPhiOverlap(const Coordinate &coord) const
returns a phi in core area for overlap jet elements
Definition: CoordToHardware.cxx:255
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
LVL1::CoordToHardware::cpModuleFPGA
unsigned int cpModuleFPGA(const Coordinate &coord)
returns ID [0-7] of the CP FPGA.
Definition: CoordToHardware.cxx:74
M_PI
#define M_PI
Definition: ActiveFraction.h:11
LVL1::JetEnergyModuleKey::col
unsigned int col(const Coordinate &coord)
return row of passed coordinate
Definition: JetEnergyModuleKey.cxx:214
CoordToHardware.h
python.LumiCalcHtml.lc
lc
Definition: LumiCalcHtml.py:579
LVL1::CoordToHardware::phiQuadrant
unsigned int phiQuadrant(const double phi) const
returns the quadrant number associated with the phi coordinate,
Definition: CoordToHardware.cxx:164
LVL1::CoordToHardware::jepCoordinateWord
unsigned int jepCoordinateWord(const Coordinate &coord)
return JEP (Jet Energy Processing) hardware coordinate word for this coordinate.
Definition: CoordToHardware.cxx:140
LVL1::CoordToHardware::cpModuleLocalRoI
unsigned int cpModuleLocalRoI(const Coordinate &coord)
returns local RoI coordinate within FPGA
Definition: CoordToHardware.cxx:104
LVL1::CoordToHardware::cpPhiOverlap
double cpPhiOverlap(const Coordinate &coord) const
returns a phi in core area for overlap CPM towers
Definition: CoordToHardware.cxx:237
LVL1::Coordinate
Coordinate class declaration.
Definition: TrigT1/TrigT1Interfaces/TrigT1Interfaces/Coordinate.h:50
LVL1::JetEnergyModuleKey::jem
unsigned int jem(const Coordinate &coord) const
returns ID of JEP module (i.e.
Definition: JetEnergyModuleKey.cxx:229
LVL1::CoordToHardware::cpCoordIsValid
bool cpCoordIsValid(const Coordinate &coord) const
returns false if Coord is outside permitted region
Definition: CoordToHardware.cxx:128
LVL1::CoordToHardware::cpModule
unsigned int cpModule(const Coordinate &coord)
return ID of CP module.
Definition: CoordToHardware.cxx:52
LVL1::CoordToHardware::jepModuleOverlap
unsigned int jepModuleOverlap(const Coordinate &coord)
returns ID of JEP module (i.e.
Definition: CoordToHardware.cxx:229
LVL1::CoordToHardware::fillRoILocalMap
void fillRoILocalMap()
No descriptions.
Definition: CoordToHardware.cxx:91
LVL1::CoordToHardware::jepModule
unsigned int jepModule(const Coordinate &coord)
returns ID of JEP module (i.e.
Definition: CoordToHardware.cxx:67
LVL1::CoordToHardware::cpRoIROD
unsigned int cpRoIROD(const Coordinate &coord)
returns Module ID of CP RoI ROD
Definition: CoordToHardware.cxx:47
LVL1::CoordToHardware::cpCrate
unsigned int cpCrate(const Coordinate &coord)
returns crate ID covering that coord.
Definition: CoordToHardware.cxx:39
query_example.col
col
Definition: query_example.py:7
JetVoronoiDiagramHelpers::coord
double coord
Definition: JetVoronoiDiagramHelpers.h:45
PlotCalibFromCool.rl
rl
Definition: PlotCalibFromCool.py:529
LVL1::CoordToHardware::cpCrateOverlap
unsigned int cpCrateOverlap(const Coordinate &coord)
returns crate ID covering that overlap coord.
Definition: CoordToHardware.cxx:205
LVL1::CoordToHardware::jepLocalCoordinate
unsigned int jepLocalCoordinate(const Coordinate &coord)
returns the roi's local coord, in the form of a 5b word.
Definition: CoordToHardware.cxx:195
LVL1::CoordToHardware::~CoordToHardware
~CoordToHardware()
Definition: CoordToHardware.cxx:27
LVL1::CoordToHardware::jepCrate
unsigned int jepCrate(const Coordinate &Coord)
returns ID of JEP Crate that covers this coordinate
Definition: CoordToHardware.cxx:32
LVL1::CoordToHardware::jepCrateOverlap
unsigned int jepCrateOverlap(const Coordinate &coord)
returns ID of JEP Crate that covers this overlap coordinate
Definition: CoordToHardware.cxx:221
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::CoordToHardware::CoordToHardware
CoordToHardware()
Definition: CoordToHardware.cxx:20
dumpNswErrorDb.quad
def quad
Definition: dumpNswErrorDb.py:24