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

Migration to DD4Hep for RPC db Loader #32102

Merged
merged 6 commits into from
Dec 9, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions CondTools/Geometry/plugins/RPCRecoIdealDBLoader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,26 @@
#include "Geometry/Records/interface/MuonNumberingRecord.h"
#include "Geometry/MuonNumbering/interface/MuonGeometryConstants.h"
#include "Geometry/RPCGeometryBuilder/src/RPCGeometryParsFromDD.h"
#include "Geometry/Records/interface/IdealGeometryRecord.h"
#include "DetectorDescription/DDCMS/interface/DDCompactView.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"

class RPCRecoIdealDBLoader : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
public:
RPCRecoIdealDBLoader(const edm::ParameterSet&) {}
RPCRecoIdealDBLoader(const edm::ParameterSet&);

void beginRun(edm::Run const& iEvent, edm::EventSetup const&) override;
void analyze(edm::Event const& iEvent, edm::EventSetup const&) override {}
void endRun(edm::Run const& iEvent, edm::EventSetup const&) override {}

private:
bool fromDD4Hep_;
};

RPCRecoIdealDBLoader::RPCRecoIdealDBLoader(const edm::ParameterSet& iC) {
fromDD4Hep_ = iC.getUntrackedParameter<bool>("fromDD4Hep", false);
}

void RPCRecoIdealDBLoader::beginRun(const edm::Run&, edm::EventSetup const& es) {
RecoIdealGeometry* rig = new RecoIdealGeometry;
edm::Service<cond::service::PoolDBOutputService> mydbservice;
Expand All @@ -32,16 +42,22 @@ void RPCRecoIdealDBLoader::beginRun(const edm::Run&, edm::EventSetup const& es)
return;
}

edm::ESTransientHandle<DDCompactView> pDD;
edm::ESHandle<MuonGeometryConstants> pMNDC;
es.get<IdealGeometryRecord>().get(pDD);
es.get<IdealGeometryRecord>().get(pMNDC);

const DDCompactView& cpv = *pDD;
RPCGeometryParsFromDD rpcpd;

rpcpd.build(&cpv, *pMNDC, *rig);

