CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/DataFormats/L1CaloTrigger/src/L1CaloRegionDetId.cc

Go to the documentation of this file.
00001 
00002 
00003 #include "DataFormats/L1CaloTrigger/interface/L1CaloRegionDetId.h"
00004 
00005 unsigned const L1CaloRegionDetId::N_PHI=18;
00006 unsigned const L1CaloRegionDetId::N_ETA=22;
00007 
00008 
00009 // default constructor - null DetId
00010 L1CaloRegionDetId::L1CaloRegionDetId() : DetId() { }
00011 
00012 
00013 // construct from raw id
00014 L1CaloRegionDetId::L1CaloRegionDetId(uint32_t rawid) : DetId(rawid) { }
00015 
00016 
00017 // construct from ieta, iphi indices
00018 // ieta runs from 0 (at -z) to 21 (at +z)
00019 L1CaloRegionDetId::L1CaloRegionDetId(unsigned ieta, unsigned iphi) :
00020   DetId(Calo, 2) 
00021 { 
00022   id_ |= (ieta & 0x1f) | ((iphi & 0x1f)<<5);
00023 }
00024 
00025 
00026 // construct from RCT crate, card, region IDs
00027 L1CaloRegionDetId::L1CaloRegionDetId(unsigned icrate, unsigned icard, unsigned irgn) :
00028   DetId(Calo, 2)
00029 {
00030 
00031   int ieta=0;
00032   int iphi=0;
00033 
00034   // Calculate iphi
00035   int phi_index = icrate % 9;
00036   if ((icard == 0) || (icard == 2) || (icard == 4))
00037     phi_index = phi_index * 2;
00038   else if ((icard == 1) || (icard == 3) || (icard == 5))
00039     phi_index = phi_index * 2 + 1;
00040   else if (icard == 6)
00041     phi_index = phi_index * 2 + irgn;
00042   // for HF
00043   else if (icard == 999)
00044     phi_index = phi_index * 2 + (irgn/4);
00045   iphi = (22 - phi_index) % 18;
00046 
00047   // Calculate ieta
00048   int eta_index = 0;
00049   if (icard < 6)
00050     eta_index = (icard/2) * 2 + irgn;
00051   else if (icard == 6)
00052     eta_index = 6;
00053   // HF
00054   else if (icard == 999)
00055     eta_index = (irgn % 4) + 7;
00056   
00057   if (icrate < 9)
00058     ieta = 10 - eta_index;
00059   else if (icrate >= 9)
00060     ieta = 11 + eta_index;
00061 
00063   id_ |= (ieta & 0x1f) | ((iphi & 0x1f)<<5);
00064 }
00065 
00066 // return RCT crate ID
00067 unsigned L1CaloRegionDetId::rctCrate() const { // TODO - check this is correct!
00068   unsigned phiCrate = ((N_PHI + 4 - iphi()) % N_PHI) / 2;
00069   return (ieta()<(N_ETA/2) ? phiCrate : phiCrate + N_PHI/2) ;
00070 }
00071 
00072 // return RCT card number
00073 unsigned L1CaloRegionDetId::rctCard() const {
00074   unsigned card = 999;
00075   unsigned rct_phi_index = (22 - iphi()) % 18;
00076   if ((ieta() == 4) || (ieta() == 17)){
00077     card = 6;
00078   }
00079   else if ((ieta() > 4) && (ieta() <= 10)){
00080     unsigned index = (ieta() - 5)/2;
00081     card = ((2 - index) * 2) + (rct_phi_index % 2);
00082   }
00083   else if ((ieta() >= 11) && (ieta() < 17)){
00084     unsigned index = (ieta() - 11)/2;
00085     card = (index * 2) + (rct_phi_index % 2);
00086   }
00087   return card;
00088 }
00089 
00090 // return RCT region number
00091 unsigned L1CaloRegionDetId::rctRegion() const {
00092   unsigned rgn = 999;
00093   unsigned rct_phi_index = (22 - iphi()) % 18;
00094   if (ieta() < 4){
00095     rgn = (3 - ieta()) + 4 * (rct_phi_index % 2);
00096   }
00097   else if (ieta() > 17){
00098     rgn = (ieta() - 18) + 4 * (rct_phi_index % 2);
00099   }
00100   else if ((ieta() == 4) || (ieta() == 17)){
00101     rgn = (rct_phi_index % 2);
00102   }
00103   else if ((ieta() > 4) && (ieta() <= 10)){
00104     rgn = (ieta() % 2);
00105   }
00106   else if ((ieta() >= 11) && (ieta() < 17)){
00107     rgn = ((ieta() - 1) % 2);
00108   }
00109   return rgn;
00110 }