Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

meritapp.cxx

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/merit/src/app/meritapp.cxx,v 1.7 2001/10/22 18:34:32 burnett Exp $
00002 
00003 // Main for merit
00004 
00005 // either tuple
00006 #include "AsciiTuple.h"
00007 #include "RootTuple.h"
00008 
00009 #include "../Analyze.h"
00010 #include "../FigureOfMerit.h"
00011 
00012 #include <iostream>
00013 #include <fstream>
00014 #include <sys/types.h>
00015 #include <sys/timeb.h>
00016 #include <string>
00017 #include <strstream>
00018 
00019 #include <assert.h>
00020 
00021 const char* _MERIT_VERSION = "$Revision: 1.7 $";
00022 static std::string  cutstr("nA");
00023 static std::string  file_name("");
00024 
00025 
00026 
00027 void FATAL(const char* s){std::cerr << "\nERROR: "<< s;}
00028 void WARNING(const char* s){std::cerr << "\nWARNING: " << s;}
00029 
00030 static timeb t_init, t_final;
00031 static const char* helptext=
00032 "\n----------------------------------------------"
00033 "\nCalling syntax: merit  -CUTS [p] [file1 | - ] [file2] ..."
00034 "\n\nAnalysis cuts: allow re-ordering of gamma rejection cuts and trigger"
00035 "\ncounting at runtime. Order of cuts is same as in this string, specific"
00036 "\n'cuts' will increment the counters merit uses for analysis of the tuple."
00037 "\nIf 'p' is specified  then percentages will be displayed as well."
00038 "\n Reads from stdin next parameter is \"-\", or from $(MERIT_INPUT_FILE) otherwise."
00039 "\n\n\tCut keys are as follows:"
00040 "\n\t\tGnnnn, : Set number generated to nnnnn, overriding gen(nnn) in tuple title"
00041 "\n\t\t1 : level 1 trigger: Track or LoCal or HiCal "
00042 "\n\t\tV : level 1 VETO throttle "
00043 "\n\t\t2 : level 2 trigger: track, no doca veto except if cal "
00044 "\n\t\t3 : level 3 trigger"
00045 "\n\t\tF : TKR FRONT Section only"
00046 "\n\t\tB : TKR BACK Section only"
00047 "\n\t\tn : number of tracks (N_tracks > 0)"
00048 "\n\t\tc : cosmic rejection cuts (old set)"
00049 "\n\t    \"(...)\" : cut expression, like Chisq<50 ( chars ()<>  must be enclosed in quotes)"
00050 "\n\t\tX : Xname, -- statistics on name"
00051 "\n\t\tA : Analysis of PSF, etc."                                                    \
00052 "\n\t\tW : write the (ascii) event to standard output (useful for filtering tuples!)"
00053 "\n\t\tL : elapsed time: last time found in variable 'Triage_Time'"
00054 "\n\t\tR : Rate: number of events/elapsed time"
00055 "\n\t\ts : size: report on event size (assuming various bits/hit)"
00056 "\n\t\tMx: Multi-PSF for bin x, x=0,1,2,3,4: do PSF analysis for 6 dE/E bins from "
00057 "\n\t\t    31 MeV to 3.1 GeV, cos theta #n, bins are 0.2 wide"
00058 "\n\t\t    x=a: all bins from 1 to 0.2, 0.2 bins"
00059 "\n\t\t      b: all bins from 1 to 0.2, 0.1 bins"
00060 "\n\t\t      n: one bin  from 1 to 0, appropriate for normal incidence, or average"
00061 "\n\t\t      i: all costh bins but one energy bin, appropriate for single energy"
00062  ;
00063 
00064 void    help()
00065 {
00066     std::cerr << "\nmerit Version " << _MERIT_VERSION << " -- Help"
00067            << helptext << "\n\n\tDefault: " << cutstr << std::endl;
00068 }
00069 
00070 int main(int argc, char* argv[])
00071 {
00072     int         n=0;
00073 
00074     if( argc>++n ) file_name = argv[n];         // required
00075     if ( std::string(file_name).find("?") != std::string::npos
00076         || file_name=="--help") {       // print help information
00077         help();
00078         return 0;
00079     }
00080     // first arg is option string if preceded by dash
00081     if( file_name[0]=='-' && file_name.size()>1) {
00082         cutstr = file_name.substr(1);
00083         file_name = "";
00084     }
00085     if( argc>++n ) {                    // optional
00086         if ( argv[n][0] == 'p' )  {
00087             Analyze::showperc(true);
00088             n++;
00089         }
00090 
00091         if ( argc>n ) {
00092             if ( argv[n][0] == '-' )  { // this is the cut sequence
00093                 cutstr = &argv[n][1];
00094             } else file_name = argv[n]; 
00095         }
00096     }
00097 
00098     if( file_name=="" ) {
00099         const char * env = ::getenv("MERIT_INPUT_FILE");
00100         if( env ) file_name=env;
00101         else {
00102             std::cerr << "No input file specified, see help" << std::endl;
00103             exit(1);
00104         }
00105     }
00106 
00107         // setup output stream
00108         std::ostream* outstream = &std::cerr;
00109         const char * env = ::getenv("MERIT_OUTPUT_FILE");
00110         if( env ){
00111                 outstream = new std::ofstream(env);
00112         }
00113     std::cerr << "Merit reading from file: \"" << file_name << "\"" << std::endl;
00114     // charge a head with ROOT here, figure out later how to do it consistently
00115 
00116 //    RootTuple* tuple = new RootTuple("unknown", file_name, "AORECON/t1");
00117     RootTuple* tuple = new RootTuple("unknown", file_name, "PDR/t1");
00118     // now assign input stream, either the file name or std input
00119         // Determine the # of events stored in ntuple
00120 
00121     std::strstream title; 
00122     title << "gen(" << tuple->numEvents() << ")" << '\0';
00123     tuple->setTitle(title.str());
00124 
00125 #if 0
00126     std::istream* infile;
00127     if( file_name== "-") {
00128         infile = &std::cin;
00129     } else {
00130         std::ifstream* realfile = new std::ifstream(file_name.c_str());
00131         if( !realfile->is_open()) {
00132             std::cerr << "Cannot open file \"" << file_name << "\"";
00133             exit(1);
00134         }
00135 
00136         infile = realfile;
00137     }
00138     Tuple* tuple;
00139 
00140     if( file_name.find_first_of(".root") >0 ) {
00141         // opened a root file
00142         tuple = new RootTuple("unknown title", file_name, "t1");
00143     }
00144     else {
00145         // assume it is ascii. (need to fix, I think).
00146         tuple = new AsciiTuple(*infile);
00147     }
00148 
00149 
00150 #endif
00151     (*outstream) << "Tuple title: \""<< tuple->title() << "\"\n" ;
00152 
00153     FigureOfMerit fm(*tuple, cutstr);
00154 
00155     ::ftime(&t_init);
00156 
00157     while ( tuple->nextEvent() ) fm.execute();
00158     ::ftime(&t_final);
00159     fm.report(*outstream);
00160         
00161     std::cerr << "\nElapsed time: "<< t_final.time-t_init.time << " sec" << std::endl;
00162     return 0;
00163 }
00164 
00165 #if 0 // ascii multi-file here for future reference
00166     int line=0, m=1;
00167     for(;;) {
00168 
00169         // read and process the current file
00170         for(; ; ++line) {
00171             (*infile) >> tup;
00172             if( !infile->good() ) break;
00173             fm.execute();       
00174         }
00175         if( argc<=++n) break;
00176         // setup next file
00177         delete infile;
00178         file_name = argv[n];
00179         std::ifstream* realfile = new std::ifstream(file_name.c_str());
00180         if( !realfile->is_open()) {
00181             std::cerr << "Cannot open file \"" << file_name << "\"";
00182             exit(1);
00183         }
00184         tup.nextStream(*(infile=realfile));
00185         std::cerr << "Tuple# "<< ++m << " \""<< tup.title() << "\"\n" ;
00186 
00187     }
00188 #endif

Generated at Wed Nov 21 12:20:39 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000