CMS 3D CMS Logo

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 }
Definition: weight.py:1
void addTree(TTree *tree, int target=-1, double weight=-1.0)
Definition: TreeTrainer.cc:58
Definition: tree.py:1
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 }
Definition: weight.py:1
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, 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 }
Definition: weight.py:1
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
Definition: tree.py:1
bool PhysicsTools::TreeTrainer::iteration ( MVATrainer trainer)

Definition at line 87 of file TreeTrainer.cc.

References caloDeepCSVTagInfos_cfi::computer, PhysicsTools::MVATrainer::getTrainCalibration(), AlCaHLTBitMon_ParallelJobs::p, 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  for( auto && p : readers ) p.loop(&computer);
96 
97  return false;
98 }
std::vector< TreeReader > readers
Definition: TreeTrainer.h:40
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 100 of file TreeTrainer.cc.

References iteration().

101 {
102  while(!iteration(trainer));
103 }
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().