diff --git a/Geometry/Records/interface/VeryForwardMisalignedGeometryRecord.h b/Geometry/Records/interface/VeryForwardMisalignedGeometryRecord.h index 632f1fc9d716a..244de1022181c 100644 --- a/Geometry/Records/interface/VeryForwardMisalignedGeometryRecord.h +++ b/Geometry/Records/interface/VeryForwardMisalignedGeometryRecord.h @@ -11,6 +11,7 @@ #include "FWCore/Framework/interface/DependentRecordImplementation.h" #include "Geometry/Records/interface/IdealGeometryRecord.h" +#include "Geometry/Records/interface/VeryForwardIdealGeometryRecord.h" #include "FWCore/Utilities/interface/mplVector.h" @@ -24,6 +25,7 @@ class VeryForwardMisalignedGeometryRecord : public edm::eventsetup::DependentRecordImplementation< VeryForwardMisalignedGeometryRecord, - edm::mpl::Vector > {}; + edm::mpl::Vector > { +}; #endif diff --git a/Geometry/Records/interface/VeryForwardRealGeometryRecord.h b/Geometry/Records/interface/VeryForwardRealGeometryRecord.h index 0893a617e047c..d20924e879930 100644 --- a/Geometry/Records/interface/VeryForwardRealGeometryRecord.h +++ b/Geometry/Records/interface/VeryForwardRealGeometryRecord.h @@ -11,6 +11,7 @@ #include "FWCore/Framework/interface/DependentRecordImplementation.h" #include "Geometry/Records/interface/IdealGeometryRecord.h" +#include "Geometry/Records/interface/VeryForwardIdealGeometryRecord.h" #include "FWCore/Utilities/interface/mplVector.h" @@ -20,8 +21,9 @@ * \ingroup TotemRPGeometry * \brief Event setup record containing the real (actual) geometry information. **/ -class VeryForwardRealGeometryRecord : public edm::eventsetup::DependentRecordImplementation< - VeryForwardRealGeometryRecord, - edm::mpl::Vector > {}; +class VeryForwardRealGeometryRecord + : public edm::eventsetup::DependentRecordImplementation< + VeryForwardRealGeometryRecord, + edm::mpl::Vector > {}; #endif diff --git a/Geometry/VeryForwardGeometryBuilder/interface/DetGeomDesc.h b/Geometry/VeryForwardGeometryBuilder/interface/DetGeomDesc.h index c1297d33c46ae..76fdf0002bfe2 100644 --- a/Geometry/VeryForwardGeometryBuilder/interface/DetGeomDesc.h +++ b/Geometry/VeryForwardGeometryBuilder/interface/DetGeomDesc.h @@ -17,6 +17,7 @@ #include "DetectorDescription/Core/interface/DDFilteredView.h" #include "DetectorDescription/DDCMS/interface/DDFilteredView.h" +#include "CondFormats/GeometryObjects/interface/PDetGeomDesc.h" #include "DataFormats/DetId/interface/DetId.h" #include @@ -59,7 +60,10 @@ class DetGeomDesc { // Constructor from DD4Hep DDFilteredView /// \param[in] isRun2 Switch between legacy run 2-like geometry and 2021+ scenarii DetGeomDesc(const cms::DDFilteredView& fv, const bool isRun2); - + // Constructor from DB object PDetGeomDesc + DetGeomDesc(const PDetGeomDesc& gd); + // Constructor from DB object PDetGeomDesc::Item + DetGeomDesc(const PDetGeomDesc::Item& item); virtual ~DetGeomDesc(); enum CopyMode { cmWithChildren, cmWithoutChildren }; diff --git a/Geometry/VeryForwardGeometryBuilder/plugins/BuildFile.xml b/Geometry/VeryForwardGeometryBuilder/plugins/BuildFile.xml index 99116324c7a55..cf67439538655 100644 --- a/Geometry/VeryForwardGeometryBuilder/plugins/BuildFile.xml +++ b/Geometry/VeryForwardGeometryBuilder/plugins/BuildFile.xml @@ -1,5 +1,6 @@ + diff --git a/Geometry/VeryForwardGeometryBuilder/plugins/CTPPSGeometryESModule.cc b/Geometry/VeryForwardGeometryBuilder/plugins/CTPPSGeometryESModule.cc index cad97b1e4e445..27b177e81a680 100644 --- a/Geometry/VeryForwardGeometryBuilder/plugins/CTPPSGeometryESModule.cc +++ b/Geometry/VeryForwardGeometryBuilder/plugins/CTPPSGeometryESModule.cc @@ -6,6 +6,8 @@ * Rewritten + Moved out common functionailities to DetGeomDesc(Builder) by Gabrielle Hugo. * Migrated to DD4hep by Wagner Carvalho and Gabrielle Hugo. * +* Add the capability of reading PPS reco geometry from the database +* ****************************************************************************/ #include "FWCore/ParameterSet/interface/ParameterSet.h" @@ -19,9 +21,11 @@ #include "DetectorDescription/DDCMS/interface/DDCompactView.h" #include "CondFormats/PPSObjects/interface/CTPPSRPAlignmentCorrectionsData.h" +#include "CondFormats/GeometryObjects/interface/PDetGeomDesc.h" #include "CondFormats/AlignmentRecord/interface/RPRealAlignmentRecord.h" #include "CondFormats/AlignmentRecord/interface/RPMisalignedAlignmentRecord.h" #include "Geometry/Records/interface/IdealGeometryRecord.h" +#include "Geometry/Records/interface/VeryForwardIdealGeometryRecord.h" #include "Geometry/Records/interface/VeryForwardMisalignedGeometryRecord.h" #include "Geometry/Records/interface/VeryForwardRealGeometryRecord.h" @@ -55,27 +59,22 @@ class CTPPSGeometryESModule : public edm::ESProducer { private: std::unique_ptr produceIdealGD(const IdealGeometryRecord&); + std::unique_ptr produceIdealGDFromPreprocessedDB(const VeryForwardIdealGeometryRecord&); std::vector fillCopyNos(TGeoIterator& it); - template - struct GDTokens { - explicit GDTokens(edm::ESConsumesCollector&& iCC) - : idealGDToken_{iCC.consumesFrom(edm::ESInputTag())}, - alignmentToken_{iCC.consumesFrom(edm::ESInputTag())} {} - const edm::ESGetToken idealGDToken_; - const edm::ESGetToken alignmentToken_; - }; - std::unique_ptr produceRealGD(const VeryForwardRealGeometryRecord&); + std::unique_ptr produceRealGDFromPreprocessedDB(const VeryForwardRealGeometryRecord&); std::unique_ptr produceRealTG(const VeryForwardRealGeometryRecord&); std::unique_ptr produceMisalignedGD(const VeryForwardMisalignedGeometryRecord&); + std::unique_ptr produceMisalignedGDFromPreprocessedDB(const VeryForwardMisalignedGeometryRecord&); std::unique_ptr produceMisalignedTG(const VeryForwardMisalignedGeometryRecord&); - template - std::unique_ptr produceGD(IdealGeometryRecord const&, + template + std::unique_ptr produceGD(const GEO&, const std::optional&, - GDTokens const&, + edm::ESGetToken const&, + edm::ESGetToken const&, const char* name); const unsigned int verbosity_; @@ -83,40 +82,73 @@ class CTPPSGeometryESModule : public edm::ESProducer { edm::ESGetToken ddToken_; edm::ESGetToken dd4hepToken_; - const bool fromDD4hep_; + edm::ESGetToken dbToken_; + const bool fromPreprocessedDB_, fromDD4hep_; - const GDTokens gdRealTokens_; - const GDTokens gdMisTokens_; + edm::ESGetToken idealGDToken_; + edm::ESGetToken idealDBGDToken_; + edm::ESGetToken realAlignmentToken_; + edm::ESGetToken misAlignmentToken_; - const edm::ESGetToken dgdRealToken_; - const edm::ESGetToken dgdMisToken_; + edm::ESGetToken dgdRealToken_; + edm::ESGetToken dgdMisToken_; }; CTPPSGeometryESModule::CTPPSGeometryESModule(const edm::ParameterSet& iConfig) : verbosity_(iConfig.getUntrackedParameter("verbosity")), isRun2_(iConfig.getParameter("isRun2")), - fromDD4hep_(iConfig.getUntrackedParameter("fromDD4hep", false)), - gdRealTokens_{setWhatProduced(this, &CTPPSGeometryESModule::produceRealGD)}, - gdMisTokens_{setWhatProduced(this, &CTPPSGeometryESModule::produceMisalignedGD)}, - dgdRealToken_{ - setWhatProduced(this, &CTPPSGeometryESModule::produceRealTG).consumes(edm::ESInputTag())}, - dgdMisToken_{ - setWhatProduced(this, &CTPPSGeometryESModule::produceMisalignedTG).consumes(edm::ESInputTag())} { - auto c = setWhatProduced(this, &CTPPSGeometryESModule::produceIdealGD); - - if (!fromDD4hep_) { + fromPreprocessedDB_(iConfig.getUntrackedParameter("fromPreprocessedDB", false)), + fromDD4hep_(iConfig.getUntrackedParameter("fromDD4hep", false)) { + if (fromPreprocessedDB_) { + auto c = setWhatProduced(this, &CTPPSGeometryESModule::produceIdealGDFromPreprocessedDB); + dbToken_ = c.consumes(edm::ESInputTag("", iConfig.getParameter("dbTag"))); + + auto c1 = setWhatProduced(this, &CTPPSGeometryESModule::produceRealGDFromPreprocessedDB); + idealDBGDToken_ = c1.consumesFrom(edm::ESInputTag()); + realAlignmentToken_ = c1.consumesFrom(edm::ESInputTag()); + + auto c2 = setWhatProduced(this, &CTPPSGeometryESModule::produceMisalignedGDFromPreprocessedDB); + misAlignmentToken_ = + c2.consumesFrom(edm::ESInputTag()); + } else if (!fromDD4hep_) { + auto c = setWhatProduced(this, &CTPPSGeometryESModule::produceIdealGD); ddToken_ = c.consumes(edm::ESInputTag("", iConfig.getParameter("compactViewTag"))); + + auto c1 = setWhatProduced(this, &CTPPSGeometryESModule::produceRealGD); + idealGDToken_ = c1.consumesFrom(edm::ESInputTag()); + realAlignmentToken_ = c1.consumesFrom(edm::ESInputTag()); + + auto c2 = setWhatProduced(this, &CTPPSGeometryESModule::produceMisalignedGD); + misAlignmentToken_ = + c2.consumesFrom(edm::ESInputTag()); } else { + auto c = setWhatProduced(this, &CTPPSGeometryESModule::produceIdealGD); dd4hepToken_ = c.consumes(edm::ESInputTag("", iConfig.getParameter("compactViewTag"))); + + auto c1 = setWhatProduced(this, &CTPPSGeometryESModule::produceRealGD); + idealGDToken_ = c1.consumesFrom(edm::ESInputTag()); + realAlignmentToken_ = c1.consumesFrom(edm::ESInputTag()); + + auto c2 = setWhatProduced(this, &CTPPSGeometryESModule::produceMisalignedGD); + misAlignmentToken_ = + c2.consumesFrom(edm::ESInputTag()); } + + auto c_RTG = setWhatProduced(this, &CTPPSGeometryESModule::produceRealTG); + dgdRealToken_ = c_RTG.consumes(edm::ESInputTag()); + + auto c_MTG = setWhatProduced(this, &CTPPSGeometryESModule::produceMisalignedTG); + dgdMisToken_ = c_MTG.consumes(edm::ESInputTag()); } void CTPPSGeometryESModule::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; desc.addUntracked("verbosity", 1); desc.add("isRun2", false)->setComment("Switch to legacy (2017-18) definition of diamond geometry"); + desc.add("dbTag", std::string()); desc.add("compactViewTag", std::string()); + desc.addUntracked("fromPreprocessedDB", false); desc.addUntracked("fromDD4hep", false); descriptions.add("CTPPSGeometryESModule", desc); } @@ -139,18 +171,32 @@ std::unique_ptr CTPPSGeometryESModule::produceIdealGD(const IdealGe } } -template -std::unique_ptr CTPPSGeometryESModule::produceGD(IdealGeometryRecord const& iIdealRec, - std::optional const& iAlignRec, - GDTokens const& iTokens, - const char* name) { +std::unique_ptr CTPPSGeometryESModule::produceIdealGDFromPreprocessedDB( + const VeryForwardIdealGeometryRecord& iRecord) { + // Get the PDetGeomDesc from EventSetup + auto const& myDB = iRecord.get(dbToken_); + + edm::LogInfo("CTPPSGeometryESModule") << " myDB size = " << myDB.container_.size(); + + // Build geo from PDetGeomDesc DB object. + auto pdet = std::make_unique(myDB); + return pdet; +} + +template +std::unique_ptr CTPPSGeometryESModule::produceGD( + GEO const& iIdealRec, + std::optional const& iAlignRec, + edm::ESGetToken const& iGDToken, + edm::ESGetToken const& iAlignToken, + const char* name) { // get the input GeometricalDet - auto const& idealGD = iIdealRec.get(iTokens.idealGDToken_); + auto const& idealGD = iIdealRec.get(iGDToken); // load alignments CTPPSRPAlignmentCorrectionsData const* alignments = nullptr; if (iAlignRec) { - auto alignmentsHandle = iAlignRec->getHandle(iTokens.alignmentToken_); + auto alignmentsHandle = iAlignRec->getHandle(iAlignToken); if (alignmentsHandle.isValid()) { alignments = alignmentsHandle.product(); } @@ -168,10 +214,33 @@ std::unique_ptr CTPPSGeometryESModule::produceGD(IdealGeometryRecor return CTPPSGeometryESCommon::applyAlignments(idealGD, alignments); } +std::unique_ptr CTPPSGeometryESModule::produceRealGDFromPreprocessedDB( + const VeryForwardRealGeometryRecord& iRecord) { + return produceGD(iRecord.getRecord(), + iRecord.tryToGetRecord(), + idealDBGDToken_, + realAlignmentToken_, + "CTPPSGeometryESModule::produceRealGDFromPreprocessedDB"); +} + +//---------------------------------------------------------------------------------------------------- + +std::unique_ptr CTPPSGeometryESModule::produceMisalignedGDFromPreprocessedDB( + const VeryForwardMisalignedGeometryRecord& iRecord) { + return produceGD(iRecord.getRecord(), + iRecord.tryToGetRecord(), + idealDBGDToken_, + misAlignmentToken_, + "CTPPSGeometryESModule::produceMisalignedGDFromPreprocessedDB"); +} + +//---------------------------------------------------------------------------------------------------- + std::unique_ptr CTPPSGeometryESModule::produceRealGD(const VeryForwardRealGeometryRecord& iRecord) { return produceGD(iRecord.getRecord(), iRecord.tryToGetRecord(), - gdRealTokens_, + idealGDToken_, + realAlignmentToken_, "CTPPSGeometryESModule::produceRealGD"); } @@ -181,7 +250,8 @@ std::unique_ptr CTPPSGeometryESModule::produceMisalignedGD( const VeryForwardMisalignedGeometryRecord& iRecord) { return produceGD(iRecord.getRecord(), iRecord.tryToGetRecord(), - gdMisTokens_, + idealGDToken_, + misAlignmentToken_, "CTPPSGeometryESModule::produceMisalignedGD"); } diff --git a/Geometry/VeryForwardGeometryBuilder/src/DetGeomDesc.cc b/Geometry/VeryForwardGeometryBuilder/src/DetGeomDesc.cc index 20124c782965f..49c169c12ae4b 100644 --- a/Geometry/VeryForwardGeometryBuilder/src/DetGeomDesc.cc +++ b/Geometry/VeryForwardGeometryBuilder/src/DetGeomDesc.cc @@ -75,6 +75,38 @@ DetGeomDesc::DetGeomDesc(const DetGeomDesc& ref, CopyMode cm) { m_z = ref.m_z; } +// Constructor from DB object PDetGeomDesc::Item +DetGeomDesc::DetGeomDesc(const PDetGeomDesc::Item& item) + : m_name(item.name_), + m_copy(item.copy_), + m_isDD4hep(true), + m_params(item.params_), // default unit from DD4hep + m_sensorType(item.sensorType_), + m_geographicalID(item.geographicalID_), + m_z(item.z_) // converted from DD4hep to mm +{ + Translation trans(item.dx_, item.dy_, item.dz_); + m_trans = trans; + RotationMatrix rot(item.axx_, item.axy_, item.axz_, item.ayx_, item.ayy_, item.ayz_, item.azx_, item.azy_, item.azz_); + m_rot = rot; + // Set the m_isABox flag for the box shaped sensors, so that m_params are properly set + if ((m_name == DDD_CTPPS_PIXELS_SENSOR_NAME || m_name == DDD_CTPPS_PIXELS_SENSOR_NAME_2x2 || + m_name == DDD_CTPPS_DIAMONDS_SEGMENT_NAME || m_name == DDD_CTPPS_UFSD_SEGMENT_NAME || + m_name.substr(0, 7) == DDD_TOTEM_TIMING_SENSOR_TMPL.substr(0, 7)) && + m_params.size() > 2) + m_isABox = true; + else + m_isABox = false; + m_diamondBoxParams = computeDiamondDimensions(m_isABox, m_isDD4hep, m_params); +} + +DetGeomDesc::DetGeomDesc(const PDetGeomDesc& pd) { + for (const auto& i : pd.container_) { + DetGeomDesc* gd = new DetGeomDesc(i); + this->addComponent(gd); + } +} + DetGeomDesc::~DetGeomDesc() { deepDeleteComponents(); } void DetGeomDesc::addComponent(DetGeomDesc* det) { m_container.emplace_back(det); } @@ -122,7 +154,7 @@ void DetGeomDesc::deepDeleteComponents() { } std::string DetGeomDesc::computeNameWithNoNamespace(std::string_view nameFromView) const { - const auto& semiColonPos = nameFromView.find(":"); + const auto& semiColonPos = nameFromView.find(':'); const std::string name{(semiColonPos != std::string::npos ? nameFromView.substr(semiColonPos + 1) : nameFromView)}; return name; } diff --git a/Geometry/VeryForwardGeometryBuilder/test/print_geometry_info_geomFromDB_cfg.py b/Geometry/VeryForwardGeometryBuilder/test/print_geometry_info_geomFromDB_cfg.py new file mode 100644 index 0000000000000..9680f9a0e387b --- /dev/null +++ b/Geometry/VeryForwardGeometryBuilder/test/print_geometry_info_geomFromDB_cfg.py @@ -0,0 +1,69 @@ +import FWCore.ParameterSet.Config as cms +process = cms.Process("GeometryInfo") + +# minimum of logs +process.MessageLogger = cms.Service("MessageLogger", + cerr = cms.untracked.PSet( + enable = cms.untracked.bool(False) + ), + cout = cms.untracked.PSet( + enable = cms.untracked.bool(True), + threshold = cms.untracked.string('INFO') + ) +) + +# geometry +process.load("CondCore.CondDB.CondDB_cfi") +# input database (in this case local sqlite file) +#process.CondDB.connect = 'sqlite_file:../../CondTools/Geometry/PPSGeometry_oldDD_multiIOV.db' +process.CondDB.connect = cms.string( 'frontier://FrontierPrep/CMS_CONDITIONS' ) + +process.PoolDBESSource = cms.ESSource("PoolDBESSource", + process.CondDB, + DumpStat=cms.untracked.bool(True), + toGet = cms.VPSet( + cms.PSet( + record = cms.string('VeryForwardIdealGeometryRecord'), + tag = cms.string("PPS_RecoGeometry_test_v1") + ) + ) +) + +process.ctppsGeometryESModule = cms.ESProducer("CTPPSGeometryESModule", + fromPreprocessedDB = cms.untracked.bool(True), + fromDD4hep = cms.untracked.bool(False), + verbosity = cms.untracked.uint32(1), +) + + +# load alignment correction +process.load("CalibPPS.ESProducers.ctppsRPAlignmentCorrectionsDataESSourceXML_cfi") +process.ctppsRPAlignmentCorrectionsDataESSourceXML.RealFiles = cms.vstring( + "Geometry/VeryForwardGeometryBuilder/test/alignment_file_1.xml", + "Geometry/VeryForwardGeometryBuilder/test/alignment_file_2.xml", +) +process.ctppsRPAlignmentCorrectionsDataESSourceXML.verbosity = 1 + +# no events to process +process.source = cms.Source("EmptySource", +# firstRun = cms.untracked.uint32(273725), # start run for 2016-2017 + firstRun = cms.untracked.uint32(314747), # start run for 2018 + firstLuminosityBlock = cms.untracked.uint32(1), + firstEvent = cms.untracked.uint32(1), + numberEventsInLuminosityBlock = cms.untracked.uint32(3), + numberEventsInRun = cms.untracked.uint32(30) +) + +process.maxEvents = cms.untracked.PSet( + input = cms.untracked.int32(1) +) + +process.ctppsGeometryInfo = cms.EDAnalyzer("CTPPSGeometryInfo", + geometryType = cms.untracked.string("real"), + printRPInfo = cms.untracked.bool(True), + printSensorInfo = cms.untracked.bool(True) +) + +process.p = cms.Path( + process.ctppsGeometryInfo +)