CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DataFormats/MuonDetId/src/CSCTriggerNumbering.cc

Go to the documentation of this file.
00001 #include <DataFormats/MuonDetId/interface/CSCTriggerNumbering.h>
00002 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
00003 #include <FWCore/Utilities/interface/Exception.h>
00004 
00005 int CSCTriggerNumbering::ringFromTriggerLabels(int station, int triggerCSCID)
00006 {
00007   if(station      < CSCDetId::minStationId() || station      > CSCDetId::maxStationId() ||
00008      triggerCSCID < MIN_CSCID                || triggerCSCID > MAX_CSCID)
00009     throw cms::Exception("CSCTriggerNumbering::InvalidInput") << "CSCTriggerNumbering::ringFromTriggerLabels():"
00010                                                               << " Station: " << station
00011                                                               << " TriggerCSCID: " << triggerCSCID
00012                                                               << " is not a valid set of labels."
00013                                                               << " Cannot Convert!!";
00014 
00015   int ring = 0;
00016 
00017   if(station == 1)
00018     if(triggerCSCID <= 3)
00019       ring = 1; 
00020     else if(triggerCSCID <= 6)
00021       ring = 2;
00022     else
00023       ring = 3;
00024   else
00025     if(triggerCSCID <= 3)
00026       ring = 1;
00027     else 
00028       ring = 2;
00029   
00030   return ring;  
00031 }
00032 
00033 int CSCTriggerNumbering::chamberFromTriggerLabels(int TriggerSector, int TriggerSubSector, int station, int TriggerCSCID)
00034 {
00035   if(TriggerSector    < MIN_TRIGSECTOR           || TriggerSector    > MAX_TRIGSECTOR           ||
00036      TriggerSubSector < MIN_TRIGSUBSECTOR        || TriggerSubSector > MAX_TRIGSUBSECTOR        ||
00037      station          < CSCDetId::minStationId() || station          > CSCDetId::maxStationId() ||
00038      TriggerCSCID     < MIN_CSCID                || TriggerCSCID     > MAX_CSCID)
00039     throw cms::Exception("CSCTriggerNumbering::InvalidInput") << "CSCTriggerNumbering::chamberFromTriggerLabels():"
00040                                                               << " Trigger Sector: " << TriggerSector 
00041                                                               << " Trigger SubSector: " << TriggerSubSector
00042                                                               << " Station: " << station
00043                                                               << " TriggerCSCID: " << TriggerCSCID
00044                                                               << " is not a valid set of labels."
00045                                                               << " Cannot Convert!!";
00046     
00047 
00048   int chamber = 0;
00049   int realsubsector = (TriggerSubSector + 2*(TriggerSector - 1))%12 + 1; // station 1 only
00050 
00051   if(station != 1)
00052     if(TriggerCSCID <= 3)
00053       chamber = (TriggerCSCID + 3*(TriggerSector - 1))%18 + 1; // Derived from CMS Note: CMS IN 2000/04 ver 2.1 Oct/2005
00054                                                                // As far as I know this is reality.
00055     else
00056       chamber = (TriggerCSCID + 6*(TriggerSector - 1) - 2)%36 + 1;
00057   else
00058     if(TriggerCSCID <= 3)
00059       chamber = (TriggerCSCID + 3*(realsubsector - 1)+34)%36 + 1;
00060     else if(TriggerCSCID <= 6)
00061       chamber = (TriggerCSCID + 3*(realsubsector - 1)+31)%36 + 1;
00062     else
00063       chamber = (TriggerCSCID + 3*(realsubsector - 1)+28)%36 + 1;
00064 
00065   return chamber;
00066 }
00067 
00068 int CSCTriggerNumbering::sectorFromTriggerLabels(int TriggerSector, int TriggerSubSector, int station)
00069 {
00070   if(TriggerSector    < MIN_TRIGSECTOR           || TriggerSector    > MAX_TRIGSECTOR           ||
00071      TriggerSubSector < MIN_TRIGSUBSECTOR        || TriggerSubSector > MAX_TRIGSUBSECTOR        ||
00072      station          < CSCDetId::minStationId() || station          > CSCDetId::maxStationId())
00073     throw cms::Exception("CSCTriggerNumbering::InvalidInput") << "CSCTriggerNumbering::sectorFromTriggerLabels():"
00074                                                               << " Trigger Sector: " << TriggerSector 
00075                                                               << " Trigger SubSector: " << TriggerSubSector
00076                                                               << " Station: " << station
00077                                                               << " is not a valid set of labels."
00078                                                               << " Cannot Convert!!";
00079 
00080   return ((station == 1) ? ((TriggerSubSector + 2*(TriggerSector - 1))%12 + 1) : TriggerSector);
00081 }
00082 
00083 int CSCTriggerNumbering::triggerSectorFromLabels(int station, int ring, int chamber)
00084 {
00085   if(station < CSCDetId::minStationId() || station > CSCDetId::maxStationId() ||
00086      ring    < CSCDetId::minRingId()    || ring    > CSCDetId::maxRingId()    ||
00087      chamber < CSCDetId::minChamberId() || chamber > CSCDetId::maxChamberId())
00088     throw cms::Exception("CSCTriggerNumbering::InvalidInput") << "CSCTriggerNumbering::triggerSectorFromLabels():"
00089                                                               << " Station: " << station
00090                                                               << " Ring: " << ring
00091                                                               << " Chamber: " << chamber
00092                                                               << " is not a valid set of labels."
00093                                                               << " Cannot Convert!!";
00094 
00095 
00096   int result;
00097   // This version 16-Nov-99 ptc to match simplified chamber labelling for cms116
00098   //@@ REQUIRES UPDATE TO 2005 REALITY, ONCE I UNDERSTAND WHAT THAT IS
00099   // UPDATED - LGRAY Feb 2006
00100   
00101   if(station > 1 && ring > 1 ) {
00102     result = ((static_cast<unsigned>(chamber-3) & 0x7f) / 6) + 1; // ch 3-8->1, 9-14->2, ... 1,2 -> 6
00103   }
00104   else {
00105     result =  (station != 1) ? ((static_cast<unsigned>(chamber-2) & 0x1f) / 3) + 1 : // ch 2-4-> 1, 5-7->2, ...
00106               ((static_cast<unsigned>(chamber-3) & 0x7f) / 6) + 1;
00107   }
00108 
00109   return (result <= 6) ? result : 6; // Max sector is 6, some calculations give a value greater than six but this is expected
00110                                      // and delt with.
00111 }
00112 
00113 int CSCTriggerNumbering::triggerSectorFromLabels(CSCDetId id)
00114 {
00115   return triggerSectorFromLabels(id.station(),id.ring(),id.chamber());
00116 }
00117 
00118 int CSCTriggerNumbering::triggerSubSectorFromLabels(int station, int chamber)
00119 {
00120   if(station < CSCDetId::minStationId() || station > CSCDetId::maxStationId() ||
00121      chamber < CSCDetId::minChamberId() || chamber > CSCDetId::maxChamberId())
00122     throw cms::Exception("CSCTriggerNumbering::InvalidInput") << "CSCTriggerNumbering::triggerSectorFromLabels():"
00123                                                               << " Station: " << station
00124                                                               << " Chamber: " << chamber
00125                                                               << " is not a valid set of labels."
00126                                                               << " Cannot Convert!!";
00127 
00128   if(station != 1) return 0; // only station one has subsectors
00129 
00130   switch(chamber) // first make things easier to deal with
00131     {
00132     case 1:
00133       chamber = 36;
00134       break;
00135     case 2:
00136       chamber = 35;
00137       break;
00138     default:
00139       chamber -= 2;
00140     }
00141 
00142   chamber = ((chamber-1)%6) + 1; // renumber all chambers to 1-6
00143 
00144   return ((chamber-1) / 3) + 1; // [1,3] -> 1 , [4,6]->2
00145 }
00146 
00147 int CSCTriggerNumbering::triggerSubSectorFromLabels(CSCDetId id)
00148 {
00149   return triggerSubSectorFromLabels(id.station(),id.chamber());
00150 }
00151 
00152 int CSCTriggerNumbering::triggerCscIdFromLabels(int station, int ring, int chamber) // updated to 2005
00153 {
00154   if(station < CSCDetId::minStationId() || station > CSCDetId::maxStationId() ||
00155      ring    < CSCDetId::minRingId()    || ring    > CSCDetId::maxRingId()    ||
00156      chamber < CSCDetId::minChamberId() || chamber > CSCDetId::maxChamberId())
00157     throw cms::Exception("CSCTriggerNumbering::InvalidInput") << "CSCTriggerNumbering::triggerSectorFromLabels():"
00158                                                               << " Station: " << station
00159                                                               << " Ring: " << ring
00160                                                               << " Chamber: " << chamber
00161                                                               << " is not a valid set of labels."
00162                                                               << " Cannot Convert!!";
00163 
00164   int result;
00165 
00166   if( station == 1 ) {
00167     result = (chamber) % 3 + 1; // 1,2,3
00168     switch (ring) {
00169     case 1:
00170       break;
00171     case 2:
00172       result += 3; // 4,5,6
00173       break;
00174     case 3:
00175       result += 6; // 7,8,9
00176       break;
00177     }
00178   }
00179   else {
00180     if( ring == 1 ) {
00181       result = (chamber+1) % 3 + 1; // 1,2,3
00182     }
00183     else {
00184       result = (chamber+3) % 6 + 4; // 4,5,6,7,8,9
00185     }
00186   }
00187   return result;
00188 }
00189 
00190 int CSCTriggerNumbering::triggerCscIdFromLabels(CSCDetId id)
00191 {
00192   return triggerCscIdFromLabels(id.station(),id.ring(),id.chamber());
00193 }