File indexing completed on 2024-09-28 07:02:58
0001
0002
0003
0004 #include "TrackerHitReconstruction.h"
0005
0006 #include <Evaluator/DD4hepUnits.h>
0007 #include <Math/GenVector/Cartesian3D.h>
0008 #include <Math/GenVector/DisplacementVector3D.h>
0009 #include <edm4eic/CovDiag3f.h>
0010 #include <edm4eic/EDM4eicVersion.h>
0011 #include <edm4hep/Vector3f.h>
0012 #include <fmt/core.h>
0013 #include <spdlog/common.h>
0014 #include <stddef.h>
0015 #include <iterator>
0016 #include <utility>
0017 #include <vector>
0018
0019 namespace eicrecon {
0020
0021 namespace {
0022 inline double get_resolution(const double pixel_size) {
0023 constexpr const double sqrt_12 = 3.4641016151;
0024 return pixel_size / sqrt_12;
0025 }
0026 inline double get_variance(const double pixel_size) {
0027 const double res = get_resolution(pixel_size);
0028 return res * res;
0029 }
0030 }
0031
0032 void TrackerHitReconstruction::init(const dd4hep::rec::CellIDPositionConverter* converter, std::shared_ptr<spdlog::logger>& logger) {
0033
0034 m_log = logger;
0035
0036 m_converter = converter;
0037 }
0038
0039 std::unique_ptr<edm4eic::TrackerHitCollection> TrackerHitReconstruction::process(const edm4eic::RawTrackerHitCollection& raw_hits) {
0040 using dd4hep::mm;
0041
0042 auto rec_hits { std::make_unique<edm4eic::TrackerHitCollection>() };
0043
0044 for (const auto& raw_hit : raw_hits) {
0045
0046 auto id = raw_hit.getCellID();
0047
0048
0049 auto pos = m_converter->position(id);
0050 auto dim = m_converter->cellDimensions(id);
0051
0052
0053 if(m_log->level() == spdlog::level::trace) {
0054 m_log->trace("position x={:.2f} y={:.2f} z={:.2f} [mm]: ", pos.x()/ mm, pos.y()/ mm, pos.z()/ mm);
0055 m_log->trace("dimension size: {}", dim.size());
0056 for (size_t j = 0; j < std::size(dim); ++j) {
0057 m_log->trace(" - dimension {:<5} size: {:.2}", j, dim[j]);
0058 }
0059 }
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070 #if EDM4EIC_VERSION_MAJOR >= 7
0071 auto rec_hit =
0072 #endif
0073 rec_hits->create(
0074 raw_hit.getCellID(),
0075 edm4hep::Vector3f{static_cast<float>(pos.x() / mm), static_cast<float>(pos.y() / mm), static_cast<float>(pos.z() / mm)},
0076 edm4eic::CovDiag3f{get_variance(dim[0] / mm), get_variance(dim[1] / mm),
0077 std::size(dim) > 2 ? get_variance(dim[2] / mm) : 0.},
0078 static_cast<float>((double)(raw_hit.getTimeStamp()) / 1000.0),
0079 m_cfg.timeResolution,
0080 static_cast<float>(raw_hit.getCharge() / 1.0e6),
0081 0.0F);
0082 #if EDM4EIC_VERSION_MAJOR >= 7
0083 rec_hit.setRawHit(raw_hit);
0084 #endif
0085
0086 }
0087
0088 return std::move(rec_hits);
0089 }
0090
0091 }