66 fStatisticsIsValid(
kFALSE ),
78 fPeriod (
b.fPeriod ),
80 fStatisticsIsValid(
kFALSE ),
81 fSumOfWeights(
b.fSumOfWeights ),
85 Log() << kFATAL <<
" Copy constructor not implemented yet " <<
Endl;
93 for(std::vector< std::pair<Double_t, const TMVA::Event*> >::iterator pIt = fNormalizeTreeTable.begin();
94 pIt != fNormalizeTreeTable.end(); ++pIt) {
103 std::string
type(
"");
106 bt->
ReadXML( node, tmva_Version_Code );
116 fStatisticsIsValid =
kFALSE;
118 if (this->GetRoot() == NULL) {
121 this->GetRoot()->SetPos(
's');
122 this->GetRoot()->SetDepth(0);
124 fSumOfWeights =
event->GetWeight();
126 this->SetPeriode(
event->GetNVariables());
130 if (
event->GetNVariables() != (
UInt_t)this->GetPeriode()) {
131 Log() << kFATAL <<
"<Insert> event vector length != Periode specified in Binary Tree" <<
Endl
132 <<
"--- event size: " <<
event->GetNVariables() <<
" Periode: " << this->GetPeriode() <<
Endl
133 <<
"--- and all this when trying filling the "<<fNNodes+1<<
"th Node" <<
Endl;
136 this->Insert(
event, this->GetRoot());
140 if (fCanNormalize) fNormalizeTreeTable.push_back( std::make_pair(0.0,
new const Event(*
event)) );
150 fStatisticsIsValid =
kFALSE;
161 fSumOfWeights +=
event->GetWeight();
178 fSumOfWeights +=
event->GetWeight();
186 else Log() << kFATAL <<
"<Insert> neither left nor right :)" <<
Endl;
194 return this->Search(
event, this->GetRoot() );
219 if (fSumOfWeights <= 0) {
220 Log() << kWARNING <<
"you asked for the SumOfWeights, which is not filled yet"
221 <<
" I call CalcStatistics which hopefully fixes things"
224 if (fSumOfWeights <= 0) Log() << kFATAL <<
" Zero events in your Search Tree" <<
Endl;
226 return fSumOfWeights;
234 if (fSumOfWeights <= 0) {
235 Log() << kWARNING <<
"you asked for the SumOfWeights, which is not filled yet"
236 <<
" I call CalcStatistics which hopefully fixes things"
239 if (fSumOfWeights <= 0) Log() << kFATAL <<
" Zero events in your Search Tree" <<
Endl;
251 fPeriod = theVars.size();
252 return Fill(events, theType);
263 if (fSumOfWeights != 0) {
265 <<
"You are filling a search three that is not empty.. "
266 <<
" do you know what you are doing?"
269 for (
UInt_t ievt=0; ievt<
n; ievt++) {
271 if (theType == -1 || (
Int_t(events[ievt]->GetClass()) == theType) ) {
272 this->Insert( events[ievt] );
273 fSumOfWeights += events[ievt]->GetWeight();
278 return fSumOfWeights;
286 std::vector< std::pair<Double_t, const TMVA::Event*> >::iterator rightBound,
290 if (leftBound == rightBound)
return;
292 if (actDim == fPeriod) actDim = 0;
293 for (std::vector< std::pair<Double_t, const TMVA::Event*> >::iterator i=leftBound; i!=rightBound; ++i) {
294 i->first = i->second->GetValue( actDim );
297 std::sort( leftBound, rightBound );
299 std::vector< std::pair<Double_t, const TMVA::Event*> >::iterator leftTemp = leftBound;
300 std::vector< std::pair<Double_t, const TMVA::Event*> >::iterator rightTemp = rightBound;
305 if (rightTemp == leftTemp ) {
309 if (leftTemp == rightTemp) {
314 std::vector< std::pair<Double_t, const TMVA::Event*> >::iterator mid = leftTemp;
315 std::vector< std::pair<Double_t, const TMVA::Event*> >::iterator midTemp = mid;
317 if (mid!=leftBound)--midTemp;
319 while (mid != leftBound && mid->second->GetValue( actDim ) == midTemp->second->GetValue( actDim )) {
324 Insert( mid->second );
329 NormalizeTree( leftBound, mid, actDim+1 );
333 NormalizeTree( mid, rightBound, actDim+1 );
347 NormalizeTree( fNormalizeTreeTable.begin(), fNormalizeTreeTable.end(), 0 );
360 if (
n != NULL)
delete n;
370 std::vector<const BinarySearchTreeNode*>* events )
372 return SearchVolume( this->GetRoot(), volume, 0, events );
380 std::vector<const BinarySearchTreeNode*>* events )
382 if (t==NULL)
return 0;
387 if (InVolume( st->
GetEventV(), volume )) {
389 if (NULL != events) events->push_back( st );
397 Int_t d = depth%this->GetPeriode();
399 Log() << kFATAL <<
"<SearchVolume> selector in Searchvolume "
405 if (tl) count += SearchVolume( st->
GetLeft(), volume, (depth+1), events );
406 if (tr) count += SearchVolume( st->
GetRight(), volume, (depth+1), events );
418 for (
UInt_t ivar=0; ivar< fPeriod; ivar++) {
420 (*(volume->
fUpper))[ivar] >=
event[ivar] );
431 if (fStatisticsIsValid)
return;
438 for (
Int_t sb=0; sb<2; sb++) {
440 fMeans[sb] = std::vector<Float_t>(fPeriod);
441 fRMS[sb] = std::vector<Float_t>(fPeriod);
442 fMin[sb] = std::vector<Float_t>(fPeriod);
443 fMax[sb] = std::vector<Float_t>(fPeriod);
444 fSum[sb] = std::vector<Double_t>(fPeriod);
445 fSumSq[sb] = std::vector<Double_t>(fPeriod);
446 for (
UInt_t j=0; j<fPeriod; j++) {
447 fMeans[sb][j] = fRMS[sb][j] = fSum[sb][j] = fSumSq[sb][j] = 0;
448 fMin[sb][j] = FLT_MAX;
449 fMax[sb][j] = -FLT_MAX;
453 if (currentNode == NULL)
return;
456 const std::vector<Float_t> & evtVec = currentNode->
GetEventV();
462 fNEventsW[
type] += weight;
463 fSumOfWeights += weight;
465 for (
UInt_t j=0; j<fPeriod; j++) {
467 fSum[
type][j] += val*weight;
468 fSumSq[
type][j] += val*val*weight;
469 if (val < fMin[
type][j]) fMin[
type][j] = val;
470 if (val > fMax[
type][j]) fMax[
type][j] = val;
473 if ( (currentNode->
GetLeft() != NULL) ) CalcStatistics( currentNode->
GetLeft() );
474 if ( (currentNode->
GetRight() != NULL) ) CalcStatistics( currentNode->
GetRight() );
477 for (
Int_t sb=0; sb<2; sb++) {
478 for (
UInt_t j=0; j<fPeriod; j++) {
479 if (fNEventsW[sb] == 0) { fMeans[sb][j] = fRMS[sb][j] = 0;
continue; }
480 fMeans[sb][j] = fSum[sb][j]/fNEventsW[sb];
481 fRMS[sb][j] =
TMath::Sqrt(fSumSq[sb][j]/fNEventsW[sb] - fMeans[sb][j]*fMeans[sb][j]);
484 fStatisticsIsValid =
kTRUE;
497 if (this->GetRoot() == NULL)
return 0;
499 std::queue< std::pair< const BinarySearchTreeNode*, Int_t > > queue;
500 std::pair< const BinarySearchTreeNode*, Int_t > st = std::make_pair( (
const BinarySearchTreeNode*)this->GetRoot(), 0 );
505 while ( !queue.empty() ) {
506 st = queue.front(); queue.pop();
508 if (count == max_points)
511 if (InVolume( st.first->GetEventV(), volume )) {
513 if (NULL != events) events->push_back( st.first );
518 if (
d ==
Int_t(this->GetPeriode()) )
d = 0;
520 if (
d != st.first->GetSelector()) {
521 Log() << kFATAL <<
"<SearchVolume> selector in Searchvolume "
522 <<
d <<
" != " <<
"node "<< st.first->GetSelector() <<
Endl;
525 tl = (*(volume->
fLower))[
d] < st.first->GetEventV()[
d] && st.first->GetLeft() != NULL;
526 tr = (*(volume->
fUpper))[
d] >= st.first->GetEventV()[
d] && st.first->GetRight() != NULL;
int Int_t
Signed integer 4 bytes (int)
float Float_t
Float 4 bytes (float)
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.