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(
"");
116 fStatisticsIsValid =
kFALSE;
118 if (this->GetRoot() ==
NULL) {
121 this->GetRoot()->SetPos(
's');
122 this->GetRoot()->SetDepth(0);
124 fSumOfWeights =
event->GetWeight();
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;
155 this->Insert(event, node->
GetLeft());
161 fSumOfWeights +=
event->GetWeight();
172 this->Insert(event, node->
GetRight());
178 fSumOfWeights +=
event->GetWeight();
186 else Log() << kFATAL <<
"<Insert> neither left nor right :)" <<
Endl;
194 return this->Search( event, this->GetRoot() );
207 return this->Search(event, node->
GetLeft());
209 return this->Search(event, node->
GetRight());
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;
263 if (fSumOfWeights != 0) {
265 <<
"You are filling a search three that is not empty.. "
266 <<
" do you know what you are doing?"
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,
293 for (std::vector< std::pair<Double_t, const TMVA::Event*> >::iterator i=
leftBound; i!=
rightBound; ++i) {
294 i->first = i->second->GetValue(
actDim );
299 std::vector< std::pair<Double_t, const TMVA::Event*> >::iterator
leftTemp =
leftBound;
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;
324 Insert(
mid->second );
347 NormalizeTree( fNormalizeTreeTable.begin(), fNormalizeTreeTable.end(), 0 );
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 )) {
388 count +=
st->GetWeight();
389 if (
NULL != events) events->push_back(
st );
398 if (
d !=
st->GetSelector()) {
399 Log() << kFATAL <<
"<SearchVolume> selector in Searchvolume "
400 <<
d <<
" != " <<
"node "<<
st->GetSelector() <<
Endl;
405 if (
tl) count += SearchVolume(
st->GetLeft(), volume, (
depth+1), events );
406 if (
tr) count += SearchVolume(
st->GetRight(), volume, (
depth+1), events );
431 if (fStatisticsIsValid)
return;
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);
447 fMeans[
sb][
j] = fRMS[
sb][
j] = fSum[
sb][
j] = fSumSq[
sb][
j] = 0;
453 if (currentNode ==
NULL)
return;
462 fNEventsW[
type] += weight;
463 fSumOfWeights += weight;
467 fSum[
type][
j] += val*weight;
468 fSumSq[
type][
j] += val*val*weight;
479 if (fNEventsW[
sb] == 0) { fMeans[
sb][
j] = fRMS[
sb][
j] = 0;
continue; }
480 fMeans[
sb][
j] = fSum[
sb][
j]/fNEventsW[
sb];
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();
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)
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
Int_t Fill(Double_t x) override
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.