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

herwig.cc

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////
00002 // Matt.Dobbs@Cern.CH, October 2002
00003 // example of generating events with Herwig using HepMC/HerwigWrapper.h
00004 // Events are read into the HepMC event record from the FORTRAN HEPEVT
00005 // common block using the IO_HERWIG strategy.
00006 //////////////////////////////////////////////////////////////////////////
00007 
00008 #include <stdlib.h>
00009 #include <time.h>
00010 
00011 #include <stdio.h>
00012 #include <iostream>
00013 #include <fstream>
00014 #include <sstream>
00015 
00016 #include "MyHerwigWrapper.h"
00017 #include "HepMC/IO_HERWIG.h"
00018 #include "HepMC/IO_Ascii.h"     
00019 #include "HepMC/GenEvent.h"
00020 #include "HepMC/HEPEVT_Wrapper.h"
00021 #include "HepMC/SimpleVector.h"
00022 
00023 #include "TH1.h"
00024 #include "TFile.h"
00025 #include "TMath.h"
00026 #include <TCanvas.h>
00027 
00028 #include "TF1.h"
00029 #include <TH2.h>
00030 #include <TStyle.h>
00031 #include "TLegend.h"
00032 #include <TTree.h>
00033 #include <TString.h>
00034 
00035 using namespace std;
00036 
00037 // include our own classes
00038 #include "../../include/Configuration.h"
00039 #include "../../include/JetFinder.h"
00040 #include "../../include/TopAnalysis.h"
00041 #include "../../include/TauAnalysis.h"
00042 #include "../../include/DiJetAnalysis.h"
00043 #include "../../include/WplusJetAnalysis.h"
00044 #include "../../include/ZAnalysis.h"
00045 #include "../../include/UEAnalysis.h"
00046 #include "../../include/EtMissAnalysis.h"
00047 #include "../../include/UserAnalysis.h"
00048 #include "readherwigConfigFile.h"
00049 
00050 // a dummy routine called on the termination of the run
00051 extern "C" void hwaend_ (void); 
00052 extern "C" {
00053   int hwgethepevtsize_(void);
00054   void hwsetmodbos_(int& i, int& ivalue);
00055   double hwgetcs(void);
00056   double hwgetcserr(void);
00057 }
00058 
00059 
00060 int main(int argc, const char* argv[]) {
00061 
00062   if(argc <= 1 ) {
00063     std::cout << "Usage: " << argv[0] << " <Configuration File>" << std::endl;
00064     return 0;
00065   }
00066 
00067 
00068   Configuration* currentconfig = new Configuration();
00069   if(currentconfig->read(argv[1]))
00070     {
00071       std::cout << " ... skip !" << std::endl;
00072       return 0;
00073     }
00074 
00075   JetFinder FindJet;
00076   FindJet.Init(currentconfig->max_eta,currentconfig->min_pt);
00077   FindJet.InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin,currentconfig->lepton_ptmin,currentconfig->DeltaR_lepton_track);
00078 
00079 
00080   std::vector<baseAnalysis*> analysis;
00081 
00082   // create analysis Objects and initialize them                                                                                          
00083   if (currentconfig->dijet) {
00084     std::cout << "Adding module DiJetAnalysis" << std::endl;
00085     analysis.push_back(new DiJetAnalysis);
00086   }
00087   if (currentconfig->wplusjet) {
00088     std::cout << "Adding module WplusJetAnalysis" << std::endl;
00089     analysis.push_back(new WplusJetAnalysis);
00090   }
00091   if(currentconfig->z){
00092     std::cout << "Adding module ZAnalysis" << std::endl;
00093     analysis.push_back(new ZAnalysis);
00094   }
00095   if(currentconfig->tau){
00096     std::cout << "Adding module TauAnalysis" << std::endl;
00097     analysis.push_back(new TauAnalysis);
00098   }
00099   if(currentconfig->top){
00100     std::cout << "Adding module TopAnalysis" << std::endl;
00101     analysis.push_back(new TopAnalysis);
00102   }
00103   if(currentconfig->ue){
00104     std::cout << "Adding module UEAnalysis" << std::endl;
00105     analysis.push_back(new UEAnalysis);
00106   }  
00107   if(currentconfig->etmiss){
00108     std::cout << "Adding module EtMissAnalysis" << std::endl;
00109     analysis.push_back(new EtMissAnalysis);
00110   }
00111   if(currentconfig->user){
00112     std::cout << "Adding module UserAnalysis" << std::endl;
00113     analysis.push_back(new UserAnalysis);
00114   }
00115   
00116 
00117   // init requested analysis modules and jet finder
00118   for (std::vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00119     (*i)->Init(currentconfig->max_eta,currentconfig->min_pt);
00120     (*i)->InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin,currentconfig->lepton_ptmin,currentconfig->DeltaR_lepton_track);
00121   }
00122 
00123 
00124   //
00125   //........................................HEPEVT
00126   // herwig-6510-2 uses HEPEVT with 10000 entries and 8-byte floating point
00127   //  numbers. We need to explicitly pass this information to the 
00128   //  HEPEVT_Wrapper.
00129   //
00130   HepMC::HEPEVT_Wrapper::set_max_number_entries(hwgethepevtsize_());
00131   HepMC::HEPEVT_Wrapper::set_sizeof_real(8);
00132 
00133   //random seed
00134   hwevnt.nrn[0]= currentconfig->rseed;
00135   
00136   // number of events
00137   hwproc.maxev = int(currentconfig->nevents); 
00138   
00139   // tell it what the beam particles are:
00140   for ( unsigned int i = 0; i < 8; ++i ) {
00141     hwbmch.part1[i] = (i < 1) ? 'P' : ' ';
00142     hwbmch.part2[i] = (i < 1) ? 'P' : ' ';
00143   }
00144 
00145   std::cout << "Configuration Parameter List:" << std::endl;
00146   for (unsigned int files=0; files<(currentconfig->ConfigFileNames).size(); files++)
00147     readConfigFile((currentconfig->ConfigFileNames)[files]);
00148 
00149   // master switches for ISR 
00150   hwpram.nospac=int(currentconfig->ISR); //switch on/off ISR
00151 
00152   // INITIALISE OTHER COMMON BLOCKS
00153   hwigin();
00154   // number of events to print
00155   hwevnt.maxpr = 1; 
00156   // compute parameter-dependent constants
00157   hwuinc(); 
00158   // initialise elementary process
00159   hweini(); 
00160 
00161   //........................................HepMC INITIALIZATIONS
00162   //
00163   // Instantiate an IO strategy for reading from HEPEVT.
00164   HepMC::IO_HERWIG hepevtio;
00165   //
00166   //........................................EVENT LOOP
00167   for ( int iEvent = 1; iEvent <= hwproc.maxev; iEvent++ ) {
00168     if ( iEvent%50==1 ) std::cout << "Processing Event Number " 
00169                                   << iEvent << std::endl;
00170     // initialise event
00171     hwuine();
00172     // generate hard subproces
00173     hwepro();
00174     // generate parton cascades
00175     hwbgen();
00176     // do heavy object decays
00177     hwdhob();
00178     // do cluster formation
00179     hwcfor();
00180     // do cluster decays
00181     hwcdec();
00182     // do unstable particle decays
00183     hwdhad();
00184     // do heavy flavour hadron decays
00185     hwdhvy();
00186     // add soft underlying event if needed
00187     hwmevt();
00188     // finish event
00189     hwufne();
00190         
00191     // Print HEPEVT format event here 
00192     // HepMC::HEPEVT_Wrapper::print_hepevt();
00193 
00194     HepMC::GenEvent* evt = hepevtio.read_next_event();
00195     // add some information to the event
00196     evt->set_event_number(iEvent);
00197     evt->set_signal_process_id(20);
00198    
00199     //change the status code in HepMC format event.  
00200     for ( HepMC::GenEvent::particle_const_iterator p =
00201             evt->particles_begin(); p != evt->particles_end(); ++p ){
00202       if( abs((*p)->status())>1 )
00203         (*p)->set_status(2);
00204     }
00205        
00206     //call the Jetfinder
00207     std::vector<fastjet::PseudoJet> inclusive_jets = FindJet.GetJet(evt);
00208 
00209     //call analysis
00210     int ret_all = true;
00211     for (std::vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00212       (*i)->SetJet(&inclusive_jets);
00213       int ret = (*i)->Process(evt);
00214       if (ret == false) ret_all = false;
00215     }
00216     
00217     if (ret_all==false) {
00218       std::cout << "Processing event number " << iEvent << std::endl;
00219       std::cout << "throw FAILURE"<<std::endl;
00220       //std::cout<<"pylist"<<std::endl;
00221       // call_pylist(2);
00222       std::cout<<std::endl;
00223       //std::cout<<"HepMC Output"<<std::endl;
00224       evt->print();
00225       std::cout<<std::endl;
00226     }
00227 
00228 
00229     if (iEvent<=hwevnt.maxpr) {
00230       std::cout << "\n\n This is the FIXED version of HEPEVT as "
00231                 << "coded in IO_HERWIG " << std::endl;
00232       //    HepMC::HEPEVT_Wrapper::print_hepevt();
00233       //    evt->print();
00234     }
00235     
00236     //delete all the jet objects, missingEt etc. to be free for the next event
00237     FindJet.ClearEvent(evt);
00238       
00239     // we also need to delete the created event from memory
00240     delete evt;
00241 
00242   }
00243   //........................................TERMINATION
00244   hwefin();
00245 
00246  
00247   TFile* f = new TFile(currentconfig->OutputFileName.c_str(),"RECREATE");
00248   for (std::vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00249     (*i)->Finalize(f);
00250   }
00251 
00252   // clean up analysis modules
00253   for (std::vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00254     delete (*i);
00255   }
00256   analysis.resize(0);
00257 
00258   // clean up config object
00259   delete currentconfig;
00260 
00261   // Tidy up
00262   std::cout<<"Herwig:  program ends"<<std::endl;
00263   f->Close();
00264  
00265   std::cout<<"Run successfully!"<<std::endl;
00266   return 0;
00267 }
00268 
00269 // a dummy user-supplied subroutine called when the run terminates:
00270 void hwaend_ (void) { return; }

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