Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:07:34

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