CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions
HepMCValidationHelper Namespace Reference

Functions

void allStatus1 (const HepMC::GenEvent *all, std::vector< const HepMC::GenParticle * > &status1)
 
void allStatus2 (const HepMC::GenEvent *all, std::vector< const HepMC::GenParticle * > &status2)
 
void allStatus3 (const HepMC::GenEvent *all, std::vector< const HepMC::GenParticle * > &status3)
 
void allVisibleParticles (const HepMC::GenEvent *all, std::vector< const HepMC::GenParticle * > &visible)
 
void findDescendents (const HepMC::GenParticle *a, std::vector< const HepMC::GenParticle * > &descendents)
 
void findFSRPhotons (const std::vector< const HepMC::GenParticle * > &leptons, const std::vector< const HepMC::GenParticle * > &all, double deltaR, std::vector< const HepMC::GenParticle * > &photons)
 
void findFSRPhotons (const std::vector< const HepMC::GenParticle * > &leptons, const HepMC::GenEvent *all, double deltaR, std::vector< const HepMC::GenParticle * > &photons)
 
TLorentzVector genMet (const HepMC::GenEvent *all, double etamin=-9999., double etamax=9999.)
 
template<class T >
bool GreaterByE (const T &a1, const T &a2)
 
bool isChargedLepton (const HepMC::GenParticle *part)
 
bool isNeutrino (const HepMC::GenParticle *part)
 
bool isTau (const HepMC::GenParticle *part)
 
void removeIsolatedLeptons (const HepMC::GenEvent *all, double deltaR, double sumPt, std::vector< const HepMC::GenParticle * > &pruned)
 
bool sortByE (const HepMC::GenParticle *a, const HepMC::GenParticle *b)
 
bool sortByPseudoRapidity (const HepMC::GenParticle *a, const HepMC::GenParticle *b)
 
bool sortByPt (const HepMC::GenParticle *a, const HepMC::GenParticle *b)
 
bool sortByRapidity (const HepMC::GenParticle *a, const HepMC::GenParticle *b)
 

Function Documentation

void HepMCValidationHelper::allStatus1 ( const HepMC::GenEvent all,
std::vector< const HepMC::GenParticle * > &  status1 
)

Definition at line 72 of file HepMCValidationHelper.cc.

Referenced by allVisibleParticles(), MBUEandQCDValidation::analyze(), findFSRPhotons(), and removeIsolatedLeptons().

72  {
73  for (HepMC::GenEvent::particle_const_iterator iter = all->particles_begin(); iter != all->particles_end(); ++iter) {
74  if ((*iter)->status() == 1)
75  status1.push_back(*iter);
76  }
77  }
void HepMCValidationHelper::allStatus2 ( const HepMC::GenEvent all,
std::vector< const HepMC::GenParticle * > &  status2 
)

Definition at line 79 of file HepMCValidationHelper.cc.

Referenced by removeIsolatedLeptons().

79  {
80  for (HepMC::GenEvent::particle_const_iterator iter = all->particles_begin(); iter != all->particles_end(); ++iter) {
81  if ((*iter)->status() == 2)
82  status1.push_back(*iter);
83  }
84  }
void HepMCValidationHelper::allStatus3 ( const HepMC::GenEvent all,
std::vector< const HepMC::GenParticle * > &  status3 
)

Definition at line 86 of file HepMCValidationHelper.cc.

86  {
87  for (HepMC::GenEvent::particle_const_iterator iter = all->particles_begin(); iter != all->particles_end(); ++iter) {
88  if ((*iter)->status() == 3)
89  status1.push_back(*iter);
90  }
91  }
void HepMCValidationHelper::allVisibleParticles ( const HepMC::GenEvent all,
std::vector< const HepMC::GenParticle * > &  visible 
)

Definition at line 267 of file HepMCValidationHelper.cc.

References allStatus1(), mps_fire::i, and isNeutrino().

Referenced by genMet().

267  {
268  std::vector<const HepMC::GenParticle*> status1;
269  visible.clear();
270  allStatus1(all, status1);
271  for (unsigned int i = 0; i < status1.size(); ++i) {
272  if (!isNeutrino(status1[i]))
273  visible.push_back(status1[i]);
274  }
275  }
void allStatus1(const HepMC::GenEvent *all, std::vector< const HepMC::GenParticle * > &status1)
bool isNeutrino(const Candidate &part)
Definition: pdgIdUtils.h:17
void HepMCValidationHelper::findDescendents ( const HepMC::GenParticle *  a,
std::vector< const HepMC::GenParticle * > &  descendents 
)

