ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
49 #include "TMVA/BinarySearchTree.h"
50 #include "TMVA/MethodPDERS.h"
51 #include "TMVA/MsgLogger.h"
52 #include "TMVA/Types.h"
53 #include "TMVA/Volume.h"
54 
55 #include "RtypesCore.h"
56 #include "TH1D.h"
57 
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 
62 TMVA::PDEFoamDecisionTreeDensity::PDEFoamDecisionTreeDensity()
63  : PDEFoamDensityBase()
64  , fClass(0)
65 {}
66 
67 ////////////////////////////////////////////////////////////////////////////////
68 /// User construcor:
69 ///
70 /// Parameters:
71 ///
72 /// - box - size of the range-searching box (n-dimensional
73 /// std::vector)
74 ///
75 /// - cls - event class used for the range-searching
76 
78  : PDEFoamDensityBase(box)
79  , fClass(cls)
80 {
81 }
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 /// Copy constructor
85 
87  : PDEFoamDensityBase(distr)
88  , fClass(distr.fClass)
89 {
90 }
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 /// This function is not used in the decision tree like PDEFoam,
94 /// instead FillHist() is used.
95 
96 Double_t TMVA::PDEFoamDecisionTreeDensity::Density(std::vector<Double_t>& /* Xarg */,
97  Double_t& /* event_density */)
98 {
99  return 0;
100 }
101 
102 ////////////////////////////////////////////////////////////////////////////////
103 /// Fill the given histograms with signal and background events,
104 /// which are found in the volume.
105 ///
106 /// Parameters:
107 ///
108 /// - volume - volume box to search in
109 ///
110 /// - hsig, hbkg, hsig_unw, hbkg_unw - histograms with weighted and
111 /// unweighted signal and background events
112 
113 void TMVA::PDEFoamDecisionTreeDensity::FillHistograms(TMVA::Volume &volume, std::vector<TH1D*> &hsig,
114  std::vector<TH1D*> &hbkg, std::vector<TH1D*> &hsig_unw,
115  std::vector<TH1D*> &hbkg_unw)
116 {
117  // sanity check
118  if (hsig.size() != volume.fLower->size()
119  || hbkg.size() != volume.fLower->size()
120  || hsig_unw.size() != volume.fLower->size()
121  || hbkg_unw.size() != volume.fLower->size())
122  Log() << kFATAL << "<PDEFoamDistr::FillHistograms> Edge histograms have wrong size!" << Endl;
123 
124  // check histograms
125  for (UInt_t idim = 0; idim < hsig.size(); ++idim) {
126  if (!hsig.at(idim) || !hbkg.at(idim) ||
127  !hsig_unw.at(idim) || !hbkg_unw.at(idim))
128  Log() << kFATAL << "<PDEFoamDistr::FillHist> Histograms not initialized!" << Endl;
129  }
130 
131  // BST nodes found in volume
132  std::vector<const TMVA::BinarySearchTreeNode*> nodes;
133 
134  // do range searching
135  fBst->SearchVolume(&volume, &nodes);
136 
137  // calc xmin and xmax of events found in cell
138  std::vector<Float_t> xmin(volume.fLower->size(), std::numeric_limits<float>::max());
139  std::vector<Float_t> xmax(volume.fLower->size(), -std::numeric_limits<float>::max());
140  for (std::vector<const TMVA::BinarySearchTreeNode*>::const_iterator it = nodes.begin();
141  it != nodes.end(); ++it) {
142  std::vector<Float_t> ev = (*it)->GetEventV();
143  for (UInt_t idim = 0; idim < xmin.size(); ++idim) {
144  if (ev.at(idim) < xmin.at(idim)) xmin.at(idim) = ev.at(idim);
145  if (ev.at(idim) > xmax.at(idim)) xmax.at(idim) = ev.at(idim);
146  }
147  }
148 
149  // reset histogram ranges to xmin, xmax found in volume
150  for (UInt_t idim = 0; idim < hsig.size(); ++idim) {
151  hsig.at(idim)->GetXaxis()->SetLimits(xmin.at(idim), xmax.at(idim));
152  hbkg.at(idim)->GetXaxis()->SetLimits(xmin.at(idim), xmax.at(idim));
153  hsig_unw.at(idim)->GetXaxis()->SetLimits(xmin.at(idim), xmax.at(idim));
154  hbkg_unw.at(idim)->GetXaxis()->SetLimits(xmin.at(idim), xmax.at(idim));
155  hsig.at(idim)->Reset();
156  hbkg.at(idim)->Reset();
157  hsig_unw.at(idim)->Reset();
158  hbkg_unw.at(idim)->Reset();
159  }
160 
161  // fill histograms with events found
162  for (std::vector<const TMVA::BinarySearchTreeNode*>::const_iterator it = nodes.begin();
163  it != nodes.end(); ++it) {
164  std::vector<Float_t> ev = (*it)->GetEventV();
165  Float_t wt = (*it)->GetWeight();
166  for (UInt_t idim = 0; idim < ev.size(); ++idim) {
167  if ((*it)->GetClass() == fClass) {
168  hsig.at(idim)->Fill(ev.at(idim), wt);
169  hsig_unw.at(idim)->Fill(ev.at(idim), 1);
170  } else {
171  hbkg.at(idim)->Fill(ev.at(idim), wt);
172  hbkg_unw.at(idim)->Fill(ev.at(idim), 1);
173  }
174  }
175  }
176 }
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
double distr(double *x, double *p)
Definition: unuranDemo.C:104
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
Definition: math.cpp:60