CMS 3D CMS Logo

ParticleLevelProducer.cc
Go to the documentation of this file.
2 
11 
12 #include "Rivet/Analysis.hh"
13 
14 using namespace std;
15 using namespace edm;
16 using namespace reco;
17 using namespace Rivet;
18 
20  srcToken_(consumes<edm::HepMCProduct>(pset.getParameter<edm::InputTag>("src"))),
21  rivetAnalysis_(new Rivet::RivetAnalysis(pset))
22 {
23  usesResource("Rivet");
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_.setIgnoreBeams(true);
37  analysisHandler_.addAnalysis(rivetAnalysis_);
38 }
39 
40 void ParticleLevelProducer::addGenJet(Rivet::Jet jet, std::unique_ptr<reco::GenJetCollection> &jets,
41  std::unique_ptr<reco::GenParticleCollection> &consts, edm::RefProd<reco::GenParticleCollection>& constsRefHandle, int &iConstituent,
42  std::unique_ptr<reco::GenParticleCollection> &tags, edm::RefProd<reco::GenParticleCollection>& tagsRefHandle, int &iTag)
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() ) genJet.setPdgId(5);
50  else if ( jet.cTagged() ) genJet.setPdgId(4);
51  genJet.setJetArea(pjet.has_area() ? pjet.area() : 0);
52 
53  for ( auto const & p : jet.particles()) {
54  auto pp4 = p4(p);
55  bool match = false; int iMatch = -1;
56  for ( auto const & q : *consts ) {
57  ++iMatch;
58  if (q.p4() == pp4) { match = true; break; }
59  }
60  if (match){
61  genJet.addDaughter(edm::refToPtr(reco::GenParticleRef(constsRefHandle, iMatch)));
62  }
63  else {
64  consts->push_back(reco::GenParticle(p.charge(), pp4, genVertex_, p.pdgId(), 1, true));
65  genJet.addDaughter(edm::refToPtr(reco::GenParticleRef(constsRefHandle, ++iConstituent)));
66  }
67  }
68  for ( auto const & p : jet.tags()) {
69  // The tag particles are accessible as jet daughters, so scale down p4 for safety.
70  // p4 needs to be multiplied by 1e20 for fragmentation analysis.
71  auto pp4 = p4(p)*1e-20;
72  bool match = false; int iMatch = -1;
73  for ( auto const & q : *tags ) {
74  ++iMatch;
75  if (q.p4() == pp4) { match = true; break; }
76  }
77  if (match){
78  genJet.addDaughter(edm::refToPtr(reco::GenParticleRef(tagsRefHandle, iMatch)));
79  }
80  else {
81  tags->push_back(reco::GenParticle(p.charge(), p4(p)*1e-20, genVertex_, p.pdgId(), 2, true));
82  genJet.addDaughter(edm::refToPtr(reco::GenParticleRef(tagsRefHandle, ++iTag)));
83  }
84  }
85 
86  jets->push_back(genJet);
87 }
88 
90 {
91  using namespace Rivet;
93 
94  std::unique_ptr<reco::GenParticleCollection> neutrinos(new reco::GenParticleCollection);
95  std::unique_ptr<reco::GenParticleCollection> photons(new reco::GenParticleCollection);
96  std::unique_ptr<reco::GenJetCollection> leptons(new reco::GenJetCollection);
97  std::unique_ptr<reco::GenJetCollection> jets(new reco::GenJetCollection);
98  std::unique_ptr<reco::GenJetCollection> fatjets(new reco::GenJetCollection);
99  std::unique_ptr<reco::GenParticleCollection> consts(new reco::GenParticleCollection);
100  std::unique_ptr<reco::GenParticleCollection> tags(new reco::GenParticleCollection);
101  std::unique_ptr<reco::METCollection> mets(new reco::METCollection);
102  auto constsRefHandle = event.getRefBeforePut<reco::GenParticleCollection>("consts");
103  auto tagsRefHandle = event.getRefBeforePut<reco::GenParticleCollection>("tags");
104 
105  edm::Handle<HepMCProduct> srcHandle;
106  event.getByToken(srcToken_, srcHandle);
107 
108  const HepMC::GenEvent* genEvent = srcHandle->GetEvent();
109  analysisHandler_.analyze(*genEvent);
110 
111  // Convert into edm objects
112  // Prompt neutrinos
113  for ( auto const & p : rivetAnalysis_->neutrinos() ) {
114  neutrinos->push_back(reco::GenParticle(p.charge(), p4(p), genVertex_, p.pdgId(), 1, true));
115  }
116  std::sort(neutrinos->begin(), neutrinos->end(), GreaterByPt<reco::Candidate>());
117 
118  // Photons
119  for ( auto const & p : rivetAnalysis_->photons() ) {
120  photons->push_back(reco::GenParticle(p.charge(), p4(p), genVertex_, p.pdgId(), 1, true));
121  }
122  std::sort(photons->begin(), photons->end(), GreaterByPt<reco::Candidate>());
123 
124  // Prompt leptons
125  int iConstituent = -1;
126  int iTag = -1;
127  for ( auto const & lepton : rivetAnalysis_->leptons() ) {
128  reco::GenJet lepJet;
129  lepJet.setP4(p4(lepton));
130  lepJet.setVertex(genVertex_);
131  lepJet.setPdgId(lepton.pdgId());
132  lepJet.setCharge(lepton.charge());
133 
134  const auto& cl = lepton.constituentLepton();
135  consts->push_back(reco::GenParticle(cl.charge(), p4(cl), genVertex_, cl.pdgId(), 1, true));
136  lepJet.addDaughter(edm::refToPtr(reco::GenParticleRef(constsRefHandle, ++iConstituent)));
137 
138  for ( auto const & p : lepton.constituentPhotons()) {
139  // ghost taus (momentum scaled with 10e-20 in RivetAnalysis.h already)
140  if (p.abspid() == 15) {
141  tags->push_back(reco::GenParticle(p.charge(), p4(p), genVertex_, p.pdgId(), 2, true));
142  lepJet.addDaughter(edm::refToPtr(reco::GenParticleRef(tagsRefHandle, ++iTag)));
143  }
144  // photons
145  else {
146  consts->push_back(reco::GenParticle(p.charge(), p4(p), genVertex_, p.pdgId(), 1, true));
147  lepJet.addDaughter(edm::refToPtr(reco::GenParticleRef(constsRefHandle, ++iConstituent)));
148  }
149  }
150 
151  leptons->push_back(lepJet);
152  }
153  std::sort(leptons->begin(), leptons->end(), GreaterByPt<reco::GenJet>());
154 
155  // Jets with constituents and tag particles
156  for ( auto jet : rivetAnalysis_->jets() ) {
157  addGenJet(jet, jets, consts, constsRefHandle, iConstituent, tags, tagsRefHandle, iTag);
158  }
159  for ( auto jet : rivetAnalysis_->fatjets() ) {
160  addGenJet(jet, fatjets, consts, constsRefHandle, iConstituent, tags, tagsRefHandle, iTag);
161  }
162 
163  // MET
165  mets->push_back(reco::MET(metP4, genVertex_));
166 
167  event.put(std::move(neutrinos), "neutrinos");
168  event.put(std::move(photons), "photons");
169  event.put(std::move(leptons), "leptons");
170  event.put(std::move(jets), "jets");
171  event.put(std::move(fatjets), "fatjets");
172  event.put(std::move(consts), "consts");
173  event.put(std::move(tags), "tags");
174  event.put(std::move(mets), "mets");
175 }
176 
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
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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
void setVertex(const Point &vertex) override
set vertex
ParticleVector neutrinos() const
Definition: RivetAnalysis.h:28
void setCharge(Charge q) final
set electric charge
Definition: LeafCandidate.h:93
Jets jets() const
Definition: RivetAnalysis.h:29
virtual void setJetArea(float fArea)
set jet area
Definition: Jet.h:103
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
math::XYZPoint Point
point in the space
Definition: Particle.h:25
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)
Rivet::RivetAnalysis * rivetAnalysis_
ParticleLevelProducer(const edm::ParameterSet &pset)
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
const edm::EDGetTokenT< edm::HepMCProduct > srcToken_
void produce(edm::Event &event, const edm::EventSetup &eventSetup) override
fixed size matrix
HLT enums.
Rivet::AnalysisHandler analysisHandler_
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
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
def move(src, dest)
Definition: eostools.py:510
Definition: event.py:1
math::PtEtaPhiELorentzVectorF LorentzVector
reco::Particle::Point genVertex_