Skip to content

Fix calculation of speed in CloseByParticleGunProducer#50241

Open
felicepantaleo wants to merge 6 commits intocms-sw:masterfrom
felicepantaleo:fix_closeby_time_16_1_0_pre2
Open

Fix calculation of speed in CloseByParticleGunProducer#50241
felicepantaleo wants to merge 6 commits intocms-sw:masterfrom
felicepantaleo:fix_closeby_time_16_1_0_pre2

Conversation

@felicepantaleo
Copy link
Copy Markdown
Contributor

This PR fixes the time-of-flight calculation in CloseByParticleGunProducer by using the full particle speed (|p|/E * c) instead of the z-velocity component (pz/E * c).
Using pz/E introduced an unphysical dependence on the sign of pz, which can lead to asymmetries in timing vs η.
The patch also updates the magnetic bending radius calculation to use the momentum magnitude and absolute charge.
This makes the path-length/time computation physically consistent for charged particles.
No interface changes; only the internal timing/path calculation is corrected.

@bfonta @AuroraPerego

@felicepantaleo
Copy link
Copy Markdown
Contributor Author

@cmsbuild please test

@cmsbuild
Copy link
Copy Markdown
Contributor

cmsbuild commented Feb 24, 2026

cms-bot internal usage

@cmsbuild
Copy link
Copy Markdown
Contributor

@cmsbuild
Copy link
Copy Markdown
Contributor

A new Pull Request was created by @felicepantaleo for master.

It involves the following packages:

  • IOMC/ParticleGuns (generators)

@cmsbuild, @lviliani, @mkirsano, @sensrcn, @theofil can you please review it and eventually sign? Thanks.
@fabiocos, @grzanka this is something you requested to watch as well.
@ftenchini, @mandrenguyen, @sextonkennedy you are the release manager for this.

cms-bot commands are listed here

@felicepantaleo
Copy link
Copy Markdown
Contributor Author

@cmsbuild please test

@bfonta
Copy link
Copy Markdown
Contributor

bfonta commented Feb 24, 2026

I performed the validation of the proposed fix.
The validation was performed with CloseBy electron samples for Run3 (2025), no PU, $|\eta|<1.3$, two particles at an arc-distance along the azimuthal angle of 20 centimeters, generated in front of the ECAL surface, and only looking at ECAL collections.

Time Validation

  • Before the fix:
RecoClustersEn_Time_CloseByElectron20p0_Run3 RecoClustersEta_Time_CloseByElectron20p0_Run3
  • After the fix:
RecoClustersEn_Time_AFTERFIX RecoClustersEta_Time_AFTERFIX

Response Validation (Run3 2025, no PU):

  • Before the fix:
ResponseE_Eta_Projected ResponseE_Eta
  • After the fix:
ResponseE_Eta_Projected_AFTERFIX ResponseE_Eta_AFTERFIX

Both the CloseBy timing and response now behave as expected.

See below the same plots for a SingleElectron gun for comparison (the high-energy tail is likely due to interactions with the tracker):

RecoClustersEn_Time_SingleElectron_Run3 RecoClustersEta_Time_SingleElectron_Run3 ResponseE_Eta_SingleElectron

@cmsbuild
Copy link
Copy Markdown
Contributor

+1

Size: This PR adds an extra 24KB to repository
Summary: https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-b4ca3b/51562/summary.html
COMMIT: a64c1b7
CMSSW: CMSSW_16_1_X_2026-02-24-1100/el8_amd64_gcc13
User test area: For local testing, you can use /cvmfs/cms-ci.cern.ch/week0/cms-sw/cmssw/50241/51562/install.sh to create a dev area with all the needed externals and cmssw changes.

Comparison Summary

Summary:

  • You potentially added 2 lines to the logs
  • Reco comparison results: 832 differences found in the comparisons
  • DQMHistoTests: Total files compared: 53
  • DQMHistoTests: Total histograms compared: 4172678
  • DQMHistoTests: Total failures: 1325
  • DQMHistoTests: Total nulls: 0
  • DQMHistoTests: Total successes: 4171333
  • DQMHistoTests: Total skipped: 20
  • DQMHistoTests: Total Missing objects: 0
  • DQMHistoSizes: Histogram memory added: 0.0 KiB( 52 files compared)
  • Checked 227 log files, 198 edm output root files, 53 DQM output files
  • TriggerResults: found differences in 1 / 51 workflows

