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 // example of generating events with Herwig using HepMC/HerwigWrapper.h 
00002 // Events are read into the HepMC event record from the FORTRAN HEPEVT 
00003 // common block using the IO_HERWIG strategy.
00004 
00005 #include <stdlib.h>
00006 #include <time.h>
00007 
00008 #include <stdio.h>
00009 #include <iostream>
00010 #include <fstream>
00011 #include <sstream>
00012 
00013 #include "MyHerwigWrapper.h"
00014 #include "HepMC/IO_HERWIG.h"
00015 #include "HepMC/IO_Ascii.h"     
00016 #include "HepMC/GenEvent.h"
00017 #include "HepMC/HEPEVT_Wrapper.h"
00018 #include "HepMC/SimpleVector.h"
00019 
00020 #include "TH1.h"
00021 #include "TFile.h"
00022 #include "TMath.h"
00023 #include <TCanvas.h>
00024 
00025 #include "TF1.h"
00026 #include <TH2.h>
00027 #include <TStyle.h>
00028 #include "TLegend.h"
00029 #include <TTree.h>
00030 #include <TString.h>
00031 
00032 using namespace std;
00033 
00034 // include our own classes
00035 #include "../../include/TopAnalysis.h"
00036 #include "../../include/TauAnalysis.h"
00037 #include "../../include/DiJetAnalysis.h"
00038 #include "../../include/WplusJetAnalysis.h"
00039 #include "../../include/ZAnalysis.h"
00040 #include "../../include/UEAnalysis.h"
00041 #include "readherwigConfigFile.h"
00042 #include "../../include/Configuration.h"
00043 
00044 // a dummy routine called on the termination of the run
00045 extern "C" void hwaend_ (void); 
00046 extern "C" {
00047   int hwgethepevtsize_(void);
00048   void hwsetmodbos_(int& i, int& ivalue);
00049   double hwgetcs(void);
00050   double hwgetcserr(void);
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   DiJetAnalysis dijet;
00070   WplusJetAnalysis wplusjet;
00071   ZAnalysis z0;
00072   TauAnalysis tau;
00073   TopAnalysis top;
00074   UEAnalysis ue;
00075 
00076   // create analysis Objects and initialize them
00077   if(currentconfig->dijet){
00078     dijet.Init(currentconfig->max_eta,currentconfig->min_pt);
00079     dijet.InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin);
00080   }
00081 
00082   if(currentconfig->wplusjet){
00083     wplusjet.Init(currentconfig->max_eta,currentconfig->min_pt);
00084     wplusjet.InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin);
00085   }
00086 
00087   if(currentconfig->z){
00088     z0.Init(currentconfig->max_eta,currentconfig->min_pt);
00089     z0.InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin);
00090   }
00091   if(currentconfig->tau){
00092     tau.Init(currentconfig->max_eta,currentconfig->min_pt);
00093     tau.InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin);
00094   }
00095   if(currentconfig->top){
00096     top.Init(currentconfig->max_eta,currentconfig->min_pt);
00097     top.InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin);
00098   }
00099   if(currentconfig->ue){
00100     ue.Init(currentconfig->max_eta,currentconfig->min_pt);
00101     ue.InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin);
00102   }
00103 
00104     //
00105     //........................................HEPEVT
00106     // herwig-6510-2 uses HEPEVT with 10000 entries and 8-byte floating point
00107     //  numbers. We need to explicitly pass this information to the 
00108     //  HEPEVT_Wrapper.
00109     //
00110     HepMC::HEPEVT_Wrapper::set_max_number_entries(hwgethepevtsize_());
00111     HepMC::HEPEVT_Wrapper::set_sizeof_real(8);
00112 
00113     //random seed
00114      hwevnt.nrn[0]= currentconfig->rseed;
00115 
00116     // number of events
00117     hwproc.maxev = int(currentconfig->nevents); 
00118 
00119     // tell it what the beam particles are:
00120     for ( unsigned int i = 0; i < 8; ++i ) {
00121         hwbmch.part1[i] = (i < 1) ? 'P' : ' ';
00122         hwbmch.part2[i] = (i < 1) ? 'P' : ' ';
00123     }
00124 
00125     std::cout << "Configuration Parameter List:" << std::endl;
00126     for (unsigned int files=0; files<(currentconfig->ConfigFileNames).size(); files++)
00127       readConfigFile((currentconfig->ConfigFileNames)[files]);
00128 
00129     // master switches for ISR 
00130     hwpram.nospac=int(currentconfig->ISR); //switch on/off ISR
00131 
00132    // INITIALISE OTHER COMMON BLOCKS
00133     hwigin();
00134    // number of events to print
00135     hwevnt.maxpr = 1; 
00136    // compute parameter-dependent constants
00137     hwuinc(); 
00138    // initialise elementary process
00139     hweini(); 
00140 
00141     //........................................HepMC INITIALIZATIONS
00142     //
00143     // Instantiate an IO strategy for reading from HEPEVT.
00144     HepMC::IO_HERWIG hepevtio;
00145     //
00146     //........................................EVENT LOOP
00147     for ( int i = 1; i <= hwproc.maxev; i++ ) {
00148         if ( i%50==1 ) std::cout << "Processing Event Number " 
00149                                  << i << std::endl;
00150         // initialise event
00151         hwuine();
00152         // generate hard subproces
00153         hwepro();
00154         // generate parton cascades
00155         hwbgen();
00156         // do heavy object decays
00157         hwdhob();
00158         // do cluster formation
00159         hwcfor();
00160         // do cluster decays
00161         hwcdec();
00162         // do unstable particle decays
00163         hwdhad();
00164         // do heavy flavour hadron decays
00165         hwdhvy();
00166         // add soft underlying event if needed
00167         hwmevt();
00168         // finish event
00169         hwufne();
00170 
00171         HepMC::GenEvent* evt = hepevtio.read_next_event();
00172         // add some information to the event
00173         evt->set_event_number(i);
00174         evt->set_signal_process_id(20);
00175 
00176     int ret_dijet = SUCCESS;
00177     int ret_wplusjet = SUCCESS;
00178     int ret_z0 = SUCCESS;
00179     int ret_tau = SUCCESS;
00180     int ret_top = SUCCESS;
00181     int ret_ue = SUCCESS;
00182 
00183     //call analysis
00184     if(currentconfig->dijet)       ret_dijet = dijet.Process(evt);
00185     if(currentconfig->wplusjet)    ret_wplusjet = wplusjet.Process(evt);
00186     if(currentconfig->z)           ret_z0 = z0.Process(evt);
00187     if(currentconfig->tau)  ret_tau = tau.Process(evt);
00188     if(currentconfig->top)  ret_top = top.Process(evt);
00189     if(currentconfig->ue)   ret_ue = ue.Process(evt);
00190 
00191 
00192     if (ret_dijet==FAILURE || ret_wplusjet==FAILURE || ret_z0==FAILURE
00193         || ret_tau==FAILURE || ret_top==FAILURE || ret_ue==FAILURE)
00194       {
00195         std::cout << "Processing event number " << i << std::endl;
00196         std::cout << "throw FAILURE"<<std::endl;
00197         //std::cout<<"pylist"<<std::endl;
00198        // call_pylist(2);
00199         std::cout<<std::endl;
00200         //std::cout<<"HepMC Output"<<std::endl;
00201        // evt->print();
00202         std::cout<<std::endl;
00203       }
00204 
00205 
00206         if (i<=hwevnt.maxpr) {
00207             std::cout << "\n\n This is the FIXED version of HEPEVT as "
00208                       << "coded in IO_HERWIG " << std::endl;
00209         //    HepMC::HEPEVT_Wrapper::print_hepevt();
00210         //    evt->print();
00211         }
00212 
00213         //delete all the jet objects to be free for the next event
00214        //if(currentconfig->dijet)       dijet.DeleteJetObject(evt);
00215         //if(currentconfig->wplusjet)    wplusjet.DeleteJetObject(evt);
00216         //if(currentconfig->z)         z0.DeleteJetObject(evt);
00217         //if(currentconfig->tau)       tau.DeleteJetObject(evt);
00218         //if(currentconfig->top)       top.DeleteJetObject(evt);
00219         //if(currentconfig->ue)        ue.DeleteJetObject(evt);
00220 
00221         // we also need to delete the created event from memory
00222         delete evt;
00223     }
00224     //........................................TERMINATION
00225     hwefin();
00226 
00227   TFile* f = new TFile(currentconfig->OutputFileName.c_str(),"RECREATE");
00228   if(currentconfig->dijet)       dijet.Finalize(f);
00229   if(currentconfig->wplusjet)    wplusjet.Finalize(f);
00230   if(currentconfig->z)         z0.Finalize(f);
00231   if(currentconfig->tau)       tau.Finalize(f);
00232   if(currentconfig->top)       top.Finalize(f);
00233   if(currentconfig->ue)        ue.finalize(f);
00234 
00235   std::cout<<"Herwig:  program ends"<<std::endl;
00236   f->Close();
00237  
00238  // Done.
00239     return 0;
00240 }
00241 
00242 // a dummy user-supplied subroutine called when the run terminates:
00243 void hwaend_ (void) { return; }

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