CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
ParticleLevelProducer Class Reference

#include <ParticleLevelProducer.h>

Inheritance diagram for ParticleLevelProducer:
edm::one::EDProducer< edm::one::SharedResources > edm::one::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 ParticleLevelProducer (const edm::ParameterSet &pset)
 
void produce (edm::Event &event, const edm::EventSetup &eventSetup) override
 
virtual ~ParticleLevelProducer ()
 
- Public Member Functions inherited from edm::one::EDProducer< edm::one::SharedResources >
 EDProducer ()=default
 
- Public Member Functions inherited from edm::one::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducerBase ()
 
- 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 ()
 
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, std::unordered_multimap< std::string, edm::ProductResolverIndex > const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- 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
 
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::vector< ModuleDescription const * > &modules, 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 updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

void addGenJet (Rivet::Jet jet, std::unique_ptr< reco::GenJetCollection > &jets, std::unique_ptr< reco::GenParticleCollection > &consts, edm::RefProd< reco::GenParticleCollection > &constsRefHandle, int &iConstituent, std::unique_ptr< reco::GenParticleCollection > &tags, edm::RefProd< reco::GenParticleCollection > &tagsRefHandle, int &iTag)
 
template<typename T >
reco::Candidate::LorentzVector p4 (const T &p) const
 

Private Attributes

Rivet::AnalysisHandler analysisHandler_
 
reco::Particle::Point genVertex_
 
Rivet::RivetAnalysisrivetAnalysis_
 
const edm::EDGetTokenT< edm::HepMCProductsrcToken_
 

Additional Inherited Members

- Public Types inherited from edm::one::EDProducerBase
typedef EDProducerBase 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::one::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 18 of file ParticleLevelProducer.h.

Constructor & Destructor Documentation

ParticleLevelProducer::ParticleLevelProducer ( const edm::ParameterSet pset)

Definition at line 19 of file ParticleLevelProducer.cc.

References analysisHandler_, genVertex_, and rivetAnalysis_.

19  :
20  srcToken_(consumes<edm::HepMCProduct>(pset.getParameter<edm::InputTag>("src"))),
22 {
23  usesResource();
24 
26 
27  produces<reco::GenParticleCollection>("neutrinos");
28  produces<reco::GenParticleCollection>("photons");
29  produces<reco::GenJetCollection>("leptons");
30  produces<reco::GenJetCollection>("jets");
31  produces<reco::GenJetCollection>("fatjets");
32  produces<reco::GenParticleCollection>("consts");
33  produces<reco::GenParticleCollection>("tags");
34  produces<reco::METCollection>("mets");
35 
36  analysisHandler_.addAnalysis(rivetAnalysis_);
37 }
T getParameter(std::string const &) const
math::XYZPoint Point
point in the space
Definition: Particle.h:25
Rivet::RivetAnalysis * rivetAnalysis_
const edm::EDGetTokenT< edm::HepMCProduct > srcToken_
Rivet::AnalysisHandler analysisHandler_
reco::Particle::Point genVertex_
virtual ParticleLevelProducer::~ParticleLevelProducer ( )
inlinevirtual

Member Function Documentation

void ParticleLevelProducer::addGenJet ( Rivet::Jet  jet,
std::unique_ptr< reco::GenJetCollection > &  jets,
std::unique_ptr< reco::GenParticleCollection > &  consts,
edm::RefProd< reco::GenParticleCollection > &  constsRefHandle,
int &  iConstituent,
std::unique_ptr< reco::GenParticleCollection > &  tags,
edm::RefProd< reco::GenParticleCollection > &  tagsRefHandle,
int &  iTag 
)
private

Definition at line 39 of file ParticleLevelProducer.cc.

References reco::CompositePtrCandidate::addDaughter(), MillePedeFileConverter_cfg::e, genVertex_, match(), AlCaHLTBitMon_ParallelJobs::p, p4(), lumiQueryAPI::q, edm::refToPtr(), reco::Jet::setJetArea(), reco::LeafCandidate::setP4(), reco::LeafCandidate::setPdgId(), and reco::LeafCandidate::setVertex().

