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

Optimized version of G4 Dormand Prince RK stepper #38849

Merged
merged 10 commits into from Aug 3, 2022

Conversation

VinInn
Copy link
Contributor

@VinInn VinInn commented Jul 25, 2022

The G4 Dormand Prince RK stepper has been optimized to profit of the constant inverse momentum of a particle during a single step.
The files that needed to be modified have been copied in SimG4Core/MagneticField/src and renamed (as well as the two corresponding classes).
Took the opportunity for few more optimizations specific to the CMS magnetic field.

The stepper is now ~30% faster.
TTbar simulation is globally ~3% faster.

Some floating point computation has changed. One cannot exclude regression due to the sensitivity of G4 to small path deviations.

@cmsbuild
Copy link
Contributor

-code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-38849/31240

  • This PR adds an extra 24KB to repository

  • Found files with invalid states:

    • SimG4Core/MagneticField/src/G4TDormandPrince45.h:
    • SimG4Core/MagneticField/src/G4TMagFieldEquation.h:

Code check has found code style and quality issues which could be resolved by applying following patch(s)

@VinInn
Copy link
Contributor Author

VinInn commented Jul 25, 2022

@cmsbuild , please test

@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-38849/31242

  • This PR adds an extra 24KB to repository

  • Found files with invalid states:

    • SimG4Core/MagneticField/src/G4TDormandPrince45.h:
    • SimG4Core/MagneticField/src/G4TMagFieldEquation.h:

@cmsbuild
Copy link
Contributor

A new Pull Request was created by @VinInn (Vincenzo Innocente) for master.

It involves the following packages:

  • SimG4Core/MagneticField (simulation)

@civanch, @mdhildreth can you please review it and eventually sign? Thanks.
@namapane, @makortel, @rovere, @bsunanda, @fabiocos, @slomeo this is something you requested to watch as well.
@perrotta, @dpiparo, @qliphy, @rappoccio you are the release manager for this.

cms-bot commands are listed here


#include "DataFormats/GeometryVector/interface/GlobalPoint.h"

#include "CLHEP/Units/GlobalSystemOfUnits.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

@VinInn , this header should not be used in header file, we are trying do not use units in headers. Alternatively, use

#include <CLHEP/Units/SystemOfUnits.h>

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 need to inline the method.

@@ -53,7 +56,9 @@ void FieldStepper::selectStepper(const std::string &ss) {
else if (ss == "G4DormandPrince745")
theStepper = new G4DormandPrince745(theEquation);
else if (ss == "G4TDormandPrince45")
Copy link
Contributor

Choose a reason for hiding this comment

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

@VinInn , old DormandPrince better do not remove, living the possibility to compare CPU performance and results. G4TDormandPrince45CMS can be added as an alternative: we have more than 10 steppers, some we did not used at so far. Addition of an extra changes nothing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok.
where I can change the default to "G4TDormandPrince45CMS"?

Copy link
Contributor

Choose a reason for hiding this comment

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

Inside SimG4Core/Application/python/g4SimHits_cfi.py

@@ -0,0 +1,88 @@
//
// ********************************************************************
Copy link
Contributor

Choose a reason for hiding this comment

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

G4 disclaimer better to remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are we sure that we are authorized to copy a G4 file and remove the discaimer?

Copy link
Contributor

Choose a reason for hiding this comment

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

there was a campaign few years ago to do this, because CMSSW should not distribute original Geant4 code. In the header, it is possible to say that it is a CMS modification of the original G4TDormandPrince45.

We have several modified Geant4 classes - it is not in contradiction with Geant4 license. By the way, with time they may be very different from the original. In several cases (not in all) I replace "G4" to "CMS" in class names, however, few remains, likely the campaign should be completed. In general, it is more clear if classes from CMSSW do not start from "G4".

@@ -0,0 +1,469 @@
//
Copy link
Contributor

Choose a reason for hiding this comment

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

G4 disclaimer better to remove.

@@ -15,7 +15,7 @@
#include "G4FieldManager.hh"
#include "G4LogicalVolumeStore.hh"
#include "G4Mag_UsualEqRhs.hh"
#include "G4TMagFieldEquation.hh"
Copy link
Contributor

Choose a reason for hiding this comment

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

better to keep the G4 equation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will make all changes once the tests are finished

@@ -20,4 +24,26 @@ namespace sim {
mutable double oldb[3];
};
}; // namespace sim

void sim::Field::GetFieldValue(const G4double xyz[], G4double bfield[3]) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

@VinInn , sorry for trivial question: in new compilers virtual methods may be successfully inlined? Is there any advantage in CPU?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is indeed inlined (as I finalized and it is used as such thanks to the template)
I observed gain in performance

Copy link
Contributor

Choose a reason for hiding this comment

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

It is because it is "final"? or recent compilers can understand inline virtual?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because it is final and the caller has a pointer of type sim::Field* not of the parent.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good to know! We have number of run time places in Geant4 and may be few in CMSSW SIM, where this can be used.

@cmsbuild
Copy link
Contributor

+1

Summary: https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-ce54ab/26434/summary.html
COMMIT: d40d970
CMSSW: CMSSW_12_5_X_2022-07-24-2300/el8_amd64_gcc10
User test area: For local testing, you can use /cvmfs/cms-ci.cern.ch/week1/cms-sw/cmssw/38849/26434/install.sh to create a dev area with all the needed externals and cmssw changes.

