CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
 
 ~ParticleLevelProducer () override
 
- Public Member Functions inherited from edm::one::EDProducer< edm::one::SharedResources >
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
- Public Member Functions inherited from edm::one::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () 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

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

std::unique_ptr
< Rivet::AnalysisHandler > 
analysisHandler_
 
reco::Particle::Point genVertex_
 
const edm::ParameterSet pset_
 
Rivet::RivetAnalysisrivetAnalysis_ = nullptr
 
const edm::EDGetTokenT
< edm::HepMCProduct
srcToken_
 

Additional Inherited Members

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

Constructor & Destructor Documentation

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

Definition at line 21 of file ParticleLevelProducer.cc.

References genVertex_.

22  : srcToken_(consumes<edm::HepMCProduct>(pset.getParameter<edm::InputTag>("src"))), pset_(pset) {
23  usesResource("Rivet");
25 
26  produces<reco::GenParticleCollection>("neutrinos");
27  produces<reco::GenParticleCollection>("photons");
28  produces<reco::GenJetCollection>("leptons");
29  produces<reco::GenJetCollection>("jets");
30  produces<reco::GenJetCollection>("fatjets");
31  produces<reco::GenParticleCollection>("consts");
32  produces<reco::GenParticleCollection>("tags");
33  produces<reco::METCollection>("mets");
34 }
const edm::ParameterSet pset_
math::XYZPoint Point
point in the space
Definition: Particle.h:25
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const edm::EDGetTokenT< edm::HepMCProduct > srcToken_
reco::Particle::Point genVertex_
ParticleLevelProducer::~ParticleLevelProducer ( )
inlineoverride

Definition at line 21 of file ParticleLevelProducer.h.

21 {}

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 36 of file ParticleLevelProducer.cc.

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

Referenced by produce().

43  {
44  const auto pjet = jet.pseudojet();
45 
46  reco::GenJet genJet;
47  genJet.setP4(p4(jet));
48  genJet.setVertex(genVertex_);
49  if (jet.bTagged())
50  genJet.setPdgId(5);
51  else if (jet.cTagged())
52  genJet.setPdgId(4);
53  genJet.setJetArea(pjet.has_area() ? pjet.area() : 0);
54 
55  for (auto const& p : jet.particles()) {
56  auto pp4 = p4(p);
57  bool match = false;
58  int iMatch = -1;
59  for (auto const& q : *consts) {
60  ++iMatch;
61  if (q.p4() == pp4) {
62  match = true;
63  break;
64  }
65  }
66  if (match) {
67  genJet.addDaughter(edm::refToPtr(reco::GenParticleRef(constsRefHandle, iMatch)));
68  } else {
69  consts->push_back(reco::GenParticle(p.charge(), pp4, genVertex_, p.pid(), 1, true));
70  genJet.addDaughter(edm::refToPtr(reco::GenParticleRef(constsRefHandle, ++iConstituent)));
71  }
72  }
73  for (auto const& p : jet.tags()) {
74  // The tag particles are accessible as jet daughters, so scale down p4 for safety.
75  // p4 needs to be multiplied by 1e20 for fragmentation analysis.
76  auto pp4 = p4(p) * 1e-20;
77  bool match = false;
78  int iMatch = -1;
79  for (auto const& q : *tags) {
80  ++iMatch;
81  if (q.p4() == pp4) {
82  match = true;
83  break;
84  }
85  }
86  if (match) {
87  genJet.addDaughter(edm::refToPtr(reco::GenParticleRef(tagsRefHandle, iMatch)));
88  } else {
89  tags->push_back(reco::GenParticle(p.charge(), p4(p) * 1e-20, genVertex_, p.pid(), 2, true));
90  genJet.addDaughter(edm::refToPtr(reco::GenParticleRef(tagsRefHandle, ++iTag)));
91  // Also save lepton+neutrino daughters of tag particles
92  int iTagMother = iTag;
93  for (auto const& d : p.constituents()) {
94  ++iTag;
95  int d_status = (d.isStable()) ? 1 : 2;
96  tags->push_back(reco::GenParticle(d.charge(), p4(d) * 1e-20, genVertex_, d.pid(), d_status, true));
97  tags->at(iTag).addMother(reco::GenParticleRef(tagsRefHandle, iTagMother));
98  tags->at(iTagMother).addDaughter(reco::GenParticleRef(tagsRefHandle, iTag));
99  genJet.addDaughter(edm::refToPtr(reco::GenParticleRef(tagsRefHandle, iTag)));
100  }
101  }
102  }
103 
104  jets->push_back(genJet);
105 }
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
void setVertex(const Point &vertex) override
set vertex
tuple d
Definition: ztail.py:151
virtual void setJetArea(float fArea)
set jet area
Definition: Jet.h:101
reco::Candidate::LorentzVector p4(const T &p) const
vector< PseudoJet > jets
Jets made from MC generator particles.
Definition: GenJet.h:23
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
void setPdgId(int pdgId) final
void setP4(const LorentzVector &p4) final
set 4-momentum
reco::Particle::Point genVertex_
template<typename T >
reco::Candidate::LorentzVector ParticleLevelProducer::p4 ( const T p) const
inlineprivate

