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

Configuration.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <sstream>
00003 #include <stdio.h>
00004 #include "HepMC/GenEvent.h"
00005 #include "HepMC/IO_GenEvent.h"
00006 #include "HepMC/GenParticle.h"
00007 #include "HepMC/GenVertex.h"
00008 #include "HepMC/IO_AsciiParticles.h"
00009 #include "HepMC/SimpleVector.h"
00010 #include "CLHEP/Vector/LorentzVector.h"
00011 
00012 using namespace std;
00013 
00014 // ROOT headers
00015 #include "TH1.h"
00016 #include <TH2.h>
00017 #include "TFile.h"
00018 #include "TMath.h"
00019 #include "TLorentzVector.h"
00020 
00021 //tau analysis header
00022 #include "../include/Configuration.h"
00023 
00024 //**********************
00025 
00026 //starting functions
00027 Configuration::Configuration()
00028 {
00029   // the default randomseed will be generated from the time
00030   srand(time(0)%900000000);
00031   rseed=rand();
00032   
00033   // default: 1000 events
00034   nevents=1000;
00035   
00036   // default Outputfilename
00037   OutputFileName="output.root";
00038   
00039   // default: no Algorithm specified
00040   dijet = false;
00041   z = false;
00042   wplusjet = false;
00043   tau = false;
00044   top = false;
00045   ue = false;
00046   
00047   // default Jet parameter
00048   coneRadius = 1.0;
00049   overlapThreshold = 0.1;
00050   jet_ptmin = 5.0;
00051   max_eta = 100;
00052   min_pt = 0.1;
00053   
00054   FSR=true;
00055   ISR=true;
00056   MI=true;
00057   
00058   IsOK=true;
00059 }
00060 
00061 Configuration::Configuration( std::string configfile )
00062 {
00063   Configuration();
00064   IsOK=read(configfile);
00065 }
00066 
00067 Configuration::~Configuration()
00068 {
00069   while(!ConfigFileNames.empty())
00070     ConfigFileNames.pop_back();
00071 }
00072 
00073 
00074 int  Configuration::read(std::string configfile){
00075   string line;
00076   ifstream myfile (configfile.c_str());
00077   std::cout << "readConfigFile: Read in Configuration from file " << configfile << std::endl;
00078   if (myfile.is_open())
00079     {
00080       // read line by line of the file
00081       while (! myfile.eof() )
00082         {
00083           std::string parameter;
00084           std::string str1;
00085           int mylong=-9999;
00086           double myfloat=-9999.9;
00087           bool mybool=false;
00088           
00089           // write read lines into string line
00090           getline (myfile,line);
00091           
00092           // now split the line into the subwords
00093           std::istringstream instring(line);
00094           std::istringstream instring2(line);
00095           std::istringstream instring3(line);
00096           
00097           // and fill string or float
00098           instring >> parameter >> str1 ;
00099           instring2 >> parameter >> myfloat ;
00100           instring3 >> parameter >> mybool ;
00101           mylong=long(myfloat);
00102           
00103           // check for Comments. If the line starts with # than skip the line
00104           std::string::size_type pos = parameter.find("#");
00105           if(pos != std::string::npos) continue;
00106           // check for Comments. If the line starts with * than skip the line
00107           std::string::size_type pos2 = parameter.find("*");
00108           if(pos2 != std::string::npos) continue;
00109           // check for Comments. If the line starts with '/' than skip the line
00110           std::string::size_type pos3 = parameter.find("/");
00111           if(pos3 != std::string::npos) continue;
00112           
00113           // skip if the string is empty
00114           if(parameter.empty()) continue;
00115           
00116           
00117           // read pysub entries
00118           if ((parameter == "rseed") && (mylong!=-9999)) {
00119             rseed=mylong;
00120             std::cout << "readConfigFile: Parameter " << parameter << "=" << rseed << std::endl;
00121           }
00122           else if ((parameter == "nevents") && (mylong!=-9999)){
00123             nevents=(unsigned int)mylong;
00124             std::cout << "readConfigFile: Parameter " << parameter << "=" << nevents << std::endl;
00125           }
00126           else if ((parameter == "OutputFileName") && (!str1.empty())){
00127             OutputFileName=str1;
00128             std::cout << "readConfigFile: Parameter " << parameter << "=" << OutputFileName << std::endl;
00129           }
00130           else if ((parameter == "ConfigFileNames") && (!str1.empty())){
00131             ConfigFileNames.push_back(str1);
00132             std::cout << "readConfigFile: Parameter " << parameter << "=" << ConfigFileNames.back() << std::endl;
00133           }
00134           else if ((parameter == "dijet_analysis") && (!str1.empty())){
00135             if( (str1 == "on") ||  (str1 == "true") ||  (str1 == "True")) dijet=true;
00136             std::cout << "readConfigFile: Parameter " << parameter << "=" << dijet << std::endl;
00137           }
00138           else if ((parameter == "z_analysis")  && (!str1.empty())){
00139             if( (str1 == "on") ||  (str1 == "true") ||  (str1 == "True")) z=true;
00140             std::cout << "readConfigFile: Parameter " << parameter << "=" << z << std::endl;
00141           }
00142           else if ((parameter == "wplusjet_analysis")  && (!str1.empty())){
00143             if( (str1 == "on")  ||  (str1 == "true") ||  (str1 == "True") ) wplusjet=true;
00144             std::cout << "readConfigFile: Parameter " << parameter << "=" << wplusjet << std::endl;
00145           }
00146           else if ((parameter == "tau_analysis")  && (!str1.empty())){
00147             if( (str1 == "on")  ||  (str1 == "true") ||  (str1 == "True") ) tau=true;
00148             std::cout << "readConfigFile: Parameter " << parameter << "=" << tau << std::endl;
00149           }
00150           else if ((parameter == "top_analysis")  && (!str1.empty())){
00151             if( (str1 == "on")  ||  (str1 == "true") ||  (str1 == "True") ) top=true;
00152             std::cout << "readConfigFile: Parameter " << parameter << "=" << top << std::endl;
00153           }
00154           else if ((parameter == "ue_analysis")  && (!str1.empty())){
00155             if( (str1 == "on")  ||  (str1 == "true") ||  (str1 == "True") ) ue=true;
00156             std::cout << "readConfigFile: Parameter " << parameter << "=" << ue << std::endl;
00157           }
00158           else if ((parameter == "jet_coneRadius") && (myfloat!=-9999.9)){
00159             coneRadius=myfloat;
00160             std::cout << "readConfigFile: Parameter " << parameter << "=" << coneRadius << std::endl;
00161           }
00162           else if ((parameter == "jet_overlapThreshold") && (myfloat!=-9999.9)){
00163             overlapThreshold=myfloat;
00164             std::cout << "readConfigFile: Parameter " << parameter << "=" << overlapThreshold << std::endl;
00165           }
00166           else if ((parameter == "jet_ptmin") && (myfloat!=-9999.9)){
00167             jet_ptmin=myfloat;
00168             std::cout << "readConfigFile: Parameter " << parameter << "=" << jet_ptmin << std::endl;
00169           }
00170           else if ((parameter == "max_eta") && (myfloat!=-9999.9)){
00171             max_eta=myfloat;
00172             std::cout << "readConfigFile: Parameter " << parameter << "=" << max_eta << std::endl;
00173           }
00174           else if ((parameter == "min_pt") && (myfloat!=-9999.9)){
00175             min_pt=myfloat;
00176             std::cout << "readConfigFile: Parameter " << parameter << "=" << min_pt << std::endl;
00177           }
00178           else if ((parameter == "FSR")  && (!str1.empty())){
00179             if( (str1 == "on")  ||  (str1 == "true") ||  (str1 == "True") ) FSR=true;
00180             else FSR=false;
00181             std::cout << "readConfigFile: Parameter " << parameter << "=" << FSR << std::endl;
00182           }
00183           else if ((parameter == "ISR")  && (!str1.empty())){
00184             if( (str1 == "on")  ||  (str1 == "true") ||  (str1 == "True") ) ISR=true;
00185             else ISR=false;
00186             std::cout << "readConfigFile: Parameter " << parameter << "=" << ISR << std::endl;
00187           }
00188           else if ((parameter == "MI")  && (!str1.empty())){
00189             if( (str1 == "on")  ||  (str1 == "true") ||  (str1 == "True") ) MI=true;
00190             else MI=false;
00191             std::cout << "readConfigFile: Parameter " << parameter << "=" << MI << std::endl;
00192           }
00193           else{
00194             std::cout << "readConfigFile: Parameter " << parameter << " not recognized!" << std::endl;
00195             return 1;
00196           }
00197         }
00198       myfile.close();
00199     }
00200   else 
00201     {
00202       cout << "readConfigFile: Unable to open file"; 
00203       return 1;
00204     }
00205   return 0;
00206 }

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