Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-03 09:36:36

0001 
0002 #include <Acts/Definitions/Algebra.hpp>
0003 #include <Acts/EventData/TrackProxy.hpp>
0004 #include <Acts/EventData/VectorMultiTrajectory.hpp>
0005 #include <Acts/EventData/VectorTrackContainer.hpp>
0006 #include <Acts/Surfaces/DiscSurface.hpp>
0007 #include <Acts/Surfaces/RadialBounds.hpp>
0008 #include <Acts/Surfaces/Surface.hpp>
0009 #include <ActsExamples/EventData/Track.hpp>
0010 #include <JANA/JApplication.h>
0011 #include <JANA/JApplicationFwd.h>
0012 #include <JANA/JEvent.h>
0013 #include <JANA/JException.h>
0014 #include <JANA/Services/JGlobalRootLock.h>
0015 #include <edm4eic/TrackCollection.h>
0016 #include <edm4eic/TrackPoint.h>
0017 #include <edm4hep/Vector3f.h>
0018 #include <fmt/format.h>
0019 #include <spdlog/logger.h>
0020 #include <Eigen/Geometry>
0021 #include <exception>
0022 #include <map>
0023 #include <string>
0024 #include <vector>
0025 
0026 #include "TrackPropagation.h"
0027 #include "TrackPropagationTest_processor.h"
0028 #include "services/rootfile/RootFile_service.h"
0029 
0030 //------------------
0031 // Init
0032 //------------------
0033 void TrackPropagationTest_processor::Init() {
0034   std::string plugin_name = ("track_propagation_test");
0035 
0036   // Get JANA application
0037   auto* app = GetApplication();
0038 
0039   // Ask service locator a file to write histograms to
0040   auto root_file_service = app->GetService<RootFile_service>();
0041 
0042   // Get TDirectory for histograms root file
0043   auto globalRootLock = app->GetService<JGlobalRootLock>();
0044   globalRootLock->acquire_write_lock();
0045   auto* file = root_file_service->GetHistFile();
0046   globalRootLock->release_lock();
0047 
0048   // Create a directory for this plugin. And subdirectories for series of histograms
0049   m_dir_main = file->mkdir(plugin_name.c_str());
0050 
0051   // Get log level from user parameter or default
0052   InitLogger(app, plugin_name);
0053 
0054   // Create TrackPropagation algorithm (must be after services are initialized)
0055   m_propagation_algo = std::make_unique<eicrecon::TrackPropagation>("TrackPropagationTest");
0056   m_propagation_algo->init();
0057 
0058   // Create HCal surface that will be used for propagation
0059   auto transform = Acts::Transform3::Identity();
0060 
0061   // make a reference disk to mimic electron-endcap HCal
0062   const auto hcalEndcapNZ    = -3322.;
0063   const auto hcalEndcapNMinR = 83.01;
0064   const auto hcalEndcapNMaxR = 950;
0065   auto hcalEndcapNBounds = std::make_shared<Acts::RadialBounds>(hcalEndcapNMinR, hcalEndcapNMaxR);
0066   auto hcalEndcapNTrf    = transform * Acts::Translation3(Acts::Vector3(0, 0, hcalEndcapNZ));
0067   m_hcal_surface = Acts::Surface::makeShared<Acts::DiscSurface>(hcalEndcapNTrf, hcalEndcapNBounds);
0068 }
0069 
0070 //------------------
0071 // Process
0072 //------------------
0073 // This function is called every event
0074 void TrackPropagationTest_processor::Process(const std::shared_ptr<const JEvent>& event) {
0075   m_log->trace("TrackPropagationTest_processor event");
0076 
0077   // Get track containers from tracking
0078   auto track_states = event->Get<Acts::ConstVectorMultiTrajectory>("CentralCKFActsTrackStates");
0079   auto tracks       = event->Get<Acts::ConstVectorTrackContainer>("CentralCKFActsTracks");
0080 
0081   if (track_states.empty() || tracks.empty()) {
0082     m_log->debug("No track containers found");
0083     return;
0084   }
0085 
0086   // Construct ConstTrackContainer from underlying containers
0087   auto trackStateContainer =
0088       std::make_shared<Acts::ConstVectorMultiTrajectory>(*track_states.front());
0089   auto trackContainer = std::make_shared<Acts::ConstVectorTrackContainer>(*tracks.front());
0090   ActsExamples::ConstTrackContainer track_container(trackContainer, trackStateContainer);
0091 
0092   // Iterate over tracks
0093   m_log->debug("Propagating through {} tracks", track_container.size());
0094   for (const auto& track : track_container) {
0095     m_log->trace(" -- track {} --", track.index());
0096 
0097     std::unique_ptr<edm4eic::TrackPoint> projection_point;
0098     try {
0099       // >>> try to propagate to surface <<<
0100       projection_point =
0101           m_propagation_algo->propagate(edm4eic::Track{}, track, track_container, m_hcal_surface);
0102     } catch (std::exception& e) {
0103       throw JException(e.what());
0104     }
0105 
0106     if (!projection_point) {
0107       m_log->trace("   could not propagate track {}!", track.index());
0108       continue;
0109     }
0110 
0111     // Now go through reconstructed tracks points
0112 
0113     auto pos    = projection_point->position;
0114     auto length = projection_point->pathlength;
0115     m_log->trace("   {:>10} {:>10.2f} {:>10.2f} {:>10.2f} {:>10.2f}", track.index(), pos.x, pos.y,
0116                  pos.z, length);
0117   }
0118 }
0119 
0120 //------------------
0121 // Finish
0122 //------------------
0123 void TrackPropagationTest_processor::Finish() {
0124   //    m_log->trace("TrackPropagationTest_processor finished\n");
0125 }