59 ClassImp(TMVA::PDEFoamDiscriminant);
64 TMVA::PDEFoamDiscriminant::PDEFoamDiscriminant()
72 TMVA::PDEFoamDiscriminant::PDEFoamDiscriminant(
const TString& name, UInt_t cls)
80 TMVA::PDEFoamDiscriminant::PDEFoamDiscriminant(
const PDEFoamDiscriminant &from)
84 Log() << kFATAL <<
"COPY CONSTRUCTOR NOT IMPLEMENTED" << Endl;
92 void TMVA::PDEFoamDiscriminant::FillFoamCells(
const Event* ev, Float_t wt)
95 std::vector<Float_t> values = ev->GetValues();
96 std::vector<Float_t> tvalues = VarTransform(values);
97 PDEFoamCell *cell = FindCell(tvalues);
101 if (ev->GetClass() == fClass)
102 SetCellElement(cell, 0, GetCellElement(cell, 0) + wt);
104 SetCellElement(cell, 1, GetCellElement(cell, 1) + wt);
111 void TMVA::PDEFoamDiscriminant::Finalize()
114 for (Long_t iCell = 0; iCell <= fLastCe; iCell++) {
115 if (!(fCells[iCell]->GetStat()))
118 Double_t n_sig = GetCellElement(fCells[iCell], 0);
119 Double_t n_bg = GetCellElement(fCells[iCell], 1);
122 Log() << kWARNING <<
"Negative number of signal events in cell " << iCell
123 <<
": " << n_sig <<
". Set to 0." << Endl;
127 Log() << kWARNING <<
"Negative number of background events in cell " << iCell
128 <<
": " << n_bg <<
". Set to 0." << Endl;
133 if (n_sig + n_bg > 0) {
135 SetCellElement(fCells[iCell], 0, n_sig / (n_sig + n_bg));
137 SetCellElement(fCells[iCell], 1, TMath::Sqrt(Sqr(n_sig / Sqr(n_sig + n_bg))*n_sig +
138 Sqr(n_bg / Sqr(n_sig + n_bg))*n_bg));
141 SetCellElement(fCells[iCell], 0, 0.5);
142 SetCellElement(fCells[iCell], 1, 1.);
171 TH2D* TMVA::PDEFoamDiscriminant::Project2(Int_t idim1, Int_t idim2, ECellValue cell_value, PDEFoamKernelBase *kernel, UInt_t nbin)
174 if ((idim1 >= GetTotDim()) || (idim1 < 0) ||
175 (idim2 >= GetTotDim()) || (idim2 < 0) ||
177 Log() << kFATAL <<
"<Project2>: wrong dimensions given: "
178 << idim1 <<
", " << idim2 << Endl;
184 Log() << kWARNING <<
"Warning: number of bins too big: " << nbin
185 <<
" Using 1000 bins for each dimension instead." << Endl;
187 }
else if (nbin < 1) {
188 Log() << kWARNING <<
"Wrong bin number: " << nbin
189 <<
"; set nbin=50" << Endl;
194 TString hname(Form(
"h_%d_vs_%d", idim1, idim2));
197 TH2D* h1 = (TH2D*)gDirectory->Get(hname.Data());
199 h1 =
new TH2D(hname.Data(), Form(
"var%d vs var%d", idim1, idim2), nbin, fXmin[idim1], fXmax[idim1], nbin, fXmin[idim2], fXmax[idim2]);
201 if (!h1) Log() << kFATAL <<
"ERROR: Can not create histo" << hname << Endl;
202 if (cell_value == kValue)
203 h1->GetZaxis()->SetRangeUser(-std::numeric_limits<float>::epsilon(),
204 1. + std::numeric_limits<float>::epsilon());
208 for (Int_t xbin = 1; xbin <= h1->GetNbinsX(); ++xbin) {
209 for (Int_t ybin = 1; ybin <= h1->GetNbinsY(); ++ybin) {
212 std::map<Int_t, Float_t> txvec;
213 txvec[idim1] = VarTransform(idim1, h1->GetXaxis()->GetBinCenter(xbin));
214 txvec[idim2] = VarTransform(idim2, h1->GetYaxis()->GetBinCenter(ybin));
218 std::vector<TMVA::PDEFoamCell*> cells = FindCells(txvec);
223 for (std::vector<TMVA::PDEFoamCell*>::const_iterator it = cells.begin();
224 it != cells.end(); ++it) {
226 PDEFoamVect cellPosi(GetTotDim()), cellSize(GetTotDim());
227 (*it)->GetHcub(cellPosi, cellSize);
230 std::vector<Float_t> tvec;
231 for (Int_t i = 0; i < GetTotDim(); ++i) {
232 if (i != idim1 && i != idim2)
233 tvec.push_back(cellPosi[i] + 0.5 * cellSize[i]);
235 tvec.push_back(txvec[i]);
239 if (kernel != NULL) {
240 cv = kernel->Estimate(
this, tvec, cell_value);
242 cv = GetCellValue(FindCell(tvec), cell_value);
244 if (cell_value == kValue) {
247 Float_t area_cell = 1.;
248 for (Int_t d1 = 0; d1 < GetTotDim(); ++d1) {
249 if ((d1 != idim1) && (d1 != idim2))
250 area_cell *= cellSize[d1];
260 h1->SetBinContent(xbin, ybin, sum_cv + h1->GetBinContent(xbin, ybin));