From d005f438fead2867b912758e7b39343dd191f151 Mon Sep 17 00:00:00 2001 From: Michael Revering Date: Tue, 31 Jan 2023 22:39:34 -0600 Subject: [PATCH 1/8] Added skimming filter for disappearing muons Applied code-checks Added code-checks and code-format --- .../interface/DisappearingMuonsSkimming.h | 113 +++++ .../python/DisappearingMuonsSkim_cfi.py | 36 ++ .../Skimming/src/DisappearingMuonsSkimming.cc | 404 ++++++++++++++++++ 3 files changed, 553 insertions(+) create mode 100644 Configuration/Skimming/interface/DisappearingMuonsSkimming.h create mode 100644 Configuration/Skimming/python/DisappearingMuonsSkim_cfi.py create mode 100644 Configuration/Skimming/src/DisappearingMuonsSkimming.cc diff --git a/Configuration/Skimming/interface/DisappearingMuonsSkimming.h b/Configuration/Skimming/interface/DisappearingMuonsSkimming.h new file mode 100644 index 0000000000000..4f5efb139545b --- /dev/null +++ b/Configuration/Skimming/interface/DisappearingMuonsSkimming.h @@ -0,0 +1,113 @@ +// -*- C++ -*- +// +// Package: Skimming/DisappearingMuonsSkimming +// Class: DisappearingMuonsSkimming +// +/**\class DisappearingMuonsSkimming DisappearingMuonsSkimming.cc Skimming/DisappearingMuonsSkimming/plugins/DisappearingMuonsSkimming.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Michael Revering +// Created: Tie, 31 Jan 2023 21:22:23 GMT +// +// +#ifndef Configuration_Skimming_DisappearingMuonsSkimming_h +#define Configuration_Skimming_DisappearingMuonsSkimming_h + +// system include files +#include + +// user include filter +#include "FWCore/Utilities/interface/InputTag.h" +#include "FWCore/Utilities/interface/EDGetToken.h" +#include "FWCore/ServiceRegistry/interface/Service.h" +#include "FWCore/Framework/interface/one/EDFilter.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" + +#include "DataFormats/TrackReco/interface/Track.h" +#include "DataFormats/TrackReco/interface/TrackFwd.h" +#include "TrackingTools/TransientTrack/interface/TransientTrack.h" +#include "DataFormats/VertexReco/interface/Vertex.h" +#include "DataFormats/VertexReco/interface/VertexFwd.h" +#include "DataFormats/Common/interface/TriggerResults.h" +#include "DataFormats/PatCandidates/interface/Muon.h" +#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" +#include "TrackingTools/Records/interface/TransientTrackRecord.h" +#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" +#include "Geometry/Records/interface/CaloGeometryRecord.h" + +// +// class declaration +// + +class DisappearingMuonsSkimming : public edm::one::EDFilter<> { +public: + explicit DisappearingMuonsSkimming(const edm::ParameterSet&); + ~DisappearingMuonsSkimming() override; + +private: + void beginJob() override; + bool filter(edm::Event&, const edm::EventSetup&) override; + void endJob() override; + bool passTriggers(const edm::Event& iEvent, + edm::EDGetToken m_trigResultsToken, + std::vector m_muonPathsToPass); + double getTrackIsolation(const edm::Event&, + edm::Handle vtxHandle, + std::vector::const_iterator& iTrack); + double getECALIsolation(const edm::Event&, const edm::EventSetup&, const reco::TransientTrack track); + + // ----------member data --------------------------- + + edm::EDGetToken recoMuonToken_; + edm::EDGetToken standaloneMuonToken_; + edm::EDGetTokenT> trackCollectionToken_; + edm::EDGetTokenT> primaryVerticesToken_; + edm::EDGetTokenT reducedEndcapRecHitCollectionToken_; + edm::EDGetTokenT reducedBarrelRecHitCollectionToken_; + edm::EDGetTokenT trigResultsToken_; + edm::EDGetToken genParticleToken_; + edm::EDGetToken genInfoToken_; + edm::ESGetToken transientTrackToken_; + edm::ESGetToken geometryToken_; + std::vector muonPathsToPass_; + + //options + double minMuPt_ = 26; + double maxMuEta_ = 2.4; + double minTrackEta_ = 1.4; + double maxTrackEta_ = 2.4; + double minTrackPt_ = 20; + double maxTransDCA_ = 0.005; + double maxLongDCA_ = 0.05; + double maxVtxChi_ = 3.; + double minInvMass_ = 50; + double maxInvMass_ = 150; + double trackIsoConesize_ = 0.3; + double trackIsoInnerCone_ = 0.01; + double ecalIsoConesize_ = 0.4; + double minEcalHitE_ = 0.3; + double maxTrackIso_ = 0.05; + double maxEcalIso_ = 10; + double minSigInvMass_ = 76; + double maxSigInvMass_ = 106; + double minStandaloneDr_ = 1.; + double maxStandaloneDE_ = -0.5; + bool keepOffPeak_ = true; + bool keepSameSign_ = true; + bool keepTotalRegion_ = true; + bool keepPartialRegion_ = true; + + //Event categories + bool sameSign; + bool totalRegion; + bool partialRegion; + bool offPeak; +}; +#endif diff --git a/Configuration/Skimming/python/DisappearingMuonsSkim_cfi.py b/Configuration/Skimming/python/DisappearingMuonsSkim_cfi.py new file mode 100644 index 0000000000000..12b1210cd6270 --- /dev/null +++ b/Configuration/Skimming/python/DisappearingMuonsSkim_cfi.py @@ -0,0 +1,36 @@ +import FWCore.ParameterSet.Config as cms + +DisappearingMuonsSkim = cms.EDFilter('DisappearingMuonsSkimming', + recoMuons = cms.InputTag("muons"), + tracks = cms.InputTag("generalTracks"), + StandaloneTracks = cms.InputTag("standAloneMuons"), + primaryVertices = cms.InputTag("offlinePrimaryVertices"), + EERecHits = cms.InputTag("reducedEcalRecHitsEE"), + EBRecHits = cms.InputTag("reducedEcalRecHitsEB"), + TriggerResultsTag = cms.InputTag("TriggerResults","","HLT"), + muonPathsToPass = cms.vstring("HLT_IsoMu24_v","HLT_IsoMu27_v"), + minMuPt = cms.double(26), + maxMuEta = cms.double(2.4), + minTrackEta = cms.double(1.4), + maxTrackEta = cms.double(2.4), + minTrackPt = cms.double(20), + maxTransDCA = cms.double(0.005), + maxLongDCA = cms.double(0.05), + maxVtxChi = cms.double(3.), + minInvMass = cms.double(50), + maxInvMass = cms.double(150), + trackIsoConesize = cms.double(0.3), + trackIsoInnerCone = cms.double(0.01), + ecalIsoConesize = cms.double(0.4), + minEcalHitE = cms.double(0.3), + maxTrackIso = cms.double(0.05), + maxEcalIso = cms.double(10), + minSigInvMass = cms.double(76), + maxSigInvMass = cms.double(106), + minStandaloneDr = cms.double(1.), + maxStandaloneDE = cms.double(-0.5), + keepOffPeak = cms.bool(True), + keepSameSign = cms.bool(True), + keepTotalRegion = cms.bool(True), + keepPartialRegion = cms.bool(True) +) diff --git a/Configuration/Skimming/src/DisappearingMuonsSkimming.cc b/Configuration/Skimming/src/DisappearingMuonsSkimming.cc new file mode 100644 index 0000000000000..721b710aad8d8 --- /dev/null +++ b/Configuration/Skimming/src/DisappearingMuonsSkimming.cc @@ -0,0 +1,404 @@ +// -*- C++ -*- +// +// Package: MuMu/DisappearingMuonsSkimming +// Class: DisappearingMuonsSkimming +// +/**\class DisappearingMuonsSkimming DisappearingMuonsSkimming_AOD.cc MuMu/DisappearingMuonsSkimming/plugins/DisappearingMuonsSkimming_AOD.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Michael Revering +// Created: Mon, 18 Jun 2018 21:22:23 GMT +// +// +// system include files +#include +#include +#include + +#include "Math/VectorUtil.h" +// user include files +#include "Configuration/Skimming/interface/DisappearingMuonsSkimming.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/one/EDFilter.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "DataFormats/Common/interface/TriggerResults.h" +#include "FWCore/Common/interface/TriggerNames.h" +#include "DataFormats/PatCandidates/interface/Muon.h" +#include "DataFormats/VertexReco/interface/Vertex.h" +#include "DataFormats/VertexReco/interface/VertexFwd.h" +#include "FWCore/Utilities/interface/InputTag.h" +#include "FWCore/Utilities/interface/EDGetToken.h" +#include "FWCore/ServiceRegistry/interface/Service.h" +#include "DataFormats/Math/interface/deltaR.h" +#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" +#include "DataFormats/Common/interface/SortedCollection.h" +#include "DataFormats/TrackReco/interface/Track.h" + +// HCAL Stuff +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" +#include "Geometry/Records/interface/CaloGeometryRecord.h" +#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h" + +// for vertexing +#include "FWCore/Framework/interface/ESHandle.h" +#include "TrackingTools/TransientTrack/interface/TransientTrack.h" +#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" +#include "TrackingTools/Records/interface/TransientTrackRecord.h" +#include "RecoVertex/KalmanVertexFit/interface/KalmanVertexFitter.h" + +DisappearingMuonsSkimming::DisappearingMuonsSkimming(const edm::ParameterSet& iConfig) + : recoMuonToken_(consumes>(iConfig.getParameter("recoMuons"))), + standaloneMuonToken_(consumes>(iConfig.getParameter("StandaloneTracks"))), + trackCollectionToken_(consumes>(iConfig.getParameter("tracks"))), + primaryVerticesToken_( + consumes>(iConfig.getParameter("primaryVertices"))), + reducedEndcapRecHitCollectionToken_( + consumes(iConfig.getParameter("EERecHits"))), + reducedBarrelRecHitCollectionToken_( + consumes(iConfig.getParameter("EBRecHits"))), + trigResultsToken_(consumes(iConfig.getParameter("TriggerResultsTag"))), + transientTrackToken_( + esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))), + geometryToken_(esConsumes(edm::ESInputTag{})) { + muonPathsToPass_ = iConfig.getParameter>("muonPathsToPass"); + //Get the options + minMuPt_ = iConfig.getParameter("minMuPt"); + maxMuEta_ = iConfig.getParameter("maxMuEta"); + minTrackEta_ = iConfig.getParameter("minTrackEta"); + maxTrackEta_ = iConfig.getParameter("maxTrackEta"); + minTrackPt_ = iConfig.getParameter("minTrackPt"); + maxTransDCA_ = iConfig.getParameter("maxTransDCA"); + maxLongDCA_ = iConfig.getParameter("maxLongDCA"); + maxVtxChi_ = iConfig.getParameter("maxVtxChi"); + minInvMass_ = iConfig.getParameter("minInvMass"); + maxInvMass_ = iConfig.getParameter("maxInvMass"); + trackIsoConesize_ = iConfig.getParameter("trackIsoConesize"); + trackIsoInnerCone_ = iConfig.getParameter("trackIsoInnerCone"); + ecalIsoConesize_ = iConfig.getParameter("ecalIsoConesize"); + minEcalHitE_ = iConfig.getParameter("minEcalHitE"); + maxTrackIso_ = iConfig.getParameter("maxTrackIso"); + maxEcalIso_ = iConfig.getParameter("maxEcalIso"); + minSigInvMass_ = iConfig.getParameter("minSigInvMass"); + maxSigInvMass_ = iConfig.getParameter("maxSigInvMass"); + minStandaloneDr_ = iConfig.getParameter("minStandaloneDr"); + maxStandaloneDE_ = iConfig.getParameter("maxStandaloneDE"); + keepOffPeak_ = iConfig.getParameter("keepOffPeak"); + keepSameSign_ = iConfig.getParameter("keepSameSign"); + keepTotalRegion_ = iConfig.getParameter("keepTotalRegion"); + keepPartialRegion_ = iConfig.getParameter("keepPartialRegion"); +} + +DisappearingMuonsSkimming::~DisappearingMuonsSkimming() {} + +// +// member functions +// + +// ------------ method called for each event ------------ +bool DisappearingMuonsSkimming::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) { + using namespace edm; + using namespace std; + using namespace reco; + + totalRegion = false; + sameSign = false; + offPeak = false; + partialRegion = false; + + edm::Handle staTracks; + iEvent.getByToken(standaloneMuonToken_, staTracks); + edm::Handle> vertices; + iEvent.getByToken(primaryVerticesToken_, vertices); + edm::Handle> recoMuons; + iEvent.getByToken(recoMuonToken_, recoMuons); + edm::Handle> thePATTrackHandle; + iEvent.getByToken(trackCollectionToken_, thePATTrackHandle); + // this wraps tracks with additional methods that are used in vertex-calculation + const TransientTrackBuilder* transientTrackBuilder = &iSetup.getData(transientTrackToken_); + + if (!passTriggers(iEvent, trigResultsToken_, muonPathsToPass_)) + return false; + + int nMuonTrackCand = 0; + float MuonTrackMass = 0.; + + //Looping over the reconstructed Muons + for (std::vector::const_iterator iMuon = recoMuons->begin(); iMuon != recoMuons->end(); iMuon++) { + if (!(iMuon->isPFMuon() && iMuon->isGlobalMuon())) + continue; + if (!(iMuon->passed(reco::Muon::CutBasedIdTight))) + continue; + if (!(iMuon->passed(reco::Muon::PFIsoTight))) + continue; + if (iMuon->pt() < minMuPt_ || fabs(iMuon->eta()) > maxMuEta_) + continue; + + //Looping over tracks for any good muon + for (std::vector::const_iterator iTrack = thePATTrackHandle->begin(); + iTrack != thePATTrackHandle->end(); + ++iTrack) { + if (!iTrack->quality(reco::Track::qualityByName("highPurity"))) + continue; + if (fabs(iTrack->eta()) > maxTrackEta_ || fabs(iTrack->eta()) < minTrackEta_) + continue; + if (iTrack->pt() < minTrackPt_) + continue; + //Check if the track belongs to a primary vertex for isolation calculation + bool foundtrack = false; + GlobalPoint tkVtx; + for (unsigned int i = 0; i < vertices->size(); i++) { + reco::VertexRef vtx(vertices, i); + if (!vtx->isValid()) { + continue; + } + for (unsigned int j = 0; j < vtx->tracksSize(); j++) { + if (vtx->trackRefAt(j)->pt() == iTrack->pt() && vtx->trackRefAt(j)->eta() == iTrack->eta() && + vtx->trackRefAt(j)->phi() == iTrack->phi()) { + foundtrack = true; + GlobalPoint vert(vtx->x(), vtx->y(), vtx->z()); + tkVtx = vert; + } + } + } + if (!foundtrack) + continue; + reco::TransientTrack tk = transientTrackBuilder->build(*iTrack); + TrajectoryStateClosestToPoint traj = tk.trajectoryStateClosestToPoint(tkVtx); + double transDCA = traj.perigeeParameters().transverseImpactParameter(); + double longDCA = traj.perigeeParameters().longitudinalImpactParameter(); + if (longDCA > maxLongDCA_) + continue; + if (transDCA > maxTransDCA_) + continue; + // make a pair of TransientTracks to feed the vertexer + std::vector tracksToVertex; + tracksToVertex.push_back(transientTrackBuilder->build(*iTrack)); + if (iMuon->isGlobalMuon()) { + tracksToVertex.push_back(transientTrackBuilder->build(iMuon->globalTrack())); + } else { + continue; + } + // try to fit these two tracks to a common vertex + KalmanVertexFitter vertexFitter; + CachingVertex<5> fittedVertex = vertexFitter.vertex(tracksToVertex); + double vtxChi = 0; + // some poor fits will simply fail to find a common vertex + if (fittedVertex.isValid() && fittedVertex.totalChiSquared() >= 0. && fittedVertex.degreesOfFreedom() > 0) { + // others we can exclude by their poor fit + vtxChi = fittedVertex.totalChiSquared() / fittedVertex.degreesOfFreedom(); + + if (vtxChi < maxVtxChi_) { + // important! evaluate momentum vectors AT THE VERTEX + TrajectoryStateClosestToPoint one_TSCP = + tracksToVertex[0].trajectoryStateClosestToPoint(fittedVertex.position()); + TrajectoryStateClosestToPoint two_TSCP = + tracksToVertex[1].trajectoryStateClosestToPoint(fittedVertex.position()); + GlobalVector one_momentum = one_TSCP.momentum(); + GlobalVector two_momentum = two_TSCP.momentum(); + + double total_energy = sqrt(one_momentum.mag2() + 0.106 * 0.106) + sqrt(two_momentum.mag2() + 0.106 * 0.106); + double total_px = one_momentum.x() + two_momentum.x(); + double total_py = one_momentum.y() + two_momentum.y(); + double total_pz = one_momentum.z() + two_momentum.z(); + MuonTrackMass = sqrt(pow(total_energy, 2) - pow(total_px, 2) - pow(total_py, 2) - pow(total_pz, 2)); + } else { + continue; + } + } else { + continue; + } + if (MuonTrackMass < minInvMass_ || MuonTrackMass > maxInvMass_) + continue; + + double trackIso = getTrackIsolation(iEvent, vertices, iTrack); + double ecalIso = getECALIsolation(iEvent, iSetup, transientTrackBuilder->build(*iTrack)); + if (trackIso > maxTrackIso_ || ecalIso > maxEcalIso_) + continue; + + //A good tag/probe pair has been selected, now check for control or signal regions + + if (iMuon->charge() == iTrack->charge()) { + sameSign = true; + } + if (MuonTrackMass < minSigInvMass_ || MuonTrackMass > maxSigInvMass_) { + offPeak = true; + } + + //If neither off-peak or same sign CR, need to check standalone muons for signal regions + double staMinDr = 10; + double staMinDEoverE = -10; + if (!staTracks->empty()) { + for (reco::TrackCollection::const_iterator staTrack = staTracks->begin(); staTrack != staTracks->end(); + ++staTrack) { + reco::TransientTrack track = transientTrackBuilder->build(*staTrack); + double dR = deltaR(track.impactPointTSCP().momentum().eta(), + track.impactPointTSCP().momentum().phi(), + (*iTrack).eta(), + (*iTrack).phi()); + double staDE = (std::sqrt(track.impactPointTSCP().momentum().mag2()) - (*iTrack).p()) / (*iTrack).p(); + if (dR < staMinDr) { + staMinDr = dR; + } + //Pick the largest standalone muon within the cone + if (dR < minStandaloneDr_ && staDE > staMinDEoverE) { + staMinDEoverE = staDE; + } + } + } + if (staMinDr > minStandaloneDr_) { + totalRegion = true; + } else { + if (staMinDEoverE < maxStandaloneDE_) { + partialRegion = true; + } + } + nMuonTrackCand++; + } + } + + if (nMuonTrackCand == 0) + return false; + bool passes = false; + //Pass all same sign CR events + if (sameSign && keepSameSign_) { + passes = true; + } + //Pass all total disappearance events + else if (totalRegion && keepTotalRegion_) { + passes = true; + } + //Pass all partial disappearkance off-peak events + else if (offPeak && keepOffPeak_) { + passes = true; + } + //Pass partial region events that pass minimum standalone muon DE/E. + else if (partialRegion && keepPartialRegion_) { + passes = true; + } + return passes; +} + +bool DisappearingMuonsSkimming::passTriggers(const edm::Event& iEvent, + edm::EDGetToken m_trigResultsToken, + std::vector m_muonPathsToPass) { + bool passTriggers = false; + edm::Handle triggerResults; + iEvent.getByToken(m_trigResultsToken, triggerResults); + const edm::TriggerNames& trigNames = iEvent.triggerNames(*triggerResults); + for (size_t i = 0; i < trigNames.size(); ++i) { + const std::string& name = trigNames.triggerName(i); + for (auto& pathName : m_muonPathsToPass) { + if ((name.find(pathName) != std::string::npos)) { + if (triggerResults->accept(i)) { + passTriggers = true; + } + } + } + } + return passTriggers; +} + +double DisappearingMuonsSkimming::getTrackIsolation(const edm::Event& iEvent, + edm::Handle vtxHandle, + std::vector::const_iterator& iTrack) { + bool foundtrack = false; + unsigned int vtxindex = -1; + unsigned int trackindex = -1; + double Isolation = 0; + for (unsigned int i = 0; i < vtxHandle->size(); i++) { + reco::VertexRef vtx(vtxHandle, i); + if (!vtx->isValid()) { + continue; + } + for (unsigned int j = 0; j < vtx->tracksSize(); j++) { + if (fabs(vtx->trackRefAt(j)->pt() == iTrack->pt())) { + vtxindex = i; + trackindex = j; + foundtrack = true; + GlobalPoint vert(vtx->x(), vtx->y(), vtx->z()); + } + } + } + + if (!foundtrack) { + return -1; + } + + reco::VertexRef primaryVtx(vtxHandle, vtxindex); + + for (unsigned int i = 0; i < primaryVtx->tracksSize(); i++) { + if (i == trackindex) + continue; + reco::TrackBaseRef secondarytrack = primaryVtx->trackRefAt(i); + if (deltaR(iTrack->eta(), iTrack->phi(), secondarytrack->eta(), secondarytrack->phi()) > trackIsoConesize_ || + deltaR(iTrack->eta(), iTrack->phi(), secondarytrack->eta(), secondarytrack->phi()) < trackIsoInnerCone_) + continue; + Isolation += secondarytrack->pt(); + } + + return Isolation / iTrack->pt(); +} + +double DisappearingMuonsSkimming::getECALIsolation(const edm::Event& iEvent, + const edm::EventSetup& iSetup, + const reco::TransientTrack track) { + edm::Handle rechitsEE; + iEvent.getByToken(reducedEndcapRecHitCollectionToken_, rechitsEE); + + edm::Handle rechitsEB; + iEvent.getByToken(reducedBarrelRecHitCollectionToken_, rechitsEB); + + const CaloGeometry& caloGeom = iSetup.getData(geometryToken_); + TrajectoryStateClosestToPoint t0 = track.impactPointTSCP(); + double eDR = 0; + + for (EcalRecHitCollection::const_iterator hit = rechitsEE->begin(); hit != rechitsEE->end(); hit++) { + const DetId id = (*hit).detid(); + const GlobalPoint hitPos = caloGeom.getSubdetectorGeometry(id)->getGeometry(id)->getPosition(); + //Check if hit and track trajectory ar in the same endcap (transient track projects both ways) + if ((hitPos.eta() * t0.momentum().eta()) < 0) { + continue; + } + TrajectoryStateClosestToPoint traj = track.trajectoryStateClosestToPoint(hitPos); + math::XYZVector idPositionRoot(hitPos.x(), hitPos.y(), hitPos.z()); + math::XYZVector trajRoot(traj.position().x(), traj.position().y(), traj.position().z()); + if (ROOT::Math::VectorUtil::DeltaR(idPositionRoot, trajRoot) < ecalIsoConesize_ && (*hit).energy() > minEcalHitE_) { + eDR += (*hit).energy(); + } + } + for (EcalRecHitCollection::const_iterator hit = rechitsEB->begin(); hit != rechitsEB->end(); hit++) { + const DetId id = (*hit).detid(); + const GlobalPoint hitPos = caloGeom.getSubdetectorGeometry(id)->getGeometry(id)->getPosition(); + if ((hitPos.eta() * t0.momentum().eta()) < 0) { + continue; + } + TrajectoryStateClosestToPoint traj = track.trajectoryStateClosestToPoint(hitPos); + math::XYZVector idPositionRoot(hitPos.x(), hitPos.y(), hitPos.z()); + math::XYZVector trajRoot(traj.position().x(), traj.position().y(), traj.position().z()); + if (ROOT::Math::VectorUtil::DeltaR(idPositionRoot, trajRoot) < ecalIsoConesize_ && (*hit).energy() > minEcalHitE_) { + eDR += (*hit).energy(); + } + } + + return eDR; +} + +// ------------ method called once each job just before starting event loop ------------ +void DisappearingMuonsSkimming::beginJob() {} + +// ------------ method called once each job just after ending the event loop ------------ +void DisappearingMuonsSkimming::endJob() {} + +//define this as a plug-in +DEFINE_FWK_MODULE(DisappearingMuonsSkimming); From c31340b8f31219221e3c95c3114a3f082f59cff3 Mon Sep 17 00:00:00 2001 From: Michael Revering Date: Sun, 5 Feb 2023 16:02:10 -0600 Subject: [PATCH 2/8] Fixed bug in track isolation by removing mistakely placed fabs() Added check of eta and phi when matching the track to a vertex. --- Configuration/Skimming/src/DisappearingMuonsSkimming.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Configuration/Skimming/src/DisappearingMuonsSkimming.cc b/Configuration/Skimming/src/DisappearingMuonsSkimming.cc index 721b710aad8d8..87cb7f67f5f18 100644 --- a/Configuration/Skimming/src/DisappearingMuonsSkimming.cc +++ b/Configuration/Skimming/src/DisappearingMuonsSkimming.cc @@ -222,6 +222,9 @@ bool DisappearingMuonsSkimming::filter(edm::Event& iEvent, const edm::EventSetup continue; double trackIso = getTrackIsolation(iEvent, vertices, iTrack); + //Track iso returns -1 when it fails to find the vertex containing the track + if (trackIso < 0) + continue; double ecalIso = getECALIsolation(iEvent, iSetup, transientTrackBuilder->build(*iTrack)); if (trackIso > maxTrackIso_ || ecalIso > maxEcalIso_) continue; @@ -322,7 +325,8 @@ double DisappearingMuonsSkimming::getTrackIsolation(const edm::Event& iEvent, continue; } for (unsigned int j = 0; j < vtx->tracksSize(); j++) { - if (fabs(vtx->trackRefAt(j)->pt() == iTrack->pt())) { + if (vtx->trackRefAt(j)->pt() == iTrack->pt() && vtx->trackRefAt(j)->eta() == iTrack->eta() && + vtx->trackRefAt(j)->phi() == iTrack->phi()) { vtxindex = i; trackindex = j; foundtrack = true; From 78b472fff77ae0e96d3835784db824c3b68b71a7 Mon Sep 17 00:00:00 2001 From: Michael Revering Date: Mon, 6 Feb 2023 18:00:59 -0600 Subject: [PATCH 3/8] Added missing abs to DCA check, switched vertex track matching to use dR and dPt Applied code-checks and code-format --- .../Skimming/src/DisappearingMuonsSkimming.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Configuration/Skimming/src/DisappearingMuonsSkimming.cc b/Configuration/Skimming/src/DisappearingMuonsSkimming.cc index 87cb7f67f5f18..eabb510c39b29 100644 --- a/Configuration/Skimming/src/DisappearingMuonsSkimming.cc +++ b/Configuration/Skimming/src/DisappearingMuonsSkimming.cc @@ -163,8 +163,10 @@ bool DisappearingMuonsSkimming::filter(edm::Event& iEvent, const edm::EventSetup continue; } for (unsigned int j = 0; j < vtx->tracksSize(); j++) { - if (vtx->trackRefAt(j)->pt() == iTrack->pt() && vtx->trackRefAt(j)->eta() == iTrack->eta() && - vtx->trackRefAt(j)->phi() == iTrack->phi()) { + double dR = deltaR(vtx->trackRefAt(j)->eta(), vtx->trackRefAt(j)->phi(), iTrack->eta(), iTrack->phi()); + double dPt = fabs(vtx->trackRefAt(j)->pt() - iTrack->pt()) / iTrack->pt(); + //Find the vertex track that is the same as the probe + if (dR < 0.001 && dPt < 0.001) { foundtrack = true; GlobalPoint vert(vtx->x(), vtx->y(), vtx->z()); tkVtx = vert; @@ -177,9 +179,9 @@ bool DisappearingMuonsSkimming::filter(edm::Event& iEvent, const edm::EventSetup TrajectoryStateClosestToPoint traj = tk.trajectoryStateClosestToPoint(tkVtx); double transDCA = traj.perigeeParameters().transverseImpactParameter(); double longDCA = traj.perigeeParameters().longitudinalImpactParameter(); - if (longDCA > maxLongDCA_) + if (fabs(longDCA) > maxLongDCA_) continue; - if (transDCA > maxTransDCA_) + if (fabs(transDCA) > maxTransDCA_) continue; // make a pair of TransientTracks to feed the vertexer std::vector tracksToVertex; @@ -325,8 +327,10 @@ double DisappearingMuonsSkimming::getTrackIsolation(const edm::Event& iEvent, continue; } for (unsigned int j = 0; j < vtx->tracksSize(); j++) { - if (vtx->trackRefAt(j)->pt() == iTrack->pt() && vtx->trackRefAt(j)->eta() == iTrack->eta() && - vtx->trackRefAt(j)->phi() == iTrack->phi()) { + double dR = deltaR(vtx->trackRefAt(j)->eta(), vtx->trackRefAt(j)->phi(), iTrack->eta(), iTrack->phi()); + double dPt = fabs(vtx->trackRefAt(j)->pt() - iTrack->pt()) / iTrack->pt(); + //Find the vertex track that is the same as the probe + if (dR < 0.001 && dPt < 0.001) { vtxindex = i; trackindex = j; foundtrack = true; From ef202ab833d1e08c27924362ba1572c2a7c1bbc2 Mon Sep 17 00:00:00 2001 From: Michael Revering Date: Tue, 7 Feb 2023 12:02:05 -0600 Subject: [PATCH 4/8] Added event content and data tier to python config file, renamed to match standards. Added skim configuration into Skims_PDWG_cff.py --- ...sSkim_cfi.py => PDWG_EXODisappMuon_cff.py} | 19 +++++++++++++++++-- .../Skimming/python/Skims_PDWG_cff.py | 11 +++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) rename Configuration/Skimming/python/{DisappearingMuonsSkim_cfi.py => PDWG_EXODisappMuon_cff.py} (65%) diff --git a/Configuration/Skimming/python/DisappearingMuonsSkim_cfi.py b/Configuration/Skimming/python/PDWG_EXODisappMuon_cff.py similarity index 65% rename from Configuration/Skimming/python/DisappearingMuonsSkim_cfi.py rename to Configuration/Skimming/python/PDWG_EXODisappMuon_cff.py index 12b1210cd6270..0caa4ddf4d4e1 100644 --- a/Configuration/Skimming/python/DisappearingMuonsSkim_cfi.py +++ b/Configuration/Skimming/python/PDWG_EXODisappMuon_cff.py @@ -1,6 +1,17 @@ import FWCore.ParameterSet.Config as cms -DisappearingMuonsSkim = cms.EDFilter('DisappearingMuonsSkimming', +import HLTrigger.HLTfilters.hltHighLevel_cfi as hlt + +from Configuration.EventContent.EventContent_cff import AODSIMEventContent +EXODisappMuonSkimContent = AODSIMEventContent.clone() +EXODisappMuonSkimContent.outputCommands.append('keep *_hbhereco_*_*') + +exoDisappMuonsHLT = hlt.hltHighLevel.clone() +exoDisappMuonsHLT.TriggerResultsTag = cms.InputTag("TriggerResults","","HLT") +exoDisappMuonsHLT.HLTPaths = ['HLT_IsoMu24_v','HLT_IsoMu27_v'] +exoDisappMuonsHLT.throw = cms.bool( False ) + +disappMuonsSelection = cms.EDFilter('DisappearingMuonsSkimming', recoMuons = cms.InputTag("muons"), tracks = cms.InputTag("generalTracks"), StandaloneTracks = cms.InputTag("standAloneMuons"), @@ -11,7 +22,7 @@ muonPathsToPass = cms.vstring("HLT_IsoMu24_v","HLT_IsoMu27_v"), minMuPt = cms.double(26), maxMuEta = cms.double(2.4), - minTrackEta = cms.double(1.4), + minTrackEta = cms.double(0), maxTrackEta = cms.double(2.4), minTrackPt = cms.double(20), maxTransDCA = cms.double(0.005), @@ -34,3 +45,7 @@ keepTotalRegion = cms.bool(True), keepPartialRegion = cms.bool(True) ) + +EXODisappMuonSkimSequence = cms.Sequence( + exoDisappMuonsHLT+disappMuonSelection +) diff --git a/Configuration/Skimming/python/Skims_PDWG_cff.py b/Configuration/Skimming/python/Skims_PDWG_cff.py index de87591de5f7a..55165838549e9 100644 --- a/Configuration/Skimming/python/Skims_PDWG_cff.py +++ b/Configuration/Skimming/python/Skims_PDWG_cff.py @@ -327,6 +327,17 @@ dataTier = cms.untracked.string('AOD') ) +from Configuration.Skimming.PDWG_EXODisappMuon_cff import * +EXODisappMuonPath = cms.Path(EXODisappMuonSkimSequence) +SKIMStreamEXODisappMuon = cms.FilteredStream( + responsible = 'PDWG', + name = 'EXODisappMuon', + paths = (EXODisappMuonPath), + content = EXODisappMuonSkimContent.outputCommands, + selectEvent = cms.untracked.PSet(), + dataTier = cms.untracked.string('AOD') + ) + ##################### # For the Data on Data Mixing in TSG from HLTrigger.Configuration.HLT_Fake1_cff import fragment as _fragment From e1f21ad7932f920223e766a55fd043bba7f4a32f Mon Sep 17 00:00:00 2001 From: Michael Revering Date: Wed, 1 Mar 2023 15:42:03 -0600 Subject: [PATCH 5/8] Fixed typos in HLT trigger and DisappMuon path, required standalone energy difference in off peak CR --- .../Skimming/python/PDWG_EXODisappMuon_cff.py | 13 ++++++++----- Configuration/Skimming/python/Skims_PDWG_cff.py | 4 ++-- .../Skimming/src/DisappearingMuonsSkimming.cc | 9 +++++---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Configuration/Skimming/python/PDWG_EXODisappMuon_cff.py b/Configuration/Skimming/python/PDWG_EXODisappMuon_cff.py index 0caa4ddf4d4e1..f87467244aa22 100644 --- a/Configuration/Skimming/python/PDWG_EXODisappMuon_cff.py +++ b/Configuration/Skimming/python/PDWG_EXODisappMuon_cff.py @@ -6,10 +6,13 @@ EXODisappMuonSkimContent = AODSIMEventContent.clone() EXODisappMuonSkimContent.outputCommands.append('keep *_hbhereco_*_*') -exoDisappMuonsHLT = hlt.hltHighLevel.clone() -exoDisappMuonsHLT.TriggerResultsTag = cms.InputTag("TriggerResults","","HLT") -exoDisappMuonsHLT.HLTPaths = ['HLT_IsoMu24_v','HLT_IsoMu27_v'] -exoDisappMuonsHLT.throw = cms.bool( False ) +exoDisappMuonsHLT = hlt.hltHighLevel.clone( + throw = False, + andOr = True, + HLTPaths = [ + "HLT_IsoMu*_v*" + ] +) disappMuonsSelection = cms.EDFilter('DisappearingMuonsSkimming', recoMuons = cms.InputTag("muons"), @@ -47,5 +50,5 @@ ) EXODisappMuonSkimSequence = cms.Sequence( - exoDisappMuonsHLT+disappMuonSelection + exoDisappMuonsHLT+disappMuonsSelection ) diff --git a/Configuration/Skimming/python/Skims_PDWG_cff.py b/Configuration/Skimming/python/Skims_PDWG_cff.py index 55165838549e9..93575f538756a 100644 --- a/Configuration/Skimming/python/Skims_PDWG_cff.py +++ b/Configuration/Skimming/python/Skims_PDWG_cff.py @@ -334,8 +334,8 @@ name = 'EXODisappMuon', paths = (EXODisappMuonPath), content = EXODisappMuonSkimContent.outputCommands, - selectEvent = cms.untracked.PSet(), - dataTier = cms.untracked.string('AOD') + selectEvents = cms.untracked.PSet(), + dataTier = cms.untracked.string('USER') ) ##################### diff --git a/Configuration/Skimming/src/DisappearingMuonsSkimming.cc b/Configuration/Skimming/src/DisappearingMuonsSkimming.cc index eabb510c39b29..7ed91198b86e5 100644 --- a/Configuration/Skimming/src/DisappearingMuonsSkimming.cc +++ b/Configuration/Skimming/src/DisappearingMuonsSkimming.cc @@ -236,9 +236,6 @@ bool DisappearingMuonsSkimming::filter(edm::Event& iEvent, const edm::EventSetup if (iMuon->charge() == iTrack->charge()) { sameSign = true; } - if (MuonTrackMass < minSigInvMass_ || MuonTrackMass > maxSigInvMass_) { - offPeak = true; - } //If neither off-peak or same sign CR, need to check standalone muons for signal regions double staMinDr = 10; @@ -265,7 +262,11 @@ bool DisappearingMuonsSkimming::filter(edm::Event& iEvent, const edm::EventSetup totalRegion = true; } else { if (staMinDEoverE < maxStandaloneDE_) { - partialRegion = true; + if (MuonTrackMass < minSigInvMass_ || MuonTrackMass > maxSigInvMass_) { + offPeak = true; + } else { + partialRegion = true; + } } } nMuonTrackCand++; From b5c98a2b86fc95ee38d6958546c45ba7689a8103 Mon Sep 17 00:00:00 2001 From: Michael Revering Date: Thu, 2 Mar 2023 11:56:23 -0600 Subject: [PATCH 6/8] Added horeco and CSC2DrecHits to disappearing muon skim event data --- Configuration/Skimming/python/PDWG_EXODisappMuon_cff.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Configuration/Skimming/python/PDWG_EXODisappMuon_cff.py b/Configuration/Skimming/python/PDWG_EXODisappMuon_cff.py index f87467244aa22..09e61929d6984 100644 --- a/Configuration/Skimming/python/PDWG_EXODisappMuon_cff.py +++ b/Configuration/Skimming/python/PDWG_EXODisappMuon_cff.py @@ -5,6 +5,8 @@ from Configuration.EventContent.EventContent_cff import AODSIMEventContent EXODisappMuonSkimContent = AODSIMEventContent.clone() EXODisappMuonSkimContent.outputCommands.append('keep *_hbhereco_*_*') +EXODisappMuonSkimContent.outputCommands.append('keep *_horeco_*_*') +EXODisappMuonSkimContent.outputCommands.append('keep *_csc2DRecHits_*_*') exoDisappMuonsHLT = hlt.hltHighLevel.clone( throw = False, From f927847dcd968a7e7978b575653ae1a758ea2fd4 Mon Sep 17 00:00:00 2001 From: Michael Revering Date: Fri, 10 Mar 2023 11:29:52 -0600 Subject: [PATCH 7/8] Removed unnecessary includes, converted deltaR to deltaR2, created fillDescriptions, and made config parameters const --- .../interface/DisappearingMuonsSkimming.h | 89 ++++---- .../Skimming/src/DisappearingMuonsSkimming.cc | 191 ++++++++++-------- 2 files changed, 150 insertions(+), 130 deletions(-) diff --git a/Configuration/Skimming/interface/DisappearingMuonsSkimming.h b/Configuration/Skimming/interface/DisappearingMuonsSkimming.h index 4f5efb139545b..750ef843753e2 100644 --- a/Configuration/Skimming/interface/DisappearingMuonsSkimming.h +++ b/Configuration/Skimming/interface/DisappearingMuonsSkimming.h @@ -22,20 +22,14 @@ #include // user include filter -#include "FWCore/Utilities/interface/InputTag.h" #include "FWCore/Utilities/interface/EDGetToken.h" -#include "FWCore/ServiceRegistry/interface/Service.h" #include "FWCore/Framework/interface/one/EDFilter.h" -#include "FWCore/Framework/interface/MakerMacros.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" - +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" #include "DataFormats/TrackReco/interface/Track.h" -#include "DataFormats/TrackReco/interface/TrackFwd.h" #include "TrackingTools/TransientTrack/interface/TransientTrack.h" #include "DataFormats/VertexReco/interface/Vertex.h" -#include "DataFormats/VertexReco/interface/VertexFwd.h" #include "DataFormats/Common/interface/TriggerResults.h" -#include "DataFormats/PatCandidates/interface/Muon.h" #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" #include "TrackingTools/Records/interface/TransientTrackRecord.h" #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" @@ -49,7 +43,8 @@ class DisappearingMuonsSkimming : public edm::one::EDFilter<> { public: explicit DisappearingMuonsSkimming(const edm::ParameterSet&); - ~DisappearingMuonsSkimming() override; + ~DisappearingMuonsSkimming() override = default; + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: void beginJob() override; @@ -65,49 +60,43 @@ class DisappearingMuonsSkimming : public edm::one::EDFilter<> { // ----------member data --------------------------- - edm::EDGetToken recoMuonToken_; - edm::EDGetToken standaloneMuonToken_; - edm::EDGetTokenT> trackCollectionToken_; - edm::EDGetTokenT> primaryVerticesToken_; - edm::EDGetTokenT reducedEndcapRecHitCollectionToken_; - edm::EDGetTokenT reducedBarrelRecHitCollectionToken_; - edm::EDGetTokenT trigResultsToken_; - edm::EDGetToken genParticleToken_; - edm::EDGetToken genInfoToken_; - edm::ESGetToken transientTrackToken_; - edm::ESGetToken geometryToken_; - std::vector muonPathsToPass_; + const edm::EDGetToken recoMuonToken_; + const edm::EDGetToken standaloneMuonToken_; + const edm::EDGetTokenT> trackCollectionToken_; + const edm::EDGetTokenT> primaryVerticesToken_; + const edm::EDGetTokenT reducedEndcapRecHitCollectionToken_; + const edm::EDGetTokenT reducedBarrelRecHitCollectionToken_; + const edm::EDGetTokenT trigResultsToken_; + const edm::EDGetToken genParticleToken_; + const edm::EDGetToken genInfoToken_; + const edm::ESGetToken transientTrackToken_; + const edm::ESGetToken geometryToken_; + const std::vector muonPathsToPass_; //options - double minMuPt_ = 26; - double maxMuEta_ = 2.4; - double minTrackEta_ = 1.4; - double maxTrackEta_ = 2.4; - double minTrackPt_ = 20; - double maxTransDCA_ = 0.005; - double maxLongDCA_ = 0.05; - double maxVtxChi_ = 3.; - double minInvMass_ = 50; - double maxInvMass_ = 150; - double trackIsoConesize_ = 0.3; - double trackIsoInnerCone_ = 0.01; - double ecalIsoConesize_ = 0.4; - double minEcalHitE_ = 0.3; - double maxTrackIso_ = 0.05; - double maxEcalIso_ = 10; - double minSigInvMass_ = 76; - double maxSigInvMass_ = 106; - double minStandaloneDr_ = 1.; - double maxStandaloneDE_ = -0.5; - bool keepOffPeak_ = true; - bool keepSameSign_ = true; - bool keepTotalRegion_ = true; - bool keepPartialRegion_ = true; - - //Event categories - bool sameSign; - bool totalRegion; - bool partialRegion; - bool offPeak; + const double minMuPt_; + const double maxMuEta_; + const double minTrackEta_; + const double maxTrackEta_; + const double minTrackPt_; + const double maxTransDCA_; + const double maxLongDCA_; + const double maxVtxChi_; + const double minInvMass_; + const double maxInvMass_; + const double trackIsoConesize_; + const double trackIsoInnerCone_; + const double ecalIsoConesize_; + const double minEcalHitE_; + const double maxTrackIso_; + const double maxEcalIso_; + const double minSigInvMass_; + const double maxSigInvMass_; + const double minStandaloneDr_; + const double maxStandaloneDE_; + const bool keepOffPeak_; + const bool keepSameSign_; + const bool keepTotalRegion_; + const bool keepPartialRegion_; }; #endif diff --git a/Configuration/Skimming/src/DisappearingMuonsSkimming.cc b/Configuration/Skimming/src/DisappearingMuonsSkimming.cc index 7ed91198b86e5..b91aeeb4fe13e 100644 --- a/Configuration/Skimming/src/DisappearingMuonsSkimming.cc +++ b/Configuration/Skimming/src/DisappearingMuonsSkimming.cc @@ -17,41 +17,27 @@ // // system include files #include -#include -#include #include "Math/VectorUtil.h" // user include files #include "Configuration/Skimming/interface/DisappearingMuonsSkimming.h" #include "FWCore/Framework/interface/Frameworkfwd.h" #include "FWCore/Framework/interface/one/EDFilter.h" - #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/MakerMacros.h" - #include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/Utilities/interface/StreamID.h" - #include "DataFormats/Common/interface/TriggerResults.h" #include "FWCore/Common/interface/TriggerNames.h" #include "DataFormats/PatCandidates/interface/Muon.h" #include "DataFormats/VertexReco/interface/Vertex.h" -#include "DataFormats/VertexReco/interface/VertexFwd.h" #include "FWCore/Utilities/interface/InputTag.h" #include "FWCore/Utilities/interface/EDGetToken.h" -#include "FWCore/ServiceRegistry/interface/Service.h" #include "DataFormats/Math/interface/deltaR.h" #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" -#include "DataFormats/Common/interface/SortedCollection.h" #include "DataFormats/TrackReco/interface/Track.h" - -// HCAL Stuff #include "Geometry/CaloGeometry/interface/CaloGeometry.h" -#include "Geometry/Records/interface/CaloGeometryRecord.h" #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h" - -// for vertexing -#include "FWCore/Framework/interface/ESHandle.h" +#include "Geometry/Records/interface/CaloGeometryRecord.h" #include "TrackingTools/TransientTrack/interface/TransientTrack.h" #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" #include "TrackingTools/Records/interface/TransientTrackRecord.h" @@ -70,36 +56,32 @@ DisappearingMuonsSkimming::DisappearingMuonsSkimming(const edm::ParameterSet& iC trigResultsToken_(consumes(iConfig.getParameter("TriggerResultsTag"))), transientTrackToken_( esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))), - geometryToken_(esConsumes(edm::ESInputTag{})) { - muonPathsToPass_ = iConfig.getParameter>("muonPathsToPass"); - //Get the options - minMuPt_ = iConfig.getParameter("minMuPt"); - maxMuEta_ = iConfig.getParameter("maxMuEta"); - minTrackEta_ = iConfig.getParameter("minTrackEta"); - maxTrackEta_ = iConfig.getParameter("maxTrackEta"); - minTrackPt_ = iConfig.getParameter("minTrackPt"); - maxTransDCA_ = iConfig.getParameter("maxTransDCA"); - maxLongDCA_ = iConfig.getParameter("maxLongDCA"); - maxVtxChi_ = iConfig.getParameter("maxVtxChi"); - minInvMass_ = iConfig.getParameter("minInvMass"); - maxInvMass_ = iConfig.getParameter("maxInvMass"); - trackIsoConesize_ = iConfig.getParameter("trackIsoConesize"); - trackIsoInnerCone_ = iConfig.getParameter("trackIsoInnerCone"); - ecalIsoConesize_ = iConfig.getParameter("ecalIsoConesize"); - minEcalHitE_ = iConfig.getParameter("minEcalHitE"); - maxTrackIso_ = iConfig.getParameter("maxTrackIso"); - maxEcalIso_ = iConfig.getParameter("maxEcalIso"); - minSigInvMass_ = iConfig.getParameter("minSigInvMass"); - maxSigInvMass_ = iConfig.getParameter("maxSigInvMass"); - minStandaloneDr_ = iConfig.getParameter("minStandaloneDr"); - maxStandaloneDE_ = iConfig.getParameter("maxStandaloneDE"); - keepOffPeak_ = iConfig.getParameter("keepOffPeak"); - keepSameSign_ = iConfig.getParameter("keepSameSign"); - keepTotalRegion_ = iConfig.getParameter("keepTotalRegion"); - keepPartialRegion_ = iConfig.getParameter("keepPartialRegion"); -} - -DisappearingMuonsSkimming::~DisappearingMuonsSkimming() {} + geometryToken_(esConsumes(edm::ESInputTag{})), + muonPathsToPass_(iConfig.getParameter>("muonPathsToPass")), + minMuPt_(iConfig.getParameter("minMuPt")), + maxMuEta_(iConfig.getParameter("maxMuEta")), + minTrackEta_(iConfig.getParameter("minTrackEta")), + maxTrackEta_(iConfig.getParameter("maxTrackEta")), + minTrackPt_(iConfig.getParameter("minTrackPt")), + maxTransDCA_(iConfig.getParameter("maxTransDCA")), + maxLongDCA_(iConfig.getParameter("maxLongDCA")), + maxVtxChi_(iConfig.getParameter("maxVtxChi")), + minInvMass_(iConfig.getParameter("minInvMass")), + maxInvMass_(iConfig.getParameter("maxInvMass")), + trackIsoConesize_(iConfig.getParameter("trackIsoConesize")), + trackIsoInnerCone_(iConfig.getParameter("trackIsoInnerCone")), + ecalIsoConesize_(iConfig.getParameter("ecalIsoConesize")), + minEcalHitE_(iConfig.getParameter("minEcalHitE")), + maxTrackIso_(iConfig.getParameter("maxTrackIso")), + maxEcalIso_(iConfig.getParameter("maxEcalIso")), + minSigInvMass_(iConfig.getParameter("minSigInvMass")), + maxSigInvMass_(iConfig.getParameter("maxSigInvMass")), + minStandaloneDr_(iConfig.getParameter("minStandaloneDr")), + maxStandaloneDE_(iConfig.getParameter("maxStandaloneDE")), + keepOffPeak_(iConfig.getParameter("keepOffPeak")), + keepSameSign_(iConfig.getParameter("keepSameSign")), + keepTotalRegion_(iConfig.getParameter("keepTotalRegion")), + keepPartialRegion_(iConfig.getParameter("keepPartialRegion")) {} // // member functions @@ -111,10 +93,10 @@ bool DisappearingMuonsSkimming::filter(edm::Event& iEvent, const edm::EventSetup using namespace std; using namespace reco; - totalRegion = false; - sameSign = false; - offPeak = false; - partialRegion = false; + bool totalRegion = false; + bool sameSign = false; + bool offPeak = false; + bool partialRegion = false; edm::Handle staTracks; iEvent.getByToken(standaloneMuonToken_, staTracks); @@ -163,13 +145,16 @@ bool DisappearingMuonsSkimming::filter(edm::Event& iEvent, const edm::EventSetup continue; } for (unsigned int j = 0; j < vtx->tracksSize(); j++) { - double dR = deltaR(vtx->trackRefAt(j)->eta(), vtx->trackRefAt(j)->phi(), iTrack->eta(), iTrack->phi()); double dPt = fabs(vtx->trackRefAt(j)->pt() - iTrack->pt()) / iTrack->pt(); //Find the vertex track that is the same as the probe - if (dR < 0.001 && dPt < 0.001) { - foundtrack = true; - GlobalPoint vert(vtx->x(), vtx->y(), vtx->z()); - tkVtx = vert; + if (dPt < 0.001) { + double dR2 = deltaR2(vtx->trackRefAt(j)->eta(), vtx->trackRefAt(j)->phi(), iTrack->eta(), iTrack->phi()); + if (dR2 < 0.001 * 0.001) { + foundtrack = true; + GlobalPoint vert(vtx->x(), vtx->y(), vtx->z()); + tkVtx = vert; + break; + } } } } @@ -186,11 +171,7 @@ bool DisappearingMuonsSkimming::filter(edm::Event& iEvent, const edm::EventSetup // make a pair of TransientTracks to feed the vertexer std::vector tracksToVertex; tracksToVertex.push_back(transientTrackBuilder->build(*iTrack)); - if (iMuon->isGlobalMuon()) { - tracksToVertex.push_back(transientTrackBuilder->build(iMuon->globalTrack())); - } else { - continue; - } + tracksToVertex.push_back(transientTrackBuilder->build(iMuon->globalTrack())); // try to fit these two tracks to a common vertex KalmanVertexFitter vertexFitter; CachingVertex<5> fittedVertex = vertexFitter.vertex(tracksToVertex); @@ -224,7 +205,7 @@ bool DisappearingMuonsSkimming::filter(edm::Event& iEvent, const edm::EventSetup continue; double trackIso = getTrackIsolation(iEvent, vertices, iTrack); - //Track iso returns -1 when it fails to find the vertex containing the track + //Track iso returns -1 when it fails to find the vertex containing the track (already checked in track selection, but might as well make sure) if (trackIso < 0) continue; double ecalIso = getECALIsolation(iEvent, iSetup, transientTrackBuilder->build(*iTrack)); @@ -232,34 +213,37 @@ bool DisappearingMuonsSkimming::filter(edm::Event& iEvent, const edm::EventSetup continue; //A good tag/probe pair has been selected, now check for control or signal regions - if (iMuon->charge() == iTrack->charge()) { sameSign = true; } - //If neither off-peak or same sign CR, need to check standalone muons for signal regions - double staMinDr = 10; + //If not same sign CR, need to check standalone muons for signal regions + double staMinDr2 = 1000; double staMinDEoverE = -10; if (!staTracks->empty()) { for (reco::TrackCollection::const_iterator staTrack = staTracks->begin(); staTrack != staTracks->end(); ++staTrack) { reco::TransientTrack track = transientTrackBuilder->build(*staTrack); - double dR = deltaR(track.impactPointTSCP().momentum().eta(), - track.impactPointTSCP().momentum().phi(), - (*iTrack).eta(), - (*iTrack).phi()); + double dR2 = deltaR2(track.impactPointTSCP().momentum().eta(), + track.impactPointTSCP().momentum().phi(), + (*iTrack).eta(), + (*iTrack).phi()); double staDE = (std::sqrt(track.impactPointTSCP().momentum().mag2()) - (*iTrack).p()) / (*iTrack).p(); - if (dR < staMinDr) { - staMinDr = dR; + if (dR2 < staMinDr2) { + staMinDr2 = dR2; } //Pick the largest standalone muon within the cone - if (dR < minStandaloneDr_ && staDE > staMinDEoverE) { + if (dR2 < minStandaloneDr_ * minStandaloneDr_ && staDE > staMinDEoverE) { staMinDEoverE = staDE; } } } - if (staMinDr > minStandaloneDr_) { - totalRegion = true; + if (staMinDr2 > minStandaloneDr_ * minStandaloneDr_) { + if (MuonTrackMass < minSigInvMass_ || MuonTrackMass > maxSigInvMass_) { + offPeak = true; + } else { + totalRegion = true; + } } else { if (staMinDEoverE < maxStandaloneDE_) { if (MuonTrackMass < minSigInvMass_ || MuonTrackMass > maxSigInvMass_) { @@ -308,6 +292,7 @@ bool DisappearingMuonsSkimming::passTriggers(const edm::Event& iEvent, if ((name.find(pathName) != std::string::npos)) { if (triggerResults->accept(i)) { passTriggers = true; + break; } } } @@ -328,14 +313,16 @@ double DisappearingMuonsSkimming::getTrackIsolation(const edm::Event& iEvent, continue; } for (unsigned int j = 0; j < vtx->tracksSize(); j++) { - double dR = deltaR(vtx->trackRefAt(j)->eta(), vtx->trackRefAt(j)->phi(), iTrack->eta(), iTrack->phi()); double dPt = fabs(vtx->trackRefAt(j)->pt() - iTrack->pt()) / iTrack->pt(); //Find the vertex track that is the same as the probe - if (dR < 0.001 && dPt < 0.001) { - vtxindex = i; - trackindex = j; - foundtrack = true; - GlobalPoint vert(vtx->x(), vtx->y(), vtx->z()); + if (dPt < 0.001) { + double dR2 = deltaR2(vtx->trackRefAt(j)->eta(), vtx->trackRefAt(j)->phi(), iTrack->eta(), iTrack->phi()); + if (dR2 < 0.001 * 0.001) { + vtxindex = i; + trackindex = j; + foundtrack = true; + break; + } } } } @@ -350,8 +337,10 @@ double DisappearingMuonsSkimming::getTrackIsolation(const edm::Event& iEvent, if (i == trackindex) continue; reco::TrackBaseRef secondarytrack = primaryVtx->trackRefAt(i); - if (deltaR(iTrack->eta(), iTrack->phi(), secondarytrack->eta(), secondarytrack->phi()) > trackIsoConesize_ || - deltaR(iTrack->eta(), iTrack->phi(), secondarytrack->eta(), secondarytrack->phi()) < trackIsoInnerCone_) + if (deltaR2(iTrack->eta(), iTrack->phi(), secondarytrack->eta(), secondarytrack->phi()) > + trackIsoConesize_ * trackIsoConesize_ || + deltaR2(iTrack->eta(), iTrack->phi(), secondarytrack->eta(), secondarytrack->phi()) < + trackIsoInnerCone_ * trackIsoInnerCone_) continue; Isolation += secondarytrack->pt(); } @@ -403,6 +392,48 @@ double DisappearingMuonsSkimming::getECALIsolation(const edm::Event& iEvent, return eDR; } +void DisappearingMuonsSkimming::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + + desc.add("recoMuons", edm::InputTag("muons")); + desc.add("tracks", edm::InputTag("generalTracks")); + desc.add("StandaloneTracks", edm::InputTag("standAloneMuons")); + desc.add("primaryVertices", edm::InputTag("offlinePrimaryVertices")); + desc.add("EERecHits", edm::InputTag("reducedEcalRecHitsEE")); + desc.add("EBRecHits", edm::InputTag("reducedEcalRecHitsEB")); + desc.add("TriggerResultsTag", edm::InputTag("TriggerResults", "", "HLT")); + desc.add>("muonPathsToPass", + { + "HLT_IsoMu24_v", + "HLT_IsoMu27_v", + }); + desc.add("minMuPt", 26); + desc.add("maxMuEta", 2.4); + desc.add("minTrackEta", 0); + desc.add("maxTrackEta", 2.4); + desc.add("minTrackPt", 20); + desc.add("maxTransDCA", 0.005); + desc.add("maxLongDCA", 0.05); + desc.add("maxVtxChi", 3.0); + desc.add("minInvMass", 50); + desc.add("maxInvMass", 150); + desc.add("trackIsoConesize", 0.3); + desc.add("trackIsoInnerCone", 0.01); + desc.add("ecalIsoConesize", 0.4); + desc.add("minEcalHitE", 0.3); + desc.add("maxTrackIso", 0.05); + desc.add("maxEcalIso", 10); + desc.add("minSigInvMass", 76); + desc.add("maxSigInvMass", 106); + desc.add("minStandaloneDr", 1.0); + desc.add("maxStandaloneDE", -0.5); + desc.add("keepOffPeak", true); + desc.add("keepSameSign", true); + desc.add("keepTotalRegion", true); + desc.add("keepPartialRegion", true); + descriptions.add("disappMuonsSelection", desc); +} + // ------------ method called once each job just before starting event loop ------------ void DisappearingMuonsSkimming::beginJob() {} From 8ee85127e5c444834d7b2387db1eafb975881dbe Mon Sep 17 00:00:00 2001 From: Michael Revering Date: Mon, 13 Mar 2023 11:54:28 -0500 Subject: [PATCH 8/8] Modified disappearing muons skimming module to create auto configuration from fillDescriptions and load them into cff file --- .../Skimming/python/PDWG_EXODisappMuon_cff.py | 36 ++----------------- .../Skimming/src/DisappearingMuonsSkimming.cc | 2 +- 2 files changed, 3 insertions(+), 35 deletions(-) diff --git a/Configuration/Skimming/python/PDWG_EXODisappMuon_cff.py b/Configuration/Skimming/python/PDWG_EXODisappMuon_cff.py index 09e61929d6984..261d6dd2fc687 100644 --- a/Configuration/Skimming/python/PDWG_EXODisappMuon_cff.py +++ b/Configuration/Skimming/python/PDWG_EXODisappMuon_cff.py @@ -16,40 +16,8 @@ ] ) -disappMuonsSelection = cms.EDFilter('DisappearingMuonsSkimming', - recoMuons = cms.InputTag("muons"), - tracks = cms.InputTag("generalTracks"), - StandaloneTracks = cms.InputTag("standAloneMuons"), - primaryVertices = cms.InputTag("offlinePrimaryVertices"), - EERecHits = cms.InputTag("reducedEcalRecHitsEE"), - EBRecHits = cms.InputTag("reducedEcalRecHitsEB"), - TriggerResultsTag = cms.InputTag("TriggerResults","","HLT"), - muonPathsToPass = cms.vstring("HLT_IsoMu24_v","HLT_IsoMu27_v"), - minMuPt = cms.double(26), - maxMuEta = cms.double(2.4), - minTrackEta = cms.double(0), - maxTrackEta = cms.double(2.4), - minTrackPt = cms.double(20), - maxTransDCA = cms.double(0.005), - maxLongDCA = cms.double(0.05), - maxVtxChi = cms.double(3.), - minInvMass = cms.double(50), - maxInvMass = cms.double(150), - trackIsoConesize = cms.double(0.3), - trackIsoInnerCone = cms.double(0.01), - ecalIsoConesize = cms.double(0.4), - minEcalHitE = cms.double(0.3), - maxTrackIso = cms.double(0.05), - maxEcalIso = cms.double(10), - minSigInvMass = cms.double(76), - maxSigInvMass = cms.double(106), - minStandaloneDr = cms.double(1.), - maxStandaloneDE = cms.double(-0.5), - keepOffPeak = cms.bool(True), - keepSameSign = cms.bool(True), - keepTotalRegion = cms.bool(True), - keepPartialRegion = cms.bool(True) -) +from Configuration.Skimming.disappearingMuonsSkimming_cfi import * +disappMuonsSelection = disappearingMuonsSkimming.clone() EXODisappMuonSkimSequence = cms.Sequence( exoDisappMuonsHLT+disappMuonsSelection diff --git a/Configuration/Skimming/src/DisappearingMuonsSkimming.cc b/Configuration/Skimming/src/DisappearingMuonsSkimming.cc index b91aeeb4fe13e..a1fed76d152dd 100644 --- a/Configuration/Skimming/src/DisappearingMuonsSkimming.cc +++ b/Configuration/Skimming/src/DisappearingMuonsSkimming.cc @@ -431,7 +431,7 @@ void DisappearingMuonsSkimming::fillDescriptions(edm::ConfigurationDescriptions& desc.add("keepSameSign", true); desc.add("keepTotalRegion", true); desc.add("keepPartialRegion", true); - descriptions.add("disappMuonsSelection", desc); + descriptions.addWithDefaultLabel(desc); } // ------------ method called once each job just before starting event loop ------------