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 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 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.
 
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

- 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

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) {}

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 measurementIndexMap =
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 ActsExamples::IndexSourceLink idx_sl(hit_surface->geometryId(), imeas);
69 Acts::SourceLink sourceLink = Acts::SourceLink(idx_sl);
70
71 auto emplace = measurementIndexMap.try_emplace(
72 sourceLink, measurementIndexMap.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 iTrack = 0; iTrack < state.number_of_tracks; ++iTrack) {
86 for (auto iMeasurement : state.measurements_per_track[iTrack]) {
87 state.tracks_per_measurement[iMeasurement].insert(iTrack);
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 iTrack = 0; iTrack < state.number_of_tracks; ++iTrack) {
95 for (auto iMeasurement : state.measurements_per_track[iTrack]) {
96 if (state.tracks_per_measurement[iMeasurement].size() > 1) {
97 ++state.shared_measurements_per_track[iTrack];
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_ = parameters.getParameter<std::string>(
167 "out_trk_collection", "TaggerTracksClean");
168
169 track_collection_ =
170 parameters.getParameter<std::string>("trackCollection", "TaggerTracks");
171
172 meas_collection_ = parameters.getParameter<std::string>("measCollection",
173 "DigiTaggerSimHits");
174 input_pass_name_ =
175 parameters.getParameter<std::string>("input_pass_name", "");
176 n_meas_min_ = parameters.getParameter<int>("nMeasurementsMin", 5);
177 maximum_shared_hits_ = parameters.getParameter<int>("maximumSharedHits", 1);
178}
std::uint32_t maximum_shared_hits_
Maximum amount of shared hits per track.

References 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 180 of file GreedyAmbiguitySolver.cxx.

180 {
181 GreedyAmbiguitySolver::State state;
182 std::vector<ldmx::Track> out_tracks;
183
184 auto tg{geometry()};
185
186 if (!event.exists(track_collection_, input_pass_name_)) {
187 ldmx_log(debug) << "Track collection not found, exiting";
188 return;
189 }
190 auto tracks{
191 event.getCollection<ldmx::Track>(track_collection_, input_pass_name_)};
192
193 if (!event.exists(meas_collection_, input_pass_name_)) {
194 ldmx_log(debug) << "Measurement collection not found, exiting";
195 return;
196 }
197 auto measurements{event.getCollection<ldmx::Measurement>(meas_collection_,
198 input_pass_name_)};
199
200 computeInitialState(tracks, measurements, state, tg,
201 tracking::sim::utils::sourceLinkHash,
202 tracking::sim::utils::sourceLinkEquality);
203 resolve(state);
204
205 for (auto iTrack : state.selected_tracks) {
206 auto clean_trk = tracks[state.track_tips.at(iTrack)];
207 if ((clean_trk.getNhits() > n_meas_min_) &&
208 (std::abs(1. / clean_trk.getQoP()) > 0.05)) {
209 out_tracks.push_back(clean_trk);
210 }
211 }
212
213 event.add(out_trk_collection_, out_tracks);
214
215 // for (auto iTrack : initial_state.selectedTracks) {
216 // std::cout << event.getEventNumber() << " " << iTrack << " " <<
217 // initial_state.trackChi2[iTrack] << " " <<
218 // initial_state.measurementsPerTrack[iTrack].size() << std::endl;
219 // }
220
221 ldmx_log(info) << " Resolved to " << state.selected_tracks.size()
222 << " tracks from "
223 << " " << tracks.size();
224}
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 iMeasurement : state.measurements_per_track[iTrack]) {
32 state.tracks_per_measurement[iMeasurement].erase(iTrack);
33 if (state.tracks_per_measurement[iMeasurement].size() == 1) {
34 auto jTrack = *state.tracks_per_measurement[iMeasurement].begin();
35 --state.shared_measurements_per_track[jTrack];
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 sharedMeasurementsComperator = [&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 trackComperator = [&state](std::size_t a, std::size_t b) {
116 auto relativeSharedMeasurements = [&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 (relativeSharedMeasurements(a) != relativeSharedMeasurements(b)) {
122 return relativeSharedMeasurements(a) < relativeSharedMeasurements(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 maximumSharedMeasurements = *std::max_element(
137 state.selected_tracks.begin(), state.selected_tracks.end(),
138 sharedMeasurementsComperator);
139 // ldmx_log(debug) <<
140 // "maximum shared measurements "
141 // << state.sharedMeasurementsPerTrack[maximumSharedMeasurements];
142 if (state.shared_measurements_per_track[maximumSharedMeasurements] <
144 break;
145 }
146
147 // Find the "worst" track by comparing them to each other
148 auto badTrack =
149 *std::max_element(state.selected_tracks.begin(),
150 state.selected_tracks.end(), trackComperator);
151 ldmx_log(trace) << "Remove track " << badTrack << ", nMeas = "
152 << state.measurements_per_track[badTrack].size()
153 << ", nShared = "
154 << state.shared_measurements_per_track[badTrack]
155 << ", chi2 =" << state.track_chi2[badTrack];
156 removeTrack(state, badTrack);
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: