CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
LeptonJetVarProducer< T > Class Template Reference

#include <PhysicsTools/NanoAOD/plugins/LeptonJetVarProducer.cc>

Inheritance diagram for LeptonJetVarProducer< T >:
edm::global::EDProducer<> edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 LeptonJetVarProducer (const edm::ParameterSet &iConfig)
 
 ~LeptonJetVarProducer () override
 
- Public Member Functions inherited from edm::global::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
 
EDProduceroperator= (const EDProducer &)=delete
 
bool wantsGlobalLuminosityBlocks () const noexcept final
 
bool wantsGlobalRuns () const noexcept final
 
bool wantsInputProcessBlocks () const noexcept final
 
bool wantsProcessBlocks () const noexcept final
 
bool wantsStreamLuminosityBlocks () const noexcept final
 
bool wantsStreamRuns () const noexcept final
 
- Public Member Functions inherited from edm::global::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
std::vector< bool > const & recordProvenanceList () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
TypeLabelList const & typeLabelList () const
 used by the fwk to register the list of products of this module More...
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const *> const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

std::tuple< float, float, float > calculatePtRatioRel (edm::Ptr< reco::Candidate > lep, edm::Ptr< pat::Jet > jet, const reco::Vertex &vtx) const
 
void produce (edm::StreamID, edm::Event &, const edm::EventSetup &) const override
 

Private Attributes

edm::EDGetTokenT< edm::View< pat::Jet > > srcJet_
 
edm::EDGetTokenT< edm::View< T > > srcLep_
 
edm::EDGetTokenT< std::vector< reco::Vertex > > srcVtx_
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
template<typename T >
using BranchAliasSetterT = ProductRegistryHelper::BranchAliasSetterT< T >
 
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex > >
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::ProducerBase
template<Transition Tr = Transition::Event>
auto produces (std::string instanceName) noexcept
 declare what type of product will make and with which optional label More...
 
template<Transition B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<BranchType B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
template<Transition Tr = Transition::Event>
auto produces () noexcept
 
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

template<typename T>
class LeptonJetVarProducer< T >

Description: [one line class summary]

Implementation: [Notes on implementation]

Definition at line 47 of file LeptonJetVarProducer.cc.

Constructor & Destructor Documentation

◆ LeptonJetVarProducer()

template<typename T >
LeptonJetVarProducer< T >::LeptonJetVarProducer ( const edm::ParameterSet iConfig)
inlineexplicit

Definition at line 49 of file LeptonJetVarProducer.cc.

52  srcVtx_(consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("srcVtx"))) {
53  produces<edm::ValueMap<float>>("ptRatio");
54  produces<edm::ValueMap<float>>("ptRel");
55  produces<edm::ValueMap<float>>("jetNDauChargedMVASel");
56  produces<edm::ValueMap<reco::CandidatePtr>>("jetForLepJetVar");
57  }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< std::vector< reco::Vertex > > srcVtx_
edm::EDGetTokenT< edm::View< pat::Jet > > srcJet_
edm::EDGetTokenT< edm::View< T > > srcLep_

◆ ~LeptonJetVarProducer()

template<typename T >
LeptonJetVarProducer< T >::~LeptonJetVarProducer ( )
inlineoverride

Definition at line 58 of file LeptonJetVarProducer.cc.

58 {}

Member Function Documentation

◆ calculatePtRatioRel()

template<typename T >
std::tuple< float, float, float > LeptonJetVarProducer< T >::calculatePtRatioRel ( edm::Ptr< reco::Candidate lep,
edm::Ptr< pat::Jet jet,
const reco::Vertex vtx 
) const
private

Definition at line 146 of file LeptonJetVarProducer.cc.

References ztail::d, eleIsoSequence_cff::deltaR, MillePedeFileConverter_cfg::e, ALCARECOEcalPhiSym_cff::float, metsig::jet, reco::Candidate::p4(), dttmaxenums::R, and L1BJetProducer_cff::vtx.

