Logo ROOT   6.14/05
Reference Guide
PDEFoamDecisionTreeDensity.cxx
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Alexander Voigt
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Classes: PDEFoamDecisionTreeDensity *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * This 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 PDEFoamDecisionTreeDensity::Density() *
15  * does this job. It uses a binary search tree, filled with training *
16  * events, in order to 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) 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 /*! \class TMVA::PDEFoamDecisionTreeDensity
35 \ingroup TMVA
36 
37 This is a concrete implementation of PDEFoam. The Density(...)
38 function returns allways 0. The function FillHistograms() is
39 added, which returns all events in a given TMVA::Volume.
40 */
41 
43 
44 #include "TMVA/BinarySearchTree.h"
45 #include "TMVA/MethodPDERS.h"
46 #include "TMVA/MsgLogger.h"
48 #include "TMVA/Types.h"
49 #include "TMVA/Volume.h"
50 
51 #include "RtypesCore.h"
52 #include "TH1D.h"
53 
54 #include <limits>
55 
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 
62  , fClass(0)
63 {}
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 /// User constructor:
67 ///
68 /// Parameters:
69 ///
70 /// - box - size of the range-searching box (n-dimensional
71 /// std::vector)
72 ///
73 /// - cls - event class used for the range-searching
74 
76  : PDEFoamDensityBase(box)
77  , fClass(cls)
78 {
79 }
80 
81 ////////////////////////////////////////////////////////////////////////////////
82 /// Copy constructor
83 
85  : PDEFoamDensityBase(distr)
86  , fClass(distr.fClass)
87 {
88 }
89 
90 ////////////////////////////////////////////////////////////////////////////////
91 /// This function is not used in the decision tree like PDEFoam,
92 /// instead FillHist() is used.
93 
94 Double_t TMVA::PDEFoamDecisionTreeDensity::Density(std::vector<Double_t>& /* Xarg */,
95  Double_t& /* event_density */)
96 {
97  return 0;
98 }
99 
100 ////////////////////////////////////////////////////////////////////////////////
101 /// Fill the given histograms with signal and background events,
102 /// which are found in the volume.
103 ///
104 /// Parameters:
105 ///
106 /// - volume - volume box to search in
107 ///
108 /// - hsig, hbkg, hsig_unw, hbkg_unw - histograms with weighted and
109 /// unweighted signal and background events
110 
111 void TMVA::PDEFoamDecisionTreeDensity::FillHistograms(TMVA::Volume &volume, std::vector<TH1D*> &hsig,
112  std::vector<TH1D*> &hbkg, std::vector<TH1D*> &hsig_unw,
113  std::vector<TH1D*> &hbkg_unw)
114 {
115  // sanity check
116  if (hsig.size() != volume.fLower->size()
117  || hbkg.size() != volume.fLower->size()
118  || hsig_unw.size() != volume.fLower->size()
119  || hbkg_unw.size() != volume.fLower->size())
120  Log() << kFATAL << "<PDEFoamDistr::FillHistograms> Edge histograms have wrong size!" << Endl;
121 
122  // check histograms
123  for (UInt_t idim = 0; idim < hsig.size(); ++idim) {
124  if (!hsig.at(idim) || !hbkg.at(idim) ||
125  !hsig_unw.at(idim) || !hbkg_unw.at(idim))
126  Log() << kFATAL << "<PDEFoamDistr::FillHist> Histograms not initialized!" << Endl;
127  }
128 
129  // BST nodes found in volume
130  std::vector<const TMVA::BinarySearchTreeNode*> nodes;
131 
132  // do range searching
133  fBst->SearchVolume(&volume, &nodes);
134 
135  // calc xmin and xmax of events found in cell
136  std::vector<Float_t> xmin(volume.fLower->size(), std::numeric_limits<float>::max());
137  std::vector<Float_t> xmax(volume.fLower->size(), -std::numeric_limits<float>::max());
138  for (std::vector<const TMVA::BinarySearchTreeNode*>::const_iterator it = nodes.begin();
139  it != nodes.end(); ++it) {
140  std::vector<Float_t> ev = (*it)->GetEventV();
141  for (UInt_t idim = 0; idim < xmin.size(); ++idim) {
142  if (ev.at(idim) < xmin.at(idim)) xmin.at(idim) = ev.at(idim);
143  if (ev.at(idim) > xmax.at(idim)) xmax.at(idim) = ev.at(idim);
144  }
145  }
146 
147  // reset histogram ranges to xmin, xmax found in volume
148  for (UInt_t idim = 0; idim < hsig.size(); ++idim) {
149  hsig.at(idim)->GetXaxis()->SetLimits(xmin.at(idim), xmax.at(idim));
150  hbkg.at(idim)->GetXaxis()->SetLimits(xmin.at(idim), xmax.at(idim));
151  hsig_unw.at(idim)->GetXaxis()->SetLimits(xmin.at(idim), xmax.at(idim));
152  hbkg_unw.at(idim)->GetXaxis()->SetLimits(xmin.at(idim), xmax.at(idim));
153  hsig.at(idim)->Reset();
154  hbkg.at(idim)->Reset();
155  hsig_unw.at(idim)->Reset();
156  hbkg_unw.at(idim)->Reset();
157  }
158 
159  // fill histograms with events found
160  for (std::vector<const TMVA::BinarySearchTreeNode*>::const_iterator it = nodes.begin();
161  it != nodes.end(); ++it) {
162  std::vector<Float_t> ev = (*it)->GetEventV();
163  Float_t wt = (*it)->GetWeight();
164  for (UInt_t idim = 0; idim < ev.size(); ++idim) {
165  if ((*it)->GetClass() == fClass) {
166  hsig.at(idim)->Fill(ev.at(idim), wt);
167  hsig_unw.at(idim)->Fill(ev.at(idim), 1);
168  } else {
169  hbkg.at(idim)->Fill(ev.at(idim), wt);
170  hbkg_unw.at(idim)->Fill(ev.at(idim), 1);
171  }
172  }
173  }
174 }
This is a concrete implementation of PDEFoam.
std::vector< Double_t > * fLower
Definition: Volume.h:73
float xmin
Definition: THbookFile.cxx:93
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:158
float Float_t
Definition: RtypesCore.h:53
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
virtual void FillHistograms(TMVA::Volume &, std::vector< TH1D *> &, std::vector< TH1D *> &, std::vector< TH1D *> &, std::vector< TH1D *> &)
Fill the given histograms with signal and background events, which are found in the volume...
unsigned int UInt_t
Definition: RtypesCore.h:42
float xmax
Definition: THbookFile.cxx:93
#define ClassImp(name)
Definition: Rtypes.h:359
virtual Double_t Density(std::vector< Double_t > &Xarg, Double_t &event_density)
This function is not used in the decision tree like PDEFoam, instead FillHist() is used...
double Double_t
Definition: RtypesCore.h:55
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 ...