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 
7 
13 
16 
17 #include <algorithm>
18 
19 using namespace std;
20 using namespace geomsort;
21 
23 
25  for(vector<const DetLayer*>::const_iterator it = allDetLayers.begin(); it != allDetLayers.end(); ++it)
26  {
27  delete *it;
28  }
29 }
30 
31 void MuonDetLayerGeometry::addCSCLayers(const pair<vector<DetLayer*>, vector<DetLayer*> >& csclayers) {
32 
33  for(auto const it : csclayers.first) {
34  cscLayers_fw.push_back(it);
35  // cscLayers_all.push_back(it);
36  allForward.push_back(it);
37  // allEndcap.push_back(it);
38  // allDetLayers.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  // cscLayers_all.push_back(it);
46  allBackward.push_back(it);
47  // allEndcap.push_back(it);
48  // allDetLayers.push_back(it);
49 
50  detLayersMap[ makeDetLayerId(it) ] = it;
51  }
52 }
53 
54 void MuonDetLayerGeometry::addRPCLayers(const vector<DetLayer*>& barrelLayers, const pair<vector<DetLayer*>, vector<DetLayer*> >& endcapLayers) {
55 
56  for(auto const it: barrelLayers) {
57  rpcLayers_barrel.push_back(it);
58  // rpcLayers_all.push_back(it);
59  allBarrel.push_back(it);
60  // allDetLayers.push_back(it);
61 
62  detLayersMap[ makeDetLayerId(it) ] = it;
63  }
64  for(auto const it: endcapLayers.first) {
65  rpcLayers_fw.push_back(it);
66  // rpcLayers_all.push_back(it);
67  // rpcLayers_endcap.push_back(it);
68  allForward.push_back(it);
69  // allEndcap.push_back(it);
70  // allDetLayers.push_back(it);
71 
72  detLayersMap[ makeDetLayerId(it) ] = it;
73  }
74 
75  for(auto const it: endcapLayers.second) {
76  rpcLayers_bk.push_back(it);
77  // rpcLayers_all.push_back(it);
78  // rpcLayers_endcap.push_back(it);
79  allBackward.push_back(it);
80  // allEndcap.push_back(it);
81  // allDetLayers.push_back(it);
82 
83  detLayersMap[ makeDetLayerId(it) ] = it;
84  }
85 
86 }
87 
88 void MuonDetLayerGeometry::addDTLayers(const vector<DetLayer*>& dtlayers) {
89 
90  for(auto const it : dtlayers) {
91  dtLayers.push_back(it);
92  allBarrel.push_back(it);
93  // allDetLayers.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 throw cms::Exception("InvalidModuleIdentification"); // << detLayer->module();
127 }
128 
129 
130 const vector<const DetLayer*>&
132  return dtLayers;
133 }
134 
135 const vector<const DetLayer*>&
137  return cscLayers_all;
138 }
139 
140 
141 const vector<const DetLayer*>&
143  return cscLayers_fw;
144 }
145 
146 
147 const vector<const DetLayer*>&
149  return cscLayers_bk;
150 }
151 
152 
153 const vector<const DetLayer*>&
155  return rpcLayers_all;
156 }
157 
158 
159 const vector<const DetLayer*>&
161  return rpcLayers_barrel;
162 }
163 
164 
165 const vector<const DetLayer*>&
167  return rpcLayers_endcap;
168 }
169 
170 
171 const vector<const DetLayer*>&
173  return rpcLayers_fw;
174 }
175 
176 
177 const vector<const DetLayer*>&
179  return rpcLayers_bk;
180 }
181 
182 
183 const vector<const DetLayer*>&
185  return allDetLayers;
186 }
187 
188 
189 const vector<const DetLayer*>&
191  return allBarrel;
192 }
193 
194 const vector<const DetLayer*>&
196  return allEndcap;
197 }
198 
199 
200 const vector<const DetLayer*>&
202  return allForward;
203 }
204 
205 
206 const vector<const DetLayer*>&
208  return allBackward;
209 }
210 
211 const DetLayer* MuonDetLayerGeometry::idToLayer(const DetId &detId) const{
212 
213  DetId id;
214 
215  if(detId.subdetId() == MuonSubdetId::CSC){
216  CSCDetId cscId( detId.rawId() );
217 
218  if(cscId.station() == 1)
219  {
220  if(cscId.ring() == 1 || cscId.ring() == 4)
221  id = CSCDetId(cscId.endcap(),1,1,0,0);
222  else if(cscId.ring() == 2 || cscId.ring() == 3)
223  id = CSCDetId(cscId.endcap(),1,2,0,0);
224  else
225  throw cms::Exception("InvalidCSCRing")<<" Invalid CSC Ring: "<<cscId.ring()<<endl;
226  }
227  else id = CSCDetId(cscId.endcap(),cscId.station(),0,0,0);
228  }
229 
230  else if (detId.subdetId() == MuonSubdetId::DT){
231  DTChamberId dtId( detId.rawId() );
232  id = DTChamberId(0,dtId.station(),0);
233  }
234  else if (detId.subdetId() == MuonSubdetId::RPC){
235  RPCDetId rpcId(detId.rawId() );
236  id = RPCDetId(rpcId.region(),0,rpcId.station(),0,rpcId.layer(),0,0);
237  }
238 
239  else throw cms::Exception("InvalidSubdetId")<< detId.subdetId();
240 
241  std::map<DetId,const DetLayer*>::const_iterator layer = detLayersMap.find(id);
242  if (layer == detLayersMap.end()) return 0;
243  return layer->second;
244 }
245 
246 
247 // Quick way to sort barrel det layers by increasing R,
248 // do not abuse!
253  const BarrelDetLayer * bdl = dynamic_cast<const BarrelDetLayer*>(p);
254  if (bdl) return bdl->specificSurface().radius();
255  else return -1.;
256  }
257 };
258 
260 
261  // The following are filled inside-out, no need to re-sort
262  // precomputed_value_sort(dtLayers.begin(), dtLayers.end(),ExtractR<DetLayer,float>());
263  // precomputed_value_sort(cscLayers_fw.begin(), cscLayers_fw.end(),ExtractAbsZ<DetLayer,float>());
264  // precomputed_value_sort(cscLayers_bk.begin(), cscLayers_bk.end(),ExtractAbsZ<DetLayer,float>());
265  // precomputed_value_sort(rpcLayers_fw.begin(), rpcLayers_fw.end(),ExtractAbsZ<DetLayer,float>());
266  // precomputed_value_sort(rpcLayers_bk.begin(), rpcLayers_bk.end(),ExtractAbsZ<DetLayer,float>());
267  // precomputed_value_sort(rpcLayers_barrel.begin(), rpcLayers_barrel.end(), ExtractR<DetLayer,float>());
268 
269  // Sort these inside-out
270  precomputed_value_sort(allBarrel.begin(), allBarrel.end(), ExtractBarrelDetLayerR());
271  precomputed_value_sort(allBackward.begin(), allBackward.end(), ExtractAbsZ<DetLayer,float>());
272  precomputed_value_sort(allForward.begin(), allForward.end(), ExtractAbsZ<DetLayer,float>());
273 
274  // Build more complicated vectors with correct sorting
275 
276  //cscLayers_all: from -Z to +Z
277  cscLayers_all.reserve(cscLayers_bk.size()+cscLayers_fw.size());
278  std::copy(cscLayers_bk.begin(),cscLayers_bk.end(),back_inserter(cscLayers_all));
279  std::reverse(cscLayers_all.begin(),cscLayers_all.end());
280  std::copy(cscLayers_fw.begin(),cscLayers_fw.end(),back_inserter(cscLayers_all));
281 
282  //rpcLayers_endcap: from -Z to +Z
283  rpcLayers_endcap.reserve(rpcLayers_bk.size()+rpcLayers_fw.size());
284  std::copy(rpcLayers_bk.begin(),rpcLayers_bk.end(),back_inserter(rpcLayers_endcap));
285  std::reverse(rpcLayers_endcap.begin(),rpcLayers_endcap.end());
286  std::copy(rpcLayers_fw.begin(),rpcLayers_fw.end(),back_inserter(rpcLayers_endcap));
287 
288  //rpcLayers_all: order is bw, barrel, fw
289  rpcLayers_all.reserve(rpcLayers_bk.size()+rpcLayers_barrel.size()+rpcLayers_fw.size());
290  std::copy(rpcLayers_bk.begin(),rpcLayers_bk.end(),back_inserter(rpcLayers_all));
291  std::reverse(rpcLayers_all.begin(),rpcLayers_all.end());
292  std::copy(rpcLayers_barrel.begin(),rpcLayers_barrel.end(),back_inserter(rpcLayers_all));
293  std::copy(rpcLayers_fw.begin(),rpcLayers_fw.end(),back_inserter(rpcLayers_all));
294 
295  // allEndcap: order is all bw, all fw
296  allEndcap.reserve(allBackward.size()+allForward.size());
297  std::copy(allBackward.begin(),allBackward.end(),back_inserter(allEndcap));
298  std::reverse(allEndcap.begin(),allEndcap.end());
299  std::copy(allForward.begin(),allForward.end(),back_inserter(allEndcap));
300 
301  // allDetLayers: order is all bw, all barrel, all fw
302  allDetLayers.reserve(allBackward.size()+allBarrel.size()+allForward.size());
303  std::copy(allBackward.begin(),allBackward.end(),back_inserter(allDetLayers));
304  std::reverse(allDetLayers.begin(),allDetLayers.end());
305  std::copy(allBarrel.begin(),allBarrel.end(),back_inserter(allDetLayers));
306  std::copy(allForward.begin(),allForward.end(),back_inserter(allDetLayers));
307 
308  // number layers
309  int sq=0;
310  for (auto l : allDetLayers)
311  (*const_cast<DetLayer*>(l)).setSeqNum(sq++);
312 
313 
314 }
const std::vector< const DetLayer * > & allEndcapLayers() const
return all endcap DetLayers (CSC+RPC), -Z to +Z
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), inside-out
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), inside-out
static const int RPC
Definition: MuonSubdetId.h:14
static const int DT
Definition: MuonSubdetId.h:12
const std::vector< const DetLayer * > & allLayers() const
return all layers (DT+CSC+RPC), order: backward, barrel, forward
const std::vector< const DetLayer * > & backwardCSCLayers() const
return the backward (-Z) CSC DetLayers, inside-out
const std::vector< const DetLayer * > & barrelRPCLayers() const
return the barrel RPC DetLayers, inside-out
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