File indexing completed on 2024-09-27 07:03:48
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <algorithm>
0011 #include <cmath>
0012
0013 #include "GaudiAlg/GaudiAlgorithm.h"
0014 #include "GaudiAlg/GaudiTool.h"
0015 #include "GaudiAlg/Transformer.h"
0016 #include "GaudiKernel/PhysicalConstants.h"
0017 #include "Gaudi/Property.h"
0018 #include "GaudiKernel/RndmGenerators.h"
0019
0020 #include <k4FWCore/DataHandle.h>
0021 #include "JugBase/IParticleSvc.h"
0022
0023
0024 #include "edm4hep/SimCalorimeterHitCollection.h"
0025
0026
0027 using namespace Gaudi::Units;
0028
0029 namespace Jug::Digi {
0030
0031
0032
0033
0034
0035
0036 class CalorimeterBirksCorr : public GaudiAlgorithm {
0037 public:
0038
0039
0040 Gaudi::Property<double> m_birksConstant{this, "birksConstant", 0.126*mm/MeV};
0041
0042 DataHandle<edm4hep::SimCalorimeterHitCollection> m_inputHitCollection{"inputHitCollection", Gaudi::DataHandle::Reader,
0043 this};
0044 DataHandle<edm4hep::SimCalorimeterHitCollection> m_outputHitCollection{"outputHitCollection", Gaudi::DataHandle::Writer,
0045 this};
0046
0047 SmartIF<IParticleSvc> m_pidSvc;
0048
0049 double birksConstant{0};
0050
0051
0052 CalorimeterBirksCorr(const std::string& name, ISvcLocator* svcLoc)
0053 : GaudiAlgorithm(name, svcLoc)
0054 {
0055 declareProperty("inputHitCollection", m_inputHitCollection, "");
0056 declareProperty("outputHitCollection", m_outputHitCollection, "");
0057 }
0058
0059 StatusCode initialize() override
0060 {
0061 if (GaudiAlgorithm::initialize().isFailure()) {
0062 return StatusCode::FAILURE;
0063 }
0064
0065 m_pidSvc = service("ParticleSvc");
0066 if (!m_pidSvc) {
0067 error() << "Unable to locate Particle Service. "
0068 << "Make sure you have ParticleSvc in the configuration."
0069 << endmsg;
0070 return StatusCode::FAILURE;
0071 }
0072
0073
0074 birksConstant = m_birksConstant.value() / mm * GeV;
0075
0076 return StatusCode::SUCCESS;
0077 }
0078
0079 StatusCode execute() override
0080 {
0081 auto& ohits = *m_outputHitCollection.createAndPut();
0082 for (const auto& hit : *m_inputHitCollection.get()) {
0083 auto ohit = ohits->create(hit.getCellID(), hit.getEnergy(), hit.getPosition());
0084 double energy = 0.;
0085 for (const auto &c: hit.getContributions()) {
0086 ohit.addToContributions(c);
0087 const double charge = m_pidSvc->particle(c.getPDG()).charge;
0088
0089 if (std::abs(charge) > 1e-5) {
0090
0091
0092 error() << "edm4hep::CaloHitContribution has no length field for Birks correction." << endmsg;
0093 return StatusCode::FAILURE;
0094 }
0095 }
0096
0097 ohit.setEnergy(energy);
0098 }
0099 return StatusCode::SUCCESS;
0100 }
0101 };
0102
0103 DECLARE_COMPONENT(CalorimeterBirksCorr)
0104
0105 }