Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-09 07:53:33

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 <spdlog/logger.h>
0017 #include <Eigen/Geometry>
0018 #include <cstddef>
0019 #include <exception>
0020 #include <gsl/pointers>
0021 #include <map>
0022 #include <string>
0023 #include <vector>
0024 
0025 #include "TrackPropagationTest_processor.h"
0026 #include "services/geometry/acts/ACTSGeo_service.h"
0027 #include "services/geometry/dd4hep/DD4hep_service.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   auto dd4hep_service = GetApplication()->GetService<DD4hep_service>();
0055   auto acts_service   = GetApplication()->GetService<ACTSGeo_service>();
0056 
0057   m_propagation_algo.init(dd4hep_service->detector(), acts_service->actsGeoProvider(), logger());
0058 
0059   // Create HCal surface that will be used for propagation
0060   auto transform = Acts::Transform3::Identity();
0061 
0062   // make a reference disk to mimic electron-endcap HCal
0063   const auto hcalEndcapNZ    = -3322.;
0064   const auto hcalEndcapNMinR = 83.01;
0065   const auto hcalEndcapNMaxR = 950;
0066   auto hcalEndcapNBounds = std::make_shared<Acts::RadialBounds>(hcalEndcapNMinR, hcalEndcapNMaxR);
0067   auto hcalEndcapNTrf    = transform * Acts::Translation3(Acts::Vector3(0, 0, hcalEndcapNZ));
0068   m_hcal_surface = Acts::Surface::makeShared<Acts::DiscSurface>(hcalEndcapNTrf, hcalEndcapNBounds);
0069 }
0070 
0071 //------------------
0072 // Process
0073 //------------------
0074 // This function is called every event
0075 void TrackPropagationTest_processor::Process(const std::shared_ptr<const JEvent>& event) {
0076   m_log->trace("TrackPropagationTest_processor event");
0077 
0078   // Get trajectories from tracking
0079   auto trajectories = event->Get<ActsExamples::Trajectories>("CentralCKFActsTrajectories");
0080 
0081   // Iterate over trajectories
0082   m_log->debug("Propagating through {} trajectories", trajectories.size());
0083   for (std::size_t traj_index = 0; traj_index < trajectories.size(); traj_index++) {
0084     auto& trajectory = trajectories[traj_index];
0085     m_log->trace(" -- trajectory {} --", traj_index);
0086 
0087     std::unique_ptr<edm4eic::TrackPoint> projection_point;
0088     try {
0089       // >>> try to propagate to surface <<<
0090       projection_point = m_propagation_algo.propagate(edm4eic::Track{}, trajectory, m_hcal_surface);
0091     } catch (std::exception& e) {
0092       throw JException(e.what());
0093     }
0094 
0095     if (!projection_point) {
0096       m_log->trace("   could not propagate!", traj_index);
0097       continue;
0098     }
0099 
0100     // Now go through reconstructed tracks points
0101 
0102     auto pos    = projection_point->position;
0103     auto length = projection_point->pathlength;
0104     m_log->trace("   {:>10} {:>10.2f} {:>10.2f} {:>10.2f} {:>10.2f}", traj_index, pos.x, pos.y,
0105                  pos.z, length);
0106   }
0107 }
0108 
0109 //------------------
0110 // Finish
0111 //------------------
0112 void TrackPropagationTest_processor::Finish() {
0113   //    m_log->trace("TrackPropagationTest_processor finished\n");
0114 }