#include "PhysicsTools/StatPatternRecognition/interface/SprExperiment.hh"
#include "PhysicsTools/StatPatternRecognition/interface/SprTrainedRBF.hh"
#include "PhysicsTools/StatPatternRecognition/interface/SprData.hh"
#include "PhysicsTools/StatPatternRecognition/interface/SprEmptyFilter.hh"
#include "PhysicsTools/StatPatternRecognition/interface/SprAbsReader.hh"
#include "PhysicsTools/StatPatternRecognition/interface/SprAbsWriter.hh"
#include "PhysicsTools/StatPatternRecognition/interface/SprDataFeeder.hh"
#include "PhysicsTools/StatPatternRecognition/interface/SprRWFactory.hh"
#include <unistd.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <memory>
Go to the source code of this file.
Functions | |
void | help (const char *prog) |
int | main (int argc, char **argv) |
void help | ( | const char * | prog | ) |
Definition at line 25 of file SprRBFNetApp.cc.
References GenMuonPlsPt100GeV_cfg::cout, and lat::endl().
00026 { 00027 cout << "Usage: " << prog 00028 << " training_data_file " 00029 << " net_configuration_file " << endl; 00030 cout << "\t Options: " << endl; 00031 cout << "\t-h --- help " << endl; 00032 cout << "\t-o output Tuple file " << endl; 00033 cout << "\t-a input ascii file mode (see SprSimpleReader.hh) " << endl; 00034 cout << "\t-A save output data in ascii instead of Root " << endl; 00035 }
Definition at line 38 of file SprRBFNetApp.cc.
References c, TestMuL1L2Filter_cff::cerr, GenMuonPlsPt100GeV_cfg::cout, lat::endl(), filter, help(), i, and vars.
00039 { 00040 // check command line 00041 if( argc < 2 ) { 00042 help(argv[0]); 00043 return 1; 00044 } 00045 00046 // init 00047 string tupleFile; 00048 int readMode = 0; 00049 SprRWFactory::DataType writeMode = SprRWFactory::Root; 00050 00051 // decode command line 00052 int c; 00053 extern char* optarg; 00054 // extern int optind; 00055 while( (c = getopt(argc,argv,"ho:a:A")) != EOF ) { 00056 switch( c ) 00057 { 00058 case 'h' : 00059 help(argv[0]); 00060 return 1; 00061 case 'o' : 00062 tupleFile = optarg; 00063 break; 00064 case 'a' : 00065 readMode = (optarg==0 ? 0 : atoi(optarg)); 00066 break; 00067 case 'A' : 00068 writeMode = SprRWFactory::Ascii; 00069 break; 00070 } 00071 } 00072 00073 // There have to be 2 arguments after all options. 00074 string trFile = argv[argc-2]; 00075 string netFile = argv[argc-1]; 00076 if( trFile.empty() ) { 00077 cerr << "No training file is specified." << endl; 00078 return 1; 00079 } 00080 if( netFile.empty() ) { 00081 cerr << "No net file is specified." << endl; 00082 return 1; 00083 } 00084 00085 // read training data from file 00086 SprRWFactory::DataType inputType 00087 = ( readMode==0 ? SprRWFactory::Root : SprRWFactory::Ascii ); 00088 auto_ptr<SprAbsReader> reader(SprRWFactory::makeReader(inputType,readMode)); 00089 auto_ptr<SprAbsFilter> filter(reader->read(trFile.c_str())); 00090 if( filter.get() == 0 ) { 00091 cerr << "Unable to read data from file " << trFile.c_str() << endl; 00092 return 2; 00093 } 00094 vector<string> vars; 00095 filter->vars(vars); 00096 cout << "Read data from file " << trFile.c_str() 00097 << " for variables"; 00098 for( int i=0;i<vars.size();i++ ) 00099 cout << " \"" << vars[i].c_str() << "\""; 00100 cout << endl; 00101 cout << "Total number of points read: " << filter->size() << endl; 00102 cout << "Points in class 0: " << filter->ptsInClass(0) 00103 << " 1: " << filter->ptsInClass(1) << endl; 00104 00105 // read net 00106 SprTrainedRBF net; 00107 if( !net.readNet(netFile.c_str()) ) { 00108 cerr << "Unable to read net file " << netFile.c_str() << endl; 00109 return 3; 00110 } 00111 else { 00112 cout << "Read net configuration file:" << endl; 00113 net.print(cout); 00114 } 00115 00116 // make histogram if requested 00117 if( tupleFile.empty() ) return 0; 00118 00119 // make a writer 00120 auto_ptr<SprAbsWriter> tuple(SprRWFactory::makeWriter(writeMode,"training")); 00121 if( !tuple->init(tupleFile.c_str()) ) { 00122 cerr << "Unable to open output file " << tupleFile.c_str() << endl; 00123 return 4; 00124 } 00125 00126 // feed 00127 SprDataFeeder feeder(filter.get(),tuple.get()); 00128 feeder.addClassifier(&net,"rbf"); 00129 if( !feeder.feed(1000) ) { 00130 cerr << "Cannot feed data into file " << tupleFile.c_str() << endl; 00131 return 5; 00132 } 00133 00134 // exit 00135 return 0; 00136 }