CMS 3D CMS Logo

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