Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
PDEFoamDensityBase.cxx
Go to the documentation of this file.
1// @(#)root/tmva $Id$
2// Author: Tancredi Carli, Dominik Dannheim, Alexander Voigt
3
4/**********************************************************************************
5 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6 * Package: TMVA *
7 * Classes: PDEFoamDensityBase *
8 * *
9 * *
10 * Description: *
11 * This class provides an interface between the Binary search tree *
12 * and the PDEFoam object. In order to build-up the foam one needs to *
13 * calculate the density of events at a given point (sampling during *
14 * Foam build-up). The function PDEFoamDensityBase::Density() does this job. It *
15 * uses a binary search tree, filled with training events, in order to *
16 * provide this density. *
17 * *
18 * Authors (alphabetical): *
19 * Tancredi Carli - CERN, Switzerland *
20 * Dominik Dannheim - CERN, Switzerland *
21 * S. Jadach - Institute of Nuclear Physics, Cracow, Poland *
22 * Alexander Voigt - TU Dresden, Germany *
23 * Peter Speckmayer - CERN, Switzerland *
24 * *
25 * Copyright (c) 2008, 2010: *
26 * CERN, Switzerland *
27 * MPI-K Heidelberg, Germany *
28 * *
29 * Redistribution and use in source and binary forms, with or without *
30 * modification, are permitted according to the terms listed in LICENSE *
31 * (see tmva/doc/LICENSE) *
32 **********************************************************************************/
33
34/*! \class TMVA::PDEFoamDensityBase
35\ingroup TMVA
36
37This is an abstract class, which provides an interface for a
38PDEFoam density estimator. Derived classes have to implement the
39Density(...) function, which returns the density of a certain
40quantity at a given phase-space point during the foam build-up.
41
42Variants of PDEFoamDensityBase are:
43
44 - PDEFoamEventDensity
45 - PDEFoamDiscriminantDensity
46 - PDEFoamTargetDensity
47 - PDEFoamDecisionTreeDensity
48
49Usage:
50
51The user has to instantiate a child class of PDEFoamDensityBase and
52set the pointer to the owner, which is a PDEFoam object:
53
54 PDEFoamDensityBase *dens = new MyDensity();
55 pdefoam->SetDensity(dens);
56
57Afterwards the binary search tree should be filled with TMVA
58events, by either using:
59
60 pdefoam->FillBinarySearchTree(event);
61
62or:
63
64 dens->FillBinarySearchTree(event);
65*/
66
68
70#include "TMVA/MsgLogger.h"
71#include "TMVA/Types.h"
72
73#include "RtypesCore.h"
74#include "Rtypes.h"
75#include "TObject.h"
76
77#include <functional>
78#include <numeric>
79#include <vector>
80
81
82////////////////////////////////////////////////////////////////////////////////
83
85: TObject(),
86 fBox(),
87 fBoxVolume(1.0),
88 fBoxHasChanged(kTRUE),
89 fBst(new TMVA::BinarySearchTree()),
90 fLogger(new MsgLogger("PDEFoamDensityBase"))
91{}
92
93////////////////////////////////////////////////////////////////////////////////
94/// User constructor
95///
96/// - box - range-searching box, where box.size() == dimension of
97/// the PDEFoam == periode of the binary search tree
98
100 : TObject(),
101 fBox(box),
102 fBoxVolume(1.0),
103 fBoxHasChanged(kTRUE),
104 fBst(new TMVA::BinarySearchTree()),
105 fLogger(new MsgLogger("PDEFoamDensityBase"))
106{
107 if (box.empty())
108 Log() << kFATAL << "Dimension of PDEFoamDensityBase is zero" << Endl;
109
110 // set periode (number of variables) of binary search tree
111 fBst->SetPeriode(box.size());
112}
113
114////////////////////////////////////////////////////////////////////////////////
115/// destructor
116
118{
119 if (fBst) delete fBst;
120 if (fLogger) delete fLogger;
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// Copy constructor
125///
126/// Creates a deep copy, using the copy constructor of
127/// TMVA::BinarySearchTree
128
130 : TObject(),
131 fBox(distr.fBox),
132 fBoxVolume(distr.fBoxVolume),
133 fBoxHasChanged(distr.fBoxHasChanged),
134 fBst(new BinarySearchTree(*distr.fBst)),
135 fLogger(new MsgLogger(*distr.fLogger))
136{
137}
138
139////////////////////////////////////////////////////////////////////////////////
140/// This method inserts the given event 'ev' it into the binary
141/// search tree.
142
144{
145 if (fBst == NULL)
146 Log() << kFATAL << "<PDEFoamDensityBase::FillBinarySearchTree> "
147 << "Binary tree is not set!" << Endl;
148
149 // insert into binary search tree
150 fBst->Insert(ev);
151}
152
153////////////////////////////////////////////////////////////////////////////////
154/// Returns the volume of range searching box fBox.
155///
156/// If the range searching box 'fBox' has changed (fBoxHasChanged is
157/// kTRUE), recalculate the box volume and set fBoxHasChanged to
158/// kFALSE
159
161{
162 if (fBoxHasChanged) {
163 fBoxHasChanged = kFALSE;
164 fBoxVolume = std::accumulate(fBox.begin(), fBox.end(), 1.0,
165 std::multiplies<Double_t>());
166 }
167 return fBoxVolume;
168}
Basic types used by ROOT and required by TInterpreter.
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
A simple Binary search tree including a volume search method.
ostringstream derivative to redirect and format output
Definition MsgLogger.h:57
This is an abstract class, which provides an interface for a PDEFoam density estimator.
Double_t GetBoxVolume()
Returns the volume of range searching box fBox.
BinarySearchTree * fBst
Binary tree to find events within a volume.
virtual ~PDEFoamDensityBase()
destructor
void FillBinarySearchTree(const Event *ev)
This method inserts the given event 'ev' it into the binary search tree.
Mother of all ROOT objects.
Definition TObject.h:41
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition fillpatterns.C:1
create variable transformations
MsgLogger & Endl(MsgLogger &ml)
Definition MsgLogger.h:148