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