diff --git a/CondFormats/GeometryObjects/interface/MuonOffsetMap.h b/CondFormats/GeometryObjects/interface/MuonOffsetMap.h new file mode 100644 index 0000000000000..afdf129671e60 --- /dev/null +++ b/CondFormats/GeometryObjects/interface/MuonOffsetMap.h @@ -0,0 +1,19 @@ +#ifndef CondFormats_GeometryObjects_MuonOffsetMap_h +#define CondFormats_GeometryObjects_MuonOffsetMap_h + +#include "CondFormats/Serialization/interface/Serializable.h" +#include +#include +#include + +class MuonOffsetMap { +public: + MuonOffsetMap() = default; + ~MuonOffsetMap() = default; + + std::unordered_map > muonMap_; + + COND_SERIALIZABLE; +}; + +#endif diff --git a/CondFormats/GeometryObjects/src/T_EventSetup_MuonOffsetMap.cc b/CondFormats/GeometryObjects/src/T_EventSetup_MuonOffsetMap.cc new file mode 100644 index 0000000000000..730bce50a9491 --- /dev/null +++ b/CondFormats/GeometryObjects/src/T_EventSetup_MuonOffsetMap.cc @@ -0,0 +1,4 @@ +#include "CondFormats/GeometryObjects/interface/MuonOffsetMap.h" +#include "FWCore/Utilities/interface/typelookup.h" + +TYPELOOKUP_DATA_REG(MuonOffsetMap); diff --git a/CondFormats/GeometryObjects/src/classes.h b/CondFormats/GeometryObjects/src/classes.h index d37fcb036731b..9bd040c3155ae 100644 --- a/CondFormats/GeometryObjects/src/classes.h +++ b/CondFormats/GeometryObjects/src/classes.h @@ -13,3 +13,4 @@ #include "CondFormats/GeometryObjects/interface/EcalSimulationParameters.h" #include "CondFormats/GeometryObjects/interface/PHGCalParameters.h" #include "CondFormats/GeometryObjects/interface/PDetGeomDesc.h" +#include "CondFormats/GeometryObjects/interface/MuonOffsetMap.h" diff --git a/CondFormats/GeometryObjects/src/classes_def.xml b/CondFormats/GeometryObjects/src/classes_def.xml index 75f459f3d7171..8bab12b0370cc 100644 --- a/CondFormats/GeometryObjects/src/classes_def.xml +++ b/CondFormats/GeometryObjects/src/classes_def.xml @@ -206,6 +206,9 @@ + + + diff --git a/Configuration/Geometry/python/GeometryDD4hepExtended2021ZeroMaterial_cff.py b/Configuration/Geometry/python/GeometryDD4hepExtended2021ZeroMaterial_cff.py index 7020aa5a73487..e27bfc1f26428 100644 --- a/Configuration/Geometry/python/GeometryDD4hepExtended2021ZeroMaterial_cff.py +++ b/Configuration/Geometry/python/GeometryDD4hepExtended2021ZeroMaterial_cff.py @@ -24,3 +24,4 @@ from Geometry.EcalCommonData.ecalSimulationParameters_cff import * from Geometry.HcalCommonData.hcalDDDSimConstants_cff import * from Geometry.MuonNumbering.muonGeometryConstants_cff import * +from Geometry.MuonNumbering.muonOffsetESProducer_cff import * diff --git a/Configuration/Geometry/python/GeometryDD4hepExtended2021_cff.py b/Configuration/Geometry/python/GeometryDD4hepExtended2021_cff.py index 583f4d575d448..c7d4e0bcf36ea 100644 --- a/Configuration/Geometry/python/GeometryDD4hepExtended2021_cff.py +++ b/Configuration/Geometry/python/GeometryDD4hepExtended2021_cff.py @@ -24,3 +24,4 @@ from Geometry.EcalCommonData.ecalSimulationParameters_cff import * from Geometry.HcalCommonData.hcalDDDSimConstants_cff import * from Geometry.MuonNumbering.muonGeometryConstants_cff import * +from Geometry.MuonNumbering.muonOffsetESProducer_cff import * diff --git a/Configuration/Geometry/python/GeometryExtended2021ZeroMaterial_cff.py b/Configuration/Geometry/python/GeometryExtended2021ZeroMaterial_cff.py index 4e948f3ef5d3a..b7e70cbd28708 100644 --- a/Configuration/Geometry/python/GeometryExtended2021ZeroMaterial_cff.py +++ b/Configuration/Geometry/python/GeometryExtended2021ZeroMaterial_cff.py @@ -8,4 +8,5 @@ from Geometry.EcalCommonData.ecalSimulationParameters_cff import * from Geometry.HcalCommonData.hcalDDDSimConstants_cff import * from Geometry.MuonNumbering.muonGeometryConstants_cff import * +from Geometry.MuonNumbering.muonOffsetESProducer_cff import * diff --git a/Configuration/Geometry/python/GeometryExtended2021_cff.py b/Configuration/Geometry/python/GeometryExtended2021_cff.py index 2a636b9dd1822..62135deb81d73 100644 --- a/Configuration/Geometry/python/GeometryExtended2021_cff.py +++ b/Configuration/Geometry/python/GeometryExtended2021_cff.py @@ -8,4 +8,5 @@ from Geometry.EcalCommonData.ecalSimulationParameters_cff import * from Geometry.HcalCommonData.hcalDDDSimConstants_cff import * from Geometry.MuonNumbering.muonGeometryConstants_cff import * +from Geometry.MuonNumbering.muonOffsetESProducer_cff import * diff --git a/Configuration/Geometry/python/dict2021Geometry.py b/Configuration/Geometry/python/dict2021Geometry.py index f08e8b479cc33..d443b79f45451 100644 --- a/Configuration/Geometry/python/dict2021Geometry.py +++ b/Configuration/Geometry/python/dict2021Geometry.py @@ -1020,7 +1020,7 @@ 'Geometry/MuonCommonData/data/mb3/2021/v1/mb3.xml', 'Geometry/MuonCommonData/data/mb4/2015/v2/mb4.xml', 'Geometry/MuonCommonData/data/mb4Shield/2021/v1/mb4Shield.xml', - 'Geometry/MuonCommonData/data/muonYoke/2021/v4/muonYoke.xml', + 'Geometry/MuonCommonData/data/muonYoke/2021/v5/muonYoke.xml', 'Geometry/MuonCommonData/data/mf/2021/v2/mf.xml', 'Geometry/MuonCommonData/data/rpcf/2015/v1/rpcf.xml', 'Geometry/MuonCommonData/data/gemf/TDR_BaseLine/gemf.xml', @@ -1029,7 +1029,7 @@ 'Geometry/MuonCommonData/data/mfshield/2017/v2/mfshield.xml', ], 2 : [ - 'Geometry/MuonCommonData/data/muonNumbering/2021/v2/muonNumbering.xml', + 'Geometry/MuonCommonData/data/muonNumbering/2021/v3/muonNumbering.xml', ], 3 : [ 'Geometry/MuonSimData/data/v2/muonSens.xml', @@ -1045,6 +1045,7 @@ ], "sim" : [ 'from Geometry.MuonNumbering.muonGeometryConstants_cff import *', + 'from Geometry.MuonNumbering.muonOffsetESProducer_cff import *', ], "reco" : [ 'from Geometry.MuonNumbering.muonNumberingInitialization_cfi import *', diff --git a/Geometry/CMSCommonData/data/dd4hep/cmsExtendedGeometry2021.xml b/Geometry/CMSCommonData/data/dd4hep/cmsExtendedGeometry2021.xml index 521f45c29cc66..d700cc305ede2 100644 --- a/Geometry/CMSCommonData/data/dd4hep/cmsExtendedGeometry2021.xml +++ b/Geometry/CMSCommonData/data/dd4hep/cmsExtendedGeometry2021.xml @@ -241,14 +241,14 @@ - + - + diff --git a/Geometry/CMSCommonData/data/dd4hep/cmsExtendedGeometry2021ZeroMaterial.xml b/Geometry/CMSCommonData/data/dd4hep/cmsExtendedGeometry2021ZeroMaterial.xml index 5f0ae14c20cc9..f1aa1e6fdd18d 100644 --- a/Geometry/CMSCommonData/data/dd4hep/cmsExtendedGeometry2021ZeroMaterial.xml +++ b/Geometry/CMSCommonData/data/dd4hep/cmsExtendedGeometry2021ZeroMaterial.xml @@ -240,14 +240,14 @@ - + - + diff --git a/Geometry/CMSCommonData/python/cmsExtendedGeometry2021XML_cfi.py b/Geometry/CMSCommonData/python/cmsExtendedGeometry2021XML_cfi.py index 0816898e77c9d..acb7ea1862fed 100644 --- a/Geometry/CMSCommonData/python/cmsExtendedGeometry2021XML_cfi.py +++ b/Geometry/CMSCommonData/python/cmsExtendedGeometry2021XML_cfi.py @@ -242,7 +242,7 @@ 'Geometry/MuonCommonData/data/mb3/2021/v1/mb3.xml', 'Geometry/MuonCommonData/data/mb4/2015/v2/mb4.xml', 'Geometry/MuonCommonData/data/mb4Shield/2021/v1/mb4Shield.xml', - 'Geometry/MuonCommonData/data/muonYoke/2021/v4/muonYoke.xml', + 'Geometry/MuonCommonData/data/muonYoke/2021/v5/muonYoke.xml', 'Geometry/MuonCommonData/data/mf/2021/v2/mf.xml', 'Geometry/MuonCommonData/data/rpcf/2015/v1/rpcf.xml', 'Geometry/MuonCommonData/data/gemf/TDR_BaseLine/gemf.xml', @@ -251,7 +251,7 @@ 'Geometry/MuonCommonData/data/mfshield/2017/v2/mfshield.xml', )+ cms.vstring( - 'Geometry/MuonCommonData/data/muonNumbering/2021/v2/muonNumbering.xml', + 'Geometry/MuonCommonData/data/muonNumbering/2021/v3/muonNumbering.xml', 'Geometry/ForwardCommonData/data/forward/2021/v1/forward.xml', 'Geometry/ForwardCommonData/data/totemt2/2021/v1/totemt2.xml', 'Geometry/ForwardCommonData/data/forwardshield/2021/v1/forwardshield.xml', diff --git a/Geometry/CMSCommonData/python/cmsExtendedGeometry2021ZeroMaterialXML_cfi.py b/Geometry/CMSCommonData/python/cmsExtendedGeometry2021ZeroMaterialXML_cfi.py index 1cd57edac0174..e3db637739d60 100644 --- a/Geometry/CMSCommonData/python/cmsExtendedGeometry2021ZeroMaterialXML_cfi.py +++ b/Geometry/CMSCommonData/python/cmsExtendedGeometry2021ZeroMaterialXML_cfi.py @@ -241,7 +241,7 @@ 'Geometry/MuonCommonData/data/mb3/2021/v1/mb3.xml', 'Geometry/MuonCommonData/data/mb4/2015/v2/mb4.xml', 'Geometry/MuonCommonData/data/mb4Shield/2021/v1/mb4Shield.xml', - 'Geometry/MuonCommonData/data/muonYoke/2021/v4/muonYoke.xml', + 'Geometry/MuonCommonData/data/muonYoke/2021/v5/muonYoke.xml', 'Geometry/MuonCommonData/data/mf/2021/v2/mf.xml', 'Geometry/MuonCommonData/data/rpcf/2015/v1/rpcf.xml', 'Geometry/MuonCommonData/data/gemf/TDR_BaseLine/gemf.xml', @@ -250,7 +250,7 @@ 'Geometry/MuonCommonData/data/mfshield/2017/v2/mfshield.xml', )+ cms.vstring( - 'Geometry/MuonCommonData/data/muonNumbering/2021/v2/muonNumbering.xml', + 'Geometry/MuonCommonData/data/muonNumbering/2021/v3/muonNumbering.xml', 'Geometry/ForwardCommonData/data/forward/2021/v1/forward.xml', 'Geometry/ForwardCommonData/data/totemt2/2021/v1/totemt2.xml', 'Geometry/ForwardCommonData/data/forwardshield/2021/v1/forwardshield.xml', diff --git a/Geometry/MuonCommonData/data/muonNumbering/2021/v3/muonNumbering.xml b/Geometry/MuonCommonData/data/muonNumbering/2021/v3/muonNumbering.xml new file mode 100644 index 0000000000000..4d06228a43446 --- /dev/null +++ b/Geometry/MuonCommonData/data/muonNumbering/2021/v3/muonNumbering.xml @@ -0,0 +1,483 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Geometry/MuonNumbering/BuildFile.xml b/Geometry/MuonNumbering/BuildFile.xml index e706b02f18e25..0ff3aee45724a 100644 --- a/Geometry/MuonNumbering/BuildFile.xml +++ b/Geometry/MuonNumbering/BuildFile.xml @@ -1,5 +1,7 @@ - + + + diff --git a/Geometry/MuonNumbering/interface/MuonOffsetFromDD.h b/Geometry/MuonNumbering/interface/MuonOffsetFromDD.h new file mode 100644 index 0000000000000..848300cd345fe --- /dev/null +++ b/Geometry/MuonNumbering/interface/MuonOffsetFromDD.h @@ -0,0 +1,28 @@ +#ifndef Geometry_MuonNUmbering_MuonOffsetFromDD_h +#define Geometry_MuonNUmbering_MuonOffsetFromDD_h + +#include "DetectorDescription/Core/interface/DDsvalues.h" +#include "DetectorDescription/Core/interface/DDCompactView.h" +#include "DetectorDescription/DDCMS/interface/DDCompactView.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include +#include + +class DDFilteredView; +class MuonOffsetMap; + +class MuonOffsetFromDD { +public: + MuonOffsetFromDD(std::vector names); + + bool build(const DDCompactView*, MuonOffsetMap&); + bool build(const cms::DDCompactView*, MuonOffsetMap&); + +private: + bool debugParameters(const MuonOffsetMap&); + int getNumber(const std::string&, const DDsvalues_type&); + const std::vector specpars_; + const unsigned int nset_; +}; + +#endif diff --git a/Geometry/MuonNumbering/plugins/BuildFile.xml b/Geometry/MuonNumbering/plugins/BuildFile.xml index e4aad995a3ad2..58ac7d0e83536 100644 --- a/Geometry/MuonNumbering/plugins/BuildFile.xml +++ b/Geometry/MuonNumbering/plugins/BuildFile.xml @@ -1,10 +1,11 @@ + + + + - - - diff --git a/Geometry/MuonNumbering/plugins/MuonOffsetESProducer.cc b/Geometry/MuonNumbering/plugins/MuonOffsetESProducer.cc new file mode 100644 index 0000000000000..be8795cd03f93 --- /dev/null +++ b/Geometry/MuonNumbering/plugins/MuonOffsetESProducer.cc @@ -0,0 +1,149 @@ +// -*- C++ -*- +// +// Package: DetectorDescription/MuonOffsetESProducer +// Class: MuonOffsetESProducer +// +/**\class MuonOffsetESProducer + + Description: Produce offsets and tags for Muon volume copy numbers + + Implementation: + The constants are defined in XML as SpecPars +*/ +// +// Original Author: Sunanda Banerjee +// Created: Fri, 16 Oct 2020 09:10:32 GMT +// +// + +#include "FWCore/Framework/interface/ModuleFactory.h" +#include "FWCore/Framework/interface/ESProducer.h" +#include "FWCore/Framework/interface/ESTransientHandle.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "CondFormats/GeometryObjects/interface/MuonOffsetMap.h" +#include "DetectorDescription/Core/interface/DDCompactView.h" +#include "DetectorDescription/DDCMS/interface/DDCompactView.h" +#include "Geometry/Records/interface/IdealGeometryRecord.h" +#include "Geometry/MuonNumbering/interface/MuonOffsetFromDD.h" + +#include +#include +#include + +//#define EDM_ML_DEBUG + +class MuonOffsetESProducer : public edm::ESProducer { +public: + MuonOffsetESProducer(const edm::ParameterSet&); + + using ReturnType = std::unique_ptr; + + static void fillDescriptions(edm::ConfigurationDescriptions&); + ReturnType produce(const IdealGeometryRecord&); + +private: + const bool fromDD4Hep_; + const std::vector names_; + edm::ESGetToken cpvTokenDDD_; + edm::ESGetToken cpvTokenDD4Hep_; +}; + +MuonOffsetESProducer::MuonOffsetESProducer(const edm::ParameterSet& iConfig) + : fromDD4Hep_(iConfig.getParameter("fromDD4Hep")), + names_(iConfig.getParameter>("names")) { + auto cc = setWhatProduced(this); + if (fromDD4Hep_) { + cpvTokenDD4Hep_ = cc.consumesFrom(edm::ESInputTag()); + } else { + cpvTokenDDD_ = cc.consumesFrom(edm::ESInputTag()); + } +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("MuonGeom") << "MuonOffsetESProducer::MuonOffsetESProducer called with dd4hep: " << fromDD4Hep_; +#endif +} + +void MuonOffsetESProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + std::vector names = {"MuonCommonNumbering", + "MuonBarrel", + "MuonEndcap", + "MuonBarrelWheels", + "MuonBarrelStation1", + "MuonBarrelStation2", + "MuonBarrelStation3", + "MuonBarrelStation4", + "MuonBarrelSuperLayer", + "MuonBarrelLayer", + "MuonBarrelWire", + "MuonRpcPlane1I", + "MuonRpcPlane1O", + "MuonRpcPlane2I", + "MuonRpcPlane2O", + "MuonRpcPlane3S", + "MuonRpcPlane4", + "MuonRpcChamberLeft", + "MuonRpcChamberMiddle", + "MuonRpcChamberRight", + "MuonRpcEndcap1", + "MuonRpcEndcap2", + "MuonRpcEndcap3", + "MuonRpcEndcap4", + "MuonRpcEndcapSector", + "MuonRpcEndcapChamberB1", + "MuonRpcEndcapChamberB2", + "MuonRpcEndcapChamberB3", + "MuonRpcEndcapChamberC1", + "MuonRpcEndcapChamberC2", + "MuonRpcEndcapChamberC3", + "MuonRpcEndcapChamberE1", + "MuonRpcEndcapChamberE2", + "MuonRpcEndcapChamberE3", + "MuonRpcEndcapChamberF1", + "MuonRpcEndcapChamberF2", + "MuonRpcEndcapChamberF3", + "MuonEndcapStation1", + "MuonEndcapStation2", + "MuonEndcapStation3", + "MuonEndcapStation4", + "MuonEndcapSubrings", + "MuonEndcapSectors", + "MuonEndcapLayers", + "MuonEndcapRing1", + "MuonEndcapRing2", + "MuonEndcapRing3", + "MuonEndcapRingA", + "MuonGEMEndcap", + "MuonGEMSector", + "MuonGEMChamber"}; + desc.add("fromDD4Hep", false); + desc.add>("names", names); + descriptions.add("muonOffsetESProducer", desc); +} + +MuonOffsetESProducer::ReturnType MuonOffsetESProducer::produce(const IdealGeometryRecord& iRecord) { +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("MuonGeom") << "MuonOffsetESProducer::produce(const IdealGeometryRecord& iRecord)"; +#endif + + auto ptp = std::make_unique(); + MuonOffsetFromDD builder(names_); + + if (fromDD4Hep_) { +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("MuonGeom") << "MuonOffsetESProducer::Try to access cms::DDCompactView"; +#endif + edm::ESTransientHandle cpv = iRecord.getTransientHandle(cpvTokenDD4Hep_); + builder.build(&(*cpv), *ptp); + } else { +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("MuonGeom") << "MuonOffsetESProducer::Try to access DDCompactView"; +#endif + edm::ESTransientHandle cpv = iRecord.getTransientHandle(cpvTokenDDD_); + builder.build(&(*cpv), *ptp); + } + return ptp; +} + +DEFINE_FWK_EVENTSETUP_MODULE(MuonOffsetESProducer); diff --git a/Geometry/MuonNumbering/python/muonOffsetESProducer_cff.py b/Geometry/MuonNumbering/python/muonOffsetESProducer_cff.py new file mode 100644 index 0000000000000..5f550b896d068 --- /dev/null +++ b/Geometry/MuonNumbering/python/muonOffsetESProducer_cff.py @@ -0,0 +1,9 @@ +import FWCore.ParameterSet.Config as cms + +from Geometry.MuonNumbering.muonOffsetESProducer_cfi import * + +from Configuration.ProcessModifiers.dd4hep_cff import dd4hep + +dd4hep.toModify(muonOffsetESProducer, + fromDD4Hep = cms.bool(True) +) diff --git a/Geometry/MuonNumbering/src/GEMNumberingScheme.cc b/Geometry/MuonNumbering/src/GEMNumberingScheme.cc index 172c79e6a7f87..41cb4c5d4f22e 100644 --- a/Geometry/MuonNumbering/src/GEMNumberingScheme.cc +++ b/Geometry/MuonNumbering/src/GEMNumberingScheme.cc @@ -35,7 +35,7 @@ int GEMNumberingScheme::baseNumberToUnitNumber(const MuonBaseNumber& num) const #ifdef EDM_ML_DEBUG if (levels != theRollLevel) edm::LogVerbatim("GEMNumberingScheme") << "MuonGEMNumberingScheme::BNToUN: BaseNumber has " << num.getLevels() - << " levels, need " << maxLevel << ":" << theRingLevel; + << " levels, need at least till " << theRollLevel; #endif int region(GEMDetId::minRegionId), ring(GEMDetId::minRingId); diff --git a/Geometry/MuonNumbering/src/MuonOffsetFromDD.cc b/Geometry/MuonNumbering/src/MuonOffsetFromDD.cc new file mode 100644 index 0000000000000..847f7fa643b26 --- /dev/null +++ b/Geometry/MuonNumbering/src/MuonOffsetFromDD.cc @@ -0,0 +1,95 @@ +#include "Geometry/MuonNumbering/interface/MuonOffsetFromDD.h" +#include "CondFormats/GeometryObjects/interface/MuonOffsetMap.h" +#include "DetectorDescription/Core/interface/DDFilteredView.h" +#include "DetectorDescription/Core/interface/DDFilter.h" +#include "DetectorDescription/Core/interface/DDValue.h" +#include "DetectorDescription/Core/interface/DDutils.h" +#include "DetectorDescription/DDCMS/interface/DDFilteredView.h" +#include +#include + +//#define EDM_ML_DEBUG + +MuonOffsetFromDD::MuonOffsetFromDD(std::vector name) : specpars_(name), nset_(name.size()) { +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("MuonGeom") << "MuonOffsetFromDD initialized with " << nset_ << " specpars"; +#endif +} + +bool MuonOffsetFromDD::build(const DDCompactView* cpv, MuonOffsetMap& php) { +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("MuonGeom") << "Inside MuonOffsetFromDD::build(const DDCompactView*, MuonOffsetMap&)"; +#endif + + // Loop over all the sets + std::string attribute = "OnlyForMuonNumbering"; + std::string name; + for (unsigned int k = 0; k < nset_; ++k) { + name = "muonstep" + std::to_string(k); + DDSpecificsMatchesValueFilter filter{DDValue(attribute, name, 0)}; + DDFilteredView fv(*cpv, filter); + bool dodet = fv.firstChild(); + DDsvalues_type sv(fv.mergedSpecifics()); + int offset = getNumber("CopyNoOffset", sv); + int tag = getNumber("CopyNoTag", sv); + while (dodet) { + name = fv.logicalPart().name().name(); + php.muonMap_[name] = std::make_pair(offset, tag); + dodet = fv.next(); + } + } + return this->debugParameters(php); +} + +bool MuonOffsetFromDD::build(const cms::DDCompactView* cpv, MuonOffsetMap& php) { + edm::LogVerbatim("MuonGeom") << "Inside MuonOffsetFromDD::build(const cms::DDCompactView*, MuonOffsetMap&)"; + + // Get the offsets and tags first + int offsets[nset_], tags[nset_]; + cms::DDFilteredView fv(cpv->detector(), cpv->detector()->worldVolume()); + for (unsigned int k = 0; k < nset_; ++k) { + std::vector off = fv.get>(specpars_[k], "CopyNoOffset"); + offsets[k] = (!off.empty()) ? off[0] : 0; + std::vector tag = fv.get>(specpars_[k], "CopyNoTag"); + tags[k] = (!tag.empty()) ? tag[0] : 0; + } + // Now loop over the detectors + std::string attribute = "OnlyForMuonNumbering"; + std::string name; + for (unsigned int k = 0; k < nset_; ++k) { + name = "muonstep" + std::to_string(k); + const cms::DDFilter filter(attribute, name); + cms::DDFilteredView fv((*cpv), filter); + while (fv.firstChild()) { + name = static_cast(fv.name()); + php.muonMap_[name] = std::make_pair(offsets[k], tags[k]); + } + } + return this->debugParameters(php); +} + +bool MuonOffsetFromDD::debugParameters(const MuonOffsetMap& php) { + edm::LogVerbatim("MuonGeom") << "MuonOffsetFromDD: Finds " << php.muonMap_.size() << " entries in the map"; +#ifdef EDM_ML_DEBUG + unsigned int k(0); + for (auto itr = php.muonMap_.begin(); itr != php.muonMap_.end(); ++itr, ++k) { + edm::LogVerbatim("MuonGeom") << "[" << k << "] " << itr->first << ": (" << (itr->second).first << ", " + << (itr->second).second << ")"; + } +#endif + return true; +} + +int MuonOffsetFromDD::getNumber(const std::string& str, const DDsvalues_type& sv) { +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("MuonGeom") << "MuonOffsetFromDD::getNumbers called for " << str; +#endif + DDValue value(str); + if (DDfetch(&sv, value)) { + const std::vector& fvec = value.doubles(); + int nval = (!fvec.empty()) ? static_cast(fvec[0]) : 0; + return nval; + } else { + return 0; + } +} diff --git a/Geometry/MuonNumbering/test/BuildFile.xml b/Geometry/MuonNumbering/test/BuildFile.xml index 34fde165a4b72..d96a30d4a8cdf 100644 --- a/Geometry/MuonNumbering/test/BuildFile.xml +++ b/Geometry/MuonNumbering/test/BuildFile.xml @@ -1,7 +1,9 @@ + + + - diff --git a/Geometry/MuonNumbering/test/MuonOffsetAnalyzer.cc b/Geometry/MuonNumbering/test/MuonOffsetAnalyzer.cc new file mode 100644 index 0000000000000..0a0b74f6a4019 --- /dev/null +++ b/Geometry/MuonNumbering/test/MuonOffsetAnalyzer.cc @@ -0,0 +1,38 @@ +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "CondFormats/GeometryObjects/interface/MuonOffsetMap.h" +#include "Geometry/Records/interface/IdealGeometryRecord.h" +#include + +class MuonOffsetAnalyzer : public edm::one::EDAnalyzer<> { +public: + explicit MuonOffsetAnalyzer(const edm::ParameterSet&); + + void analyze(edm::Event const& iEvent, edm::EventSetup const&) override; + +private: + edm::ESGetToken parToken_; +}; + +MuonOffsetAnalyzer::MuonOffsetAnalyzer(const edm::ParameterSet&) { + parToken_ = esConsumes(edm::ESInputTag{}); +} + +void MuonOffsetAnalyzer::analyze(const edm::Event& /*iEvent*/, const edm::EventSetup& iSetup) { + const auto& par = iSetup.getData(parToken_); + const MuonOffsetMap* php = ∥ + + edm::LogVerbatim("MuonGeom") << "MuonOffsetFromDD: Finds " << php->muonMap_.size() << " entries in the map"; + + unsigned int k(0); + for (auto itr = php->muonMap_.begin(); itr != php->muonMap_.end(); ++itr, ++k) { + edm::LogVerbatim("MuonGeom") << "[" << k << "] " << itr->first << ": (" << (itr->second).first << ", " + << (itr->second).second << ")"; + } +} + +DEFINE_FWK_MODULE(MuonOffsetAnalyzer); diff --git a/Geometry/MuonNumbering/test/testMuonOffsetDD4Hep_cfg.py b/Geometry/MuonNumbering/test/testMuonOffsetDD4Hep_cfg.py new file mode 100644 index 0000000000000..c89c802dc4c26 --- /dev/null +++ b/Geometry/MuonNumbering/test/testMuonOffsetDD4Hep_cfg.py @@ -0,0 +1,22 @@ +import FWCore.ParameterSet.Config as cms + +from Configuration.Eras.Era_Run3_dd4hep_cff import Run3_dd4hep + +process = cms.Process('Dump',Run3_dd4hep) + +process.load('Configuration.Geometry.GeometryDD4hepExtended2021_cff') +process.load('Geometry.MuonNumbering.muonOffsetESProducer_cff') +process.load('FWCore.MessageService.MessageLogger_cfi') + +process.source = cms.Source("EmptySource") +process.maxEvents = cms.untracked.PSet( + input = cms.untracked.int32(1) + ) + +if hasattr(process,'MessageLogger'): + process.MessageLogger.categories.append('MuonGeom') + +process.hpa = cms.EDAnalyzer("MuonOffsetAnalyzer") +process.Timing = cms.Service("Timing") + +process.p1 = cms.Path(process.hpa) diff --git a/Geometry/MuonNumbering/test/testMuonOffsetDDD_cfg.py b/Geometry/MuonNumbering/test/testMuonOffsetDDD_cfg.py new file mode 100644 index 0000000000000..160d3cec9612f --- /dev/null +++ b/Geometry/MuonNumbering/test/testMuonOffsetDDD_cfg.py @@ -0,0 +1,22 @@ +import FWCore.ParameterSet.Config as cms + +from Configuration.Eras.Era_Run3_cff import Run3 + +process = cms.Process('Dump',Run3) + +process.load('Configuration.Geometry.GeometryExtended2021_cff') +process.load('Geometry.MuonNumbering.muonOffsetESProducer_cff') +process.load('FWCore.MessageService.MessageLogger_cfi') + +process.source = cms.Source("EmptySource") +process.maxEvents = cms.untracked.PSet( + input = cms.untracked.int32(1) + ) + +if hasattr(process,'MessageLogger'): + process.MessageLogger.categories.append('MuonGeom') + +process.hpa = cms.EDAnalyzer("MuonOffsetAnalyzer") +process.Timing = cms.Service("Timing") + +process.p1 = cms.Path(process.hpa) diff --git a/SimG4CMS/Muon/BuildFile.xml b/SimG4CMS/Muon/BuildFile.xml index 092ff6fd14c74..74a1dccc423ca 100644 --- a/SimG4CMS/Muon/BuildFile.xml +++ b/SimG4CMS/Muon/BuildFile.xml @@ -1,9 +1,10 @@ + + + - - diff --git a/SimG4CMS/Muon/interface/MuonG4Numbering.h b/SimG4CMS/Muon/interface/MuonG4Numbering.h index 99c793bc8ec6e..c8650e3c729cb 100644 --- a/SimG4CMS/Muon/interface/MuonG4Numbering.h +++ b/SimG4CMS/Muon/interface/MuonG4Numbering.h @@ -21,10 +21,11 @@ class G4Step; class MuonBaseNumber; class MuonGeometryConstants; +class MuonOffsetMap; class MuonG4Numbering { public: - MuonG4Numbering(const MuonGeometryConstants& muonConstants); + MuonG4Numbering(const MuonGeometryConstants& muonConstants, const MuonOffsetMap* offMap, bool dd4hep); ~MuonG4Numbering(){}; MuonBaseNumber PhysicalVolumeToBaseNumber(const G4Step* aStep); @@ -35,6 +36,8 @@ class MuonG4Numbering { const int getCopyNoBaseNo(const int); const bool copyNoRelevant(const int); + const MuonOffsetMap* offMap_; + const bool dd4hep_; int theLevelPart; int theSuperPart; int theBasePart; diff --git a/SimG4CMS/Muon/interface/MuonRPCFrameRotation.h b/SimG4CMS/Muon/interface/MuonRPCFrameRotation.h index 67b52f29f02c5..4fd6861dba1a8 100644 --- a/SimG4CMS/Muon/interface/MuonRPCFrameRotation.h +++ b/SimG4CMS/Muon/interface/MuonRPCFrameRotation.h @@ -12,6 +12,7 @@ */ #include "SimG4CMS/Muon/interface/MuonFrameRotation.h" +#include "CondFormats/GeometryObjects/interface/MuonOffsetMap.h" #include "G4Step.hh" @@ -20,7 +21,7 @@ class MuonGeometryConstants; class MuonRPCFrameRotation : public MuonFrameRotation { public: - MuonRPCFrameRotation(const MuonGeometryConstants& constants); + MuonRPCFrameRotation(const MuonGeometryConstants& constants, const MuonOffsetMap* offMap, bool dd4hep); ~MuonRPCFrameRotation() override; Local3DPoint transformPoint(const Local3DPoint&, const G4Step*) const override; diff --git a/SimG4CMS/Muon/interface/MuonSensitiveDetector.h b/SimG4CMS/Muon/interface/MuonSensitiveDetector.h index ef3d4f9911fd1..805164d33f61b 100644 --- a/SimG4CMS/Muon/interface/MuonSensitiveDetector.h +++ b/SimG4CMS/Muon/interface/MuonSensitiveDetector.h @@ -19,6 +19,7 @@ #include "SimG4Core/Notification/interface/BeginOfEvent.h" #include "SimG4Core/SensitiveDetector/interface/SensitiveTkDetector.h" #include "DataFormats/GeometryVector/interface/LocalPoint.h" +#include "CondFormats/GeometryObjects/interface/MuonOffsetMap.h" #include @@ -59,7 +60,7 @@ class MuonSensitiveDetector : public SensitiveTkDetector, public ObserverGetHistoryDepth(); ii++) { G4VPhysicalVolume* vol = touch->GetVolume(ii); int copyno = vol->GetCopyNo(); + int extra(0); + if (dd4hep_ && (offMap_ != nullptr)) { + std::string namx = static_cast(vol->GetName()); + std::size_t last = namx.rfind('_'); + std::string name = ((last == std::string::npos) ? namx : (namx.substr(0, last))); + auto itr = offMap_->muonMap_.find(name); + if (itr != offMap_->muonMap_.end()) + extra = (itr->second).first + (itr->second).second; #ifdef EDM_ML_DEBUG - edm::LogVerbatim("MuonSim") << "MuonG4Numbering: " << vol->GetName() << " " << copyno << std::endl - << "Split " << copyNoRelevant(copyno) << ":" << theLevelPart << ":" << theSuperPart - << " "; + edm::LogVerbatim("MuonSim") << "MuonG4Numbering: " << namx << ":" << name << " iterator " + << (itr != offMap_->muonMap_.end()) << " Extra " << extra; +#endif + } + copyno += extra; +#ifdef EDM_ML_DEBUG + edm::LogVerbatim("MuonSim") << "MuonG4Numbering: " << vol->GetName() << " " << copyno << " Split " + << copyNoRelevant(copyno) << ":" << theLevelPart << ":" << theSuperPart << " "; #endif if (copyNoRelevant(copyno)) { num.addBase(getCopyNoLevel(copyno), getCopyNoSuperNo(copyno), getCopyNoBaseNo(copyno) - theStartCopyNo); diff --git a/SimG4CMS/Muon/src/MuonRPCFrameRotation.cc b/SimG4CMS/Muon/src/MuonRPCFrameRotation.cc index 6a097e26e1f31..022d1b5e717eb 100644 --- a/SimG4CMS/Muon/src/MuonRPCFrameRotation.cc +++ b/SimG4CMS/Muon/src/MuonRPCFrameRotation.cc @@ -5,9 +5,11 @@ #include "G4Step.hh" -MuonRPCFrameRotation::MuonRPCFrameRotation(const MuonGeometryConstants& muonConstants) +MuonRPCFrameRotation::MuonRPCFrameRotation(const MuonGeometryConstants& muonConstants, + const MuonOffsetMap* offMap, + bool dd4hep) : MuonFrameRotation::MuonFrameRotation() { - g4numbering = new MuonG4Numbering(muonConstants); + g4numbering = new MuonG4Numbering(muonConstants, offMap, dd4hep); int theLevelPart = muonConstants.getValue("level"); theRegion = muonConstants.getValue("mr_region") / theLevelPart; } diff --git a/SimG4CMS/Muon/src/MuonSensitiveDetector.cc b/SimG4CMS/Muon/src/MuonSensitiveDetector.cc index 2579a7dcbaca2..1df916dc19832 100644 --- a/SimG4CMS/Muon/src/MuonSensitiveDetector.cc +++ b/SimG4CMS/Muon/src/MuonSensitiveDetector.cc @@ -52,16 +52,20 @@ MuonSensitiveDetector::MuonSensitiveDetector(const std::string& name, ePersistentCutGeV = m_MuonSD.getParameter("EnergyThresholdForPersistency") / CLHEP::GeV; //Default 1. GeV allMuonsPersistent = m_MuonSD.getParameter("AllMuonsPersistent"); printHits = m_MuonSD.getParameter("PrintHits"); - + bool dd4hep = p.getParameter("g4GeometryDD4hepSource"); // // Here simply create 1 MuonSlaveSD for the moment // #ifdef EDM_ML_DEBUG - edm::LogVerbatim("MuonSim") << "create MuonSubDetector " << name; + edm::LogVerbatim("MuonSim") << "create MuonSubDetector " << name << " with dd4hep flag " << dd4hep; #endif detector = new MuonSubDetector(name); //The constants take time to calculate and are needed by many helpers + edm::ESHandle mom; + es.get().get(mom); + const MuonOffsetMap* offmap = (mom.isValid()) ? mom.product() : nullptr; + edm::LogVerbatim("MuonSim") << "Finds the offset map at " << offmap; edm::ESHandle mdc; es.get().get(mdc); if (!mdc.isValid()) @@ -72,7 +76,7 @@ MuonSensitiveDetector::MuonSensitiveDetector(const std::string& name, theRotation = new MuonEndcapFrameRotation(); sdet = "Endcap"; } else if (detector->isRPC()) { - theRotation = new MuonRPCFrameRotation(constants); + theRotation = new MuonRPCFrameRotation(constants, offmap, dd4hep); sdet = "RPC"; } else if (detector->isGEM()) { theRotation = new MuonGEMFrameRotation(constants); @@ -85,15 +89,14 @@ MuonSensitiveDetector::MuonSensitiveDetector(const std::string& name, } slaveMuon = new MuonSlaveSD(detector, theManager); numbering = new MuonSimHitNumberingScheme(detector, constants); - g4numbering = new MuonG4Numbering(constants); + g4numbering = new MuonG4Numbering(constants, offmap, dd4hep); if (printHits) { thePrinter = new SimHitPrinter("HitPositionOSCAR.dat"); } - edm::LogVerbatim("MuonSensitiveDetector") - << " of type " << sdet << " <" << GetName() << "> EnergyThresholdForPersistency(GeV) " - << ePersistentCutGeV / CLHEP::GeV << " allMuonsPersistent: " << allMuonsPersistent; + edm::LogVerbatim("MuonSim") << " of type " << sdet << " <" << GetName() << "> EnergyThresholdForPersistency(GeV) " + << ePersistentCutGeV / CLHEP::GeV << " allMuonsPersistent: " << allMuonsPersistent; theG4ProcessTypeEnumerator = new G4ProcessTypeEnumerator; }