Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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/GeometryAligner/interface/GeometryAligner.h"
0045 #include "CondFormats/GeometryObjects/interface/PTrackerParameters.h"
0046 #include "Geometry/Records/interface/PTrackerParametersRcd.h"
0047 #include "Geometry/Records/interface/PTrackerAdditionalParametersPerDetRcd.h"
0048 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0049 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentRcd.h"
0050 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentErrorExtendedRcd.h"
0051 #include "CondFormats/AlignmentRecord/interface/DTAlignmentRcd.h"
0052 #include "CondFormats/AlignmentRecord/interface/DTAlignmentErrorExtendedRcd.h"
0053 #include "CondFormats/AlignmentRecord/interface/CSCAlignmentRcd.h"
0054 #include "CondFormats/AlignmentRecord/interface/CSCAlignmentErrorExtendedRcd.h"
0055 #include "CondFormats/AlignmentRecord/interface/GEMAlignmentRcd.h"
0056 #include "CondFormats/AlignmentRecord/interface/GEMAlignmentErrorExtendedRcd.h"
0057 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
0058 #include "CondFormats/Alignment/interface/DetectorGlobalPosition.h"
0059 
0060 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0061 
0062 //
0063 // class decleration
0064 //
0065 
0066 class AlignmentMonitorAsAnalyzer : public edm::one::EDAnalyzer<> {
0067 public:
0068   explicit AlignmentMonitorAsAnalyzer(const edm::ParameterSet&);
0069   ~AlignmentMonitorAsAnalyzer() override = default;
0070 
0071   typedef std::pair<const Trajectory*, const reco::Track*> ConstTrajTrackPair;
0072   typedef std::vector<ConstTrajTrackPair> ConstTrajTrackPairCollection;
0073 
0074 private:
0075   void beginJob() override;
0076   void analyze(const edm::Event&, const edm::EventSetup&) override;
0077   void endJob() override;
0078 
0079   // ----------member data ---------------------------
0080   edm::InputTag m_tjTag;
0081   edm::ParameterSet m_aliParamStoreCfg;
0082 
0083   std::unique_ptr<AlignableTracker> m_alignableTracker;
0084   std::unique_ptr<AlignableMuon> m_alignableMuon;
0085   std::unique_ptr<AlignmentParameterStore> m_alignmentParameterStore;
0086 
0087   std::vector<std::unique_ptr<AlignmentMonitorBase>> m_monitors;
0088 
0089   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> esTokenTTopo_;
0090   const edm::ESGetToken<GeometricDet, IdealGeometryRecord> esTokenGeomDet_;
0091   const edm::ESGetToken<PTrackerParameters, PTrackerParametersRcd> esTokenPTP_;
0092   const edm::ESGetToken<PTrackerAdditionalParametersPerDet, PTrackerAdditionalParametersPerDetRcd> esTokenPtitp_;
0093   const edm::ESGetToken<DTGeometry, MuonGeometryRecord> esTokenDT_;
0094   const edm::ESGetToken<CSCGeometry, MuonGeometryRecord> esTokenCSC_;
0095   const edm::ESGetToken<GEMGeometry, MuonGeometryRecord> esTokenGEM_;
0096   const edm::ESGetToken<Alignments, GlobalPositionRcd> esTokenGPR_;
0097   const edm::ESGetToken<Alignments, TrackerAlignmentRcd> esTokenTkAl_;
0098   const edm::ESGetToken<AlignmentErrorsExtended, TrackerAlignmentErrorExtendedRcd> esTokenTkAPE_;
0099   const edm::ESGetToken<Alignments, DTAlignmentRcd> esTokenDTAl_;
0100   const edm::ESGetToken<AlignmentErrorsExtended, DTAlignmentErrorExtendedRcd> esTokenDTAPE_;
0101   const edm::ESGetToken<Alignments, CSCAlignmentRcd> esTokenCSCAl_;
0102   const edm::ESGetToken<AlignmentErrorsExtended, CSCAlignmentErrorExtendedRcd> esTokenCSCAPE_;
0103   const edm::ESGetToken<Alignments, GEMAlignmentRcd> esTokenGEMAl_;
0104   const edm::ESGetToken<AlignmentErrorsExtended, GEMAlignmentErrorExtendedRcd> esTokenGEMAPE_;
0105   const edm::EDGetTokenT<TrajTrackAssociationCollection> trajTrackToken_;
0106   bool m_firstEvent;
0107 };
0108 
0109 //
0110 // constants, enums and typedefs
0111 //
0112 
0113 //
0114 // static data member definitions
0115 //
0116 
0117 //
0118 // constructors and destructor
0119 //
0120 AlignmentMonitorAsAnalyzer::AlignmentMonitorAsAnalyzer(const edm::ParameterSet& iConfig)
0121     : m_tjTag(iConfig.getParameter<edm::InputTag>("tjTkAssociationMapTag")),
0122       m_aliParamStoreCfg(iConfig.getParameter<edm::ParameterSet>("ParameterStore")),
0123       esTokenTTopo_(esConsumes()),
0124       esTokenGeomDet_(esConsumes()),
0125       esTokenPTP_(esConsumes()),
0126       esTokenPtitp_(esConsumes()),
0127       esTokenDT_(esConsumes(edm::ESInputTag("", "idealForAlignmentMonitorAsAnalyzer"))),
0128       esTokenCSC_(esConsumes(edm::ESInputTag("", "idealForAlignmentMonitorAsAnalyzer"))),
0129       esTokenGEM_(esConsumes(edm::ESInputTag("", "idealForAlignmentMonitorAsAnalyzer"))),
0130       esTokenGPR_(esConsumes()),
0131       esTokenTkAl_(esConsumes()),
0132       esTokenTkAPE_(esConsumes()),
0133       esTokenDTAl_(esConsumes()),
0134       esTokenDTAPE_(esConsumes()),
0135       esTokenCSCAl_(esConsumes()),
0136       esTokenCSCAPE_(esConsumes()),
0137       esTokenGEMAl_(esConsumes()),
0138       esTokenGEMAPE_(esConsumes()),
0139       trajTrackToken_(consumes<TrajTrackAssociationCollection>(m_tjTag)) {
0140   edm::ConsumesCollector consumeCollector = consumesCollector();
0141   std::vector<std::string> monitors = iConfig.getUntrackedParameter<std::vector<std::string>>("monitors");
0142 
0143   for (auto const& mon : monitors) {
0144     m_monitors.emplace_back(AlignmentMonitorPluginFactory::get()->create(
0145         mon, iConfig.getUntrackedParameter<edm::ParameterSet>(mon), consumeCollector));
0146   }
0147 }
0148 
0149 //
0150 // member functions
0151 //
0152 
0153 // ------------ method called to for each event  ------------
0154 void AlignmentMonitorAsAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0155   //Retrieve tracker topology from geometry
0156   const TrackerTopology* const tTopo = &iSetup.getData(esTokenTTopo_);
0157 
0158   if (m_firstEvent) {
0159     GeometryAligner aligner;
0160 
0161     const GeometricDet* geom = &iSetup.getData(esTokenGeomDet_);
0162     const PTrackerParameters& ptp = iSetup.getData(esTokenPTP_);
0163     const PTrackerAdditionalParametersPerDet* ptitp = &iSetup.getData(esTokenPtitp_);
0164     TrackerGeomBuilderFromGeometricDet trackerBuilder;
0165     std::shared_ptr<TrackerGeometry> theTracker(trackerBuilder.build(geom, ptitp, ptp, tTopo));
0166 
0167     edm::ESHandle<DTGeometry> theMuonDT = iSetup.getHandle(esTokenDT_);
0168     edm::ESHandle<CSCGeometry> theMuonCSC = iSetup.getHandle(esTokenCSC_);
0169     edm::ESHandle<GEMGeometry> theMuonGEM = iSetup.getHandle(esTokenGEM_);
0170     edm::ESHandle<Alignments> globalPositionRcd = iSetup.getHandle(esTokenGPR_);
0171 
0172     const Alignments* alignments = &iSetup.getData(esTokenTkAl_);
0173     const AlignmentErrorsExtended* alignmentErrors = &iSetup.getData(esTokenTkAPE_);
0174     aligner.applyAlignments<TrackerGeometry>(&(*theTracker),
0175                                              alignments,
0176                                              alignmentErrors,
0177                                              align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)));
0178 
0179     edm::ESHandle<Alignments> dtAlignments = iSetup.getHandle(esTokenDTAl_);
0180     edm::ESHandle<AlignmentErrorsExtended> dtAlignmentErrorsExtended = iSetup.getHandle(esTokenDTAPE_);
0181     aligner.applyAlignments<DTGeometry>(&(*theMuonDT),
0182                                         &(*dtAlignments),
0183                                         &(*dtAlignmentErrorsExtended),
0184                                         align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)));
0185 
0186     edm::ESHandle<Alignments> cscAlignments = iSetup.getHandle(esTokenCSCAl_);
0187     edm::ESHandle<AlignmentErrorsExtended> cscAlignmentErrorsExtended = iSetup.getHandle(esTokenCSCAPE_);
0188     aligner.applyAlignments<CSCGeometry>(&(*theMuonCSC),
0189                                          &(*cscAlignments),
0190                                          &(*cscAlignmentErrorsExtended),
0191                                          align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)));
0192 
0193     edm::ESHandle<Alignments> gemAlignments = iSetup.getHandle(esTokenGEMAl_);
0194     edm::ESHandle<AlignmentErrorsExtended> gemAlignmentErrorsExtended = iSetup.getHandle(esTokenGEMAPE_);
0195     aligner.applyAlignments<GEMGeometry>(&(*theMuonGEM),
0196                                          &(*gemAlignments),
0197                                          &(*gemAlignmentErrorsExtended),
0198                                          align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)));
0199 
0200     // within an analyzer, modules can't expect to see any selected alignables!
0201     align::Alignables empty_alignables;
0202 
0203     m_alignableTracker = std::make_unique<AlignableTracker>(&(*theTracker), tTopo);
0204     m_alignableMuon = std::make_unique<AlignableMuon>(&(*theMuonDT), &(*theMuonCSC), &(*theMuonGEM));
0205     m_alignmentParameterStore = std::make_unique<AlignmentParameterStore>(empty_alignables, m_aliParamStoreCfg);
0206 
0207     for (auto const& monitor : m_monitors) {
0208       monitor->beginOfJob(m_alignableTracker.get(), m_alignableMuon.get(), m_alignmentParameterStore.get());
0209     }
0210     for (auto const& monitor : m_monitors) {
0211       monitor->startingNewLoop();
0212     }
0213 
0214     m_firstEvent = false;
0215   }
0216 
0217   // Retrieve trajectories and tracks from the event
0218   const edm::Handle<TrajTrackAssociationCollection>& trajTracksMap = iEvent.getHandle(trajTrackToken_);
0219 
0220   // Form pairs of trajectories and tracks
0221   ConstTrajTrackPairCollection trajTracks;
0222   for (const auto& iPair : *trajTracksMap) {
0223     trajTracks.push_back(ConstTrajTrackPair(&(*iPair.key), &(*iPair.val)));
0224   }
0225 
0226   // Run the monitors
0227   for (const auto& monitor : m_monitors) {
0228     monitor->duringLoop(iEvent, iSetup, trajTracks);
0229   }
0230 }
0231 
0232 // ------------ method called once each job just before starting event loop  ------------
0233 void AlignmentMonitorAsAnalyzer::beginJob() { m_firstEvent = true; }
0234 
0235 // ------------ method called once each job just after ending the event loop  ------------
0236 void AlignmentMonitorAsAnalyzer::endJob() {
0237   for (auto const& monitor : m_monitors) {
0238     monitor->endOfLoop();
0239   }
0240   for (auto const& monitor : m_monitors) {
0241     monitor->endOfJob();
0242   }
0243 }
0244 
0245 //define this as a plug-in
0246 DEFINE_FWK_MODULE(AlignmentMonitorAsAnalyzer);