CMS 3D CMS Logo

ComphepSingletopFilterPy8.cc
Go to the documentation of this file.
1 // Package: GenFilters
2 // Class: ComphepSingletopFilterPy8
3 //
4 /*
5  class ComphepSingletopFilterPy8 ComphepSingletopFilterPy8.cc GeneratorInterface/GenFilters/src/ComphepSingletopFilterPy8.cc
6 
7  Description: a filter to match LO/NLO in comphep-generated singletop
8 
9  Implementation:
10  <Notes on implementation>
11 */
12 //
13 // Original Author: Vladimir Molchanov
14 // Created: Wed Mar 25 19:43:12 CET 2009
15 // $Id: ComphepSingletopFilterPy8.cc,v 1.3 2009/12/15 10:29:32 fabiocos Exp $
16 // Author: Alexey Baskakov
17 // Created: Oct 2014
18 // ComphepSingletopFilterPy8.cc,v 2.1
19 //
20 
21 // system include files
22 #include <vector>
23 #include <boost/format.hpp>
24 
25 // user include files
28 #include "CLHEP/Vector/LorentzVector.h"
29 
30 #include "HepMC/IO_GenEvent.h"
31 
32 
33 
34 using namespace std;
35 using namespace HepMC;
36 
38  token_(consumes<edm::HepMCProduct>(edm::InputTag(iConfig.getUntrackedParameter("moduleLabel",std::string("generator")),"unsmeared")))
39 {
40  ptsep = iConfig.getParameter<double>("pTSep");
41 }
42 
44 
46 {
47  read22 = read23 = 0;
48  pass22 = pass23 = 0;
49  hardLep = 23; //identifies the "hard part" in Pythia8
50  }
51 
53 {
54  cout << "Proc: 2-->2 2-->3 Total" << endl;
55  cout << boost::format("Read: %9d %9d %9d") % read22 % read23 % (read22+read23)
56  << endl;
57  cout << boost::format("Pass: %9d %9d %9d") % pass22 % pass23 % (pass22+pass23)
58  << endl;
59 }
60 
61 
63 {
64 
65 
67 //iEvent.getByLabel("generator","unsmeared", evt);
68 iEvent.getByToken(token_, evt);
69 const HepMC::GenEvent * myEvt = evt->GetEvent();
70 
71 int id_bdec=0, id_lJet=0, id_b_from_top=0, id_lep = 0;
72 //vars for lepton top
73 const GenParticle * gp_clep = nullptr;
74 GenVertex * gv_hard = nullptr;
75 
76 const GenParticle * gp_lep_FSR = nullptr;
77 GenVertex * gv_lep = nullptr;
78 vector<const GenParticle *> vgp_lep;
79 
80 //vars for add b from top
81 GenVertex * gv = nullptr;
82 const GenParticle * gp = nullptr;
83 vector<const GenParticle *> vgp_bsec;
84 
85 //vars for light Jet (light q)
86 GenVertex * gv_lJet= nullptr;
87 const GenParticle * gplJet= nullptr;
88 vector<const GenParticle *> vgp_lJet;
89 
90 //vars for b from top
91 GenVertex * gv_b_t= nullptr;
92 const GenParticle * gp_b_t= nullptr;
93 vector<const GenParticle *> vgp_b_t;
94 
95 
96 //Run through all particles in myEvt, if lepton found saves it gp_clep
97  for (GenEvent::particle_const_iterator it = myEvt->particles_begin(); it != myEvt->particles_end(); ++it)
98  {
99  if (abs((*it)->status()) == hardLep)
100  {
101  int abs_id = abs((*it)->pdg_id());//11=e, -11=E, 13=mu, -13=Mu, 15=l(tau), -15=L
102  if (abs_id==11 || abs_id==13 || abs_id==15)
103  {
104  gp_clep = *it;
105  id_lep = (*it)->pdg_id();
106  gv_lep=(*it)->production_vertex();
107  // Lepton FSR
108  while (gv_lep)
109  {
110  gp_lep_FSR = nullptr;
111  for (GenVertex::particle_iterator it = gv_lep->particles_begin(children); it != gv_lep->particles_end(children); ++it)
112  {
113  if ((*it)->pdg_id() == id_lep)
114  {
115  if (!gp_lep_FSR || (*it)->momentum().perp2() > gp_lep_FSR->momentum().perp2())
116  {
117  gp_lep_FSR = *it;
118  }
119  }
120  }
121  if (gp_lep_FSR)
122  {
123  gv_lep = gp_lep_FSR->end_vertex();
124  vgp_lep.push_back(gp_lep_FSR); //vertex of
125  }
126  else
127  {
128  gv_lep = nullptr; //exits the "while" loop
129  }
130  }
131  break;
132  }
133  }
134  }
135 // Goes to lepton production vertex
136  gv_hard = gp_clep->production_vertex();
137 
138  if (! gp_clep)
139  {
140  cout << "ERROR: ComphepSingletopFilterPy8: no charged lepton" << endl;
141  return false;
142  }
143 
144 
145 //Run through lepton production_vertex
146  for (GenVertex::particle_iterator it = gv_hard->particles_begin(children); it != gv_hard->particles_end(children); ++it)
147  {
148  int pdg_id = (*it)->pdg_id(); // KF in Pythia
149  int abs_id = abs(pdg_id);
150 
151 //selection of light quark among particles in primary vertex
152  if(abs_id<5)
153  {
154  id_lJet = (*it)->pdg_id();
155  gv_lJet=(*it)->production_vertex();
156 
157  while (gv_lJet)
158  {
159  gplJet = nullptr;
160  for (GenVertex::particle_iterator it = gv_lJet->particles_begin(children); it != gv_lJet->particles_end(children); ++it)
161  {
162  if ((*it)->pdg_id() == id_lJet)
163  {
164  if (!gplJet || (*it)->momentum().perp2() > gplJet->momentum().perp2())
165  {
166  gplJet = *it;
167  }
168  }
169  }
170 
171  if (gplJet)
172  {
173  gv_lJet = gplJet->end_vertex();
174  vgp_lJet.push_back(gplJet); //vertex of
175  }
176  else
177  {
178  gv_lJet = nullptr; //exits the "while" loop
179  }
180  }
181  }
182 
183  if (abs(pdg_id) == 5) // 5 = b
184  {
185  if (pdg_id * (gp_clep->pdg_id()) < 0)
186  { //b is from top
187  id_bdec = pdg_id;
188 
189  id_b_from_top = (*it)->pdg_id();
190  gv_b_t = (*it)->production_vertex();
191 
192  while (gv_b_t)
193  {
194  gp_b_t = nullptr;
195  for (GenVertex::particle_iterator it = gv_b_t->particles_begin(children); it != gv_b_t->particles_end(children); ++it)
196  {
197  if ((*it)->pdg_id() == id_b_from_top)
198  {
199  if (!gp_b_t || (*it)->momentum().perp2() > gp_b_t->momentum().perp2())
200  {
201  gp_b_t = *it;
202  }
203  }
204  }
205 
206  if (gp_b_t)
207  {
208  gv_b_t = gp_b_t->end_vertex();
209  vgp_b_t.push_back(gp_b_t); //vertex of
210  }
211  else
212  {
213  gv_b_t = nullptr; //exits the "while" loop
214  }
215  }
216  }
217  else
218  {//If process 2-3, then aditional b in the initial state fills
219  vgp_bsec.push_back(*it);
220  }
221  }
222  }
223 
224 
225 bool process22 = (vgp_bsec.empty()); //if there is no aditional b-quark in primary vexrtes, then it is tq-process (2->2)
226 
227  if (process22)
228  {
229  for (GenVertex::particle_iterator it = gv_hard->particles_begin(parents); it != gv_hard->particles_end(parents); ++it) //Among parents of lepton production vertex(primary vertex) we find b-quark.
230  {
231 
232  if ((*it)->pdg_id() == id_bdec)
233  {
234  gv = (*it)->production_vertex();
235  break;
236  }
237  }
238  if (! gv)
239  {
240  cerr << "ERROR: ComphepSingletopFilterPy8: HepMC inconsistency (! gv)" << endl;
241  myEvt->print();
242  return false;
243  }
244  }
245  else
246  {
247  gv = vgp_bsec.back()->end_vertex();
248  }
249 
250 //##Correction for GV vertex, because of additional gluons in ISR
251 bool WeFoundAdditional_b_quark = false;
252 int loopCount = 0, gv_loopCount = 0;
253  while (WeFoundAdditional_b_quark != true)
254  {
256  for (GenVertex::particle_iterator it = gv->particles_begin(children); it != gv->particles_end(children); ++it)
257  {
259  if ((*it)->pdg_id() == -id_bdec)
260  { //we found right vertex of ISR gluon splitting!
261  WeFoundAdditional_b_quark = true;//gv = (*it)->production_vertex();
262  }
263  }
264  if (WeFoundAdditional_b_quark == false)
265  {
267  for (GenVertex::particle_iterator it = gv->particles_begin(parents); it != gv->particles_end(parents); ++it)
268  {
269  if ((*it)->pdg_id() == id_bdec)
270  {
271  gv = (*it)->production_vertex();
272 
273  }
274  }
275  }
276  loopCount++;
277 
278  if (loopCount > 100)//loop protection, nothing more
279  {
280 cerr << "ERROR: ComphepSingletopFilterPy8: HepMC inconsistency (No add b vertex found)" << endl;
281  break;
282  }
283  }
284 
285 
286 
287  while (gv)
288  {
289  gp = nullptr;
290 
291  for (GenVertex::particle_iterator it = gv->particles_begin(children); it != gv->particles_end(children); ++it)
292  {
293  if ((*it)->pdg_id() == -id_bdec)
294  {
295  if (!gp || (*it)->momentum().perp2() > gp->momentum().perp2())
296  {
297  gp = *it;
298 
299  }
300  }
301  }
302  if (gp)
303  {
304  gv = gp->end_vertex();
305  vgp_bsec.push_back(gp); //vertex of
306  }
307  else
308  {
309  gv = nullptr; //exits the "while" loop
310  }
311  gv_loopCount++;
312  }
313 
314 
315  if (vgp_bsec.empty())
316  {
317  cerr << "ERROR: ComphepSingletopFilterPy8: HepMC inconsistency (vgp_bsec.size() == 0)" << endl;
318  return false;
319  }
320 
321  double pt = vgp_bsec.back()->momentum().perp();
322  // double eta = vgp_bsec.back()->momentum().eta();
323  bool pass;
324  if (process22)
325  {
326  read22 += 1;
327  pass = pt < ptsep;
328  if (pass) pass22 += 1;
329  }
330  else
331  {
332  read23 += 1;
333  pass = ptsep <= pt;
334  if (pass) pass23 += 1;
335  }
336  return pass;
337 }
338 
339 
T getParameter(std::string const &) const
TPRegexp parents
Definition: eve_filter.cc:21
ComphepSingletopFilterPy8(const edm::ParameterSet &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
int iEvent
Definition: GenABIO.cc:224
bool filter(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< edm::HepMCProduct > token_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
format
Some error handling for the usage.
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
HLT enums.