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(
"");
117 fStatisticsIsValid =
kFALSE;
119 if (this->GetRoot() ==
NULL) {
122 this->GetRoot()->SetPos(
's');
123 this->GetRoot()->SetDepth(0);
125 fSumOfWeights =
event->GetWeight();
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;
156 this->Insert(event, node->
GetLeft());
162 fSumOfWeights +=
event->GetWeight();
173 this->Insert(event, node->
GetRight());
179 fSumOfWeights +=
event->GetWeight();
187 else Log() << kFATAL <<
"<Insert> neither left nor right :)" <<
Endl;
195 return this->Search( event, this->GetRoot() );
208 return this->Search(event, node->
GetLeft());
210 return this->Search(event, node->
GetRight());
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;
264 if (fSumOfWeights != 0) {
266 <<
"You are filling a search three that is not empty.. "
267 <<
" do you know what you are doing?"
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,
294 for (std::vector< std::pair<Double_t, const TMVA::Event*> >::iterator i=
leftBound; i!=
rightBound; ++i) {
295 i->first = i->second->GetValue(
actDim );
300 std::vector< std::pair<Double_t, const TMVA::Event*> >::iterator
leftTemp =
leftBound;
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;
325 Insert(
mid->second );
348 NormalizeTree( fNormalizeTreeTable.begin(), fNormalizeTreeTable.end(), 0 );
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 )) {
389 count +=
st->GetWeight();
390 if (
NULL != events) events->push_back(
st );
399 if (
d !=
st->GetSelector()) {
400 Log() << kFATAL <<
"<SearchVolume> selector in Searchvolume "
401 <<
d <<
" != " <<
"node "<<
st->GetSelector() <<
Endl;
406 if (
tl) count += SearchVolume(
st->GetLeft(), volume, (
depth+1), events );
407 if (
tr) count += SearchVolume(
st->GetRight(), volume, (
depth+1), events );
432 if (fStatisticsIsValid)
return;
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);
448 fMeans[
sb][
j] = fRMS[
sb][
j] = fSum[
sb][
j] = fSumSq[
sb][
j] = 0;
454 if (currentNode ==
NULL)
return;
463 fNEventsW[
type] += weight;
464 fSumOfWeights += weight;
468 fSum[
type][
j] += val*weight;
469 fSumSq[
type][
j] += val*val*weight;
480 if (fNEventsW[
sb] == 0) { fMeans[
sb][
j] = fRMS[
sb][
j] = 0;
continue; }
481 fMeans[
sb][
j] = fSum[
sb][
j]/fNEventsW[
sb];
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();
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;
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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
const_iterator begin() const
const_iterator end() const
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
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.
UInt_t GetNVariables() const
accessor to the number of variables
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.