Definition at line 93 of file HepMCValidationHelper.cc.

Referenced by removeIsolatedLeptons().

93  {
94  HepMC::GenVertex* decayVertex = a->end_vertex();
95  if (!decayVertex)
96  return;
97  HepMC::GenVertex::particles_out_const_iterator ipart;
98  for (ipart = decayVertex->particles_out_const_begin(); ipart != decayVertex->particles_out_const_end(); ++ipart) {
99  if ((*ipart)->status() == 1)
100  descendents.push_back(*ipart);
101  else
102  findDescendents(*ipart, descendents);
103  }
104  }
double a
Definition: hdecay.h:119
void findDescendents(const reco::GenParticleRef &base, reco::GenParticleRefVector &descendents, int status, int pdgId=0)
find all descendents of a given status and pdgId (recursive)
void HepMCValidationHelper::findFSRPhotons ( const std::vector< const HepMC::GenParticle * > &  leptons,
const std::vector< const HepMC::GenParticle * > &  all,
double  deltaR,
std::vector< const HepMC::GenParticle * > &  photons 
)

Definition at line 20 of file HepMCValidationHelper.cc.

References HLT_FULL_cff::deltaR, mps_fire::i, and mps_update::status.

Referenced by WValidation::analyze(), DrellYanValidation::analyze(), findFSRPhotons(), and removeIsolatedLeptons().

23  {
24  //find all status 1 photons
25  std::vector<const HepMC::GenParticle*> allphotons;
26  for (unsigned int i = 0; i < all.size(); ++i) {
27  if (all[i]->status() == 1 && all[i]->pdg_id() == 22)
28  allphotons.push_back(all[i]);
29  }
30 
31  //loop over the photons and check the distance wrt the leptons
32  for (unsigned int ipho = 0; ipho < allphotons.size(); ++ipho) {
33  bool close = false;
34  for (unsigned int ilep = 0; ilep < leptons.size(); ++ilep) {
35  if (deltaR(allphotons[ipho]->momentum(), leptons[ilep]->momentum()) < deltaRcut) {
36  close = true;
37  break;
38  }
39  }
40  if (close)
41  fsrphotons.push_back(allphotons[ipho]);
42  }
43  }
list status
Definition: mps_update.py:107
def all
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
void HepMCValidationHelper::findFSRPhotons ( const std::vector< const HepMC::GenParticle * > &  leptons,
const HepMC::GenEvent all,
double  deltaR,
std::vector< const HepMC::GenParticle * > &  photons 
)

Definition at line 11 of file HepMCValidationHelper.cc.

References allStatus1(), and findFSRPhotons().

14  {
15  std::vector<const HepMC::GenParticle*> status1;
16  allStatus1(all, status1);
17  findFSRPhotons(leptons, status1, deltaRcut, fsrphotons);
18  }
void findFSRPhotons(const std::vector< const HepMC::GenParticle * > &leptons, const std::vector< const HepMC::GenParticle * > &all, double deltaR, std::vector< const HepMC::GenParticle * > &photons)
void allStatus1(const HepMC::GenEvent *all, std::vector< const HepMC::GenParticle * > &status1)
TLorentzVector HepMCValidationHelper::genMet ( const HepMC::GenEvent all,
double  etamin = -9999.,
double  etamax = 9999. 
)

Definition at line 278 of file HepMCValidationHelper.cc.

References allVisibleParticles(), mps_fire::i, objects.METAnalyzer::met, and submitPVValidationJobs::t.

Referenced by GenSpecificAlgo::addInfo(), WValidation::analyze(), HLTJetMETValidation::analyze(), pat::GenMETExtractor::produce(), HLTTauMCProducer::produce(), and l1t::GenToInputProducer::produce().

278  {
279  std::vector<const HepMC::GenParticle*> visible;
280  allVisibleParticles(all, visible);
281  TLorentzVector momsum(0., 0., 0., 0.);
282  for (unsigned int i = 0; i < visible.size(); ++i) {
283  if (visible[i]->momentum().eta() > etamin && visible[i]->momentum().eta() < etamax) {
284  TLorentzVector mom(visible[i]->momentum().x(),
285  visible[i]->momentum().y(),
286  visible[i]->momentum().z(),
287  visible[i]->momentum().t());
288  momsum += mom;
289  }
290  }
291  TLorentzVector met(-momsum.Px(), -momsum.Py(), 0., momsum.Pt());
292  return met;
293  }
float float float z
uint16_t const *__restrict__ x
Definition: gpuClustering.h:39
void allVisibleParticles(const HepMC::GenEvent *all, std::vector< const HepMC::GenParticle * > &visible)
template<class T >
bool HepMCValidationHelper::GreaterByE ( const T a1,
const T a2 
)
inline

Definition at line 10 of file HepMCValidationHelper.h.

10  {
11  return a1.E() > a2.E();
12  }
bool HepMCValidationHelper::isChargedLepton ( const HepMC::GenParticle *  part)

Definition at line 46 of file HepMCValidationHelper.cc.

References funct::abs(), and mps_update::status.

Referenced by removeIsolatedLeptons().

46  {
47  int status = part->status();
48  unsigned int pdg_id = abs(part->pdg_id());
49  if (status == 2)
50  return pdg_id == 15;
51  else
52  return status == 1 && (pdg_id == 11 || pdg_id == 13);
53  }
list status
Definition: mps_update.py:107
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
part
Definition: HCALResponse.h:20
bool HepMCValidationHelper::isNeutrino ( const HepMC::GenParticle *  part)

Definition at line 56 of file HepMCValidationHelper.cc.

References funct::abs(), and mps_update::status.

Referenced by allVisibleParticles(), and removeIsolatedLeptons().

56  {
57  int status = part->status();
58  unsigned int pdg_id = abs(part->pdg_id());
59  return status == 1 && (pdg_id == 12 || pdg_id == 14 || pdg_id == 16);
60  }
list status
Definition: mps_update.py:107
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
part
Definition: HCALResponse.h:20
bool HepMCValidationHelper::isTau ( const HepMC::GenParticle *  part)

Definition at line 63 of file HepMCValidationHelper.cc.

References funct::abs().

Referenced by removeIsolatedLeptons().

63 { return part->status() == 2 && abs(part->pdg_id()) == 15; }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
part
Definition: HCALResponse.h:20
void HepMCValidationHelper::removeIsolatedLeptons ( const HepMC::GenEvent all,
double  deltaR,
double  sumPt,
std::vector< const HepMC::GenParticle * > &  pruned 
)

Definition at line 106 of file HepMCValidationHelper.cc.

References allStatus1(), allStatus2(), gather_cfg::cout, HLT_FULL_cff::deltaR, findDescendents(), findFSRPhotons(), mps_fire::i, isChargedLepton(), isNeutrino(), isTau(), dqmiolumiharvest::j, HLT_FULL_cff::leptons, submitPVValidationJobs::t, and runTauDisplay::taus.

Referenced by MBUEandQCDValidation::analyze().

