From de6661c83da0dc4f93290a12c5d0ba9c16611674 Mon Sep 17 00:00:00 2001 From: Brian Francis Date: Tue, 16 Jun 2020 13:36:24 -0400 Subject: [PATCH 1/5] Add track-based isolation, recHit energy sum to IsolatedTrack class --- .../PatCandidates/interface/IsolatedTrack.h | 22 ++- .../PatCandidates/src/classes_def_objects.xml | 3 +- .../plugins/PATIsolatedTrackProducer.cc | 155 ++++++++++++++++-- .../python/slimming/isolatedTracks_cfi.py | 19 ++- 4 files changed, 185 insertions(+), 14 deletions(-) diff --git a/DataFormats/PatCandidates/interface/IsolatedTrack.h b/DataFormats/PatCandidates/interface/IsolatedTrack.h index 44c1fabb679dd..8c1757cd0449d 100644 --- a/DataFormats/PatCandidates/interface/IsolatedTrack.h +++ b/DataFormats/PatCandidates/interface/IsolatedTrack.h @@ -24,8 +24,11 @@ namespace pat { : LeafCandidate(0, LorentzVector(0, 0, 0, 0)), pfIsolationDR03_(pat::PFIsolation()), miniIsolation_(pat::PFIsolation()), + trackIsolation_(0.), matchedCaloJetEmEnergy_(0.), matchedCaloJetHadEnergy_(0.), + associatedEcalEnergy_(0.), + associatedHcalEnergy_(0.), pfLepOverlap_(false), pfNeutralSum_(0.), dz_(0.), @@ -47,8 +50,11 @@ namespace pat { explicit IsolatedTrack(const PFIsolation& iso, const PFIsolation& miniiso, + float trackiso, float caloJetEm, float caloJetHad, + float ecalEnergy, + float hcalEnergy, bool pfLepOverlap, float pfNeutralSum, const LorentzVector& p4, @@ -73,8 +79,11 @@ namespace pat { : LeafCandidate(charge, p4, Point(0., 0., 0.), id), pfIsolationDR03_(iso), miniIsolation_(miniiso), + trackIsolation_(trackiso), matchedCaloJetEmEnergy_(caloJetEm), matchedCaloJetHadEnergy_(caloJetHad), + associatedEcalEnergy_(ecalEnergy), + associatedHcalEnergy_(hcalEnergy), pfLepOverlap_(pfLepOverlap), pfNeutralSum_(pfNeutralSum), dz_(dz), @@ -97,12 +106,15 @@ namespace pat { ~IsolatedTrack() override {} const PFIsolation& pfIsolationDR03() const { return pfIsolationDR03_; } - const PFIsolation& miniPFIsolation() const { return miniIsolation_; } + float trackIsolation() const { return trackIsolation_; } float matchedCaloJetEmEnergy() const { return matchedCaloJetEmEnergy_; } float matchedCaloJetHadEnergy() const { return matchedCaloJetHadEnergy_; } + float associatedEcalEnergy() const { return associatedEcalEnergy_; } + float associatedHcalEnergy() const { return associatedHcalEnergy_; } + bool pfLepOverlap() const { return pfLepOverlap_; } float pfNeutralSum() const { return pfNeutralSum_; } @@ -121,6 +133,11 @@ namespace pat { const reco::HitPattern& hitPattern() const { return hitPattern_; } + // helper functions for PhysicsTools/PatAlgos/python/slimming/isolatedTracks_cfi.py + int numMissingInnerHits() const { return hitPattern_.trackerLayersWithoutMeasurement(reco::HitPattern::MISSING_INNER_HITS); } + int numMissingMiddleHits() const { return hitPattern_.trackerLayersWithoutMeasurement(reco::HitPattern::TRACK_HITS); } + int numMissingOuterHits() const { return hitPattern_.trackerLayersWithoutMeasurement(reco::HitPattern::MISSING_OUTER_HITS); } + float dEdxStrip() const { return dEdxStrip_; } float dEdxPixel() const { return dEdxPixel_; } @@ -141,8 +158,11 @@ namespace pat { protected: PFIsolation pfIsolationDR03_; PFIsolation miniIsolation_; + float trackIsolation_; float matchedCaloJetEmEnergy_; //energy of nearest calojet within a given dR; float matchedCaloJetHadEnergy_; + float associatedEcalEnergy_; // sum of EBEE recHits within a given dR + float associatedHcalEnergy_; // sum of HBHE recHits within a given dR bool pfLepOverlap_; float pfNeutralSum_; float dz_, dxy_, dzError_, dxyError_; diff --git a/DataFormats/PatCandidates/src/classes_def_objects.xml b/DataFormats/PatCandidates/src/classes_def_objects.xml index 7fe1ad99422de..a5463a0b15096 100644 --- a/DataFormats/PatCandidates/src/classes_def_objects.xml +++ b/DataFormats/PatCandidates/src/classes_def_objects.xml @@ -121,7 +121,8 @@ - + + diff --git a/PhysicsTools/PatAlgos/plugins/PATIsolatedTrackProducer.cc b/PhysicsTools/PatAlgos/plugins/PATIsolatedTrackProducer.cc index 5aaabbaa3ceb6..bacabcdc34332 100644 --- a/PhysicsTools/PatAlgos/plugins/PATIsolatedTrackProducer.cc +++ b/PhysicsTools/PatAlgos/plugins/PATIsolatedTrackProducer.cc @@ -22,6 +22,8 @@ #include "DataFormats/TrackReco/interface/TrackExtraFwd.h" #include "DataFormats/TrackReco/interface/DeDxData.h" #include "DataFormats/TrackReco/interface/DeDxHitInfo.h" +#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" +#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" #include "DataFormats/VertexReco/interface/Vertex.h" #include "DataFormats/VertexReco/interface/VertexFwd.h" #include "RecoTracker/DeDx/interface/DeDxTools.h" @@ -39,6 +41,11 @@ #include "MagneticField/Engine/interface/MagneticField.h" +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" +#include "Geometry/Records/interface/CaloGeometryRecord.h" +#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h" +#include "Geometry/CaloGeometry/interface/CaloCellGeometry.h" + namespace pat { class PATIsolatedTrackProducer : public edm::stream::EDProducer<> { @@ -58,6 +65,11 @@ namespace pat { pat::PFIsolation& iso, pat::PFIsolation& miniiso) const; + float getTrackIsolation(const PolarLorentzVector& track_p4, + const math::XYZPoint& track_vtx, + const float& track_dzError, + const reco::TrackCollection* tracks) const; + bool getPFLeptonOverlap(const PolarLorentzVector& p4, const pat::PackedCandidateCollection* pc) const; float getPFNeutralSum(const PolarLorentzVector& p4, const pat::PackedCandidateCollection* pc, int pc_idx) const; @@ -72,6 +84,15 @@ namespace pat { TrackDetMatchInfo getTrackDetMatchInfo(const edm::Event&, const edm::EventSetup&, const reco::Track&); void getCaloJetEnergy(const PolarLorentzVector&, const reco::CaloJetCollection*, float&, float&) const; + + void getAssociatedCaloEnergy(const PolarLorentzVector&, + const EBRecHitCollection&, + const EERecHitCollection&, + const HBHERecHitCollection&, + float&, + float&) const; + + bool insideCone(const PolarLorentzVector&, const DetId &, const double) const; private: const edm::EDGetTokenT pc_; @@ -87,21 +108,28 @@ namespace pat { const edm::EDGetTokenT gt2dedxHitInfo_; const bool addPrescaledDeDxTracks_; const edm::EDGetTokenT> gt2dedxHitInfoPrescale_; + const edm::EDGetTokenT EBRecHits_; + const edm::EDGetTokenT EERecHits_; + const edm::EDGetTokenT HBHERecHits_; + const bool usePrecomputedDeDxStrip_; const bool usePrecomputedDeDxPixel_; - const float pT_cut_; // only save cands with pT>pT_cut_ - const float pT_cut_noIso_; // above this pT, don't apply any iso cut - const float pfIsolation_DR_; // isolation radius - const float pfIsolation_DZ_; // used in determining if pfcand is from PV or PU - const float absIso_cut_; // save if ANY of absIso, relIso, or miniRelIso pass the cuts + const float pT_cut_; // only save cands with pT>pT_cut_ + const float pT_cut_noIso_; // above this pT, don't apply any iso cut + const float pfIsolation_DR_; // isolation radius + const float pfIsolation_DZ_; // used in determining if pfcand is from PV or PU + const float trackIsolation_DR_; // isolation radius + const float trackIsolation_maxDZSig_; // used in determining if two tracks are from different vertices + const float absIso_cut_; // save if ANY of absIso, relIso, or miniRelIso pass the cuts const float relIso_cut_; const float miniRelIso_cut_; - const float caloJet_DR_; // save energy of nearest calojet within caloJet_DR_ - const float pflepoverlap_DR_; // pf lepton overlap radius - const float pflepoverlap_pTmin_; // pf lepton overlap min pT (only look at PF candidates with pT>pflepoverlap_pTmin_) - const float pcRefNearest_DR_; // radius for nearest charged packed candidate - const float pcRefNearest_pTmin_; // min pT for nearest charged packed candidate - const float pfneutralsum_DR_; // pf lepton overlap radius + const float caloJet_DR_; // save energy of nearest calojet within caloJet_DR_ + const float associatedCaloEnergy_DR_; // sum recHit energy within DR of track + const float pflepoverlap_DR_; // pf lepton overlap radius + const float pflepoverlap_pTmin_; // pf lepton overlap min pT (only look at PF candidates with pT>pflepoverlap_pTmin_) + const float pcRefNearest_DR_; // radius for nearest charged packed candidate + const float pcRefNearest_pTmin_; // min pT for nearest charged packed candidate + const float pfneutralsum_DR_; // pf lepton overlap radius const bool saveDeDxHitInfo_; StringCutObjectSelector saveDeDxHitInfoCut_; @@ -109,6 +137,8 @@ namespace pat { TrackDetectorAssociator trackAssociator_; TrackAssociatorParameters trackAssocParameters_; + + edm::ESHandle caloGeometry_; }; } // namespace pat @@ -131,16 +161,22 @@ pat::PATIsolatedTrackProducer::PATIsolatedTrackProducer(const edm::ParameterSet& gt2dedxHitInfoPrescale_(addPrescaledDeDxTracks_ ? consumes>( iConfig.getParameter("dEdxHitInfoPrescale")) : edm::EDGetTokenT>()), + EBRecHits_(consumes(iConfig.getParameter("EBRecHits"))), + EERecHits_(consumes(iConfig.getParameter("EERecHits"))), + HBHERecHits_(consumes(iConfig.getParameter("HBHERecHits"))), usePrecomputedDeDxStrip_(iConfig.getParameter("usePrecomputedDeDxStrip")), usePrecomputedDeDxPixel_(iConfig.getParameter("usePrecomputedDeDxPixel")), pT_cut_(iConfig.getParameter("pT_cut")), pT_cut_noIso_(iConfig.getParameter("pT_cut_noIso")), pfIsolation_DR_(iConfig.getParameter("pfIsolation_DR")), pfIsolation_DZ_(iConfig.getParameter("pfIsolation_DZ")), + trackIsolation_DR_(iConfig.getParameter("trackIsolation_DR")), + trackIsolation_maxDZSig_(iConfig.getParameter("trackIsolation_maxDZSig")), absIso_cut_(iConfig.getParameter("absIso_cut")), relIso_cut_(iConfig.getParameter("relIso_cut")), miniRelIso_cut_(iConfig.getParameter("miniRelIso_cut")), caloJet_DR_(iConfig.getParameter("caloJet_DR")), + associatedCaloEnergy_DR_(iConfig.getParameter("associatedCaloEnergy_DR")), pflepoverlap_DR_(iConfig.getParameter("pflepoverlap_DR")), pflepoverlap_pTmin_(iConfig.getParameter("pflepoverlap_pTmin")), pcRefNearest_DR_(iConfig.getParameter("pcRefNearest_DR")), @@ -229,6 +265,21 @@ void pat::PATIsolatedTrackProducer::produce(edm::Event& iEvent, const edm::Event iSetup.get().get(ecalS_h); const EcalChannelStatus* ecalS = ecalS_h.product(); + // get recHits collections for associated calo energy sums + edm::Handle EBRecHits; + iEvent.getByToken(EBRecHits_, EBRecHits); + + edm::Handle EERecHits; + iEvent.getByToken(EERecHits_, EERecHits); + + edm::Handle HBHERecHits; + iEvent.getByToken(HBHERecHits_, HBHERecHits); + + // get calorimeter geometry for recHit positions in associated calo energy sum calculation + iSetup.get().get(caloGeometry_); + if (!caloGeometry_.isValid()) + throw cms::Exception("FatalError") << "Unable to find CaloGeometryRecord in event.\n"; + auto outDeDxC = std::make_unique(); std::vector dEdXass; @@ -256,6 +307,7 @@ void pat::PATIsolatedTrackProducer::produce(edm::Event& iEvent, const edm::Event float dz, dxy, dzError, dxyError; int pfCandInd; //to avoid counting packedPFCands in their own isolation int ltCandInd; //to avoid pointing lost track to itself when looking for closest + math::XYZPoint vtx; // for use in getTrackIsolation // get the four-momentum and charge if (isInPackedCands) { @@ -264,12 +316,14 @@ void pat::PATIsolatedTrackProducer::produce(edm::Event& iEvent, const edm::Event charge = pfCand->charge(); pfCandInd = pcref.key(); ltCandInd = -1; + vtx = pfCand->vertex(); } else if (isInLostTracks) { p4 = lostTrack->p4(); polarP4 = lostTrack->p4(); charge = lostTrack->charge(); pfCandInd = -1; ltCandInd = ltref.key(); + vtx = lostTrack->vertex(); } else { double m = 0.13957018; //assume pion mass double E = sqrt(m * m + gentk.p() * gentk.p()); @@ -278,6 +332,7 @@ void pat::PATIsolatedTrackProducer::produce(edm::Event& iEvent, const edm::Event charge = gentk.charge(); pfCandInd = -1; ltCandInd = -1; + vtx = gentk.vertex(); } int prescaled = 0; @@ -332,9 +387,15 @@ void pat::PATIsolatedTrackProducer::produce(edm::Event& iEvent, const edm::Event refToCand = pat::PackedCandidateRef(); //NULL reference } + // get the track isolation of the track + float trackIso = getTrackIsolation(polarP4, vtx, dzError, generalTracks); + float caloJetEm, caloJetHad; getCaloJetEnergy(polarP4, caloJets.product(), caloJetEm, caloJetHad); + float ecalEnergy, hcalEnergy; + getAssociatedCaloEnergy(polarP4, *EBRecHits, *EERecHits, *HBHERecHits, ecalEnergy, hcalEnergy); + bool pfLepOverlap = getPFLeptonOverlap(polarP4, pc); float pfNeutralSum = getPFNeutralSum(polarP4, pc, pfCandInd); @@ -393,8 +454,11 @@ void pat::PATIsolatedTrackProducer::produce(edm::Event& iEvent, const edm::Event outPtrP->push_back(pat::IsolatedTrack(isolationDR03, miniIso, + trackIso, caloJetEm, caloJetHad, + ecalEnergy, + hcalEnergy, pfLepOverlap, pfNeutralSum, p4, @@ -478,9 +542,15 @@ void pat::PATIsolatedTrackProducer::produce(edm::Event& iEvent, const edm::Event fromPV = pfCand.fromPV(); refToCand = pcref; + // get the track isolation of the track + float trackIso = getTrackIsolation(polarP4, pfCand.vertex(), dzError, generalTracks); + float caloJetEm, caloJetHad; getCaloJetEnergy(polarP4, caloJets.product(), caloJetEm, caloJetHad); + float ecalEnergy, hcalEnergy; + getAssociatedCaloEnergy(polarP4, *EBRecHits, *EERecHits, *HBHERecHits, ecalEnergy, hcalEnergy); + bool pfLepOverlap = getPFLeptonOverlap(polarP4, pc); float pfNeutralSum = getPFNeutralSum(polarP4, pc, ipc); @@ -507,8 +577,11 @@ void pat::PATIsolatedTrackProducer::produce(edm::Event& iEvent, const edm::Event outPtrP->push_back(pat::IsolatedTrack(isolationDR03, miniIso, + trackIso, caloJetEm, caloJetHad, + ecalEnergy, + hcalEnergy, pfLepOverlap, pfNeutralSum, pfCand.p4(), @@ -592,6 +665,25 @@ void pat::PATIsolatedTrackProducer::getIsolation(const PolarLorentzVector& p4, miniiso = pat::PFIsolation(chmiso, nhmiso, phmiso, pumiso); } +float pat::PATIsolatedTrackProducer::getTrackIsolation(const PolarLorentzVector& track_p4, + const math::XYZPoint& track_vtx, + const float& track_dzError, + const reco::TrackCollection* tracks) const { + float sumPt = 0.; + for (const auto& t : *tracks) { + // exclude tracks from different vertices by dz signficance + // similar to primary vertex assignment, but includes dzError from both tracks + if (fabs(t.dz(track_vtx)) >= trackIsolation_maxDZSig_ * hypot(t.dzError(), track_dzError)) + continue; + + float dR = deltaR(t, track_p4); + if (dR < trackIsolation_DR_ && dR > 1.e-12) // exclude candidate itself with dR>1.e-12 + sumPt += t.pt (); + } + + return sumPt; +} + //get overlap of isolated track with a PF lepton bool pat::PATIsolatedTrackProducer::getPFLeptonOverlap(const PolarLorentzVector& p4, const pat::PackedCandidateCollection* pc) const { @@ -777,6 +869,47 @@ void pat::PATIsolatedTrackProducer::getCaloJetEnergy(const PolarLorentzVector& p } } +void pat::PATIsolatedTrackProducer::getAssociatedCaloEnergy(const PolarLorentzVector& p4, + const EBRecHitCollection& EBRecHits, + const EERecHitCollection& EERecHits, + const HBHERecHitCollection& HBHERecHits, + float& eEM, + float& eHad) const { + eEM = 0.; + for (const auto& hit : EBRecHits) { + if (insideCone(p4, hit.detid(), associatedCaloEnergy_DR_)) + eEM += hit.energy(); + } + for (const auto& hit : EERecHits) { + if (insideCone(p4, hit.detid(), associatedCaloEnergy_DR_)) + eEM += hit.energy(); + } + + eHad = 0.; + for (const auto& hit : HBHERecHits) { + if (insideCone(p4, hit.detid(), associatedCaloEnergy_DR_)) + eHad += hit.energy(); + } +} + +bool pat::PATIsolatedTrackProducer::insideCone(const PolarLorentzVector& p4, + const DetId &id, + const double dR) const { + + if (!caloGeometry_.isValid() || + !caloGeometry_->getSubdetectorGeometry(id) || + !caloGeometry_->getSubdetectorGeometry(id)->getGeometry(id)) { + throw cms::Exception("FatalError") << "Failed to access geometry for DetId: " << id.rawId(); + return false; + } + + const GlobalPoint &idPosition = caloGeometry_->getSubdetectorGeometry(id)->getGeometry(id)->getPosition(); + if (idPosition.mag() < 0.01) return false; + + math::XYZVector idPositionRoot(idPosition.x(), idPosition.y(), idPosition.z()); + return deltaR(p4, idPositionRoot) < dR; +} + using pat::PATIsolatedTrackProducer; #include "FWCore/Framework/interface/MakerMacros.h" DEFINE_FWK_MODULE(PATIsolatedTrackProducer); diff --git a/PhysicsTools/PatAlgos/python/slimming/isolatedTracks_cfi.py b/PhysicsTools/PatAlgos/python/slimming/isolatedTracks_cfi.py index b07862696dab1..d2e24b1fc476f 100644 --- a/PhysicsTools/PatAlgos/python/slimming/isolatedTracks_cfi.py +++ b/PhysicsTools/PatAlgos/python/slimming/isolatedTracks_cfi.py @@ -24,6 +24,15 @@ " abs(dxy) < 0.5 && abs(dz) < 0.5 && "+ " (miniPFIsolation().chargedHadronIso()/pt < 1.0 || pt > 100)" ) +_exoDisappearingTrackCut = ( + "pt > 30 && "+ + "abs(dxy) < 0.05 && abs(dz) < 1.0 &&"+ + "numMissingInnerHits == 0 &&"+ + "numMissingMiddleHits == 0 &&"+ + "numMissingOuterHits >= 1 &&"+ + "trackIsolation/pt < 0.1" +) + isolatedTracks = cms.EDProducer("PATIsolatedTrackProducer", tkAssocParamBlock, packedPFCandidates = cms.InputTag("packedPFCandidates"), @@ -35,6 +44,10 @@ dEdxDataPixel = cms.InputTag("dedxPixelHarmonic2"), dEdxHitInfo = cms.InputTag("dedxHitInfo"), dEdxHitInfoPrescale = cms.InputTag("dedxHitInfo","prescale"), + EBRecHits = cms.InputTag ("reducedEcalRecHitsEB"), + EERecHits = cms.InputTag ("reducedEcalRecHitsEE"), + HBHERecHits = cms.InputTag ("reducedHcalRecHits", "hbhereco"), + addPrescaledDeDxTracks = cms.bool(False), usePrecomputedDeDxStrip = cms.bool(True), # if these are set to True, will get estimated DeDx from DeDxData branches usePrecomputedDeDxPixel = cms.bool(True), # if set to False, will manually compute using dEdxHitInfo @@ -44,11 +57,15 @@ pfIsolation_DZ = cms.double(0.1), miniIsoParams = cms.vdouble(0.05, 0.2, 10.0), # (minDR, maxDR, kT) # dR for miniiso is max(minDR, min(maxDR, kT/pT)) + trackIsolation_DR = cms.double(0.3), + trackIsolation_maxDZSig = cms.double(3.0), + absIso_cut = cms.double(5.0), relIso_cut = cms.double(0.2), miniRelIso_cut = cms.double(0.2), caloJet_DR = cms.double(0.3), + associatedCaloEnergy_DR = cms.double(0.5), pflepoverlap_DR = cms.double(0.001), pflepoverlap_pTmin = cms.double(5.0), @@ -59,7 +76,7 @@ pfneutralsum_DR = cms.double(0.05), saveDeDxHitInfo = cms.bool(True), - saveDeDxHitInfoCut = cms.string("(%s) || (%s)" % (_susySoftDisappearingTrackCut,_exoHighPtTrackCut)), + saveDeDxHitInfoCut = cms.string("(%s) || (%s) || (%s)" % (_susySoftDisappearingTrackCut,_exoHighPtTrackCut,_exoDisappearingTrackCut)), ) def miniAOD_customizeIsolatedTracksFastSim(process): From a9e80ed6cef9b7c4d69658f278a9c6252e797aac Mon Sep 17 00:00:00 2001 From: czkaiweb Date: Fri, 11 Sep 2020 07:33:56 -0500 Subject: [PATCH 2/5] changes for code-format check --- .../PatCandidates/interface/IsolatedTrack.h | 16 ++-- .../plugins/PATIsolatedTrackProducer.cc | 78 +++++++++---------- 2 files changed, 49 insertions(+), 45 deletions(-) diff --git a/DataFormats/PatCandidates/interface/IsolatedTrack.h b/DataFormats/PatCandidates/interface/IsolatedTrack.h index 8c1757cd0449d..960e342ac831a 100644 --- a/DataFormats/PatCandidates/interface/IsolatedTrack.h +++ b/DataFormats/PatCandidates/interface/IsolatedTrack.h @@ -134,9 +134,15 @@ namespace pat { const reco::HitPattern& hitPattern() const { return hitPattern_; } // helper functions for PhysicsTools/PatAlgos/python/slimming/isolatedTracks_cfi.py - int numMissingInnerHits() const { return hitPattern_.trackerLayersWithoutMeasurement(reco::HitPattern::MISSING_INNER_HITS); } - int numMissingMiddleHits() const { return hitPattern_.trackerLayersWithoutMeasurement(reco::HitPattern::TRACK_HITS); } - int numMissingOuterHits() const { return hitPattern_.trackerLayersWithoutMeasurement(reco::HitPattern::MISSING_OUTER_HITS); } + int numMissingInnerHits() const { + return hitPattern_.trackerLayersWithoutMeasurement(reco::HitPattern::MISSING_INNER_HITS); + } + int numMissingMiddleHits() const { + return hitPattern_.trackerLayersWithoutMeasurement(reco::HitPattern::TRACK_HITS); + } + int numMissingOuterHits() const { + return hitPattern_.trackerLayersWithoutMeasurement(reco::HitPattern::MISSING_OUTER_HITS); + } float dEdxStrip() const { return dEdxStrip_; } float dEdxPixel() const { return dEdxPixel_; } @@ -161,8 +167,8 @@ namespace pat { float trackIsolation_; float matchedCaloJetEmEnergy_; //energy of nearest calojet within a given dR; float matchedCaloJetHadEnergy_; - float associatedEcalEnergy_; // sum of EBEE recHits within a given dR - float associatedHcalEnergy_; // sum of HBHE recHits within a given dR + float associatedEcalEnergy_; // sum of EBEE recHits within a given dR + float associatedHcalEnergy_; // sum of HBHE recHits within a given dR bool pfLepOverlap_; float pfNeutralSum_; float dz_, dxy_, dzError_, dxyError_; diff --git a/PhysicsTools/PatAlgos/plugins/PATIsolatedTrackProducer.cc b/PhysicsTools/PatAlgos/plugins/PATIsolatedTrackProducer.cc index bacabcdc34332..4377f034a9470 100644 --- a/PhysicsTools/PatAlgos/plugins/PATIsolatedTrackProducer.cc +++ b/PhysicsTools/PatAlgos/plugins/PATIsolatedTrackProducer.cc @@ -84,15 +84,16 @@ namespace pat { TrackDetMatchInfo getTrackDetMatchInfo(const edm::Event&, const edm::EventSetup&, const reco::Track&); void getCaloJetEnergy(const PolarLorentzVector&, const reco::CaloJetCollection*, float&, float&) const; - - void getAssociatedCaloEnergy(const PolarLorentzVector&, - const EBRecHitCollection&, - const EERecHitCollection&, - const HBHERecHitCollection&, - float&, + + void getAssociatedCaloEnergy(const PolarLorentzVector&, + const EBRecHitCollection&, + const EERecHitCollection&, + const HBHERecHitCollection&, + float&, float&) const; - bool insideCone(const PolarLorentzVector&, const DetId &, const double) const; + bool insideCone(const PolarLorentzVector&, const DetId&, const double) const; + private: const edm::EDGetTokenT pc_; @@ -114,22 +115,22 @@ namespace pat { const bool usePrecomputedDeDxStrip_; const bool usePrecomputedDeDxPixel_; - const float pT_cut_; // only save cands with pT>pT_cut_ - const float pT_cut_noIso_; // above this pT, don't apply any iso cut - const float pfIsolation_DR_; // isolation radius - const float pfIsolation_DZ_; // used in determining if pfcand is from PV or PU - const float trackIsolation_DR_; // isolation radius - const float trackIsolation_maxDZSig_; // used in determining if two tracks are from different vertices - const float absIso_cut_; // save if ANY of absIso, relIso, or miniRelIso pass the cuts + const float pT_cut_; // only save cands with pT>pT_cut_ + const float pT_cut_noIso_; // above this pT, don't apply any iso cut + const float pfIsolation_DR_; // isolation radius + const float pfIsolation_DZ_; // used in determining if pfcand is from PV or PU + const float trackIsolation_DR_; // isolation radius + const float trackIsolation_maxDZSig_; // used in determining if two tracks are from different vertices + const float absIso_cut_; // save if ANY of absIso, relIso, or miniRelIso pass the cuts const float relIso_cut_; const float miniRelIso_cut_; - const float caloJet_DR_; // save energy of nearest calojet within caloJet_DR_ - const float associatedCaloEnergy_DR_; // sum recHit energy within DR of track - const float pflepoverlap_DR_; // pf lepton overlap radius - const float pflepoverlap_pTmin_; // pf lepton overlap min pT (only look at PF candidates with pT>pflepoverlap_pTmin_) - const float pcRefNearest_DR_; // radius for nearest charged packed candidate - const float pcRefNearest_pTmin_; // min pT for nearest charged packed candidate - const float pfneutralsum_DR_; // pf lepton overlap radius + const float caloJet_DR_; // save energy of nearest calojet within caloJet_DR_ + const float associatedCaloEnergy_DR_; // sum recHit energy within DR of track + const float pflepoverlap_DR_; // pf lepton overlap radius + const float pflepoverlap_pTmin_; // pf lepton overlap min pT (only look at PF candidates with pT>pflepoverlap_pTmin_) + const float pcRefNearest_DR_; // radius for nearest charged packed candidate + const float pcRefNearest_pTmin_; // min pT for nearest charged packed candidate + const float pfneutralsum_DR_; // pf lepton overlap radius const bool saveDeDxHitInfo_; StringCutObjectSelector saveDeDxHitInfoCut_; @@ -273,7 +274,7 @@ void pat::PATIsolatedTrackProducer::produce(edm::Event& iEvent, const edm::Event iEvent.getByToken(EERecHits_, EERecHits); edm::Handle HBHERecHits; - iEvent.getByToken(HBHERecHits_, HBHERecHits); + iEvent.getByToken(HBHERecHits_, HBHERecHits); // get calorimeter geometry for recHit positions in associated calo energy sum calculation iSetup.get().get(caloGeometry_); @@ -305,9 +306,9 @@ void pat::PATIsolatedTrackProducer::produce(edm::Event& iEvent, const edm::Event pat::PackedCandidateRef refToCand; int pdgId, charge, fromPV; float dz, dxy, dzError, dxyError; - int pfCandInd; //to avoid counting packedPFCands in their own isolation - int ltCandInd; //to avoid pointing lost track to itself when looking for closest - math::XYZPoint vtx; // for use in getTrackIsolation + int pfCandInd; //to avoid counting packedPFCands in their own isolation + int ltCandInd; //to avoid pointing lost track to itself when looking for closest + math::XYZPoint vtx; // for use in getTrackIsolation // get the four-momentum and charge if (isInPackedCands) { @@ -677,8 +678,8 @@ float pat::PATIsolatedTrackProducer::getTrackIsolation(const PolarLorentzVector& continue; float dR = deltaR(t, track_p4); - if (dR < trackIsolation_DR_ && dR > 1.e-12) // exclude candidate itself with dR>1.e-12 - sumPt += t.pt (); + if (dR < trackIsolation_DR_ && dR > 1.e-12) // exclude candidate itself with dR>1.e-12 + sumPt += t.pt(); } return sumPt; @@ -869,15 +870,15 @@ void pat::PATIsolatedTrackProducer::getCaloJetEnergy(const PolarLorentzVector& p } } -void pat::PATIsolatedTrackProducer::getAssociatedCaloEnergy(const PolarLorentzVector& p4, - const EBRecHitCollection& EBRecHits, - const EERecHitCollection& EERecHits, - const HBHERecHitCollection& HBHERecHits, +void pat::PATIsolatedTrackProducer::getAssociatedCaloEnergy(const PolarLorentzVector& p4, + const EBRecHitCollection& EBRecHits, + const EERecHitCollection& EERecHits, + const HBHERecHitCollection& HBHERecHits, float& eEM, float& eHad) const { eEM = 0.; for (const auto& hit : EBRecHits) { - if (insideCone(p4, hit.detid(), associatedCaloEnergy_DR_)) + if (insideCone(p4, hit.detid(), associatedCaloEnergy_DR_)) eEM += hit.energy(); } for (const auto& hit : EERecHits) { @@ -892,19 +893,16 @@ void pat::PATIsolatedTrackProducer::getAssociatedCaloEnergy(const PolarLorentzVe } } -bool pat::PATIsolatedTrackProducer::insideCone(const PolarLorentzVector& p4, - const DetId &id, - const double dR) const { - - if (!caloGeometry_.isValid() || - !caloGeometry_->getSubdetectorGeometry(id) || +bool pat::PATIsolatedTrackProducer::insideCone(const PolarLorentzVector& p4, const DetId& id, const double dR) const { + if (!caloGeometry_.isValid() || !caloGeometry_->getSubdetectorGeometry(id) || !caloGeometry_->getSubdetectorGeometry(id)->getGeometry(id)) { throw cms::Exception("FatalError") << "Failed to access geometry for DetId: " << id.rawId(); return false; } - const GlobalPoint &idPosition = caloGeometry_->getSubdetectorGeometry(id)->getGeometry(id)->getPosition(); - if (idPosition.mag() < 0.01) return false; + const GlobalPoint& idPosition = caloGeometry_->getSubdetectorGeometry(id)->getGeometry(id)->getPosition(); + if (idPosition.mag() < 0.01) + return false; math::XYZVector idPositionRoot(idPosition.x(), idPosition.y(), idPosition.z()); return deltaR(p4, idPositionRoot) < dR; From 090a3581e5da456ff0c1d00ab663b4ba2e92621b Mon Sep 17 00:00:00 2001 From: czkaiweb Date: Fri, 11 Sep 2020 08:07:07 -0500 Subject: [PATCH 3/5] changes for code format change --- PhysicsTools/PatAlgos/plugins/PATIsolatedTrackProducer.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/PhysicsTools/PatAlgos/plugins/PATIsolatedTrackProducer.cc b/PhysicsTools/PatAlgos/plugins/PATIsolatedTrackProducer.cc index 4377f034a9470..059a8c1121535 100644 --- a/PhysicsTools/PatAlgos/plugins/PATIsolatedTrackProducer.cc +++ b/PhysicsTools/PatAlgos/plugins/PATIsolatedTrackProducer.cc @@ -93,7 +93,6 @@ namespace pat { float&) const; bool insideCone(const PolarLorentzVector&, const DetId&, const double) const; - private: const edm::EDGetTokenT pc_; @@ -874,7 +873,7 @@ void pat::PATIsolatedTrackProducer::getAssociatedCaloEnergy(const PolarLorentzVe const EBRecHitCollection& EBRecHits, const EERecHitCollection& EERecHits, const HBHERecHitCollection& HBHERecHits, - float& eEM, + float& eEM, float& eHad) const { eEM = 0.; for (const auto& hit : EBRecHits) { From e7acbcb544cb81013f15c27afe7996b6133ae18c Mon Sep 17 00:00:00 2001 From: czkaiweb Date: Mon, 14 Sep 2020 04:41:47 -0500 Subject: [PATCH 4/5] modified to deltaR2 --- .../PatAlgos/plugins/PATIsolatedTrackProducer.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/PhysicsTools/PatAlgos/plugins/PATIsolatedTrackProducer.cc b/PhysicsTools/PatAlgos/plugins/PATIsolatedTrackProducer.cc index 059a8c1121535..d9e07521d7bc1 100644 --- a/PhysicsTools/PatAlgos/plugins/PATIsolatedTrackProducer.cc +++ b/PhysicsTools/PatAlgos/plugins/PATIsolatedTrackProducer.cc @@ -630,7 +630,7 @@ void pat::PATIsolatedTrackProducer::getIsolation(const PolarLorentzVector& p4, if (int(pf_it - pc->begin()) == pc_idx) //don't count itself continue; int id = std::abs(pf_it->pdgId()); - bool fromPV = (pf_it->fromPV() > 1 || fabs(pf_it->dz()) < pfIsolation_DZ_); + bool fromPV = (pf_it->fromPV() > 1 || std::fabs(pf_it->dz()) < pfIsolation_DZ_); float pt = pf_it->p4().pt(); float dr = deltaR(p4, *pf_it); @@ -673,11 +673,11 @@ float pat::PATIsolatedTrackProducer::getTrackIsolation(const PolarLorentzVector& for (const auto& t : *tracks) { // exclude tracks from different vertices by dz signficance // similar to primary vertex assignment, but includes dzError from both tracks - if (fabs(t.dz(track_vtx)) >= trackIsolation_maxDZSig_ * hypot(t.dzError(), track_dzError)) + if (std::fabs(t.dz(track_vtx)) >= trackIsolation_maxDZSig_ * hypot(t.dzError(), track_dzError)) continue; - float dR = deltaR(t, track_p4); - if (dR < trackIsolation_DR_ && dR > 1.e-12) // exclude candidate itself with dR>1.e-12 + float dR2 = deltaR2(t, track_p4); + if (dR2 < trackIsolation_DR_ * trackIsolation_DR_ && dR2 > 1.e-24) // exclude candidate itself with dR>1.e-12 sumPt += t.pt(); } @@ -730,7 +730,7 @@ void pat::PATIsolatedTrackProducer::getNearestPCRef(const PolarLorentzVector& p4 if (int(pf_it - pc->begin()) == pc_idx) //don't count itself continue; int charge = std::abs(pf_it->charge()); - bool fromPV = (pf_it->fromPV() > 1 || fabs(pf_it->dz()) < pfIsolation_DZ_); + bool fromPV = (pf_it->fromPV() > 1 || std::fabs(pf_it->dz()) < pfIsolation_DZ_); float pt = pf_it->p4().pt(); float dr = deltaR(p4, *pf_it); if (charge == 0) // exclude neutral candidates @@ -904,7 +904,7 @@ bool pat::PATIsolatedTrackProducer::insideCone(const PolarLorentzVector& p4, con return false; math::XYZVector idPositionRoot(idPosition.x(), idPosition.y(), idPosition.z()); - return deltaR(p4, idPositionRoot) < dR; + return deltaR2(p4, idPositionRoot) < dR * dR; } using pat::PATIsolatedTrackProducer; From 28fd4cebf2937b943d268029c257bd94a4f1d83d Mon Sep 17 00:00:00 2001 From: czkaiweb Date: Mon, 14 Sep 2020 05:00:04 -0500 Subject: [PATCH 5/5] modified to std::abs --- PhysicsTools/PatAlgos/plugins/PATIsolatedTrackProducer.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PhysicsTools/PatAlgos/plugins/PATIsolatedTrackProducer.cc b/PhysicsTools/PatAlgos/plugins/PATIsolatedTrackProducer.cc index d9e07521d7bc1..c1a69d0257c1f 100644 --- a/PhysicsTools/PatAlgos/plugins/PATIsolatedTrackProducer.cc +++ b/PhysicsTools/PatAlgos/plugins/PATIsolatedTrackProducer.cc @@ -630,7 +630,7 @@ void pat::PATIsolatedTrackProducer::getIsolation(const PolarLorentzVector& p4, if (int(pf_it - pc->begin()) == pc_idx) //don't count itself continue; int id = std::abs(pf_it->pdgId()); - bool fromPV = (pf_it->fromPV() > 1 || std::fabs(pf_it->dz()) < pfIsolation_DZ_); + bool fromPV = (pf_it->fromPV() > 1 || std::abs(pf_it->dz()) < pfIsolation_DZ_); float pt = pf_it->p4().pt(); float dr = deltaR(p4, *pf_it); @@ -673,7 +673,7 @@ float pat::PATIsolatedTrackProducer::getTrackIsolation(const PolarLorentzVector& for (const auto& t : *tracks) { // exclude tracks from different vertices by dz signficance // similar to primary vertex assignment, but includes dzError from both tracks - if (std::fabs(t.dz(track_vtx)) >= trackIsolation_maxDZSig_ * hypot(t.dzError(), track_dzError)) + if (std::abs(t.dz(track_vtx)) >= trackIsolation_maxDZSig_ * hypot(t.dzError(), track_dzError)) continue; float dR2 = deltaR2(t, track_p4); @@ -730,7 +730,7 @@ void pat::PATIsolatedTrackProducer::getNearestPCRef(const PolarLorentzVector& p4 if (int(pf_it - pc->begin()) == pc_idx) //don't count itself continue; int charge = std::abs(pf_it->charge()); - bool fromPV = (pf_it->fromPV() > 1 || std::fabs(pf_it->dz()) < pfIsolation_DZ_); + bool fromPV = (pf_it->fromPV() > 1 || std::abs(pf_it->dz()) < pfIsolation_DZ_); float pt = pf_it->p4().pt(); float dr = deltaR(p4, *pf_it); if (charge == 0) // exclude neutral candidates