LDMX Software
tracking::reco::GreedyAmbiguitySolver Class Referencefinal

Minimal example of a processor. More...

#include <GreedyAmbiguitySolver.h>

Classes

struct  State
 

Public Member Functions

 GreedyAmbiguitySolver (const std::string &name, framework::Process &process)
 Constructor.
 
virtual ~GreedyAmbiguitySolver ()=default
 Destructor.
 
void onNewRun (const ldmx::RunHeader &rh) override
 onNewRun is the first function called for each processor after the conditions are fully configured and accessible.
 
void configure (framework::config::Parameters &parameters) override
 Configure the processor using the given user specified parameters.
 
void produce (framework::Event &event) override
 Process the event and put new data products into it.
 
- 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 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.
 
virtual void onProcessEnd ()
 Callback for the EventProcessor to take any necessary action when the processing of events finishes, such as calculating job-summary quantities.
 
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

template<typename geometry_t , typename source_link_hash_t , typename source_link_equality_t >
void computeInitialState (std::vector< ldmx::Track > tracks, std::vector< ldmx::Measurement > measurements, State &state, geometry_t &tg, source_link_hash_t &&sourceLinkHash, source_link_equality_t &&sourceLinkEquality) const
 
void resolve (State &state)
 Updates the state iteratively by evicting one track after the other until the final state conditions are met.
 
void removeTrack (State &state, std::size_t iTrack) const
 

Private Attributes

std::uint32_t maximum_shared_hits_ {1}
 Maximum amount of shared hits per track.
 
std::uint32_t maximum_iterations_ {1000}
 Maximum number of iterations.
 
std::size_t n_meas_min_ {7}
 Minimum number of measurement to form a track.
 
std::string out_trk_collection_ {"TaggerTracksClean"}
 
std::string track_collection_ {"TaggerTracks"}
 
std::string meas_collection_ {"DigiTaggerSimHits"}
 
std::string input_pass_name_ {""}
 

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 ()
 
- 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

Minimal example of a processor.

This processor will loop over all of the ECal hits in an event and print out their details.

Definition at line 49 of file GreedyAmbiguitySolver.h.

Constructor & Destructor Documentation

◆ GreedyAmbiguitySolver()

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

Constructor.

Parameters
nameName for this instance of the class.
processThe Process class associated with EventProcessor, provided by the framework.

Definition at line 11 of file GreedyAmbiguitySolver.cxx.

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

Member Function Documentation

◆ computeInitialState()

template<typename geometry_t , typename source_link_hash_t , typename source_link_equality_t >
void tracking::reco::GreedyAmbiguitySolver::computeInitialState ( std::vector< ldmx::Track > tracks,
std::vector< ldmx::Measurement > measurements,
State & state,
geometry_t & tg,
source_link_hash_t && sourceLinkHash,
source_link_equality_t && sourceLinkEquality ) const
private
Parameters
tracksThe input track container.
stateAn empty state object which is expected to be default constructed.
sourceLinkHashA functor to acquire a hash from a given source link.
sourceLinkEqualityA functor to check equality of two source links.

Definition at line 43 of file GreedyAmbiguitySolver.cxx.

46 {
47 auto measurement_index_map =
48 std::unordered_map<Acts::SourceLink, std::size_t, source_link_hash_t,
49 source_link_equality_t>(0, sourceLinkHash,
50 sourceLinkEquality);
51
52 // auto tg{geometry()};
53 // Iterate through all input tracks, collect their properties like measurement
54 // count and chi2 and fill the measurement map in order to relate tracks to
55 // each other if they have shared hits_.
56 state.number_of_tracks_ = 0;
57 for (const auto& track : tracks) {
58 // Kick out tracks that do not fulfill our initial requirements
59 if (track.getNhits() < n_meas_min_) {
60 continue;
61 }
62
63 std::vector<std::size_t> measurements;
64 for (auto imeas : track.getMeasurementsIdxs()) {
65 auto meas = meas_coll.at(imeas);
66 const Acts::Surface* hit_surface = tg.getSurface(meas.getLayerID());
67 // Store the index_ source link
68 acts_examples::IndexSourceLink idx_sl(hit_surface->geometryId(), imeas);
69 Acts::SourceLink source_link = Acts::SourceLink(idx_sl);
70
71 auto emplace = measurement_index_map.try_emplace(
72 source_link, measurement_index_map.size());
73 measurements.push_back(emplace.first->second);
74 }
75
76 state.track_tips_.push_back(state.number_of_tracks_);
77 state.track_chi2_.push_back(track.getChi2() / track.getNdf());
78 state.measurements_per_track_.push_back(std::move(measurements));
79 state.selected_tracks_.insert(state.number_of_tracks_);
80
81 ++state.number_of_tracks_;
82 }
83
84 // Now we relate measurements to tracks
85 for (std::size_t i_track = 0; i_track < state.number_of_tracks_; ++i_track) {
86 for (auto i_measurement : state.measurements_per_track_[i_track]) {
87 state.tracks_per_measurement_[i_measurement].insert(i_track);
88 }
89 }
90
91 // Finally, we can accumulate the number of shared measurements per track
92 state.shared_measurements_per_track_ =
93 std::vector<std::size_t>(state.track_tips_.size(), 0);
94 for (std::size_t i_track = 0; i_track < state.number_of_tracks_; ++i_track) {
95 for (auto i_measurement : state.measurements_per_track_[i_track]) {
96 if (state.tracks_per_measurement_[i_measurement].size() > 1) {
97 ++state.shared_measurements_per_track_[i_track];
98 }
99 }
100 }
101}
std::size_t n_meas_min_
Minimum number of measurement to form a track.

