CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/RecoMET/METAlgorithms/src/HcalHPDRBXMap.cc

Go to the documentation of this file.
00001 //
00002 // HcalHPDRBXMap.cc
00003 //
00004 //   description: implementation of HcalHPDRBXMap.
00005 //
00006 //   author: J.P. Chou, Brown
00007 //
00008 
00009 #include "RecoMET/METAlgorithms/interface/HcalHPDRBXMap.h"
00010 #include "FWCore/Utilities/interface/EDMException.h"
00011 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
00012 
00013 // static class member declaration
00014 HcalTopology HcalHPDRBXMap::theTopology_;
00015 
00016 
00017 // empty constructor/destructor
00018 HcalHPDRBXMap::HcalHPDRBXMap() {}
00019 HcalHPDRBXMap::~HcalHPDRBXMap() {}
00020 
00021 // returns if the HPD index is valid
00022 bool HcalHPDRBXMap::isValidHPD(int index)
00023 {
00024   return (index>=0 && index<=NUM_HPDS-1);
00025 }
00026 
00027 // returns if the RBX index is valid
00028 bool HcalHPDRBXMap::isValidRBX(int index)
00029 {
00030   return (index>=0 && index<=NUM_RBXS-1);
00031 }
00032 
00033 bool HcalHPDRBXMap::isValid(const HcalDetId& id)
00034 {
00035   if(id.subdet()!=HcalBarrel && id.subdet()!=HcalEndcap) return false;
00036   if(theTopology_.valid(id)) return true;
00037   else return false;
00038 }
00039 
00040 bool HcalHPDRBXMap::isValid(int ieta, int iphi)
00041 {
00042   int absieta=abs(ieta);
00043   if(absieta<=29 && absieta>=1 && iphi>=1 && iphi<=72) {
00044     if(absieta<=20) return true;
00045     if(absieta>=21 && iphi%2==1) return true;
00046   }
00047   return false;
00048 }
00049 
00050 // returns the subdetector (HE or HE) for an HPD index
00051 HcalSubdetector HcalHPDRBXMap::subdetHPD(int index)
00052 {
00053   if(!isValidHPD(index))
00054     throw edm::Exception(edm::errors::LogicError)
00055       << " HPD index " << index << " is invalid in HcalHPDRBXMap::subdetHPD().\n";
00056 
00057   if(index/NUM_HPDS_PER_SUBDET<=1) return HcalBarrel;
00058   else return HcalEndcap;
00059 }
00060 
00061 // returns the subdetector (HE or HE) for an RBX index
00062 HcalSubdetector HcalHPDRBXMap::subdetRBX(int index)
00063 {
00064   if(!isValidRBX(index))
00065     throw edm::Exception(edm::errors::LogicError)
00066       << " RBX index " << index << " is invalid in HcalHPDRBXMap::subdetRBX().\n";
00067 
00068   if(index/NUM_RBXS_PER_SUBDET<=1) return HcalBarrel;
00069   else return HcalEndcap;
00070 }
00071 
00072 // returns the zside (1 or -1) given an HPD index
00073 int HcalHPDRBXMap::zsideHPD(int index)
00074 {
00075   if(!isValidHPD(index))
00076     throw edm::Exception(edm::errors::LogicError)
00077       << " HPD index " << index << " is invalid in HcalHPDRBXMap::zsideHPD().\n";
00078 
00079   if(index/NUM_HPDS_PER_SUBDET==0 || index/NUM_HPDS_PER_SUBDET==2) return 1;
00080   else return -1;
00081 }
00082 
00083 // returns the zside (1 or -1) given an RBX index
00084 int HcalHPDRBXMap::zsideRBX(int index)
00085 {
00086   if(!isValidRBX(index))
00087     throw edm::Exception(edm::errors::LogicError)
00088       << " RBX index " << index << " is invalid in HcalHPDRBXMap::zsideRBX().\n";
00089 
00090   if(index/NUM_RBXS_PER_SUBDET==0 || index/NUM_RBXS_PER_SUBDET==2) return 1;
00091   else return -1;
00092 }
00093 
00094 // returns the lowest iphi used in an HPD
00095 int HcalHPDRBXMap::iphiloHPD(int index)
00096 {
00097   if(!isValidHPD(index))
00098     throw edm::Exception(edm::errors::LogicError)
00099       << " HPD index " << index << " is invalid in HcalHPDRBXMap::iphiloHPD().\n";
00100   
00101   // adjust for offset between iphi and the HPD index
00102   // index-->iphi
00103   // 0-->71, 1-->72, 2-->1, 3-->2, 4-->3, ..., 70-->69, 71-->70
00104   int iphi=index%NUM_HPDS_PER_SUBDET-1;
00105   if(iphi<=0) iphi+=NUM_HPDS_PER_SUBDET;
00106 
00107   // HB
00108   if(subdetHPD(index)==HcalBarrel) return iphi;
00109 
00110   // HE
00111   if(iphi%2==0) return iphi-1;
00112   else          return iphi;
00113 }
00114 
00115 // returns the lowest iphi used in an RBX
00116 int HcalHPDRBXMap::iphiloRBX(int index)
00117 {
00118   if(!isValidRBX(index))
00119     throw edm::Exception(edm::errors::LogicError)
00120       << " RBX index " << index << " is invalid in HcalHPDRBXMap::iphiloRBX().\n";
00121 
00122   // get the list of HPD indices in the RBX
00123   boost::array<int, NUM_HPDS_PER_RBX> arr;
00124   indicesHPDfromRBX(index, arr);
00125 
00126   // return the lowest iphi of the first HPD
00127   return iphiloHPD(arr[0]);
00128 }
00129 
00130 // returns the highest iphi used in an HPD
00131 int HcalHPDRBXMap::iphihiHPD(int index)
00132 {
00133   if(!isValidHPD(index))
00134     throw edm::Exception(edm::errors::LogicError)
00135       << " HPD index " << index << " is invalid in HcalHPDRBXMap::iphihiHPD().\n";
00136   
00137   // adjust for offset between iphi and the HPD index
00138   // index-->iphi
00139   // 0-->71, 1-->72, 2-->1, 3-->2, 4-->3, ..., 70-->69, 71-->70
00140   int iphi=index%NUM_HPDS_PER_SUBDET-1;
00141   if(iphi<=0) iphi+=NUM_HPDS_PER_SUBDET;
00142 
00143   // HB
00144   if(subdetHPD(index)==HcalBarrel) return iphi;
00145 
00146   // HE
00147   if(iphi%2==0) return iphi;
00148   else          return iphi+1;
00149 }
00150 
00151 // returns the highest iphi used in an RBX
00152 int HcalHPDRBXMap::iphihiRBX(int index)
00153 {
00154   if(!isValidRBX(index))
00155     throw edm::Exception(edm::errors::LogicError)
00156       << " RBX index " << index << " is invalid in HcalHPDRBXMap::iphihiRBX().\n";
00157   
00158   // get the list of HPD indices in the RBX
00159   boost::array<int, NUM_HPDS_PER_RBX> arr;
00160   indicesHPDfromRBX(index, arr);
00161 
00162   // return the highest iphi of the last HPD
00163   return iphihiHPD(arr[NUM_HPDS_PER_RBX-1]);
00164 }
00165 
00166 
00167 // returns the list of HPD indices found in a given RBX
00168 void HcalHPDRBXMap::indicesHPDfromRBX(int rbxindex, boost::array<int, NUM_HPDS_PER_RBX>& hpdindices)
00169 {
00170   if(!isValidRBX(rbxindex))
00171     throw edm::Exception(edm::errors::LogicError)
00172       << " RBX index " << rbxindex << " is invalid in HcalHPDRBXMap::indicesHPD().\n";
00173 
00174   for(unsigned int i=0; i<hpdindices.size(); i++)
00175     hpdindices[i]=rbxindex*NUM_HPDS_PER_RBX+i;
00176 
00177   return;
00178 }
00179 
00180 // returns the RBX index given an HPD index
00181 int HcalHPDRBXMap::indexRBXfromHPD(int hpdindex)
00182 {
00183   if(!isValidHPD(hpdindex))
00184     throw edm::Exception(edm::errors::LogicError)
00185       << " HPD index " << hpdindex << " is invalid in HcalHPDRBXMap::indexRBX().\n";
00186 
00187   return hpdindex/NUM_HPDS_PER_RBX;
00188 }
00189 
00190 
00191 // get the HPD index from an HcalDetector id
00192 int HcalHPDRBXMap::indexHPD(const HcalDetId& id)
00193 {
00194   // return bad index if subdetector is invalid
00195   if(!isValid(id)) {
00196     throw edm::Exception(edm::errors::LogicError)
00197       << " HcalDetId " << id << " is invalid in HcalHPDRBXMap::indexHPD().\n";
00198   }
00199 
00200   // specify the readout module (subdet and number)
00201   int subdet=-1;
00202   if(id.subdet()==HcalBarrel && id.zside()==1)  subdet=0;
00203   if(id.subdet()==HcalBarrel && id.zside()==-1) subdet=1;
00204   if(id.subdet()==HcalEndcap && id.zside()==1)  subdet=2;
00205   if(id.subdet()==HcalEndcap && id.zside()==-1) subdet=3;
00206 
00207   int iphi=id.iphi();
00208   int absieta=abs(id.ieta());
00209 
00210   // adjust for offset between iphi and the HPD index
00211   // index-->iphi
00212   // 0-->71, 1-->72, 2-->1, 3-->2, 4-->3, ..., 70-->69, 71-->70
00213   int index=iphi+1;
00214   if(index>=NUM_HPDS_PER_SUBDET) index-=NUM_HPDS_PER_SUBDET;
00215   index+=subdet*NUM_HPDS_PER_SUBDET;
00216 
00217   // modify the index in the HE
00218   if((subdet==2 || subdet==3) && absieta>=21 && absieta<=29) {
00219     if(iphi%4==3 && absieta%2==1 && absieta!=29) index++;
00220     if(iphi%4==3 && absieta==29 && id.depth()==2) index++;
00221     if(iphi%4==1 && absieta%2==0 && absieta!=29) index++;
00222     if(iphi%4==1 && absieta==29 && id.depth()==1) index++;
00223   }
00224   return index;
00225 }
00226 
00227 int HcalHPDRBXMap::indexRBX(const HcalDetId& id)
00228 {
00229   return indexRBXfromHPD(indexHPD(id));
00230 }
00231 
00232 void HcalHPDRBXMap::indexHPDfromEtaPhi(int ieta, int iphi, std::vector<int>& hpdindices)
00233 {
00234   // clear the vector
00235   hpdindices.clear();
00236   int absieta=abs(ieta);
00237 
00238   if(absieta<=15) {        // HB only, depth doesn't matter
00239     hpdindices.push_back(indexHPD(HcalDetId(HcalBarrel, ieta, iphi, 1)));
00240   } else if(absieta==16) { // HB and HE, depth doesn't matter
00241     hpdindices.push_back(indexHPD(HcalDetId(HcalBarrel, ieta, iphi, 1)));
00242     hpdindices.push_back(indexHPD(HcalDetId(HcalEndcap, ieta, iphi, 3)));
00243   } else if(absieta<29) {  // HE only, depth doesn't matter
00244     hpdindices.push_back(indexHPD(HcalDetId(HcalEndcap, ieta, iphi, 1)));
00245   } else {                 // HE only, but depth matters
00246     hpdindices.push_back(indexHPD(HcalDetId(HcalEndcap, ieta, iphi, 1)));
00247     hpdindices.push_back(indexHPD(HcalDetId(HcalEndcap, ieta, iphi, 2)));
00248   }
00249 
00250   return;
00251 }
00252 
00253 void HcalHPDRBXMap::indexRBXfromEtaPhi(int ieta, int iphi, std::vector<int>& rbxindices)
00254 {
00255   // clear the vector
00256   rbxindices.clear();
00257   int absieta=abs(ieta);
00258 
00259   if(absieta<=15) {        // HB only
00260     rbxindices.push_back(indexRBX(HcalDetId(HcalBarrel, ieta, iphi, 1)));
00261   } else if(absieta==16) { // HB and HE
00262     rbxindices.push_back(indexRBX(HcalDetId(HcalBarrel, ieta, iphi, 1)));
00263     rbxindices.push_back(indexRBX(HcalDetId(HcalEndcap, ieta, iphi, 3)));
00264   } else {                 // HE only
00265     rbxindices.push_back(indexRBX(HcalDetId(HcalEndcap, ieta, iphi, 1)));
00266   }
00267 
00268   return;
00269 }