CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes
PhysicsTools::TrainProcessor Class Reference

#include <TrainProcessor.h>

Inheritance diagram for PhysicsTools::TrainProcessor:
PhysicsTools::Source PhysicsTools::ProcessRegistry< Base_t, CalibBase_t, Parent_t >::Factory

Classes

struct  Dummy
 
struct  Registry
 
struct  SigBkg
 

Public Types

typedef TrainerMonitoring::Module Monitoring
 
typedef
edmplugin::PluginFactory
< Dummy *()> 
PluginFactory
 

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 ()
 
- Public Member Functions inherited from PhysicsTools::Source
const SourceVariableSetgetInputs () const
 
AtomicId getName () const
 
SourceVariablegetOutput (AtomicId name) const
 
const SourceVariableSetgetOutputs () const
 
bool isTrained () const
 
 Source (AtomicId name, bool trained=false)
 
virtual ~Source ()
 
- Public Member Functions inherited from PhysicsTools::ProcessRegistry< Base_t, CalibBase_t, Parent_t >::Factory
template<>
VarProcessorcreate (const char *name, const Calibration::VarProcessor *calib, const MVAComputer *parent)
 
template<>
TrainProcessorcreate (const char *, const AtomicId *, MVATrainer *)
 
template<>
TrainProcessorcreate (const char *name, const AtomicId *id, MVATrainer *trainer)
 
template<>
VarProcessorcreate (const char *, const Calibration::VarProcessor *, const MVAComputer *)
 

Protected Member Functions

bool exists (const std::string &name)
 
virtual void * requestObject (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 Member Functions inherited from PhysicsTools::Source
SourceVariableSetgetInputs ()
 
SourceVariableSetgetOutputs ()
 

Protected Attributes

Monitoringmonitoring
 
std::string name
 
MVATrainertrainer
 
- Protected Attributes inherited from PhysicsTools::Source
bool trained
 

Private Attributes

std::vector< SigBkgmonHistos
 
MonitoringmonModule
 

Additional Inherited Members

- Static Public Member Functions inherited from PhysicsTools::ProcessRegistry< Base_t, CalibBase_t, Parent_t >::Factory
static Base_t * create (const char *name, const CalibBase_t *calib, Parent_t *parent=0)
 

Detailed Description

Definition at line 28 of file TrainProcessor.h.

Member Typedef Documentation

Definition at line 40 of file TrainProcessor.h.

Definition at line 70 of file TrainProcessor.h.

Constructor & Destructor Documentation

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

Definition at line 19 of file TrainProcessor.cc.

21  :
23 {
24 }
Source(AtomicId name, bool trained=false)
Definition: Source.h:15
PhysicsTools::TrainProcessor::~TrainProcessor ( )
virtual

Definition at line 26 of file TrainProcessor.cc.

27 {
28 }

Member Function Documentation

virtual void PhysicsTools::TrainProcessor::cleanup ( void  )
inlinevirtual

Definition at line 65 of file TrainProcessor.h.

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

65 {}
virtual void PhysicsTools::TrainProcessor::configure ( XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *  config)
inlinevirtual

Definition at line 51 of file TrainProcessor.h.

51 {}
void PhysicsTools::TrainProcessor::doTrainBegin ( )

Definition at line 30 of file TrainProcessor.cc.

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

31 {
32  bool booked = false;
33  unsigned int nBins = 50;
34 
35  if (!monitoring) {
36  const char *source = getName();
37  if (source) {
38  monitoring = trainer->bookMonitor(name + "_" + source);
39  monModule = trainer->bookMonitor(std::string("input_") +
40  source);
41  } else {
42  monModule = trainer->bookMonitor("output");
43  nBins = 400;
44  }
45 
46  booked = monModule != 0;
47  }
48 
49  if (booked) {
50  std::vector<SourceVariable*> inputs = getInputs().get();
51  for(std::vector<SourceVariable*>::const_iterator iter =
52  inputs.begin(); iter != inputs.end(); ++iter) {
53 
54  SourceVariable *var = *iter;
55  std::string name =
56  (const char*)var->getSource()->getName()
57  + std::string("_")
58  + (const char*)var->getName();
59 
60  SigBkg pair;
61  pair.entries[0] = pair.entries[1] = 0;
62  pair.histo[0] = monModule->book<TH1F>(name + "_bkg",
63  (name + "_bkg").c_str(),
64  (name + " background").c_str(), nBins, 0, 0);
65  pair.histo[1] = monModule->book<TH1F>(name + "_sig",
66  (name + "_sig").c_str(),
67  (name + " signal").c_str(), nBins, 0, 0);
68  pair.underflow[0] = pair.underflow[1] = 0.0;
69  pair.overflow[0] = pair.overflow[1] = 0.0;
70 
71  pair.sameBinning = true; // use as default
72  if (monitoring) {
75  } else {
76  pair.min = -99999.0;
77  pair.max = +99999.0;
78  }
79 
80  monHistos.push_back(pair);
81  }
82  }
83 
84  trainBegin();
85 }
const SourceVariableSet & getInputs() const
Definition: Source.h:26
const double infinity
std::vector< SourceVariable * > get(bool withMagic=false) const
SourceVariableSet inputs
Definition: Source.h:39
void book(const std::string &name, T *object)
TrainerMonitoring::Module * bookMonitor(const std::string &name)
Definition: MVATrainer.cc:710
AtomicId getName() const
Definition: Source.h:19
std::vector< SigBkg > monHistos
void PhysicsTools::TrainProcessor::doTrainData ( const std::vector< double > *  values,
bool  target,
double  weight,
bool  train,
bool  test 
)

Definition at line 87 of file TrainProcessor.cc.

References min, monHistos, monModule, filterCSVwithJSON::target, testData(), trainData(), relativeConstraints::value, and CommonMethods::weight().

90 {
91  if (monModule && test) {
92  for(std::vector<SigBkg>::iterator iter = monHistos.begin();
93  iter != monHistos.end(); ++iter) {
94  const std::vector<double> &vals =
95  values[iter - monHistos.begin()];
96  for(std::vector<double>::const_iterator value =
97  vals.begin(); value != vals.end(); ++value) {
98 
99  iter->entries[target]++;
100 
101  if (*value <= iter->min) {
102  iter->underflow[target] += weight;
103  continue;
104  } else if (*value >= iter->max) {
105  iter->overflow[target] += weight;
106  continue;
107  }
108 
109  iter->histo[target]->Fill(*value, weight);
110 
111  if (iter->sameBinning)
112  iter->histo[!target]->Fill(*value, 0);
113  }
114  }
115  }
116 
117  if (train)
119  if (test)
120  testData(values, target, weight, train);
121 }
#define min(a, b)
Definition: mlp_lapack.h:161
virtual void testData(const std::vector< double > *values, bool target, double weight, bool trainedOn)
virtual void trainData(const std::vector< double > *values, bool target, double weight)
std::vector< SigBkg > monHistos
void PhysicsTools::TrainProcessor::doTrainEnd ( )

Definition at line 123 of file TrainProcessor.cc.

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

124 {
125  trainEnd();
126 
127  if (monModule) {
128  for(std::vector<SigBkg>::const_iterator iter =
129  monHistos.begin(); iter != monHistos.end(); ++iter) {
130 
131  for(unsigned int i = 0; i < 2; i++) {
132  Int_t oBin = iter->histo[i]->GetNbinsX() + 1;
133  iter->histo[i]->SetBinContent(0,
134  iter->histo[i]->GetBinContent(0) +
135  iter->underflow[i]);
136  iter->histo[i]->SetBinContent(oBin,
137  iter->histo[i]->GetBinContent(oBin) +
138  iter->overflow[i]);
139  iter->histo[i]->SetEntries(iter->entries[i]);
140  }
141  }
142 
143  monModule = 0;
144  }
145 }
int i
Definition: DBlmapReader.cc:9
std::vector< SigBkg > monHistos
bool PhysicsTools::TrainProcessor::exists ( const std::string &  name)
inlineprotected

Definition at line 83 of file TrainProcessor.h.

84  { return boost::filesystem::exists(name.c_str()); }
virtual Calibration::VarProcessor* PhysicsTools::TrainProcessor::getCalibration ( ) const
inlinevirtual

Definition at line 56 of file TrainProcessor.h.

56 { return 0; }
virtual Variable::Flags PhysicsTools::TrainProcessor::getDefaultFlags ( ) const
inlinevirtual
const char* PhysicsTools::TrainProcessor::getId ( ) const
inline

Definition at line 67 of file TrainProcessor.h.

References name.

67 { return name.c_str(); }
virtual bool PhysicsTools::TrainProcessor::load ( )
inlinevirtual

Definition at line 63 of file TrainProcessor.h.

63 { return true; }
virtual void PhysicsTools::TrainProcessor::passFlags ( const std::vector< Variable::Flags > &  flags)
inlinevirtual

Definition at line 54 of file TrainProcessor.h.

54 {}
virtual void* PhysicsTools::TrainProcessor::requestObject ( const std::string &  name) const
inlineprotectedvirtual

Definition at line 80 of file TrainProcessor.h.

81  { return 0; }
virtual void PhysicsTools::TrainProcessor::save ( )
inlinevirtual

Definition at line 64 of file TrainProcessor.h.

64 {}
virtual void PhysicsTools::TrainProcessor::testData ( const std::vector< double > *  values,
bool  target,
double  weight,
bool  trainedOn 
)
inlineprotectedvirtual

Definition at line 76 of file TrainProcessor.h.

Referenced by doTrainData().

77  {}
virtual void PhysicsTools::TrainProcessor::trainBegin ( )
inlineprotectedvirtual

Definition at line 73 of file TrainProcessor.h.

Referenced by doTrainBegin().

73 {}
virtual void PhysicsTools::TrainProcessor::trainData ( const std::vector< double > *  values,
bool  target,
double  weight 
)
inlineprotectedvirtual

Definition at line 74 of file TrainProcessor.h.

Referenced by doTrainData().

75  {}
virtual void PhysicsTools::TrainProcessor::trainEnd ( )
inlineprotectedvirtual

Definition at line 78 of file TrainProcessor.h.

References PhysicsTools::Source::trained.

Referenced by doTrainEnd().

78 { trained = true; }

Member Data Documentation

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

Definition at line 101 of file TrainProcessor.h.

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

Monitoring* PhysicsTools::TrainProcessor::monitoring
protected

Definition at line 88 of file TrainProcessor.h.

Referenced by doTrainBegin().

Monitoring* PhysicsTools::TrainProcessor::monModule
private

Definition at line 102 of file TrainProcessor.h.

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

std::string PhysicsTools::TrainProcessor::name
protected
MVATrainer* PhysicsTools::TrainProcessor::trainer
protected

Definition at line 87 of file TrainProcessor.h.

Referenced by doTrainBegin().