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

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