6 #include "TLorentzVector.h"
10 namespace HepMCValidationHelper {
12 const HepMC::GenEvent*
all,
14 std::vector<const HepMC::GenParticle*>& fsrphotons){
16 std::vector<const HepMC::GenParticle*> status1;
22 const std::vector<const HepMC::GenParticle*>&
all,
24 std::vector<const HepMC::GenParticle*>& fsrphotons){
27 std::vector<const HepMC::GenParticle*> allphotons;
28 for (
unsigned int i = 0;
i < all.size(); ++
i){
29 if (all[
i]->
status()==1 && all[
i]->pdg_id()==22) allphotons.push_back(all[
i]);
33 for (
unsigned int ipho = 0; ipho < allphotons.size(); ++ipho){
35 for (
unsigned int ilep = 0; ilep < leptons.size(); ++ilep){
36 if (
deltaR(allphotons[ipho]->momentum(), leptons[ilep]->momentum()) < deltaRcut){
41 if (close) fsrphotons.push_back(allphotons[ipho]);
47 int status = part->status();
48 unsigned int pdg_id =
abs(part->pdg_id());
49 if (status == 2)
return pdg_id == 15;
50 else return status == 1 && (pdg_id == 11 || pdg_id == 13 ) ;
55 int status = part->status();
56 unsigned int pdg_id =
abs(part->pdg_id());
57 return status == 1 && (pdg_id == 12 || pdg_id == 14 || pdg_id == 16) ;
62 return part->status() == 2 &&
abs(part->pdg_id()) == 15;
72 void allStatus1(
const HepMC::GenEvent*
all, std::vector<const HepMC::GenParticle*>& status1){
73 for (HepMC::GenEvent::particle_const_iterator iter = all->particles_begin(); iter != all->particles_end(); ++iter){
74 if ((*iter)->status() == 1) status1.push_back(*iter);
78 void allStatus2(
const HepMC::GenEvent*
all, std::vector<const HepMC::GenParticle*>& status1){
79 for (HepMC::GenEvent::particle_const_iterator iter = all->particles_begin(); iter != all->particles_end(); ++iter){
80 if ((*iter)->status() == 2) status1.push_back(*iter);
84 void allStatus3(
const HepMC::GenEvent*
all, std::vector<const HepMC::GenParticle*>& status1){
85 for (HepMC::GenEvent::particle_const_iterator iter = all->particles_begin(); iter != all->particles_end(); ++iter){
86 if ((*iter)->status() == 3) status1.push_back(*iter);
91 HepMC::GenVertex* decayVertex = a->end_vertex();
92 if (!decayVertex)
return;
93 HepMC::GenVertex::particles_out_const_iterator ipart;
94 for (ipart = decayVertex->particles_out_const_begin(); ipart != decayVertex->particles_out_const_end(); ++ipart ){
95 if ((*ipart)->status() == 1) descendents.push_back(*ipart);
100 void removeIsolatedLeptons(
const HepMC::GenEvent*
all,
double deltaRcut,
double sumPtCut, std::vector<const HepMC::GenParticle*>& pruned) {
102 std::vector<const HepMC::GenParticle*> status1;
104 std::vector<const HepMC::GenParticle*> toRemove;
106 for (
unsigned int i = 0;
i < status1.size(); ++
i){
111 std::vector<const HepMC::GenParticle*>
leptons;
112 leptons.push_back(status1[i]);
113 std::vector<const HepMC::GenParticle*> removedForIsolation;
114 removedForIsolation.push_back(status1[i]);
116 #ifdef DEBUG_HepMCValidationHelper
120 std::vector<const HepMC::GenParticle*> forIsolation;
121 std::vector<const HepMC::GenParticle*>::iterator iiso;
122 for (iiso = status1.begin(); iiso != status1.end(); ++iiso){
123 std::vector<const HepMC::GenParticle*>::const_iterator iremove;
125 for ( iremove = removedForIsolation.begin(); iremove != removedForIsolation.end(); ++iremove){
126 if ((*iiso)->barcode() == (*iremove)->barcode()) {
127 #ifdef DEBUG_HepMCValidationHelper
134 if (!marked) forIsolation.push_back(*iiso);
138 for (iiso = forIsolation.begin(); iiso < forIsolation.end(); ++iiso){
139 if (
deltaR(leptons.front()->momentum(), (*iiso)->momentum()) < deltaRcut){
140 sumIso += (*iiso)->momentum().perp();
144 if (sumIso < sumPtCut) {
145 #ifdef DEBUG_HepMCValidationHelper
146 std::cout <<
"particle " << *status1[
i] <<
" is considered isolated, with sumPt " << sumIso << std::endl;
148 toRemove.insert(toRemove.end(), removedForIsolation.begin(), removedForIsolation.end());
150 #ifdef DEBUG_HepMCValidationHelper
152 std::cout <<
"NOT isolated! " << *status1[
i] <<
" is considered not isolated, with sumPt " << sumIso << std::endl;
159 std::vector<const HepMC::GenParticle*> status2;
161 std::vector<const HepMC::GenParticle*> taus;
163 for (
unsigned int i = 0;
i < status2.size(); ++
i){
167 bool duplicate =
false;
168 TLorentzVector taumomentum(status2[i]->momentum().
x(), status2[i]->momentum().
y(), status2[i]->momentum().
z(), status2[i]->momentum().
t());
169 for (
unsigned int j = 0;
j < taus.size(); ++
j){
171 TLorentzVector othermomentum(taus[
j]->momentum().
x(), taus[
j]->momentum().
y(), taus[
j]->momentum().
z(), taus[
j]->momentum().
t());
172 othermomentum-=taumomentum;
173 if (status2[i]->pdg_id() == taus[
j]->pdg_id() &&
174 othermomentum.E() < 0.1 &&
175 othermomentum.P() < 0.1 ){
180 if (!duplicate) taus.push_back(status2[i]);
184 for (
unsigned int i = 0;
i < taus.size(); ++
i){
185 std::vector<const HepMC::GenParticle*> taudaughters;
187 assert(taudaughters.size()>0);
188 const HepMC::FourVector& taumom = taus[
i]->momentum();
190 std::vector<const HepMC::GenParticle*> forIsolation;
191 std::vector<const HepMC::GenParticle*>::iterator iiso;
192 for (iiso = status1.begin(); iiso < status1.end(); ++iiso){
194 std::vector<const HepMC::GenParticle*>::const_iterator iremove;
195 for ( iremove = taudaughters.begin(); iremove != taudaughters.end(); ++iremove){
196 if ((*iiso)->barcode() == (*iremove)->barcode()) {
197 #ifdef DEBUG_HepMCValidationHelper
203 if (!marked) forIsolation.push_back(*iiso);
208 for (iiso = forIsolation.begin(); iiso < forIsolation.end(); ++iiso){
209 if (
deltaR(taumom, (*iiso)->momentum()) < deltaRcut){
210 sumIso += (*iiso)->momentum().perp();
214 if (sumIso < sumPtCut) {
215 #ifdef DEBUG_HepMCValidationHelper
216 std::cout <<
"particle " << *taus[
i] <<
" is considered isolated, with sumPt " << sumIso << std::endl;
218 toRemove.insert(toRemove.end(), taudaughters.begin(), taudaughters.end());
224 for (
unsigned int i = 0;
i < status1.size(); ++
i){
226 std::vector<const HepMC::GenParticle*>::const_iterator iremove;
227 for ( iremove = toRemove.begin(); iremove != toRemove.end(); ++iremove){
228 if (status1[
i]->barcode() == (*iremove)->barcode()){
233 if (!marked) pruned.push_back(status1[
i]);
236 #ifdef DEBUG_HepMCValidationHelper
237 std::cout<<
"list of remaining particles:" <<std::endl;
238 for (
unsigned int i = 0;
i < pruned.size(); ++
i){
246 std::vector<const HepMC::GenParticle*> status1;
249 for (
unsigned int i = 0;
i < status1.size(); ++
i){
250 if (!
isNeutrino(status1[
i])) visible.push_back(status1[i]);
255 TLorentzVector
genMet(
const HepMC::GenEvent*
all,
double etamin,
double etamax){
256 std::vector<const HepMC::GenParticle*> visible;
258 TLorentzVector momsum(0., 0., 0., 0.);
259 for (
unsigned int i = 0;
i < visible.size(); ++
i){
260 if (visible[
i]->momentum().eta() > etamin && visible[
i]->momentum().eta() < etamax) {
261 TLorentzVector mom(visible[
i]->momentum().
x(), visible[
i]->momentum().
y(), visible[
i]->momentum().
z(), visible[
i]->momentum().
t());
265 TLorentzVector
met(-momsum.Px(), -momsum.Py(), 0., momsum.Pt());
bool isTau(const HepMC::GenParticle *part)
void allStatus3(const HepMC::GenEvent *all, std::vector< const HepMC::GenParticle * > &status3)
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)
void removeIsolatedLeptons(const HepMC::GenEvent *all, double deltaR, double sumPt, std::vector< const HepMC::GenParticle * > &pruned)
void allStatus2(const HepMC::GenEvent *all, std::vector< const HepMC::GenParticle * > &status2)
void allVisibleParticles(const HepMC::GenEvent *all, std::vector< const HepMC::GenParticle * > &visible)
void findDescendents(const HepMC::GenParticle *a, std::vector< const HepMC::GenParticle * > &descendents)
double deltaR(double eta1, double eta2, double phi1, double phi2)
TLorentzVector genMet(const HepMC::GenEvent *all, double etamin=-9999., double etamax=9999.)
bool isNeutrino(const HepMC::GenParticle *part)