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 // include our own classes
00036 #include "../../include/Configuration.h"
00037 #include "../../include/JetFinder.h"
00038 #include "../../include/ttbarAnalysis.h"
00039 #include "../../include/ZtautauAnalysis.h"
00040 #include "../../include/WtaunuAnalysis.h"
00041 #include "../../include/bbbarAnalysis.h"
00042 #include "../../include/JetAnalysis.h"
00043 #include "../../include/WplusJetAnalysis.h"
00044 #include "../../include/ZAnalysis.h"
00045 #include "../../include/UEAnalysis.h"
00046 #include "../../include/EtMissAnalysis.h"
00047 #include "../../include/ElasScatAnalysis.h"
00048 #include "../../include/UserAnalysis.h"
00049 #include "readherwigConfigFile.h"
00050 
00051 using namespace std;
00052 
00053 // a dummy routine called on the termination of the run
00054 extern "C" void hwaend_ (void); 
00055 extern "C" {
00056   int hwgethepevtsize_(void);
00057   void hwsetmodbos_(int& i, int& ivalue);
00058   double hwgetcs(void);
00059   double hwgetcserr(void);
00060 }
00061 
00062 // ---------------------------------------------------------------------- 
00063 int main(int argc, const char* argv[]) 
00064 {
00065   if ( argc <= 1 ) {
00066     cout << "Usage: " << argv[0] << " <Configuration File>" << endl;
00067     return 0;
00068   }
00069 
00070   Configuration* currentconfig = new Configuration();
00071   if ( currentconfig->read( argv[ 1 ] ) ) {
00072     cout << " ... skip !" << 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,
00079     currentconfig->lepton_ptmin, currentconfig->DeltaR_lepton_track, currentconfig->jetalgorithm );
00080 
00081     // create analysis Objects and initialize them                                                                                          
00082   vector<baseAnalysis*> analysis;
00083 
00084   if (currentconfig->jet) {
00085     cout << "Adding module JetAnalysis" << endl;
00086     analysis.push_back(new JetAnalysis);
00087   }
00088   if (currentconfig->wplusjet) {
00089     cout << "Adding module WplusJetAnalysis" << endl;
00090     analysis.push_back(new WplusJetAnalysis);
00091   }
00092   if(currentconfig->z){
00093     cout << "Adding module ZAnalysis" << endl;
00094     analysis.push_back(new ZAnalysis);
00095   }
00096   if(currentconfig->ztautau){
00097     cout << "Adding module ZtautauAnalysis" << endl;
00098     analysis.push_back(new ZtautauAnalysis);
00099   }
00100   if(currentconfig->wtaunu){
00101     cout << "Adding module WtaunuAnalysis" << endl;
00102     analysis.push_back(new WtaunuAnalysis);
00103   }
00104   if(currentconfig->bbbar){
00105     cout << "Adding module bbbarAnalysis" << endl;
00106     analysis.push_back(new bbbarAnalysis);
00107   }
00108   if(currentconfig->ttbar){
00109     cout << "Adding module ttbarAnalysis" << endl;
00110     analysis.push_back(new ttbarAnalysis);
00111   }
00112   if(currentconfig->ue){
00113     cout << "Adding module UEAnalysis" << endl;
00114     analysis.push_back(new UEAnalysis);
00115   }  
00116   if(currentconfig->etmiss){
00117     cout << "Adding module EtMissAnalysis" << endl;
00118     analysis.push_back(new EtMissAnalysis);
00119   }
00120   if(currentconfig->elasScat){
00121     cout << "Adding module ElasScatAnalysis" << endl;
00122     analysis.push_back(new ElasScatAnalysis);
00123   }
00124   if(currentconfig->user){
00125     cout << "Adding module UserAnalysis" << endl;
00126     analysis.push_back(new UserAnalysis);
00127   }
00128 
00129   // init requested analysis modules and jet finder
00130   for (vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00131     (*i)->Init(currentconfig->max_eta,currentconfig->min_pt);
00132     (*i)->InitJetFinder( currentconfig->coneRadius, currentconfig->overlapThreshold, currentconfig->jet_ptmin,
00133       currentconfig->lepton_ptmin, currentconfig->DeltaR_lepton_track, currentconfig->jetalgorithm );
00134   }
00135 
00136 
00137   //
00138   //........................................HEPEVT
00139   // herwig-6510-2 uses HEPEVT with 10000 entries and 8-byte floating point
00140   //  numbers. We need to explicitly pass this information to the 
00141   //  HEPEVT_Wrapper.
00142   //
00143   HepMC::HEPEVT_Wrapper::set_max_number_entries(hwgethepevtsize_());
00144   HepMC::HEPEVT_Wrapper::set_sizeof_real(8);
00145 
00146   //random seed
00147   hwevnt.nrn[0] = currentconfig->rseed;
00148   
00149   // number of events
00150   hwproc.maxev = int(currentconfig->nevents); 
00151   
00152   // tell it what the beam particles are:
00153   for ( unsigned int i = 0; i < 8; ++i ) {
00154     hwbmch.part1[i] = (i < 1) ? 'P' : ' ';
00155     hwbmch.part2[i] = (i < 1) ? 'P' : ' ';
00156   }
00157 
00158   // INITIALISE OTHER COMMON BLOCKS
00159   hwigin();
00160   jimmin();
00161 
00162   cout << "Configuration Parameter List:" << endl;
00163   for (unsigned int files=0; files<(currentconfig->ConfigFileNames).size(); files++)
00164     readConfigFile((currentconfig->ConfigFileNames)[files]);
00165 
00166   // master switches for ISR
00167   // true switches ISR off!
00168   //  hwpram.nospac=int(currentconfig->ISR); //switch on/off ISR
00169     
00170   // number of events to print
00171   hwevnt.maxpr = 1; 
00172   // compute parameter-dependent constants
00173   hwuinc(); 
00174   // initialise elementary process
00175   hweini(); 
00176   // initialise jimmy event
00177   jminit();
00178   //........................................HepMC INITIALIZATIONS
00179   //
00180   // Instantiate an IO strategy for reading from HEPEVT.
00181   HepMC::IO_HERWIG hepevtio;
00182   //
00183   //........................................EVENT LOOP
00184   for ( int iEvent = 1; iEvent <= hwproc.maxev; iEvent++ ) {
00185     if ( iEvent%50==1 ) cout << "Processing Event Number " 
00186                                   << iEvent << endl;
00187 //     // initialise event
00188 //     hwuine();
00189 //     // generate hard subproces
00190 //     hwepro();
00191 //     // generate parton cascades
00192 //     hwbgen();
00193 //     // do heavy object decays
00194 //     hwdhob();
00195 //     // do cluster formation
00196 //     hwcfor();
00197 //     // do cluster decays
00198 //     hwcdec();
00199 //     // do unstable particle decays
00200 //     hwdhad();
00201 //     // do heavy flavour hadron decays
00202 //     hwdhvy();
00203 //     // add soft underlying event if needed
00204 //     hwmevt();
00205 //     // finish event
00206 //     hwufne();
00207 
00208     // initialise event
00209     hwuine();
00210     // generate hard subproces
00211     hwepro();
00212     // generate parton cascades
00213     hwbgen();
00214 
00215     // Do Jimmy underlying event if required.
00216     int abort = 0;
00217     hwmsct(&abort);
00218     if (abort != 0) {
00219       cout << "Event aborted by hwmsct." << endl;
00220       hwufne();  // finish event
00221       continue;
00222     }
00223 
00224     //    if (abort == 0) {
00225       hwdhob();  // Do heavy quark decays
00226       hwcfor();  // Do cluster formation
00227       hwcdec();  // Do cluster decays
00228       hwdhad();  // Do unstable particle decays
00229       hwdhvy();  // Do heavy flavor decays
00230       hwmevt();  // Add soft underlying event
00231       hwufne();  // finish event
00232     //}
00233       if (hwevnt.ierror==-1 || hwevnt.ierror>99) {
00234         cout << "Event Error, Number: " << " Code: " << hwevnt.ierror << endl;
00235         continue;
00236       }
00237     
00238     // Print HEPEVT format event here 
00239     // HepMC::HEPEVT_Wrapper::print_hepevt();
00240 
00241     HepMC::GenEvent* evt = hepevtio.read_next_event();
00242     // add some information to the event
00243     evt->set_event_number(iEvent);
00244     evt->set_signal_process_id(20);
00245    
00246     // the status codes should not be changed, otherwise you change
00247     // the output of the MC generators (status code variabl) and this
00248     // should not be done
00249     //     //change the status code in HepMC format event.  
00250     //     for ( HepMC::GenEvent::particle_const_iterator p =
00251     //      evt->particles_begin(); p != evt->particles_end(); ++p ){
00252     //       if( abs((*p)->status())>1 )
00253     //  (*p)->set_status(2);
00254     //     }
00255        
00256     //call the Jetfinder
00257     vector<fastjet::PseudoJet> inclusive_jets = FindJet.GetJet(evt);
00258 
00259     //call analysis
00260     int ret_all = true;
00261     for (vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00262       (*i)->SetJet(&inclusive_jets);
00263       int ret = (*i)->Process(evt);
00264       if (ret == false) ret_all = false;
00265     }
00266 
00267     if (ret_all==false) {
00268       cout << "Processing event number " << iEvent << endl;
00269       cout << "throw FAILURE"<<endl;
00270       //cout<<"pylist"<<endl;
00271       // call_pylist(2);
00272       cout<<endl;
00273       //cout<<"HepMC Output"<<endl;
00274       // evt->print();
00275       cout<<endl;
00276     }
00277 
00278 
00279     if (iEvent<=hwevnt.maxpr) {
00280       cout << "\n\n This is the FIXED version of HEPEVT as "
00281                 << "coded in IO_HERWIG " << endl;
00282       //    HepMC::HEPEVT_Wrapper::print_hepevt();
00283       //    evt->print();
00284     }
00285     
00286     //delete all the jet objects, missingEt etc. to be free for the next event
00287     FindJet.ClearEvent(evt);
00288       
00289     // we also need to delete the created event from memory
00290     delete evt;
00291 
00292   }
00293   //........................................TERMINATION
00294   hwefin();
00295 
00296  
00297   TFile* f = new TFile(currentconfig->OutputFileName.c_str(),"RECREATE");
00298   for (vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00299     (*i)->Finalize(f);
00300   }
00301 
00302   // clean up analysis modules
00303   for (vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00304     delete (*i);
00305   }
00306   analysis.resize(0);
00307 
00308   // clean up config object
00309   delete currentconfig;
00310 
00311   // Tidy up
00312   cout<<"Herwig:  program ends"<<endl;
00313   f->Close();
00314  
00315   cout<<"Run successfully!"<<endl;
00316   return 0;
00317 }
00318 
00319 // a dummy user-supplied subroutine called when the run terminates:
00320 void hwaend_ (void) { return; }

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