CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/DataFormats/HcalDetId/src/HcalDetId.cc

Go to the documentation of this file.
00001 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00002 #include "FWCore/Utilities/interface/Exception.h"
00003 #include <ostream>
00004 
00005 const HcalDetId HcalDetId::Undefined(HcalEmpty,0,0,0);
00006 
00007 HcalDetId::HcalDetId() : DetId() {
00008 }
00009 
00010 HcalDetId::HcalDetId(uint32_t rawid) : DetId(rawid) {
00011 }
00012 
00013 HcalDetId::HcalDetId(HcalSubdetector subdet, int tower_ieta, int tower_iphi, int depth) : DetId(Hcal,subdet) {
00014   // (no checking at this point!)
00015   id_ |= ((depth&0x1F)<<14) |
00016     ((tower_ieta>0)?(0x2000|(tower_ieta<<7)):((-tower_ieta)<<7)) |
00017     (tower_iphi&0x7F);
00018 }
00019 
00020 HcalDetId::HcalDetId(const DetId& gen) {
00021   if (!gen.null()) {
00022     HcalSubdetector subdet=(HcalSubdetector(gen.subdetId()));
00023     if (gen.det()!=Hcal || 
00024         (subdet!=HcalBarrel && subdet!=HcalEndcap && 
00025          subdet!=HcalOuter && subdet!=HcalForward )) {
00026       throw cms::Exception("Invalid DetId") << "Cannot initialize HcalDetId from " << std::hex << gen.rawId() << std::dec; 
00027     }  
00028   }
00029   id_=gen.rawId();
00030 }
00031 
00032 HcalDetId& HcalDetId::operator=(const DetId& gen) {
00033   if (!gen.null()) {
00034     HcalSubdetector subdet=(HcalSubdetector(gen.subdetId()));
00035     if (gen.det()!=Hcal || 
00036         (subdet!=HcalBarrel && subdet!=HcalEndcap && 
00037          subdet!=HcalOuter && subdet!=HcalForward ))
00038       {
00039         throw cms::Exception("Invalid DetId") << "Cannot assign HcalDetId from " << std::hex << gen.rawId() << std::dec; 
00040       }  
00041   }
00042   id_=gen.rawId();
00043   return (*this);
00044 }
00045 
00046 int HcalDetId::crystal_iphi_low() const { 
00047   int simple_iphi=((iphi()-1)*5)+1; 
00048   simple_iphi+=10;
00049   return ((simple_iphi>360)?(simple_iphi-360):(simple_iphi));
00050 }
00051 
00052 int HcalDetId::crystal_iphi_high() const { 
00053   int simple_iphi=((iphi()-1)*5)+5; 
00054   simple_iphi+=10;
00055   return ((simple_iphi>360)?(simple_iphi-360):(simple_iphi));
00056 }
00057 
00058 std::ostream& operator<<(std::ostream& s,const HcalDetId& id) {
00059   switch (id.subdet()) {
00060   case(HcalBarrel) : return s << "(HB " << id.ieta() << ',' << id.iphi() << ',' << id.depth() << ')';
00061   case(HcalEndcap) : return s << "(HE " << id.ieta() << ',' << id.iphi() << ',' << id.depth() << ')';
00062   case(HcalForward) : return s << "(HF " << id.ieta() << ',' << id.iphi() << ',' << id.depth() << ')';
00063   case(HcalOuter) : return s << "(HO " << id.ieta() << ',' << id.iphi() << ')';
00064   default : return s << id.rawId();
00065   }
00066 }
00067 
00068