File indexing completed on 2024-08-13 05:00:12
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0015 #include "FWCore/Framework/interface/MakerMacros.h"
0016 #include "FWCore/Utilities/interface/Exception.h"
0017 #include "FWCore/Framework/interface/ESHandle.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0020
0021
0022 #include "FWCore/ServiceRegistry/interface/Service.h"
0023 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0024
0025
0026 #include "Alignment/MuonAlignment/interface/AlignableMuon.h"
0027 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
0028 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0029 #include "Geometry/GEMGeometry/interface/GEMGeometry.h"
0030 #include "Alignment/MuonAlignment/interface/MuonScenarioBuilder.h"
0031 #include "Alignment/CommonAlignment/interface/Alignable.h"
0032 #include "Geometry/GeometryAligner/interface/GeometryAligner.h"
0033 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0034
0035 #include <memory>
0036
0037 #include <iostream>
0038
0039 class MuonMisalignedProducer : public edm::one::EDAnalyzer<> {
0040 public:
0041
0042 MuonMisalignedProducer(const edm::ParameterSet&);
0043
0044
0045 ~MuonMisalignedProducer() override;
0046
0047
0048 void analyze(const edm::Event&, const edm::EventSetup&) override;
0049
0050 void saveToDB();
0051
0052 private:
0053 const bool theSaveToDB;
0054 const edm::ParameterSet theScenario;
0055
0056 std::string theDTAlignRecordName, theDTErrorRecordName;
0057 std::string theCSCAlignRecordName, theCSCErrorRecordName;
0058 std::string theGEMAlignRecordName, theGEMErrorRecordName;
0059
0060 edm::ESGetToken<DTGeometry, MuonGeometryRecord> esTokenDT_;
0061 edm::ESGetToken<CSCGeometry, MuonGeometryRecord> esTokenCSC_;
0062 edm::ESGetToken<GEMGeometry, MuonGeometryRecord> esTokenGEM_;
0063
0064 Alignments dt_Alignments;
0065 AlignmentErrorsExtended dt_AlignmentErrorsExtended;
0066 Alignments csc_Alignments;
0067 AlignmentErrorsExtended csc_AlignmentErrorsExtended;
0068 Alignments gem_Alignments;
0069 AlignmentErrorsExtended gem_AlignmentErrorsExtended;
0070 };
0071
0072
0073 MuonMisalignedProducer::MuonMisalignedProducer(const edm::ParameterSet& p)
0074 : theSaveToDB(p.getUntrackedParameter<bool>("saveToDbase")),
0075 theScenario(p.getParameter<edm::ParameterSet>("scenario")),
0076 theDTAlignRecordName("DTAlignmentRcd"),
0077 theDTErrorRecordName("DTAlignmentErrorExtendedRcd"),
0078 theCSCAlignRecordName("CSCAlignmentRcd"),
0079 theCSCErrorRecordName("CSCAlignmentErrorExtendedRcd"),
0080 theGEMAlignRecordName("GEMAlignmentRcd"),
0081 theGEMErrorRecordName("GEMAlignmentErrorExtendedRcd"),
0082 esTokenDT_(esConsumes(edm::ESInputTag("", "idealForMuonMisalignedProducer"))),
0083 esTokenCSC_(esConsumes(edm::ESInputTag("", "idealForMuonMisalignedProducer"))),
0084 esTokenGEM_(esConsumes(edm::ESInputTag("", "idealForMuonMisalignedProducer"))) {}
0085
0086
0087 MuonMisalignedProducer::~MuonMisalignedProducer() = default;
0088
0089
0090 void MuonMisalignedProducer::analyze(const edm::Event& event, const edm::EventSetup& eventSetup) {
0091 edm::LogInfo("MisalignedMuon") << "Producer called";
0092
0093 edm::ESHandle<DTGeometry> theDTGeometry = eventSetup.getHandle(esTokenDT_);
0094 edm::ESHandle<CSCGeometry> theCSCGeometry = eventSetup.getHandle(esTokenCSC_);
0095 edm::ESHandle<GEMGeometry> theGEMGeometry = eventSetup.getHandle(esTokenGEM_);
0096
0097
0098 AlignableMuon* theAlignableMuon = new AlignableMuon(&(*theDTGeometry), &(*theCSCGeometry), &(*theGEMGeometry));
0099
0100
0101 MuonScenarioBuilder scenarioBuilder(theAlignableMuon);
0102 scenarioBuilder.applyScenario(theScenario);
0103
0104
0105 dt_Alignments = *(theAlignableMuon->dtAlignments());
0106 dt_AlignmentErrorsExtended = *(theAlignableMuon->dtAlignmentErrorsExtended());
0107 csc_Alignments = *(theAlignableMuon->cscAlignments());
0108 csc_AlignmentErrorsExtended = *(theAlignableMuon->cscAlignmentErrorsExtended());
0109 gem_Alignments = *(theAlignableMuon->gemAlignments());
0110 gem_AlignmentErrorsExtended = *(theAlignableMuon->gemAlignmentErrorsExtended());
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121 if (theSaveToDB)
0122 this->saveToDB();
0123
0124 edm::LogInfo("MisalignedMuon") << "Producer done";
0125 }
0126
0127
0128 void MuonMisalignedProducer::saveToDB(void) {
0129
0130 edm::Service<cond::service::PoolDBOutputService> poolDbService;
0131 if (!poolDbService.isAvailable())
0132 throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
0133
0134
0135 poolDbService->writeOneIOV<Alignments>(dt_Alignments, poolDbService->beginOfTime(), theDTAlignRecordName);
0136 poolDbService->writeOneIOV<AlignmentErrorsExtended>(
0137 dt_AlignmentErrorsExtended, poolDbService->beginOfTime(), theDTErrorRecordName);
0138
0139
0140 poolDbService->writeOneIOV<Alignments>(csc_Alignments, poolDbService->beginOfTime(), theCSCAlignRecordName);
0141 poolDbService->writeOneIOV<AlignmentErrorsExtended>(
0142 csc_AlignmentErrorsExtended, poolDbService->beginOfTime(), theCSCErrorRecordName);
0143 poolDbService->writeOneIOV<Alignments>(gem_Alignments, poolDbService->beginOfTime(), theGEMAlignRecordName);
0144 poolDbService->writeOneIOV<AlignmentErrorsExtended>(
0145 gem_AlignmentErrorsExtended, poolDbService->beginOfTime(), theGEMErrorRecordName);
0146 }
0147
0148 DEFINE_FWK_MODULE(MuonMisalignedProducer);