Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14:27

0001 // -*- C++ -*-
0002 //
0003 // Package:    DetectorDescription/DTGeometryESProducer
0004 // Class:      DTGeometryESProducer
0005 //
0006 /**\class DTGeometryESProducer
0007 
0008  Description: DT Geometry ES producer
0009 
0010  Implementation:
0011      Based on a copy of original DTGeometryESProducer
0012 */
0013 //
0014 // Original Author:  Ianna Osborne
0015 //         Created:  Wed, 16 Jan 2019 10:19:37 GMT
0016 //         Modified by Sergio Lo Meo (sergio.lo.meo@cern.ch) Mon, 31 August 2020
0017 //
0018 //
0019 #include "CondFormats/GeometryObjects/interface/RecoIdealGeometry.h"
0020 #include "CondFormats/Alignment/interface/DetectorGlobalPosition.h"
0021 #include "CondFormats/Alignment/interface/AlignmentErrorsExtended.h"
0022 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
0023 #include "CondFormats/AlignmentRecord/interface/DTAlignmentRcd.h"
0024 #include "CondFormats/AlignmentRecord/interface/DTAlignmentErrorRcd.h"
0025 #include "CondFormats/AlignmentRecord/interface/DTAlignmentErrorExtendedRcd.h"
0026 #include "Geometry/CommonTopologies/interface/GeometryAligner.h"
0027 #include "Geometry/Records/interface/DTRecoGeometryRcd.h"
0028 #include "DataFormats/GeometrySurface/interface/Plane.h"
0029 #include "DataFormats/GeometrySurface/interface/Bounds.h"
0030 #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h"
0031 #include "FWCore/Framework/interface/ESTransientHandle.h"
0032 #include "FWCore/Framework/interface/ModuleFactory.h"
0033 #include "FWCore/Framework/interface/ESProducer.h"
0034 #include "FWCore/Framework/interface/ESProductHost.h"
0035 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0036 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0037 #include "FWCore/Utilities/interface/ESGetToken.h"
0038 #include "FWCore/Utilities/interface/ReusableObjectHolder.h"
0039 #include "Geometry/MuonNumbering/interface/MuonGeometryNumbering.h"
0040 #include "Geometry/MuonNumbering/interface/MuonGeometryConstants.h"
0041 #include "Geometry/Records/interface/MuonNumberingRecord.h"
0042 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0043 #include "Geometry/Records/interface/DDSpecParRegistryRcd.h"
0044 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0045 #include "DetectorDescription/DDCMS/interface/DDSpecParRegistry.h"
0046 #include "DetectorDescription/DDCMS/interface/DDDetector.h"
0047 #include "DetectorDescription/DDCMS/interface/DDFilteredView.h"
0048 #include "DetectorDescription/DDCMS/interface/BenchmarkGrd.h"
0049 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0050 #include "DTGeometryBuilder.h"
0051 
0052 #include <memory>
0053 #include <iostream>
0054 #include <iterator>
0055 #include <string>
0056 
0057 using namespace edm;
0058 using namespace std;
0059 using namespace cms;
0060 
0061 class DTGeometryESProducer : public ESProducer {
0062 public:
0063   DTGeometryESProducer(const ParameterSet&);
0064   ~DTGeometryESProducer() override;
0065 
0066   using ReturnType = shared_ptr<DTGeometry>;
0067   using Detector = dd4hep::Detector;
0068 
0069   ReturnType produce(const MuonGeometryRecord& record);
0070 
0071 private:
0072   using HostType = ESProductHost<DTGeometry, MuonNumberingRecord, DTRecoGeometryRcd>;
0073 
0074   void setupGeometry(MuonNumberingRecord const&, shared_ptr<HostType>&);
0075   void setupDBGeometry(DTRecoGeometryRcd const&, shared_ptr<HostType>&);
0076 
0077   ReusableObjectHolder<HostType> m_holder;
0078 
0079   edm::ESGetToken<Alignments, GlobalPositionRcd> m_globalPositionToken;
0080   edm::ESGetToken<Alignments, DTAlignmentRcd> m_alignmentsToken;
0081   edm::ESGetToken<AlignmentErrorsExtended, DTAlignmentErrorExtendedRcd> m_alignmentErrorsToken;
0082   edm::ESGetToken<MuonGeometryConstants, IdealGeometryRecord> m_mdcToken;
0083   edm::ESGetToken<DDDetector, IdealGeometryRecord> m_cpvToken;
0084   edm::ESGetToken<DDSpecParRegistry, DDSpecParRegistryRcd> m_registryToken;
0085   const ESInputTag m_tag;
0086   const string m_alignmentsLabel;
0087   const string m_myLabel;
0088   const string m_attribute;
0089   const string m_value;
0090   bool m_applyAlignment;
0091   bool m_fromDDD;
0092 };
0093 
0094 DTGeometryESProducer::DTGeometryESProducer(const ParameterSet& iConfig)
0095     : m_tag(iConfig.getParameter<ESInputTag>("DDDetector")),
0096       m_alignmentsLabel(iConfig.getParameter<string>("alignmentsLabel")),
0097       m_myLabel(iConfig.getParameter<string>("appendToDataLabel")),
0098       m_attribute(iConfig.getParameter<string>("attribute")),
0099       m_value(iConfig.getParameter<string>("value")),
0100       m_fromDDD(iConfig.getParameter<bool>("fromDDD")) {
0101   m_applyAlignment = iConfig.getParameter<bool>("applyAlignment");
0102 
0103   auto cc = setWhatProduced(this);
0104 
0105   if (m_applyAlignment) {
0106     m_globalPositionToken = cc.consumesFrom<Alignments, GlobalPositionRcd>(edm::ESInputTag{"", m_alignmentsLabel});
0107     m_alignmentsToken = cc.consumesFrom<Alignments, DTAlignmentRcd>(edm::ESInputTag{"", m_alignmentsLabel});
0108     m_alignmentErrorsToken =
0109         cc.consumesFrom<AlignmentErrorsExtended, DTAlignmentErrorExtendedRcd>(edm::ESInputTag{"", m_alignmentsLabel});
0110   }
0111 
0112   if (m_fromDDD) {
0113     m_mdcToken = cc.consumesFrom<MuonGeometryConstants, IdealGeometryRecord>(edm::ESInputTag{});
0114     m_cpvToken = cc.consumesFrom<DDDetector, IdealGeometryRecord>(m_tag);
0115     m_registryToken = cc.consumesFrom<DDSpecParRegistry, DDSpecParRegistryRcd>(m_tag);
0116   }
0117 
0118   edm::LogInfo("Geometry") << "@SUB=DTGeometryESProducer"
0119                            << "Label '" << m_myLabel << "' " << (m_applyAlignment ? "looking for" : "IGNORING")
0120                            << " alignment labels '" << m_alignmentsLabel << "'.";
0121 }
0122 
0123 DTGeometryESProducer::~DTGeometryESProducer() {}
0124 
0125 std::shared_ptr<DTGeometry> DTGeometryESProducer::produce(const MuonGeometryRecord& record) {
0126   auto host = m_holder.makeOrGet([]() { return new HostType; });
0127 
0128   {
0129     BenchmarkGrd counter("DTGeometryESProducer");
0130 
0131     if (m_fromDDD) {
0132       host->ifRecordChanges<MuonNumberingRecord>(record, [this, &host](auto const& rec) { setupGeometry(rec, host); });
0133     } else {
0134       host->ifRecordChanges<DTRecoGeometryRcd>(record, [this, &host](auto const& rec) { setupDBGeometry(rec, host); });
0135     }
0136   }
0137 
0138   if (m_applyAlignment) {
0139     const auto& globalPosition = record.get(m_globalPositionToken);
0140     const auto& alignments = record.get(m_alignmentsToken);
0141     const auto& alignmentErrors = record.get(m_alignmentErrorsToken);
0142 
0143     if (alignments.empty() && alignmentErrors.empty() && globalPosition.empty()) {
0144       edm::LogInfo("Config") << "@SUB=DTGeometryRecord::produce"
0145                              << "Alignment and global position errors";
0146 
0147     } else {
0148       GeometryAligner aligner;
0149       aligner.applyAlignments<DTGeometry>(
0150           &(*host), &alignments, &alignmentErrors, align::DetectorGlobalPosition(globalPosition, DetId(DetId::Muon)));
0151     }
0152   }
0153 
0154   return host;
0155 }
0156 
0157 void DTGeometryESProducer::setupGeometry(const MuonNumberingRecord& record, shared_ptr<HostType>& host) {
0158   host->clear();
0159 
0160   const auto& mdc = record.get(m_mdcToken);
0161 
0162   edm::ESTransientHandle<DDDetector> cpv = record.getTransientHandle(m_cpvToken);
0163 
0164   ESTransientHandle<DDSpecParRegistry> registry = record.getTransientHandle(m_registryToken);
0165 
0166   DDSpecParRefs myReg;
0167   {
0168     BenchmarkGrd b1("DTGeometryESProducer Filter Registry");
0169     registry->filter(myReg, m_attribute, m_value);
0170   }
0171 
0172   DTGeometryBuilder builder;
0173   builder.build(*host, cpv.product(), mdc, myReg);
0174 }
0175 
0176 void DTGeometryESProducer::setupDBGeometry(const DTRecoGeometryRcd& record, std::shared_ptr<HostType>& host) {
0177   // host->clear();
0178   // edm::ESHandle<RecoIdealGeometry> rig;
0179   // record.get(rig);
0180   // DTGeometryBuilderFromCondDB builder;
0181   // builder.build(host, *rig);
0182 }
0183 
0184 DEFINE_FWK_EVENTSETUP_MODULE(DTGeometryESProducer);