Coding conventions, removing compilation warnings, consistent usage of const
authorhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 30 Oct 2007 21:46:49 +0000 (21:46 +0000)
committerhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 30 Oct 2007 21:46:49 +0000 (21:46 +0000)
STAT/TKDInterpolator.cxx
STAT/TKDInterpolator.h
STAT/TKDInterpolatorBase.cxx
STAT/TKDInterpolatorBase.h
STAT/TKDNodeInfo.cxx
STAT/TKDNodeInfo.h
STAT/TKDPDF.cxx
STAT/TKDPDF.h
STAT/TKDSpline.cxx
STAT/TKDSpline.h

index b9d0c1f..2abe0d1 100644 (file)
@@ -66,7 +66,7 @@ Int_t TKDInterpolator::GetNodeIndex(const Float_t *p)
 
 
 //_________________________________________________________________
-Bool_t TKDInterpolator::SetNode(const Int_t inode, const TKDNodeInfo &ref)
+Bool_t TKDInterpolator::SetNode(Int_t inode, const TKDNodeInfo &ref)
 {
        if(!fTNodes){
                printf("W - TKDInterpolator::SetNode() : Node array not defined.\n");
@@ -78,5 +78,6 @@ Bool_t TKDInterpolator::SetNode(const Int_t inode, const TKDNodeInfo &ref)
        }
        TKDNodeInfo *node = (TKDNodeInfo*)(*fTNodes)[inode];
        (*node) = ref;
+       return kTRUE;
 }
 
index 94b4783..8970a9d 100644 (file)
@@ -12,9 +12,10 @@ public:
        TKDInterpolator(Int_t ndim, Int_t npoints=0);
        ~TKDInterpolator();
        void       AddNode(const TKDNodeInfo &ref);
+       void       Build(Int_t ndim) {TKDInterpolatorBase::Build(ndim);}
        void       Build(Int_t npoints, Int_t ndim);
        Int_t      GetNodeIndex(const Float_t *p);
-       Bool_t     SetNode(const Int_t i, const TKDNodeInfo &ref);
+       Bool_t     SetNode(Int_t i, const TKDNodeInfo &ref);
 
 private:
        TKDInterpolator(const TKDInterpolator &);
index 7b1d61b..1999b95 100644 (file)
@@ -30,7 +30,7 @@ ClassImp(TKDInterpolatorBase)
 
 
 //_________________________________________________________________
-TKDInterpolatorBase::TKDInterpolatorBase(const Int_t dim) :
+TKDInterpolatorBase::TKDInterpolatorBase(Int_t dim) :
        fNSize(dim)
        ,fNTNodes(0)
        ,fTNodes(0x0)
@@ -48,7 +48,7 @@ TKDInterpolatorBase::TKDInterpolatorBase(const Int_t dim) :
 }
 
 //_________________________________________________________________
