perf: Use map to accelerate parameter estimator #952
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While I was playing around with the seeding, I noticed that the
TrackParamsEstimationAlgorithm
was a significant source of overhead for high pile-up events. When processing events with 4000 pions, the time taken to run this algorithm starts to approach the runtime of seeding itself. For much larger events, in the neighbourhood of 12000 pions (where we get higher fake rates), the result was even worse with the track parameter estimation taking hundreds of milliseconds. The reason for this is simple: given |S| spacepoints (which in itself linear in the number of particles), the track parameter estimation performs an O(|S|) lookup operation for each of the O(1) hits in each seed. In total, there are O(|S|) (or even O(|S|3) in the uncapped case) seeds, and so the track parameter estimation is a somewhat expensive O(|S|2) algorithm.In this commit, I replace the O(|S|) lookup operation by an equivalent O(log |S|) operation permitted by
std::map
. This reduces the overall complexity to O(|S| log |S|), providing a significant speed-up. For the previously mentioned 12000 pion events, the processing time of this specific algorithm on my laptop drops from 259 milliseconds to 21 milliseconds: a speed-up of a factor twelve.