Fork me on GitHub

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

Last change on this file since 388 was 349, checked in by severine ovyn, 16 years ago

first test

File size: 7.0 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 WeightContainer w1 = e1->weights();
94 WeightContainer w2 = e2->weights();
95 if( w1.size() != w2.size() ) {
96 std::cerr << "compareWeights: size of weight container differs " << std::endl;
97 return false;
98 }
99 for( int i=0; i<w1.size(); ++i ) {
100 if( w1[i] != w2[i] ) {
101 std::cerr << "compareWeights: weight container entry "
102 << i << " differs" << std::endl;
103 return false;
104 }
105 }
106 return true;
107}
108
109bool compareParticles( GenEvent* e1, GenEvent* e2 ) {
110 if( e1->particles_size() != e2->particles_size() ) {
111 std::cerr << "compareParticles: number of particles differs " << std::endl;
112 return false;
113 }
114 if( e1->particles_size() == 0 ) { return true; }
115 for ( GenEvent::particle_const_iterator p1 = e1->particles_begin(),
116 p2 = e2->particles_begin();
117 p1 != e1->particles_end(); ++p1, ++p2 ) {
118 /* std::cout << "compareParticles: particle "
119 << (*p1)->barcode() << " " << (*p2)->barcode()
120 << std::endl; */
121 if ( **p1 != **p2 ) {
122 std::cerr << "compareParticles: particle "
123 << (*p1)->barcode() << " differs from "
124 << (*p2)->barcode() << std::endl;
125 return false;
126 }
127 }
128 return true;
129}
130
131bool compareVertices( GenEvent* e1, GenEvent* e2 ) {
132 if( e1->vertices_size() != e2->vertices_size() ) {
133 std::cerr << "compareVertices: number of vertices differs " << std::endl;
134 return false;
135 }
136 for ( GenEvent::vertex_const_iterator v = e1->vertices_begin();
137 v != e1->vertices_end(); ++v ) {
138 //std::cout << "compareVertices: comparing vertex "
139 // << (*v)->barcode() << std::endl;
140 GenVertex* v1 = (*v);
141 GenVertex* v2 = e2->barcode_to_vertex((*v)->barcode());
142 compareVertex( (*v), e2->barcode_to_vertex((*v)->barcode()));
143 if ( (*v1) != (*v2) ) {
144 std::cerr << "compareVertices: vertex "
145 << (*v)->barcode() << " differs" << std::endl;
146 return false;
147 }
148 }
149 return true;
150}
151
152bool compareVertex( GenVertex* v1, GenVertex* v2 ) {
153 if ( v1->position() != v2->position() ) {
154 std::cerr << "compareVertex: position "
155 << v1->barcode() << " differs" << std::endl;
156 return false;
157 }
158 // if the size of the inlist differs, return false.
159 if ( v1->particles_in_size() != v2->particles_in_size() ) {
160 std::cerr << "compareVertex: particles_in_size "
161 << v1->barcode() << " differs" << std::endl;
162 return false;
163 }
164 // loop over the inlist and ensure particles are identical
165 if ( v1->particles_in_const_begin() != v1->particles_in_const_end() ) {
166 for ( GenVertex::particles_in_const_iterator
167 ia = v1->particles_in_const_begin(),
168 ib = v2->particles_in_const_begin();
169 ia != v1->particles_in_const_end(); ia++, ib++ ){
170 if ( **ia != **ib ) {
171 std::cerr << "compareVertex: incoming particle "
172 << v1->barcode() << " differs: "
173 << (*ia)->barcode() << " " << (*ib)->barcode()
174 << std::endl;
175 //return false;
176 }
177 }
178 }
179 // if the size of the outlist differs, return false.
180 if ( v1->particles_out_size() != v2->particles_out_size() ) {
181 std::cerr << "compareVertex: particles_out_size "
182 << v1->barcode() << " differs" << std::endl;
183 return false;
184 }
185 // loop over the outlist and ensure particles are identical
186 if ( v1->particles_out_const_begin() != v1->particles_out_const_end() ) {
187 for ( GenVertex::particles_out_const_iterator
188 ia = v1->particles_out_const_begin(),
189 ib = v2->particles_out_const_begin();
190 ia != v1->particles_out_const_end(); ia++, ib++ ){
191 if ( **ia != **ib ) {
192 std::cerr << "compareVertex: outgoing particle "
193 << v1->barcode() << " differs: "
194 << (*ia)->barcode() << " " << (*ib)->barcode()
195 << std::endl;
196 //return false;
197 }
198 }
199 }
200 return true;
201}
202
203} // HepMC
Note: See TracBrowser for help on using the repository browser.