Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-08-13 05:00:12

0001 ///
0002 /// An ESProducer that fills the MuonDigiGeometryRcd with a misaligned Muon
0003 ///
0004 /// This should replace the standard DTGeometry and CSCGeometry producers
0005 /// when producing Misalignment scenarios.
0006 ///
0007 /// \file
0008 /// $Date: 2009/03/26 09:56:51 $
0009 /// $Revision: 1.11 $
0010 /// \author Andre Sznajder - UERJ(Brazil)
0011 ///
0012 
0013 // Framework
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 // Conditions database
0022 #include "FWCore/ServiceRegistry/interface/Service.h"
0023 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0024 
0025 // Alignment
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   /// Constructor
0042   MuonMisalignedProducer(const edm::ParameterSet&);
0043 
0044   /// Destructor
0045   ~MuonMisalignedProducer() override;
0046 
0047   /// Produce the misaligned Muon geometry and store iti
0048   void analyze(const edm::Event&, const edm::EventSetup&) override;
0049   /// Save alignemnts and error to database
0050   void saveToDB();
0051 
0052 private:
0053   const bool theSaveToDB;               /// whether or not writing to DB
0054   const edm::ParameterSet theScenario;  /// misalignment scenario
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   // Create the Muon geometry from ideal geometry
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   // Create the alignable hierarchy
0098   AlignableMuon* theAlignableMuon = new AlignableMuon(&(*theDTGeometry), &(*theCSCGeometry), &(*theGEMGeometry));
0099 
0100   // Create misalignment scenario
0101   MuonScenarioBuilder scenarioBuilder(theAlignableMuon);
0102   scenarioBuilder.applyScenario(theScenario);
0103 
0104   // Get alignments and errors
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   // Misalign the EventSetup geometry
0113   /* GeometryAligner aligner;
0114   aligner.applyAlignments<DTGeometry>(&(*theDTGeometry), dt_Alignments, dt_AlignmentErrorsExtended, AlignTransform());
0115   aligner.applyAlignments<CSCGeometry>(
0116       &(*theCSCGeometry), csc_Alignments, csc_AlignmentErrorsExtended, AlignTransform());
0117   aligner.applyAlignments<GEMGeometry>(
0118       &(*theGEMGeometry), gem_Alignments, gem_AlignmentErrorsExtended, AlignTransform());
0119   */
0120   // Write alignments to DB
0121   if (theSaveToDB)
0122     this->saveToDB();
0123 
0124   edm::LogInfo("MisalignedMuon") << "Producer done";
0125 }
0126 
0127 //__________________________________________________________________________________________________
0128 void MuonMisalignedProducer::saveToDB(void) {
0129   // Call service
0130   edm::Service<cond::service::PoolDBOutputService> poolDbService;
0131   if (!poolDbService.isAvailable())  // Die if not available
0132     throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
0133 
0134   // Store DT alignments and errors
0135   poolDbService->writeOneIOV<Alignments>(dt_Alignments, poolDbService->beginOfTime(), theDTAlignRecordName);
0136   poolDbService->writeOneIOV<AlignmentErrorsExtended>(
0137       dt_AlignmentErrorsExtended, poolDbService->beginOfTime(), theDTErrorRecordName);
0138 
0139   // Store CSC alignments and errors
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);