CMS 3D CMS Logo

MuonDetLayerGeometry.cc
Go to the documentation of this file.
1 
11 
19 
22 
23 #include <algorithm>
24 
25 using namespace std;
26 using namespace geomsort;
27 
29 
31  for(vector<const DetLayer*>::const_iterator it = allDetLayers.begin(); it != allDetLayers.end(); ++it)
32  {
33  delete *it;
34  }
35 }
36 
37 void MuonDetLayerGeometry::addCSCLayers(const pair<vector<DetLayer*>, vector<DetLayer*> >& csclayers) {
38 
39  for(auto const it : csclayers.first) {
40  cscLayers_fw.push_back(it);
41  allForward.push_back(it);
42 
43  detLayersMap[ makeDetLayerId(it) ] = it;
44  }
45 
46  for(auto const it: csclayers.second) {
47  cscLayers_bk.push_back(it);
48  allBackward.push_back(it);
49 
50  detLayersMap[ makeDetLayerId(it) ] = it;
51  }
52 }
53 
54 void MuonDetLayerGeometry::addGEMLayers(const pair<vector<DetLayer*>, vector<DetLayer*> >& gemlayers) {
55  LogDebug("Muon|RecoMuon|MuonDetLayerGeometry") << "Adding GEMlayers "<<std::endl;
56  for(auto const it : gemlayers.first) {
57  gemLayers_fw.push_back(it);
58  allForward.push_back(it);
59  detLayersMap[ makeDetLayerId(it) ] = it;
60  LogDebug("Muon|RecoMuon|MuonDetLayerGeometry") << "Adding GEMforward "<<std::endl;
61  }
62  for(auto const it: gemlayers.second) {
63  gemLayers_bk.push_back(it);
64  allBackward.push_back(it);
65  detLayersMap[ makeDetLayerId(it) ] = it;
66  LogDebug("Muon|RecoMuon|MuonDetLayerGeometry") << "Adding GEMbackward "<<std::endl;
67  }
68 }
69 
70 
71 void MuonDetLayerGeometry::addME0Layers(const pair<vector<DetLayer*>, vector<DetLayer*> >& me0layers) {
72 
73  LogDebug("Muon|RecoMuon|MuonDetLayerGeometry") << "Adding ME0layers "<<std::endl;
74 
75  for(auto const it : me0layers.first) {
76  me0Layers_fw.push_back(it);
77  allForward.push_back(it);
78 
79  detLayersMap[ makeDetLayerId(it) ] = it;
80  LogDebug("Muon|RecoMuon|MuonDetLayerGeometry") << "Adding ME0forward "<<std::endl;
81  }
82  for(auto const it : me0layers.second) {
83  me0Layers_bk.push_back(it);
84  allBackward.push_back(it);
85 
86  detLayersMap[ makeDetLayerId(it) ] = it;
87  LogDebug("Muon|RecoMuon|MuonDetLayerGeometry") << "Adding ME0backward "<<std::endl;
88  }
89 }
90 
91 void MuonDetLayerGeometry::addRPCLayers(const vector<DetLayer*>& barrelLayers, const pair<vector<DetLayer*>, vector<DetLayer*> >& endcapLayers) {
92 
93  for(auto const it: barrelLayers) {
94  rpcLayers_barrel.push_back(it);
95  allBarrel.push_back(it);
96 
97  detLayersMap[ makeDetLayerId(it) ] = it;
98  }
99  for(auto const it: endcapLayers.first) {
100  rpcLayers_fw.push_back(it);
101  allForward.push_back(it);
102 
103  detLayersMap[ makeDetLayerId(it) ] = it;
104  }
105 
106  for(auto const it: endcapLayers.second) {
107  rpcLayers_bk.push_back(it);
108  allBackward.push_back(it);
109 
110  detLayersMap[ makeDetLayerId(it) ] = it;
111  }
112 
113 }
114 
115 void MuonDetLayerGeometry::addDTLayers(const vector<DetLayer*>& dtlayers) {
116 
117  for(auto const it : dtlayers) {
118  dtLayers.push_back(it);
119  allBarrel.push_back(it);
120 
121  detLayersMap[ makeDetLayerId(it) ] = it;
122  }
123 }
124 
126 
127  if(detLayer->subDetector() == GeomDetEnumerators::CSC){
128  CSCDetId id( detLayer->basicComponents().front()->geographicalId().rawId() ) ;
129 
130  if(id.station() == 1 )
131  {
132  if(id.ring() == 1 || id.ring() == 4)
133  return CSCDetId(id.endcap(),1,1,0,0);
134  else if(id.ring() == 2 || id.ring() == 3)
135  return CSCDetId(id.endcap(),1,2,0,0);
136  else
137  throw cms::Exception("InvalidCSCRing")<<" Invalid CSC Ring: "<<id.ring()<<endl;
138  }
139  else
140  return CSCDetId(id.endcap(),id.station(),0,0,0);
141 
142  }
143  else if(detLayer->subDetector() == GeomDetEnumerators::DT){
144  DTChamberId id( detLayer->basicComponents().front()->geographicalId().rawId() ) ;
145  return DTChamberId(0,id.station(),0);
146  }
147  else if(detLayer->subDetector()== GeomDetEnumerators::RPCBarrel ||
149  RPCDetId id( detLayer->basicComponents().front()->geographicalId().rawId());
150  return RPCDetId(id.region(),0,id.station(),0,id.layer(),0,0);
151  }
152  else if( detLayer->subDetector()== GeomDetEnumerators::GEM){
153  GEMDetId id( detLayer->basicComponents().front()->geographicalId().rawId());
154  return GEMDetId(id.region(),1,id.station(),id.layer(),0,0);
155  }
156  else if( detLayer->subDetector()== GeomDetEnumerators::ME0){
157  ME0DetId id( detLayer->basicComponents().front()->geographicalId().rawId());
158  return ME0DetId(id.region(),id.layer(),0,0);
159  }
160  else throw cms::Exception("InvalidModuleIdentification"); // << detLayer->module();
161 }
162 
163 
164 const vector<const DetLayer*>&
166  return dtLayers;
167 }
168 
169 const vector<const DetLayer*>&
171  return cscLayers_all;
172 }
173 
174 
175 const vector<const DetLayer*>&
177  return cscLayers_fw;
178 }
179 
180 
181 const vector<const DetLayer*>&
183  return cscLayers_bk;
184 }
185 
187 const vector<const DetLayer*>&
189  return gemLayers_all;
190 }
191 
192 
193 const vector<const DetLayer*>&
195  return gemLayers_fw;
196 }
197 
198 
199 const vector<const DetLayer*>&
201  return gemLayers_bk;
202 }
203 
205 
206 
208 
209 const vector<const DetLayer*>&
211  return me0Layers_all;
212 }
213 
214 
215 const vector<const DetLayer*>&
217  return me0Layers_fw;
218 }
219 
220 
221 const vector<const DetLayer*>&
223  return me0Layers_bk;
224 }
225 
227 
228 const vector<const DetLayer*>&
230  return rpcLayers_all;
231 }
232 
233 
234 const vector<const DetLayer*>&
236  return rpcLayers_barrel;
237 }
238 
239 
240 const vector<const DetLayer*>&
242  return rpcLayers_endcap;
243 }
244 
245 
246 const vector<const DetLayer*>&
248  return rpcLayers_fw;
249 }
250 
251 
252 const vector<const DetLayer*>&
254  return rpcLayers_bk;
255 }
256 
257 
258 const vector<const DetLayer*>&
260  return allDetLayers;
261 }
262 
263 
264 const vector<const DetLayer*>&
266  return allBarrel;
267 }
268 
269 const vector<const DetLayer*>&
271  return allEndcap;
272 }
273 
274 
275 const vector<const DetLayer*>&
277  return allForward;
278 }
279 
280 
281 const vector<const DetLayer*>&
283  return allBackward;
284 }
285 
287 //
288 const vector<const DetLayer*>&
290  return allEndcapCscGem;
291 }
292 
293 
294 const vector<const DetLayer*>&
296  return allCscGemForward;
297 }
298 
299 
300 const vector<const DetLayer*>&
302  return allCscGemBackward;
303 }
304 
306 
307 const vector<const DetLayer*>&
309  return allEndcapCscME0;
310 }
311 
312 
313 const vector<const DetLayer*>&
315  return allCscME0Forward;
316 }
317 
318 
319 const vector<const DetLayer*>&
321  return allCscME0Backward;
322 }
323 
324 
326 
327 const DetLayer* MuonDetLayerGeometry::idToLayer(const DetId &detId) const{
328 
329  DetId id;
330 
331  if(detId.subdetId() == MuonSubdetId::CSC){
332  CSCDetId cscId( detId.rawId() );
333 
334  if(cscId.station() == 1)
335  {
336  if(cscId.ring() == 1 || cscId.ring() == 4)
337  id = CSCDetId(cscId.endcap(),1,1,0,0);
338  else if(cscId.ring() == 2 || cscId.ring() == 3)
339  id = CSCDetId(cscId.endcap(),1,2,0,0);
340  else
341  throw cms::Exception("InvalidCSCRing")<<" Invalid CSC Ring: "<<cscId.ring()<<endl;
342  }
343  else id = CSCDetId(cscId.endcap(),cscId.station(),0,0,0);
344  }
345 
346  else if (detId.subdetId() == MuonSubdetId::DT){
347  DTChamberId dtId( detId.rawId() );
348  id = DTChamberId(0,dtId.station(),0);
349  }
350  else if (detId.subdetId() == MuonSubdetId::RPC){
351  RPCDetId rpcId(detId.rawId() );
352  id = RPCDetId(rpcId.region(),0,rpcId.station(),0,rpcId.layer(),0,0);
353  }
354  else if (detId.subdetId() == MuonSubdetId::GEM){
355  GEMDetId gemId(detId.rawId() );
356  id = GEMDetId(gemId.region(),1,gemId.station(),gemId.layer(),0,0);
357  }
358  else if (detId.subdetId() == MuonSubdetId::ME0){
359  ME0DetId me0Id(detId.rawId() );
360  id = ME0DetId(me0Id.region(),me0Id.layer(),0,0);
361  LogDebug("Muon|RecoMuon|MuonDetLayerGeometry") << " Found an ME0DetId: " << me0Id.rawId()
362  <<",id: "<< id.rawId()<<std::endl;
363 
364  }
365  else throw cms::Exception("InvalidSubdetId")<< detId.subdetId();
366 
367  std::map<DetId,const DetLayer*>::const_iterator layer = detLayersMap.find(id);
368  if (layer == detLayersMap.end()) return 0;
369  return layer->second;
370 }
371 
372 
373 // Quick way to sort barrel det layers by increasing R,
374 // do not abuse!
378  result_type operator()(const DetLayer* p) const {
379  const BarrelDetLayer * bdl = dynamic_cast<const BarrelDetLayer*>(p);
380  if (bdl) return bdl->specificSurface().radius();
381  else return -1.;
382  }
383 };
384 
386 
387  // The following are filled inside-out, no need to re-sort
388  // precomputed_value_sort(dtLayers.begin(), dtLayers.end(),ExtractR<DetLayer,float>());
389  // precomputed_value_sort(cscLayers_fw.begin(), cscLayers_fw.end(),ExtractAbsZ<DetLayer,float>());
390  // precomputed_value_sort(cscLayers_bk.begin(), cscLayers_bk.end(),ExtractAbsZ<DetLayer,float>());
391  // precomputed_value_sort(rpcLayers_fw.begin(), rpcLayers_fw.end(),ExtractAbsZ<DetLayer,float>());
392  // precomputed_value_sort(rpcLayers_bk.begin(), rpcLayers_bk.end(),ExtractAbsZ<DetLayer,float>());
393  // precomputed_value_sort(rpcLayers_barrel.begin(), rpcLayers_barrel.end(), ExtractR<DetLayer,float>());
394 
395  // Sort these inside-out
396  precomputed_value_sort(allBarrel.begin(), allBarrel.end(), ExtractBarrelDetLayerR());
397  precomputed_value_sort(allBackward.begin(), allBackward.end(), ExtractAbsZ<DetLayer,float>());
398  precomputed_value_sort(allForward.begin(), allForward.end(), ExtractAbsZ<DetLayer,float>());
399 
400  // Build more complicated vectors with correct sorting
401 
402  //cscLayers_all: from -Z to +Z
403  cscLayers_all.reserve(cscLayers_bk.size()+cscLayers_fw.size());
404  std::copy(cscLayers_bk.begin(),cscLayers_bk.end(),back_inserter(cscLayers_all));
405  std::reverse(cscLayers_all.begin(),cscLayers_all.end());
406  std::copy(cscLayers_fw.begin(),cscLayers_fw.end(),back_inserter(cscLayers_all));
407 
408  //gemLayers_all: from -Z to +Z
409  gemLayers_all.reserve(gemLayers_bk.size()+gemLayers_fw.size());
410  std::copy(gemLayers_bk.begin(),gemLayers_bk.end(),back_inserter(gemLayers_all));
411  std::reverse(gemLayers_all.begin(),gemLayers_all.end());
412  std::copy(gemLayers_fw.begin(),gemLayers_fw.end(),back_inserter(gemLayers_all));
413 
414  //me0Layers_all: from -Z to +Z
415  me0Layers_all.reserve(me0Layers_bk.size()+me0Layers_fw.size());
416  std::copy(me0Layers_bk.begin(),me0Layers_bk.end(),back_inserter(me0Layers_all));
417  std::reverse(me0Layers_all.begin(),me0Layers_all.end());
418  std::copy(me0Layers_fw.begin(),me0Layers_fw.end(),back_inserter(me0Layers_all));
419 
420  //rpcLayers_endcap: from -Z to +Z
421  rpcLayers_endcap.reserve(rpcLayers_bk.size()+rpcLayers_fw.size());
422  std::copy(rpcLayers_bk.begin(),rpcLayers_bk.end(),back_inserter(rpcLayers_endcap));
423  std::reverse(rpcLayers_endcap.begin(),rpcLayers_endcap.end());
424  std::copy(rpcLayers_fw.begin(),rpcLayers_fw.end(),back_inserter(rpcLayers_endcap));
425 
426  //rpcLayers_all: order is bw, barrel, fw
427  rpcLayers_all.reserve(rpcLayers_bk.size()+rpcLayers_barrel.size()+rpcLayers_fw.size());
428  std::copy(rpcLayers_bk.begin(),rpcLayers_bk.end(),back_inserter(rpcLayers_all));
429  std::reverse(rpcLayers_all.begin(),rpcLayers_all.end());
430  std::copy(rpcLayers_barrel.begin(),rpcLayers_barrel.end(),back_inserter(rpcLayers_all));
431  std::copy(rpcLayers_fw.begin(),rpcLayers_fw.end(),back_inserter(rpcLayers_all));
432 
433  // allEndcap: order is all bw, all fw
434  allEndcap.reserve(allBackward.size()+allForward.size());
435  std::copy(allBackward.begin(),allBackward.end(),back_inserter(allEndcap));
436  std::reverse(allEndcap.begin(),allEndcap.end());
437  std::copy(allForward.begin(),allForward.end(),back_inserter(allEndcap));
438 
439  // allEndcapCSCGEM: order is all bw, all fw
440  allEndcapCscGem.reserve(cscLayers_bk.size()+cscLayers_fw.size()+gemLayers_bk.size()+gemLayers_fw.size());
441  std::copy(cscLayers_bk.begin(),cscLayers_bk.end(),back_inserter(allEndcapCscGem));
442  std::copy(gemLayers_bk.begin(),gemLayers_bk.end(),back_inserter(allEndcapCscGem));
443  std::reverse(allEndcapCscGem.begin(),allEndcapCscGem.end());
444  std::copy(cscLayers_fw.begin(),cscLayers_fw.end(),back_inserter(allEndcapCscGem));
445  std::copy(gemLayers_fw.begin(),gemLayers_fw.end(),back_inserter(allEndcapCscGem));
446 
447  // allCscGemForward
448  allCscGemForward.reserve(cscLayers_fw.size()+gemLayers_fw.size());
449  std::copy(cscLayers_fw.begin(),cscLayers_fw.end(),back_inserter(allCscGemForward));
450  std::copy(gemLayers_fw.begin(),gemLayers_fw.end(),back_inserter(allCscGemForward));
451 
452  // allCscGemBackward
453  allCscGemBackward.reserve(cscLayers_bk.size()+gemLayers_bk.size());
454  std::copy(cscLayers_bk.begin(),cscLayers_bk.end(),back_inserter(allCscGemBackward));
455  std::copy(gemLayers_bk.begin(),gemLayers_bk.end(),back_inserter(allCscGemBackward));
456 
457  // allCscME0Forward
458  allCscME0Forward.reserve(cscLayers_fw.size()+me0Layers_fw.size());
459  std::copy(cscLayers_fw.begin(),cscLayers_fw.end(),back_inserter(allCscME0Forward));
460  std::copy(me0Layers_fw.begin(),me0Layers_fw.end(),back_inserter(allCscME0Forward));
461 
462  // allCscME0Backward
463  allCscME0Backward.reserve(cscLayers_bk.size()+me0Layers_bk.size());
464  std::copy(cscLayers_bk.begin(),cscLayers_bk.end(),back_inserter(allCscME0Backward));
465  std::copy(me0Layers_bk.begin(),me0Layers_bk.end(),back_inserter(allCscME0Backward));
466 
467  // allEndcapCSCME0: order is all bw, all fw
468  allEndcapCscME0.reserve(cscLayers_bk.size()+cscLayers_fw.size()+me0Layers_bk.size()+me0Layers_fw.size());
469  std::copy(cscLayers_bk.begin(),cscLayers_bk.end(),back_inserter(allEndcapCscME0));
470  std::copy(me0Layers_bk.begin(),me0Layers_bk.end(),back_inserter(allEndcapCscME0));
471  std::reverse(allEndcapCscME0.begin(),allEndcapCscME0.end());
472  std::copy(cscLayers_fw.begin(),cscLayers_fw.end(),back_inserter(allEndcapCscME0));
473  std::copy(me0Layers_fw.begin(),me0Layers_fw.end(),back_inserter(allEndcapCscME0));
474 
475  // allDetLayers: order is all bw, all barrel, all fw
476  allDetLayers.reserve(allBackward.size()+allBarrel.size()+allForward.size());
477  std::copy(allBackward.begin(),allBackward.end(),back_inserter(allDetLayers));
478  std::reverse(allDetLayers.begin(),allDetLayers.end());
479  std::copy(allBarrel.begin(),allBarrel.end(),back_inserter(allDetLayers));
480  std::copy(allForward.begin(),allForward.end(),back_inserter(allDetLayers));
481 
482  // number layers
483  int sq=0;
484  for (auto l : allDetLayers)
485  (*const_cast<DetLayer*>(l)).setSeqNum(sq++);
486 
487 
488 }
#define LogDebug(id)
const std::vector< const DetLayer * > & allEndcapCscME0Layers() const
return all endcap DetLayers (CSC+ME0), -Z to +Z
const std::vector< const DetLayer * > & backwardGEMLayers() const
return the backward (-Z) GEM DetLayers, inside-out
const std::vector< const DetLayer * > & allCscGemBackwardLayers() const
return all endcap DetLayers (CSC+GEM), -Z to +Z
void addME0Layers(const std::pair< std::vector< DetLayer * >, std::vector< DetLayer * > > &gemlayers)
virtual const DetLayer * idToLayer(const DetId &detId) const override
return the DetLayer which correspond to a certain DetId
const std::vector< const DetLayer * > & allEndcapLayers() const
return all endcap DetLayers (CSC+RPC+GEM+ME0), -Z to +Z
virtual SubDetector subDetector() const =0
The type of detector (PixelBarrel, PixelEndcap, TIB, TOB, TID, TEC, CSC, DT, RPCBarrel, RPCEndcap)
virtual const std::vector< const GeomDet * > & basicComponents() const =0
static const int GEM
Definition: MuonSubdetId.h:15
const std::vector< const DetLayer * > & forwardRPCLayers() const
return the forward (+Z) RPC DetLayers, inside-out
void addDTLayers(const std::vector< DetLayer * > &dtlayers)
virtual const BoundCylinder & specificSurface() const final
Extension of the interface.
const std::vector< const DetLayer * > & allCSCLayers() const
return the CSC DetLayers (endcap), -Z to +Z
result_type operator()(const DetLayer *p) const
const std::vector< const DetLayer * > & forwardME0Layers() const
return the forward (+Z) ME0 DetLayers, inside-out
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
static const int ME0
Definition: MuonSubdetId.h:16
static const int CSC
Definition: MuonSubdetId.h:13
const std::vector< const DetLayer * > & allCscME0ForwardLayers() const
return all endcap DetLayers (CSC+ME0), -Z to +Z
const std::vector< const DetLayer * > & allForwardLayers() const
return all forward (+Z) layers (CSC+RPC+GEM+ME0), inside-out
void addGEMLayers(const std::pair< std::vector< DetLayer * >, std::vector< DetLayer * > > &gemlayers)
const std::vector< const DetLayer * > & allBarrelLayers() const
return all barrel DetLayers (DT+RPC), inside-out
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
MuonDetLayerGeometry()
Constructor.
const std::vector< const DetLayer * > & endcapRPCLayers() const
return the endcap RPC DetLayers, -Z to +Z
const std::vector< const DetLayer * > & allME0Layers() const
return the ME0 DetLayers (endcap), -Z to +Z
Definition: DetId.h:18
const std::vector< const DetLayer * > & allDTLayers() const
return the DT DetLayers (barrel), inside-out
const std::vector< const DetLayer * > & backwardME0Layers() const
return the backward (-Z) ME0 DetLayers, inside-out
const std::vector< const DetLayer * > & forwardCSCLayers() const
return the forward (+Z) CSC DetLayers, inside-out
DetId makeDetLayerId(const DetLayer *detLayer) const
virtual ~MuonDetLayerGeometry()
Destructor.
const std::vector< const DetLayer * > & allCscME0BackwardLayers() const
return all endcap DetLayers (CSC+ME0), -Z to +Z
void addRPCLayers(const std::vector< DetLayer * > &barrelRPCLayers, const std::pair< std::vector< DetLayer * >, std::vector< DetLayer * > > &endcapRPCLayers)
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr)
const std::vector< const DetLayer * > & allBackwardLayers() const
return all backward (-Z) layers (CSC+RPC+GEM+ME0), inside-out
static const int RPC
Definition: MuonSubdetId.h:14
const std::vector< const DetLayer * > & allGEMLayers() const
return the GEM DetLayers (endcap), -Z to +Z
static const int DT
Definition: MuonSubdetId.h:12
const std::vector< const DetLayer * > & allLayers() const
return all layers (DT+CSC+RPC+GEM), order: backward, barrel, forward
const std::vector< const DetLayer * > & forwardGEMLayers() const
return the forward (+Z) GEM DetLayers, inside-out
const std::vector< const DetLayer * > & backwardCSCLayers() const
return the backward (-Z) CSC DetLayers, inside-out
const std::vector< const DetLayer * > & allCscGemForwardLayers() const
return all endcap DetLayers (CSC+GEM), -Z to +Z
const std::vector< const DetLayer * > & barrelRPCLayers() const
return the barrel RPC DetLayers, inside-out
const std::vector< const DetLayer * > & allEndcapCscGemLayers() const
return all endcap DetLayers (CSC+GEM), -Z to +Z
const std::vector< const DetLayer * > & backwardRPCLayers() const
return the backward (-Z) RPC DetLayers, inside-out
void addCSCLayers(const std::pair< std::vector< DetLayer * >, std::vector< DetLayer * > > &csclayers)
const std::vector< const DetLayer * > & allRPCLayers() const
return all RPC DetLayers, order: backward, barrel, forward