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

Update of the DT migration to DD4HEP #31043

Merged
merged 18 commits into from Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions Geometry/DTGeometryBuilder/plugins/DTGeometryValidate.cc
Expand Up @@ -82,11 +82,13 @@ class DTGeometryValidate : public one::EDAnalyzer<> {

DTGeometryValidate::DTGeometryValidate(const edm::ParameterSet& iConfig)
: dtGeometryToken_{esConsumes<DTGeometry, MuonGeometryRecord>(edm::ESInputTag{})},
infileName_(iConfig.getUntrackedParameter<string>("infileName", "cmsGeom10.root")),
//infileName_(iConfig.getUntrackedParameter<string>("infileName", "Geometry/DTGeometryBuilder/data/cmsRecoGeom-2021.root")),
outfileName_(iConfig.getUntrackedParameter<string>("outfileName", "validateDTGeometry.root")),
tolerance_(iConfig.getUntrackedParameter<int>("tolerance", 6)) {
fwGeometry_.loadMap(infileName_.c_str());
outFile_ = new TFile(outfileName_.c_str(), "RECREATE");
edm::FileInPath fp("Geometry/DTGeometryBuilder/data/cmsRecoGeom-2021.root");
Copy link
Contributor

Choose a reason for hiding this comment

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

@slomeo , may be you can keep the infileName as a configurable parameter in validateDTGeometry_cfg.py and use

edm::FileInPath fp(infileName_.c_str());

fwGeometry_.loadMap(fp.fullPath().c_str());
//fwGeometry_.loadMap(infileName_.c_str());
outFile_ = TFile::Open(outfileName_.c_str(), "RECREATE");
}

void DTGeometryValidate::analyze(const edm::Event& event, const edm::EventSetup& eventSetup) {
Expand Down
47 changes: 23 additions & 24 deletions Geometry/DTGeometryBuilder/plugins/dd4hep/DTGeometryBuilder.cc
Expand Up @@ -14,6 +14,7 @@
//
// Original Author: Ianna Osborne
// Created: Wed, 16 Jan 2019 10:19:37 GMT
// Modified by Sergio Lo Meo (sergio.lo.meo@cern.ch) Tue, 04 August 2020
//
//
#include "CondFormats/GeometryObjects/interface/RecoIdealGeometry.h"
Expand All @@ -28,15 +29,15 @@
#include "DataFormats/GeometrySurface/interface/Plane.h"
#include "DataFormats/GeometrySurface/interface/Bounds.h"
#include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h"

#include "Geometry/MuonNumbering/interface/DD4hep_MuonNumbering.h"
#include "Geometry/MuonNumbering/interface/MuonGeometryNumbering.h"
#include "Geometry/Records/interface/MuonNumberingRecord.h"
#include "Geometry/Records/interface/MuonGeometryRecord.h"
#include "Geometry/Records/interface/GeometryFileRcd.h"
#include "DetectorDescription/DDCMS/interface/DDDetector.h"
#include "DetectorDescription/DDCMS/interface/DDFilteredView.h"
#include "Geometry/DTGeometry/interface/DTGeometry.h"
#include "Geometry/MuonNumbering/interface/DD4hep_DTNumberingScheme.h"
#include "Geometry/MuonNumbering/interface/MuonBaseNumber.h"
#include "Geometry/MuonNumbering/interface/DTNumberingScheme.h"
#include "DTGeometryBuilder.h"
#include "DD4hep/Detector.h"

Expand All @@ -48,7 +49,7 @@ using namespace edm;
using namespace std;
using namespace cms;

void DTGeometryBuilder::buildGeometry(DDFilteredView& fview, DTGeometry& geom, const MuonNumbering& num) const {
void DTGeometryBuilder::buildGeometry(DDFilteredView& fview, DTGeometry& geom, const MuonGeometryConstants& num) const {
bool doChamber = fview.firstChild();

while (doChamber) {
Expand Down Expand Up @@ -90,13 +91,13 @@ DTGeometryBuilder::RCPPlane DTGeometryBuilder::plane(const DDFilteredView& fview
bounds));
}

DTChamber* DTGeometryBuilder::buildChamber(DDFilteredView& fview, const MuonNumbering& muonConstants) const {
int rawid = dtnum_->getDetId(muonConstants.geoHistoryToBaseNumber(fview.history()));
DTChamber* DTGeometryBuilder::buildChamber(DDFilteredView& fview, const MuonGeometryConstants& muonConstants) const {
MuonGeometryNumbering mdddnum(muonConstants);
DTNumberingScheme dtnum(muonConstants);
int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fview.history()));

DTChamberId detId(rawid);
auto const& par = fview.parameters();
// par[0] r-phi dimension - different in different chambers
// par[1] z dimension - constant 125.55 cm
// par[2] radial thickness - almost constant about 18 cm

RCPPlane surf(plane(fview, new RectangularPlaneBounds(par[0], par[1], par[2])));

Expand All @@ -107,16 +108,15 @@ DTChamber* DTGeometryBuilder::buildChamber(DDFilteredView& fview, const MuonNumb

DTSuperLayer* DTGeometryBuilder::buildSuperLayer(DDFilteredView& fview,
DTChamber* chamber,
const MuonNumbering& muonConstants) const {
int rawid = dtnum_->getDetId(muonConstants.geoHistoryToBaseNumber(fview.history()));
const MuonGeometryConstants& muonConstants) const {
MuonGeometryNumbering mdddnum(muonConstants);
DTNumberingScheme dtnum(muonConstants);
int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fview.history()));

DTSuperLayerId slId(rawid);

auto const& par = fview.parameters();
// par[0] r-phi dimension - changes in different chambers
// par[1] z dimension - constant 126.8 cm
// par[2] radial thickness - almost constant about 20 cm

// Ok this is the slayer position...
RCPPlane surf(plane(fview, new RectangularPlaneBounds(par[0], par[1], par[2])));

DTSuperLayer* slayer = new DTSuperLayer(slId, surf, chamber);
Expand All @@ -129,21 +129,21 @@ DTSuperLayer* DTGeometryBuilder::buildSuperLayer(DDFilteredView& fview,

DTLayer* DTGeometryBuilder::buildLayer(DDFilteredView& fview,
DTSuperLayer* sl,
const MuonNumbering& muonConstants) const {
int rawid = dtnum_->getDetId(muonConstants.geoHistoryToBaseNumber(fview.history()));
const MuonGeometryConstants& muonConstants) const {
MuonGeometryNumbering mdddnum(muonConstants);
DTNumberingScheme dtnum(muonConstants);
int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fview.history()));

DTLayerId layId(rawid);

auto const& par = fview.parameters();
// Layer specific parameter (size)
// par[0] r-phi dimension - changes in different chambers
// par[1] z dimension - constant 126.8 cm
// par[2] radial thickness - almost constant about 20 cm

RCPPlane surf(plane(fview, new RectangularPlaneBounds(par[0], par[1], par[2])));

// Loop on wires
fview.down();
bool doWire = fview.sibling();
int firstWire = fview.volume()->GetNumber(); // copy no
int firstWire = fview.volume()->GetNumber();
auto const& wpar = fview.parameters();
float wireLength = wpar[1];

Expand All @@ -166,11 +166,10 @@ DTLayer* DTGeometryBuilder::buildLayer(DDFilteredView& fview,

void DTGeometryBuilder::build(DTGeometry& geom,
const DDDetector* det,
const MuonNumbering& num,
const MuonGeometryConstants& num,
const dd4hep::SpecParRefs& refs) {
Volume top = det->worldVolume();
DDFilteredView fview(det, top);
fview.mergedSpecifics(refs);
dtnum_ = make_unique<DTNumberingScheme>(num.values());
buildGeometry(fview, geom, num);
}
37 changes: 28 additions & 9 deletions Geometry/DTGeometryBuilder/plugins/dd4hep/DTGeometryBuilder.h
@@ -1,9 +1,29 @@
#ifndef GEOMETRY_RECO_GEOMETRY_DT_GEOMETRY_BUILDER_H
#define GEOMETRY_RECO_GEOMETRY_DT_GEOMETRY_BUILDER_H

// -*- C++ -*-
//
// Package: DetectorDescription/DTGeometryBuilder
// Class: DTGeometryBuilder
//
/**\class DTGeometryBuilder

Description: DT Geometry builder from DD4hep

Implementation:
DT Geometry Builder iterates over a Detector Tree and
retrvieves DT chambers, super layers, layers and wires.
*/
//
// Original Author: Ianna Osborne
// Created: Wed, 16 Jan 2019 10:19:37 GMT
// Modified by Sergio Lo Meo (sergio.lo.meo@cern.ch) Tue, 04 August 2020
//
//

#include "DataFormats/GeometrySurface/interface/ReferenceCounted.h"
#include "DataFormats/GeometrySurface/interface/Plane.h"
#include "Geometry/MuonNumbering/interface/DD4hep_DTNumberingScheme.h"
#include "Geometry/MuonNumbering/interface/DTNumberingScheme.h"

#include <DD4hep/SpecParRegistry.h>

Expand All @@ -15,36 +35,35 @@ class DTGeometry;
class DTChamber;
class DTSuperLayer;
class DTLayer;
class MuonGeometryConstants;
class MuonGeometryNumbering;

namespace cms {

class DDDetector;
class DDFilteredView;
class MuonNumbering;

class DTGeometryBuilder {
public:
DTGeometryBuilder() {}

void build(DTGeometry&, const DDDetector*, const MuonNumbering&, const dd4hep::SpecParRefs&);
void build(DTGeometry&, const DDDetector*, const MuonGeometryConstants&, const dd4hep::SpecParRefs&);

private:
void buildGeometry(DDFilteredView&, DTGeometry&, const MuonNumbering&) const;
void buildGeometry(DDFilteredView&, DTGeometry&, const MuonGeometryConstants&) const;

/// create the chamber
DTChamber* buildChamber(DDFilteredView&, const MuonNumbering&) const;
DTChamber* buildChamber(DDFilteredView&, const MuonGeometryConstants&) const;

/// create the SL
DTSuperLayer* buildSuperLayer(DDFilteredView&, DTChamber*, const MuonNumbering&) const;
DTSuperLayer* buildSuperLayer(DDFilteredView&, DTChamber*, const MuonGeometryConstants&) const;

/// create the layer
DTLayer* buildLayer(DDFilteredView&, DTSuperLayer*, const MuonNumbering&) const;
DTLayer* buildLayer(DDFilteredView&, DTSuperLayer*, const MuonGeometryConstants&) const;

using RCPPlane = ReferenceCountingPointer<Plane>;

RCPPlane plane(const DDFilteredView&, Bounds* bounds) const;

std::unique_ptr<cms::DTNumberingScheme> dtnum_ = nullptr;
};
} // namespace cms

Expand Down
Expand Up @@ -13,6 +13,7 @@
//
// Original Author: Ianna Osborne
// Created: Wed, 16 Jan 2019 10:19:37 GMT
// Modified by Sergio Lo Meo (sergio.lo.meo@cern.ch) Tue, 04 August 2020
//
//
#include "CondFormats/GeometryObjects/interface/RecoIdealGeometry.h"
Expand All @@ -27,7 +28,6 @@
#include "DataFormats/GeometrySurface/interface/Plane.h"
#include "DataFormats/GeometrySurface/interface/Bounds.h"
#include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h"

#include "FWCore/Framework/interface/ESTransientHandle.h"
#include "FWCore/Framework/interface/ModuleFactory.h"
#include "FWCore/Framework/interface/ESProducer.h"
Expand All @@ -36,7 +36,8 @@
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/ESGetToken.h"
#include "FWCore/Utilities/interface/ReusableObjectHolder.h"
#include "Geometry/MuonNumbering/interface/DD4hep_MuonNumbering.h"
#include "Geometry/MuonNumbering/interface/MuonGeometryNumbering.h"
#include "Geometry/MuonNumbering/interface/MuonGeometryConstants.h"
#include "Geometry/Records/interface/MuonNumberingRecord.h"
#include "Geometry/Records/interface/MuonGeometryRecord.h"
#include "Geometry/Records/interface/DDSpecParRegistryRcd.h"
Expand Down Expand Up @@ -78,7 +79,7 @@ class DTGeometryESProducer : public ESProducer {
edm::ESGetToken<Alignments, GlobalPositionRcd> m_globalPositionToken;
edm::ESGetToken<Alignments, DTAlignmentRcd> m_alignmentsToken;
edm::ESGetToken<AlignmentErrorsExtended, DTAlignmentErrorExtendedRcd> m_alignmentErrorsToken;
edm::ESGetToken<MuonNumbering, MuonNumberingRecord> m_mdcToken;
edm::ESGetToken<MuonGeometryConstants, IdealGeometryRecord> m_mdcToken;
edm::ESGetToken<DDDetector, IdealGeometryRecord> m_cpvToken;
edm::ESGetToken<DDSpecParRegistry, DDSpecParRegistryRcd> m_registryToken;
const ESInputTag m_tag;
Expand Down Expand Up @@ -109,7 +110,7 @@ DTGeometryESProducer::DTGeometryESProducer(const ParameterSet& iConfig)
}

if (m_fromDDD) {
m_mdcToken = cc.consumesFrom<MuonNumbering, MuonNumberingRecord>(edm::ESInputTag{});
m_mdcToken = cc.consumesFrom<MuonGeometryConstants, IdealGeometryRecord>(edm::ESInputTag{});
m_cpvToken = cc.consumesFrom<DDDetector, IdealGeometryRecord>(m_tag);
m_registryToken = cc.consumesFrom<DDSpecParRegistry, DDSpecParRegistryRcd>(m_tag);
}
Expand Down Expand Up @@ -137,8 +138,6 @@ std::shared_ptr<DTGeometry> DTGeometryESProducer::produce(const MuonGeometryReco
// Called whenever the alignments or alignment errors change
//
if (m_applyAlignment) {
// m_applyAlignment is scheduled for removal.
// Ideal geometry obtained by using 'fake alignment' (with m_applyAlignment = true)
edm::ESHandle<Alignments> globalPosition;
record.getRecord<GlobalPositionRcd>().get(m_alignmentsLabel, globalPosition);
Copy link
Contributor

Choose a reason for hiding this comment

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

Sidetracking a bit, but I want to note that these calls need to be changed to use the ESGetToken to get the products. Getting products by labels in was disabled already some time ago in ESProducers.

Copy link
Contributor

Choose a reason for hiding this comment

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

@makortel I made an issue about this problem: #31288

edm::ESHandle<Alignments> alignments;
Expand Down
35 changes: 17 additions & 18 deletions Geometry/DTGeometryBuilder/test/python/validateDTGeometry_cfg.py
Expand Up @@ -7,13 +7,15 @@
process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(1)
)
process.DDDetectorESProducer = cms.ESSource("DDDetectorESProducer",
confGeomXMLFiles = cms.FileInPath('Geometry/CMSCommonData/data/dd4hep/cmsExtendedGeometry2021.xml'),
appendToDataLabel = cms.string('MUON')
)

process.load('Configuration.StandardSequences.DD4hep_GeometrySim_cff')
process.load("FWCore.MessageLogger.MessageLogger_cfi")
process.load("Geometry.MuonNumbering.muonNumberingInitialization_cfi")
process.load("Geometry.MuonNumbering.muonGeometryConstants_cff")


process.DTGeometryESProducer = cms.ESProducer("DTGeometryESProducer",
DDDetector = cms.ESInputTag('','MUON'),
DDDetector = cms.ESInputTag('',''),
appendToDataLabel = cms.string(''),
applyAlignment = cms.bool(False),
alignmentsLabel = cms.string(''),
Expand All @@ -22,23 +24,20 @@
fromDDD = cms.bool(True)
)

process.DDCompactViewESProducer = cms.ESProducer("DDCompactViewESProducer",
appendToDataLabel = cms.string('')
)

process.DDSpecParRegistryESProducer = cms.ESProducer("DDSpecParRegistryESProducer",
appendToDataLabel = cms.string('MUON')
appendToDataLabel = cms.string('')
)

process.MuonNumberingESProducer = cms.ESProducer("MuonNumberingESProducer",
label = cms.string('MUON'),
key = cms.string('MuonCommonNumbering')
)

#
# Note: Please, download the geometry file from a location
# specified by Fireworks/Geometry/data/download.url
#
# For example: wget http://cmsdoc.cern.ch/cms/data/CMSSW/Fireworks/Geometry/data/v4/cmsGeom10.root
#
process.muonGeometryConstants.fromDD4Hep = True


process.valid = cms.EDAnalyzer("DTGeometryValidate",
infileName = cms.untracked.string('cmsGeom2021.root'),

# infileName = cms.untracked.string('cmsRecoGeom-2021.root'),
Copy link
Contributor

Choose a reason for hiding this comment

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

see my comment https://github.com/cms-sw/cmssw/pull/31043/files/2d3b727f5f67fa52bda586c67dc5acbde80f3e77..278777a07be31745322a4ac08abba9488fac5af1#r478965333
its better to keep it configurable. So I would suggest that keep infileName and set it to

infileName = cms.untracked.string('Geometry/DTGeometryBuilder/data/cmsRecoGeom-2021.root'),

Copy link
Contributor

Choose a reason for hiding this comment

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

So I would suggest that keep infileName and set it to

infileName = cms.untracked.string('Geometry/DTGeometryBuilder/data/cmsRecoGeom-2021.root'),

Note that FileInPath can be used in python as well, so this could be

infileName = cms.untracked.FileInPath('Geometry/DTGeometryBuilder/data/cmsRecoGeom-2021.root'),

and in the C++

auto fp = iConfig.getUntrackedParameter<edm::FileInPath>("infileName");

outfileName = cms.untracked.string('validateDTGeometry.root'),
tolerance = cms.untracked.int32(7)
)
Expand Down
54 changes: 0 additions & 54 deletions Geometry/MuonNumbering/interface/DD4hep_DTNumberingScheme.h

This file was deleted.

3 changes: 2 additions & 1 deletion Geometry/MuonNumbering/interface/DTNumberingScheme.h
Expand Up @@ -6,7 +6,8 @@
* implementation of MuonNumberingScheme for muon barrel,
* converts the MuonBaseNumber to a unit id
*
* \author Arno Straessner, CERN <arno.straessner@cern.ch>
* Original \author Arno Straessner, CERN <arno.straessner@cern.ch>
* Modified by Sunanda B. in different PRs (the last one is #30971)
*
*/

Expand Down