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 all 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
9 changes: 5 additions & 4 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")),
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to use FileInPath to get the file e.g. for python module you need to do something like

file = cms.FileInPath('CondFormats/HcalObjects/data/hcal_pedestals_fC_v6_mc.txt')

and from cc code you can do something like

edm::FileInPath fp("DetectorDescription/Core/test/lpnames.out");

OR
std::ifstream inputFile(config.getParameter<edm::FileInPath>("maskFile").fullPath());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@smuzaffar : I modified the constructor of the DTGeometryValidate.cc in this way:

..
edm::FileInPath fp("Geometry/DTGeometryBuilder/data/cmsRecoGeom-2021.root"); fwGeometry_.loadMap(fp.fullPath().c_str());

instead of
...
iConfig.getUntrackedParameter("infileName", "Geometry/DTGeometryBuilder/data/cmsRecoGeom-2021.root"))
....
fwGeometry_.loadMap(infileName_.c_str());

The compilation is ok, but when I run: "cmsRun Geometry/DTGeometryBuilder/test/pyton/validateDTGeometry_cfg.py" I see:

----- Begin Fatal Exception 27-Aug-2020 15:33:18 CEST-----------------------
An exception of category 'FileInPathError' occurred while
[0] Constructing the EventProcessor
[1] Constructing module: class=DTGeometryValidate label='valid'
Exception Message:
edm::FileInPath unable to find file Geometry/DTGeometryBuilder/data/cmsRecoGeom-2021.root anywhere in the search path.
The search path is defined by: CMSSW_SEARCH_PATH
${CMSSW_SEARCH_PATH} is: /build/slomeo/CMSSW_11_2_X_2020-08-23-2300/poison:/build/slomeo/CMSSW_11_2_X_2020-08-23-2300/src:/build/slomeo/CMSSW_11_2_X_2020-08-23-2300/external/slc7_amd64_gcc820/data:/cvmfs/cms-ib.cern.ch/week1/slc7_amd64_gcc820/cms/cmssw-patch/CMSSW_11_2_X_2020-08-23-2300/poison:/cvmfs/cms-ib.cern.ch/week1/slc7_amd64_gcc820/cms/cmssw-patch/CMSSW_11_2_X_2020-08-23-2300/src:/cvmfs/cms-ib.cern.ch/week1/slc7_amd64_gcc820/cms/cmssw-patch/CMSSW_11_2_X_2020-08-23-2300/external/slc7_amd64_gcc820/data
Current directory is: /build/slomeo/CMSSW_11_2_X_2020-08-23-2300/src
----- End Fatal Exception -------------------------------------------------

Where is my mistake?

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(infileName_.c_str());
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is infileName_ not just a edm::FileInPath?

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

void DTGeometryValidate::analyze(const edm::Event& event, const edm::EventSetup& eventSetup) {
Expand All @@ -95,7 +97,6 @@ void DTGeometryValidate::analyze(const edm::Event& event, const edm::EventSetup&
if (dtGeometry_.isValid()) {
LogVerbatim("DTGeometry") << "Validating DT chamber geometry";
validateDTChamberGeometry();

LogVerbatim("DTGeometry") << "Validating DT layer geometry";
validateDTLayerGeometry();
} else
Expand Down
60 changes: 27 additions & 33 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) Mon, 31 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,35 +49,32 @@ 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) {
DTChamber* chamber = buildChamber(fview, num);

// Loop on SLs
bool doSL = fview.nextSibling();
while (doSL) {
DTSuperLayer* sl = buildSuperLayer(fview, chamber, num);

// Loop on Layers
fview.down();
bool doLayers = fview.sibling();
while (doLayers) {
DTLayer* l = buildLayer(fview, sl, num);
geom.add(l);

doLayers = fview.sibling(); // go to next Layer
doLayers = fview.sibling();
}
// Done with layers

geom.add(sl);
doSL = fview.nextSibling(); // go to next SL
doSL = fview.nextSibling();
}
geom.add(chamber);

fview.parent(); // stop iterating current branch
doChamber = fview.firstChild(); // go to next chamber
fview.parent();
doChamber = fview.firstChild();
}
}

Expand All @@ -90,13 +88,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,43 +105,40 @@ 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);

// add to the chamber
chamber->add(slayer);

return slayer;
}

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 +161,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);
}
40 changes: 28 additions & 12 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) Mon, 31 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,32 @@ 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
21 changes: 8 additions & 13 deletions Geometry/DTGeometryBuilder/plugins/dd4hep/DTGeometryESProducer.cc
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) Mon, 31 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 All @@ -133,19 +134,15 @@ std::shared_ptr<DTGeometry> DTGeometryESProducer::produce(const MuonGeometryReco
host->ifRecordChanges<DTRecoGeometryRcd>(record, [this, &host](auto const& rec) { setupDBGeometry(rec, host); });
}
}
//
// 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;
record.getRecord<DTAlignmentRcd>().get(m_alignmentsLabel, alignments);
edm::ESHandle<AlignmentErrorsExtended> alignmentErrors;
record.getRecord<DTAlignmentErrorExtendedRcd>().get(m_alignmentsLabel, alignmentErrors);
// Only apply alignment if values exist

if (alignments->empty() && alignmentErrors->empty() && globalPosition->empty()) {
edm::LogInfo("Config") << "@SUB=DTGeometryRecord::produce"
<< "Alignment(Error)s and global position (label '" << m_alignmentsLabel
Expand All @@ -160,7 +157,7 @@ std::shared_ptr<DTGeometry> DTGeometryESProducer::produce(const MuonGeometryReco
}
}

return host; // automatically converts to std::shared_ptr<DTGeometry>
return host;
}

void DTGeometryESProducer::setupGeometry(const MuonNumberingRecord& record, shared_ptr<HostType>& host) {
Expand All @@ -184,10 +181,8 @@ void DTGeometryESProducer::setupGeometry(const MuonNumberingRecord& record, shar

void DTGeometryESProducer::setupDBGeometry(const DTRecoGeometryRcd& record, std::shared_ptr<HostType>& host) {
// host->clear();

// edm::ESHandle<RecoIdealGeometry> rig;
// record.get(rig);

// DTGeometryBuilderFromCondDB builder;
// builder.build(host, *rig);
}
Expand Down
26 changes: 14 additions & 12 deletions Geometry/DTGeometryBuilder/test/python/testDTGeometry.py
Expand Up @@ -7,6 +7,11 @@
input = cms.untracked.int32(1)
)

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.MessageLogger = cms.Service(
"MessageLogger",
statistics = cms.untracked.vstring('cout', 'dtGeometry'),
Expand Down Expand Up @@ -41,13 +46,8 @@
'dtGeometry')
)

process.DDDetectorESProducer = cms.ESSource("DDDetectorESProducer",
confGeomXMLFiles = cms.FileInPath('Geometry/CMSCommonData/data/dd4hep/cmsExtendedGeometry2021.xml'),
appendToDataLabel = cms.string('MUON')
)

process.DTGeometryESProducer = cms.ESProducer("DTGeometryESProducer",
DDDetector = cms.ESInputTag('','MUON'),
DDDetector = cms.ESInputTag('',''),
appendToDataLabel = cms.string(''),
applyAlignment = cms.bool(False),
alignmentsLabel = cms.string(''),
Expand All @@ -56,17 +56,19 @@
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')
)
process.muonGeometryConstants.fromDD4Hep = True


process.test = cms.EDAnalyzer("DTGeometryTest",
DDDetector = cms.ESInputTag('','MUON')
DDDetector = cms.ESInputTag('','')
)

process.p = cms.Path(process.test)