Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix calculation of TrackingParticle::numberOfHits() #17382

Merged

Conversation

makortel
Copy link
Contributor

@makortel makortel commented Feb 2, 2017

The TrackingParticle::numberOfHits() (and the two other "number of hits") is calculated in a loop over the SimHits of a SimTrack, where only SimHits with the same particleType as the SimTrack's pdgId and the same particleType and processType as the "first hit" (or that's how the intention looks like). The purpose seems to be to ignore hits from e.g. delta rays or decays where the same SimTrack is reused.

I agree with the intention, but the definition of "first hit" is flawed. When iterating over the multimap from SimTrack id to an index in a vector<const PSimHit*> in
https://github.com/cms-sw/cmssw/blob/CMSSW_9_0_0_pre2/SimGeneral/TrackingAnalysis/plugins/TrackingTruthAccumulator.cc#L637-L674
the SimHits of a SimTracks are iterated in the order they get inserted in the multimap in
https://github.com/cms-sw/cmssw/blob/CMSSW_9_0_0_pre2/SimGeneral/TrackingAnalysis/plugins/TrackingTruthAccumulator.cc#L563-L566
The order of SimHits originates from
https://github.com/cms-sw/cmssw/blob/CMSSW_9_0_0_pre2/SimGeneral/TrackingAnalysis/plugins/TrackingTruthAccumulator.cc#L515-L530
and
https://github.com/cms-sw/cmssw/blob/CMSSW_9_0_0_pre2/SimGeneral/TrackingAnalysis/plugins/TrackingTruthAccumulator.cc#L306-L314
https://github.com/cms-sw/cmssw/blob/CMSSW_9_0_0_pre2/SimGeneral/MixingModule/python/trackingTruthProducer_cfi.py#L11-L27
i.e. first muon detectors, then pixel, and last (strip) tracker. If the "first hit" (according to the current logic) has particleType different from the SimTrack's pdgId, the resulting numberOfHits is zero. In phase0/1 this can happen if a non-muon particle decays to a muon resulting hit(s) in muon detectors. In phase2 the problem is exacerbated because also outer tracker SimHits are stored in the "pixel hit" collections, and for some reason for some SimTracks the OT SimHits have smaller index than pixel SimHits (typically leading to numberOfHits() being 0).

The proposed fix is to sort the SimHits by their timeOfFlight() before being inserted to the multimap, and ignore SimHits having particleType different from TrackingParticle pdgId from the "first hit" particleType+processType deduction (they are anyway ignored from the numberOfHits calculation already now).

But even this is not perfect, as there are cases where e.g. all SimHits have particleType different from TrackingParticle pdgId. So some further thought is still needed, but I think this PR is nevertheless an improvement. Similar fix is applied to TrackingParticleNumberOfHits as well.

Given that prior #17338 the TrackingParticles with numberOfHits()==0 were ignored in QuickTrackAssociatorByHits, this bug caused some legitimate track-TrackingParticle pairs to not be associated. Already alone this PR would give almost the same changes in track true/fake classification as #17338 (there are cases where all SimHits of a TrackingParticle have a different particleType from the TrackingParticle pdgId, so #17338 was anyway needed). On top of #17338, the plots showing the number of hits or layers are expected to show small changes.

