pythia6.cc

Go to the documentation of this file.
00001 /***********************************************************************
00002 *                                                                      *
00003 * File: pythia6_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 // this is needed to generate some random numbers
00017 #include <stdlib.h>
00018 #include <time.h>
00019 
00020 #include <stdio.h>
00021 #include <iostream>
00022 #include <fstream>
00023 #include <sstream>
00024 #include "HepMC/PythiaWrapper.h"
00025 #include "HepMC/IO_HEPEVT.h"
00026 #include "HepMC/IO_Ascii.h"
00027 #include "HepMC/GenEvent.h"
00028 #include "HepMC/SimpleVector.h"
00029 #include "MyPythia6Wrapper.h"
00030 
00031 #include "TH1.h"
00032 #include "TFile.h"
00033 #include "TMath.h"
00034 #include <TCanvas.h>
00035 
00036 #include "TF1.h"
00037 #include <TH2.h>
00038 #include <TStyle.h>
00039 #include "TLegend.h"
00040 #include <TTree.h>
00041 #include <TString.h>
00042 
00043 using namespace std;
00044 
00045 // include our own classes
00046 #include "../../include/Configuration.h"
00047 #include "../../include/JetFinder.h"
00048 #include "../../include/TopAnalysis.h"
00049 #include "../../include/TauAnalysis.h"
00050 #include "../../include/DiJetAnalysis.h"
00051 #include "../../include/WplusJetAnalysis.h"
00052 #include "../../include/ZAnalysis.h"
00053 #include "../../include/UEAnalysis.h"
00054 #include "../../include/EtMissAnalysis.h"
00055 #include "../../include/ElasScatAnalysis.h"
00056 #include "../../include/UserAnalysis.h"
00057 #include "readpythiaConfigFile.h"
00058 
00059 /**************************************************************************/
00060 
00061 int main(int argc, const char* argv[]) {
00062     
00063   if(argc <= 1 ) {
00064     std::cout << "Usage: " << argv[0] << " <Configuration File>" << std::endl;
00065     return 0;
00066   }
00067   
00068   
00069   Configuration* currentconfig = new Configuration();
00070   if(currentconfig->read(argv[1]))
00071     {
00072       std::cout << " ... skip !" << std::endl;
00073       return 0;
00074     }
00075   
00076   JetFinder FindJet;
00077   FindJet.Init(currentconfig->max_eta,currentconfig->min_pt);
00078   FindJet.InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin,currentconfig->lepton_ptmin,currentconfig->DeltaR_lepton_track);
00079 
00080 
00081   std::vector<baseAnalysis*> analysis;
00082 
00083   // create analysis Objects and initialize them                                                                                          
00084   if (currentconfig->dijet) {
00085     std::cout << "Adding module DiJetAnalysis" << std::endl;
00086     analysis.push_back(new DiJetAnalysis);
00087   }
00088   if (currentconfig->wplusjet) {
00089     std::cout << "Adding module WplusJetAnalysis" << std::endl;
00090     analysis.push_back(new WplusJetAnalysis);
00091   }
00092   if(currentconfig->z){
00093     std::cout << "Adding module ZAnalysis" << std::endl;
00094     analysis.push_back(new ZAnalysis);
00095   }
00096   if(currentconfig->tau){
00097     std::cout << "Adding module TauAnalysis" << std::endl;
00098     analysis.push_back(new TauAnalysis);
00099   }
00100   if(currentconfig->top){
00101     std::cout << "Adding module TopAnalysis" << std::endl;
00102     analysis.push_back(new TopAnalysis);
00103   }
00104   if(currentconfig->ue){
00105     std::cout << "Adding module UEAnalysis" << std::endl;
00106     analysis.push_back(new UEAnalysis);
00107   }  
00108   if(currentconfig->etmiss){
00109     std::cout << "Adding module EtMissAnalysis" << std::endl;
00110     analysis.push_back(new EtMissAnalysis);
00111   }
00112   if(currentconfig->elasScat){
00113     std::cout << "Adding module ElasScatAnalysis" << std::endl;
00114     analysis.push_back(new ElasScatAnalysis);
00115   }
00116   if(currentconfig->user){
00117     std::cout << "Adding module UserAnalysis" << std::endl;
00118     analysis.push_back(new UserAnalysis);
00119   }
00120   
00121 
00122   // init requested analysis modules and jet finder
00123   for (std::vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00124     (*i)->Init(currentconfig->max_eta,currentconfig->min_pt);
00125     (*i)->InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin,currentconfig->lepton_ptmin,currentconfig->DeltaR_lepton_track);
00126   }
00127 
00128   //........................................HEPEVT
00129   //  Standard Pythia >6.1 uses HEPEVT with NMXHEP=4000 entries and 8-byte
00130   //  floating point numbers. We need to explicitly pass this information
00131   //  to the HEPEVT_Wrapper.
00132   pyjets.n=0; // ensure dummyness of the next call
00133   call_pyhepc(1); // mstu(8) is set to NMXHEP in this dummy call (version >=6.404)
00134   //HepMC::HEPEVT_Wrapper::set_max_number_entries(pydat1.mstu[8-1]);
00135   HepMC::HEPEVT_Wrapper::set_max_number_entries(10000);
00136   HepMC::HEPEVT_Wrapper::set_sizeof_real(8);
00137   
00138   //
00139   //........................................PYTHIA INITIALIZATIONS
00140   // (Some platforms may require the initialization of pythia PYDATA block
00141   //  data as external - if you get pythia initialization errors try
00142   //  commenting in/out the below call to initpydata() )
00143   // initpydata();
00144   //
00145   
00146   // set random number seed (mandatory!) ... this may be overwritten by function readConfigFile
00147   pydatr.mrpy[1-1] = currentconfig->rseed ;
00148   
00149   //int tunemode=300;
00150   //pytune( &tunemode );
00151   
00152   std::cout << "Configuration Parameter List:" << std::endl;
00153   
00154   for (unsigned int files=0; files<(currentconfig->ConfigFileNames).size(); files++)
00155     readConfigFile((currentconfig->ConfigFileNames)[files]);
00156 
00157   // these three lines are set in the config file Pythia6_Common.config
00158   //   // master switches for FSR, ISR and MI
00159   //   pypars.mstp[61-1]=int(currentconfig->ISR); 
00160   //   pypars.mstp[71-1]=int(currentconfig->FSR); 
00161   //   pypars.mstp[81-1]=int(currentconfig->MI); 
00162 
00163   // Call pythia initialization
00164   call_pyinit("CMS", "p", "p", 14000.);
00165   
00166   //........................................HepMC INITIALIZATIONS
00167   //
00168   // Instantiate an IO strategy for reading from HEPEVT.
00169   HepMC::IO_HEPEVT hepevtio;
00170   //
00171   // Instantiate an IO strategy to write the data to file - it uses the 
00172   //  same ParticleDataTable
00173   //HepMC::IO_Ascii ascii_io("test_pythia_hepmc.dat",std::ios::out);
00174   
00175   //.......EVENT LOOP:
00176   
00177   int nShow = 50;
00178   int nShowPace = max(1,int(currentconfig->nevents)/nShow);
00179   
00180   for (unsigned int iEvent = 1 ; iEvent <= currentconfig->nevents; iEvent++) {
00181     
00182     // Begin event loop. 
00183     if (iEvent%nShowPace == 0) cout << "pythia6:  Now begin event "
00184                                     << iEvent << endl;
00185     
00186     call_pyevnt();      // generate one event with Pythia
00187     // pythia pyhepc routine converts common PYJETS in common HEPEVT
00188     call_pyhepc(1);
00189     HepMC::GenEvent* evt = hepevtio.read_next_event();
00190     // add some information to the event
00191     evt->set_event_number(iEvent);
00192     evt->set_signal_process_id(20);
00193     // write the event out to the ascii file
00194     //    ascii_io << evt;
00195     
00196     //call the Jetfinder
00197     vector<fastjet::PseudoJet> inclusive_jets = FindJet.GetJet(evt);
00198 
00199     //call analysis
00200     int ret_all = true;
00201     for (std::vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00202       (*i)->SetJet(&inclusive_jets);
00203       int ret = (*i)->Process(evt);
00204       if (ret == false) ret_all = false;
00205     }
00206 
00207     if (ret_all==false) {
00208       std::cout << "Processing event number " << iEvent << std::endl;    
00209       std::cout << "throw FAILURE"<<std::endl;
00210       //std::cout<<"pylist"<<std::endl;
00211       //call_pylist(2);
00212       //std::cout<<std::endl;
00213       //std::cout<<"HepMC Output"<<std::endl;
00214       //evt->print();
00215       std::cout<<std::endl;
00216     }
00217 
00218     //delete all the jet objects, missingEt etc. to be free for the next event
00219     FindJet.ClearEvent(evt);
00220     
00221     // we also need to delete the created event from memory
00222     delete evt;
00223   } // end of event loop
00224   
00225   
00226   // write out some information from Pythia to the screen
00227   call_pystat(1);    
00228   
00229   TFile* f = new TFile(currentconfig->OutputFileName.c_str(),"RECREATE");
00230   for (std::vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00231     (*i)->Finalize(f);
00232   }
00233 
00234   // clean up analysis modules
00235   for (std::vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00236     delete (*i);
00237   }
00238   analysis.resize(0);
00239 
00240   // clean up config object
00241   delete currentconfig;
00242   
00243   std::cout<<"pythia6:  program ends"<<std::endl;
00244   f->Close();
00245 
00246   std::cout<<"Run successfully!"<<std::endl;
00247   return 0;
00248   
00249 }
00250 

Generated on Mon Jan 4 15:22:34 2010 for HepMCAnalysis by  doxygen 1.4.7