Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:25:28

0001 //

0002 // HcalHPDRBXMap.cc

0003 //

0004 //   description: implementation of HcalHPDRBXMap.

0005 //

0006 //   author: J.P. Chou, Brown

0007 //

0008 
0009 #include "RecoMET/METAlgorithms/interface/HcalHPDRBXMap.h"
0010 #include "FWCore/Utilities/interface/EDMException.h"
0011 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
0012 
0013 // empty constructor/destructor

0014 HcalHPDRBXMap::HcalHPDRBXMap() {}
0015 HcalHPDRBXMap::~HcalHPDRBXMap() {}
0016 
0017 // returns if the HPD index is valid

0018 bool HcalHPDRBXMap::isValidHPD(int index) { return (index >= 0 && index <= NUM_HPDS - 1); }
0019 
0020 // returns if the RBX index is valid

0021 bool HcalHPDRBXMap::isValidRBX(int index) { return (index >= 0 && index <= NUM_RBXS - 1); }
0022 
0023 bool HcalHPDRBXMap::isValid(const HcalDetId& id) {
0024   if (id.subdet() != HcalBarrel && id.subdet() != HcalEndcap)
0025     return false;
0026   return isValid(id.ieta(), id.iphi());
0027 }
0028 
0029 bool HcalHPDRBXMap::isValid(int ieta, int iphi) {
0030   int absieta = abs(ieta);
0031   if (absieta <= 29 && absieta >= 1 && iphi >= 1 && iphi <= 72) {
0032     if (absieta <= 20)
0033       return true;
0034     if (absieta >= 21 && iphi % 2 == 1)
0035       return true;
0036   }
0037   return false;
0038 }
0039 
0040 // returns the subdetector (HE or HE) for an HPD index

0041 HcalSubdetector HcalHPDRBXMap::subdetHPD(int index) {
0042   if (!isValidHPD(index))
0043     throw edm::Exception(edm::errors::LogicError)
0044         << " HPD index " << index << " is invalid in HcalHPDRBXMap::subdetHPD().\n";
0045 
0046   if (index / NUM_HPDS_PER_SUBDET <= 1)
0047     return HcalBarrel;
0048   else
0049     return HcalEndcap;
0050 }
0051 
0052 // returns the subdetector (HE or HE) for an RBX index

0053 HcalSubdetector HcalHPDRBXMap::subdetRBX(int index) {
0054   if (!isValidRBX(index))
0055     throw edm::Exception(edm::errors::LogicError)
0056         << " RBX index " << index << " is invalid in HcalHPDRBXMap::subdetRBX().\n";
0057 
0058   if (index / NUM_RBXS_PER_SUBDET <= 1)
0059     return HcalBarrel;
0060   else
0061     return HcalEndcap;
0062 }
0063 
0064 // returns the zside (1 or -1) given an HPD index

0065 int HcalHPDRBXMap::zsideHPD(int index) {
0066   if (!isValidHPD(index))
0067     throw edm::Exception(edm::errors::LogicError)
0068         << " HPD index " << index << " is invalid in HcalHPDRBXMap::zsideHPD().\n";
0069 
0070   if (index / NUM_HPDS_PER_SUBDET == 0 || index / NUM_HPDS_PER_SUBDET == 2)
0071     return 1;
0072   else
0073     return -1;
0074 }
0075 
0076 // returns the zside (1 or -1) given an RBX index

0077 int HcalHPDRBXMap::zsideRBX(int index) {
0078   if (!isValidRBX(index))
0079     throw edm::Exception(edm::errors::LogicError)
0080         << " RBX index " << index << " is invalid in HcalHPDRBXMap::zsideRBX().\n";
0081 
0082   if (index / NUM_RBXS_PER_SUBDET == 0 || index / NUM_RBXS_PER_SUBDET == 2)
0083     return 1;
0084   else
0085     return -1;
0086 }
0087 
0088 // returns the lowest iphi used in an HPD

