alpgen_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 #include <stdlib.h>       // this is needed to generate some random numbers
00016 #include <time.h>
00017 #include <stdio.h>
00018 
00019 #include <iostream>
00020 #include <vector>
00021 #include <fstream>
00022 #include <sstream>
00023 
00024 #include "HepMC/PythiaWrapper.h"
00025 #include "HepMC/IO_HEPEVT.h"
00026 // #include "HepMC/IO_Ascii.h"
00027 #include "HepMC/IO_BaseClass.h"
00028 #include "HepMC/GenEvent.h"
00029 #include "HepMC/SimpleVector.h"
00030 #include "MyPythia6Wrapper.h"
00031 
00032 #include "TH1.h"
00033 #include "TFile.h"
00034 #include "TMath.h"
00035 #include <TCanvas.h>
00036 
00037 #include "TF1.h"
00038 #include <TH2.h>
00039 #include <TStyle.h>
00040 #include "TLegend.h"
00041 #include <TTree.h>
00042 #include <TString.h>
00043 
00044 // include our own classes
00045 #include "../../include/Configuration.h"
00046 #include "../../include/JetFinder.h"
00047 #include "../../include/ttbarAnalysis.h"
00048 #include "../../include/ZtautauAnalysis.h"
00049 #include "../../include/WtaunuAnalysis.h"
00050 #include "../../include/bbbarAnalysis.h"
00051 #include "../../include/JetAnalysis.h"
00052 #include "../../include/WplusJetAnalysis.h"
00053 #include "../../include/ZAnalysis.h"
00054 #include "../../include/UEAnalysis.h"
00055 #include "../../include/EtMissAnalysis.h"
00056 #include "../../include/ElasScatAnalysis.h"
00057 #include "../../include/UserAnalysis.h"
00058 
00059 #include "readpythiaConfigFile.h"
00060 #include "alpgen_spec.h"
00061 #include "test_hepmc.h"
00062 
00063 using namespace std;
00064 
00065 extern "C" {
00066 
00067   void pyupev_();
00068 };
00069 
00070 // ---------------------------------------------------------------------- 
00071 int main( int argc, const char *argv[] ) 
00072 {
00073   if ( argc <= 1 ) {
00074     cout << "Usage: " << argv[ 0 ] << " <Configuration File>" << endl;
00075     return 0;
00076   }
00077  
00078     // read configuration 
00079   Configuration *currentconfig = new Configuration;
00080   if ( currentconfig->read( argv[ 1 ] ) ) {
00081     cout << " ... skip !" << endl;
00082     return 0;
00083   }
00084   
00085     // initialize Jet Finder
00086   JetFinder FindJet;
00087   FindJet.Init( currentconfig->max_eta, currentconfig->min_pt );
00088   FindJet.InitJetFinder( currentconfig->coneRadius, currentconfig->overlapThreshold,
00089       currentconfig->jet_ptmin, currentconfig->lepton_ptmin, currentconfig->DeltaR_lepton_track, currentconfig->jetalgorithm );
00090 
00091     // create analysis objects and initialize them 
00092   vector< baseAnalysis* > analysis;
00093 
00094   if ( currentconfig->jet ) {
00095     cout << "Adding module JetAnalysis" << endl;
00096     analysis.push_back( new JetAnalysis );
00097   }
00098   if ( currentconfig->wplusjet ) {
00099     cout << "Adding module WplusJetAnalysis" << endl;
00100     analysis.push_back( new WplusJetAnalysis );
00101   }
00102   if ( currentconfig->z ) {
00103     cout << "Adding module ZAnalysis" << endl;
00104     analysis.push_back( new ZAnalysis );
00105   }
00106   if ( currentconfig->ztautau ) {
00107     cout << "Adding module ZtautauAnalysis" << endl;
00108     analysis.push_back( new ZtautauAnalysis );
00109   }
00110   if ( currentconfig->wtaunu ) {
00111     cout << "Adding module WtaunuAnalysis" << endl;
00112     analysis.push_back( new WtaunuAnalysis );
00113   }
00114   if ( currentconfig->bbbar ) {
00115     cout << "Adding module bbbarAnalysis" << endl;
00116     analysis.push_back( new bbbarAnalysis );
00117   }
00118   if ( currentconfig->ttbar ) {
00119     cout << "Adding module ttbarAnalysis" << endl;
00120     analysis.push_back( new ttbarAnalysis );
00121   }
00122   if ( currentconfig->ue ) {
00123     cout << "Adding module UEAnalysis" << endl;
00124     analysis.push_back( new UEAnalysis );
00125   }  
00126   if( currentconfig->etmiss ) {
00127     cout << "Adding module EtMissAnalysis" << endl;
00128     analysis.push_back( new EtMissAnalysis );
00129   }
00130   if ( currentconfig->elasScat ) {
00131     cout << "Adding module ElasScatAnalysis" << endl;
00132     analysis.push_back( new ElasScatAnalysis );
00133   }
00134   if ( currentconfig->user ) {
00135     cout << "Adding module UserAnalysis" << endl;
00136     analysis.push_back( new UserAnalysis );
00137   }
00138 
00139     // init requested analysis modules 
00140   for ( vector< baseAnalysis* >::const_iterator i( analysis.begin() ); i != analysis.end(); ++i ) {
00141     (*i)->Init( currentconfig->max_eta, currentconfig->min_pt );
00142     (*i)->InitJetFinder( currentconfig->coneRadius, currentconfig->overlapThreshold, currentconfig->jet_ptmin,
00143         currentconfig->lepton_ptmin, currentconfig->DeltaR_lepton_track, currentconfig->jetalgorithm );
00144   }
00145 
00146     //........................................HEPEVT
00147     //  Standard Pythia >6.1 uses HEPEVT with NMXHEP=4000 entries and 8-byte
00148     //  floating point numbers. We need to explicitly pass this information
00149     //  to the HEPEVT_Wrapper.
00150   pyjets.n = 0; // ensure dummyness of the next call
00151   call_pyhepc( 1 ); // mstu(8) is set to NMXHEP in this dummy call (version >=6.404)
00152   //HepMC::HEPEVT_Wrapper::set_max_number_entries(pydat1.mstu[8-1]);
00153   //HepMC::HEPEVT_Wrapper::set_max_number_entries( 4000 );
00154   HepMC::HEPEVT_Wrapper::set_max_number_entries( 10000 );
00155   HepMC::HEPEVT_Wrapper::set_sizeof_real( 8 );
00156   
00157   //........................................PYTHIA INITIALIZATIONS
00158   // (Some platforms may require the initialization of pythia PYDATA block
00159   //  data as external - if you get pythia initialization errors try
00160   //  commenting in/out the below call to initpydata() )
00161   // initpydata();
00162   //
00163   
00164   // set random number seed (mandatory!) ... this may be overwritten by function readConfigFile
00165   pydatr.mrpy[ 1 - 1 ] = currentconfig->rseed;
00166   
00167   //int tunemode=300;
00168   //pytune( &tunemode );
00169   
00170   cout << "Configuration Parameter List:" << endl;
00171   
00172   for ( size_t iFile = 0; iFile < currentconfig->ConfigFileNames.size(); ++iFile ) {
00173     readConfigFile( currentconfig->ConfigFileNames.at( iFile ) );
00174   }
00175 
00176   // these three lines are set in the config file Pythia6_Common.config
00177   //   // master switches for FSR, ISR and MI
00178   //   pypars.mstp[61-1]=int(currentconfig->ISR); 
00179   //   pypars.mstp[71-1]=int(currentconfig->FSR); 
00180   //   pypars.mstp[81-1]=int(currentconfig->MI); 
00181 
00182     // initialize Pythia
00183   //call_pyinit( "CMS", "p", "p", 14000. );
00184   call_pyinit( "USER", "", "", 0. );
00185   //upinit();       // user process
00186    
00187   evstat_.nvpass = 0; 
00188   evstat_.nvcall = 0; 
00189   evstat_.nvfail = 0;
00190   
00191     //........................................HepMC INITIALIZATIONS
00192     //
00193     // Instantiate an IO strategy for reading from HEPEVT.
00194   HepMC::IO_HEPEVT hepevtio;
00195   HepMC::GenEvent *evt = 0;
00196   
00197   //
00198   // Instantiate an IO strategy to write the data to file - it uses the 
00199   //  same ParticleDataTable
00200   //HepMC::IO_Ascii ascii_io("test_pythia_hepmc.dat",std::ios::out);
00201 
00202     // a bit of setup
00203   //int pyhepcMode = 1;         // PYJETS -> PYHEPC transformation argument
00204   int pylistMode = 1;         // pylist call argument, see Pythia manual for available options
00205   int pystatMode = 1;         // pystat call argument, see Pythia manual for available options
00206     
00207   bool doFillEvWeight = true;
00208   bool doFillEvXsec   = true;
00209 
00210     // initialize user process common block
00211   pyupev_();
00212  
00213     //.......EVENT LOOP:
00214   int nShow = 50;
00215   int nShowPace = max( 1, static_cast< int >( currentconfig->nevents ) / nShow );
00216   
00217   HepMC::IO_GenEvent ascii_io( "myexample_alpgen.dat", std::ios::out );
00218 
00219   for ( size_t iEvent = 1; iEvent <= currentconfig->nevents; ++iEvent ) {
00220     if ( iEvent % nShowPace == 0) {
00221       cout << "pythia6:  Now begin event " << iEvent << endl;
00222     }
00223 
00224       // generate next event with Pythia
00225     call_pyevnt();      
00226     //upevnt();
00227     call_pylist( pylistMode );
00228     
00229       // pythia pyhepc routine converts common PYJETS in common HEPEVT
00230       // get the HEPEVT record of the event
00231     call_pyhepc( 1 ); //pyhepcMode );
00232     hepevtio.print();
00233    
00234       //ALSFIN: NUP=0 in the event means the end of file
00235     if ( hepeup_.NUP == 0 ) {
00236       cout << "end of ER after " << iEvent - 1 << " events." << endl;
00237       break;
00238     }
00239             
00240       // get the HEPMC record of the event
00241     evt = hepevtio.read_next_event();
00242     evt->print();
00243 
00244     if ( !( evt->is_valid() ) ) {
00245       cerr << "got invalid HepMC event after " << iEvent << " events." << endl;
00246       cerr << "exit the generation loop now. " << endl;
00247       break;
00248     } 
00249     
00250     if ( !testHepMC( evt ) ) {
00251       cerr << "ERROR: Invalid HepMC event! Event #: " << iEvent << endl; 
00252       cerr << ">> Exit the generation loop now." << endl;
00253       //break;      !!!
00254     }
00255 
00256 
00257     //hepevtio.fill_next_event();
00258     
00259       // add some information to the event ???????????????
00260     evt->set_event_number( iEvent );
00261     evt->set_signal_process_id( 20 );
00262 
00263     ascii_io << evt;
00264 
00265       // fill alpgen-specific event weight info
00266     if ( doFillEvWeight ) {
00267       fill_eweight( evt );
00268     }
00269     
00270       // fill x-section info
00271     if ( doFillEvXsec ) {
00272       fill_exsec( evt );
00273     }
00274 
00275 
00276       // some printout for the first event
00277 /*    if ( iEvent == 1 ) {
00278       cout << "----------------------------------------------------------------------" << endl;
00279       cout << " Documentation printout from alpgen_pythia6.cc: " << endl;
00280       cout << " Listing the Pythia event # " << iEvent << " in Pythia internal PYJETS format: " << endl;
00281       call_pylist( pylistMode );
00282         //std::cout<<" Listing the Pythia event # "<<n_events<<" in HepMC format:   "<<std::endl;
00283       //evt->print();
00284       cout << "----------------------------------------------------------------------" << endl;
00285     }*/
00286                 
00287     
00288     // write the event out to the ascii file
00289     //    ascii_io << evt;
00290     
00291       // call the Jetfinder
00292     vector< fastjet::PseudoJet > inclusiveJets = FindJet.GetJet( evt );
00293 
00294       // call analyses
00295     int retAll = true;
00296     for ( vector< baseAnalysis* >::const_iterator i( analysis.begin() ); i != analysis.end(); ++i ) {
00297       (*i)->SetJet( &inclusiveJets );
00298       if ( !( (*i)->Process( evt ) ) ) {
00299         retAll = false;
00300       }
00301     }
00302 
00303     if ( !retAll ) {
00304       cerr << "Processing event number " << iEvent << endl;    
00305       cerr << "throw FAILURE" << endl;
00306       cout << ">>> pylist output: " << endl;
00307       call_pylist( 2 );
00308       //cout << ">>> HepMC Output" << endl;
00309       //evt->print();
00310       cerr << endl;
00311     }
00312 
00313       //delete all the jet objects, missingEt etc. to be free for the next event
00314     FindJet.ClearEvent( evt );
00315     
00316     //::GenEvent *evt = hepevtio.read_next_event();
00317       // we also need to delete the created event from memory
00318     delete evt;
00319     evt = 0;
00320   } // end of event loop
00321   
00322     // write out some information from Pythia to the screen
00323   call_pystat( pystatMode );    
00324   
00325   TFile *f = new TFile( currentconfig->OutputFileName.c_str(), "RECREATE" );
00326   for ( vector< baseAnalysis* >::const_iterator i( analysis.begin() ); i != analysis.end(); ++i ) {
00327     (*i)->Finalize( f );
00328   }
00329 
00330     // clean up analysis modules
00331   for ( vector< baseAnalysis* >::iterator i( analysis.begin() ); i != analysis.end(); ++i ) {
00332     if ( *i ) {
00333       delete *i;
00334       *i = 0;
00335     }
00336   }
00337   analysis.clear();
00338 
00339     // clean up config object
00340   delete currentconfig;
00341   currentconfig = 0;
00342   
00343   cout << "alpgen_pythia6: program ends" << endl;
00344   f->Close();
00345 
00346   cout << "Successfull run!" << endl;
00347   return 0;
00348 }
00349 

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