CMS 3D CMS Logo

PhysicsTools::TrainProcessor Class Reference

#include <PhysicsTools/MVATrainer/interface/TrainProcessor.h>

Inheritance diagram for PhysicsTools::TrainProcessor:

PhysicsTools::Source PhysicsTools::ProcessRegistry< Base_t, CalibBase_t, Parent_t >::Factory

List of all members.

Public Types

typedef TrainerMonitoring::Module Monitoring

Public Member Functions

virtual void cleanup ()
virtual void configure (XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *config)
void doTrainBegin ()
void doTrainData (const std::vector< double > *values, bool target, double weight, bool train, bool test)
void doTrainEnd ()
virtual Calibration::VarProcessorgetCalibration () const
virtual Variable::Flags getDefaultFlags () const
const char * getId () const
virtual bool load ()
virtual void passFlags (const std::vector< Variable::Flags > &flags)
virtual void save ()
 TrainProcessor (const char *name, const AtomicId *id, MVATrainer *trainer)
virtual ~TrainProcessor ()

Protected Member Functions

bool exists (const std::string &name)
virtual voidrequestObject (const std::string &name) const
virtual void testData (const std::vector< double > *values, bool target, double weight, bool trainedOn)
virtual void trainBegin ()
virtual void trainData (const std::vector< double > *values, bool target, double weight)
virtual void trainEnd ()

Protected Attributes

Monitoringmonitoring
std::string name
MVATrainertrainer

Private Attributes

std::vector< SigBkgmonHistos
MonitoringmonModule

Classes

struct  Registry
struct  SigBkg


Detailed Description

Definition at line 26 of file TrainProcessor.h.


Member Typedef Documentation

typedef TrainerMonitoring::Module PhysicsTools::TrainProcessor::Monitoring

Definition at line 38 of file TrainProcessor.h.


Constructor & Destructor Documentation

PhysicsTools::TrainProcessor::TrainProcessor ( const char *  name,
const AtomicId id,
MVATrainer trainer 
)

Definition at line 13 of file TrainProcessor.cc.

00015                                                     :
00016         Source(*id), name(name), trainer(trainer), monitoring(0), monModule(0)
00017 {
00018 }

PhysicsTools::TrainProcessor::~TrainProcessor (  )  [virtual]

Definition at line 20 of file TrainProcessor.cc.

00021 {
00022 }


Member Function Documentation

virtual void PhysicsTools::TrainProcessor::cleanup ( void   )  [inline, virtual]

Definition at line 63 of file TrainProcessor.h.

Referenced by PhysicsTools::MVATrainer::~MVATrainer().

00063 {}

virtual void PhysicsTools::TrainProcessor::configure ( XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *  config  )  [inline, virtual]

Definition at line 49 of file TrainProcessor.h.

00049 {}

void PhysicsTools::TrainProcessor::doTrainBegin (  ) 

Definition at line 24 of file TrainProcessor.cc.

References PhysicsTools::TrainerMonitoring::Module::book(), PhysicsTools::MVATrainer::bookMonitor(), PhysicsTools::TrainProcessor::SigBkg::entries, PhysicsTools::SourceVariableSet::get(), PhysicsTools::Source::getInputs(), PhysicsTools::Variable::getName(), PhysicsTools::Source::getName(), PhysicsTools::SourceVariable::getSource(), PhysicsTools::TrainProcessor::SigBkg::histo, infinity, PhysicsTools::Source::inputs, iter, PhysicsTools::TrainProcessor::SigBkg::max, PhysicsTools::TrainProcessor::SigBkg::min, monHistos, monitoring, monModule, name, PhysicsTools::TrainProcessor::SigBkg::overflow, PhysicsTools::TrainProcessor::SigBkg::sameBinning, source, trainBegin(), trainer, and PhysicsTools::TrainProcessor::SigBkg::underflow.

