00001 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
00002 #include <FWCore/Utilities/interface/Exception.h>
00003 #include <iostream>
00004
00005 CSCDetId::CSCDetId():DetId(DetId::Muon, MuonSubdetId::CSC){}
00006
00007
00008 CSCDetId::CSCDetId(uint32_t id):DetId(id) {
00009 if (det()!=DetId::Muon || subdetId()!=MuonSubdetId::CSC) {
00010 throw cms::Exception("InvalidDetId") << "CSCDetId ctor:"
00011 << " det: " << det()
00012 << " subdet: " << subdetId()
00013 << " is not a valid CSC id";
00014 }
00015 }
00016
00017 CSCDetId::CSCDetId(DetId id):DetId(id) {
00018 if (det()!=DetId::Muon || subdetId()!=MuonSubdetId::CSC) {
00019 throw cms::Exception("InvalidDetId") << "CSCDetId ctor:"
00020 << " det: " << det()
00021 << " subdet: " << subdetId()
00022 << " is not a valid CSC id";
00023 }
00024 }
00025
00026 CSCDetId::CSCDetId( int iendcap, int istation, int iring, int ichamber,
00027 int ilayer ) :
00028 DetId(DetId::Muon, MuonSubdetId::CSC)
00029 {
00030 if (iendcap < 0 || iendcap > MAX_ENDCAP ||
00031 istation < 0 || istation > MAX_STATION ||
00032 iring < 0 || iring > MAX_RING ||
00033 ichamber < 0 || ichamber > MAX_CHAMBER ||
00034 ilayer < 0 || ilayer > MAX_LAYER ) {
00035 throw cms::Exception("InvalidDetId") << "CSCDetId ctor:"
00036 << " Invalid parameters: "
00037 << " E:"<< iendcap
00038 << " S:"<< istation
00039 << " R:"<< iring
00040 << " C:"<< ichamber
00041 << " L:"<< ilayer
00042 << std::endl;
00043 }
00044 id_ |= init(iendcap, istation, iring, ichamber, ilayer);
00045 }
00046
00047 int CSCDetId::triggerSector() const
00048 {
00049
00050
00051 int result;
00052 int ring = this->ring();
00053 int station = this->station();
00054 int chamber = this->chamber();
00055
00056 if(station > 1 && ring > 1 ) {
00057 result = ((static_cast<unsigned>(chamber-3) & 0x7f) / 6) + 1;
00058 }
00059 else {
00060 result = (station != 1) ? ((static_cast<unsigned>(chamber-2) & 0x1f) / 3) + 1 :
00061 ((static_cast<unsigned>(chamber-3) & 0x7f) / 6) + 1;
00062 }
00063
00064 return (result <= 6) ? result : 6;
00065 }
00066
00067 int CSCDetId::triggerCscId() const
00068 {
00069
00070
00071 int result;
00072 int ring = this->ring();
00073 int station = this->station();
00074 int chamber = this->chamber();
00075
00076 if( station == 1 ) {
00077 result = (chamber) % 3 + 1;
00078 switch (ring) {
00079 case 1:
00080 break;
00081 case 2:
00082 result += 3;
00083 break;
00084 case 3:
00085 result += 6;
00086 break;
00087 }
00088 }
00089 else {
00090 if( ring == 1 ) {
00091 result = (chamber+1) % 3 + 1;
00092 }
00093 else {
00094 result = (chamber+3) % 6 + 4;
00095 }
00096 }
00097 return result;
00098 }
00099
00100 unsigned short CSCDetId::iChamberType( unsigned short istation, unsigned short iring ) {
00101 int i = 2 * istation + iring;
00102 if ( istation == 1 ) {
00103 --i;
00104 if ( i > 4 ) i = 1;
00105 }
00106 return i;
00107 }
00108
00109
00110 std::ostream& operator<<( std::ostream& os, const CSCDetId& id )
00111 {
00112
00113
00114 os << " E:" << id.endcap()
00115 << " S:" << id.station()
00116 << " R:" << id.ring()
00117 << " C:" << id.chamber()
00118 << " L:" << id.layer();
00119 return os;
00120 }
00121