Comparison Summary

Summary:

  • No significant changes to the logs found
  • Reco comparison results: 68010 differences found in the comparisons
  • DQMHistoTests: Total files compared: 51
  • DQMHistoTests: Total histograms compared: 3667670
  • DQMHistoTests: Total failures: 481117
  • DQMHistoTests: Total nulls: 368
  • DQMHistoTests: Total successes: 3186163
  • DQMHistoTests: Total skipped: 22
  • DQMHistoTests: Total Missing objects: 0
  • DQMHistoSizes: Histogram memory added: 2.2259999999999995 KiB( 50 files compared)
  • DQMHistoSizes: changed ( 10224.0 ): 0.065 KiB SiStrip/MechanicalView
  • DQMHistoSizes: changed ( 11834.0 ): 1.259 KiB SiStrip/MechanicalView
  • DQMHistoSizes: changed ( 250202.181 ): 0.580 KiB SiStrip/MechanicalView
  • DQMHistoSizes: changed ( 25202.0 ): -0.660 KiB SiStrip/MechanicalView
  • DQMHistoSizes: changed ( 312.0 ): -0.004 KiB MessageLogger/Warnings
  • DQMHistoSizes: changed ( 7.3 ): -1.084 KiB SiStrip/MechanicalView
  • DQMHistoSizes: changed ( 8.0 ): 2.070 KiB SiStrip/MechanicalView
  • Checked 210 log files, 47 edm output root files, 51 DQM output files
  • TriggerResults: found differences in 14 / 50 workflows

@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-38849/31343

  • This PR adds an extra 36KB to repository

  • Found files with invalid states:

    • SimG4Core/MagneticField/src/G4TMagFieldEquationCMS.h:
    • SimG4Core/MagneticField/src/G4TDormandPrince45.h:
    • SimG4Core/MagneticField/src/G4TMagFieldEquation.h:
    • SimG4Core/MagneticField/src/G4TDormandPrince45CMS.h:

@cmsbuild
Copy link
Contributor

Pull request #38849 was updated. @cmsbuild, @civanch, @mdhildreth can you please check and sign again.

@civanch
Copy link
Contributor

civanch commented Jul 31, 2022

please test

@cmsbuild
Copy link
Contributor

-1

Failed Tests: UnitTests
Summary: https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-ce54ab/26548/summary.html
COMMIT: 1734467
CMSSW: CMSSW_12_5_X_2022-07-30-1100/el8_amd64_gcc10
User test area: For local testing, you can use /cvmfs/cms-ci.cern.ch/week1/cms-sw/cmssw/38849/26548/install.sh to create a dev area with all the needed externals and cmssw changes.

Unit Tests

I found errors in the following unit tests:

---> test test-das-selected-lumis had ERRORS

Comparison Summary

Summary:

  • No significant changes to the logs found
  • Reco comparison results: 0 differences found in the comparisons
  • DQMHistoTests: Total files compared: 51
  • DQMHistoTests: Total histograms compared: 3668050
  • DQMHistoTests: Total failures: 2
  • DQMHistoTests: Total nulls: 0
  • DQMHistoTests: Total successes: 3668026
  • DQMHistoTests: Total skipped: 22
  • DQMHistoTests: Total Missing objects: 0
  • DQMHistoSizes: Histogram memory added: 0.0 KiB( 50 files compared)
  • Checked 210 log files, 47 edm output root files, 51 DQM output files
  • TriggerResults: no differences found

@civanch
Copy link
Contributor

civanch commented Jul 31, 2022

please test

there was DAS error

@cmsbuild
Copy link
Contributor

cmsbuild commented Aug 1, 2022

+1

Summary: https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-ce54ab/26552/summary.html
COMMIT: 1734467
CMSSW: CMSSW_12_5_X_2022-07-31-0000/el8_amd64_gcc10
User test area: For local testing, you can use /cvmfs/cms-ci.cern.ch/week0/cms-sw/cmssw/38849/26552/install.sh to create a dev area with all the needed externals and cmssw changes.

Comparison Summary

Summary:

  • No significant changes to the logs found
  • Reco comparison results: 6 differences found in the comparisons
  • DQMHistoTests: Total files compared: 51
  • DQMHistoTests: Total histograms compared: 3669004
  • DQMHistoTests: Total failures: 19
  • DQMHistoTests: Total nulls: 1
  • DQMHistoTests: Total successes: 3668962
  • DQMHistoTests: Total skipped: 22
  • DQMHistoTests: Total Missing objects: 0
  • DQMHistoSizes: Histogram memory added: 0.004 KiB( 50 files compared)
  • DQMHistoSizes: changed ( 312.0 ): 0.004 KiB MessageLogger/Warnings
  • Checked 210 log files, 47 edm output root files, 51 DQM output files
  • TriggerResults: no differences found

@civanch
Copy link
Contributor

civanch commented Aug 1, 2022

+1

@cmsbuild
Copy link
Contributor

cmsbuild commented Aug 1, 2022

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. @perrotta, @dpiparo, @qliphy, @rappoccio (and backports should be raised in the release meeting by the corresponding L2)

@qliphy
Copy link
Contributor

qliphy commented Aug 3, 2022

+1

@cmsbuild cmsbuild merged commit be16b47 into cms-sw:master Aug 3, 2022
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