File indexing completed on 2024-08-13 05:00:37
0001 #include "FWCore/Framework/interface/ESProducer.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 #include "Geometry/Records/interface/MTDDigiGeometryRecord.h"
0004 #include "Geometry/MTDGeometryBuilder/interface/MTDGeometry.h"
0005
0006 #include "Geometry/MTDGeometryBuilder/interface/MTDGeomBuilderFromGeometricTimingDet.h"
0007 #include "Geometry/MTDNumberingBuilder/interface/GeometricTimingDet.h"
0008 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0009 #include "Geometry/Records/interface/PMTDParametersRcd.h"
0010 #include "CondFormats/GeometryObjects/interface/PMTDParameters.h"
0011 #include "Geometry/MTDNumberingBuilder/interface/MTDTopology.h"
0012 #include "Geometry/Records/interface/MTDTopologyRcd.h"
0013
0014
0015 #include "CondFormats/Alignment/interface/Alignments.h"
0016 #include "CondFormats/Alignment/interface/AlignmentErrorsExtended.h"
0017 #include "CondFormats/Alignment/interface/AlignmentSurfaceDeformations.h"
0018 #include "CondFormats/Alignment/interface/DetectorGlobalPosition.h"
0019 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
0020 #include "CondFormats/AlignmentRecord/interface/MTDAlignmentRcd.h"
0021 #include "CondFormats/AlignmentRecord/interface/MTDAlignmentErrorExtendedRcd.h"
0022 #include "CondFormats/AlignmentRecord/interface/MTDSurfaceDeformationRcd.h"
0023 #include "Geometry/GeometryAligner/interface/GeometryAligner.h"
0024
0025 #include "FWCore/Framework/interface/EventSetup.h"
0026 #include "FWCore/Framework/interface/ESHandle.h"
0027 #include "FWCore/Framework/interface/ModuleFactory.h"
0028 #include "FWCore/Framework/interface/ESProducer.h"
0029 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0030 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0031
0032 #include <memory>
0033 #include <string>
0034
0035 class MTDDigiGeometryESModule : public edm::ESProducer {
0036 public:
0037 MTDDigiGeometryESModule(const edm::ParameterSet& p);
0038 std::unique_ptr<MTDGeometry> produce(const MTDDigiGeometryRecord&);
0039
0040 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0041
0042 private:
0043
0044 const std::string alignmentsLabel_;
0045 const std::string myLabel_;
0046
0047 edm::ESGetToken<GeometricTimingDet, IdealGeometryRecord> geomTimingDetToken_;
0048 edm::ESGetToken<MTDTopology, MTDTopologyRcd> mtdTopoToken_;
0049 edm::ESGetToken<PMTDParameters, PMTDParametersRcd> pmtdParamsToken_;
0050
0051
0052 edm::ESGetToken<Alignments, GlobalPositionRcd> globalAlignToken_;
0053 edm::ESGetToken<Alignments, MTDAlignmentRcd> mtdAlignToken_;
0054 edm::ESGetToken<AlignmentErrorsExtended, MTDAlignmentErrorExtendedRcd> alignErrorsToken_;
0055 edm::ESGetToken<AlignmentSurfaceDeformations, MTDSurfaceDeformationRcd> deformationsToken_;
0056
0057 const bool applyAlignment_;
0058 const bool fromDDD_;
0059 };
0060
0061
0062 MTDDigiGeometryESModule::MTDDigiGeometryESModule(const edm::ParameterSet& p)
0063 : alignmentsLabel_(p.getParameter<std::string>("alignmentsLabel")),
0064 myLabel_(p.getParameter<std::string>("appendToDataLabel")),
0065 applyAlignment_(p.getParameter<bool>("applyAlignment")),
0066 fromDDD_(p.getParameter<bool>("fromDDD"))
0067
0068 {
0069 auto cc = setWhatProduced(this);
0070 const edm::ESInputTag kEmpty;
0071 geomTimingDetToken_ = cc.consumesFrom<GeometricTimingDet, IdealGeometryRecord>(kEmpty);
0072 mtdTopoToken_ = cc.consumesFrom<MTDTopology, MTDTopologyRcd>(kEmpty);
0073 pmtdParamsToken_ = cc.consumesFrom<PMTDParameters, PMTDParametersRcd>(kEmpty);
0074
0075 {
0076 const edm::ESInputTag kAlignTag{"", alignmentsLabel_};
0077 globalAlignToken_ = cc.consumesFrom<Alignments, GlobalPositionRcd>(kAlignTag);
0078 mtdAlignToken_ = cc.consumesFrom<Alignments, MTDAlignmentRcd>(kAlignTag);
0079 alignErrorsToken_ = cc.consumesFrom<AlignmentErrorsExtended, MTDAlignmentErrorExtendedRcd>(kAlignTag);
0080 deformationsToken_ = cc.consumesFrom<AlignmentSurfaceDeformations, MTDSurfaceDeformationRcd>(kAlignTag);
0081 }
0082
0083 edm::LogInfo("Geometry") << "@SUB=MTDDigiGeometryESModule"
0084 << "Label '" << myLabel_ << "' " << (applyAlignment_ ? "looking for" : "IGNORING")
0085 << " alignment labels '" << alignmentsLabel_ << "'.";
0086 }
0087
0088
0089 void MTDDigiGeometryESModule::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0090 edm::ParameterSetDescription descDB;
0091 descDB.add<std::string>("appendToDataLabel", "");
0092 descDB.add<bool>("fromDDD", false);
0093 descDB.add<bool>("applyAlignment", true);
0094 descDB.add<std::string>("alignmentsLabel", "");
0095 descriptions.add("mtdGeometryDB", descDB);
0096
0097 edm::ParameterSetDescription desc;
0098 desc.add<std::string>("appendToDataLabel", "");
0099 desc.add<bool>("fromDDD", true);
0100 desc.add<bool>("applyAlignment", true);
0101 desc.add<std::string>("alignmentsLabel", "");
0102 descriptions.add("mtdGeometry", desc);
0103 }
0104
0105
0106 std::unique_ptr<MTDGeometry> MTDDigiGeometryESModule::produce(const MTDDigiGeometryRecord& iRecord) {
0107
0108
0109
0110 GeometricTimingDet const& gD = iRecord.get(geomTimingDetToken_);
0111
0112 MTDTopology const& tTopo = iRecord.get(mtdTopoToken_);
0113
0114 PMTDParameters const& ptp = iRecord.get(pmtdParamsToken_);
0115
0116 MTDGeomBuilderFromGeometricTimingDet builder;
0117 std::unique_ptr<MTDGeometry> mtd(builder.build(&(gD), ptp, &tTopo));
0118
0119 if (applyAlignment_) {
0120
0121 Alignments const& globalPosition = iRecord.get(globalAlignToken_);
0122 Alignments const& alignments = iRecord.get(mtdAlignToken_);
0123 AlignmentErrorsExtended const& alignmentErrors = iRecord.get(alignErrorsToken_);
0124
0125 if (alignments.empty() && alignmentErrors.empty() && globalPosition.empty()) {
0126 edm::LogInfo("Config") << "@SUB=MTDDigiGeometryRecord::produce"
0127 << "Alignment(Error)s and global position (label '" << alignmentsLabel_
0128 << "') empty: Geometry producer (label "
0129 << "'" << myLabel_ << "') assumes fake and does not apply.";
0130 } else {
0131 GeometryAligner ali;
0132 ali.applyAlignments<MTDGeometry>(mtd.get(),
0133 &(alignments),
0134 &(alignmentErrors),
0135 align::DetectorGlobalPosition(globalPosition, DetId(DetId::Forward)));
0136 }
0137
0138 AlignmentSurfaceDeformations const& surfaceDeformations = iRecord.get(deformationsToken_);
0139
0140 if (surfaceDeformations.empty()) {
0141 edm::LogInfo("Config") << "@SUB=MTDDigiGeometryRecord::produce"
0142 << "AlignmentSurfaceDeformations (label '" << alignmentsLabel_
0143 << "') empty: Geometry producer (label "
0144 << "'" << myLabel_ << "') assumes fake and does not apply.";
0145 } else {
0146 GeometryAligner ali;
0147 ali.attachSurfaceDeformations<MTDGeometry>(mtd.get(), &(surfaceDeformations));
0148 }
0149 }
0150
0151 return mtd;
0152 }
0153
0154 DEFINE_FWK_EVENTSETUP_MODULE(MTDDigiGeometryESModule);