File indexing completed on 2023-01-21 00:19:03
0001 #ifndef Alignment_CommonAlignmentProducer_AlignmentProducerBase_h
0002 #define Alignment_CommonAlignmentProducer_AlignmentProducerBase_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 #include <memory>
0026
0027 #include "Alignment/CommonAlignment/interface/Utilities.h"
0028 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentAlgorithmBase.h"
0029 #include "Alignment/CommonAlignmentMonitor/interface/AlignmentMonitorBase.h"
0030
0031 #include "CondFormats/Alignment/interface/Alignments.h"
0032 #include "CondFormats/AlignmentRecord/interface/CSCAlignmentRcd.h"
0033 #include "CondFormats/AlignmentRecord/interface/CSCAlignmentErrorExtendedRcd.h"
0034 #include "CondFormats/AlignmentRecord/interface/CSCSurveyRcd.h"
0035 #include "CondFormats/AlignmentRecord/interface/CSCSurveyErrorExtendedRcd.h"
0036 #include "CondFormats/AlignmentRecord/interface/DTAlignmentRcd.h"
0037 #include "CondFormats/AlignmentRecord/interface/DTAlignmentErrorExtendedRcd.h"
0038 #include "CondFormats/AlignmentRecord/interface/DTSurveyRcd.h"
0039 #include "CondFormats/AlignmentRecord/interface/DTSurveyErrorExtendedRcd.h"
0040 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
0041 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentRcd.h"
0042 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentErrorExtendedRcd.h"
0043 #include "CondFormats/AlignmentRecord/interface/TrackerSurfaceDeformationRcd.h"
0044 #include "CondFormats/AlignmentRecord/interface/TrackerSurveyRcd.h"
0045 #include "CondFormats/AlignmentRecord/interface/TrackerSurveyErrorExtendedRcd.h"
0046 #include "CondFormats/GeometryObjects/interface/PTrackerParameters.h"
0047 #include "CondFormats/Common/interface/Time.h"
0048
0049 #include "FWCore/Framework/interface/ESHandle.h"
0050 #include "FWCore/Framework/interface/ESWatcher.h"
0051 #include "FWCore/Framework/interface/Frameworkfwd.h"
0052 #include "FWCore/Framework/interface/ConsumesCollector.h"
0053
0054 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0055 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
0056 #include "Geometry/GEMGeometry/interface/GEMGeometry.h"
0057 #include "Geometry/CommonTopologies/interface/GeometryAligner.h"
0058 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0059 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0060 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0061 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0062
0063 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
0064
0065 class AlignTransform;
0066 class Alignments;
0067 class AlignmentErrorsExtended;
0068 class AlignmentSurfaceDeformations;
0069 struct SurveyErrors;
0070 class TrackerTopology;
0071 class TrackerDigiGeometryRecord;
0072
0073 class AlignmentProducerBase {
0074 protected:
0075 AlignmentProducerBase(const edm::ParameterSet&, edm::ConsumesCollector);
0076
0077
0078 virtual ~AlignmentProducerBase() noexcept(false);
0079
0080
0081
0082 void startProcessing();
0083
0084
0085 void terminateProcessing(const edm::EventSetup* = nullptr);
0086
0087
0088 bool processEvent(const edm::Event&, const edm::EventSetup&);
0089
0090
0091 void beginRunImpl(const edm::Run&, const edm::EventSetup&);
0092
0093
0094 void endRunImpl(const edm::Run&, const edm::EventSetup&);
0095
0096
0097 void beginLuminosityBlockImpl(const edm::LuminosityBlock&, const edm::EventSetup&);
0098
0099
0100 void endLuminosityBlockImpl(const edm::LuminosityBlock&, const edm::EventSetup&);
0101
0102 int nEvent() const { return nevent_; }
0103
0104
0105
0106 void initAlignmentAlgorithm(const edm::EventSetup&, bool update = false);
0107
0108
0109
0110 bool finish();
0111
0112 virtual bool getTrajTrackAssociationCollection(const edm::Event&, edm::Handle<TrajTrackAssociationCollection>&) = 0;
0113 virtual bool getBeamSpot(const edm::Event&, edm::Handle<reco::BeamSpot>&) = 0;
0114 virtual bool getTkFittedLasBeamCollection(const edm::Run&, edm::Handle<TkFittedLasBeamCollection>&) = 0;
0115 virtual bool getTsosVectorCollection(const edm::Run&, edm::Handle<TsosVectorCollection>&) = 0;
0116 virtual bool getAliClusterValueMap(const edm::Event&, edm::Handle<AliClusterValueMap>&) = 0;
0117
0118 std::shared_ptr<TrackerGeometry> trackerGeometry_;
0119 edm::ESHandle<DTGeometry> muonDTGeometry_;
0120 edm::ESHandle<CSCGeometry> muonCSCGeometry_;
0121 edm::ESHandle<GEMGeometry> muonGEMGeometry_;
0122 const bool doTracker_, doMuon_, useExtras_;
0123
0124
0125 const edm::InputTag tjTkAssociationMapTag_;
0126
0127
0128 const edm::InputTag beamSpotTag_;
0129
0130
0131 const edm::InputTag tkLasBeamTag_;
0132
0133
0134 const edm::InputTag clusterValueMapTag_;
0135
0136 private:
0137
0138 void createAlignmentAlgorithm(edm::ConsumesCollector&);
0139
0140
0141 void createMonitors(edm::ConsumesCollector&);
0142
0143
0144 void createCalibrations(edm::ConsumesCollector&);
0145
0146
0147 bool setupChanged(const edm::EventSetup&);
0148
0149
0150 void initBeamSpot(const edm::Event&);
0151
0152
0153 void createGeometries(const edm::EventSetup&, const TrackerTopology*);
0154
0155
0156
0157 void applyAlignmentsToDB(const edm::EventSetup&);
0158
0159
0160
0161 void createAlignables(const TrackerTopology*, bool update = false);
0162
0163
0164 void buildParameterStore();
0165
0166
0167 void applyMisalignment();
0168
0169
0170 void simpleMisalignment(const align::Alignables&, const std::string&, float, float, bool);
0171
0172
0173
0174 void applyAlignmentsToGeometry();
0175
0176
0177
0178 template <class G, class Rcd, class ErrRcd>
0179 void applyDB(const G*,
0180 const edm::EventSetup&,
0181 const edm::ESGetToken<Alignments, Rcd>&,
0182 const edm::ESGetToken<AlignmentErrorsExtended, ErrRcd>&,
0183 const AlignTransform&) const;
0184
0185
0186 template <class G, class DeformationRcd>
0187 void applyDB(const G*,
0188 const edm::EventSetup&,
0189 const edm::ESGetToken<AlignmentSurfaceDeformations, DeformationRcd>&) const;
0190
0191
0192 void readInSurveyRcds(const edm::EventSetup&);
0193
0194
0195 void addSurveyInfo(Alignable*);
0196
0197
0198 void storeAlignmentsToDB();
0199
0200
0201
0202 void writeForRunRange(cond::Time_t);
0203
0204
0205
0206
0207 void writeDB(Alignments*,
0208 const std::string&,
0209 AlignmentErrorsExtended*,
0210 const std::string&,
0211 const AlignTransform*,
0212 cond::Time_t) const;
0213
0214
0215
0216 void writeDB(const AlignmentSurfaceDeformations&, const std::string&, cond::Time_t) const;
0217
0218
0219
0220
0221
0222
0223 std::unique_ptr<AlignmentAlgorithmBase> alignmentAlgo_;
0224 CalibrationsOwner calibrations_;
0225 AlignmentMonitors monitors_;
0226
0227 std::unique_ptr<AlignmentParameterStore> alignmentParameterStore_;
0228 std::unique_ptr<AlignableTracker> alignableTracker_;
0229 std::unique_ptr<AlignableMuon> alignableMuon_;
0230 std::unique_ptr<AlignableExtras> alignableExtras_;
0231
0232 edm::Handle<reco::BeamSpot> beamSpot_;
0233
0234 std::unique_ptr<const Alignments> globalPositions_;
0235
0236 const align::RunRanges uniqueRunRanges_;
0237 int nevent_{0};
0238 bool runAtPCL_{false};
0239
0240
0241
0242 edm::ParameterSet config_;
0243
0244 const int stNFixAlignables_;
0245 const double stRandomShift_, stRandomRotation_;
0246 const bool applyDbAlignment_, checkDbAlignmentValidity_;
0247 const bool doMisalignmentScenario_;
0248 const bool saveToDB_, saveApeToDB_, saveDeformationsToDB_;
0249 const bool useSurvey_;
0250 const bool enableAlignableUpdates_;
0251 const std::string tkAliRcdName_;
0252
0253
0254 const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> ttopoToken_;
0255 const edm::ESGetToken<GeometricDet, IdealGeometryRecord> geomDetToken_;
0256 const edm::ESGetToken<PTrackerParameters, PTrackerParametersRcd> ptpToken_;
0257 const edm::ESGetToken<DTGeometry, MuonGeometryRecord> dtGeomToken_;
0258 const edm::ESGetToken<CSCGeometry, MuonGeometryRecord> cscGeomToken_;
0259 const edm::ESGetToken<GEMGeometry, MuonGeometryRecord> gemGeomToken_;
0260
0261 const edm::ESGetToken<Alignments, TrackerAlignmentRcd> tkAliToken_;
0262 const edm::ESGetToken<Alignments, DTAlignmentRcd> dtAliToken_;
0263 const edm::ESGetToken<Alignments, CSCAlignmentRcd> cscAliToken_;
0264 const edm::ESGetToken<Alignments, GEMAlignmentRcd> gemAliToken_;
0265 const edm::ESGetToken<AlignmentErrorsExtended, TrackerAlignmentErrorExtendedRcd> tkAliErrToken_;
0266 const edm::ESGetToken<AlignmentErrorsExtended, DTAlignmentErrorExtendedRcd> dtAliErrToken_;
0267 const edm::ESGetToken<AlignmentErrorsExtended, CSCAlignmentErrorExtendedRcd> cscAliErrToken_;
0268 const edm::ESGetToken<AlignmentErrorsExtended, GEMAlignmentErrorExtendedRcd> gemAliErrToken_;
0269 const edm::ESGetToken<AlignmentSurfaceDeformations, TrackerSurfaceDeformationRcd> tkSurfDefToken_;
0270
0271 const edm::ESGetToken<Alignments, GlobalPositionRcd> gprToken_;
0272 const edm::ESGetToken<Alignments, TrackerSurveyRcd> tkSurveyToken_;
0273 const edm::ESGetToken<SurveyErrors, TrackerSurveyErrorExtendedRcd> tkSurvErrorToken_;
0274 const edm::ESGetToken<Alignments, DTSurveyRcd> dtSurveyToken_;
0275 const edm::ESGetToken<SurveyErrors, DTSurveyErrorExtendedRcd> dtSurvErrorToken_;
0276 const edm::ESGetToken<Alignments, CSCSurveyRcd> cscSurveyToken_;
0277 const edm::ESGetToken<SurveyErrors, CSCSurveyErrorExtendedRcd> cscSurvErrorToken_;
0278
0279
0280
0281 edm::ESWatcher<IdealGeometryRecord> watchIdealGeometryRcd_;
0282 edm::ESWatcher<GlobalPositionRcd> watchGlobalPositionRcd_;
0283
0284 edm::ESWatcher<TrackerAlignmentRcd> watchTrackerAlRcd_;
0285 edm::ESWatcher<TrackerAlignmentErrorExtendedRcd> watchTrackerAlErrorExtRcd_;
0286 edm::ESWatcher<TrackerSurfaceDeformationRcd> watchTrackerSurDeRcd_;
0287
0288 edm::ESWatcher<DTAlignmentRcd> watchDTAlRcd_;
0289 edm::ESWatcher<DTAlignmentErrorExtendedRcd> watchDTAlErrExtRcd_;
0290 edm::ESWatcher<CSCAlignmentRcd> watchCSCAlRcd_;
0291 edm::ESWatcher<CSCAlignmentErrorExtendedRcd> watchCSCAlErrExtRcd_;
0292
0293 edm::ESWatcher<TrackerSurveyRcd> watchTkSurveyRcd_;
0294 edm::ESWatcher<TrackerSurveyErrorExtendedRcd> watchTkSurveyErrExtRcd_;
0295 edm::ESWatcher<DTSurveyRcd> watchDTSurveyRcd_;
0296 edm::ESWatcher<DTSurveyErrorExtendedRcd> watchDTSurveyErrExtRcd_;
0297 edm::ESWatcher<CSCSurveyRcd> watchCSCSurveyRcd_;
0298 edm::ESWatcher<CSCSurveyErrorExtendedRcd> watchCSCSurveyErrExtRcd_;
0299
0300
0301
0302 size_t surveyIndex_{0};
0303 const Alignments* surveyValues_{nullptr};
0304 const SurveyErrors* surveyErrors_{nullptr};
0305
0306
0307 bool isAlgoInitialized_{false};
0308 bool isDuringLoop_{false};
0309
0310
0311 cond::Time_t firstRun_{cond::timeTypeSpecs[cond::runnumber].endValue};
0312 };
0313
0314 template <class G, class Rcd, class ErrRcd>
0315 void AlignmentProducerBase::applyDB(const G* geometry,
0316 const edm::EventSetup& iSetup,
0317 const edm::ESGetToken<Alignments, Rcd>& aliToken,
0318 const edm::ESGetToken<AlignmentErrorsExtended, ErrRcd>& errToken,
0319 const AlignTransform& globalCoordinates) const {
0320
0321
0322
0323
0324
0325 const Rcd& record = iSetup.get<Rcd>();
0326 if (checkDbAlignmentValidity_) {
0327 const edm::ValidityInterval& validity = record.validityInterval();
0328 const edm::IOVSyncValue first = validity.first();
0329 const edm::IOVSyncValue last = validity.last();
0330 if (first != edm::IOVSyncValue::beginOfTime() || last != edm::IOVSyncValue::endOfTime()) {
0331 throw cms::Exception("DatabaseError")
0332 << "@SUB=AlignmentProducerBase::applyDB"
0333 << "\nTrying to apply " << record.key().name() << " with multiple IOVs in tag.\n"
0334 << "Validity range is " << first.eventID().run() << " - " << last.eventID().run();
0335 }
0336 }
0337
0338 const Alignments* alignments = &record.get(aliToken);
0339 const AlignmentErrorsExtended* alignmentErrors = &iSetup.getData(errToken);
0340
0341 GeometryAligner aligner;
0342 aligner.applyAlignments<G>(geometry, alignments, alignmentErrors, globalCoordinates);
0343 }
0344
0345 template <class G, class DeformationRcd>
0346 void AlignmentProducerBase::applyDB(
0347 const G* geometry,
0348 const edm::EventSetup& iSetup,
0349 const edm::ESGetToken<AlignmentSurfaceDeformations, DeformationRcd>& surfDefToken) const {
0350
0351
0352
0353 const DeformationRcd& record = iSetup.get<DeformationRcd>();
0354 if (checkDbAlignmentValidity_) {
0355 const edm::ValidityInterval& validity = record.validityInterval();
0356 const edm::IOVSyncValue first = validity.first();
0357 const edm::IOVSyncValue last = validity.last();
0358 if (first != edm::IOVSyncValue::beginOfTime() || last != edm::IOVSyncValue::endOfTime()) {
0359 throw cms::Exception("DatabaseError")
0360 << "@SUB=AlignmentProducerBase::applyDB"
0361 << "\nTrying to apply " << record.key().name() << " with multiple IOVs in tag.\n"
0362 << "Validity range is " << first.eventID().run() << " - " << last.eventID().run();
0363 }
0364 }
0365 const AlignmentSurfaceDeformations* surfaceDeformations = &record.get(surfDefToken);
0366
0367 GeometryAligner aligner;
0368 aligner.attachSurfaceDeformations<G>(geometry, surfaceDeformations);
0369 }
0370
0371 #endif