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

herwigpp_2.3.1.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/Configuration.h"
00042 #include "../../include/JetFinder.h"
00043 #include "../../include/TopAnalysis.h"
00044 #include "../../include/TauAnalysis.h"
00045 #include "../../include/DiJetAnalysis.h"
00046 #include "../../include/WplusJetAnalysis.h"
00047 #include "../../include/ZAnalysis.h"
00048 #include "../../include/UEAnalysis.h"
00049 #include "../../include/EtMissAnalysis.h"
00050 #include "../../include/UserAnalysis.h"
00051 #include "readHerwigConfigFile.h"
00052 
00053 int main(int argc, const char* argv[]) {
00054 
00055   if(argc <= 1 ) {
00056     std::cout << "Usage: " << argv[0] << " <Configuration File>" << std::endl;
00057     return 0;
00058   }
00059   
00060   
00061   Configuration* currentconfig = new Configuration();
00062   if(currentconfig->read(argv[1]))
00063     {
00064       std::cout << " ... skip !" << std::endl;
00065       return 0;
00066     }
00067 
00068   JetFinder FindJet;
00069   FindJet.Init(currentconfig->max_eta,currentconfig->min_pt);
00070   FindJet.InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin,currentconfig->lepton_ptmin,currentconfig->DeltaR_lepton_track);
00071 
00072 
00073   std::vector<baseAnalysis*> analysis;
00074 
00075   // create analysis Objects and initialize them                                                                                          
00076   if (currentconfig->dijet) {
00077     std::cout << "Adding module DiJetAnalysis" << std::endl;
00078     analysis.push_back(new DiJetAnalysis);
00079   }
00080   if (currentconfig->wplusjet) {
00081     std::cout << "Adding module WplusJetAnalysis" << std::endl;
00082     analysis.push_back(new WplusJetAnalysis);
00083   }
00084   if(currentconfig->z){
00085     std::cout << "Adding module ZAnalysis" << std::endl;
00086     analysis.push_back(new ZAnalysis);
00087   }
00088   if(currentconfig->tau){ 
00089     std::cout << "Adding module TauAnalysis" << std::endl;
00090     analysis.push_back(new TauAnalysis);
00091   }
00092   if(currentconfig->top){
00093     std::cout << "Adding module TopAnalysis" << std::endl;
00094     analysis.push_back(new TopAnalysis);
00095   }
00096   if(currentconfig->ue){
00097     std::cout << "Adding module UEAnalysis" << std::endl;
00098     analysis.push_back(new UEAnalysis);
00099   }  
00100   if(currentconfig->etmiss){
00101     std::cout << "Adding module EtMissAnalysis" << std::endl;
00102     analysis.push_back(new EtMissAnalysis);
00103   }
00104   if(currentconfig->user){
00105     std::cout << "Adding module UserAnalysis" << std::endl;
00106     analysis.push_back(new UserAnalysis);
00107   }
00108   
00109 
00110   // init requested analysis modules and jet finder
00111   for (std::vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00112     (*i)->Init(currentconfig->max_eta,currentconfig->min_pt);
00113     (*i)->InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin,currentconfig->lepton_ptmin,currentconfig->DeltaR_lepton_track);
00114   }
00115 
00116 
00117   // Add a path to seach for dynamically linkable libraries
00118   std::cout<<"Add a path to seach for dynamically linkable libraries..."<<std::endl;
00119   ThePEG::DynamicLoader::appendPath(HWMODULEDIR);
00120   ThePEG::DynamicLoader::appendPath(THEPEGMODULEDIR);
00121   
00122   //Load a whole repository from the given file
00123   std::cout<<"Load repository from a given file..."<<std::endl;
00124   const string repopath = string(HWREPODIR) + "/HerwigDefaults.rpo";
00125   ThePEG::Repository::load(repopath);
00126 
00127   //Setup process,interpret the command in cmd and return possible messages
00128   std::cout<<"Setup process,interpret the command in cmd and return possible messages..."<<std::endl;
00129 
00130   // set random number seed (mandatory!) ... this may be overwritten by function readConfigFile
00131   char exec_command[100];
00132   sprintf(exec_command,"set LHCGenerator:RandomNumberGenerator:Seed %ld",currentconfig->rseed); 
00133   ThePEG::Repository::exec("cd /Herwig/Generators", cout);
00134   ThePEG::Repository::exec(exec_command, cout);
00135 
00136   // vector to store herwig commandlines from Configuration file
00137   std::vector< std::string > herwig_commands;
00138   // read in commandlines
00139   for (unsigned int files=0; files<(currentconfig->ConfigFileNames).size(); files++)
00140     readConfigFile(&herwig_commands,(currentconfig->ConfigFileNames)[files]);
00141 
00142   // loop over the commands
00143   for(unsigned int i=0; i<herwig_commands.size(); i++)
00144     ThePEG::Repository::exec( herwig_commands[i].c_str(), cout);
00145 
00146   //switches for FSR, ISR and MI
00147   ThePEG::Repository::exec("cd /Herwig/Shower", cout);
00148   
00149   sprintf(exec_command,"set SplittingGenerator:ISR %c",currentconfig->ISR);
00150   ThePEG::Repository::exec(exec_command, cout);
00151   
00152   sprintf(exec_command,"set SplittingGenerator:FSR %c",currentconfig->FSR);
00153   ThePEG::Repository::exec(exec_command, cout);
00154   
00155   sprintf(exec_command,"set ShowerHandler:MPI %c",currentconfig->MI);
00156   ThePEG::Repository::exec(exec_command, cout);
00157 
00158 
00159   //Check sanity of the object during the setup phase
00160   ThePEG::Repository::update();
00161 
00162   // ThePEG generator object.
00163   ThePEG::EGPtr m_hw;
00164 
00165   // ThePEG event object.
00166   ThePEG::EventPtr m_event;
00167 
00168   // Make a "run" object from the config repository.
00169   std::cout<<"make a run object ..."<<std::endl;
00170   ThePEG::EGPtr tmpEG = ThePEG::BaseRepository::GetObject<ThePEG::EGPtr>("/Herwig/Generators/LHCGenerator");
00171   m_hw = ThePEG::Repository::makeRun(tmpEG, "LHC");
00172 
00173   // Herwig++ initializing
00174   std::cout<<"Herwig++ initializing..."<<std::endl;
00175   m_hw->initialize();
00176 
00177   // Loop for events generating and fill histograms
00178   std::cout<<"Generating events and filling histograms..."<<std::endl;
00179   
00180   //Change the value of nEvent to the number of events you want to generate
00181   for (unsigned int iEvent = 0; iEvent < currentconfig->nevents; ++iEvent) {
00182 
00183     // Run the generator for one event.
00184     assert(m_hw);
00185     m_event = m_hw->shoot();
00186     
00187     // Fill HepMC event from Herwig's internally stored EventPtr.
00188     // Convert the Herwig event into the HepMC GenEvent
00189     HepMC::GenEvent*  evt= ThePEG::HepMCConverter<HepMC::GenEvent>::convert(*m_event, false, ThePEG::GeV);
00190 
00191     // debug print out
00192     std::cout << "Processing event number " << iEvent << std::endl;
00193     if (iEvent < 0) evt->print();
00194 
00195     //call the Jetfinder
00196     vector<fastjet::PseudoJet> inclusive_jets = FindJet.GetJet(evt);
00197 
00198     //call analysis
00199     int ret_all = true;
00200     for (std::vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00201       (*i)->SetJet(&inclusive_jets);
00202       int ret = (*i)->Process(evt);
00203       if (ret == false) ret_all = false;
00204     }
00205     
00206     if (ret_all==false) {
00207       std::cout << "Processing event number " << iEvent << std::endl;
00208       std::cout << "throw FAILURE"<<std::endl;
00209       //std::cout<<"HepMC Output"<<std::endl;
00210       //evt->print();
00211       std::cout<<std::endl;
00212     }
00213     
00214     // delete all the jet objects, missingEt etc. to be free for the next event
00215     FindJet.ClearEvent(evt);
00216     
00217     // delete event
00218     delete evt;
00219   }
00220   
00221   TFile* f = new TFile(currentconfig->OutputFileName.c_str(),"RECREATE");
00222   for (std::vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00223     (*i)->Finalize(f);
00224   }
00225 
00226   // clean up analysis modules
00227   for (std::vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00228     delete (*i);
00229   }
00230   analysis.resize(0);
00231 
00232   // clean up config object
00233   delete currentconfig;
00234 
00235   //Tidy up, Herwig++ finalizing
00236   std::cout<<"Herwig++ finalizing..."<<std::endl;
00237   assert(m_hw);
00238   m_hw->finalize();
00239   ThePEG::Repository::cleanup();
00240 
00241   std::cout<<"Run successfully!"<<std::endl;
00242   return 0;
00243 }

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