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
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);
218 }
219 
221 {
223  lclphiadd theadd(address);
224 
225  if(useMiniLUTs && isTMB07)
226  {
228  }
229  else if(LUTsFromFile) result = me_lcl_phi[address];
230  else result = calcLocalPhi(theadd);
231 
232  return result;
233 }
234 
236 {
238 
239  if(useMiniLUTs && isTMB07)
240  {
241  result = CSCSectorReceiverMiniLUT::calcLocalPhiMini(address.toint());
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
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 
518 {
520 
522  else if(LUTsFromFile) result = me_global_phi[address];
523  else result = calcGlobalPhiME(gblphiadd(address));
524 
525  return result;
526 }
527 
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
569 {
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));
582 
583  return result;
584 }
585 
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));
595 
596  return result;
597 }
598 
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));
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 {
720  double float_eta = getGlobalEtaValue(address.cscid, address.wire_group, address.phi_local);
721  unsigned int_eta = 0;
722  unsigned bend_global = 0; // not filled yet... will change when it is.
724  const unsigned me12EtaCut = 56;
725 
726  if ((float_eta < CSCTFConstants::minEta) || (float_eta >= CSCTFConstants::maxEta))
727  {
728  edm::LogWarning("CSCSectorReceiverLUT:OutOfBounds")
729  << "CSCSectorReceiverLUT warning: float_eta = " << float_eta
730  << " minEta = " << CSCTFConstants::minEta << " maxEta = " << CSCTFConstants::maxEta
731  << " station " << _station << " sector " << _sector
732  << " chamber " << address.cscid << " wire group " << address.wire_group;
733 
734  throw cms::Exception("CSCSectorReceiverLUT")
735  << "+++ Value of CSC ID, " << float_eta
736  << ", is out of bounds [" << CSCTFConstants::minEta << "-"
737  << CSCTFConstants::maxEta << ") +++\n";
738 
739  //if (float_eta < CSCTFConstants::minEta)
740  //result.global_eta = 0;
741  //else if (float_eta >= CSCTFConstants::maxEta)
742  //result.global_eta = CSCTFConstants::etaBins - 1;
743  }
744  else
745  {
746  float_eta -= CSCTFConstants::minEta;
747  float_eta = float_eta/etaPerBin;
748  int_eta = static_cast<unsigned>(float_eta);
749  /* Commented until I find out its use.
750  // Fine-tune eta boundary between DT and CSC.
751  if ((intEta == L1MuCSCSetup::CscEtaStart() && (L1MuCSCSetup::CscEtaStartCorr() > 0.) ) ||
752  (intEta == L1MuCSCSetup::CscEtaStart() - 1 && (L1MuCSCSetup::CscEtaStartCorr() < 0.) ) ) {
753  bitEta = (thisEta-minEta-L1MuCSCSetup::CscEtaStartCorr())/EtaPerBin;
754  intEta = static_cast<int>(bitEta);
755  }
756  */
757  if (_station == 1 && address.cscid >= static_cast<unsigned>(CSCTriggerNumbering::minTriggerCscId())
758  && address.cscid <= static_cast<unsigned>(CSCTriggerNumbering::maxTriggerCscId()) )
759  {
760  unsigned ring = CSCTriggerNumbering::ringFromTriggerLabels(_station, address.cscid);
761 
762  if (ring == 1 && int_eta < me12EtaCut) {int_eta = me12EtaCut;}
763  else if (ring == 2 && int_eta >= me12EtaCut) {int_eta = me12EtaCut-1;}
764  }
765  result.global_eta = int_eta;
766  }
767  result.global_bend = bend_global;
768 
769  return result;
770 }
771 
772 gbletadat CSCSectorReceiverLUT::globalEtaME(int tphi_bend, int tphi_local, int twire_group, int tcscid) const
773 {
775  gbletaadd theadd;
776 
777  theadd.phi_bend = tphi_bend;
778  theadd.phi_local = (tphi_local>>(CSCBitWidths::kLocalPhiDataBitWidth - 2)) & 0x3; // want 2 msb of local phi
779  theadd.wire_group = twire_group;
780  theadd.cscid = tcscid;
781 
783  else if(LUTsFromFile) result = me_global_eta[theadd.toint()];
784  else result = calcGlobalEtaME(theadd);
785 
786  return result;
787 }
788 
790 {
792  gbletaadd theadd(address);
793 
795  else if(LUTsFromFile) result = me_global_eta[address];
796  else result = calcGlobalEtaME(theadd);
797  return result;
798 }
799 
801 {
803 
805  else if(LUTsFromFile) result = me_global_eta[address.toint()];
806  else result = calcGlobalEtaME(address);
807  return result;
808 }
809 
811  std::string fileName = "";
812  if (_station == 1) {
813  if (_subsector == 1) fileName += "1a";
814  if (_subsector == 2) fileName += "1b";
815  }
816  else if (_station == 2) fileName += "2";
817  else if (_station == 3) fileName += "3";
818  else if (_station == 4) fileName += "4";
819  fileName += "End";
820  if (_endcap == 1) fileName += "1";
821  else fileName += "2";
822  fileName += "Sec";
823  if (_sector == 1) fileName += "1";
824  else if (_sector == 2) fileName += "2";
825  else if (_sector == 3) fileName += "3";
826  else if (_sector == 4) fileName += "4";
827  else if (_sector == 5) fileName += "5";
828  else if (_sector == 6) fileName += "6";
829  fileName += "LUT";
830  return fileName;
831 }
832 
834 {
835  if(!me_lcl_phi_loaded)
836  {
838  memset(me_lcl_phi, 0, (1<<CSCBitWidths::kLocalPhiAddressWidth)*sizeof(short));
840  std::ifstream LocalPhiLUT;
841 
842  edm::LogInfo("CSCSectorReceiverLUT") << "Loading SR LUT: " << fName;
843 
844  if(isBinary)
845  {
846  LocalPhiLUT.open(fName.c_str(),std::ios::binary);
847  LocalPhiLUT.seekg(0,std::ios::end);
848  int length = LocalPhiLUT.tellg();
849  if(length == (1<<CSCBitWidths::kLocalPhiAddressWidth)*sizeof(short))
850  {
851  LocalPhiLUT.seekg(0,std::ios::beg);
852  LocalPhiLUT.read(reinterpret_cast<char*>(me_lcl_phi),length);
853  LocalPhiLUT.close();
854  }
855  else
856  edm::LogError("CSCSectorReceiverLUT") << "File "<< fName << " is incorrect size!";
857  LocalPhiLUT.close();
858  }
859  else
860  {
861  LocalPhiLUT.open(fName.c_str());
862  unsigned i = 0;
863  unsigned short temp = 0;
864  while(!LocalPhiLUT.eof() && i < 1<<CSCBitWidths::kLocalPhiAddressWidth)
865  {
866  LocalPhiLUT >> temp;
867  me_lcl_phi[i++] = (*reinterpret_cast<lclphidat*>(&temp));
868  }
869  LocalPhiLUT.close();
870  }
871  }
872  if(!me_global_phi)
873  {
875  memset(me_global_phi, 0, (1<<CSCBitWidths::kGlobalPhiAddressWidth)*sizeof(short));
877  std::ifstream GlobalPhiLUT;
878 
879  edm::LogInfo("CSCSectorReceiverLUT") << "Loading SR LUT: " << fName;
880 
881  if(isBinary)
882  {
883  GlobalPhiLUT.open(fName.c_str(),std::ios::binary);
884  GlobalPhiLUT.seekg(0,std::ios::end);
885  int length = GlobalPhiLUT.tellg();
886  if(length == (1<<CSCBitWidths::kGlobalPhiAddressWidth)*sizeof(short))
887  {
888  GlobalPhiLUT.seekg(0,std::ios::beg);
889  GlobalPhiLUT.read(reinterpret_cast<char*>(me_global_phi),length);
890  }
891  else
892  edm::LogError("CSCSectorReceiverLUT") << "File "<< fName << " is incorrect size!";
893  GlobalPhiLUT.close();
894  }
895  else
896  {
897  GlobalPhiLUT.open( fName.c_str());
898  unsigned short temp = 0;
899  unsigned i = 0;
900  while(!GlobalPhiLUT.eof() && i < 1<<CSCBitWidths::kGlobalPhiAddressWidth)
901  {
902  GlobalPhiLUT >> temp;
903  me_global_phi[i++] = (*reinterpret_cast<gblphidat*>(&temp));
904  }
905  GlobalPhiLUT.close();
906  }
907  }
908  if(!mb_global_phi && _station == 1) // MB lut only in station one.
909  {
911  memset(mb_global_phi, 0, (1<<CSCBitWidths::kGlobalPhiAddressWidth)*sizeof(short));
913  std::ifstream GlobalPhiLUT;
914 
915  edm::LogInfo("CSCSectorReceiverLUT") << "Loading SR LUT: " << fName;
916 
917  if(isBinary)
918  {
919  GlobalPhiLUT.open( fName.c_str(),std::ios::binary);
920  GlobalPhiLUT.seekg(0,std::ios::end);
921  int length = GlobalPhiLUT.tellg();
922  if(length == (1<<CSCBitWidths::kGlobalPhiAddressWidth)*sizeof(short))
923  {
924  GlobalPhiLUT.seekg(0,std::ios::beg);
925  GlobalPhiLUT.read(reinterpret_cast<char*>(mb_global_phi),length);
926  }
927  else
928  edm::LogError("CSCSectorReceiverLUT") << "File "<< fName << " is incorrect size!";
929  GlobalPhiLUT.close();
930  }
931  else
932  {
933  GlobalPhiLUT.open(fName.c_str());
934  unsigned short temp = 0;
935  unsigned i = 0;
936  while(!GlobalPhiLUT.eof() && i < 1<<CSCBitWidths::kGlobalPhiAddressWidth)
937  {
938  GlobalPhiLUT >> temp;
939  mb_global_phi[i++] = (*reinterpret_cast<gblphidat*>(&temp));
940  }
941  GlobalPhiLUT.close();
942  }
943  }
944  if(!me_global_eta)
945  {
947  memset(me_global_eta, 0, (1<<CSCBitWidths::kGlobalEtaAddressWidth)*sizeof(short));
949  std::ifstream GlobalEtaLUT;
950 
951  edm::LogInfo("CSCSectorReceiverLUT") << "Loading SR LUT: " << fName;
952 
953  if(isBinary)
954  {
955  GlobalEtaLUT.open(fName.c_str(),std::ios::binary);
956  GlobalEtaLUT.seekg(0,std::ios::end);
957  int length = GlobalEtaLUT.tellg();
958  if(length == (1<<CSCBitWidths::kGlobalEtaAddressWidth)*sizeof(short))
959  {
960  GlobalEtaLUT.seekg(0,std::ios::beg);
961  GlobalEtaLUT.read(reinterpret_cast<char*>(me_global_eta),length);
962  }
963  else
964  edm::LogError("CSCSectorReceiverLUT") << "File "<< fName << " is incorrect size!";
965  GlobalEtaLUT.close();
966  }
967  else
968  {
969  GlobalEtaLUT.open(fName.c_str());
970  unsigned short temp = 0;
971  unsigned i = 0;
972  while(!GlobalEtaLUT.eof() && i < 1<<CSCBitWidths::kGlobalEtaAddressWidth)
973  {
974  GlobalEtaLUT >> temp;
975  me_global_eta[i++] = (*reinterpret_cast<gbletadat*>(&temp));
976  }
977  GlobalEtaLUT.close();
978  }
979  }
980 }
981 
#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
char * address
Definition: mlp_lapack.h:14
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.
gbletadat globalEtaME(int phi_bend, int phi_local, int wire_group, int cscid) const
class global_phi_address gblphiadd
edm::FileInPath mb_gbl_phi_file
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
CSCSectorReceiverLUT & operator=(const CSCSectorReceiverLUT &)
int numberOfWireGroups() const
static int ringFromTriggerLabels(int station, int triggerCSCID)
static global_phi_data calcGlobalPhiMEMini(unsigned short endcap, unsigned short sector, unsigned short station, unsigned short subsector, unsigned theadd)
gblphidat globalPhiMB(int phi_local, int wire_group, int cscid) const
double getGlobalPhiValue(const CSCLayer *thelayer, const unsigned &strip, const unsigned &wire_group) const
static const double SECTOR1_CENT_RAD
double getGlobalEtaValue(const unsigned &cscid, const unsigned &wire_group, const unsigned &phi_local) const
static CSCTriggerGeomManager * get()
lclphidat localPhi(int strip, int pattern, int quality, int lr) const
Geometry Lookup Tables.
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:41
static const double maxEta
tuple lut
Definition: lumiPlot.py:244
#define end
Definition: vmac.h:38
GlobalPoint centerOfWireGroup(int wireGroup) const
Definition: CSCLayer.cc:10
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)
#define M_PI
Definition: BFit3D.cc:3
static lclphidat calcLocalPhiMini(unsigned theadd)
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
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:171
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 CSCLayerGeometry * geometry() const
Definition: CSCLayer.h:47
#define constexpr
gblphidat calcGlobalPhiMB(const gblphidat &me_gphi_data) const
gblphidat globalPhiME(int phi_local, int wire_group, int cscid) const