Logo ROOT   6.08/07
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 //_____________________________________________________________________
35 //
36 // PDEFoamDecisionTreeDensity
37 //
38 // This is a concrete implementation of PDEFoam. The Density(...)
39 // function returns allways 0. The function FillHistograms() is
40 // added, which returns all events in a given TMVA::Volume.
41 // _____________________________________________________________________
42 
44 
45 #include "TMVA/BinarySearchTree.h"
46 #include "TMVA/MethodPDERS.h"
47 #include "TMVA/MsgLogger.h"
49 #include "TMVA/Types.h"
50 #include "TMVA/Volume.h"
51 
52 #include "RtypesCore.h"
53 #include "TH1D.h"
54 
55 #include <limits>
56 
58 
59 ////////////////////////////////////////////////////////////////////////////////
60 
63  , fClass(0)
64 {}
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// User construcor:
68 ///
69 /// Parameters:
70 ///
71 /// - box - size of the range-searching box (n-dimensional
72 /// std::vector)
73 ///
74 /// - cls - event class used for the range-searching
75 
77  : PDEFoamDensityBase(box)
78  , fClass(cls)
79 {
80 }
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Copy constructor
84 
86  : PDEFoamDensityBase(distr)
87  , fClass(distr.fClass)
88 {
89 }
90 
91 ////////////////////////////////////////////////////////////////////////////////
92 /// This function is not used in the decision tree like PDEFoam,
93 /// instead FillHist() is used.
94 
95 Double_t TMVA::PDEFoamDecisionTreeDensity::Density(std::vector<Double_t>& /* Xarg */,
96  Double_t& /* event_density */)
97 {
98  return 0;
99 }
100 
101 ////////////////////////////////////////////////////////////////////////////////
102 /// Fill the given histograms with signal and background events,
103 /// which are found in the volume.
104 ///
105 /// Parameters:
106 ///
107 /// - volume - volume box to search in
108 ///
109 /// - hsig, hbkg, hsig_unw, hbkg_unw - histograms with weighted and
110 /// unweighted signal and background events
111 
112 void TMVA::PDEFoamDecisionTreeDensity::FillHistograms(TMVA::Volume &volume, std::vector<TH1D*> &hsig,
113  std::vector<TH1D*> &hbkg, std::vector<TH1D*> &hsig_unw,
114  std::vector<TH1D*> &hbkg_unw)
115 {
116  // sanity check
117  if (hsig.size() != volume.fLower->size()
118  || hbkg.size() != volume.fLower->size()
119  || hsig_unw.size() != volume.fLower->size()
120  || hbkg_unw.size() != volume.fLower->size())
121  Log() << kFATAL << "<PDEFoamDistr::FillHistograms> Edge histograms have wrong size!" << Endl;
122 
123  // check histograms
124  for (UInt_t idim = 0; idim < hsig.size(); ++idim) {
125  if (!hsig.at(idim) || !hbkg.at(idim) ||
126  !hsig_unw.at(idim) || !hbkg_unw.at(idim))
127  Log() << kFATAL << "<PDEFoamDistr::FillHist> Histograms not initialized!" << Endl;
128  }
129 
130  // BST nodes found in volume
131  std::vector<const TMVA::BinarySearchTreeNode*> nodes;
132 
133  // do range searching
134  fBst->SearchVolume(&volume, &nodes);
135 
136  // calc xmin and xmax of events found in cell
137  std::vector<Float_t> xmin(volume.fLower->size(), std::numeric_limits<float>::max());
138  std::vector<Float_t> xmax(volume.fLower->size(), -std::numeric_limits<float>::max());
139  for (std::vector<const TMVA::BinarySearchTreeNode*>::const_iterator it = nodes.begin();
140  it != nodes.end(); ++it) {
141  std::vector<Float_t> ev = (*it)->GetEventV();
142  for (UInt_t idim = 0; idim < xmin.size(); ++idim) {
143  if (ev.at(idim) < xmin.at(idim)) xmin.at(idim) = ev.at(idim);
144  if (ev.at(idim) > xmax.at(idim)) xmax.at(idim) = ev.at(idim);
145  }
146  }
147 
148  // reset histogram ranges to xmin, xmax found in volume
149  for (UInt_t idim = 0; idim < hsig.size(); ++idim) {
150  hsig.at(idim)->GetXaxis()->SetLimits(xmin.at(idim), xmax.at(idim));
151  hbkg.at(idim)->GetXaxis()->SetLimits(xmin.at(idim), xmax.at(idim));
152  hsig_unw.at(idim)->GetXaxis()->SetLimits(xmin.at(idim), xmax.at(idim));
153  hbkg_unw.at(idim)->GetXaxis()->SetLimits(xmin.at(idim), xmax.at(idim));
154  hsig.at(idim)->Reset();
155  hbkg.at(idim)->Reset();
156  hsig_unw.at(idim)->Reset();
157  hbkg_unw.at(idim)->Reset();
158  }
159 
160  // fill histograms with events found
161  for (std::vector<const TMVA::BinarySearchTreeNode*>::const_iterator it = nodes.begin();
162  it != nodes.end(); ++it) {
163  std::vector<Float_t> ev = (*it)->GetEventV();
164  Float_t wt = (*it)->GetWeight();
165  for (UInt_t idim = 0; idim < ev.size(); ++idim) {
166  if ((*it)->GetClass() == fClass) {
167  hsig.at(idim)->Fill(ev.at(idim), wt);
168  hsig_unw.at(idim)->Fill(ev.at(idim), 1);
169  } else {
170  hbkg.at(idim)->Fill(ev.at(idim), wt);
171  hbkg_unw.at(idim)->Fill(ev.at(idim), 1);
172  }
173  }
174  }
175 }
std::vector< Double_t > * fLower
Definition: Volume.h:75
float xmin
Definition: THbookFile.cxx:93
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:162
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
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:279
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
Abstract ClassifierFactory template that handles arbitrary types.
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 ...