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<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  vector<DetLayer*>::const_iterator it;
34  for(it=csclayers.first.begin(); it!=csclayers.first.end(); it++) {
35  cscLayers_fw.push_back(*it);
36  // cscLayers_all.push_back(*it);
37  allForward.push_back(*it);
38  // allEndcap.push_back(*it);
39  // allDetLayers.push_back(*it);
40 
41  detLayersMap[ makeDetLayerId(*it) ] = *it;
42  }
43 
44  for(it=csclayers.second.begin(); it!=csclayers.second.end(); it++) {
45  cscLayers_bk.push_back(*it);
46  // cscLayers_all.push_back(*it);
47  allBackward.push_back(*it);
48  // allEndcap.push_back(*it);
49  // allDetLayers.push_back(*it);
50 
51  detLayersMap[ makeDetLayerId(*it) ] = *it;
52  }
53 }
54 
55 void MuonDetLayerGeometry::addRPCLayers(const vector<DetLayer*>& barrelLayers, const pair<vector<DetLayer*>, vector<DetLayer*> >& endcapLayers) {
56 
57  vector<DetLayer*>::const_iterator it;
58 
59  for (it=barrelLayers.begin();it!=barrelLayers.end();it++){
60  rpcLayers_barrel.push_back(*it);
61  // rpcLayers_all.push_back(*it);
62  allBarrel.push_back(*it);
63  // allDetLayers.push_back(*it);
64 
65  detLayersMap[ makeDetLayerId(*it) ] = *it;
66  }
67  for (it=endcapLayers.first.begin(); it!=endcapLayers.first.end(); it++){
68  rpcLayers_fw.push_back(*it);
69  // rpcLayers_all.push_back(*it);
70  // rpcLayers_endcap.push_back(*it);
71  allForward.push_back(*it);
72  // allEndcap.push_back(*it);
73  // allDetLayers.push_back(*it);
74 
75  detLayersMap[ makeDetLayerId(*it) ] = *it;
76  }
77 
78  for (it=endcapLayers.second.begin(); it!=endcapLayers.second.end(); it++){
79  rpcLayers_bk.push_back(*it);
80  // rpcLayers_all.push_back(*it);
81  // rpcLayers_endcap.push_back(*it);
82  allBackward.push_back(*it);
83  // allEndcap.push_back(*it);
84  // allDetLayers.push_back(*it);
85 
86  detLayersMap[ makeDetLayerId(*it) ] = *it;
87  }
88 
89 }
90 
91 void MuonDetLayerGeometry::addDTLayers(const vector<DetLayer*>& dtlayers) {
92 
93  vector<DetLayer*>::const_iterator it;
94  for(it=dtlayers.begin(); it!=dtlayers.end(); it++) {
95  dtLayers.push_back(*it);
96  allBarrel.push_back(*it);
97  // allDetLayers.push_back(*it);
98 
99  detLayersMap[ makeDetLayerId(*it) ] = *it;
100  }
101 }
102 
104 
105  if(detLayer->subDetector() == GeomDetEnumerators::CSC){
106  CSCDetId id( detLayer->basicComponents().front()->geographicalId().rawId() ) ;
107 
108  if(id.station() == 1 )
109  {
110  if(id.ring() == 1 || id.ring() == 4)
111  return CSCDetId(id.endcap(),1,1,0,0);
112  else if(id.ring() == 2 || id.ring() == 3)
113  return CSCDetId(id.endcap(),1,2,0,0);
114  else
115  throw cms::Exception("InvalidCSCRing")<<" Invalid CSC Ring: "<<id.ring()<<endl;
116  }
117  else
118  return CSCDetId(id.endcap(),id.station(),0,0,0);
119 
120  }
121  else if(detLayer->subDetector() == GeomDetEnumerators::DT){
122  DTChamberId id( detLayer->basicComponents().front()->geographicalId().rawId() ) ;
123  return DTChamberId(0,id.station(),0);
124  }
125  else if(detLayer->subDetector()== GeomDetEnumerators::RPCBarrel ||
127  RPCDetId id( detLayer->basicComponents().front()->geographicalId().rawId());
128  return RPCDetId(id.region(),0,id.station(),0,id.layer(),0,0);
129  }
130  else throw cms::Exception("InvalidModuleIdentification"); // << detLayer->module();
131 }
132 
133 
134 const vector<DetLayer*>&
136  return dtLayers;
137 }
138 
139 const vector<DetLayer*>&
141  return cscLayers_all;
142 }
143 
144 
145 const vector<DetLayer*>&
147  return cscLayers_fw;
148 }
149 
150 
151 const vector<DetLayer*>&
153  return cscLayers_bk;
154 }
155 
156 
157 const vector<DetLayer*>&
159  return rpcLayers_all;
160 }
161 
162 
163 const vector<DetLayer*>&
165  return rpcLayers_barrel;
166 }
167 
168 
169 const vector<DetLayer*>&
171  return rpcLayers_endcap;
172 }
173 
174 
175 const vector<DetLayer*>&
177  return rpcLayers_fw;
178 }
179 
180 
181 const vector<DetLayer*>&
183  return rpcLayers_bk;
184 }
185 
186 
187 const vector<DetLayer*>&
189  return allDetLayers;
190 }
191 
192 
193 const vector<DetLayer*>&
195  return allBarrel;
196 }
197 
198 const vector<DetLayer*>&
200  return allEndcap;
201 }
202 
203 
204 const vector<DetLayer*>&
206  return allForward;
207 }
208 
209 
210 const vector<DetLayer*>&
212  return allBackward;
213 }
214 
215 const DetLayer* MuonDetLayerGeometry::idToLayer(const DetId &detId) const{
216 
217  DetId id;
218 
219  if(detId.subdetId() == MuonSubdetId::CSC){
220  CSCDetId cscId( detId.rawId() );
221 
222  if(cscId.station() == 1)
223  {
224  if(cscId.ring() == 1 || cscId.ring() == 4)
225  id = CSCDetId(cscId.endcap(),1,1,0,0);
226  else if(cscId.ring() == 2 || cscId.ring() == 3)
227  id = CSCDetId(cscId.endcap(),1,2,0,0);
228  else
229  throw cms::Exception("InvalidCSCRing")<<" Invalid CSC Ring: "<<cscId.ring()<<endl;
230  }
231  else id = CSCDetId(cscId.endcap(),cscId.station(),0,0,0);
232  }
233 
234  else if (detId.subdetId() == MuonSubdetId::DT){
235  DTChamberId dtId( detId.rawId() );
236  id = DTChamberId(0,dtId.station(),0);
237  }
238  else if (detId.subdetId() == MuonSubdetId::RPC){
239  RPCDetId rpcId(detId.rawId() );
240  id = RPCDetId(rpcId.region(),0,rpcId.station(),0,rpcId.layer(),0,0);
241  }
242 
243  else throw cms::Exception("InvalidSubdetId")<< detId.subdetId();
244 
245  std::map<DetId,DetLayer*>::const_iterator layer = detLayersMap.find(id);
246  if (layer == detLayersMap.end()) return 0;
247  return layer->second;
248 }
249 
250 
251 // Quick way to sort barrel det layers by increasing R,
252 // do not abuse!
257  const BarrelDetLayer * bdl = dynamic_cast<const BarrelDetLayer*>(p);
258  if (bdl) return bdl->specificSurface().radius();
259  else return -1.;
260  }
261 };
262 
264 
265  // The following are filled inside-out, no need to re-sort
266  // precomputed_value_sort(dtLayers.begin(), dtLayers.end(),ExtractR<DetLayer,float>());
267  // precomputed_value_sort(cscLayers_fw.begin(), cscLayers_fw.end(),ExtractAbsZ<DetLayer,float>());
268  // precomputed_value_sort(cscLayers_bk.begin(), cscLayers_bk.end(),ExtractAbsZ<DetLayer,float>());
269  // precomputed_value_sort(rpcLayers_fw.begin(), rpcLayers_fw.end(),ExtractAbsZ<DetLayer,float>());
270  // precomputed_value_sort(rpcLayers_bk.begin(), rpcLayers_bk.end(),ExtractAbsZ<DetLayer,float>());
271  // precomputed_value_sort(rpcLayers_barrel.begin(), rpcLayers_barrel.end(), ExtractR<DetLayer,float>());
272 
273  // Sort these inside-out
274  precomputed_value_sort(allBarrel.begin(), allBarrel.end(), ExtractBarrelDetLayerR());
275  precomputed_value_sort(allBackward.begin(), allBackward.end(), ExtractAbsZ<DetLayer,float>());
276  precomputed_value_sort(allForward.begin(), allForward.end(), ExtractAbsZ<DetLayer,float>());
277 
278  // Build more complicated vectors with correct sorting
279 
280  //cscLayers_all: from -Z to +Z
281  cscLayers_all.reserve(cscLayers_bk.size()+cscLayers_fw.size());
282  std::copy(cscLayers_bk.begin(),cscLayers_bk.end(),back_inserter(cscLayers_all));
283  std::reverse(cscLayers_all.begin(),cscLayers_all.end());
284  std::copy(cscLayers_fw.begin(),cscLayers_fw.end(),back_inserter(cscLayers_all));
285 
286  //rpcLayers_endcap: from -Z to +Z
287  rpcLayers_endcap.reserve(rpcLayers_bk.size()+rpcLayers_fw.size());
288  std::copy(rpcLayers_bk.begin(),rpcLayers_bk.end(),back_inserter(rpcLayers_endcap));
289  std::reverse(rpcLayers_endcap.begin(),rpcLayers_endcap.end());
290  std::copy(rpcLayers_fw.begin(),rpcLayers_fw.end(),back_inserter(rpcLayers_endcap));
291 
292  //rpcLayers_all: order is bw, barrel, fw
293  rpcLayers_all.reserve(rpcLayers_bk.size()+rpcLayers_barrel.size()+rpcLayers_fw.size());
294  std::copy(rpcLayers_bk.begin(),rpcLayers_bk.end(),back_inserter(rpcLayers_all));
295  std::reverse(rpcLayers_all.begin(),rpcLayers_all.end());
296  std::copy(rpcLayers_barrel.begin(),rpcLayers_barrel.end(),back_inserter(rpcLayers_all));
297  std::copy(rpcLayers_fw.begin(),rpcLayers_fw.end(),back_inserter(rpcLayers_all));
298 
299  // allEndcap: order is all bw, all fw
300  allEndcap.reserve(allBackward.size()+allForward.size());
301  std::copy(allBackward.begin(),allBackward.end(),back_inserter(allEndcap));
302  std::reverse(allEndcap.begin(),allEndcap.end());
303  std::copy(allForward.begin(),allForward.end(),back_inserter(allEndcap));
304 
305  // allDetLayers: order is all bw, all barrel, all fw
306  allDetLayers.reserve(allBackward.size()+allBarrel.size()+allForward.size());
307  std::copy(allBackward.begin(),allBackward.end(),back_inserter(allDetLayers));
308  std::reverse(allDetLayers.begin(),allDetLayers.end());
309  std::copy(allBarrel.begin(),allBarrel.end(),back_inserter(allDetLayers));
310  std::copy(allForward.begin(),allForward.end(),back_inserter(allDetLayers));
311 
312 
313 }
const std::vector< DetLayer * > & endcapRPCLayers() const
return the endcap RPC DetLayers, -Z to +Z
const std::vector< DetLayer * > & allCSCLayers() const
return the CSC DetLayers (endcap), -Z to +Z
virtual SubDetector subDetector() const =0
The type of detector (PixelBarrel, PixelEndcap, TIB, TOB, TID, TEC, CSC, DT, RPCBarrel, RPCEndcap)
void addDTLayers(const std::vector< DetLayer * > &dtlayers)
const std::vector< DetLayer * > & backwardRPCLayers() const
return the backward (-Z) RPC DetLayers, inside-out
const std::vector< DetLayer * > & allForwardLayers() const
return all forward (+Z) layers (CSC+RPC), inside-out
const std::vector< DetLayer * > & allDTLayers() const
return the DT DetLayers (barrel), inside-out
virtual const DetLayer * idToLayer(const DetId &detId) const
return the DetLayer which correspond to a certain DetId
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< DetLayer * > & barrelRPCLayers() const
return the barrel RPC DetLayers, inside-out
const std::vector< DetLayer * > & forwardRPCLayers() const
return the forward (+Z) RPC DetLayers, 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
const std::vector< DetLayer * > & allEndcapLayers() const
return all endcap DetLayers (CSC+RPC), -Z to +Z
MuonDetLayerGeometry()
Constructor.
const std::vector< DetLayer * > & allBackwardLayers() const
return all backward (-Z) layers (CSC+RPC), inside-out
Definition: DetId.h:18
const std::vector< DetLayer * > & backwardCSCLayers() const
return the backward (-Z) CSC DetLayers, inside-out
const std::vector< DetLayer * > & allLayers() const
return all layers (DT+CSC+RPC), order: backward, barrel, forward
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)
static const int RPC
Definition: MuonSubdetId.h:14
const std::vector< DetLayer * > & forwardCSCLayers() const
return the forward (+Z) CSC DetLayers, inside-out
static const int DT
Definition: MuonSubdetId.h:12
virtual const BoundCylinder & specificSurface() const GCC11_FINAL
Extension of the interface.
const std::vector< DetLayer * > & allBarrelLayers() const
return all barrel DetLayers (DT+RPC), inside-out
void addCSCLayers(const std::pair< std::vector< DetLayer * >, std::vector< DetLayer * > > &csclayers)
const std::vector< DetLayer * > & allRPCLayers() const
return all RPC DetLayers, order: backward, barrel, forward