ROOT logo
// @(#)root/tmva $Id: PDEFoamEventDensity.cxx 40028 2011-06-27 17:15:12Z stelzer $
// Author: Tancredi Carli, Dominik Dannheim, Alexander Voigt

/**********************************************************************************
 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
 * Package: TMVA                                                                  *
 * Classes: PDEFoamEventDensity                                                   *
 * Web    : http://tmva.sourceforge.net                                           *
 *                                                                                *
 * Description:                                                                   *
 *      The TFDSITR class provides an interface between the Binary search tree    *
 *      and the PDEFoam object.  In order to build-up the foam one needs to       *
 *      calculate the density of events at a given point (sampling during         *
 *      Foam build-up).  The function PDEFoamEventDensity::Density() does         *
 *      this job.  It                                                             *
 *      uses a binary search tree, filled with training events, in order to       *
 *      provide this density.                                                     *
 *                                                                                *
 * Authors (alphabetical):                                                        *
 *      Tancredi Carli   - CERN, Switzerland                                      *
 *      Dominik Dannheim - CERN, Switzerland                                      *
 *      S. Jadach        - Institute of Nuclear Physics, Cracow, Poland           *
 *      Alexander Voigt  - TU Dresden, Germany                                    *
 *      Peter Speckmayer - CERN, Switzerland                                      *
 *                                                                                *
 * Copyright (c) 2008, 2010:                                                      *
 *      CERN, Switzerland                                                         *
 *      MPI-K Heidelberg, Germany                                                 *
 *                                                                                *
 * Redistribution and use in source and binary forms, with or without             *
 * modification, are permitted according to the terms listed in LICENSE           *
 * (http://tmva.sourceforge.net/LICENSE)                                          *
 **********************************************************************************/

//_____________________________________________________________________
//
// PDEFoamEventDensity
//
// This is a concrete implementation of PDEFoam.  Density(...)
// estimates the event (weight) density at a given phase-space point
// using range-searching.
// _____________________________________________________________________

#include <cmath>

#ifndef ROOT_TMVA_PDEFoamEventDensity
#include "TMVA/PDEFoamEventDensity.h"
#endif

ClassImp(TMVA::PDEFoamEventDensity)

//_____________________________________________________________________
TMVA::PDEFoamEventDensity::PDEFoamEventDensity()
   : PDEFoamDensityBase()
{}

//_____________________________________________________________________
TMVA::PDEFoamEventDensity::PDEFoamEventDensity(std::vector<Double_t> box)
   : PDEFoamDensityBase(box)
{
   // User construcor
   //
   // Parameters:
   //
   // - box - size of sampling box
}

//_____________________________________________________________________
TMVA::PDEFoamEventDensity::PDEFoamEventDensity(const PDEFoamEventDensity &distr)
   : PDEFoamDensityBase(distr)
{
   // Copy constructor
}

