CMS 3D CMS Logo

PythiaProbeFilter.cc
Go to the documentation of this file.
1 
3 
4 
6 #include <iostream>
7 
8 using namespace edm;
9 using namespace std;
10 using namespace Pythia8;
11 
12 
14 token_(consumes<edm::HepMCProduct>(edm::InputTag(iConfig.getUntrackedParameter("moduleLabel",std::string("generator")),"unsmeared"))),
15 particleID(iConfig.getUntrackedParameter("ParticleID", 0)),
16 MomID(iConfig.getUntrackedParameter("MomID", 0)),
17 GrandMomID(iConfig.getUntrackedParameter("GrandMomID", 0)),
18 chargeconju(iConfig.getUntrackedParameter("ChargeConjugation", true)),
19 nsisters(iConfig.getUntrackedParameter("NumberOfSisters", 0)),
20 naunts(iConfig.getUntrackedParameter("NumberOfAunts", 0)),
21 minptcut(iConfig.getUntrackedParameter("MinPt", 0.)),
22 maxptcut(iConfig.getUntrackedParameter("MaxPt", 14000.)),
23 minetacut(iConfig.getUntrackedParameter("MinEta", -10.)),
24 maxetacut(iConfig.getUntrackedParameter("MaxEta", 10.)),
25 countQEDCorPhotons(iConfig.getUntrackedParameter("countQEDCorPhotons", false))
26 {
27  //now do what ever initialization is needed
28  vector<int> defID;
29  defID.push_back(0);
30  exclsisIDs = iConfig.getUntrackedParameter< vector<int> >("SisterIDs",defID);
31  exclauntIDs = iConfig.getUntrackedParameter< vector<int> >("AuntIDs",defID);
32  identicalParticle=false;
33  for( unsigned int ilist=0; ilist< exclsisIDs.size(); ++ilist) {
34  if (fabs(exclsisIDs[ilist])==fabs(particleID))
35  identicalParticle=true;
36  }
37  // create pythia8 instance to access particle data
38  edm::LogInfo("PythiaProbeFilter::PythiaProbeFilter") << "Creating pythia8 instance for particle properties" << endl;
39  if(!fLookupGen.get()) fLookupGen.reset(new Pythia());
40 }
41 
42 
44 {
45 
46  // do anything here that needs to be done at desctruction time
47  // (e.g. close files, deallocate resources etc.)
48 
49 }
50 
51 bool PythiaProbeFilter::AlreadyExcludedCheck(std::vector<unsigned int> excludedList, unsigned int current_part) const
52 {
53  bool result=false;
54  for (unsigned int checkNow: excludedList ){
55  if (current_part!=checkNow) continue;
56  result=true; break;
57  }
58  return result;
59 }
60 //
61 // member functions
62 //
63 // ------------ method called to produce the data ------------
65 {
66  using namespace edm;
67  bool accepted = false;
69  iEvent.getByToken(token_, evt);
70 
71  const HepMC::GenEvent * myGenEvent = evt->GetEvent();
72 
73  //access particles
74  for ( HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin(); p != myGenEvent->particles_end(); ++p ) {
75  //select tag particle
76  if (fabs((*p)->pdg_id()) == fabs(particleID))
77  if( (*p)->pdg_id() != particleID && !chargeconju ) continue;
78 
79  if( fabs((*p)->pdg_id()) != fabs(particleID) && chargeconju ) continue;
80  //kinematic properties of tag
81  if ((*p)->momentum().perp()< minptcut || (*p)->momentum().perp()>maxptcut )
82  continue;
83  if ((*p)->momentum().eta()< minetacut || (*p)->momentum().eta()>maxetacut ) continue;
84  //remove probe side particles
85  bool excludeTagParticle=false;
86  if (naunts==0){
87  if ( (*p)->production_vertex()) {
88  for ( HepMC::GenVertex::particle_iterator anc=(*p)->production_vertex()->particles_begin(HepMC::parents); anc != (*p)->production_vertex()->particles_end(HepMC::parents); ++anc ) {
89  if (fabs((*anc)->pdg_id())!=fabs(MomID) && chargeconju) continue;
90  else if ((*anc)->pdg_id()!=MomID && !chargeconju) continue;
91  int nsis=0; int exclsis=0; std::vector<unsigned int> checklistSis;
92  if ((*anc)->end_vertex()){
93  for ( HepMC::GenVertex::particle_iterator sis=(*anc)->end_vertex()->particles_begin(HepMC::children); sis != (*anc)->end_vertex()->particles_end(HepMC::children); ++sis ) {
94  //identify the tag particle in the decay
95  if ((*p)->pdg_id()==(*sis)->pdg_id() && (identicalParticle || !chargeconju)) continue;
96  if (fabs((*p)->pdg_id())==fabs((*sis)->pdg_id()) && !identicalParticle && chargeconju) continue;
97  //remove QED photons
98  if ((*sis)->pdg_id()==22 && !countQEDCorPhotons) continue;
99  nsis++;
100  //check if this sis is excluded already
101  for( unsigned int ilist=0; ilist< exclsisIDs.size(); ++ilist) {
102  if(AlreadyExcludedCheck(checklistSis,ilist)){
103  continue;}
104  if (fabs(exclsisIDs[ilist])==fabs((*sis)->pdg_id()) && chargeconju){
105  exclsis++; checklistSis.push_back(ilist);
106  }
107  if (exclsisIDs[ilist]==(*sis)->pdg_id() && !chargeconju){
108  exclsis++; checklistSis.push_back(ilist);
109  }
110  }
111  }
112  }
113  if (nsis==exclsis && nsis==nsisters) {
114  excludeTagParticle=true; break;}
115  }
116  }
117  }
118  else if (naunts>0){
119  //now take into account that we have up 2 generations in the decay
120  if ( (*p)->production_vertex() ) {
121  for ( HepMC::GenVertex::particle_iterator anc=(*p)->production_vertex()->particles_begin(HepMC::parents); anc != (*p)->production_vertex()->particles_end(HepMC::parents); ++anc ) {
122  if (fabs((*anc)->pdg_id())!=fabs(MomID) && chargeconju) continue;
123  else if ((*anc)->pdg_id()!=MomID && !chargeconju) continue;
124  int nsis=0; int exclsis=0; std::vector<unsigned int> checklistSis;
125  int naunt=0; int exclaunt=0; std::vector<unsigned int> checklistAunt;
126  if ((*anc)->end_vertex()){
127  for ( HepMC::GenVertex::particle_iterator sis=(*anc)->end_vertex()->particles_begin(HepMC::children); sis != (*anc)->end_vertex()->particles_end(HepMC::children); ++sis ) {
128  //identify the particle under study in the decay
129  if ((*p)->pdg_id()==(*sis)->pdg_id() && (identicalParticle || !chargeconju)) continue;
130  if (fabs((*p)->pdg_id())==fabs((*sis)->pdg_id()) && !identicalParticle && chargeconju) continue;
131  //remove QED photons
132  if ((*sis)->pdg_id()==22 && !countQEDCorPhotons) continue;
133  nsis++;
134  for( unsigned int ilist=0; ilist< exclsisIDs.size(); ++ilist) {
135  if(AlreadyExcludedCheck(checklistSis,ilist)) continue;
136  if (fabs(exclsisIDs[ilist])==fabs((*sis)->pdg_id()) && chargeconju){
137  exclsis++; checklistSis.push_back(ilist);}
138  if (exclsisIDs[ilist]==(*sis)->pdg_id() && !chargeconju){
139  exclsis++; checklistSis.push_back(ilist); }
140  }
141  }
142  }
143  //check sisters
144  if (nsis!=exclsis || nsis!=nsisters) break;
145  if ( (*anc)->production_vertex() ) {
146  for ( HepMC::GenVertex::particle_iterator granc=(*anc)->production_vertex()->particles_begin(HepMC::parents); granc != (*anc)->production_vertex()->particles_end(HepMC::parents); ++granc ) {
147  if (fabs((*granc)->pdg_id())!=fabs(GrandMomID) && chargeconju)
148  continue;
149  else if ((*granc)->pdg_id()!=GrandMomID && !chargeconju)
150  continue;
151  for ( HepMC::GenVertex::particle_iterator aunt=(*granc)->end_vertex()->particles_begin(HepMC::children); aunt != (*granc)->end_vertex()->particles_end(HepMC::children); ++aunt ) {
152  if ((*aunt)->pdg_id()==(*anc)->pdg_id()) continue;
153  if ((*aunt)->pdg_id()==22 && !countQEDCorPhotons) continue;
154  naunt++;
155  for( unsigned int ilist=0; ilist< exclauntIDs.size(); ++ilist) {
156  if(AlreadyExcludedCheck(checklistAunt,ilist)) continue;
157  if (fabs(exclauntIDs[ilist])==fabs((*aunt)->pdg_id()) && chargeconju){
158  exclaunt++; checklistAunt.push_back(ilist); }
159  if (exclauntIDs[ilist]==(*aunt)->pdg_id() && !chargeconju){
160  exclaunt++; checklistAunt.push_back(ilist); }
161  }
162  }
163  }
164  }
165  //check aunts
166  if (naunt==exclaunt && naunt==naunts) {
167  excludeTagParticle=true; break;}
168  }
169  }
170  }
171  if (excludeTagParticle) continue;
172  accepted = true;
173  break;
174  }
175 
176  if (accepted){
177  return true; }
178  else {
179  return false;}
180 
181 }
T getUntrackedParameter(std::string const &, T const &) const
TPRegexp parents
Definition: eve_filter.cc:21
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
~PythiaProbeFilter() override
const double minetacut
bool filter(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
const double maxptcut
int iEvent
Definition: GenABIO.cc:224
std::vector< int > exclsisIDs
const double maxetacut
const edm::EDGetTokenT< edm::HepMCProduct > token_
PythiaProbeFilter(const edm::ParameterSet &)
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
bool accepted(std::vector< std::string_view > const &, std::string_view)
bool AlreadyExcludedCheck(std::vector< unsigned int > excludedList, unsigned int current_part) const
HLT enums.
std::vector< int > exclauntIDs
const double minptcut
std::unique_ptr< Pythia8::Pythia > fLookupGen
const bool countQEDCorPhotons