CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ComphepSingletopFilter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: GenFilters
4 // Class: ComphepSingletopFilter
5 //
13 //
14 // Original Author: Vladimir Molchanov
15 // Created: Wed Mar 25 19:43:12 CET 2009
16 //
17 //
18 
19 
20 // system include files
21 #include <vector>
22 #include <boost/format.hpp>
23 
24 // user include files
27 
28 
29 //
30 // class declaration
31 //
32 
34  hepMCProductTag_(iConfig.getParameter<edm::InputTag>("hepMCProductTag")) {
35  ptsep = iConfig.getParameter<double>("pTSep");
36 }
37 
38 
40 
41 
43  read22 = read23 = 0;
44  pass22 = pass23 = 0;
45 }
46 
47 
49  using namespace std;
50  cout << "Proc: 2-->2 2-->3 Total" << endl;
51  cout << boost::format("Read: %9d %9d %9d") % read22 % read23 % (read22+read23)
52  << endl;
53  cout << boost::format("Pass: %9d %9d %9d") % pass22 % pass23 % (pass22+pass23)
54  << endl;
55 }
56 
57 
60  const edm::EventSetup& iSetup) {
61 
62  using namespace std;
63  using namespace HepMC;
64 
66  iEvent.getByLabel(hepMCProductTag_, evt);
67  const HepMC::GenEvent * myEvt = evt->GetEvent();
68 // myEvt->print(); // to print the record
69 
70  const GenParticle * gp_clep = NULL;
71 
72  for (GenEvent::particle_const_iterator it = myEvt->particles_begin();
73  it != myEvt->particles_end(); ++it) {
74  if ((*it)->status() == 3) {
75  int abs_id = abs((*it)->pdg_id());
76  if (abs_id==11 || abs_id==13 || abs_id==15) {
77  gp_clep = *it;
78  break;
79  }
80  }
81  }
82 
83  if (! gp_clep) {
84  cerr << "ERROR: ComphepSingletopFilter: no charged lepton" << endl;
85  return false;
86  }
87 
88  int id_bdec = 0;
89  vector<const GenParticle *> vgp_bsec;
90 
91  GenVertex * gv_hard = gp_clep->production_vertex();
92 
93  for (GenVertex::particle_iterator it = gv_hard->particles_begin(children);
94  it != gv_hard->particles_end(children); ++it) {
95  int pdg_id = (*it)->pdg_id();
96  if (abs(pdg_id) == 5) {
97  if (pdg_id * (gp_clep->pdg_id()) < 0) {
98  id_bdec = pdg_id;
99  } else {
100  vgp_bsec.push_back(*it);
101  }
102  }
103  }
104 
105  bool process22 = (vgp_bsec.size() == 0);
106 
107  GenVertex * gv = NULL;
108  if (process22) {
109  for (GenVertex::particle_iterator it = gv_hard->particles_begin(parents);
110  it != gv_hard->particles_end(parents); ++it) {
111  if ((*it)->pdg_id() == id_bdec) {
112  gv = (*it)->production_vertex();
113  break;
114  }
115  }
116  if (! gv) {
117  cerr << "ERROR: ComphepSingletopFilter: HepMC inconsistency" << endl;
118  myEvt->print();
119  return false;
120  }
121  } else {
122  gv = vgp_bsec.back()->end_vertex();
123  }
124  const GenParticle * gp;
125  while (gv) {
126  gp = NULL;
127  for (GenVertex::particle_iterator it = gv->particles_begin(children);
128  it != gv->particles_end(children); ++it) {
129  if ((*it)->pdg_id() == -id_bdec) {
130  if (!gp || (*it)->momentum().perp2() > gp->momentum().perp2()) {
131  gp = *it;
132  }
133  }
134  }
135  if (gp) {
136  gv = gp->end_vertex();
137  vgp_bsec.push_back(gp);
138  } else {
139  gv = NULL;
140  }
141  }
142 
143  if (vgp_bsec.size() == 0) {
144  cerr << "ERROR: ComphepSingletopFilter: HepMC inconsistency" << endl;
145  return false;
146  }
147 
148  double pt = vgp_bsec.back()->momentum().perp();
149  bool pass;
150  if (process22) {
151  read22 += 1;
152  pass = pt < ptsep;
153  if (pass) pass22 += 1;
154  } else {
155  read23 += 1;
156  pass = ptsep <= pt;
157  if (pass) pass23 += 1;
158  }
159 
160  return pass;
161 }
162 
163 
T getParameter(std::string const &) const
TPRegexp parents
Definition: eve_filter.cc:21
#define NULL
Definition: scimark2.h:8
string format
Some error handling for the usage.
virtual bool filter(edm::Event &, const edm::EventSetup &)
int iEvent
Definition: GenABIO.cc:230
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:420
ComphepSingletopFilter(const edm::ParameterSet &)
tuple cout
Definition: gather_cfg.py:121