//_____________________________________________________________________
Double_t TMVA::PDEFoamEventDensity::Density(std::vector<Double_t> &Xarg, Double_t &event_density)
{
   // This function is needed during the foam buildup.  It returns the
   // event density within the range-searching volume (specified by
   // fBox).
   //
   // Parameters:
   //
   // - Xarg - event vector (in [fXmin,fXmax]) to place the box at
   //
   // - event_density - here the event density is stored
   //
   // Returns:
   //
   // Number of events (event weights), which were found in the
   // range-searching volume at point 'Xarg', divided by the box
   // volume.

   if (!fBst)
      Log() << kFATAL << "<PDEFoamEventDensity::Density()> Binary tree not found!" << Endl;

   //create volume around point to be found
   std::vector<Double_t> lb(GetBox().size());
   std::vector<Double_t> ub(GetBox().size());

   // probevolume relative to hypercube with edge length 1:
   const Double_t probevolume_inv = 1.0 / GetBoxVolume();

   // set upper and lower bound for search volume
   for (UInt_t idim = 0; idim < GetBox().size(); ++idim) {
      lb[idim] = Xarg[idim] - GetBox().at(idim) / 2.0;
      ub[idim] = Xarg[idim] + GetBox().at(idim) / 2.0;
   }

   TMVA::Volume volume(&lb, &ub);                        // volume to search in
   std::vector<const TMVA::BinarySearchTreeNode*> nodes; // BST nodes found

   // do range searching
   Double_t SumOfWeights = fBst->SearchVolume(&volume, &nodes);

   // store density based on total number of events
   event_density = nodes.size() * probevolume_inv;

   // return:  N_total(weighted) / cell_volume
   return (SumOfWeights + 0.1) * probevolume_inv;
}
 PDEFoamEventDensity.cxx:1
 PDEFoamEventDensity.cxx:2
 PDEFoamEventDensity.cxx:3
 PDEFoamEventDensity.cxx:4
 PDEFoamEventDensity.cxx:5
 PDEFoamEventDensity.cxx:6
 PDEFoamEventDensity.cxx:7
 PDEFoamEventDensity.cxx:8
 PDEFoamEventDensity.cxx:9
 PDEFoamEventDensity.cxx:10
 PDEFoamEventDensity.cxx:11
 PDEFoamEventDensity.cxx:12
 PDEFoamEventDensity.cxx:13
 PDEFoamEventDensity.cxx:14
 PDEFoamEventDensity.cxx:15
 PDEFoamEventDensity.cxx:16
 PDEFoamEventDensity.cxx:17
 PDEFoamEventDensity.cxx:18
 PDEFoamEventDensity.cxx:19
 PDEFoamEventDensity.cxx:20
 PDEFoamEventDensity.cxx:21
 PDEFoamEventDensity.cxx:22
 PDEFoamEventDensity.cxx:23
 PDEFoamEventDensity.cxx:24
 PDEFoamEventDensity.cxx:25
 PDEFoamEventDensity.cxx:26
 PDEFoamEventDensity.cxx:27
 PDEFoamEventDensity.cxx:28
 PDEFoamEventDensity.cxx:29
 PDEFoamEventDensity.cxx:30
 PDEFoamEventDensity.cxx:31
 PDEFoamEventDensity.cxx:32
 PDEFoamEventDensity.cxx:33
 PDEFoamEventDensity.cxx:34
 PDEFoamEventDensity.cxx:35
 PDEFoamEventDensity.cxx:36
 PDEFoamEventDensity.cxx:37
 PDEFoamEventDensity.cxx:38
 PDEFoamEventDensity.cxx:39
 PDEFoamEventDensity.cxx:40
 PDEFoamEventDensity.cxx:41
 PDEFoamEventDensity.cxx:42
 PDEFoamEventDensity.cxx:43
 PDEFoamEventDensity.cxx:44
 PDEFoamEventDensity.cxx:45
 PDEFoamEventDensity.cxx:46
 PDEFoamEventDensity.cxx:47
 PDEFoamEventDensity.cxx:48
 PDEFoamEventDensity.cxx:49
 PDEFoamEventDensity.cxx:50
 PDEFoamEventDensity.cxx:51
 PDEFoamEventDensity.cxx:52
 PDEFoamEventDensity.cxx:53
 PDEFoamEventDensity.cxx:54
 PDEFoamEventDensity.cxx:55
 PDEFoamEventDensity.cxx:56
 PDEFoamEventDensity.cxx:57
 PDEFoamEventDensity.cxx:58
 PDEFoamEventDensity.cxx:59
 PDEFoamEventDensity.cxx:60
 PDEFoamEventDensity.cxx:61
 PDEFoamEventDensity.cxx:62
 PDEFoamEventDensity.cxx:63
 PDEFoamEventDensity.cxx:64
 PDEFoamEventDensity.cxx:65
 PDEFoamEventDensity.cxx:66
 PDEFoamEventDensity.cxx:67
 PDEFoamEventDensity.cxx:68
 PDEFoamEventDensity.cxx:69
 PDEFoamEventDensity.cxx:70
 PDEFoamEventDensity.cxx:71
 PDEFoamEventDensity.cxx:72
 PDEFoamEventDensity.cxx:73
 PDEFoamEventDensity.cxx:74
 PDEFoamEventDensity.cxx:75
 PDEFoamEventDensity.cxx:76
 PDEFoamEventDensity.cxx:77
 PDEFoamEventDensity.cxx:78
 PDEFoamEventDensity.cxx:79
 PDEFoamEventDensity.cxx:80
 PDEFoamEventDensity.cxx:81
 PDEFoamEventDensity.cxx:82
 PDEFoamEventDensity.cxx:83
 PDEFoamEventDensity.cxx:84
 PDEFoamEventDensity.cxx:85
 PDEFoamEventDensity.cxx:86
 PDEFoamEventDensity.cxx:87
 PDEFoamEventDensity.cxx:88
 PDEFoamEventDensity.cxx:89
 PDEFoamEventDensity.cxx:90
 PDEFoamEventDensity.cxx:91
 PDEFoamEventDensity.cxx:92
 PDEFoamEventDensity.cxx:93
 PDEFoamEventDensity.cxx:94
 PDEFoamEventDensity.cxx:95
 PDEFoamEventDensity.cxx:96
 PDEFoamEventDensity.cxx:97
 PDEFoamEventDensity.cxx:98
 PDEFoamEventDensity.cxx:99
 PDEFoamEventDensity.cxx:100
 PDEFoamEventDensity.cxx:101
 PDEFoamEventDensity.cxx:102
 PDEFoamEventDensity.cxx:103
 PDEFoamEventDensity.cxx:104
 PDEFoamEventDensity.cxx:105
 PDEFoamEventDensity.cxx:106
 PDEFoamEventDensity.cxx:107
 PDEFoamEventDensity.cxx:108
 PDEFoamEventDensity.cxx:109
 PDEFoamEventDensity.cxx:110
 PDEFoamEventDensity.cxx:111
 PDEFoamEventDensity.cxx:112
 PDEFoamEventDensity.cxx:113
 PDEFoamEventDensity.cxx:114
 PDEFoamEventDensity.cxx:115
 PDEFoamEventDensity.cxx:116
 PDEFoamEventDensity.cxx:117
 PDEFoamEventDensity.cxx:118
 PDEFoamEventDensity.cxx:119
 PDEFoamEventDensity.cxx:120
 PDEFoamEventDensity.cxx:121