Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 13:03:11

0001 #include "Geometry/HcalCommonData/interface/HcalHitRelabeller.h"
0002 #include "DataFormats/HcalDetId/interface/HcalTestNumbering.h"
0003 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0004 
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 
0007 //#define EDM_ML_DEBUG
0008 
0009 HcalHitRelabeller::HcalHitRelabeller(bool nd) : theRecNumber(nullptr), neutralDensity_(nd) {
0010 #ifdef EDM_ML_DEBUG
0011   edm::LogVerbatim("HcalSim") << "HcalHitRelabeller initialized with"
0012                               << " neutralDensity " << neutralDensity_;
0013 #endif
0014 }
0015 
0016 void HcalHitRelabeller::process(std::vector<PCaloHit>& hcalHits) {
0017   if (theRecNumber) {
0018 #ifdef EDM_ML_DEBUG
0019     int ii(0);
0020 #endif
0021     for (auto& hcalHit : hcalHits) {
0022 #ifdef EDM_ML_DEBUG
0023       edm::LogVerbatim("HcalSim") << "Hit[" << ii << "] " << std::hex << hcalHit.id() << std::dec << " Neutral density "
0024                                   << neutralDensity_;
0025 #endif
0026       double energy = (hcalHit.energy());
0027       if (neutralDensity_) {
0028         energy *= (energyWt(hcalHit.id()));
0029         hcalHit.setEnergy(energy);
0030       }
0031       DetId newid = relabel(hcalHit.id());
0032 #ifdef EDM_ML_DEBUG
0033       edm::LogVerbatim("HcalSim") << "Hit " << ii << " out of " << hcalHits.size() << " " << std::hex << newid.rawId()
0034                                   << std::dec << " E " << energy;
0035 #endif
0036       hcalHit.setID(newid.rawId());
0037 #ifdef EDM_ML_DEBUG
0038       edm::LogVerbatim("HcalSim") << "Modified Hit " << HcalDetId(hcalHit.id());
0039       ++ii;
0040 #endif
0041     }
0042   } else {
0043     edm::LogWarning("HcalSim") << "HcalHitRelabeller: no valid HcalDDDRecConstants";
0044   }
0045 }
0046 
0047 void HcalHitRelabeller::setGeometry(const HcalDDDRecConstants*& recNum) { theRecNumber = recNum; }
0048 
0049 DetId HcalHitRelabeller::relabel(const uint32_t testId) const {
0050   return HcalHitRelabeller::relabel(testId, theRecNumber);
0051 }
0052 
0053 DetId HcalHitRelabeller::relabel(const uint32_t testId, const HcalDDDRecConstants* theRecNumber) {
0054 #ifdef EDM_ML_DEBUG
0055   edm::LogVerbatim("HcalSim") << "Enter HcalHitRelabeller::relabel";
0056 #endif
0057   HcalDetId hid;
0058   int det, z, depth, eta, phi, layer, sign;
0059   HcalTestNumbering::unpackHcalIndex(testId, det, z, depth, eta, phi, layer);
0060 #ifdef EDM_ML_DEBUG
0061   edm::LogVerbatim("HcalSim") << "det: " << det << " "
0062                               << "z: " << z << " "
0063                               << "depth: " << depth << " "
0064                               << "ieta: " << eta << " "
0065                               << "iphi: " << phi << " "
0066                               << "layer: " << layer;
0067 #endif
0068   sign = (z == 0) ? (-1) : (1);
0069   HcalDDDRecConstants::HcalID id = theRecNumber->getHCID(det, sign * eta, phi, layer, depth);
0070 
0071   if (id.subdet == int(HcalBarrel)) {
0072     hid = HcalDetId(HcalBarrel, sign * id.eta, id.phi, id.depth);
0073   } else if (id.subdet == int(HcalEndcap)) {
0074     hid = HcalDetId(HcalEndcap, sign * id.eta, id.phi, id.depth);
0075   } else if (id.subdet == int(HcalOuter)) {
0076     hid = HcalDetId(HcalOuter, sign * id.eta, id.phi, id.depth);
0077   } else if (id.subdet == int(HcalForward)) {
0078     hid = HcalDetId(HcalForward, sign * id.eta, id.phi, id.depth);
0079   }
0080 #ifdef EDM_ML_DEBUG
0081   edm::LogVerbatim("HcalSim") << " new HcalDetId -> hex.RawID = " << std::hex << hid.rawId() << std::dec
0082                               << " det, z, depth, eta, phi = " << det << " " << z << " " << id.depth << " " << id.eta
0083                               << " " << id.phi << " ---> " << hid;
0084 #endif
0085   return hid;
0086 }
0087 
0088 double HcalHitRelabeller::energyWt(const uint32_t testId) const {
0089   int det, z, depth, eta, phi, layer;
0090   HcalTestNumbering::unpackHcalIndex(testId, det, z, depth, eta, phi, layer);
0091   int zside = (z == 0) ? (-1) : (1);
0092   double wt = (((det == 1) || (det == 2)) && (depth == 1)) ? theRecNumber->getLayer0Wt(det, phi, zside) : 1.0;
0093 #ifdef EDM_ML_DEBUG
0094   edm::LogVerbatim("HcalSim") << "EnergyWT::det: " << det << " z: " << z << ":" << zside << " depth: " << depth
0095                               << " ieta: " << eta << " iphi: " << phi << " layer: " << layer << " wt " << wt;
0096 #endif
0097   return wt;
0098 }