CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DataFormats/HcalDetId/src/HcalGenericDetId.cc

Go to the documentation of this file.
00001 
00006 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
00007 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00008 #include "DataFormats/HcalDetId/interface/HcalTrigTowerDetId.h"
00009 #include "DataFormats/HcalDetId/interface/HcalZDCDetId.h"
00010 #include "DataFormats/HcalDetId/interface/HcalCastorDetId.h"
00011 #include "DataFormats/HcalDetId/interface/HcalCalibDetId.h"
00012 #include <iostream>
00013 #include <cstdlib>
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 zside=0, ietaAbs=0, ieta=0, iphi=0, depth=0, channel=0, sector=0, module=0;
00095 
00096   switch (genericSubdet()) {
00097     // HB valid DetIds: phi=1-72,eta=1-14,depth=1; phi=1-72,eta=15-16,depth=1-2
00098   case HcalGenericDetId::HcalGenBarrel:
00099     {
00100       HcalDetId tid(rawId() ); 
00101       zside = tid.zside();
00102       ietaAbs = tid.ietaAbs();
00103       iphi = tid.iphi();
00104       depth = tid.depth();
00105       
00106       // if (ietaAbs < 16)   index = (iphi - 1)*18 + (ietaAbs - 1) + (depth - 1);
00107       // if (ietaAbs == 16)  index = (iphi - 1)*18 + ietaAbs + (depth - 1);
00108 
00109       index = (iphi - 1)*18 + ietaAbs + depth - 2;
00110       if (ietaAbs == 16) ++index;
00111       
00112       if (zside == -1) index += HBhalf;
00113     }
00114     break;
00115     // HE valid DetIds: phi=1-72,eta=16-17,depth=1; phi=1-72,eta=18-20,depth=1-2; 
00116     //                  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
00117     //                  phi=1-71(in steps of 2),eta=29,depth=1-2
00118   case HcalGenericDetId::HcalGenEndcap:
00119     {
00120       HcalDetId tid(rawId() ); 
00121       zside = tid.zside();
00122       ietaAbs = tid.ietaAbs();
00123       iphi = tid.iphi();
00124       depth = tid.depth();
00125       
00126       if (!h2mode_)
00127         {
00128           if (ietaAbs == 16 || ietaAbs == 17)  index = (iphi - 1)*8 + (iphi/2)*20 + (ietaAbs - 16);
00129           if (ietaAbs >= 18 && ietaAbs <= 20)  index = (iphi - 1)*8 + (iphi/2)*20 + 2  + 2*(ietaAbs-18) + (depth - 1);
00130           if (ietaAbs >= 21 && ietaAbs <= 26)  index = (iphi - 1)*8 + (iphi/2)*20 + 8  + 2*(ietaAbs-21) + (depth - 1);
00131           if (ietaAbs >= 27 && ietaAbs <= 28)  index = (iphi - 1)*8 + (iphi/2)*20 + 20 + 3*(ietaAbs-27) + (depth - 1);
00132           if (ietaAbs == 29)                   index = (iphi - 1)*8 + (iphi/2)*20 + 26 + 2*(ietaAbs-29) + (depth - 1);
00133         }
00134       else
00135         {
00136           // make as general as possible, don't care about tight packing for the moment
00137           //      index = (iphi-1)*(4*14) + (ietaAbs - 16)*4 + (depth - 1);
00138           index = 4*( 14*(iphi-1) + (ietaAbs - 16)) + (depth - 1);
00139           
00140           //      if (ietaAbs == 16)                   index = (iphi - 1)*11 + (iphi/2)*20 + (ietaAbs - 16);
00141           //      if (ietaAbs == 17)                   index = (iphi - 1)*11 + (iphi/2)*20 + 1 + (ietaAbs - 17) + (depth - 1);
00142           //      if (ietaAbs >= 18 && ietaAbs <= 20)  index = (iphi - 1)*11 + (iphi/2)*20 + 5  + 2*(ietaAbs-18) + (depth - 1);
00143           //      if (ietaAbs >= 21 && ietaAbs <= 26)  index = (iphi - 1)*11 + (iphi/2)*20 + 11 + 2*(ietaAbs-21) + (depth - 1);
00144           //      if (ietaAbs >= 27 && ietaAbs <= 28)  index = (iphi - 1)*11 + (iphi/2)*20 + 23 + 3*(ietaAbs-27) + (depth - 1);
00145           //      if (ietaAbs == 29)                   index = (iphi - 1)*11 + (iphi/2)*20 + 29 + 2*(ietaAbs-29) + (depth - 1);
00146         }
00147       if (zside == -1) index += HEhalf;
00148       
00149     }
00150     break;
00151   // HO valid DetIds: phi=1-72,eta=1-15,depth=4!
00152   case HcalGenericDetId::HcalGenOuter:
00153     {
00154       HcalDetId tid(rawId() ); 
00155       zside = tid.zside();
00156       ietaAbs = tid.ietaAbs();
00157       iphi = tid.iphi();
00158       depth = tid.depth();
00159       
00160       index = (iphi - 1)*15 + (ietaAbs - 1);
00161       
00162       if (zside == -1) index += HOhalf;
00163     }
00164     break;
00165     // 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
00166   case HcalGenericDetId::HcalGenForward:
00167     {
00168       HcalDetId tid(rawId() ); 
00169       zside = tid.zside();
00170       ietaAbs = tid.ietaAbs();
00171       iphi = tid.iphi();
00172       depth = tid.depth();
00173       
00174       index = ((iphi-1)/4)*4 + ((iphi-1)/2)*22 + 2*(ietaAbs-29) + (depth - 1);
00175       
00176       if (zside == -1)  index += HFhalf;
00177     }
00178     break;
00179   // TriggerTower:
00180   case HcalGenericDetId::HcalGenTriggerTower:
00181     {
00182       HcalTrigTowerDetId tid(rawId() ); 
00183       zside = tid.zside();
00184       ietaAbs = tid.ietaAbs();
00185       iphi = tid.iphi();
00186       
00187       if ((iphi-1)%4==0) index = (iphi-1)*32 + (ietaAbs-1) - (12*((iphi-1)/4));
00188       else               index = (iphi-1)*28 + (ietaAbs-1) + (4*(((iphi-1)/4)+1));
00189       
00190       if (zside == -1) index += HThalf;
00191       // ieta = ietaAbs*zside;      
00192     }
00193     break;
00194   // ZDC: ZDC_EM: 1 to 5, ZDC_HAD: 1 to 4, ZDC_LUM: 1,2, eta = +1, -1
00195   case HcalGenericDetId::HcalGenZDC:
00196     {
00197       HcalZDCDetId tid(rawId() ); 
00198       zside   = tid.zside();
00199       channel = tid.channel();
00200       //depth   = tid.depth();//depth is not unique, channel is
00201       
00202       switch (tid.section() ) {
00203       case HcalZDCDetId::EM:   index = (channel-1); break;
00204       case HcalZDCDetId::HAD:  index = 5 + (channel-1); break;
00205       case HcalZDCDetId::LUM:  index = 9 + (channel-1); break;
00206       default: break;
00207       }
00208       if (zside == -1) index += ZDChalf;
00209     }
00210     break;
00211     // Castor: zside +-1, sector (phi-segmentation) 1..16, module (z segm.) 1..14
00212     // total: 14*16=224 per zside
00213   case HcalGenericDetId::HcalGenCastor:
00214     {
00215       HcalCastorDetId tid(rawId() ); 
00216       zside = tid.zside();
00217       sector = tid.sector();
00218       module = tid.module();
00219       
00220       index = 14*(sector-1) + (module-1);
00221       if (zside == -1) index += CASTORhalf;
00222       
00223     }
00224     break;
00225   // Calibration channels: no zside=-1 ! with current naming convention
00226   case HcalGenericDetId::HcalGenCalibration:
00227     {
00228       HcalCalibDetId tid(rawId() );
00229       channel = tid.cboxChannel();
00230       ieta = tid.ieta();
00231       iphi = tid.iphi();
00232       zside = tid.zside();
00233       
00234       
00235       if (tid.calibFlavor()==HcalCalibDetId::CalibrationBox) {
00236         
00237         HcalSubdetector subDet = tid.hcalSubdet();
00238         
00239         if (subDet==HcalBarrel) {
00240           //std::cout<<"CALIB_HB:  ";
00241           //dphi = 4 (18 phi values), 3 channel types (0,1,2), eta = -1 or 1
00242           //total of 18*3*2=108 channels
00243           index = ((iphi+1)/4-1) + 18*channel + 27*(ieta+1);
00244         }
00245         else if (subDet==HcalEndcap) {
00246           //std::cout<<"CALIB_HE:  ";
00247           //dphi = 4 (18 phi values), 6 channel types (0,1,3,4,5,6), eta = -1 or 1
00248           //total of 18*6*2=216 channels
00249           if (channel>2) channel-=1;
00250           index = ((iphi+1)/4-1) + 18*channel + 54*(ieta+1) + 108;
00251         } 
00252         else if (subDet==HcalForward) {
00253           //std::cout<<"CALIB_HF:  ";
00254           //dphi = 18 (4 phi values), 3 channel types (0,1,8), eta = -1 or 1
00255           if (channel==8) channel = 2;
00256           //total channels 4*3*2=24
00257           index = (iphi-1)/18 + 4*channel + 6*(ieta+1) + 324;
00258         }
00259         else if (subDet==HcalOuter) {
00260           //std::cout<<"CALIB_HO:  ";
00261           //there are 5 special calib crosstalk channels, one in each ring
00262           if (channel==7) {
00263             channel = 2;
00264             index = (ieta+2) + 420;
00265           }
00266           //for HOM/HOP dphi = 6 (12 phi values),  2 channel types (0,1), eta = -2,-1 or 1,2
00267           //for HO0/YB0 dphi = 12 (6 phi values),  2 channel types (0,1), eta = 0
00268           else{
00269             if (ieta<0) index      = ((iphi+1)/12-1) + 36*channel + 6*(ieta+2) + 348;
00270             else if (ieta>0) index = ((iphi+1)/12-1) + 36*channel + 6*(ieta+2) + 6 + 348;
00271             else index             = ((iphi+1)/6-1)  + 36*channel + 6*(ieta+2) + 348;
00272           }
00273         } 
00274         else {
00275           std::cout << "HCAL Det Id not valid!" << std::endl;
00276           index = 0;
00277         }
00278         
00279       }
00280       else if (tid.calibFlavor()==HcalCalibDetId::HOCrosstalk) {
00281         //std::cout<<"HX:  ";
00282         //for YB0/HO0 phi is grouped in 6 groups of 6 with dphi=2 but the transitions are 1 or 3
00283         // in such a way that the %36 operation yeilds unique values for every iphi
00284         if (abs(ieta)==4)  index = ((iphi-1)%36) + (((zside+1)*36)/2) + 72 + 425;   //ieta = 1 YB0/HO0;
00285         else               index = (iphi-1) + (36*(zside+1)*2) + 425;  //ieta = 0 for HO2M/HO1M ieta=2 for HO1P/HO2P;
00286       }
00287       //std::cout << "  " << ieta << "  " << zside << "  " << iphi << "  " << depth << "  " << index << std::endl;
00288     }
00289     //std::cout << "eta:  " << ieta << "  side:  " << zside << "  phi:  " << iphi << "  depth:  " << depth << "  index:  " << index << std::endl;
00290 
00291     break;
00292   default: break;
00293  
00294   } // end switch
00295   
00296   return index;
00297 }