generator.cc

Go to the documentation of this file.
00001 /*Generator dependant!!!*/
00002 
00003 /***********************************************************************
00004 *                                                                      *
00005 * File: pythia8_jet.cc                                                 *
00006 * This is a simple test program.                                       *
00007 * Copyright \ufffd 2005 Torbj\ufffdrn Sj\ufffdstrand                   *
00008 *                                                                      *
00009 * Modified by sj and ca                                                *
00010 *                                                                      *
00011 ***********************************************************************/
00012 #include "Pythia.h"
00013 
00014 #include "LHAFortran.h"
00015 
00016 #include "HepMCInterface.h"
00017 
00018 #include "HepMC/GenEvent.h"
00019 
00020 // this is needed to generate some random numbers                                                                                                                                                                    
00021 #include <stdlib.h>
00022 #include <time.h>
00023 
00024 #include <iostream>
00025 #include <stdio.h>
00026 #include "HepMC/IO_GenEvent.h"
00027 #include "HepMC/GenEvent.h"
00028 #include "HepMC/IO_AsciiParticles.h"
00029 #include "HepMC/SimpleVector.h"
00030 
00031 using namespace Pythia8; 
00032 using namespace std;
00033 
00034 #include "Configuration.h"
00035 
00036 
00037 /**************************************************************************/
00038 
00039 int main(int argc, const char* argv[]) {
00040   
00041   if(argc <= 2 ) { //ap
00042     std::cout << "Usage: " << argv[0] << " <Configuration File>" << " <name of file to generate to>"<< std::endl; //ap
00043     return 0;
00044   }
00045   
00046   Configuration* currentconfig = new Configuration();
00047   if(currentconfig->read(argv[1]))
00048     {
00049       //std::cout << " ... skip !" << std::endl;
00050       return 0;
00051     }
00052   
00053 
00054   HepMC::I_Pythia8 ToHepMC;
00055 
00056   // Generator. Process selection. LHC initialization.
00057   //Pythia pythia;
00058   Pythia pythia(std::getenv("Pythia8DATA"));
00059 
00060   char processline[64];
00061   // Read in commands from external file.
00062   for (unsigned int files=0; files<currentconfig->ConfigFileNames.size(); files++)
00063       {
00064           //std::cout << "pythia8: Will use settings from file " << currentconfig->ConfigFileNames[files].c_str() << std::endl;
00065           pythia.readFile(currentconfig->ConfigFileNames[files].c_str());
00066       }
00067 
00068   // as done for the random seed, if it is specified
00069   pythia.readString("Random:setSeed = on");
00070   //sprintf(processline,"Random:seed = %ld",currentconfig->rseed);
00071   pythia.readString(processline);
00072 
00073   // master switches for FSR, ISR and MI
00074   //sprintf(processline,"PartonLevel:FSR = %d",int(currentconfig->FSR));
00075   pythia.readString(processline);
00076 
00077   //sprintf(processline,"PartonLevel:ISR = %d",int(currentconfig->ISR));
00078   pythia.readString(processline);
00079 
00080   //sprintf(processline,"PartonLevel:MI = %d",int(currentconfig->MI));
00081   pythia.readString(processline);
00082 
00083   // Settings can also be changed with this command
00084   //pythia.readString("WeakBosonAndParton:all = on");
00085 
00086   pythia.init( 2212, 2212, 14000.);
00087 
00088   // Shorthand for the event and for settings.
00089   Event& event = pythia.event;
00090   Settings& settings = pythia.settings;
00091 
00092   // Extract settings to be used in the main program.
00093   int nEvent = currentconfig->nevents;
00094   //sj//  int nEvent = settings.mode("Main:numberOfEvents");
00095   //int nList = settings.mode("Main:numberToList");
00096   int nShow = settings.mode("Main:timesToShow");
00097   int nAbort = settings.mode("Main:timesAllowErrors");
00098   bool showChangedSettings = settings.flag("Main:showChangedSettings");
00099   bool showAllSettings = settings.flag("Main:showAllSettings");
00100   bool showAllParticleData = settings.flag("Main:showAllParticleData");
00101 
00102   // List changed data.
00103   if (showChangedSettings) settings.listChanged();
00104   if (showAllSettings) settings.listAll();
00105 
00106   // List particle data.  
00107   //if (showAllParticleData) ParticleDataTable::listAll();
00108   //starting at least for Pythia8 135 use the following line
00109   if (showAllParticleData) pythia.particleData.listAll();
00110 
00111   // Begin event loop.
00112   int nShowPace = max(1,nEvent/nShow); 
00113   int iAbort = 0; 
00114   HepMC::IO_GenEvent ascii_out(argv[2],std::ios::out);  //add ap
00115   for (int iEvent = 0; iEvent < nEvent; ++iEvent) {
00116 
00117         if (iEvent%nShowPace == 0) 
00118             //cout << "pythia8: Now begin event "  << iEvent << endl;
00119 
00120     // Generate events. Quit if too many failures.
00121     if (!pythia.next()) {
00122       if (++iAbort < nAbort) continue;
00123       //cout << "pythia8:  Event generation aborted prematurely, owing to error!\n"; 
00124       break;
00125     }
00126  
00127     // List first few events, both hard process and complete events.
00128     //if (iEvent < nList) { 
00129     //if (iEvent < nEvent) { 
00130     //  pythia.process.list();
00131       //event.list();
00132     // }
00133 
00134     //cout << "before ctor" << endl;
00135     HepMC::GenEvent* hepmcevt = new HepMC::GenEvent();
00136     //cout << "after ctor" << endl;
00137     ToHepMC.fill_next_event( event, hepmcevt );
00138     //cout << "fill nex" << endl;
00139     
00140     
00141 
00142     // OUTPUT
00143     ascii_out << hepmcevt;    //add ap
00144     
00145 
00146     delete hepmcevt;
00147     // End of event loop.
00148   }
00149 
00150   // gen>>>>>>>>>>>>>>>>>>>>>>>>
00151   // Final statistics.
00152   pythia.statistics();
00153   //  pythia.particleData.listAll();
00154   pythia.settings.writeFile("allSettings.cmnd",true);
00155 
00156 
00157   // clean up config object
00158   delete currentconfig;
00159 
00160   // Tidy up
00161   std::cout<<"pythia8: program ends"<<std::endl;
00162   std::cout<<"Run successfully!"<<std::endl;
00163   
00164   return 0;
00165 }
00166 

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