CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes
JetPartonMatcher Class Reference
Inheritance diagram for JetPartonMatcher:
edm::global::EDProducer<> edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Classes

struct  WorkingVariables
 

Public Member Functions

 JetPartonMatcher (const edm::ParameterSet &)
 
 ~JetPartonMatcher () 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 final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
bool wantsStreamLuminosityBlocks () const final
 
bool wantsStreamRuns () const 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
 
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)
 
 ~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
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESProxyIndex > 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
 
bool registeredToConsumeMany (TypeID const &, 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::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

int fillAlgoritDefinition (const Jet &, WorkingVariables &) const
 
int fillPhysicsDefinition (const Jet &, WorkingVariables &) const
 
void produce (edm::StreamID, edm::Event &, const edm::EventSetup &) const override
 

Private Attributes

double coneSizeToAssociate
 
bool doPriority
 
edm::EDGetTokenT< edm::View
< reco::Jet > > 
m_jetsSrcToken
 
edm::EDGetTokenT
< GenParticleRefVector
m_ParticleSrcToken
 
bool physDefinition
 
vector< int > priorityList
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
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
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::ProducerBase
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 ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
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

Definition at line 94 of file JetPartonMatcher.cc.

Constructor & Destructor Documentation

JetPartonMatcher::JetPartonMatcher ( const edm::ParameterSet iConfig)

Definition at line 123 of file JetPartonMatcher.cc.

References edm::ParameterSet::exists(), and edm::ParameterSet::getParameter().

123  {
124  produces<JetMatchedPartonsCollection>();
125  m_jetsSrcToken = consumes<edm::View<reco::Jet> >(iConfig.getParameter<edm::InputTag>("jets"));
126  m_ParticleSrcToken = consumes<GenParticleRefVector>(iConfig.getParameter<edm::InputTag>("partons"));
127  coneSizeToAssociate = iConfig.getParameter<double>("coneSizeToAssociate");
128  if (iConfig.exists("doPriority")) {
129  doPriority = iConfig.getParameter<bool>("doPriority");
130  priorityList = iConfig.getParameter<vector<int> >("priorityList");
131  } else {
132  doPriority = false;
133  priorityList.clear();
134  }
135 }
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::EDGetTokenT< GenParticleRefVector > m_ParticleSrcToken
vector< int > priorityList
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< edm::View< reco::Jet > > m_jetsSrcToken
JetPartonMatcher::~JetPartonMatcher ( )
override

Definition at line 139 of file JetPartonMatcher.cc.

139 {}

Member Function Documentation

int JetPartonMatcher::fillAlgoritDefinition ( const Jet theJet,
WorkingVariables wv 
) const
private

Definition at line 209 of file JetPartonMatcher.cc.

References funct::abs(), HLT_FULL_cff::DeltaR, spr::find(), visualization-live-secondInstance_cfg::m, reco::LeafCandidate::p4(), JetPartonMatcher::WorkingVariables::particles, reco::LeafCandidate::pdgId(), reco::LeafCandidate::pt(), reco::LeafCandidate::status(), JetPartonMatcher::WorkingVariables::theHardest, JetPartonMatcher::WorkingVariables::theHeaviest, and JetPartonMatcher::WorkingVariables::theNearest2.

209  {
210  int tempParticle = -1;
211  int tempPartonHighestPt = -1;
212  int tempNearest = -1;
213  float maxPt = 0;
214  float minDr = 1000;
215  bool foundPriority = false;
216 
217  // Loop over the particles in question until we find a priority
218  // "hit", or if we find none in the priority list (or we don't want
219  // to consider priority), then loop through all particles and fill
220  // standard definition.
221 
222  //
223  // Matching:
224  //
225  // 1) First try to match by hand. The "priority list" is given
226  // by the user. The algorithm finds any particles in that
227  // "priority list" that are within the specified cone size.
228  // If it finds one, it counts the object as associating to that
229  // particle.
230  // NOTE! The objects in the priority list are given in order
231  // of priority. So if the user specifies:
232  // 6, 24, 21,
233  // then it will first look for top quarks, then W bosons, then gluons.
234  // 2) If no priority items are found, do the default "standard"
235  // matching.
236  for (size_t m = 0; m < wv.particles->size() && !foundPriority; ++m) {
237  // const Candidate & aParton = *(wv.particles->at(m).get());
238  const GenParticle& aParton = *(wv.particles->at(m).get());
239  int flavour = abs(aParton.pdgId());
240 
241  // "Priority" behavoir:
242  // Associate to the first particle found in the priority list, regardless
243  // of delta R.
244  if (doPriority) {
245  vector<int>::const_iterator ipriority = find(priorityList.begin(), priorityList.end(), flavour);
246  // Check to see if this particle is in our priority list
247  if (ipriority != priorityList.end()) {
248  // This particle is on our priority list. If it matches,
249  // we break, since we take in order of priority, not deltaR
250  double dist = DeltaR(theJet.p4(), aParton.p4());
251  if (dist <= coneSizeToAssociate) {
252  tempParticle = m;
253  foundPriority = true;
254  }
255  }
256  }
257  // Here we do not want to do priority matching. Ensure the "foundPriority" swtich
258  // is turned off.
259  else {
260  foundPriority = false;
261  }
262 
263  // Default behavior:
264  // Look for partons before the color string to associate.
265  // Do this if we don't want to do priority matching, or if
266  // we didn't find a priority object.
267 
268  if (!foundPriority && aParton.status() != 3) {
269  double dist = DeltaR(theJet.p4(), aParton.p4());
270  if (dist <= coneSizeToAssociate) {
271  if (dist < minDr) {
272  minDr = dist;
273  tempNearest = m;
274  }
275  if (tempParticle == -1 && (flavour == 4))
276  tempParticle = m;
277  if (flavour == 5)
278  tempParticle = m;
279  if (aParton.pt() > maxPt) {
280  maxPt = aParton.pt();
281  tempPartonHighestPt = m;
282  }
283  }
284  }
285  }
286 
287  if (foundPriority) {
288  wv.theHeaviest = tempParticle; // The priority-matched particle
289  wv.theHardest = -1; // set the rest to -1
290  wv.theNearest2 = -1; // " "
291  } else {
292  wv.theHeaviest = tempParticle;
293  wv.theHardest = tempPartonHighestPt;
294  wv.theNearest2 = tempNearest;
295  if (tempParticle == -1)
296  tempParticle = tempPartonHighestPt;
297  }
298  return tempParticle;
299 }
double pt() const final
transverse momentum
float *__restrict__ wv
int status() const final
status word
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
const LorentzVector & p4() const final
four-momentum Lorentz vector
int pdgId() const final
PDG identifier.
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
vector< int > priorityList
int JetPartonMatcher::fillPhysicsDefinition ( const Jet theJet,
WorkingVariables wv 
) const
private

Definition at line 323 of file JetPartonMatcher.cc.

References funct::abs(), HLT_FULL_cff::DeltaR, spr::find(), visualization-live-secondInstance_cfg::m, reco::CompositeRefCandidateT< D >::numberOfDaughters(), reco::LeafCandidate::p4(), JetPartonMatcher::WorkingVariables::particles, reco::LeafCandidate::pdgId(), reco::LeafCandidate::status(), JetPartonMatcher::WorkingVariables::theHardest, JetPartonMatcher::WorkingVariables::theHeaviest, JetPartonMatcher::WorkingVariables::theNearest2, and JetPartonMatcher::WorkingVariables::theNearest3.

323  {
324  float TheBiggerConeSize = 0.7; // In HepMC it's 0.3 --> it's a mistake: value has to be 0.7
325  int tempParticle = -1;
326  int nInTheCone = 0;
327  int tempNearest = -1;
328  float minDr = 1000;
329  bool foundPriority = false;
330 
331  vector<const reco::Candidate*> theContaminations;
332  theContaminations.clear();
333 
334  // Loop over the particles in question until we find a priority
335  // "hit", or if we find none in the priority list (or we don't want
336  // to consider priority), then loop through all particles and fill
337  // standard definition.
338 
339  //
340  // Matching:
341  //
342  // 1) First try to match by hand. The "priority list" is given
343  // by the user. The algorithm finds any particles in that
344  // "priority list" that are within the specified cone size.
345  // If it finds one, it counts the object as associating to that
346  // particle.
347  // NOTE! The objects in the priority list are given in order
348  // of priority. So if the user specifies:
349  // 6, 24, 21,
350  // then it will first look for top quarks, then W bosons, then gluons.
351  // 2) If no priority items are found, do the default "standard"
352  // matching.
353  for (size_t m = 0; m < wv.particles->size() && !foundPriority; ++m) {
354  // const Candidate & aParticle = *(wv.particles->at(m).get());
355  const GenParticle& aParticle = *(wv.particles->at(m).get());
356  int flavour = abs(aParticle.pdgId());
357 
358  // "Priority" behavoir:
359  // Associate to the first particle found in the priority list, regardless
360  // of delta R.
361  if (doPriority) {
362  vector<int>::const_iterator ipriority = find(priorityList.begin(), priorityList.end(), flavour);
363  // Check to see if this particle is in our priority list
364  if (ipriority != priorityList.end()) {
365  // This particle is on our priority list. If it matches,
366  // we break, since we take in order of priority, not deltaR
367  double dist = DeltaR(theJet.p4(), aParticle.p4());
368  if (dist <= coneSizeToAssociate) {
369  tempParticle = m;
370  foundPriority = true;
371  }
372  }
373  }
374  // Here we do not want to do priority matching. Ensure the "foundPriority" swtich
375  // is turned off.
376  else {
377  foundPriority = false;
378  }
379 
380  // Default behavior:
381  if (!foundPriority) {
382  // skipping all particle but udscbg (is this correct/enough?!?!)
383  bool isAParton = false;
384  if (flavour == 1 || flavour == 2 || flavour == 3 || flavour == 4 || flavour == 5 || flavour == 21)
385  isAParton = true;
386  if (!isAParton)
387  continue;
388  double dist = DeltaR(theJet.p4(), aParticle.p4());
389  if (aParticle.status() == 3 && dist < minDr) {
390  minDr = dist;
391  tempNearest = m;
392  }
393  if (aParticle.status() == 3 && dist <= coneSizeToAssociate) {
394  //cout << "particle in small cone=" << aParticle.pdgId() << endl;
395  tempParticle = m;
396  nInTheCone++;
397  }
398  // Look for heavy partons in TheBiggerConeSize now
399  if (aParticle.numberOfDaughters() > 0 && aParticle.status() != 3) {
400  if (flavour == 1 || flavour == 2 || flavour == 3 || flavour == 21)
401  continue;
402  if (dist < TheBiggerConeSize)
403  theContaminations.push_back(&aParticle);
404  }
405  }
406  }
407 
408  // Here's the default behavior for assignment if there is no priority.
409  if (!foundPriority) {
410  wv.theNearest3 = tempNearest;
411 
412  if (nInTheCone != 1)
413  return -1; // rejected --> only one initialParton requested
414  if (theContaminations.empty())
415  return tempParticle; //no contamination
416  int initialPartonFlavour = abs((wv.particles->at(tempParticle).get())->pdgId());
417 
418  vector<const Candidate*>::const_iterator itCont = theContaminations.begin();
419  for (; itCont != theContaminations.end(); itCont++) {
420  int contaminatingFlavour = abs((*itCont)->pdgId());
421  if ((*itCont)->numberOfMothers() > 0 && (*itCont)->mother(0) == wv.particles->at(tempParticle).get())
422  continue; // mother is the initialParton --> OK
423  if (initialPartonFlavour == 4) {
424  if (contaminatingFlavour == 4)
425  continue; // keep association --> the initialParton is a c --> the contaminated parton is a c
426  tempParticle = -1; // all the other cases reject!
427  return tempParticle;
428  }
429  }
430  }
431  // If there is priority, then just set the heaviest to priority, the rest are -1.
432  else {
433  wv.theHeaviest = tempParticle; // Set the heaviest to tempParticle
434  wv.theNearest2 = -1; // Set the rest to -1
435  wv.theNearest3 = -1; // " "
436  wv.theHardest = -1; // " "
437  }
438 
439  return tempParticle;
440 }
float *__restrict__ wv
size_t numberOfDaughters() const override
number of daughters
int status() const final
status word
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
const LorentzVector & p4() const final
four-momentum Lorentz vector
int pdgId() const final
PDG identifier.
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
vector< int > priorityList
void JetPartonMatcher::produce ( edm::StreamID  ,
edm::Event iEvent,
const edm::EventSetup iEs 
) const
overrideprivatevirtual

Implements edm::global::EDProducerBase.

Definition at line 143 of file JetPartonMatcher.cc.

References reco::LeafCandidate::eta(), edm::Event::getByToken(), dqmiolumiharvest::j, visualization-live-secondInstance_cfg::m, eostools::move(), JetPartonMatcher::WorkingVariables::particles, reco::LeafCandidate::pdgId(), reco::LeafCandidate::phi(), reco::LeafCandidate::pt(), edm::Event::put(), reco::LeafCandidate::status(), JetPartonMatcher::WorkingVariables::theHeaviest, JetPartonMatcher::WorkingVariables::theNearest2, JetPartonMatcher::WorkingVariables::theNearest3, and gpuVertexFinder::wv.

143  {
144  WorkingVariables wv;
146  iEvent.getByToken(m_jetsSrcToken, jets_h);
147  iEvent.getByToken(m_ParticleSrcToken, wv.particles);
148 
149  edm::LogVerbatim("JetPartonMatcher") << "=== Partons size:" << wv.particles->size();
150 
151  for (size_t m = 0; m < wv.particles->size(); ++m) {
152  const GenParticle& aParton = *(wv.particles->at(m).get());
153  edm::LogVerbatim("JetPartonMatcher") << aParton.status() << " " << aParton.pdgId() << " " << aParton.pt() << " "
154  << aParton.eta() << " " << aParton.phi() << endl;
155  }
156 
157  auto jetMatchedPartons = std::make_unique<JetMatchedPartonsCollection>(reco::JetRefBaseProd(jets_h));
158 
159  for (size_t j = 0; j < jets_h->size(); j++) {
160  const int theMappedPartonAlg = fillAlgoritDefinition((*jets_h)[j], wv);
161  const int theMappedPartonPhy = fillPhysicsDefinition((*jets_h)[j], wv);
162 
163  GenParticleRef pHV;
164  GenParticleRef pN2;
165  GenParticleRef pN3;
166  GenParticleRef pPH;
167  GenParticleRef pAL;
168 
169  if (wv.theHeaviest >= 0)
170  pHV = wv.particles->at(wv.theHeaviest);
171  if (wv.theNearest2 >= 0)
172  pN2 = wv.particles->at(wv.theNearest2);
173  if (wv.theNearest3 >= 0)
174  pN3 = wv.particles->at(wv.theNearest3);
175  if (theMappedPartonPhy >= 0)
176  pPH = wv.particles->at(theMappedPartonPhy);
177  if (theMappedPartonAlg >= 0)
178  pAL = wv.particles->at(theMappedPartonAlg);
179 
180  (*jetMatchedPartons)[jets_h->refAt(j)] = MatchedPartons(pHV, pN2, pN3, pPH, pAL);
181  }
182 
183  iEvent.put(std::move(jetMatchedPartons));
184 }
Log< level::Info, true > LogVerbatim
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
double pt() const final
transverse momentum
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
int fillAlgoritDefinition(const Jet &, WorkingVariables &) const
float *__restrict__ wv
int status() const final
status word
int pdgId() const final
PDG identifier.
edm::RefToBaseProd< reco::Jet > JetRefBaseProd
Definition: JetCollection.h:13
edm::EDGetTokenT< GenParticleRefVector > m_ParticleSrcToken
def move
Definition: eostools.py:511
edm::EDGetTokenT< edm::View< reco::Jet > > m_jetsSrcToken
int fillPhysicsDefinition(const Jet &, WorkingVariables &) const
double phi() const final
momentum azimuthal angle
double eta() const final
momentum pseudorapidity

Member Data Documentation

double JetPartonMatcher::coneSizeToAssociate
private

Definition at line 115 of file JetPartonMatcher.cc.

bool JetPartonMatcher::doPriority
private

Definition at line 117 of file JetPartonMatcher.cc.

edm::EDGetTokenT<edm::View<reco::Jet> > JetPartonMatcher::m_jetsSrcToken
private

Definition at line 113 of file JetPartonMatcher.cc.

edm::EDGetTokenT<GenParticleRefVector> JetPartonMatcher::m_ParticleSrcToken
private

Definition at line 114 of file JetPartonMatcher.cc.

bool JetPartonMatcher::physDefinition
private

Definition at line 116 of file JetPartonMatcher.cc.

vector<int> JetPartonMatcher::priorityList
private

Definition at line 118 of file JetPartonMatcher.cc.