From 7a9b86028d98ce799ccbb17d55fd44b3d060f680 Mon Sep 17 00:00:00 2001 From: Shujie Li Date: Fri, 25 Oct 2024 11:39:19 -0700 Subject: [PATCH 1/2] add noise hits to reconstructed hits by randomly generating cell id --- .../tracking/TrackerHitReconstruction.cc | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/src/algorithms/tracking/TrackerHitReconstruction.cc b/src/algorithms/tracking/TrackerHitReconstruction.cc index 5fe85534e..0f40d6907 100644 --- a/src/algorithms/tracking/TrackerHitReconstruction.cc +++ b/src/algorithms/tracking/TrackerHitReconstruction.cc @@ -15,6 +15,8 @@ #include #include #include +#include +#include // For displaying bits (optional) namespace eicrecon { @@ -41,6 +43,8 @@ std::unique_ptr TrackerHitReconstruction::process auto rec_hits { std::make_unique() }; + + // add hits from DD4hep for (const auto& raw_hit : raw_hits) { auto id = raw_hit.getCellID(); @@ -85,6 +89,74 @@ std::unique_ptr TrackerHitReconstruction::process } + //------------------------------------------------ + // Example code of adding random noise hits + // Shujie Li, 08.2024 + // use the first raw hits to obtain the volume ID of the detector system + // this also make sure the hit container has at least one hit + int num_hits=10; // total number of noise hits in this detector volume. Should move this to the config file + std::vector noise_ids; + + // generate valid random cell id + for (const auto& hit0 : raw_hits) { + uint64_t id0,vol_id; + id0 = hit0.getCellID(); + // vol ID is the last 8 bits in Si tracker. Need to make it more flexible + // may want to predefine the layer/module ID as well to speed up the radom ID generation + vol_id = id0 & 0xFF; + // std::cout<<"::: "<(id0)<<" ::"< distr; // Define the range for 64-bit integers + dd4hep::Position pos; + int nn=0; + int i=0; + while (i < num_hits) { + uint64_t randomNum = distr(eng); // Generate a random 64-bit number + randomNum = (randomNum & ~uint64_t(0xFF)) | vol_id; // Clear the last 8 bits and set them to 'vol ID' + try { + pos = m_converter->position(randomNum); + // std::cout<<" ::: converter position "<(vol_id) <<":"<< i<<"/"<position(id); + auto dim = m_converter->cellDimensions(id); + // >oO trace + if(m_log->level() == spdlog::level::trace) { + m_log->trace("Noise hits inserted: position x={:.2f} y={:.2f} z={:.2f} [mm]: ", pos.x()/ mm, pos.y()/ mm, pos.z()/ mm); + m_log->trace("dimension size: {}", dim.size()); + for (size_t j = 0; j < std::size(dim); ++j) { + m_log->trace(" - dimension {:<5} size: {:.2}", j, dim[j]); + } + } + #if EDM4EIC_VERSION_MAJOR >= 7 + auto rec_hit = + #endif + rec_hits->create( + id, // Raw DD4hep cell ID + edm4hep::Vector3f{static_cast(pos.x() / mm), static_cast(pos.y() / mm), static_cast(pos.z() / mm)}, // mm + edm4eic::CovDiag3f{get_variance(dim[0] / mm), get_variance(dim[1] / mm), // variance (see note above) + std::size(dim) > 2 ? get_variance(dim[2] / mm) : 0.}, + static_cast(0), // ns + m_cfg.timeResolution, // in ns + static_cast(0), // Collected energy (GeV) + 0.0F); // Error on the energy + + } return std::move(rec_hits); } From 8c4c8c7f952206b08ae28cf588df526b28b6f3f6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 25 Oct 2024 18:41:27 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/algorithms/tracking/TrackerHitReconstruction.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/algorithms/tracking/TrackerHitReconstruction.cc b/src/algorithms/tracking/TrackerHitReconstruction.cc index 0f40d6907..aab6298f6 100644 --- a/src/algorithms/tracking/TrackerHitReconstruction.cc +++ b/src/algorithms/tracking/TrackerHitReconstruction.cc @@ -99,11 +99,11 @@ std::unique_ptr TrackerHitReconstruction::process // generate valid random cell id for (const auto& hit0 : raw_hits) { - uint64_t id0,vol_id; + uint64_t id0,vol_id; id0 = hit0.getCellID(); // vol ID is the last 8 bits in Si tracker. Need to make it more flexible // may want to predefine the layer/module ID as well to speed up the radom ID generation - vol_id = id0 & 0xFF; + vol_id = id0 & 0xFF; // std::cout<<"::: "<(id0)<<" ::"< TrackerHitReconstruction::process break; } - // generate noise hits from ids. + // generate noise hits from ids. for (auto id : noise_ids) { // Get position and dimension auto pos = m_converter->position(id);