CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonDetLayerGeometry.cc
Go to the documentation of this file.
1 
9 
16 
19 
20 #include <algorithm>
21 
22 using namespace std;
23 using namespace geomsort;
24 
26 
28  for(vector<const DetLayer*>::const_iterator it = allDetLayers.begin(); it != allDetLayers.end(); ++it)
29  {
30  delete *it;
31  }
32 }
33 
34 void MuonDetLayerGeometry::addCSCLayers(const pair<vector<DetLayer*>, vector<DetLayer*> >& csclayers) {
35 
36  for(auto const it : csclayers.first) {
37  cscLayers_fw.push_back(it);
38  allForward.push_back(it);
39 
40  detLayersMap[ makeDetLayerId(it) ] = it;
41  }
42 
43  for(auto const it: csclayers.second) {
44  cscLayers_bk.push_back(it);
45  allBackward.push_back(it);
46 
47  detLayersMap[ makeDetLayerId(it) ] = it;
48  }
49 }
50 
51 void MuonDetLayerGeometry::addGEMLayers(const pair<vector<DetLayer*>, vector<DetLayer*> >& gemlayers) {
52 
53  for(auto const it : gemlayers.first) {
54  gemLayers_fw.push_back(it);
55  allForward.push_back(it);
56  detLayersMap[ makeDetLayerId(it) ] = it;
57  }
58  for(auto const it: gemlayers.second) {
59  gemLayers_bk.push_back(it);
60  allBackward.push_back(it);
61  detLayersMap[ makeDetLayerId(it) ] = it;
62  }
63  }
64 
65 void MuonDetLayerGeometry::addRPCLayers(const vector<DetLayer*>& barrelLayers, const pair<vector<DetLayer*>, vector<DetLayer*> >& endcapLayers) {
66 
67  for(auto const it: barrelLayers) {
68  rpcLayers_barrel.push_back(it);
69  allBarrel.push_back(it);
70 
71  detLayersMap[ makeDetLayerId(it) ] = it;
72  }
73  for(auto const it: endcapLayers.first) {
74  rpcLayers_fw.push_back(it);
75  allForward.push_back(it);
76 
77  detLayersMap[ makeDetLayerId(it) ] = it;
78  }
79 
80  for(auto const it: endcapLayers.second) {
81  rpcLayers_bk.push_back(it);
82  allBackward.push_back(it);
83 
84  detLayersMap[ makeDetLayerId(it) ] = it;
85  }
86 
87 }
88 
89 void MuonDetLayerGeometry::addDTLayers(const vector<DetLayer*>& dtlayers) {
90 
91  for(auto const it : dtlayers) {
92  dtLayers.push_back(it);
93  allBarrel.push_back(it);
94 
95  detLayersMap[ makeDetLayerId(it) ] = it;
96  }
97 }
98 
100 
101  if(detLayer->subDetector() == GeomDetEnumerators::CSC){
102  CSCDetId id( detLayer->basicComponents().front()->geographicalId().rawId() ) ;
103 
104  if(id.station() == 1 )
105  {
106  if(id.ring() == 1 || id.ring() == 4)
107  return CSCDetId(id.endcap(),1,1,0,0);
108  else if(id.ring() == 2 || id.ring() == 3)
109  return CSCDetId(id.endcap(),1,2,0,0);
110  else
111  throw cms::Exception("InvalidCSCRing")<<" Invalid CSC Ring: "<<id.ring()<<endl;
112  }
113  else
114  return CSCDetId(id.endcap(),id.station(),0,0,0);
115 
116  }
117  else if(detLayer->subDetector() == GeomDetEnumerators::DT){
118  DTChamberId id( detLayer->basicComponents().front()->geographicalId().rawId() ) ;
119  return DTChamberId(0,id.station(),0);
120  }
121  else if(detLayer->subDetector()== GeomDetEnumerators::RPCBarrel ||
123  RPCDetId id( detLayer->basicComponents().front()->geographicalId().rawId());
124  return RPCDetId(id.region(),0,id.station(),0,id.layer(),0,0);
125  }
126  else if( detLayer->subDetector()== GeomDetEnumerators::GEM){
127  GEMDetId id( detLayer->basicComponents().front()->geographicalId().rawId());
128  return GEMDetId(id.region(),1,id.station(),id.layer(),0,0);
129  }
130 
131  else throw cms::Exception("InvalidModuleIdentification"); // << detLayer->module();
132 }
133 
134 
135 const vector<const DetLayer*>&
137  return dtLayers;
138 }
139 
140 const vector<const DetLayer*>&
142  return cscLayers_all;
143 }
144 
145 
146 const vector<const DetLayer*>&
148  return cscLayers_fw;
149 }
150 
151 
152 const vector<const DetLayer*>&
154  return cscLayers_bk;
155 }
156 
158 const vector<const DetLayer*>&
160  return gemLayers_all;
161 }
162 
163 
164 const vector<const DetLayer*>&
166  return gemLayers_fw;
167 }
168 
169 
170 const vector<const DetLayer*>&
172  return gemLayers_bk;
173 }
174 
176 
177 const vector<const DetLayer*>&
179  return rpcLayers_all;
180 }
181 
182 
183 const vector<const DetLayer*>&
185  return rpcLayers_barrel;
186 }
187 
188 
189 const vector<const DetLayer*>&
191  return rpcLayers_endcap;
192 }
193 
194 
195 const vector<const DetLayer*>&
197  return rpcLayers_fw;
198 }
199 
200 
201 const vector<const DetLayer*>&
203  return rpcLayers_bk;
204 }
205 
206 
207 const vector<const DetLayer*>&
209  return allDetLayers;
210 }
211 
212 
213 const vector<const DetLayer*>&
215  return allBarrel;
216 }
217 
218 const vector<const DetLayer*>&
220  return allEndcap;
221 }
222 
223 
224 const vector<const DetLayer*>&
226  return allForward;
227 }
228 
229 
230 const vector<const DetLayer*>&
232  return allBackward;
233 }
234 
236 //
237 const vector<const DetLayer*>&
239  return allEndcapCscGem;
240 }
241 
242 
243 const vector<const DetLayer*>&
245  return allCscGemForward;
246 }
247 
248 
249 const vector<const DetLayer*>&
251  return allCscGemBackward;
252 }
253 
255 
256 const DetLayer* MuonDetLayerGeometry::idToLayer(const DetId &detId) const{
257 
258  DetId id;
259 
260  if(detId.subdetId() == MuonSubdetId::CSC){
261  CSCDetId cscId( detId.rawId() );
262 
263  if(cscId.station() == 1)
264  {
265  if(cscId.ring() == 1 || cscId.ring() == 4)
266  id = CSCDetId(cscId.endcap(),1,1,0,0);
267  else if(cscId.ring() == 2 || cscId.ring() == 3)
268  id = CSCDetId(cscId.endcap(),1,2,0,0);
269  else
270  throw cms::Exception("InvalidCSCRing")<<" Invalid CSC Ring: "<<cscId.ring()<<endl;
271  }
272  else id = CSCDetId(cscId.endcap(),cscId.station(),0,0,0);
273  }
274 
275  else if (detId.subdetId() == MuonSubdetId::DT){
276  DTChamberId dtId( detId.rawId() );
277  id = DTChamberId(0,dtId.station(),0);
278  }
279  else if (detId.subdetId() == MuonSubdetId::RPC){
280  RPCDetId rpcId(detId.rawId() );
281  id = RPCDetId(rpcId.region(),0,rpcId.station(),0,rpcId.layer(),0,0);
282  }
283  else if (detId.subdetId() == MuonSubdetId::GEM){
284  GEMDetId gemId(detId.rawId() );
285  id = GEMDetId(gemId.region(),1,gemId.station(),gemId.layer(),0,0);
286  }
287 
288  else throw cms::Exception("InvalidSubdetId")<< detId.subdetId();
289 
290  std::map<DetId,const DetLayer*>::const_iterator layer = detLayersMap.find(id);
291  if (layer == detLayersMap.end()) return 0;
292  return layer->second;
293 }
294 
295 
296 // Quick way to sort barrel det layers by increasing R,
297 // do not abuse!
302  const BarrelDetLayer * bdl = dynamic_cast<const BarrelDetLayer*>(p);
303  if (bdl) return bdl->specificSurface().radius();
304  else return -1.;
305  }
306 };
307 
309 
310  // The following are filled inside-out, no need to re-sort
311  // precomputed_value_sort(dtLayers.begin(), dtLayers.end(),ExtractR<DetLayer,float>());
312  // precomputed_value_sort(cscLayers_fw.begin(), cscLayers_fw.end(),ExtractAbsZ<DetLayer,float>());
313  // precomputed_value_sort(cscLayers_bk.begin(), cscLayers_bk.end(),ExtractAbsZ<DetLayer,float>());
314  // precomputed_value_sort(rpcLayers_fw.begin(), rpcLayers_fw.end(),ExtractAbsZ<DetLayer,float>());
315  // precomputed_value_sort(rpcLayers_bk.begin(), rpcLayers_bk.end(),ExtractAbsZ<DetLayer,float>());
316  // precomputed_value_sort(rpcLayers_barrel.begin(), rpcLayers_barrel.end(), ExtractR<DetLayer,float>());
317 
318  // Sort these inside-out
319  precomputed_value_sort(allBarrel.begin(), allBarrel.end(), ExtractBarrelDetLayerR());
320  precomputed_value_sort(allBackward.begin(), allBackward.end(), ExtractAbsZ<DetLayer,float>());
321  precomputed_value_sort(allForward.begin(), allForward.end(), ExtractAbsZ<DetLayer,float>());
322 
323  // Build more complicated vectors with correct sorting
324 
325  //cscLayers_all: from -Z to +Z
326  cscLayers_all.reserve(cscLayers_bk.size()+cscLayers_fw.size());
327  std::copy(cscLayers_bk.begin(),cscLayers_bk.end(),back_inserter(cscLayers_all));
328  std::reverse(cscLayers_all.begin(),cscLayers_all.end());
329  std::copy(cscLayers_fw.begin(),cscLayers_fw.end(),back_inserter(cscLayers_all));
330 
331  //gemLayers_all: from -Z to +Z
332  gemLayers_all.reserve(gemLayers_bk.size()+gemLayers_fw.size());
333  std::copy(gemLayers_bk.begin(),gemLayers_bk.end(),back_inserter(gemLayers_all));
334  std::reverse(gemLayers_all.begin(),gemLayers_all.end());
335  std::copy(gemLayers_fw.begin(),gemLayers_fw.end(),back_inserter(gemLayers_all));
336 
337  //rpcLayers_endcap: from -Z to +Z
338  rpcLayers_endcap.reserve(rpcLayers_bk.size()+rpcLayers_fw.size());
339  std::copy(rpcLayers_bk.begin(),rpcLayers_bk.end(),back_inserter(rpcLayers_endcap));
340  std::reverse(rpcLayers_endcap.begin(),rpcLayers_endcap.end());
341  std::copy(rpcLayers_fw.begin(),rpcLayers_fw.end(),back_inserter(rpcLayers_endcap));
342 
343  //rpcLayers_all: order is bw, barrel, fw
344  rpcLayers_all.reserve(rpcLayers_bk.size()+rpcLayers_barrel.size()+rpcLayers_fw.size());
345  std::copy(rpcLayers_bk.begin(),rpcLayers_bk.end(),back_inserter(rpcLayers_all));
346  std::reverse(rpcLayers_all.begin(),rpcLayers_all.end());
347  std::copy(rpcLayers_barrel.begin(),rpcLayers_barrel.end(),back_inserter(rpcLayers_all));
348  std::copy(rpcLayers_fw.begin(),rpcLayers_fw.end(),back_inserter(rpcLayers_all));
349 
350  // allEndcap: order is all bw, all fw
351  allEndcap.reserve(allBackward.size()+allForward.size());
352  std::copy(allBackward.begin(),allBackward.end(),back_inserter(allEndcap));
353  std::reverse(allEndcap.begin(),allEndcap.end());
354  std::copy(allForward.begin(),allForward.end(),back_inserter(allEndcap));
355 
356  // allEndcapCSCGEM: order is all bw, all fw
357  allEndcapCscGem.reserve(cscLayers_bk.size()+cscLayers_fw.size()+gemLayers_bk.size()+gemLayers_fw.size());
358  std::copy(cscLayers_bk.begin(),cscLayers_bk.end(),back_inserter(allEndcapCscGem));
359  std::copy(gemLayers_bk.begin(),gemLayers_bk.end(),back_inserter(allEndcapCscGem));
360  std::reverse(allEndcapCscGem.begin(),allEndcapCscGem.end());
361  std::copy(cscLayers_fw.begin(),cscLayers_fw.end(),back_inserter(allEndcapCscGem));
362  std::copy(gemLayers_fw.begin(),gemLayers_fw.end(),back_inserter(allEndcapCscGem));
363 
364  // allCscGemForward
365  allCscGemForward.reserve(cscLayers_fw.size()+gemLayers_fw.size());
366  std::copy(cscLayers_fw.begin(),cscLayers_fw.end(),back_inserter(allCscGemForward));
367  std::copy(gemLayers_fw.begin(),gemLayers_fw.end(),back_inserter(allCscGemForward));
368 
369  // allCscGemBackward
370  allCscGemBackward.reserve(cscLayers_bk.size()+gemLayers_bk.size());
371  std::copy(cscLayers_bk.begin(),cscLayers_bk.end(),back_inserter(allCscGemBackward));
372  std::copy(gemLayers_bk.begin(),gemLayers_bk.end(),back_inserter(allCscGemBackward));
373 
374  // allDetLayers: order is all bw, all barrel, all fw
375  allDetLayers.reserve(allBackward.size()+allBarrel.size()+allForward.size());
376  std::copy(allBackward.begin(),allBackward.end(),back_inserter(allDetLayers));
377  std::reverse(allDetLayers.begin(),allDetLayers.end());
378  std::copy(allBarrel.begin(),allBarrel.end(),back_inserter(allDetLayers));
379  std::copy(allForward.begin(),allForward.end(),back_inserter(allDetLayers));
380 
381  // number layers
382  int sq=0;
383  for (auto l : allDetLayers)
384  (*const_cast<DetLayer*>(l)).setSeqNum(sq++);
385 
386 
387 }
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
const std::vector< const DetLayer * > & allEndcapLayers() const
return all endcap DetLayers (CSC+RPC+GEM), -Z to +Z
static const int GEM
Definition: MuonSubdetId.h:15
virtual SubDetector subDetector() const =0
The type of detector (PixelBarrel, PixelEndcap, TIB, TOB, TID, TEC, CSC, DT, RPCBarrel, RPCEndcap)
const std::vector< const DetLayer * > & forwardRPCLayers() const
return the forward (+Z) RPC DetLayers, inside-out
virtual const DetLayer * idToLayer(const DetId &detId) const override
return the DetLayer which correspond to a certain DetId
void addDTLayers(const std::vector< DetLayer * > &dtlayers)
const std::vector< const DetLayer * > & allCSCLayers() const
return the CSC DetLayers (endcap), -Z to +Z
result_type operator()(const DetLayer *p) const
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
static const int CSC
Definition: MuonSubdetId.h:13
const std::vector< const DetLayer * > & allForwardLayers() const
return all forward (+Z) layers (CSC+RPC+GEM), 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
Definition: DetId.h:18
const std::vector< const DetLayer * > & allDTLayers() const
return the DT DetLayers (barrel), inside-out
const std::vector< const DetLayer * > & forwardCSCLayers() const
return the forward (+Z) CSC DetLayers, inside-out
virtual const BoundCylinder & specificSurface() const
Extension of the interface.
virtual const std::vector< const GeomDet * > & basicComponents() const =0
DetId makeDetLayerId(const DetLayer *detLayer) const
virtual ~MuonDetLayerGeometry()
Destructor.
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), 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