-void   TKDInterpolatorBase::Build(const Int_t n)
+void   TKDInterpolatorBase::Build(Int_t n)
 {
        // allocate memory for data
 
@@ -79,14 +79,14 @@ Bool_t      TKDInterpolatorBase::GetCOGPoint(Int_t inode, Float_t *&coord, Float_t &v
        if(inode < 0 || inode > fNTNodes) return kFALSE;
 
        TKDNodeInfo *node = (TKDNodeInfo*)(*fTNodes)[inode];
-       coord = &(node->fData[0]);
-       val = node->fVal[0];
-       err = node->fVal[1];
+       coord = &(node->Data()[0]);
+       val = node->Val()[0];
+       err = node->Val()[1];
        return kTRUE;
 }
 
 //_________________________________________________________________
-TKDNodeInfo* TKDInterpolatorBase::GetNodeInfo(const Int_t inode) const
+TKDNodeInfo* TKDInterpolatorBase::GetNodeInfo(Int_t inode) const
 {
        if(!fTNodes || inode >= fNTNodes) return 0x0;
        return (TKDNodeInfo*)(*fTNodes)[inode];
@@ -130,7 +130,7 @@ Double_t TKDInterpolatorBase::Eval(const Double_t *point, Double_t &result, Doub
                return 0.;
        }
        TKDNodeInfo *node = (TKDNodeInfo*)(*fTNodes)[nodeIndex];
-       if((fStatus&1) && node->fCov && !force) return node->CookPDF(point, result, error);
+       if((fStatus&1) && node->Cov() && !force) return node->CookPDF(point, result, error);
 
        // Allocate memory
        if(!fBuffer) fBuffer = new Double_t[2*fLambda];
@@ -138,7 +138,7 @@ Double_t TKDInterpolatorBase::Eval(const Double_t *point, Double_t &result, Doub
                fRefPoints = new Float_t*[fNSize];
                for(int id=0; id<fNSize; id++){
                        fRefPoints[id] = new Float_t[fNTNodes];
-                       for(int in=0; in<fNTNodes; in++) fRefPoints[id][in] = ((TKDNodeInfo*)(*fTNodes)[in])->fData[id];
+                       for(int in=0; in<fNTNodes; in++) fRefPoints[id][in] = ((TKDNodeInfo*)(*fTNodes)[in])->Data()[id];
                }
                fKDhelper = new TKDTreeIF(fNTNodes, fNSize, 30, fRefPoints);
                fKDhelper->MakeBoundaries();
@@ -175,7 +175,7 @@ Double_t TKDInterpolatorBase::Eval(const Double_t *point, Double_t &result, Doub
                        tnode = (TKDNodeInfo*)(*fTNodes)[index[in]];
                        //tnode->Print();
                        if(fStatus&1){ // INT
-                               Float_t *bounds = &(tnode->fData[fNSize]);
+                               Float_t *bounds = &(tnode->Data()[fNSize]);
                                ipar = 0;
                                for(int idim=0; idim<fNSize; idim++){
                                        fBuffer[ipar++] = .5*(bounds[2*idim] + bounds[2*idim+1]);
@@ -183,7 +183,7 @@ Double_t TKDInterpolatorBase::Eval(const Double_t *point, Double_t &result, Doub
                                        for(int jdim=idim+1; jdim<fNSize; jdim++) fBuffer[ipar++] = (bounds[2*idim] + bounds[2*idim+1]) * (bounds[2*jdim] + bounds[2*jdim+1]) * .25;
                                }
                        } else { // COG
-                               Float_t *p = &(tnode->fData[0]);
+                               Float_t *p = &(tnode->Data()[0]);
                                ipar = 0;
                                for(int idim=0; idim<fNSize; idim++){
                                        fBuffer[ipar++] = p[idim];
@@ -199,8 +199,8 @@ Double_t TKDInterpolatorBase::Eval(const Double_t *point, Double_t &result, Doub
                         
 //                     printf("x[");
 //                     for(int idim=0; idim<fLambda-1; idim++) printf("%f ", fBuffer[idim]);
-//                     printf("]  v[%f +- %f] (%f, %f)\n", tnode->fVal[0], tnode->fVal[1]/w, tnode->fVal[1], w);
-                       fFitter->AddPoint(fBuffer, tnode->fVal[0], tnode->fVal[1]/w);
+//                     printf("]  v[%f +- %f] (%f, %f)\n", tnode->Val()[0], tnode->Val()[1]/w, tnode->Val()[1], w);
+                       fFitter->AddPoint(fBuffer, tnode->Val()[0], tnode->Val()[1]/w);
                }
                npoints += 4;
        } while(fFitter->Eval());
@@ -261,7 +261,7 @@ void TKDInterpolatorBase::DrawBins(UInt_t ax1, UInt_t ax2, Float_t ax1min, Float
                box->SetFillStyle(3002);
                box->SetFillColor(50+inode/*Int_t(gRandom->Uniform()*50.)*/);
                
-               bounds = &(((TKDNodeInfo*)(*fTNodes)[inode])->fData[fNSize]);
+               bounds = &(((TKDNodeInfo*)(*fTNodes)[inode])->Data()[fNSize]);
                box->DrawBox(bounds[2*ax1]+kBorder, bounds[2*ax2]+kBorder, bounds[2*ax1+1]-kBorder, bounds[2*ax2+1]-kBorder);
        }
 
@@ -272,14 +272,14 @@ void TKDInterpolatorBase::DrawBins(UInt_t ax1, UInt_t ax2, Float_t ax1min, Float
        ref->SetMarkerColor(2);
        for(int inode = 0; inode < fNTNodes; inode++){
                TKDNodeInfo *node = (TKDNodeInfo*)(*fTNodes)[inode];
-               ref->SetPoint(inode, node->fData[ax1], node->fData[ax2]);
+               ref->SetPoint(inode, node->Data()[ax1], node->Data()[ax2]);
        }
        ref->Draw("p");
        return;
 }
 
 //__________________________________________________________________
-void TKDInterpolatorBase::SetInterpolationMethod(const Bool_t on)
+void TKDInterpolatorBase::SetInterpolationMethod(Bool_t on)
 {
 // Set interpolation bit to "on".
        
@@ -289,7 +289,7 @@ void TKDInterpolatorBase::SetInterpolationMethod(const Bool_t on)
 
 
 //_________________________________________________________________
-void TKDInterpolatorBase::SetStore(const Bool_t on)
+void TKDInterpolatorBase::SetStore(Bool_t on)
 {
 // Set store bit to "on"
        
@@ -298,7 +298,7 @@ void TKDInterpolatorBase::SetStore(const Bool_t on)
 }
 
 //_________________________________________________________________
-void TKDInterpolatorBase::SetWeights(const Bool_t on)
+void TKDInterpolatorBase::SetWeights(Bool_t on)
 {
 // Set weights bit to "on"
        
index 5b59170..ae7097b 100644 (file)
@@ -26,7 +26,7 @@ class TKDNodeInfo;
 class TKDInterpolatorBase
 {
 public:        
-       TKDInterpolatorBase(const Int_t size = 0);
+       TKDInterpolatorBase(Int_t size = 0);
        virtual ~TKDInterpolatorBase();
 
        Double_t   Eval(const Double_t *point, Double_t &result, Double_t &error, Bool_t force = kFALSE);
@@ -34,20 +34,20 @@ public:
        Float_t    GetAlpha() const {return fAlpha;}
        Bool_t     GetCOGPoint(Int_t node, Float_t *&coord, Float_t &val, Float_t &error) const;
        Bool_t     GetInterpolationMethod() const {return fStatus&1;}
-       TKDNodeInfo* GetNodeInfo(const Int_t inode) const;
+       TKDNodeInfo* GetNodeInfo(Int_t inode) const;
        Int_t      GetNTNodes() const {return fNTNodes;}
        void       GetStatus();
        Bool_t     GetStore() const {return fStatus&2;}
        Bool_t     GetWeights() const {return fStatus&4;}
 
        void       DrawBins(UInt_t ax1 = 0, UInt_t ax2 = 1, Float_t ax1min=-1., Float_t ax1max=1., Float_t ax2min=-1., Float_t ax2max=1.);
-       void       SetAlpha(const Float_t a){if(a>0.) fAlpha = a;}
-       void       SetInterpolationMethod(const Bool_t on = kTRUE);
-       void       SetStore(const Bool_t on = kTRUE);
-       void       SetWeights(const Bool_t on = kTRUE);
+       void       SetAlpha(Float_t a){if(a>0.) fAlpha = a;}
+       void       SetInterpolationMethod(Bool_t on = kTRUE);
+       void       SetStore(Bool_t on = kTRUE);
+       void       SetWeights(Bool_t on = kTRUE);
 
 protected:
-       virtual void      Build(const Int_t nnodes);
+       virtual void      Build(Int_t nnodes);
 
 private:
        TKDInterpolatorBase(const TKDInterpolatorBase &);
index a406952..9ba6020 100644 (file)
@@ -8,13 +8,14 @@ ClassImp(TKDNodeInfo)
 
 
 //_________________________________________________________________
-TKDNodeInfo::TKDNodeInfo(const Int_t dim):
+TKDNodeInfo::TKDNodeInfo(Int_t dim):
        TObject()
        ,fNDim(3*dim)
        ,fData(0x0)
        ,fCov(0x0)
        ,fPar(0x0)
 {
+  // Default constructor
        fVal[0] = 0.; fVal[1] = 0.;
        Build(dim);
 }
@@ -27,6 +28,7 @@ TKDNodeInfo::TKDNodeInfo(const TKDNodeInfo &ref):
        ,fCov(0x0)
        ,fPar(0x0)
 {
+  // Copy constructor
        Build(fNDim/3);
 
        memcpy(fData, ref.fData, fNDim*sizeof(Float_t));
@@ -40,6 +42,7 @@ TKDNodeInfo::TKDNodeInfo(const TKDNodeInfo &ref):
 //_________________________________________________________________
 TKDNodeInfo::~TKDNodeInfo()
 {
+  // Destructor
        if(fData) delete [] fData;
        if(fCov){
                delete fPar;
@@ -67,7 +70,7 @@ TKDNodeInfo& TKDNodeInfo::operator=(const TKDNodeInfo & ref)
 }
 
 //_________________________________________________________________
-void TKDNodeInfo::Build(const Int_t dim)
+void TKDNodeInfo::Build(Int_t dim)
 {
 // Allocate/Reallocate space for this node.
 
@@ -86,14 +89,15 @@ void TKDNodeInfo::Build(const Int_t dim)
 }
 
 //_________________________________________________________________
-void TKDNodeInfo::Print()
+void TKDNodeInfo::Print(const Option_t *) const
 {
+  // Print the content of the node
        Int_t dim = fNDim/3;
        printf("x[");
        for(int idim=0; idim<dim; idim++) printf("%f ", fData[idim]);
        printf("] f = [%f +- %f]\n", fVal[0], fVal[1]);
 
-       Float_t *bounds = &fData[dim];
+       //      Float_t *bounds = &fData[dim];
        printf("range[");
        for(int idim=0; idim<dim; idim++) printf("(%f %f) ", fData[2*idim], fData[2*idim+1]);
        printf("]\n");
@@ -104,7 +108,7 @@ void TKDNodeInfo::Print()
                return;
        }
        
-       Int_t lambda = Int_t(1 + dim + .5*dim*(dim+1));
+       //      Int_t lambda = Int_t(1 + dim + .5*dim*(dim+1));
        for(int ip=0; ip<3; ip++) printf("p%d[%f] ", ip, (*fPar)(ip));
        printf("\n");
 }
@@ -112,6 +116,7 @@ void TKDNodeInfo::Print()
 //_________________________________________________________________
 void TKDNodeInfo::Store(const TVectorD &par, const TMatrixD &cov)
 {
+  // Store the parameters and the covariance in the node
        if(!fCov){
                fCov = new TMatrixD(cov.GetNrows(), cov.GetNrows());
                fPar = new TVectorD(par.GetNrows());
index 9a522c9..66458a8 100644 (file)
@@ -9,24 +9,30 @@ template <typename Value> class TVectorT;
 typedef struct TVectorT<Double_t> TVectorD;
 template <typename Value> class TMatrixT;
 typedef class TMatrixT<Double_t> TMatrixD;
-class TKDInterpolatorBase;
+//class TKDInterpolatorBase;
 class TKDNodeInfo : public TObject
 {
-friend class TKDInterpolatorBase;
+  //friend class TKDInterpolatorBase;
 public:
-       TKDNodeInfo(const Int_t ndim = 0);
-       TKDNodeInfo(const TKDNodeInfo &);
-       TKDNodeInfo& operator=(const TKDNodeInfo &);
+       TKDNodeInfo(Int_t ndim = 0);
+       TKDNodeInfo(const TKDNodeInfo & ref);
+       TKDNodeInfo& operator=(const TKDNodeInfo & ref);
        virtual  ~TKDNodeInfo();
        Double_t  CookPDF(const Double_t *point, Double_t &result, Double_t &error);
-       inline Bool_t    Has(const Float_t *p);
-       void      Print();
+       inline Bool_t    Has(const Float_t *p) const;
+       void      Print(const Option_t * = "") const;
        void      Store(const TVectorD &par, const TMatrixD &cov);
 
+       Int_t GetSize() const { return fNDim; }
+       Float_t *  Data() { return fData; } 
+       Float_t *  Val() { return fVal; } 
+       TMatrixD * Cov() { return fCov; }
+       TVectorD * Par() { return fPar; }
+
 protected:
-       void      Build(const Int_t ndim);
+       void      Build(Int_t ndim);
 
-public:
+private:
        Int_t     fNDim;          // 3 times data dimension
        Float_t   *fData;         //[fNDim] node's data
        Float_t   fVal[2];        // measured value for node
@@ -37,7 +43,7 @@ public:
 };
 
 //_____________________________________________________________________
-Bool_t TKDNodeInfo::Has(const Float_t *p)
+Bool_t TKDNodeInfo::Has(const Float_t *p) const
 {
        Int_t n = 0;
        Int_t ndim = fNDim/3;
index 44f6b47..9bc9e88 100644 (file)
@@ -81,7 +81,7 @@ TKDPDF::~TKDPDF()
 }
 
 //_________________________________________________________________
-void TKDPDF::Build()
+void TKDPDF::Build(Int_t)
 {
 // Fill interpolator's data array i.e.
 //  - estimation points 
@@ -100,19 +100,19 @@ void TKDPDF::Build()
        Int_t *indexPoints;
        for(int inode=0, tnode = fNnodes; inode<fNTNodes-1; inode++, tnode++){
                node = (TKDNodeInfo*)(*fTNodes)[inode];
-               node->fVal[0] =  Float_t(fBucketSize)/fNpoints;
+               node->Val()[0] =  Float_t(fBucketSize)/fNpoints;
                bounds = GetBoundary(tnode);
-               for(int idim=0; idim<fNDim; idim++) node->fVal[0] /= (bounds[2*idim+1] - bounds[2*idim]);
-               node->fVal[1] =  node->fVal[0]/TMath::Sqrt(float(fBucketSize));
+               for(int idim=0; idim<fNDim; idim++) node->Val()[0] /= (bounds[2*idim+1] - bounds[2*idim]);
+               node->Val()[1] =  node->Val()[0]/TMath::Sqrt(float(fBucketSize));
                
                indexPoints = GetPointsIndexes(tnode);
                // loop points in this terminal node
                for(int idim=0; idim<fNDim; idim++){
-                       node->fData[idim] = 0.;
-                       for(int ip = 0; ip<fBucketSize; ip++) node->fData[idim] += fData[idim][indexPoints[ip]];
-                       node->fData[idim] /= fBucketSize;
+                       node->Data()[idim] = 0.;
+                       for(int ip = 0; ip<fBucketSize; ip++) node->Data()[idim] += fData[idim][indexPoints[ip]];
+                       node->Data()[idim] /= fBucketSize;
                }
-               memcpy(&(node->fData[fNDim]), bounds, fNDimm*sizeof(Float_t));
+               memcpy(&(node->Data()[fNDim]), bounds, fNDimm*sizeof(Float_t));
        }
 
        // analyze last (incomplete) terminal node
@@ -120,19 +120,19 @@ void TKDPDF::Build()
        counts = counts ? counts : fBucketSize;
        Int_t inode = fNTNodes - 1, tnode = inode + fNnodes;
        node = (TKDNodeInfo*)(*fTNodes)[inode];
-       node->fVal[0] =  Float_t(counts)/fNpoints;
+       node->Val()[0] =  Float_t(counts)/fNpoints;
        bounds = GetBoundary(tnode);
-       for(int idim=0; idim<fNDim; idim++) node->fVal[0] /= (bounds[2*idim+1] - bounds[2*idim]);
-       node->fVal[1] =  node->fVal[0]/TMath::Sqrt(float(counts));
+       for(int idim=0; idim<fNDim; idim++) node->Val()[0] /= (bounds[2*idim+1] - bounds[2*idim]);
+       node->Val()[1] =  node->Val()[0]/TMath::Sqrt(float(counts));
 
        // loop points in this terminal node
        indexPoints = GetPointsIndexes(tnode);
        for(int idim=0; idim<fNDim; idim++){
-               node->fData[idim] = 0.;
-               for(int ip = 0; ip<counts; ip++) node->fData[idim] += fData[idim][indexPoints[ip]];
-               node->fData[idim] /= counts;
+               node->Data()[idim] = 0.;
+               for(int ip = 0; ip<counts; ip++) node->Data()[idim] += fData[idim][indexPoints[ip]];
+               node->Data()[idim] /= counts;
        }
-       memcpy(&(node->fData[fNDim]), bounds, fNDimm*sizeof(Float_t));
+       memcpy(&(node->Data()[fNDim]), bounds, fNDimm*sizeof(Float_t));
 
        delete [] fBoundaries;
        fBoundaries = 0x0;
@@ -166,7 +166,7 @@ void TKDPDF::DrawNode(Int_t tnode, UInt_t ax1, UInt_t ax2)
 
        // draw estimation point
        TKDNodeInfo *node = (TKDNodeInfo*)(*fTNodes)[inode];
-       TMarker *m=new TMarker(node->fData[ax1], node->fData[ax2], 20);
+       TMarker *m=new TMarker(node->Data()[ax1], node->Data()[ax2], 20);
        m->SetMarkerColor(2);
        m->SetMarkerSize(1.7);
        
index 15f71a9..846e3e0 100644 (file)
@@ -32,7 +32,7 @@ public:
 private:
        TKDPDF(const TKDPDF &);
        TKDPDF& operator=(const TKDPDF &);
-               void       Build();
+               void       Build(Int_t ndim = 0);
 
                                        
        ClassDef(TKDPDF, 1)   // data interpolator based on KD tree
index 25315c7..7a355a4 100644 (file)
@@ -19,7 +19,7 @@ TKDSpline::TKDSpline(Int_t npoints, Int_t ndim) :
 
 
 //_________________________________________________________________
-void TKDSpline::Build()
+void TKDSpline::Build(Int_t)
 {
 }
 
index a33741c..37fef2b 100644 (file)
@@ -12,7 +12,7 @@ public:
        TKDSpline(Int_t npoints, Int_t ndim);
 
 private:
-       void            Build();
+       void            Build(Int_t ndim = 0);
        
 protected: