CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
reco::PFMETProducerMVA Class Reference

#include <PFMETProducerMVA.h>

Inheritance diagram for reco::PFMETProducerMVA:
edm::stream::EDProducer<>

Public Member Functions

 PFMETProducerMVA (const edm::ParameterSet &)
 
 ~PFMETProducerMVA () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Private Types

typedef std::vector< edm::InputTagvInputTag
 

Private Member Functions

double chargedEnFrac (const reco::Candidate *iCand, const reco::CandidateView &pfCandidates, const reco::Vertex *hardScatterVertex)
 
double chargedFracInCone (const reco::Candidate *iCand, const reco::CandidateView &pfCandidates, const reco::Vertex *hardScatterVertex, double iDRMax=0.2)
 
std::vector< reco::PUSubMETCandInfocomputeJetInfo (const reco::PFJetCollection &, const edm::Handle< reco::PFJetCollection > &, const edm::ValueMap< float > &, const reco::VertexCollection &, const reco::Vertex *, const reco::JetCorrector &iCorr, edm::Event &iEvent, const edm::EventSetup &iSetup, std::vector< reco::PUSubMETCandInfo > &iLeptons, std::vector< reco::PUSubMETCandInfo > &iCands)
 
std::vector< reco::PUSubMETCandInfocomputeLeptonInfo (const std::vector< edm::EDGetTokenT< reco::CandidateView > > &srcLeptons_, const reco::CandidateView &pfCandidates, const reco::Vertex *hardScatterVertex, int &lId, bool &lHasPhotons, edm::Event &iEvent)
 
std::vector< reco::PUSubMETCandInfocomputePFCandidateInfo (const reco::CandidateView &, const reco::Vertex *)
 
std::vector< reco::Vertex::PointcomputeVertexInfo (const reco::VertexCollection &)
 
bool istau (const reco::Candidate *iCand)
 
bool passPFLooseId (const reco::PFJet *iJet)
 
void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

double globalThreshold_
 
METAlgo metAlgo_
 
double minCorrJetPt_
 
int minNumLeptons_
 
edm::EDGetTokenT< reco::JetCorrectormJetCorrector_
 
PFMETAlgorithmMVA mvaMEtAlgo_
 
bool mvaMEtAlgo_isInitialized_
 
PFSpecificAlgo pfMEtSpecificAlgo_
 
edm::EDGetTokenT< reco::PFJetCollectionsrcCorrJets_
 
edm::EDGetTokenT< edm::ValueMap< float > > srcJetIds_
 
std::vector< edm::EDGetTokenT< reco::CandidateView > > srcLeptons_
 
edm::EDGetTokenT< edm::View< reco::Candidate > > srcPFCandidatesView_
 
edm::EDGetTokenT< reco::PFJetCollectionsrcUncorrJets_
 
edm::EDGetTokenT< reco::VertexCollectionsrcVertices_
 
bool useType1_
 
int verbosity_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

Definition at line 43 of file PFMETProducerMVA.h.

Member Typedef Documentation

◆ vInputTag

typedef std::vector<edm::InputTag> reco::PFMETProducerMVA::vInputTag
private

Definition at line 92 of file PFMETProducerMVA.h.

Constructor & Destructor Documentation

◆ PFMETProducerMVA()

PFMETProducerMVA::PFMETProducerMVA ( const edm::ParameterSet cfg)

Definition at line 10 of file PFMETProducerMVA.cc.

References looper::cfg, globalThreshold_, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, minCorrJetPt_, minNumLeptons_, mJetCorrector_, srcCorrJets_, srcJetIds_, srcLeptons_, srcPFCandidatesView_, srcUncorrJets_, srcVertices_, useType1_, and verbosity_.

11  : mvaMEtAlgo_(cfg, consumesCollector()), mvaMEtAlgo_isInitialized_(false) {
12  srcCorrJets_ = consumes<reco::PFJetCollection>(cfg.getParameter<edm::InputTag>("srcCorrJets"));
13  srcUncorrJets_ = consumes<reco::PFJetCollection>(cfg.getParameter<edm::InputTag>("srcUncorrJets"));
14  srcJetIds_ = consumes<edm::ValueMap<float> >(cfg.getParameter<edm::InputTag>("srcMVAPileupJetId"));
15  srcPFCandidatesView_ = consumes<reco::CandidateView>(cfg.getParameter<edm::InputTag>("srcPFCandidates"));
16  srcVertices_ = consumes<reco::VertexCollection>(cfg.getParameter<edm::InputTag>("srcVertices"));
17  vInputTag srcLeptonsTags = cfg.getParameter<vInputTag>("srcLeptons");
18  for (vInputTag::const_iterator it = srcLeptonsTags.begin(); it != srcLeptonsTags.end(); it++) {
19  srcLeptons_.push_back(consumes<reco::CandidateView>(*it));
20  }
21  mJetCorrector_ = consumes<reco::JetCorrector>(cfg.getParameter<edm::InputTag>("corrector"));
22  minNumLeptons_ = cfg.getParameter<int>("minNumLeptons");
23 
24  globalThreshold_ = cfg.getParameter<double>("globalThreshold");
25 
26  minCorrJetPt_ = cfg.getParameter<double>("minCorrJetPt");
27  useType1_ = cfg.getParameter<bool>("useType1");
28 
29  verbosity_ = (cfg.exists("verbosity")) ? cfg.getParameter<int>("verbosity") : 0;
30 
31  produces<reco::PFMETCollection>();
32 }
PFMETAlgorithmMVA mvaMEtAlgo_
std::vector< edm::EDGetTokenT< reco::CandidateView > > srcLeptons_
edm::EDGetTokenT< edm::ValueMap< float > > srcJetIds_
edm::EDGetTokenT< edm::View< reco::Candidate > > srcPFCandidatesView_
edm::EDGetTokenT< reco::PFJetCollection > srcCorrJets_
std::vector< edm::InputTag > vInputTag
edm::EDGetTokenT< reco::VertexCollection > srcVertices_
edm::EDGetTokenT< reco::JetCorrector > mJetCorrector_
edm::EDGetTokenT< reco::PFJetCollection > srcUncorrJets_