148  {
149  auto rawp4 = jet->correctedP4("Uncorrected");
150  auto lepp4 = lep->p4();
151 
152  if ((rawp4 - lepp4).R() < 1e-4)
153  return std::tuple<float, float, float>(1.0, 0.0, 0.0);
154 
155  auto l1corrFactor = jet->jecFactor("L1FastJet") / jet->jecFactor("Uncorrected");
156 
157  auto jetp4 = (rawp4 - lepp4 * (1.0 / l1corrFactor)) * (jet->pt() / rawp4.pt()) + lepp4;
158  auto ptratio = lepp4.pt() / jetp4.pt();
159  auto ptrel = lepp4.Vect().Cross((jetp4 - lepp4).Vect().Unit()).R();
160 
161  unsigned int jndau = 0;
162  for (const auto& _d : jet->daughterPtrVector()) {
163  const auto d = dynamic_cast<const pat::PackedCandidate*>(_d.get());
164  if (d->charge() == 0)
165  continue;
166  if (d->fromPV() <= 1)
167  continue;
168  if (deltaR(*d, *lep) > 0.4)
169  continue;
170  if (!(d->hasTrackDetails()))
171  continue;
172  auto tk = d->pseudoTrack();
173  if (tk.pt() > 1 && tk.hitPattern().numberOfValidHits() >= 8 && tk.hitPattern().numberOfValidPixelHits() >= 2 &&
174  tk.normalizedChi2() < 5 && fabs(tk.dxy(vtx.position())) < 0.2 && fabs(tk.dz(vtx.position())) < 17)
175  jndau++;
176  }
177 
178  return std::tuple<float, float, float>(ptratio, ptrel, float(jndau));
179 }
d
Definition: ztail.py:151
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector

◆ fillDescriptions()

template<typename T >
void LeptonJetVarProducer< T >::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 183 of file LeptonJetVarProducer.cc.

References edm::ConfigurationDescriptions::add(), submitPVResolutionJobs::desc, timingPdfMaker::modname, and AlCaHLTBitMon_QueryRunRegistry::string.

183  {
184  //The following says we do not know what parameters are allowed so do no validation
185  // Please change this to state exactly what you do use, even if it is no parameters
187  desc.add<edm::InputTag>("srcJet")->setComment("jet input collection");
188  desc.add<edm::InputTag>("srcLep")->setComment("lepton input collection");
189  desc.add<edm::InputTag>("srcVtx")->setComment("primary vertex input collection");
191  if (typeid(T) == typeid(pat::Muon))
192  modname += "Muon";
193  else if (typeid(T) == typeid(pat::Electron))
194  modname += "Electron";
195  modname += "JetVarProducer";
196  descriptions.add(modname, desc);
197 }
Analysis-level electron class.
Definition: Electron.h:51
void add(std::string const &label, ParameterSetDescription const &psetDescription)
long double T
Analysis-level muon class.
Definition: Muon.h:51

◆ produce()

