67 fStatisticsIsValid(
kFALSE ),
79 fPeriod (
b.fPeriod ),
81 fStatisticsIsValid(
kFALSE ),
82 fSumOfWeights(
b.fSumOfWeights ),
86 Log() << kFATAL <<
" Copy constructor not implemented yet " <<
Endl;
94 for(std::vector< std::pair<Double_t, const TMVA::Event*> >::iterator pIt = fNormalizeTreeTable.begin();
95 pIt != fNormalizeTreeTable.end(); ++pIt) {
104 std::string
type(
"");
107 bt->
ReadXML( node, tmva_Version_Code );
117 fStatisticsIsValid =
kFALSE;
119 if (this->GetRoot() == NULL) {
122 this->GetRoot()->SetPos(
's');
123 this->GetRoot()->SetDepth(0);
125 fSumOfWeights =
event->GetWeight();
127 this->SetPeriode(
event->GetNVariables());
131 if (
event->GetNVariables() != (
UInt_t)this->GetPeriode()) {
132 Log() << kFATAL <<
"<Insert> event vector length != Periode specified in Binary Tree" <<
Endl
133 <<
"--- event size: " <<
event->GetNVariables() <<
" Periode: " << this->GetPeriode() <<
Endl
134 <<
"--- and all this when trying filling the "<<fNNodes+1<<
"th Node" <<
Endl;
137 this->Insert(
event, this->GetRoot());
141 if (fCanNormalize) fNormalizeTreeTable.push_back( std::make_pair(0.0,
new const Event(*
event)) );
151 fStatisticsIsValid =
kFALSE;
162 fSumOfWeights +=
event->GetWeight();
179 fSumOfWeights +=
event->GetWeight();
187 else Log() << kFATAL <<
"<Insert> neither left nor right :)" <<
Endl;
195 return this->Search(
event, this->GetRoot() );
220 if (fSumOfWeights <= 0) {
221 Log() << kWARNING <<
"you asked for the SumOfWeights, which is not filled yet"
222 <<
" I call CalcStatistics which hopefully fixes things"
225 if (fSumOfWeights <= 0) Log() << kFATAL <<
" Zero events in your Search Tree" <<
Endl;
227 return fSumOfWeights;
235 if (fSumOfWeights <= 0) {
236 Log() << kWARNING <<
"you asked for the SumOfWeights, which is not filled yet"
237 <<
" I call CalcStatistics which hopefully fixes things"
240 if (fSumOfWeights <= 0) Log() << kFATAL <<
" Zero events in your Search Tree" <<
Endl;
252 fPeriod = theVars.size();
253 return Fill(events, theType);
264 if (fSumOfWeights != 0) {
266 <<
"You are filling a search three that is not empty.. "
267 <<
" do you know what you are doing?"
270 for (
UInt_t ievt=0; ievt<
n; ievt++) {
272 if (theType == -1 || (
Int_t(events[ievt]->GetClass()) == theType) ) {
273 this->Insert( events[ievt] );
274 fSumOfWeights += events[ievt]->GetWeight();
279 return fSumOfWeights;
287 std::vector< std::pair<Double_t, const TMVA::Event*> >::iterator rightBound,
291 if (leftBound == rightBound)
return;
293 if (actDim == fPeriod) actDim = 0;
294 for (std::vector< std::pair<Double_t, const TMVA::Event*> >::iterator i=leftBound; i!=rightBound; ++i) {
295 i->first = i->second->GetValue( actDim );
298 std::sort( leftBound, rightBound );
300 std::vector< std::pair<Double_t, const TMVA::Event*> >::iterator leftTemp = leftBound;
301 std::vector< std::pair<Double_t, const TMVA::Event*> >::iterator rightTemp = rightBound;
306 if (rightTemp == leftTemp ) {
310 if (leftTemp == rightTemp) {
315 std::vector< std::pair<Double_t, const TMVA::Event*> >::iterator mid = leftTemp;
316 std::vector< std::pair<Double_t, const TMVA::Event*> >::iterator midTemp = mid;
318 if (mid!=leftBound)--midTemp;
320 while (mid != leftBound && mid->second->GetValue( actDim ) == midTemp->second->GetValue( actDim )) {
325 Insert( mid->second );
330 NormalizeTree( leftBound, mid, actDim+1 );
334 NormalizeTree( mid, rightBound, actDim+1 );
348 NormalizeTree( fNormalizeTreeTable.begin(), fNormalizeTreeTable.end(), 0 );
361 if (
n != NULL)
delete n;
371 std::vector<const BinarySearchTreeNode*>* events )
373 return SearchVolume( this->GetRoot(), volume, 0, events );
381 std::vector<const BinarySearchTreeNode*>* events )
383 if (t==NULL)
return 0;
388 if (InVolume( st->
GetEventV(), volume )) {
390 if (NULL != events) events->push_back( st );
398 Int_t d = depth%this->GetPeriode();
400 Log() << kFATAL <<
"<SearchVolume> selector in Searchvolume "
406 if (tl) count += SearchVolume( st->
GetLeft(), volume, (depth+1), events );
407 if (tr) count += SearchVolume( st->
GetRight(), volume, (depth+1), events );
419 for (
UInt_t ivar=0; ivar< fPeriod; ivar++) {
421 (*(volume->
fUpper))[ivar] >=
event[ivar] );
432 if (fStatisticsIsValid)
return;
439 for (
Int_t sb=0; sb<2; sb++) {
441 fMeans[sb] = std::vector<Float_t>(fPeriod);
442 fRMS[sb] = std::vector<Float_t>(fPeriod);
443 fMin[sb] = std::vector<Float_t>(fPeriod);
444 fMax[sb] = std::vector<Float_t>(fPeriod);
445 fSum[sb] = std::vector<Double_t>(fPeriod);
446 fSumSq[sb] = std::vector<Double_t>(fPeriod);
447 for (
UInt_t j=0; j<fPeriod; j++) {
448 fMeans[sb][j] = fRMS[sb][j] = fSum[sb][j] = fSumSq[sb][j] = 0;
449 fMin[sb][j] = FLT_MAX;
450 fMax[sb][j] = -FLT_MAX;
454 if (currentNode == NULL)
return;
457 const std::vector<Float_t> & evtVec = currentNode->
GetEventV();
463 fNEventsW[
type] += weight;
464 fSumOfWeights += weight;
466 for (
UInt_t j=0; j<fPeriod; j++) {
468 fSum[
type][j] += val*weight;
469 fSumSq[
type][j] += val*val*weight;
470 if (val < fMin[
type][j]) fMin[
type][j] = val;
471 if (val > fMax[
type][j]) fMax[
type][j] = val;
474 if ( (currentNode->
GetLeft() != NULL) ) CalcStatistics( currentNode->
GetLeft() );
475 if ( (currentNode->
GetRight() != NULL) ) CalcStatistics( currentNode->
GetRight() );
478 for (
Int_t sb=0; sb<2; sb++) {
479 for (
UInt_t j=0; j<fPeriod; j++) {
480 if (fNEventsW[sb] == 0) { fMeans[sb][j] = fRMS[sb][j] = 0;
continue; }
481 fMeans[sb][j] = fSum[sb][j]/fNEventsW[sb];
482 fRMS[sb][j] =
TMath::Sqrt(fSumSq[sb][j]/fNEventsW[sb] - fMeans[sb][j]*fMeans[sb][j]);
485 fStatisticsIsValid =
kTRUE;
498 if (this->GetRoot() == NULL)
return 0;
500 std::queue< std::pair< const BinarySearchTreeNode*, Int_t > > queue;
501 std::pair< const BinarySearchTreeNode*, Int_t > st = std::make_pair( (
const BinarySearchTreeNode*)this->GetRoot(), 0 );
506 while ( !queue.empty() ) {
507 st = queue.front(); queue.pop();
509 if (count == max_points)
512 if (InVolume( st.first->GetEventV(), volume )) {
514 if (NULL != events) events->push_back( st.first );
519 if (
d ==
Int_t(this->GetPeriode()) )
d = 0;
521 if (
d != st.first->GetSelector()) {
522 Log() << kFATAL <<
"<SearchVolume> selector in Searchvolume "
523 <<
d <<
" != " <<
"node "<< st.first->GetSelector() <<
Endl;
526 tl = (*(volume->
fLower))[
d] < st.first->GetEventV()[
d] && st.first->GetLeft() != NULL;
527 tr = (*(volume->
fUpper))[
d] >= st.first->GetEventV()[
d] && st.first->GetRight() != NULL;
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Node for the BinarySearch or Decision Trees.
void SetSelector(Short_t i)
set index of variable used for discrimination at this node
Float_t GetWeight() const
const std::vector< Float_t > & GetEventV() const
Short_t GetSelector() const
return index of variable used for discrimination at this node
A simple Binary search tree including a volume search method.
Int_t SearchVolumeWithMaxLimit(TMVA::Volume *, std::vector< const TMVA::BinarySearchTreeNode * > *events=nullptr, Int_t=-1)
recursively walk through the daughter nodes and add up all weights of events that lie within the give...
BinarySearchTreeNode * Search(Event *event) const
search the tree to find the node matching "event"
Double_t SearchVolume(Volume *, std::vector< const TMVA::BinarySearchTreeNode * > *events=nullptr)
search the whole tree and add up all weights of events that lie within the given volume
void CalcStatistics(TMVA::Node *n=nullptr)
calculate basic statistics (mean, rms for each variable)
void Clear(TMVA::Node *n=nullptr)
clear nodes
Bool_t InVolume(const std::vector< Float_t > &, Volume *) const
test if the data points are in the given volume
virtual ~BinarySearchTree(void)
destructor
Double_t Fill(const std::vector< TMVA::Event * > &events, const std::vector< Int_t > &theVars, Int_t theType=-1)
create the search tree from the event collection using ONLY the variables specified in "theVars"
Double_t fNEventsW[2]
Number of events per class, taking into account event weights.
void NormalizeTree()
Normalisation of tree.
Double_t GetSumOfWeights(void) const
return the sum of event (node) weights
BinarySearchTree(void)
default constructor
void Insert(const Event *)
insert a new "event" in the binary tree
static BinarySearchTree * CreateFromXML(void *node, UInt_t tmva_Version_Code=262657)
re-create a new tree (decision tree or search tree) from XML
Base class for BinarySearch and Decision Trees.
virtual void ReadXML(void *node, UInt_t tmva_Version_Code=262657)
read attributes from XML
Node for the BinarySearch or Decision Trees.
virtual Node * GetLeft() const
virtual void SetRight(Node *r)
virtual Bool_t GoesLeft(const Event &) const =0
virtual void SetLeft(Node *l)
virtual void SetParent(Node *p)
virtual Bool_t GoesRight(const Event &) const =0
virtual Node * GetRight() const
@ kSignal
Never change this number - it is elsewhere assumed to be zero !
Volume for BinarySearchTree.
std::vector< Double_t > * fLower
vector with lower volume dimensions
std::vector< Double_t > * fUpper
vector with upper volume dimensions
MsgLogger & Endl(MsgLogger &ml)
Double_t Sqrt(Double_t x)
Returns the square root of x.