109  {
110  //get all status 1 particles
111  std::vector<const HepMC::GenParticle*> status1;
112  allStatus1(all, status1);
113  std::vector<const HepMC::GenParticle*> toRemove;
114  //loop on all particles and find candidates to be isolated
115  for (unsigned int i = 0; i < status1.size(); ++i) {
116  //if it is a neutrino is a charged lepton (not a tau) this is a candidate to be isolated
117  if (isNeutrino(status1[i]) || (isChargedLepton(status1[i]) && !isTau(status1[i]))) {
118  //list of particles not to be considered in the isolation computation.
119  //this includes the particle to be isolated and the fsr photons in case of charged lepton
120  std::vector<const HepMC::GenParticle*> leptons;
121  leptons.push_back(status1[i]);
122  std::vector<const HepMC::GenParticle*> removedForIsolation;
123  removedForIsolation.push_back(status1[i]);
124  if (isChargedLepton(status1[i]))
125  findFSRPhotons(leptons, status1, deltaRcut, removedForIsolation);
126 #ifdef DEBUG_HepMCValidationHelper
127  //std::cout << removedForIsolation.size() << " particles to be removed for isolation calculation " << std::endl;
128 #endif
129  //create vector of particles to compute isolation (removing removedForIsolation);
130  std::vector<const HepMC::GenParticle*> forIsolation;
131  std::vector<const HepMC::GenParticle*>::iterator iiso;
132  for (iiso = status1.begin(); iiso != status1.end(); ++iiso) {
133  std::vector<const HepMC::GenParticle*>::const_iterator iremove;
134  bool marked = false;
135  for (iremove = removedForIsolation.begin(); iremove != removedForIsolation.end(); ++iremove) {
136  if ((*iiso)->barcode() == (*iremove)->barcode()) {
137 #ifdef DEBUG_HepMCValidationHelper
138  //std::cout << "removing particle " << **iiso << " from the list of particles to compute isolation" << std::endl;
139 #endif
140  marked = true;
141  break;
142  }
143  }
144  if (!marked)
145  forIsolation.push_back(*iiso);
146  }
147  //now compute isolation
148  double sumIso = 0;
149  for (iiso = forIsolation.begin(); iiso < forIsolation.end(); ++iiso) {
150  if (deltaR(leptons.front()->momentum(), (*iiso)->momentum()) < deltaRcut) {
151  sumIso += (*iiso)->momentum().perp();
152  }
153  }
154  //if isolated remove from the pruned list
155  if (sumIso < sumPtCut) {
156 #ifdef DEBUG_HepMCValidationHelper
157  std::cout << "particle " << *status1[i] << " is considered isolated, with sumPt " << sumIso << std::endl;
158 #endif
159  toRemove.insert(toRemove.end(), removedForIsolation.begin(), removedForIsolation.end());
160  }
161 #ifdef DEBUG_HepMCValidationHelper
162  else {
163  std::cout << "NOT isolated! " << *status1[i] << " is considered not isolated, with sumPt " << sumIso
164  << std::endl;
165  }
166 #endif
167  }
168  }
169  //at this point we have taken care of the electrons and muons, but pruned could still contain the decay products of isolated taus,
170  //we want to remove these as well
171  std::vector<const HepMC::GenParticle*> status2;
172  allStatus2(all, status2);
173  std::vector<const HepMC::GenParticle*> taus;
174  //getTaus(all, taus);
175  for (unsigned int i = 0; i < status2.size(); ++i) {
176  if (isTau(status2[i])) {
177  //check the list we have already for duplicates
178  //there use to be duplicates in some generators (sherpa)
179  bool duplicate = false;
180  TLorentzVector taumomentum(status2[i]->momentum().x(),
181  status2[i]->momentum().y(),
182  status2[i]->momentum().z(),
183  status2[i]->momentum().t());
184  for (unsigned int j = 0; j < taus.size(); ++j) {
185  //compare momenta
186  TLorentzVector othermomentum(
187  taus[j]->momentum().x(), taus[j]->momentum().y(), taus[j]->momentum().z(), taus[j]->momentum().t());
188  othermomentum -= taumomentum;
189  if (status2[i]->pdg_id() == taus[j]->pdg_id() &&
190  othermomentum.E() < 0.1 && //std::numeric_limits<float>::epsilon() &&
191  othermomentum.P() < 0.1) { //std::numeric_limits<float>::epsilon()){
192  duplicate = true;
193  break;
194  }
195  }
196  if (!duplicate)
197  taus.push_back(status2[i]);
198  }
199  }
200  //loop over the taus, find the descendents, remove all these from the list of particles to compute isolation
201  for (unsigned int i = 0; i < taus.size(); ++i) {
202  std::vector<const HepMC::GenParticle*> taudaughters;
203  findDescendents(taus[i], taudaughters);
204  if (taudaughters.empty()) {
205  edm::LogError("HepMCValidationHelper") << "Tau with no daughters. This is a bug. Fix it";
206  abort();
207  }
208  const HepMC::FourVector& taumom = taus[i]->momentum();
209  //remove the daughters from the list of particles to compute isolation
210  std::vector<const HepMC::GenParticle*> forIsolation;
211  std::vector<const HepMC::GenParticle*>::iterator iiso;
212  for (iiso = status1.begin(); iiso < status1.end(); ++iiso) {
213  bool marked = false;
214  std::vector<const HepMC::GenParticle*>::const_iterator iremove;
215  for (iremove = taudaughters.begin(); iremove != taudaughters.end(); ++iremove) {
216  if ((*iiso)->barcode() == (*iremove)->barcode()) {
217 #ifdef DEBUG_HepMCValidationHelper
218 // std::cout << "removing particle " << **iiso << " from the list of particles to compute isolation because it comes from a tau" << std::endl;
219 #endif
220  marked = true;
221  break;
222  }
223  }
224  if (!marked)
225  forIsolation.push_back(*iiso);
226  }
227  //no compute isolation wrt the status 2 tau direction
228  double sumIso = 0;
229  for (iiso = forIsolation.begin(); iiso < forIsolation.end(); ++iiso) {
230  if (deltaR(taumom, (*iiso)->momentum()) < deltaRcut) {
231  sumIso += (*iiso)->momentum().perp();
232  }
233  }
234  //if isolated remove the tau daughters from the pruned list
235  if (sumIso < sumPtCut) {
236 #ifdef DEBUG_HepMCValidationHelper
237  std::cout << "particle " << *taus[i] << " is considered isolated, with sumPt " << sumIso << std::endl;
238 #endif
239  toRemove.insert(toRemove.end(), taudaughters.begin(), taudaughters.end());
240  }
241  }
242 
243  //now actually remove
244  pruned.clear();
245  for (unsigned int i = 0; i < status1.size(); ++i) {
246  bool marked = false;
247  std::vector<const HepMC::GenParticle*>::const_iterator iremove;
248  for (iremove = toRemove.begin(); iremove != toRemove.end(); ++iremove) {
249  if (status1[i]->barcode() == (*iremove)->barcode()) {
250  marked = true;
251  break;
252  }
253  }
254  if (!marked)
255  pruned.push_back(status1[i]);
256  }
257 
258 #ifdef DEBUG_HepMCValidationHelper
259  std::cout << "list of remaining particles:" << std::endl;
260  for (unsigned int i = 0; i < pruned.size(); ++i) {
261  std::cout << *pruned[i] << std::endl;
262  }
263 #endif
264  }
void findFSRPhotons(const std::vector< const HepMC::GenParticle * > &leptons, const std::vector< const HepMC::GenParticle * > &all, double deltaR, std::vector< const HepMC::GenParticle * > &photons)
bool isChargedLepton(const HepMC::GenParticle *part)
void allStatus1(const HepMC::GenEvent *all, std::vector< const HepMC::GenParticle * > &status1)
Log< level::Error, false > LogError
float float float z
bool isNeutrino(const Candidate &part)
Definition: pdgIdUtils.h:17
void allStatus2(const HepMC::GenEvent *all, std::vector< const HepMC::GenParticle * > &status2)
uint16_t const *__restrict__ x
Definition: gpuClustering.h:39
tuple cout
Definition: gather_cfg.py:144
void findDescendents(const reco::GenParticleRef &base, reco::GenParticleRefVector &descendents, int status, int pdgId=0)
find all descendents of a given status and pdgId (recursive)
bool isTau(const Candidate &part)
Definition: pdgIdUtils.h:11
bool HepMCValidationHelper::sortByE ( const HepMC::GenParticle *  a,
const HepMC::GenParticle *  b 
)
inline

