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 beforeNewRun (ldmx::RunHeader &header)
 Handle allowing producers to modify run headers before the run begins.
 
- Public Member Functions inherited from framework::EventProcessor
 EventProcessor (const std::string &name, Process &process)
 Class constructor.
 
virtual ~EventProcessor ()
 Class destructor.
 
virtual void onNewRun (const ldmx::RunHeader &runHeader)
 Callback for the EventProcessor to take any necessary action when the run being processed changes.
 
virtual void onFileOpen (EventFile &eventFile)
 Callback for the EventProcessor to take any necessary action when a new event input ROOT file is opened.
 
virtual void onFileClose (EventFile &eventFile)
 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

- Static Public Member Functions inherited from framework::EventProcessor
static void declare (const std::string &classname, int classtype, EventProcessorMaker *)
 Internal function which is part of the PluginFactory machinery.
 
- Static Public Attributes inherited from framework::Producer
static const int CLASSTYPE {1}
 Constant used to track EventProcessor types by the PluginFactory.
 
- Protected Member Functions inherited from tracking::reco::TrackingGeometryUser
const Acts::GeometryContext & geometry_context ()
 
const Acts::MagneticFieldContext & magnetic_field_context ()
 
const Acts::CalibrationContext & calibration_context ()
 
const geo::TrackersTrackingGeometrygeometry ()
 
- Protected Member Functions inherited from framework::EventProcessor
void abortEvent ()
 Abort the event immediately.
 
- Protected Attributes inherited from framework::EventProcessor
HistogramHelper histograms_
 Interface class for making and filling histograms.
 
NtupleManagerntuple_ {NtupleManager::getInstance()}
 Manager for any ntuples.
 
logging::logger theLog_
 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) {}

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_ = parameters.getParameter<std::string>(
22 "seed_collection", "LinearRecoilSeedTracks");
23 // output track collection
24 out_trk_collection_ = parameters.getParameter<std::string>(
25 "out_trk_collection", "LinearRecoilTracks");
26
27 input_pass_name_ =
28 parameters.getParameter<std::string>("input_pass_name", "");
29
30} // configure

◆ findTracks()

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

Definition at line 72 of file LinearTrackFinder.cxx.

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

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

◆ onProcessEnd()

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

Output event statistics.

Reimplemented from framework::EventProcessor.

Definition at line 65 of file LinearTrackFinder.cxx.

65 {
66 ldmx_log(info) << "found " << n_tracks_ << " tracks / " << n_events_
67 << " events.";
68 ldmx_log(info) << "AVG Time/Event: " << std::fixed << std::setprecision(1)
69 << processing_time_ / n_events_ << " ms";
70} // 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 32 of file LinearTrackFinder.cxx.

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