CMS 3D CMS Logo

TopGenEvent.cc
Go to the documentation of this file.
3 
7 
12 }
13 
14 const reco::GenParticle* TopGenEvent::candidate(int id, unsigned int parentId) const {
15  const reco::GenParticle* cand = nullptr;
16  const reco::GenParticleCollection& partsColl = *parts_;
17  for (unsigned int i = 0; i < partsColl.size(); ++i) {
18  if (partsColl[i].pdgId() == id) {
19  if (parentId == 0 ? true : partsColl[i].mother() && std::abs(partsColl[i].mother()->pdgId()) == (int)parentId) {
20  cand = &partsColl[i];
21  }
22  }
23  }
24  return cand;
25 }
26 
27 void TopGenEvent::print() const {
28  edm::LogVerbatim log("TopGenEvent");
29  log << "\n"
30  << "--------------------------------------\n"
31  << "- Dump TopGenEvent Content -\n"
32  << "--------------------------------------\n";
33  for (reco::GenParticleCollection::const_iterator part = parts_->begin(); part < parts_->end(); ++part) {
34  log << "pdgId:" << std::setw(5) << part->pdgId() << ", "
35  << "mass:" << std::setw(11) << part->p4().mass() << ", "
36  << "energy:" << std::setw(11) << part->energy() << ", "
37  << "pt:" << std::setw(11) << part->pt() << "\n";
38  }
39 }
40 
41 int TopGenEvent::numberOfLeptons(bool fromWBoson) const {
42  int lep = 0;
43  const reco::GenParticleCollection& partsColl = *parts_;
44  for (unsigned int i = 0; i < partsColl.size(); ++i) {
45  if (reco::isLepton(partsColl[i])) {
46  if (fromWBoson) {
47  if (partsColl[i].mother() && std::abs(partsColl[i].mother()->pdgId()) == TopDecayID::WID) {
48  ++lep;
49  }
50  } else {
51  ++lep;
52  }
53  }
54  }
55  return lep;
56 }
57 
58 int TopGenEvent::numberOfLeptons(WDecay::LeptonType typeRestriction, bool fromWBoson) const {
59  int leptonType = -1;
60  switch (typeRestriction) {
61  // resolve whether or not there is
62  // any restriction in lepton types
63  case WDecay::kElec:
65  break;
66  case WDecay::kMuon:
68  break;
69  case WDecay::kTau:
71  break;
72  case WDecay::kNone:
73  break;
74  }
75  int lep = 0;
76  const reco::GenParticleCollection& partsColl = *parts_;
77  for (unsigned int i = 0; i < partsColl.size(); ++i) {
78  if (fromWBoson) {
79  // restrict to particles originating from the W boson
80  if (!(partsColl[i].mother() && std::abs(partsColl[i].mother()->pdgId()) == TopDecayID::WID)) {
81  continue;
82  }
83  }
84  if (leptonType > 0) {
85  // in case of lepton type restriction
86  if (std::abs(partsColl[i].pdgId()) == leptonType) {
87  ++lep;
88  }
89  } else {
90  // take any lepton type into account else
91  if (reco::isLepton(partsColl[i])) {
92  ++lep;
93  }
94  }
95  }
96  return lep;
97 }
98 
99 int TopGenEvent::numberOfBQuarks(bool fromTopQuark) const {
100  int bq = 0;
101  const reco::GenParticleCollection& partsColl = *parts_;
102  for (unsigned int i = 0; i < partsColl.size(); ++i) {
103  //depend if radiation qqbar are included or not
104  if (std::abs(partsColl[i].pdgId()) == TopDecayID::bID) {
105  if (fromTopQuark) {
106  if (partsColl[i].mother() && std::abs(partsColl[i].mother()->pdgId()) == TopDecayID::tID) {
107  ++bq;
108  }
109  } else {
110  ++bq;
111  }
112  }
113  }
114  return bq;
115 }
116 
117 std::vector<const reco::GenParticle*> TopGenEvent::topSisters() const {
118  std::vector<const reco::GenParticle*> sisters;
119  for (reco::GenParticleCollection::const_iterator part = parts_->begin(); part < parts_->end(); ++part) {
120  if (part->numberOfMothers() == 0 && std::abs(part->pdgId()) != TopDecayID::tID) {
121  // choose top sister which do not have a
122  // mother and are whether top nor anti-top
123  if (dynamic_cast<const reco::GenParticle*>(&(*part)) == nullptr) {
124  throw edm::Exception(edm::errors::InvalidReference, "Not a GenParticle");
125  }
126  sisters.push_back(part->clone());
127  }
128  }
129  return sisters;
130 }
131 
132 const reco::GenParticle* TopGenEvent::daughterQuarkOfTop(bool invertCharge) const {
133  const reco::GenParticle* cand = nullptr;
134  for (reco::GenParticleCollection::const_iterator top = parts_->begin(); top < parts_->end(); ++top) {
135  if (top->pdgId() == (invertCharge ? -TopDecayID::tID : TopDecayID::tID)) {
136  for (reco::GenParticle::const_iterator quark = top->begin(); quark < top->end(); ++quark) {
137  if (std::abs(quark->pdgId()) <= TopDecayID::bID) {
138  cand = dynamic_cast<const reco::GenParticle*>(&(*quark));
139  if (cand == nullptr) {
140  throw edm::Exception(edm::errors::InvalidReference, "Not a GenParticle");
141  }
142  break;
143  }
144  }
145  }
146  }
147  return cand;
148 }
149 
150 const reco::GenParticle* TopGenEvent::daughterQuarkOfWPlus(bool invertQuarkCharge, bool invertBosonCharge) const {
151  const reco::GenParticle* cand = nullptr;
152  const reco::GenParticleCollection& partsColl = *parts_;
153  for (unsigned int i = 0; i < partsColl.size(); ++i) {
154  if (partsColl[i].mother() &&
155  partsColl[i].mother()->pdgId() == (invertBosonCharge ? -TopDecayID::WID : TopDecayID::WID) &&
156  std::abs(partsColl[i].pdgId()) <= TopDecayID::bID &&
157  (invertQuarkCharge ? reco::flavour(partsColl[i]) < 0 : reco::flavour(partsColl[i]) > 0)) {
158  cand = &partsColl[i];
159  }
160  }
161  return cand;
162 }
163 
164 std::vector<const reco::GenParticle*> TopGenEvent::lightQuarks(bool includingBQuarks) const {
165  std::vector<const reco::GenParticle*> lightQuarks;
166  for (reco::GenParticleCollection::const_iterator part = parts_->begin(); part < parts_->end(); ++part) {
167  if ((includingBQuarks && std::abs(part->pdgId()) == TopDecayID::bID) || std::abs(part->pdgId()) < TopDecayID::bID) {
168  if (dynamic_cast<const reco::GenParticle*>(&(*part)) == nullptr) {
169  throw edm::Exception(edm::errors::InvalidReference, "Not a GenParticle");
170  }
171  lightQuarks.push_back(part->clone());
172  }
173  }
174  return lightQuarks;
175 }
176 
177 std::vector<const reco::GenParticle*> TopGenEvent::radiatedGluons(int pdgId) const {
178  std::vector<const reco::GenParticle*> rads;
179  for (reco::GenParticleCollection::const_iterator part = parts_->begin(); part < parts_->end(); ++part) {
180  if (part->mother() && part->mother()->pdgId() == pdgId) {
181  if (part->pdgId() == TopDecayID::glueID) {
182  if (dynamic_cast<const reco::GenParticle*>(&(*part)) == nullptr) {
183  throw edm::Exception(edm::errors::InvalidReference, "Not a GenParticle");
184  }
185  }
186  rads.push_back(part->clone());
187  }
188  }
189  return rads;
190 }
edm::RefProd< GenParticleCollection >
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
edm::errors::InvalidReference
Definition: EDMException.h:39
TopGenEvent::numberOfBQuarks
int numberOfBQuarks(bool fromTopQuark=true) const
return number of b quarks in the decay chain
Definition: TopGenEvent.cc:99
TopGenEvent.h
reco::GenParticle
Definition: GenParticle.h:21
reco::flavour
int flavour(const Candidate &part)
Definition: pdgIdUtils.h:21
TopGenEvent::daughterQuarkOfWPlus
const reco::GenParticle * daughterQuarkOfWPlus(bool invertQuarkCharge=false, bool invertBosonCharge=false) const
return quark daughter quark of W boson
Definition: TopGenEvent.cc:150
TopDecayID::bID
static const int bID
Definition: TopGenEvent.h:13
reco::GenParticleCollection
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
Definition: GenParticleFwd.h:13
reco::candidate::const_iterator
Definition: const_iterator.h:14
TopGenEvent::initPartons_
reco::GenParticleRefProd initPartons_
reference to the list of initial partons (has to be kept in the event!)
Definition: TopGenEvent.h:113
TopGenEvent::radiatedGluons
std::vector< const reco::GenParticle * > radiatedGluons(int pdgId) const
return radiated gluons from particle with pdgId
Definition: TopGenEvent.cc:177
TopDecayID::elecID
static const int elecID
Definition: TopGenEvent.h:18
TopGenEvent::numberOfLeptons
int numberOfLeptons(bool fromWBoson=true) const
return number of leptons in the decay chain
Definition: TopGenEvent.cc:41
reco::isLepton
bool isLepton(const Candidate &part)
Definition: pdgIdUtils.h:13
GenParticle.h
EDMException.h
TopDecayID::muonID
static const int muonID
Definition: TopGenEvent.h:19
TopGenEvent::TopGenEvent
TopGenEvent()
empty constructor
Definition: TopGenEvent.h:43
TopDecayID::glueID
static const int glueID
Definition: TopGenEvent.h:14
part
part
Definition: HCALResponse.h:20
TopGenEvent::lightQuarks
std::vector< const reco::GenParticle * > lightQuarks(bool includingBQuarks=false) const
return all light quarks or all quarks including b's
Definition: TopGenEvent.cc:164
TopDecaySubset_cfi.decaySubset
decaySubset
Definition: TopDecaySubset_cfi.py:7
TopDecayID::tID
static const int tID
Definition: TopGenEvent.h:12
TopGenEvent::candidate
const reco::GenParticle * candidate(int id, unsigned int parentId=0) const
get candidate with given pdg id if available; 0 else
Definition: TopGenEvent.cc:14
TopGenEvent::top
const reco::GenParticle * top() const
return top if available; 0 else
Definition: TopGenEvent.h:101
reco::Candidate::end
const_iterator end() const
last daughter const_iterator
Definition: Candidate.h:145
reco::LeafCandidate::pdgId
int pdgId() const final
PDG identifier.
Definition: LeafCandidate.h:176
TopGenEvent::topSisters
std::vector< const reco::GenParticle * > topSisters() const
return number of top anti-top sisters
Definition: TopGenEvent.cc:117
cand
Definition: decayParser.h:32
createfilelist.int
int
Definition: createfilelist.py:10
EgammaValidation_cff.pdgId
pdgId
Definition: EgammaValidation_cff.py:117
pdgIdUtils.h
WDecay::kTau
Definition: TopGenEvent.h:27
TopDecayID::WID
static const int WID
Definition: TopGenEvent.h:17
TopDecayID::tauID
static const int tauID
Definition: TopGenEvent.h:20
WDecay::LeptonType
LeptonType
Definition: TopGenEvent.h:27
TopGenEvent::print
void print() const
Definition: TopGenEvent.cc:27
WDecay::kNone
Definition: TopGenEvent.h:27
TopInitSubset_cfi.initSubset
initSubset
Definition: TopInitSubset_cfi.py:7
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
WDecay::kMuon
Definition: TopGenEvent.h:27
Exception
Definition: hltDiff.cc:245
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
TopGenEvent::parts_
reco::GenParticleRefProd parts_
reference to the top decay chain (has to be kept in the event!)
Definition: TopGenEvent.h:111
objects.autophobj.leptonType
leptonType
BASIC VERSION WITH ONLY MAIN LEPTON ID CRITERIA.
Definition: autophobj.py:48
WDecay::kElec
Definition: TopGenEvent.h:27
edm::Log
Definition: MessageLogger.h:70
reco::Candidate::begin
const_iterator begin() const
first daughter const_iterator
Definition: Candidate.h:143
TopGenEvent::daughterQuarkOfTop
const reco::GenParticle * daughterQuarkOfTop(bool invertCharge=false) const
return daughter quark of top quark (which can have flavor b, s or d)
Definition: TopGenEvent.cc:132