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