Fork me on GitHub

source: svn/trunk/Utilities/HepMC/src/CompareGenEvent.cc@ 683

Last change on this file since 683 was 571, checked in by cp3-support, 13 years ago

upgrade HepMC to version 2.06.05

File size: 6.7 KB
Line 
1/////////////////////////////////////////////////////////////////////////
2// CompareGenEvent.cc
3//
4// garren@fnal.gov, January 2008
5// Free functions used to compare two copies of GenEvent
6//////////////////////////////////////////////////////////////////////////
7//
8
9#include <iostream>
10
11#include "CompareGenEvent.h"
12#include "GenEvent.h"
13
14namespace HepMC {
15
16bool compareGenEvent( GenEvent* e1, GenEvent* e2)
17{
18 //std::cout << "compareGenEvent: comparing event " << e1->event_number() << " to event "
19 // << e2->event_number() << std::endl;
20 if( e1->event_number() != e2->event_number() ) {
21 std::cerr << "compareGenEvent: event numbers differ " << std::endl;
22 return false;
23 }
24 if( e1->signal_process_id() != e2->signal_process_id() ) {
25 std::cerr << "compareGenEvent: signal process ids differ " << std::endl;
26 return false;
27 }
28 if( e1->event_scale() != e2->event_scale() ) {
29 std::cerr << "compareGenEvent: event scales differ " << std::endl;
30 return false;
31 }
32 if( e1->alphaQCD() != e2->alphaQCD() ) {
33 std::cerr << "compareGenEvent: alphaQCD differs " << std::endl;
34 return false;
35 }
36 if( e1->alphaQED() != e2->alphaQED() ) {
37 std::cerr << "alphaQED differs " << std::endl;
38 return false;
39 }
40 if( e1->mpi() != e2->mpi() ) {
41 std::cerr << "compareGenEvent: mpi differs " << std::endl;
42 return false;
43 }
44 if ( !compareSignalProcessVertex( e1, e2 ) ) { return false; }
45 if ( !compareBeamParticles( e1, e2 ) ) { return false; }
46 if ( !compareWeights( e1, e2 ) ) { return false; }
47 if( e1->random_states() != e2->random_states() ) {
48 std::cerr << "compareGenEvent: random states differ " << std::endl;
49 return false;
50 }
51 if( e1->heavy_ion() != e2->heavy_ion() ) {
52 std::cerr << "compareGenEvent: heavy ions differ " << std::endl;
53 return false;
54 }
55 if( e1->pdf_info() != e2->pdf_info() ) {
56 std::cerr << "compareGenEvent: pdf info differs " << std::endl;
57 return false;
58 }
59 if ( !compareParticles( e1, e2 ) ) { return false; }
60 if ( !compareVertices( e1, e2 ) ) { return false; }
61 return true;
62}
63
64bool compareSignalProcessVertex( GenEvent* e1, GenEvent* e2 ) {
65 // compare signal process vertex
66 GenVertex* s1 = e1->signal_process_vertex();
67 GenVertex* s2 = e2->signal_process_vertex();
68 if( s1 && s2 ) {
69 if( (*s1) != (*s2) ) {
70 std::cerr << "compareSignalProcessVertex: signal process vertices differ " << std::endl;
71 return false;
72 }
73 }
74 return true;
75}
76
77bool compareBeamParticles( GenEvent* e1, GenEvent* e2 ) {
78 GenParticle* e1b1 = e1->beam_particles().first;
79 GenParticle* e1b2 = e1->beam_particles().second;
80 GenParticle* e2b1 = e2->beam_particles().first;
81 GenParticle* e2b2 = e2->beam_particles().second;
82 if( e1b1 && e1b2 && e2b1 && e2b2 ) {
83 if( (*e1b1) == (*e2b1) && (*e1b2) == (*e2b2) ) {
84 } else {
85 std::cerr << "compareBeamParticles: beam particles differ " << std::endl;
86 return false;
87 }
88 }
89 return true;
90}
91
92bool compareWeights( GenEvent* e1, GenEvent* e2 ) {
93 if( e1->weights() == e2->weights() ) return true;
94 std::cerr << "compareWeights: weight containers differ " << std::endl;
95 return false;
96}
97
98bool compareParticles( GenEvent* e1, GenEvent* e2 ) {
99 if( e1->particles_size() != e2->particles_size() ) {
100 std::cerr << "compareParticles: number of particles differs " << std::endl;
101 return false;
102 }
103 if( e1->particles_size() == 0 ) { return true; }
104 for ( GenEvent::particle_const_iterator p1 = e1->particles_begin(),
105 p2 = e2->particles_begin();
106 p1 != e1->particles_end(); ++p1, ++p2 ) {
107 /* std::cout << "compareParticles: particle "
108 << (*p1)->barcode() << " " << (*p2)->barcode()
109 << std::endl; */
110 if ( **p1 != **p2 ) {
111 std::cerr << "compareParticles: particle "
112 << (*p1)->barcode() << " differs from "
113 << (*p2)->barcode() << std::endl;
114 return false;
115 }
116 }
117 return true;
118}
119
120bool compareVertices( GenEvent* e1, GenEvent* e2 ) {
121 if( e1->vertices_size() != e2->vertices_size() ) {
122 std::cerr << "compareVertices: number of vertices differs " << std::endl;
123 return false;
124 }
125 for ( GenEvent::vertex_const_iterator v = e1->vertices_begin();
126 v != e1->vertices_end(); ++v ) {
127 //std::cout << "compareVertices: comparing vertex "
128 // << (*v)->barcode() << std::endl;
129 GenVertex* v1 = (*v);
130 GenVertex* v2 = e2->barcode_to_vertex((*v)->barcode());
131 compareVertex( (*v), e2->barcode_to_vertex((*v)->barcode()));
132 if ( (*v1) != (*v2) ) {
133 std::cerr << "compareVertices: vertex "
134 << (*v)->barcode() << " differs" << std::endl;
135 return false;
136 }
137 }
138 return true;
139}
140
141bool compareVertex( GenVertex* v1, GenVertex* v2 ) {
142 if ( v1->position() != v2->position() ) {
143 std::cerr << "compareVertex: position "
144 << v1->barcode() << " differs" << std::endl;
145 return false;
146 }
147 // if the size of the inlist differs, return false.
148 if ( v1->particles_in_size() != v2->particles_in_size() ) {
149 std::cerr << "compareVertex: particles_in_size "
150 << v1->barcode() << " differs" << std::endl;
151 return false;
152 }
153 // loop over the inlist and ensure particles are identical
154 if ( v1->particles_in_const_begin() != v1->particles_in_const_end() ) {
155 for ( GenVertex::particles_in_const_iterator
156 ia = v1->particles_in_const_begin(),
157 ib = v2->particles_in_const_begin();
158 ia != v1->particles_in_const_end(); ia++, ib++ ){
159 if ( **ia != **ib ) {
160 std::cerr << "compareVertex: incoming particle "
161 << v1->barcode() << " differs: "
162 << (*ia)->barcode() << " " << (*ib)->barcode()
163 << std::endl;
164 //return false;
165 }
166 }
167 }
168 // if the size of the outlist differs, return false.
169 if ( v1->particles_out_size() != v2->particles_out_size() ) {
170 std::cerr << "compareVertex: particles_out_size "
171 << v1->barcode() << " differs" << std::endl;
172 return false;
173 }
174 // loop over the outlist and ensure particles are identical
175 if ( v1->particles_out_const_begin() != v1->particles_out_const_end() ) {
176 for ( GenVertex::particles_out_const_iterator
177 ia = v1->particles_out_const_begin(),
178 ib = v2->particles_out_const_begin();
179 ia != v1->particles_out_const_end(); ia++, ib++ ){
180 if ( **ia != **ib ) {
181 std::cerr << "compareVertex: outgoing particle "
182 << v1->barcode() << " differs: "
183 << (*ia)->barcode() << " " << (*ib)->barcode()
184 << std::endl;
185 //return false;
186 }
187 }
188 }
189 return true;
190}
191
192} // HepMC
Note: See TracBrowser for help on using the repository browser.