CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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<> edm::stream::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 PFMETProducerMVA (const edm::ParameterSet &)
 
 ~PFMETProducerMVA ()
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
- Public Member Functions inherited from edm::stream::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducerBase ()
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Types

typedef std::vector
< edm::InputTag
vInputTag
 

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::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)
 
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)
 
std::vector
< reco::PUSubMETCandInfo
computePFCandidateInfo (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 &)
 

Private Attributes

double globalThreshold_
 
METAlgo metAlgo_
 
double minCorrJetPt_
 
int minNumLeptons_
 
edm::EDGetTokenT
< reco::JetCorrector
mJetCorrector_
 
PFMETAlgorithmMVA mvaMEtAlgo_
 
bool mvaMEtAlgo_isInitialized_
 
PFSpecificAlgo pfMEtSpecificAlgo_
 
edm::EDGetTokenT
< reco::PFJetCollection
srcCorrJets_
 
edm::EDGetTokenT
< edm::ValueMap< float > > 
srcJetIds_
 
std::vector< edm::EDGetTokenT
< reco::CandidateView > > 
srcLeptons_
 
edm::EDGetTokenT< edm::View
< reco::Candidate > > 
srcPFCandidatesView_
 
edm::EDGetTokenT
< reco::PFJetCollection
srcUncorrJets_
 
edm::EDGetTokenT
< reco::VertexCollection
srcVertices_
 
bool useType1_
 
int verbosity_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T...> CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T...> HasAbility
 
typedef
CacheTypes::LuminosityBlockCache 
LuminosityBlockCache
 
typedef
LuminosityBlockContextT
< LuminosityBlockCache,
RunCache, GlobalCache
LuminosityBlockContext
 
typedef
CacheTypes::LuminosityBlockSummaryCache 
LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache,
GlobalCache
RunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Public Types inherited from edm::stream::EDProducerBase
typedef EDProducerAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::stream::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 45 of file PFMETProducerMVA.h.

Member Typedef Documentation

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

Definition at line 85 of file PFMETProducerMVA.h.

Constructor & Destructor Documentation

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

Definition at line 9 of file PFMETProducerMVA.cc.

References edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), globalThreshold_, minCorrJetPt_, minNumLeptons_, mJetCorrector_, srcCorrJets_, srcJetIds_, srcLeptons_, srcPFCandidatesView_, srcUncorrJets_, srcVertices_, useType1_, and verbosity_.

10  : mvaMEtAlgo_(cfg),
12 {
13  srcCorrJets_ = consumes<reco::PFJetCollection>(cfg.getParameter<edm::InputTag>("srcCorrJets"));
14  srcUncorrJets_ = consumes<reco::PFJetCollection>(cfg.getParameter<edm::InputTag>("srcUncorrJets"));
15  srcJetIds_ = consumes<edm::ValueMap<float> >(cfg.getParameter<edm::InputTag>("srcMVAPileupJetId"));
16  srcPFCandidatesView_ = consumes<reco::CandidateView>(cfg.getParameter<edm::InputTag>("srcPFCandidates"));
17  srcVertices_ = consumes<reco::VertexCollection>(cfg.getParameter<edm::InputTag>("srcVertices"));
18  vInputTag srcLeptonsTags = cfg.getParameter<vInputTag>("srcLeptons");
19  for(vInputTag::const_iterator it=srcLeptonsTags.begin();it!=srcLeptonsTags.end();it++) {
20  srcLeptons_.push_back( consumes<reco::CandidateView >( *it ) );
21  }
22  mJetCorrector_ = consumes<reco::JetCorrector>(cfg.getParameter<edm::InputTag>("corrector"));
23  minNumLeptons_ = cfg.getParameter<int>("minNumLeptons");
24 
25  globalThreshold_ = cfg.getParameter<double>("globalThreshold");
26 
27  minCorrJetPt_ = cfg.getParameter<double> ("minCorrJetPt");
28  useType1_ = cfg.getParameter<bool> ("useType1");
29 
30  verbosity_ = ( cfg.exists("verbosity") ) ?
31  cfg.getParameter<int>("verbosity") : 0;
32 
33  produces<reco::PFMETCollection>();
34 }
PFMETAlgorithmMVA mvaMEtAlgo_
T getParameter(std::string const &) const
std::vector< edm::EDGetTokenT< reco::CandidateView > > srcLeptons_
bool exists(std::string const &parameterName) const
checks if a parameter exists
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 ( )

Definition at line 36 of file PFMETProducerMVA.cc.

36 {}

Member Function Documentation

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

Definition at line 305 of file PFMETProducerMVA.cc.

References RecoTauCleanerPlugins::charge, chargedFracInCone(), reco::Candidate::isElectron(), reco::Candidate::isMuon(), reco::Candidate::isPhoton(), EnergyCorrector::pt, pat::Tau::signalCands(), reco::PFTau::signalPFCands(), and edm::PtrVectorBase::size().

Referenced by computeLeptonInfo().

306  {
307  if(iCand->isMuon()) {
308  return 1;
309  }
310  if(iCand->isElectron()) {
311  return 1.;
312  }
313  if(iCand->isPhoton() ) {return chargedFracInCone(iCand, pfCandidates,hardScatterVertex);}
314  double lPtTot = 0; double lPtCharged = 0;
315  const reco::PFTau *lPFTau = 0;
316  lPFTau = dynamic_cast<const reco::PFTau*>(iCand);
317  if(lPFTau != nullptr) {
318  for (UInt_t i0 = 0; i0 < lPFTau->signalPFCands().size(); i0++) {
319  lPtTot += (lPFTau->signalPFCands())[i0]->pt();
320  if((lPFTau->signalPFCands())[i0]->charge() == 0) continue;
321  lPtCharged += (lPFTau->signalPFCands())[i0]->pt();
322  }
323  }
324  else {
325  const pat::Tau *lPatPFTau = nullptr;
326  lPatPFTau = dynamic_cast<const pat::Tau*>(iCand);
327  if(lPatPFTau != nullptr) {
328  for (UInt_t i0 = 0; i0 < lPatPFTau->signalCands().size(); i0++) {
329  lPtTot += (lPatPFTau->signalCands())[i0]->pt();
330  if((lPatPFTau->signalCands())[i0]->charge() == 0) continue;
331  lPtCharged += (lPatPFTau->signalCands())[i0]->pt();
332  }
333  }
334  }
335  if(lPtTot == 0) lPtTot = 1.;
336  return lPtCharged/lPtTot;
337 }
size_type size() const
Size of the RefVector.
Definition: PtrVectorBase.h:78
reco::CandidatePtrVector signalCands() const
const std::vector< reco::PFCandidatePtr > & signalPFCands() const
PFCandidates in signal region.
Definition: PFTau.cc:78
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:56
virtual bool isMuon() const =0
virtual bool isElectron() const =0
double PFMETProducerMVA::chargedFracInCone ( const reco::Candidate iCand,
const reco::CandidateView pfCandidates,
const reco::Vertex hardScatterVertex,
double  iDRMax = 0.2 
)
private

Definition at line 356 of file PFMETProducerMVA.cc.

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

Referenced by chargedEnFrac().

359 {
360  double iDR2Max = iDRMax*iDRMax;
361  reco::Candidate::LorentzVector lVis(0,0,0,0);
362  for ( reco::CandidateView::const_iterator pfCandidate = pfCandidates.begin();
363  pfCandidate != pfCandidates.end(); ++pfCandidate ) {
364  if(deltaR2(iCand->p4(),pfCandidate->p4()) > iDR2Max) continue;
365  double dZ = -999.; // PH: If no vertex is reconstructed in the event
366  // or PFCandidate has no track, set dZ to -999
367  if ( hardScatterVertex ) {
368  const reco::PFCandidate* pfc = dynamic_cast<const reco::PFCandidate* >( (&(*pfCandidate)) );
369  if( pfc != nullptr ) { //PF candidate for RECO and PAT levels
370  if ( pfc->trackRef().isNonnull() ) dZ = std::abs(pfc->trackRef()->dz(hardScatterVertex->position()));
371  else if ( pfc->gsfTrackRef().isNonnull() ) dZ = std::abs(pfc->gsfTrackRef()->dz(hardScatterVertex->position()));
372  }
373  else { //if not, then packedCandidate for miniAOD level
374  const pat::PackedCandidate* pfc = dynamic_cast<const pat::PackedCandidate* >( &(*pfCandidate) );
375  dZ = std::abs( pfc->dz( hardScatterVertex->position() ) );
376  }
377  }
378  if(std::abs(dZ) > 0.1) continue;
379  lVis += pfCandidate->p4();
380  }
381  return lVis.pt()/iCand->pt();
382 }
virtual float dz(size_t ipv=0) const
dz with respect to the PV[ipv]
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
virtual double pt() const =0
transverse momentum
const Point & position() const
position
Definition: Vertex.h:106
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:433
const_iterator begin() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double deltaR2(const T1 &t1, const T2 &t2)
Definition: deltaR.h:36
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:39
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:85
reco::GsfTrackRef gsfTrackRef() const
Definition: PFCandidate.cc:471
const_iterator end() const
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
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 191 of file PFMETProducerMVA.cc.

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

Referenced by produce().

198 {
199  std::vector<reco::PUSubMETCandInfo> retVal;
200  for ( reco::PFJetCollection::const_iterator uncorrJet = uncorrJets.begin();
201  uncorrJet != uncorrJets.end(); ++uncorrJet ) {
202  // for ( reco::PFJetCollection::const_iterator corrJet = corrJets.begin();
203  // corrJet != corrJets.end(); ++corrJet ) {
204  auto corrJet = corrJets->begin();
205  for( size_t cjIdx=0;cjIdx<corrJets->size();++cjIdx, ++corrJet) {
206  reco::PFJetRef corrJetRef( corrJets, cjIdx );
207 
208  // match corrected and uncorrected jets
209  if ( uncorrJet->jetArea() != corrJet->jetArea() ) continue;
210  if ( deltaR2(corrJet->p4(),uncorrJet->p4()) > dR2Min ) continue;
211 
212  // check that jet passes loose PFJet id.
213  if(!passPFLooseId(&(*uncorrJet))) continue;
214 
215  // compute jet energy correction factor
216  // (= ratio of corrected/uncorrected jet Pt)
217  //double jetEnCorrFactor = corrJet->pt()/uncorrJet->pt();
218  reco::PUSubMETCandInfo jetInfo;
219 
220  // PH: apply jet energy corrections for all Jets ignoring recommendations
221  jetInfo.setP4( corrJet->p4() );
222  double lType1Corr = 0;
223  if(useType1_) { //Compute the type 1 correction ===> This code is crap
224  double pCorr = iCorrector.correction(*uncorrJet);
225  lType1Corr = std::abs(corrJet->pt()-pCorr*uncorrJet->pt());
226  TLorentzVector pVec; pVec.SetPtEtaPhiM(lType1Corr,0,corrJet->phi(),0);
227  reco::Candidate::LorentzVector pType1Corr; pType1Corr.SetCoordinates(pVec.Px(),pVec.Py(),pVec.Pz(),pVec.E());
228  //Filter to leptons
229  bool pOnLepton = false;
230  for(unsigned int i0 = 0; i0 < iLeptons.size(); i0++) {
231  if(deltaR2(iLeptons[i0].p4(),corrJet->p4()) < dR2Max) {pOnLepton = true; break;}
232  }
233  //Add it to PF Collection
234  if(corrJet->pt() > 10 && !pOnLepton) {
235  reco::PUSubMETCandInfo pfCandidateInfo;
236  pfCandidateInfo.setP4( pType1Corr );
237  pfCandidateInfo.setDZ( -999 );
238  iCands.push_back(pfCandidateInfo);
239  }
240  //Scale
241  lType1Corr = (pCorr*uncorrJet->pt()-uncorrJet->pt());
242  lType1Corr /=corrJet->pt();
243  }
244 
245  // check that jet Pt used to compute MVA based jet id. is above threshold
246  if ( !(jetInfo.p4().pt() > minCorrJetPt_) ) continue;
247 
248 
249  jetInfo.setMvaVal( jetIds[ corrJetRef ] );
250  float chEnF = (uncorrJet->chargedEmEnergy() + uncorrJet->chargedHadronEnergy() + uncorrJet->chargedMuEnergy() )/uncorrJet->energy();
251  if(useType1_) chEnF += lType1Corr*(1-jetInfo.chargedEnFrac() );
252  jetInfo.setChargedEnFrac( chEnF );
253  retVal.push_back(jetInfo);
254  break;
255  }
256  }
257 
258  //order jets per pt
259  std::sort( retVal.begin(), retVal.end() );
260 
261  return retVal;
262 }
const double dR2Max
void setDZ(float dZ)
Definition: PUSubMETData.h:51
void setP4(const reco::Candidate::LorentzVector p4)
Definition: PUSubMETData.h:50
void setMvaVal(float mva)
Definition: PUSubMETData.h:60
bool passPFLooseId(const reco::PFJet *iJet)
double p4[4]
Definition: TauolaWrapper.h:92
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double deltaR2(const T1 &t1, const T2 &t2)
Definition: deltaR.h:36
void setChargedEnFrac(float chEnF)
Definition: PUSubMETData.h:61
const double dR2Min
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
float chargedEnFrac() const
Definition: PUSubMETData.h:45
const reco::Candidate::LorentzVector & p4() const
Definition: PUSubMETData.h:34
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 141 of file PFMETProducerMVA.cc.

