Skip to content

Commit 821d9f0

Browse files
author
Michele Mormile
committed
Fixed code checks and format
1 parent de637b5 commit 821d9f0

File tree

2 files changed

+70
-47
lines changed

2 files changed

+70
-47
lines changed

GeneratorInterface/GenFilters/plugins/PhotonGenFilter.cc

Lines changed: 65 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,33 @@ bool PhotonGenFilter::filter(edm::StreamID, edm::Event &iEvent, const edm::Event
2828
bool accepted_event = false;
2929

3030
for (HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin(); p != myGenEvent->particles_end();
31-
++p) { // loop through all particles
32-
if ((*p)->pdg_id() == 22 && !hasAncestor(*p,[](int x){return x > 30 && x != 2212;})) { // loop through all photons that don't come from hadrons
31+
++p) { // loop through all particles
32+
if ((*p)->pdg_id() == 22 && !hasAncestor(*p, [](int x) {
33+
return x > 30 && x != 2212;
34+
})) { // loop through all photons that don't come from hadrons
3335
if ((*p)->momentum().perp() > ptMin && (*p)->status() == 1 && (*p)->momentum().eta() > etaMin &&
34-
(*p)->momentum().eta() < etaMax) { // check if photon passes pt and eta cuts
36+
(*p)->momentum().eta() < etaMax) { // check if photon passes pt and eta cuts
3537
bool good_photon = true;
3638
double phi = (*p)->momentum().phi();
3739
double eta = (*p)->momentum().eta();
3840
double pt = (*p)->momentum().perp();
39-
double frixione_isolation_coefficient = pt/(1-cos(drMin));
41+
double frixione_isolation_coefficient = pt / (1 - cos(drMin));
4042
vector<double> particles_pt, particles_deltar;
4143
for (HepMC::GenEvent::particle_const_iterator q = myGenEvent->particles_begin();
4244
q != myGenEvent->particles_end();
43-
++q) { // loop through all particles to compute frixione isolation
44-
if (&p != &q) { // don't compare the photon to itself
45+
++q) { // loop through all particles to compute frixione isolation
46+
if (&p != &q) { // don't compare the photon to itself
4547
if ((*q)->momentum().perp() > ptThreshold && (*q)->pdg_id() != 22 && (*q)->pdg_id() != 12 &&
4648
(*q)->pdg_id() != 14 && (*q)->pdg_id() != 16 &&
47-
(*q)->status() == 1)
48-
{ // check if particle passes pt and status cuts and is not a neutrino or photon
49+
(*q)->status() == 1) { // check if particle passes pt and status cuts and is not a neutrino or photon
4950
double phi2 = (*q)->momentum().phi();
5051
double deltaphi = fabs(phi - phi2);
5152
if (deltaphi > M_PI)
5253
deltaphi = 2. * M_PI - deltaphi;
5354
double eta2 = (*q)->momentum().eta();
5455
double deltaeta = fabs(eta - eta2);
5556
double deltaR = sqrt(deltaeta * deltaeta + deltaphi * deltaphi);
56-
if (deltaR < drMin) // check if particle is within drMin of photon, for isolation
57+
if (deltaR < drMin) // check if particle is within drMin of photon, for isolation
5758
{
5859
particles_pt.push_back((*q)->momentum().perp());
5960
particles_deltar.push_back(deltaR);
@@ -62,12 +63,9 @@ bool PhotonGenFilter::filter(edm::StreamID, edm::Event &iEvent, const edm::Event
6263
}
6364
}
6465
//order particles_pt and particles_deltar according to increasing particles_deltar
65-
for (unsigned int i = 0; i < particles_deltar.size(); i++)
66-
{
67-
for (unsigned int j = i + 1; j < particles_deltar.size(); j++)
68-
{
69-
if (particles_deltar[i] > particles_deltar[j])
70-
{
66+
for (unsigned int i = 0; i < particles_deltar.size(); i++) {
67+
for (unsigned int j = i + 1; j < particles_deltar.size(); j++) {
68+
if (particles_deltar[i] > particles_deltar[j]) {
7169
double temp = particles_deltar[i];
7270
particles_deltar[i] = particles_deltar[j];
7371
particles_deltar[j] = temp;
@@ -79,20 +77,29 @@ bool PhotonGenFilter::filter(edm::StreamID, edm::Event &iEvent, const edm::Event
7977
}
8078
//calculate frixione isolation
8179
double total_pt = 0;
82-
for (unsigned int i = 0; i < particles_deltar.size(); i++)
83-
{
80+
for (unsigned int i = 0; i < particles_deltar.size(); i++) {
8481
total_pt += particles_pt[i];
85-
if (total_pt > frixione_isolation_coefficient * (1 - cos(particles_deltar[i])))
86-
{
87-
good_photon = false; // if for some delta R the isolation condition is not satisfied, the photon is not good
82+
if (total_pt > frixione_isolation_coefficient * (1 - cos(particles_deltar[i]))) {
83+
good_photon =
84+
false; // if for some delta R the isolation condition is not satisfied, the photon is not good
8885
break;
8986
}
9087
}
91-
if (good_photon){
92-
if (hasAncestor(*p,[](int x){return x == 11 || x == 13 || x ==15;}) || hasAncestor(*p,[](int x){return x == 24 || x == 5;},true,false)) { // check if photon is from decay and defines the event as acceptable
88+
if (good_photon) {
89+
if (hasAncestor(*p, [](int x) { return x == 11 || x == 13 || x == 15; }) ||
90+
hasAncestor(
91+
*p,
92+
[](int x) { return x == 24 || x == 5; },
93+
true,
94+
false)) { // check if photon is from decay and defines the event as acceptable
9395
accepted_event = true;
9496
}
95-
if (!hasAncestor(*p,[](int x){return x == 11 || x == 13 || x ==15;}) && hasAncestor(*p,[](int x){return x == 24 || x == 5;},false,true)) { // check if photon comes from the hard process and discards it, in case it is
97+
if (!hasAncestor(*p, [](int x) { return x == 11 || x == 13 || x == 15; }) &&
98+
hasAncestor(
99+
*p,
100+
[](int x) { return x == 24 || x == 5; },
101+
false,
102+
true)) { // check if photon comes from the hard process and discards it, in case it is
96103
return false;
97104
}
98105
}
@@ -115,36 +122,48 @@ void PhotonGenFilter::fillDescriptions(edm::ConfigurationDescriptions &descripti
115122
descriptions.add("PhotonGenFilter", desc);
116123
}
117124

125+
bool PhotonGenFilter::hasAncestor(
126+
HepMC::GenParticle *particle,
127+
function<bool(int)> check,
128+
bool isWorBFromDecayCheck,
129+
bool isWorBPromptCheck) const { // function to check if a particle has a certain ancestor
130+
if (!particle)
131+
return false;
118132

119-
bool PhotonGenFilter::hasAncestor(HepMC::GenParticle* particle, function<bool(int)> check,bool isWorBFromDecayCheck,bool isWorBPromptCheck) const { // function to check if a particle has a certain ancestor
120-
if (!particle) return false;
121-
122-
HepMC::GenVertex* prodVertex = particle->production_vertex();
133+
HepMC::GenVertex *prodVertex = particle->production_vertex();
123134

124135
// If the particle doesn't have a production vertex, it has no parents.
125-
if (!prodVertex) return false;
136+
if (!prodVertex)
137+
return false;
126138

127139
// Loop over all parents (incoming particles) of the vertex
128-
for (auto parent = prodVertex->particles_begin(HepMC::parents);
129-
parent != prodVertex->particles_end(HepMC::parents); ++parent) {
130-
131-
int pdgId = abs((*parent)->pdg_id());
132-
133-
// Check if the PDG ID respects a check
134-
if (check(pdgId)) {
135-
if (isWorBFromDecayCheck) {
136-
return hasAncestor(*parent,[](int x){return x == 6;},false,false); // if the photon has a W or b quark ancestor, check if it comes from a top quark
137-
}
138-
else if (isWorBPromptCheck) {
139-
return !hasAncestor(*parent,[](int x){return x == 6;},false,false); // if the photon has a W or b quark ancestor, check that it doesn't come from a top quark decay (therefore it comes form the hard process)
140-
}
141-
else return true;
142-
}
140+
for (auto parent = prodVertex->particles_begin(HepMC::parents); parent != prodVertex->particles_end(HepMC::parents);
141+
++parent) {
142+
int pdgId = abs((*parent)->pdg_id());
143+
144+
// Check if the PDG ID respects a check
145+
if (check(pdgId)) {
146+
if (isWorBFromDecayCheck) {
147+
return hasAncestor(
148+
*parent,
149+
[](int x) { return x == 6; },
150+
false,
151+
false); // if the photon has a W or b quark ancestor, check if it comes from a top quark
152+
} else if (isWorBPromptCheck) {
153+
return !hasAncestor(
154+
*parent,
155+
[](int x) { return x == 6; },
156+
false,
157+
false); // if the photon has a W or b quark ancestor, check that it doesn't come from a top quark decay (therefore it comes form the hard process)
158+
} else
159+
return true;
160+
}
143161

144-
return hasAncestor(*parent, check,isWorBFromDecayCheck,isWorBPromptCheck); // Recursively check the ancestry of the parent
145-
}
162+
return hasAncestor(
163+
*parent, check, isWorBFromDecayCheck, isWorBPromptCheck); // Recursively check the ancestry of the parent
164+
}
146165

147-
return false;
166+
return false;
148167
}
149168

150169
DEFINE_FWK_MODULE(PhotonGenFilter);

GeneratorInterface/GenFilters/plugins/PhotonGenFilter.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "FWCore/Framework/interface/MakerMacros.h"
1212

1313
#include "FWCore/ParameterSet/interface/ParameterSet.h"
14+
#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
1415

1516
namespace edm {
1617
class HepMCProduct;
@@ -22,7 +23,10 @@ class PhotonGenFilter : public edm::global::EDFilter<> {
2223
~PhotonGenFilter() override;
2324

2425
bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
25-
bool hasAncestor(HepMC::GenParticle* particle, std::function<bool(int)> check,bool isWorBFromDecayCheck=false,bool isWorBPromptCheck=false) const;
26+
bool hasAncestor(HepMC::GenParticle* particle,
27+
std::function<bool(int)> check,
28+
bool isWorBFromDecayCheck = false,
29+
bool isWorBPromptCheck = false) const;
2630
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
2731

2832
private:

0 commit comments

Comments
 (0)