Tested in CMSSW_9_0_X_2017-01-22-2300 (on top of #17338), expected changes in validation plots are described above. No changes are expected in reco quantities.

@rovere @VinInn @ebrondol @slava77

Because the processType and particleType are taken from the "first"
SimHit of a SimTrack, it is important to get the "first" right.
Previously it was the one with the smallest index in the SimHit
vector, but this fails for Phase2 tracker where also the outer tracker
(OT) SimHits are in the same event products as pixel SimHits, and for
some reason the OT SimHits are inserted before the pixel SimHits.

I believe using the time of flight is more robust way to decide which
SimHit is "first".
These are anyway ignored from the number of hit calculation, so let's
ignore them from the "first hit" deduction as well.
@makortel
Copy link
Contributor Author

makortel commented Feb 2, 2017

@cmsbuild, please test

@cmsbuild
Copy link
Contributor

cmsbuild commented Feb 2, 2017

The tests are being triggered in jenkins.
https://cmssdt.cern.ch/jenkins/job/ib-any-integration/17577/console Started: 2017/02/02 09:50

@cmsbuild
Copy link
Contributor

cmsbuild commented Feb 2, 2017

A new Pull Request was created by @makortel (Matti Kortelainen) for CMSSW_9_0_X.

It involves the following packages:

SimGeneral/TrackingAnalysis

@cmsbuild, @civanch, @mdhildreth, @davidlange6 can you please review it and eventually sign? Thanks.
@battibass, @abbiendi, @GiacomoSguazzoni, @jhgoh, @VinInn, @calderona, @HuguesBrun, @rovere, @trocino, @dgulhan this is something you requested to watch as well.
@davidlange6, @smuzaffar you are the release manager for this.

cms-bot commands are listed here #13028

@slava77
Copy link
Contributor

slava77 commented Feb 2, 2017

@makortel
with the sort and an extra loop, I'm curious if the CPU time remains roughly unchanged.
Could you please confirm

Thanks

@makortel
Copy link
Contributor Author

makortel commented Feb 2, 2017

@slava77 I must admit that I have not checked the impact on timing.

In TrackingTruthAccumulator the added sort will certainly have an effect, but, on the other hand, I'd expect the trackIdToHitIndex_.upper_bound() being called only once per SimTrack (instead of each iteration over the SimTrack SimHits) to compensate (both are O(n log(n)) with n being the number of SimHits).

In TrackingParticleNumberOfLayers there is already a sort, only the comparison function is made more complex. The added for does not add additional iteration over the SimHits, it is just to move the starting point of the main loop to the first SimHit with particleType equal to TrackingParticle's pdgId. Also here I'd expect CPU time to remain roughly the same.

@cmsbuild
Copy link
Contributor

cmsbuild commented Feb 2, 2017

@cmsbuild
Copy link
Contributor

cmsbuild commented Feb 2, 2017

Comparison job queued.

@cmsbuild
Copy link
Contributor

cmsbuild commented Feb 2, 2017

Comparison is ready
https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-17382/17577/summary.html

@slava77 comparisons for the following workflows were not done due to missing matrix map:

  • 20034.0_TTbar_14TeV+TTbar_14TeV_TuneCUETP8M1_2023D7_GenSimHLBeamSpotFull14+DigiFullTrigger_2023D7+RecoFullGlobal_2023D7+HARVESTFullGlobal_2023D7
  • 21234.0_TTbar_14TeV+TTbar_14TeV_TuneCUETP8M1_2023D4_GenSimHLBeamSpotFull14+DigiFullTrigger_2023D4+RecoFullGlobal_2023D4+HARVESTFullGlobal_2023D4
  • 23234.0_TTbar_14TeV+TTbar_14TeV_TuneCUETP8M1_2023D8_GenSimHLBeamSpotFull14+DigiFullTrigger_2023D8+RecoFullGlobal_2023D8+HARVESTFullGlobal_2023D8

@civanch
Copy link
Contributor

civanch commented Feb 2, 2017

+1

@cmsbuild
Copy link
Contributor

cmsbuild commented Feb 2, 2017

This pull request is fully signed and it will be integrated in one of the next CMSSW_9_0_X IBs (tests are also fine). This pull request requires discussion in the ORP meeting before it's merged. @davidlange6, @smuzaffar

@davidlange6
Copy link
Contributor

+1

@cmsbuild cmsbuild merged commit a5cd073 into cms-sw:CMSSW_9_0_X Feb 2, 2017
@makortel makortel deleted the fixTrackingParticleNumberOfHits branch February 12, 2018 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants