#include "TMVA/BinarySearchTreeNode.h"
#include "Riostream.h"
#include <stdexcept>
#include <assert.h>
#include "TMVA/Event.h"
#include "TMVA/MsgLogger.h"
ClassImp(TMVA::BinarySearchTreeNode)
TMVA::BinarySearchTreeNode::BinarySearchTreeNode( Event* e ) :
TMVA::Node(),
fEventV(std::vector<Float_t>()),
fWeight(e==0?0:e->GetWeight()),
fIsSignal(e==0?kTRUE:e->IsSignal()),
fSelector( -1 )
{
if (e!=0)
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()
<< " data: " << endl;
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;
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 ) { delete this; return kFALSE; }
depth = itmp;
is >> pos >> selIdx >> tmp;
this->SetDepth(itmp);
this->SetPos(pos);
this->SetSelector(selIdx);
is >> nvar >> tmp;
fEventV.clear();
for (UInt_t ivar=0; ivar<nvar; ivar++) {
is >> evtValFloat;
fEventV.push_back(evtValFloat);
}
is >> tmp >> fWeight;
is >> sigbkgd;
fIsSignal = (sigbkgd=="Signal");
return kTRUE;
}
void TMVA::BinarySearchTreeNode::ReadRec( istream& is, char &pos, UInt_t &depth,
TMVA::Node* parent )
{
if ( ! ReadDataRecord(is) ) return;
depth = GetDepth();
pos = GetPos();
while( parent!=0 && parent->GetDepth() != GetDepth()-1) parent=parent->GetParent();
if (parent!=0) {
SetParent(parent);
if (GetPos()=='l') parent->SetLeft(this);
if (GetPos()=='r') parent->SetRight(this);
}
char childPos;
UInt_t childDepth;
TMVA::Node * newNode = new TMVA::BinarySearchTreeNode( );
newNode->ReadRec(is, childPos, childDepth, this);
}
Int_t TMVA::BinarySearchTreeNode::GetMemSize() const
{
Int_t size = sizeof(*this);
if (GetLeft() !=0) size += GetLeft()->GetMemSize();
if (GetRight()!=0) size += GetRight()->GetMemSize();
return size;
}
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.