00001
00002
00003 #include "PhysicsTools/StatPatternRecognition/interface/SprExperiment.hh"
00004 #include "PhysicsTools/StatPatternRecognition/interface/SprAbsTrainedClassifier.hh"
00005 #include "PhysicsTools/StatPatternRecognition/interface/SprAbsFilter.hh"
00006 #include "PhysicsTools/StatPatternRecognition/interface/SprUtils.hh"
00007
00008 #include <stdio.h>
00009 #include <utility>
00010 #include <fstream>
00011
00012 using namespace std;
00013
00014
00015 bool SprAbsTrainedClassifier::accept(const std::vector<double>& v,
00016 double& response) const
00017 {
00018 response = this->response(v);
00019 if( cut_.empty() ) return true;
00020 bool passed = false;
00021 for( int i=0;i<cut_.size();i++ ) {
00022 const pair<double,double>& lims = cut_[i];
00023 if( response>lims.first && response<lims.second ) {
00024 passed = true;
00025 break;
00026 }
00027 }
00028 return passed;
00029 }
00030
00031
00032 bool SprAbsTrainedClassifier::store(const char* filename) const
00033 {
00034
00035 string fname = filename;
00036 ofstream os(fname.c_str());
00037 if( !os ) {
00038 cerr << "Unable to open file " << fname.c_str() << endl;
00039 return false;
00040 }
00041
00042
00043 this->print(os);
00044
00045
00046 os << "==================================================" << endl;
00047 os << "Dimensions:" << endl;
00048 for( int i=0;i<vars_.size();i++ ) {
00049 char s [200];
00050 sprintf(s,"%5i %40s",i,vars_[i].c_str());
00051 os << s << endl;
00052 }
00053 os << "==================================================" << endl;
00054
00055
00056 return true;
00057 }
00058
00059
00060 bool SprAbsTrainedClassifier::storeCode(const char* filename) const
00061 {
00062
00063 string fname = filename;
00064 ofstream os(fname.c_str());
00065 if( !os ) {
00066 cerr << "Unable to open file " << fname.c_str() << endl;
00067 return false;
00068 }
00069
00070
00071 return this->generateCode(os);
00072 }