CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/Geometry/MuonNumbering/src/DTNumberingScheme.cc

Go to the documentation of this file.
00001 #include "Geometry/MuonNumbering/interface/DTNumberingScheme.h"
00002 #include "DataFormats/MuonDetId/interface/DTWireId.h"
00003 #include "Geometry/MuonNumbering/interface/MuonBaseNumber.h"
00004 #include "Geometry/MuonNumbering/interface/MuonDDDConstants.h"
00005 #include <iostream>
00006 
00007 //#define LOCAL_DEBUG
00008 
00009 DTNumberingScheme::DTNumberingScheme( const MuonDDDConstants& muonConstants ) {
00010   initMe(muonConstants);
00011 }
00012 
00013 DTNumberingScheme::DTNumberingScheme( const DDCompactView& cpv ) {
00014   MuonDDDConstants muonConstants(cpv);
00015   initMe(muonConstants);
00016 }
00017 
00018 void DTNumberingScheme::initMe ( const MuonDDDConstants& muonConstants ) {
00019   int theLevelPart=muonConstants.getValue("level");
00020   theRegionLevel=muonConstants.getValue("mb_region")/theLevelPart;
00021   theWheelLevel=muonConstants.getValue("mb_wheel")/theLevelPart;
00022   theStationLevel=muonConstants.getValue("mb_station")/theLevelPart;
00023   theSuperLayerLevel=muonConstants.getValue("mb_superlayer")/theLevelPart;
00024   theLayerLevel=muonConstants.getValue("mb_layer")/theLevelPart;
00025   theWireLevel=muonConstants.getValue("mb_wire")/theLevelPart;
00026 #ifdef LOCAL_DEBUG
00027   std::cout << "Initialize DTNumberingScheme" << std::endl;
00028   std::cout << "theRegionLevel " << theRegionLevel <<std::endl;
00029   std::cout << "theWheelLevel " << theWheelLevel <<std::endl;
00030   std::cout << "theStationLevel " << theStationLevel <<std::endl;
00031   std::cout << "theSuperLayerLevel " << theSuperLayerLevel <<std::endl;
00032   std::cout << "theLayerLevel " << theLayerLevel <<std::endl;
00033   std::cout << "theWireLevel " << theWireLevel <<std::endl;
00034 #endif
00035 
00036 }
00037 
00038 int DTNumberingScheme::baseNumberToUnitNumber(const MuonBaseNumber num){
00039   
00040 #ifdef LOCAL_DEBUG
00041   std::cout << "DTNumbering "<<num.getLevels()<<std::endl;
00042   for (int level=1;level<=num.getLevels();level++) {
00043     std::cout << level << " " << num.getSuperNo(level)
00044               << " " << num.getBaseNo(level) << std::endl;
00045   }
00046 #endif
00047   if (num.getLevels()!=theWireLevel) {
00048     std::cout << "DTNS::BNToUN "
00049               << "BaseNumber has " << num.getLevels() << " levels,"
00050               << "need "<<theWireLevel<<std::endl;
00051     return 0;
00052   }
00053   
00054 
00055 //   // Meaningful ranges are enforced by DTWireId, (which
00056 //   // however allows for 0 in wire, layer, superlayer!!!)
00057 // 
00058 //   if ((wire_id < 1) || (wire_id > 100)) {
00059 //     std::cout << "DTNumberingScheme: ";
00060 //     std::cout << "wire id out of range: ";
00061 //     std::cout << wire_id <<std::endl;
00062 //   }
00063     
00064 //   if ((layer_id < 1) || (layer_id > 4)) {
00065 //     std::cout << "DTNumberingScheme: ";
00066 //     std::cout << "layer id out of range: ";
00067 //     std::cout << layer_id <<std::endl;
00068 //   }
00069     
00070 //   if ((superlayer_id < 1) || (superlayer_id > 3)) {
00071 //     std::cout << "DTNumberingScheme: ";
00072 //     std::cout << "super-layer id out of range: ";
00073 //     std::cout << superlayer_id <<std::endl;
00074 //   }
00075 
00076 
00077   return getDetId(num);
00078 }
00079 
00080 int DTNumberingScheme::getDetId(const MuonBaseNumber num) const {
00081   
00082   int wire_id=0;
00083   int layer_id=0;
00084   int superlayer_id=0;
00085   int sector_id=0;
00086   int station_id=0;
00087   int wheel_id=0;
00088 
00089   //decode significant barrel levels
00090   decode(num,
00091          wire_id,
00092          layer_id,
00093          superlayer_id,
00094          sector_id,
00095          station_id,
00096          wheel_id);
00097   
00098 // These ranges are enforced by DTWireId
00099 //   if ((sector_id < 1) || (sector_id > 14)) {
00100 //     std::cout << "DTNumberingScheme: ";
00101 //     std::cout << "sector id out of range: ";
00102 //     std::cout << sector_id <<std::endl;
00103 //   }
00104     
00105 //   if ((station_id < 1) || (station_id > 4)) {
00106 //     std::cout << "DTNumberingScheme: ";
00107 //     std::cout << "station id out of range: ";
00108 //     std::cout << station_id <<std::endl;
00109 //   }
00110     
00111 //   if ((wheel_id < -2) || (wheel_id > 2)) {
00112 //     std::cout << "DTNumberingScheme: ";
00113 //     std::cout << "wheel id out of range: ";
00114 //     std::cout << wheel_id <<std::endl;
00115 //   }
00116     
00117   DTWireId id(wheel_id,station_id,sector_id,superlayer_id,layer_id,wire_id);
00118   
00119 #ifdef LOCAL_DEBUG
00120   std::cout << "DTNumberingScheme: " << id << std::endl;
00121 #endif
00122   
00123   return id.rawId();
00124 }
00125 
00126 void DTNumberingScheme::decode(const MuonBaseNumber& num,
00127                                int& wire_id,
00128                                int& layer_id,
00129                                int& superlayer_id,
00130                                int& sector_id,
00131                                int& station_id,
00132                                int& wheel_id) const {
00133   for (int level=1;level<=num.getLevels();level++) {
00134 
00135     //decode
00136     if (level==theWheelLevel) {
00137       const int copyno=num.getBaseNo(level);      
00138       wheel_id=copyno-2;
00139 
00140     } else if (level==theStationLevel) {
00141       const int station_tag = num.getSuperNo(level);
00142       const int copyno = num.getBaseNo(level);
00143       station_id=station_tag;
00144       sector_id=copyno+1;   
00145 
00146     } else if (level==theSuperLayerLevel) {
00147       const int copyno = num.getBaseNo(level);
00148       superlayer_id = copyno + 1;
00149 
00150     } else if (level==theLayerLevel) {
00151       const int copyno = num.getBaseNo(level);
00152       layer_id=copyno+1;
00153 
00154     } else if (level==theWireLevel) {
00155       const int copyno = num.getBaseNo(level);
00156       wire_id = copyno+1;
00157     }
00158   }
00159 }