if (fromDD4Hep_) {
edm::ESTransientHandle<cms::DDCompactView> pDD;
es.get<IdealGeometryRecord>().get(pDD);
es.get<IdealGeometryRecord>().get(pMNDC);
const cms::DDCompactView& cpv = *pDD;
rpcpd.build(&cpv, *pMNDC, *rig);
} else {
edm::ESTransientHandle<DDCompactView> pDD;
es.get<IdealGeometryRecord>().get(pDD);
es.get<IdealGeometryRecord>().get(pMNDC);
const DDCompactView& cpv = *pDD;
rpcpd.build(&cpv, *pMNDC, *rig);
}
if (mydbservice->isNewTagRequest("RPCRecoGeometryRcd")) {
mydbservice->createNewIOV<RecoIdealGeometry>(
rig, mydbservice->beginOfTime(), mydbservice->endOfTime(), "RPCRecoGeometryRcd");
Expand Down
13 changes: 12 additions & 1 deletion CondTools/Geometry/test/rpcgeometrywriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
process.load('CondCore.CondDB.CondDB_cfi')
process.load('Configuration.StandardSequences.GeometryExtended_cff')
process.load('Geometry.MuonNumbering.muonNumberingInitialization_cfi')
process.load("Geometry.MuonNumbering.muonGeometryConstants_cff")
process.load('Configuration.StandardSequences.DD4hep_GeometrySim_cff')
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it is right to include this DD4hep geometry. This file needs to work with both old DD and DD4hep.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cvuosalo : I added the same line for PR #32001 (for CSC). Without it an error appears:

----- Begin Fatal Exception 12-Nov-2020 09:04:49 CET-----------------------
An exception of category 'NoProxyException' occurred while
[0] Processing global begin Run run: 1
[1] Calling method for module RPCRecoIdealDBLoader/'RPCGeometryWriter'
Exception Message:
No data of type "DDCompactView" with label "" in record "IdealGeometryRecord"
Please add an ESSource or ESProducer to your job which can deliver this data.
----- End Fatal Exception -------------------------------------------------
%MSG-i DDCompactViewImpl: 12-Nov-2020 09:04:49 CET EndJob
DDD transient representation has been destructed.
%MSG

process.load('FWCore.MessageService.MessageLogger_cfi')

process.MessageLogger = cms.Service("MessageLogger",
destinations = cms.untracked.vstring('myLog'),
myLog = cms.untracked.PSet(
threshold = cms.untracked.string('INFO'),
)
)

process.source = cms.Source("EmptyIOVSource",
lastValue = cms.uint64(1),
Expand All @@ -12,7 +22,8 @@
interval = cms.uint64(1)
)

process.RPCGeometryWriter = cms.EDAnalyzer("RPCRecoIdealDBLoader")
process.RPCGeometryWriter = cms.EDAnalyzer("RPCRecoIdealDBLoader",
fromDD4Hep = cms.untracked.bool(False))

process.CondDB.timetype = cms.untracked.string('runnumber')
process.CondDB.connect = cms.string('sqlite_file:myfile.db')
Expand Down
114 changes: 103 additions & 11 deletions Geometry/RPCGeometryBuilder/src/RPCGeometryParsFromDD.cc
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
/** Implementation of the RPC Geometry Builder from DDD
/* Implementation of the RPCGeometryParsFromDD Class
* Build the RPCGeometry from the DDD and DD4Hep description
*
* DD4hep part added to the original old file (DD version) made by M. Maggi (INFN Bari)
* Author: Sergio Lo Meo ([email protected])
* Created: Mon, 09 Nov 2020
*
* \author Port of: MuDDDRPCBuilder (ORCA)
* \author M. Maggi - INFN Bari
*/
#include "Geometry/RPCGeometryBuilder/src/RPCGeometryParsFromDD.h"
#include "DataFormats/MuonDetId/interface/RPCDetId.h"

#include <CondFormats/GeometryObjects/interface/RecoIdealGeometry.h>
#include <DetectorDescription/Core/interface/DDFilter.h>
#include <DetectorDescription/Core/interface/DDFilteredView.h>
#include <DetectorDescription/Core/interface/DDSolid.h>

#include "Geometry/MuonNumbering/interface/MuonGeometryNumbering.h"
#include "Geometry/MuonNumbering/interface/MuonBaseNumber.h"
#include "Geometry/MuonNumbering/interface/RPCNumberingScheme.h"

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

#include "CLHEP/Units/GlobalSystemOfUnits.h"

#include <iostream>
#include <algorithm>
#include <DetectorDescription/DDCMS/interface/DDFilteredView.h>
#include <DetectorDescription/DDCMS/interface/DDCompactView.h>
#include "DetectorDescription/DDCMS/interface/DDSpecParRegistry.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

RPCGeometryParsFromDD::RPCGeometryParsFromDD() {}

RPCGeometryParsFromDD::~RPCGeometryParsFromDD() {}

// DD
void RPCGeometryParsFromDD::build(const DDCompactView* cview,
const MuonGeometryConstants& muonConstants,
RecoIdealGeometry& rgeo) {
Expand All @@ -39,6 +42,20 @@ void RPCGeometryParsFromDD::build(const DDCompactView* cview,
this->buildGeometry(fview, muonConstants, rgeo);
}

// DD4Hep

void RPCGeometryParsFromDD::build(const cms::DDCompactView* cview,
const MuonGeometryConstants& muonConstants,
RecoIdealGeometry& rgeo) {
const std::string attribute = "ReadOutName";
const std::string value = "MuonRPCHits";
const cms::DDFilter filter(attribute, value);
cms::DDFilteredView fview(*cview, filter);
this->buildGeometry(fview, muonConstants, rgeo);
}

// DD

void RPCGeometryParsFromDD::buildGeometry(DDFilteredView& fview,
const MuonGeometryConstants& muonConstants,
RecoIdealGeometry& rgeo) {
Expand All @@ -50,6 +67,7 @@ void RPCGeometryParsFromDD::buildGeometry(DDFilteredView& fview,
// Get the The Rpc det Id
RPCNumberingScheme rpcnum(muonConstants);
const int detid = rpcnum.baseNumberToUnitNumber(mbn);

RPCDetId rpcid(detid);

DDValue numbOfStrips("nStrips");
Expand All @@ -67,6 +85,11 @@ void RPCGeometryParsFromDD::buildGeometry(DDFilteredView& fview,
const std::vector<double> dpar = fview.logicalPart().solid().parameters();

const std::string name = fview.logicalPart().name().name();

edm::LogVerbatim("RPCGeometryParsFromDD")
<< " (1) "
<< "detid: " << detid << " name: " << name << " number of Strips: " << nStrips;

const std::vector<std::string> strpars = {name};
const DDTranslation& tran = fview.translation();

Expand All @@ -78,15 +101,84 @@ void RPCGeometryParsFromDD::buildGeometry(DDFilteredView& fview,
const double width = dpar[0];
const double length = dpar[1];
const double thickness = dpar[2];
edm::LogVerbatim("RPCGeometryParsFromDD")
<< " (2) dpar.size() == 3, width: " << width << " length: " << length << " thickness: " << thickness;
pars = {width, length, thickness, numbOfStrips.doubles()[0]};
} else {
pars = {
dpar[4] /*b/2*/, dpar[8] /*B/2*/, dpar[0] /*h/2*/, 0.4, numbOfStrips.doubles()[0] /*h/2*/
};
const double dpar4 = dpar[4];
const double dpar8 = dpar[8];
const double dpar0 = dpar[0];
pars = {dpar4, dpar8, dpar0, 0.4, numbOfStrips.doubles()[0]};
edm::LogVerbatim("RPCGeometryParsFromDD")
<< " (3), else, dpar[4]: " << dpar4 << " dpar[8]: " << dpar8 << " dpar[0]: " << dpar0;
}

const std::vector<double> vtra = {tran.x(), tran.y(), tran.z()};

edm::LogVerbatim("RPCGeometryParsFromDD")
<< " (4), tran.x() " << tran.x() << " tran.y(): " << tran.y() << " tran.z(): " << tran.z();

const std::vector<double> vrot = {x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z()};
edm::LogVerbatim("RPCGeometryParsFromDD")
<< " (5), x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z() " << x.X() << ", " << x.Y() << ", "
<< x.Z() << ", " << y.X() << ", " << y.Y() << ", " << y.Z() << ", " << z.X() << ", " << z.Y() << ", " << z.Z();
rgeo.insert(rpcid.rawId(), vtra, vrot, pars, strpars);
}
}

// DD4Hep

void RPCGeometryParsFromDD::buildGeometry(cms::DDFilteredView& fview,
const MuonGeometryConstants& muonConstants,
RecoIdealGeometry& rgeo) {
while (fview.firstChild()) {
MuonGeometryNumbering mdddnum(muonConstants);
RPCNumberingScheme rpcnum(muonConstants);
int rawidCh = rpcnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fview.history()));
RPCDetId rpcid = RPCDetId(rawidCh);

auto nStrips = fview.get<double>("nStrips");

std::vector<double> dpar = fview.parameters();

std::string_view name = fview.name();

edm::LogVerbatim("RPCGeometryParsFromDD")
<< " (1), detid: " << rawidCh << " name: " << std::string(name) << " number of Strips: " << nStrips;

const std::vector<std::string> strpars = {std::string(name)};

std::vector<double> tran(3);
tran[0] = static_cast<double>(fview.translation().X()) / dd4hep::mm;
tran[1] = static_cast<double>(fview.translation().Y()) / dd4hep::mm;
tran[2] = static_cast<double>(fview.translation().Z()) / dd4hep::mm;

DDRotationMatrix rota;
fview.rot(rota);
DD3Vector x, y, z;
rota.GetComponents(x, y, z);
const std::vector<double> rot = {x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z()};

if (dd4hep::isA<dd4hep::Box>(fview.solid())) {
const std::vector<double> pars = {
dpar[0] / dd4hep::mm, dpar[1] / dd4hep::mm, dpar[2] / dd4hep::mm, double(nStrips)};
edm::LogVerbatim("RPCGeometryParsFromDD")
<< " (2), dd4hep::Box, width: " << dpar[0] / dd4hep::mm << " length: " << dpar[1] / dd4hep::mm
<< " thickness: " << dpar[2] / dd4hep::mm;
rgeo.insert(rpcid, tran, rot, pars, strpars);
} else {
const double ti = 0.4;
const std::vector<double> pars = {
dpar[0] / dd4hep::mm, dpar[1] / dd4hep::mm, dpar[3] / dd4hep::mm, ti, double(nStrips)};
edm::LogVerbatim("RPCGeometryParsFromDD") << " (3), else, dpar[0] (i.e. dpar[4] for DD): " << dpar[0] / dd4hep::mm
<< " dpar[1] (i.e. dpar[8] for DD): " << dpar[1] / dd4hep::mm
<< " dpar[3] (i.e. dpar[0] for DD): " << dpar[3] / dd4hep::mm;
rgeo.insert(rpcid, tran, rot, pars, strpars);
}
edm::LogVerbatim("RPCGeometryParsFromDD")
<< " (4), tran.x(): " << tran[0] << " tran.y(): " << tran[1] << " tran.z(): " << tran[2];
edm::LogVerbatim("RPCGeometryParsFromDD")
<< " (5), x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z(): " << x.X() << ", " << x.Y() << ", "
<< x.Z() << ", " << y.X() << ", " << y.Y() << ", " << y.Z() << ", " << z.X() << ", " << z.Y() << ", " << z.Z();
}
}
21 changes: 16 additions & 5 deletions Geometry/RPCGeometryBuilder/src/RPCGeometryParsFromDD.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#ifndef RPCGeometry_RPCGeometryParsFromDD_H
#define RPCGeometry_RPCGeometryParsFromDD_H

/** \class RPCGeometryParsFromDD
* Build the RPCGeometry ftom the DDD description
*
* \author Port of: MuDDDRPCBuilder, MuonRPCGeometryBuilder (ORCA)
* \author M. Maggi - INFN Bari
/* \class RPCGeometryParsFromDD
* Build the RPCGeometry from the DDD and DD4Hep description
*
* DD4hep part added to the original old file (DD version) made by M. Maggi (INFN Bari)
* Author: Sergio Lo Meo ([email protected])
* Created: Mon, 09 Nov 2020
*
*/

Expand All @@ -15,6 +16,10 @@

class DDCompactView;
class DDFilteredView;
namespace cms { // DD4Hep
class DDFilteredView;
class DDCompactView;
} // namespace cms
class RPCDetId;
class RPCRoll;
class MuonGeometryConstants;
Expand All @@ -25,10 +30,16 @@ class RPCGeometryParsFromDD {

~RPCGeometryParsFromDD();

// DD
void build(const DDCompactView* cview, const MuonGeometryConstants& muonConstants, RecoIdealGeometry& rgeo);
// DD4Hep
void build(const cms::DDCompactView* cview, const MuonGeometryConstants& muonConstants, RecoIdealGeometry& rgeo);

private:
// DD
void buildGeometry(DDFilteredView& fview, const MuonGeometryConstants& muonConstants, RecoIdealGeometry& rgeo);
// DD4Hep
void buildGeometry(cms::DDFilteredView& fview, const MuonGeometryConstants& muonConstants, RecoIdealGeometry& rgeo);
};

#endif