CMS 3D CMS Logo

CSCSectorReceiverLUT.cc
Go to the documentation of this file.
8 
13 
15 
17 
18 #include <fstream>
19 #include <cstring>
20 
23 
24 
25 CSCSectorReceiverLUT::CSCSectorReceiverLUT(int endcap, int sector, int subsector, int station,
26  const edm::ParameterSet & pset, bool TMB07):_endcap(endcap),_sector(sector),
27  _subsector(subsector),
28  _station(station),isTMB07(TMB07)
29 {
30  LUTsFromFile = pset.getUntrackedParameter<bool>("ReadLUTs",false);
31  useMiniLUTs = pset.getUntrackedParameter<bool>("UseMiniLUTs", true);
32  isBinary = pset.getUntrackedParameter<bool>("Binary",false);
33 
34  me_global_eta = nullptr;
35  me_global_phi = nullptr;
36  mb_global_phi = nullptr;
37  if(LUTsFromFile && !useMiniLUTs)
38  {
39  me_lcl_phi_file = pset.getUntrackedParameter<edm::FileInPath>("LocalPhiLUT", edm::FileInPath(std::string("L1Trigger/CSCTrackFinder/LUTs/LocalPhiLUT"
40  + (isBinary ? std::string(".bin") : std::string(".dat")))));
41  me_gbl_phi_file = pset.getUntrackedParameter<edm::FileInPath>("GlobalPhiLUTME", edm::FileInPath((std::string("L1Trigger/CSCTrackFinder/LUTs/GlobalPhiME")
42  + encodeFileIndex()
43  + (isBinary ? std::string(".bin") : std::string(".dat")))));
44  if(station == 1)
45  mb_gbl_phi_file = pset.getUntrackedParameter<edm::FileInPath>("GlobalPhiLUTMB", edm::FileInPath((std::string("L1Trigger/CSCTrackFinder/LUTs/GlobalPhiMB")
46  + encodeFileIndex()
47  + (isBinary ? std::string(".bin") : std::string(".dat")))));
48  me_gbl_eta_file = pset.getUntrackedParameter<edm::FileInPath>("GlobalEtaLUTME", edm::FileInPath((std::string("L1Trigger/CSCTrackFinder/LUTs/GlobalEtaME")
49  + encodeFileIndex()
50  + (isBinary ? std::string(".bin") : std::string(".dat")))));
52  }
53 
54 }
55 
57  _sector(lut._sector),
59  _station(lut._station),
65  isBinary(lut.isBinary)
66 {
67  if(lut.mb_global_phi)
68  {
71  }
72  else mb_global_phi = nullptr;
73  if(lut.me_global_phi)
74  {
77  }
78  else me_global_phi = nullptr;
79  if(lut.me_global_eta)
80  {
83  }
84  else me_global_eta = nullptr;
85 }
86 
88 {
89  if(this != &lut)
90  {
91  _endcap = lut._endcap;
92  _sector = lut._sector;
93  _subsector = lut._subsector;
94  _station = lut._station;
100  isBinary = lut.isBinary;
101 
102  if(lut.mb_global_phi)
103  {
106  }
107  else mb_global_phi = nullptr;
108 
109  if(lut.me_global_phi)
110  {
113  }
114  else me_global_phi = nullptr;
115 
116  if(lut.me_global_eta)
117  {
120  }
121  else me_global_eta = nullptr;
122  }
123  return *this;
124 }
125 
127 {
129  {
130  delete me_lcl_phi;
131  me_lcl_phi = nullptr;
132  me_lcl_phi_loaded = false;
133  }
134  if(me_global_eta)
135  {
136  delete me_global_eta;
137  me_global_eta = nullptr;
138  }
139  if(me_global_phi)
140  {
141  delete me_global_phi;
142  me_global_phi = nullptr;
143  }
144  if(mb_global_phi)
145  {
146  delete mb_global_phi;
147  mb_global_phi = nullptr;
148  }
149 }
150 
152 {
153  lclphidat data;
154 
156  double binPhiL = static_cast<double>(maxPhiL)/(2.*CSCConstants::MAX_NUM_STRIPS);
157 
158  double patternOffset;
159 
160  if(isTMB07) patternOffset = CSCPatternLUT::get2007Position((theadd.pattern_type<<3) + theadd.clct_pattern);
161  else patternOffset = CSCPatternLUT::getPosition(theadd.clct_pattern);
162 
163  // The phiL value stored is for the center of the half-/di-strip.
164  if(theadd.strip < 2*CSCConstants::MAX_NUM_STRIPS)
165  if(theadd.pattern_type == 1 || isTMB07) // if halfstrip (Note: no distrips in TMB 2007 patterns)
166  data.phi_local = static_cast<unsigned>((0.5 + theadd.strip + patternOffset)*binPhiL);
167  else // if distrip
168  data.phi_local = static_cast<unsigned>((2 + theadd.strip + 4.*patternOffset)*binPhiL);
169  else {
170  throw cms::Exception("CSCSectorReceiverLUT")
171  << "+++ Value of strip, " << theadd.strip
172  << ", exceeds max allowed, " << 2*CSCConstants::MAX_NUM_STRIPS-1
173  << " +++\n";
174  }
175 
176  if (data.phi_local >= maxPhiL) {
177  throw cms::Exception("CSCSectorReceiverLUT")
178  << "+++ Value of phi_local, " << data.phi_local
179  << ", exceeds max allowed, " << maxPhiL-1 << " +++\n";
180  }
181 
182  LogDebug("CSCSectorReceiver")
183  << "endcap = " << _endcap << " station = " << _station
184  << " maxPhiL = " << maxPhiL << " binPhiL = " << binPhiL;
185  LogDebug("CSCSectorReceiver")
186  << "strip # " << theadd.strip << " hs/ds = " << theadd.pattern_type
187  << " pattern = " << theadd.clct_pattern << " offset = " << patternOffset
188  << " phi_local = " << data.phi_local;
189 
191  data.phi_bend_local = 0;
192 
193  return data; //return LUT result
194 }
195 
196 
198 {
199  // read data in from a file... Add this later.
200 }
201 
203  const int quality, const int lr, const bool gangedME1a) const
204 {
205  lclphiadd theadd;
206 
207  theadd.strip = strip;
208  theadd.clct_pattern = pattern & 0x7;
209  theadd.pattern_type = (pattern & 0x8) >> 3;
210  theadd.quality = quality;
211  theadd.lr = lr;
212  theadd.spare = 0;
213 
214  return localPhi(theadd, gangedME1a );
215 }
216 
217 lclphidat CSCSectorReceiverLUT::localPhi(unsigned address, const bool gangedME1a) const
218 {
220  lclphiadd theadd(address);
221 
222  if(useMiniLUTs && isTMB07)
223  {
224  result = CSCSectorReceiverMiniLUT::calcLocalPhiMini(address, gangedME1a);
225  }
226  else if(LUTsFromFile) result = me_lcl_phi[address];
227  else result = calcLocalPhi(theadd);
228 
229  return result;
230 }
231 
232 lclphidat CSCSectorReceiverLUT::localPhi(lclphiadd address, const bool gangedME1a) const
233 {
235 
236  if(useMiniLUTs && isTMB07)
237  {
238  result = CSCSectorReceiverMiniLUT::calcLocalPhiMini(address.toint(), gangedME1a);
239  }
240  else if(LUTsFromFile) result = me_lcl_phi[address.toint()];
241  else result = calcLocalPhi(address);
242 
243  return result;
244 }
245 
246 double CSCSectorReceiverLUT::getGlobalPhiValue(const CSCLayer* thelayer, const unsigned& strip, const unsigned& wire_group) const
247 {
248  double result = 0.0;
249  //CSCLayerGeometry* thegeom;
250  //LocalPoint lp;
251  //GlobalPoint gp;
252 
253  try
254  {
255  //thegeom = const_cast<CSCLayerGeometry*>(thelayer->geometry());
256  //lp = thegeom->stripWireGroupIntersection(strip, wire_group);
257  //gp = thelayer->surface().toGlobal(lp);
258  result = thelayer->centerOfStrip(strip).phi();//gp.phi();
259 
260  if (result < 0.) result += 2.*M_PI;
261  }
262  catch(edm::Exception& e)
263  {
264  LogDebug("CSCSectorReceiverLUT|getGlobalPhiValue") << e.what();
265  }
266 
267  return result;
268 }
269 
271 {
272  gblphidat result(0);
273  const CSCChamber* thechamber = nullptr;
274  const CSCLayer* thelayer = nullptr;
275  const CSCLayerGeometry* layergeom = nullptr;
276  int cscid = address.cscid;
277  unsigned wire_group = address.wire_group;
278  unsigned local_phi = address.phi_local;
279  const double sectorOffset = (CSCTFConstants::SECTOR1_CENT_RAD-CSCTFConstants::SECTOR_RAD/2.) + (_sector-1)*M_PI/3.;
280 
281  //Number of global phi units per radian.
283  double binPhiG = static_cast<double>(maxPhiG)/CSCTFConstants::SECTOR_RAD;
284 
285  // We will use these to convert the local phi into radians.
286  constexpr unsigned int maxPhiL = 1<<CSCBitWidths::kLocalPhiDataBitWidth;
287  const double binPhiL = static_cast<double>(maxPhiL)/(2.*CSCConstants::MAX_NUM_STRIPS);
288 
290  {
291  edm::LogWarning("CSCSectorReceiverLUT|getGlobalPhiValue")
292  << " warning: cscId " << cscid << " is out of bounds ["
295  throw cms::Exception("CSCSectorReceiverLUT")
296  << "+++ Value of CSC ID, " << cscid
297  << ", is out of bounds [" << CSCTriggerNumbering::minTriggerCscId() << "-"
298  << CSCTriggerNumbering::maxTriggerCscId() << "] +++\n";
299  }
300 
302  {
303  edm::LogWarning("CSCSectorReceiverLUT|getGlobalPhiValue")
304  << " warning: cscId " << cscid << " is out of bounds ["
307  throw cms::Exception("CSCSectorReceiverLUT")
308  << "+++ Value of CSC ID, " << cscid
309  << ", is out of bounds [" << CSCTriggerNumbering::minTriggerCscId() << "-"
310  << CSCTriggerNumbering::maxTriggerCscId() << "] +++\n";
311  }
312 
313  if(wire_group >= 1<<5)
314  {
315  edm::LogWarning("CSCSectorReceiverLUT|getGlobalPhiValue")
316  << "warning: wire_group" << wire_group
317  << " is out of bounds (1-" << ((1<<5)-1) << "]\n";
318  throw cms::Exception("CSCSectorReceiverLUT")
319  << "+++ Value of wire_group, " << wire_group
320  << ", is out of bounds (1-" << ((1<<5)-1) << "] +++\n";
321  }
322 
323  if(local_phi >= maxPhiL)
324  {
325  edm::LogWarning("CSCSectorReceiverLUT|getGlobalPhiValue")
326  << "warning: local_phi" << local_phi
327  << " is out of bounds [0-" << maxPhiL << ")\n";
328  throw cms::Exception("CSCSectorReceiverLUT")
329  << "+++ Value of local_phi, " << local_phi
330  << ", is out of bounds [0-, " << maxPhiL << ") +++\n";
331  }
332 
333  try
334  {
337  CSCDetId detid(_endcap, _station, ring, chid, 0);
338  thechamber = const_cast<const CSCChamber*>(csc_g->chamber(detid));
339  if(thechamber)
340  {
341  if(isTMB07)
342  {
343  layergeom = thechamber->layer(CSCConstants::KEY_CLCT_LAYER)->geometry();
344  thelayer = thechamber->layer(CSCConstants::KEY_CLCT_LAYER);
345  }
346  else
347  {
348  layergeom = thechamber->layer(CSCConstants::KEY_CLCT_LAYER_PRE_TMB07)->geometry();
349  thelayer = thechamber->layer(CSCConstants::KEY_CLCT_LAYER_PRE_TMB07);
350  }
351  const int nStrips = layergeom->numberOfStrips();
352  // PhiL is the strip number converted into some units between 0 and
353  // 1023. When we did the conversion in fillLocalPhiTable(), we did
354  // not know for which chamber we do it (and, therefore, how many strips
355  // it has), and always used the maximum possible number of strips
356  // per chamber, MAX_NUM_STRIPS=80. Now, since we know the chamber id
357  // and how many strips the chamber has, we can re-adjust the scale.
358  //const double scale = static_cast<double>(CSCConstants::MAX_NUM_STRIPS)/nStrips;
359 
360  int strip = 0, halfstrip = 0;
361 
362  halfstrip = static_cast<int>(local_phi/binPhiL);
363  strip = halfstrip/2;
364 
365  // Find the phi width of the chamber and the position of its "left"
366  // (lower phi) edge (both in radians).
367  // Phi positions of the centers of the first and of the last strips
368  // in the chamber.
369  const double phi_f = getGlobalPhiValue(thelayer, 1, wire_group);
370  const double phi_l = getGlobalPhiValue(thelayer, nStrips, wire_group);
371  // Phi widths of the half-strips at both ends of the chamber;
372  // surprisingly, they are not the same.
373  const double hsWidth_f = fabs(getGlobalPhiValue(thelayer, 2, wire_group) - phi_f)/2.;
374  const double hsWidth_l = fabs(phi_l - getGlobalPhiValue(thelayer, nStrips - 1, wire_group))/2.;
375 
376  // The "natural" match between the strips and phi values -- when
377  // a larger strip number corresponds to a larger phi value, i.e. strips
378  // are counted clockwise if we look at them from the inside of the
379  // detector -- is reversed for some stations. At the moment, these
380  // are stations 3 and 4 of the 1st endcap, and stations 1 and 2 of
381  // the 2nd endcap. Instead of using
382  // if ((theEndcap == 1 && theStation <= 2) ||
383  // (theEndcap == 2 && theStation >= 3)),
384  // we get the order from the phi values of the first and the last strip
385  // in a chamber, just in case the counting scheme changes in the future.
386  // Once we know how the strips are counted, we can go from the middle
387  // of the strips to their outer edges.
388  bool clockwiseOrder;
389  double leftEdge, rightEdge;
390  if (fabs(phi_f - phi_l) < M_PI)
391  {
392  if (phi_f < phi_l) clockwiseOrder = true;
393  else clockwiseOrder = false;
394  }
395  else
396  { // the chamber crosses the phi = pi boundary
397  if (phi_f < phi_l) clockwiseOrder = false;
398  else clockwiseOrder = true;
399  }
400  if (clockwiseOrder)
401  {
402  leftEdge = phi_f - hsWidth_f;
403  rightEdge = phi_l + hsWidth_l;
404  }
405  else
406  {
407  leftEdge = phi_l - hsWidth_l;
408  rightEdge = phi_f + hsWidth_f;
409  }
410  if (fabs(phi_f - phi_l) >= M_PI) {rightEdge += 2.*M_PI;}
411  //double chamberWidth = (rightEdge - leftEdge);
412 
413  // Chamber offset, relative to the edge of the sector.
414  //double chamberOffset = leftEdge - sectorOffset;
415  //if (chamberOffset < -M_PI) chamberOffset += 2*M_PI;
416 
417  double temp_phi = 0.0, strip_phi = 0.0, delta_phi = 0.0;
418  double distFromHalfStripCenter = 0.0, halfstripWidth = 0.0;
419 
420  if (strip < nStrips)
421  {
422  // Approximate distance from the center of the half-strip to the center
423  // of this phil bin, in units of half-strip width.
424  distFromHalfStripCenter = (local_phi+0.5)/binPhiL - halfstrip - 0.5;
425  // Half-strip width (in rad), calculated as the half-distance between
426  // the adjacent strips. Since in the current ORCA implementation
427  // the half-strip width changes from strip to strip, base the choice
428  // of the adjacent strip on the half-strip number.
429  if ((halfstrip%2 == 0 && halfstrip != 0) || halfstrip == 2*nStrips-1) {
430  halfstripWidth =
431  fabs(getGlobalPhiValue(thelayer, strip+1, wire_group) - getGlobalPhiValue(thelayer, strip, wire_group)) / 2.;
432  }
433  else
434  {
435  halfstripWidth =
436  fabs(getGlobalPhiValue(thelayer, strip+1, wire_group) - getGlobalPhiValue(thelayer, strip+2, wire_group)) / 2.;
437  }
438  // Correction for the strips crossing the 180 degree boundary.
439  if (halfstripWidth > M_PI/2.) halfstripWidth = M_PI - halfstripWidth;
440  // Phi at the center of the strip.
441  strip_phi = getGlobalPhiValue(thelayer, strip+1, wire_group);
442  // Distance between the center of the strip and the phil position.
443  delta_phi = halfstripWidth*(((halfstrip%2)-0.5)+distFromHalfStripCenter);
444  if (clockwiseOrder)
445  temp_phi = strip_phi+ delta_phi;
446  else
447  temp_phi = strip_phi- delta_phi;
448  }
449  else
450  {
451  // PhiL values that do not have corresponding strips (the chamber
452  // has less than 80 strips assumed in fillLocalPhi). It does not
453  // really matter what we do with these values; at the moment, just
454  // set them to the phis of the edges of the chamber.
455  if (clockwiseOrder) temp_phi = rightEdge;
456  else temp_phi = leftEdge;
457  }
458 
459  // Finally, subtract the sector offset and convert to the scale of
460  // the global phi.
461 
462  temp_phi -= sectorOffset;
463 
464  if (temp_phi < 0.) temp_phi += 2.*M_PI;
465 
466  temp_phi *= binPhiG;
467 
468  if (temp_phi < 0.)
469  {
470  result.global_phi = 0;
471  }
472  else if (temp_phi >= maxPhiG)
473  {
474  result.global_phi = maxPhiG - 1;
475  }
476  else
477  {
478  result.global_phi = static_cast<unsigned short>(temp_phi);
479  }
480 
481  LogDebug("CSCSectorReceiverLUT")
482  << "local_phi = " << local_phi
483  << " halfstrip = " << halfstrip << " strip = " << strip
484  << " distFromHalfStripCenter = " << distFromHalfStripCenter
485  << " halfstripWidth = " << halfstripWidth
486  << " strip phi = " << strip_phi/(M_PI/180.)
487  << " temp_phi = " << temp_phi*CSCTFConstants::SECTOR_DEG/maxPhiG
488  << " global_phi = " << result.global_phi
489  << " " << result.global_phi*CSCTFConstants::SECTOR_DEG/maxPhiG;
490 
491  }
492  }
493  catch(edm::Exception& e)
494  {
495  edm::LogError("CSCSectorReceiverLUT|getGlobalPhiValue") << e.what();
496  }
497 
498  return result;
499 }
500 
501 gblphidat CSCSectorReceiverLUT::globalPhiME(int phi_local, int wire_group, int cscid, const bool gangedME1a) const
502 {
504  gblphiadd theadd;
505  theadd.phi_local = phi_local;
506  theadd.wire_group = ((1<<5)-1)&(wire_group >> 2); // want 2-7 of wg
507  theadd.cscid = cscid;
508 
510  else if(LUTsFromFile) result = me_global_phi[theadd.toint()];
511  else result = calcGlobalPhiME(theadd);
512 
513  return result;
514 }
515 
516 gblphidat CSCSectorReceiverLUT::globalPhiME(unsigned address, const bool gangedME1a) const
517 {
519 
521  else if(LUTsFromFile) result = me_global_phi[address];
522  else result = calcGlobalPhiME(gblphiadd(address));
523 
524  return result;
525 }
526 
527 gblphidat CSCSectorReceiverLUT::globalPhiME(gblphiadd address, const bool gangedME1a) const
528 {
530 
532  else if(LUTsFromFile) result = me_global_phi[address.toint()];
533  else result = calcGlobalPhiME(address);
534 
535  return result;
536 }
537 
539 {
540  gblphidat dtlut;
541 
542  // The following method was ripped from D. Holmes' LUT conversion program
543  // modifications from Darin and GP
544  int GlobalPhiMin = (_subsector == 1) ? 0x42 : 0x800; // (0.999023 : 31 in degrees)
545  int GlobalPhiMax = (_subsector == 1) ? 0x7ff : 0xfbd; // (30.985 : 60.986 in degrees)
546  double GlobalPhiShift = (1.0*GlobalPhiMin + (GlobalPhiMax - GlobalPhiMin)/2.0);
547 
548  double dt_out = static_cast<double>(csclut.global_phi) - GlobalPhiShift;
549 
550  // these numbers are 62 deg / 1 rad (CSC phi scale vs. DT phi scale)
551  dt_out = (dt_out/1982)*2145; //CSC phi 62 degrees; DT phi 57.3 degrees
552 
553  if(dt_out >= 0) // msb != 1
554  {
555  dtlut.global_phi = 0x7ff&static_cast<unsigned>(dt_out);
556  }
557  else
558  {
559  dtlut.global_phi = static_cast<unsigned>(-dt_out);
560  dtlut.global_phi = ~dtlut.global_phi;
561  dtlut.global_phi |= 0x800;
562  }
563 
564  return dtlut;
565 }
566 
567 gblphidat CSCSectorReceiverLUT::globalPhiMB(int phi_local,int wire_group, int cscid, const bool gangedME1a) const
568 {
569  gblphiadd address;
571 
572  address.cscid = cscid;
573  address.wire_group = ((1<<5)-1)&(wire_group>>2);
574  address.phi_local = phi_local;
575 
576  // comment for now
577  // if(useMiniLUTs && isTMB07) result = CSCSectorReceiverMiniLUT::calcGlobalPhiMBMini(_endcap, _sector, _subsector, address.toint());
578  //else
579  if(LUTsFromFile) result = mb_global_phi[address.toint()];
580  else result = calcGlobalPhiMB(globalPhiME(address, gangedME1a));
581 
582  return result;
583 }
584 
585 gblphidat CSCSectorReceiverLUT::globalPhiMB(unsigned address, const bool gangedME1a) const
586 {
588  gblphiadd theadd(address);
589 
590  //if(useMiniLUTs && isTMB07) result = CSCSectorReceiverMiniLUT::calcGlobalPhiMBMini(_endcap, _sector, _subsector, address);
591  //else
592  if(LUTsFromFile) result = mb_global_phi[theadd.toint()];
593  else result = calcGlobalPhiMB(globalPhiME(address, gangedME1a));
594 
595  return result;
596 }
597 
598 gblphidat CSCSectorReceiverLUT::globalPhiMB(gblphiadd address, const bool gangedME1a) const
599 {
601 
602  //if(useMiniLUTs && isTMB07) result = CSCSectorReceiverMiniLUT::calcGlobalPhiMBMini(_endcap, _sector, _subsector, address.toint());
603  //else
604  if(LUTsFromFile) result = mb_global_phi[address.toint()];
605  else result = calcGlobalPhiMB(globalPhiME(address, gangedME1a));
606 
607  return result;
608 }
609 
610 double CSCSectorReceiverLUT::getGlobalEtaValue(const unsigned& thecscid, const unsigned& thewire_group, const unsigned& thephi_local) const
611 {
612  double result = 0.0;
613  unsigned wire_group = thewire_group;
614  int cscid = thecscid;
615  unsigned phi_local = thephi_local;
616 
617  // Flag to be set if one wants to apply phi corrections ONLY in ME1/1.
618  // Turn it into a parameter?
619  bool me1ir_only = false;
620 
623  edm::LogWarning("CSCSectorReceiverLUT|getEtaValue")
624  << " warning: cscId " << cscid
625  << " is out of bounds [1-" << CSCTriggerNumbering::maxTriggerCscId()
626  << "]\n";
628  }
629 
630  CSCLayerGeometry* layerGeom = nullptr;
631  const unsigned numBins = 1 << 2; // 4 local phi bins
632 
633  if(phi_local > numBins - 1) {
634  edm::LogWarning("CSCSectorReceiverLUT|getEtaValue")
635  << "warning: phiL " << phi_local
636  << " is out of bounds [0-" << numBins - 1 << "]\n";
637  phi_local = numBins - 1;
638  }
639  try
640  {
643  CSCDetId detid(_endcap, _station, ring, chid, 0);
644  const CSCChamber* thechamber = const_cast<const CSCChamber*>(csc_g->chamber(detid));
645  if(thechamber) {
646  layerGeom = const_cast<CSCLayerGeometry*>(thechamber->layer(CSCConstants::KEY_ALCT_LAYER)->geometry());
647  const unsigned nWireGroups = layerGeom->numberOfWireGroups();
648 
649  // Check wire group numbers; expect them to be counted from 0, as in
650  // CorrelatedLCTDigi class.
651  if (wire_group >= nWireGroups) {
652  edm::LogWarning("CSCSectorReceiverLUT|getEtaValue")
653  << "warning: wireGroup " << wire_group
654  << " is out of bounds [0-" << nWireGroups << ")\n";
655  wire_group = nWireGroups - 1;
656  }
657  // Convert to [1; nWireGroups] range used in geometry methods.
658  wire_group += 1;
659 
660  // If me1ir_only is set, apply phi corrections only in ME1/1.
661  if (me1ir_only &&
662  (_station != 1 ||
664  {
665  result = thechamber->layer(CSCConstants::KEY_ALCT_LAYER)->centerOfWireGroup(wire_group).eta();
666  }
667  else {
668  const unsigned nStrips = layerGeom->numberOfStrips();
669  const unsigned nStripsPerBin = CSCConstants::MAX_NUM_STRIPS/numBins;
674  // Check that no strips will be left out.
675  if (nStrips%numBins != 0 || CSCConstants::MAX_NUM_STRIPS%numBins != 0)
676  edm::LogWarning("CSCSectorReceiverLUT")
677  << "getGlobalEtaValue warning: number of strips "
678  << nStrips << " (" << CSCConstants::MAX_NUM_STRIPS
679  << ") is not divisible by numBins " << numBins
680  << " Station " << _station << " sector " << _sector
681  << " subsector " << _subsector << " cscid " << cscid << "\n";
682 
683  unsigned maxStripPrevBin = 0, maxStripThisBin = 0;
684  unsigned correctionStrip;
685  LocalPoint lPoint;
686  GlobalPoint gPoint;
687  // Bins phi_local and find the the middle strip for each bin.
688  maxStripThisBin = nStripsPerBin * (phi_local+1);
689  if (maxStripThisBin <= nStrips) {
690  correctionStrip = nStripsPerBin/2 * (2*phi_local+1);
691  }
692  else {
693  // If the actual number of strips in the chamber is smaller than
694  // the number of strips corresponding to the right edge of this phi
695  // local bin, we take the middle strip between number of strips
696  // at the left edge of the bin and the actual number of strips.
697  maxStripPrevBin = nStripsPerBin * phi_local;
698  correctionStrip = (nStrips+maxStripPrevBin)/2;
699  }
700 
701  lPoint = layerGeom->stripWireGroupIntersection(correctionStrip, wire_group);
702  gPoint = thechamber->layer(CSCConstants::KEY_ALCT_LAYER)->surface().toGlobal(lPoint);
703 
704  // end calc of eta correction.
705  result = gPoint.eta();
706  }
707  }
708  }
709  catch (cms::Exception &e)
710  {
711  LogDebug("CSCSectorReceiver|OutofBoundInput") << e.what();
712  }
713 
714  return std::fabs(result);
715 }
716 
717 
719 {
720 
721 
723  double float_eta = getGlobalEtaValue(address.cscid, address.wire_group, address.phi_local);
724  unsigned int_eta = 0;
725  unsigned bend_global = 0; // not filled yet... will change when it is.
727  const unsigned me12EtaCut = 56;
728 
729 
730 
731 
732 
733  if ((float_eta < CSCTFConstants::minEta) || (float_eta >= CSCTFConstants::maxEta))
734  {
735  edm::LogWarning("CSCSectorReceiverLUT:OutOfBounds")
736  << "CSCSectorReceiverLUT warning: float_eta = " << float_eta
737  << " minEta = " << CSCTFConstants::minEta << " maxEta = " << CSCTFConstants::maxEta
738  << " station " << _station << " sector " << _sector
739  << " chamber " << address.cscid << " wire group " << address.wire_group;
740 
741  throw cms::Exception("CSCSectorReceiverLUT")
742  << "+++ Value of CSC ID, " << float_eta
743  << ", is out of bounds [" << CSCTFConstants::minEta << "-"
744  << CSCTFConstants::maxEta << ") +++\n";
745 
746  //if (float_eta < CSCTFConstants::minEta)
747  //result.global_eta = 0;
748  //else if (float_eta >= CSCTFConstants::maxEta)
749  //result.global_eta = CSCTFConstants::etaBins - 1;
750  }
751  else
752  {
753  float_eta -= CSCTFConstants::minEta;
754  float_eta = float_eta/etaPerBin;
755  int_eta = static_cast<unsigned>(float_eta);
756  /* Commented until I find out its use.
757  // Fine-tune eta boundary between DT and CSC.
758  if ((intEta == L1MuCSCSetup::CscEtaStart() && (L1MuCSCSetup::CscEtaStartCorr() > 0.) ) ||
759  (intEta == L1MuCSCSetup::CscEtaStart() - 1 && (L1MuCSCSetup::CscEtaStartCorr() < 0.) ) ) {
760  bitEta = (thisEta-minEta-L1MuCSCSetup::CscEtaStartCorr())/EtaPerBin;
761  intEta = static_cast<int>(bitEta);
762  }
763  */
764  if (_station == 1 && address.cscid >= static_cast<unsigned>(CSCTriggerNumbering::minTriggerCscId())
765  && address.cscid <= static_cast<unsigned>(CSCTriggerNumbering::maxTriggerCscId()) )
766  {
767  unsigned ring = CSCTriggerNumbering::ringFromTriggerLabels(_station, address.cscid);
768 
769  if (ring == 1 && int_eta < me12EtaCut) {int_eta = me12EtaCut;}
770  else if (ring == 2 && int_eta >= me12EtaCut) {int_eta = me12EtaCut-1;}
771  }
772  result.global_eta = int_eta;
773  }
774  result.global_bend = bend_global;
775 
776  return result;
777 }
778 
779 gbletadat CSCSectorReceiverLUT::globalEtaME(int tphi_bend, int tphi_local, int twire_group, int tcscid, const bool gangedME1a) const
780 {
782  gbletaadd theadd;
783 
784  theadd.phi_bend = tphi_bend;
785  theadd.phi_local = (tphi_local>>(CSCBitWidths::kLocalPhiDataBitWidth - 2)) & 0x3; // want 2 msb of local phi
786  theadd.wire_group = twire_group;
787  theadd.cscid = tcscid;
789  else if(LUTsFromFile) result = me_global_eta[theadd.toint()];
790  else result = calcGlobalEtaME(theadd);
791 
792 
793  return result;
794 }
795 
796 gbletadat CSCSectorReceiverLUT::globalEtaME(unsigned address, const bool gangedME1a ) const
797 {
799  gbletaadd theadd(address);
800 
802  else if(LUTsFromFile) result = me_global_eta[address];
803  else result = calcGlobalEtaME(theadd);
804  return result;
805 }
806 
807 gbletadat CSCSectorReceiverLUT::globalEtaME(gbletaadd address, const bool gangedME1a) const
808 {
810 
812  else if(LUTsFromFile) result = me_global_eta[address.toint()];
813  else result = calcGlobalEtaME(address);
814  return result;
815 }
816 
818  std::string fileName = "";
819  if (_station == 1) {
820  if (_subsector == 1) fileName += "1a";
821  if (_subsector == 2) fileName += "1b";
822  }
823  else if (_station == 2) fileName += "2";
824  else if (_station == 3) fileName += "3";
825  else if (_station == 4) fileName += "4";
826  fileName += "End";
827  if (_endcap == 1) fileName += "1";
828  else fileName += "2";
829  fileName += "Sec";
830  if (_sector == 1) fileName += "1";
831  else if (_sector == 2) fileName += "2";
832  else if (_sector == 3) fileName += "3";
833  else if (_sector == 4) fileName += "4";
834  else if (_sector == 5) fileName += "5";
835  else if (_sector == 6) fileName += "6";
836  fileName += "LUT";
837  return fileName;
838 }
839 
841 {
842  if(!me_lcl_phi_loaded)
843  {
846  std::ifstream LocalPhiLUT;
847 
848  edm::LogInfo("CSCSectorReceiverLUT") << "Loading SR LUT: " << fName;
849 
850  if(isBinary)
851  {
852  LocalPhiLUT.open(fName.c_str(),std::ios::binary);
853  LocalPhiLUT.seekg(0,std::ios::end);
854  int length = LocalPhiLUT.tellg();
855  if(length == (1<<CSCBitWidths::kLocalPhiAddressWidth)*sizeof(short))
856  {
857  LocalPhiLUT.seekg(0,std::ios::beg);
858  LocalPhiLUT.read(reinterpret_cast<char*>(me_lcl_phi),length);
859  LocalPhiLUT.close();
860  }
861  else
862  edm::LogError("CSCSectorReceiverLUT") << "File "<< fName << " is incorrect size!";
863  LocalPhiLUT.close();
864  }
865  else
866  {
867  LocalPhiLUT.open(fName.c_str());
868  unsigned i = 0;
869  unsigned short temp = 0;
870  while(!LocalPhiLUT.eof() && i < 1<<CSCBitWidths::kLocalPhiAddressWidth)
871  {
872  LocalPhiLUT >> temp;
873  me_lcl_phi[i++] = (*reinterpret_cast<lclphidat*>(&temp));
874  }
875  LocalPhiLUT.close();
876  }
877  }
878  if(!me_global_phi)
879  {
882  std::ifstream GlobalPhiLUT;
883 
884  edm::LogInfo("CSCSectorReceiverLUT") << "Loading SR LUT: " << fName;
885 
886  if(isBinary)
887  {
888  GlobalPhiLUT.open(fName.c_str(),std::ios::binary);
889  GlobalPhiLUT.seekg(0,std::ios::end);
890  int length = GlobalPhiLUT.tellg();
891  if(length == (1<<CSCBitWidths::kGlobalPhiAddressWidth)*sizeof(short))
892  {
893  GlobalPhiLUT.seekg(0,std::ios::beg);
894  GlobalPhiLUT.read(reinterpret_cast<char*>(me_global_phi),length);
895  }
896  else
897  edm::LogError("CSCSectorReceiverLUT") << "File "<< fName << " is incorrect size!";
898  GlobalPhiLUT.close();
899  }
900  else
901  {
902  GlobalPhiLUT.open( fName.c_str());
903  unsigned short temp = 0;
904  unsigned i = 0;
905  while(!GlobalPhiLUT.eof() && i < 1<<CSCBitWidths::kGlobalPhiAddressWidth)
906  {
907  GlobalPhiLUT >> temp;
908  me_global_phi[i++] = (*reinterpret_cast<gblphidat*>(&temp));
909  }
910  GlobalPhiLUT.close();
911  }
912  }
913  if(!mb_global_phi && _station == 1) // MB lut only in station one.
914  {
917  std::ifstream GlobalPhiLUT;
918 
919  edm::LogInfo("CSCSectorReceiverLUT") << "Loading SR LUT: " << fName;
920 
921  if(isBinary)
922  {
923  GlobalPhiLUT.open( fName.c_str(),std::ios::binary);
924  GlobalPhiLUT.seekg(0,std::ios::end);
925  int length = GlobalPhiLUT.tellg();
926  if(length == (1<<CSCBitWidths::kGlobalPhiAddressWidth)*sizeof(short))
927  {
928  GlobalPhiLUT.seekg(0,std::ios::beg);
929  GlobalPhiLUT.read(reinterpret_cast<char*>(mb_global_phi),length);
930  }
931  else
932  edm::LogError("CSCSectorReceiverLUT") << "File "<< fName << " is incorrect size!";
933  GlobalPhiLUT.close();
934  }
935  else
936  {
937  GlobalPhiLUT.open(fName.c_str());
938  unsigned short temp = 0;
939  unsigned i = 0;
940  while(!GlobalPhiLUT.eof() && i < 1<<CSCBitWidths::kGlobalPhiAddressWidth)
941  {
942  GlobalPhiLUT >> temp;
943  mb_global_phi[i++] = (*reinterpret_cast<gblphidat*>(&temp));
944  }
945  GlobalPhiLUT.close();
946  }
947  }
948  if(!me_global_eta)
949  {
952  std::ifstream GlobalEtaLUT;
953 
954  edm::LogInfo("CSCSectorReceiverLUT") << "Loading SR LUT: " << fName;
955 
956  if(isBinary)
957  {
958  GlobalEtaLUT.open(fName.c_str(),std::ios::binary);
959  GlobalEtaLUT.seekg(0,std::ios::end);
960  int length = GlobalEtaLUT.tellg();
961  if(length == (1<<CSCBitWidths::kGlobalEtaAddressWidth)*sizeof(short))
962  {
963  GlobalEtaLUT.seekg(0,std::ios::beg);
964  GlobalEtaLUT.read(reinterpret_cast<char*>(me_global_eta),length);
965  }
966  else
967  edm::LogError("CSCSectorReceiverLUT") << "File "<< fName << " is incorrect size!";
968  GlobalEtaLUT.close();
969  }
970  else
971  {
972  GlobalEtaLUT.open(fName.c_str());
973  unsigned short temp = 0;
974  unsigned i = 0;
975  while(!GlobalEtaLUT.eof() && i < 1<<CSCBitWidths::kGlobalEtaAddressWidth)
976  {
977  GlobalEtaLUT >> temp;
978  me_global_eta[i++] = (*reinterpret_cast<gbletadat*>(&temp));
979  }
980  GlobalEtaLUT.close();
981  }
982  }
983 }
984 
#define LogDebug(id)
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:106
LocalPoint stripWireGroupIntersection(int strip, int wireGroup) const
T getUntrackedParameter(std::string const &, T const &) const
lclphidat localPhi(int strip, int pattern, int quality, int lr, const bool gangedME1a=false) const
Geometry Lookup Tables.
static global_phi_data calcGlobalPhiMEMini(unsigned short endcap, unsigned short sector, unsigned short station, unsigned short subsector, unsigned theadd, const bool gangedME1a)
static double getPosition(int pattern)
Definition: CSCPatternLUT.cc:9
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
static const double minEta
int numberOfStrips() const
char const * what() const override
Definition: Exception.cc:141
gbletadat calcGlobalEtaME(const gbletaadd &address) const
Global Eta LUT.
std::string encodeFileIndex() const
Helpers.
class global_phi_address gblphiadd
edm::FileInPath mb_gbl_phi_file
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
CSCSectorReceiverLUT & operator=(const CSCSectorReceiverLUT &)
int numberOfWireGroups() const
static int ringFromTriggerLabels(int station, int triggerCSCID)
#define constexpr
double getGlobalPhiValue(const CSCLayer *thelayer, const unsigned &strip, const unsigned &wire_group) const
static const double SECTOR1_CENT_RAD
gblphidat globalPhiME(int phi_local, int wire_group, int cscid, const bool gangedME1a=false) const
double getGlobalEtaValue(const unsigned &cscid, const unsigned &wire_group, const unsigned &phi_local) const
edm::FileInPath me_gbl_phi_file
edm::FileInPath me_lcl_phi_file
CSCSectorReceiverLUT(int endcap, int sector, int subsector, int station, const edm::ParameterSet &pset, bool TMB07)
const CSCLayer * layer(CSCDetId id) const
Return the layer corresponding to the given id.
Definition: CSCChamber.cc:39
static const double maxEta
#define end
Definition: vmac.h:39
static lclphidat calcLocalPhiMini(unsigned theadd, const bool gangedME1a)
GlobalPoint centerOfWireGroup(int wireGroup) const
Definition: CSCLayer.cc:10
gblphidat globalPhiMB(int phi_local, int wire_group, int cscid, const bool gangedME1a=false) const
#define M_PI
GlobalPoint centerOfStrip(int strip) const
Definition: CSCLayer.cc:4
static double get2007Position(int pattern)
edm::FileInPath me_gbl_eta_file
static const double SECTOR_DEG
static lclphidat * me_lcl_phi
class global_phi_data gblphidat
const CSCChamber * chamber(CSCDetId id) const
Return the chamber corresponding to given DetId.
Definition: CSCGeometry.cc:133
class local_phi_address lclphiadd
class local_phi_data lclphidat
Data Types.
T eta() const
Definition: PV3DBase.h:76
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
gbletadat globalEtaME(int phi_bend, int phi_local, int wire_group, int cscid, const bool gangedME1a=false) const
gblphidat calcGlobalPhiME(const gblphiadd &address) const
Global Phi LUT.
class global_eta_address gbletaadd
static const double SECTOR_RAD
std::string fullPath() const
Definition: FileInPath.cc:197
lclphidat calcLocalPhi(const lclphiadd &address) const
Local Phi LUT.
class global_eta_data gbletadat
const CSCGeometry * csc_g
static global_eta_data calcGlobalEtaMEMini(unsigned short endcap, unsigned short sector, unsigned short station, unsigned short subsector, unsigned theadd, const bool gangedME1a)
const CSCLayerGeometry * geometry() const
Definition: CSCLayer.h:47
static int chamberFromTriggerLabels(int TriggerSector, int TriggerSubSector, int station, int TriggerCSCID)
gblphidat calcGlobalPhiMB(const gblphidat &me_gphi_data) const