Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:31:52

0001 // -*- C++ -*-
0002 //
0003 // Package:    AlignmentMonitorAsAnalyzer
0004 // Class:      AlignmentMonitorAsAnalyzer
0005 //
0006 /**\class AlignmentMonitorAsAnalyzer AlignmentMonitorAsAnalyzer.cc Alignment/CommonAlignmentMonitor/src/AlignmentMonitorAsAnalyzer.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Jim Pivarski
0015 //         Created:  Sat Apr 26 12:36:13 CDT 2008
0016 // $Id: AlignmentMonitorAsAnalyzer.cc,v 1.9 2012/07/13 09:18:40 yana Exp $
0017 //
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 #include "FWCore/Framework/interface/ESHandle.h"
0029 #include "FWCore/Framework/interface/ESTransientHandle.h"
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 
0032 #include "Alignment/CommonAlignmentMonitor/interface/AlignmentMonitorBase.h"
0033 #include "Alignment/CommonAlignmentMonitor/interface/AlignmentMonitorPluginFactory.h"
0034 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
0035 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentParameterStore.h"
0036 #include "Alignment/CommonAlignment/interface/Utilities.h"
0037 
0038 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0039 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h"
0040 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0041 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
0042 #include "Geometry/GEMGeometry/interface/GEMGeometry.h"
0043 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0044 #include "Geometry/CommonTopologies/interface/GeometryAligner.h"
0045 #include "CondFormats/GeometryObjects/interface/PTrackerParameters.h"
0046 #include "Geometry/Records/interface/PTrackerParametersRcd.h"
0047 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0048 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentRcd.h"
0049 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentErrorExtendedRcd.h"
0050 #include "CondFormats/AlignmentRecord/interface/DTAlignmentRcd.h"
0051 #include "CondFormats/AlignmentRecord/interface/DTAlignmentErrorExtendedRcd.h"
0052 #include "CondFormats/AlignmentRecord/interface/CSCAlignmentRcd.h"
0053 #include "CondFormats/AlignmentRecord/interface/CSCAlignmentErrorExtendedRcd.h"
0054 #include "CondFormats/AlignmentRecord/interface/GEMAlignmentRcd.h"
0055 #include "CondFormats/AlignmentRecord/interface/GEMAlignmentErrorExtendedRcd.h"
0056 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
0057 #include "CondFormats/Alignment/interface/DetectorGlobalPosition.h"
0058 
0059 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0060 
0061 //
0062 // class decleration
0063 //
0064 
0065 class AlignmentMonitorAsAnalyzer : public edm::one::EDAnalyzer<> {
0066 public:
0067   explicit AlignmentMonitorAsAnalyzer(const edm::ParameterSet&);
0068   ~AlignmentMonitorAsAnalyzer() override = default;
0069 
0070   typedef std::pair<const Trajectory*, const reco::Track*> ConstTrajTrackPair;
0071   typedef std::vector<ConstTrajTrackPair> ConstTrajTrackPairCollection;
0072 
0073 private:
0074   void beginJob() override;
0075   void analyze(const edm::Event&, const edm::EventSetup&) override;
0076   void endJob() override;
0077 
0078   // ----------member data ---------------------------
0079   edm::InputTag m_tjTag;
0080   edm::ParameterSet m_aliParamStoreCfg;
0081 
0082   std::unique_ptr<AlignableTracker> m_alignableTracker;
0083   std::unique_ptr<AlignableMuon> m_alignableMuon;
0084   std::unique_ptr<AlignmentParameterStore> m_alignmentParameterStore;
0085 
0086   std::vector<std::unique_ptr<AlignmentMonitorBase>> m_monitors;
0087 
0088   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> esTokenTTopo_;
0089   const edm::ESGetToken<GeometricDet, IdealGeometryRecord> esTokenGeomDet_;
0090   const edm::ESGetToken<PTrackerParameters, PTrackerParametersRcd> esTokenPTP_;
0091   const edm::ESGetToken<DTGeometry, MuonGeometryRecord> esTokenDT_;
0092   const edm::ESGetToken<CSCGeometry, MuonGeometryRecord> esTokenCSC_;
0093   const edm::ESGetToken<GEMGeometry, MuonGeometryRecord> esTokenGEM_;
0094   const edm::ESGetToken<Alignments, GlobalPositionRcd> esTokenGPR_;
0095   const edm::ESGetToken<Alignments, TrackerAlignmentRcd> esTokenTkAl_;
0096   const edm::ESGetToken<AlignmentErrorsExtended, TrackerAlignmentErrorExtendedRcd> esTokenTkAPE_;
0097   const edm::ESGetToken<Alignments, DTAlignmentRcd> esTokenDTAl_;
0098   const edm::ESGetToken<AlignmentErrorsExtended, DTAlignmentErrorExtendedRcd> esTokenDTAPE_;
0099   const edm::ESGetToken<Alignments, CSCAlignmentRcd> esTokenCSCAl_;
0100   const edm::ESGetToken<AlignmentErrorsExtended, CSCAlignmentErrorExtendedRcd> esTokenCSCAPE_;
0101   const edm::ESGetToken<Alignments, GEMAlignmentRcd> esTokenGEMAl_;
0102   const edm::ESGetToken<AlignmentErrorsExtended, GEMAlignmentErrorExtendedRcd> esTokenGEMAPE_;
0103   const edm::EDGetTokenT<TrajTrackAssociationCollection> trajTrackToken_;
0104   bool m_firstEvent;
0105 };
0106 
0107 //
0108 // constants, enums and typedefs
0109 //
0110 
0111 //
0112 // static data member definitions
0113 //
0114 
0115 //
0116 // constructors and destructor
0117 //
0118 AlignmentMonitorAsAnalyzer::AlignmentMonitorAsAnalyzer(const edm::ParameterSet& iConfig)
0119     : m_tjTag(iConfig.getParameter<edm::InputTag>("tjTkAssociationMapTag")),
0120       m_aliParamStoreCfg(iConfig.getParameter<edm::ParameterSet>("ParameterStore")),
0121       esTokenTTopo_(esConsumes()),
0122       esTokenGeomDet_(esConsumes()),
0123       esTokenPTP_(esConsumes()),
0124       esTokenDT_(esConsumes(edm::ESInputTag("", "idealForAlignmentMonitorAsAnalyzer"))),
0125       esTokenCSC_(esConsumes(edm::ESInputTag("", "idealForAlignmentMonitorAsAnalyzer"))),
0126       esTokenGEM_(esConsumes(edm::ESInputTag("", "idealForAlignmentMonitorAsAnalyzer"))),
0127       esTokenGPR_(esConsumes()),
0128       esTokenTkAl_(esConsumes()),
0129       esTokenTkAPE_(esConsumes()),
0130       esTokenDTAl_(esConsumes()),
0131       esTokenDTAPE_(esConsumes()),
0132       esTokenCSCAl_(esConsumes()),
0133       esTokenCSCAPE_(esConsumes()),
0134       esTokenGEMAl_(esConsumes()),
0135       esTokenGEMAPE_(esConsumes()),
0136       trajTrackToken_(consumes<TrajTrackAssociationCollection>(m_tjTag)) {
0137   edm::ConsumesCollector consumeCollector = consumesCollector();
0138   std::vector<std::string> monitors = iConfig.getUntrackedParameter<std::vector<std::string>>("monitors");
0139 
0140   for (auto const& mon : monitors) {
0141     m_monitors.emplace_back(AlignmentMonitorPluginFactory::get()->create(
0142         mon, iConfig.getUntrackedParameter<edm::ParameterSet>(mon), consumeCollector));
0143   }
0144 }
0145 
0146 //
0147 // member functions
0148 //
0149 
0150 // ------------ method called to for each event  ------------
0151 void AlignmentMonitorAsAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0152   //Retrieve tracker topology from geometry
0153   const TrackerTopology* const tTopo = &iSetup.getData(esTokenTTopo_);
0154 
0155   if (m_firstEvent) {
0156     GeometryAligner aligner;
0157 
0158     const GeometricDet* geom = &iSetup.getData(esTokenGeomDet_);
0159     const PTrackerParameters& ptp = iSetup.getData(esTokenPTP_);
0160     TrackerGeomBuilderFromGeometricDet trackerBuilder;
0161     std::shared_ptr<TrackerGeometry> theTracker(trackerBuilder.build(geom, ptp, tTopo));
0162 
0163     edm::ESHandle<DTGeometry> theMuonDT = iSetup.getHandle(esTokenDT_);
0164     edm::ESHandle<CSCGeometry> theMuonCSC = iSetup.getHandle(esTokenCSC_);
0165     edm::ESHandle<GEMGeometry> theMuonGEM = iSetup.getHandle(esTokenGEM_);
0166     edm::ESHandle<Alignments> globalPositionRcd = iSetup.getHandle(esTokenGPR_);
0167 
0168     const Alignments* alignments = &iSetup.getData(esTokenTkAl_);
0169     const AlignmentErrorsExtended* alignmentErrors = &iSetup.getData(esTokenTkAPE_);
0170     aligner.applyAlignments<TrackerGeometry>(&(*theTracker),
0171                                              alignments,
0172                                              alignmentErrors,
0173                                              align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)));
0174 
0175     edm::ESHandle<Alignments> dtAlignments = iSetup.getHandle(esTokenDTAl_);
0176     edm::ESHandle<AlignmentErrorsExtended> dtAlignmentErrorsExtended = iSetup.getHandle(esTokenDTAPE_);
0177     aligner.applyAlignments<DTGeometry>(&(*theMuonDT),
0178                                         &(*dtAlignments),
0179                                         &(*dtAlignmentErrorsExtended),
0180                                         align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)));
0181 
0182     edm::ESHandle<Alignments> cscAlignments = iSetup.getHandle(esTokenCSCAl_);
0183     edm::ESHandle<AlignmentErrorsExtended> cscAlignmentErrorsExtended = iSetup.getHandle(esTokenCSCAPE_);
0184     aligner.applyAlignments<CSCGeometry>(&(*theMuonCSC),
0185                                          &(*cscAlignments),
0186                                          &(*cscAlignmentErrorsExtended),
0187                                          align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)));
0188 
0189     edm::ESHandle<Alignments> gemAlignments = iSetup.getHandle(esTokenGEMAl_);
0190     edm::ESHandle<AlignmentErrorsExtended> gemAlignmentErrorsExtended = iSetup.getHandle(esTokenGEMAPE_);
0191     aligner.applyAlignments<GEMGeometry>(&(*theMuonGEM),
0192                                          &(*gemAlignments),
0193                                          &(*gemAlignmentErrorsExtended),
0194                                          align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)));
0195 
0196     // within an analyzer, modules can't expect to see any selected alignables!
0197     align::Alignables empty_alignables;
0198 
0199     m_alignableTracker = std::make_unique<AlignableTracker>(&(*theTracker), tTopo);
0200     m_alignableMuon = std::make_unique<AlignableMuon>(&(*theMuonDT), &(*theMuonCSC), &(*theMuonGEM));
0201     m_alignmentParameterStore = std::make_unique<AlignmentParameterStore>(empty_alignables, m_aliParamStoreCfg);
0202 
0203     for (auto const& monitor : m_monitors) {
0204       monitor->beginOfJob(m_alignableTracker.get(), m_alignableMuon.get(), m_alignmentParameterStore.get());
0205     }
0206     for (auto const& monitor : m_monitors) {
0207       monitor->startingNewLoop();
0208     }
0209 
0210     m_firstEvent = false;
0211   }
0212 
0213   // Retrieve trajectories and tracks from the event
0214   const edm::Handle<TrajTrackAssociationCollection>& trajTracksMap = iEvent.getHandle(trajTrackToken_);
0215 
0216   // Form pairs of trajectories and tracks
0217   ConstTrajTrackPairCollection trajTracks;
0218   for (const auto& iPair : *trajTracksMap) {
0219     trajTracks.push_back(ConstTrajTrackPair(&(*iPair.key), &(*iPair.val)));
0220   }
0221 
0222   // Run the monitors
0223   for (const auto& monitor : m_monitors) {
0224     monitor->duringLoop(iEvent, iSetup, trajTracks);
0225   }
0226 }
0227 
0228 // ------------ method called once each job just before starting event loop  ------------
0229 void AlignmentMonitorAsAnalyzer::beginJob() { m_firstEvent = true; }
0230 
0231 // ------------ method called once each job just after ending the event loop  ------------
0232 void AlignmentMonitorAsAnalyzer::endJob() {
0233   for (auto const& monitor : m_monitors) {
0234     monitor->endOfLoop();
0235   }
0236   for (auto const& monitor : m_monitors) {
0237     monitor->endOfJob();
0238   }
0239 }
0240 
0241 //define this as a plug-in
0242 DEFINE_FWK_MODULE(AlignmentMonitorAsAnalyzer);