CMS 3D CMS Logo

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

#include <TreeTrainer.h>

Public Member Functions

void addReader (const TreeReader &reader)
 
void addTree (TTree *tree, int target=-1, double weight=-1.0)
 
bool iteration (MVATrainer *trainer)
 
void reset ()
 
Calibration::MVAComputertrain (const std::string &trainDescription, double crossValidation=0.0, bool useXSLT=false)
 
void train (MVATrainer *trainer)
 
 TreeTrainer ()
 
 TreeTrainer (TTree *tree, double weight=-1.0)
 
 TreeTrainer (TTree *signal, TTree *background, double weight=-1.0)
 
 ~TreeTrainer ()
 

Private Attributes

std::vector< TreeReaderreaders
 
std::vector< double * > weights
 

Detailed Description

Definition at line 18 of file TreeTrainer.h.

Constructor & Destructor Documentation

PhysicsTools::TreeTrainer::TreeTrainer ( )

Definition at line 19 of file TreeTrainer.cc.

20 {
21 }
PhysicsTools::TreeTrainer::TreeTrainer ( TTree *  tree,
double  weight = -1.0 
)

Definition at line 23 of file TreeTrainer.cc.

References addTree().

24 {
25  addTree(tree, -1, weight);
26 }
void addTree(TTree *tree, int target=-1, double weight=-1.0)
Definition: TreeTrainer.cc:58
PhysicsTools::TreeTrainer::TreeTrainer ( TTree *  signal,
TTree *  background,
double  weight = -1.0 
)

Definition at line 28 of file TreeTrainer.cc.

References addTree().

29 {
30  addTree(signal, true, weight);
31  addTree(background, false, weight);
32 }
void addTree(TTree *tree, int target=-1, double weight=-1.0)
Definition: TreeTrainer.cc:58
PhysicsTools::TreeTrainer::~TreeTrainer ( )

Definition at line 34 of file TreeTrainer.cc.

References reset().

35 {
36  reset();
37 }

Member Function Documentation

void PhysicsTools::TreeTrainer::addReader ( const TreeReader reader)

Definition at line 82 of file TreeTrainer.cc.

References readers.

Referenced by addTree().

83 {
84  readers.push_back(reader);
85 }
std::vector< TreeReader > readers
Definition: TreeTrainer.h:40
void PhysicsTools::TreeTrainer::addTree ( TTree *  tree,
int  target = -1,
double  weight = -1.0 
)

Definition at line 58 of file TreeTrainer.cc.

References addReader(), PhysicsTools::TreeReader::addSingle(), PhysicsTools::MVATrainer::kTargetId, PhysicsTools::MVATrainer::kWeightId, matplotRender::reader, dqmd_manager::targets, and weights.

Referenced by TreeTrainer().

59 {
60  static const bool targets[2] = { true, false };
61 
62  TreeReader reader(tree, false, weight > 0.0);
63 
64  if (target >= 0) {
65  if (tree->GetBranch("__TARGET__"))
66  throw cms::Exception("TreeTrainer")
67  << "__TARGET__ branch already present in file."
68  << std::endl;
69 
70  reader.addSingle(MVATrainer::kTargetId, &targets[!target]);
71  }
72 
73  if (weight > 0.0) {
74  double *ptr = new double(weight);
75  weights.push_back(ptr);
76  reader.addSingle(MVATrainer::kWeightId, ptr);
77  }
78 
80 }
static const AtomicId kTargetId
Definition: MVATrainer.h:59
static const AtomicId kWeightId
Definition: MVATrainer.h:60
std::vector< double * > weights
Definition: TreeTrainer.h:42
void addReader(const TreeReader &reader)
Definition: TreeTrainer.cc:82
bool PhysicsTools::TreeTrainer::iteration ( MVATrainer trainer)

Definition at line 87 of file TreeTrainer.cc.

References calib, PhysicsTools::MVATrainer::getTrainCalibration(), PhysicsTools::TreeReader::loop(), and readers.

Referenced by train().

88 {
89  Calibration::MVAComputer *calib = trainer->getTrainCalibration();
90  if (!calib)
91  return true;
92 
93  MVAComputer computer(calib, true);
94 
95  std::for_each(readers.begin(), readers.end(),
96  std::bind2nd(std::mem_fun_ref(&TreeReader::loop),
97  &computer));
98 
99  return false;
100 }
MVATrainerComputer * calib
Definition: MVATrainer.cc:64
std::vector< TreeReader > readers
Definition: TreeTrainer.h:40
uint64_t loop(const MVAComputer *mva)
Definition: TreeReader.cc:298
void PhysicsTools::TreeTrainer::reset ( void  )

Definition at line 50 of file TreeTrainer.cc.

References readers, and weights.

Referenced by ~TreeTrainer().

51 {
52  readers.clear();
53  std::for_each(weights.begin(), weights.end(),
54  std::ptr_fun(&::operator delete));
55  weights.clear();
56 }
std::vector< TreeReader > readers
Definition: TreeTrainer.h:40
std::vector< double * > weights
Definition: TreeTrainer.h:42
Calibration::MVAComputer * PhysicsTools::TreeTrainer::train ( const std::string &  trainDescription,
double  crossValidation = 0.0,
bool  useXSLT = false 
)

Definition at line 39 of file TreeTrainer.cc.

References PhysicsTools::MVATrainer::getCalibration(), PhysicsTools::MVATrainer::setCrossValidation(), and PhysicsTools::MVATrainer::setMonitoring().

42 {
43  MVATrainer trainer(trainFile, useXSLT);
44  trainer.setMonitoring(true);
45  trainer.setCrossValidation(crossValidation);
46  train(&trainer);
47  return trainer.getCalibration();
48 }
Calibration::MVAComputer * train(const std::string &trainDescription, double crossValidation=0.0, bool useXSLT=false)
Definition: TreeTrainer.cc:39
void PhysicsTools::TreeTrainer::train ( MVATrainer trainer)

Definition at line 102 of file TreeTrainer.cc.

References iteration().

103 {
104  while(!iteration(trainer));
105 }
bool iteration(MVATrainer *trainer)
Definition: TreeTrainer.cc:87

Member Data Documentation

std::vector<TreeReader> PhysicsTools::TreeTrainer::readers
private

Definition at line 40 of file TreeTrainer.h.

Referenced by addReader(), iteration(), and reset().

std::vector<double*> PhysicsTools::TreeTrainer::weights
private

Definition at line 42 of file TreeTrainer.h.

Referenced by addTree(), and reset().