LDMX Software
tracking::reco::LinearTrackFinder Class Reference

Public Member Functions

 LinearTrackFinder (const std::string &name, framework::Process &process)
 Constructor.
 
virtual ~LinearTrackFinder ()=default
 Destructor.
 
void onProcessEnd () override
 Output event statistics.
 
void configure (framework::config::Parameters &parameters) override
 Configure the processor using the given user specified parameters.
 
void produce (framework::Event &event) override
 Run the processor.
 
- Public Member Functions inherited from tracking::reco::TrackingGeometryUser
 TrackingGeometryUser (const std::string &name, framework::Process &p)
 
- Public Member Functions inherited from framework::Producer
 Producer (const std::string &name, Process &process)
 Class constructor.
 
virtual void process (Event &event) final
 Processing an event for a Producer is calling produce.
 
- Public Member Functions inherited from framework::EventProcessor
 DECLARE_FACTORY (EventProcessor, EventProcessor *, const std::string &, Process &)
 declare that we have a factory for this class
 
 EventProcessor (const std::string &name, Process &process)
 Class constructor.
 
virtual ~EventProcessor ()=default
 Class destructor.
 
virtual void beforeNewRun (ldmx::RunHeader &run_header)
 Callback for Producers to add parameters to the run header before conditions are initialized.
 
virtual void onNewRun (const ldmx::RunHeader &run_header)
 Callback for the EventProcessor to take any necessary action when the run being processed changes.
 
virtual void onFileOpen (EventFile &event_file)
 Callback for the EventProcessor to take any necessary action when a new event input ROOT file is opened.
 
virtual void onFileClose (EventFile &event_file)
 Callback for the EventProcessor to take any necessary action when a event input ROOT file is closed.
 
virtual void onProcessStart ()
 Callback for the EventProcessor to take any necessary action when the processing of events starts, such as creating histograms.
 
template<class T >
const T & getCondition (const std::string &condition_name)
 Access a conditions object for the current event.
 
TDirectory * getHistoDirectory ()
 Access/create a directory in the histogram file for this event processor to create histograms and analysis tuples.
 
void setStorageHint (framework::StorageControl::Hint hint)
 Mark the current event as having the given storage control hint from this module_.
 
void setStorageHint (framework::StorageControl::Hint hint, const std::string &purposeString)
 Mark the current event as having the given storage control hint from this module and the given purpose string.
 
int getLogFrequency () const
 Get the current logging frequency from the process.
 
int getRunNumber () const
 Get the run number from the process.
 
std::string getName () const
 Get the processor name.
 
void createHistograms (const std::vector< framework::config::Parameters > &histos)
 Internal function which is used to create histograms passed from the python configuration @parma histos vector of Parameters that configure histograms to create.
 

Private Member Functions

std::vector< ldmx::StraightTrackfindTracks (const std::vector< ldmx::StraightTrack > &track_seeds)
 
bool isPositionUsed (const ldmx::Measurement &measurement, const std::set< std::tuple< float, float, float > > &used_sensor_positions)
 

Private Attributes

int n_events_ {0}
 
double processing_time_ {0.}
 
std::string out_trk_collection_ {"LinearRecoilTracks"}
 
std::string seed_collection_ {"LinearRecoilSeedTracks"}
 
std::string input_pass_name_ {""}
 
int n_seeds_ {0}
 
int n_tracks_ {0}
 

Additional Inherited Members

- Protected Member Functions inherited from tracking::reco::TrackingGeometryUser
const Acts::GeometryContext & geometryContext ()
 
const Acts::MagneticFieldContext & magneticFieldContext ()
 
const Acts::CalibrationContext & calibrationContext ()
 
const geo::TrackersTrackingGeometrygeometry ()
 
void loadBField (const std::string &path, const std::vector< double > &map_offset={0., 0., 0.})
 Load the interpolated B-field map from path and cache it.
 
void loadBField (const std::vector< double > &map_offset={0., 0., 0.})
 Load B-field from the path recorded in the detector GDML.
 
std::shared_ptr< Acts::MagneticFieldProvider > bField () const
 Return the loaded B-field provider.
 
- Protected Member Functions inherited from framework::EventProcessor
void abortEvent ()
 Abort the event immediately.
 
- Protected Attributes inherited from framework::EventProcessor
HistogramPool histograms_
 helper object for making and filling histograms
 
NtupleManagerntuple_ {NtupleManager::getInstance()}
 Manager for any ntuples.
 
logging::logger the_log_
 The logger for this EventProcessor.
 

Detailed Description

Definition at line 24 of file LinearTrackFinder.h.

