54 ClassImp(TMVA::BinarySearchTreeNode);
59 TMVA::BinarySearchTreeNode::BinarySearchTreeNode(
const Event* e, UInt_t )
61 fEventV ( std::vector<Float_t>() ),
62 fTargets ( std::vector<Float_t>() ),
63 fWeight ( e==0?0:e->GetWeight() ),
64 fClass ( e==0?0:e->GetClass() ),
68 for (UInt_t ivar=0; ivar<e->GetNVariables(); ivar++) fEventV.push_back(e->GetValue(ivar));
69 for (std::vector<Float_t>::const_iterator it = e->GetTargets().begin(); it < e->GetTargets().end(); ++it ) {
70 fTargets.push_back( (*it) );
78 TMVA::BinarySearchTreeNode::BinarySearchTreeNode( BinarySearchTreeNode* parent,
char pos ) :
79 TMVA::Node(parent,pos),
80 fEventV ( std::vector<Float_t>() ),
81 fTargets ( std::vector<Float_t>() ),
92 TMVA::BinarySearchTreeNode::BinarySearchTreeNode (
const BinarySearchTreeNode &n,
93 BinarySearchTreeNode* parent ) :
95 fEventV ( n.fEventV ),
96 fTargets ( n.fTargets ),
97 fWeight ( n.fWeight ),
99 fSelector( n.fSelector )
101 this->SetParent( parent );
102 if (n.GetLeft() == 0 ) this->SetLeft(NULL);
103 else this->SetLeft(
new BinarySearchTreeNode( *((BinarySearchTreeNode*)(n.GetLeft())),
this));
105 if (n.GetRight() == 0 ) this->SetRight(NULL);
106 else this->SetRight(
new BinarySearchTreeNode( *((BinarySearchTreeNode*)(n.GetRight())),
this));
113 TMVA::BinarySearchTreeNode::~BinarySearchTreeNode()
120 Bool_t TMVA::BinarySearchTreeNode::GoesRight(
const TMVA::Event& e )
const
122 if (e.GetValue(fSelector) > GetEventV()[fSelector])
return true;
129 Bool_t TMVA::BinarySearchTreeNode::GoesLeft(
const TMVA::Event& e)
const
131 if (e.GetValue(fSelector) <= GetEventV()[fSelector])
return true;
139 Bool_t TMVA::BinarySearchTreeNode::EqualsMe(
const TMVA::Event& e)
const
141 Bool_t result =
true;
142 for (UInt_t i=0; i<GetEventV().size(); i++) {
143 result&= (e.GetValue(i) == GetEventV()[i]);
151 void TMVA::BinarySearchTreeNode::Print( std::ostream& os )
const
153 os <<
"< *** " << std::endl <<
" node.Data: ";
154 std::vector<Float_t>::const_iterator it=fEventV.begin();
155 os << fEventV.size() <<
" vars: ";
156 for (;it!=fEventV.end(); ++it) os <<
" " << std::setw(10) << *it;
157 os <<
" EvtWeight " << std::setw(10) << fWeight;
158 os << std::setw(10) <<
"Class: " << GetClass() << std::endl;
160 os <<
"Selector: " << this->GetSelector() <<std::endl;
161 os <<
"My address is " << long(
this) <<
", ";
162 if (this->GetParent() != NULL) os <<
" parent at addr: " << long(this->GetParent()) ;
163 if (this->GetLeft() != NULL) os <<
" left daughter at addr: " << long(this->GetLeft());
164 if (this->GetRight() != NULL) os <<
" right daughter at addr: " << long(this->GetRight()) ;
166 os <<
" **** > "<< std::endl;
172 void TMVA::BinarySearchTreeNode::PrintRec( std::ostream& os )
const
174 os << this->GetDepth() <<
" " << this->GetPos() <<
" " << this->GetSelector()
175 <<
" data: " << std::endl;
176 std::vector<Float_t>::const_iterator it=fEventV.begin();
177 os << fEventV.size() <<
" vars: ";
178 for (;it!=fEventV.end(); ++it) os <<
" " << std::setw(10) << *it;
179 os <<
" EvtWeight " << std::setw(10) << fWeight;
180 os << std::setw(10) <<
"Class: " << GetClass() << std::endl;
182 if (this->GetLeft() != NULL)this->GetLeft()->PrintRec(os) ;
183 if (this->GetRight() != NULL)this->GetRight()->PrintRec(os);
189 Bool_t TMVA::BinarySearchTreeNode::ReadDataRecord( std::istream& is, UInt_t )
193 UInt_t depth, selIdx, nvar;
200 if ( itmp==-1 ) {
return kFALSE; }
204 this->SetDepth(depth);
206 this->SetSelector(selIdx);
212 for (UInt_t ivar=0; ivar<nvar; ivar++) {
213 is >> evtValFloat; fEventV.push_back(evtValFloat);
215 is >> tmp >> fWeight;
217 fClass = (sigbkgd==
"S" || sigbkgd==
"Signal")?0:1;
225 void TMVA::BinarySearchTreeNode::ReadAttributes(
void* node, UInt_t )
227 gTools().ReadAttr(node,
"selector", fSelector );
228 gTools().ReadAttr(node,
"weight", fWeight );
230 gTools().ReadAttr(node,
"type", sb);
231 if (sb==
"Signal" || sb==
"0")
237 gTools().ReadAttr(node,
"NVars",nvars);
238 fEventV.resize(nvars);
245 void TMVA::BinarySearchTreeNode::AddAttributesToNode(
void* node)
const {
246 gTools().AddAttr(node,
"selector", fSelector );
247 gTools().AddAttr(node,
"weight", fWeight );
249 gTools().AddAttr(node,
"type", GetClass());
250 gTools().AddAttr(node,
"NVars", fEventV.size());
257 void TMVA::BinarySearchTreeNode::AddContentToNode( std::stringstream& s )
const
259 std::ios_base::fmtflags ff = s.flags();
261 for (UInt_t i=0; i<fEventV.size(); i++) s << std::scientific <<
" " << fEventV[i];
262 for (UInt_t i=0; i<fTargets.size(); i++) s << std::scientific <<
" " << fTargets[i];
268 void TMVA::BinarySearchTreeNode::ReadContent( std::stringstream& s )
271 for (UInt_t i=0; i<fEventV.size(); i++){
275 while (s >> temp) fTargets.push_back(temp);