CMS 3D CMS Logo

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