0089 int HcalHPDRBXMap::iphiloHPD(int index) {
0090   if (!isValidHPD(index))
0091     throw edm::Exception(edm::errors::LogicError)
0092         << " HPD index " << index << " is invalid in HcalHPDRBXMap::iphiloHPD().\n";
0093 
0094   // adjust for offset between iphi and the HPD index

0095   // index-->iphi

0096   // 0-->71, 1-->72, 2-->1, 3-->2, 4-->3, ..., 70-->69, 71-->70

0097   int iphi = index % NUM_HPDS_PER_SUBDET - 1;
0098   if (iphi <= 0)
0099     iphi += NUM_HPDS_PER_SUBDET;
0100 
0101   // HB

0102   if (subdetHPD(index) == HcalBarrel)
0103     return iphi;
0104 
0105   // HE

0106   if (iphi % 2 == 0)
0107     return iphi - 1;
0108   else
0109     return iphi;
0110 }
0111 
0112 // returns the lowest iphi used in an RBX

0113 int HcalHPDRBXMap::iphiloRBX(int index) {
0114   if (!isValidRBX(index))
0115     throw edm::Exception(edm::errors::LogicError)
0116         << " RBX index " << index << " is invalid in HcalHPDRBXMap::iphiloRBX().\n";
0117 
0118   // get the list of HPD indices in the RBX

0119   std::array<int, NUM_HPDS_PER_RBX> arr;
0120   indicesHPDfromRBX(index, arr);
0121 
0122   // return the lowest iphi of the first HPD

0123   return iphiloHPD(arr[0]);
0124 }
0125 
0126 // returns the highest iphi used in an HPD

0127 int HcalHPDRBXMap::iphihiHPD(int index) {
0128   if (!isValidHPD(index))
0129     throw edm::Exception(edm::errors::LogicError)
0130         << " HPD index " << index << " is invalid in HcalHPDRBXMap::iphihiHPD().\n";
0131 
0132   // adjust for offset between iphi and the HPD index

0133   // index-->iphi

0134   // 0-->71, 1-->72, 2-->1, 3-->2, 4-->3, ..., 70-->69, 71-->70

0135   int iphi = index % NUM_HPDS_PER_SUBDET - 1;
0136   if (iphi <= 0)
0137     iphi += NUM_HPDS_PER_SUBDET;
0138 
0139   // HB

0140   if (subdetHPD(index) == HcalBarrel)
0141     return iphi;
0142 
0143   // HE

0144   if (iphi % 2 == 0)
0145     return iphi;
0146   else
0147     return iphi + 1;
0148 }
0149 
0150 // returns the highest iphi used in an RBX

0151 int HcalHPDRBXMap::iphihiRBX(int index) {
0152   if (!isValidRBX(index))
0153     throw edm::Exception(edm::errors::LogicError)
0154         << " RBX index " << index << " is invalid in HcalHPDRBXMap::iphihiRBX().\n";
0155 
0156   // get the list of HPD indices in the RBX

0157   std::array<int, NUM_HPDS_PER_RBX> arr;
0158   indicesHPDfromRBX(index, arr);
0159 
0160   // return the highest iphi of the last HPD

0161   return iphihiHPD(arr[NUM_HPDS_PER_RBX - 1]);
0162 }
0163 
0164 // returns the list of HPD indices found in a given RBX

0165 void HcalHPDRBXMap::indicesHPDfromRBX(int rbxindex, std::array<int, NUM_HPDS_PER_RBX>& hpdindices) {
0166   if (!isValidRBX(rbxindex))
0167     throw edm::Exception(edm::errors::LogicError)
0168         << " RBX index " << rbxindex << " is invalid in HcalHPDRBXMap::indicesHPD().\n";
0169 
0170   for (unsigned int i = 0; i < hpdindices.size(); i++)
0171     hpdindices[i] = rbxindex * NUM_HPDS_PER_RBX + i;
0172 
0173   return;
0174 }
0175 
0176 // returns the RBX index given an HPD index

0177 int HcalHPDRBXMap::indexRBXfromHPD(int hpdindex) {
0178   if (!isValidHPD(hpdindex))
0179     throw edm::Exception(edm::errors::LogicError)
0180         << " HPD index " << hpdindex << " is invalid in HcalHPDRBXMap::indexRBX().\n";
0181 
0182   return hpdindex / NUM_HPDS_PER_RBX;
0183 }
0184 
0185 // get the HPD index from an HcalDetector id

