CMS 3D CMS Logo

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 HepMC::GenEvent *all, double deltaR, std::vector< const HepMC::GenParticle * > &photons)
 
void findFSRPhotons (const std::vector< const HepMC::GenParticle * > &leptons, const std::vector< const HepMC::GenParticle * > &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

◆ allStatus1()

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

Definition at line 72 of file HepMCValidationHelper.cc.

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  }

References python.cmstools::all().

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

◆ allStatus2()

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

Definition at line 79 of file HepMCValidationHelper.cc.

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  }

References python.cmstools::all().

Referenced by removeIsolatedLeptons().

◆ allStatus3()

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  }

References python.cmstools::all().

◆ allVisibleParticles()

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

Definition at line 267 of file HepMCValidationHelper.cc.

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  }

References python.cmstools::all(), allStatus1(), mps_fire::i, and isNeutrino().

Referenced by genMet().

◆ findDescendents()

void HepMCValidationHelper::findDescendents ( const HepMC::GenParticle *  a,
std::vector< const HepMC::GenParticle * > &  descendents 
)

Definition at line 93 of file HepMCValidationHelper.cc.

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  }

References a.

Referenced by removeIsolatedLeptons().

◆ findFSRPhotons() [1/2]

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.

14  {
15  std::vector<const HepMC::GenParticle*> status1;
16  allStatus1(all, status1);
17  findFSRPhotons(leptons, status1, deltaRcut, fsrphotons);
18  }

References python.cmstools::all(), allStatus1(), findFSRPhotons(), and HLT_FULL_cff::leptons.

◆ findFSRPhotons() [2/2]

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.

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  }

References python.cmstools::all(), PbPb_ZMuSkimMuonDPG_cff::deltaR, mps_fire::i, HLT_FULL_cff::leptons, and mps_update::status.

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

◆ genMet()

TLorentzVector HepMCValidationHelper::genMet ( const HepMC::GenEvent all,
double  etamin = -9999.,
double  etamax = 9999. 
)

Definition at line 278 of file HepMCValidationHelper.cc.

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  }

References python.cmstools::all(), allVisibleParticles(), muonTiming_cfi::etamax, muonTiming_cfi::etamin, mps_fire::i, BTaggingMonitor_cfi::met, and submitPVValidationJobs::t.

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

◆ GreaterByE()

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  }

References testProducerWithPsetDescEmpty_cfi::a2.

◆ isChargedLepton()

bool HepMCValidationHelper::isChargedLepton ( const HepMC::GenParticle *  part)

Definition at line 46 of file HepMCValidationHelper.cc.

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  }

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

Referenced by removeIsolatedLeptons().

◆ isNeutrino()

bool HepMCValidationHelper::isNeutrino ( const HepMC::GenParticle *  part)

Definition at line 56 of file HepMCValidationHelper.cc.

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  }

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

Referenced by allVisibleParticles(), and removeIsolatedLeptons().

◆ isTau()

bool HepMCValidationHelper::isTau ( const HepMC::GenParticle *  part)

Definition at line 63 of file HepMCValidationHelper.cc.

63 { return part->status() == 2 && abs(part->pdg_id()) == 15; }

References funct::abs().

Referenced by removeIsolatedLeptons().

◆ removeIsolatedLeptons()

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.

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  }

References python.cmstools::all(), allStatus1(), allStatus2(), gather_cfg::cout, PbPb_ZMuSkimMuonDPG_cff::deltaR, findDescendents(), findFSRPhotons(), mps_fire::i, isChargedLepton(), isNeutrino(), isTau(), dqmiolumiharvest::j, HLT_FULL_cff::leptons, HiggsValidation_cfi::pdg_id, submitPVValidationJobs::t, and Tau3MuMonitor_cff::taus.

Referenced by MBUEandQCDValidation::analyze().

◆ sortByE()

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  }

References a, and b.

◆ sortByPseudoRapidity()

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  }

References a, and b.

◆ sortByPt()

bool HepMCValidationHelper::sortByPt ( const HepMC::GenParticle *  a,
const HepMC::GenParticle *  b 
)
inline

Definition at line 15 of file HepMCValidationHelper.h.

15  {
16  return a->momentum().perp() > b->momentum().perp();
17  }

References a, and b.

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

◆ sortByRapidity()

bool HepMCValidationHelper::sortByRapidity ( const HepMC::GenParticle *  a,
const HepMC::GenParticle *  b 
)
inline

Definition at line 25 of file HepMCValidationHelper.h.

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  }

References a, b, and dqm-mbProfile::log.

HiggsValidation_cfi.pdg_id
pdg_id
Definition: HiggsValidation_cfi.py:6
HepMCValidationHelper::allVisibleParticles
void allVisibleParticles(const HepMC::GenEvent *all, std::vector< const HepMC::GenParticle * > &visible)
Definition: HepMCValidationHelper.cc:267
mps_fire.i
i
Definition: mps_fire.py:428
HepMCValidationHelper::allStatus2
void allStatus2(const HepMC::GenEvent *all, std::vector< const HepMC::GenParticle * > &status2)
Definition: HepMCValidationHelper.cc:79
detailsBasic3DVector::z
float float float z
Definition: extBasic3DVector.h:14
HLT_FULL_cff.leptons
leptons
Definition: HLT_FULL_cff.py:26283
mps_update.status
status
Definition: mps_update.py:69
Tau3MuMonitor_cff.taus
taus
Definition: Tau3MuMonitor_cff.py:7
gather_cfg.cout
cout
Definition: gather_cfg.py:144
HepMCValidationHelper::findFSRPhotons
void findFSRPhotons(const std::vector< const HepMC::GenParticle * > &leptons, const std::vector< const HepMC::GenParticle * > &all, double deltaR, std::vector< const HepMC::GenParticle * > &photons)
Definition: HepMCValidationHelper.cc:20
python.cmstools.all
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:26
muonTiming_cfi.etamin
etamin
Definition: muonTiming_cfi.py:30
reco::isNeutrino
bool isNeutrino(const Candidate &part)
Definition: pdgIdUtils.h:17
testProducerWithPsetDescEmpty_cfi.a2
a2
Definition: testProducerWithPsetDescEmpty_cfi.py:35
BTaggingMonitor_cfi.met
met
Definition: BTaggingMonitor_cfi.py:84
part
part
Definition: HCALResponse.h:20
b
double b
Definition: hdecay.h:118
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
a
double a
Definition: hdecay.h:119
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
HepMCValidationHelper::isChargedLepton
bool isChargedLepton(const HepMC::GenParticle *part)
Definition: HepMCValidationHelper.cc:46
muonTiming_cfi.etamax
etamax
Definition: muonTiming_cfi.py:23
genVertex_cff.x
x
Definition: genVertex_cff.py:12
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
reco::isTau
bool isTau(const Candidate &part)
Definition: pdgIdUtils.h:11
HepMCValidationHelper::allStatus1
void allStatus1(const HepMC::GenEvent *all, std::vector< const HepMC::GenParticle * > &status1)
Definition: HepMCValidationHelper.cc:72
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
GenParticlesHelper::findDescendents
void findDescendents(const reco::GenParticleRef &base, reco::GenParticleRefVector &descendents, int status, int pdgId=0)
find all descendents of a given status and pdgId (recursive)
Definition: GenParticlesHelper.cc:28