Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-06 02:54:07

0001 /*
0002  * MuonCandidateMatcher.h
0003  *
0004  *  Created on: Dec 14, 2020
0005  *      Author: kbunkow
0006  */
0007 
0008 #ifndef L1T_OmtfP1_TOOLS_MUONCANDIDATEMATCHER_H_
0009 #define L1T_OmtfP1_TOOLS_MUONCANDIDATEMATCHER_H_
0010 
0011 #include "L1Trigger/L1TMuonOverlapPhase1/interface/Omtf/AlgoMuon.h"
0012 #include "L1Trigger/L1TMuonOverlapPhase1/interface/Omtf/IOMTFEmulationObserver.h"
0013 
0014 ////////////////////
0015 // FRAMEWORK HEADERS
0016 #include "FWCore/Framework/interface/ESHandle.h"
0017 #include "FWCore/Framework/interface/EventSetup.h"
0018 #include "FWCore/Utilities/interface/InputTag.h"
0019 #include "FWCore/Utilities/interface/ESGetToken.h"
0020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0021 
0022 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
0023 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
0024 
0025 ///////////////////////
0026 // DATA FORMATS HEADERS
0027 #include "DataFormats/Common/interface/Handle.h"
0028 #include "DataFormats/Common/interface/Ref.h"
0029 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuRegionalCand.h"
0030 #include "DataFormats/L1TMuon/interface/RegionalMuonCand.h"
0031 #include "DataFormats/L1TMuon/interface/RegionalMuonCandFwd.h"
0032 
0033 #include "SimDataFormats/Track/interface/SimTrack.h"
0034 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
0035 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
0036 
0037 ////////////////////////////
0038 // DETECTOR GEOMETRY HEADERS
0039 #include "MagneticField/Engine/interface/MagneticField.h"
0040 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0041 
0042 ////////////////
0043 // PHYSICS TOOLS
0044 #include "TrackPropagation/SteppingHelixPropagator/interface/SteppingHelixPropagator.h"
0045 #include "TrackPropagation/SteppingHelixPropagator/interface/SteppingHelixStateInfo.h"
0046 
0047 #include "TH1D.h"
0048 
0049 class MatchingResult {
0050 public:
0051   enum class ResultType : short { propagationFailed = -1, notMatched = 0, matched = 1, duplicate = 2 };
0052 
0053   MatchingResult() {}
0054 
0055   MatchingResult(const SimTrack& simTrack) : simTrack(&simTrack) {
0056     pdgId = simTrack.type();
0057     genPt = simTrack.momentum().pt();
0058     genEta = simTrack.momentum().eta();
0059     genPhi = simTrack.momentum().phi();
0060   }
0061 
0062   MatchingResult(const TrackingParticle& trackingParticle) : trackingParticle(&trackingParticle) {
0063     pdgId = trackingParticle.pdgId();
0064     genPt = trackingParticle.pt();
0065     genEta = trackingParticle.momentum().eta();
0066     genPhi = trackingParticle.momentum().phi();
0067   }
0068 
0069   ResultType result = ResultType::notMatched;
0070   //bool propagationFailed = false;
0071   double deltaPhi = 0;
0072   double deltaEta = 0;
0073 
0074   double propagatedPhi = 0;
0075   double propagatedEta = 0;
0076 
0077   double matchingLikelihood = 0;
0078 
0079   const l1t::RegionalMuonCand* muonCand = nullptr;
0080   AlgoMuonPtr procMuon;  //Processor gbCandidate
0081 
0082   //to avoid using simTrack or trackingParticle
0083   double pdgId = 0;
0084   double genPt = 0;
0085   double genEta = 0;
0086   double genPhi = 0;
0087 
0088   const SimTrack* simTrack = nullptr;
0089   const TrackingParticle* trackingParticle = nullptr;
0090 };
0091 
0092 /*
0093  * matches simMuons or tracking particles
0094  */
0095 class CandidateSimMuonMatcher : public IOMTFEmulationObserver {
0096 public:
0097   CandidateSimMuonMatcher(const edm::ParameterSet& edmCfg,
0098                           const OMTFConfiguration* omtfConfig,
0099                           const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord>& magneticFieldEsToken,
0100                           const edm::ESGetToken<Propagator, TrackingComponentsRecord>& propagatorEsToken);
0101 
0102   ~CandidateSimMuonMatcher() override;
0103 
0104   void beginRun(edm::EventSetup const& eventSetup) override;
0105 
0106   void observeProcesorEmulation(unsigned int iProcessor,
0107                                 l1t::tftype mtfType,
0108                                 const std::shared_ptr<OMTFinput>&,
0109                                 const AlgoMuons& algoCandidates,
0110                                 const AlgoMuons& gbCandidates,
0111                                 const std::vector<l1t::RegionalMuonCand>& candMuons) override;
0112 
0113   void observeEventBegin(const edm::Event& event) override;
0114 
0115   void observeEventEnd(const edm::Event& event,
0116                        std::unique_ptr<l1t::RegionalMuonCandBxCollection>& finalCandidates) override;
0117 
0118   void endJob() override;
0119 
0120   //simplified ghost busting
0121   //only candidates in the bx=0 are included
0122   //ghost busts at the same time the  mtfCands and the gbCandidates
0123   //gbCandidates - all gbCandidates from all processors, should be one-to-one as the mtfCands,
0124   //and the ghostBustedProcMuons are one-to-onr to the returned RegionalMuonCands
0125   static std::vector<const l1t::RegionalMuonCand*> ghostBust(const l1t::RegionalMuonCandBxCollection* mtfCands,
0126                                                              const AlgoMuons& gbCandidates,
0127                                                              AlgoMuons& ghostBustedProcMuons);
0128 
0129   FreeTrajectoryState simTrackToFts(const SimTrack& simTrack, const SimVertex& simVertex);
0130 
0131   FreeTrajectoryState simTrackToFts(const TrackingParticle& trackingParticle);
0132 
0133   TrajectoryStateOnSurface atStation2(FreeTrajectoryState ftsStart, float eta) const;
0134 
0135   TrajectoryStateOnSurface propagate(const SimTrack& simTrack, const edm::SimVertexContainer* simVertices);
0136 
0137   TrajectoryStateOnSurface propagate(const TrackingParticle& trackingParticle);
0138 
0139   //tsof should be the result of track propagation
0140   MatchingResult match(const l1t::RegionalMuonCand* omtfCand,
0141                        const AlgoMuonPtr& procMuon,
0142                        const SimTrack& simTrack,
0143                        TrajectoryStateOnSurface& tsof);
0144 
0145   MatchingResult match(const l1t::RegionalMuonCand* omtfCand,
0146                        const AlgoMuonPtr& procMuon,
0147                        const TrackingParticle& trackingParticle,
0148                        TrajectoryStateOnSurface& tsof);
0149 
0150   std::vector<MatchingResult> cleanMatching(std::vector<MatchingResult> matchingResults,
0151                                             std::vector<const l1t::RegionalMuonCand*>& muonCands,
0152                                             AlgoMuons& ghostBustedProcMuons);
0153 
0154   std::vector<MatchingResult> match(std::vector<const l1t::RegionalMuonCand*>& muonCands,
0155                                     AlgoMuons& ghostBustedProcMuons,
0156                                     const edm::SimTrackContainer* simTracks,
0157                                     const edm::SimVertexContainer* simVertices,
0158                                     std::function<bool(const SimTrack&)> const& simTrackFilter);
0159 
0160   std::vector<MatchingResult> match(std::vector<const l1t::RegionalMuonCand*>& muonCands,
0161                                     AlgoMuons& ghostBustedProcMuons,
0162                                     const TrackingParticleCollection* trackingParticles,
0163                                     std::function<bool(const TrackingParticle&)> const& simTrackFilter);
0164 
0165   std::vector<MatchingResult> getMatchingResults() { return matchingResults; }
0166 
0167 private:
0168   const OMTFConfiguration* omtfConfig;
0169 
0170   const edm::ParameterSet& edmCfg;
0171 
0172   AlgoMuons gbCandidates;
0173   std::vector<MatchingResult> matchingResults;
0174 
0175   const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord>& magneticFieldEsToken;
0176   const edm::ESGetToken<Propagator, TrackingComponentsRecord>& propagatorEsToken;
0177 
0178   edm::ESHandle<MagneticField> magField;
0179   edm::ESHandle<Propagator> propagator;
0180 
0181   TH1D* deltaPhiPropCandMean = nullptr;
0182   TH1D* deltaPhiPropCandStdDev = nullptr;
0183 };
0184 
0185 #endif /* L1T_OmtfP1_TOOLS_MUONCANDIDATEMATCHER_H_ */