CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/Geometry/MuonNumbering/src/CSCNumberingScheme.cc

Go to the documentation of this file.
00001 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00002 #include "Geometry/MuonNumbering/interface/CSCNumberingScheme.h"
00003 #include "Geometry/MuonNumbering/interface/MuonBaseNumber.h"
00004 #include "Geometry/MuonNumbering/interface/MuonDDDConstants.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 
00007 #include <iostream>
00008 
00009 //#define LOCAL_DEBUG
00010 
00011 CSCNumberingScheme::CSCNumberingScheme( const MuonDDDConstants& muonConstants ) {
00012   initMe(muonConstants);
00013 }
00014 
00015 CSCNumberingScheme::CSCNumberingScheme( const DDCompactView& cpv )
00016 {
00017   MuonDDDConstants muonConstants(cpv);
00018   initMe(muonConstants);
00019 }
00020 
00021 void CSCNumberingScheme::initMe (  const MuonDDDConstants& muonConstants ) {
00022   int theLevelPart=muonConstants.getValue("level");
00023   theRegionLevel=muonConstants.getValue("me_region")/theLevelPart;
00024   theStationLevel=muonConstants.getValue("me_station")/theLevelPart;
00025   theSubringLevel=muonConstants.getValue("me_subring")/theLevelPart;
00026   theSectorLevel=muonConstants.getValue("me_sector")/theLevelPart;
00027   theRingLevel=muonConstants.getValue("me_ring")/theLevelPart;
00028   theLayerLevel=muonConstants.getValue("me_layer")/theLevelPart;
00029 #ifdef LOCAL_DEBUG
00030   std::cout << "Initialize CSCNumberingScheme" << std::endl;
00031   std::cout << "theRegionLevel " << theRegionLevel <<std::endl;
00032   std::cout << "theStationLevel " << theStationLevel <<std::endl;
00033   std::cout << "theSubringLevel " << theSubringLevel <<std::endl;
00034   std::cout << "theSectorLevel " << theSectorLevel <<std::endl;
00035   std::cout << "theRingLevel " << theRingLevel <<std::endl;
00036   std::cout << "theLayerLevel " << theLayerLevel <<std::endl;
00037 #endif
00038 }
00039 
00040 int CSCNumberingScheme::baseNumberToUnitNumber(const MuonBaseNumber num){
00041 
00042 #ifdef LOCAL_DEBUG
00043   std::cout << "CSCNumbering "<<num.getLevels()<<std::endl;
00044   for (int level=1;level<=num.getLevels();level++) {
00045     std::cout << level << " " << num.getSuperNo(level)
00046          << " " << num.getBaseNo(level) << std::endl;
00047   }
00048 #endif
00049 
00050   int fwbw_id=0;
00051   int station_id=0;
00052   int ring_id=0;
00053   int subring_id=0;
00054   int sector_id=0;
00055   int layer_id=0;
00056 
00057   // Decode endcap levels
00058   // We should be able to work with 6 (layer-level) or 5 (chamber-level)
00059   
00060     for (int level=1;level<=num.getLevels();level++) {
00061 
00062     if (level==theRegionLevel) {
00063       const int copyno=num.getBaseNo(level);
00064       fwbw_id=copyno+1;
00065       LogDebug("CSCNumbering") << "endcap=" << fwbw_id ;
00066 
00067     } else if (level==theStationLevel) {
00068       const int station_tag = num.getSuperNo(level);      
00069       station_id=station_tag;
00070       LogDebug("CSCNumbering")<< "station=" << station_id ;
00071       
00072     } else if (level==theSubringLevel) {
00073       const int copyno=num.getBaseNo(level);
00074       subring_id=copyno+1;
00075       LogDebug("CSCNumbering")<<"subring=" << subring_id ;
00076 
00077     } else if (level==theSectorLevel) {
00078       const int copyno=num.getBaseNo(level);
00079       sector_id=copyno+1;
00080       LogDebug("CSCNumbering")<< "sector=" << sector_id ;
00081 
00082     } else if (level==theLayerLevel) {
00083       const int copyno=num.getBaseNo(level);
00084       layer_id=copyno+1;
00085       LogDebug("CSCNumbering") << "layer=" << layer_id ;
00086 
00087     } else if (level==theRingLevel) {
00088       const int ring_tag = num.getSuperNo(level);      
00089       ring_id=ring_tag;
00090       LogDebug("CSCNumbering") << "ring=" << ring_id ;
00091     }
00092   }      
00093 
00094   // check validity 
00095     
00096   if ((fwbw_id < 1) || (fwbw_id > 2)) {
00097     edm::LogError("CSCNumbering") << "@SUB=CSCNumberingScheme::baseNumberToUnitNumber" << "forward/backward id out of range:" << fwbw_id;
00098   }
00099     
00100   if ((station_id < 1) || (station_id > 4)) {
00101     edm::LogError("CSCNumbering") << "@SUB=CSCNumberingScheme::baseNumberToUnitNumber" << "station id out of range:" << station_id;
00102   }
00103     
00104    if ((ring_id < 1) || (ring_id > 4)) {
00105      edm::LogError("CSCNumbering") << "@SUB=CSCNumberingScheme::baseNumberToUnitNumber" << "ring id out of range:" << ring_id ;
00106    }
00107     
00108   if ((subring_id < 1) || (subring_id > 2)) {
00109     edm::LogError("CSCNumbering") << "@SUB=CSCNumberingScheme::baseNumberToUnitNumber" << "subring id out of range:" << subring_id ;
00110   }
00111     
00112   if ((sector_id < 1) || (sector_id > 36)) {
00113     edm::LogError("CSCNumbering") << "@SUB=CSCNumberingScheme::baseNumberToUnitNumber" << "sector id out of range:" << sector_id ;
00114   }
00115 
00116   // Allow id=0 since that means a chamber    
00117   if ((layer_id < 0) || (layer_id > 6)) {
00118     edm::LogError("CSCNumbering") << "@SUB=CSCNumberingScheme::baseNumberToUnitNumber" << "layer id out of range" << layer_id ;
00119   }
00120     
00121   // find appropriate chamber label
00122     
00123    int chamber_id=chamberIndex(station_id, ring_id,
00124                               subring_id, sector_id);
00125     
00126   // convert into raw id of appropriate DetId
00127     
00128   int intIndex=CSCDetId::rawIdMaker(fwbw_id, station_id, ring_id,
00129                      chamber_id, layer_id);
00130 
00131 #ifdef LOCAL_DEBUG
00132   std::cout << "CSCNumberingScheme : ";
00133   std::cout << " fw/bw " <<  fwbw_id;
00134   std::cout << " station " <<  station_id;
00135   std::cout << " ring " <<  ring_id;
00136   std::cout << " subring " <<  subring_id;
00137   std::cout << " chamber " <<  chamber_id;
00138   std::cout << " sector " <<  sector_id;
00139   std::cout << " layer " <<  layer_id;
00140   std::cout << std::endl;
00141 #endif
00142 
00143   return intIndex;
00144 }
00145 
00146 int CSCNumberingScheme::chamberIndex(int station_id,  
00147            int ring_id, int subring_id, int sector_id) const {
00148 
00149   int chamber_id=0;
00150 
00151   // chamber label is related to sector_id but we need to
00152   // adjust to real hardware labelling
00153   // Tim confirms this works properly according to CMS IN 2000/004 Version 2.5 March 2007.
00154 
00155   if (ring_id == 3) {
00156     chamber_id=sector_id;
00157   } else {
00158     if (subring_id == 1) {
00159       chamber_id=2*sector_id-1;
00160     } else { 
00161       chamber_id=2*sector_id;
00162     }
00163   }
00164 
00165   return chamber_id;
00166 
00167 }