◆ ~PFMETProducerMVA()

PFMETProducerMVA::~PFMETProducerMVA ( )
override

Definition at line 34 of file PFMETProducerMVA.cc.

34 {}

Member Function Documentation

◆ chargedEnFrac()

double PFMETProducerMVA::chargedEnFrac ( const reco::Candidate iCand,
const reco::CandidateView pfCandidates,
const reco::Vertex hardScatterVertex 
)
private

Definition at line 335 of file PFMETProducerMVA.cc.

References reco::charge(), chargedFracInCone(), reco::Candidate::isElectron(), reco::Candidate::isMuon(), reco::Candidate::isPhoton(), zmumugammaAnalyzer_cfi::pfCandidates, DiDispStaMuonMonitor_cfi::pt, reco::PFTau::signalCands(), pat::Tau::signalCands(), and edm::PtrVectorBase::size().

Referenced by computeLeptonInfo().

337  {
338  if (iCand->isMuon()) {
339  return 1;
340  }
341  if (iCand->isElectron()) {
342  return 1.;
343  }
344  if (iCand->isPhoton()) {
345  return chargedFracInCone(iCand, pfCandidates, hardScatterVertex);
346  }
347  double lPtTot = 0;
348  double lPtCharged = 0;
349  const reco::PFTau* lPFTau = nullptr;
350  lPFTau = dynamic_cast<const reco::PFTau*>(iCand);
351  if (lPFTau != nullptr) {
352  for (UInt_t i0 = 0; i0 < lPFTau->signalCands().size(); i0++) {
353  lPtTot += (lPFTau->signalCands())[i0]->pt();
354  if ((lPFTau->signalCands())[i0]->charge() == 0)
355  continue;
356  lPtCharged += (lPFTau->signalCands())[i0]->pt();
357  }
358  } else {
359  const pat::Tau* lPatPFTau = nullptr;
360  lPatPFTau = dynamic_cast<const pat::Tau*>(iCand);
361  if (lPatPFTau != nullptr) {
362  for (UInt_t i0 = 0; i0 < lPatPFTau->signalCands().size(); i0++) {
363  lPtTot += (lPatPFTau->signalCands())[i0]->pt();
364  if ((lPatPFTau->signalCands())[i0]->charge() == 0)
365  continue;
366  lPtCharged += (lPatPFTau->signalCands())[i0]->pt();
367  }
368  }
369  }
370  if (lPtTot == 0)
371  lPtTot = 1.;
372  return lPtCharged / lPtTot;
373 }
size_type size() const
Size of the RefVector.
Definition: PtrVectorBase.h:75
const std::vector< reco::CandidatePtr > & signalCands() const
Candidates in signal region.
Definition: PFTau.cc:74
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr float charge(ConstView const &tracks, int32_t i)
Definition: TracksSoA.h:73
double chargedFracInCone(const reco::Candidate *iCand, const reco::CandidateView &pfCandidates, const reco::Vertex *hardScatterVertex, double iDRMax=0.2)
virtual bool isPhoton() const =0
Analysis-level tau class.
Definition: Tau.h:53
virtual bool isMuon() const =0
reco::CandidatePtrVector signalCands() const
virtual bool isElectron() const =0

◆ chargedFracInCone()

double PFMETProducerMVA::chargedFracInCone ( const reco::Candidate iCand,
const reco::CandidateView pfCandidates,
const reco::Vertex hardScatterVertex,
double  iDRMax = 0.2 
)
private

Definition at line 402 of file PFMETProducerMVA.cc.

References funct::abs(), reco::deltaR2(), pat::PackedCandidate::dz(), reco::PFCandidate::gsfTrackRef(), edm::Ref< C, T, F >::isNonnull(), reco::Candidate::p4(), zmumugammaAnalyzer_cfi::pfCandidates, reco::Vertex::position(), reco::Candidate::pt(), and reco::PFCandidate::trackRef().

Referenced by chargedEnFrac().

405  {
406  double iDR2Max = iDRMax * iDRMax;
407  reco::Candidate::LorentzVector lVis(0, 0, 0, 0);
408  for (reco::CandidateView::const_iterator pfCandidate = pfCandidates.begin(); pfCandidate != pfCandidates.end();
409  ++pfCandidate) {
410  if (deltaR2(iCand->p4(), pfCandidate->p4()) > iDR2Max)
411  continue;
412  double dZ = -999.; // PH: If no vertex is reconstructed in the event
413  // or PFCandidate has no track, set dZ to -999
414  if (hardScatterVertex) {
415  const reco::PFCandidate* pfc = dynamic_cast<const reco::PFCandidate*>((&(*pfCandidate)));
416  if (pfc != nullptr) { //PF candidate for RECO and PAT levels
417  if (pfc->trackRef().isNonnull())
418  dZ = std::abs(pfc->trackRef()->dz(hardScatterVertex->position()));
419  else if (pfc->gsfTrackRef().isNonnull())
420  dZ = std::abs(pfc->gsfTrackRef()->dz(hardScatterVertex->position()));
421  } else { //if not, then packedCandidate for miniAOD level
422  const pat::PackedCandidate* pfc = dynamic_cast<const pat::PackedCandidate*>(&(*pfCandidate));
423  dZ = std::abs(pfc->dz(hardScatterVertex->position()));
424  }
425  }
426  if (std::abs(dZ) > 0.1)
427  continue;
428  lVis += pfCandidate->p4();
429  }
430  return lVis.pt() / iCand->pt();
431 }
reco::GsfTrackRef gsfTrackRef() const
Definition: PFCandidate.cc:469
virtual double pt() const =0
transverse momentum
const Point & position() const
position
Definition: Vertex.h:128
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:88
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:437
virtual float dz(size_t ipv=0) const
dz with respect to the PV[ipv]
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector

◆ computeJetInfo()

std::vector< reco::PUSubMETCandInfo > PFMETProducerMVA::computeJetInfo ( const reco::PFJetCollection uncorrJets,
const edm::Handle< reco::PFJetCollection > &  corrJets,
const edm::ValueMap< float > &  jetIds,
const reco::VertexCollection vertices,
const reco::Vertex hardScatterVertex,
const reco::JetCorrector iCorr,
edm::Event iEvent,
const edm::EventSetup iSetup,
std::vector< reco::PUSubMETCandInfo > &  iLeptons,
std::vector< reco::PUSubMETCandInfo > &  iCands 
)
private

Definition at line 206 of file PFMETProducerMVA.cc.

References funct::abs(), reco::PUSubMETCandInfo::chargedEnFrac(), reco::JetCorrector::correction(), reco::deltaR2(), dR2Max, dR2Min, minCorrJetPt_, reco::PUSubMETCandInfo::p4(), passPFLooseId(), reco::PUSubMETCandInfo::setChargedEnFrac(), reco::PUSubMETCandInfo::setDZ(), reco::PUSubMETCandInfo::setMvaVal(), reco::PUSubMETCandInfo::setP4(), jetUpdater_cfi::sort, and useType1_.

Referenced by produce().

215  {
216  std::vector<reco::PUSubMETCandInfo> retVal;
217  for (reco::PFJetCollection::const_iterator uncorrJet = uncorrJets.begin(); uncorrJet != uncorrJets.end();
218  ++uncorrJet) {
219  // for ( reco::PFJetCollection::const_iterator corrJet = corrJets.begin();
220  // corrJet != corrJets.end(); ++corrJet ) {
221  auto corrJet = corrJets->begin();
222  for (size_t cjIdx = 0; cjIdx < corrJets->size(); ++cjIdx, ++corrJet) {
223  reco::PFJetRef corrJetRef(corrJets, cjIdx);
224 
225  // match corrected and uncorrected jets
226  if (uncorrJet->jetArea() != corrJet->jetArea())
227  continue;
228  if (deltaR2(corrJet->p4(), uncorrJet->p4()) > dR2Min)
229  continue;
230 
231  // check that jet passes loose PFJet id.
232  if (!passPFLooseId(&(*uncorrJet)))
233  continue;
234 
235  // compute jet energy correction factor
236  // (= ratio of corrected/uncorrected jet Pt)
237  //double jetEnCorrFactor = corrJet->pt()/uncorrJet->pt();
238  reco::PUSubMETCandInfo jetInfo;
239 
240  // PH: apply jet energy corrections for all Jets ignoring recommendations
241  jetInfo.setP4(corrJet->p4());
242  double lType1Corr = 0;
243  if (useType1_) { //Compute the type 1 correction ===> This code is crap
244  double pCorr = iCorrector.correction(*uncorrJet);
245  lType1Corr = std::abs(corrJet->pt() - pCorr * uncorrJet->pt());
246  TLorentzVector pVec;
247  pVec.SetPtEtaPhiM(lType1Corr, 0, corrJet->phi(), 0);
249  pType1Corr.SetCoordinates(pVec.Px(), pVec.Py(), pVec.Pz(), pVec.E());
250  //Filter to leptons
251  bool pOnLepton = false;
252  for (unsigned int i0 = 0; i0 < iLeptons.size(); i0++) {
253  if (deltaR2(iLeptons[i0].p4(), corrJet->p4()) < dR2Max) {
254  pOnLepton = true;
255  break;
256  }
257  }
258  //Add it to PF Collection
259  if (corrJet->pt() > 10 && !pOnLepton) {
260  reco::PUSubMETCandInfo pfCandidateInfo;
261  pfCandidateInfo.setP4(pType1Corr);
262  pfCandidateInfo.setDZ(-999);
263  iCands.push_back(pfCandidateInfo);
264  }
265  //Scale
266  lType1Corr = (pCorr * uncorrJet->pt() - uncorrJet->pt());
267  lType1Corr /= corrJet->pt();
268  }
269 
270  // check that jet Pt used to compute MVA based jet id. is above threshold
271  if (!(jetInfo.p4().pt() > minCorrJetPt_))
272  continue;
273 
274  jetInfo.setMvaVal(jetIds[corrJetRef]);
275  float chEnF = (uncorrJet->chargedEmEnergy() + uncorrJet->chargedHadronEnergy() + uncorrJet->chargedMuEnergy()) /
276  uncorrJet->energy();
277  if (useType1_)
278  chEnF += lType1Corr * (1 - jetInfo.chargedEnFrac());
279  jetInfo.setChargedEnFrac(chEnF);
280  retVal.push_back(jetInfo);
281  break;
282  }
283  }
284 
285  //order jets per pt
286  std::sort(retVal.begin(), retVal.end());
287 
288  return retVal;
289 }
const double dR2Max
void setDZ(float dZ)
Definition: PUSubMETData.h:47
void setP4(const reco::Candidate::LorentzVector p4)
Definition: PUSubMETData.h:46
void setMvaVal(float mva)
Definition: PUSubMETData.h:56
bool passPFLooseId(const reco::PFJet *iJet)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const reco::Candidate::LorentzVector & p4() const
Definition: PUSubMETData.h:30
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
void setChargedEnFrac(float chEnF)
Definition: PUSubMETData.h:57
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
float chargedEnFrac() const
Definition: PUSubMETData.h:41
const double dR2Min

◆ computeLeptonInfo()

std::vector< reco::PUSubMETCandInfo > PFMETProducerMVA::computeLeptonInfo ( const std::vector< edm::EDGetTokenT< reco::CandidateView > > &  srcLeptons_,
const reco::CandidateView pfCandidates,
const reco::Vertex hardScatterVertex,
int &  lId,
bool &  lHasPhotons,
edm::Event iEvent 
)
private

Definition at line 140 of file PFMETProducerMVA.cc.

References funct::abs(), edm::View< T >::begin(), chargedEnFrac(), reco::deltaR2(), dPtMatch, dR2Max, edm::View< T >::end(), edm::Event::getByToken(), istau(), AK4CaloJetsMCFlavour_cff::leptonInfo, HLT_2024v10_cff::leptons, reco::PUSubMETCandInfo::setChargedEnFrac(), reco::PUSubMETCandInfo::setP4(), srcLeptons_, and trackerHitRTTI::vector.

Referenced by produce().

146  {
147  std::vector<reco::PUSubMETCandInfo> leptonInfo;
148 
149  for (std::vector<edm::EDGetTokenT<reco::CandidateView> >::const_iterator srcLeptons_i = srcLeptons_.begin();
150  srcLeptons_i != srcLeptons_.end();
151  ++srcLeptons_i) {
153  evt.getByToken(*srcLeptons_i, leptons);
154  for (reco::CandidateView::const_iterator lepton1 = leptons->begin(); lepton1 != leptons->end(); ++lepton1) {
155  bool pMatch = false;
156  for (std::vector<edm::EDGetTokenT<reco::CandidateView> >::const_iterator srcLeptons_j = srcLeptons_.begin();
157  srcLeptons_j != srcLeptons_.end();
158  ++srcLeptons_j) {
160  evt.getByToken(*srcLeptons_j, leptons2);
161  for (reco::CandidateView::const_iterator lepton2 = leptons2->begin(); lepton2 != leptons2->end(); ++lepton2) {
162  if (&(*lepton1) == &(*lepton2)) {
163  continue;
164  }
165  if (deltaR2(lepton1->p4(), lepton2->p4()) < dR2Max) {
166  pMatch = true;
167  }
168  if (pMatch && !istau(&(*lepton1)) && istau(&(*lepton2))) {
169  pMatch = false;
170  }
171  if (pMatch && ((istau(&(*lepton1)) && istau(&(*lepton2))) || (!istau(&(*lepton1)) && !istau(&(*lepton2)))) &&
172  lepton1->pt() > lepton2->pt()) {
173  pMatch = false;
174  }
175  if (pMatch && lepton1->pt() == lepton2->pt()) {
176  pMatch = false;
177  for (unsigned int i0 = 0; i0 < leptonInfo.size(); i0++) {
178  if (std::abs(lepton1->pt() - leptonInfo[i0].p4().pt()) < dPtMatch) {
179  pMatch = true;
180  break;
181  }
182  }
183  }
184  if (pMatch)
185  break;
186  }
187  if (pMatch)
188  break;
189  }
190  if (pMatch)
191  continue;
192  reco::PUSubMETCandInfo pLeptonInfo;
193  pLeptonInfo.setP4(lepton1->p4());
194  pLeptonInfo.setChargedEnFrac(chargedEnFrac(&(*lepton1), pfCandidates_view, hardScatterVertex));
195  leptonInfo.push_back(pLeptonInfo);
196  if (lepton1->isPhoton()) {
197  lHasPhotons = true;
198  }
199  }
200  lId++;
201  }
202 
203  return leptonInfo;
204 }
const double dR2Max
std::vector< edm::EDGetTokenT< reco::CandidateView > > srcLeptons_
void setP4(const reco::Candidate::LorentzVector p4)
Definition: PUSubMETData.h:46
bool istau(const reco::Candidate *iCand)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const double dPtMatch
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
void setChargedEnFrac(float chEnF)
Definition: PUSubMETData.h:57
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:88
double chargedEnFrac(const reco::Candidate *iCand, const reco::CandidateView &pfCandidates, const reco::Vertex *hardScatterVertex)
const_iterator begin() const
const_iterator end() const

◆ computePFCandidateInfo()

std::vector< reco::PUSubMETCandInfo > PFMETProducerMVA::computePFCandidateInfo ( const reco::CandidateView pfCandidates,
const reco::Vertex hardScatterVertex 
)
private

Definition at line 291 of file PFMETProducerMVA.cc.

References funct::abs(), pat::PackedCandidate::dz(), reco::PFCandidate::gsfTrackRef(), edm::Ref< C, T, F >::isNonnull(), zmumugammaAnalyzer_cfi::pfCandidates, reco::Vertex::position(), reco::PUSubMETCandInfo::setDZ(), reco::PUSubMETCandInfo::setP4(), and reco::PFCandidate::trackRef().

Referenced by produce().

292  {
293  std::vector<reco::PUSubMETCandInfo> retVal;
294  for (reco::CandidateView::const_iterator pfCandidate = pfCandidates.begin(); pfCandidate != pfCandidates.end();
295  ++pfCandidate) {
296  double dZ = -999.; // PH: If no vertex is reconstructed in the event
297  // or PFCandidate has no track, set dZ to -999
298  if (hardScatterVertex) {
299  const reco::PFCandidate* pfc = dynamic_cast<const reco::PFCandidate*>(&(*pfCandidate));
300  if (pfc != nullptr) { //PF candidate for RECO and PAT levels
301  if (pfc->trackRef().isNonnull())
302  dZ = std::abs(pfc->trackRef()->dz(hardScatterVertex->position()));
303  else if (pfc->gsfTrackRef().isNonnull())
304  dZ = std::abs(pfc->gsfTrackRef()->dz(hardScatterVertex->position()));
305  } else { //if not, then packedCandidate for miniAOD level
306  const pat::PackedCandidate* pfc = dynamic_cast<const pat::PackedCandidate*>(&(*pfCandidate));
307  dZ = std::abs(pfc->dz(hardScatterVertex->position()));
308  //exact dz=zero corresponds to the -999 case for pfcandidate
309  if (dZ == 0) {
310  dZ = -999;
311  }
312  }
313  }
314  reco::PUSubMETCandInfo pfCandidateInfo;
315  pfCandidateInfo.setP4(pfCandidate->p4());
316  pfCandidateInfo.setDZ(dZ);
317  retVal.push_back(pfCandidateInfo);
318  }
319  return retVal;
320 }
reco::GsfTrackRef gsfTrackRef() const
Definition: PFCandidate.cc:469
void setDZ(float dZ)
Definition: PUSubMETData.h:47
const Point & position() const
position
Definition: Vertex.h:128
void setP4(const reco::Candidate::LorentzVector p4)
Definition: PUSubMETData.h:46
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:88
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:437
virtual float dz(size_t ipv=0) const
dz with respect to the PV[ipv]

◆ computeVertexInfo()

std::vector< reco::Vertex::Point > PFMETProducerMVA::computeVertexInfo ( const reco::VertexCollection vertices)
private

Definition at line 322 of file PFMETProducerMVA.cc.

References funct::abs(), bphysicsOniaDQM_cfi::vertex, and AlignmentTracksFromVertexSelector_cfi::vertices.

Referenced by produce().

322  {
323  std::vector<reco::Vertex::Point> retVal;
324  for (reco::VertexCollection::const_iterator vertex = vertices.begin(); vertex != vertices.end(); ++vertex) {
325  if (std::abs(vertex->z()) > 24.)
326  continue;
327  if (vertex->ndof() < 4.)
328  continue;
329  if (vertex->position().Rho() > 2.)
330  continue;
331  retVal.push_back(vertex->position());
332  }
333  return retVal;
334 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22

◆ istau()

bool PFMETProducerMVA::istau ( const reco::Candidate iCand)
private

Definition at line 375 of file PFMETProducerMVA.cc.

References reco::Candidate::isElectron(), reco::Candidate::isMuon(), and reco::Candidate::isPhoton().

Referenced by computeLeptonInfo().

375  {
376  if (iCand->isMuon())
377  return false;
378  if (iCand->isElectron())
379  return false;
380  if (iCand->isPhoton())
381  return false;
382  return true;
383 }
virtual bool isPhoton() const =0
virtual bool isMuon() const =0
virtual bool isElectron() const =0

◆ passPFLooseId()

bool PFMETProducerMVA::passPFLooseId ( const reco::PFJet iJet)
private

Definition at line 384 of file PFMETProducerMVA.cc.

References funct::abs(), reco::PFJet::chargedEmEnergy(), reco::PFJet::chargedHadronEnergy(), reco::PFJet::chargedMultiplicity(), reco::LeafCandidate::energy(), reco::LeafCandidate::eta(), reco::Jet::nConstituents(), reco::PFJet::neutralEmEnergy(), and reco::PFJet::neutralHadronEnergy().

Referenced by computeJetInfo().

384  {
385  if (iJet->energy() == 0)
386  return false;
387  if (iJet->neutralHadronEnergy() / iJet->energy() > 0.99)
388  return false;
389  if (iJet->neutralEmEnergy() / iJet->energy() > 0.99)
390  return false;
391  if (iJet->nConstituents() < 2)
392  return false;
393  if (iJet->chargedHadronEnergy() / iJet->energy() <= 0 && std::abs(iJet->eta()) < 2.4)
394  return false;
395  if (iJet->chargedEmEnergy() / iJet->energy() > 0.99 && std::abs(iJet->eta()) < 2.4)
396  return false;
397  if (iJet->chargedMultiplicity() < 1 && std::abs(iJet->eta()) < 2.4)
398  return false;
399  return true;
400 }
float neutralHadronEnergy() const
neutralHadronEnergy
Definition: PFJet.h:99
int chargedMultiplicity() const
chargedMultiplicity
Definition: PFJet.h:152
float chargedEmEnergy() const
chargedEmEnergy
Definition: PFJet.h:139
float neutralEmEnergy() const
neutralEmEnergy
Definition: PFJet.h:147
virtual int nConstituents() const
of constituents
Definition: Jet.h:65
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float chargedHadronEnergy() const
chargedHadronEnergy
Definition: PFJet.h:95
double energy() const final
energy
double eta() const final
momentum pseudorapidity

◆ produce()

void PFMETProducerMVA::produce ( edm::Event evt,
const edm::EventSetup es 
)
overrideprivate

Definition at line 36 of file PFMETProducerMVA.cc.

References computeJetInfo(), computeLeptonInfo(), computePFCandidateInfo(), computeVertexInfo(), l1tPFClustersFromHGC3DClusters_cfi::corrector, PFMETAlgorithmMVA::evaluateMVA(), edm::EventID::event(), edm::Event::getByToken(), PFMETAlgorithmMVA::getMEt(), PFMETAlgorithmMVA::getMEtCov(), globalThreshold_, edm::EventBase::id(), PFMETAlgorithmMVA::initialize(), AK4CaloJetsMCFlavour_cff::leptonInfo, HLT_2024v10_cff::leptons, LogDebug, edm::EventBase::luminosityBlock(), CommonMETData::met, metAlgo_, CommonMETData::mex, CommonMETData::mey, minNumLeptons_, mJetCorrector_, eostools::move(), mvaMEtAlgo_, mvaMEtAlgo_isInitialized_, HLT_2024v10_cff::numLeptons, reco::LeafCandidate::p4(), pfMEtSpecificAlgo_, reco::LeafCandidate::phi(), reco::LeafCandidate::pt(), edm::Event::put(), reco::LeafCandidate::px(), reco::LeafCandidate::py(), PFSpecificAlgo::run(), METAlgo::run(), edm::EventID::run(), PFMETAlgorithmMVA::setHasPhotons(), PFMETAlgorithmMVA::setInput(), reco::LeafCandidate::setP4(), reco::MET::setSignificanceMatrix(), srcCorrJets_, srcJetIds_, srcLeptons_, srcPFCandidatesView_, srcUncorrJets_, srcVertices_, CommonMETData::sumet, useType1_, trackerHitRTTI::vector, AlignmentTracksFromVertexSelector_cfi::vertices, and L1BJetProducer_cff::vtx.

36  {
37  // CV: check if the event is to be skipped
38  if (minNumLeptons_ > 0) {
39  int numLeptons = 0;
40  for (std::vector<edm::EDGetTokenT<reco::CandidateView> >::const_iterator srcLeptons_i = srcLeptons_.begin();
41  srcLeptons_i != srcLeptons_.end();
42  ++srcLeptons_i) {
44  evt.getByToken(*srcLeptons_i, leptons);
45  numLeptons += leptons->size();
46  }
47  if (!(numLeptons >= minNumLeptons_)) {
48  LogDebug("produce") << "<PFMETProducerMVA::produce>:" << std::endl
49  << "Run: " << evt.id().run() << ", LS: " << evt.luminosityBlock()
50  << ", Event: " << evt.id().event() << std::endl
51  << " numLeptons = " << numLeptons << ", minNumLeptons = " << minNumLeptons_
52  << " --> skipping !!" << std::endl;
53 
54  reco::PFMET pfMEt;
55  auto pfMEtCollection = std::make_unique<reco::PFMETCollection>();
56  pfMEtCollection->push_back(pfMEt);
57  evt.put(std::move(pfMEtCollection));
58  return;
59  }
60  }
61 
62  //get jet IDs
64  evt.getByToken(srcJetIds_, jetIds);
65 
66  // get jets (corrected and uncorrected)
68  evt.getByToken(srcCorrJets_, corrJets);
69 
71  evt.getByToken(srcUncorrJets_, uncorrJets);
72 
74  if (useType1_) {
76  }
77 
78  edm::Handle<reco::CandidateView> pfCandidates_view;
79  evt.getByToken(srcPFCandidatesView_, pfCandidates_view);
80 
81  // get vertices
84  // take vertex with highest sum(trackPt) as the vertex of the "hard scatter" interaction
85  // (= first entry in vertex collection)
86  const reco::Vertex* hardScatterVertex = (!vertices->empty()) ? &(vertices->front()) : nullptr;
87 
88  // get leptons
89  // (excluded from sum over PFCandidates when computing hadronic recoil)
90  int lId = 0;
91  bool lHasPhotons = false;
92  std::vector<reco::PUSubMETCandInfo> leptonInfo =
93  computeLeptonInfo(srcLeptons_, *pfCandidates_view, hardScatterVertex, lId, lHasPhotons, evt);
94 
95  // initialize MVA MET algorithm
96  // (this will load the BDTs, stored as GBRForrest objects;
97  // either in input ROOT files or in SQL-lite files/the Conditions Database)
101  }
102 
103  // reconstruct "standard" particle-flow missing Et
104  CommonMETData pfMEt_data = metAlgo_.run((*pfCandidates_view), globalThreshold_);
105  SpecificPFMETData specificPfMET = pfMEtSpecificAlgo_.run((*pfCandidates_view));
106  const reco::Candidate::LorentzVector p4(pfMEt_data.mex, pfMEt_data.mey, 0.0, pfMEt_data.met);
107  const reco::Candidate::Point vtx(0.0, 0.0, 0.0);
108  reco::PFMET pfMEt(specificPfMET, pfMEt_data.sumet, p4, vtx);
109  reco::Candidate::LorentzVector pfMEtP4_original = pfMEt.p4();
110 
111  // compute objects specific to MVA based MET reconstruction
112  std::vector<reco::PUSubMETCandInfo> pfCandidateInfo = computePFCandidateInfo(*pfCandidates_view, hardScatterVertex);
113  std::vector<reco::PUSubMETCandInfo> jetInfo = computeJetInfo(
114  *uncorrJets, corrJets, *jetIds, *vertices, hardScatterVertex, *corrector, evt, es, leptonInfo, pfCandidateInfo);
115  std::vector<reco::Vertex::Point> vertexInfo = computeVertexInfo(*vertices);
116  // compute MVA based MET and estimate of its uncertainty
117  mvaMEtAlgo_.setInput(leptonInfo, jetInfo, pfCandidateInfo, vertexInfo);
118  mvaMEtAlgo_.setHasPhotons(lHasPhotons);
120  pfMEt.setP4(mvaMEtAlgo_.getMEt());
122 
123  LogDebug("produce") << "Run: " << evt.id().run() << ", LS: " << evt.luminosityBlock()
124  << ", Event: " << evt.id().event() << std::endl
125  << " PFMET: Pt = " << pfMEtP4_original.pt() << ", phi = " << pfMEtP4_original.phi() << " "
126  << "(Px = " << pfMEtP4_original.px() << ", Py = " << pfMEtP4_original.py() << ")" << std::endl
127  << " MVA MET: Pt = " << pfMEt.pt() << " phi = " << pfMEt.phi() << " (Px = " << pfMEt.px()
128  << ", Py = " << pfMEt.py() << ")" << std::endl
129  << " Cov:" << std::endl
130  << (mvaMEtAlgo_.getMEtCov())(0, 0) << " " << (mvaMEtAlgo_.getMEtCov())(0, 1) << std::endl
131  << (mvaMEtAlgo_.getMEtCov())(1, 0) << " " << (mvaMEtAlgo_.getMEtCov())(1, 1) << std::endl
132  << std::endl;
133 
134  // add PFMET object to the event
135  auto pfMEtCollection = std::make_unique<reco::PFMETCollection>();
136  pfMEtCollection->push_back(pfMEt);
137  evt.put(std::move(pfMEtCollection));
138 }
PFMETAlgorithmMVA mvaMEtAlgo_
SpecificPFMETData run(const edm::View< reco::Candidate > &pfCands, edm::ValueMap< float > const *weights=nullptr)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
std::vector< edm::EDGetTokenT< reco::CandidateView > > srcLeptons_
double pt() const final
transverse momentum
PFSpecificAlgo pfMEtSpecificAlgo_
std::vector< reco::Vertex::Point > computeVertexInfo(const reco::VertexCollection &)
void setSignificanceMatrix(const reco::METCovMatrix &matrix)
Definition: MET.cc:142
const reco::METCovMatrix & getMEtCov() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:65
void setInput(const std::vector< reco::PUSubMETCandInfo > &, const std::vector< reco::PUSubMETCandInfo > &, const std::vector< reco::PUSubMETCandInfo > &, const std::vector< reco::Vertex::Point > &)
const LorentzVector & p4() const final
four-momentum Lorentz vector
edm::EDGetTokenT< edm::ValueMap< float > > srcJetIds_
reco::Candidate::LorentzVector getMEt() const
double px() const final
x coordinate of momentum vector
edm::EDGetTokenT< edm::View< reco::Candidate > > srcPFCandidatesView_
edm::EDGetTokenT< reco::PFJetCollection > srcCorrJets_
edm::EDGetTokenT< reco::VertexCollection > srcVertices_
std::vector< reco::PUSubMETCandInfo > computeLeptonInfo(const std::vector< edm::EDGetTokenT< reco::CandidateView > > &srcLeptons_, const reco::CandidateView &pfCandidates, const reco::Vertex *hardScatterVertex, int &lId, bool &lHasPhotons, edm::Event &iEvent)
Structure containing data common to all types of MET.
Definition: CommonMETData.h:12
edm::EventID id() const
Definition: EventBase.h:63
void initialize(const edm::EventSetup &)
double py() const final
y coordinate of momentum vector
MET made from Particle Flow Candidates.
void setHasPhotons(bool hasPhotons)
RunNumber_t run() const
Definition: EventID.h:38
edm::EDGetTokenT< reco::JetCorrector > mJetCorrector_
std::vector< reco::PUSubMETCandInfo > computeJetInfo(const reco::PFJetCollection &, const edm::Handle< reco::PFJetCollection > &, const edm::ValueMap< float > &, const reco::VertexCollection &, const reco::Vertex *, const reco::JetCorrector &iCorr, edm::Event &iEvent, const edm::EventSetup &iSetup, std::vector< reco::PUSubMETCandInfo > &iLeptons, std::vector< reco::PUSubMETCandInfo > &iCands)
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
math::XYZPoint Point
point in the space
Definition: Candidate.h:40
CommonMETData run(const edm::View< reco::Candidate > &candidates, double globalThreshold=0.0, edm::ValueMap< float > const *weights=nullptr)
Definition: METAlgo.cc:16
edm::EDGetTokenT< reco::PFJetCollection > srcUncorrJets_
double phi() const final
momentum azimuthal angle
void setP4(const LorentzVector &p4) final
set 4-momentum
def move(src, dest)
Definition: eostools.py:511
EventNumber_t event() const
Definition: EventID.h:40
std::vector< reco::PUSubMETCandInfo > computePFCandidateInfo(const reco::CandidateView &, const reco::Vertex *)
#define LogDebug(id)

