Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-29 01:21:31

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