Referenced by produce(), and ~ParticleLevelProducer().

42 {
43  const auto pjet = jet.pseudojet();
44 
45  reco::GenJet genJet;
46  genJet.setP4(p4(jet));
47  genJet.setVertex(genVertex_);
48  if ( jet.bTagged() ) genJet.setPdgId(5);
49  genJet.setJetArea(pjet.has_area() ? pjet.area() : 0);
50 
51  for ( auto const & p : jet.particles()) {
52  auto pp4 = p4(p);
53  bool match = false; int iMatch = -1;
54  for ( auto const & q : *consts ) {
55  ++iMatch;
56  if (q.p4() == pp4) { match = true; break; }
57  }
58  if (match){
59  genJet.addDaughter(edm::refToPtr(reco::GenParticleRef(constsRefHandle, iMatch)));
60  }
61  else {
62  consts->push_back(reco::GenParticle(p.charge(), pp4, genVertex_, p.pdgId(), 1, true));
63  genJet.addDaughter(edm::refToPtr(reco::GenParticleRef(constsRefHandle, ++iConstituent)));
64  }
65  }
66  for ( auto const & p : jet.tags()) {
67  // The tag particles are accessible as jet daughters, so scale down p4 for safety.
68  // p4 needs to be multiplied by 1e20 for fragmentation analysis.
69  auto pp4 = p4(p)*1e-20;
70  bool match = false; int iMatch = -1;
71  for ( auto const & q : *tags ) {
72  ++iMatch;
73  if (q.p4() == pp4) { match = true; break; }
74  }
75  if (match){
76  genJet.addDaughter(edm::refToPtr(reco::GenParticleRef(tagsRefHandle, iMatch)));
77  }
78  else {
79  tags->push_back(reco::GenParticle(p.charge(), p4(p)*1e-20, genVertex_, p.pdgId(), 2, true));
80  genJet.addDaughter(edm::refToPtr(reco::GenParticleRef(tagsRefHandle, ++iTag)));
81  }
82  }
83 
84  jets->push_back(genJet);
85 }
Ptr< typename C::value_type > refToPtr(Ref< C, typename C::value_type, refhelper::FindUsingAdvance< C, typename C::value_type > > const &ref)
Definition: RefToPtr.h:18
virtual void setPdgId(int pdgId) final
virtual void setJetArea(float fArea)
set jet area
Definition: Jet.h:103
reco::Candidate::LorentzVector p4(const T &p) const
vector< PseudoJet > jets
Jets made from MC generator particles.
Definition: GenJet.h:24
virtual void setVertex(const Point &vertex)
set vertex
virtual void setP4(const LorentzVector &p4) final
set 4-momentum
void addDaughter(const CandidatePtr &)
add a daughter via a reference
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
reco::Particle::Point genVertex_
template<typename T >
reco::Candidate::LorentzVector ParticleLevelProducer::p4 ( const T p) const
inlineprivate

Definition at line 30 of file ParticleLevelProducer.h.

Referenced by addGenJet(), Tau.Tau::dxy_approx(), Tau.Tau::dz(), Lepton.Lepton::p4WithFSR(), and produce().

31  {
32  return reco::Candidate::LorentzVector(p.px(), p.py(), p.pz(), p.energy());
33  }
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
void ParticleLevelProducer::produce ( edm::Event event,
const edm::EventSetup eventSetup 
)
override

Definition at line 87 of file ParticleLevelProducer.cc.

