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