CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
JetFlavourCutFilter.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 JetFlavourCutFilter::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  iter != inVertex->particles_in_const_end();iter++)
49  parents.push_back(*iter);
50 
51  cout << "isC "<<(*p)->pdg_id()<<" status "<<(*p)->status()<<" Parents: "<<parents.size()<<" - ";
52  for (GenPartVectIt z = parents.begin(); z != parents.end(); z++){
53  cout << (*z)->pdg_id()<<" ";
54  }
55 
56  //vector< GenParticle * > child = (*p)->listChildren();
57  vector< GenParticle * > child;
58  HepMC::GenVertex* outVertex = (*p)->end_vertex();
59  for(std::vector<GenParticle*>::const_iterator iter = outVertex->particles_in_const_begin();
60  iter != outVertex->particles_in_const_end();iter++)
61  child.push_back(*iter);
62 
63  cout << " - Child: "<<child.size()<<" - ";
64  for (GenPartVectIt z = child.begin(); z != child.end(); z++){
65  cout << (*z)->pdg_id()<<" ";
66  }
67  cout<<"\n";
68  }
69 }
70 
71 
73 {
75  iEvent.getByToken(token_, evt);
76 
77  const HepMC::GenEvent * generated_event = evt->GetEvent();
78 
79  bool event_passed = false;
80 
81  vector<int> foundQ;
82  HepMC::GenEvent::particle_const_iterator p;
83  for (p = generated_event->particles_begin(); p != generated_event->particles_end(); p++) {
84  if (((*p)->pdg_id() < 1) && ((*p)->pdg_id() > -10)) { // We have an anti-quark
85 // cout << "antiQ "<< (*p)->pdg_id();
86  //vector< GenParticle * > parents = (*p)->listParents();
87  vector< GenParticle * > parents;
88  HepMC::GenVertex* inVertex = (*p)->production_vertex();
89  for(std::vector<GenParticle*>::const_iterator iter = inVertex->particles_in_const_begin();
90  iter != inVertex->particles_in_const_end();iter++)
91  parents.push_back(*iter);
92 
93  for (GenPartVectIt z = parents.begin(); z != parents.end(); z++){
94 
95  vector< GenParticle * > child;
96  HepMC::GenVertex* outVertex = (*z)->end_vertex();
97  for(std::vector<GenParticle*>::const_iterator iter = outVertex->particles_in_const_begin();
98  iter != outVertex->particles_in_const_end();iter++)
99  child.push_back(*iter);
100 
101  if (findParticle(child, -(*p)->pdg_id())) foundQ.push_back(-(*p)->pdg_id());
102  }
103 // cout << " "<< foundQ.size()<<endl;
104 
105  }
106 
107  }
108 
109  int flavour = 0;
110  int ff[6];
111  ff[0]=0; ff[1]=0; ff[2]=0; ff[3]=0; ff[4]=0; ff[5]=0;
112  for (vector<int>::iterator i = foundQ.begin(); i != foundQ.end(); i++){
113  ++ff[(*i)-1];
114  if ((*i)>flavour) flavour = (*i);
115  }
116  // Is it light quark jet?
117  if ((flavour>=0)&&(flavour<=3)) flavour=1;
118  // Do we have more than one heavy flavour ?
119  if ( (ff[3] && ff[4]) || (ff[3] && ff[5]) || (ff[4] && ff[5]) ) flavour =0;
120 
121  if (jetType!=flavour) event_passed=true;
122 
123 // cout <<"Final flavour: " << ff[0]<<" "<<ff[1]<<" "<<ff[2]<<" "<<ff[3]<<" "<<ff[4]<<" "<<ff[5];
124 // if (ff[0]||ff[1]||ff[2]) cout << " light";
125 // if (ff[3]) cout << " charm";
126 // if (ff[4]) cout << " bottom";
127 // if (ff[5]) cout << " top";
128 // if ((ff[0]||ff[1]||ff[2])&&((ff[3] + ff[4]+ff[5]))) {cout << " LH";};
129 // if ( (ff[3] && ff[4]) || (ff[3] && ff[5]) || (ff[4] && ff[5]) ) {cout <<" notDef";}//printHisto(start,end);//}
130 
131 // cout<<" "<< flavour << event_passed << endl;
132 
133  if (event_passed) noAccepted++;
134 
135  delete generated_event;
136 
137  return event_passed;
138 }
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
HepMC::GenParticle * findParticle(const GenPartVect &genPartVect, const int requested_id)
void printHisto(const HepMC::GenEvent::particle_iterator start, const HepMC::GenEvent::particle_iterator end)
int iEvent
Definition: GenABIO.cc:230
#define end
Definition: vmac.h:37
virtual bool filter(edm::Event &, const edm::EventSetup &)
tuple cout
Definition: gather_cfg.py:121
std::vector< HepMC::GenParticle * > GenPartVect
int flavour(const Candidate &part)
Definition: pdgIdUtils.h:31
std::vector< HepMC::GenParticle * >::const_iterator GenPartVectIt
JetFlavourCutFilter(const edm::ParameterSet &)