Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-09-27 07:03:09

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