TKDEAdapter.cxx

Go to the documentation of this file.
00001 // @(#)root/gl:$Id: TKDEAdapter.cxx 33600 2010-05-21 09:24:32Z rdm $
00002 // Author:  Timur Pocheptsov  28/07/2009
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2009, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include <stdexcept>
00013 
00014 #include "TKDEAdapter.h"
00015 #include "TKDEFGT.h"
00016 #include "TError.h"
00017 #include "TGL5D.h"
00018 #include "TAxis.h"
00019 
00020 namespace Rgl {
00021 namespace Fgt {
00022 
00023 //______________________________________________________________________________
00024 TKDEAdapter::TKDEAdapter()
00025                : fW(0), fH(0), fD(0),
00026                  fSliceSize(0),
00027                  fXMin(0.), fXStep(0.),
00028                  fYMin(0.), fYStep(0.),
00029                  fZMin(0.), fZStep(0.),
00030                  fDE(0),
00031                  fE(10.)
00032 {
00033    //Constructor. "Half-baked" object.
00034 }
00035 
00036 //______________________________________________________________________________
00037 void TKDEAdapter::SetGeometry(const TGL5DDataSet *dataSet)
00038 {
00039    //Set grid's dimensions.
00040    const TAxis *xA = dataSet->GetXAxis();
00041    const Rgl::Range_t &xMinMax = dataSet->GetXRange();
00042    const Double_t xRange = xMinMax.second - xMinMax.first;
00043 
00044    const TAxis *yA = dataSet->GetYAxis();
00045    const Rgl::Range_t &yMinMax = dataSet->GetYRange();
00046    const Double_t yRange = yMinMax.second - yMinMax.first;
00047 
00048    const TAxis *zA = dataSet->GetZAxis();
00049    const Rgl::Range_t &zMinMax = dataSet->GetZRange();
00050    const Double_t zRange = zMinMax.second - zMinMax.first;
00051    
00052    fW = xA->GetNbins();
00053    fH = yA->GetNbins();
00054    fD = zA->GetNbins();
00055 
00056    fSliceSize = fW * fH;
00057 
00058    fXMin = (xA->GetBinLowEdge(1) - xMinMax.first) / xRange;
00059    fXStep = (xA->GetBinUpEdge(xA->GetLast()) - xA->GetBinLowEdge(xA->GetFirst())) / (fW - 1) / xRange;
00060 
00061    fYMin = (yA->GetBinLowEdge(1) - yMinMax.first) / yRange;
00062    fYStep = (yA->GetBinUpEdge(yA->GetLast()) - yA->GetBinLowEdge(yA->GetFirst())) / (fH - 1) / yRange;
00063 
00064    fZMin = (zA->GetBinLowEdge(1) - zMinMax.first) / zRange;
00065    fZStep = (zA->GetBinCenter(zA->GetLast()) - zA->GetBinLowEdge(zA->GetFirst())) / (fD - 1) / zRange;
00066 }
00067 
00068 //______________________________________________________________________________
00069 void TKDEAdapter::SetE(Double_t e)
00070 {
00071    //e for kdefgt.
00072    fE = e;
00073 }
00074 
00075 //______________________________________________________________________________
00076 Double_t TKDEAdapter::GetE()const
00077 {
00078    //e for kdefgt.
00079    return fE;
00080 }
00081 
00082 //______________________________________________________________________________
00083 UInt_t TKDEAdapter::GetW()const
00084 {
00085    //Number of cells along X.
00086    return fW;
00087 }
00088 
00089 //______________________________________________________________________________
00090 UInt_t TKDEAdapter::GetH()const
00091 {
00092    //Number of cells along Y.
00093    return fH;
00094 }
00095 
00096 //______________________________________________________________________________
00097 UInt_t TKDEAdapter::GetD()const
00098 {
00099    //Number of cells along Z.
00100    return fD;
00101 }
00102 
00103 //______________________________________________________________________________
00104 void TKDEAdapter::SetDataSource(const TKDEFGT *de)
00105 {
00106    //Set density estimator as a data source.
00107    fDE = de;
00108 }
00109 
00110 //______________________________________________________________________________
00111 void TKDEAdapter::FetchDensities()const
00112 {
00113    //Do some initialization and calculate densities.
00114    if (!fDE) {
00115       Error("TKDEAdapter::FetchFirstSlices", "Density estimator is a null pointer."
00116             " Set it correctly first.");
00117       throw std::runtime_error("No density estimator.");
00118    }
00119 
00120    fGrid.resize(fD * fSliceSize * 3);//3 is the number of coordinates: xyz
00121 
00122    //1D index into fGrid array.
00123    UInt_t ind = 0;
00124    //The first slice.
00125    for(UInt_t k = 0; k < fD; ++k) {
00126       for (UInt_t i = 0; i < fH; ++i) {
00127          for (UInt_t j = 0; j < fW; ++j, ind += 3) {
00128             fGrid[ind]     = fXMin + j * fXStep;
00129             fGrid[ind + 1] = fYMin + i * fYStep;
00130             fGrid[ind + 2] = fZMin + k * fZStep;
00131          }
00132       }
00133    }
00134    
00135    fDensities.resize(fSliceSize * fD);
00136    //Ok, now, we can estimate densities.
00137    fDE->Predict(fGrid, fDensities, fE);
00138 }
00139 
00140 //______________________________________________________________________________
00141 Float_t TKDEAdapter::GetData(UInt_t i, UInt_t j, UInt_t k)const
00142 {
00143    // Get data at given position.
00144    const UInt_t ind = k * fSliceSize + j * fW + i;
00145    return fDensities[ind];
00146 }
00147 
00148 //______________________________________________________________________________
00149 void TKDEAdapter::FreeVectors()
00150 {
00151    // Free grid and density vectors.
00152    vector_t().swap(fGrid);
00153    vector_t().swap(fDensities);
00154 }
00155 
00156 }
00157 }

Generated on Tue Jul 5 14:18:10 2011 for ROOT_528-00b_version by  doxygen 1.5.1