CMS 3D CMS Logo

Public Member Functions | Private Attributes

PhysicsTools::TreeTrainer Class Reference

#include <TreeTrainer.h>

List of all members.

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 ()
void train (MVATrainer *trainer)
Calibration::MVAComputertrain (const std::string &trainDescription, double crossValidation=0.0, bool useXSLT=false)
 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.

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

Definition at line 23 of file TreeTrainer.cc.

References addTree().

{
        addTree(tree, -1, weight);
}
PhysicsTools::TreeTrainer::TreeTrainer ( TTree *  signal,
TTree *  background,
double  weight = -1.0 
)

Definition at line 28 of file TreeTrainer.cc.

References addTree().

{
        addTree(signal, true, weight);
        addTree(background, false, weight);
}
PhysicsTools::TreeTrainer::~TreeTrainer ( )

Definition at line 34 of file TreeTrainer.cc.

References reset().

{
        reset();
}

Member Function Documentation

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

Definition at line 82 of file TreeTrainer.cc.

References readers.

Referenced by addTree().

{
        readers.push_back(reader);
}
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, and weights.

Referenced by TreeTrainer().

{
        static const bool targets[2] = { true, false };

        TreeReader reader(tree, false, weight > 0.0);

        if (target >= 0) {
                if (tree->GetBranch("__TARGET__"))
                        throw cms::Exception("TreeTrainer")
                                << "__TARGET__ branch already present in file."
                                << std::endl;

                reader.addSingle(MVATrainer::kTargetId, &targets[!target]);
        }

        if (weight > 0.0) {
                double *ptr = new double(weight);
                weights.push_back(ptr);
                reader.addSingle(MVATrainer::kWeightId, ptr);
        }

        addReader(reader);
}
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().

{
        Calibration::MVAComputer *calib = trainer->getTrainCalibration();   
        if (!calib)
                return true;

        MVAComputer computer(calib, true);

        std::for_each(readers.begin(), readers.end(),
                      std::bind2nd(std::mem_fun_ref(&TreeReader::loop),
                                   &computer));

        return false;
}
void PhysicsTools::TreeTrainer::reset ( void  )

Definition at line 50 of file TreeTrainer.cc.

References readers, and weights.

Referenced by ~TreeTrainer().

{
        readers.clear();
        std::for_each(weights.begin(), weights.end(),
                      std::ptr_fun(&::operator delete));
        weights.clear();
}
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().

{
        MVATrainer trainer(trainFile, useXSLT);
        trainer.setMonitoring(true);
        trainer.setCrossValidation(crossValidation);
        train(&trainer);
        return trainer.getCalibration();
}
void PhysicsTools::TreeTrainer::train ( MVATrainer trainer)

Definition at line 102 of file TreeTrainer.cc.

References iteration().

{
        while(!iteration(trainer));
}

Member Data Documentation

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().