CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/DataFormats/EcalDetId/src/EcalElectronicsId.cc

Go to the documentation of this file.
00001 #include "DataFormats/EcalDetId/interface/EcalElectronicsId.h"
00002 #include "FWCore/Utilities/interface/Exception.h"
00003 
00004 
00005 #include <iostream>
00006 
00007 
00008 EcalElectronicsId::EcalElectronicsId() {
00009   EcalElectronicsId_=0xFFFFFFFFu;
00010 }
00011 
00012 EcalElectronicsId::EcalElectronicsId(uint32_t id) {
00013   EcalElectronicsId_=id;
00014 }
00015 
00016 EcalElectronicsId::EcalElectronicsId(int dccid, int towerid, int stripid, int xtalid){
00017   if ( (dccid < MIN_DCCID) || (dccid > MAX_DCCID) ||  
00018        (towerid < MIN_TOWERID) || (towerid > MAX_TOWERID) ||  
00019        (stripid < MIN_STRIPID) || (stripid > MAX_STRIPID) ||  
00020        (xtalid < MIN_XTALID) || (xtalid > MAX_XTALID) )
00021     throw cms::Exception("InvalidDetId") << "EcalElectronicsId:  Cannot create object.  Indexes out of bounds. Dcc tower strip xtal " << dccid << " " << towerid << " " << stripid << " " << xtalid << ".";
00022   EcalElectronicsId_= (xtalid&0x7) | ( (stripid&0x7) << 3) | ( (towerid&0x7F) << 6) | ((dccid&0x7F) << 13);
00023 }
00024 
00025 
00026 EcalSubdetector EcalElectronicsId::subdet() const {
00027         int dcc = dccId();
00028         if ( (dcc >= MIN_DCCID_EBM && dcc <= MAX_DCCID_EBM) ||
00029              (dcc >= MIN_DCCID_EBP && dcc <= MAX_DCCID_EBP) ) return EcalBarrel;
00030         else return EcalEndcap;
00031 }
00032 
00033 int EcalElectronicsId::zside() const {
00034         int dcc = dccId();
00035         if ( (dcc >= MIN_DCCID_EEM && dcc <= MAX_DCCID_EEM)) return -1;
00036         if ( (dcc >= MIN_DCCID_EBM && dcc <= MAX_DCCID_EBM)) return -1;
00037         if ( (dcc >= MIN_DCCID_EEP && dcc <= MAX_DCCID_EEP)) return +1;
00038         if ( (dcc >= MIN_DCCID_EBP && dcc <= MAX_DCCID_EBP)) return +1;
00039         return 0;
00040 }
00041 
00042 
00043 
00044 static int EEQuadrant(int dcc, int dcc_channel) {
00045         // Q1 = EE+N or EE-F, Top
00046         // Q2 = EE+F or EE-N, Top
00047         // Q3 = EE+F or EE-N, Bottom
00048         // Q4 = EE+N or EE-F, Bottom
00049         //  (local notation)
00050         // in Q1-Q3 and in Q2-Q4, the relation between strip#, channel# and xtal_id
00051         // is the same
00052  int q=-1;
00053   if ( (dcc == EcalElectronicsId::DCC_EEP + 1) || ( dcc == EcalElectronicsId::DCC_EEP + 2) ||
00054        (dcc == EcalElectronicsId::DCC_EEP && dcc_channel <= EcalElectronicsId::kDCCChannelBoundary) ||
00055        (dcc == EcalElectronicsId::DCC_EEM + 3) || ( dcc == EcalElectronicsId::DCC_EEM + 4) ||
00056        (dcc == EcalElectronicsId::DCC_EEM + 5 && dcc_channel <= EcalElectronicsId::kDCCChannelBoundary) ) q=1;
00057   else if ( (dcc == EcalElectronicsId::DCC_EEP + 3) || ( dcc == EcalElectronicsId::DCC_EEP + 4) ||
00058        (dcc == EcalElectronicsId::DCC_EEP+5 && dcc_channel <= EcalElectronicsId::kDCCChannelBoundary) ||
00059        (dcc == EcalElectronicsId::DCC_EEM && dcc_channel <= EcalElectronicsId::kDCCChannelBoundary) ||
00060        (dcc == EcalElectronicsId::DCC_EEM + 1) || ( dcc == EcalElectronicsId::DCC_EEM + 2) ) q=2;
00061   else if ( (dcc == EcalElectronicsId::DCC_EEP + 6) ||
00062        (dcc == EcalElectronicsId::DCC_EEP + 5 && dcc_channel > EcalElectronicsId::kDCCChannelBoundary) ||
00063        (dcc == EcalElectronicsId::DCC_EEP + 7 && dcc_channel > EcalElectronicsId::kDCCChannelBoundary) ||
00064        (dcc == EcalElectronicsId::DCC_EEM && dcc_channel > EcalElectronicsId::kDCCChannelBoundary) ||
00065        (dcc == EcalElectronicsId::DCC_EEM + 8) ||
00066        (dcc == EcalElectronicsId::DCC_EEM + 7 && dcc_channel > EcalElectronicsId::kDCCChannelBoundary)) q=3;
00067   else
00068        q=4;
00069   return q;
00070 }
00071 
00072 int EcalElectronicsId::channelId() const {
00073  int dcc = dccId() ;
00074  int dcc_channel = towerId();
00075  int quadrant = EEQuadrant(dcc, dcc_channel);
00076  int strip = stripId();
00077  int xtal = xtalId();
00078  int channel;
00079  if (quadrant ==1 || quadrant== 3) channel = 5*(strip-1) + xtal;
00080  else channel = 5*(xtal-1) + strip;
00081  return channel;
00082 }
00083 
00084 /*
00085 int EcalElectronicsId::stripId() {
00086  int dcc = dccId() ;
00087  int dcc_channel = towerId();
00088  int quadrant = EEQuadrant(dcc, dcc_channel);
00089  int xtal = channelId();
00090  int strip;
00091  if (quadrant ==1 || quadrant== 3) strip = (xtal-1)/5 +1;
00092  else strip = (xtal-1) % 5 +1;
00093  return strip;
00094 }
00095 
00096 int EcalElectronicsId::XtalInStripId() {
00097  int dcc = dccId() ;
00098  int dcc_channel = towerId();
00099  int quadrant = EEQuadrant(dcc, dcc_channel);
00100  int xtal = channelId();
00101  int id;
00102  if (quadrant ==1 || quadrant== 3) id = (xtal-1)%5 + 1;
00103  else id = (xtal-1)/5 +1;
00104  return id;
00105 }
00106 */
00107 
00108 
00109 
00110 std::ostream& operator<<(std::ostream& os,const EcalElectronicsId& id) 
00111 {
00112   return os << id.dccId() << ',' << id.towerId() << ',' << id.stripId() << ',' << id.xtalId() ;
00113 }
00114