ROOT  6.06/09
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 
68 #include <numeric>
69 #include <functional>
70 
71 #ifndef ROOT_TMVA_PDEFoamDensityBase
73 #endif
74 
76 
77 ////////////////////////////////////////////////////////////////////////////////
78 
79 TMVA::PDEFoamDensityBase::PDEFoamDensityBase()
80  : TObject(),
81  fBox(),
82  fBoxVolume(1.0),
83  fBoxHasChanged(kTRUE),
84  fBst(new TMVA::BinarySearchTree()),
85  fLogger(new MsgLogger("PDEFoamDensityBase"))
86 {}
87 
88 ////////////////////////////////////////////////////////////////////////////////
89 /// User constructor
90 ///
91 /// - box - range-searching box, where box.size() == dimension of
92 /// the PDEFoam == periode of the binary search tree
93 
95  : TObject(),
96  fBox(box),
97  fBoxVolume(1.0),
98  fBoxHasChanged(kTRUE),
99  fBst(new TMVA::BinarySearchTree()),
100  fLogger(new MsgLogger("PDEFoamDensityBase"))
101 {
102  if (box.empty())
103  Log() << kFATAL << "Dimension of PDEFoamDensityBase is zero" << Endl;
104 
105  // set periode (number of variables) of binary search tree
106  fBst->SetPeriode(box.size());
107 }
108 
109 ////////////////////////////////////////////////////////////////////////////////
110 /// destructor
111 
113 {
114  if (fBst) delete fBst;
115  if (fLogger) delete fLogger;
116 }
117 
118 ////////////////////////////////////////////////////////////////////////////////
119 /// Copy constructor
120 ///
121 /// Creates a deep copy, using the copy constructor of
122 /// TMVA::BinarySearchTree
123 
125  : TObject(),
126  fBox(distr.fBox),
127  fBoxVolume(distr.fBoxVolume),
128  fBoxHasChanged(distr.fBoxHasChanged),
129  fBst(new BinarySearchTree(*distr.fBst)),
130  fLogger(new MsgLogger(*distr.fLogger))
131 {
132 }
133 
134 ////////////////////////////////////////////////////////////////////////////////
135 /// This method inserts the given event 'ev' it into the binary
136 /// search tree.
137 
139 {
140  if (fBst == NULL)
141  Log() << kFATAL << "<PDEFoamDensityBase::FillBinarySearchTree> "
142  << "Binary tree is not set!" << Endl;
143 
144  // insert into binary search tree
145  fBst->Insert(ev);
146 }
147 
148 ////////////////////////////////////////////////////////////////////////////////
149 /// Returns the volume of range searching box fBox.
150 ///
151 /// If the range searching box 'fBox' has changed (fBoxHasChanged is
152 /// kTRUE), recalculate the box volume and set fBoxHasChanged to
153 /// kFALSE
154 
156 {
157  if (fBoxHasChanged) {
158  fBoxHasChanged = kFALSE;
159  fBoxVolume = std::accumulate(fBox.begin(), fBox.end(), 1.0,
160  std::multiplies<Double_t>());
161  }
162  return fBoxVolume;
163 }
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
ClassImp(TMVA::PDEFoamDensityBase) TMVA
virtual ~PDEFoamDensityBase()
destructor
void FillBinarySearchTree(const Event *ev)
This method inserts the given event 'ev' it into the binary search tree.
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:58
MsgLogger & Log() const
message logger
Abstract ClassifierFactory template that handles arbitrary types.
#define NULL
Definition: Rtypes.h:82
const Bool_t kTRUE
Definition: Rtypes.h:91
Definition: math.cpp:60