Constructor & Destructor Documentation

◆ LinearTrackFinder()

tracking::reco::LinearTrackFinder::LinearTrackFinder ( const std::string & name,
framework::Process & process )

Constructor.

Parameters
nameThe name of the instance of this object.
processThe process running this producer.

Definition at line 15 of file LinearTrackFinder.cxx.

17 : TrackingGeometryUser(name, process) {}
virtual void process(Event &event) final
Processing an event for a Producer is calling produce.

Member Function Documentation

◆ configure()

void tracking::reco::LinearTrackFinder::configure ( framework::config::Parameters & parameters)
overridevirtual

Configure the processor using the given user specified parameters.

Parameters
parametersSet of parameters used to configure this processor.

Reimplemented from framework::EventProcessor.

Definition at line 19 of file LinearTrackFinder.cxx.

19 {
20 // seeds from the event
21 seed_collection_ =
22 parameters.get<std::string>("seed_collection", "LinearRecoilSeedTracks");
23 // output track collection
24 out_trk_collection_ =
25 parameters.get<std::string>("out_trk_collection", "LinearRecoilTracks");
26
27 input_pass_name_ = parameters.get<std::string>("input_pass_name");
28
29} // configure
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78

References framework::config::Parameters::get().

◆ findTracks()

std::vector< ldmx::StraightTrack > tracking::reco::LinearTrackFinder::findTracks ( const std::vector< ldmx::StraightTrack > & track_seeds)
private

Definition at line 70 of file LinearTrackFinder.cxx.

71 {
72 std::vector<ldmx::StraightTrack> best_tracks;
73 std::map<std::array<double, 3>, std::vector<ldmx::StraightTrack>>
74 seeds_by_rec_hit;
75
76 // Group seeds by their EcalRecHit point
77 for (const auto& seed : track_seeds) {
78 auto rec_hit_point = seed.getFirstLayerEcalRecHit();
79 seeds_by_rec_hit[rec_hit_point].push_back(seed);
80 }
81
82 // Track used sensor positions
83 std::set<std::tuple<float, float, float>> used_sensor_positions;
84
85 // Find the best seed for each RecHit
86 // numTracks <= number of RecHits
87 for (auto& entry : seeds_by_rec_hit) {
88 const auto& rec_hit_point = entry.first;
89 auto& seeds_with_same_rec_hit = entry.second;
90
91 ldmx_log(debug) << "Processing RecHit at: (" << rec_hit_point[0] << ", "
92 << rec_hit_point[1] << ", " << rec_hit_point[2] << ")\n";
93
94 // Main function to remove seeds with overlapping sensor positions
95 seeds_with_same_rec_hit.erase(
96 std::remove_if(
97 seeds_with_same_rec_hit.begin(), seeds_with_same_rec_hit.end(),
98 [&](const ldmx::StraightTrack& seed) {
99 for (const auto& measurement : seed.getAllSensorPoints()) {
100 // Check if this sensor's position is already used
101 if (isPositionUsed(measurement, used_sensor_positions)) {
102 // Mark this seed for removal
103 return true;
104 } // ifPositionUsed
105 } // for measurement
106 // Keep the seed if no position overlap
107 return false;
108 }),
109 seeds_with_same_rec_hit.end());
110
111 // If no valid seeds remain after filtering, skip to next RecHit
112 if (seeds_with_same_rec_hit.empty()) continue;
113
114 // Find the seed with the lowest chi2 for this RecHit, this is "best" seed
115 auto best_seed_it = std::min_element(
116 seeds_with_same_rec_hit.begin(), seeds_with_same_rec_hit.end(),
117 [](const ldmx::StraightTrack& trk_a, const ldmx::StraightTrack& trk_b) {
118 return trk_a.getChi2() < trk_b.getChi2();
119 });
120
121 // Store the best seed for this RecHit
122 ldmx::StraightTrack best_seed = *best_seed_it;
123 best_tracks.push_back(best_seed);
124
125 ldmx_log(debug) << "For RecHit at: (" << rec_hit_point[0] << ", "
126 << rec_hit_point[1] << ", " << rec_hit_point[2] << ")\n";
127
128 // Add best seed's sensor position to the global used positions set
129 auto best_seed_measurement = best_seed.getAllSensorPoints();
130
131 for (auto& position_object : best_seed_measurement) {
132 used_sensor_positions.insert(
133 std::make_tuple(position_object.getGlobalPosition()[0],
134 position_object.getGlobalPosition()[1],
135 position_object.getGlobalPosition()[2]));
136 ldmx_log(debug) << "We used the following point: ("
137 << position_object.getGlobalPosition()[0] << ", "
138 << position_object.getGlobalPosition()[1] << ", "
139 << position_object.getGlobalPosition()[2] << ")\n";
140 ldmx_log(debug) << "Which gave a track a distance: "
141 << best_seed.getDistanceToRecHit()
142 << " to the closest ECalRecHit\n";
143 } // for sensor points in "best" seed
144
145 } // for entry loop, everytime we loop onto a new RecHit, we will have fewer
146 // points to check
147
148 return best_tracks;
149
150} // findTracks

◆ isPositionUsed()

bool tracking::reco::LinearTrackFinder::isPositionUsed ( const ldmx::Measurement & measurement,
const std::set< std::tuple< float, float, float > > & used_sensor_positions )
private

Definition at line 152 of file LinearTrackFinder.cxx.

154 {
155 const auto& position = std::make_tuple(measurement.getGlobalPosition()[0],
156 measurement.getGlobalPosition()[1],
157 measurement.getGlobalPosition()[2]);
158
159 return used_sensor_positions.find(position) != used_sensor_positions.end();
160
161} // isPositionUsed
std::array< float, 3 > getGlobalPosition() const
Definition Measurement.h:49

◆ onProcessEnd()

void tracking::reco::LinearTrackFinder::onProcessEnd ( )
overridevirtual

Output event statistics.

Reimplemented from framework::EventProcessor.

Definition at line 63 of file LinearTrackFinder.cxx.

63 {
64 ldmx_log(info) << "found " << n_tracks_ << " tracks / " << n_events_
65 << " events.";
66 ldmx_log(info) << "AVG Time/Event: " << std::fixed << std::setprecision(1)
67 << processing_time_ / n_events_ << " ms";
68} // onProcessEnd

◆ produce()

void tracking::reco::LinearTrackFinder::produce ( framework::Event & event)
overridevirtual

Run the processor.

Parameters
eventThe event to process.

Implements framework::Producer.

Definition at line 31 of file LinearTrackFinder.cxx.

31 {
32 std::vector<ldmx::StraightTrack> straight_tracks;
33
34 auto start = std::chrono::high_resolution_clock::now();
35
36 n_events_++;
37 if (n_events_ % 1000 == 0) ldmx_log(info) << "events processed:" << n_events_;
38
39 ldmx_log(debug) << "Retrieve the seeds::" << seed_collection_;
40
41 const auto& seed_tracks = event.getCollection<ldmx::StraightTrack>(
42 seed_collection_, input_pass_name_);
43
44 n_seeds_ = seed_tracks.size();
45 ldmx_log(debug) << "Number of seeds::" << n_seeds_;
46
47 if (n_seeds_ > 0) {
48 straight_tracks = findTracks(seed_tracks);
49 }
50
51 n_tracks_ += straight_tracks.size();
52
53 // Add the tracks to the event
54 event.add(out_trk_collection_, straight_tracks);
55
56 auto end = std::chrono::high_resolution_clock::now();
57 auto diff = end - start;
58 processing_time_ += std::chrono::duration<double, std::milli>(diff).count();
59
60 straight_tracks.clear();
61} // produce

Member Data Documentation

◆ input_pass_name_

std::string tracking::reco::LinearTrackFinder::input_pass_name_ {""}
private

Definition at line 64 of file LinearTrackFinder.h.

64{""};

◆ n_events_

int tracking::reco::LinearTrackFinder::n_events_ {0}
private

Definition at line 56 of file LinearTrackFinder.h.

56{0};

◆ n_seeds_

int tracking::reco::LinearTrackFinder::n_seeds_ {0}
private

Definition at line 66 of file LinearTrackFinder.h.

66{0};

◆ n_tracks_

int tracking::reco::LinearTrackFinder::n_tracks_ {0}
private

Definition at line 67 of file LinearTrackFinder.h.

67{0};

◆ out_trk_collection_

std::string tracking::reco::LinearTrackFinder::out_trk_collection_ {"LinearRecoilTracks"}
private

Definition at line 60 of file LinearTrackFinder.h.

60{"LinearRecoilTracks"};

◆ processing_time_

double tracking::reco::LinearTrackFinder::processing_time_ {0.}
private

Definition at line 57 of file LinearTrackFinder.h.

57{0.};

◆ seed_collection_

std::string tracking::reco::LinearTrackFinder::seed_collection_ {"LinearRecoilSeedTracks"}
private

Definition at line 63 of file LinearTrackFinder.h.

63{"LinearRecoilSeedTracks"};

The documentation for this class was generated from the following files: