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
 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 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

std::string correctorLabel_
 
double globalThreshold_
 
METAlgo metAlgo_
 
double minCorrJetPt_
 
int minNumLeptons_
 
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< edm::Handle
< double > > 
srcRho_
 
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
 
- 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::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- 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 64 of file PFMETProducerMVA.h.

Member Typedef Documentation

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

Definition at line 103 of file PFMETProducerMVA.h.

Constructor & Destructor Documentation

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

Definition at line 9 of file PFMETProducerMVA.cc.

References correctorLabel_, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), globalThreshold_, minCorrJetPt_, minNumLeptons_, srcCorrJets_, srcJetIds_, srcLeptons_, srcPFCandidatesView_, srcRho_, srcUncorrJets_, srcVertices_, AlCaHLTBitMon_QueryRunRegistry::string, 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 
23  minNumLeptons_ = cfg.getParameter<int>("minNumLeptons");
24  srcRho_ = consumes<edm::Handle<double> >(cfg.getParameter<edm::InputTag>("srcRho"));
25 
26  globalThreshold_ = cfg.getParameter<double>("globalThreshold");
27 
28  minCorrJetPt_ = cfg.getParameter<double> ("minCorrJetPt");
29  useType1_ = cfg.getParameter<bool> ("useType1");
30  correctorLabel_ = cfg.getParameter<std::string>("corrector");
31 
32  verbosity_ = ( cfg.exists("verbosity") ) ?
33  cfg.getParameter<int>("verbosity") : 0;
34 
35  produces<reco::PFMETCollection>();
36 }
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< edm::Handle< double > > srcRho_
edm::EDGetTokenT< reco::PFJetCollection > srcUncorrJets_
PFMETProducerMVA::~PFMETProducerMVA ( )

Definition at line 38 of file PFMETProducerMVA.cc.

38 {}

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 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:71
reco::CandidatePtrVector signalCands() const
const std::vector< reco::PFCandidatePtr > & signalPFCands() const
PFCandidates in signal region.
Definition: PFTau.cc:74
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:250
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:81
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 JetCorrector iCorr,
edm::Event iEvent,
const edm::EventSetup iSetup,
std::vector< reco::PUSubMETCandInfo > &  iLeptons,
std::vector< reco::PUSubMETCandInfo > &  iCands 
)
private

Definition at line 190 of file PFMETProducerMVA.cc.

References funct::abs(), reco::PUSubMETCandInfo::chargedEnFrac(), L1FastjetCorrector::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().

197 {
198  const L1FastjetCorrector* lCorrector = dynamic_cast<const L1FastjetCorrector*>(&iCorrector);
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 = lCorrector->correction(*uncorrJet,iEvent,iSetup);
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
virtual double correction(const LorentzVector &fJet) const
apply correction using Jet information only
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 140 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().

143  {
144 
145  std::vector<reco::PUSubMETCandInfo> leptonInfo;
146 
147  for ( std::vector<edm::EDGetTokenT<reco::CandidateView > >::const_iterator srcLeptons_i = srcLeptons_.begin();
148  srcLeptons_i != srcLeptons_.end(); ++srcLeptons_i ) {
150  evt.getByToken(*srcLeptons_i, leptons);
151  for ( reco::CandidateView::const_iterator lepton1 = leptons->begin();
152  lepton1 != leptons->end(); ++lepton1 ) {
153  bool pMatch = false;
154  for ( std::vector<edm::EDGetTokenT<reco::CandidateView> >::const_iterator srcLeptons_j = srcLeptons_.begin();
155  srcLeptons_j != srcLeptons_.end(); ++srcLeptons_j ) {
157  evt.getByToken(*srcLeptons_j, leptons2);
158  for ( reco::CandidateView::const_iterator lepton2 = leptons2->begin();
159  lepton2 != leptons2->end(); ++lepton2 ) {
160  if(&(*lepton1) == &(*lepton2)) { continue; }
161  if(deltaR2(lepton1->p4(),lepton2->p4()) < dR2Max) { pMatch = true; }
162  if(pMatch && !istau(&(*lepton1)) && istau(&(*lepton2))) { pMatch = false; }
163  if(pMatch && ( (istau(&(*lepton1)) && istau(&(*lepton2))) || (!istau(&(*lepton1)) && !istau(&(*lepton2))))
164  && lepton1->pt() > lepton2->pt()) { pMatch = false; }
165  if(pMatch && lepton1->pt() == lepton2->pt()) {
166  pMatch = false;
167  for(unsigned int i0 = 0; i0 < leptonInfo.size(); i0++) {
168  if(std::abs(lepton1->pt() - leptonInfo[i0].p4().pt()) < dPtMatch) { pMatch = true; break; }
169  }
170  }
171  if(pMatch) break;
172  }
173  if(pMatch) break;
174  }
175  if(pMatch) continue;
176  reco::PUSubMETCandInfo pLeptonInfo;
177  pLeptonInfo.setP4( lepton1->p4() );
178  pLeptonInfo.setChargedEnFrac( chargedEnFrac(&(*lepton1),pfCandidates_view,hardScatterVertex) );
179  leptonInfo.push_back(pLeptonInfo);
180  if(lepton1->isPhoton()) { lHasPhotons = true; }
181  }
182  lId++;
183  }
184 
185  return leptonInfo;
186 }
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:81
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:250
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:81
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 40 of file PFMETProducerMVA.cc.

References computeJetInfo(), computeLeptonInfo(), computePFCandidateInfo(), computeVertexInfo(), mvaPFMET_cff::corrector, correctorLabel_, PFMETAlgorithmMVA::evaluateMVA(), edm::EventID::event(), edm::Event::getByToken(), JetCorrector::getJetCorrector(), 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_, 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.

41 {
42  // CV: check if the event is to be skipped
43  if ( minNumLeptons_ > 0 ) {
44  int numLeptons = 0;
45  for ( std::vector<edm::EDGetTokenT<reco::CandidateView> >::const_iterator srcLeptons_i = srcLeptons_.begin();
46  srcLeptons_i != srcLeptons_.end(); ++srcLeptons_i ) {
48  evt.getByToken(*srcLeptons_i, leptons);
49  numLeptons += leptons->size();
50  }
51  if ( !(numLeptons >= minNumLeptons_) ) {
52  LogDebug( "produce" )
53  << "<PFMETProducerMVA::produce>:" << std::endl
54  << "Run: " << evt.id().run() << ", LS: " << evt.luminosityBlock() << ", Event: " << evt.id().event() << std::endl
55  << " numLeptons = " << numLeptons << ", minNumLeptons = " << minNumLeptons_ << " --> skipping !!" << std::endl;
56 
57  reco::PFMET pfMEt;
58  std::auto_ptr<reco::PFMETCollection> pfMEtCollection(new reco::PFMETCollection());
59  pfMEtCollection->push_back(pfMEt);
60  evt.put(pfMEtCollection);
61  return;
62  }
63  }
64 
65  //get jet IDs
67  evt.getByToken(srcJetIds_, jetIds);
68 
69  // get jets (corrected and uncorrected)
71  evt.getByToken(srcCorrJets_, corrJets);
72 
74  evt.getByToken(srcUncorrJets_, uncorrJets);
75 
76  const JetCorrector* corrector = nullptr;
78 
79  edm::Handle<reco::CandidateView> pfCandidates_view;
80  evt.getByToken(srcPFCandidatesView_, pfCandidates_view);
81 
82  // get vertices
84  evt.getByToken(srcVertices_, vertices);
85  // take vertex with highest sum(trackPt) as the vertex of the "hard scatter" interaction
86  // (= first entry in vertex collection)
87  const reco::Vertex* hardScatterVertex = ( vertices->size() >= 1 ) ?
88  &(vertices->front()) : nullptr;
89 
90  // get leptons
91  // (excluded from sum over PFCandidates when computing hadronic recoil)
92  int lId = 0;
93  bool lHasPhotons = false;
94  std::vector<reco::PUSubMETCandInfo> leptonInfo = computeLeptonInfo(srcLeptons_,*pfCandidates_view,hardScatterVertex, lId, lHasPhotons,
95  evt);
96 
97  // initialize MVA MET algorithm
98  // (this will load the BDTs, stored as GBRForrest objects;
99  // either in input ROOT files or in SQL-lite files/the Conditions Database)
100  if ( !mvaMEtAlgo_isInitialized_ ) {
103  }
104 
105  // reconstruct "standard" particle-flow missing Et
106  CommonMETData pfMEt_data = metAlgo_.run( (*pfCandidates_view), globalThreshold_);
107  SpecificPFMETData specificPfMET = pfMEtSpecificAlgo_.run( (*pfCandidates_view) );
108  const reco::Candidate::LorentzVector p4( pfMEt_data.mex, pfMEt_data.mey, 0.0, pfMEt_data.met);
109  const reco::Candidate::Point vtx(0.0, 0.0, 0.0 );
110  reco::PFMET pfMEt(specificPfMET,pfMEt_data.sumet, p4, vtx);
111  reco::Candidate::LorentzVector pfMEtP4_original = pfMEt.p4();
112 
113  // compute objects specific to MVA based MET reconstruction
114  std::vector<reco::PUSubMETCandInfo> pfCandidateInfo = computePFCandidateInfo(*pfCandidates_view, hardScatterVertex);
115  std::vector<reco::PUSubMETCandInfo> jetInfo = computeJetInfo(*uncorrJets, corrJets, *jetIds, *vertices, hardScatterVertex, *corrector,evt,es,leptonInfo,pfCandidateInfo);
116  std::vector<reco::Vertex::Point> vertexInfo = computeVertexInfo(*vertices);
117  // compute MVA based MET and estimate of its uncertainty
118  mvaMEtAlgo_.setInput(leptonInfo, jetInfo, pfCandidateInfo, vertexInfo);
119  mvaMEtAlgo_.setHasPhotons(lHasPhotons);
121  pfMEt.setP4(mvaMEtAlgo_.getMEt());
123 
124  LogDebug("produce")
125  << "Run: " << evt.id().run() << ", LS: " << evt.luminosityBlock() << ", Event: " << evt.id().event() << std::endl
126  << " PFMET: Pt = " << pfMEtP4_original.pt() << ", phi = " << pfMEtP4_original.phi() << " "
127  << "(Px = " << pfMEtP4_original.px() << ", Py = " << pfMEtP4_original.py() << ")" << std::endl
128  << " MVA MET: Pt = " << pfMEt.pt() << " phi = " << pfMEt.phi() << " (Px = " << pfMEt.px() << ", 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 << std::endl;
132 
133  // add PFMET object to the event
134  std::auto_ptr<reco::PFMETCollection> pfMEtCollection(new reco::PFMETCollection());
135  pfMEtCollection->push_back(pfMEt);
136  evt.put(pfMEtCollection);
137 }
#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:449
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:88
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
edm::EDGetTokenT< reco::PFJetCollection > srcCorrJets_
double p4[4]
Definition: TauolaWrapper.h:92
std::vector< reco::PUSubMETCandInfo > computeJetInfo(const reco::PFJetCollection &, const edm::Handle< reco::PFJetCollection > &, const edm::ValueMap< float > &, const reco::VertexCollection &, const reco::Vertex *, const JetCorrector &iCorr, edm::Event &iEvent, const edm::EventSetup &iSetup, std::vector< reco::PUSubMETCandInfo > &iLeptons, std::vector< reco::PUSubMETCandInfo > &iCands)
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)
virtual double px() const
x coordinate of momentum vector
static const JetCorrector * getJetCorrector(const std::string &fName, const edm::EventSetup &fSetup)
retrieve corrector from the event setup. troughs exception if something is missing ...
Definition: JetCorrector.cc:50
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

std::string reco::PFMETProducerMVA::correctorLabel_
private

Definition at line 108 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

double reco::PFMETProducerMVA::globalThreshold_
private

Definition at line 111 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

METAlgo reco::PFMETProducerMVA::metAlgo_
private

Definition at line 115 of file PFMETProducerMVA.h.

Referenced by produce().

double reco::PFMETProducerMVA::minCorrJetPt_
private

Definition at line 113 of file PFMETProducerMVA.h.

Referenced by computeJetInfo(), and PFMETProducerMVA().

int reco::PFMETProducerMVA::minNumLeptons_
private

Definition at line 105 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

PFMETAlgorithmMVA reco::PFMETProducerMVA::mvaMEtAlgo_
private

Definition at line 117 of file PFMETProducerMVA.h.

Referenced by produce().

bool reco::PFMETProducerMVA::mvaMEtAlgo_isInitialized_
private

Definition at line 118 of file PFMETProducerMVA.h.

Referenced by produce().

PFSpecificAlgo reco::PFMETProducerMVA::pfMEtSpecificAlgo_
private

Definition at line 116 of file PFMETProducerMVA.h.

Referenced by produce().

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

Definition at line 97 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

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

Definition at line 99 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

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

Definition at line 104 of file PFMETProducerMVA.h.

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

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

Definition at line 101 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

edm::EDGetTokenT<edm::Handle<double> > reco::PFMETProducerMVA::srcRho_
private

Definition at line 106 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA().

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

Definition at line 98 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

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

Definition at line 102 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA(), and produce().

bool reco::PFMETProducerMVA::useType1_
private

Definition at line 109 of file PFMETProducerMVA.h.

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

int reco::PFMETProducerMVA::verbosity_
private

Definition at line 121 of file PFMETProducerMVA.h.

Referenced by PFMETProducerMVA().