CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/DataFormats/HcalDetId/src/HcalZDCDetId.cc

Go to the documentation of this file.
00001 #include "DataFormats/HcalDetId/interface/HcalZDCDetId.h"
00002 #include "FWCore/Utilities/interface/Exception.h"
00003 
00004 HcalZDCDetId::HcalZDCDetId() : DetId() {
00005 }
00006 
00007 
00008 HcalZDCDetId::HcalZDCDetId(uint32_t rawid) : DetId(rawid) {
00009 }
00010 
00011 HcalZDCDetId::HcalZDCDetId(Section section, bool true_for_positive_eta, int channel) : DetId(DetId::Calo,SubdetectorId) {
00012   id_|=(section&0x3)<<4;
00013   if (true_for_positive_eta) id_|=0x40;
00014   id_|=channel&0xF;
00015 }
00016 
00017 HcalZDCDetId::HcalZDCDetId(const DetId& gen) {
00018   if (!gen.null() && (gen.det()!=Calo || gen.subdetId()!=SubdetectorId)) {
00019     throw cms::Exception("Invalid DetId") << "Cannot initialize ZDCDetId from " << std::hex << gen.rawId() << std::dec; 
00020   }
00021   id_=gen.rawId();
00022 }
00023 
00024 HcalZDCDetId& HcalZDCDetId::operator=(const DetId& gen) {
00025   if (!gen.null() && (gen.det()!=Calo || gen.subdetId()!=SubdetectorId)) {
00026     throw cms::Exception("Invalid DetId") << "Cannot assign ZDCDetId from " << std::hex << gen.rawId() << std::dec; 
00027   }
00028   id_=gen.rawId();
00029   return *this;
00030 }
00031 
00032 uint32_t 
00033 HcalZDCDetId::denseIndex() const 
00034 {
00035    const int se ( section() ) ;
00036    return ( ( zside()<0 ? 0 : kDepTot ) + channel() - 1 +
00037             ( se == HAD  ? kDepEM :
00038               ( se == LUM ? kDepEM + kDepHAD : 0 ) ) ) ;
00039 }
00040 
00041 HcalZDCDetId 
00042 HcalZDCDetId::detIdFromDenseIndex( uint32_t di ) 
00043 {
00044    if( validDenseIndex( di ) )
00045    {
00046       const bool lz ( di >= kDepTot ) ;
00047       const uint32_t in ( di%kDepTot ) ;
00048       const Section se ( in<kDepEM ? EM :
00049                          ( in<kDepEM+kDepHAD ? HAD : LUM ) ) ;
00050       const uint32_t dp ( EM == se ? in+1 :
00051                           ( HAD == se ? in - kDepEM + 1 : in - kDepEM - kDepHAD + 1 ) ) ;
00052       return HcalZDCDetId( se, lz, dp ) ;
00053    }
00054    else
00055    {
00056       return HcalZDCDetId() ;
00057    }
00058 }
00059 
00060 bool 
00061 HcalZDCDetId::validDetId( Section se ,
00062                           int     dp   )
00063 {
00064   return ( dp >= 1 && (
00065                        ( ( se == EM      ) &&
00066                          ( dp <= kDepEM  )    ) ||
00067                        ( ( se == HAD     ) &&
00068                          ( dp <= kDepHAD )    ) ||
00069                        ( ( se == LUM     ) &&
00070                          ( dp <= kDepLUM )    )   
00071                        )
00072            ) ;
00073 }
00074 
00075 std::ostream& operator<<(std::ostream& s,const HcalZDCDetId& id) {
00076   s << "(ZDC" << ((id.zside()==1)?("+"):("-"));
00077   switch (id.section()) {
00078   case(HcalZDCDetId::EM) : s << " EM "; break;
00079   case(HcalZDCDetId::HAD) : s << " HAD "; break;
00080   case(HcalZDCDetId::LUM) : s << " LUM "; break;
00081   default : s <<" UNKNOWN ";
00082   }
00083   return s << id.channel() << "," << id.depth() << ')';
00084 }
00085