Logo ROOT   6.08/07
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 //_____________________________________________________________________
35 //
36 // PDEFoamDensityBase
37 //
38 // This is an abstract class, which provides an interface for a
39 // PDEFoam density estimator. Derived classes have to implement the
40 // Density(...) function, which returns the density of a certain
41 // quantity at a given phase-space point during the foam build-up.
42 //
43 // Variants of PDEFoamDensityBase are:
44 //
45 // - PDEFoamEventDensity
46 // - PDEFoamDiscriminantDensity
47 // - PDEFoamTargetDensity
48 // - PDEFoamDecisionTreeDensity
49 //
50 // Usage:
51 //
52 // The user has to instantiate a child class of PDEFoamDensityBase and
53 // set the pointer to the owner, which is a PDEFoam object:
54 //
55 // PDEFoamDensityBase *dens = new MyDensity();
56 // pdefoam->SetDensity(dens);
57 //
58 // Afterwards the binary search tree should be filled with TMVA
59 // events, by either using
60 //
61 // pdefoam->FillBinarySearchTree(event);
62 //
63 // or
64 //
65 // dens->FillBinarySearchTree(event);
66 // _____________________________________________________________________
67 
69 
70 #include "TMVA/BinarySearchTree.h"
71 #include "TMVA/MsgLogger.h"
72 #include "TMVA/Types.h"
73 
74 #include "RtypesCore.h"
75 #include "Rtypes.h"
76 #include "TObject.h"
77 
78 #include <functional>
79 #include <numeric>
80 #include <vector>
81 
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 
87 : TObject(),
88  fBox(),
89  fBoxVolume(1.0),
90  fBoxHasChanged(kTRUE),
91  fBst(new TMVA::BinarySearchTree()),
92  fLogger(new MsgLogger("PDEFoamDensityBase"))
93 {}
94 
95 ////////////////////////////////////////////////////////////////////////////////
96 /// User constructor
97 ///
98 /// - box - range-searching box, where box.size() == dimension of
99 /// the PDEFoam == periode of the binary search tree
100 
102  : TObject(),
103  fBox(box),
104  fBoxVolume(1.0),
105  fBoxHasChanged(kTRUE),
106  fBst(new TMVA::BinarySearchTree()),
107  fLogger(new MsgLogger("PDEFoamDensityBase"))
108 {
109  if (box.empty())
110  Log() << kFATAL << "Dimension of PDEFoamDensityBase is zero" << Endl;
111 
112  // set periode (number of variables) of binary search tree
113  fBst->SetPeriode(box.size());
114 }
115 
116 ////////////////////////////////////////////////////////////////////////////////
117 /// destructor
118 
120 {
121  if (fBst) delete fBst;
122  if (fLogger) delete fLogger;
123 }
124 
125 ////////////////////////////////////////////////////////////////////////////////
126 /// Copy constructor
127 ///
128 /// Creates a deep copy, using the copy constructor of
129 /// TMVA::BinarySearchTree
130 
132  : TObject(),
133  fBox(distr.fBox),
134  fBoxVolume(distr.fBoxVolume),
136  fBst(new BinarySearchTree(*distr.fBst)),
137  fLogger(new MsgLogger(*distr.fLogger))
138 {
139 }
140 
141 ////////////////////////////////////////////////////////////////////////////////
142 /// This method inserts the given event 'ev' it into the binary
143 /// search tree.
144 
146 {
147  if (fBst == NULL)
148  Log() << kFATAL << "<PDEFoamDensityBase::FillBinarySearchTree> "
149  << "Binary tree is not set!" << Endl;
150 
151  // insert into binary search tree
152  fBst->Insert(ev);
153 }
154 
155 ////////////////////////////////////////////////////////////////////////////////
156 /// Returns the volume of range searching box fBox.
157 ///
158 /// If the range searching box 'fBox' has changed (fBoxHasChanged is
159 /// kTRUE), recalculate the box volume and set fBoxHasChanged to
160 /// kFALSE
161 
163 {
164  if (fBoxHasChanged) {
166  fBoxVolume = std::accumulate(fBox.begin(), fBox.end(), 1.0,
167  std::multiplies<Double_t>());
168  }
169  return fBoxVolume;
170 }
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:162
const Bool_t kFALSE
Definition: Rtypes.h:92
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
virtual ~PDEFoamDensityBase()
destructor
void FillBinarySearchTree(const Event *ev)
This method inserts the given event &#39;ev&#39; it into the binary search tree.
MsgLogger & Log() const
message logger
std::vector< Double_t > fBox
void Insert(const Event *)
insert a new "event" in the binary tree
#define ClassImp(name)
Definition: Rtypes.h:279
double Double_t
Definition: RtypesCore.h:55
Double_t GetBoxVolume()
Returns the volume of range searching box fBox.
Mother of all ROOT objects.
Definition: TObject.h:37
Abstract ClassifierFactory template that handles arbitrary types.
#define NULL
Definition: Rtypes.h:82
const Bool_t kTRUE
Definition: Rtypes.h:91