References funct::abs(), chargedEnFrac(), reco::deltaR2(), dPtMatch, dR2Max, edm::Event::getByToken(), istau(), HLT_25ns14e33_v1_cff::leptons, reco::PUSubMETCandInfo::setChargedEnFrac(), reco::PUSubMETCandInfo::setP4(), and srcLeptons_.

Referenced by produce().

144  {
145 
146  std::vector<reco::PUSubMETCandInfo> leptonInfo;
147 
148  for ( std::vector<edm::EDGetTokenT<reco::CandidateView > >::const_iterator srcLeptons_i = srcLeptons_.begin();
149  srcLeptons_i != srcLeptons_.end(); ++srcLeptons_i ) {
151  evt.getByToken(*srcLeptons_i, leptons);
152  for ( reco::CandidateView::const_iterator lepton1 = leptons->begin();
153  lepton1 != leptons->end(); ++lepton1 ) {
154  bool pMatch = false;
155  for ( std::vector<edm::EDGetTokenT<reco::CandidateView> >::const_iterator srcLeptons_j = srcLeptons_.begin();
156  srcLeptons_j != srcLeptons_.end(); ++srcLeptons_j ) {
158  evt.getByToken(*srcLeptons_j, leptons2);
159  for ( reco::CandidateView::const_iterator lepton2 = leptons2->begin();
160  lepton2 != leptons2->end(); ++lepton2 ) {
161  if(&(*lepton1) == &(*lepton2)) { continue; }
162  if(deltaR2(lepton1->p4(),lepton2->p4()) < dR2Max) { pMatch = true; }
163  if(pMatch && !istau(&(*lepton1)) && istau(&(*lepton2))) { pMatch = false; }
164  if(pMatch && ( (istau(&(*lepton1)) && istau(&(*lepton2))) || (!istau(&(*lepton1)) && !istau(&(*lepton2))))
165  && lepton1->pt() > lepton2->pt()) { pMatch = false; }
166  if(pMatch && lepton1->pt() == lepton2->pt()) {
167  pMatch = false;
168  for(unsigned int i0 = 0; i0 < leptonInfo.size(); i0++) {
169  if(std::abs(lepton1->pt() - leptonInfo[i0].p4().pt()) < dPtMatch) { pMatch = true; break; }
170  }
171  }
172  if(pMatch) break;
173  }
174  if(pMatch) break;
175  }
176  if(pMatch) continue;
177  reco::PUSubMETCandInfo pLeptonInfo;
178  pLeptonInfo.setP4( lepton1->p4() );
179  pLeptonInfo.setChargedEnFrac( chargedEnFrac(&(*lepton1),pfCandidates_view,hardScatterVertex) );
180  leptonInfo.push_back(pLeptonInfo);
181  if(lepton1->isPhoton()) { lHasPhotons = true; }
182  }
183  lId++;
184  }
185 
186  return leptonInfo;
187 }
const double dR2Max
std::vector< edm::EDGetTokenT< reco::CandidateView > > srcLeptons_
void setP4(const reco::Candidate::LorentzVector p4)
Definition: PUSubMETData.h:50
bool istau(const reco::Candidate *iCand)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const double dPtMatch
double deltaR2(const T1 &t1, const T2 &t2)
Definition: deltaR.h:36
void setChargedEnFrac(float chEnF)
Definition: PUSubMETData.h:61
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:85
double chargedEnFrac(const reco::Candidate *iCand, const reco::CandidateView &pfCandidates, const reco::Vertex *hardScatterVertex)
std::vector< reco::PUSubMETCandInfo > PFMETProducerMVA::computePFCandidateInfo ( const reco::CandidateView pfCandidates,
const reco::Vertex hardScatterVertex 
)
private

Definition at line 264 of file PFMETProducerMVA.cc.

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

Referenced by produce().

266 {
267  std::vector<reco::PUSubMETCandInfo> retVal;
268  for ( reco::CandidateView::const_iterator pfCandidate = pfCandidates.begin();
269  pfCandidate != pfCandidates.end(); ++pfCandidate ) {
270  double dZ = -999.; // PH: If no vertex is reconstructed in the event
271  // or PFCandidate has no track, set dZ to -999
272  if ( hardScatterVertex ) {
273  const reco::PFCandidate* pfc = dynamic_cast<const reco::PFCandidate* >( &(*pfCandidate) );
274  if( pfc != nullptr ) { //PF candidate for RECO and PAT levels
275  if ( pfc->trackRef().isNonnull() ) dZ = std::abs(pfc->trackRef()->dz(hardScatterVertex->position()));
276  else if ( pfc->gsfTrackRef().isNonnull() ) dZ = std::abs(pfc->gsfTrackRef()->dz(hardScatterVertex->position()));
277  }
278  else { //if not, then packedCandidate for miniAOD level
279  const pat::PackedCandidate* pfc = dynamic_cast<const pat::PackedCandidate* >( &(*pfCandidate) );
280  dZ = std::abs( pfc->dz( hardScatterVertex->position() ) );
281  //exact dz=zero corresponds to the -999 case for pfcandidate
282  if(dZ==0) {dZ=-999;}
283  }
284  }
285  reco::PUSubMETCandInfo pfCandidateInfo;
286  pfCandidateInfo.setP4( pfCandidate->p4() );
287  pfCandidateInfo.setDZ( dZ );
288  retVal.push_back(pfCandidateInfo);
289  }
290  return retVal;
291 }
virtual float dz(size_t ipv=0) const
dz with respect to the PV[ipv]
void setDZ(float dZ)
Definition: PUSubMETData.h:51
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
void setP4(const reco::Candidate::LorentzVector p4)
Definition: PUSubMETData.h:50
const Point & position() const
position
Definition: Vertex.h:106
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:433
const_iterator begin() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:39
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:85
reco::GsfTrackRef gsfTrackRef() const
Definition: PFCandidate.cc:471
const_iterator end() const
std::vector< reco::Vertex::Point > PFMETProducerMVA::computeVertexInfo ( const reco::VertexCollection vertices)
private

Definition at line 293 of file PFMETProducerMVA.cc.

References funct::abs().

Referenced by produce().

