Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-09 00:51:11

0001 // -*- C++ -*-
0002 //
0003 // Package:    HLTrigger/Muon
0004 // Class:      HLTScoutingMuonProducer
0005 //
0006 /**\class HLTScoutingMuonProducer HLTScoutingMuonProducer.cc HLTScoutingMuonProducer.cc
0007 
0008 Description: Producer for ScoutingMuon
0009 
0010 */
0011 //
0012 // Original Author:  David G. Sheffield (Rutgers)
0013 //         Created:  Fri, 31 Jul 2015
0014 //
0015 //
0016 
0017 #include "HLTScoutingMuonProducer.h"
0018 #include "DataFormats/Math/interface/deltaR.h"
0019 #include "TMath.h"
0020 
0021 //
0022 // constructors and destructor
0023 //
0024 HLTScoutingMuonProducer::HLTScoutingMuonProducer(const edm::ParameterSet& iConfig)
0025     : ChargedCandidateCollection_(
0026           consumes<reco::RecoChargedCandidateCollection>(iConfig.getParameter<edm::InputTag>("ChargedCandidates"))),
0027       displacedvertexCollection_(
0028           consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("displacedvertexCollection"))),
0029       MuonCollection_(consumes<reco::MuonCollection>(iConfig.getParameter<edm::InputTag>("InputMuons"))),
0030       linkToken_(consumes<reco::MuonTrackLinksCollection>(iConfig.getParameter<edm::InputTag>("InputLinks"))),
0031       TrackCollection_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("Tracks"))),
0032       EcalPFClusterIsoMap_(consumes<RecoChargedCandMap>(iConfig.getParameter<edm::InputTag>("EcalPFClusterIsoMap"))),
0033       HcalPFClusterIsoMap_(consumes<RecoChargedCandMap>(iConfig.getParameter<edm::InputTag>("HcalPFClusterIsoMap"))),
0034       TrackIsoMap_(consumes<edm::ValueMap<double>>(iConfig.getParameter<edm::InputTag>("TrackIsoMap"))),
0035       muonPtCut(iConfig.getParameter<double>("muonPtCut")),
0036       muonEtaCut(iConfig.getParameter<double>("muonEtaCut")),
0037       minVtxProbCut(iConfig.getParameter<double>("minVtxProbCut")) {
0038   //register products
0039   produces<Run3ScoutingMuonCollection>();
0040   produces<Run3ScoutingVertexCollection>("displacedVtx");
0041 }
0042 
0043 HLTScoutingMuonProducer::~HLTScoutingMuonProducer() = default;
0044 
0045 // ------------ method called to produce the data  ------------
0046 void HLTScoutingMuonProducer::produce(edm::StreamID sid, edm::Event& iEvent, edm::EventSetup const& setup) const {
0047   using namespace edm;
0048 
0049   std::unique_ptr<Run3ScoutingMuonCollection> outMuons(new Run3ScoutingMuonCollection());
0050   std::unique_ptr<Run3ScoutingVertexCollection> dispVertices(new Run3ScoutingVertexCollection());
0051 
0052   // Get RecoChargedCandidate
0053   Handle<reco::RecoChargedCandidateCollection> ChargedCandidateCollection;
0054   if (!iEvent.getByToken(ChargedCandidateCollection_, ChargedCandidateCollection)) {
0055     iEvent.put(std::move(outMuons));
0056     iEvent.put(std::move(dispVertices), "displacedVtx");
0057     return;
0058   }
0059 
0060   std::pair<reco::RecoChargedCandidate, reco::RecoChargedCandidate> ivtxMuPair;
0061   std::vector<std::pair<reco::RecoChargedCandidate, reco::RecoChargedCandidate>> vtxMuPair;
0062 
0063   //get displaced vertices
0064   Handle<reco::VertexCollection> displacedvertexCollection;
0065   if (iEvent.getByToken(displacedvertexCollection_, displacedvertexCollection)) {
0066     for (auto& dispvtx : *displacedvertexCollection) {
0067       if (!dispvtx.isValid())
0068         continue;
0069       float vtxProb = 0.0;
0070       if ((dispvtx.chi2() >= 0.0) && (dispvtx.ndof() > 0))
0071         vtxProb = TMath::Prob(dispvtx.chi2(), dispvtx.ndof());
0072       if (vtxProb < minVtxProbCut)
0073         continue;
0074 
0075       // Get the 2 tracks associated to displaced vertex
0076       auto trackIt = dispvtx.tracks_begin();
0077       reco::TrackRef vertextkRef1 = (*trackIt).castTo<reco::TrackRef>();
0078       trackIt++;
0079       reco::TrackRef vertextkRef2 = (*trackIt).castTo<reco::TrackRef>();
0080 
0081       // Get the muons associated with the tracks
0082       int iFoundRefs = 0;
0083       for (auto const& cand : *ChargedCandidateCollection) {
0084         reco::TrackRef tkRef = cand.get<reco::TrackRef>();
0085         if (tkRef == vertextkRef1) {
0086           ivtxMuPair.first = cand;
0087           iFoundRefs++;
0088         }
0089         if (tkRef == vertextkRef2) {
0090           ivtxMuPair.second = cand;
0091           iFoundRefs++;
0092         }
0093       }
0094       if (iFoundRefs < 2)
0095         continue;
0096       vtxMuPair.push_back(ivtxMuPair);
0097 
0098       dispVertices->emplace_back(dispvtx.x(),
0099                                  dispvtx.y(),
0100                                  dispvtx.z(),
0101                                  dispvtx.zError(),
0102                                  dispvtx.xError(),
0103                                  dispvtx.yError(),
0104                                  dispvtx.tracksSize(),
0105                                  dispvtx.chi2(),
0106                                  dispvtx.ndof(),
0107                                  dispvtx.isValid());
0108     }
0109   }
0110 
0111   // Get Muon collection
0112   Handle<reco::MuonCollection> MuonCollection;
0113   if (!iEvent.getByToken(MuonCollection_, MuonCollection)) {
0114     iEvent.put(std::move(outMuons));
0115     iEvent.put(std::move(dispVertices), "displacedVtx");
0116     return;
0117   }
0118 
0119   // Get Links collection
0120   edm::Handle<reco::MuonTrackLinksCollection> links;
0121   if (!iEvent.getByToken(linkToken_, links)) {
0122     iEvent.put(std::move(outMuons));
0123     iEvent.put(std::move(dispVertices), "displacedVtx");
0124     return;
0125   }
0126 
0127   // Get EcalPFClusterIsoMap
0128   Handle<RecoChargedCandMap> EcalPFClusterIsoMap;
0129   iEvent.getByToken(EcalPFClusterIsoMap_, EcalPFClusterIsoMap);
0130 
0131   // Get HcalPFClusterIsoMap
0132   Handle<RecoChargedCandMap> HcalPFClusterIsoMap;
0133   iEvent.getByToken(HcalPFClusterIsoMap_, HcalPFClusterIsoMap);
0134 
0135   // Get TrackIsoMap
0136   Handle<ValueMap<double>> TrackIsoMap;
0137   iEvent.getByToken(TrackIsoMap_, TrackIsoMap);
0138 
0139   // Produce muons
0140   std::vector<int> vtxInd;
0141   float minDR2 = 1e-06;
0142   int index = 0;
0143 
0144   for (auto& muon : *ChargedCandidateCollection) {
0145     reco::RecoChargedCandidateRef muonRef = getRef(ChargedCandidateCollection, index);
0146     ++index;
0147     if (muonRef.isNull() || !muonRef.isAvailable())
0148       continue;
0149 
0150     reco::TrackRef track = muon.track();
0151     if (track.isNull() || !track.isAvailable())
0152       continue;
0153 
0154     int validStandAloneMuonHits = 0;
0155     int matchedStandAloneMuonStations = 0;
0156     for (auto const& link : *links) {
0157       const reco::Track& trackerTrack = *link.trackerTrack();
0158       float dR2 = deltaR2(track->eta(), track->phi(), trackerTrack.eta(), trackerTrack.phi());
0159       float dPt = std::abs(track->pt() - trackerTrack.pt());
0160       if (track->pt() != 0)
0161         dPt = dPt / track->pt();
0162 
0163       if (dR2 < 0.02 * 0.02 and dPt < 0.001) {
0164         if (link.standAloneTrack().isNonnull()) {
0165           validStandAloneMuonHits = link.standAloneTrack()->hitPattern().numberOfValidMuonHits();
0166           matchedStandAloneMuonStations = link.standAloneTrack()->hitPattern().muonStationsWithValidHits();
0167         }
0168       }
0169     }
0170 
0171     unsigned int recoMuonType = 2;  // Global muon
0172     float normalizedChi2 = 999.0;
0173     int nRecoMuonValidMuonHits = 0;
0174     int nRecoMuonChambers = 0;
0175     int nRecoMuonChambersCSCorDT = 0;
0176     int nRecoMuonMatches = 0;
0177     int nRecoMuonMatchedStations = 0;
0178     unsigned int nRecoMuonExpectedMatchedStations = 0;
0179     unsigned int recoMuonStationMask = 0;
0180     int nRecoMuonMatchedRPCLayers = 0;
0181     unsigned int recoMuonRPClayerMask = 0;
0182     for (auto const& recoMu : *MuonCollection) {
0183       float dR2 = deltaR2(muon.eta(), muon.phi(), recoMu.eta(), recoMu.phi());
0184       float dPt = std::abs(muon.pt() - recoMu.pt());
0185       if (muon.pt() != 0)
0186         dPt = dPt / muon.pt();
0187 
0188       if (dR2 < 0.02 * 0.02 and dPt < 0.001) {
0189         if (recoMu.globalTrack().isNonnull()) {
0190           normalizedChi2 = recoMu.globalTrack()->normalizedChi2();
0191           nRecoMuonValidMuonHits = recoMu.globalTrack()->hitPattern().numberOfValidMuonHits();
0192         }
0193         recoMuonType = recoMu.type();
0194         nRecoMuonChambers = recoMu.numberOfChambers();
0195         nRecoMuonChambersCSCorDT = recoMu.numberOfChambersCSCorDT();
0196         nRecoMuonMatches = recoMu.numberOfMatches();
0197         nRecoMuonMatchedStations = recoMu.numberOfMatchedStations();
0198         nRecoMuonExpectedMatchedStations = recoMu.expectedNnumberOfMatchedStations();
0199         recoMuonStationMask = recoMu.stationMask();
0200         nRecoMuonMatchedRPCLayers = recoMu.numberOfMatchedRPCLayers();
0201         recoMuonRPClayerMask = recoMu.RPClayerMask();
0202       }
0203     }
0204 
0205     if (muon.pt() < muonPtCut)
0206       continue;
0207     if (fabs(muon.eta()) > muonEtaCut)
0208       continue;
0209 
0210     double ecalisopf = -1.0;
0211     if (EcalPFClusterIsoMap.isValid()) {
0212       ecalisopf = (*EcalPFClusterIsoMap)[muonRef];
0213     }
0214 
0215     double hcalisopf = -1.0;
0216     if (HcalPFClusterIsoMap.isValid()) {
0217       hcalisopf = (*HcalPFClusterIsoMap)[muonRef];
0218     }
0219 
0220     double trackiso = -1.0;
0221     if (TrackIsoMap.isValid()) {
0222       trackiso = (*TrackIsoMap)[muonRef];
0223     }
0224 
0225     vtxInd.reserve(vtxMuPair.size());
0226     for (unsigned int i = 0; i < vtxMuPair.size(); i++) {
0227       float dr2_1 = reco::deltaR2(((vtxMuPair[i]).first), muon);
0228       float dr2_2 = reco::deltaR2(((vtxMuPair[i]).second), muon);
0229       if ((dr2_1 < minDR2) || (dr2_2 < minDR2))
0230         vtxInd.push_back(i);
0231     }
0232 
0233     outMuons->emplace_back(muon.pt(),
0234                            muon.eta(),
0235                            muon.phi(),
0236                            muon.mass(),
0237                            recoMuonType,
0238                            track->charge(),
0239                            normalizedChi2,
0240                            ecalisopf,
0241                            hcalisopf,
0242                            trackiso,
0243                            validStandAloneMuonHits,
0244                            matchedStandAloneMuonStations,
0245                            nRecoMuonValidMuonHits,
0246                            nRecoMuonChambers,
0247                            nRecoMuonChambersCSCorDT,
0248                            nRecoMuonMatches,
0249                            nRecoMuonMatchedStations,
0250                            nRecoMuonExpectedMatchedStations,
0251                            recoMuonStationMask,
0252                            nRecoMuonMatchedRPCLayers,
0253                            recoMuonRPClayerMask,
0254                            track->hitPattern().numberOfValidPixelHits(),
0255                            track->hitPattern().numberOfValidStripHits(),
0256                            track->hitPattern().pixelLayersWithMeasurement(),
0257                            track->hitPattern().trackerLayersWithMeasurement(),
0258                            track->chi2(),
0259                            track->ndof(),
0260                            track->dxy(),
0261                            track->dz(),
0262                            track->qoverp(),
0263                            track->lambda(),
0264                            track->pt(),
0265                            track->phi(),
0266                            track->eta(),
0267                            track->dxyError(),
0268                            track->dzError(),
0269                            track->qoverpError(),
0270                            track->lambdaError(),
0271                            track->phiError(),
0272                            track->dsz(),
0273                            track->dszError(),
0274                            track->covariance(0, 1),
0275                            track->covariance(0, 2),
0276                            track->covariance(0, 3),
0277                            track->covariance(0, 4),
0278                            track->covariance(1, 2),
0279                            track->covariance(1, 3),
0280                            track->covariance(1, 4),
0281                            track->covariance(2, 3),
0282                            track->covariance(2, 4),
0283                            track->covariance(3, 4),
0284                            track->vx(),
0285                            track->vy(),
0286                            track->vz(),
0287                            vtxInd,
0288                            track->hitPattern().run3ScoutingHitPatternPOD());
0289     vtxInd.clear();
0290   }
0291 
0292   // Put output
0293   iEvent.put(std::move(outMuons));
0294   iEvent.put(std::move(dispVertices), "displacedVtx");
0295 }
0296 
0297 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0298 void HLTScoutingMuonProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0299   edm::ParameterSetDescription desc;
0300   desc.add<edm::InputTag>("ChargedCandidates", edm::InputTag("hltIterL3MuonCandidatesNoVtx"));
0301   desc.add<edm::InputTag>("displacedvertexCollection", edm::InputTag("hltDisplacedmumuVtxProducer"));
0302   desc.add<edm::InputTag>("InputMuons", edm::InputTag("hltIterL3MuonsNoVtx"));
0303   desc.add<edm::InputTag>("InputLinks", edm::InputTag("hltL3MuonsIterL3LinksNoVtx"));
0304   desc.add<edm::InputTag>("Tracks", edm::InputTag("hltPixelTracks"));
0305   desc.add<edm::InputTag>("EcalPFClusterIsoMap", edm::InputTag("hltMuonEcalMFPFClusterIsoForMuonsNoVtx"));
0306   desc.add<edm::InputTag>("HcalPFClusterIsoMap", edm::InputTag("hltMuonHcalPFClusterIsoForMuonsNoVtx"));
0307   desc.add<edm::InputTag>("TrackIsoMap",
0308                           edm::InputTag("hltMuonTkRelIsolationCut0p09MapNoVtx:combinedRelativeIsoDeposits"));
0309   desc.add<double>("muonPtCut", 3.0);
0310   desc.add<double>("muonEtaCut", 2.4);
0311   desc.add<double>("minVtxProbCut", 0.001);
0312 
0313   descriptions.add("hltScoutingMuonProducer", desc);
0314 }
0315 
0316 // declare this class as a framework plugin
0317 #include "FWCore/Framework/interface/MakerMacros.h"
0318 DEFINE_FWK_MODULE(HLTScoutingMuonProducer);