CMS 3D CMS Logo

HcalGenericDetId.cc

Go to the documentation of this file.
00001 
00007 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
00008 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00009 #include "DataFormats/HcalDetId/interface/HcalTrigTowerDetId.h"
00010 #include "DataFormats/HcalDetId/interface/HcalZDCDetId.h"
00011 #include "DataFormats/HcalDetId/interface/HcalCastorDetId.h"
00012 #include "DataFormats/HcalDetId/interface/HcalCalibDetId.h"
00013 #include <iostream>
00014 
00015 HcalOtherSubdetector HcalGenericDetId::otherSubdet () const {
00016   if (HcalSubdetector(subdetId()) != HcalOther) return HcalOtherEmpty;
00017   return HcalOtherSubdetector ((rawId()>>20)&0x1F);
00018 }
00019 
00020 HcalGenericDetId::HcalGenericSubdetector HcalGenericDetId::genericSubdet () const {
00021   if (null()) return HcalGenEmpty;
00022   switch (det()) {
00023   case Calo : 
00024     switch (subdetId()) {
00025     case HcalZDCDetId::SubdetectorId : return HcalGenZDC;
00026     case HcalCastorDetId::SubdetectorId : return HcalGenCastor;
00027     default: return HcalGenUnknown;
00028     } 
00029   case Hcal :
00030     switch (HcalSubdetector(subdetId())) {
00031     case 0: return HcalGenEmpty;
00032     case HcalBarrel: return HcalGenBarrel;
00033     case HcalEndcap: return HcalGenEndcap;
00034     case HcalOuter: return HcalGenOuter;
00035     case HcalForward: return HcalGenForward;
00036     case HcalTriggerTower: return HcalGenTriggerTower;
00037     case HcalOther:
00038       switch (otherSubdet ()) {
00039       case HcalCalibration: return HcalGenCalibration;
00040       default: return HcalGenUnknown;
00041     }
00042     default: return HcalGenUnknown;
00043     }
00044     default: return HcalGenUnknown;
00045   }
00046   return HcalGenUnknown;
00047 }
00048   
00049 bool HcalGenericDetId::isHcalDetId () const {
00050   HcalGenericSubdetector subdet = genericSubdet ();
00051   return subdet == HcalGenBarrel || subdet == HcalGenEndcap || subdet == HcalGenOuter || subdet == HcalGenForward; 
00052 }
00053 
00054 bool HcalGenericDetId::isHcalCalibDetId () const {
00055   HcalGenericSubdetector subdet = genericSubdet ();
00056   return subdet == HcalGenCalibration;
00057 }
00058 
00059 bool HcalGenericDetId::isHcalTrigTowerDetId () const {
00060   HcalGenericSubdetector subdet = genericSubdet ();
00061   return subdet == HcalGenTriggerTower;
00062 }
00063 
00064 bool HcalGenericDetId::isHcalZDCDetId () const {
00065   HcalGenericSubdetector subdet = genericSubdet ();
00066   return subdet == HcalGenZDC;
00067 }
00068 
00069 bool HcalGenericDetId::isHcalCastorDetId () const {
00070   HcalGenericSubdetector subdet = genericSubdet ();
00071   return subdet == HcalGenCastor;
00072 }
00073 
00074 std::ostream& operator<<(std::ostream& s,const HcalGenericDetId& id) {
00075   if (id.null()) s << "(Null Id)";
00076   else 
00077     switch (id.genericSubdet()) {
00078     case HcalGenericDetId::HcalGenBarrel: 
00079     case HcalGenericDetId::HcalGenEndcap: 
00080     case HcalGenericDetId::HcalGenOuter: 
00081     case HcalGenericDetId::HcalGenForward: s << HcalDetId(id); break;
00082     case HcalGenericDetId::HcalGenTriggerTower: s << HcalTrigTowerDetId(id); break;
00083     case HcalGenericDetId::HcalGenZDC: s << HcalZDCDetId(id); break;
00084     case HcalGenericDetId::HcalGenCastor: s << HcalCastorDetId(id); break;
00085     case HcalGenericDetId::HcalGenCalibration: s << HcalCalibDetId(id); break;
00086     default: s << "(Hcal Unknown Id: 0x" << std::hex << id.rawId() << std::dec << ')';
00087     }
00088   return s;
00089 }
00090 
00091 int HcalGenericDetId::hashedId(bool h2mode_) const {
00092   int index = -1;
00093 
00094   int HBhalf = 1296;
00095   int HEhalf = 1296;
00096   if (h2mode_) HEhalf = 4032;
00097   int HOhalf = 1080;
00098   int HFhalf = 864;
00099   int HThalf = 2088;
00100   int ZDChalf = 11;
00101 
00102   int zside=0, ietaAbs=0, ieta=0, iphi=0, depth=0, channel=0;
00103 
00104   // HB valid DetIds: phi=1-72,eta=1-14,depth=1; phi=1-72,eta=15-16,depth=1-2
00105   if (genericSubdet() == HcalGenericDetId::HcalGenBarrel )
00106     {
00107       HcalDetId tid(rawId() ); 
00108       zside = tid.zside();
00109       ietaAbs = tid.ietaAbs();
00110       iphi = tid.iphi();
00111       depth = tid.depth();
00112 
00113       if (ietaAbs < 16)   index = (iphi - 1)*18 + (ietaAbs - 1) + (depth - 1);
00114       if (ietaAbs == 16)  index = (iphi - 1)*18 + ietaAbs + (depth - 1);
00115       
00116       if (zside == -1) index += HBhalf;
00117     }
00118   
00119   // HE valid DetIds: phi=1-72,eta=16-17,depth=1; phi=1-72,eta=18-20,depth=1-2; 
00120   //                  phi=1-71(in steps of 2),eta=21-26,depth=1-2; phi=1-71(in steps of 2),eta=27-28,depth=1-3
00121   //                  phi=1-71(in steps of 2),eta=29,depth=1-2
00122   if (genericSubdet() ==  HcalGenericDetId::HcalGenEndcap )
00123     {
00124       HcalDetId tid(rawId() ); 
00125       zside = tid.zside();
00126       ietaAbs = tid.ietaAbs();
00127       iphi = tid.iphi();
00128       depth = tid.depth();
00129       
00130       if (!h2mode_)
00131         {
00132           if (ietaAbs == 16 || ietaAbs == 17)  index = (iphi - 1)*8 + (iphi/2)*20 + (ietaAbs - 16);
00133           if (ietaAbs >= 18 && ietaAbs <= 20)  index = (iphi - 1)*8 + (iphi/2)*20 + 2  + 2*(ietaAbs-18) + (depth - 1);
00134           if (ietaAbs >= 21 && ietaAbs <= 26)  index = (iphi - 1)*8 + (iphi/2)*20 + 8  + 2*(ietaAbs-21) + (depth - 1);
00135           if (ietaAbs >= 27 && ietaAbs <= 28)  index = (iphi - 1)*8 + (iphi/2)*20 + 20 + 3*(ietaAbs-27) + (depth - 1);
00136           if (ietaAbs == 29)                   index = (iphi - 1)*8 + (iphi/2)*20 + 26 + 2*(ietaAbs-29) + (depth - 1);
00137         }
00138       else
00139         {
00140           // make as general as possible, don't care about tight packing for the moment
00141           index = (iphi-1)*4*14 + (ietaAbs - 16)*4 + (depth - 1);
00142 
00143 //        if (ietaAbs == 16)                   index = (iphi - 1)*11 + (iphi/2)*20 + (ietaAbs - 16);
00144 //        if (ietaAbs == 17)                   index = (iphi - 1)*11 + (iphi/2)*20 + 1 + (ietaAbs - 17) + (depth - 1);
00145 //        if (ietaAbs >= 18 && ietaAbs <= 20)  index = (iphi - 1)*11 + (iphi/2)*20 + 5  + 2*(ietaAbs-18) + (depth - 1);
00146 //        if (ietaAbs >= 21 && ietaAbs <= 26)  index = (iphi - 1)*11 + (iphi/2)*20 + 11 + 2*(ietaAbs-21) + (depth - 1);
00147 //        if (ietaAbs >= 27 && ietaAbs <= 28)  index = (iphi - 1)*11 + (iphi/2)*20 + 23 + 3*(ietaAbs-27) + (depth - 1);
00148 //        if (ietaAbs == 29)                   index = (iphi - 1)*11 + (iphi/2)*20 + 29 + 2*(ietaAbs-29) + (depth - 1);
00149         }
00150       if (zside == -1) index += HEhalf;
00151 
00152     }
00153 
00154   // HO valid DetIds: phi=1-72,eta=1-15,depth=4!
00155   if (genericSubdet() == HcalGenericDetId::HcalGenOuter )
00156     {
00157       HcalDetId tid(rawId() ); 
00158       zside = tid.zside();
00159       ietaAbs = tid.ietaAbs();
00160       iphi = tid.iphi();
00161       depth = tid.depth();
00162       
00163       index = (iphi - 1)*15 + (ietaAbs - 1);
00164 
00165       if (zside == -1) index += HOhalf;
00166   }
00167 
00168   // HF valid DetIds: phi=1-71(in steps of 2),eta=29-39,depth=1-2; phi=3-71(in steps of 4),eta=40-41,depth=1-2
00169   if (genericSubdet() == HcalGenericDetId::HcalGenForward )
00170     {
00171       HcalDetId tid(rawId() ); 
00172       zside = tid.zside();
00173       ietaAbs = tid.ietaAbs();
00174       iphi = tid.iphi();
00175       depth = tid.depth();
00176 
00177       index = ((iphi-1)/4)*4 + ((iphi-1)/2)*22 + 2*(ietaAbs-29) + (depth - 1);
00178 
00179       if (zside == -1)  index += HFhalf;
00180     }
00181 
00182   // TriggerTower:
00183   if (genericSubdet() == HcalGenericDetId::HcalGenTriggerTower )
00184     {
00185       HcalTrigTowerDetId tid(rawId() ); 
00186       zside = tid.zside();
00187       ietaAbs = tid.ietaAbs();
00188       iphi = tid.iphi();
00189 
00190       int HTphi1_18 = 576;
00191       if (iphi < 19) index = (iphi-1)*32 + (ietaAbs-1);
00192       else index = HTphi1_18 + (iphi-19)*28 + (ietaAbs-1);
00193 
00194       if (zside == -1) index += HThalf;
00195     }
00196 
00197   // ZDC: ZDC_EM: 1 to 5, ZDC_HAD: 1 to 4, ZDC_LUM: 1,2, eta = +1, -1
00198   if (genericSubdet() == HcalGenericDetId::HcalGenZDC )
00199     {
00200       HcalZDCDetId tid(rawId() ); 
00201       zside = tid.zside();
00202       depth = tid.depth();
00203 
00204       switch (tid.section() ) {
00205       case HcalZDCDetId::EM:   index = (depth-1); break;
00206       case HcalZDCDetId::HAD:  index = 5 + (depth-1); break;
00207       case HcalZDCDetId::LUM:  index = 9 + (depth-1); break;
00208       default: break;
00209       }
00210       if (zside == -1) index += ZDChalf;
00211     }
00212 
00213   // Castor: ???
00214   if (genericSubdet() == HcalGenericDetId::HcalGenCastor )
00215     {
00216       HcalCastorDetId tid(rawId() ); 
00217 
00218     }
00219 
00220   // Calibration channels: no zside=-1 ! with current naming convention
00221   if (genericSubdet() == HcalGenericDetId::HcalGenCalibration )
00222     {
00223       HcalCalibDetId tid(rawId() );
00224       channel = tid.cboxChannel();
00225       ieta = tid.ieta();
00226       iphi = tid.iphi();
00227       zside = tid.zside();
00228 
00229       if (tid.calibFlavor()==HcalCalibDetId::CalibrationBox) {
00230 
00231         HcalSubdetector subDet = tid.hcalSubdet();
00232 
00233         if (subDet==HcalBarrel) {
00234           index = ((iphi+1)/4-1) + 18*channel + 27*(ieta+1);
00235         } else if (subDet==HcalEndcap) {
00236           index = ((iphi+1)/4-1) + 18*channel + 63*(ieta+1) + 108;
00237         } else if (subDet==HcalForward) {
00238           if (channel==8) channel = 3;
00239           index = (iphi-1)/18 + 4*channel + 8*(ieta+1) + 360;
00240         } else if (subDet==HcalOuter) {
00241           if (channel==7) channel = 2;
00242           index = ((iphi+1)/6-1) + 12*(ieta+2) + 65*channel + 391;
00243         } else {
00244           std::cout << "HCAL Det Id not valid!" << std::endl;
00245           index = 0;
00246         }
00247 
00248      } else if (tid.calibFlavor()==HcalCalibDetId::HOCrosstalk) {
00249         if (ieta==11) {
00250            switch(iphi) {
00251            case(16): index = 288+577; // 576 is the index of the last calib channel
00252            case(31): index = 289+577;
00253            case(5): index = 290+577;
00254            case(67): index = 291+577;
00255            default: index = 0;
00256            }
00257         } else {
00258           if (ieta==4) ieta = 0;
00259           if (ieta==15) ieta = 1;
00260           index = (iphi-1) + 72*(ieta) + 72*(zside+1) + 577;
00261         }
00262      }
00263      
00264    }
00265 
00266   //std::cout << "eta=" << ietaAbs << " side=" << zside << " phi=" << iphi << " depth=" << depth << " index=" << index << std::endl;
00267 
00268   return index;
00269 }

Generated on Tue Jun 9 17:30:59 2009 for CMSSW by  doxygen 1.5.4