Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 * *
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 * (see tmva/doc/LICENSE) *
32 **********************************************************************************/
33
34/*! \class TMVA::PDEFoamDecisionTreeDensity
35\ingroup TMVA
36
37This is a concrete implementation of PDEFoam. The Density(...)
38function returns allways 0. The function FillHistograms() is
39added, which returns all events in a given TMVA::Volume.
40*/
41
43
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
56
57////////////////////////////////////////////////////////////////////////////////
58
63
64////////////////////////////////////////////////////////////////////////////////
65/// User constructor:
66///
67/// Parameters:
68///
69/// - box - size of the range-searching box (n-dimensional
70/// std::vector)
71///
72/// - cls - event class used for the range-searching
73
79
80////////////////////////////////////////////////////////////////////////////////
81/// Copy constructor
82
88
89////////////////////////////////////////////////////////////////////////////////
90/// This function is not used in the decision tree like PDEFoam,
91/// instead FillHist() is used.
92
93Double_t TMVA::PDEFoamDecisionTreeDensity::Density(std::vector<Double_t>& /* Xarg */,
94 Double_t& /* event_density */)
95{
96 return 0;
97}
98
99////////////////////////////////////////////////////////////////////////////////
100/// Fill the given histograms with signal and background events,
101/// which are found in the volume.
102///
103/// Parameters:
104///
105/// - volume - volume box to search in
106///
107/// - hsig, hbkg, hsig_unw, hbkg_unw - histograms with weighted and
108/// unweighted signal and background events
109
111 std::vector<TH1D*> &hbkg, std::vector<TH1D*> &hsig_unw,
112 std::vector<TH1D*> &hbkg_unw)
113{
114 // sanity check
115 if (hsig.size() != volume.fLower->size()
116 || hbkg.size() != volume.fLower->size()
117 || hsig_unw.size() != volume.fLower->size()
118 || hbkg_unw.size() != volume.fLower->size())
119 Log() << kFATAL << "<PDEFoamDistr::FillHistograms> Edge histograms have wrong size!" << Endl;
120
121 // check histograms
122 for (UInt_t idim = 0; idim < hsig.size(); ++idim) {
123 if (!hsig.at(idim) || !hbkg.at(idim) ||
124 !hsig_unw.at(idim) || !hbkg_unw.at(idim))
125 Log() << kFATAL << "<PDEFoamDistr::FillHist> Histograms not initialized!" << Endl;
126 }
127
128 // BST nodes found in volume
129 std::vector<const TMVA::BinarySearchTreeNode*> nodes;
130
131 // do range searching
132 fBst->SearchVolume(&volume, &nodes);
133
134 // calc xmin and xmax of events found in cell
135 std::vector<Float_t> xmin(volume.fLower->size(), std::numeric_limits<float>::max());
136 std::vector<Float_t> xmax(volume.fLower->size(), -std::numeric_limits<float>::max());
137 for (std::vector<const TMVA::BinarySearchTreeNode*>::const_iterator it = nodes.begin();
138 it != nodes.end(); ++it) {
139 std::vector<Float_t> ev = (*it)->GetEventV();
140 for (UInt_t idim = 0; idim < xmin.size(); ++idim) {
141 if (ev.at(idim) < xmin.at(idim)) xmin.at(idim) = ev.at(idim);
142 if (ev.at(idim) > xmax.at(idim)) xmax.at(idim) = ev.at(idim);
143 }
144 }
145
146 // reset histogram ranges to xmin, xmax found in volume
147 for (UInt_t idim = 0; idim < hsig.size(); ++idim) {
148 hsig.at(idim)->GetXaxis()->SetLimits(xmin.at(idim), xmax.at(idim));
149 hbkg.at(idim)->GetXaxis()->SetLimits(xmin.at(idim), xmax.at(idim));
150 hsig_unw.at(idim)->GetXaxis()->SetLimits(xmin.at(idim), xmax.at(idim));
151 hbkg_unw.at(idim)->GetXaxis()->SetLimits(xmin.at(idim), xmax.at(idim));
152 hsig.at(idim)->Reset();
153 hbkg.at(idim)->Reset();
154 hsig_unw.at(idim)->Reset();
155 hbkg_unw.at(idim)->Reset();
156 }
157
158 // fill histograms with events found
159 for (std::vector<const TMVA::BinarySearchTreeNode*>::const_iterator it = nodes.begin();
160 it != nodes.end(); ++it) {
161 std::vector<Float_t> ev = (*it)->GetEventV();
162 Float_t wt = (*it)->GetWeight();
163 for (UInt_t idim = 0; idim < ev.size(); ++idim) {
164 if ((*it)->GetClass() == fClass) {
165 hsig.at(idim)->Fill(ev.at(idim), wt);
166 hsig_unw.at(idim)->Fill(ev.at(idim), 1);
167 } else {
168 hbkg.at(idim)->Fill(ev.at(idim), wt);
169 hbkg_unw.at(idim)->Fill(ev.at(idim), 1);
170 }
171 }
172 }
173}
Cppyy::TCppType_t fClass
Basic types used by ROOT and required by TInterpreter.
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
float xmin
float xmax
This is a concrete implementation of PDEFoam.
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.
Double_t Density(std::vector< Double_t > &Xarg, Double_t &event_density) override
This function is not used in the decision tree like PDEFoam, instead FillHist() is used.
This is an abstract class, which provides an interface for a PDEFoam density estimator.
Volume for BinarySearchTree.
Definition Volume.h:47
std::vector< Double_t > * fLower
vector with lower volume dimensions
Definition Volume.h:75
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition fillpatterns.C:1
MsgLogger & Endl(MsgLogger &ml)
Definition MsgLogger.h:148