MyHtautauAnalysis/exe/AAN_analysis.cxx

00001 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00002 // 8.11.2006, AUTHOR: OLIVER KORTNER
00003 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00004 
00005 //::::::::::::::::::::::::::::::::::::::::::::::::::::
00006 //:: MAIN PROGRAMME TO RUN THE ANALYSIS OF THE AAN. ::
00007 //::::::::::::::::::::::::::::::::::::::::::::::::::::
00008 
00009 //:::::::::::::::::
00010 //:: HEADER FILE ::
00011 //:::::::::::::::::
00012 
00013 // standard C++ //
00014 #include <iostream>
00015 #include <fstream>
00016 
00017 // STL //
00018 #include <string>
00019 #include <vector>
00020 
00021 // AAN reader //
00022 #include "NtupleReader/NtupleReader.h"
00023 //#include "NtupleReader/NtupleReaderFast.h"
00024 #include "NtupleReader/MyDatasetInfo.h"
00025 #include "NtupleReader/MyTrigger.h"
00026 
00027 // ROOT //
00028 #include "TSystem.h"
00029 #include "TObjString.h"
00030 
00031 // user analysis //
00032 //#include "MyAnalysisExample/MyAnalysisExample.h"  //example
00033 //#include "HiggsAnalysis/MyJetAnalysis.h"    // steffen
00034 #include "MyHtautauAnalysis/MyHtautauAnalysis.h" // manfred
00035 //#include "HiggsAnalysis/Ttbar_Analyse.h"  // thies
00036 
00037 //::::::::::::::::::::::::
00038 //:: NAMESPACE SETTINGS ::
00039 //::::::::::::::::::::::::
00040 
00041 using namespace std;
00042 
00043 
00044 //:::::::::::::::::
00045 //:: METHOD help ::
00046 //:::::::::::::::::
00047 
00048 void help(const char *argv0) {
00049     
00050     cerr << "Usage: " << argv0 << " [options] <cut_values file> <infile> <outfile>"<< endl
00051          << "       <infile> can be <textfile>.txt or <rootfile>.root " << endl
00052          << "Options:"                                                  << endl
00053          << "-o <path>:\tWrite outputfile in directory <path>"          << endl
00054          << "-a <addon>:\tWrite outputfile as filename_<addon>.root"    << endl
00055          << "-e <events>:\tRun analysis on <events> events"             << endl
00056          << "-s <events>:\tSkip the first <events> events"              << endl
00057          << "-i:\t\tQuit when outputfile already exits"                 << endl
00058          << "-h:\t\tShow this message and quit."                        << endl;
00059     exit(0);
00060 }
00061 
00062 
00063 //::::::::::
00064 //:: MAIN ::
00065 //::::::::::
00066 
00067 int main(int argc, char * argv[]) {
00068 
00069    //----------------------------
00070    //-- PARSE THE COMMAND LINE --
00071    //----------------------------
00072         
00073         cout<<"argc "<<argc<<endl;
00074         
00075     extern char *optarg;
00076     //extern int optind, optopt;
00077     char c;
00078     string infile(""), outputpath(""), addon(""), outfile("");
00079     string settingsFile("");
00080     bool overwrite(true);
00081     int  nb_events(-1);
00082     int first_event(0);
00083 
00084     while((c = getopt(argc, argv, "-hio:a:e:s:")) !=-1)
00085     {
00086         //cout << c <<endl;
00087         switch(c)
00088         {
00089         case 'i':
00090             {
00091                 overwrite = false;
00092                 break;
00093             }
00094         case 'o':
00095             {
00096                 outputpath = optarg;
00097                 break;
00098             }
00099         case 'a':
00100             {
00101                 addon = optarg;
00102                 break;
00103             }
00104         case 'e':
00105             {
00106                 nb_events = atoi(optarg);
00107                 break;
00108             } 
00109         case 's':
00110             {
00111                 first_event = atoi(optarg);
00112                 break;
00113             } 
00114         case 1:
00115             {   
00116                 if(settingsFile==""){
00117                     settingsFile = optarg;
00118                 }
00119                                 else if(infile==""){
00120                                         infile = optarg;
00121                                 }
00122                 else{
00123                     outfile = optarg;
00124                 }
00125                 break;
00126             }
00127         default:
00128             cerr << "Help or unknown argument!" << endl;
00129             help(argv[0]);
00130             break;
00131         }
00132                 
00133     }
00134         if(infile=="" || outfile==""){
00135                 cerr<<"Provide a infile and a outfile"<<endl;
00136                 help(argv[0]);
00137                 exit(1);
00138         }
00139     
00140     cout << endl
00141          << "command line arguments: "     << endl
00142          << "  outputpath:  " << outputpath << endl
00143          << "  cut_values:  " << settingsFile << endl
00144          << "  infile:      " << infile     << endl
00145          << "  outfile:     " << outfile    << endl
00146          << "  addon:       " << addon      << endl
00147          << "  nb_events:   " << nb_events  << endl 
00148          << "  first event: " << first_event  << endl 
00149          << "  overwrite:   " << overwrite  << endl
00150          << endl;
00151    
00152    
00153 //     cout << "\n\n"
00154 //             << "===============================\n"
00155 //             << "===============================\n"
00156 //             << "   !!!  Loose electrons  !!! \n"
00157 //             << "===============================\n"
00158 //             << "===============================\n"
00159 //             << "\n\n";
00160    //---------------
00161    //-- VARIABLES --
00162    //---------------
00163    
00164    
00165    //TSystem *gSystem=new TSystem;
00166    //gSystem->Load("libAnalysisTools.so");
00167    
00168    MyHtautauAnalysis my_analysis; 
00169 
00170 
00171    string sdummy; // auxiliary string
00172    vector<string> filename; // vector containing the names of the AAN files
00173 
00174 
00175     //-------------------------
00176     //-- CHECK THE INPUTFILE --
00177     //-------------------------
00178 
00179     if(TString(infile).Contains(".root")){
00180        
00181         filename.push_back(infile);
00182     }
00183     else if(TString(infile).Contains(".txt")){
00184        
00185         ifstream settings_file(infile.c_str()); // file containing names of AAN files
00186         if (settings_file.fail()) {
00187             cerr << endl
00188                  << "ERROR: Could not open file " << infile << endl
00189                  << endl;
00190             return 1;
00191         }
00192        
00193         //-------------------------------------
00194         //-- READ THE NAMES OF THE AAN FILES --
00195         //-------------------------------------
00196        
00197         while (!settings_file.eof()) {
00198             settings_file >> sdummy;
00199             if (settings_file.eof()) {
00200                 break;
00201             }
00202             filename.push_back(sdummy);
00203         }
00204        
00205     }else{
00206         cerr << endl
00207              << "ERROR: could not read inputfile " << infile << "," << endl
00208              << "       please provide '.root' or '.txt' file." << endl
00209              << endl;
00210         return 1;
00211     }
00212  
00213 
00214     //------------------------------------------------------------
00215     //-- CHECK WHETHER THE FILE COMES FROM CBNT OR NTUPLEWRITER --
00216     //------------------------------------------------------------
00217 
00218     TFile testfile(filename[0].c_str());
00219    
00220     TTree* Colltree = (TTree*)testfile.Get("CollectionTree");
00221     TTree* CBNTtree = (TTree*)testfile.Get("CBNT/T3333");
00222    
00223     bool CBNT_flag = false;
00224    
00225     if(Colltree!=NULL && CBNTtree==NULL){
00226         CBNT_flag = false;
00227     }
00228     else if(Colltree==NULL && CBNTtree!=NULL){
00229         CBNT_flag = true;
00230     }
00231     else{
00232         cerr << endl
00233              << "ERROR: could not read tree" << endl
00234              << "       please provide 'CollectionTree' or 'CBNT/T3333'." << endl
00235              << endl;
00236         return 1;  
00237     }
00238 
00239     testfile.Close();
00240    
00241       
00242     //----------------------------------------------------------
00243     //-- INITIALIZE THE EVENT READER AND LOOP OVER THE EVENTS --
00244     //----------------------------------------------------------
00245    
00246     //set the output filename
00247     //my_analysis.filename = filename[0].c_str();
00248    
00249 //    TObjArray*  TOarray  = ((TString)filename[0].c_str()).Tokenize("/");
00250 //    TObjString* TOstring = (TObjString*)TOarray->Last();
00251      
00252     my_analysis.filename   = outfile;
00253     my_analysis.settingsFilename   = settingsFile;
00254         //TOstring->GetString();
00255 //    my_analysis.outputpath = TString(outputpath);
00256 //    my_analysis.addon      = TString(addon);
00257 //    my_analysis.overwrite  = overwrite;
00258 
00259     if(!CBNT_flag){
00260         NtupleReader reader(filename, string("CollectionTree"), &my_analysis);
00261         reader.event_loop(nb_events, first_event);
00262     }
00263     else{
00264  //       NtupleReaderFast reader(filename, string("CBNT/T3333"),  &my_analysis);
00265  //       reader.event_loop();
00266     }
00267       
00268    
00269     return 0;
00270    
00271    
00272    
00273    
00274    
00275    
00276    
00277    
00278    
00279    
00280    
00281    
00282    
00283    
00284    
00285    
00286    
00287    
00288    
00289    
00290    
00291    
00292    
00293    
00294    
00295    // 
00296 //    
00297 //    
00298 //    
00299 //    
00300 //    bool multifiles;
00301 //    multifiles = true;
00302 //    
00303 //    if (!multifiles){
00304 //        filename.push_back(argv[1]);
00305 //    }
00306 //    
00307 //    if (multifiles){  
00308 //      ifstream settings_file(argv[1]); // file containing the names of the
00309 //                                      // AAN files
00310 //      if (settings_file.fail()) {
00311 //              cerr << endl
00312 //                      << "Could not open settings file " << argv[1] << "."
00313 //                      << endl;
00314 //              return 1;
00315 //      }
00316 //    
00317 //      //-------------------------------------
00318 //      //-- READ THE NAMES OF THE AAN FILES --
00319 //      //-------------------------------------
00320 //    
00321 //      while (!settings_file.eof()) {
00322 //              settings_file >> sdummy;
00323 //              if (settings_file.eof()) {
00324 //                      break;
00325 //              }
00326 //              filename.push_back(sdummy);
00327 //      }
00328 //    }
00329 //    //----------------------------------------------------------
00330 //    //-- INITIALIZE THE EVENT READER AND LOOP OVER THE EVENTS --
00331 //    //----------------------------------------------------------
00332 // 
00333 //    //my_analysis.filename = filename[0].c_str();
00334 //    my_analysis.filename = argv[2];
00335 // 
00336 //  // fuer ntuple vom NtupleWriter
00337 //    NtupleReader reader(filename, string("CollectionTree"), &my_analysis);
00338 //  
00339 //  // fuer CBNTs von Makis
00340 //  //  NtupleReaderFast reader(filename, string("CBNT/t3333"),  &my_analysis);
00341 // 
00342 //  // fuer die selbst geschriebenen:
00343 //  //  NtupleReaderFast reader(filename, string("CBNT/T3333"),  &my_analysis);
00344 //    
00345 //    reader.event_loop();
00346 //    
00347 //    return 0;
00348 //    //-----------------------------
00349 //    //-- CHECK FOR CORRECT USAGE --
00350 //    //-----------------------------
00351 // 
00352 //    if (argc!=3) {
00353 //       cerr << endl
00354 //         << "Incorrect usage!\n"
00355 //         << "Correct usage:\n"
00356 //         << "AAN_analysis.exe <file of input files> <outputfilename>\n";
00357 //       return 1;
00358 //    }
00359    
00360 }

Generated on Tue Oct 21 11:50:43 2008 for NtupleAnalysis by  doxygen 1.5.1