Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
PDEFoamTarget.cxx
Go to the documentation of this file.
1// @(#)root/tmva $Id$
2// Author: Tancredi Carli, Dominik Dannheim, Alexander Voigt
3
4/**********************************************************************************
5 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6 * Package: TMVA *
7 * Classes: PDEFoamTarget *
8 * *
9 * *
10 * Description: *
11 * Implementation. *
12 * *
13 * Authors (alphabetical): *
14 * Tancredi Carli - CERN, Switzerland *
15 * Dominik Dannheim - CERN, Switzerland *
16 * S. Jadach - Institute of Nuclear Physics, Cracow, Poland *
17 * Alexander Voigt - TU Dresden, Germany *
18 * Peter Speckmayer - CERN, Switzerland *
19 * *
20 * Copyright (c) 2008, 2010: *
21 * CERN, Switzerland *
22 * MPI-K Heidelberg, Germany *
23 * *
24 * Redistribution and use in source and binary forms, with or without *
25 * modification, are permitted according to the terms listed in LICENSE *
26 * (see tmva/doc/LICENSE) *
27 **********************************************************************************/
28
29/*! \class TMVA::PDEFoamTarget
30\ingroup TMVA
31This PDEFoam variant stores in every cell the average target
32fTarget (see the Constructor) as well as the statistical error on
33the target fTarget. It therefore acts as a target estimator. It
34should be booked together with the PDEFoamTargetDensity density
35estimator, which returns the target fTarget density at a given
36phase space point during the foam build-up.
37*/
38
39#include "TMVA/PDEFoamTarget.h"
40
41#include "TMVA/Event.h"
42#include "TMVA/MsgLogger.h"
43#include "TMVA/PDEFoam.h"
44#include "TMVA/PDEFoamCell.h"
46#include "TMVA/Types.h"
47
48#include "TMath.h"
49
50#include "Rtypes.h"
51
53
54////////////////////////////////////////////////////////////////////////////////
55/// Default constructor for streamer, user should not use it.
56
58: PDEFoam()
59 , fTarget(0)
60{
61}
62
63////////////////////////////////////////////////////////////////////////////////
64/// User constructor
65///
66/// Parameters:
67///
68/// - name - name of PDEFoam object
69///
70/// - target - target number to range-search for
71
73 : PDEFoam(name)
74 , fTarget(target)
75{
76}
77
78////////////////////////////////////////////////////////////////////////////////
79/// Copy Constructor NOT IMPLEMENTED (NEVER USED)
80
82 : PDEFoam(from)
83 , fTarget(from.fTarget)
84{
85 Log() << kFATAL << "COPY CONSTRUCTOR NOT IMPLEMENTED" << Endl;
86}
87
88////////////////////////////////////////////////////////////////////////////////
89/// This function fills an event into the discriminant PDEFoam. The
90/// weight 'wt' is filled into cell element 0 if the event is of
91/// class 'fTarget', and filled into cell element 1 otherwise.
92
94{
95 // find corresponding foam cell
96 std::vector<Float_t> values = ev->GetValues();
97 std::vector<Float_t> tvalues = VarTransform(values);
98 std::vector<Float_t> targets = ev->GetTargets();
99 PDEFoamCell *cell = FindCell(tvalues);
100
101 // 0. Element: Number of events
102 // 1. Element: Target 0
103 SetCellElement(cell, 0, GetCellElement(cell, 0) + wt);
104 SetCellElement(cell, 1, GetCellElement(cell, 1) + wt * targets.at(fTarget));
105}
106
107////////////////////////////////////////////////////////////////////////////////
108/// Calculate average cell target in every cell and save them to the
109/// cell. Cell element 0 will contain the average target and cell
110/// element 1 will contain the error on the target.
111
113{
114 // loop over cells
115 for (Long_t iCell = 0; iCell <= fLastCe; iCell++) {
116 if (!(fCells[iCell]->GetStat()))
117 continue;
118
119 Double_t n_ev = GetCellElement(fCells[iCell], 0); // get number of events
120 Double_t tar = GetCellElement(fCells[iCell], 1); // get sum of targets
121
122 if (n_ev > 0) {
123 SetCellElement(fCells[iCell], 0, tar / n_ev); // set average target
124 SetCellElement(fCells[iCell], 1, tar / TMath::Sqrt(n_ev)); // set error on average target
125 } else {
126 SetCellElement(fCells[iCell], 0, 0.0); // set mean target
127 SetCellElement(fCells[iCell], 1, -1); // set mean target error
128 }
129 }
130}
131
132////////////////////////////////////////////////////////////////////////////////
133/// Returns true, if the target error equals -1, as set in
134/// Finalize() in case of no events in the cell
135
137{
138 return GetCellValue(cell, kValueError) == -1;
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// This function finds the cell, which corresponds to the given
143/// untransformed event vector 'xvec' and return its value, which is
144/// given by the parameter 'cv'.
145///
146/// If cv == kValue, it is checked wether the cell value is
147/// undefined. If this is the case, then the mean of the neighbor's
148/// target values is returned, using GetAverageNeighborsValue().
149
150Float_t TMVA::PDEFoamTarget::GetCellValue(const std::vector<Float_t> &xvec, ECellValue cv, PDEFoamKernelBase *kernel)
151{
152 std::vector<Float_t> txvec(VarTransform(xvec));
153 PDEFoamCell *cell = FindCell(txvec);
154
155 if (!CellValueIsUndefined(cell)) {
156 // cell is not empty
157 if (kernel == NULL)
158 return GetCellValue(cell, cv);
159 else
160 return kernel->Estimate(this, txvec, cv);
161 } else
162 // cell is empty -> calc average target of neighbor cells
163 return GetAverageNeighborsValue(txvec, kValue);
164}
165
166////////////////////////////////////////////////////////////////////////////////
167/// This function returns the average value 'cv' of only nearest
168/// neighbor cells. It is used in cases, where empty cells shall
169/// not be evaluated.
170///
171/// Parameters:
172/// - txvec - event vector, transformed into foam coordinates [0, 1]
173/// - cv - cell value, see definition of ECellValue
174
176 ECellValue cv)
177{
178 const Float_t xoffset = 1.e-6;
179 Float_t norm = 0; // normalisation
180 Float_t result = 0; // return value
181
182 PDEFoamCell *cell = FindCell(txvec); // find corresponding cell
183 PDEFoamVect cellSize(GetTotDim());
184 PDEFoamVect cellPosi(GetTotDim());
185 cell->GetHcub(cellPosi, cellSize); // get cell coordinates
186
187 // loop over all dimensions and find neighbor cells
188 for (Int_t dim = 0; dim < GetTotDim(); dim++) {
189 std::vector<Float_t> ntxvec(txvec);
190 PDEFoamCell* left_cell = 0; // left cell
191 PDEFoamCell* right_cell = 0; // right cell
192
193 // get left cell
194 ntxvec[dim] = cellPosi[dim] - xoffset;
195 left_cell = FindCell(ntxvec);
196 if (!CellValueIsUndefined(left_cell)) {
197 // if left cell is not empty, take its value
198 result += GetCellValue(left_cell, cv);
199 norm++;
200 }
201 // get right cell
202 ntxvec[dim] = cellPosi[dim] + cellSize[dim] + xoffset;
203 right_cell = FindCell(ntxvec);
204 if (!CellValueIsUndefined(right_cell)) {
205 // if right cell is not empty, take its value
206 result += GetCellValue(right_cell, cv);
207 norm++;
208 }
209 }
210 if (norm > 0) result /= norm; // calc average target
211 else result = 0; // return null if all neighbors are empty
212
213 return result;
214}
long Long_t
Definition RtypesCore.h:54
float Float_t
Definition RtypesCore.h:57
#define ClassImp(name)
Definition Rtypes.h:377
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
char name[80]
Definition TGX11.cxx:110
std::vector< Float_t > & GetTargets()
Definition Event.h:103
std::vector< Float_t > & GetValues()
Definition Event.h:94
void GetHcub(PDEFoamVect &, PDEFoamVect &) const
Provides size and position of the cell These parameter are calculated by analyzing information in all...
This class is the abstract kernel interface for PDEFoam.
virtual Float_t Estimate(PDEFoam *, std::vector< Float_t > &, ECellValue)=0
This PDEFoam variant stores in every cell the average target fTarget (see the Constructor) as well as...
Bool_t CellValueIsUndefined(PDEFoamCell *cell)
Returns true, if the target error equals -1, as set in Finalize() in case of no events in the cell.
PDEFoamTarget()
Default constructor for streamer, user should not use it.
virtual void Finalize()
Calculate average cell target in every cell and save them to the cell.
virtual void FillFoamCells(const Event *ev, Float_t wt)
This function fills an event into the discriminant PDEFoam.
virtual Float_t GetCellValue(const std::vector< Float_t > &xvec, ECellValue cv, PDEFoamKernelBase *)
This function finds the cell, which corresponds to the given untransformed event vector 'xvec' and re...
Float_t GetAverageNeighborsValue(std::vector< Float_t > &, ECellValue)
This function returns the average value 'cv' of only nearest neighbor cells.
Implementation of PDEFoam.
Definition PDEFoam.h:79
MsgLogger & Log() const
Definition PDEFoam.h:240
Basic string class.
Definition TString.h:139
MsgLogger & Endl(MsgLogger &ml)
Definition MsgLogger.h:148
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:662