0186 int HcalHPDRBXMap::indexHPD(const HcalDetId& id) {
0187   // return bad index if subdetector is invalid

0188   if (!isValid(id)) {
0189     throw edm::Exception(edm::errors::LogicError)
0190         << " HcalDetId " << id << " is invalid in HcalHPDRBXMap::indexHPD().\n";
0191   }
0192 
0193   // specify the readout module (subdet and number)

0194   int subdet = -1;
0195   if (id.subdet() == HcalBarrel && id.zside() == 1)
0196     subdet = 0;
0197   if (id.subdet() == HcalBarrel && id.zside() == -1)
0198     subdet = 1;
0199   if (id.subdet() == HcalEndcap && id.zside() == 1)
0200     subdet = 2;
0201   if (id.subdet() == HcalEndcap && id.zside() == -1)
0202     subdet = 3;
0203 
0204   int iphi = id.iphi();
0205   int absieta = abs(id.ieta());
0206 
0207   // adjust for offset between iphi and the HPD index

0208   // index-->iphi

0209   // 0-->71, 1-->72, 2-->1, 3-->2, 4-->3, ..., 70-->69, 71-->70

0210   int index = iphi + 1;
0211   if (index >= NUM_HPDS_PER_SUBDET)
0212     index -= NUM_HPDS_PER_SUBDET;
0213   index += subdet * NUM_HPDS_PER_SUBDET;
0214 
0215   // modify the index in the HE

0216   if ((subdet == 2 || subdet == 3) && absieta >= 21 && absieta <= 29) {
0217     if (iphi % 4 == 3 && absieta % 2 == 1 && absieta != 29)
0218       index++;
0219     if (iphi % 4 == 3 && absieta == 29 && id.depth() == 2)
0220       index++;
0221     if (iphi % 4 == 1 && absieta % 2 == 0 && absieta != 29)
0222       index++;
0223     if (iphi % 4 == 1 && absieta == 29 && id.depth() == 1)
0224       index++;
0225   }
0226   return index;
0227 }
0228 
0229 int HcalHPDRBXMap::indexRBX(const HcalDetId& id) { return indexRBXfromHPD(indexHPD(id)); }
0230 
0231 void HcalHPDRBXMap::indexHPDfromEtaPhi(int ieta, int iphi, std::vector<int>& hpdindices) {
0232   // clear the vector

0233   hpdindices.clear();
0234   int absieta = abs(ieta);
0235 
0236   if (absieta <= 15) {  // HB only, depth doesn't matter

0237     hpdindices.push_back(indexHPD(HcalDetId(HcalBarrel, ieta, iphi, 1)));
0238   } else if (absieta == 16) {  // HB and HE, depth doesn't matter

0239     hpdindices.push_back(indexHPD(HcalDetId(HcalBarrel, ieta, iphi, 1)));
0240     hpdindices.push_back(indexHPD(HcalDetId(HcalEndcap, ieta, iphi, 3)));
0241   } else if (absieta < 29) {  // HE only, depth doesn't matter

0242     hpdindices.push_back(indexHPD(HcalDetId(HcalEndcap, ieta, iphi, 1)));
0243   } else {  // HE only, but depth matters

0244     hpdindices.push_back(indexHPD(HcalDetId(HcalEndcap, ieta, iphi, 1)));
0245     hpdindices.push_back(indexHPD(HcalDetId(HcalEndcap, ieta, iphi, 2)));
0246   }
0247 
0248   return;
0249 }
0250 
0251 void HcalHPDRBXMap::indexRBXfromEtaPhi(int ieta, int iphi, std::vector<int>& rbxindices) {
0252   // clear the vector

0253   rbxindices.clear();
0254   int absieta = abs(ieta);
0255 
0256   if (absieta <= 15) {  // HB only

0257     rbxindices.push_back(indexRBX(HcalDetId(HcalBarrel, ieta, iphi, 1)));
0258   } else if (absieta == 16) {  // HB and HE

0259     rbxindices.push_back(indexRBX(HcalDetId(HcalBarrel, ieta, iphi, 1)));
0260     rbxindices.push_back(indexRBX(HcalDetId(HcalEndcap, ieta, iphi, 3)));
0261   } else {  // HE only

0262     rbxindices.push_back(indexRBX(HcalDetId(HcalEndcap, ieta, iphi, 1)));
0263   }
0264 
0265   return;
0266 }