ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 //_____________________________________________________________________
35 //
36 // PDEFoamDiscriminantDensity
37 //
38 // This is a concrete implementation of PDEFoam. Density(...)
39 // estimates the discriminant density at a given phase-space point
40 // using range-searching. The discriminant D is defined as
41 //
42 // D = #events with given class / total number of events
43 // _____________________________________________________________________
44 
46 
47 #include "TMVA/BinarySearchTree.h"
49 #include "TMVA/MsgLogger.h"
50 #include "TMVA/Types.h"
51 #include "TMVA/Volume.h"
52 
53 #include "Rtypes.h"
54 
55 #include <cmath>
56 #include <vector>
57 
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 
62 TMVA::PDEFoamDiscriminantDensity::PDEFoamDiscriminantDensity()
63  : PDEFoamDensityBase()
64  , fClass(0)
65 {}
66 
67 ////////////////////////////////////////////////////////////////////////////////
68 /// User construcor:
69 ///
70 /// Parameters:
71 ///
72 /// - box - size of the range-searching box (n-dimensional
73 /// std::vector)
74 ///
75 /// - cls - event class used for the range-searching
76 
78  : PDEFoamDensityBase(box)
79  , fClass(cls)
80 {
81 }
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 /// Copy constructor
85 
87  : PDEFoamDensityBase(distr)
88  , fClass(distr.fClass)
89 {
90 }
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 /// This function is needed during the foam buildup. It returns the
94 /// average number density of events of type fClass within the
95 /// range-searching volume (specified by fBox).
96 ///
97 /// Parameters:
98 ///
99 /// - xev - event vector (in [fXmin,fXmax]) to place the box at
100 ///
101 /// - event_density - here the event density is stored
102 ///
103 /// Returns:
104 ///
105 /// Number of events (event weights) of type fClass, which were
106 /// found in the range-searching volume at point 'xev', divided by
107 /// the box volume.
108 
109 Double_t TMVA::PDEFoamDiscriminantDensity::Density(std::vector<Double_t> &xev, Double_t &event_density)
110 {
111  if (!fBst)
112  Log() << kFATAL << "<PDEFoamDiscriminantDensity::Density()> Binary tree not set!" << Endl;
113 
114  //create volume around point to be found
115  std::vector<Double_t> lb(GetBox().size());
116  std::vector<Double_t> ub(GetBox().size());
117 
118  // probevolume relative to hypercube with edge length 1:
119  const Double_t probevolume_inv = 1.0 / GetBoxVolume();
120 
121  // set upper and lower bound for search volume
122  for (UInt_t idim = 0; idim < GetBox().size(); ++idim) {
123  lb[idim] = xev[idim] - GetBox().at(idim) / 2.0;
124  ub[idim] = xev[idim] + GetBox().at(idim) / 2.0;
125  }
126 
127  TMVA::Volume volume(&lb, &ub); // volume to search in
128  std::vector<const TMVA::BinarySearchTreeNode*> nodes; // BST nodes found
129 
130  // do range searching
131  const Double_t sumOfWeights = fBst->SearchVolume(&volume, &nodes);
132 
133  // store density based on total number of events
134  event_density = nodes.size() * probevolume_inv;
135 
136  Double_t n_sig = 0; // number of signal events found
137  // calc number of signal events in nodes
138  for (std::vector<const TMVA::BinarySearchTreeNode*>::const_iterator it = nodes.begin();
139  it != nodes.end(); ++it) {
140  if ((*it)->GetClass() == fClass) // signal node
141  n_sig += (*it)->GetWeight();
142  }
143 
144  // return: (n_sig/n_total) / (cell_volume)
145  return (n_sig / (sumOfWeights + 0.1)) * probevolume_inv;
146 }
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:162
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
double distr(double *x, double *p)
Definition: unuranDemo.C:104
TClass * fClass
pointer to the foreign object
unsigned int UInt_t
Definition: RtypesCore.h:42
double Double_t
Definition: RtypesCore.h:55
virtual Double_t Density(std::vector< Double_t > &Xarg, Double_t &event_density)
This function is needed during the foam buildup.
ClassImp(TMVA::PDEFoamDiscriminantDensity) TMVA
Definition: math.cpp:60