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/Configuration.h"
00045 #include "../../include/JetFinder.h"
00046 #include "../../include/DiJetAnalysis.h"
00047 #include "../../include/WplusJetAnalysis.h"
00048 #include "../../include/ZAnalysis.h"
00049 #include "../../include/TauAnalysis.h"
00050 #include "../../include/TopAnalysis.h"
00051 #include "../../include/UEAnalysis.h"
00052 #include "../../include/EtMissAnalysis.h"
00053 #include "../../include/UserAnalysis.h"
00054 
00055 /**************************************************************************/
00056 
00057 int main(int argc, const char* argv[]) {
00058   
00059   if(argc <= 1 ) {
00060     std::cout << "Usage: " << argv[0] << " <Configuration File>" << std::endl;
00061     return 0;
00062   }
00063   
00064   
00065   Configuration* currentconfig = new Configuration();
00066   if(currentconfig->read(argv[1]))
00067     {
00068       std::cout << " ... skip !" << std::endl;
00069       return 0;
00070     }
00071   
00072   //argv[2] = (Pythia8DATA);
00073   
00074   JetFinder FindJet;
00075   FindJet.Init(currentconfig->max_eta,currentconfig->min_pt);
00076   FindJet.InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin,currentconfig->lepton_ptmin,currentconfig->DeltaR_lepton_track);
00077 
00078   std::vector<baseAnalysis*> analysis;
00079 
00080   // create analysis Objects and initialize them                                                                                          
00081   if (currentconfig->dijet) {
00082     std::cout << "Adding module DiJetAnalysis" << std::endl;
00083     analysis.push_back(new DiJetAnalysis);
00084   }
00085   if (currentconfig->wplusjet) {
00086     std::cout << "Adding module WplusJetAnalysis" << std::endl;
00087     analysis.push_back(new WplusJetAnalysis);
00088   }
00089   if(currentconfig->z){
00090     std::cout << "Adding module ZAnalysis" << std::endl;
00091     analysis.push_back(new ZAnalysis);
00092   }
00093   if(currentconfig->tau){
00094     std::cout << "Adding module TauAnalysis" << std::endl;
00095     analysis.push_back(new TauAnalysis);
00096   }
00097   if(currentconfig->top){
00098     std::cout << "Adding module TopAnalysis" << std::endl;
00099     analysis.push_back(new TopAnalysis);
00100   }
00101   if(currentconfig->ue){
00102     std::cout << "Adding module UEAnalysis" << std::endl;
00103     analysis.push_back(new UEAnalysis);
00104   }  
00105   if(currentconfig->etmiss){
00106     std::cout << "Adding module EtMissAnalysis" << std::endl;
00107     analysis.push_back(new EtMissAnalysis);
00108   }
00109   if(currentconfig->user){
00110     std::cout << "Adding module UserAnalysis" << std::endl;
00111     analysis.push_back(new UserAnalysis);
00112   }
00113 
00114   // init requested analysis modules and jet finder
00115   for (std::vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00116     (*i)->Init(currentconfig->max_eta,currentconfig->min_pt);
00117     (*i)->InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin,currentconfig->lepton_ptmin,currentconfig->DeltaR_lepton_track);
00118   }
00119 
00120   
00121   HepMC::I_Pythia8 ToHepMC;
00122 
00123   // Generator. Process selection. LHC initialization.
00124   //Pythia pythia;
00125   Pythia pythia(std::getenv("Pythia8DATA"));
00126 
00127   char processline[64];
00128   // Read in commands from external file.
00129   for (unsigned int files=0; files<currentconfig->ConfigFileNames.size(); files++)
00130       {
00131           std::cout << "pythia8: Will use settings from file " << currentconfig->ConfigFileNames[files].c_str() << std::endl;
00132           pythia.readFile(currentconfig->ConfigFileNames[files].c_str());
00133       }
00134 
00135   // as done for the random seed, if it is specified
00136   pythia.readString("Random:setSeed = on");
00137   sprintf(processline,"Random:seed = %ld",currentconfig->rseed);
00138   pythia.readString(processline);
00139 
00140   // master switches for FSR, ISR and MI
00141   sprintf(processline,"PartonLevel:FSR = %d",int(currentconfig->FSR));
00142   pythia.readString(processline);
00143 
00144   sprintf(processline,"PartonLevel:ISR = %d",int(currentconfig->ISR));
00145   pythia.readString(processline);
00146 
00147   sprintf(processline,"PartonLevel:MI = %d",int(currentconfig->MI));
00148   pythia.readString(processline);
00149 
00150   // Settings can also be changed with this command
00151   //pythia.readString("WeakBosonAndParton:all = on");
00152 
00153   pythia.init( 2212, 2212, 14000.);
00154 
00155   // Shorthand for the event and for settings.
00156   Event& event = pythia.event;
00157   Settings& settings = pythia.settings;
00158 
00159   // Extract settings to be used in the main program.
00160   int nEvent = currentconfig->nevents;
00161   //sj//  int nEvent = settings.mode("Main:numberOfEvents");
00162   int nList = settings.mode("Main:numberToList");
00163   int nShow = settings.mode("Main:timesToShow");
00164   int nAbort = settings.mode("Main:timesAllowErrors");
00165   bool showChangedSettings = settings.flag("Main:showChangedSettings");
00166   bool showAllSettings = settings.flag("Main:showAllSettings");
00167   bool showAllParticleData = settings.flag("Main:showAllParticleData");
00168 
00169   // List changed data.
00170   if (showChangedSettings) settings.listChanged();
00171   if (showAllSettings) settings.listAll();
00172 
00173   // List particle data.  
00174   if (showAllParticleData) ParticleDataTable::listAll();
00175 
00176   // Begin event loop.
00177   int nShowPace = max(1,nEvent/nShow); 
00178   int iAbort = 0; 
00179   for (int iEvent = 0; iEvent < nEvent; ++iEvent) {
00180 
00181         if (iEvent%nShowPace == 0) 
00182             cout << "pythia8: Now begin event "  << iEvent << endl;
00183 
00184     // Generate events. Quit if too many failures.
00185     if (!pythia.next()) {
00186       if (++iAbort < nAbort) continue;
00187       cout << "pythia8:  Event generation aborted prematurely, owing to error!\n"; 
00188       break;
00189     }
00190  
00191     // List first few events, both hard process and complete events.
00192     //if (iEvent < nList) { 
00193     //if (iEvent < nEvent) { 
00194     //  pythia.process.list();
00195       //event.list();
00196     // }
00197 
00198     HepMC::GenEvent* hepmcevt = new HepMC::GenEvent();
00199     ToHepMC.fill_next_event( event, hepmcevt );
00200 
00201     //hepmcevt->print();
00202 
00203     //call the Jetfinder
00204     vector<fastjet::PseudoJet> inclusive_jets = FindJet.GetJet(hepmcevt);
00205 
00206     //call analysis
00207     int ret_all = true;
00208     for (std::vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00209       (*i)->SetJet(&inclusive_jets);
00210       int ret = (*i)->Process(hepmcevt);
00211       if (ret == false) ret_all = false;
00212     }
00213     
00214     if (ret_all==false) {
00215       std::cout << "Processing event number " << iEvent << std::endl;    
00216       std::cout << "throw FAILURE"<<std::endl;
00217       //std::cout<<std::endl;
00218       //std::cout<<"HepMC Output"<<std::endl;
00219       //hepmcevt->print();
00220       std::cout<<std::endl;
00221     }
00222 
00223     //delete all the jet objects to be free for the next event
00224     FindJet.ClearEvent(hepmcevt);
00225 
00226     // clear memory from this event
00227     delete hepmcevt;
00228 
00229     // End of event loop.
00230   }
00231 
00232   // Final statistics.
00233   pythia.statistics();
00234   //  pythia.particleData.listAll();
00235   pythia.settings.writeFile("allSettings.cmnd",true);
00236 
00237   TFile* f = new TFile(currentconfig->OutputFileName.c_str(),"RECREATE");
00238   for (std::vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00239     (*i)->Finalize(f);
00240   }
00241 
00242   // clean up analysis modules
00243   for (std::vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00244     delete (*i);
00245   }
00246   analysis.resize(0);
00247 
00248   // clean up config object
00249   delete currentconfig;
00250 
00251   // Tidy up
00252   std::cout<<"pythia8: program ends"<<std::endl;
00253   f->Close();
00254 
00255   std::cout<<"Run successfully!"<<std::endl;
00256   return 0;
00257 }
00258 

Generated on Thu Jul 23 14:57:35 2009 for HepMCAnalysis by  doxygen 1.3.9.1