Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:15

0001 #include "DataFormats/EcalDetId/interface/EcalElectronicsId.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 
0004 #include <ostream>
0005 
0006 EcalElectronicsId::EcalElectronicsId() { EcalElectronicsId_ = 0xFFFFFFFFu; }
0007 
0008 EcalElectronicsId::EcalElectronicsId(uint32_t id) { EcalElectronicsId_ = id; }
0009 
0010 EcalElectronicsId::EcalElectronicsId(int dccid, int towerid, int stripid, int xtalid) {
0011   if ((dccid < MIN_DCCID) || (dccid > MAX_DCCID) || (towerid < MIN_TOWERID) || (towerid > MAX_TOWERID) ||
0012       (stripid < MIN_STRIPID) || (stripid > MAX_STRIPID) || (xtalid < MIN_XTALID) || (xtalid > MAX_XTALID))
0013     throw cms::Exception("InvalidDetId")
0014         << "EcalElectronicsId:  Cannot create object.  Indexes out of bounds. Dcc tower strip xtal " << dccid << " "
0015         << towerid << " " << stripid << " " << xtalid << ".";
0016   EcalElectronicsId_ = (xtalid & 0x7) | ((stripid & 0x7) << 3) | ((towerid & 0x7F) << 6) | ((dccid & 0x7F) << 13);
0017 }
0018 
0019 EcalSubdetector EcalElectronicsId::subdet() const {
0020   int dcc = dccId();
0021   if ((dcc >= MIN_DCCID_EBM && dcc <= MAX_DCCID_EBM) || (dcc >= MIN_DCCID_EBP && dcc <= MAX_DCCID_EBP))
0022     return EcalBarrel;
0023   else
0024     return EcalEndcap;
0025 }
0026 
0027 int EcalElectronicsId::zside() const {
0028   int dcc = dccId();
0029   if ((dcc >= MIN_DCCID_EEM && dcc <= MAX_DCCID_EEM))
0030     return -1;
0031   if ((dcc >= MIN_DCCID_EBM && dcc <= MAX_DCCID_EBM))
0032     return -1;
0033   if ((dcc >= MIN_DCCID_EEP && dcc <= MAX_DCCID_EEP))
0034     return +1;
0035   if ((dcc >= MIN_DCCID_EBP && dcc <= MAX_DCCID_EBP))
0036     return +1;
0037   return 0;
0038 }
0039 
0040 static int EEQuadrant(int dcc, int dcc_channel) {
0041   // Q1 = EE+N or EE-F, Top
0042   // Q2 = EE+F or EE-N, Top
0043   // Q3 = EE+F or EE-N, Bottom
0044   // Q4 = EE+N or EE-F, Bottom
0045   //  (local notation)
0046   // in Q1-Q3 and in Q2-Q4, the relation between strip#, channel# and xtal_id
0047   // is the same
0048   int q = -1;
0049   if ((dcc == EcalElectronicsId::DCC_EEP + 1) || (dcc == EcalElectronicsId::DCC_EEP + 2) ||
0050       (dcc == EcalElectronicsId::DCC_EEP && dcc_channel <= EcalElectronicsId::kDCCChannelBoundary) ||
0051       (dcc == EcalElectronicsId::DCC_EEM + 3) || (dcc == EcalElectronicsId::DCC_EEM + 4) ||
0052       (dcc == EcalElectronicsId::DCC_EEM + 5 && dcc_channel <= EcalElectronicsId::kDCCChannelBoundary))
0053     q = 1;
0054   else if ((dcc == EcalElectronicsId::DCC_EEP + 3) || (dcc == EcalElectronicsId::DCC_EEP + 4) ||
0055            (dcc == EcalElectronicsId::DCC_EEP + 5 && dcc_channel <= EcalElectronicsId::kDCCChannelBoundary) ||
0056            (dcc == EcalElectronicsId::DCC_EEM && dcc_channel <= EcalElectronicsId::kDCCChannelBoundary) ||
0057            (dcc == EcalElectronicsId::DCC_EEM + 1) || (dcc == EcalElectronicsId::DCC_EEM + 2))
0058     q = 2;
0059   else if ((dcc == EcalElectronicsId::DCC_EEP + 6) ||
0060            (dcc == EcalElectronicsId::DCC_EEP + 5 && dcc_channel > EcalElectronicsId::kDCCChannelBoundary) ||
0061            (dcc == EcalElectronicsId::DCC_EEP + 7 && dcc_channel > EcalElectronicsId::kDCCChannelBoundary) ||
0062            (dcc == EcalElectronicsId::DCC_EEM && dcc_channel > EcalElectronicsId::kDCCChannelBoundary) ||
0063            (dcc == EcalElectronicsId::DCC_EEM + 8) ||
0064            (dcc == EcalElectronicsId::DCC_EEM + 7 && dcc_channel > EcalElectronicsId::kDCCChannelBoundary))
0065     q = 3;
0066   else
0067     q = 4;
0068   return q;
0069 }
0070 
0071 int EcalElectronicsId::channelId() const {
0072   int dcc = dccId();
0073   int dcc_channel = towerId();
0074   int quadrant = EEQuadrant(dcc, dcc_channel);
0075   int strip = stripId();
0076   int xtal = xtalId();
0077   int channel;
0078   if (quadrant == 1 || quadrant == 3)
0079     channel = 5 * (strip - 1) + xtal;
0080   else
0081     channel = 5 * (xtal - 1) + strip;
0082   return channel;
0083 }
0084 
0085 /*
0086 int EcalElectronicsId::stripId() {
0087  int dcc = dccId() ;
0088  int dcc_channel = towerId();
0089  int quadrant = EEQuadrant(dcc, dcc_channel);
0090  int xtal = channelId();
0091  int strip;
0092  if (quadrant ==1 || quadrant== 3) strip = (xtal-1)/5 +1;
0093  else strip = (xtal-1) % 5 +1;
0094  return strip;
0095 }
0096 
0097 int EcalElectronicsId::XtalInStripId() {
0098  int dcc = dccId() ;
0099  int dcc_channel = towerId();
0100  int quadrant = EEQuadrant(dcc, dcc_channel);
0101  int xtal = channelId();
0102  int id;
0103  if (quadrant ==1 || quadrant== 3) id = (xtal-1)%5 + 1;
0104  else id = (xtal-1)/5 +1;
0105  return id;
0106 }
0107 */
0108 
0109 std::ostream& operator<<(std::ostream& os, const EcalElectronicsId& id) {
0110   return os << id.dccId() << ',' << id.towerId() << ',' << id.stripId() << ',' << id.xtalId();
0111 }