CMS 3D CMS Logo

GeometryTranslator.cc
Go to the documentation of this file.
3 
4 // event setup stuff / geometries
7 
11 
17 
20 
21 #include <cmath> // for pi
22 
23 using namespace L1TMuon;
24 
26  _geom_cache_id(0ULL), _magfield_cache_id(0ULL) {
27 }
28 
30 }
31 
32 double
34  switch(tp.subsystem()) {
36  return calcDTSpecificEta(tp);
37  break;
39  return calcCSCSpecificEta(tp);
40  break;
42  return calcRPCSpecificEta(tp);
43  break;
45  return calcGEMSpecificEta(tp);
46  break;
47  default:
48  return std::nan("Invalid TP type!");
49  break;
50  }
51 }
52 
53 double
55  switch(tp.subsystem()) {
57  return calcDTSpecificPhi(tp);
58  break;
60  return calcCSCSpecificPhi(tp);
61  break;
63  return calcRPCSpecificPhi(tp);
64  break;
66  return calcGEMSpecificPhi(tp);
67  break;
68  default:
69  return std::nan("Invalid TP type!");
70  break;
71  }
72 }
73 
74 double
76  switch(tp.subsystem()) {
78  return calcDTSpecificBend(tp);
79  break;
81  return calcCSCSpecificBend(tp);
82  break;
84  return calcRPCSpecificBend(tp);
85  break;
87  return calcGEMSpecificBend(tp);
88  break;
89  default:
90  return std::nan("Invalid TP type!");
91  break;
92  }
93 }
94 
97  switch(tp.subsystem()) {
99  return calcDTSpecificPoint(tp);
100  break;
102  return getCSCSpecificPoint(tp);
103  break;
105  return getRPCSpecificPoint(tp);
106  break;
108  return getGEMSpecificPoint(tp);
109  break;
110  default:
111  GlobalPoint ret(GlobalPoint::Polar(std::nan("Invalid TP type!"), std::nan("Invalid TP type!"), std::nan("Invalid TP type!")));
112  return ret;
113  break;
114  }
115 }
116 
119  unsigned long long geomid = geom.cacheIdentifier();
120  if( _geom_cache_id != geomid ) {
121  geom.get(_geome0);
122  geom.get(_geogem);
123  geom.get(_georpc);
124  geom.get(_geocsc);
125  geom.get(_geodt);
126  _geom_cache_id = geomid;
127  }
128 
129  const IdealMagneticFieldRecord& magfield = es.get<IdealMagneticFieldRecord>();
130  unsigned long long magfieldid = magfield.cacheIdentifier();
131  if( _magfield_cache_id != magfieldid ) {
132  magfield.get(_magfield);
133  _magfield_cache_id = magfieldid;
134  }
135 }
136 
139  LocalPoint lp;
140  GlobalPoint gp;
141 
142  if (!tp.getGEMData().isME0) { // use GEM geometry
143  const GEMDetId id(tp.detId<GEMDetId>());
144  const GEMEtaPartition * roll = _geogem->etaPartition(id);
145  assert(roll);
146  //const uint16_t pad = tp.getGEMData().pad;
147  // Use half-strip precision, - 0.5 at the end to get the center of the strip
148  const float pad = (0.5 * static_cast<float>(tp.getGEMData().pad_low + tp.getGEMData().pad_hi)) - 0.5;
149  lp = roll->centreOfPad(pad);
150  gp = roll->surface().toGlobal(lp);
151 
152  } else { // use ME0 geometry
153  const ME0DetId id(tp.detId<ME0DetId>());
154  const ME0EtaPartition * roll = _geome0->etaPartition(id);
155  assert(roll);
156  //const uint16_t pad = tp.getGEMData().pad;
157  // Use half-strip precision, - 0.5 at the end to get the center of the strip
158  const float pad = (0.5 * static_cast<float>(tp.getGEMData().pad_low + tp.getGEMData().pad_hi)) - 0.5;
159  //lp = roll->centreOfPad(pad); // does not work
160  const float strip = 2.0 * pad;
161  lp = roll->centreOfStrip(strip);
162  gp = roll->surface().toGlobal(lp);
163  }
164 
165  //roll.release();
166 
167  return gp;
168 }
169 
170 double
172  return getGEMSpecificPoint(tp).eta();
173 }
174 
175 double
177  return getGEMSpecificPoint(tp).phi();
178 }
179 
180 double
182  return tp.getGEMData().bend;
183 }
184 
185 
188  const RPCDetId id(tp.detId<RPCDetId>());
189  const RPCRoll * roll = _georpc->roll(id);
190  assert(roll);
191  //const int strip = static_cast<int>(tp.getRPCData().strip);
192  // Use half-strip precision, - 0.5 at the end to get the center of the strip
193  const float strip = (0.5 * static_cast<float>(tp.getRPCData().strip_low + tp.getRPCData().strip_hi)) - 0.5;
194  const LocalPoint lp = roll->centreOfStrip(strip);
195  const GlobalPoint gp = roll->surface().toGlobal(lp);
196 
197  //roll.release();
198 
199  return gp;
200 }
201 
202 double
204  return getRPCSpecificPoint(tp).eta();
205 }
206 
207 double
209  return getRPCSpecificPoint(tp).phi();
210 }
211 
212 // this function actually does nothing since RPC
213 // hits are point-like objects
214 double
216  return 0.0;
217 }
218 
219 
220 // alot of this is transcription and consolidation of the CSC
221 // global phi calculation code
222 // this works directly with the geometry
223 // rather than using the old phi luts
226  const CSCDetId id(tp.detId<CSCDetId>());
227  // we should change this to weak_ptrs at some point
228  // requires introducing std::shared_ptrs to geometry
229  std::unique_ptr<const CSCChamber> chamb(_geocsc->chamber(id));
230  std::unique_ptr<const CSCLayerGeometry> layer_geom(
231  chamb->layer(CSCConstants::KEY_ALCT_LAYER)->geometry()
232  );
233  std::unique_ptr<const CSCLayer> layer(
234  chamb->layer(CSCConstants::KEY_ALCT_LAYER)
235  );
236 
237  const uint16_t halfstrip = tp.getCSCData().strip;
238  const uint16_t pattern = tp.getCSCData().pattern;
239  const uint16_t keyWG = tp.getCSCData().keywire;
240  //const unsigned maxStrips = layer_geom->numberOfStrips();
241 
242  // so we can extend this later
243  // assume TMB2007 half-strips only as baseline
244  double offset = 0.0;
245  switch(1) {
246  case 1:
247  offset = CSCPatternLUT::get2007Position(pattern);
248  }
249  const unsigned halfstrip_offs = unsigned(0.5 + halfstrip + offset);
250  const unsigned strip = halfstrip_offs/2 + 1; // geom starts from 1
251 
252  // the rough location of the hit at the ALCT key layer
253  // we will refine this using the half strip information
254  const LocalPoint coarse_lp =
255  layer_geom->stripWireGroupIntersection(strip,keyWG);
256  const GlobalPoint coarse_gp = layer->surface().toGlobal(coarse_lp);
257 
258  // the strip width/4.0 gives the offset of the half-strip
259  // center with respect to the strip center
260  const double hs_offset = layer_geom->stripPhiPitch()/4.0;
261 
262  // determine handedness of the chamber
263  const bool ccw = isCSCCounterClockwise(layer);
264  // we need to subtract the offset of even half strips and add the odd ones
265  const double phi_offset = ( ( halfstrip_offs%2 ? 1 : -1)*
266  ( ccw ? -hs_offset : hs_offset ) );
267 
268  // the global eta calculation uses the middle of the strip
269  // so no need to increment it
270  const GlobalPoint final_gp( GlobalPoint::Polar( coarse_gp.theta(),
271  (coarse_gp.phi().value() +
272  phi_offset),
273  coarse_gp.mag() ) );
274 
275  // We need to add in some notion of the 'error' on trigger primitives
276  // like the width of the wire group by the width of the strip
277  // or something similar
278 
279  // release ownership of the pointers
280  chamb.release();
281  layer_geom.release();
282  layer.release();
283 
284  return final_gp;
285 }
286 
287 double
289  return getCSCSpecificPoint(tp).eta();
290 }
291 
292 double
294  return getCSCSpecificPoint(tp).phi();
295 }
296 
297 double
299  return tp.getCSCData().bend;
300 }
301 
304  const DTChamberId baseid(tp.detId<DTChamberId>());
305  // do not use this pointer for anything other than creating a trig geom
306  std::unique_ptr<DTChamber> chamb(
307  const_cast<DTChamber*>(_geodt->chamber(baseid))
308  );
309  std::unique_ptr<DTTrigGeom> trig_geom( new DTTrigGeom(chamb.get(),false) );
310  chamb.release(); // release it here so no one gets funny ideas
311  // super layer one is the theta superlayer in a DT chamber
312  // station 4 does not have a theta super layer
313  // the BTI index from the theta trigger is an OR of some BTI outputs
314  // so, we choose the BTI that's in the middle of the group
315  // as the BTI that we get theta from
316  // TODO:::::>>> need to make sure this ordering doesn't flip under wheel sign
317  const int NBTI_theta = ( (baseid.station() != 4) ?
318  trig_geom->nCell(2) : trig_geom->nCell(3) );
319  const int bti_group = tp.getDTData().theta_bti_group;
320  const unsigned bti_actual = bti_group*NBTI_theta/7 + NBTI_theta/14 + 1;
321  DTBtiId thetaBTI;
322  if ( baseid.station() != 4 && bti_group != -1) {
323  thetaBTI = DTBtiId(baseid,2,bti_actual);
324  } else {
325  // since this is phi oriented it'll give us theta in the middle
326  // of the chamber
327  thetaBTI = DTBtiId(baseid,3,1);
328  }
329  const GlobalPoint theta_gp = trig_geom->CMSPosition(thetaBTI);
330 
331  // local phi in sector -> global phi
332  double phi = ((double)tp.getDTData().radialAngle)/4096.0;
333  phi += tp.getDTData().sector*M_PI/6.0; // add sector offset
334 
335  return GlobalPoint( GlobalPoint::Polar( theta_gp.theta(),
336  phi,
337  theta_gp.mag() ) );
338 }
339 
340 double
342  return calcDTSpecificPoint(tp).eta();
343 }
344 
345 double
347  return calcDTSpecificPoint(tp).phi();
348 }
349 
350 // we have the bend except for station 3
351 double
353  int bend = tp.getDTData().bendingAngle;
354  double bendf = bend/512.0;
355  return bendf;
356 }
357 
359 isCSCCounterClockwise(const std::unique_ptr<const CSCLayer>& layer) const {
360  const int nStrips = layer->geometry()->numberOfStrips();
361  const double phi1 = layer->centerOfStrip(1).phi();
362  const double phiN = layer->centerOfStrip(nStrips).phi();
363  return ( (std::abs(phi1 - phiN) < M_PI && phi1 >= phiN) ||
364  (std::abs(phi1 - phiN) >= M_PI && phi1 < phiN) );
365 }
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:106
unsigned long long cacheIdentifier() const
edm::ESHandle< DTGeometry > _geodt
LocalPoint centreOfStrip(int strip) const
Definition: RPCRoll.cc:52
const subsystem_type subsystem() const
const DTData getDTData() const
const DTChamber * chamber(const DTChamberId &id) const
Return a DTChamber given its id.
Definition: DTGeometry.cc:117
const GEMData getGEMData() const
unsigned long long _geom_cache_id
double calcRPCSpecificBend(const TriggerPrimitive &) const
double calcDTSpecificEta(const TriggerPrimitive &) const
double calcGEMSpecificEta(const TriggerPrimitive &) const
edm::ESHandle< RPCGeometry > _georpc
edm::ESHandle< GEMGeometry > _geogem
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
edm::ESHandle< ME0Geometry > _geome0
GlobalPoint getRPCSpecificPoint(const TriggerPrimitive &) const
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
LocalPoint centreOfStrip(int strip) const
GlobalPoint getCSCSpecificPoint(const TriggerPrimitive &) const
const CSCData getCSCData() const
const ME0EtaPartition * etaPartition(ME0DetId id) const
Return a etaPartition given its id.
Definition: ME0Geometry.cc:64
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
const GEMEtaPartition * etaPartition(GEMDetId id) const
Return a GEMEtaPartition given its id.
Definition: GEMGeometry.cc:99
const RPCData getRPCData() const
double calcGEMSpecificPhi(const TriggerPrimitive &) const
double calcRPCSpecificPhi(const TriggerPrimitive &) const
edm::ESHandle< MagneticField > _magfield
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
T mag() const
Definition: PV3DBase.h:67
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
double calculateBendAngle(const TriggerPrimitive &) const
void checkAndUpdateGeometry(const edm::EventSetup &)
edm::ESHandle< CSCGeometry > _geocsc
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double calcCSCSpecificPhi(const TriggerPrimitive &) const
#define M_PI
double calculateGlobalPhi(const TriggerPrimitive &) const
static double get2007Position(int pattern)
double calcDTSpecificBend(const TriggerPrimitive &) const
const CSCChamber * chamber(CSCDetId id) const
Return the chamber corresponding to given DetId.
Definition: CSCGeometry.cc:133
double calcCSCSpecificEta(const TriggerPrimitive &) const
GlobalPoint calcDTSpecificPoint(const TriggerPrimitive &) const
T eta() const
Definition: PV3DBase.h:76
LocalPoint centreOfPad(int pad) const
T get() const
Definition: EventSetup.h:71
double calcDTSpecificPhi(const TriggerPrimitive &) const
GlobalPoint getGEMSpecificPoint(const TriggerPrimitive &) const
int station() const
Return the station number.
Definition: DTChamberId.h:51
unsigned long long _magfield_cache_id
double calculateGlobalEta(const TriggerPrimitive &) const
double calcGEMSpecificBend(const TriggerPrimitive &) const
bool isCSCCounterClockwise(const std::unique_ptr< const CSCLayer > &) const
const RPCRoll * roll(RPCDetId id) const
Return a roll given its id.
Definition: RPCGeometry.cc:75
double calcRPCSpecificEta(const TriggerPrimitive &) const
GlobalPoint getGlobalPoint(const TriggerPrimitive &) const
double calcCSCSpecificBend(const TriggerPrimitive &) const