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
52
53////////////////////////////////////////////////////////////////////////////////
54/// Default constructor for streamer, user should not use it.
55
57: PDEFoam()
58 , fTarget(0)
59{
60}
61
62////////////////////////////////////////////////////////////////////////////////
63/// User constructor
64///
65/// Parameters:
66///
67/// - name - name of PDEFoam object
68///
69/// - target - target number to range-search for
70
76
77////////////////////////////////////////////////////////////////////////////////
78/// Copy Constructor NOT IMPLEMENTED (NEVER USED)
79
81 : PDEFoam(from)
82 , fTarget(from.fTarget)
83{
84 Log() << kFATAL << "COPY CONSTRUCTOR NOT IMPLEMENTED" << Endl;
85}
86
87////////////////////////////////////////////////////////////////////////////////
88/// This function fills an event into the discriminant PDEFoam. The
89/// weight 'wt' is filled into cell element 0 if the event is of
90/// class 'fTarget', and filled into cell element 1 otherwise.
91
93{
94 // find corresponding foam cell
95 std::vector<Float_t> values = ev->GetValues();
96 std::vector<Float_t> tvalues = VarTransform(values);
97 std::vector<Float_t> targets = ev->GetTargets();
98 PDEFoamCell *cell = FindCell(tvalues);
99
100 // 0. Element: Number of events
101 // 1. Element: Target 0
102 SetCellElement(cell, 0, GetCellElement(cell, 0) + wt);
103 SetCellElement(cell, 1, GetCellElement(cell, 1) + wt * targets.at(fTarget));
104}
105
106////////////////////////////////////////////////////////////////////////////////
107/// Calculate average cell target in every cell and save them to the
108/// cell. Cell element 0 will contain the average target and cell
109/// element 1 will contain the error on the target.
110
112{
113 // loop over cells
114 for (Long_t iCell = 0; iCell <= fLastCe; iCell++) {
115 if (!(fCells[iCell]->GetStat()))
116 continue;
117
118 Double_t n_ev = GetCellElement(fCells[iCell], 0); // get number of events
119 Double_t tar = GetCellElement(fCells[iCell], 1); // get sum of targets
120
121 if (n_ev > 0) {
122 SetCellElement(fCells[iCell], 0, tar / n_ev); // set average target
123 SetCellElement(fCells[iCell], 1, tar / TMath::Sqrt(n_ev)); // set error on average target
124 } else {
125 SetCellElement(fCells[iCell], 0, 0.0); // set mean target
126 SetCellElement(fCells[iCell], 1, -1); // set mean target error
127 }
128 }
129}
130
131////////////////////////////////////////////////////////////////////////////////
132/// Returns true, if the target error equals -1, as set in
133/// Finalize() in case of no events in the cell
134
136{
137 return GetCellValue(cell, kValueError) == -1;
138}
139
140////////////////////////////////////////////////////////////////////////////////
141/// This function finds the cell, which corresponds to the given
142/// untransformed event vector 'xvec' and return its value, which is
143/// given by the parameter 'cv'.
144///
145/// If cv == kValue, it is checked wether the cell value is
146/// undefined. If this is the case, then the mean of the neighbor's
147/// target values is returned, using GetAverageNeighborsValue().
148
149Float_t TMVA::PDEFoamTarget::GetCellValue(const std::vector<Float_t> &xvec, ECellValue cv, PDEFoamKernelBase *kernel)
150{
151 std::vector<Float_t> txvec(VarTransform(xvec));
152 PDEFoamCell *cell = FindCell(txvec);
153
154 if (!CellValueIsUndefined(cell)) {
155 // cell is not empty
156 if (kernel == NULL)
157 return GetCellValue(cell, cv);
158 else
159 return kernel->Estimate(this, txvec, cv);
160 } else
161 // cell is empty -> calc average target of neighbor cells
162 return GetAverageNeighborsValue(txvec, kValue);
163}
164
165////////////////////////////////////////////////////////////////////////////////
166/// This function returns the average value 'cv' of only nearest
167/// neighbor cells. It is used in cases, where empty cells shall
168/// not be evaluated.
169///
170/// Parameters:
171/// - txvec - event vector, transformed into foam coordinates [0, 1]
172/// - cv - cell value, see definition of ECellValue
173
175 ECellValue cv)
176{
177 const Float_t xoffset = 1.e-6;
178 Float_t norm = 0; // normalisation
179 Float_t result = 0; // return value
180
181 PDEFoamCell *cell = FindCell(txvec); // find corresponding cell
182 PDEFoamVect cellSize(GetTotDim());
183 PDEFoamVect cellPosi(GetTotDim());
184 cell->GetHcub(cellPosi, cellSize); // get cell coordinates
185
186 // loop over all dimensions and find neighbor cells
187 for (Int_t dim = 0; dim < GetTotDim(); dim++) {
188 std::vector<Float_t> ntxvec(txvec);
189 PDEFoamCell* left_cell = 0; // left cell
190 PDEFoamCell* right_cell = 0; // right cell
191
192 // get left cell
193 ntxvec[dim] = cellPosi[dim] - xoffset;
194 left_cell = FindCell(ntxvec);
195 if (!CellValueIsUndefined(left_cell)) {
196 // if left cell is not empty, take its value
197 result += GetCellValue(left_cell, cv);
198 norm++;
199 }
200 // get right cell
201 ntxvec[dim] = cellPosi[dim] + cellSize[dim] + xoffset;
202 right_cell = FindCell(ntxvec);
203 if (!CellValueIsUndefined(right_cell)) {
204 // if right cell is not empty, take its value
205 result += GetCellValue(right_cell, cv);
206 norm++;
207 }
208 }
209 if (norm > 0) result /= norm; // calc average target
210 else result = 0; // return null if all neighbors are empty
211
212 return result;
213}
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
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.
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
This class is the abstract kernel interface for PDEFoam.
This PDEFoam variant stores in every cell the average target fTarget (see the Constructor) as well as...
void Finalize() override
Calculate average cell target in every cell and save them to the cell.
Bool_t CellValueIsUndefined(PDEFoamCell *cell) override
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.
Float_t GetCellValue(const std::vector< Float_t > &xvec, ECellValue cv, PDEFoamKernelBase *) override
This function finds the cell, which corresponds to the given untransformed event vector 'xvec' and re...
void FillFoamCells(const Event *ev, Float_t wt) override
This function fills an event into the discriminant PDEFoam.
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:138
MsgLogger & Endl(MsgLogger &ml)
Definition MsgLogger.h:148
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:673