Configuration.cc

Go to the documentation of this file.
00001 // this class header file
00002 #include "../include/Configuration.h"
00003 
00004 #include <iostream>
00005 #include <fstream>
00006 #include <sstream>
00007 #include <cstdlib>
00008 
00009 using namespace std;
00010 
00011 //---------------------------------------------------------------------- 
00012 Configuration::Configuration()
00013 {
00014     // the default randomseed will be generated from the time
00015   srand( time(0) % 900000000 );
00016   rseed = rand();
00017   
00018     // default: 1000 events
00019   nevents = 1000;
00020   
00021     // default Outputfilename
00022   OutputFileName = "output.root";
00023   
00024     // default: no Algorithm specified
00025   jet       = false;
00026   z         = false;
00027   wplusjet  = false;
00028   ztautau   = false;
00029   ttbar     = false;
00030   ue        = false;
00031   etmiss    = false;
00032   elasScat  = false;
00033   wtaunu    = false;
00034   bbbar     = false;
00035   user      = false;
00036 
00037     // default Jet parameter
00038   coneRadius          = 0.4;
00039   overlapThreshold    = 0.75;
00040   jet_ptmin           = 15.0;
00041   lepton_ptmin        = 15.0;
00042   DeltaR_lepton_track = 0.4;
00043   max_eta             = 2.5;
00044   min_pt              = 0.5;
00045   jetalgorithm        = 2;        // siscone = 1, antikt = 2
00046   
00047   FSR = true;
00048   ISR = true;
00049   MI  = true;
00050   
00051   IsOK = true;
00052 }
00053 
00054 //---------------------------------------------------------------------- 
00055 Configuration::Configuration( const string &configfile )
00056 {
00057   Configuration();
00058   IsOK = read( configfile );
00059 }
00060 
00061 //---------------------------------------------------------------------- 
00062 Configuration::~Configuration()
00063 {}
00064 
00065 //---------------------------------------------------------------------- 
00066 int Configuration::read( const string &configfile )
00067 {
00068   ifstream myfile( configfile.c_str() );
00069   cout << "readConfigFile: Read in Configuration from file '" << configfile << "'" << endl;
00070   
00071   if ( !myfile.is_open() ) {
00072     cerr << "readConfigFile: Unable to open file" << endl;
00073     return 1;
00074   }
00075 
00076     // clean-up before      
00077   ConfigFileNames.clear();
00078   InputFileNames.clear();
00079 
00080     // read line by line of the file
00081   string line;
00082   while ( !myfile.eof() ) {
00083     string parameter, str1;
00084     
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     istringstream instring( line );
00094     istringstream instring2( line );
00095     istringstream instring3( line );
00096     
00097     // and fill string or float
00098     instring >> parameter >> str1 ;
00099     instring2 >> parameter >> myfloat ;
00100     instring3 >> parameter >> mybool ;
00101     mylong = static_cast< long >( myfloat );
00102     
00103     // check for Comments. If the line starts with # than skip the line
00104     string::size_type pos = parameter.find( "#" );
00105     if ( pos != string::npos ) continue;
00106     
00107     // check for Comments. If the line starts with * than skip the line
00108     string::size_type pos2 = parameter.find( "*" );
00109     if ( pos2 != string::npos ) continue;
00110     
00111     // check for Comments. If the line starts with '/' than skip the line
00112     string::size_type pos3 = parameter.find( "/" );
00113     if( pos3 != string::npos ) continue;
00114     
00115     // skip if the string is empty
00116     if( parameter.empty() ) continue;
00117     
00118     // read pysub entries
00119     if ( ( parameter == "rseed" ) && ( mylong != -9999 ) ) {
00120       rseed = mylong;
00121       cout << "readConfigFile: Parameter " << parameter << "=" << rseed << endl;
00122     }
00123     else if ( ( parameter == "nevents" ) && ( mylong != -9999 ) ) {
00124       nevents = static_cast< unsigned int >( mylong );
00125       cout << "readConfigFile: Parameter " << parameter << "=" << nevents << endl;
00126     }
00127     else if ( ( parameter == "OutputFileName" ) && ( !str1.empty() ) ) {
00128       OutputFileName = str1;
00129       cout << "readConfigFile: Parameter " << parameter << "=" << OutputFileName << endl;
00130     }
00131     else if ( ( parameter == "ConfigFileNames" ) && ( !str1.empty() ) ) {
00132       ConfigFileNames.push_back( str1 );
00133       cout << "readConfigFile: Parameter " << parameter << "=" << ConfigFileNames.back() << endl;
00134     }
00135     else if ( ( parameter == "InputFileNames" ) && ( !str1.empty() ) ) {
00136       InputFileNames.push_back( str1 );
00137       cout << "readConfigFile: Parameter " << parameter << "=" << InputFileNames.back() << endl;
00138     }
00139     else if ( ( parameter == "jet_analysis" ) && ( !str1.empty() ) ) {
00140       jet = isParamOn( str1 );
00141       cout << "readConfigFile: Parameter " << parameter << "=" << jet << endl;
00142     }
00143     else if ( ( parameter == "z_analysis" ) && ( !str1.empty() ) ) {
00144       z = isParamOn( str1 );
00145       cout << "readConfigFile: Parameter " << parameter << "=" << z << endl;
00146     }
00147     else if ( ( parameter == "wplusjet_analysis" ) && ( !str1.empty() ) ) {
00148       wplusjet = isParamOn( str1 );
00149       cout << "readConfigFile: Parameter " << parameter << "=" << wplusjet << endl;
00150     }
00151     else if ( ( parameter == "ztautau_analysis" ) && ( !str1.empty() ) ) {
00152       ztautau = isParamOn( str1 );
00153       cout << "readConfigFile: Parameter " << parameter << "=" << ztautau << endl;
00154     }
00155     else if ( ( parameter == "ttbar_analysis" ) && ( !str1.empty() ) ) {
00156       ttbar = isParamOn( str1 );
00157       cout << "readConfigFile: Parameter " << parameter << "=" << ttbar << endl;
00158     }
00159     else if ( ( parameter == "ue_analysis" ) && ( !str1.empty() ) ) {
00160       ue = isParamOn( str1 );
00161       cout << "readConfigFile: Parameter " << parameter << "=" << ue << endl;
00162     }
00163     else if ( ( parameter == "etmiss_analysis" ) && ( !str1.empty() ) ) {
00164       etmiss = isParamOn( str1 );
00165       cout << "readConfigFile: Parameter " << parameter << "=" << etmiss << endl;
00166     }
00167     else if ( ( parameter == "elasScat_analysis" ) && ( !str1.empty() ) ) {
00168       elasScat = isParamOn( str1 );
00169       cout << "readConfigFile: Parameter " << parameter << "=" << elasScat << endl;
00170     }
00171     else if ( ( parameter == "wtaunu_analysis" ) && ( !str1.empty() ) ) {
00172       wtaunu = isParamOn( str1 );
00173       cout << "readConfigFile: Parameter " << parameter << "=" << wtaunu << endl;
00174     }
00175     else if ( ( parameter == "bbbar_analysis" ) && ( !str1.empty() ) ) {
00176       bbbar = isParamOn( str1 );
00177       cout << "readConfigFile: Parameter " << parameter << "=" << bbbar << endl;
00178     }
00179     else if ( ( parameter == "user_analysis") && ( !str1.empty() ) ) {
00180       user = isParamOn( str1 );
00181       cout << "readConfigFile: Parameter " << parameter << "=" << user << endl;
00182     }
00183     else if ( ( parameter == "jet_coneRadius" ) && ( myfloat != -9999.9 ) ) {
00184       coneRadius = myfloat;
00185       cout << "readConfigFile: Parameter " << parameter << "=" << coneRadius << endl;
00186     }
00187     else if ( ( parameter == "jet_overlapThreshold" ) && ( myfloat != -9999.9 ) ) {
00188       overlapThreshold = myfloat;
00189       cout << "readConfigFile: Parameter " << parameter << "=" << overlapThreshold << endl;
00190     }
00191     else if ( ( parameter == "jet_ptmin" ) && ( myfloat != -9999.9 ) ) {
00192       jet_ptmin = myfloat;
00193       cout << "readConfigFile: Parameter " << parameter << "=" << jet_ptmin << endl;
00194     }
00195     else if ( ( parameter == "DeltaR_lepton_track" ) && ( myfloat != -9999.9 ) ) {
00196       DeltaR_lepton_track = myfloat;
00197       cout << "readConfigFile: Parameter " << parameter << "=" << DeltaR_lepton_track << endl;
00198     }
00199     else if ( ( parameter == "lepton_ptmin" ) && ( myfloat != -9999.9 ) ) {
00200       lepton_ptmin = myfloat;
00201       cout << "readConfigFile: Parameter " << parameter << "=" << lepton_ptmin << endl;
00202     }
00203     else if ( ( parameter == "max_eta" ) && ( myfloat != -9999.9 ) ) {
00204       max_eta = myfloat;
00205       cout << "readConfigFile: Parameter " << parameter << "=" << max_eta << endl;
00206     }
00207     else if ( ( parameter == "min_pt" ) && ( myfloat != -9999.9 ) ){
00208       min_pt = myfloat;
00209       cout << "readConfigFile: Parameter " << parameter << "=" << min_pt << endl;
00210     }
00211     else if ((parameter == "jetalgorithm") && (mylong!=-9999)){
00212       jetalgorithm=mylong;
00213       cout << "readConfigFile: Parameter " << parameter << "=" << jetalgorithm << endl;
00214     }
00215     else if ( ( parameter == "FSR" ) && ( !str1.empty() ) ) {
00216       FSR = isParamOn( str1 );
00217       cout << "readConfigFile: Parameter " << parameter << "=" << FSR << endl;
00218     }
00219     else if ( ( parameter == "ISR" ) && ( !str1.empty() ) ) {
00220       ISR = isParamOn( str1 );
00221       cout << "readConfigFile: Parameter " << parameter << "=" << ISR << endl;
00222     }
00223     else if ( ( parameter == "MI" ) && ( !str1.empty() ) ) {
00224       MI = isParamOn( str1 );
00225       cout << "readConfigFile: Parameter " << parameter << "=" << MI << endl;
00226     }
00227     else{
00228       cout << "readConfigFile: Parameter " << parameter << " not recognized!" << endl;
00229       return 1;
00230     }
00231   }
00232   myfile.close();
00233   
00234   return 0;
00235 }
00236 
00237 //---------------------------------------------------------------------- 
00238 bool Configuration::isParamOn( const string &str ) const
00239 {
00240   return ( str == "on" ) || ( str == "true" ) || ( str == "True" );
00241 }
00242 

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