294 {
295  std::vector<reco::Vertex::Point> retVal;
296  for ( reco::VertexCollection::const_iterator vertex = vertices.begin();
297  vertex != vertices.end(); ++vertex ) {
298  if(std::abs(vertex->z()) > 24.) continue;
299  if(vertex->ndof() < 4.) continue;
300  if(vertex->position().Rho() > 2.) continue;
301  retVal.push_back(vertex->position());
302  }
303  return retVal;
304 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool PFMETProducerMVA::istau ( const reco::Candidate iCand)
private

Definition at line 339 of file PFMETProducerMVA.cc.

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

Referenced by computeLeptonInfo().

339  {
340  if(iCand->isMuon()) return false;
341  if(iCand->isElectron()) return false;
342  if(iCand->isPhoton()) return false;
343  return true;
344 }
virtual bool isPhoton() const =0
virtual bool isMuon() const =0
virtual bool isElectron() const =0
bool PFMETProducerMVA::passPFLooseId ( const reco::PFJet iJet)
private

Definition at line 345 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().

345  {
346  if(iJet->energy()== 0) return false;
347  if(iJet->neutralHadronEnergy()/iJet->energy() > 0.99) return false;
348  if(iJet->neutralEmEnergy()/iJet->energy() > 0.99) return false;
349  if(iJet->nConstituents() < 2) return false;
350  if(iJet->chargedHadronEnergy()/iJet->energy() <= 0 && std::abs(iJet->eta()) < 2.4 ) return false;
351  if(iJet->chargedEmEnergy()/iJet->energy() > 0.99 && std::abs(iJet->eta()) < 2.4 ) return false;
352  if(iJet->chargedMultiplicity() < 1 && std::abs(iJet->eta()) < 2.4 ) return false;
353  return true;
354 }
float chargedEmEnergy() const
chargedEmEnergy
Definition: PFJet.h:142
int chargedMultiplicity() const
chargedMultiplicity
Definition: PFJet.h:155
virtual double eta() const
momentum pseudorapidity
float neutralEmEnergy() const
neutralEmEnergy
Definition: PFJet.h:150
virtual double energy() const
energy
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
virtual int nConstituents() const
of constituents
Definition: Jet.h:65
float neutralHadronEnergy() const
neutralHadronEnergy
Definition: PFJet.h:102
float chargedHadronEnergy() const
chargedHadronEnergy
Definition: PFJet.h:98
void PFMETProducerMVA::produce ( edm::Event evt,
const edm::EventSetup es 
)
privatevirtual

Implements edm::stream::EDProducerBase.

Definition at line 38 of file PFMETProducerMVA.cc.

References computeJetInfo(), computeLeptonInfo(), computePFCandidateInfo(), computeVertexInfo(), mvaPFMET_cff::corrector, PFMETAlgorithmMVA::evaluateMVA(), edm::EventID::event(), edm::Event::getByToken(), PFMETAlgorithmMVA::getMEt(), PFMETAlgorithmMVA::getMEtCov(), globalThreshold_, edm::EventBase::id(), PFMETAlgorithmMVA::initialize(), HLT_25ns14e33_v1_cff::leptons, LogDebug, edm::EventBase::luminosityBlock(), CommonMETData::met, metAlgo_, CommonMETData::mex, CommonMETData::mey, minNumLeptons_, mJetCorrector_, mvaMEtAlgo_, mvaMEtAlgo_isInitialized_, HLT_25ns14e33_v1_cff::numLeptons, p4, 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_, and HLT_25ns14e33_v1_cff::vertices.

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

Member Data Documentation

double reco::PFMETProducerMVA::globalThreshold_
private

Definition at line 91 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

METAlgo reco::PFMETProducerMVA::metAlgo_
private

Definition at line 95 of file PFMETProducerMVA.h.

Referenced by produce().

double reco::PFMETProducerMVA::minCorrJetPt_
private

Definition at line 93 of file PFMETProducerMVA.h.

Referenced by computeJetInfo(), and PFMETProducerMVA().

int reco::PFMETProducerMVA::minNumLeptons_
private

Definition at line 87 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

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

Definition at line 84 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

PFMETAlgorithmMVA reco::PFMETProducerMVA::mvaMEtAlgo_
private

Definition at line 97 of file PFMETProducerMVA.h.

Referenced by produce().

bool reco::PFMETProducerMVA::mvaMEtAlgo_isInitialized_
private

Definition at line 98 of file PFMETProducerMVA.h.

Referenced by produce().

PFSpecificAlgo reco::PFMETProducerMVA::pfMEtSpecificAlgo_
private

Definition at line 96 of file PFMETProducerMVA.h.

Referenced by produce().

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

Definition at line 78 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

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

Definition at line 80 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

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

Definition at line 86 of file PFMETProducerMVA.h.

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

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

Definition at line 82 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

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

Definition at line 79 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

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

Definition at line 83 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

bool reco::PFMETProducerMVA::useType1_
private

Definition at line 89 of file PFMETProducerMVA.h.

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

int reco::PFMETProducerMVA::verbosity_
private

Definition at line 101 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA().