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

[DD4hep] Tool for creation of DD4hep geometry DB payloads and for migration validation #34111

Merged
merged 3 commits into from Jul 27, 2021

Conversation

cvuosalo
Copy link
Contributor

@cvuosalo cvuosalo commented Jun 14, 2021

There is a tool for expert use to create geometry DB payloads from DDD XML files. This PR provides a DD4hep version of the same tool. An initial decision was made to match the design and function of the DDD tool to reduce development risks and to facilitate validation.

Note that this tool is intended for the creation of Run 3 DD4hep geometry DB payloads. At this time, it is not anticipated that Runs 1-2 DB geometry payloads will be re-built. For Phase 2, the suitability of this design will have to be assessed, and changes may be necessary.

This tool produces the complete detector geometry in a human-readable XML file, which is not only suitable for loading into the DB but also can be used for diagnostics and validation.

There are two minor issues that will be addressed in follow-up PRs. The DB payload creation script currently has the reduced material scenarios commented out. A subsequent PR will implement those scenarios. Secondly, PPS uses a special XML payload for reconstruction, which is currently created with DDD. A later PR will implement creation of this payload with DD4hep.

Validation
The extended geometry description DB payload created by the tool was validated against its DDD counterpart incrementally, section by section, to ensure the content was identical. A stress test where the tool read its own output was also done to verify it would reproduce that output. Also, 100 ttbar events generated with DD4hep XML and DD4hep DB payloads were checked to verify that there were no significant differences in results. A RelVal is underway for further validation.

Reco geometry DB payloads were checked to see that they are identical to the ones created with DDD. The Tracker Reco geometry DB payload created with DD4hep is not numerically identical to the DDD version, but it was thoroughly checked to see that the content is the same as DDD, except for insignificant numerical variations. The output of DDDCmsTrackerContruction::printAllTrackerGeometricDets was checked, as well as the ModuleInfo.log, ModuleNumbering.dat, TECLayout_CMSSW.dat outputs from Geometry/TrackerGeometryBuilder/test/ModuleInfo.cc, and all were found to be the same for DD4hep and DDD. The only differences were phi angles equal to |pi| that varied between -pi and +pi, and tiny values near 0 that could varied between -1e-12 and +1e-12.

To avoid these variations in future comparisons when new DB payloads are candidates for uploading, this PR proposes that values in the DD4hep Tracker Reco geometry record (the PGeometricDet) be standardized as follows:

  • phi values of |pi| will be set to +pi.
  • Translation x, y, z values and rotation matrix elements that are <=|1e-10| will be set to true 0.
    This proposal has already been discussed with the Tracker DPG.

@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-34111/23303

@cmsbuild
Copy link
Contributor

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

It involves the following packages:

CondTools/Geometry
DetectorDescription/DDCMS
DetectorDescription/OfflineDBLoader

@civanch, @Dr15Jones, @makortel, @cvuosalo, @ianna, @mdhildreth, @cmsbuild, @ggovi can you please review it and eventually sign? Thanks.
@mmusich, @fabiocos, @slomeo, @vargasa this is something you requested to watch as well.
@silviodonato, @dpiparo, @qliphy you are the release manager for this.

cms-bot commands are listed here

@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-34111/23345

@cmsbuild
Copy link
Contributor

Pull request #34111 was updated. @civanch, @Dr15Jones, @makortel, @cvuosalo, @ianna, @mdhildreth, @cmsbuild, @ggovi can you please check and sign again.

Copy link
Contributor

@ianna ianna left a comment

Choose a reason for hiding this comment

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

@cvuosalo - IMHO, the whole approach is seriously flawed. It tries to re-implement the DDD Stores, but does it half way. It uses a full Geant4 geometry where a simpler and more elegant approach would do (e.g. DDD Graph).

@makortel - FYI

#include "G4Material.hh"
#include "G4ReflectionFactory.hh"
#include "TGeoManager.h"

Copy link
Contributor

Choose a reason for hiding this comment

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

@cvuosalo - it looks like a very complicated way to make one XML file out of a few XML files. You introduce dependency on ROOT, DD4hep, AND Geant4 to do that! A much more elegant and efficient way is to simply use DDD that creates a Graph.

@@ -19,6 +20,8 @@ namespace cms {

m_description = &dd4hep::Detector::getInstance(tag);
m_description->addExtension<cms::DDVectorsMap>(&m_vectors);
m_context = new cms::DDParsingContext(*m_description, makePayload);
Copy link
Contributor

Choose a reason for hiding this comment

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

@cvuosalo - is it a memory leak?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See below on line 34. In general use, when this code is not creating a DB payload, the parsing context is removed after the end of parsing. If I understand DD4hep correctly, the removeExtension method issues a delete on the pointer that was passed to addExtension.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please, do not expose an XML parsing context beyond an XML parser. Thanks.

@cvuosalo
Copy link
Contributor Author

Refinement and simplification is certainly possible as time allows. My first priority was to try to match the old DD DB payload as closely as possible. This whole design will need to be revisited for Phase 2 DD4hep, which has more challenging requirements than Run 3. I think Phase 2 is a good opportunity for considering new approaches for the DB payloads, since the DB payloads will be completely new. Some of the code in this PR might be useful for Phase 2, or maybe it will be dropped for an entirely different method.

@ianna
Copy link
Contributor

ianna commented Jun 17, 2021

Refinement and simplification is certainly possible as time allows. My first priority was to try to match the old DD DB payload as closely as possible. This whole design will need to be revisited for Phase 2 DD4hep, which has more challenging requirements than Run 3. I think Phase 2 is a good opportunity for considering new approaches for the DB payloads, since the DB payloads will be completely new. Some of the code in this PR might be useful for Phase 2, or maybe it will be dropped for an entirely different method.

The problem with this temporary solution is that an Assembly as an XML description is ignored. Once a payload is produced using this approach, we’d have to support it. This has a long time implication and restricts the future design. I’d suggest we do not use a DB payload for an ideal geometry description in DD4hep-based workflows until we have a proper solution.

@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-34111/23369

@cmsbuild
Copy link
Contributor

Pull request #34111 was updated. @civanch, @Dr15Jones, @makortel, @cvuosalo, @ianna, @mdhildreth, @cmsbuild, @ggovi can you please check and sign again.

Copy link
Contributor

@ianna ianna left a comment

Choose a reason for hiding this comment

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

some more questions

@@ -137,6 +137,7 @@ namespace cms {
UNICODE(rParent);
UNICODE(ChildName);
UNICODE(rChild);
UNICODE(rPhysVol);
Copy link
Contributor

Choose a reason for hiding this comment

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

@cvuosalo - why is it needed?

Copy link
Contributor

Choose a reason for hiding this comment

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

please, remove

@@ -860,6 +865,16 @@ void Converter<DDLPosPart>::operator()(xml_h element) const {
string childName = ns.prepend(ns.attr<string>(e.child(DD_CMU(rChild)), _U(name)));
Volume parent = ns.volume(parentName, false);
Volume child = ns.volume(childName, false);
xml_dim_t physVolName = e.child(DD_CMU(rPhysVol), false);
Copy link
Contributor

Choose a reason for hiding this comment

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

@cvuosalo - why not use to (re-)store an Assembly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this tag was my workaround since Assembly had no definition in XML until yesterday. But now that we can define assemblies in XML, this workaround can be dropped and replaced with explicit Assembly definitions, which are much more elegant.

@cvuosalo
Copy link
Contributor Author

The unit test errors appear to be unrelated to this PR and seem to be in the IB and related to:
#34601
#34587

@cvuosalo
Copy link
Contributor Author

The Event Setup warnings in CondTools/Geometry/plugins/PGeometricDetBuilder.cc should be resolved in a separate PR. The DB group may already be working on this as part of the ES migration to tokens.

@cvuosalo
Copy link
Contributor Author

@cms-sw/db-l2 Could you please review this PR soon? I would like to try to include it in 12_0_0_pre5 that is due July 27th. Thanks.

@cvuosalo
Copy link
Contributor Author

@cmsbuild please test with #34622

@cmsbuild
Copy link
Contributor

+1

Summary: https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-fb9c5d/17217/summary.html
COMMIT: a9b3ef1
CMSSW: CMSSW_12_0_X_2021-07-26-1100/slc7_amd64_gcc900
User test area: For local testing, you can use /cvmfs/cms-ci.cern.ch/week1/cms-sw/cmssw/34111/17217/install.sh to create a dev area with all the needed externals and cmssw changes.

CMS StaticAnalyzer warnings: There are 3 EventSetupRecord::get warnings. See https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-fb9c5d/17217/llvm-analysis/esrget-sa.txt for details.

Comparison Summary

Summary:

  • No significant changes to the logs found
  • Reco comparison results: 4 differences found in the comparisons
  • DQMHistoTests: Total files compared: 39
  • DQMHistoTests: Total histograms compared: 2998564
  • DQMHistoTests: Total failures: 7
  • DQMHistoTests: Total nulls: 0
  • DQMHistoTests: Total successes: 2998535
  • DQMHistoTests: Total skipped: 22
  • DQMHistoTests: Total Missing objects: 0
  • DQMHistoSizes: Histogram memory added: 0.0 KiB( 38 files compared)
  • Checked 165 log files, 37 edm output root files, 39 DQM output files
  • TriggerResults: no differences found

@civanch
Copy link
Contributor

civanch commented Jul 27, 2021

+1

@ggovi
Copy link
Contributor

ggovi commented Jul 27, 2021

+1

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

@civanch
Copy link
Contributor

civanch commented Jul 27, 2021

urgent

Copy link
Contributor

@ianna ianna left a comment

Choose a reason for hiding this comment

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

@cvuosalo - I still have a number of concerns about this code. We should discuss it offline.

# reco parts of the database are also filled.
cmsRun geometryExtended2021DD4hep_writer.py

# Now put the other scenarios into the database.
Copy link
Contributor

Choose a reason for hiding this comment

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

@cvuosalo - please, remove commented out code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As mentioned in the PR description, a forthcoming PR will enable these lines to produce the reduced material scenarios. Right now the lines serve as reminders of what will be implemented soon.

@@ -112,6 +114,12 @@ GeometricDet::GeometricDet(cms::DDFilteredView* fv, GeometricEnumType type)
shape_(fv->shape()),
params_(computeLegacyShapeParameters(shape_, fv->solid())),
isFromDD4hep_(true) {
using namespace angle_units::operators;
if (almostEqual(phi_, -1._pi, 10)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@cvuosalo - how much does it cost in terms of performance loss?

Copy link
Contributor

Choose a reason for hiding this comment

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

@ianna , I agree with your concerns but just today we should decide to merge this PR or to close it. We cannot improve it anymore.

I would propose to merge and for the next release 12_1_0 we should put efforts for the code optimization.

Copy link
Contributor Author

@cvuosalo cvuosalo Jul 27, 2021

Choose a reason for hiding this comment

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

These lines are executed when the GeometricDet is being built with DD4hep from XML. In production, the GeometricDet is read from the PGeometricDet in the DB, so this constructor is not called.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A quick check of the start-up time (including XML processing) of DD4hep XML workflow 11634.911 shows no significant difference between this PR and another PR test without this PR. More careful checks will be needed to determine whether this added function has a measurable effect on performance. Note that the almostEqual function is a simple template, so it shouldn't have much overhead.

Copy link
Contributor

Choose a reason for hiding this comment

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

These lines are executed when the GeometricDet is being built with DD4hep from XML. In production, the GeometricDet is read from the PGeometricDet in the DB, so this constructor is not called.

This is not true for the Phase 2 geometry that is using XML as a main source.

Copy link
Contributor

Choose a reason for hiding this comment

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

More careful checks will be needed to determine whether this added function has a measurable effect on performance. Note that the almostEqual function is a simple template, so it shouldn't have much overhead.

Yes, careful performance measurement ought to be done before merging the code. Any operation times the number of GeometricDets will have an effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Performance testing of this if statement shows no significant effect. The PGeometricDetBuilder, which creates the GeometricDet and copies it to a persistent version, was tested with and without this if check. The total user time in both cases was about 14.7 +- 0.2 seconds. It appears that the cost of this if statement is not significant compared to the time required to navigate through the geometry in order to calculate the GeometricDet.
For reference, in Run 3 there are 24508 GeometricDet records, with three cases where a phi value of -pi was calculated and reset to pi by this check.

@qliphy
Copy link
Contributor

qliphy commented Jul 27, 2021

+1

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

6 participants