Logo ROOT  
Reference Guide
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 
37 This is an abstract class, which provides an interface for a
38 PDEFoam density estimator. Derived classes have to implement the
39 Density(...) function, which returns the density of a certain
40 quantity at a given phase-space point during the foam build-up.
41 
42 Variants of PDEFoamDensityBase are:
43 
44  - PDEFoamEventDensity
45  - PDEFoamDiscriminantDensity
46  - PDEFoamTargetDensity
47  - PDEFoamDecisionTreeDensity
48 
49 Usage:
50 
51 The user has to instantiate a child class of PDEFoamDensityBase and
52 set the pointer to the owner, which is a PDEFoam object:
53 
54  PDEFoamDensityBase *dens = new MyDensity();
55  pdefoam->SetDensity(dens);
56 
57 Afterwards the binary search tree should be filled with TMVA
58 events, by either using:
59 
60  pdefoam->FillBinarySearchTree(event);
61 
62 or:
63 
64  dens->FillBinarySearchTree(event);
65 */
66 
68 
69 #include "TMVA/BinarySearchTree.h"
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 }
TMVA::PDEFoamDensityBase::FillBinarySearchTree
void FillBinarySearchTree(const Event *ev)
This method inserts the given event 'ev' it into the binary search tree.
Definition: PDEFoamDensityBase.cxx:144
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TMVA::PDEFoamDensityBase::~PDEFoamDensityBase
virtual ~PDEFoamDensityBase()
destructor
Definition: PDEFoamDensityBase.cxx:118
TMVA::PDEFoamDensityBase
Definition: PDEFoamDensityBase.h:72
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TMVA::PDEFoamDensityBase::PDEFoamDensityBase
PDEFoamDensityBase()
Definition: PDEFoamDensityBase.cxx:85
TMath::Log
Double_t Log(Double_t x)
Definition: TMath.h:749
TMVA::BinarySearchTree::SetPeriode
void SetPeriode(Int_t p)
Definition: BinarySearchTree.h:97
PDEFoamDensityBase.h
box
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
MsgLogger.h
TMVA::BinarySearchTree
Definition: BinarySearchTree.h:65
BinarySearchTree.h
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TMVA::PDEFoamDensityBase::GetBoxVolume
Double_t GetBoxVolume()
Returns the volume of range searching box fBox.
Definition: PDEFoamDensityBase.cxx:161
TMVA::PDEFoamDensityBase::Log
MsgLogger & Log() const
message logger
Definition: PDEFoamDensityBase.h:109
Types.h
TMVA::Endl
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:182
TMVA::PDEFoamDensityBase::fBst
BinarySearchTree * fBst
Definition: PDEFoamDensityBase.h:106
Double_t
double Double_t
Definition: RtypesCore.h:59
RtypesCore.h
TMVA::MsgLogger
Definition: MsgLogger.h:83
TObject.h
TObject
Definition: TObject.h:37
TMVA::Event
Definition: Event.h:51
Rtypes.h
TMVA
create variable transformations
Definition: GeneticMinimizer.h:22