References n_meas_min_.

Referenced by produce().

◆ configure()

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

Configure the processor using the given user specified parameters.

The user specified parameters that are availabed are defined in the python configuration class. Look at the my_processor.py module of the EventProc python for the python structure.

Parameters
parametersSet of parameters used to configure this processor.

Reimplemented from framework::EventProcessor.

Definition at line 164 of file GreedyAmbiguitySolver.cxx.

165 {
166 out_trk_collection_ =
167 parameters.get<std::string>("out_trk_collection", "TaggerTracksClean");
168
169 track_collection_ =
170 parameters.get<std::string>("trackCollection", "TaggerTracks");
171
172 meas_collection_ =
173 parameters.get<std::string>("measCollection", "DigiTaggerSimHits");
174 input_pass_name_ = parameters.get<std::string>("input_pass_name");
175 n_meas_min_ = parameters.get<int>("nMeasurementsMin", 5);
176 maximum_shared_hits_ = parameters.get<int>("maximumSharedHits", 1);
177}
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
std::uint32_t maximum_shared_hits_
Maximum amount of shared hits per track.

References framework::config::Parameters::get(), maximum_shared_hits_, and n_meas_min_.

◆ onNewRun()

void tracking::reco::GreedyAmbiguitySolver::onNewRun ( const ldmx::RunHeader & rh)
overridevirtual

onNewRun is the first function called for each processor after the conditions are fully configured and accessible.

This is where you could create single-processors, multi-event calculation objects.

Reimplemented from framework::EventProcessor.

Definition at line 162 of file GreedyAmbiguitySolver.cxx.

162{}

◆ produce()

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

Process the event and put new data products into it.

Parameters
eventThe event to process.

Implements framework::Producer.

Definition at line 179 of file GreedyAmbiguitySolver.cxx.

179 {
180 GreedyAmbiguitySolver::State state;
181 std::vector<ldmx::Track> out_tracks;
182
183 auto tg{geometry()};
184
185 if (!event.exists(track_collection_, input_pass_name_)) {
186 ldmx_log(debug) << "Track collection not found, exiting";
187 return;
188 }
189 auto tracks{
190 event.getCollection<ldmx::Track>(track_collection_, input_pass_name_)};
191
192 if (!event.exists(meas_collection_, input_pass_name_)) {
193 ldmx_log(debug) << "Measurement collection not found, exiting";
194 return;
195 }
196 auto measurements{event.getCollection<ldmx::Measurement>(meas_collection_,
197 input_pass_name_)};
198
199 computeInitialState(tracks, measurements, state, tg,
200 tracking::sim::utils::sourceLinkHash,
201 tracking::sim::utils::sourceLinkEquality);
202 resolve(state);
203
204 for (auto i_track : state.selected_tracks_) {
205 auto clean_trk = tracks[state.track_tips_.at(i_track)];
206 if ((clean_trk.getNhits() > n_meas_min_) &&
207 (std::abs(1. / clean_trk.getQoP()) > 0.05)) {
208 out_tracks.push_back(clean_trk);
209 }
210 }
211
212 event.add(out_trk_collection_, out_tracks);
213
214 // for (auto iTrack : initial_state.selectedTracks) {
215 // std::cout << event.getEventNumber() << " " << iTrack << " " <<
216 // initial_state.trackChi2[iTrack] << " " <<
217 // initial_state.measurementsPerTrack[iTrack].size() << std::endl;
218 // }
219
220 ldmx_log(info) << " Resolved to " << state.selected_tracks_.size()
221 << " tracks from " << " " << tracks.size();
222}
bool exists(const std::string &name, const std::string &passName, bool unique=true) const
Check for the existence of an object or collection with the given name and pass name in the event.
Definition Event.cxx:92
Implementation of a track object.
Definition Track.h:53
void computeInitialState(std::vector< ldmx::Track > tracks, std::vector< ldmx::Measurement > measurements, State &state, geometry_t &tg, source_link_hash_t &&sourceLinkHash, source_link_equality_t &&sourceLinkEquality) const
void resolve(State &state)
Updates the state iteratively by evicting one track after the other until the final state conditions ...

References computeInitialState(), framework::Event::exists(), n_meas_min_, and resolve().

◆ removeTrack()

void tracking::reco::GreedyAmbiguitySolver::removeTrack ( State & state,
std::size_t iTrack ) const
private
Parameters
stateA state object that was previously filled by the initialization.
iTrack

Definition at line 29 of file GreedyAmbiguitySolver.cxx.

30 {
31 for (auto i_measurement : state.measurements_per_track_[iTrack]) {
32 state.tracks_per_measurement_[i_measurement].erase(iTrack);
33 if (state.tracks_per_measurement_[i_measurement].size() == 1) {
34 auto j_track = *state.tracks_per_measurement_[i_measurement].begin();
35 --state.shared_measurements_per_track_[j_track];
36 }
37 }
38 state.selected_tracks_.erase(iTrack);
39}

Referenced by resolve().

◆ resolve()

void tracking::reco::GreedyAmbiguitySolver::resolve ( State & state)
private

Updates the state iteratively by evicting one track after the other until the final state conditions are met.

Parameters
stateA state object that was previously filled by the initialization.

Compares two tracks based on the number of shared measurements in order to decide if we already met the final state.

Compares two tracks in order to find the one which should be evicted. First we compare the relative amount of shared measurements. If that is indecisive we use the chi2.

Helper to calculate the relative amount of shared measurements.

Definition at line 103 of file GreedyAmbiguitySolver.cxx.

103 {
106 auto shared_measurements_comperator = [&state](std::size_t a, std::size_t b) {
107 return state.shared_measurements_per_track_[a] <
108 state.shared_measurements_per_track_[b];
109 };
110
114 auto track_comperator = [&state](std::size_t a, std::size_t b) {
116 auto relative_shared_measurements = [&state](std::size_t i) {
117 return 1.0 * state.shared_measurements_per_track_[i] /
118 state.measurements_per_track_[i].size();
119 };
120
121 if (relative_shared_measurements(a) != relative_shared_measurements(b)) {
122 return relative_shared_measurements(a) < relative_shared_measurements(b);
123 }
124 return state.track_chi2_[a] < state.track_chi2_[b];
125 };
126
127 for (std::size_t i = 0; i < maximum_iterations_; ++i) {
128 // Lazy out if there is nothing to filter on.
129 if (state.selected_tracks_.empty()) {
130 ldmx_log(trace) << "No tracks left - exit loop";
131 break;
132 }
133
134 // Find the maximum amount of shared measurements per track to decide if we
135 // are done or not.
136 auto maximum_shared_measurements = *std::max_element(
137 state.selected_tracks_.begin(), state.selected_tracks_.end(),
138 shared_measurements_comperator);
139 // ldmx_log(debug) <<
140 // "maximum shared measurements "
141 // << state.sharedMeasurementsPerTrack[maximumSharedMeasurements];
142 if (state.shared_measurements_per_track_[maximum_shared_measurements] <
144 break;
145 }
146
147 // Find the "worst" track by comparing them to each other
148 auto bad_track =
149 *std::max_element(state.selected_tracks_.begin(),
150 state.selected_tracks_.end(), track_comperator);
151 ldmx_log(trace) << "Remove track " << bad_track << ", nMeas = "
152 << state.measurements_per_track_[bad_track].size()
153 << ", nShared = "
154 << state.shared_measurements_per_track_[bad_track]
155 << ", chi2 =" << state.track_chi2_[bad_track];
156 removeTrack(state, bad_track);
157 }
158}
void removeTrack(State &state, std::size_t iTrack) const
std::uint32_t maximum_iterations_
Maximum number of iterations.

References maximum_iterations_, maximum_shared_hits_, and removeTrack().

Referenced by produce().

Member Data Documentation

◆ input_pass_name_

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

Definition at line 104 of file GreedyAmbiguitySolver.h.

104{""};

◆ maximum_iterations_

std::uint32_t tracking::reco::GreedyAmbiguitySolver::maximum_iterations_ {1000}
private

Maximum number of iterations.

Definition at line 93 of file GreedyAmbiguitySolver.h.

93{1000};

Referenced by resolve().

◆ maximum_shared_hits_

std::uint32_t tracking::reco::GreedyAmbiguitySolver::maximum_shared_hits_ {1}
private

Maximum amount of shared hits per track.

Definition at line 91 of file GreedyAmbiguitySolver.h.

91{1};

Referenced by configure(), and resolve().

◆ meas_collection_

std::string tracking::reco::GreedyAmbiguitySolver::meas_collection_ {"DigiTaggerSimHits"}
private

Definition at line 102 of file GreedyAmbiguitySolver.h.

102{"DigiTaggerSimHits"};

◆ n_meas_min_

std::size_t tracking::reco::GreedyAmbiguitySolver::n_meas_min_ {7}
private

Minimum number of measurement to form a track.

Definition at line 96 of file GreedyAmbiguitySolver.h.

96{7};

Referenced by computeInitialState(), configure(), and produce().

◆ out_trk_collection_

std::string tracking::reco::GreedyAmbiguitySolver::out_trk_collection_ {"TaggerTracksClean"}
private

Definition at line 98 of file GreedyAmbiguitySolver.h.

98{"TaggerTracksClean"};

◆ track_collection_

std::string tracking::reco::GreedyAmbiguitySolver::track_collection_ {"TaggerTracks"}
private

Definition at line 100 of file GreedyAmbiguitySolver.h.

100{"TaggerTracks"};

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