#include <stdexcept>
#include "Riostream.h"
#include "TMVA/BinarySearchTreeNode.h"
#include "TMVA/Event.h"
#include "TMVA/MsgLogger.h"
ClassImp(TMVA::BinarySearchTreeNode)
TMVA::BinarySearchTreeNode::BinarySearchTreeNode( const Event* e ) :
TMVA::Node(),
fWeight(e==0?0:e->GetWeight()),
fIsSignal(e==0?kTRUE:e->IsSignal()),
fSelector( -1 )
{
if (e!=0) {
fEventV.reserve(e->GetNVars());
for (UInt_t ivar=0; ivar<e->GetNVars(); ivar++) fEventV.push_back(e->GetVal(ivar));
}
}
TMVA::BinarySearchTreeNode::BinarySearchTreeNode( BinarySearchTreeNode* parent, char pos ) :
TMVA::Node(parent,pos),
fEventV(std::vector<Float_t>()),
fWeight(0),
fIsSignal(kTRUE),
fSelector( -1 )
{
}
TMVA::BinarySearchTreeNode::BinarySearchTreeNode ( const BinarySearchTreeNode &n,
BinarySearchTreeNode* parent ) :
TMVA::Node(n),
fEventV(n.fEventV),
fWeight(n.fWeight),
fIsSignal(n.fIsSignal),
fSelector (n.fSelector)
{
this->SetParent( parent );
if (n.GetLeft() == 0 ) this->SetLeft(NULL);
else this->SetLeft( new BinarySearchTreeNode( *((BinarySearchTreeNode*)(n.GetLeft())),this));
if (n.GetRight() == 0 ) this->SetRight(NULL);
else this->SetRight( new BinarySearchTreeNode( *((BinarySearchTreeNode*)(n.GetRight())),this));
}
TMVA::BinarySearchTreeNode::~BinarySearchTreeNode()
{
}
Bool_t TMVA::BinarySearchTreeNode::GoesRight( const TMVA::Event& e ) const
{
if (e.GetVal(fSelector) > GetEventV()[fSelector]) return true;
else return false;
}
Bool_t TMVA::BinarySearchTreeNode::GoesLeft(const TMVA::Event& e) const
{
if (e.GetVal(fSelector) <= GetEventV()[fSelector]) return true;
else return false;
}
Bool_t TMVA::BinarySearchTreeNode::EqualsMe(const TMVA::Event& e) const
{
Bool_t result = true;
for (UInt_t i=0; i<GetEventV().size(); i++) {
result&= (e.GetVal(i) == GetEventV()[i]);
}
return result;
}
void TMVA::BinarySearchTreeNode::Print( ostream& os ) const
{
os << "< *** " <<endl << " node.Data: ";
std::vector<Float_t>::const_iterator it=fEventV.begin();
os << fEventV.size() << " vars: ";
for (;it!=fEventV.end(); it++) os << " " << std::setw(10) << *it;
os << " EvtWeight " << std::setw(10) << fWeight;
os << std::setw(10) << (fIsSignal?" Signal":" Background") << endl;
os << "Selector: " << this->GetSelector() <<endl;
os << "My address is " << long(this) << ", ";
if (this->GetParent() != NULL) os << " parent at addr: " << long(this->GetParent()) ;
if (this->GetLeft() != NULL) os << " left daughter at addr: " << long(this->GetLeft());
if (this->GetRight() != NULL) os << " right daughter at addr: " << long(this->GetRight()) ;
os << " **** > "<< endl;
}
void TMVA::BinarySearchTreeNode::PrintRec( ostream& os ) const
{
os << this->GetDepth() << " " << this->GetPos() << " " << this->GetSelector() << endl;
std::vector<Float_t>::const_iterator it=fEventV.begin();
os << fEventV.size();
for (;it!=fEventV.end(); it++) os << " " << std::setw(10) << *it;
os << " w: " << std::setprecision(10) << fWeight;
os << (fIsSignal?" S":" B") << endl;
if (this->GetLeft() != NULL)this->GetLeft()->PrintRec(os) ;
if (this->GetRight() != NULL)this->GetRight()->PrintRec(os);
}
Bool_t TMVA::BinarySearchTreeNode::ReadDataRecord( istream& is )
{
std::string tmp;
UInt_t depth;
char pos;
TString sigbkgd;
Float_t evtValFloat;
UInt_t nvar;
Int_t itmp;
UInt_t selIdx;
is >> itmp;
if (itmp == -1) { return kFALSE; }
depth = itmp;
is >> pos >> selIdx;
this->SetDepth(itmp);
this->SetPos(pos);
this->SetSelector(selIdx);
is >> nvar;
fEventV.clear();
fEventV.reserve(nvar);
for (UInt_t ivar=0; ivar<nvar; ivar++) {
is >> evtValFloat;
fEventV.push_back(evtValFloat);
}
is >> tmp >> fWeight;
is >> sigbkgd;
fIsSignal = (sigbkgd=="S" || sigbkgd=="Signal");
return kTRUE;
}
Last change: Wed Jun 25 08:48:05 2008
Last generated: 2008-06-25 08:48
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.