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  delete *it;
33  }
34 }
35 
36 void MuonDetLayerGeometry::addCSCLayers(const pair<vector<DetLayer*>, vector<DetLayer*> >& csclayers) {
37  for (auto const it : csclayers.first) {
38  cscLayers_fw.push_back(it);
39  allForward.push_back(it);
40 
41  detLayersMap[makeDetLayerId(it)] = it;
42  }
43 
44  for (auto const it : csclayers.second) {
45  cscLayers_bk.push_back(it);
46  allBackward.push_back(it);
47 
48  detLayersMap[makeDetLayerId(it)] = it;
49  }
50 }
51 
52 void MuonDetLayerGeometry::addGEMLayers(const pair<vector<DetLayer*>, vector<DetLayer*> >& gemlayers) {
53  LogDebug("Muon|RecoMuon|MuonDetLayerGeometry") << "Adding GEMlayers " << std::endl;
54  for (auto const it : gemlayers.first) {
55  gemLayers_fw.push_back(it);
56  allForward.push_back(it);
57  detLayersMap[makeDetLayerId(it)] = it;
58  LogDebug("Muon|RecoMuon|MuonDetLayerGeometry") << "Adding GEMforward " << std::endl;
59  }
60  for (auto const it : gemlayers.second) {
61  gemLayers_bk.push_back(it);
62  allBackward.push_back(it);
63  detLayersMap[makeDetLayerId(it)] = it;
64  LogDebug("Muon|RecoMuon|MuonDetLayerGeometry") << "Adding GEMbackward " << std::endl;
65  }
66 }
67 
68 void MuonDetLayerGeometry::addME0Layers(const pair<vector<DetLayer*>, vector<DetLayer*> >& me0layers) {
69  LogDebug("Muon|RecoMuon|MuonDetLayerGeometry") << "Adding ME0layers " << std::endl;
70 
71  for (auto const it : me0layers.first) {
72  me0Layers_fw.push_back(it);
73  allForward.push_back(it);
74 
75  detLayersMap[makeDetLayerId(it)] = it;
76  LogDebug("Muon|RecoMuon|MuonDetLayerGeometry") << "Adding ME0forward " << std::endl;
77  }
78  for (auto const it : me0layers.second) {
79  me0Layers_bk.push_back(it);
80  allBackward.push_back(it);
81 
82  detLayersMap[makeDetLayerId(it)] = it;
83  LogDebug("Muon|RecoMuon|MuonDetLayerGeometry") << "Adding ME0backward " << std::endl;
84  }
85 }
86 
87 void MuonDetLayerGeometry::addRPCLayers(const vector<DetLayer*>& barrelLayers,
88  const pair<vector<DetLayer*>, vector<DetLayer*> >& endcapLayers) {
89  for (auto const it : barrelLayers) {
90  rpcLayers_barrel.push_back(it);
91  allBarrel.push_back(it);
92 
93  detLayersMap[makeDetLayerId(it)] = it;
94  }
95  for (auto const it : endcapLayers.first) {
96  rpcLayers_fw.push_back(it);
97  allForward.push_back(it);
98 
99  detLayersMap[makeDetLayerId(it)] = it;
100  }
101 
102  for (auto const it : endcapLayers.second) {
103  rpcLayers_bk.push_back(it);
104  allBackward.push_back(it);
105 
106  detLayersMap[makeDetLayerId(it)] = it;
107  }
108 }
109 
110 void MuonDetLayerGeometry::addDTLayers(const vector<DetLayer*>& dtlayers) {
111  for (auto const it : dtlayers) {
112  dtLayers.push_back(it);
113  allBarrel.push_back(it);
114 
115  detLayersMap[makeDetLayerId(it)] = it;
116  }
117 }
118 
120  if (detLayer->subDetector() == GeomDetEnumerators::CSC) {
121  CSCDetId id(detLayer->basicComponents().front()->geographicalId().rawId());
122 
123  if (id.station() == 1) {
124  if (id.ring() == 1 || id.ring() == 4)
125  return CSCDetId(id.endcap(), 1, 1, 0, 0);
126  else if (id.ring() == 2 || id.ring() == 3)
127  return CSCDetId(id.endcap(), 1, 2, 0, 0);
128  else
129  throw cms::Exception("InvalidCSCRing") << " Invalid CSC Ring: " << id.ring() << endl;
130  } else
131  return CSCDetId(id.endcap(), id.station(), 0, 0, 0);
132 
133  } else if (detLayer->subDetector() == GeomDetEnumerators::DT) {
134  DTChamberId id(detLayer->basicComponents().front()->geographicalId().rawId());
135  return DTChamberId(0, id.station(), 0);
136  } else if (detLayer->subDetector() == GeomDetEnumerators::RPCBarrel ||
138  RPCDetId id(detLayer->basicComponents().front()->geographicalId().rawId());
139  return RPCDetId(id.region(), 0, id.station(), 0, id.layer(), 0, 0);
140  } else if (detLayer->subDetector() == GeomDetEnumerators::GEM) {
141  GEMDetId id(detLayer->basicComponents().front()->geographicalId().rawId());
142  return GEMDetId(id.region(), 1, id.station(), id.layer(), 0, 0);
143  } else if (detLayer->subDetector() == GeomDetEnumerators::ME0) {
144  ME0DetId id(detLayer->basicComponents().front()->geographicalId().rawId());
145  return ME0DetId(id.region(), id.layer(), 0, 0);
146  } else
147  throw cms::Exception("InvalidModuleIdentification"); // << detLayer->module();
148 }
149 
150 const vector<const DetLayer*>& MuonDetLayerGeometry::allDTLayers() const { return dtLayers; }
151 
152 const vector<const DetLayer*>& MuonDetLayerGeometry::allCSCLayers() const { return cscLayers_all; }
153 
154 const vector<const DetLayer*>& MuonDetLayerGeometry::forwardCSCLayers() const { return cscLayers_fw; }
155 
156 const vector<const DetLayer*>& MuonDetLayerGeometry::backwardCSCLayers() const { return cscLayers_bk; }
157 
159 const vector<const DetLayer*>& MuonDetLayerGeometry::allGEMLayers() const { return gemLayers_all; }
160 
161 const vector<const DetLayer*>& MuonDetLayerGeometry::forwardGEMLayers() const { return gemLayers_fw; }
162 
163 const vector<const DetLayer*>& MuonDetLayerGeometry::backwardGEMLayers() const { return gemLayers_bk; }
164 
166 
168 
169 const vector<const DetLayer*>& MuonDetLayerGeometry::allME0Layers() const { return me0Layers_all; }
170 
171 const vector<const DetLayer*>& MuonDetLayerGeometry::forwardME0Layers() const { return me0Layers_fw; }
172 
173 const vector<const DetLayer*>& MuonDetLayerGeometry::backwardME0Layers() const { return me0Layers_bk; }
174 
176 
177 const vector<const DetLayer*>& MuonDetLayerGeometry::allRPCLayers() const { return rpcLayers_all; }
178 
179 const vector<const DetLayer*>& MuonDetLayerGeometry::barrelRPCLayers() const { return rpcLayers_barrel; }
180 
181 const vector<const DetLayer*>& MuonDetLayerGeometry::endcapRPCLayers() const { return rpcLayers_endcap; }
182 
183 const vector<const DetLayer*>& MuonDetLayerGeometry::forwardRPCLayers() const { return rpcLayers_fw; }
184 
185 const vector<const DetLayer*>& MuonDetLayerGeometry::backwardRPCLayers() const { return rpcLayers_bk; }
186 
187 const vector<const DetLayer*>& MuonDetLayerGeometry::allLayers() const { return allDetLayers; }
188 
189 const vector<const DetLayer*>& MuonDetLayerGeometry::allBarrelLayers() const { return allBarrel; }
190 
191 const vector<const DetLayer*>& MuonDetLayerGeometry::allEndcapLayers() const { return allEndcap; }
192 
193 const vector<const DetLayer*>& MuonDetLayerGeometry::allForwardLayers() const { return allForward; }
194 
195 const vector<const DetLayer*>& MuonDetLayerGeometry::allBackwardLayers() const { return allBackward; }
196 
198 //
199 const vector<const DetLayer*>& MuonDetLayerGeometry::allEndcapCscGemLayers() const { return allEndcapCscGem; }
200 
201 const vector<const DetLayer*>& MuonDetLayerGeometry::allCscGemForwardLayers() const { return allCscGemForward; }
202 
203 const vector<const DetLayer*>& MuonDetLayerGeometry::allCscGemBackwardLayers() const { return allCscGemBackward; }
204 
206 
207 const vector<const DetLayer*>& MuonDetLayerGeometry::allEndcapCscME0Layers() const { return allEndcapCscME0; }
208 
209 const vector<const DetLayer*>& MuonDetLayerGeometry::allCscME0ForwardLayers() const { return allCscME0Forward; }
210 
211 const vector<const DetLayer*>& MuonDetLayerGeometry::allCscME0BackwardLayers() const { return allCscME0Backward; }
212 
214 
216  DetId id;
217 
218  if (detId.subdetId() == MuonSubdetId::CSC) {
219  CSCDetId cscId(detId.rawId());
220 
221  if (cscId.station() == 1) {
222  if (cscId.ring() == 1 || cscId.ring() == 4)
223  id = CSCDetId(cscId.endcap(), 1, 1, 0, 0);
224  else if (cscId.ring() == 2 || cscId.ring() == 3)
225  id = CSCDetId(cscId.endcap(), 1, 2, 0, 0);
226  else
227  throw cms::Exception("InvalidCSCRing") << " Invalid CSC Ring: " << cscId.ring() << endl;
228  } else
229  id = CSCDetId(cscId.endcap(), cscId.station(), 0, 0, 0);
230  }
231 
232  else if (detId.subdetId() == MuonSubdetId::DT) {
233  DTChamberId dtId(detId.rawId());
234  id = DTChamberId(0, dtId.station(), 0);
235  } else if (detId.subdetId() == MuonSubdetId::RPC) {
236  RPCDetId rpcId(detId.rawId());
237  id = RPCDetId(rpcId.region(), 0, rpcId.station(), 0, rpcId.layer(), 0, 0);
238  } else if (detId.subdetId() == MuonSubdetId::GEM) {
239  GEMDetId gemId(detId.rawId());
240  id = GEMDetId(gemId.region(), 1, gemId.station(), gemId.layer(), 0, 0);
241  } else if (detId.subdetId() == MuonSubdetId::ME0) {
242  ME0DetId me0Id(detId.rawId());
243  id = ME0DetId(me0Id.region(), me0Id.layer(), 0, 0);
244  LogDebug("Muon|RecoMuon|MuonDetLayerGeometry")
245  << " Found an ME0DetId: " << me0Id.rawId() << ",id: " << id.rawId() << std::endl;
246 
247  } else
248  throw cms::Exception("InvalidSubdetId") << detId.subdetId();
249 
250  std::map<DetId, const DetLayer*>::const_iterator layer = detLayersMap.find(id);
251  if (layer == detLayersMap.end())
252  return nullptr;
253  return layer->second;
254 }
255 
256 // Quick way to sort barrel det layers by increasing R,
257 // do not abuse!
259 struct ExtractBarrelDetLayerR {
262  const BarrelDetLayer* bdl = dynamic_cast<const BarrelDetLayer*>(p);
263  if (bdl)
264  return bdl->specificSurface().radius();
265  else
266  return -1.;
267  }
268 };
269 
271  // The following are filled inside-out, no need to re-sort
272  // precomputed_value_sort(dtLayers.begin(), dtLayers.end(),ExtractR<DetLayer,float>());
273  // precomputed_value_sort(cscLayers_fw.begin(), cscLayers_fw.end(),ExtractAbsZ<DetLayer,float>());
274  // precomputed_value_sort(cscLayers_bk.begin(), cscLayers_bk.end(),ExtractAbsZ<DetLayer,float>());
275  // precomputed_value_sort(rpcLayers_fw.begin(), rpcLayers_fw.end(),ExtractAbsZ<DetLayer,float>());
276  // precomputed_value_sort(rpcLayers_bk.begin(), rpcLayers_bk.end(),ExtractAbsZ<DetLayer,float>());
277  // precomputed_value_sort(rpcLayers_barrel.begin(), rpcLayers_barrel.end(), ExtractR<DetLayer,float>());
278 
279  // Sort these inside-out
280  precomputed_value_sort(allBarrel.begin(), allBarrel.end(), ExtractBarrelDetLayerR());
281  precomputed_value_sort(allBackward.begin(), allBackward.end(), ExtractAbsZ<DetLayer, float>());
282  precomputed_value_sort(allForward.begin(), allForward.end(), ExtractAbsZ<DetLayer, float>());
283 
284  // Build more complicated vectors with correct sorting
285 
286  //cscLayers_all: from -Z to +Z
287  cscLayers_all.reserve(cscLayers_bk.size() + cscLayers_fw.size());
288  std::copy(cscLayers_bk.begin(), cscLayers_bk.end(), back_inserter(cscLayers_all));
289  std::reverse(cscLayers_all.begin(), cscLayers_all.end());
290  std::copy(cscLayers_fw.begin(), cscLayers_fw.end(), back_inserter(cscLayers_all));
291 
292  //gemLayers_all: from -Z to +Z
293  gemLayers_all.reserve(gemLayers_bk.size() + gemLayers_fw.size());
294  std::copy(gemLayers_bk.begin(), gemLayers_bk.end(), back_inserter(gemLayers_all));
295  std::reverse(gemLayers_all.begin(), gemLayers_all.end());
296  std::copy(gemLayers_fw.begin(), gemLayers_fw.end(), back_inserter(gemLayers_all));
297 
298  //me0Layers_all: from -Z to +Z
299  me0Layers_all.reserve(me0Layers_bk.size() + me0Layers_fw.size());
300  std::copy(me0Layers_bk.begin(), me0Layers_bk.end(), back_inserter(me0Layers_all));
301  std::reverse(me0Layers_all.begin(), me0Layers_all.end());
302  std::copy(me0Layers_fw.begin(), me0Layers_fw.end(), back_inserter(me0Layers_all));
303 
304  //rpcLayers_endcap: from -Z to +Z
305  rpcLayers_endcap.reserve(rpcLayers_bk.size() + rpcLayers_fw.size());
306  std::copy(rpcLayers_bk.begin(), rpcLayers_bk.end(), back_inserter(rpcLayers_endcap));
307  std::reverse(rpcLayers_endcap.begin(), rpcLayers_endcap.end());
308  std::copy(rpcLayers_fw.begin(), rpcLayers_fw.end(), back_inserter(rpcLayers_endcap));
309 
310  //rpcLayers_all: order is bw, barrel, fw
311  rpcLayers_all.reserve(rpcLayers_bk.size() + rpcLayers_barrel.size() + rpcLayers_fw.size());
312  std::copy(rpcLayers_bk.begin(), rpcLayers_bk.end(), back_inserter(rpcLayers_all));
313  std::reverse(rpcLayers_all.begin(), rpcLayers_all.end());
314  std::copy(rpcLayers_barrel.begin(), rpcLayers_barrel.end(), back_inserter(rpcLayers_all));
315  std::copy(rpcLayers_fw.begin(), rpcLayers_fw.end(), back_inserter(rpcLayers_all));
316 
317  // allEndcap: order is all bw, all fw
318  allEndcap.reserve(allBackward.size() + allForward.size());
319  std::copy(allBackward.begin(), allBackward.end(), back_inserter(allEndcap));
320  std::reverse(allEndcap.begin(), allEndcap.end());
321  std::copy(allForward.begin(), allForward.end(), back_inserter(allEndcap));
322 
323  // allEndcapCSCGEM: order is all bw, all fw
324  allEndcapCscGem.reserve(cscLayers_bk.size() + cscLayers_fw.size() + gemLayers_bk.size() + gemLayers_fw.size());
325  std::copy(cscLayers_bk.begin(), cscLayers_bk.end(), back_inserter(allEndcapCscGem));
326  std::copy(gemLayers_bk.begin(), gemLayers_bk.end(), back_inserter(allEndcapCscGem));
327  std::reverse(allEndcapCscGem.begin(), allEndcapCscGem.end());
328  std::copy(cscLayers_fw.begin(), cscLayers_fw.end(), back_inserter(allEndcapCscGem));
329  std::copy(gemLayers_fw.begin(), gemLayers_fw.end(), back_inserter(allEndcapCscGem));
330 
331  // allCscGemForward
332  allCscGemForward.reserve(cscLayers_fw.size() + gemLayers_fw.size());
333  std::copy(cscLayers_fw.begin(), cscLayers_fw.end(), back_inserter(allCscGemForward));
334  std::copy(gemLayers_fw.begin(), gemLayers_fw.end(), back_inserter(allCscGemForward));
335 
336  // allCscGemBackward
337  allCscGemBackward.reserve(cscLayers_bk.size() + gemLayers_bk.size());
338  std::copy(cscLayers_bk.begin(), cscLayers_bk.end(), back_inserter(allCscGemBackward));
339  std::copy(gemLayers_bk.begin(), gemLayers_bk.end(), back_inserter(allCscGemBackward));
340 
341  // allCscME0Forward
342  allCscME0Forward.reserve(cscLayers_fw.size() + me0Layers_fw.size());
343  std::copy(cscLayers_fw.begin(), cscLayers_fw.end(), back_inserter(allCscME0Forward));
344  std::copy(me0Layers_fw.begin(), me0Layers_fw.end(), back_inserter(allCscME0Forward));
345 
346  // allCscME0Backward
347  allCscME0Backward.reserve(cscLayers_bk.size() + me0Layers_bk.size());
348  std::copy(cscLayers_bk.begin(), cscLayers_bk.end(), back_inserter(allCscME0Backward));
349  std::copy(me0Layers_bk.begin(), me0Layers_bk.end(), back_inserter(allCscME0Backward));
350 
351  // allEndcapCSCME0: order is all bw, all fw
352  allEndcapCscME0.reserve(cscLayers_bk.size() + cscLayers_fw.size() + me0Layers_bk.size() + me0Layers_fw.size());
353  std::copy(cscLayers_bk.begin(), cscLayers_bk.end(), back_inserter(allEndcapCscME0));
354  std::copy(me0Layers_bk.begin(), me0Layers_bk.end(), back_inserter(allEndcapCscME0));
355  std::reverse(allEndcapCscME0.begin(), allEndcapCscME0.end());
356  std::copy(cscLayers_fw.begin(), cscLayers_fw.end(), back_inserter(allEndcapCscME0));
357  std::copy(me0Layers_fw.begin(), me0Layers_fw.end(), back_inserter(allEndcapCscME0));
358 
359  // allDetLayers: order is all bw, all barrel, all fw
360  allDetLayers.reserve(allBackward.size() + allBarrel.size() + allForward.size());
361  std::copy(allBackward.begin(), allBackward.end(), back_inserter(allDetLayers));
362  std::reverse(allDetLayers.begin(), allDetLayers.end());
363  std::copy(allBarrel.begin(), allBarrel.end(), back_inserter(allDetLayers));
364  std::copy(allForward.begin(), allForward.end(), back_inserter(allDetLayers));
365 
366  // number layers
367  int sq = 0;
368  for (auto l : allDetLayers)
369  (*const_cast<DetLayer*>(l)).setSeqNum(sq++);
370 }
const std::vector< const DetLayer * > & allBackwardLayers() const
return all backward (-Z) layers (CSC+RPC+GEM+ME0), inside-out
const std::vector< const DetLayer * > & allEndcapCscME0Layers() const
return all endcap DetLayers (CSC+ME0), -Z to +Z
const std::vector< const DetLayer * > & forwardCSCLayers() const
return the forward (+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 * > & backwardRPCLayers() const
return the backward (-Z) RPC DetLayers, inside-out
static constexpr int GEM
Definition: MuonSubdetId.h:14
~MuonDetLayerGeometry() override
Destructor.
const std::vector< const DetLayer * > & endcapRPCLayers() const
return the endcap RPC DetLayers, -Z to +Z
const std::vector< const DetLayer * > & backwardME0Layers() const
return the backward (-Z) ME0 DetLayers, inside-out
const std::vector< const DetLayer * > & allForwardLayers() const
return all forward (+Z) layers (CSC+RPC+GEM+ME0), inside-out
virtual SubDetector subDetector() const =0
The type of detector (PixelBarrel, PixelEndcap, TIB, TOB, TID, TEC, CSC, DT, RPCBarrel, RPCEndcap)
const DetLayer * idToLayer(const DetId &detId) const override
return the DetLayer which correspond to a certain DetId
void addGEMLayers(const std::pair< std::vector< DetLayer *>, std::vector< DetLayer *> > &gemlayers)
const std::vector< const DetLayer * > & allDTLayers() const
return the DT DetLayers (barrel), inside-out
const std::vector< const DetLayer * > & forwardME0Layers() const
return the forward (+Z) ME0 DetLayers, inside-out
const std::vector< const DetLayer * > & allRPCLayers() const
return all RPC DetLayers, order: backward, barrel, forward
const std::vector< const DetLayer * > & allLayers() const
return all layers (DT+CSC+RPC+GEM), order: backward, barrel, forward
const std::vector< const DetLayer * > & forwardRPCLayers() const
return the forward (+Z) RPC DetLayers, inside-out
void addDTLayers(const std::vector< DetLayer *> &dtlayers)
void addRPCLayers(const std::vector< DetLayer *> &barrelRPCLayers, const std::pair< std::vector< DetLayer *>, std::vector< DetLayer *> > &endcapRPCLayers)
const std::vector< const DetLayer * > & forwardGEMLayers() const
return the forward (+Z) GEM DetLayers, inside-out
const std::vector< const DetLayer * > & allME0Layers() const
return the ME0 DetLayers (endcap), -Z to +Z
const std::vector< const DetLayer * > & allCscGemBackwardLayers() const
return all endcap DetLayers (CSC+GEM), -Z to +Z
const std::vector< const DetLayer * > & allGEMLayers() const
return the GEM DetLayers (endcap), -Z to +Z
void addME0Layers(const std::pair< std::vector< DetLayer *>, std::vector< DetLayer *> > &gemlayers)
result_type operator()(const DetLayer *p) const
static constexpr int ME0
Definition: MuonSubdetId.h:15
MuonDetLayerGeometry()
Constructor.
void addCSCLayers(const std::pair< std::vector< DetLayer *>, std::vector< DetLayer *> > &csclayers)
const std::vector< const DetLayer * > & allEndcapCscGemLayers() const
return all endcap DetLayers (CSC+GEM), -Z to +Z
DetId makeDetLayerId(const DetLayer *detLayer) const
const std::vector< const DetLayer * > & allCSCLayers() const
return the CSC DetLayers (endcap), -Z to +Z
Definition: DetId.h:17
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr, const Compare &comp)
const std::vector< const DetLayer * > & backwardGEMLayers() const
return the backward (-Z) GEM DetLayers, inside-out
const std::vector< const DetLayer * > & backwardCSCLayers() const
return the backward (-Z) CSC DetLayers, inside-out
static constexpr int RPC
Definition: MuonSubdetId.h:13
virtual const BoundCylinder & specificSurface() const final
Extension of the interface.
const std::vector< const DetLayer * > & allCscME0BackwardLayers() const
return all endcap DetLayers (CSC+ME0), -Z to +Z
virtual const std::vector< const GeomDet * > & basicComponents() const =0
const std::vector< const DetLayer * > & allBarrelLayers() const
return all barrel DetLayers (DT+RPC), inside-out
const std::vector< const DetLayer * > & allEndcapLayers() const
return all endcap DetLayers (CSC+RPC+GEM+ME0), -Z to +Z
static constexpr int DT
Definition: MuonSubdetId.h:11
const std::vector< const DetLayer * > & allCscME0ForwardLayers() const
return all endcap DetLayers (CSC+ME0), -Z to +Z
const std::vector< const DetLayer * > & barrelRPCLayers() const
return the barrel RPC DetLayers, inside-out
static constexpr int CSC
Definition: MuonSubdetId.h:12
#define LogDebug(id)