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

Adding angle utilities #26227

Merged
merged 15 commits into from May 28, 2019
Merged

Adding angle utilities #26227

merged 15 commits into from May 28, 2019

Conversation

cvuosalo
Copy link
Contributor

@cvuosalo cvuosalo commented Mar 20, 2019

PR description:

In many spots in CMSSW, code like the following appears:

if (pointphi >= twopi)
     pointphi -= twopi;
if(pointphi < 0)
     pointphi += twopi;

The intent is to constrain the angle to the range 0<= angle < 2pi, but the code, as in this example, sometimes doesn't handle the case of an |angle| >= 4pi.

DataFormats/Math/interface/deltaPhi.h provides a reduceRange() function for this purpose, but tests show this function is not as fast as it could be, and it suffers from sensitivity in its if statement to small deviations from pi.

This PR adds a new function make0to2pi, that can be significantly faster than reduceRange() and that greatly reduces value drift due to floating-point comparisons. This new function is added without changing the implementation of reduceRange() because changing reduceRange() could cause slight differences in program behavior. Usage of reduceRange() can later be replaced on a case-by-case basis where better performance and precision is required.

The Phi class in DataFormats/GeometryVector/interface/Phi.h represents an angle that maintains a value from -pi to pi. This PR enhances this class in a backwardly compatible fashion to allow the option of keeping the angle in the range from 0 to 2pi.

In addition, the generic angle utilities in the GeantUnits.h file are moved to deltaPhi.h because they are not Geant-specific and should be usable without subjecting code to Geant conventions.

PR validation:

A unit test program is included in this PR, and it verifies basic functions of the code and gives some rough performance measures.

Some performance results comparing reduceRange() and make0to2pi are shown below.

The entry for the Phi templates in the classes_def.xml file uses ClassVersion 3 because the revised template is effectively a new class. No problems with the ROOT dictionary for Phi were observed. Using baseline CMSSW_10_6_0_pre2 code without this PR, I wrote a Phi variable to a ROOT file. Then, with the new PR code, I could successfully read the Phi variable out of that same ROOT file, so there appears to be backwards compatibility in reading old ROOT files containing the Phi class. However, a scan of CMSSW finds no cases where Phi variables were written to ROOT files, so it doesn't look like the ability to read the old version of Phi variables in ROOT files is even needed.

No backport is needed.

@cmsbuild
Copy link
Contributor

The code-checks are being triggered in jenkins.

@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-26227/8851

  • This PR adds an extra 20KB to repository

@cmsbuild
Copy link
Contributor

A new Pull Request was created by @cvuosalo (Carl Vuosalo) for master.

It involves the following packages:

DataFormats/Math

@cmsbuild, @perrotta, @slava77 can you please review it and eventually sign? Thanks.
@makortel, @felicepantaleo, @rovere this is something you requested to watch as well.
@davidlange6, @slava77, @fabiocos you are the release manager for this.

cms-bot commands are listed here

@cvuosalo cvuosalo closed this Mar 20, 2019
@cvuosalo cvuosalo reopened this Mar 20, 2019
@cvuosalo
Copy link
Contributor Author

@ianna: Please review and let us know if you approve.
@bsunanda: FYI

@cvuosalo
Copy link
Contributor Author

@VinInn, @fwyzard: If you have time and would like to comment, we would appreciate your thoughts on the following questions. For angle values that need to be kept in the range [0, 2pi), what coding approach best balances reliability, developer convenience, and performance? Does this PR achieve this balance, or could it be improved?

@cvuosalo
Copy link
Contributor Author

@cmsbuild please test

@cmsbuild
Copy link
Contributor

cmsbuild commented Mar 20, 2019

The tests are being triggered in jenkins.
https://cmssdt.cern.ch/jenkins/job/ib-any-integration/33694/console Started: 2019/03/20 23:27

@cmsbuild
Copy link
Contributor

@cmsbuild
Copy link
Contributor

Comparison job queued.

@cmsbuild
Copy link
Contributor

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

