00001 #include <iostream>
00002 #include <iterator>
00003 #include "SimDataFormats/HiGenData/interface/SubEvent.h"
00004 using namespace edm;
00005
00006 HepMC::GenParticle* SubEvent::getParticle(const HepMC::GenEvent& evt, int index) const {
00007
00008
00009
00010 std::vector<HepMC::GenParticle*> parts = getParticles(evt);
00011 HepMC::GenParticle* particle = parts[index];
00012 if(particle) return particle;
00013 else{
00014 std::cout<<"error loading particle, particle with index "<<index<<" doesn't exist!"<<std::endl;
00015 return 0;
00016 }
00017 }
00018
00019 std::vector<HepMC::GenParticle*> SubEvent::getParticles(const HepMC::GenEvent& evt) const {
00020 std::vector<HepMC::GenParticle*> cands;
00021
00022 HepMC::GenVertex* vertex = getVertex(evt);
00023 HepMC::GenVertex::particle_iterator p;
00024 HepMC::GenVertex::particle_iterator start = vertex->particles_begin( HepMC::relatives );
00025 HepMC::GenVertex::particle_iterator end = vertex->particles_end( HepMC::relatives );
00026 for ( p = start; p != end; ++p ) {
00027 cands.push_back(*p);
00028 }
00029
00030 return cands;
00031
00032 }
00033
00034 HepMC::GenVertex* SubEvent::getVertex(const HepMC::GenEvent& evt) const {
00035
00036 HepMC::GenVertex* vertex;
00037 HepMC::GenEvent::vertex_const_iterator v;
00038 HepMC::GenEvent::vertex_const_iterator start = evt.vertices_begin();
00039 HepMC::GenEvent::vertex_const_iterator end = evt.vertices_end();
00040 for ( v = start; v != end; ++v ){
00041 HepMC::GenVertex* dummy = *v;
00042 if(dummy->id() == sub_id){
00043 vertex = *v;
00044 break;
00045 }
00046 }
00047 if(!vertex){
00048 std::cout<<"Error - Vertex with id : "<<sub_id<<" could not be found!"<<std::endl;
00049 }
00050 return vertex;
00051 }
00052
00053 HepMC::GenParticle* SubEvent::getBoson(const HepMC::GenEvent& evt){
00054 HepMC::GenParticle* boson = getParticle(evt,3);
00055 if(boson) return boson;
00056 else{
00057 std::cout<<"error loading boson, particle with index 1 doesn't exist!"<<std::endl;
00058 return 0;
00059 }
00060 }
00061 HepMC::GenParticle* SubEvent::getParton1(const HepMC::GenEvent& evt){
00062 HepMC::GenParticle* parton = getParticle(evt,1);
00063 if(parton) return parton;
00064 else{
00065 std::cout<<"error loading parton, particle with index 2 doesn't exist!"<<std::endl;
00066 return 0;
00067 }
00068 }
00069 HepMC::GenParticle* SubEvent::getParton2(const HepMC::GenEvent& evt){
00070 HepMC::GenParticle* parton = getParticle(evt,2);
00071 if(parton) return parton;
00072 else{
00073 std::cout<<"error loading parton, particle with index 3 doesn't exist!"<<std::endl;
00074 return 0;
00075 }
00076 }