From: abercuci Date: Fri, 2 Oct 2009 12:11:02 +0000 (+0000) Subject: add draw functionality for TKDNodeInfo X-Git-Url: http://git.uio.no/git/?p=u%2Fmrichter%2FAliRoot.git;a=commitdiff_plain;h=b6f6b31a449a30a2b71452141e9ca103ba89af58 add draw functionality for TKDNodeInfo --- diff --git a/STAT/STATLinkDef.h b/STAT/STATLinkDef.h index 5b09bacb7a6..fe7b9862fdf 100644 --- a/STAT/STATLinkDef.h +++ b/STAT/STATLinkDef.h @@ -9,6 +9,7 @@ #pragma link C++ class TKDInterpolatorBase+; #pragma link C++ class TKDNodeInfo+; +#pragma link C++ class TKDNodeInfo::TKDNodeDraw+; #pragma link C++ class TKDPDF+; #pragma link C++ class TKDInterpolator+; #pragma link C++ class TKDSpline+; diff --git a/STAT/TKDInterpolatorBase.cxx b/STAT/TKDInterpolatorBase.cxx index 2afcf08b24d..df0c1933572 100644 --- a/STAT/TKDInterpolatorBase.cxx +++ b/STAT/TKDInterpolatorBase.cxx @@ -2,16 +2,13 @@ #include "TKDNodeInfo.h" #include "TKDTree.h" -#include "TRandom.h" +#include "TROOT.h" #include "TClonesArray.h" #include "TLinearFitter.h" #include "TTree.h" #include "TH2.h" #include "TObjArray.h" #include "TObjString.h" -#include "TBox.h" -#include "TGraph.h" -#include "TMarker.h" #include "TMath.h" #include "TVectorD.h" #include "TMatrixD.h" @@ -35,6 +32,7 @@ TKDInterpolatorBase::TKDInterpolatorBase(Int_t dim) : fNSize(dim) ,fNTNodes(0) ,fTNodes(0x0) + ,fTNodesDraw(0x0) ,fStatus(4) ,fLambda(1 + dim + (dim*(dim+1)>>1)) ,fDepth(-1) @@ -74,7 +72,14 @@ TKDInterpolatorBase::~TKDInterpolatorBase() for(int idim=0; idimDelete(); + delete fTNodes; + } + delete [] fTNodesDraw; + + TH2 *h2=0x0; + if((h2 = (TH2S*)gROOT->FindObject("hKDnodes"))) delete h2; } @@ -267,33 +272,24 @@ void TKDInterpolatorBase::DrawBins(UInt_t ax1, UInt_t ax2, Float_t ax1min, Float - TH2 *h2 = new TH2S("hNodes", "", 100, ax1min, ax1max, 100, ax2min, ax2max); - h2->GetXaxis()->SetTitle(Form("x_{%d}", ax1)); - h2->GetYaxis()->SetTitle(Form("x_{%d}", ax2)); + TH2 *h2 = 0x0; + if(!(h2 = (TH2S*)gROOT->FindObject("hKDnodes"))){ + h2 = new TH2S("hKDnodes", "", 100, ax1min, ax1max, 100, ax2min, ax2max); + h2->GetXaxis()->SetTitle(Form("x_{%d}", ax1)); + h2->GetYaxis()->SetTitle(Form("x_{%d}", ax2)); + } h2->Draw(); - const Float_t kBorder = 0.;//1.E-4; - TBox *boxArray = new TBox[fNTNodes], *box; - Float_t *bounds = 0x0; - for(int inode = 0; inode < fNTNodes; inode++){ - box = &boxArray[inode]; - box->SetFillStyle(3002); - box->SetFillColor(50+Int_t(gRandom->Uniform()*50.)); - - 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); - } - // Draw reference points - TGraph *ref = new TGraph(fNTNodes); - ref->SetMarkerStyle(3); - ref->SetMarkerSize(.7); - ref->SetMarkerColor(2); - for(int inode = 0; inode < fNTNodes; inode++){ - TKDNodeInfo *node = (TKDNodeInfo*)(*fTNodes)[inode]; - ref->SetPoint(inode, node->Data()[ax1], node->Data()[ax2]); + if(!fTNodesDraw) fTNodesDraw = new TKDNodeInfo::TKDNodeDraw[fNTNodes]; + TKDNodeInfo::TKDNodeDraw *box = 0x0; + for(Int_t in=0; inSetNode(node, fNSize, ax1, ax2); + box->Draw(); } - ref->Draw("p"); return; } diff --git a/STAT/TKDInterpolatorBase.h b/STAT/TKDInterpolatorBase.h index 4bd228e79b3..4b831bba10c 100644 --- a/STAT/TKDInterpolatorBase.h +++ b/STAT/TKDInterpolatorBase.h @@ -5,6 +5,10 @@ #include "Rtypes.h" #endif +#ifndef ROOT_TKDNodeInfo +#include "TKDNodeInfo.h" +#endif + /////////////////////////////////////////////////////////////// // // Base non parametric interpolation algorithm. @@ -22,7 +26,6 @@ template class TKDTree; typedef class TKDTree TKDTreeIF; class TLinearFitter; class TClonesArray; -class TKDNodeInfo; class TKDInterpolatorBase { public: @@ -62,6 +65,7 @@ protected: Int_t fNSize; // data dimension Int_t fNTNodes; //Number of evaluation data points TClonesArray *fTNodes; //interpolation nodes + TKDNodeInfo::TKDNodeDraw *fTNodesDraw; //graphical representation of interpolation nodes //private: UChar_t fStatus; // status of the interpolator diff --git a/STAT/TKDNodeInfo.cxx b/STAT/TKDNodeInfo.cxx index 9ba602039e1..9040a719de4 100644 --- a/STAT/TKDNodeInfo.cxx +++ b/STAT/TKDNodeInfo.cxx @@ -1,41 +1,43 @@ #include "TKDNodeInfo.h" +#include "TRandom.h" #include "TVectorD.h" #include "TMatrixD.h" #include "TMath.h" ClassImp(TKDNodeInfo) +ClassImp(TKDNodeInfo::TKDNodeDraw) //_________________________________________________________________ TKDNodeInfo::TKDNodeInfo(Int_t dim): - TObject() - ,fNDim(3*dim) - ,fData(0x0) - ,fCov(0x0) - ,fPar(0x0) + TObject() + ,fNDim(3*dim) + ,fData(0x0) + ,fCov(0x0) + ,fPar(0x0) { // Default constructor - fVal[0] = 0.; fVal[1] = 0.; - Build(dim); + fVal[0] = 0.; fVal[1] = 0.; + Build(dim); } //_________________________________________________________________ TKDNodeInfo::TKDNodeInfo(const TKDNodeInfo &ref): - TObject((TObject&) ref) - ,fNDim(fNDim) - ,fData(0x0) - ,fCov(0x0) - ,fPar(0x0) + TObject((TObject&) ref) + ,fNDim(fNDim) + ,fData(0x0) + ,fCov(0x0) + ,fPar(0x0) { // Copy constructor - Build(fNDim/3); + Build(fNDim/3); - memcpy(fData, ref.fData, fNDim*sizeof(Float_t)); - fVal[0] = ref.fVal[0]; - fVal[1] = ref.fVal[1]; - if(ref.fCov) (*fCov) = (*ref.fCov); - if(ref.fPar) (*fPar) = (*ref.fPar); + memcpy(fData, ref.fData, fNDim*sizeof(Float_t)); + fVal[0] = ref.fVal[0]; + fVal[1] = ref.fVal[1]; + if(ref.fCov) (*fCov) = (*ref.fCov); + if(ref.fPar) (*fPar) = (*ref.fPar); } @@ -43,30 +45,30 @@ TKDNodeInfo::TKDNodeInfo(const TKDNodeInfo &ref): TKDNodeInfo::~TKDNodeInfo() { // Destructor - if(fData) delete [] fData; - if(fCov){ - delete fPar; - delete fCov; - } + if(fData) delete [] fData; + if(fCov){ + delete fPar; + delete fCov; + } } //_________________________________________________________________ TKDNodeInfo& TKDNodeInfo::operator=(const TKDNodeInfo & ref) { // Info("operator==()", "..."); - - Int_t ndim = fNDim/3; - if(fNDim != ref.fNDim){ - fNDim = ref.fNDim; - Build(ndim); - } - memcpy(fData, ref.fData, fNDim*sizeof(Float_t)); - fVal[0] = ref.fVal[0]; - fVal[1] = ref.fVal[1]; - if(ref.fCov) (*fCov) = (*ref.fCov); - if(ref.fPar) (*fPar) = (*ref.fPar); - - return *this; + + Int_t ndim = fNDim/3; + if(fNDim != ref.fNDim){ + fNDim = ref.fNDim; + Build(ndim); + } + memcpy(fData, ref.fData, fNDim*sizeof(Float_t)); + fVal[0] = ref.fVal[0]; + fVal[1] = ref.fVal[1]; + if(ref.fCov) (*fCov) = (*ref.fCov); + if(ref.fPar) (*fPar) = (*ref.fPar); + + return *this; } //_________________________________________________________________ @@ -76,53 +78,53 @@ void TKDNodeInfo::Build(Int_t dim) // Info("Build()", "..."); - if(!dim) return; - - Int_t lambda = Int_t(1 + dim + .5*dim*(dim+1)); - if(fData) delete [] fData; - fData = new Float_t[fNDim]; - if(fCov){ - fCov->ResizeTo(lambda, lambda); - fPar->ResizeTo(lambda); - } - return; + if(!dim) return; + + Int_t lambda = Int_t(1 + dim + .5*dim*(dim+1)); + if(fData) delete [] fData; + fData = new Float_t[fNDim]; + if(fCov){ + fCov->ResizeTo(lambda, lambda); + fPar->ResizeTo(lambda); + } + return; } //_________________________________________________________________ void TKDNodeInfo::Print(const Option_t *) const { // Print the content of the node - Int_t dim = fNDim/3; - printf("x["); - for(int idim=0; idim10) return 0.; // support only up to 10 dimensions - - Int_t lambda = 1 + ndim + (ndim*(ndim+1)>>1); - Double_t fdfdp[66]; - Int_t ipar = 0; - fdfdp[ipar++] = 1.; - for(int idim=0; idim10) return 0.; // support only up to 10 dimensions + + Int_t lambda = 1 + ndim + (ndim*(ndim+1)>>1); + Double_t fdfdp[66]; + Int_t ipar = 0; + fdfdp[ipar++] = 1.; + for(int idim=0; idimUniform()*50.)); + + fCOG.SetMarkerStyle(3); + fCOG.SetMarkerSize(.7); + fCOG.SetMarkerColor(2); +} + + +//_________________________________________________________________ +void TKDNodeInfo::TKDNodeDraw::Draw(Option_t* option) +{ + TBox::Draw(option); + fCOG.Draw("p"); +} + +//_________________________________________________________________ +void TKDNodeInfo::TKDNodeDraw::SetNode(TKDNodeInfo *node, UChar_t size, UChar_t ax1, UChar_t ax2) +{ + const Float_t kBorder = 0.;//1.E-4; + Float_t *bounds = &(node->Data()[size]); + //printf("x1[%f] x2[%f] y1[%f] y2[%f]\n", bounds[2*ax1], bounds[2*ax1+1], bounds[2*ax2], bounds[2*ax2+1]); + fX1=bounds[2*ax1]+kBorder; + fX2=bounds[2*ax1+1]-kBorder; + fY1=bounds[2*ax2]+kBorder; + fY2=bounds[2*ax2+1]-kBorder; + + Float_t x(node->Data()[ax1]), y(node->Data()[ax2]); + //printf("x[%f] y[%f]\n", x, y); + fCOG.SetX(x); fCOG.SetY(y); +} + + diff --git a/STAT/TKDNodeInfo.h b/STAT/TKDNodeInfo.h index 66458a89c29..2a5a988c480 100644 --- a/STAT/TKDNodeInfo.h +++ b/STAT/TKDNodeInfo.h @@ -5,51 +5,73 @@ #include "TObject.h" #endif +#ifndef ROOT_TBox +#include "TBox.h" +#endif + +#ifndef ROOT_TMarker +#include "TMarker.h" +#endif + template class TVectorT; typedef struct TVectorT TVectorD; template class TMatrixT; typedef class TMatrixT TMatrixD; -//class TKDInterpolatorBase; class TKDNodeInfo : public TObject { //friend class TKDInterpolatorBase; public: - 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) 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; } + class TKDNodeDraw : public TBox { + public: + TKDNodeDraw(); + ~TKDNodeDraw() {;} + void Draw(Option_t* option = ""); + void SetNode(TKDNodeInfo*, UChar_t s, UChar_t ax1=0, UChar_t ax2=1); + private: + TKDNodeDraw(const TKDNodeDraw & ref); + TKDNodeDraw& operator=(const TKDNodeDraw & ref); + + TMarker fCOG; // COG of the node + + ClassDef(TKDNodeDraw, 1) // graphical representation of 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) 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(Int_t ndim); + void Build(Int_t ndim); private: - Int_t fNDim; // 3 times data dimension - Float_t *fData; //[fNDim] node's data - Float_t fVal[2]; // measured value for node - TMatrixD *fCov; // interpolator covariance matrix - TVectorD *fPar; // interpolator parameters + Int_t fNDim; // 3 times data dimension + Float_t *fData; //[fNDim] node's data + Float_t fVal[2]; // measured value for node + TMatrixD *fCov; // interpolator covariance matrix + TVectorD *fPar; // interpolator parameters - ClassDef(TKDNodeInfo, 1) // node info for interpolator + ClassDef(TKDNodeInfo, 1) // node info for interpolator }; //_____________________________________________________________________ Bool_t TKDNodeInfo::Has(const Float_t *p) const { - Int_t n = 0; - Int_t ndim = fNDim/3; - for(int id=0; id=fData[ndim+2*id] && p[id]=fData[ndim+2*id] && p[id]