Comparison Summary:

  • No significant changes to the logs found
  • Reco comparison results: 0 differences found in the comparisons
  • DQMHistoTests: Total files compared: 32
  • DQMHistoTests: Total histograms compared: 3114829
  • DQMHistoTests: Total failures: 1
  • DQMHistoTests: Total nulls: 0
  • DQMHistoTests: Total successes: 3114631
  • DQMHistoTests: Total skipped: 197
  • DQMHistoTests: Total Missing objects: 0
  • DQMHistoSizes: Histogram memory added: 0.0 KiB( 31 files compared)
  • Checked 133 log files, 14 edm output root files, 32 DQM output files

@VinInn
Copy link
Contributor

VinInn commented Mar 21, 2019

Sorry, there are already N version of it.
What's wrong with
https://cmssdt.cern.ch/dxr/CMSSW/source/DataFormats/Math/interface/deltaPhi.h#14
?

@cmsbuild
Copy link
Contributor

@cmsbuild
Copy link
Contributor

Comparison job queued.

@cmsbuild
Copy link
Contributor

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

Comparison Summary:

  • No significant changes to the logs found
  • Reco comparison results: 5766 differences found in the comparisons
  • DQMHistoTests: Total files compared: 33
  • DQMHistoTests: Total histograms compared: 3212004
  • DQMHistoTests: Total failures: 7765
  • DQMHistoTests: Total nulls: 0
  • DQMHistoTests: Total successes: 3203905
  • DQMHistoTests: Total skipped: 334
  • DQMHistoTests: Total Missing objects: 0
  • DQMHistoSizes: Histogram memory added: 0.0 KiB( 32 files compared)
  • Checked 137 log files, 14 edm output root files, 33 DQM output files

@cvuosalo
Copy link
Contributor Author

As before, the comparison test differences are almost entirely in two Phase 2 simulation workflows which have different random sequences in the SIM step. These differences are not due to this PR.

I think all issues in this PR have been addressed, so I hope it can be soon approved.

@cvuosalo
Copy link
Contributor Author

+1

@perrotta
Copy link
Contributor

+1

@fabiocos
Copy link
Contributor

@civanch @kpedro88 do you have further comments?

@civanch
Copy link
Contributor

civanch commented May 21, 2019

+1

@kpedro88
Copy link
Contributor

+upgrade

@cmsbuild
Copy link
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. @davidlange6, @slava77, @smuzaffar, @fabiocos (and backports should be raised in the release meeting by the corresponding L2)

@kpedro88
Copy link
Contributor

+1

@cmsbuild cmsbuild merged commit 1007a44 into cms-sw:master May 28, 2019
// calling fmod to improve performance.

template <class valType>
inline constexpr valType make0To2pi(valType angle) {
Copy link
Contributor

Choose a reason for hiding this comment

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

commenting here instead of in #27637

about angle0to2pi
IMHO, it would be more consistent to move it up in this file to the reco namespace and rename to reduceRange0To2pi
Also, if it's implementation is really faster, replace the current reduceRange of [-pi,pi] with the faster variant.

Copy link
Contributor

Choose a reason for hiding this comment

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

@slava77 and @cvuosalo - can we think of other then reco namespace? It would be confusing if the DD code uses reco::

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Concerning the possible replacement of reduceRange: Since make0To2pi checks for floating-point value drift over repeated calculations and reduceRange does not, there is a good possibility that comparison tests for replacing reduceRange would show small differences. make0To2pi should provide more correct results, but it would be required to show that the comparison test differences were correct, appropriate, and desirable, which might be a challenge. I did not replace reduceRange in this PR for this very reason.

Perhaps replacement could be done on a step-by-step basis by developers familiar with the applications getting changed so that the comparison differences would be easier to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd suggest putting everything in the file in the delta_phi namespace to match the header file name, but I don't have a strong opinion about namespace naming.

Copy link
Contributor

Choose a reason for hiding this comment

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

About the small differences, it should be acceptable, considering the expected speedup and improved numerical precision (unless perhaps a PR comes after the deadline with an "urgent" tag and some unrelated changes inside).

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