Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:46

0001 #include <DataFormats/MuonDetId/interface/CSCTriggerNumbering.h>
0002 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
0003 #include <FWCore/Utilities/interface/Exception.h>
0004 
0005 int CSCTriggerNumbering::ringFromTriggerLabels(int station, int triggerCSCID) {
0006   if (station < CSCDetId::minStationId() || station > CSCDetId::maxStationId() || triggerCSCID < MIN_CSCID ||
0007       triggerCSCID > MAX_CSCID)
0008     throw cms::Exception("CSCTriggerNumbering::InvalidInput")
0009         << "CSCTriggerNumbering::ringFromTriggerLabels():"
0010         << " Station: " << station << " TriggerCSCID: " << triggerCSCID << " is not a valid set of labels."
0011         << " Cannot Convert!!";
0012 
0013   int ring = 0;
0014 
0015   if (station == 1)
0016     if (triggerCSCID <= 3)
0017       ring = 1;
0018     else if (triggerCSCID <= 6)
0019       ring = 2;
0020     else
0021       ring = 3;
0022   else if (triggerCSCID <= 3)
0023     ring = 1;
0024   else
0025     ring = 2;
0026 
0027   return ring;
0028 }
0029 
0030 int CSCTriggerNumbering::chamberFromTriggerLabels(int TriggerSector,
0031                                                   int TriggerSubSector,
0032                                                   int station,
0033                                                   int TriggerCSCID) {
0034   if (TriggerSector < MIN_TRIGSECTOR || TriggerSector > MAX_TRIGSECTOR || TriggerSubSector < MIN_TRIGSUBSECTOR ||
0035       TriggerSubSector > MAX_TRIGSUBSECTOR || station < CSCDetId::minStationId() ||
0036       station > CSCDetId::maxStationId() || TriggerCSCID < MIN_CSCID || TriggerCSCID > MAX_CSCID)
0037     throw cms::Exception("CSCTriggerNumbering::InvalidInput")
0038         << "CSCTriggerNumbering::chamberFromTriggerLabels():"
0039         << " Trigger Sector: " << TriggerSector << " Trigger SubSector: " << TriggerSubSector << " Station: " << station
0040         << " TriggerCSCID: " << TriggerCSCID << " is not a valid set of labels."
0041         << " Cannot Convert!!";
0042 
0043   int chamber = 0;
0044   int realsubsector = (TriggerSubSector + 2 * (TriggerSector - 1)) % 12 + 1;  // station 1 only
0045 
0046   if (station != 1)
0047     if (TriggerCSCID <= 3)
0048       // Derived from CMS Note: CMS IN 2000/04 ver 2.1 Oct/2005
0049       // As far as I know this is reality.
0050       chamber = (TriggerCSCID + 3 * (TriggerSector - 1)) % 18 + 1;
0051 
0052     else
0053       chamber = (TriggerCSCID + 6 * (TriggerSector - 1) - 2) % 36 + 1;
0054   else if (TriggerCSCID <= 3)
0055     chamber = (TriggerCSCID + 3 * (realsubsector - 1) + 34) % 36 + 1;
0056   else if (TriggerCSCID <= 6)
0057     chamber = (TriggerCSCID + 3 * (realsubsector - 1) + 31) % 36 + 1;
0058   else
0059     chamber = (TriggerCSCID + 3 * (realsubsector - 1) + 28) % 36 + 1;
0060 
0061   return chamber;
0062 }
0063 
0064 int CSCTriggerNumbering::sectorFromTriggerLabels(int TriggerSector, int TriggerSubSector, int station) {
0065   if (TriggerSector < MIN_TRIGSECTOR || TriggerSector > MAX_TRIGSECTOR || TriggerSubSector < MIN_TRIGSUBSECTOR ||
0066       TriggerSubSector > MAX_TRIGSUBSECTOR || station < CSCDetId::minStationId() || station > CSCDetId::maxStationId())
0067     throw cms::Exception("CSCTriggerNumbering::InvalidInput")
0068         << "CSCTriggerNumbering::sectorFromTriggerLabels():"
0069         << " Trigger Sector: " << TriggerSector << " Trigger SubSector: " << TriggerSubSector << " Station: " << station
0070         << " is not a valid set of labels."
0071         << " Cannot Convert!!";
0072 
0073   return ((station == 1) ? ((TriggerSubSector + 2 * (TriggerSector - 1)) % 12 + 1) : TriggerSector);
0074 }
0075 
0076 int CSCTriggerNumbering::triggerSectorFromLabels(int station, int ring, int chamber) {
0077   if (station < CSCDetId::minStationId() || station > CSCDetId::maxStationId() || ring < CSCDetId::minRingId() ||
0078       ring > CSCDetId::maxRingId() || chamber < CSCDetId::minChamberId() || chamber > CSCDetId::maxChamberId())
0079     throw cms::Exception("CSCTriggerNumbering::InvalidInput")
0080         << "CSCTriggerNumbering::triggerSectorFromLabels():"
0081         << " Station: " << station << " Ring: " << ring << " Chamber: " << chamber << " is not a valid set of labels."
0082         << " Cannot Convert!!";
0083 
0084   int result;
0085   // This version 16-Nov-99 ptc to match simplified chamber labelling for cms116
0086   //@@ REQUIRES UPDATE TO 2005 REALITY, ONCE I UNDERSTAND WHAT THAT IS
0087   // UPDATED - LGRAY Feb 2006
0088 
0089   if (station > 1 && ring > 1) {
0090     result = ((static_cast<unsigned>(chamber - 3) & 0x7f) / 6) + 1;  // ch 3-8->1, 9-14->2, ... 1,2 -> 6
0091   } else {
0092     result = (station != 1) ? ((static_cast<unsigned>(chamber - 2) & 0x1f) / 3) + 1 :  // ch 2-4-> 1, 5-7->2, ...
0093                  ((static_cast<unsigned>(chamber - 3) & 0x7f) / 6) + 1;
0094   }
0095 
0096   // Max sector is 6, some calculations give a value greater than six but this is expected
0097   // and delt with.
0098   return (result <= 6) ? result : 6;
0099 }
0100 
0101 int CSCTriggerNumbering::triggerSectorFromLabels(CSCDetId id) {
0102   return triggerSectorFromLabels(id.station(), id.ring(), id.chamber());
0103 }
0104 
0105 int CSCTriggerNumbering::triggerSubSectorFromLabels(int station, int chamber) {
0106   if (station < CSCDetId::minStationId() || station > CSCDetId::maxStationId() || chamber < CSCDetId::minChamberId() ||
0107       chamber > CSCDetId::maxChamberId())
0108     throw cms::Exception("CSCTriggerNumbering::InvalidInput")
0109         << "CSCTriggerNumbering::triggerSectorFromLabels():"
0110         << " Station: " << station << " Chamber: " << chamber << " is not a valid set of labels."
0111         << " Cannot Convert!!";
0112 
0113   if (station != 1)
0114     return 0;  // only station one has subsectors
0115 
0116   switch (chamber)  // first make things easier to deal with
0117   {
0118     case 1:
0119       chamber = 36;
0120       break;
0121     case 2:
0122       chamber = 35;
0123       break;
0124     default:
0125       chamber -= 2;
0126   }
0127 
0128   chamber = ((chamber - 1) % 6) + 1;  // renumber all chambers to 1-6
0129 
0130   return ((chamber - 1) / 3) + 1;  // [1,3] -> 1 , [4,6]->2
0131 }
0132 
0133 int CSCTriggerNumbering::triggerSubSectorFromLabels(CSCDetId id) {
0134   return triggerSubSectorFromLabels(id.station(), id.chamber());
0135 }
0136 
0137 int CSCTriggerNumbering::triggerCscIdFromLabels(int station, int ring, int chamber)  // updated to 2005
0138 {
0139   if (station < CSCDetId::minStationId() || station > CSCDetId::maxStationId() || ring < CSCDetId::minRingId() ||
0140       ring > CSCDetId::maxRingId() || chamber < CSCDetId::minChamberId() || chamber > CSCDetId::maxChamberId())
0141     throw cms::Exception("CSCTriggerNumbering::InvalidInput")
0142         << "CSCTriggerNumbering::triggerSectorFromLabels():"
0143         << " Station: " << station << " Ring: " << ring << " Chamber: " << chamber << " is not a valid set of labels."
0144         << " Cannot Convert!!";
0145 
0146   int result;
0147 
0148   if (station == 1) {
0149     result = (chamber) % 3 + 1;  // 1,2,3
0150     switch (ring) {
0151       case 1:
0152         break;
0153       case 2:
0154         result += 3;  // 4,5,6
0155         break;
0156       case 3:
0157         result += 6;  // 7,8,9
0158         break;
0159     }
0160   } else {
0161     if (ring == 1) {
0162       result = (chamber + 1) % 3 + 1;  // 1,2,3
0163     } else {
0164       result = (chamber + 3) % 6 + 4;  // 4,5,6,7,8,9
0165     }
0166   }
0167   return result;
0168 }
0169 
0170 int CSCTriggerNumbering::triggerCscIdFromLabels(CSCDetId id) {
0171   return triggerCscIdFromLabels(id.station(), id.ring(), id.chamber());
0172 }