hepmc - Diff between revs 423 and 432
Subversion Repositories:
| Rev 423 | Rev 432 | |||
|---|---|---|---|---|
| Line 22... | Line 22... | |||
| 22 | 22 | |||
| 23 | // define methods and classes used by this test | 23 | // define methods and classes used by this test | |
| 24 | #include "IsGoodEvent.h" | 24 | #include "IsGoodEvent.h" | |
| 25 | #include "testHepMCMethods.h" | 25 | #include "testHepMCMethods.h" | |
| 26 | 26 | |||
| 27 | void read_testIOGenEvent(); | - | ||
| 28 | void read_variousFormats(); | - | ||
| 29 | void writeWithCrossSection(); | - | ||
| 30 | void readWithCrossSection(); | - | ||
| 31 | void read_nan(); | - | ||
| - | 27 | void read_testIOGenEvent(std::ostream & os); | ||
| - | 28 | void read_variousFormats(std::ostream & os); | ||
| - | 29 | void writeWithCrossSection(std::ostream & os); | ||
| - | 30 | void readWithCrossSection(std::ostream & os); | ||
| - | 31 | void writeWithWeight(std::ostream & os); | ||
| - | 32 | void readWithWeight(std::ostream & os); | ||
| - | 33 | void read_nan(std::ostream & os); | ||
| 32 | 34 | |||
| 33 | int main() { | 35 | int main() { | |
| 34 | read_testIOGenEvent(); | - | ||
| 35 | read_variousFormats(); | - | ||
| 36 | read_nan(); | - | ||
| 37 | writeWithCrossSection(); | - | ||
| 38 | readWithCrossSection(); | - | ||
| - | 36 | std::ofstream os( "testHepMC.cout" ); | ||
| - | 37 | std::ofstream osv( "testHepMCVarious.cout" ); | ||
| - | 38 | read_testIOGenEvent(os); | ||
| - | 39 | read_variousFormats(osv); | ||
| - | 40 | read_nan(os); | ||
| - | 41 | writeWithCrossSection(os); | ||
| - | 42 | readWithCrossSection(os); | ||
| - | 43 | writeWithWeight(os); | ||
| - | 44 | readWithWeight(os); | ||
| 39 | return 0; | 45 | return 0; | |
| 40 | } | 46 | } | |
| 41 | 47 | |||
| 42 | void read_testIOGenEvent() | - | ||
| - | 48 | void read_testIOGenEvent(std::ostream & os) | ||
| 43 | { | 49 | { | |
| 44 | std::cout << std::endl; | - | ||
| 45 | std::cout << "basic IO_GenEvent input and output" << std::endl; | - | ||
| - | 50 | os << std::endl; | ||
| - | 51 | os << "basic IO_GenEvent input and output" << std::endl; | ||
| 46 | // declare an input strategy to read the data produced with the | 52 | // declare an input strategy to read the data produced with the | |
| 47 | // example_MyPythia - units are GeV and mm | 53 | // example_MyPythia - units are GeV and mm | |
| 48 | HepMC::IO_GenEvent ascii_in("@srcdir@/testIOGenEvent.input",std::ios::in); | 54 | HepMC::IO_GenEvent ascii_in("@srcdir@/testIOGenEvent.input",std::ios::in); | |
| 49 | ascii_in.use_input_units( HepMC::Units::GEV, HepMC::Units::MM ); | 55 | ascii_in.use_input_units( HepMC::Units::GEV, HepMC::Units::MM ); | |
| 50 | // declare another IO_GenEvent for writing out the good events | 56 | // declare another IO_GenEvent for writing out the good events | |
| Line 60... | Line 66... | |||
| 60 | int icount=0; | 66 | int icount=0; | |
| 61 | int num_good_events=0; | 67 | int num_good_events=0; | |
| 62 | HepMC::GenEvent* evt = ascii_in.read_next_event(); | 68 | HepMC::GenEvent* evt = ascii_in.read_next_event(); | |
| 63 | while ( evt ) { | 69 | while ( evt ) { | |
| 64 | ++icount; | 70 | ++icount; | |
| 65 | if ( icount%50==1 ) std::cout << "Processing Event Number " << icount | - | ||
| - | 71 | if ( icount%50==1 ) os << "Processing Event Number " << icount | ||
| 66 | << " its # " << evt->event_number() | 72 | << " its # " << evt->event_number() | |
| 67 | << std::endl; | 73 | << std::endl; | |
| 68 | if ( is_good_event(evt) ) { | 74 | if ( is_good_event(evt) ) { | |
| 69 | particleTypes(evt); | - | ||
| - | 75 | particleTypes(evt,os); | ||
| 70 | ascii_out << evt; | 76 | ascii_out << evt; | |
| 71 | particle_out << evt; | 77 | particle_out << evt; | |
| 72 | prec_out << evt; | 78 | prec_out << evt; | |
| 73 | ++num_good_events; | 79 | ++num_good_events; | |
| 74 | } | 80 | } | |
| Line 76... | Line 82... | |||
| 76 | // clean up and get next event | 82 | // clean up and get next event | |
| 77 | delete evt; | 83 | delete evt; | |
| 78 | ascii_in >> evt; | 84 | ascii_in >> evt; | |
| 79 | } | 85 | } | |
| 80 | //........................................PRINT RESULT | 86 | //........................................PRINT RESULT | |
| 81 | std::cout << num_good_events << " out of " << icount | - | ||
| - | 87 | os << num_good_events << " out of " << icount | ||
| 82 | << " processed events passed the cuts. Finished." << std::endl; | 88 | << " processed events passed the cuts. Finished." << std::endl; | |
| 83 | } | 89 | } | |
| 84 | 90 | |||
| 85 | void read_variousFormats() | - | ||
| - | 91 | void read_variousFormats(std::ostream & os) | ||
| 86 | { | 92 | { | |
| 87 | std::cout << std::endl; | - | ||
| 88 | std::cout << "process varied input" << std::endl; | - | ||
| - | 93 | os << std::endl; | ||
| - | 94 | os << "process varied input" << std::endl; | ||
| 89 | // declare an input strategy | 95 | // declare an input strategy | |
| 90 | HepMC::IO_GenEvent ascii_in("@srcdir@/testHepMCVarious.input",std::ios::in); | 96 | HepMC::IO_GenEvent ascii_in("@srcdir@/testHepMCVarious.input",std::ios::in); | |
| 91 | ascii_in.use_input_units( HepMC::Units::GEV, HepMC::Units::MM ); | 97 | ascii_in.use_input_units( HepMC::Units::GEV, HepMC::Units::MM ); | |
| 92 | // declare another IO_GenEvent for writing out the good events | 98 | // declare another IO_GenEvent for writing out the good events | |
| 93 | HepMC::IO_GenEvent ascii_out("testHepMCVarious.out",std::ios::out); | 99 | HepMC::IO_GenEvent ascii_out("testHepMCVarious.out",std::ios::out); | |
| Line 95... | Line 101... | |||
| 95 | int icount=0; | 101 | int icount=0; | |
| 96 | HepMC::GenEvent* evt = ascii_in.read_next_event(); | 102 | HepMC::GenEvent* evt = ascii_in.read_next_event(); | |
| 97 | while ( evt ) { | 103 | while ( evt ) { | |
| 98 | icount++; | 104 | icount++; | |
| 99 | double pim; | 105 | double pim; | |
| 100 | std::cout << "Processing Event Number " << icount | - | ||
| - | 106 | os << "Processing Event Number " << icount | ||
| 101 | << " its # " << evt->event_number() | 107 | << " its # " << evt->event_number() | |
| 102 | << std::endl; | 108 | << std::endl; | |
| 103 | ascii_out << evt; | 109 | ascii_out << evt; | |
| 104 | // units should be unknown | 110 | // units should be unknown | |
| 105 | evt->write_units(); | - | ||
| - | 111 | evt->write_units(os); | ||
| 106 | pim = findPiZero(evt); | 112 | pim = findPiZero(evt); | |
| 107 | std::cout << " pizero mass: " << pim << std::endl; | - | ||
| 108 | // set units to GeV and mm | - | ||
| 109 | evt->use_units(HepMC::Units::GEV, HepMC::Units::MM); | - | ||
| 110 | evt->write_units(); | - | ||
| 111 | pim = findPiZero(evt); | - | ||
| 112 | std::cout << " pizero mass: " << pim | - | ||
| 113 | << " " << HepMC::Units::name( evt->momentum_unit() ) << std::endl; | - | ||
| 114 | // convert units to MeV | - | ||
| 115 | evt->use_units(HepMC::Units::MEV, HepMC::Units::MM); | - | ||
| 116 | evt->write_units(); | - | ||
| 117 | pim = findPiZero(evt); | - | ||
| 118 | std::cout << " pizero mass: " << pim | - | ||
| 119 | << " " << HepMC::Units::name( evt->momentum_unit() ) << std::endl; | - | ||
| - | 113 | os << " pizero mass: " << pim << std::endl; | ||
| - | 114 | if( HepMC::Units::name( evt->momentum_unit() ) == "GEV" ) { | ||
| - | 115 | os << " GenEvent units are GeV" << std::endl; | ||
| - | 116 | if( pim > 1.0 ) { | ||
| - | 117 | // presume units are MEV and out of sync | ||
| - | 118 | os << " pizero units are MeV" << std::endl; | ||
| - | 119 | repairUnits(evt,HepMC::Units::MEV,HepMC::Units::GEV); | ||
| - | 120 | // set units to MeV and mm | ||
| - | 121 | evt->use_units(HepMC::Units::MEV, HepMC::Units::MM); | ||
| - | 122 | evt->write_units(os); | ||
| - | 123 | pim = findPiZero(evt); | ||
| - | 124 | os << " pizero mass: " << pim | ||
| - | 125 | << " " << HepMC::Units::name( evt->momentum_unit() ) << std::endl; | ||
| - | 126 | // convert units to MeV | ||
| - | 127 | evt->use_units(HepMC::Units::MEV, HepMC::Units::MM); | ||
| - | 128 | evt->write_units(os); | ||
| - | 129 | pim = findPiZero(evt); | ||
| - | 130 | os << " pizero mass: " << pim | ||
| - | 131 | << " " << HepMC::Units::name( evt->momentum_unit() ) << std::endl; | ||
| - | 132 | } else if( pim > 0.1 ) { | ||
| - | 133 | // presume units are GEV | ||
| - | 134 | os << " pizero units are GeV" << std::endl; | ||
| - | 135 | // set units to GeV and mm | ||
| - | 136 | evt->use_units(HepMC::Units::GEV, HepMC::Units::MM); | ||
| - | 137 | evt->write_units(os); | ||
| - | 138 | pim = findPiZero(evt); | ||
| - | 139 | os << " pizero mass: " << pim | ||
| - | 140 | << " " << HepMC::Units::name( evt->momentum_unit() ) << std::endl; | ||
| - | 141 | // convert units to MeV | ||
| - | 142 | evt->use_units(HepMC::Units::MEV, HepMC::Units::MM); | ||
| - | 143 | evt->write_units(os); | ||
| - | 144 | pim = findPiZero(evt); | ||
| - | 145 | os << " pizero mass: " << pim | ||
| - | 146 | << " " << HepMC::Units::name( evt->momentum_unit() ) << std::endl; | ||
| - | 147 | } else { | ||
| - | 148 | os << " pizero mass: " << pim | ||
| - | 149 | << " is inconsistent with allowed units " << std::endl; | ||
| - | 150 | } | ||
| - | 151 | } else if( HepMC::Units::name( evt->momentum_unit() ) == "MEV" ) { | ||
| - | 152 | os << " GenEvent units are MeV" << std::endl; | ||
| - | 153 | if( pim > 1.0 ) { | ||
| - | 154 | // presume units are MEV | ||
| - | 155 | os << " pizero units are MeV" << std::endl; | ||
| - | 156 | // set units to MeV and mm | ||
| - | 157 | evt->use_units(HepMC::Units::MEV, HepMC::Units::MM); | ||
| - | 158 | evt->write_units(os); | ||
| - | 159 | pim = findPiZero(evt); | ||
| - | 160 | os << " pizero mass: " << pim | ||
| - | 161 | << " " << HepMC::Units::name( evt->momentum_unit() ) << std::endl; | ||
| - | 162 | // convert units to MeV | ||
| - | 163 | evt->use_units(HepMC::Units::MEV, HepMC::Units::MM); | ||
| - | 164 | evt->write_units(os); | ||
| - | 165 | pim = findPiZero(evt); | ||
| - | 166 | os << " pizero mass: " << pim | ||
| - | 167 | << " " << HepMC::Units::name( evt->momentum_unit() ) << std::endl; | ||
| - | 168 | } else if( pim > 0.1 ) { | ||
| - | 169 | // presume units are GEV and out of sync | ||
| - | 170 | os << " pizero units are GeV" << std::endl; | ||
| - | 171 | repairUnits(evt,HepMC::Units::GEV,HepMC::Units::MEV); | ||
| - | 172 | evt->write_units(os); | ||
| - | 173 | pim = findPiZero(evt); | ||
| - | 174 | os << " pizero mass: " << pim | ||
| - | 175 | << " " << HepMC::Units::name( evt->momentum_unit() ) << std::endl; | ||
| - | 176 | // convert units to MeV | ||
| - | 177 | evt->use_units(HepMC::Units::MEV, HepMC::Units::MM); | ||
| - | 178 | evt->write_units(os); | ||
| - | 179 | pim = findPiZero(evt); | ||
| - | 180 | os << " pizero mass: " << pim | ||
| - | 181 | << " " << HepMC::Units::name( evt->momentum_unit() ) << std::endl; | ||
| - | 182 | } else { | ||
| - | 183 | os << " pizero mass: " << pim | ||
| - | 184 | << " is inconsistent with allowed units " << std::endl; | ||
| - | 185 | } | ||
| - | 186 | } | ||
| 120 | // clean up and get next event | 187 | // clean up and get next event | |
| 121 | delete evt; | 188 | delete evt; | |
| 122 | ascii_in >> evt; | 189 | ascii_in >> evt; | |
| 123 | } | 190 | } | |
| 124 | //........................................PRINT RESULT | 191 | //........................................PRINT RESULT | |
| 125 | std::cout << icount << " events processed. Finished." << std::endl; | - | ||
| - | 192 | os << icount << " events processed. Finished." << std::endl; | ||
| 126 | } | 193 | } | |
| 127 | 194 | |||
| 128 | void writeWithCrossSection() | - | ||
| - | 195 | void writeWithCrossSection(std::ostream & os) | ||
| 129 | { | 196 | { | |
| 130 | // declare an input strategy to read input data | 197 | // declare an input strategy to read input data | |
| 131 | // units are GeV and mm | 198 | // units are GeV and mm | |
| 132 | HepMC::IO_GenEvent ascii_in("@srcdir@/testIOGenEvent.input",std::ios::in); | 199 | HepMC::IO_GenEvent ascii_in("@srcdir@/testIOGenEvent.input",std::ios::in); | |
| 133 | ascii_in.use_input_units( HepMC::Units::GEV, HepMC::Units::MM ); | 200 | ascii_in.use_input_units( HepMC::Units::GEV, HepMC::Units::MM ); | |
| Line 142... | Line 209... | |||
| 142 | const double xs0 = 0.00346; | 209 | const double xs0 = 0.00346; | |
| 143 | const double xs1 = 0.12; | 210 | const double xs1 = 0.12; | |
| 144 | const double xs2 = 33.234; | 211 | const double xs2 = 33.234; | |
| 145 | const double xs3 = 459.345; | 212 | const double xs3 = 459.345; | |
| 146 | double xserr = 0.0001; | 213 | double xserr = 0.0001; | |
| - | 214 | double wgt1, wgt2; | ||
| 147 | HepMC::GenEvent* evt = ascii_in.read_next_event(); | 215 | HepMC::GenEvent* evt = ascii_in.read_next_event(); | |
| 148 | while ( evt ) { | 216 | while ( evt ) { | |
| 149 | icount++; | 217 | icount++; | |
| 150 | // use a variety of arbitrary cross section values | 218 | // use a variety of arbitrary cross section values | |
| 151 | if( icount < 10 ) { | 219 | if( icount < 10 ) { | |
| Line 165... | Line 233... | |||
| 165 | if ( icount == 10 ) xserr += 0.01; | 233 | if ( icount == 10 ) xserr += 0.01; | |
| 166 | if ( icount == 20 ) xserr += 0.4; | 234 | if ( icount == 20 ) xserr += 0.4; | |
| 167 | if ( icount == 30 ) xserr += 1.0; | 235 | if ( icount == 30 ) xserr += 1.0; | |
| 168 | // attach this cross section to the event | 236 | // attach this cross section to the event | |
| 169 | evt->set_cross_section( cross ); | 237 | evt->set_cross_section( cross ); | |
| 170 | evt->write_cross_section(); | - | ||
| - | 238 | evt->write_cross_section(os); | ||
| - | 239 | // add weights | ||
| - | 240 | wgt1 = 0.9853 + (double)icount * 0.00033; | ||
| - | 241 | wgt2 = 0.9853 + (double)(icount+1) * 0.00033; | ||
| - | 242 | evt->weights().push_back(0.3456); | ||
| - | 243 | evt->weights()["weightName"] = wgt1; | ||
| - | 244 | evt->weights()["second weight name"] = wgt2; | ||
| 171 | if ( icount%20==1 ) { | 245 | if ( icount%20==1 ) { | |
| 172 | std::cout << "writeWithCrossSection: Processing Event Number " << icount | - | ||
| - | 246 | os << "writeWithCrossSection: Processing Event Number " << icount | ||
| 173 | << " its # " << evt->event_number() | 247 | << " its # " << evt->event_number() | |
| 174 | << std::endl; | 248 | << std::endl; | |
| 175 | ascii_out << evt; | 249 | ascii_out << evt; | |
| 176 | evt->print(xout); | 250 | evt->print(xout); | |
| 177 | } | 251 | } | |
| Line 179... | Line 253... | |||
| 179 | // clean up and get next event | 253 | // clean up and get next event | |
| 180 | delete evt; | 254 | delete evt; | |
| 181 | ascii_in >> evt; | 255 | ascii_in >> evt; | |
| 182 | } | 256 | } | |
| 183 | //........................................PRINT RESULT | 257 | //........................................PRINT RESULT | |
| 184 | std::cout << "writeWithCrossSection processed " << icount << " events. Finished." << std::endl; | - | ||
| - | 258 | os << "writeWithCrossSection processed " << icount << " events. Finished." << std::endl; | ||
| 185 | } | 259 | } | |
| 186 | 260 | |||
| 187 | void readWithCrossSection() | - | ||
| - | 261 | void readWithCrossSection(std::ostream & os) | ||
| 188 | { | 262 | { | |
| 189 | // read the file we just wrote | 263 | // read the file we just wrote | |
| 190 | HepMC::IO_GenEvent ascii_in("testCrossSection.out",std::ios::in); | 264 | HepMC::IO_GenEvent ascii_in("testCrossSection.out",std::ios::in); | |
| 191 | // declare another IO_GenEvent for writing out some events | 265 | // declare another IO_GenEvent for writing out some events | |
| 192 | HepMC::IO_GenEvent ascii_out("testCrossSection2.out",std::ios::out); | 266 | HepMC::IO_GenEvent ascii_out("testCrossSection2.out",std::ios::out); | |
| 193 | //........................................EVENT LOOP | 267 | //........................................EVENT LOOP | |
| 194 | int icount=0; | 268 | int icount=0; | |
| 195 | HepMC::GenEvent* evt = ascii_in.read_next_event(); | 269 | HepMC::GenEvent* evt = ascii_in.read_next_event(); | |
| 196 | while ( evt ) { | 270 | while ( evt ) { | |
| 197 | ++icount; | 271 | ++icount; | |
| 198 | std::cout << "readWithCrossSection: Processing Event Number " << icount | - | ||
| - | 272 | os << "readWithCrossSection: Processing Event Number " << icount | ||
| 199 | << " its # " << evt->event_number() | 273 | << " its # " << evt->event_number() | |
| 200 | << std::endl; | 274 | << std::endl; | |
| 201 | if (evt->cross_section()->cross_section() <= 0) { | 275 | if (evt->cross_section()->cross_section() <= 0) { | |
| 202 | std::cout << "testReadCrossSection: invalid cross-section!" << std::endl; | - | ||
| - | 276 | os << "testReadCrossSection: invalid cross-section!" << std::endl; | ||
| 203 | } | 277 | } | |
| 204 | ascii_out << evt; | 278 | ascii_out << evt; | |
| 205 | 279 | |||
| 206 | // clean up and get next event | 280 | // clean up and get next event | |
| 207 | delete evt; | 281 | delete evt; | |
| 208 | ascii_in >> evt; | 282 | ascii_in >> evt; | |
| 209 | } | 283 | } | |
| 210 | //........................................PRINT RESULT | 284 | //........................................PRINT RESULT | |
| 211 | std::cout << "readWithCrossSection processed " << icount << " events. Finished." << std::endl; | - | ||
| - | 285 | os << "readWithCrossSection processed " << icount << " events. Finished." << std::endl; | ||
| 212 | } | 286 | } | |
| 213 | 287 | |||
| 214 | void read_nan() | - | ||
| - | 288 | void read_nan(std::ostream & os) | ||
| 215 | { | 289 | { | |
| 216 | // Read an input file that has corrupt information (nan's) | 290 | // Read an input file that has corrupt information (nan's) | |
| 217 | // | 291 | // | |
| 218 | HepMC::IO_GenEvent xin("@srcdir@/testHepMCVarious.input",std::ios::in); | 292 | HepMC::IO_GenEvent xin("@srcdir@/testHepMCVarious.input",std::ios::in); | |
| 219 | HepMC::IO_GenEvent xout("testNaN.out",std::ios::out); | 293 | HepMC::IO_GenEvent xout("testNaN.out",std::ios::out); | |
| 220 | //........................................EVENT LOOP | 294 | //........................................EVENT LOOP | |
| 221 | int icount=0; | 295 | int icount=0; | |
| 222 | int invaliddata=0; | 296 | int invaliddata=0; | |
| 223 | bool ok = true; | 297 | bool ok = true; | |
| 224 | std::cout << "---------------------------------------- " << std::endl; | - | ||
| 225 | std::cout << "Begin NaN test " << std::endl; | - | ||
| - | 298 | os << "---------------------------------------- " << std::endl; | ||
| - | 299 | os << "Begin NaN test " << std::endl; | ||
| 226 | HepMC::GenEvent* evt = xin.read_next_event(); | 300 | HepMC::GenEvent* evt = xin.read_next_event(); | |
| 227 | // | 301 | // | |
| 228 | // To recover from corrupt input, replace "while(evt) {...}" | 302 | // To recover from corrupt input, replace "while(evt) {...}" | |
| 229 | // with "while(ok) { if(evt) {... xin >> evt;} else {...} }" | 303 | // with "while(ok) { if(evt) {... xin >> evt;} else {...} }" | |
| 230 | // | 304 | // | |
| 231 | while ( ok ) { | 305 | while ( ok ) { | |
| 232 | if( evt ) { | 306 | if( evt ) { | |
| 233 | ++icount; | 307 | ++icount; | |
| 234 | std::cout << "read_nan: Processing Event Number " << icount | - | ||
| - | 308 | os << "read_nan: Processing Event Number " << icount | ||
| 235 | << " its # " << evt->event_number() | 309 | << " its # " << evt->event_number() | |
| 236 | << std::endl; | 310 | << std::endl; | |
| 237 | xout << evt; | 311 | xout << evt; | |
| 238 | // clean up and get next event | 312 | // clean up and get next event | |
| 239 | delete evt; | 313 | delete evt; | |
| 240 | xin >> evt; | 314 | xin >> evt; | |
| 241 | } else if (xin.error_type() == HepMC::IO_Exception::InvalidData ) { | 315 | } else if (xin.error_type() == HepMC::IO_Exception::InvalidData ) { | |
| 242 | ++invaliddata; | 316 | ++invaliddata; | |
| 243 | std::cerr << "INPUT ERROR: " << xin.error_message() << std::endl; | - | ||
| - | 317 | os << "INPUT ERROR: " << xin.error_message() << std::endl; | ||
| 244 | // clean up and get next event | 318 | // clean up and get next event | |
| 245 | delete evt; | 319 | delete evt; | |
| 246 | xin >> evt; | 320 | xin >> evt; | |
| 247 | } else if (invaliddata > 50 ) { | 321 | } else if (invaliddata > 50 ) { | |
| 248 | std::cerr << "INPUT ERROR: " << xin.error_message() << std::endl; | - | ||
| - | 322 | os << "INPUT ERROR: " << xin.error_message() << std::endl; | ||
| 249 | ok = false; | 323 | ok = false; | |
| 250 | } else { | 324 | } else { | |
| 251 | ok = false; | 325 | ok = false; | |
| 252 | } | 326 | } | |
| 253 | } | 327 | } | |
| 254 | // print status of input stream | 328 | // print status of input stream | |
| 255 | if ( xin.error_type() != 0 ) { | 329 | if ( xin.error_type() != 0 ) { | |
| 256 | std::cout << "processing of @srcdir@/testHepMCVarious.input ended with error " | - | ||
| - | 330 | os << "processing of @srcdir@/testHepMCVarious.input ended with error " | ||
| 257 | << xin.error_type() << std::endl; | 331 | << xin.error_type() << std::endl; | |
| 258 | std::cout << " --- " << xin.error_message() << std::endl; | - | ||
| - | 332 | os << " --- " << xin.error_message() << std::endl; | ||
| 259 | } | 333 | } | |
| 260 | std::cout << icount << " events processed and " | - | ||
| - | 334 | os << icount << " events processed and " | ||
| 261 | << invaliddata << " events ignored. Finished." | 335 | << invaliddata << " events ignored. Finished." | |
| 262 | << std::endl; | 336 | << std::endl; | |
| 263 | std::cout << "End NaN test " << std::endl; | - | ||
| 264 | std::cout << "---------------------------------------- " << std::endl; | - | ||
| - | 337 | os << "End NaN test " << std::endl; | ||
| - | 338 | os << "---------------------------------------- " << std::endl; | ||
| 265 | } | 339 | } | |
| 266 | 340 | |||
| - | 341 | void writeWithWeight(std::ostream & os) | ||
| - | 342 | { | ||
| - | 343 | // declare an input strategy to read input data | ||
| - | 344 | // units are GeV and mm | ||
| - | 345 | HepMC::IO_GenEvent ascii_in("@srcdir@/testIOGenEvent.input",std::ios::in); | ||
| - | 346 | ascii_in.use_input_units( HepMC::Units::GEV, HepMC::Units::MM ); | ||
| - | 347 | // declare another IO_GenEvent for writing out some events | ||
| - | 348 | HepMC::IO_GenEvent ascii_out("testWithWeight.out",std::ios::out); | ||
| - | 349 | // declare an output stream for printing events | ||
| - | 350 | std::ofstream xout( "testWithWeight.cout" ); | ||
| - | 351 | //........................................EVENT LOOP | ||
| - | 352 | int icount=0; | ||
| - | 353 | double wgt1, wgt2; | ||
| - | 354 | HepMC::GenEvent* evt = ascii_in.read_next_event(); | ||
| - | 355 | while ( evt ) { | ||
| - | 356 | icount++; | ||
| - | 357 | // add weights | ||
| - | 358 | wgt1 = 0.9853 + (double)icount * 0.00033; | ||
| - | 359 | wgt2 = 0.9853 + (double)(icount+1) * 0.00033; | ||
| - | 360 | evt->weights().push_back(0.3456); | ||
| - | 361 | evt->weights().push_back(wgt1); | ||
| - | 362 | evt->weights().push_back(wgt2); | ||
| - | 363 | if ( icount%20==1 ) { | ||
| - | 364 | os << "writeWithWeight: Processing Event Number " << icount | ||
| - | 365 | << " its # " << evt->event_number() | ||
| - | 366 | << std::endl; | ||
| - | 367 | ascii_out << evt; | ||
| - | 368 | evt->print(xout); | ||
| - | 369 | } | ||
| - | 370 | |||
| - | 371 | // clean up and get next event | ||
| - | 372 | delete evt; | ||
| - | 373 | ascii_in >> evt; | ||
| - | 374 | } | ||
| - | 375 | //........................................PRINT RESULT | ||
| - | 376 | os << "writeWithWeight processed " << icount << " events. Finished." << std::endl; | ||
| - | 377 | } | ||
| - | 378 | |||
| - | 379 | void readWithWeight(std::ostream & os) | ||
| - | 380 | { | ||
| - | 381 | // read the file we just wrote | ||
| - | 382 | HepMC::IO_GenEvent ascii_in("testWithWeight.out",std::ios::in); | ||
| - | 383 | // declare another IO_GenEvent for writing out some events | ||
| - | 384 | HepMC::IO_GenEvent ascii_out("testWithWeight2.out",std::ios::out); | ||
| - | 385 | //........................................EVENT LOOP | ||
| - | 386 | int icount=0; | ||
| - | 387 | HepMC::GenEvent* evt = ascii_in.read_next_event(); | ||
| - | 388 | while ( evt ) { | ||
| - | 389 | ++icount; | ||
| - | 390 | os << "readWithWeight: Processing Event Number " << icount | ||
| - | 391 | << " its # " << evt->event_number() | ||
| - | 392 | << std::endl; | ||
| - | 393 | if ( !evt->cross_section() ) { | ||
| - | 394 | os << "testReadCrossSection: invalid cross-section!" << std::endl; | ||
| - | 395 | } | ||
| - | 396 | ascii_out << evt; | ||
| - | 397 | |||
| - | 398 | // clean up and get next event | ||
| - | 399 | delete evt; | ||
| - | 400 | ascii_in >> evt; | ||
| - | 401 | } | ||
| - | 402 | //........................................PRINT RESULT | ||
| - | 403 | os << "readWithWeight processed " << icount << " events. Finished." << std::endl; | ||
| - | 404 | } | ||
