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

reader.cc

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

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