test
CMS 3D CMS Logo

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