Member Data Documentation

◆ globalThreshold_

double reco::PFMETProducerMVA::globalThreshold_
private

Definition at line 98 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

◆ metAlgo_

METAlgo reco::PFMETProducerMVA::metAlgo_
private

Definition at line 102 of file PFMETProducerMVA.h.

Referenced by produce().

◆ minCorrJetPt_

double reco::PFMETProducerMVA::minCorrJetPt_
private

Definition at line 100 of file PFMETProducerMVA.h.

Referenced by computeJetInfo(), and PFMETProducerMVA().

◆ minNumLeptons_

int reco::PFMETProducerMVA::minNumLeptons_
private

Definition at line 94 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

◆ mJetCorrector_

edm::EDGetTokenT<reco::JetCorrector> reco::PFMETProducerMVA::mJetCorrector_
private

Definition at line 91 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

◆ mvaMEtAlgo_

PFMETAlgorithmMVA reco::PFMETProducerMVA::mvaMEtAlgo_
private

Definition at line 104 of file PFMETProducerMVA.h.

Referenced by produce().

◆ mvaMEtAlgo_isInitialized_

bool reco::PFMETProducerMVA::mvaMEtAlgo_isInitialized_
private

Definition at line 105 of file PFMETProducerMVA.h.

Referenced by produce().

