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 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)
 
template<class T >
bool sortByPtRef (const T lhs, const T rhs)
 
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 73 of file HepMCValidationHelper.cc.

References python.cmstools::all().

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

73  {
74  for (HepMC::GenEvent::particle_const_iterator iter = all->particles_begin(); iter != all->particles_end(); ++iter) {
75  if ((*iter)->status() == 1)
76  status1.push_back(*iter);
77  }
78  }
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25

◆ allStatus2()

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

Definition at line 80 of file HepMCValidationHelper.cc.

References python.cmstools::all().

Referenced by removeIsolatedLeptons().

80  {
81  for (HepMC::GenEvent::particle_const_iterator iter = all->particles_begin(); iter != all->particles_end(); ++iter) {
82  if ((*iter)->status() == 2)
83  status1.push_back(*iter);
84  }
85  }
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25

◆ allStatus3()

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

Definition at line 87 of file HepMCValidationHelper.cc.

References python.cmstools::all().

87  {
88  for (HepMC::GenEvent::particle_const_iterator iter = all->particles_begin(); iter != all->particles_end(); ++iter) {
89  if ((*iter)->status() == 3)
90  status1.push_back(*iter);
91  }
92  }
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25

◆ allVisibleParticles()

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

Definition at line 269 of file HepMCValidationHelper.cc.

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

Referenced by genMet().

269  {
270  std::vector<const HepMC::GenParticle*> status1;
271  visible.clear();
272  allStatus1(all, status1);
273  for (unsigned int i = 0; i < status1.size(); ++i) {
274  if (!isNeutrino(status1[i]))
275  visible.push_back(status1[i]);
276  }
277  }
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
bool isNeutrino(const Candidate &part)
Definition: pdgIdUtils.h:17
void allStatus1(const HepMC::GenEvent *all, std::vector< const HepMC::GenParticle *> &status1)

◆ findDescendents()

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

Definition at line 94 of file HepMCValidationHelper.cc.

References a.

Referenced by removeIsolatedLeptons().

94  {
95  HepMC::GenVertex* decayVertex = a->end_vertex();
96  if (!decayVertex)
97  return;
98  HepMC::GenVertex::particles_out_const_iterator ipart;
99  for (ipart = decayVertex->particles_out_const_begin(); ipart != decayVertex->particles_out_const_end(); ++ipart) {
100  if ((*ipart)->status() == 1)
101  descendents.push_back(*ipart);
102  else
103  findDescendents(*ipart, descendents);
104  }
105  }
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)

◆ findFSRPhotons() [1/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 21 of file HepMCValidationHelper.cc.

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

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

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

◆ findFSRPhotons() [2/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 12 of file HepMCValidationHelper.cc.

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

15  {
16  std::vector<const HepMC::GenParticle*> status1;
17  allStatus1(all, status1);
18  findFSRPhotons(leptons, status1, deltaRcut, fsrphotons);
19  }
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
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)

◆ genMet()

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

Definition at line 280 of file HepMCValidationHelper.cc.

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

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

280  {
281  std::vector<const HepMC::GenParticle*> visible;
282  allVisibleParticles(all, visible);
283  TLorentzVector momsum(0., 0., 0., 0.);
284  for (unsigned int i = 0; i < visible.size(); ++i) {
285  if (visible[i]->momentum().eta() > etamin && visible[i]->momentum().eta() < etamax) {
286  TLorentzVector mom(visible[i]->momentum().x(),
287  visible[i]->momentum().y(),
288  visible[i]->momentum().z(),
289  visible[i]->momentum().t());
290  momsum += mom;
291  }
292  }
293  TLorentzVector met(-momsum.Px(), -momsum.Py(), 0., momsum.Pt());
294  return met;
295  }
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
float float float z
void allVisibleParticles(const HepMC::GenEvent *all, std::vector< const HepMC::GenParticle *> &visible)
float x

◆ GreaterByE()

template<class T >
bool HepMCValidationHelper::GreaterByE ( const T a1,
const T a2 
)
inline

Definition at line 10 of file HepMCValidationHelper.h.

References testProducerWithPsetDescEmpty_cfi::a2.

10  {
11  return a1.E() > a2.E();
12  }

◆ isChargedLepton()

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

Definition at line 47 of file HepMCValidationHelper.cc.

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

Referenced by removeIsolatedLeptons().

47  {
48  int status = part->status();
49  unsigned int pdg_id = abs(part->pdg_id());
50  if (status == 2)
51  return pdg_id == 15;
52  else
53  return status == 1 && (pdg_id == 11 || pdg_id == 13);
54  }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
part
Definition: HCALResponse.h:20

◆ isNeutrino()

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

Definition at line 57 of file HepMCValidationHelper.cc.

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

Referenced by allVisibleParticles(), and removeIsolatedLeptons().

57  {
58  int status = part->status();
59  unsigned int pdg_id = abs(part->pdg_id());
60  return status == 1 && (pdg_id == 12 || pdg_id == 14 || pdg_id == 16);
61  }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
part
Definition: HCALResponse.h:20

◆ isTau()

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

Definition at line 64 of file HepMCValidationHelper.cc.

References funct::abs().

Referenced by removeIsolatedLeptons().

64 { 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

◆ removeIsolatedLeptons()

void HepMCValidationHelper::removeIsolatedLeptons ( const HepMC::GenEvent all,
double  deltaR,
double  sumPt,
std::vector< const HepMC::GenParticle *> &  pruned 
)

Definition at line 107 of file HepMCValidationHelper.cc.

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

Referenced by MBUEandQCDValidation::analyze().

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

◆ sortByE()

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

Definition at line 25 of file HepMCValidationHelper.h.

References a, and b.

25  {
26  return a->momentum().e() > b->momentum().e();
27  }
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119

◆ sortByPseudoRapidity()

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

Definition at line 39 of file HepMCValidationHelper.h.

References a, and b.

39  {
40  return a->momentum().eta() > b->momentum().eta();
41  }
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119

◆ sortByPt()

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

Definition at line 15 of file HepMCValidationHelper.h.

References a, and b.

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

◆ sortByPtRef()

template<class T >
bool HepMCValidationHelper::sortByPtRef ( const T  lhs,
const T  rhs 
)
inline

Definition at line 20 of file HepMCValidationHelper.h.

20  {
21  return lhs->pt() > rhs->pt();
22  }

◆ sortByRapidity()

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

Definition at line 30 of file HepMCValidationHelper.h.

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

30  {
31  const HepMC::FourVector& amom = a->momentum();
32  const HepMC::FourVector& bmom = b->momentum();
33  double rapa = 0.5 * std::log((amom.e() + amom.z()) / (amom.e() - amom.z()));
34  double rapb = 0.5 * std::log((bmom.e() + bmom.z()) / (bmom.e() - bmom.z()));
35  return rapa > rapb;
36  }
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119