Go to the documentation of this file.00001 #include "GeneratorInterface/GenFilters/interface/JetFlavourCutFilter.h"
00002
00003 using namespace edm;
00004 using namespace std;
00005 using namespace HepMC;
00006
00007
00008
00009 JetFlavourCutFilter::JetFlavourCutFilter(const edm::ParameterSet& iConfig)
00010 {
00011 label_ = iConfig.getUntrackedParameter("moduleLabel",std::string("generator"));
00012 jetType = iConfig.getParameter< int >("jetType");
00013 if ((jetType>=1)&&(jetType<=3)) jetType=1;
00014
00015 noAccepted = 0;
00016 }
00017
00018
00019 JetFlavourCutFilter::~JetFlavourCutFilter()
00020 {
00021 std::cout << "Total number of accepted events = " << noAccepted << std::endl;
00022 }
00023
00024
00025 HepMC::GenParticle * JetFlavourCutFilter::findParticle(const GenPartVect genPartVect,
00026 const int requested_id)
00027 {
00028 for (GenPartVectIt p = genPartVect.begin(); p != genPartVect.end(); p++)
00029 {
00030 if (requested_id == (*p)->pdg_id()) return *p;
00031 }
00032 return 0;
00033 }
00034
00035
00036
00037 void
00038 JetFlavourCutFilter::printHisto(const HepMC::GenEvent::particle_iterator start,
00039 const HepMC::GenEvent::particle_iterator end)
00040 {
00041 HepMC::GenEvent::particle_iterator p;
00042 for (p = start; p != end; p++)
00043 {
00044
00045 vector< GenParticle * > parents;
00046 HepMC::GenVertex* inVertex = (*p)->production_vertex();
00047 for(std::vector<GenParticle*>::const_iterator iter = inVertex->particles_in_const_begin();
00048 iter != inVertex->particles_in_const_end();iter++)
00049 parents.push_back(*iter);
00050
00051 cout << "isC "<<(*p)->pdg_id()<<" status "<<(*p)->status()<<" Parents: "<<parents.size()<<" - ";
00052 for (GenPartVectIt z = parents.begin(); z != parents.end(); z++){
00053 cout << (*z)->pdg_id()<<" ";
00054 }
00055
00056
00057 vector< GenParticle * > child;
00058 HepMC::GenVertex* outVertex = (*p)->end_vertex();
00059 for(std::vector<GenParticle*>::const_iterator iter = outVertex->particles_in_const_begin();
00060 iter != outVertex->particles_in_const_end();iter++)
00061 child.push_back(*iter);
00062
00063 cout << " - Child: "<<child.size()<<" - ";
00064 for (GenPartVectIt z = child.begin(); z != child.end(); z++){
00065 cout << (*z)->pdg_id()<<" ";
00066 }
00067 cout<<"\n";
00068 }
00069 }
00070
00071
00072 bool JetFlavourCutFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00073 {
00074 edm::Handle<HepMCProduct> evt;
00075 iEvent.getByLabel(label_, evt);
00076
00077 const HepMC::GenEvent * generated_event = evt->GetEvent();
00078
00079 bool event_passed = false;
00080
00081 vector<int> foundQ;
00082 HepMC::GenEvent::particle_const_iterator p;
00083 for (p = generated_event->particles_begin(); p != generated_event->particles_end(); p++) {
00084 if (((*p)->pdg_id() < 1) && ((*p)->pdg_id() > -10)) {
00085
00086
00087 vector< GenParticle * > parents;
00088 HepMC::GenVertex* inVertex = (*p)->production_vertex();
00089 for(std::vector<GenParticle*>::const_iterator iter = inVertex->particles_in_const_begin();
00090 iter != inVertex->particles_in_const_end();iter++)
00091 parents.push_back(*iter);
00092
00093 for (GenPartVectIt z = parents.begin(); z != parents.end(); z++){
00094
00095 vector< GenParticle * > child;
00096 HepMC::GenVertex* outVertex = (*z)->end_vertex();
00097 for(std::vector<GenParticle*>::const_iterator iter = outVertex->particles_in_const_begin();
00098 iter != outVertex->particles_in_const_end();iter++)
00099 child.push_back(*iter);
00100
00101 if (findParticle(child, -(*p)->pdg_id())) foundQ.push_back(-(*p)->pdg_id());
00102 }
00103
00104
00105 }
00106
00107 }
00108
00109 int flavour = 0;
00110 int ff[6];
00111 ff[0]=0; ff[1]=0; ff[2]=0; ff[3]=0; ff[4]=0; ff[5]=0;
00112 for (vector<int>::iterator i = foundQ.begin(); i != foundQ.end(); i++){
00113 ++ff[(*i)-1];
00114 if ((*i)>flavour) flavour = (*i);
00115 }
00116
00117 if ((flavour>=0)&&(flavour<=3)) flavour=1;
00118
00119 if ( (ff[3] && ff[4]) || (ff[3] && ff[5]) || (ff[4] && ff[5]) ) flavour =0;
00120
00121 if (jetType!=flavour) event_passed=true;
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 if (event_passed) noAccepted++;
00134
00135 delete generated_event;
00136
00137 return event_passed;
00138 }