reader.cc

Go to the documentation of this file.
00001 /**
00002  *
00003  * @short Program to read HepMC format from file and run analysis modules
00004  *
00005  * @author Wolfgang Ehrenfeld, DESY, Germany
00006  *
00007  * @version \$Id: reader.cc,v 1.3 2009-05-27 11:06:59 sjohnert Exp $
00008  *
00009  */
00010 
00011 #include "HepMC/IO_GenEvent.h"
00012 #include "HepMC/GenEvent.h"
00013 
00014 #include <iostream>
00015 #include <fstream>
00016 
00017 // include our analysis modules
00018 #include "../../include/Configuration.h"
00019 #include "../../include/JetFinder.h"
00020 #include "../../include/ttbarAnalysis.h"
00021 #include "../../include/ZtautauAnalysis.h"
00022 #include "../../include/WtaunuAnalysis.h"
00023 #include "../../include/bbbarAnalysis.h"
00024 #include "../../include/JetAnalysis.h"
00025 #include "../../include/WplusJetAnalysis.h"
00026 #include "../../include/ZAnalysis.h"
00027 #include "../../include/UEAnalysis.h"
00028 #include "../../include/EtMissAnalysis.h"
00029 #include "../../include/ElasScatAnalysis.h"
00030 #include "../../include/UserAnalysis.h"
00031 
00032 #include "TFile.h"
00033 
00034 using namespace std;
00035 
00036 int main(int argc, const char* argv[]) 
00037 {
00038   if(argc <= 1 ) {
00039     cout << "Usage: " << argv[0] << " <Configuration File>" << endl;
00040     return 0;
00041   }
00042   
00043   Configuration* currentconfig = new Configuration();
00044   if(currentconfig->read(argv[1])) {
00045     cout << " ... skip !" << endl;
00046     return 0;
00047   }
00048 
00049   JetFinder FindJet;
00050   FindJet.Init(currentconfig->max_eta,currentconfig->min_pt);
00051   FindJet.InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin,currentconfig->lepton_ptmin,currentconfig->DeltaR_lepton_track);
00052 
00053 
00054   // create analysis Objects and initialize them                                                                                          
00055   vector<baseAnalysis*> analysis;
00056 
00057   if (currentconfig->jet) {
00058     cout << "Adding module JetAnalysis" << endl;
00059     analysis.push_back(new JetAnalysis);
00060   }
00061   if (currentconfig->wplusjet) {
00062     cout << "Adding module WplusJetAnalysis" << endl;
00063     analysis.push_back(new WplusJetAnalysis);
00064   }
00065   if(currentconfig->z){
00066     cout << "Adding module ZAnalysis" << endl;
00067     analysis.push_back(new ZAnalysis);
00068   }
00069   if(currentconfig->ztautau){
00070     cout << "Adding module ZtautauAnalysis" << endl;
00071     analysis.push_back(new ZtautauAnalysis);
00072   }
00073   if(currentconfig->wtaunu){
00074     cout << "Adding module WtaunuAnalysis" << endl;
00075     analysis.push_back(new WtaunuAnalysis);
00076   }
00077   if(currentconfig->bbbar){
00078     cout << "Adding module bbbarAnalysis" << endl;
00079     analysis.push_back(new bbbarAnalysis);
00080   }
00081   if(currentconfig->ttbar ){
00082     cout << "Adding module ttbarAnalysis" << endl;
00083     analysis.push_back(new ttbarAnalysis);
00084   }
00085   if(currentconfig->ue){
00086     cout << "Adding module UEAnalysis" << endl;
00087     analysis.push_back(new UEAnalysis);
00088   }  
00089   if(currentconfig->etmiss){
00090     cout << "Adding module EtMissAnalysis" << endl;
00091     analysis.push_back(new EtMissAnalysis);
00092   }
00093   if(currentconfig->elasScat){
00094     cout << "Adding module ElasScatAnalysis" << endl;
00095     analysis.push_back(new ElasScatAnalysis);
00096   }
00097   if(currentconfig->user){
00098     cout << "Adding module UserAnalysis" << endl;
00099     analysis.push_back(new UserAnalysis);
00100   }
00101   
00102   // init requested analysis modules and jet finder
00103   for (vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00104     (*i)->Init(currentconfig->max_eta,currentconfig->min_pt);
00105     (*i)->InitJetFinder(currentconfig->coneRadius,currentconfig->overlapThreshold,currentconfig->jet_ptmin,currentconfig->lepton_ptmin,currentconfig->DeltaR_lepton_track);
00106   }
00107 
00108 
00109   // Loop over events from files and fill histograms
00110   cout<<"Reading events and filling histograms..."<<endl;
00111   
00112   size_t iEvent(0);
00113   for (size_t i(0); iEvent < currentconfig->nevents && i<currentconfig->InputFileNames.size(); ++i) {
00114 
00115     // open input stream
00116     ifstream istr(currentconfig->InputFileNames[i].c_str());
00117     if (!istr) {
00118       cerr << "reader: can not open file "  << currentconfig->InputFileNames[i] << endl;
00119       exit(-1);
00120     }
00121 
00122     HepMC::IO_GenEvent ascii_in(istr);
00123     
00124     // now read the file
00125     HepMC::GenEvent* evt = ascii_in.read_next_event();
00126 
00127     while (evt && (iEvent < currentconfig->nevents)) {
00128       ++iEvent;
00129 
00130       /* --- analysis of event --- */
00131 
00132       // debug print out
00133       if (iEvent%50==0) {
00134         cout << "Processing event number " << iEvent << endl;
00135         // evt->print();
00136       }
00137 
00138       // call the Jetfinder
00139       vector<fastjet::PseudoJet> inclusive_jets = FindJet.GetJet(evt);
00140 
00141       // call active analysis modules
00142       int ret_all = true;
00143       for (vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00144         (*i)->SetJet(&inclusive_jets);
00145         int ret = (*i)->Process(evt);
00146         if (ret == false) ret_all = false;
00147       }
00148     
00149       // catch errors
00150       if (ret_all==false) {
00151         cout << "Processing event number " << iEvent << endl;
00152         cout << "throw FAILURE"<<endl;
00153         //cout<<"HepMC Output"<<endl;
00154         //evt->print();
00155         cout<<endl;
00156       }
00157     
00158       // delete all the jet objects, missingEt etc. to be free for the next event
00159       FindJet.ClearEvent(evt);
00160           
00161       //delete event and read in next
00162       delete evt;
00163       ascii_in >> evt;
00164 
00165     } // while loop over events
00166 
00167   } // loop over input fules
00168   cout << "reader: " << iEvent << " events found." << endl;
00169 
00170   // finalise step
00171   TFile* f = new TFile(currentconfig->OutputFileName.c_str(),"RECREATE");
00172   for (vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00173     (*i)->Finalize(f);
00174   }
00175 
00176   // clean up analysis modules and configuration
00177   for (vector<baseAnalysis*>::const_iterator i(analysis.begin()); i != analysis.end(); ++i) {
00178     delete (*i);
00179   }
00180   analysis.resize(0);
00181 
00182   delete currentconfig;
00183 
00184   cout << "reader: finished successfully!" << endl;
00185   return 0;
00186 }

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