00001 
00002 
00003 
00004 
00005 
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 
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 
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 
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     
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   
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   
00139   
00140   
00141   
00142   
00143   HepMC::HEPEVT_Wrapper::set_max_number_entries(hwgethepevtsize_());
00144   HepMC::HEPEVT_Wrapper::set_sizeof_real(8);
00145 
00146   
00147   hwevnt.nrn[0] = currentconfig->rseed;
00148   
00149   
00150   hwproc.maxev = int(currentconfig->nevents); 
00151   
00152   
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   
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   
00167   
00168   
00169     
00170   
00171   hwevnt.maxpr = 1; 
00172   
00173   hwuinc(); 
00174   
00175   hweini(); 
00176   
00177   jminit();
00178   
00179   
00180   
00181   HepMC::IO_HERWIG hepevtio;
00182   
00183   
00184   for ( int iEvent = 1; iEvent <= hwproc.maxev; iEvent++ ) {
00185     if ( iEvent%50==1 ) cout << "Processing Event Number " 
00186                                   << iEvent << endl;
00187 
00188 
00189 
00190 
00191 
00192 
00193 
00194 
00195 
00196 
00197 
00198 
00199 
00200 
00201 
00202 
00203 
00204 
00205 
00206 
00207 
00208     
00209     hwuine();
00210     
00211     hwepro();
00212     
00213     hwbgen();
00214 
00215     
00216     int abort = 0;
00217     hwmsct(&abort);
00218     if (abort != 0) {
00219       cout << "Event aborted by hwmsct." << endl;
00220       hwufne();  
00221       continue;
00222     }
00223 
00224     
00225       hwdhob();  
00226       hwcfor();  
00227       hwcdec();  
00228       hwdhad();  
00229       hwdhvy();  
00230       hwmevt();  
00231       hwufne();  
00232     
00233       if (hwevnt.ierror==-1 || hwevnt.ierror>99) {
00234         cout << "Event Error, Number: " << " Code: " << hwevnt.ierror << endl;
00235         continue;
00236       }
00237     
00238     
00239     
00240 
00241     HepMC::GenEvent* evt = hepevtio.read_next_event();
00242     
00243     evt->set_event_number(iEvent);
00244     evt->set_signal_process_id(20);
00245    
00246     
00247     
00248     
00249     
00250     
00251     
00252     
00253     
00254     
00255        
00256     
00257     vector<fastjet::PseudoJet> inclusive_jets = FindJet.GetJet(evt);
00258 
00259     
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       
00271       
00272       cout<<endl;
00273       
00274       
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       
00283       
00284     }
00285     
00286     
00287     FindJet.ClearEvent(evt);
00288       
00289     
00290     delete evt;
00291 
00292   }
00293   
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   
00303   for (vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00304     delete (*i);
00305   }
00306   analysis.resize(0);
00307 
00308   
00309   delete currentconfig;
00310 
00311   
00312   cout<<"Herwig:  program ends"<<endl;
00313   f->Close();
00314  
00315   cout<<"Run successfully!"<<endl;
00316   return 0;
00317 }
00318 
00319 
00320 void hwaend_ (void) { return; }