Definition at line 20 of file HepMCValidationHelper.h.

20  {
21  return a->momentum().e() > b->momentum().e();
22  }
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119
bool HepMCValidationHelper::sortByPseudoRapidity ( const HepMC::GenParticle *  a,
const HepMC::GenParticle *  b 
)
inline

Definition at line 34 of file HepMCValidationHelper.h.

34  {
35  return a->momentum().eta() > b->momentum().eta();
36  }
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119
bool HepMCValidationHelper::sortByPt ( const HepMC::GenParticle *  a,
const HepMC::GenParticle *  b 
)
inline

Definition at line 15 of file HepMCValidationHelper.h.

Referenced by WValidation::analyze(), and DrellYanValidation::analyze().

15  {
16  return a->momentum().perp() > b->momentum().perp();
17  }
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119
bool HepMCValidationHelper::sortByRapidity ( const HepMC::GenParticle *  a,
const HepMC::GenParticle *  b 
)
inline

Definition at line 25 of file HepMCValidationHelper.h.

References log.

25  {
26  const HepMC::FourVector& amom = a->momentum();
27  const HepMC::FourVector& bmom = b->momentum();
28  double rapa = 0.5 * std::log((amom.e() + amom.z()) / (amom.e() - amom.z()));
29  double rapb = 0.5 * std::log((bmom.e() + bmom.z()) / (bmom.e() - bmom.z()));
30  return rapa > rapb;
31  }
static std::vector< std::string > checklist log
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119