Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

pythia8.cc

Go to the documentation of this file.
00001 /***********************************************************************
00002 *                                                                      *
00003 * File: pythia8_jet.cc                                                 *
00004 * This is a simple test program.                                       *
00005 * Copyright \ufffd 2005 Torbj\ufffdrn Sj\ufffdstrand                   *
00006 *                                                                      *
00007 * Modified by sj and ca                                                *
00008 *                                                                      *
00009 ***********************************************************************/
00010 #include "Pythia.h"
00011 
00012 #include "LHAFortran.h"
00013 
00014 #include "HepMCInterface.h"
00015 
00016 #include "HepMC/GenEvent.h"
00017 
00018 // this is needed to generate some random numbers                                                                                                                                                                    
00019 #include <stdlib.h>
00020 #include <time.h>
00021 
00022 #include <iostream>
00023 #include <stdio.h>
00024 #include "HepMC/IO_GenEvent.h"
00025 #include "HepMC/GenEvent.h"
00026 #include "HepMC/IO_AsciiParticles.h"
00027 #include "HepMC/SimpleVector.h"
00028 
00029 #include "TH1.h"
00030 #include "TFile.h"
00031 #include "TMath.h"
00032 #include <TCanvas.h>
00033 
00034 #include "TF1.h"
00035 #include <TH2.h>
00036 #include <TStyle.h>
00037 #include "TLegend.h"
00038 #include <TTree.h>
00039 #include <TString.h>
00040 
00041 using namespace Pythia8; 
00042 using namespace std;
00043 
00044 #include "../../include/DiJetAnalysis.h"
00045 #include "../../include/WplusJetAnalysis.h"
00046 #include "../../include/ZAnalysis.h"
00047 #include "../../include/TauAnalysis.h"
00048 #include "../../include/TopAnalysis.h"
00049 #include "../../include/UEAnalysis.h"
00050 #include "../../include/Configuration.h"
00051 
00052 /**************************************************************************/
00053 
00054 int main(int argc, const char* argv[]) {
00055 
00056     if(argc <= 1 ) {
00057         std::cout << "Usage: " << argv[0] << " <Configuration File>" << std::endl;
00058         return 0;
00059     }
00060 
00061 
00062     Configuration* currentconfig = new Configuration();
00063     if(currentconfig->read(argv[1]))
00064         {
00065             std::cout << " ... skip !" << std::endl;
00066             return 0;
00067         }
00068 
00069     //argv[2] = (Pythia8DATA);
00070 
00071     DiJetAnalysis dijet;
00072     WplusJetAnalysis wplusjet;
00073     ZAnalysis z0;
00074     TauAnalysis tau;
00075     TopAnalysis top;
00076     UEAnalysis ue;
00077 
00078     // create analysis Objects and initialize them                                                                                          
00079   if(currentconfig->dijet){
00080     dijet.Init(currentconfig->max_eta,currentconfig->min_pt);
00081     dijet.InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin);
00082   }
00083 
00084   if(currentconfig->wplusjet){
00085     wplusjet.Init(currentconfig->max_eta,currentconfig->min_pt);
00086     wplusjet.InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin);
00087   }
00088 
00089   if(currentconfig->z){
00090     z0.Init(currentconfig->max_eta,currentconfig->min_pt);
00091     z0.InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin);
00092   }
00093   if(currentconfig->tau){
00094     tau.Init(currentconfig->max_eta,currentconfig->min_pt);
00095     tau.InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin);
00096   }
00097   if(currentconfig->top){
00098     top.Init(currentconfig->max_eta,currentconfig->min_pt);
00099     top.InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin);
00100   }
00101   if(currentconfig->ue){
00102     ue.Init(currentconfig->max_eta,currentconfig->min_pt);
00103     ue.InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin);
00104   }
00105   
00106   HepMC::I_Pythia8 ToHepMC;
00107 
00108   // Generator. Process selection. LHC initialization.
00109   //Pythia pythia;
00110   Pythia pythia(std::getenv("Pythia8DATA"));
00111 
00112   // as done for the random seed, if it is specified
00113   char processline[64];
00114   pythia.readString("Random:setSeed = on");
00115   sprintf(processline,"Random:seed = %ld",currentconfig->rseed);
00116   pythia.readString(processline);
00117 
00118   // Read in commands from external file.
00119   for (unsigned int files=0; files<currentconfig->ConfigFileNames.size(); files++)
00120       {
00121           std::cout << "pythia8: Will use settings from file " << currentconfig->ConfigFileNames[files].c_str() << std::endl;
00122           pythia.readFile(currentconfig->ConfigFileNames[files].c_str());
00123       }
00124 
00125   // master switches for FSR, ISR and MI
00126   sprintf(processline,"PartonLevel:FSR = %d",int(currentconfig->FSR));
00127   pythia.readString(processline);
00128 
00129   sprintf(processline,"PartonLevel:ISR = %d",int(currentconfig->ISR));
00130   pythia.readString(processline);
00131 
00132   sprintf(processline,"PartonLevel:MI = %d",int(currentconfig->MI));
00133   pythia.readString(processline);
00134 
00135   // Settings can also be changed with this command
00136   //pythia.readString("WeakBosonAndParton:all = on");
00137 
00138   pythia.init( 2212, 2212, 14000.);
00139 
00140   // Shorthand for the event and for settings.
00141   Event& event = pythia.event;
00142   Settings& settings = pythia.settings;
00143 
00144   // Extract settings to be used in the main program.
00145   int nEvent = currentconfig->nevents;
00146   //sj//  int nEvent = settings.mode("Main:numberOfEvents");
00147   int nList = settings.mode("Main:numberToList");
00148   int nShow = settings.mode("Main:timesToShow");
00149   int nAbort = settings.mode("Main:timesAllowErrors");
00150   bool showChangedSettings = settings.flag("Main:showChangedSettings");
00151   bool showAllSettings = settings.flag("Main:showAllSettings");
00152   bool showAllParticleData = settings.flag("Main:showAllParticleData");
00153 
00154   // List changed data.
00155   if (showChangedSettings) settings.listChanged();
00156   if (showAllSettings) settings.listAll();
00157 
00158   // List particle data.  
00159   if (showAllParticleData) ParticleDataTable::listAll();
00160 
00161   // Begin event loop.
00162   int nShowPace = max(1,nEvent/nShow); 
00163   int iAbort = 0; 
00164   for (int iEvent = 0; iEvent < nEvent; ++iEvent) {
00165 
00166         if (iEvent%nShowPace == 0) 
00167             cout << "pythia8: Now begin event "  << iEvent << endl;
00168 
00169     // Generate events. Quit if too many failures.
00170     if (!pythia.next()) {
00171       if (++iAbort < nAbort) continue;
00172       cout << "pythia8:  Event generation aborted prematurely, owing to error!\n"; 
00173       break;
00174     }
00175  
00176     // List first few events, both hard process and complete events.
00177     //if (iEvent < nList) { 
00178     //if (iEvent < nEvent) { 
00179     //  pythia.process.list();
00180       //event.list();
00181     // }
00182 
00183     HepMC::GenEvent* hepmcevt = new HepMC::GenEvent();
00184     ToHepMC.fill_next_event( event, hepmcevt );
00185 
00186     //hepmcevt->print();
00187 
00188     int ret_dijet = SUCCESS;
00189     int ret_wplusjet = SUCCESS;
00190     int ret_z0 = SUCCESS;
00191     int ret_tau = SUCCESS;
00192     int ret_top = SUCCESS;
00193     int ret_ue = SUCCESS;
00194 
00195     //call analysis
00196     if(currentconfig->dijet)       ret_dijet = dijet.Process(hepmcevt);
00197     if(currentconfig->wplusjet)    ret_wplusjet = wplusjet.Process(hepmcevt);
00198     if(currentconfig->z)           ret_z0 = z0.Process(hepmcevt);
00199     if(currentconfig->tau)  ret_tau = tau.Process(hepmcevt);
00200     if(currentconfig->top)  ret_top = top.Process(hepmcevt);
00201     if(currentconfig->ue)   ret_ue = ue.Process(hepmcevt);
00202 
00203     if (ret_dijet==FAILURE || ret_wplusjet==FAILURE || ret_z0==FAILURE 
00204         || ret_tau==FAILURE || ret_top==FAILURE || ret_ue==FAILURE)
00205       {
00206         std::cout << "Processing event number " << iEvent << std::endl;    
00207         std::cout << "throw FAILURE"<<std::endl;
00208         //std::cout<<std::endl;
00209         //std::cout<<"HepMC Output"<<std::endl;
00210         //hepmcevt->print();
00211         std::cout<<std::endl;
00212       }
00213 
00214     //delete all the jet objects to be free for the next event
00215     if(currentconfig->dijet)       dijet.DeleteJetObject(hepmcevt);
00216     if(currentconfig->wplusjet)    wplusjet.DeleteJetObject(hepmcevt);
00217     if(currentconfig->z)         z0.DeleteJetObject(hepmcevt);
00218     if(currentconfig->tau)       tau.DeleteJetObject(hepmcevt);
00219     if(currentconfig->top)       top.DeleteJetObject(hepmcevt);
00220     if(currentconfig->ue)        ue.DeleteJetObject(hepmcevt);
00221 
00222     // clear memory from this event
00223     delete hepmcevt;
00224 
00225     // End of event loop.
00226   }
00227 
00228   // Final statistics.
00229   pythia.statistics();
00230   //  pythia.particleData.listAll();
00231   pythia.settings.writeFile("allSettings.cmnd",true);
00232 
00233   //JetpAnalysis jet;
00234   TFile* f = new TFile(currentconfig->OutputFileName.c_str(),"RECREATE");
00235     if(currentconfig->dijet)       dijet.Finalize(f);
00236     if(currentconfig->wplusjet)    wplusjet.Finalize(f);
00237     if(currentconfig->z)         z0.Finalize(f);
00238     if(currentconfig->tau)       tau.Finalize(f);
00239     if(currentconfig->top)       top.Finalize(f);
00240     if(currentconfig->ue)       ue.finalize(f);
00241 
00242   std::cout<<"pythia8: program ends"<<std::endl;
00243   f->Close();
00244   // Done.
00245   return 0;
00246 }
00247 

Generated on Mon Feb 16 15:58:20 2009 for HepMCAnalysis by  doxygen 1.3.9.1