00001
00002
00003
00004
00046
00047
00048 #include <iostream>
00049 #include "HepMC/PythiaWrapper.h"
00050 #include "HepMC/IO_HEPEVT.h"
00051 #include "HepMC/IO_GenEvent.h"
00052 #include "HepMC/IO_AsciiParticles.h"
00053 #include "HepMC/GenEvent.h"
00054 #include "PythiaHelper.h"
00055
00057
00061 class IsGoodEventMyPythia {
00062 public:
00064 bool operator()( const HepMC::GenEvent* evt ) {
00065 for ( HepMC::GenEvent::particle_const_iterator p
00066 = evt->particles_begin(); p != evt->particles_end(); ++p ){
00067 if ( (*p)->pdg_id() == 22 && (*p)->momentum().perp() > 25. ) {
00068
00069
00070
00071 return 1;
00072 }
00073 }
00074 return 0;
00075 }
00076 };
00077
00078
00079 void pythia_out();
00080 void pythia_in();
00081 void pythia_in_out();
00082 void event_selection();
00083 void pythia_particle_out();
00084
00085 int main() {
00086
00087 pythia_out();
00088
00089 event_selection();
00090
00091 pythia_in();
00092
00093 pythia_in_out();
00094
00095 return 0;
00096 }
00097
00098
00099 void pythia_out()
00100 {
00101 std::cout << std::endl;
00102 std::cout << "Begin pythia_out()" << std::endl;
00103
00104
00105
00106
00107
00108 HepMC::HEPEVT_Wrapper::set_max_number_entries(4000);
00109 HepMC::HEPEVT_Wrapper::set_sizeof_real(8);
00110
00111
00112 initPythia();
00113
00114
00115
00116
00117 HepMC::IO_HEPEVT hepevtio;
00118
00119 {
00120
00121 HepMC::IO_GenEvent ascii_io("example_MyPythia.dat",std::ios::out);
00122
00123
00124 for ( int i = 1; i <= 100; i++ ) {
00125 if ( i%50==1 ) std::cout << "Processing Event Number "
00126 << i << std::endl;
00127 call_pyevnt();
00128
00129 call_pyhepc( 1 );
00130 HepMC::GenEvent* evt = hepevtio.read_next_event();
00131
00132 evt->use_units(HepMC::Units::GEV, HepMC::Units::MM);
00133
00134 evt->set_event_number(i);
00135 evt->set_signal_process_id(20);
00136
00137 evt->set_mpi( pypars.msti[31-1] );
00138
00139 evt->set_cross_section( HepMC::getPythiaCrossSection() );
00140
00141 ascii_io << evt;
00142
00143 delete evt;
00144 }
00145
00146
00147 call_pystat( 1 );
00148 }
00149 }
00150
00151
00152 void event_selection()
00153 {
00154 std::cout << std::endl;
00155 std::cout << "Begin event_selection()" << std::endl;
00156
00157
00158
00159
00160
00161 HepMC::HEPEVT_Wrapper::set_max_number_entries(4000);
00162 HepMC::HEPEVT_Wrapper::set_sizeof_real(8);
00163
00164
00165 initPythia();
00166
00167
00168
00169 HepMC::IO_HEPEVT hepevtio;
00170
00171 IsGoodEventMyPythia is_good_event;
00172
00173 int icount=0;
00174 int num_good_events=0;
00175 for ( int i = 1; i <= 100; i++ ) {
00176 icount++;
00177 if ( i%50==1 ) std::cout << "Processing Event Number "
00178 << i << std::endl;
00179 call_pyevnt();
00180
00181 call_pyhepc( 1 );
00182 HepMC::GenEvent* evt = hepevtio.read_next_event();
00183
00184 evt->use_units(HepMC::Units::GEV, HepMC::Units::MM);
00185
00186 evt->set_mpi( pypars.msti[31-1] );
00187
00188 evt->set_cross_section( HepMC::getPythiaCrossSection() );
00189
00190 if ( is_good_event(evt) ) {
00191 std::cout << "Good Event Number " << i << std::endl;
00192 ++num_good_events;
00193 }
00194
00195 delete evt;
00196 }
00197
00198
00199 call_pystat( 1 );
00200
00201 std::cout << num_good_events << " out of " << icount
00202 << " processed events passed the cuts. Finished." << std::endl;
00203 }
00204
00205 void pythia_in()
00206 {
00207 std::cout << std::endl;
00208 std::cout << "Begin pythia_in()" << std::endl;
00209 std::cout << "reading example_MyPythia.dat" << std::endl;
00210
00211 {
00212
00213 std::ifstream istr( "example_MyPythia.dat" );
00214 if( !istr ) {
00215 std::cerr << "example_ReadMyPythia: cannot open example_MyPythia.dat" << std::endl;
00216 exit(-1);
00217 }
00218 HepMC::IO_GenEvent ascii_in(istr);
00219
00220 HepMC::IO_GenEvent ascii_out("example_MyPythia2.dat",std::ios::out);
00221
00222 int icount=0;
00223 HepMC::GenEvent* evt = ascii_in.read_next_event();
00224 while ( evt ) {
00225 icount++;
00226 if ( icount%50==1 ) std::cout << "Processing Event Number " << icount
00227 << " its # " << evt->event_number()
00228 << std::endl;
00229
00230 ascii_out << evt;
00231 delete evt;
00232 ascii_in >> evt;
00233 }
00234
00235 std::cout << icount << " events found. Finished." << std::endl;
00236 }
00237 }
00238
00239 void pythia_in_out()
00240 {
00241 std::cout << std::endl;
00242 std::cout << "Begin pythia_in_out()" << std::endl;
00243
00244
00245
00246
00247
00248 HepMC::HEPEVT_Wrapper::set_max_number_entries(4000);
00249 HepMC::HEPEVT_Wrapper::set_sizeof_real(8);
00250
00251
00252 initPythia();
00253
00254
00255
00256
00257 HepMC::IO_HEPEVT hepevtio;
00258
00259
00260 {
00261
00262 HepMC::IO_GenEvent ascii_io("example_MyPythiaRead.dat",std::ios::out);
00263
00264
00265 for ( int i = 1; i <= 100; i++ ) {
00266 if ( i%50==1 ) std::cout << "Processing Event Number "
00267 << i << std::endl;
00268 call_pyevnt();
00269
00270 call_pyhepc( 1 );
00271 HepMC::GenEvent* evt = hepevtio.read_next_event();
00272
00273 evt->use_units(HepMC::Units::GEV, HepMC::Units::MM);
00274
00275 evt->set_cross_section( HepMC::getPythiaCrossSection() );
00276
00277 evt->set_event_number(i);
00278 evt->set_signal_process_id(20);
00279
00280 ascii_io << evt;
00281
00282 delete evt;
00283 }
00284
00285
00286 call_pystat( 1 );
00287 }
00288
00289
00290 {
00291
00292 HepMC::IO_GenEvent ascii_in("example_MyPythiaRead.dat",std::ios::in);
00293 HepMC::IO_GenEvent ascii_io2("example_MyPythiaRead2.dat",std::ios::out);
00294 int icount=0;
00295 HepMC::GenEvent* evt = ascii_in.read_next_event();
00296 while ( evt ) {
00297 icount++;
00298 if ( icount%50==1 ) std::cout << "Processing Event Number " << icount
00299 << " its # " << evt->event_number()
00300 << std::endl;
00301
00302 ascii_io2 << evt;
00303 delete evt;
00304 ascii_in >> evt;
00305 }
00306
00307 std::cout << icount << " events found. Finished." << std::endl;
00308 }
00309 }
00310
00311 void pythia_particle_out()
00312 {
00313 std::cout << std::endl;
00314 std::cout << "Begin pythia_particle_out()" << std::endl;
00315
00316
00317
00318
00319
00320 HepMC::HEPEVT_Wrapper::set_max_number_entries(4000);
00321 HepMC::HEPEVT_Wrapper::set_sizeof_real(8);
00322
00323
00324 initPythia();
00325
00326
00327
00328
00329 HepMC::IO_HEPEVT hepevtio;
00330
00331 {
00332
00333 HepMC::IO_AsciiParticles ascii_io("example_PythiaParticle.dat",std::ios::out);
00334
00335
00336 for ( int i = 1; i <= 100; i++ ) {
00337 if ( i%50==1 ) std::cout << "Processing Event Number "
00338 << i << std::endl;
00339 call_pyevnt();
00340
00341 call_pyhepc( 1 );
00342 HepMC::GenEvent* evt = hepevtio.read_next_event();
00343
00344 evt->use_units(HepMC::Units::GEV, HepMC::Units::MM);
00345
00346 evt->set_cross_section( HepMC::getPythiaCrossSection() );
00347
00348 evt->set_event_number(i);
00349 evt->set_signal_process_id(20);
00350
00351 ascii_io << evt;
00352
00353 delete evt;
00354 }
00355
00356
00357 call_pystat( 1 );
00358 }
00359 }
00360