12 #ifndef HEPEVT_WRAPPER_HEADER_ONLY 13 #include "HepMC/HEPEVT_Wrapper.h" 14 #include "HepMC/GenEvent.h" 15 #include "HepMC/GenParticle.h" 16 #include "HepMC/GenVertex.h" 32 if (lx->pid() !=rx->pid())
return (lx->pid() < rx->pid());
33 if (lx->status() !=rx->status())
return (lx->status() < rx->status());
35 return (lx->momentum().e()<rx->momentum().e());
44 bool operator()(
const std::pair<GenVertexPtr,int>& lx,
const std::pair<GenVertexPtr,int>& rx )
const 46 if (lx.second!=rx.second)
return (lx.second < rx.second);
47 if (lx.first->particles_in().size()!=rx.first->particles_in().size())
return (lx.first->particles_in().size()<rx.first->particles_in().size());
48 if (lx.first->particles_out().size()!=rx.first->particles_out().size())
return (lx.first->particles_out().size()<rx.first->particles_out().size());
50 std::vector<int> lx_id_in;
51 std::vector<int> rx_id_in;
52 for (std::vector<GenParticlePtr>::const_iterator pp=lx.first->particles_in().begin(); pp!=lx.first->particles_in().end(); pp++ ) lx_id_in.push_back((*pp)->pid());
53 for (std::vector<GenParticlePtr>::const_iterator pp=rx.first->particles_in().begin(); pp!=rx.first->particles_in().end(); pp++ ) rx_id_in.push_back((*pp)->pid());
54 std::sort(lx_id_in.begin(),lx_id_in.end());
55 std::sort(rx_id_in.begin(),rx_id_in.end());
56 for (
unsigned int i=0; i<lx_id_in.size(); i++)
if (lx_id_in[i]!=rx_id_in[i])
return (lx_id_in[i]<rx_id_in[i]);
58 std::vector<int> lx_id_out;
59 std::vector<int> rx_id_out;
60 for (std::vector<GenParticlePtr>::const_iterator pp=lx.first->particles_in().begin(); pp!=lx.first->particles_in().end(); pp++ ) lx_id_out.push_back((*pp)->pid());
61 for (std::vector<GenParticlePtr>::const_iterator pp=rx.first->particles_in().begin(); pp!=rx.first->particles_in().end(); pp++ ) rx_id_out.push_back((*pp)->pid());
62 std::sort(lx_id_out.begin(),lx_id_out.end());
63 std::sort(rx_id_out.begin(),rx_id_out.end());
64 for (
unsigned int i=0; i<lx_id_out.size(); i++)
if (lx_id_out[i]!=rx_id_out[i])
return (lx_id_out[i]<rx_id_out[i]);
66 std::vector<double> lx_mom_in;
67 std::vector<double> rx_mom_in;
68 for (std::vector<GenParticlePtr>::const_iterator pp=lx.first->particles_in().begin(); pp!=lx.first->particles_in().end(); pp++ ) lx_mom_in.push_back((*pp)->momentum().e());
69 for (std::vector<GenParticlePtr>::const_iterator pp=rx.first->particles_in().begin(); pp!=rx.first->particles_in().end(); pp++ ) rx_mom_in.push_back((*pp)->momentum().e());
70 std::sort(lx_mom_in.begin(),lx_mom_in.end());
71 std::sort(rx_mom_in.begin(),rx_mom_in.end());
72 for (
unsigned int i=0; i<lx_mom_in.size(); i++)
if (lx_mom_in[i]!=rx_mom_in[i])
return (lx_mom_in[i]<rx_mom_in[i]);
74 std::vector<double> lx_mom_out;
75 std::vector<double> rx_mom_out;
76 for (std::vector<GenParticlePtr>::const_iterator pp=lx.first->particles_in().begin(); pp!=lx.first->particles_in().end(); pp++ ) lx_mom_out.push_back((*pp)->momentum().e());
77 for (std::vector<GenParticlePtr>::const_iterator pp=rx.first->particles_in().begin(); pp!=rx.first->particles_in().end(); pp++ ) rx_mom_out.push_back((*pp)->momentum().e());
78 std::sort(lx_mom_out.begin(),lx_mom_out.end());
79 std::sort(rx_mom_out.begin(),rx_mom_out.end());
80 for (
unsigned int i=0; i<lx_mom_out.size(); i++)
if (lx_mom_out[i]!=rx_mom_out[i])
return (lx_mom_out[i]<rx_mom_out[i]);
83 return (lx.first<lx.first);
87 void calculate_longest_path_to_top(
GenVertexPtr v,std::map<GenVertexPtr,int>& pathl)
90 for (std::vector<GenParticlePtr>::const_iterator pp=v->particles_in().begin(); pp!=v->particles_in().end(); pp++ )
94 if (!v2) p=std::max(p,1);
96 {
if (pathl.find(v2)==pathl.end()) calculate_longest_path_to_top(v2,pathl); p=std::max(p, pathl[v2]+1);}
105 if ( !evt ) { std::cerr <<
"IO_HEPEVT::fill_next_event error - passed null event." << std::endl;
return false;}
107 std::map<GenParticlePtr,int > hepevt_particles;
108 std::map<int,GenParticlePtr > particles_index;
109 std::map<GenVertexPtr,std::pair<std::set<int>,std::set<int> > > hepevt_vertices;
110 std::map<int,GenVertexPtr > vertex_index;
118 hepevt_particles[p]=i;
119 particles_index[i]=p;
122 v->add_particle_out(p);
127 hepevt_vertices[v]=std::pair<std::set<int>,std::set<int> >(in,out);
132 for (std::map<GenParticlePtr,int >::iterator it1= hepevt_particles.begin(); it1!= hepevt_particles.end(); it1++)
133 for (std::map<GenParticlePtr,int >::iterator it2= hepevt_particles.begin(); it2!= hepevt_particles.end(); it2++)
135 hepevt_vertices[it2->first->production_vertex()].first.insert(it1->second);
142 std::map<GenVertexPtr,std::pair<std::set<int>,std::set<int> > > final_vertices_map;
143 for (std::map<
GenVertexPtr,std::pair<std::set<int>,std::set<int> > >::iterator vs= hepevt_vertices.begin(); vs!= hepevt_vertices.end(); vs++)
145 if ((final_vertices_map.size()==0)||(vs->second.first.size()==0&&vs->second.second.size()!=0)) { final_vertices_map.insert(*vs);
continue; }
146 std::map<GenVertexPtr,std::pair<std::set<int>,std::set<int> > >::iterator v2;
147 for (v2=final_vertices_map.begin(); v2!=final_vertices_map.end(); v2++)
if (vs->second.first==v2->second.first) {v2->second.second.insert(vs->second.second.begin(),vs->second.second.end());
break;}
148 if (v2==final_vertices_map.end()) final_vertices_map.insert(*vs);
151 std::vector<GenParticlePtr> final_particles;
153 for (std::map<
GenVertexPtr,std::pair<std::set<int>,std::set<int> > >:: iterator it=final_vertices_map.begin(); it!=final_vertices_map.end(); it++)
156 std::set<int> in=it->second.first;
157 std::set<int> out=it->second.second;
158 used.insert(in.begin(),in.end());
159 used.insert(out.begin(),out.end());
160 for (std::set<int>::iterator el=in.begin(); el!=in.end(); el++) v->add_particle_in(particles_index[*el]);
161 if (in.size()!=0)
for (std::set<int>::iterator el=out.begin(); el!=out.end(); el++) v->add_particle_out(particles_index[*el]);
163 for (std::set<int>::iterator el=used.begin(); el!=used.end(); el++) final_particles.push_back(particles_index[*el]);
180 if ( !evt )
return false;
184 std::map<GenVertexPtr,int> longest_paths;
185 for ( std::vector<GenVertexPtr>::const_iterator v = evt->
vertices().begin(); v != evt->
vertices().end(); ++v ) calculate_longest_path_to_top(*v,longest_paths);
187 std::vector<std::pair<GenVertexPtr,int> > sorted_paths;
188 copy(longest_paths.begin(),longest_paths.end(),std::back_inserter(sorted_paths));
191 std::vector<GenParticlePtr> sorted_particles;
192 std::vector<GenParticlePtr> stable_particles;
194 for (std::vector<std::pair<GenVertexPtr,int> >::iterator it=sorted_paths.begin(); it!=sorted_paths.end(); it++)
196 std::vector<GenParticlePtr> Q;
197 copy(it->first->particles_in().begin(),it->first->particles_in().end(),back_inserter(Q));
199 copy(Q.begin(),Q.end(),std::back_inserter(sorted_particles));
201 for (std::vector<GenParticlePtr>::const_iterator pp=it->first->particles_out().begin(); pp!=it->first->particles_out().end(); pp++ )
202 if(!((*pp)->end_vertex())) stable_particles.push_back(*pp);
205 copy(stable_particles.begin(),stable_particles.end(),std::back_inserter(sorted_particles));
211 for (
int i = 1; i <= particle_counter; ++i )
215 FourVector m = sorted_particles[i-1]->momentum();
220 if ( sorted_particles[i-1]->production_vertex() &&
221 sorted_particles[i-1]->production_vertex()->particles_in().size())
223 FourVector p = sorted_particles[i-1]->production_vertex()->position();
225 std::vector<int> mothers;
227 for (std::vector<GenParticlePtr>::const_iterator
228 it=sorted_particles[i-1]->production_vertex()->particles_in().begin();
229 it!=sorted_particles[i-1]->production_vertex()->particles_in().end(); it++)
230 for (
int j = 1; j <= particle_counter; ++j )
231 if (sorted_particles[j-1]==(*it))
232 mothers.push_back(j);
233 sort(mothers.begin(),mothers.end());
234 if (mothers.size()==0)
235 mothers.push_back(0);
236 if (mothers.size()==1) mothers.push_back(mothers[0]);
static double py(int index)
Get Y momentum.
static void set_number_entries(int noentries)
Set number of entries.
double px() const
x-component of momentum
double y() const
y-component of position/displacement
static int status(int index)
Get status code.
static bool GenEvent_to_HEPEVT(const GenEvent *evt)
Convert GenEvent to HEPEVT.
static void set_status(int index, int status)
Set status code.
static double y(int index)
Get Y Production vertex.
static double e(int index)
Get Energy.
static double px(int index)
Get X momentum.
static void set_parents(int index, int firstparent, int lastparent)
Set parents.
static double pz(int index)
Get Z momentum.
void set_event_number(int num)
Set event number.
int event_number() const
Get event number.
static double z(int index)
Get Z Production vertex.
void add_tree(const std::vector< GenParticlePtr > &particles)
Add whole tree in topological order.
static int max_number_entries()
Block size.
Smart pointer for HepMC objects.
double x() const
x-component of position/displacement
static double t(int index)
Get production time.
Stores event-related information.
static void set_id(int index, int id)
Set PDG particle id.
double t() const
Time component of position/displacement.
Fortran common block HEPEVT.
static int event_number()
Get event number.
static void set_event_number(int evtno)
Set event number.
static double x(int index)
Get X Production vertex.
double py() const
y-component of momentum
static int first_parent(int index)
Get index of 1st mother.
static int id(int index)
Get PDG particle id.
static double m(int index)
Get generated mass.
double e() const
Energy component of momentum.
const std::vector< GenVertexPtr > & vertices() const
Get list of vertices (const)
static void set_children(int index, int firstchild, int lastchild)
Set children.
static void set_mass(int index, double mass)
Set mass.
static int number_entries()
Get number of entries.
static int last_parent(int index)
Get index of last mother.
double pz() const
z-component of momentum
Definition of template class SmartPointer.
static void set_position(int index, double x, double y, double z, double t)
Set position in time-space.
double z() const
z-component of position/displacement
static void set_momentum(int index, double px, double py, double pz, double e)
Set 4-momentum.
static bool HEPEVT_to_GenEvent(GenEvent *evt)
Convert HEPEVT to GenEvent.