Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-02 08:55:47

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 Whitney Armstrong, Sylvester Joosten
0003 
0004 #include <cmath>
0005 // Gaudi
0006 #include "Gaudi/Property.h"
0007 #include "Gaudi/Algorithm.h"
0008 #include "GaudiKernel/RndmGenerators.h"
0009 #include "GaudiKernel/ToolHandle.h"
0010 
0011 #include "Acts/Definitions/Common.hpp"
0012 #include "Acts/Definitions/Units.hpp"
0013 #include <k4FWCore/DataHandle.h>
0014 #include <k4Interface/IGeoSvc.h>
0015 #include "ActsExamples/EventData/Track.hpp"
0016 
0017 #include "edm4eic/ClusterCollection.h"
0018 #include "edm4eic/TrackerHitCollection.h"
0019 #include "edm4hep/utils/vector_utils.h"
0020 
0021 #include "Acts/Surfaces/PerigeeSurface.hpp"
0022 
0023 ///// (Reconstructed) track parameters e.g. close to the vertex.
0024 // using TrackParameters = Acts::CurvilinearTrackParameters;
0025 
0026 ///// Container of reconstructed track states for multiple tracks.
0027 // using TrackParametersContainer = std::vector<TrackParameters>;
0028 
0029 ///// MultiTrajectory definition
0030 // using Trajectory = Acts::MultiTrajectory<SourceLink>;
0031 
0032 ///// Container for the truth fitting/finding track(s)
0033 // using TrajectoryContainer = std::vector<SimMultiTrajectory>;
0034 
0035 namespace Jug::Reco {
0036 
0037 /** Initial Track parameters from MC truth.
0038  *
0039  *  TrackParmetersContainer
0040  *
0041  *  \ingroup tracking
0042  */
0043 class TrackParamClusterInit : public Gaudi::Algorithm {
0044 private:
0045   mutable DataHandle<edm4eic::ClusterCollection> m_inputClusters{"inputClusters", Gaudi::DataHandle::Reader, this};
0046   mutable DataHandle<ActsExamples::TrackParametersContainer> m_outputInitialTrackParameters{"outputInitialTrackParameters",
0047                                                                       Gaudi::DataHandle::Writer, this};
0048 
0049 public:
0050   TrackParamClusterInit(const std::string& name, ISvcLocator* svcLoc) : Gaudi::Algorithm(name, svcLoc) {
0051     declareProperty("inputClusters", m_inputClusters, "Input clusters");
0052     declareProperty("outputInitialTrackParameters", m_outputInitialTrackParameters, "");
0053   }
0054 
0055   StatusCode initialize() override {
0056     if (Gaudi::Algorithm::initialize().isFailure()) {
0057       return StatusCode::FAILURE;
0058     }
0059     IRndmGenSvc* randSvc = Gaudi::svcLocator()->service<IRndmGenSvc>("RndmGenSvc", true);
0060     if (randSvc == nullptr) {
0061       return StatusCode::FAILURE;
0062     }
0063     return StatusCode::SUCCESS;
0064   }
0065 
0066   StatusCode execute(const EventContext&) const override {
0067     // input collection
0068     const auto* const clusters = m_inputClusters.get();
0069     // Create output collections
0070     auto* init_trk_params = m_outputInitialTrackParameters.createAndPut();
0071 
0072     for (const auto& c : *clusters) {
0073 
0074       using Acts::UnitConstants::GeV;
0075       using Acts::UnitConstants::MeV;
0076       using Acts::UnitConstants::mm;
0077       using Acts::UnitConstants::ns;
0078 
0079       double p = c.getEnergy() * GeV;
0080       if (p < 0.1 * GeV) {
0081         continue;
0082       }
0083       double len    = edm4hep::utils::magnitude(c.getPosition());
0084       auto momentum = c.getPosition() * p / len;
0085 
0086       Acts::BoundVector params;
0087       params(Acts::eBoundLoc0)   = 0.0 * mm;
0088       params(Acts::eBoundLoc1)   = 0.0 * mm;
0089       params(Acts::eBoundPhi)    = edm4hep::utils::angleAzimuthal(momentum);
0090       params(Acts::eBoundTheta)  = edm4hep::utils::anglePolar(momentum);
0091       params(Acts::eBoundQOverP) = 1 / p;
0092       params(Acts::eBoundTime)   = 0 * ns;
0093 
0094       auto pSurface = Acts::Surface::makeShared<Acts::PerigeeSurface>(Acts::Vector3{0, 0, 0});
0095 
0096       if (msgLevel(MSG::DEBUG)) {
0097         debug() << "Invoke track finding seeded by truth particle with p = " << p / GeV << " GeV" << endmsg;
0098       }
0099 
0100       // add both charges to the track candidate...
0101       init_trk_params->push_back({pSurface, params, {}, Acts::ParticleHypothesis::pion()});
0102 
0103       Acts::BoundVector params2;
0104       params2(Acts::eBoundLoc0)   = 0.0 * mm;
0105       params2(Acts::eBoundLoc1)   = 0.0 * mm;
0106       params2(Acts::eBoundPhi)    = edm4hep::utils::angleAzimuthal(momentum);
0107       params2(Acts::eBoundTheta)  = edm4hep::utils::anglePolar(momentum);
0108       params2(Acts::eBoundQOverP) = -1 / p;
0109       params2(Acts::eBoundTime)   = 0 * ns;
0110       init_trk_params->push_back({pSurface, params2, {}, Acts::ParticleHypothesis::pion()});
0111 
0112       // acts v1.2.0:
0113       // init_trk_params->emplace_back(Acts::Vector4(0 * mm, 0 * mm, 0 * mm, 0),
0114       //                              Acts::Vector3(c.x() * p / len, c.y() * p / len, c.z() * p / len), p, -1,
0115       //                              std::make_optional(cov));
0116       // debug() << init_trk_params->back() << endmsg;
0117       // init_trk_params->emplace_back(Acts::Vector4(0 * mm, 0 * mm, 0 * mm, 0),
0118       //                              Acts::Vector3(c.x() * p / len, c.y() * p / len, c.z() * p / len), p, 1,
0119       //                              std::make_optional(cov));
0120       ////debug() << init_trk_params->back() << endmsg;
0121       // init_trk_params->emplace_back(Acts::Vector4(0 * mm, 0 * mm, 0 * mm, 0),
0122       //                              Acts::Vector3(c.x() * p / len, c.y() * p / len, c.z() * p / len), p, 0,
0123       //                              std::make_optional(cov));
0124     }
0125     return StatusCode::SUCCESS;
0126   }
0127 };
0128 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
0129 DECLARE_COMPONENT(TrackParamClusterInit)
0130 
0131 } // namespace Jug::Reco