File indexing completed on 2025-07-10 08:57:26
0001
0002
0003
0004 #include <algorithm>
0005
0006
0007 #include "Gaudi/Algorithm.h"
0008
0009 #include "Gaudi/Property.h"
0010 #include "GaudiKernel/RndmGenerators.h"
0011
0012 #include "DD4hep/DD4hepUnits.h"
0013 #include "DDRec/CellIDPositionConverter.h"
0014 #include "DDRec/Surface.h"
0015 #include "DDRec/SurfaceManager.h"
0016
0017 #include <k4FWCore/DataHandle.h>
0018 #include <k4Interface/IGeoSvc.h>
0019
0020
0021
0022 #include "edm4eic/RawTrackerHitCollection.h"
0023 #include "edm4eic/TrackerHitCollection.h"
0024
0025 #include "DD4hep/DD4hepUnits.h"
0026
0027 namespace {
0028 inline double get_resolution(const double pixel_size) {
0029 constexpr const double sqrt_12 = 3.4641016151;
0030 return pixel_size / sqrt_12;
0031 }
0032 inline double get_variance(const double pixel_size) {
0033 const double res = get_resolution(pixel_size);
0034 return res * res;
0035 }
0036 }
0037
0038 namespace Jug::Reco {
0039
0040
0041
0042
0043
0044 class TrackerHitReconstruction : public Gaudi::Algorithm {
0045 private:
0046 Gaudi::Property<float> m_timeResolution{this, "timeResolution", 10};
0047 mutable DataHandle<edm4eic::RawTrackerHitCollection> m_inputHitCollection{"inputHitCollection", Gaudi::DataHandle::Reader,
0048 this};
0049 mutable DataHandle<edm4eic::TrackerHitCollection> m_outputHitCollection{"outputHitCollection", Gaudi::DataHandle::Writer,
0050 this};
0051
0052
0053 SmartIF<IGeoSvc> m_geoSvc;
0054 std::shared_ptr<const dd4hep::rec::CellIDPositionConverter> m_converter;
0055
0056 public:
0057
0058 TrackerHitReconstruction(const std::string& name, ISvcLocator* svcLoc) : Gaudi::Algorithm(name, svcLoc) {
0059 declareProperty("inputHitCollection", m_inputHitCollection, "");
0060 declareProperty("outputHitCollection", m_outputHitCollection, "");
0061 }
0062
0063 StatusCode initialize() override {
0064 if (Gaudi::Algorithm::initialize().isFailure()) {
0065 return StatusCode::FAILURE;
0066 }
0067 m_geoSvc = service("GeoSvc");
0068 if (!m_geoSvc) {
0069 error() << "Unable to locate Geometry Service. "
0070 << "Make sure you have GeoSvc and SimSvc in the right order in the configuration." << endmsg;
0071 return StatusCode::FAILURE;
0072 }
0073 m_converter = std::make_shared<const dd4hep::rec::CellIDPositionConverter>(*(m_geoSvc->getDetector()));
0074 return StatusCode::SUCCESS;
0075 }
0076
0077 StatusCode execute(const EventContext&) const override {
0078 constexpr auto mm = dd4hep::mm;
0079
0080 const auto* const rawhits = m_inputHitCollection.get();
0081
0082 auto* rec_hits = m_outputHitCollection.createAndPut();
0083
0084 debug() << " raw hits size : " << std::size(*rawhits) << endmsg;
0085 for (const auto& ahit : *rawhits) {
0086
0087 auto pos = m_converter->position(ahit.getCellID());
0088 auto dim = m_converter->cellDimensions(ahit.getCellID());
0089
0090 if (msgLevel(MSG::VERBOSE)) {
0091 size_t i = 0;
0092 for (const auto& p : {pos.x(), pos.y(), pos.z()}) {
0093 verbose() << "position " << i++ << " [mm]: " << p / mm << endmsg;
0094 }
0095 verbose() << "dimension size: " << std::size(dim) << endmsg;
0096 for (size_t j = 0; j < std::size(dim); ++j) {
0097 verbose() << " - dimension " << j << " size: " << dim[j] << endmsg;
0098 }
0099 }
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109 rec_hits->create(
0110 ahit.getCellID(),
0111 edm4hep::Vector3f{static_cast<float>(pos.x() / mm), static_cast<float>(pos.y() / mm), static_cast<float>(pos.z() / mm)},
0112 edm4eic::CovDiag3f{get_variance(dim[0] / mm), get_variance(dim[1] / mm),
0113 std::size(dim) > 2 ? get_variance(dim[2] / mm) : 0.},
0114 static_cast<float>(ahit.getTimeStamp() / 1000),
0115 m_timeResolution,
0116 static_cast<float>(ahit.getCharge() / 1.0e6),
0117 0.0F
0118 );
0119 }
0120 return StatusCode::SUCCESS;
0121 }
0122 };
0123
0124 DECLARE_COMPONENT(TrackerHitReconstruction)
0125
0126 }