CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/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 << "theRegionLevel " << theRegionLevel <<std::endl;
00031   std::cout << "theStationLevel " << theStationLevel <<std::endl;
00032   std::cout << "theSubringLevel " << theSubringLevel <<std::endl;
00033   std::cout << "theSectorLevel " << theSectorLevel <<std::endl;
00034   std::cout << "theRingLevel " << theRingLevel <<std::endl;
00035   std::cout << "theLayerLevel " << theLayerLevel <<std::endl;
00036 #endif
00037 }
00038 
00039 int CSCNumberingScheme::baseNumberToUnitNumber(const MuonBaseNumber num){
00040 
00041 #ifdef LOCAL_DEBUG
00042   std::cout << "CSCNumbering "<<num.getLevels()<<std::endl;
00043   for (int level=1;level<=num.getLevels();level++) {
00044     std::cout << level << " " << num.getSuperNo(level)
00045          << " " << num.getBaseNo(level) << std::endl;
00046   }
00047 #endif
00048 
00049   int fwbw_id=0;
00050   int station_id=0;
00051   int ring_id=0;
00052   int subring_id=0;
00053   int sector_id=0;
00054   int layer_id=0;
00055 
00056   // Decode endcap levels
00057   // We should be able to work with 6 (layer-level) or 5 (chamber-level)
00058   
00059     for (int level=1;level<=num.getLevels();level++) {
00060 
00061     if (level==theRegionLevel) {
00062       const int copyno=num.getBaseNo(level);
00063       fwbw_id=copyno+1;
00064       LogDebug("CSCNumbering") << "endcap=" << fwbw_id ;
00065 
00066     } else if (level==theStationLevel) {
00067       const int station_tag = num.getSuperNo(level);      
00068       station_id=station_tag;
00069       LogDebug("CSCNumbering")<< "station=" << station_id ;
00070       
00071     } else if (level==theSubringLevel) {
00072       const int copyno=num.getBaseNo(level);
00073       subring_id=copyno+1;
00074       LogDebug("CSCNumbering")<<"subring=" << subring_id ;
00075 
00076     } else if (level==theSectorLevel) {
00077       const int copyno=num.getBaseNo(level);
00078       sector_id=copyno+1;
00079       LogDebug("CSCNumbering")<< "sector=" << sector_id ;
00080 
00081     } else if (level==theLayerLevel) {
00082       const int copyno=num.getBaseNo(level);
00083       layer_id=copyno+1;
00084       LogDebug("CSCNumbering") << "layer=" << layer_id ;
00085 
00086     } else if (level==theRingLevel) {
00087       const int ring_tag = num.getSuperNo(level);      
00088       ring_id=ring_tag;
00089       LogDebug("CSCNumbering") << "ring=" << ring_id ;
00090     }
00091   }      
00092 
00093   // check validity 
00094     
00095   if ((fwbw_id < 1) || (fwbw_id > 2)) {
00096     edm::LogError("CSCNumbering") << "@SUB=CSCNumberingScheme::baseNumberToUnitNumber" << "forward/backward id out of range:" << fwbw_id;
00097   }
00098     
00099   if ((station_id < 1) || (station_id > 4)) {
00100     edm::LogError("CSCNumbering") << "@SUB=CSCNumberingScheme::baseNumberToUnitNumber" << "station id out of range:" << station_id;
00101   }
00102     
00103    if ((ring_id < 1) || (ring_id > 4)) {
00104      edm::LogError("CSCNumbering") << "@SUB=CSCNumberingScheme::baseNumberToUnitNumber" << "ring id out of range:" << ring_id ;
00105    }
00106     
00107   if ((subring_id < 1) || (subring_id > 2)) {
00108     edm::LogError("CSCNumbering") << "@SUB=CSCNumberingScheme::baseNumberToUnitNumber" << "subring id out of range:" << subring_id ;
00109   }
00110     
00111   if ((sector_id < 1) || (sector_id > 36)) {
00112     edm::LogError("CSCNumbering") << "@SUB=CSCNumberingScheme::baseNumberToUnitNumber" << "sector id out of range:" << sector_id ;
00113   }
00114 
00115   // Allow id=0 since that means a chamber    
00116   if ((layer_id < 0) || (layer_id > 6)) {
00117     edm::LogError("CSCNumbering") << "@SUB=CSCNumberingScheme::baseNumberToUnitNumber" << "layer id out of range" << layer_id ;
00118   }
00119     
00120   // find appropriate chamber label
00121     
00122    int chamber_id=chamberIndex(station_id, ring_id,
00123                               subring_id, sector_id);
00124     
00125   // convert into raw id of appropriate DetId
00126     
00127   int intIndex=CSCDetId::rawIdMaker(fwbw_id, station_id, ring_id,
00128                      chamber_id, layer_id);
00129 
00130 #ifdef LOCAL_DEBUG
00131   std::cout << "CSCNumberingScheme : ";
00132   std::cout << " fw/bw " <<  fwbw_id;
00133   std::cout << " station " <<  station_id;
00134   std::cout << " ring " <<  ring_id;
00135   std::cout << " subring " <<  subring_id;
00136   std::cout << " chamber " <<  chamber_id;
00137   std::cout << " sector " <<  sector_id;
00138   std::cout << " layer " <<  layer_id;
00139   std::cout << std::endl;
00140 #endif
00141 
00142   return intIndex;
00143 }
00144 
00145 int CSCNumberingScheme::chamberIndex(int station_id,  
00146            int ring_id, int subring_id, int sector_id) const {
00147 
00148   int chamber_id=0;
00149 
00150   // chamber label is related to sector_id but we need to
00151   // adjust to real hardware labelling
00152   // Tim confirms this works properly according to CMS IN 2000/004 Version 2.5 March 2007.
00153 
00154   if (ring_id == 3) {
00155     chamber_id=sector_id;
00156   } else {
00157     if (subring_id == 1) {
00158       chamber_id=2*sector_id-1;
00159     } else { 
00160       chamber_id=2*sector_id;
00161     }
00162   }
00163 
00164   return chamber_id;
00165 
00166 }