References reco::CompositePtrCandidate::addDaughter(), addGenJet(), analysisHandler_, GetRecoTauVFromDQM_MC_cff::cl, DEFINE_FWK_MODULE, Rivet::RivetAnalysis::fatjets(), MCTruth::genEvent, genVertex_, metsig::jet, Rivet::RivetAnalysis::jets(), fwrapper::jets, AK4PFJetsMCFlavourInfos_cfi::leptons, Rivet::RivetAnalysis::leptons(), Rivet::RivetAnalysis::met(), TtSemiLepSignalSelMVAComputer_cfi::mets, eostools::move(), TtSemiLepHypHitFit_cfi::neutrinos, Rivet::RivetAnalysis::neutrinos(), AlCaHLTBitMon_ParallelJobs::p, p4(), Rivet::RivetAnalysis::photons(), jetCleaner_cfi::photons, funct::pow(), edm::refToPtr(), rivetAnalysis_, reco::LeafCandidate::setCharge(), reco::LeafCandidate::setP4(), reco::LeafCandidate::setPdgId(), reco::LeafCandidate::setVertex(), mathSSE::sqrt(), and srcToken_.

Referenced by ~ParticleLevelProducer().

88 {
89  using namespace Rivet;
91 
92  std::unique_ptr<reco::GenParticleCollection> neutrinos(new reco::GenParticleCollection);
93  std::unique_ptr<reco::GenParticleCollection> photons(new reco::GenParticleCollection);
94  std::unique_ptr<reco::GenJetCollection> leptons(new reco::GenJetCollection);
95  std::unique_ptr<reco::GenJetCollection> jets(new reco::GenJetCollection);
96  std::unique_ptr<reco::GenJetCollection> fatjets(new reco::GenJetCollection);
97  std::unique_ptr<reco::GenParticleCollection> consts(new reco::GenParticleCollection);
98  std::unique_ptr<reco::GenParticleCollection> tags(new reco::GenParticleCollection);
99  std::unique_ptr<reco::METCollection> mets(new reco::METCollection);
100  auto constsRefHandle = event.getRefBeforePut<reco::GenParticleCollection>("consts");
101  auto tagsRefHandle = event.getRefBeforePut<reco::GenParticleCollection>("tags");
102 
103  edm::Handle<HepMCProduct> srcHandle;
104  event.getByToken(srcToken_, srcHandle);
105 
106  const HepMC::GenEvent* genEvent = srcHandle->GetEvent();
107  analysisHandler_.analyze(*genEvent);
108 
109  // Convert into edm objects
110  // Prompt neutrinos
111  for ( auto const & p : rivetAnalysis_->neutrinos() ) {
112  neutrinos->push_back(reco::GenParticle(p.charge(), p4(p), genVertex_, p.pdgId(), 1, true));
113  }
114  std::sort(neutrinos->begin(), neutrinos->end(), GreaterByPt<reco::Candidate>());
115 
116  // Photons
117  for ( auto const & p : rivetAnalysis_->photons() ) {
118  photons->push_back(reco::GenParticle(p.charge(), p4(p), genVertex_, p.pdgId(), 1, true));
119  }
120  std::sort(photons->begin(), photons->end(), GreaterByPt<reco::Candidate>());
121 
122  // Prompt leptons
123  int iConstituent = -1;
124  for ( auto const & lepton : rivetAnalysis_->leptons() ) {
125  reco::GenJet lepJet;
126  lepJet.setP4(p4(lepton));
127  lepJet.setVertex(genVertex_);
128  lepJet.setPdgId(lepton.pdgId());
129  lepJet.setCharge(lepton.charge());
130 
131  const auto cl = lepton.constituentLepton();
132  consts->push_back(reco::GenParticle(cl.charge(), p4(cl), genVertex_, cl.pdgId(), 1, true));
133  lepJet.addDaughter(edm::refToPtr(reco::GenParticleRef(constsRefHandle, ++iConstituent)));
134 
135  for ( auto const & p : lepton.constituentPhotons()) {
136  consts->push_back(reco::GenParticle(p.charge(), p4(p), genVertex_, p.pdgId(), 1, true));
137  lepJet.addDaughter(edm::refToPtr(reco::GenParticleRef(constsRefHandle, ++iConstituent)));
138  }
139 
140  leptons->push_back(lepJet);
141  }
142  std::sort(leptons->begin(), leptons->end(), GreaterByPt<reco::GenJet>());
143 
144  // Jets with constituents and tag particles
145  int iTag = -1;
146  for ( auto jet : rivetAnalysis_->jets() ) {
147  addGenJet(jet, jets, consts, constsRefHandle, iConstituent, tags, tagsRefHandle, iTag);
148  }
149  for ( auto jet : rivetAnalysis_->fatjets() ) {
150  addGenJet(jet, fatjets, consts, constsRefHandle, iConstituent, tags, tagsRefHandle, iTag);
151  }
152 
153  // MET
155  mets->push_back(reco::MET(metP4, genVertex_));
156 
157  event.put(std::move(neutrinos), "neutrinos");
158  event.put(std::move(photons), "photons");
159  event.put(std::move(leptons), "leptons");
160  event.put(std::move(jets), "jets");
161  event.put(std::move(fatjets), "fatjets");
162  event.put(std::move(consts), "consts");
163  event.put(std::move(tags), "tags");
164  event.put(std::move(mets), "mets");
165 }
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
Vector3 met() const
Definition: RivetAnalysis.h:31
Ptr< typename C::value_type > refToPtr(Ref< C, typename C::value_type, refhelper::FindUsingAdvance< C, typename C::value_type > > const &ref)
Definition: RefToPtr.h:18
virtual void setPdgId(int pdgId) final
std::vector< GenJet > GenJetCollection
collection of GenJet objects
std::vector< reco::MET > METCollection
collection of MET objects
Definition: METCollection.h:23
Jets fatjets() const
Definition: RivetAnalysis.h:30
genEvent
Definition: MCTruth.py:33
ParticleVector neutrinos() const
Definition: RivetAnalysis.h:28
Jets jets() const
Definition: RivetAnalysis.h:29
ParticleVector photons() const
Definition: RivetAnalysis.h:27
reco::Candidate::LorentzVector p4(const T &p) const
Definition: MET.h:42
T sqrt(T t)
Definition: SSEVec.h:18
vector< PseudoJet > jets
virtual void setCharge(Charge q) final
set electric charge
Definition: LeafCandidate.h:93
std::vector< DressedLepton > leptons() const
Definition: RivetAnalysis.h:26
Jets made from MC generator particles.
Definition: GenJet.h:24
void addGenJet(Rivet::Jet jet, std::unique_ptr< reco::GenJetCollection > &jets, std::unique_ptr< reco::GenParticleCollection > &consts, edm::RefProd< reco::GenParticleCollection > &constsRefHandle, int &iConstituent, std::unique_ptr< reco::GenParticleCollection > &tags, edm::RefProd< reco::GenParticleCollection > &tagsRefHandle, int &iTag)
virtual void setVertex(const Point &vertex)
set vertex
Rivet::RivetAnalysis * rivetAnalysis_
virtual void setP4(const LorentzVector &p4) final
set 4-momentum
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
const edm::EDGetTokenT< edm::HepMCProduct > srcToken_
Rivet::AnalysisHandler analysisHandler_
void addDaughter(const CandidatePtr &)
add a daughter via a reference
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
def move(src, dest)
Definition: eostools.py:510
math::PtEtaPhiELorentzVectorF LorentzVector
reco::Particle::Point genVertex_

Member Data Documentation

Rivet::AnalysisHandler ParticleLevelProducer::analysisHandler_
private

Definition at line 40 of file ParticleLevelProducer.h.

Referenced by ParticleLevelProducer(), and produce().

reco::Particle::Point ParticleLevelProducer::genVertex_
private

Definition at line 37 of file ParticleLevelProducer.h.

Referenced by addGenJet(), ParticleLevelProducer(), and produce().

Rivet::RivetAnalysis* ParticleLevelProducer::rivetAnalysis_
private

Definition at line 39 of file ParticleLevelProducer.h.

Referenced by ParticleLevelProducer(), and produce().

const edm::EDGetTokenT<edm::HepMCProduct> ParticleLevelProducer::srcToken_
private

Definition at line 35 of file ParticleLevelProducer.h.

Referenced by produce().