00025 {
00026         bool booked = false;
00027         unsigned int nBins = 50;
00028 
00029         if (!monitoring) {
00030                 const char *source = getName();
00031                 if (source) {
00032                         monitoring = trainer->bookMonitor(name + "_" + source);
00033                         monModule = trainer->bookMonitor(std::string("input_") +
00034                                                          source);
00035                 } else {
00036                         monModule = trainer->bookMonitor("output");
00037                         nBins = 400;
00038                 }
00039 
00040                 booked = monModule != 0;
00041         }
00042 
00043         if (booked) {
00044                 std::vector<SourceVariable*> inputs = getInputs().get();
00045                 for(std::vector<SourceVariable*>::const_iterator iter =
00046                         inputs.begin(); iter != inputs.end(); ++iter) {
00047 
00048                         SourceVariable *var = *iter;
00049                         std::string name =
00050                                 (const char*)var->getSource()->getName()
00051                                 + std::string("_")
00052                                 + (const char*)var->getName();
00053 
00054                         SigBkg pair;
00055                         pair.entries[0] = pair.entries[1] = 0;
00056                         pair.histo[0] = monModule->book<TH1F>(name + "_bkg",
00057                                 (name + "_bkg").c_str(),
00058                                 (name + " background").c_str(), nBins, 0, 0);
00059                         pair.histo[1] = monModule->book<TH1F>(name + "_sig",
00060                                 (name + "_sig").c_str(),
00061                                 (name + " signal").c_str(), nBins, 0, 0);
00062                         pair.underflow[0] = pair.underflow[1] = 0.0;
00063                         pair.overflow[0] = pair.overflow[1] = 0.0;
00064 
00065                         pair.sameBinning = true;        // use as default
00066                         if (monitoring) {
00067                                 pair.min = -std::numeric_limits<double>::infinity();
00068                                 pair.max = +std::numeric_limits<double>::infinity();
00069                         } else {
00070                                 pair.min = -99999.0;
00071                                 pair.max = +99999.0;
00072                         }
00073 
00074                         monHistos.push_back(pair);
00075                 }
00076         }
00077 
00078         trainBegin();
00079 }

void PhysicsTools::TrainProcessor::doTrainData ( const std::vector< double > *  values,
bool  target,
double  weight,
bool  train,
bool  test 
)

Definition at line 81 of file TrainProcessor.cc.

References iter, min, monHistos, monModule, testData(), trainData(), and value.

00084 {
00085         if (monModule && test) {
00086                 for(std::vector<SigBkg>::iterator iter = monHistos.begin();
00087                     iter != monHistos.end(); ++iter) {
00088                         const std::vector<double> &vals =
00089                                         values[iter - monHistos.begin()];
00090                         for(std::vector<double>::const_iterator value =
00091                                 vals.begin(); value != vals.end(); ++value) {
00092 
00093                                 iter->entries[target]++;
00094 
00095                                 if (*value <= iter->min) {
00096                                         iter->underflow[target] += weight;
00097                                         continue;
00098                                 } else if (*value >= iter->max) {
00099                                         iter->overflow[target] += weight;
00100                                         continue;
00101                                 }
00102 
00103                                 iter->histo[target]->Fill(*value, weight);
00104 
00105                                 if (iter->sameBinning)
00106                                         iter->histo[!target]->Fill(*value, 0);
00107                         }
00108                 }
00109         }
00110 
00111         if (train)
00112                 trainData(values, target, weight);
00113         if (test)
00114                 testData(values, target, weight, train);
00115 }

void PhysicsTools::TrainProcessor::doTrainEnd (  ) 

Definition at line 117 of file TrainProcessor.cc.

References i, iter, monHistos, monModule, and trainEnd().

00118 {
00119         trainEnd();
00120 
00121         if (monModule) {
00122                 for(std::vector<SigBkg>::const_iterator iter =
00123                         monHistos.begin(); iter != monHistos.end(); ++iter) {
00124 
00125                         for(unsigned int i = 0; i < 2; i++) {
00126                                 Int_t oBin = iter->histo[i]->GetNbinsX() + 1;
00127                                 iter->histo[i]->SetBinContent(0,
00128                                         iter->histo[i]->GetBinContent(0) +
00129                                         iter->underflow[i]);
00130                                 iter->histo[i]->SetBinContent(oBin,
00131                                         iter->histo[i]->GetBinContent(oBin) +
00132                                         iter->overflow[i]);
00133                                 iter->histo[i]->SetEntries(iter->entries[i]);
00134                         }
00135                 }
00136 
00137                 monModule = 0;
00138         }
00139 }

bool PhysicsTools::TrainProcessor::exists ( const std::string &  name  )  [inline, protected]

Definition at line 78 of file TrainProcessor.h.

00079         { return boost::filesystem::exists(name.c_str()); }

virtual Calibration::VarProcessor* PhysicsTools::TrainProcessor::getCalibration (  )  const [inline, virtual]

Definition at line 54 of file TrainProcessor.h.

Referenced by PhysicsTools::MVATrainer::getCalibration(), and PhysicsTools::MVATrainer::makeTrainCalibration().

00054 { return 0; }

virtual Variable::Flags PhysicsTools::TrainProcessor::getDefaultFlags (  )  const [inline, virtual]

Definition at line 45 of file TrainProcessor.h.

References PhysicsTools::Variable::FLAG_NONE.

00046         { return Variable::FLAG_NONE; }

const char* PhysicsTools::TrainProcessor::getId (  )  const [inline]

Definition at line 65 of file TrainProcessor.h.

References name.

00065 { return name.c_str(); }

virtual bool PhysicsTools::TrainProcessor::load ( void   )  [inline, virtual]

Definition at line 61 of file TrainProcessor.h.

00061 { return true; }

virtual void PhysicsTools::TrainProcessor::passFlags ( const std::vector< Variable::Flags > &  flags  )  [inline, virtual]

Definition at line 52 of file TrainProcessor.h.

00052 {}

virtual void* PhysicsTools::TrainProcessor::requestObject ( const std::string &  name  )  const [inline, protected, virtual]

Definition at line 75 of file TrainProcessor.h.

00076         { return 0; }

virtual void PhysicsTools::TrainProcessor::save ( void   )  [inline, virtual]

Definition at line 62 of file TrainProcessor.h.

00062 {}

virtual void PhysicsTools::TrainProcessor::testData ( const std::vector< double > *  values,
bool  target,
double  weight,
bool  trainedOn 
) [inline, protected, virtual]

Definition at line 71 of file TrainProcessor.h.

Referenced by doTrainData().

00072                                                                           {}

virtual void PhysicsTools::TrainProcessor::trainBegin (  )  [inline, protected, virtual]

Definition at line 68 of file TrainProcessor.h.

Referenced by doTrainBegin().

00068 {}

virtual void PhysicsTools::TrainProcessor::trainData ( const std::vector< double > *  values,
bool  target,
double  weight 
) [inline, protected, virtual]

Definition at line 69 of file TrainProcessor.h.

Referenced by doTrainData().

00070                                                            {}

virtual void PhysicsTools::TrainProcessor::trainEnd (  )  [inline, protected, virtual]

Definition at line 73 of file TrainProcessor.h.

References PhysicsTools::Source::trained.

Referenced by doTrainEnd().

00073 { trained = true; }


Member Data Documentation

std::vector<SigBkg> PhysicsTools::TrainProcessor::monHistos [private]

Definition at line 96 of file TrainProcessor.h.

Referenced by doTrainBegin(), doTrainData(), and doTrainEnd().

Monitoring* PhysicsTools::TrainProcessor::monitoring [protected]

Definition at line 83 of file TrainProcessor.h.

Referenced by doTrainBegin().

Monitoring* PhysicsTools::TrainProcessor::monModule [private]

Definition at line 97 of file TrainProcessor.h.

Referenced by doTrainBegin(), doTrainData(), and doTrainEnd().

std::string PhysicsTools::TrainProcessor::name [protected]

Reimplemented from PhysicsTools::Source.

Definition at line 81 of file TrainProcessor.h.

Referenced by doTrainBegin(), and getId().

MVATrainer* PhysicsTools::TrainProcessor::trainer [protected]

Definition at line 82 of file TrainProcessor.h.

Referenced by doTrainBegin().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:50:15 2009 for CMSSW by  doxygen 1.5.4