CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/RecoMuon/DetLayers/src/MuonCSCDetLayerGeometryBuilder.cc

Go to the documentation of this file.
00001 #include <RecoMuon/DetLayers/src/MuonCSCDetLayerGeometryBuilder.h>
00002 
00003 #include <RecoMuon/DetLayers/interface/MuRingForwardDoubleLayer.h>
00004 #include <RecoMuon/DetLayers/interface/MuDetRing.h>
00005 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
00006 #include <Geometry/CommonDetUnit/interface/GeomDet.h>
00007 
00008 #include <Utilities/General/interface/precomputed_value_sort.h>
00009 #include <Geometry/CommonDetUnit/interface/DetSorting.h>
00010 
00011 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00012 
00013 #include <iostream>
00014 
00015 using namespace std;
00016 
00017 pair<vector<DetLayer*>, vector<DetLayer*> > 
00018 MuonCSCDetLayerGeometryBuilder::buildLayers(const CSCGeometry& geo) {
00019 
00020   vector<DetLayer*> result[2]; // one for each endcap
00021   
00022   for(int i=0; i<2; i++) {        
00023     
00024     int endcap = i+1;
00025     
00026     // ME/1/1a (= station 1, ring 4) and ME/1/1b (= station 1, ring 1)
00027     {
00028       vector<int> rings;
00029       rings.push_back(4);
00030       rings.push_back(1);
00031       
00032       MuRingForwardDoubleLayer* layer = buildLayer(endcap, 1, rings, geo);          
00033       if (layer) result[i].push_back(layer);  
00034     }
00035     
00036     // ME/1/2 and 1/3 (= station 1, ring 2 and 3)
00037     {
00038       vector<int> rings;
00039       rings.push_back(2);
00040       rings.push_back(3);
00041       
00042       MuRingForwardDoubleLayer* layer = buildLayer(endcap, 1, rings, geo);          
00043       if (layer) result[i].push_back(layer);  
00044     }    
00045     
00046     // Stations 2,3,4
00047     for(int station = 2; station <= CSCDetId::maxStationId(); station++) {
00048       vector<int> rings;      
00049       for(int ring = CSCDetId::minRingId(); ring <= CSCDetId::maxRingId(); ring++) {
00050         rings.push_back(ring);
00051       }
00052       MuRingForwardDoubleLayer* layer = buildLayer(endcap, station, rings, geo);          
00053       if (layer) result[i].push_back(layer);
00054     }
00055   }
00056   pair<vector<DetLayer*>, vector<DetLayer*> > res_pair(result[0], result[1]); 
00057   return res_pair;
00058 }
00059 
00060 MuRingForwardDoubleLayer* MuonCSCDetLayerGeometryBuilder::buildLayer(int endcap,
00061                                                                int station,
00062                                                                vector<int>& rings,
00063                                                                const CSCGeometry& geo) {
00064   const std::string metname = "Muon|RecoMuon|RecoMuonDetLayers|MuonCSCDetLayerGeometryBuilder";
00065   MuRingForwardDoubleLayer* result=0;
00066   
00067   vector<const ForwardDetRing*> frontRings, backRings;
00068   
00069   for (vector<int>::iterator ring = rings.begin(); ring!=rings.end(); ring++) {    
00070     vector<const GeomDet*> frontGeomDets, backGeomDets;
00071     for(int chamber = CSCDetId::minChamberId(); chamber <= CSCDetId::maxChamberId(); chamber++) {
00072       CSCDetId detId(endcap, station, (*ring), chamber, 0);
00073       const GeomDet* geomDet = geo.idToDet(detId);
00074       // we sometimes loop over more chambers than there are in ring
00075       bool isInFront = isFront(station, *ring, chamber);
00076       if(geomDet != 0)
00077       {
00078         if(isInFront)
00079         {
00080           frontGeomDets.push_back(geomDet);
00081         }
00082         else
00083         {
00084           backGeomDets.push_back(geomDet);
00085         }
00086         LogTrace(metname) << "get CSC chamber "
00087                           <<  CSCDetId(endcap, station, (*ring), chamber, 0)
00088                           << " at R=" << geomDet->position().perp()
00089                           << ", phi=" << geomDet->position().phi()
00090                           << ", z= " << geomDet->position().z() 
00091                           << " isFront? " << isInFront;
00092       }
00093     }
00094 
00095     if(!backGeomDets.empty())
00096     {
00097       backRings.push_back(makeDetRing(backGeomDets));
00098     }
00099 
00100     if(!frontGeomDets.empty())
00101     {
00102       frontRings.push_back(makeDetRing(frontGeomDets));
00103       assert(!backGeomDets.empty());
00104       float frontz = frontRings[0]->position().z();
00105       float backz  = backRings[0]->position().z();
00106       assert(fabs(frontz) < fabs(backz));
00107     }
00108   }
00109   
00110   // How should they be sorted?
00111   //    precomputed_value_sort(muDetRods.begin(), muDetRods.end(), geomsort::ExtractZ<GeometricSearchDet,float>());
00112   result = new MuRingForwardDoubleLayer(frontRings, backRings);  
00113   LogTrace(metname) << "New MuRingForwardLayer with " << frontRings.size() 
00114                     << " and " << backRings.size()
00115                     << " rings, at Z " << result->position().z()
00116                     << " R1: " << result->specificSurface().innerRadius()
00117                     << " R2: " << result->specificSurface().outerRadius(); 
00118   return result;
00119 }
00120 
00121 
00122 bool MuonCSCDetLayerGeometryBuilder::isFront(int station, int ring, int chamber)
00123 {
00124   bool result = false;
00125   
00126   bool isOverlapping = !(station == 1 && ring == 3);
00127   // not overlapping means back
00128   if(isOverlapping)
00129   {
00130     bool isEven = (chamber%2==0);
00131     // odd chambers are bolted to the iron, which faces
00132     // forward in 1&2, backward in 3&4, so...
00133     result = (station<3) ? isEven : !isEven;
00134   }
00135   return result;
00136 }
00137 
00138 
00139 
00140 MuDetRing * MuonCSCDetLayerGeometryBuilder::makeDetRing(vector<const GeomDet*> & geomDets)
00141 {
00142     const std::string metname = "Muon|RecoMuon|RecoMuonDetLayers|MuonCSCDetLayerGeometryBuilder";
00143 
00144 
00145     precomputed_value_sort(geomDets.begin(), geomDets.end(), geomsort::DetPhi());
00146     MuDetRing * result = new MuDetRing(geomDets);
00147     LogTrace(metname) << "New MuDetRing with " << geomDets.size()
00148                         << " chambers at z="<< result->position().z()
00149                         << " R1: " << result->specificSurface().innerRadius()
00150                         << " R2: " << result->specificSurface().outerRadius();
00151     return result;
00152 }
00153