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/ElasScatAnalysis.h"
00048 #include "../../include/UserAnalysis.h"
00049 #include "readherwigConfigFile.h"
00050 
00051 // a dummy routine called on the termination of the run
00052 extern "C" void hwaend_ (void); 
00053 extern "C" {
00054   int hwgethepevtsize_(void);
00055   void hwsetmodbos_(int& i, int& ivalue);
00056   double hwgetcs(void);
00057   double hwgetcserr(void);
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 
00129   //
00130   //........................................HEPEVT
00131   // herwig-6510-2 uses HEPEVT with 10000 entries and 8-byte floating point
00132   //  numbers. We need to explicitly pass this information to the 
00133   //  HEPEVT_Wrapper.
00134   //
00135   HepMC::HEPEVT_Wrapper::set_max_number_entries(hwgethepevtsize_());
00136   HepMC::HEPEVT_Wrapper::set_sizeof_real(8);
00137 
00138   //random seed
00139   hwevnt.nrn[0]= currentconfig->rseed;
00140   
00141   // number of events
00142   hwproc.maxev = int(currentconfig->nevents); 
00143   
00144   // tell it what the beam particles are:
00145   for ( unsigned int i = 0; i < 8; ++i ) {
00146     hwbmch.part1[i] = (i < 1) ? 'P' : ' ';
00147     hwbmch.part2[i] = (i < 1) ? 'P' : ' ';
00148   }
00149 
00150   std::cout << "Configuration Parameter List:" << std::endl;
00151   for (unsigned int files=0; files<(currentconfig->ConfigFileNames).size(); files++)
00152     readConfigFile((currentconfig->ConfigFileNames)[files]);
00153 
00154   // master switches for ISR 
00155   hwpram.nospac=int(currentconfig->ISR); //switch on/off ISR
00156 
00157   // INITIALISE OTHER COMMON BLOCKS
00158   hwigin();
00159   // number of events to print
00160   hwevnt.maxpr = 1; 
00161   // compute parameter-dependent constants
00162   hwuinc(); 
00163   // initialise elementary process
00164   hweini(); 
00165   // initialise jimmy event
00166   jminit();
00167   //........................................HepMC INITIALIZATIONS
00168   //
00169   // Instantiate an IO strategy for reading from HEPEVT.
00170   HepMC::IO_HERWIG hepevtio;
00171   //
00172   //........................................EVENT LOOP
00173   for ( int iEvent = 1; iEvent <= hwproc.maxev; iEvent++ ) {
00174     if ( iEvent%50==1 ) std::cout << "Processing Event Number " 
00175                                   << iEvent << std::endl;
00176 //     // initialise event
00177 //     hwuine();
00178 //     // generate hard subproces
00179 //     hwepro();
00180 //     // generate parton cascades
00181 //     hwbgen();
00182 //     // do heavy object decays
00183 //     hwdhob();
00184 //     // do cluster formation
00185 //     hwcfor();
00186 //     // do cluster decays
00187 //     hwcdec();
00188 //     // do unstable particle decays
00189 //     hwdhad();
00190 //     // do heavy flavour hadron decays
00191 //     hwdhvy();
00192 //     // add soft underlying event if needed
00193 //     hwmevt();
00194 //     // finish event
00195 //     hwufne();
00196 
00197     // initialise event
00198     hwuine();
00199     // generate hard subproces
00200     hwepro();
00201     // generate parton cascades
00202     hwbgen();
00203     // Do Jimmy underlying event if required.
00204     int abort = 0;
00205     if (abort == 0) {
00206       hwmsct(&abort);
00207       hwdhob();  // Do heavy quark decays
00208       hwcfor();  // Do cluster formation
00209       hwcdec();  // Do cluster decays
00210       hwdhad();  // Do unstable particle decays
00211       hwdhvy();  // Do heavy flavor decays
00212       hwmevt();  // Add soft underlying event
00213       hwufne();  // finish event
00214     }
00215     
00216     // Print HEPEVT format event here 
00217     // HepMC::HEPEVT_Wrapper::print_hepevt();
00218 
00219     HepMC::GenEvent* evt = hepevtio.read_next_event();
00220     // add some information to the event
00221     evt->set_event_number(iEvent);
00222     evt->set_signal_process_id(20);
00223    
00224     // the status codes should not be changed, otherwise you change
00225     // the output of the MC generators (status code variabl) and this
00226     // should not be done
00227     //     //change the status code in HepMC format event.  
00228     //     for ( HepMC::GenEvent::particle_const_iterator p =
00229     //      evt->particles_begin(); p != evt->particles_end(); ++p ){
00230     //       if( abs((*p)->status())>1 )
00231     //  (*p)->set_status(2);
00232     //     }
00233        
00234     //call the Jetfinder
00235     std::vector<fastjet::PseudoJet> inclusive_jets = FindJet.GetJet(evt);
00236 
00237     //call analysis
00238     int ret_all = true;
00239     for (std::vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00240       (*i)->SetJet(&inclusive_jets);
00241       int ret = (*i)->Process(evt);
00242       if (ret == false) ret_all = false;
00243     }
00244 
00245     if (ret_all==false) {
00246       std::cout << "Processing event number " << iEvent << std::endl;
00247       std::cout << "throw FAILURE"<<std::endl;
00248       //std::cout<<"pylist"<<std::endl;
00249       // call_pylist(2);
00250       std::cout<<std::endl;
00251       //std::cout<<"HepMC Output"<<std::endl;
00252       // evt->print();
00253       std::cout<<std::endl;
00254     }
00255 
00256 
00257     if (iEvent<=hwevnt.maxpr) {
00258       std::cout << "\n\n This is the FIXED version of HEPEVT as "
00259                 << "coded in IO_HERWIG " << std::endl;
00260       //    HepMC::HEPEVT_Wrapper::print_hepevt();
00261       //    evt->print();
00262     }
00263     
00264     //delete all the jet objects, missingEt etc. to be free for the next event
00265     FindJet.ClearEvent(evt);
00266       
00267     // we also need to delete the created event from memory
00268     delete evt;
00269 
00270   }
00271   //........................................TERMINATION
00272   hwefin();
00273 
00274  
00275   TFile* f = new TFile(currentconfig->OutputFileName.c_str(),"RECREATE");
00276   for (std::vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00277     (*i)->Finalize(f);
00278   }
00279 
00280   // clean up analysis modules
00281   for (std::vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00282     delete (*i);
00283   }
00284   analysis.resize(0);
00285 
00286   // clean up config object
00287   delete currentconfig;
00288 
00289   // Tidy up
00290   std::cout<<"Herwig:  program ends"<<std::endl;
00291   f->Close();
00292  
00293   std::cout<<"Run successfully!"<<std::endl;
00294   return 0;
00295 }
00296 
00297 // a dummy user-supplied subroutine called when the run terminates:
00298 void hwaend_ (void) { return; }

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