@@ -239,11 +239,12 @@ void CloseByParticleGunProducer::produce(Event& e, const EventSetup& es) {

// compute correct path assuming uniform magnetic field in CMS
double pathLength = 0.;
const double speed = p.pz() / p.e() * c_light / CLHEP::cm;
const double pabs = std::sqrt(p.px() * p.px() + p.py() * p.py() + p.pz() * p.pz());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One could use p.mag() instead of pabs [reference].

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some discussion with @AuroraPerego, we realized there is ambiguity in the definitions of px() and x() (and the same for the other components). Still, using .mag() for the case at hand should be correct.
To be noted that here we should use .setPx() and friends instead of .setX() and friends, for clarity. They do exactly the same operation, though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @bfonta
mag() was replaced by rho() in the version of hepmc we are using in cmssw. std::hypot is more stable, I moved to use that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felicepantaleo Note that std::hypot will be slower than std::sqrt(x*x + y*y) due to overflow and underflow guarantees.

@cmsbuild
Copy link
Copy Markdown
Contributor

@felicepantaleo
Copy link
Copy Markdown
Contributor Author

@cmsbuild please test

@cmsbuild
Copy link
Copy Markdown
Contributor

This pull request is fully signed and it will be integrated in one of the next master IBs (tests are also fine). This pull request will now be reviewed by the release team before it's merged. @ftenchini, @mandrenguyen, @sextonkennedy (and backports should be raised in the release meeting by the corresponding L2)

@mandrenguyen
Copy link
Copy Markdown
Contributor

mandrenguyen commented Apr 23, 2026

@felicepantaleo The problem is not who can merge the PR. The problem is it has to be fully signed before it can be merged. This is done now, so once you fix the conflicts, we will merge it (assuming the tests still pass).

@felicepantaleo
Copy link
Copy Markdown
Contributor Author

@cmsbuild please test

@cmsbuild
Copy link
Copy Markdown
Contributor

@cmsbuild
Copy link
Copy Markdown
Contributor

Pull request #50241 was updated. @lviliani, @mkirsano, @sensrcn, @theofil can you please check and sign again.

@cmsbuild
Copy link
Copy Markdown
Contributor

+1

Size: This PR adds an extra 24KB to repository
Summary: https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-b4ca3b/52885/summary.html
COMMIT: 0c0a881
CMSSW: CMSSW_17_0_X_2026-04-26-2300/el8_amd64_gcc13
User test area: For local testing, you can use /cvmfs/cms-ci.cern.ch/week1/cms-sw/cmssw/50241/52885/install.sh to create a dev area with all the needed externals and cmssw changes.

Comparison Summary

Summary:

  • You potentially removed 5 lines from the logs
  • ROOTFileChecks: Some differences in event products or their sizes found
  • Reco comparison results: 804 differences found in the comparisons
  • DQMHistoTests: Total files compared: 53
  • DQMHistoTests: Total histograms compared: 4186963
  • DQMHistoTests: Total failures: 652
  • DQMHistoTests: Total nulls: 0
  • DQMHistoTests: Total successes: 4186291
  • DQMHistoTests: Total skipped: 20
  • DQMHistoTests: Total Missing objects: 0
  • DQMHistoSizes: Histogram memory added: 0.0 KiB( 52 files compared)
  • Checked 227 log files, 197 edm output root files, 53 DQM output files
  • TriggerResults: found differences in 1 / 51 workflows

@felicepantaleo
Copy link
Copy Markdown
Contributor Author

@bfonta can you post again the plots with this rebase?

@bfonta
Copy link
Copy Markdown
Contributor

bfonta commented Apr 27, 2026

Yes, but only once I've understood the segmentation violation that arises when fixing the conflicts in #50292.

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.

6 participants