Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-01-21 00:19:33

0001 #include "FWCore/Framework/interface/ESProducer.h"
0002 #include "FWCore/Framework/interface/EventSetup.h"
0003 #include "FWCore/Framework/interface/ESHandle.h"
0004 #include "FWCore/Framework/interface/ModuleFactory.h"
0005 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0008 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0009 #include "CondFormats/Alignment/interface/Alignments.h"
0010 #include "CondFormats/Alignment/interface/AlignmentErrorsExtended.h"
0011 #include "CondFormats/Alignment/interface/AlignmentSurfaceDeformations.h"
0012 #include "CondFormats/Alignment/interface/DetectorGlobalPosition.h"
0013 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
0014 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentRcd.h"
0015 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentErrorExtendedRcd.h"
0016 #include "CondFormats/AlignmentRecord/interface/TrackerSurfaceDeformationRcd.h"
0017 #include "CondFormats/GeometryObjects/interface/PTrackerParameters.h"
0018 #include "Geometry/CommonTopologies/interface/GeometryAligner.h"
0019 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0020 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0021 #include "Geometry/Records/interface/PTrackerParametersRcd.h"
0022 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0023 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0024 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h"
0025 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0026 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
0027 
0028 #include <memory>
0029 #include <string>
0030 
0031 class TrackerDigiGeometryESModule : public edm::ESProducer {
0032 public:
0033   TrackerDigiGeometryESModule(const edm::ParameterSet& p);
0034   ~TrackerDigiGeometryESModule() override;
0035   std::unique_ptr<TrackerGeometry> produce(const TrackerDigiGeometryRecord&);
0036 
0037   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0038 
0039 private:
0040   /// Called when geometry description changes
0041   const std::string alignmentsLabel_;
0042   const std::string myLabel_;
0043 
0044   edm::ESGetToken<GeometricDet, IdealGeometryRecord> geometricDetToken_;
0045   edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> trackerTopoToken_;
0046   edm::ESGetToken<PTrackerParameters, PTrackerParametersRcd> trackerParamsToken_;
0047 
0048   edm::ESGetToken<Alignments, GlobalPositionRcd> globalAlignmentToken_;
0049   edm::ESGetToken<Alignments, TrackerAlignmentRcd> trackerAlignmentToken_;
0050   edm::ESGetToken<AlignmentErrorsExtended, TrackerAlignmentErrorExtendedRcd> alignmentErrorsToken_;
0051   edm::ESGetToken<AlignmentSurfaceDeformations, TrackerSurfaceDeformationRcd> deformationsToken_;
0052 
0053   const bool applyAlignment_;  // Switch to apply alignment corrections
0054 };
0055 
0056 //__________________________________________________________________
0057 TrackerDigiGeometryESModule::TrackerDigiGeometryESModule(const edm::ParameterSet& p)
0058     : alignmentsLabel_(p.getParameter<std::string>("alignmentsLabel")),
0059       myLabel_(p.getParameter<std::string>("appendToDataLabel")),
0060       applyAlignment_(p.getParameter<bool>("applyAlignment")) {
0061   {
0062     auto cc = setWhatProduced(this);
0063     const edm::ESInputTag kEmptyTag;
0064     geometricDetToken_ = cc.consumesFrom<GeometricDet, IdealGeometryRecord>(kEmptyTag);
0065     trackerTopoToken_ = cc.consumesFrom<TrackerTopology, TrackerTopologyRcd>(kEmptyTag);
0066     trackerParamsToken_ = cc.consumesFrom<PTrackerParameters, PTrackerParametersRcd>(kEmptyTag);
0067 
0068     if (applyAlignment_) {
0069       const edm::ESInputTag kAlignTag{"", alignmentsLabel_};
0070       globalAlignmentToken_ = cc.consumesFrom<Alignments, GlobalPositionRcd>(kAlignTag);
0071       trackerAlignmentToken_ = cc.consumesFrom<Alignments, TrackerAlignmentRcd>(kAlignTag);
0072       alignmentErrorsToken_ = cc.consumesFrom<AlignmentErrorsExtended, TrackerAlignmentErrorExtendedRcd>(kAlignTag);
0073       deformationsToken_ = cc.consumesFrom<AlignmentSurfaceDeformations, TrackerSurfaceDeformationRcd>(kAlignTag);
0074     }
0075   }
0076 
0077   edm::LogInfo("Geometry") << "@SUB=TrackerDigiGeometryESModule"
0078                            << "Label '" << myLabel_ << "' " << (applyAlignment_ ? "looking for" : "IGNORING")
0079                            << " alignment labels '" << alignmentsLabel_ << "'.";
0080 }
0081 
0082 //__________________________________________________________________
0083 TrackerDigiGeometryESModule::~TrackerDigiGeometryESModule() {}
0084 
0085 void TrackerDigiGeometryESModule::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0086   edm::ParameterSetDescription descDB;
0087   descDB.add<std::string>("appendToDataLabel", "");
0088   descDB.add<bool>("fromDDD", false);
0089   descDB.add<bool>("applyAlignment", true);
0090   descDB.add<std::string>("alignmentsLabel", "");
0091   descriptions.add("trackerGeometryDB", descDB);
0092 
0093   edm::ParameterSetDescription desc;
0094   desc.add<std::string>("appendToDataLabel", "");
0095   desc.add<bool>("fromDDD", true);
0096   desc.add<bool>("applyAlignment", true);
0097   desc.add<std::string>("alignmentsLabel", "");
0098   descriptions.add("trackerGeometry", desc);
0099 }
0100 
0101 //__________________________________________________________________
0102 std::unique_ptr<TrackerGeometry> TrackerDigiGeometryESModule::produce(const TrackerDigiGeometryRecord& iRecord) {
0103   //
0104   // Called whenever the alignments, alignment errors or global positions change
0105   //
0106   auto const& gD = iRecord.get(geometricDetToken_);
0107 
0108   auto const& tTopo = iRecord.get(trackerTopoToken_);
0109 
0110   auto const& ptp = iRecord.get(trackerParamsToken_);
0111 
0112   TrackerGeomBuilderFromGeometricDet builder;
0113   std::unique_ptr<TrackerGeometry> tracker(builder.build(&gD, ptp, &tTopo));
0114 
0115   if (applyAlignment_) {
0116     // Since fake is fully working when checking for 'empty', we should get rid of applyAlignment_!
0117     auto const& globalPosition = iRecord.get(globalAlignmentToken_);
0118     auto const& alignments = iRecord.get(trackerAlignmentToken_);
0119     auto const& alignmentErrors = iRecord.get(alignmentErrorsToken_);
0120     // apply if not empty:
0121     if (alignments.empty() && alignmentErrors.empty() && globalPosition.empty()) {
0122       edm::LogInfo("Config") << "@SUB=TrackerDigiGeometryRecord::produce"
0123                              << "Alignment(Error)s and global position (label '" << alignmentsLabel_
0124                              << "') empty: Geometry producer (label "
0125                              << "'" << myLabel_ << "') assumes fake and does not apply.";
0126     } else {
0127       GeometryAligner ali;
0128       ali.applyAlignments<TrackerGeometry>(tracker.get(),
0129                                            &(alignments),
0130                                            &(alignmentErrors),
0131                                            align::DetectorGlobalPosition(globalPosition, DetId(DetId::Tracker)));
0132     }
0133 
0134     auto const& surfaceDeformations = iRecord.get(deformationsToken_);
0135     // apply if not empty:
0136     if (surfaceDeformations.empty()) {
0137       edm::LogInfo("Config") << "@SUB=TrackerDigiGeometryRecord::produce"
0138                              << "AlignmentSurfaceDeformations (label '" << alignmentsLabel_
0139                              << "') empty: Geometry producer (label "
0140                              << "'" << myLabel_ << "') assumes fake and does not apply.";
0141     } else {
0142       GeometryAligner ali;
0143       ali.attachSurfaceDeformations<TrackerGeometry>(tracker.get(), &(surfaceDeformations));
0144     }
0145   }
0146 
0147   return tracker;
0148 }
0149 
0150 DEFINE_FWK_EVENTSETUP_MODULE(TrackerDigiGeometryESModule);