ROOT  6.06/09
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 
43 #include <limits>
44 
45 #ifndef ROOT_TMVA_PDEFoamDecisionTreeDensity
47 #endif
48 
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 
53 TMVA::PDEFoamDecisionTreeDensity::PDEFoamDecisionTreeDensity()
54  : PDEFoamDensityBase()
55  , fClass(0)
56 {}
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// User construcor:
60 ///
61 /// Parameters:
62 ///
63 /// - box - size of the range-searching box (n-dimensional
64 /// std::vector)
65 ///
66 /// - cls - event class used for the range-searching
67 
69  : PDEFoamDensityBase(box)
70  , fClass(cls)
71 {
72 }
73 
74 ////////////////////////////////////////////////////////////////////////////////
75 /// Copy constructor
76 
78  : PDEFoamDensityBase(distr)
79  , fClass(distr.fClass)
80 {
81 }
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 /// This function is not used in the decision tree like PDEFoam,
85 /// instead FillHist() is used.
86 
87 Double_t TMVA::PDEFoamDecisionTreeDensity::Density(std::vector<Double_t>& /* Xarg */,
88  Double_t& /* event_density */)
89 {
90  return 0;
91 }
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 /// Fill the given histograms with signal and background events,
95 /// which are found in the volume.
96 ///
97 /// Parameters:
98 ///
99 /// - volume - volume box to search in
100 ///
101 /// - hsig, hbkg, hsig_unw, hbkg_unw - histograms with weighted and
102 /// unweighted signal and background events
103 
104 void TMVA::PDEFoamDecisionTreeDensity::FillHistograms(TMVA::Volume &volume, std::vector<TH1D*> &hsig,
105  std::vector<TH1D*> &hbkg, std::vector<TH1D*> &hsig_unw,
106  std::vector<TH1D*> &hbkg_unw)
107 {
108  // sanity check
109  if (hsig.size() != volume.fLower->size()
110  || hbkg.size() != volume.fLower->size()
111  || hsig_unw.size() != volume.fLower->size()
112  || hbkg_unw.size() != volume.fLower->size())
113  Log() << kFATAL << "<PDEFoamDistr::FillHistograms> Edge histograms have wrong size!" << Endl;
114 
115  // check histograms
116  for (UInt_t idim = 0; idim < hsig.size(); ++idim) {
117  if (!hsig.at(idim) || !hbkg.at(idim) ||
118  !hsig_unw.at(idim) || !hbkg_unw.at(idim))
119  Log() << kFATAL << "<PDEFoamDistr::FillHist> Histograms not initialized!" << Endl;
120  }
121 
122  // BST nodes found in volume
123  std::vector<const TMVA::BinarySearchTreeNode*> nodes;
124 
125  // do range searching
126  fBst->SearchVolume(&volume, &nodes);
127 
128  // calc xmin and xmax of events found in cell
129  std::vector<Float_t> xmin(volume.fLower->size(), std::numeric_limits<float>::max());
130  std::vector<Float_t> xmax(volume.fLower->size(), -std::numeric_limits<float>::max());
131  for (std::vector<const TMVA::BinarySearchTreeNode*>::const_iterator it = nodes.begin();
132  it != nodes.end(); ++it) {
133  std::vector<Float_t> ev = (*it)->GetEventV();
134  for (UInt_t idim = 0; idim < xmin.size(); ++idim) {
135  if (ev.at(idim) < xmin.at(idim)) xmin.at(idim) = ev.at(idim);
136  if (ev.at(idim) > xmax.at(idim)) xmax.at(idim) = ev.at(idim);
137  }
138  }
139 
140  // reset histogram ranges to xmin, xmax found in volume
141  for (UInt_t idim = 0; idim < hsig.size(); ++idim) {
142  hsig.at(idim)->GetXaxis()->SetLimits(xmin.at(idim), xmax.at(idim));
143  hbkg.at(idim)->GetXaxis()->SetLimits(xmin.at(idim), xmax.at(idim));
144  hsig_unw.at(idim)->GetXaxis()->SetLimits(xmin.at(idim), xmax.at(idim));
145  hbkg_unw.at(idim)->GetXaxis()->SetLimits(xmin.at(idim), xmax.at(idim));
146  hsig.at(idim)->Reset();
147  hbkg.at(idim)->Reset();
148  hsig_unw.at(idim)->Reset();
149  hbkg_unw.at(idim)->Reset();
150  }
151 
152  // fill histograms with events found
153  for (std::vector<const TMVA::BinarySearchTreeNode*>::const_iterator it = nodes.begin();
154  it != nodes.end(); ++it) {
155  std::vector<Float_t> ev = (*it)->GetEventV();
156  Float_t wt = (*it)->GetWeight();
157  for (UInt_t idim = 0; idim < ev.size(); ++idim) {
158  if ((*it)->GetClass() == fClass) {
159  hsig.at(idim)->Fill(ev.at(idim), wt);
160  hsig_unw.at(idim)->Fill(ev.at(idim), 1);
161  } else {
162  hbkg.at(idim)->Fill(ev.at(idim), wt);
163  hbkg_unw.at(idim)->Fill(ev.at(idim), 1);
164  }
165  }
166  }
167 }
std::vector< Double_t > * fLower
Definition: Volume.h:75
float xmin
Definition: THbookFile.cxx:93
ClassImp(TMVA::PDEFoamDecisionTreeDensity) TMVA
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:162
float Float_t
Definition: RtypesCore.h:53
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...
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
TClass * fClass
pointer to the foreign object
unsigned int UInt_t
Definition: RtypesCore.h:42
float xmax
Definition: THbookFile.cxx:93
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
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Definition: vector.h:440
Abstract ClassifierFactory template that handles arbitrary types.
Definition: math.cpp:60