Logo ROOT   6.16/01
Reference Guide
PDEFoamTargetDensity.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: PDEFoamTargetDensity *
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 PDEFoamTargetDensity::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::PDEFoamTargetDensity
35\ingroup TMVA
36This is a concrete implementation of PDEFoam. Density(...)
37estimates the target density (target number: fTarget) at a given
38phase-space point using range-searching.
39*/
40
42
44#include "TMVA/MsgLogger.h"
46#include "TMVA/Types.h"
47#include "TMVA/Volume.h"
48
49#include "Rtypes.h"
50
51#include <cmath>
52#include <vector>
53
55
56////////////////////////////////////////////////////////////////////////////////
57
60 , fTarget(0)
61{}
62
63////////////////////////////////////////////////////////////////////////////////
64/// User constructor
65///
66/// Parameters:
67///
68/// - box - size of the range-searching box (n-dimensional
69/// std::vector)
70///
71/// - target - the target number to calculate the density for
72
75 , fTarget(target)
76{
77}
78
79////////////////////////////////////////////////////////////////////////////////
80/// Copy constructor
81
83 : PDEFoamDensityBase(distr)
84 , fTarget(distr.fTarget)
85{
86}
87
88////////////////////////////////////////////////////////////////////////////////
89/// This function is needed during the foam buildup. It returns the
90/// average target value within the range-searching box at point
91/// xev, divided by volume (specified by fBox).
92///
93/// Parameters:
94///
95/// - xev - event vector (in [fXmin,fXmax]) to place the box at
96///
97/// - event_density - here the event density is stored
98///
99/// Returns:
100///
101/// Average target value in the range-searching volume at point
102/// 'xev', divided by the box volume.
103
104Double_t TMVA::PDEFoamTargetDensity::Density(std::vector<Double_t> &xev, Double_t &event_density)
105{
106 if (!fBst)
107 Log() << kFATAL << "<PDEFoamTargetDensity::Density()> Binary tree not found!" << Endl;
108
109 //create volume around point to be found
110 std::vector<Double_t> lb(GetBox().size());
111 std::vector<Double_t> ub(GetBox().size());
112
113 // probevolume relative to hypercube with edge length 1:
114 const Double_t probevolume_inv = 1.0 / GetBoxVolume();
115
116 // set upper and lower bound for search volume
117 for (UInt_t idim = 0; idim < GetBox().size(); ++idim) {
118 lb[idim] = xev[idim] - GetBox().at(idim) / 2.0;
119 ub[idim] = xev[idim] + GetBox().at(idim) / 2.0;
120 }
121
122 TMVA::Volume volume(&lb, &ub); // volume to search in
123 std::vector<const TMVA::BinarySearchTreeNode*> nodes; // BST nodes found
124
125 // do range searching
126 const Double_t sumOfWeights = fBst->SearchVolume(&volume, &nodes);
127
128 // store density based on total number of events
129 event_density = nodes.size() * probevolume_inv;
130
131 Double_t n_tar = 0; // number of target events found
132 // now sum over all nodes->GetTarget(0);
133 for (std::vector<const TMVA::BinarySearchTreeNode*>::const_iterator it = nodes.begin();
134 it != nodes.end(); ++it) {
135 n_tar += ((*it)->GetTargets()).at(fTarget) * ((*it)->GetWeight());
136 }
137
138 // return: (n_tar/n_total) / (cell_volume)
139 return (n_tar / (sumOfWeights + 0.1)) * probevolume_inv;
140}
unsigned int UInt_t
Definition: RtypesCore.h:42
double Double_t
Definition: RtypesCore.h:55
#define ClassImp(name)
Definition: Rtypes.h:363
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:48
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:158
Double_t Log(Double_t x)
Definition: TMath.h:748