00001
00008 #include <RecoMuon/DetLayers/interface/MuonDetLayerGeometry.h>
00009
00010 #include <FWCore/Utilities/interface/Exception.h>
00011 #include <TrackingTools/DetLayers/interface/DetLayer.h>
00012 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
00013 #include <DataFormats/MuonDetId/interface/DTChamberId.h>
00014 #include <DataFormats/MuonDetId/interface/RPCDetId.h>
00015
00016 #include <Utilities/General/interface/precomputed_value_sort.h>
00017 #include <DataFormats/GeometrySurface/interface/GeometricSorting.h>
00018
00019 #include <algorithm>
00020
00021 using namespace std;
00022 using namespace geomsort;
00023
00024 MuonDetLayerGeometry::MuonDetLayerGeometry() {}
00025
00026 MuonDetLayerGeometry::~MuonDetLayerGeometry(){
00027 for(vector<DetLayer*>::const_iterator it = allDetLayers.begin(); it != allDetLayers.end(); ++it)
00028 {
00029 delete *it;
00030 }
00031 }
00032
00033 void MuonDetLayerGeometry::addCSCLayers(pair<vector<DetLayer*>, vector<DetLayer*> > csclayers) {
00034
00035 vector<DetLayer*>::const_iterator it;
00036 for(it=csclayers.first.begin(); it!=csclayers.first.end(); it++) {
00037 cscLayers_fw.push_back(*it);
00038
00039 allForward.push_back(*it);
00040
00041
00042
00043 detLayersMap[ makeDetLayerId(*it) ] = *it;
00044 }
00045
00046 for(it=csclayers.second.begin(); it!=csclayers.second.end(); it++) {
00047 cscLayers_bk.push_back(*it);
00048
00049 allBackward.push_back(*it);
00050
00051
00052
00053 detLayersMap[ makeDetLayerId(*it) ] = *it;
00054 }
00055 }
00056
00057 void MuonDetLayerGeometry::addRPCLayers(vector<DetLayer*> barrelLayers, pair<vector<DetLayer*>, vector<DetLayer*> > endcapLayers) {
00058
00059 vector<DetLayer*>::const_iterator it;
00060
00061 for (it=barrelLayers.begin();it!=barrelLayers.end();it++){
00062 rpcLayers_barrel.push_back(*it);
00063
00064 allBarrel.push_back(*it);
00065
00066
00067 detLayersMap[ makeDetLayerId(*it) ] = *it;
00068 }
00069 for (it=endcapLayers.first.begin(); it!=endcapLayers.first.end(); it++){
00070 rpcLayers_fw.push_back(*it);
00071
00072
00073 allForward.push_back(*it);
00074
00075
00076
00077 detLayersMap[ makeDetLayerId(*it) ] = *it;
00078 }
00079
00080 for (it=endcapLayers.second.begin(); it!=endcapLayers.second.end(); it++){
00081 rpcLayers_bk.push_back(*it);
00082
00083
00084 allBackward.push_back(*it);
00085
00086
00087
00088 detLayersMap[ makeDetLayerId(*it) ] = *it;
00089 }
00090
00091 }
00092
00093 void MuonDetLayerGeometry::addDTLayers(vector<DetLayer*> dtlayers) {
00094
00095 vector<DetLayer*>::const_iterator it;
00096 for(it=dtlayers.begin(); it!=dtlayers.end(); it++) {
00097 dtLayers.push_back(*it);
00098 allBarrel.push_back(*it);
00099
00100
00101 detLayersMap[ makeDetLayerId(*it) ] = *it;
00102 }
00103 }
00104
00105 DetId MuonDetLayerGeometry::makeDetLayerId(const DetLayer* detLayer) const{
00106
00107 if(detLayer->subDetector() == GeomDetEnumerators::CSC){
00108 CSCDetId id( detLayer->basicComponents().front()->geographicalId().rawId() ) ;
00109
00110 if(id.station() == 1 )
00111 {
00112 if(id.ring() == 1 || id.ring() == 4)
00113 return CSCDetId(id.endcap(),1,1,0,0);
00114 else if(id.ring() == 2 || id.ring() == 3)
00115 return CSCDetId(id.endcap(),1,2,0,0);
00116 else
00117 throw cms::Exception("InvalidCSCRing")<<" Invalid CSC Ring: "<<id.ring()<<endl;
00118 }
00119 else
00120 return CSCDetId(id.endcap(),id.station(),0,0,0);
00121
00122 }
00123 else if(detLayer->subDetector() == GeomDetEnumerators::DT){
00124 DTChamberId id( detLayer->basicComponents().front()->geographicalId().rawId() ) ;
00125 return DTChamberId(0,id.station(),0);
00126 }
00127 else if(detLayer->subDetector()== GeomDetEnumerators::RPCBarrel ||
00128 detLayer->subDetector()== GeomDetEnumerators::RPCEndcap){
00129 RPCDetId id( detLayer->basicComponents().front()->geographicalId().rawId());
00130 return RPCDetId(id.region(),0,id.station(),0,id.layer(),0,0);
00131 }
00132 else throw cms::Exception("InvalidModuleIdentification");
00133 }
00134
00135
00136 const vector<DetLayer*>&
00137 MuonDetLayerGeometry::allDTLayers() const {
00138 return dtLayers;
00139 }
00140
00141 const vector<DetLayer*>&
00142 MuonDetLayerGeometry::allCSCLayers() const {
00143 return cscLayers_all;
00144 }
00145
00146
00147 const vector<DetLayer*>&
00148 MuonDetLayerGeometry::forwardCSCLayers() const {
00149 return cscLayers_fw;
00150 }
00151
00152
00153 const vector<DetLayer*>&
00154 MuonDetLayerGeometry::backwardCSCLayers() const {
00155 return cscLayers_bk;
00156 }
00157
00158
00159 const vector<DetLayer*>&
00160 MuonDetLayerGeometry::allRPCLayers() const {
00161 return rpcLayers_all;
00162 }
00163
00164
00165 const vector<DetLayer*>&
00166 MuonDetLayerGeometry::barrelRPCLayers() const {
00167 return rpcLayers_barrel;
00168 }
00169
00170
00171 const vector<DetLayer*>&
00172 MuonDetLayerGeometry::endcapRPCLayers() const {
00173 return rpcLayers_endcap;
00174 }
00175
00176
00177 const vector<DetLayer*>&
00178 MuonDetLayerGeometry::forwardRPCLayers() const {
00179 return rpcLayers_fw;
00180 }
00181
00182
00183 const vector<DetLayer*>&
00184 MuonDetLayerGeometry::backwardRPCLayers() const {
00185 return rpcLayers_bk;
00186 }
00187
00188
00189 const vector<DetLayer*>&
00190 MuonDetLayerGeometry::allLayers() const {
00191 return allDetLayers;
00192 }
00193
00194
00195 const vector<DetLayer*>&
00196 MuonDetLayerGeometry::allBarrelLayers() const {
00197 return allBarrel;
00198 }
00199
00200 const vector<DetLayer*>&
00201 MuonDetLayerGeometry::allEndcapLayers() const {
00202 return allEndcap;
00203 }
00204
00205
00206 const vector<DetLayer*>&
00207 MuonDetLayerGeometry::allForwardLayers() const {
00208 return allForward;
00209 }
00210
00211
00212 const vector<DetLayer*>&
00213 MuonDetLayerGeometry::allBackwardLayers() const {
00214 return allBackward;
00215 }
00216
00217 const DetLayer* MuonDetLayerGeometry::idToLayer(const DetId &detId) const{
00218
00219 DetId id;
00220
00221 if(detId.subdetId() == MuonSubdetId::CSC){
00222 CSCDetId cscId( detId.rawId() );
00223
00224 if(cscId.station() == 1)
00225 {
00226 if(cscId.ring() == 1 || cscId.ring() == 4)
00227 id = CSCDetId(cscId.endcap(),1,1,0,0);
00228 else if(cscId.ring() == 2 || cscId.ring() == 3)
00229 id = CSCDetId(cscId.endcap(),1,2,0,0);
00230 else
00231 throw cms::Exception("InvalidCSCRing")<<" Invalid CSC Ring: "<<cscId.ring()<<endl;
00232 }
00233 else id = CSCDetId(cscId.endcap(),cscId.station(),0,0,0);
00234 }
00235
00236 else if (detId.subdetId() == MuonSubdetId::DT){
00237 DTChamberId dtId( detId.rawId() );
00238 id = DTChamberId(0,dtId.station(),0);
00239 }
00240 else if (detId.subdetId() == MuonSubdetId::RPC){
00241 RPCDetId rpcId(detId.rawId() );
00242 id = RPCDetId(rpcId.region(),0,rpcId.station(),0,rpcId.layer(),0,0);
00243 }
00244
00245 else throw cms::Exception("InvalidSubdetId")<< detId.subdetId();
00246
00247 std::map<DetId,DetLayer*>::const_iterator layer = detLayersMap.find(id);
00248 if (layer == detLayersMap.end()) return 0;
00249 return layer->second;
00250 }
00251
00252
00253
00254
00255 #include <TrackingTools/DetLayers/interface/BarrelDetLayer.h>
00256 struct ExtractBarrelDetLayerR {
00257 typedef Surface::Scalar result_type;
00258 result_type operator()(const DetLayer* p) const {
00259 const BarrelDetLayer * bdl = dynamic_cast<const BarrelDetLayer*>(p);
00260 if (bdl) return bdl->specificSurface().radius();
00261 else return -1.;
00262 }
00263 };
00264
00265 void MuonDetLayerGeometry::sortLayers() {
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276 precomputed_value_sort(allBarrel.begin(), allBarrel.end(), ExtractBarrelDetLayerR());
00277 precomputed_value_sort(allBackward.begin(), allBackward.end(), ExtractAbsZ<DetLayer,float>());
00278 precomputed_value_sort(allForward.begin(), allForward.end(), ExtractAbsZ<DetLayer,float>());
00279
00280
00281
00282
00283 cscLayers_all.reserve(cscLayers_bk.size()+cscLayers_fw.size());
00284 std::copy(cscLayers_bk.begin(),cscLayers_bk.end(),back_inserter(cscLayers_all));
00285 std::reverse(cscLayers_all.begin(),cscLayers_all.end());
00286 std::copy(cscLayers_fw.begin(),cscLayers_fw.end(),back_inserter(cscLayers_all));
00287
00288
00289 rpcLayers_endcap.reserve(rpcLayers_bk.size()+rpcLayers_fw.size());
00290 std::copy(rpcLayers_bk.begin(),rpcLayers_bk.end(),back_inserter(rpcLayers_endcap));
00291 std::reverse(rpcLayers_endcap.begin(),rpcLayers_endcap.end());
00292 std::copy(rpcLayers_fw.begin(),rpcLayers_fw.end(),back_inserter(rpcLayers_endcap));
00293
00294
00295 rpcLayers_all.reserve(rpcLayers_bk.size()+rpcLayers_barrel.size()+rpcLayers_fw.size());
00296 std::copy(rpcLayers_bk.begin(),rpcLayers_bk.end(),back_inserter(rpcLayers_all));
00297 std::reverse(rpcLayers_all.begin(),rpcLayers_all.end());
00298 std::copy(rpcLayers_barrel.begin(),rpcLayers_barrel.end(),back_inserter(rpcLayers_all));
00299 std::copy(rpcLayers_fw.begin(),rpcLayers_fw.end(),back_inserter(rpcLayers_all));
00300
00301
00302 allEndcap.reserve(allBackward.size()+allForward.size());
00303 std::copy(allBackward.begin(),allBackward.end(),back_inserter(allEndcap));
00304 std::reverse(allEndcap.begin(),allEndcap.end());
00305 std::copy(allForward.begin(),allForward.end(),back_inserter(allEndcap));
00306
00307
00308 allDetLayers.reserve(allBackward.size()+allBarrel.size()+allForward.size());
00309 std::copy(allBackward.begin(),allBackward.end(),back_inserter(allDetLayers));
00310 std::reverse(allDetLayers.begin(),allDetLayers.end());
00311 std::copy(allBarrel.begin(),allBarrel.end(),back_inserter(allDetLayers));
00312 std::copy(allForward.begin(),allForward.end(),back_inserter(allDetLayers));
00313
00314
00315 }