MyHtoWWAnalysis/exe/AAN_analysis.cxx

00001 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00002 // 03/2007, AUTHOR: STEFFEN KAISER
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 #include "unistd.h"
00017 
00018 // STL //
00019 #include <string>
00020 #include <vector>
00021 
00022 // AAN reader //
00023 #include "NtupleReader/NtupleReader.h"
00024 //#include "NtupleReader/NtupleReaderFast.h"
00025 
00026 // ROOT //
00027 #include "TSystem.h"
00028 #include "TObjString.h"
00029 
00030 // user analysis //
00031 #include "MyHtoWWAnalysis/MyHtoWWAnalysis.h"
00032 
00033 //::::::::::::::::::::::::
00034 //:: NAMESPACE SETTINGS ::
00035 //::::::::::::::::::::::::
00036 
00037 using namespace std;
00038 
00039 
00040 //:::::::::::::::::
00041 //:: METHOD help ::
00042 //:::::::::::::::::
00043 
00044 void help(const char *argv0) {
00045     
00046     cerr << "Usage: " << argv0 << " [options] <infile>"                 << endl
00047          << "       <infile> can be <textfile>.txt or <rootfile>.root " << endl
00048          << "Options:"                                                  << endl
00049          << "-o <path>:\tWrite outputfile in directory <path>"          << endl
00050          << "-a <addon>:\tWrite outputfile as filename_<addon>.root"    << endl
00051          << "-d <decay>:\tRun analysis in the decay mode <decay>"       << endl
00052          << "-c <v1=x,v2=y>:\tUse these cut values "                    << endl
00053          << "-f <file>:\tUse cut values defined in <file>"              << endl
00054          << "-e <events>:\tRun analysis on <events> events"             << endl
00055          << "-s <events>:\tSkip the first <events> events"              << endl
00056          << "-i:\t\tQuit when outputfile already exits"                 << endl
00057          << "-h:\t\tShow this message and quit."                        << endl;
00058     exit(0);
00059 }
00060 
00061 //::::::::::
00062 //:: MAIN ::
00063 //::::::::::
00064 
00065 int main(int argc, char * argv[]) {
00066 
00067    //----------------------------
00068    //-- PARSE THE COMMAND LINE --
00069    //----------------------------
00070 
00071     extern char *optarg;
00072     //extern int optind, optopt;
00073     char c;
00074     string infile(""), outputpath(""), addon(""), decay_mode(""), cutstring(""), cutfile("");
00075     bool overwrite(true);
00076     int  nb_events(-1), first_event(0);
00077     
00078     while((c = getopt(argc, argv, "-hio:a:d:c:f:e:s:")) !=-1)
00079     {
00080         //cout << c <<endl;
00081         switch(c)
00082         {
00083         case 'i':
00084             {
00085                 overwrite = false;
00086                 break;
00087             }
00088         case 'o':
00089             {
00090                 outputpath = optarg;
00091                 break;
00092             }
00093         case 'a':
00094             {
00095                 addon = optarg;
00096                 break;
00097             }
00098         case 'd':
00099             {
00100                 decay_mode = optarg;
00101                 break;
00102             }
00103         case 'c':
00104             {
00105                 cutstring = optarg;
00106                 break;
00107             } 
00108         case 'f':
00109             {
00110                 cutfile = optarg;
00111                 break;
00112             } 
00113         case 'e':
00114             {
00115                 nb_events = atoi(optarg);
00116                 break;
00117             } 
00118         case 's':
00119             {
00120                 first_event = atoi(optarg);
00121                 break;
00122             } 
00123         case 1:
00124             {
00125                 infile = optarg;
00126                 break;
00127             }
00128         default:
00129             cerr << "Help or unknown argument!" << endl;
00130             help(argv[0]);
00131             break;
00132         }
00133     }
00134 
00135     if(infile == ""){
00136         cerr << "Error: Missing input file!" << endl;
00137         help(argv[0]);
00138     }
00139     
00140     cout << endl
00141          << "command line arguments: "     << endl
00142          << "  outputpath:  " << outputpath  << endl
00143          << "  infile:      " << infile      << endl
00144          << "  addon:       " << addon       << endl
00145          << "  decay_mode:  " << decay_mode  << endl
00146          << "  cutfile:     " << cutfile     << endl
00147          << "  cutstring:   " << cutstring   << endl
00148          << "  nb_events:   " << nb_events   << endl 
00149          << "  first event: " << first_event << endl 
00150          << "  overwrite:   " << overwrite   << endl
00151          << endl;
00152    
00153 
00154     //---------------
00155     //-- VARIABLES --
00156     //---------------
00157    
00158     //TSystem *gSystem=new TSystem;
00159     //gSystem->Load("libAnalysisTools.so");
00160    
00161     MyHtoWWAnalysis my_analysis;
00162    
00163 
00164     string sdummy; // auxiliary string
00165     vector<string> filename; // vector containing names of AAN files
00166 
00167 
00168     //-------------------------
00169     //-- CHECK THE INPUTFILE --
00170     //-------------------------
00171 
00172     if(TString(infile).Contains(".root")){
00173        
00174         filename.push_back(infile);
00175     }
00176     else if(TString(infile).Contains(".txt")){
00177        
00178         ifstream settings_file(infile.c_str()); // file containing names of AAN files
00179         if (settings_file.fail()) {
00180             cerr << endl
00181                  << "ERROR: Could not open settings file " << infile << endl
00182                  << endl;
00183             return 1;
00184         }
00185        
00186         //-------------------------------------
00187         //-- READ THE NAMES OF THE AAN FILES --
00188         //-------------------------------------
00189        
00190         while (!settings_file.eof()) {
00191             settings_file >> sdummy;
00192             if (settings_file.eof()) {
00193                 break;
00194             }
00195             filename.push_back(sdummy);
00196         }
00197        
00198     }else{
00199         cerr << endl
00200              << "ERROR: could not read inputfile " << infile << "," << endl
00201              << "       please provide '.root' or '.txt' file." << endl
00202              << endl;
00203         return 1;
00204     }
00205  
00206 
00207     //------------------------------------------------------------
00208     //-- CHECK WHETHER THE FILE COMES FROM CBNT OR NTUPLEWRITER --
00209     //------------------------------------------------------------
00210 
00211     TFile testfile(filename[0].c_str());
00212     
00213     TTree* Colltree = (TTree*)testfile.Get("CollectionTree");
00214     TTree* CBNTtree = (TTree*)testfile.Get("CBNT/T3333");
00215    
00216     bool CBNT_flag = false;
00217    
00218     if(Colltree!=NULL && CBNTtree==NULL){
00219         CBNT_flag = false;
00220     }
00221     else if(Colltree==NULL && CBNTtree!=NULL){
00222         CBNT_flag = true;
00223     }
00224     else{
00225         cerr << endl
00226              << "ERROR: could not read tree" << endl
00227              << "       please provide 'CollectionTree' or 'CBNT/T3333'." << endl
00228              << endl;
00229         return 1;  
00230     }
00231 
00232     testfile.Close();
00233    
00234       
00235     //----------------------------------------------------------
00236     //-- INITIALIZE THE EVENT READER AND LOOP OVER THE EVENTS --
00237     //----------------------------------------------------------
00238    
00239     //set the output filename
00240     //my_analysis.filename = filename[0].c_str();
00241    
00242     TObjArray*  TOarray  = ((TString)filename[0].c_str()).Tokenize("/");
00243     TObjString* TOstring = (TObjString*)TOarray->Last();
00244      
00245     my_analysis.filename     = TOstring->GetString();
00246     my_analysis.outputpath   = TString(outputpath);
00247     my_analysis.addon        = TString(addon);
00248     my_analysis.overwrite    = overwrite;
00249     my_analysis.m_decay_mode = decay_mode;
00250     my_analysis.m_cutstring  = cutstring;
00251     my_analysis.m_cutfile    = cutfile;
00252 
00253     if(!CBNT_flag){
00254         NtupleReader reader(filename, string("CollectionTree"), &my_analysis);
00255         reader.event_loop(nb_events, first_event);
00256     }
00257     else{
00258         cerr << "NtupleReaderFast has been removed from the Makefile" << endl;
00259         exit(1);
00260         //NtupleReaderFast reader(filename, string("CBNT/T3333"),  &my_analysis);
00261         //reader.event_loop();
00262     }
00263       
00264    
00265     return 0;
00266    
00267 }
00268 
00269 
00270    //-----------------------------
00271    //-- CHECK FOR CORRECT USAGE --
00272    //-----------------------------
00273  
00274     // if (argc<2 || argc>3) {
00275 //         //if (argc!=2) {
00276 //         cerr << endl
00277 //              << "Incorrect usage!\n"
00278 //              << "Correct usage:\n"
00279 //              << "AAN_analysis.exe <textfile.txt> [<outputpath>], or\n"
00280 //              << "AAN_analysis.exe <rootfile.root> [<outputpath>]\n" 
00281 //              << endl;
00282 //         return 1;
00283 //     }

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