File indexing completed on 2024-08-13 05:00:13
0001
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include "FWCore/Framework/interface/ESHandle.h"
0004 #include "FWCore/Framework/interface/ModuleFactory.h"
0005 #include "FWCore/Framework/interface/ESProducer.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008
0009
0010 #include "FWCore/ServiceRegistry/interface/Service.h"
0011 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0012
0013
0014 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h"
0015 #include "Geometry/GeometryAligner/interface/GeometryAligner.h"
0016 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0017 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0018 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0019
0020
0021 #include "CondFormats/Alignment/interface/AlignmentErrorsExtended.h"
0022 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
0023 #include "Alignment/TrackerAlignment/interface/TrackerScenarioBuilder.h"
0024 #include "Alignment/CommonAlignment/interface/Alignable.h"
0025
0026
0027 #include <memory>
0028 #include <algorithm>
0029
0030
0031
0032
0033
0034
0035
0036
0037 class MisalignedTrackerESProducer : public edm::ESProducer {
0038 public:
0039
0040 MisalignedTrackerESProducer(const edm::ParameterSet& p);
0041
0042
0043 ~MisalignedTrackerESProducer() override;
0044
0045
0046 std::unique_ptr<TrackerGeometry> produce(const TrackerDigiGeometryRecord& iRecord);
0047
0048 private:
0049 edm::ESGetToken<GeometricDet, IdealGeometryRecord> geomDetToken_;
0050 edm::ESGetToken<PTrackerParameters, PTrackerParametersRcd> ptpToken_;
0051 edm::ESGetToken<PTrackerAdditionalParametersPerDet, PTrackerAdditionalParametersPerDetRcd> ptitpToken_;
0052 edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoToken_;
0053
0054 const bool theSaveToDB;
0055 const bool
0056 theSaveFakeScenario;
0057 const edm::ParameterSet theScenario;
0058 const std::string theAlignRecordName, theErrorRecordName;
0059 };
0060
0061
0062
0063
0064
0065
0066 MisalignedTrackerESProducer::MisalignedTrackerESProducer(const edm::ParameterSet& p)
0067 : theSaveToDB(p.getUntrackedParameter<bool>("saveToDbase")),
0068 theSaveFakeScenario(p.getUntrackedParameter<bool>("saveFakeScenario")),
0069 theScenario(p.getParameter<edm::ParameterSet>("scenario")),
0070 theAlignRecordName("TrackerAlignmentRcd"),
0071 theErrorRecordName("TrackerAlignmentErrorExtendedRcd") {
0072 auto cc = setWhatProduced(this);
0073 geomDetToken_ = cc.consumes();
0074 ptpToken_ = cc.consumes();
0075 ptitpToken_ = cc.consumes();
0076 topoToken_ = cc.consumes();
0077 }
0078
0079
0080 MisalignedTrackerESProducer::~MisalignedTrackerESProducer() {}
0081
0082
0083 std::unique_ptr<TrackerGeometry> MisalignedTrackerESProducer::produce(const TrackerDigiGeometryRecord& iRecord) {
0084
0085 const TrackerTopology* tTopo = &iRecord.get(topoToken_);
0086
0087 edm::LogInfo("MisalignedTracker") << "Producer called";
0088
0089
0090 const GeometricDet* gD = &iRecord.get(geomDetToken_);
0091 const PTrackerParameters& ptp = iRecord.get(ptpToken_);
0092 const PTrackerAdditionalParametersPerDet* ptitp = &iRecord.get(ptitpToken_);
0093
0094 TrackerGeomBuilderFromGeometricDet trackerBuilder;
0095 std::unique_ptr<TrackerGeometry> theTracker(trackerBuilder.build(gD, ptitp, ptp, tTopo));
0096
0097
0098 auto theAlignableTracker = std::make_unique<AlignableTracker>(&(*theTracker), tTopo);
0099
0100
0101 TrackerScenarioBuilder scenarioBuilder(&(*theAlignableTracker));
0102 scenarioBuilder.applyScenario(theScenario);
0103 Alignments alignments = *(theAlignableTracker->alignments());
0104 AlignmentErrorsExtended alignmentErrors = *(theAlignableTracker->alignmentErrors());
0105
0106
0107 GeometryAligner aligner;
0108 aligner.applyAlignments<TrackerGeometry>(&(*theTracker),
0109 &alignments,
0110 &alignmentErrors,
0111 AlignTransform());
0112
0113
0114 if (theSaveToDB) {
0115
0116 edm::Service<cond::service::PoolDBOutputService> poolDbService;
0117 if (!poolDbService.isAvailable())
0118 throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
0119 if (theSaveFakeScenario) {
0120 alignments.clear();
0121 alignmentErrors.clear();
0122 }
0123 poolDbService->writeOneIOV<Alignments>(alignments, poolDbService->currentTime(), theAlignRecordName);
0124 poolDbService->writeOneIOV<AlignmentErrorsExtended>(
0125 alignmentErrors, poolDbService->currentTime(), theErrorRecordName);
0126 }
0127
0128 edm::LogInfo("MisalignedTracker") << "Producer done";
0129 return theTracker;
0130 }
0131
0132 DEFINE_FWK_EVENTSETUP_MODULE(MisalignedTrackerESProducer);