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 * Web : http://tmva.sourceforge.net *
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 * (http://tmva.sourceforge.net/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
82
83////////////////////////////////////////////////////////////////////////////////
84
86: TObject(),
87 fBox(),
88 fBoxVolume(1.0),
89 fBoxHasChanged(kTRUE),
90 fBst(new TMVA::BinarySearchTree()),
91 fLogger(new MsgLogger("PDEFoamDensityBase"))
92{}
93
94////////////////////////////////////////////////////////////////////////////////
95/// User constructor
96///
97/// - box - range-searching box, where box.size() == dimension of
98/// the PDEFoam == periode of the binary search tree
99
101 : TObject(),
102 fBox(box),
103 fBoxVolume(1.0),
104 fBoxHasChanged(kTRUE),
105 fBst(new TMVA::BinarySearchTree()),
106 fLogger(new MsgLogger("PDEFoamDensityBase"))
107{
108 if (box.empty())
109 Log() << kFATAL << "Dimension of PDEFoamDensityBase is zero" << Endl;
110
111 // set periode (number of variables) of binary search tree
112 fBst->SetPeriode(box.size());
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// destructor
117
119{
120 if (fBst) delete fBst;
121 if (fLogger) delete fLogger;
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// Copy constructor
126///
127/// Creates a deep copy, using the copy constructor of
128/// TMVA::BinarySearchTree
129
131 : TObject(),
132 fBox(distr.fBox),
133 fBoxVolume(distr.fBoxVolume),
134 fBoxHasChanged(distr.fBoxHasChanged),
135 fBst(new BinarySearchTree(*distr.fBst)),
136 fLogger(new MsgLogger(*distr.fLogger))
137{
138}
139
140////////////////////////////////////////////////////////////////////////////////
141/// This method inserts the given event 'ev' it into the binary
142/// search tree.
143
145{
146 if (fBst == NULL)
147 Log() << kFATAL << "<PDEFoamDensityBase::FillBinarySearchTree> "
148 << "Binary tree is not set!" << Endl;
149
150 // insert into binary search tree
151 fBst->Insert(ev);
152}
153
154////////////////////////////////////////////////////////////////////////////////
155/// Returns the volume of range searching box fBox.
156///
157/// If the range searching box 'fBox' has changed (fBoxHasChanged is
158/// kTRUE), recalculate the box volume and set fBoxHasChanged to
159/// kFALSE
160
162{
163 if (fBoxHasChanged) {
164 fBoxHasChanged = kFALSE;
165 fBoxVolume = std::accumulate(fBox.begin(), fBox.end(), 1.0,
166 std::multiplies<Double_t>());
167 }
168 return fBoxVolume;
169}
const Bool_t kFALSE
Definition RtypesCore.h:92
double Double_t
Definition RtypesCore.h:59
const Bool_t kTRUE
Definition RtypesCore.h:91
#define ClassImp(name)
Definition Rtypes.h:364
A simple Binary search tree including a volume search method.
ostringstream derivative to redirect and format output
Definition MsgLogger.h:59
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.
MsgLogger & Log() const
message logger
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:37
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:158