template<typename T >
void LeptonJetVarProducer< T >::produce ( edm::StreamID  streamID,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
overrideprivatevirtual

Implements edm::global::EDProducerBase.

Definition at line 90 of file LeptonJetVarProducer.cc.

References iEvent, metsig::jet, electrons_cff::jetForLepJetVar, electrons_cff::jetNDauChargedMVASel, matchByCommonSourceCandidatePtr(), eostools::move(), electrons_cff::ptRatio, electrons_cff::ptRel, electrons_cff::srcJet, and electrons_cff::srcLep.

90  {
91  auto srcJet = iEvent.getHandle(srcJet_);
92  auto srcLep = iEvent.getHandle(srcLep_);
93  const auto& vtxProd = iEvent.get(srcVtx_);
94 
95  unsigned int nJet = srcJet->size();
96  unsigned int nLep = srcLep->size();
97 
98  std::vector<float> ptRatio(nLep, -1);
99  std::vector<float> ptRel(nLep, -1);
100  std::vector<float> jetNDauChargedMVASel(nLep, 0);
101  std::vector<reco::CandidatePtr> jetForLepJetVar(nLep, reco::CandidatePtr());
102 
103  const auto& pv = vtxProd.at(0);
104 
105  for (unsigned int il = 0; il < nLep; il++) {
106  for (unsigned int ij = 0; ij < nJet; ij++) {
107  auto lep = srcLep->ptrAt(il);
108  auto jet = srcJet->ptrAt(ij);
109  if (matchByCommonSourceCandidatePtr(*lep, *jet)) {
110  auto res = calculatePtRatioRel(lep, jet, pv);
111  ptRatio[il] = std::get<0>(res);
112  ptRel[il] = std::get<1>(res);
113  jetNDauChargedMVASel[il] = std::get<2>(res);
114  jetForLepJetVar[il] = jet;
115  break; // take leading jet with shared source candidates
116  }
117  }
118  }
119 
120  auto ptRatioV = std::make_unique<edm::ValueMap<float>>();
121  edm::ValueMap<float>::Filler fillerRatio(*ptRatioV);
122  fillerRatio.insert(srcLep, ptRatio.begin(), ptRatio.end());
123  fillerRatio.fill();
124  iEvent.put(std::move(ptRatioV), "ptRatio");
125 
126  auto ptRelV = std::make_unique<edm::ValueMap<float>>();
127  edm::ValueMap<float>::Filler fillerRel(*ptRelV);
128  fillerRel.insert(srcLep, ptRel.begin(), ptRel.end());
129  fillerRel.fill();
130  iEvent.put(std::move(ptRelV), "ptRel");
131 
132  auto jetNDauChargedMVASelV = std::make_unique<edm::ValueMap<float>>();
133  edm::ValueMap<float>::Filler fillerNDau(*jetNDauChargedMVASelV);
134  fillerNDau.insert(srcLep, jetNDauChargedMVASel.begin(), jetNDauChargedMVASel.end());
135  fillerNDau.fill();
136  iEvent.put(std::move(jetNDauChargedMVASelV), "jetNDauChargedMVASel");
137 
138  auto jetForLepJetVarV = std::make_unique<edm::ValueMap<reco::CandidatePtr>>();
139  edm::ValueMap<reco::CandidatePtr>::Filler fillerjetForLepJetVar(*jetForLepJetVarV);
140  fillerjetForLepJetVar.insert(srcLep, jetForLepJetVar.begin(), jetForLepJetVar.end());
141  fillerjetForLepJetVar.fill();
142  iEvent.put(std::move(jetForLepJetVarV), "jetForLepJetVar");
143 }
std::tuple< float, float, float > calculatePtRatioRel(edm::Ptr< reco::Candidate > lep, edm::Ptr< pat::Jet > jet, const reco::Vertex &vtx) const
Definition: Electron.h:6
edm::EDGetTokenT< std::vector< reco::Vertex > > srcVtx_
int iEvent
Definition: GenABIO.cc:224
bool matchByCommonSourceCandidatePtr(const C1 &c1, const C2 &c2)
Definition: MatchingUtils.h:9
edm::EDGetTokenT< edm::View< pat::Jet > > srcJet_
def move(src, dest)
Definition: eostools.py:511
edm::EDGetTokenT< edm::View< T > > srcLep_

Member Data Documentation

◆ srcJet_

template<typename T >
edm::EDGetTokenT<edm::View<pat::Jet> > LeptonJetVarProducer< T >::srcJet_
private

Definition at line 71 of file LeptonJetVarProducer.cc.

◆ srcLep_

template<typename T >
edm::EDGetTokenT<edm::View<T> > LeptonJetVarProducer< T >::srcLep_
private

Definition at line 72 of file LeptonJetVarProducer.cc.

◆ srcVtx_

template<typename T >
edm::EDGetTokenT<std::vector<reco::Vertex> > LeptonJetVarProducer< T >::srcVtx_
private

Definition at line 73 of file LeptonJetVarProducer.cc.