* *
* File and Version Information: *
* $Id: BinarySearchTree.cxx,v 1.3 2006/05/23 19:35:06 brun Exp $
**********************************************************************************/
#include "TMatrixDBase.h"
#include "TObjString.h"
#include "TTree.h"
#include "Riostream.h"
#include <stdexcept>
#ifndef ROOT_TMVA_Tools
#include "TMVA/Tools.h"
#endif
#ifndef ROOT_TMVA_BinarySearchTree
#include "TMVA/BinarySearchTree.h"
#endif
ClassImp(TMVA::BinarySearchTree)
using std::vector;
TMVA::BinarySearchTree::BinarySearchTree( void )
{
}
TMVA::BinarySearchTree::~BinarySearchTree( void )
{
}
Int_t TMVA::BinarySearchTree::Fill( TTree* theTree, vector<TString>* theVars,
Int_t theType )
{
Int_t nevents=0;
fPeriode = (*theVars).size();
Int_t n=theTree->GetEntries();
for (Int_t ievt=0; ievt<n; ievt++) {
if (theType == -1 || (int)TMVA::Tools::GetValue( theTree, ievt, "type" ) == theType) {
TMVA::Event *e=new TMVA::Event(theTree, ievt, theVars);
this->Insert( e , kTRUE);
nevents++;
}
}
if (nevents <= 0) {
cerr << "--- TMVA::BinarySearchTree::BinarySearchTree::Fill( TTree* ... Error: number of events "
<< "in tree is zero: " << nevents << endl;
throw std::invalid_argument( "Abort" );
}
return nevents;
}
Int_t TMVA::BinarySearchTree::Fill( vector<TMVA::Event*> theTree, vector<Int_t> theVars,
Int_t theType )
{
fPeriode = (theVars).size();
Int_t nevents = 0;
Int_t n=theTree.size();
for (Int_t ievt=0; ievt<n; ievt++) {
if (theType == -1 || theTree[ievt]->GetType() == theType) {
TMVA::Event *e=new TMVA::Event();
for (Int_t j=0; j<fPeriode; j++){
e->Insert(theTree[ievt]->GetData(theVars[j]) );
}
e->SetWeight(theTree[ievt]->GetWeight() );
this->Insert( e , kTRUE);
nevents++;
}
}
if (nevents <= 0) {
cout << "--- TMVA::BinarySearchTree::BinarySearchTree:Fill(std::vector<TMVA::Event*> ... "
<< "Error: number of events "
<< "that got actually filled into the tree is zero: " << nevents << endl;
exit(1);
}
return nevents;
}
Int_t TMVA::BinarySearchTree::Fill( vector<TMVA::Event*> theTree, Int_t theType )
{
Int_t n=theTree.size();
Int_t nevents = 0;
for (Int_t ievt=0; ievt<n; ievt++) {
if (theType == -1 || theTree[ievt]->GetType() == theType) {
this->Insert( theTree[ievt] , kFALSE);
nevents++;
}
}
return nevents;
}
Double_t TMVA::BinarySearchTree::SearchVolume( TMVA::Volume* volume,
std::vector<TMVA::Event*>* events )
{
return SearchVolume( this->GetRoot(), volume, 0, events );
}
Double_t TMVA::BinarySearchTree::SearchVolume( TMVA::Node* t, TMVA::Volume* volume, Int_t depth,
std::vector<TMVA::Event*>* events )
{
if (t==NULL) return 0;
Double_t count = 0.0;
if (InVolume( t->GetData(), volume )) {
count += t->GetData()->GetWeight();
if (NULL != events) events->push_back( t->GetData() );
}
if (t->GetLeft()==NULL && t->GetRight()==NULL) return count;
Bool_t tl, tr;
Int_t d = depth%this->GetPeriode();
if (d != t->GetSelector()) {
cout << "Fatal error in TMVA::BinarySearchTree::SearchVolume: selector in Searchvolume "
<< d << " != " << "node "<< t->GetSelector() << " ==> abort" << endl;
exit(1);
}
tl = (*(volume->fLower))[d] < (t->GetData()->GetData(d));
tr = (*(volume->fUpper))[d] >= (t->GetData()->GetData(d));
if (tl) count += SearchVolume( t->GetLeft(), volume, (depth+1), events );
if (tr) count += SearchVolume( t->GetRight(), volume, (depth+1), events );
return count;
}
Bool_t TMVA::BinarySearchTree::InVolume( TMVA::Event* event, TMVA::Volume* volume ) const
{
Bool_t result = false;
for (Int_t ivar=0; ivar< fPeriode; ivar++) {
result = ( (*(volume->fLower))[ivar] < ((event->GetData(ivar))) &&
(*(volume->fUpper))[ivar] >= ((event->GetData(ivar))) );
if (!result) break;
}
return result;
}
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.