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 20 of file TrainProcessor.cc.

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

Definition at line 27 of file TrainProcessor.cc.

28 {
29 }

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 31 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, getDQMSummary::iter, PhysicsTools::TrainProcessor::SigBkg::max, PhysicsTools::TrainProcessor::SigBkg::min, monHistos, monitoring, monModule, name, PhysicsTools::TrainProcessor::SigBkg::overflow, PhysicsTools::TrainProcessor::SigBkg::sameBinning, source, AlCaHLTBitMon_QueryRunRegistry::string, trainBegin(), trainer, and PhysicsTools::TrainProcessor::SigBkg::underflow.

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

Definition at line 88 of file TrainProcessor.cc.

References getDQMSummary::iter, min(), monHistos, monModule, filterCSVwithJSON::target, testData(), trainData(), create_public_pileup_plots::vals, relativeConstraints::value, and histoStyle::weight.

91 {
92  if (monModule && test) {
93  for(std::vector<SigBkg>::iterator iter = monHistos.begin();
94  iter != monHistos.end(); ++iter) {
95  const std::vector<double> &vals =
96  values[iter - monHistos.begin()];
97  for(std::vector<double>::const_iterator value =
98  vals.begin(); value != vals.end(); ++value) {
99 
100  iter->entries[target]++;
101 
102  if (*value <= iter->min) {
103  iter->underflow[target] += weight;
104  continue;
105  } else if (*value >= iter->max) {
106  iter->overflow[target] += weight;
107  continue;
108  }
109 
110  iter->histo[target]->Fill(*value, weight);
111 
112  if (iter->sameBinning)
113  iter->histo[!target]->Fill(*value, 0);
114  }
115  }
116  }
117 
118  if (train)
120  if (test)
121  testData(values, target, weight, train);
122 }
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)
T min(T a, T b)
Definition: MathUtil.h:58
std::vector< SigBkg > monHistos
int weight
Definition: histoStyle.py:50
void PhysicsTools::TrainProcessor::doTrainEnd ( )

Definition at line 124 of file TrainProcessor.cc.

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

125 {
126  trainEnd();
127 
128  if (monModule) {
129  for(std::vector<SigBkg>::const_iterator iter =
130  monHistos.begin(); iter != monHistos.end(); ++iter) {
131 
132  for(unsigned int i = 0; i < 2; i++) {
133  Int_t oBin = iter->histo[i]->GetNbinsX() + 1;
134  iter->histo[i]->SetBinContent(0,
135  iter->histo[i]->GetBinContent(0) +
136  iter->underflow[i]);
137  iter->histo[i]->SetBinContent(oBin,
138  iter->histo[i]->GetBinContent(oBin) +
139  iter->overflow[i]);
140  iter->histo[i]->SetEntries(iter->entries[i]);
141  }
142  }
143 
144  monModule = 0;
145  }
146 }
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().