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

herwigpp_2.3.0.cc

Go to the documentation of this file.
00001 //example of Herwig++, generate pp -> ttbar events
00002 //by Zhonghua Qin <zhonghua.qin@desy.de> 
00003 #include "ThePEG/Repository/EventGenerator.h"
00004 #include "ThePEG/Repository/Repository.h"
00005 #include "ThePEG/Persistency/PersistentIStream.h"
00006 #include "ThePEG/Utilities/DynamicLoader.h"
00007 #include "ThePEG/EventRecord/Event.h"
00008 #include "ThePEG/EventRecord/SubProcess.h"
00009 #include "ThePEG/Handlers/XComb.h"
00010 #include "ThePEG/Handlers/EventHandler.h"
00011 #include "ThePEG/PDF/PartonExtractor.h"
00012 #include "ThePEG/PDF/PDF.h"
00013 #include "ThePEG/Vectors/HepMCConverter.h"
00014 #include "ThePEGHepMC_1.4.0.h"
00015 
00016 #include "HepMC/GenEvent.h"
00017 #include "HepMC/IO_GenEvent.h"
00018 #include "HepMC/GenEvent.h"
00019 #include "HepMC/IO_AsciiParticles.h"
00020 #include "HepMC/SimpleVector.h"
00021 
00022 #include <iostream>
00023 #include <stdio.h>
00024 #include <string>
00025 
00026 #include "TH1.h"
00027 #include "TFile.h"
00028 #include "TMath.h"
00029 #include <TCanvas.h>
00030 
00031 #include "TF1.h"
00032 #include <TH2.h>
00033 #include <TStyle.h>
00034 #include "TLegend.h"
00035 #include <TTree.h>
00036 #include <TString.h>
00037 
00038 using namespace ThePEG;
00039 
00040 // include our own classes
00041 #include "../../include/TopAnalysis.h"
00042 #include "../../include/TauAnalysis.h"
00043 #include "../../include/DiJetAnalysis.h"
00044 #include "../../include/WplusJetAnalysis.h"
00045 #include "../../include/ZAnalysis.h"
00046 #include "../../include/UEAnalysis.h"
00047 #include "readHerwigConfigFile.h"
00048 #include "../../include/Configuration.h"
00049 
00050 int main(int argc, const char* argv[]) {
00051 
00052   if(argc <= 1 ) {
00053       std::cout << "Usage: " << argv[0] << " <Configuration File>" << std::endl;
00054       return 0;
00055   }
00056   
00057   
00058   Configuration* currentconfig = new Configuration();
00059   if(currentconfig->read(argv[1]))
00060       {
00061           std::cout << " ... skip !" << std::endl;
00062           return 0;
00063       }
00064 
00065   DiJetAnalysis dijet;
00066   WplusJetAnalysis wplusjet;
00067   ZAnalysis z0;
00068   TauAnalysis tau;
00069   TopAnalysis top;
00070   UEAnalysis ue;
00071 
00072   // create analysis Objects and initialize them                                                                                          
00073   if(currentconfig->dijet){
00074     dijet.Init(currentconfig->max_eta,currentconfig->min_pt);
00075     dijet.InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin);
00076   }
00077 
00078   if(currentconfig->wplusjet){
00079     wplusjet.Init(currentconfig->max_eta,currentconfig->min_pt);
00080     wplusjet.InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin);
00081   }
00082 
00083   if(currentconfig->z){
00084     z0.Init(currentconfig->max_eta,currentconfig->min_pt);
00085     z0.InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin);
00086   }
00087   if(currentconfig->tau){
00088     tau.Init(currentconfig->max_eta,currentconfig->min_pt);
00089     tau.InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin);
00090   }
00091   if(currentconfig->top){
00092     top.Init(currentconfig->max_eta,currentconfig->min_pt);
00093     top.InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin);
00094   }
00095   if(currentconfig->ue){
00096     ue.Init(currentconfig->max_eta,currentconfig->min_pt);
00097     ue.InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin);
00098   }
00099   
00100   //Add a path to seach for dynamically linkable libraries
00101   std::cout<<"Add a path to seach for dynamically linkable libraries..."<<std::endl;
00102   ThePEG::DynamicLoader::appendPath(HWMODULEDIR);
00103   ThePEG::DynamicLoader::appendPath(THEPEGMODULEDIR);
00104   
00105   //Load a whole repository from the given file
00106   std::cout<<"Load repository from a given file..."<<std::endl;
00107   const string repopath = string(HWREPODIR) + "/HerwigDefaults.rpo";
00108   ThePEG::Repository::load(repopath);
00109 
00110   //Setup process,interpret the command in cmd and return possible messages
00111   std::cout<<"Setup process,interpret the command in cmd and return possible messages..."<<std::endl;
00112 
00113   // set random number seed (mandatory!) ... this may be overwritten by function readConfigFile
00114   char exec_command[100];
00115   sprintf(exec_command,"set LHCGenerator:RandomNumberGenerator:Seed %ld",currentconfig->rseed); 
00116   ThePEG::Repository::exec("cd /Herwig/Generators", cout);
00117   ThePEG::Repository::exec(exec_command, cout);
00118 
00119   // vector to store herwig commandlines from Configuration file
00120   std::vector< std::string > herwig_commands;
00121   // read in commandlines
00122   for (unsigned int files=0; files<(currentconfig->ConfigFileNames).size(); files++)
00123       readConfigFile(&herwig_commands,(currentconfig->ConfigFileNames)[files]);
00124 
00125   // loop over the commands
00126   for(unsigned int i=0; i<herwig_commands.size(); i++)
00127       ThePEG::Repository::exec( herwig_commands[i].c_str(), cout);
00128 
00129 //switches for FSR, ISR and MI
00130   ThePEG::Repository::exec("cd /Herwig/Shower", cout);
00131 
00132   sprintf(exec_command,"set SplittingGenerator:ISR %c",currentconfig->ISR);
00133   ThePEG::Repository::exec(exec_command, cout);
00134 
00135   sprintf(exec_command,"set SplittingGenerator:FSR %c",currentconfig->FSR);
00136   ThePEG::Repository::exec(exec_command, cout);
00137 
00138   sprintf(exec_command,"set ShowerHandler:MPI %c",currentconfig->MI);
00139   ThePEG::Repository::exec(exec_command, cout);
00140 
00141   //Check sanity of the object during the setup phase
00142   ThePEG::Repository::update();
00143 
00144  // ThePEG generator object.
00145   ThePEG::EGPtr m_hw;
00146 
00147   // ThePEG event object.
00148   ThePEG::EventPtr m_event;
00149 
00150  // Make a "run" object from the config repository.
00151   ThePEG::EGPtr tmpEG = ThePEG::BaseRepository::GetObject<ThePEG::EGPtr>("/Herwig/Generators/LHCGenerator");
00152   m_hw = ThePEG::Repository::makeRun(tmpEG, "LHC");
00153 
00154  //Herwig++ initializing
00155   std::cout<<"Herwig++ initializing..."<<std::endl;
00156   m_hw->initialize();
00157 
00158  //Loop for events generating and fill histograms
00159   std::cout<<"Generating events and filling histograms..."<<std::endl;
00160   
00161  //Change the value of nEvent to the number of events you want to generate
00162   for (unsigned int iEvent = 0; iEvent < currentconfig->nevents; ++iEvent) {
00163 
00164  // Run the generator for one event.
00165   assert(m_hw);
00166   m_event = m_hw->shoot();
00167 
00168  // Fill HepMC event from Herwig's internally stored EventPtr.
00169  // Convert the Herwig event into the HepMC GenEvent
00170  // HepMC::GenEvent*  evt = new HepMC::GenEvent();
00171   //  ThePEG::HepMCConverter<HepMC::GenEvent>::convert(*m_event, *evt, false, ThePEG::GeV);
00172   HepMC::GenEvent*  evt= ThePEG::HepMCConverter<HepMC::GenEvent>::convert(*m_event, false, ThePEG::GeV);
00173 
00174   int ret_dijet = SUCCESS;
00175   int ret_wplusjet = SUCCESS;
00176   int ret_z0 = SUCCESS;
00177   int ret_tau = SUCCESS;
00178   int ret_top = SUCCESS;
00179   int ret_ue = SUCCESS;
00180 
00181   //call analysis
00182   if(currentconfig->dijet)       ret_dijet = dijet.Process(evt);
00183   if(currentconfig->wplusjet)    ret_wplusjet = wplusjet.Process(evt);
00184   if(currentconfig->z)           ret_z0 = z0.Process(evt);
00185   if(currentconfig->tau)  ret_tau = tau.Process(evt);
00186   if(currentconfig->top)  ret_top = top.Process(evt);
00187   if(currentconfig->ue)   ret_ue = ue.Process(evt);
00188 
00189   if (ret_dijet==FAILURE || ret_wplusjet==FAILURE || ret_z0==FAILURE
00190       || ret_tau==FAILURE || ret_top==FAILURE || ret_ue==FAILURE)
00191       {
00192           std::cout << "Processing event number " << iEvent << std::endl;
00193           std::cout << "throw FAILURE"<<std::endl;
00194           //std::cout<<"HepMC Output"<<std::endl;
00195           //evt->print();
00196           std::cout<<std::endl;
00197       }
00198 
00199   //delete all the jet objects to be free for the next event
00200   if(currentconfig->dijet)       dijet.DeleteJetObject(evt);
00201   if(currentconfig->wplusjet)    wplusjet.DeleteJetObject(evt);
00202   if(currentconfig->z)         z0.DeleteJetObject(evt);
00203   if(currentconfig->tau)       tau.DeleteJetObject(evt);
00204   if(currentconfig->top)       top.DeleteJetObject(evt);
00205   if(currentconfig->ue)        ue.DeleteJetObject(evt);
00206 
00207   delete evt;
00208   }
00209 
00210   TFile* f = new TFile(currentconfig->OutputFileName.c_str(),"RECREATE");
00211   if(currentconfig->dijet)       dijet.Finalize(f);
00212   if(currentconfig->wplusjet)    wplusjet.Finalize(f);
00213   if(currentconfig->z)         z0.Finalize(f);
00214   if(currentconfig->tau)       tau.Finalize(f);
00215   if(currentconfig->top)       top.Finalize(f);
00216   if(currentconfig->ue)        ue.finalize(f);
00217   delete currentconfig;
00218 
00219   //Tidy up, Herwig++ finalizing
00220   std::cout<<"Herwig++ finalizing..."<<std::endl;
00221   assert(m_hw);
00222   m_hw->finalize();
00223   ThePEG::Repository::cleanup();
00224 
00225   std::cout<<"Run successfully!"<<std::endl;
00226   return 0;
00227  }

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