Logo ROOT  
Reference Guide
PDEFoamDiscriminantDensity.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: PDEFoamDiscriminantDensity *
8 * Web : http://tmva.sourceforge.net *
9 * *
10 * Description: *
11 * The TFDSITR 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 PDEFoamDiscriminantDensity::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::PDEFoamDiscriminantDensity
35\ingroup TMVA
36
37This is a concrete implementation of PDEFoam. Density(...)
38estimates the discriminant density at a given phase-space point
39using range-searching. The discriminant D is defined as
40
41 D = #events with given class / total number of events
42*/
44
47#include "TMVA/MsgLogger.h"
49#include "TMVA/Types.h"
50#include "TMVA/Volume.h"
51
52#include "Rtypes.h"
53
54#include <cmath>
55#include <vector>
56
58
59////////////////////////////////////////////////////////////////////////////////
60
63 , fClass(0)
64{}
65
66////////////////////////////////////////////////////////////////////////////////
67/// User constructor:
68///
69/// Parameters:
70///
71/// - box - size of the range-searching box (n-dimensional
72/// std::vector)
73///
74/// - cls - event class used for the range-searching
75
78 , fClass(cls)
79{
80}
81
82////////////////////////////////////////////////////////////////////////////////
83/// Copy constructor
84
86 : PDEFoamDensityBase(distr)
87 , fClass(distr.fClass)
88{
89}
90
91////////////////////////////////////////////////////////////////////////////////
92/// This function is needed during the foam buildup. It returns the
93/// average number density of events of type fClass within the
94/// range-searching volume (specified by fBox).
95///
96/// Parameters:
97///
98/// - xev - event vector (in [fXmin,fXmax]) to place the box at
99///
100/// - event_density - here the event density is stored
101///
102/// Returns:
103///
104/// Number of events (event weights) of type fClass, which were
105/// found in the range-searching volume at point 'xev', divided by
106/// the box volume.
107
108Double_t TMVA::PDEFoamDiscriminantDensity::Density(std::vector<Double_t> &xev, Double_t &event_density)
109{
110 if (!fBst)
111 Log() << kFATAL << "<PDEFoamDiscriminantDensity::Density()> Binary tree not set!" << Endl;
112
113 //create volume around point to be found
114 std::vector<Double_t> lb(GetBox().size());
115 std::vector<Double_t> ub(GetBox().size());
116
117 // probe volume relative to hypercube with edge length 1:
118 const Double_t probevolume_inv = 1.0 / GetBoxVolume();
119
120 // set upper and lower bound for search volume
121 for (UInt_t idim = 0; idim < GetBox().size(); ++idim) {
122 lb[idim] = xev[idim] - GetBox().at(idim) / 2.0;
123 ub[idim] = xev[idim] + GetBox().at(idim) / 2.0;
124 }
125
126 TMVA::Volume volume(&lb, &ub); // volume to search in
127 std::vector<const TMVA::BinarySearchTreeNode*> nodes; // BST nodes found
128
129 // do range searching
130 const Double_t sumOfWeights = fBst->SearchVolume(&volume, &nodes);
131
132 // store density based on total number of events
133 event_density = nodes.size() * probevolume_inv;
134
135 Double_t n_sig = 0; // number of signal events found
136 // calc number of signal events in nodes
137 for (std::vector<const TMVA::BinarySearchTreeNode*>::const_iterator it = nodes.begin();
138 it != nodes.end(); ++it) {
139 if ((*it)->GetClass() == fClass) // signal node
140 n_sig += (*it)->GetWeight();
141 }
142
143 // return: (n_sig/n_total) / (cell_volume)
144 return (n_sig / (sumOfWeights + 0.1)) * probevolume_inv;
145}
Cppyy::TCppType_t fClass
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define ClassImp(name)
Definition: Rtypes.h:375
This is an abstract class, which provides an interface for a PDEFoam density estimator.
This is a concrete implementation of PDEFoam.
virtual Double_t Density(std::vector< Double_t > &Xarg, Double_t &event_density)
This function is needed during the foam buildup.
Volume for BinarySearchTree.
Definition: Volume.h:47
@ kFATAL
Definition: Types.h:61
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:148
Double_t Log(Double_t x)
Returns the natural logarithm of x.
Definition: TMath.h:753