ROOT  6.06/09
Reference Guide
PDEFoamEventDensity.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: PDEFoamEventDensity *
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 PDEFoamEventDensity::Density() does *
15  * this job. It *
16  * uses a binary search tree, filled with training events, in order to *
17  * provide this density. *
18  * *
19  * Authors (alphabetical): *
20  * Tancredi Carli - CERN, Switzerland *
21  * Dominik Dannheim - CERN, Switzerland *
22  * S. Jadach - Institute of Nuclear Physics, Cracow, Poland *
23  * Alexander Voigt - TU Dresden, Germany *
24  * Peter Speckmayer - CERN, Switzerland *
25  * *
26  * Copyright (c) 2008, 2010: *
27  * CERN, Switzerland *
28  * MPI-K Heidelberg, Germany *
29  * *
30  * Redistribution and use in source and binary forms, with or without *
31  * modification, are permitted according to the terms listed in LICENSE *
32  * (http://tmva.sourceforge.net/LICENSE) *
33  **********************************************************************************/
34 
35 //_____________________________________________________________________
36 //
37 // PDEFoamEventDensity
38 //
39 // This is a concrete implementation of PDEFoam. Density(...)
40 // estimates the event (weight) density at a given phase-space point
41 // using range-searching.
42 // _____________________________________________________________________
43 
44 #include <cmath>
45 
46 #ifndef ROOT_TMVA_PDEFoamEventDensity
48 #endif
49 
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 
54 TMVA::PDEFoamEventDensity::PDEFoamEventDensity()
55  : PDEFoamDensityBase()
56 {}
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// User construcor
60 ///
61 /// Parameters:
62 ///
63 /// - box - size of sampling box
64 
66  : PDEFoamDensityBase(box)
67 {
68 }
69 
70 ////////////////////////////////////////////////////////////////////////////////
71 /// Copy constructor
72 
74  : PDEFoamDensityBase(distr)
75 {
76 }
77 
78 ////////////////////////////////////////////////////////////////////////////////
79 /// This function is needed during the foam buildup. It returns the
80 /// event density within the range-searching volume (specified by
81 /// fBox).
82 ///
83 /// Parameters:
84 ///
85 /// - xev - event vector (in [fXmin,fXmax]) to place the box at
86 ///
87 /// - event_density - here the event density is stored
88 ///
89 /// Returns:
90 ///
91 /// Number of events (event weights), which were found in the
92 /// range-searching volume at point 'xev', divided by the box
93 /// volume.
94 
95 Double_t TMVA::PDEFoamEventDensity::Density(std::vector<Double_t> &xev, Double_t &event_density)
96 {
97  if (!fBst)
98  Log() << kFATAL << "<PDEFoamEventDensity::Density()> Binary tree not found!" << Endl;
99 
100  //create volume around point to be found
101  std::vector<Double_t> lb(GetBox().size());
102  std::vector<Double_t> ub(GetBox().size());
103 
104  // probevolume relative to hypercube with edge length 1:
105  const Double_t probevolume_inv = 1.0 / GetBoxVolume();
106 
107  // set upper and lower bound for search volume
108  for (UInt_t idim = 0; idim < GetBox().size(); ++idim) {
109  lb[idim] = xev[idim] - GetBox().at(idim) / 2.0;
110  ub[idim] = xev[idim] + GetBox().at(idim) / 2.0;
111  }
112 
113  TMVA::Volume volume(&lb, &ub); // volume to search in
114  std::vector<const TMVA::BinarySearchTreeNode*> nodes; // BST nodes found
115 
116  // do range searching
117  const Double_t sumOfWeights = fBst->SearchVolume(&volume, &nodes);
118 
119  // store density based on total number of events
120  event_density = nodes.size() * probevolume_inv;
121 
122  // return: N_total(weighted) / cell_volume
123  return (sumOfWeights + 0.1) * probevolume_inv;
124 }
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:162
virtual Double_t Density(std::vector< Double_t > &Xarg, Double_t &event_density)
This function is needed during the foam buildup.
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
unsigned int UInt_t
Definition: RtypesCore.h:42
ClassImp(TMVA::PDEFoamEventDensity) TMVA
double Double_t
Definition: RtypesCore.h:55
Abstract ClassifierFactory template that handles arbitrary types.
Definition: math.cpp:60