CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
JetFlavourFilter.cc
Go to the documentation of this file.
2 
3 using namespace edm;
4 using namespace std;
5 using namespace HepMC;
6 
7 
8 
10 {
11  token_ = consumes<edm::HepMCProduct>(edm::InputTag(iConfig.getUntrackedParameter("moduleLabel",std::string("generator")),"unsmeared"));
12  jetType = iConfig.getParameter< int >("jetType");
13  if ((jetType>=1)&&(jetType<=3)) jetType=1;
14 
15  noAccepted = 0;
16 }
17 
18 
20 {
21  std::cout << "Total number of accepted events = " << noAccepted << std::endl;
22 }
23 
24 
26  const int requested_id)
27 {
28  for (GenPartVectIt p = genPartVect.begin(); p != genPartVect.end(); p++)
29  {
30  if (requested_id == (*p)->pdg_id()) return *p;
31  }
32  return 0;
33 }
34 
35 
36 
37 void
38 JetFlavourFilter::printHisto(const HepMC::GenEvent::particle_iterator start,
39  const HepMC::GenEvent::particle_iterator end)
40 {
41  HepMC::GenEvent::particle_iterator p;
42  for (p = start; p != end; p++)
43  {
44  //vector< GenParticle * > parents = (*p)->listParents();
45  vector< GenParticle * > parents;
46  HepMC::GenVertex* inVertex = (*p)->production_vertex();
47  for(std::vector<GenParticle*>::const_iterator iter = inVertex->particles_in_const_begin();
48  // for(GenVertex::particles_in_const_iterator iter = inVertex->particles_in_const_begin();
49  iter != inVertex->particles_in_const_end();iter++)
50  parents.push_back(*iter);
51 
52  cout << "isC "<<(*p)->pdg_id()<<" status "<<(*p)->status()<<" Parents: "<<parents.size()<<" - ";
53  for (GenPartVectIt z = parents.begin(); z != parents.end(); z++){
54  cout << (*z)->pdg_id()<<" ";
55  }
56 
57  //vector< GenParticle * > child = (*p)->listChildren();
58  vector< GenParticle * > child;
59  HepMC::GenVertex* outVertex = (*p)->end_vertex();
60  for(GenVertex::particles_in_const_iterator iter = outVertex->particles_in_const_begin();
61  iter != outVertex->particles_in_const_end();iter++)
62  child.push_back(*iter);
63 
64  cout << " - Child: "<<child.size()<<" - ";
65  for (GenPartVectIt z = child.begin(); z != child.end(); z++){
66  cout << (*z)->pdg_id()<<" ";
67  }
68  cout<<"\n";
69  }
70 }
71 
72 
74 {
76  iEvent.getByToken(token_, evt);
77 
78  const HepMC::GenEvent * generated_event = evt->GetEvent();
79 
80  bool event_passed = false;
81 
82  vector<int> foundQ;
83  HepMC::GenEvent::particle_const_iterator p;
84  for (p = generated_event->particles_begin(); p != generated_event->particles_end(); p++) {
85  if (((*p)->pdg_id() < 1) && ((*p)->pdg_id() > -10)) { // We have an anti-quark
86 // cout << "antiQ "<< (*p)->pdg_id();
87  //vector< GenParticle * > parents = (*p)->listParents();
88  vector< GenParticle * > parents;
89  HepMC::GenVertex* inVertex = (*p)->production_vertex();
90  for(GenVertex::particles_in_const_iterator iter = inVertex->particles_in_const_begin();
91  iter != inVertex->particles_in_const_end();iter++)
92  parents.push_back(*iter);
93 
94  for (GenPartVectIt z = parents.begin(); z != parents.end(); z++){
95 
96  vector< GenParticle * > child;
97  HepMC::GenVertex* outVertex = (*z)->end_vertex();
98  for(GenVertex::particles_in_const_iterator iter = outVertex->particles_in_const_begin();
99  iter != outVertex->particles_in_const_end();iter++)
100  child.push_back(*iter);
101 
102  if (findParticle(child, -(*p)->pdg_id())) foundQ.push_back(-(*p)->pdg_id());
103  }
104 // cout << " "<< foundQ.size()<<endl;
105 
106  }
107 
108  }
109 
110  int flavour = 0;
111  int ff[6];
112  ff[0]=0; ff[1]=0; ff[2]=0; ff[3]=0; ff[4]=0; ff[5]=0;
113  for (vector<int>::iterator i = foundQ.begin(); i != foundQ.end(); i++){
114  ++ff[(*i)-1];
115  if ((*i)>flavour) flavour = (*i);
116  }
117  // Is it light quark jet?
118  if ((flavour>=0)&&(flavour<=3)) flavour=1;
119  // Do we have more than one heavy flavour ?
120  if ( (ff[3] && ff[4]) || (ff[3] && ff[5]) || (ff[4] && ff[5]) ) flavour =0;
121 
122  if (jetType==flavour) event_passed =true;
123 
124 // cout <<"Final flavour: " << ff[0]<<" "<<ff[1]<<" "<<ff[2]<<" "<<ff[3]<<" "<<ff[4]<<" "<<ff[5];
125 // if (ff[0]||ff[1]||ff[2]) cout << " light";
126 // if (ff[3]) cout << " charm";
127 // if (ff[4]) cout << " bottom";
128 // if (ff[5]) cout << " top";
129 // if ((ff[0]||ff[1]||ff[2])&&((ff[3] + ff[4]+ff[5]))) {cout << " LH";};
130 // if ( (ff[3] && ff[4]) || (ff[3] && ff[5]) || (ff[4] && ff[5]) ) {cout <<" notDef";}//printHisto(start,end);//}
131 
132 // cout<<" "<<flavour<<event_passed<<endl;
133 
134  if (event_passed) noAccepted++;
135 
136  delete generated_event;
137 
138  return event_passed;
139 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
TPRegexp parents
Definition: eve_filter.cc:21
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
void printHisto(const HepMC::GenEvent::particle_iterator start, const HepMC::GenEvent::particle_iterator end)
std::vector< HepMC::GenParticle * > GenPartVect
int iEvent
Definition: GenABIO.cc:230
virtual bool filter(edm::Event &, const edm::EventSetup &)
HepMC::GenParticle * findParticle(const GenPartVect &genPartVect, const int requested_id)
#define end
Definition: vmac.h:37
JetFlavourFilter(const edm::ParameterSet &)
std::vector< HepMC::GenParticle * >::const_iterator GenPartVectIt
tuple cout
Definition: gather_cfg.py:121
int flavour(const Candidate &part)
Definition: pdgIdUtils.h:31