generator.cc

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////
00002 // Matt.Dobbs@Cern.CH, October 2002
00003 // example of generating events with Herwig using HepMC/HerwigWrapper.h
00004 // Events are read into the HepMC event record from the FORTRAN HEPEVT
00005 // common block using the IO_HERWIG strategy.
00006 //////////////////////////////////////////////////////////////////////////
00007 
00008 #include <stdlib.h>
00009 #include <time.h>
00010 
00011 #include <stdio.h>
00012 #include <iostream>
00013 #include <fstream>
00014 #include <sstream>
00015 
00016 #include "MyHerwigWrapper.h"
00017 #include "HepMC/IO_HERWIG.h"
00018 //#include "HepMC/IO_Ascii.h"   
00019 #include "HepMC/GenEvent.h"
00020 #include "HepMC/HEPEVT_Wrapper.h"
00021 #include "HepMC/SimpleVector.h"
00022 #include "HepMC/IO_GenEvent.h"  //ap add
00023 
00024 
00025 // include our own classes
00026 #include "Configuration.h"
00027 #include "readherwigConfigFile.h"
00028 
00029 using namespace std;
00030 
00031 // a dummy routine called on the termination of the run
00032 extern "C" void hwaend_ (void); 
00033 extern "C" {
00034   int hwgethepevtsize_(void);
00035   void hwsetmodbos_(int& i, int& ivalue);
00036   double hwgetcs(void);
00037   double hwgetcserr(void);
00038 }
00039 
00040 // ---------------------------------------------------------------------- 
00041 int main(int argc, const char* argv[]) 
00042 {
00043   if(argc <= 2 ) { //ap
00044     std::cout << "Usage: " << argv[0] << " <Configuration File>" << " <name of file to generate to>"<< std::endl; //ap
00045     return 0;
00046   }
00047 
00048   Configuration* currentconfig = new Configuration();
00049   if ( currentconfig->read( argv[ 1 ] ) ) {
00050     cout << " ... skip !" << endl;
00051     return 0;
00052   }
00053 
00054  
00055 
00056   //
00057   //........................................HEPEVT
00058   // herwig-6510-2 uses HEPEVT with 10000 entries and 8-byte floating point
00059   //  numbers. We need to explicitly pass this information to the 
00060   //  HEPEVT_Wrapper.
00061   //
00062   HepMC::HEPEVT_Wrapper::set_max_number_entries(hwgethepevtsize_());
00063   HepMC::HEPEVT_Wrapper::set_sizeof_real(8);
00064 
00065   //random seed
00066   hwevnt.nrn[0] = currentconfig->rseed;
00067   
00068   // number of events
00069   hwproc.maxev = int(currentconfig->nevents); 
00070   
00071   // tell it what the beam particles are:
00072   for ( unsigned int i = 0; i < 8; ++i ) {
00073     hwbmch.part1[i] = (i < 1) ? 'P' : ' ';
00074     hwbmch.part2[i] = (i < 1) ? 'P' : ' ';
00075   }
00076 
00077   // INITIALISE OTHER COMMON BLOCKS
00078   hwigin();
00079   jimmin();
00080 
00081   cout << "Configuration Parameter List:" << endl;
00082   for (unsigned int files=0; files<(currentconfig->ConfigFileNames).size(); files++)
00083     readConfigFile((currentconfig->ConfigFileNames)[files]);
00084 
00085   // master switches for ISR
00086   // true switches ISR off!
00087   //  hwpram.nospac=int(currentconfig->ISR); //switch on/off ISR
00088     
00089   // number of events to print
00090   hwevnt.maxpr = 1; 
00091   // compute parameter-dependent constants
00092   hwuinc(); 
00093   // initialise elementary process
00094   hweini(); 
00095   // initialise jimmy event
00096   jminit();
00097   //........................................HepMC INITIALIZATIONS
00098   //
00099   // Instantiate an IO strategy for reading from HEPEVT.
00100   HepMC::IO_HERWIG hepevtio;
00101   //
00102   //........................................EVENT LOOP
00103   HepMC::IO_GenEvent ascii_out(argv[2],std::ios::out);  //add ap
00104   for ( int iEvent = 1; iEvent <= hwproc.maxev; iEvent++ ) {
00105     if ( iEvent%50==1 ) cout << "Processing Event Number " 
00106                                   << iEvent << endl;
00107 //     // initialise event
00108 //     hwuine();
00109 //     // generate hard subproces
00110 //     hwepro();
00111 //     // generate parton cascades
00112 //     hwbgen();
00113 //     // do heavy object decays
00114 //     hwdhob();
00115 //     // do cluster formation
00116 //     hwcfor();
00117 //     // do cluster decays
00118 //     hwcdec();
00119 //     // do unstable particle decays
00120 //     hwdhad();
00121 //     // do heavy flavour hadron decays
00122 //     hwdhvy();
00123 //     // add soft underlying event if needed
00124 //     hwmevt();
00125 //     // finish event
00126 //     hwufne();
00127 
00128     // initialise event
00129     hwuine();
00130     // generate hard subproces
00131     hwepro();
00132     // generate parton cascades
00133     hwbgen();
00134 
00135     // Do Jimmy underlying event if required.
00136     int abort = 0;
00137     hwmsct(&abort);
00138     if (abort != 0) {
00139       cout << "Event aborted by hwmsct." << endl;
00140       hwufne();  // finish event
00141       continue;
00142     }
00143 
00144     //    if (abort == 0) {
00145       hwdhob();  // Do heavy quark decays
00146       hwcfor();  // Do cluster formation
00147       hwcdec();  // Do cluster decays
00148       hwdhad();  // Do unstable particle decays
00149       hwdhvy();  // Do heavy flavor decays
00150       hwmevt();  // Add soft underlying event
00151       hwufne();  // finish event
00152     //}
00153       if (hwevnt.ierror==-1 || hwevnt.ierror>99) {
00154         cout << "Event Error, Number: " << " Code: " << hwevnt.ierror << endl;
00155         continue;
00156       }
00157     
00158     // Print HEPEVT format event here 
00159     // HepMC::HEPEVT_Wrapper::print_hepevt();
00160 
00161     HepMC::GenEvent* evt = hepevtio.read_next_event();
00162     // add some information to the event
00163     evt->set_event_number(iEvent);
00164     evt->set_signal_process_id(20);
00165    
00166     // the status codes should not be changed, otherwise you change
00167     // the output of the MC generators (status code variabl) and this
00168     // should not be done
00169     //     //change the status code in HepMC format event.  
00170     //     for ( HepMC::GenEvent::particle_const_iterator p =
00171     //      evt->particles_begin(); p != evt->particles_end(); ++p ){
00172     //       if( abs((*p)->status())>1 )
00173     //  (*p)->set_status(2);
00174     //     }
00175        
00176     ascii_out << evt;    //add ap
00177       
00178     // we also need to delete the created event from memory
00179     delete evt;
00180 
00181   }
00182   //........................................TERMINATION
00183   hwefin();
00184 
00185  
00186   // clean up config object
00187   delete currentconfig;
00188 
00189  
00190   cout<<"Run successfully!"<<endl;
00191   return 0;
00192 }
00193 
00194 // a dummy user-supplied subroutine called when the run terminates:
00195 void hwaend_ (void) { return; }

Generated on Wed Aug 31 09:44:48 2011 for HepMCAnalysis by  doxygen 1.4.7