Definition at line 35 of file ParticleLevelProducer.h.

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

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

Implements edm::one::EDProducerBase.

Definition at line 107 of file ParticleLevelProducer.cc.

References reco::CompositePtrCandidate::addDaughter(), addGenJet(), analysisHandler_, Rivet::RivetAnalysis::fatjets(), MCTruth::genEvent, genVertex_, metsig::jet, Rivet::RivetAnalysis::jets(), fwrapper::jets, Rivet::RivetAnalysis::leptons(), HLT_FULL_cff::leptons, Rivet::RivetAnalysis::met(), eostools::move(), Rivet::RivetAnalysis::neutrinos(), AlCaHLTBitMon_ParallelJobs::p, p4(), Rivet::RivetAnalysis::photons(), interactiveExample::photons, funct::pow(), pset_, edm::refToPtr(), rivetAnalysis_, reco::LeafCandidate::setCharge(), reco::LeafCandidate::setP4(), reco::LeafCandidate::setPdgId(), reco::LeafCandidate::setVertex(), mathSSE::sqrt(), srcToken_, and getPayloadData::tags.

107  {
108  using namespace Rivet;
110 
111  std::unique_ptr<reco::GenParticleCollection> neutrinos(new reco::GenParticleCollection);
112  std::unique_ptr<reco::GenParticleCollection> photons(new reco::GenParticleCollection);
113  std::unique_ptr<reco::GenJetCollection> leptons(new reco::GenJetCollection);
114  std::unique_ptr<reco::GenJetCollection> jets(new reco::GenJetCollection);
115  std::unique_ptr<reco::GenJetCollection> fatjets(new reco::GenJetCollection);
116  std::unique_ptr<reco::GenParticleCollection> consts(new reco::GenParticleCollection);
117  std::unique_ptr<reco::GenParticleCollection> tags(new reco::GenParticleCollection);
118  std::unique_ptr<reco::METCollection> mets(new reco::METCollection);
119  auto constsRefHandle = event.getRefBeforePut<reco::GenParticleCollection>("consts");
120  auto tagsRefHandle = event.getRefBeforePut<reco::GenParticleCollection>("tags");
121 
122  edm::Handle<HepMCProduct> srcHandle;
123  event.getByToken(srcToken_, srcHandle);
124 
125  const HepMC::GenEvent* genEvent = srcHandle->GetEvent();
126 
127  if (!rivetAnalysis_ || !rivetAnalysis_->hasProjection("FS")) {
129  analysisHandler_ = std::make_unique<Rivet::AnalysisHandler>();
130 
131  analysisHandler_->setIgnoreBeams(true);
132  analysisHandler_->addAnalysis(rivetAnalysis_);
133  }
134 
135  analysisHandler_->analyze(*genEvent);
136 
137  // Convert into edm objects
138  // Prompt neutrinos
139  for (auto const& p : rivetAnalysis_->neutrinos()) {
140  neutrinos->push_back(reco::GenParticle(p.charge(), p4(p), genVertex_, p.pid(), 1, true));
141  }
142  std::sort(neutrinos->begin(), neutrinos->end(), GreaterByPt<reco::Candidate>());
143 
144  // Photons
145  for (auto const& p : rivetAnalysis_->photons()) {
146  photons->push_back(reco::GenParticle(p.charge(), p4(p), genVertex_, p.pid(), 1, true));
147  }
148  std::sort(photons->begin(), photons->end(), GreaterByPt<reco::Candidate>());
149 
150  // Prompt leptons
151  int iConstituent = -1;
152  int iTag = -1;
153  for (auto const& lepton : rivetAnalysis_->leptons()) {
154  reco::GenJet lepJet;
155  lepJet.setP4(p4(lepton));
156  lepJet.setVertex(genVertex_);
157  lepJet.setPdgId(lepton.pid());
158  lepJet.setCharge(lepton.charge());
159 
160  for (auto const& p : lepton.constituents()) {
161  // ghost taus (momentum scaled with 10e-20 in RivetAnalysis.h already)
162  if (p.abspid() == 15) {
163  tags->push_back(reco::GenParticle(p.charge(), p4(p), genVertex_, p.pid(), 2, true));
164  lepJet.addDaughter(edm::refToPtr(reco::GenParticleRef(tagsRefHandle, ++iTag)));
165  }
166  // electrons, muons, photons
167  else {
168  consts->push_back(reco::GenParticle(p.charge(), p4(p), genVertex_, p.pid(), 1, true));
169  lepJet.addDaughter(edm::refToPtr(reco::GenParticleRef(constsRefHandle, ++iConstituent)));
170  }
171  }
172 
173  leptons->push_back(lepJet);
174  }
175  std::sort(leptons->begin(), leptons->end(), GreaterByPt<reco::GenJet>());
176 
177  // Jets with constituents and tag particles
178  for (const auto& jet : rivetAnalysis_->jets()) {
179  addGenJet(jet, jets, consts, constsRefHandle, iConstituent, tags, tagsRefHandle, iTag);
180  }
181  for (const auto& jet : rivetAnalysis_->fatjets()) {
182  addGenJet(jet, fatjets, consts, constsRefHandle, iConstituent, tags, tagsRefHandle, iTag);
183  }
184 
185  // MET
187  rivetAnalysis_->met().y(),
188  0.,
189  sqrt(pow(rivetAnalysis_->met().x(), 2) + pow(rivetAnalysis_->met().y(), 2)));
190  mets->push_back(reco::MET(metP4, genVertex_));
191 
192  event.put(std::move(neutrinos), "neutrinos");
193  event.put(std::move(photons), "photons");
194  event.put(std::move(leptons), "leptons");
195  event.put(std::move(jets), "jets");
196  event.put(std::move(fatjets), "fatjets");
197  event.put(std::move(consts), "consts");
198  event.put(std::move(tags), "tags");
199  event.put(std::move(mets), "mets");
200 }
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
Vector3 met() const
Definition: RivetAnalysis.h:30
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
std::vector< GenJet > GenJetCollection
collection of GenJet objects
Particles leptons() const
Definition: RivetAnalysis.h:25
const edm::ParameterSet pset_
std::vector< reco::MET > METCollection
collection of MET objects
Definition: METCollection.h:22
Jets fatjets() const
Definition: RivetAnalysis.h:29
void setVertex(const Point &vertex) override
set vertex
void setCharge(Charge q) final
set electric charge
Jets jets() const
Definition: RivetAnalysis.h:28
reco::Candidate::LorentzVector p4(const T &p) const
Definition: MET.h:41
T sqrt(T t)
Definition: SSEVec.h:19
vector< PseudoJet > jets
def move
Definition: eostools.py:511
Jets made from MC generator particles.
Definition: GenJet.h:23
tuple genEvent
Definition: MCTruth.py:34
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)
Rivet::RivetAnalysis * rivetAnalysis_
std::unique_ptr< Rivet::AnalysisHandler > analysisHandler_
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
const edm::EDGetTokenT< edm::HepMCProduct > srcToken_
void addDaughter(const CandidatePtr &)
add a daughter via a reference
Particles photons() const
Definition: RivetAnalysis.h:26
Particles neutrinos() const
Definition: RivetAnalysis.h:27
void setPdgId(int pdgId) final
void setP4(const LorentzVector &p4) final
set 4-momentum
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
math::PtEtaPhiELorentzVectorF LorentzVector
reco::Particle::Point genVertex_

Member Data Documentation

std::unique_ptr<Rivet::AnalysisHandler> ParticleLevelProducer::analysisHandler_
private

Definition at line 45 of file ParticleLevelProducer.h.

Referenced by produce().

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

Definition at line 42 of file ParticleLevelProducer.h.

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

const edm::ParameterSet ParticleLevelProducer::pset_
private

Definition at line 40 of file ParticleLevelProducer.h.

Referenced by produce().

Rivet::RivetAnalysis* ParticleLevelProducer::rivetAnalysis_ = nullptr
private

Definition at line 44 of file ParticleLevelProducer.h.

Referenced by produce().

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

Definition at line 39 of file ParticleLevelProducer.h.

Referenced by produce().