#include <algorithm>
#include "Riostream.h"
#include "TMVA/DecisionTreeNode.h"
#include "TMVA/Tools.h"
#include "TMVA/Event.h"
using std::string;
ClassImp(TMVA::DecisionTreeNode)
;
TMVA::DecisionTreeNode::DecisionTreeNode()
: TMVA::Node(),
fCutValue(0),
fCutType ( kTRUE ),
fSelector ( -1 ),
fNSigEvents ( 0 ),
fNBkgEvents ( 0 ),
fNEvents ( -1 ),
fSeparationIndex (-1 ),
fSeparationGain ( -1 ),
fNodeType (-99 ),
fSequence ( 0 )
{
}
TMVA::DecisionTreeNode::DecisionTreeNode(TMVA::Node* p, char pos)
: TMVA::Node(p, pos),
fCutValue(0),
fCutType ( kTRUE ),
fSelector ( -1 ),
fNSigEvents ( 0 ),
fNBkgEvents ( 0 ),
fNEvents ( -1 ),
fSeparationIndex (-1 ),
fSeparationGain ( -1 ),
fNodeType (-99 ),
fSequence ( 0 )
{
if (pos == 'r' ){
ULong_t tmp =1; for (UInt_t i=1; i<this->GetDepth(); i++) {tmp *= 2; }
fSequence = ((DecisionTreeNode*)p)->GetSequence() + tmp;
} else {
fSequence = ((DecisionTreeNode*)p)->GetSequence();
}
}
TMVA::DecisionTreeNode::DecisionTreeNode(const TMVA::DecisionTreeNode &n,
DecisionTreeNode* parent)
: TMVA::Node(n),
fCutValue( n.fCutValue ),
fCutType ( n.fCutType ),
fSelector ( n.fSelector ),
fNSigEvents ( n.fNSigEvents ),
fNBkgEvents ( n.fNBkgEvents ),
fNEvents ( n.fNEvents ),
fSeparationIndex ( n.fSeparationIndex ),
fSeparationGain ( n.fSeparationGain ),
fNodeType ( n.fNodeType ),
fSequence ( n.fSequence )
{
this->SetParent( parent );
if (n.GetLeft() == 0 ) this->SetLeft(NULL);
else this->SetLeft( new DecisionTreeNode( *((DecisionTreeNode*)(n.GetLeft())),this));
if (n.GetRight() == 0 ) this->SetRight(NULL);
else this->SetRight( new DecisionTreeNode( *((DecisionTreeNode*)(n.GetRight())),this));
}
Bool_t TMVA::DecisionTreeNode::GoesRight(const TMVA::Event & e) const
{
Bool_t result;
result = (e.GetVal(this->GetSelector()) > this->GetCutValue() );
if (fCutType == kTRUE) return result;
else return !result;
}
Bool_t TMVA::DecisionTreeNode::GoesLeft(const TMVA::Event & e) const
{
if (!this->GoesRight(e)) return kTRUE;
else return kFALSE;
}
Double_t TMVA::DecisionTreeNode::GetSoverSB( void ) const
{
return this->GetNSigEvents() / ( this->GetNSigEvents() + this->GetNBkgEvents());
}
Double_t TMVA::DecisionTreeNode::GetPurity( void ) const
{
Double_t p = this->GetNSigEvents() / ( this->GetNSigEvents() + this->GetNBkgEvents());
p = p>0.5 ? p : 1-p ;
return p;
}
void TMVA::DecisionTreeNode::Print(ostream& os) const
{
os << "< *** " <<endl;
os << " d: " << this->GetDepth()
<< " seq: " << this->GetSequence()
<< " ivar: " << this->GetSelector()
<< " cut: " << this->GetCutValue()
<< " cType: " << this->GetCutType()
<< " s: " << this->GetNSigEvents()
<< " b: " << this->GetNBkgEvents()
<< " nEv: " << this->GetNEvents()
<< " sepI: " << this->GetSeparationIndex()
<< " sepG: " << this->GetSeparationGain()
<< " nType: " << this->GetNodeType()
<<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::DecisionTreeNode::PrintRec(ostream& os) const
{
os << this->GetDepth()
<< " " << this->GetPos()
<< " seq: " << this->GetSequence()
<< " ivar: " << this->GetSelector()
<< " cut: " << this->GetCutValue()
<< " cType: " << this->GetCutType()
<< " s: " << this->GetNSigEvents()
<< " b: " << this->GetNBkgEvents()
<< " nEv: " << this->GetNEvents()
<< " sepI: " << this->GetSeparationIndex()
<< " sepG: " << this->GetSeparationGain()
<< " nType: " << this->GetNodeType()
<<endl;
if(this->GetLeft() != NULL)this->GetLeft()->PrintRec(os) ;
if(this->GetRight() != NULL)this->GetRight()->PrintRec(os);
}
void TMVA::DecisionTreeNode::ReadRec(istream& is, char &pos, UInt_t &depth,
TMVA::Node* parent )
{
string tmp;
Double_t dtmp1, dtmp2, dtmp3, dtmp4, dtmp5, dtmp6, dtmp7;
UInt_t itmp;
Int_t itmp1, itmp2;
ULong_t lseq;
if (parent==NULL) {
is >> itmp >> pos ;
this->SetPos(pos);
} else {
this->SetPos(pos);
}
is >> tmp >> lseq
>> tmp >> itmp1 >> tmp >> dtmp1 >> tmp >> dtmp2 >> tmp >> dtmp3
>> tmp >> dtmp4 >> tmp >> dtmp5 >> tmp >> dtmp6
>> tmp >> dtmp7 >> tmp >> itmp2 ;
this->SetSelector((UInt_t)itmp1);
this->SetCutValue(dtmp1);
this->SetCutType(dtmp2);
this->SetNSigEvents(dtmp3);
this->SetNBkgEvents(dtmp4);
this->SetNEvents(dtmp5);
this->SetSeparationIndex(dtmp6);
this->SetSeparationGain(dtmp7);
this->SetNodeType(itmp2);
this->SetSequence(lseq);
UInt_t nextDepth;
char nextPos;
is >> itmp1 >> nextPos ;
nextDepth = UInt_t(itmp1);
if ( UInt_t(nextDepth) == this->GetDepth()+1){
if (nextPos=='l') {
this->SetLeft(new TMVA::DecisionTreeNode(this,'l'));
this->GetLeft()->ReadRec(is,nextPos,nextDepth,this);
}
}
if ( UInt_t(nextDepth) == this->GetDepth()+1){
if (nextPos=='r') {
this->SetRight(new TMVA::DecisionTreeNode(this,'r'));
this->GetRight()->ReadRec(is,nextPos,nextDepth,this);
}
}
pos = nextPos;
depth= nextDepth;
}
void TMVA::DecisionTreeNode::ClearNodeAndAllDaughters()
{
fNSigEvents=0;
fNBkgEvents=0;
fNEvents = 0;
fSeparationIndex=-1;
fSeparationGain=-1;
if(this->GetLeft() != NULL)
((DecisionTreeNode*)(this->GetLeft()))->ClearNodeAndAllDaughters();
if(this->GetRight() != NULL)
((DecisionTreeNode*)(this->GetRight()))->ClearNodeAndAllDaughters();
}
ROOT page - Class index - Class Hierarchy - Top of the page
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.