ATLAS Offline Software
EfexCellMapping.cxx
Go to the documentation of this file.
7 EfexCellMapping::EfexCellMapping(int crate, int efexnumber,
8  int fpga, int mgtchannelout , int dataword)
9 {
10  auto genintint = [] (int col,int intstr)
11  {return std::make_pair(col , std::to_string(intstr) );};
12  using searchpairs = std::vector<std::pair<int,std::string>>;
13 
14  //Retrieve input quad inMGT pair
15  auto tab6search = searchpairs();
16  tab6search.push_back(genintint(0,fpga));
17  tab6search.push_back(genintint(3,mgtchannelout));
18  auto tab6line = m_tables.GetTable(6)->FindLine(tab6search);
19  int quad = std::stoi( tab6line->at(1) );
20  int mgtin = std::stoi( tab6line->at(2) );
21  this->init(crate,efexnumber, fpga, quad, mgtin, dataword);
22 }
23 
24 EfexCellMapping::EfexCellMapping( roiType, int crate, int efexnumber,
25  int fpga, int eta, int phi )
26 {
27  if ( (crate<0) || (crate>1) || (efexnumber<0) || (efexnumber>11) )
28  return;
29  if ( (eta<0) || (eta>5) || (phi<0) || (phi>7) )
30  return;
31 
32  int etaIndex = (efexnumber%3)*16 + fpga*4 + eta - 25;
33  int phiIndex = crate*32 +(efexnumber/3)*8 + phi + 2;
34  phiIndex %= 64;
35  double etaWidth = 0.1;
36  double phiWidth = M_PI/32.0;
37  double etaCoord = (etaIndex+0.5)*etaWidth;
38  double phiCoord = (phiIndex+0.5)*phiWidth;
39 
42  true, etaIndex, phiIndex,
43  etaWidth, phiWidth,
44  etaCoord, phiCoord );
45 }
46 
47 EfexCellMapping::EfexCellMapping( roiType, int crate, int efexnumber,
48  int fpga, int eta, int phi, int seed )
49 {
50  if ( (crate<0) || (crate>1) || (efexnumber<0) || (efexnumber>11) )
51  return;
52  if ( (eta<0) || (eta>5) || (phi<0) || (phi>7) )
53  return;
54  if ( (seed<0) || (seed>3) )
55  return;
56 
57  int etaIndex = (efexnumber%3)*64 + fpga*16 + eta*4 + seed - 100;
58  int phiIndex = crate*32 +(efexnumber/3)*8 + phi + 2;
59  phiIndex %= 64;
60  double etaWidth = 0.025;
61  double phiWidth = M_PI/32.0;
62  double etaCoord = (etaIndex+0.5)*etaWidth;
63  double phiCoord = (phiIndex+0.5)*phiWidth;
64 
67  true, etaIndex, phiIndex,
68  etaWidth, phiWidth,
69  etaCoord, phiCoord );
70 }
71 
72 
74 {
75  return m_region;
76 }
77 
79 {
80  return m_hwinfo;
81 }
82 std::string EfexCellMapping::getLatomeID() const
83 {
84  return m_latomeid;
85 }
86 void EfexCellMapping::init(int crate, int efexnumber,
87  int fpga, int quad, int mgtchannel , int dataword){
88  //Ensure m_region always exists even if invalid
91  //Run common constructor methods
92  std::string efexcords = this->findModuleCords(crate, efexnumber);
93  // Test data read in
94  /*
95  for(int tableidx=1 ; tableidx<6; tableidx++ ){
96  std::cout << "Printing Table:" << std::to_string(tableidx)<< std::endl;
97  ((m_tables)->GetTable(tableidx))->PrintTable(true);
98  }
99  */
100  // (m_tables)->GetTable(4)->PrintTable();
101  //Basic Lamdas to gen search pairs
102  auto genintstr = [] (int col, std::string str )
103  {return std::make_pair(col , str );};
104  auto genintint = [] (int col,int intstr)
105  {return std::make_pair(col , std::to_string(intstr) );};
106  using searchpairs = std::vector<std::pair<int,std::string>>;
107 
108  //Complete CSV search
109 
110  //METHOD #1 to retrieve eta-phi-layer
111  auto tab4search = searchpairs();
112  tab4search.push_back(genintstr(0,efexcords));
113  tab4search.push_back(genintint(1,fpga));
114  tab4search.push_back(genintint(2,quad));
115  tab4search.push_back(genintint(3,mgtchannel));
116  auto tab4line = m_tables.GetTable(4)->FindLine(tab4search);
117  if ( tab4line->size() == 0 )
118  return;
119 // std::cout << "Table4 Search Found:" << std::endl;
120 // for(auto entry : *tab4line ){std::cout << entry << " ,";}
121 // std::cout << std::endl;
122 
123  //Create a valid minipod str
124  std::string mpod = tab4line->at(4);
125  auto tab3search = searchpairs();
126  tab3search.push_back(genintstr(0,efexcords));
127  tab3search.push_back(genintstr(1,mpod));
128  auto tab3line = m_tables.GetTable(3)->FindLine(tab3search);
129  if ( tab3line->size() == 0 )
130  return;
131 // std::cout << "Table3 Search Found:" << std::endl;
132 // for(auto entry : *tab3line ){std::cout << entry << " ,";}
133 // std::cout << std::endl;
134  m_inputconnector = std::stoi(tab3line->at(2));
135  m_fibrenumber = std::stoi(tab3line->at(3));
136 
137  //Generate a valid HW info object
139  m_inputconnector,mpod);
140 
141  auto tab2search = searchpairs();
142  tab2search.push_back(genintstr(0,efexcords));
143  tab2search.push_back(genintint(1,m_inputconnector));
144  tab2search.push_back(genintint(2,m_fibrenumber));
145  tab2search.push_back(genintint(3,dataword ));
146  auto tab2line = m_tables.GetTable(2)->FindLine(tab2search);
147  if ( tab2line->size() == 0 )
148  return;
149 
150  int globaleta = std::stoi( tab2line->at(4) );
151  int globalphi = std::stoi( tab2line->at(5) );
152  //std::cout << "My layer str is " << tab2line->at(6) << std::endl;
153  int layer = std::stoi( tab2line->at(6),nullptr ,16 );
154  m_latomeid = tab2line->at(8);
155  //std::cout << "My layer int is " << tab2line->at(6) << std::endl;
156  //Once Search complete, generate detector region info
157 
158  //Predeclare enum
159  auto efexlabel = L1CaloDetectorRegion::EFEX;
160  // enum layertype: int;
161  double supercelletawidth(0);
162  double supercellphiwidth(0.09817477);
163  int supercelletaoffset(0);
164  if(layer == 0){
165  supercelletawidth = 0.1;
166  }
167  else if(1 <= layer && layer <= 4){
168  supercelletawidth = 0.025;
169  supercelletaoffset = (layer - 1 )%4;
170  }
171  else if(5 <= layer && layer <= 8){
172  supercelletawidth = 0.025;
173  supercelletaoffset = (layer - 1 )%4;
174  }
175  else if(layer == 9 || layer == 10){
176  supercelletawidth = 0.1;
177  }
178  double toweretalowside = (double)globaleta/10;
179  double towerphilowside = (double)globalphi*0.09817477;
180  double supercelletacoord = toweretalowside + 0.025*(double)supercelletaoffset +
181  0.5*supercelletawidth ;
182  double supercellphicoord = towerphilowside + 0.5*supercellphiwidth;
183  if(layer == 0){
184  m_region = L1CaloDetectorRegion( efexlabel,
185  L1CaloDetectorRegion::Presampler, true, globaleta, globalphi,
186  supercelletawidth, supercellphiwidth , supercelletacoord, supercellphicoord);
187  }
188  else if(1 <= layer && layer <= 4){
189  m_region = L1CaloDetectorRegion( efexlabel,
190  L1CaloDetectorRegion::Front, true, globaleta, globalphi,
191  supercelletawidth, supercellphiwidth , supercelletacoord, supercellphicoord);
192  }
193  else if(5 <= layer && layer <= 8){
194  m_region = L1CaloDetectorRegion( efexlabel,
195  L1CaloDetectorRegion::Middle, true, globaleta, globalphi,
196  supercelletawidth, supercellphiwidth , supercelletacoord, supercellphicoord);
197  }
198  else if(layer == 9){
199  m_region = L1CaloDetectorRegion( efexlabel,
200  L1CaloDetectorRegion::Back, true, globaleta, globalphi,
201  supercelletawidth, supercellphiwidth , supercelletacoord, supercellphicoord);
202  }
203  else if(layer == 10){
204  m_region = L1CaloDetectorRegion( efexlabel,
205  L1CaloDetectorRegion::Hadronic, true, globaleta, globalphi,
206  supercelletawidth, supercellphiwidth , supercelletacoord, supercellphicoord);
207  }
208  int globalEta = m_region.getEtaIndex();
210  std::string miniPodLabel = m_hwinfo.getMpodLabel();
211  int moduleCBA = 2 - ( efexcords.at(0) - 'A' ); //ASCII operation
212  int octantNum = ( efexcords.at(1) - '0' ) - 1; //ASCII operation
213  int moduleBaseEta = -24 + (moduleCBA * 16);
214  int fpgaBaseEta = moduleBaseEta + (fpga * 4);
215  int fpgaLowerEta = fpgaBaseEta;
216  int fpgaUpperEta = fpgaBaseEta + 4;
217  if (moduleCBA == 0 && fpga == 0) { fpgaLowerEta--; }
218  else if (moduleCBA == 2 && fpga == 3) { fpgaUpperEta++; }
219  int shiftedPhi = (globalPhi + 62) % 64;
220  int lowerShiftedPhi = octantNum * 8;
221  int upperShiftedPhi = lowerShiftedPhi + 8;
222  int fpgaOverlap = 0;
223  if (shiftedPhi >= upperShiftedPhi || shiftedPhi < lowerShiftedPhi) {
224  // Set overlap bit 1 if phi is just below the core, 2 otherwise.
225  // We need special treatment of the wraparound near phi=0 (or 64).
226  if (octantNum == 0 || octantNum == 7) {
227  fpgaOverlap |= (shiftedPhi > 32) ? 1 : 2;
228  }
229  else {
230  fpgaOverlap |= (shiftedPhi < lowerShiftedPhi) ? 1 : 2;
231  }
232  }
233  if (globalEta >= fpgaUpperEta || globalEta < fpgaLowerEta) {
234  fpgaOverlap |= (globalEta < fpgaLowerEta) ? 4 : 8;
235  }
236  m_hwinfo.setOverlap(fpgaOverlap);
237 
238 }
239 std::string EfexCellMapping::findModuleCords(int crate, int efexnumber) const {
240  // Set of sensible range checks, if out of range return so blank
241  // declaration of L1CaloDetector Region
242  if ( (crate<0 || crate>1) ){
243  throw "Invalid Crate # created within eFEX mapping";
244  return "Err";
245  }
246  if ( efexnumber<0 || efexnumber>11 ){
247  throw "Invalid Module # created within eFEX mapping";
248  return "Err";
249  }
250  // For input crate and efexnumber (assuming 'eFEX number' for
251  // efexnumber label)
252 
253  // Find old eFEX labels in mapping csvs
254  // with octant [1:8] and eta slice [A,B,C]:
255  int octant = 4*crate + efexnumber/3 + 1; //Note int div
256 
257  int etaslicenum = 3 - efexnumber%3; //obvious A=1 etc mapping
258  std::string etaslice;
259  switch(etaslicenum){
260  case 1:
261  etaslice = 'A';
262  break;
263  case 2:
264  etaslice = 'B';
265  break;
266  case 3:
267  etaslice = 'C';
268  break;
269  }
270  return etaslice + std::to_string(octant);
271 }
EfexCellMapping::m_tables
EfexCSVTables & m_tables
Definition: EfexCellMapping.h:45
L1CaloDetectorRegion::Front
@ Front
Definition: L1CaloDetectorRegion.h:28
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
EfexHardwareInfo::getMpodLabel
std::string getMpodLabel() const
Definition: EfexHardwareInfo.cxx:39
L1CaloDetectorRegion::Back
@ Back
Definition: L1CaloDetectorRegion.h:30
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
L1CaloDetectorRegion::Presampler
@ Presampler
Definition: L1CaloDetectorRegion.h:27
EfexCellMapping::getDetectorRegion
L1CaloDetectorRegion getDetectorRegion() const
Definition: EfexCellMapping.cxx:73
EfexCellMapping::getHardwareInfo
EfexHardwareInfo getHardwareInfo() const
Definition: EfexCellMapping.cxx:78
M_PI
#define M_PI
Definition: ActiveFraction.h:11
L1CaloDetectorRegion::Hadronic
@ Hadronic
Definition: L1CaloDetectorRegion.h:24
EfexHardwareInfo
Definition: EfexHardwareInfo.h:4
EfexCellMapping::EfexCellMapping
EfexCellMapping(int crate, int efexnumber, int fpga, int quad, int mgtchannel, int dataword)
Definition: EfexCellMapping.h:19
EfexCellMapping::m_latomeid
std::string m_latomeid
Definition: EfexCellMapping.h:46
L1CaloDetectorRegion::EFEX
@ EFEX
Definition: L1CaloDetectorRegion.h:16
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
EfexCellMapping::roiType
roiType
Definition: EfexCellMapping.h:17
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
EfexCellMapping::m_inputconnector
int m_inputconnector
Definition: EfexCellMapping.h:39
EfexCellMapping::init
void init(int crate, int efexnumber, int fpga, int quad, int mgtchannel, int dataword)
Definition: EfexCellMapping.cxx:86
L1CaloDetectorRegion::CPM
@ CPM
Definition: L1CaloDetectorRegion.h:14
EfexCellMapping::m_hwinfo
EfexHardwareInfo m_hwinfo
Definition: EfexCellMapping.h:44
L1CaloDetectorRegion::getEtaIndex
int getEtaIndex() const
Definition: L1CaloDetectorRegion.h:44
TRT::Hit::globalPhi
@ globalPhi
Definition: HitInfo.h:38
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
L1CaloDetectorRegion
Definition: L1CaloDetectorRegion.h:8
EfexCellMapping::m_fibrenumber
int m_fibrenumber
Definition: EfexCellMapping.h:38
EfexCellMapping.h
query_example.col
col
Definition: query_example.py:7
eflowRec::phiIndex
unsigned int phiIndex(float phi, float binsize)
calculate phi index for a given phi
Definition: EtaPhiLUT.cxx:23
EfexCellMapping::findModuleCords
std::string findModuleCords(int crate, int efexnumber) const
Definition: EfexCellMapping.cxx:239
L1CaloDetectorRegion::getPhiIndex
int getPhiIndex() const
Definition: L1CaloDetectorRegion.h:45
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
xAOD::phiWidth
phiWidth
Definition: RingSetConf_v1.cxx:612
L1CaloDetectorRegion::Both
@ Both
Definition: L1CaloDetectorRegion.h:31
EfexHardwareInfo::setOverlap
void setOverlap(int overlap)
Definition: EfexHardwareInfo.cxx:47
L1CaloDetectorRegion::Middle
@ Middle
Definition: L1CaloDetectorRegion.h:29
str
Definition: BTagTrackIpAccessor.cxx:11
EfexCellMapping::getLatomeID
std::string getLatomeID() const
Definition: EfexCellMapping.cxx:82
CSVTablesBase::GetTable
std::shared_ptr< CSVWrapper > GetTable(int table_num)
Definition: CSVTablesBase.cxx:23
dumpNswErrorDb.quad
def quad
Definition: dumpNswErrorDb.py:24
EfexCellMapping::m_region
L1CaloDetectorRegion m_region
Definition: EfexCellMapping.h:43