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