Logo ROOT   6.12/07
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 /*! \class TMVA::PDEFoamEventDensity
36 \ingroup TMVA
37 This is a concrete implementation of PDEFoam. Density(...)
38 estimates the event (weight) density at a given phase-space point
39 using range-searching.
40 */
41 
43 
44 #include "TMVA/BinarySearchTree.h"
46 #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 
62 {}
63 
64 ////////////////////////////////////////////////////////////////////////////////
65 /// User constructor
66 ///
67 /// Parameters:
68 ///
69 /// - box - size of sampling box
70 
72  : PDEFoamDensityBase(box)
73 {
74 }
75 
76 ////////////////////////////////////////////////////////////////////////////////
77 /// Copy constructor
78 
80  : PDEFoamDensityBase(distr)
81 {
82 }
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 /// This function is needed during the foam buildup. It returns the
86 /// event density within the range-searching volume (specified by
87 /// fBox).
88 ///
89 /// Parameters:
90 ///
91 /// - xev - event vector (in [fXmin,fXmax]) to place the box at
92 ///
93 /// - event_density - here the event density is stored
94 ///
95 /// Returns:
96 ///
97 /// Number of events (event weights), which were found in the
98 /// range-searching volume at point 'xev', divided by the box
99 /// volume.
100 
101 Double_t TMVA::PDEFoamEventDensity::Density(std::vector<Double_t> &xev, Double_t &event_density)
102 {
103  if (!fBst)
104  Log() << kFATAL << "<PDEFoamEventDensity::Density()> Binary tree not found!" << Endl;
105 
106  //create volume around point to be found
107  std::vector<Double_t> lb(GetBox().size());
108  std::vector<Double_t> ub(GetBox().size());
109 
110  // probevolume relative to hypercube with edge length 1:
111  const Double_t probevolume_inv = 1.0 / GetBoxVolume();
112 
113  // set upper and lower bound for search volume
114  for (UInt_t idim = 0; idim < GetBox().size(); ++idim) {
115  lb[idim] = xev[idim] - GetBox().at(idim) / 2.0;
116  ub[idim] = xev[idim] + GetBox().at(idim) / 2.0;
117  }
118 
119  TMVA::Volume volume(&lb, &ub); // volume to search in
120  std::vector<const TMVA::BinarySearchTreeNode*> nodes; // BST nodes found
121 
122  // do range searching
123  const Double_t sumOfWeights = fBst->SearchVolume(&volume, &nodes);
124 
125  // store density based on total number of events
126  event_density = nodes.size() * probevolume_inv;
127 
128  // return: N_total(weighted) / cell_volume
129  return (sumOfWeights + 0.1) * probevolume_inv;
130 }
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:158
const std::vector< Double_t > & GetBox() const
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
Volume for BinarySearchTree.
Definition: Volume.h:48
MsgLogger & Log() const
message logger
unsigned int UInt_t
Definition: RtypesCore.h:42
This is a concrete implementation of PDEFoam.
#define ClassImp(name)
Definition: Rtypes.h:359
double Double_t
Definition: RtypesCore.h:55
Double_t GetBoxVolume()
Returns the volume of range searching box fBox.
This is an abstract class, which provides an interface for a PDEFoam density estimator.
Double_t SearchVolume(Volume *, std::vector< const TMVA::BinarySearchTreeNode *> *events=0)
search the whole tree and add up all weights of events that lie within the given volume ...