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 
25 GeometryTranslator::GeometryTranslator() : _geom_cache_id(0ULL), _magfield_cache_id(0ULL) {}
26 
28 
30  switch (tp.subsystem()) {
32  return calcDTSpecificEta(tp);
33  break;
35  return calcCSCSpecificEta(tp);
36  break;
38  return calcRPCSpecificEta(tp);
39  break;
41  return calcGEMSpecificEta(tp);
42  break;
43  default:
44  return std::nan("Invalid TP type!");
45  break;
46  }
47 }
48 
50  switch (tp.subsystem()) {
52  return calcDTSpecificPhi(tp);
53  break;
55  return calcCSCSpecificPhi(tp);
56  break;
58  return calcRPCSpecificPhi(tp);
59  break;
61  return calcGEMSpecificPhi(tp);
62  break;
63  default:
64  return std::nan("Invalid TP type!");
65  break;
66  }
67 }
68 
70  switch (tp.subsystem()) {
72  return calcDTSpecificBend(tp);
73  break;
75  return calcCSCSpecificBend(tp);
76  break;
78  return calcRPCSpecificBend(tp);
79  break;
81  return calcGEMSpecificBend(tp);
82  break;
83  default:
84  return std::nan("Invalid TP type!");
85  break;
86  }
87 }
88 
90  switch (tp.subsystem()) {
92  return calcDTSpecificPoint(tp);
93  break;
95  return getCSCSpecificPoint(tp);
96  break;
98  return getRPCSpecificPoint(tp);
99  break;
101  return getGEMSpecificPoint(tp);
102  break;
103  default:
105  GlobalPoint::Polar(std::nan("Invalid TP type!"), std::nan("Invalid TP type!"), std::nan("Invalid TP type!")));
106  return ret;
107  break;
108  }
109 }
110 
113  unsigned long long geomid = geom.cacheIdentifier();
114  if (_geom_cache_id != geomid) {
115  geom.get(_geome0);
116  geom.get(_geogem);
117  geom.get(_georpc);
118  geom.get(_geocsc);
119  geom.get(_geodt);
120  _geom_cache_id = geomid;
121  }
122 
124  unsigned long long magfieldid = magfield.cacheIdentifier();
125  if (_magfield_cache_id != magfieldid) {
126  magfield.get(_magfield);
127  _magfield_cache_id = magfieldid;
128  }
129 }
130 
132  LocalPoint lp;
133  GlobalPoint gp;
134 
135  if (!tp.getGEMData().isME0) { // use GEM geometry
136  const GEMDetId id(tp.detId<GEMDetId>());
137  const GEMEtaPartition* roll = _geogem->etaPartition(id);
138  assert(roll);
139  //const uint16_t pad = tp.getGEMData().pad;
140  // Use half-strip precision, - 0.5 at the end to get the center of the strip
141  const float pad = (0.5 * static_cast<float>(tp.getGEMData().pad_low + tp.getGEMData().pad_hi)) - 0.5;
142  lp = roll->centreOfPad(pad);
143  gp = roll->surface().toGlobal(lp);
144 
145  } else { // use ME0 geometry
146  const ME0DetId id(tp.detId<ME0DetId>());
147  const ME0EtaPartition* roll = _geome0->etaPartition(id);
148  assert(roll);
149  //const uint16_t pad = tp.getGEMData().pad;
150  // Use half-strip precision, - 0.5 at the end to get the center of the strip
151  const float pad = (0.5 * static_cast<float>(tp.getGEMData().pad_low + tp.getGEMData().pad_hi)) - 0.5;
152  //lp = roll->centreOfPad(pad); // does not work
153  const float strip = 2.0 * pad;
154  lp = roll->centreOfStrip(strip);
155  gp = roll->surface().toGlobal(lp);
156  }
157 
158  //roll.release();
159 
160  return gp;
161 }
162 
164  return getGEMSpecificPoint(tp).eta();
165 }
166 
168  return getGEMSpecificPoint(tp).phi();
169 }
170 
172 
174  const RPCDetId id(tp.detId<RPCDetId>());
175  const RPCRoll* roll = _georpc->roll(id);
176  assert(roll);
177  //const int strip = static_cast<int>(tp.getRPCData().strip);
178  // Use half-strip precision, - 0.5 at the end to get the center of the strip
179  const float strip = (0.5 * static_cast<float>(tp.getRPCData().strip_low + tp.getRPCData().strip_hi)) - 0.5;
180  const LocalPoint lp = roll->centreOfStrip(strip);
181  const GlobalPoint gp = roll->surface().toGlobal(lp);
182 
183  //roll.release();
184 
185  return gp;
186 }
187 
189  return getRPCSpecificPoint(tp).eta();
190 }
191 
193  return getRPCSpecificPoint(tp).phi();
194 }
195 
196 // this function actually does nothing since RPC
197 // hits are point-like objects
198 double GeometryTranslator::calcRPCSpecificBend(const TriggerPrimitive& tp) const { return 0.0; }
199 
200 // alot of this is transcription and consolidation of the CSC
201 // global phi calculation code
202 // this works directly with the geometry
203 // rather than using the old phi luts
205  const CSCDetId id(tp.detId<CSCDetId>());
206  // we should change this to weak_ptrs at some point
207  // requires introducing std::shared_ptrs to geometry
208  std::unique_ptr<const CSCChamber> chamb(_geocsc->chamber(id));
209  std::unique_ptr<const CSCLayerGeometry> layer_geom(chamb->layer(CSCConstants::KEY_ALCT_LAYER)->geometry());
210  std::unique_ptr<const CSCLayer> layer(chamb->layer(CSCConstants::KEY_ALCT_LAYER));
211 
212  const uint16_t halfstrip = tp.getCSCData().strip;
213  const uint16_t pattern = tp.getCSCData().pattern;
214  const uint16_t keyWG = tp.getCSCData().keywire;
215  //const unsigned maxStrips = layer_geom->numberOfStrips();
216 
217  // so we can extend this later
218  // assume TMB2007 half-strips only as baseline
219  double offset = 0.0;
220  switch (1) {
221  case 1:
222  offset = CSCPatternLUT::get2007Position(pattern);
223  }
224  const unsigned halfstrip_offs = unsigned(0.5 + halfstrip + offset);
225  const unsigned strip = halfstrip_offs / 2 + 1; // geom starts from 1
226 
227  // the rough location of the hit at the ALCT key layer
228  // we will refine this using the half strip information
229  const LocalPoint coarse_lp = layer_geom->stripWireGroupIntersection(strip, keyWG);
230  const GlobalPoint coarse_gp = layer->surface().toGlobal(coarse_lp);
231 
232  // the strip width/4.0 gives the offset of the half-strip
233  // center with respect to the strip center
234  const double hs_offset = layer_geom->stripPhiPitch() / 4.0;
235 
236  // determine handedness of the chamber
237  const bool ccw = isCSCCounterClockwise(layer);
238  // we need to subtract the offset of even half strips and add the odd ones
239  const double phi_offset = ((halfstrip_offs % 2 ? 1 : -1) * (ccw ? -hs_offset : hs_offset));
240 
241  // the global eta calculation uses the middle of the strip
242  // so no need to increment it
243  const GlobalPoint final_gp(
244  GlobalPoint::Polar(coarse_gp.theta(), (coarse_gp.phi().value() + phi_offset), coarse_gp.mag()));
245 
246  // We need to add in some notion of the 'error' on trigger primitives
247  // like the width of the wire group by the width of the strip
248  // or something similar
249 
250  // release ownership of the pointers
251  chamb.release();
252  layer_geom.release();
253  layer.release();
254 
255  return final_gp;
256 }
257 
259  return getCSCSpecificPoint(tp).eta();
260 }
261 
263  return getCSCSpecificPoint(tp).phi();
264 }
265 
267 
269  const DTChamberId baseid(tp.detId<DTChamberId>());
270  // do not use this pointer for anything other than creating a trig geom
271  std::unique_ptr<DTChamber> chamb(const_cast<DTChamber*>(_geodt->chamber(baseid)));
272  std::unique_ptr<DTTrigGeom> trig_geom(new DTTrigGeom(chamb.get(), false));
273  chamb.release(); // release it here so no one gets funny ideas
274  // super layer one is the theta superlayer in a DT chamber
275  // station 4 does not have a theta super layer
276  // the BTI index from the theta trigger is an OR of some BTI outputs
277  // so, we choose the BTI that's in the middle of the group
278  // as the BTI that we get theta from
279  // TODO:::::>>> need to make sure this ordering doesn't flip under wheel sign
280  const int NBTI_theta = ((baseid.station() != 4) ? trig_geom->nCell(2) : trig_geom->nCell(3));
281  const int bti_group = tp.getDTData().theta_bti_group;
282  const unsigned bti_actual = bti_group * NBTI_theta / 7 + NBTI_theta / 14 + 1;
283  DTBtiId thetaBTI;
284  if (baseid.station() != 4 && bti_group != -1) {
285  thetaBTI = DTBtiId(baseid, 2, bti_actual);
286  } else {
287  // since this is phi oriented it'll give us theta in the middle
288  // of the chamber
289  thetaBTI = DTBtiId(baseid, 3, 1);
290  }
291  const GlobalPoint theta_gp = trig_geom->CMSPosition(thetaBTI);
292 
293  // local phi in sector -> global phi
294  double phi = ((double)tp.getDTData().radialAngle) / 4096.0;
295  phi += tp.getDTData().sector * M_PI / 6.0; // add sector offset
296 
297  return GlobalPoint(GlobalPoint::Polar(theta_gp.theta(), phi, theta_gp.mag()));
298 }
299 
301 
303 
304 // we have the bend except for station 3
306  int bend = tp.getDTData().bendingAngle;
307  double bendf = bend / 512.0;
308  return bendf;
309 }
310 
311 bool GeometryTranslator::isCSCCounterClockwise(const std::unique_ptr<const CSCLayer>& layer) const {
312  const int nStrips = layer->geometry()->numberOfStrips();
313  const double phi1 = layer->centerOfStrip(1).phi();
314  const double phiN = layer->centerOfStrip(nStrips).phi();
315  return ((std::abs(phi1 - phiN) < M_PI && phi1 >= phiN) || (std::abs(phi1 - phiN) >= M_PI && phi1 < phiN));
316 }
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:81
unsigned long long cacheIdentifier() const
edm::ESHandle< DTGeometry > _geodt
LocalPoint centreOfStrip(int strip) const
Definition: RPCRoll.cc:26
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:90
const GEMData getGEMData() const
unsigned long long _geom_cache_id
ret
prodAgent to be discontinued
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:66
edm::ESHandle< ME0Geometry > _geome0
GlobalPoint getRPCSpecificPoint(const TriggerPrimitive &) const
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T1 value() const
Explicit access to value in case implicit conversion not OK.
Definition: Phi.h:75
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:35
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
const GEMEtaPartition * etaPartition(GEMDetId id) const
Return a GEMEtaPartition given its id.
Definition: GEMGeometry.cc:77
const RPCData getRPCData() const
nStrips
1.2 is to make the matching window safely the two nearest strips 0.35 is the size of an ME0 chamber i...
double calcGEMSpecificPhi(const TriggerPrimitive &) const
double calcRPCSpecificPhi(const TriggerPrimitive &) const
edm::ESHandle< MagneticField > _magfield
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72
T mag() const
Definition: PV3DBase.h:64
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:100
double calcCSCSpecificEta(const TriggerPrimitive &) const
GlobalPoint calcDTSpecificPoint(const TriggerPrimitive &) const
T eta() const
Definition: PV3DBase.h:73
LocalPoint centreOfPad(int pad) const
T get() const
Definition: EventSetup.h:73
double calcDTSpecificPhi(const TriggerPrimitive &) const
GlobalPoint getGEMSpecificPoint(const TriggerPrimitive &) const
int station() const
Return the station number.
Definition: DTChamberId.h:42
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:50
double calcRPCSpecificEta(const TriggerPrimitive &) const
GlobalPoint getGlobalPoint(const TriggerPrimitive &) const
double calcCSCSpecificBend(const TriggerPrimitive &) const