◆ pfMEtSpecificAlgo_

PFSpecificAlgo reco::PFMETProducerMVA::pfMEtSpecificAlgo_
private

Definition at line 103 of file PFMETProducerMVA.h.

Referenced by produce().

◆ srcCorrJets_

edm::EDGetTokenT<reco::PFJetCollection> reco::PFMETProducerMVA::srcCorrJets_
private

Definition at line 85 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

◆ srcJetIds_

edm::EDGetTokenT<edm::ValueMap<float> > reco::PFMETProducerMVA::srcJetIds_
private

Definition at line 87 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

◆ srcLeptons_

std::vector<edm::EDGetTokenT<reco::CandidateView> > reco::PFMETProducerMVA::srcLeptons_
private

Definition at line 93 of file PFMETProducerMVA.h.

Referenced by computeLeptonInfo(), PFMETProducerMVA(), and produce().

◆ srcPFCandidatesView_

edm::EDGetTokenT<edm::View<reco::Candidate> > reco::PFMETProducerMVA::srcPFCandidatesView_
private

Definition at line 89 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

◆ srcUncorrJets_

edm::EDGetTokenT<reco::PFJetCollection> reco::PFMETProducerMVA::srcUncorrJets_
private

Definition at line 86 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

◆ srcVertices_

edm::EDGetTokenT<reco::VertexCollection> reco::PFMETProducerMVA::srcVertices_
private

Definition at line 90 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

◆ useType1_

bool reco::PFMETProducerMVA::useType1_
private

Definition at line 96 of file PFMETProducerMVA.h.

Referenced by computeJetInfo(), PFMETProducerMVA(), and produce().

◆ verbosity_

int reco::PFMETProducerMVA::verbosity_
private

Definition at line 108 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA().