TFoamCell.cxx

Go to the documentation of this file.
00001 // @(#)root/foam:$Id: TFoamCell.cxx 35900 2010-09-30 10:19:53Z brun $
00002 // Author: S. Jadach <mailto:Stanislaw.jadach@ifj.edu.pl>, P.Sawicki <mailto:Pawel.Sawicki@ifj.edu.pl>
00003 
00004 //_________________________________________________________________________________
00005 //
00006 // Class TFoamCell  used in TFoam
00007 // ==============================
00008 // Objects of this class are hyper-rectangular cells organized in the binary tree.
00009 // Special algorithm for encoding relative positioning of the cells
00010 // allow to save total memory allocation needed for the system of cells.
00011 //
00012 //_________________________________________________________________________________
00013 
00014 #include "Riostream.h"
00015 #include "TFoamCell.h"
00016 #include "TFoamVect.h"
00017 
00018 
00019 ClassImp(TFoamCell);
00020 
00021 //________________________________________________________________________________
00022 TFoamCell::TFoamCell()
00023 {
00024 // Default constructor for streamer
00025 
00026    fParent  = 0;
00027    fDaught0 = 0;
00028    fDaught1 = 0;
00029 }
00030 
00031 //_________________________________________________________________________________
00032 TFoamCell::TFoamCell(Int_t kDim)
00033 {
00034 // User constructor allocating single empty Cell
00035    if (  kDim >0) {
00036       //---------=========----------
00037       fDim     = kDim;
00038       fSerial   = 0;
00039       fStatus   = 1;
00040       fParent   = 0;
00041       fDaught0  = 0;
00042       fDaught1  = 0;
00043       fXdiv     = 0.0;
00044       fBest     = 0;
00045       fVolume   = 0.0;
00046       fIntegral = 0.0;
00047       fDrive    = 0.0;
00048       fPrimary  = 0.0;
00049    } else
00050       Error("TFoamCell","Dimension has to be >0 \n ");
00051 }
00052 
00053 //_________________________________________________________________________________
00054 TFoamCell::TFoamCell(TFoamCell &From): TObject(From)
00055 {
00056 // Copy constructor (not tested!)
00057 
00058    Error("TFoamCell", "+++++ NEVER USE Copy constructor for TFoamCell \n");
00059    fStatus      = From.fStatus;
00060    fParent      = From.fParent;
00061    fDaught0     = From.fDaught0;
00062    fDaught1     = From.fDaught1;
00063    fXdiv        = From.fXdiv;
00064    fBest        = From.fBest;
00065    fVolume      = From.fVolume;
00066    fIntegral    = From.fIntegral;
00067    fDrive       = From.fDrive;
00068    fPrimary     = From.fPrimary;
00069 }
00070 
00071 //___________________________________________________________________________________
00072 TFoamCell::~TFoamCell()
00073 {
00074 // Destructor
00075 }
00076 
00077 //___________________________________________________________________________________
00078 TFoamCell& TFoamCell::operator=(const TFoamCell &From)
00079 {
00080 // Substitution operator = (never used)
00081 
00082    Info("TFoamCell", "operator=\n ");
00083    if (&From == this) return *this;
00084    fStatus      = From.fStatus;
00085    fParent      = From.fParent;
00086    fDaught0     = From.fDaught0;
00087    fDaught1     = From.fDaught1;
00088    fXdiv        = From.fXdiv;
00089    fBest        = From.fBest;
00090    fVolume      = From.fVolume;
00091    fIntegral    = From.fIntegral;
00092    fDrive       = From.fDrive;
00093    fPrimary     = From.fPrimary;
00094    return *this;
00095 }
00096 
00097 
00098 //___________________________________________________________________________________
00099 void TFoamCell::Fill(Int_t Status, TFoamCell *Parent, TFoamCell *Daugh1, TFoamCell *Daugh2)
00100 {
00101 // Fills in certain data into newly allocated cell
00102 
00103    fStatus  = Status;
00104    fParent  = Parent;
00105    fDaught0 = Daugh1;
00106    fDaught1 = Daugh2;
00107 }
00108 
00109 ////////////////////////////////////////////////////////////////////////////////
00110 //              GETTERS/SETTERS
00111 ////////////////////////////////////////////////////////////////////////////////
00112 
00113 //_____________________________________________________________________________________
00114 void    TFoamCell::GetHcub( TFoamVect &cellPosi, TFoamVect &cellSize)  const
00115 {
00116 // Provides size and position of the cell
00117 // These parameter are calculated by analyzing information in all parents
00118 // cells up to the root cell. It takes time but saves memory.
00119    if(fDim<1) return;
00120    const TFoamCell *pCell,*dCell;
00121    cellPosi = 0.0; cellSize=1.0; // load all components
00122    dCell = this;
00123    while(dCell != 0) {
00124       pCell = dCell->GetPare();
00125       if( pCell== 0) break;
00126       Int_t    kDiv = pCell->fBest;
00127       Double_t xDivi = pCell->fXdiv;
00128       if(dCell == pCell->GetDau0()  ) {
00129          cellSize[kDiv] *=xDivi;
00130          cellPosi[kDiv] *=xDivi;
00131       } else if(   dCell == pCell->GetDau1()  ) {
00132          cellSize[kDiv] *=(1.0-xDivi);
00133          cellPosi[kDiv]  =cellPosi[kDiv]*(1.0-xDivi)+xDivi;
00134       } else {
00135          Error("GetHcub ","Something wrong with linked tree \n");
00136       }
00137       dCell=pCell;
00138    }//while
00139 }//GetHcub
00140 
00141 //______________________________________________________________________________________
00142 void    TFoamCell::GetHSize( TFoamVect &cellSize)  const
00143 {
00144 // Provides size of the cell
00145 // Size parameters are calculated by analyzing information in all parents
00146 // cells up to the root cell. It takes time but saves memory.
00147    if(fDim<1) return;
00148    const TFoamCell *pCell,*dCell;
00149    cellSize=1.0; // load all components
00150    dCell = this;
00151    while(dCell != 0) {
00152       pCell = dCell->GetPare();
00153       if( pCell== 0) break;
00154       Int_t    kDiv = pCell->fBest;
00155       Double_t xDivi = pCell->fXdiv;
00156       if(dCell == pCell->GetDau0() ) {
00157          cellSize[kDiv]=cellSize[kDiv]*xDivi;
00158       } else if(dCell == pCell->GetDau1()  ) {
00159          cellSize[kDiv]=cellSize[kDiv]*(1.0-xDivi);
00160       } else {
00161          Error("GetHSize ","Something wrong with linked tree \n");
00162       }
00163       dCell=pCell;
00164    }//while
00165 }//GetHSize
00166 
00167 //_________________________________________________________________________________________
00168 void TFoamCell::CalcVolume(void)
00169 {
00170 // Calculates volume of the cell using size params which are calculated
00171 
00172    Int_t k;
00173    Double_t volu=1.0;
00174    if(fDim>0) {         // h-cubical subspace
00175       TFoamVect cellSize(fDim);
00176       GetHSize(cellSize);
00177       for(k=0; k<fDim; k++) volu *= cellSize[k];
00178    }
00179    fVolume =volu;
00180 }
00181 
00182 //__________________________________________________________________________________________
00183 void TFoamCell::Print(Option_t *option) const
00184 {
00185 // Printout of the cell geometry parameters for the debug purpose
00186 
00187    if(!option) Error("Print", "No option set\n");
00188 
00189    cout <<  " Status= "<<     fStatus   <<",";
00190    cout <<  " Volume= "<<     fVolume   <<",";
00191    cout <<  " TrueInteg= " << fIntegral <<",";
00192    cout <<  " DriveInteg= "<< fDrive    <<",";
00193    cout <<  " PrimInteg= " << fPrimary  <<",";
00194    cout<< endl;
00195    cout <<  " Xdiv= "<<fXdiv<<",";
00196    cout <<  " Best= "<<fBest<<",";
00197    cout <<  " Parent=  {"<< (GetPare() ? GetPare()->GetSerial() : -1) <<"} "; // extra DEBUG
00198    cout <<  " Daught0= {"<< (GetDau0() ? GetDau0()->GetSerial() : -1 )<<"} "; // extra DEBUG
00199    cout <<  " Daught1= {"<< (GetDau1() ? GetDau1()->GetSerial()  : -1 )<<"} "; // extra DEBUG
00200    cout<< endl;
00201    //
00202    //
00203    if(fDim>0 ) {
00204       TFoamVect cellPosi(fDim); TFoamVect cellSize(fDim);
00205       GetHcub(cellPosi,cellSize);
00206       cout <<"   Posi= "; cellPosi.Print("1"); cout<<","<< endl;
00207       cout <<"   Size= "; cellSize.Print("1"); cout<<","<< endl;
00208    }
00209 }
00210 ///////////////////////////////////////////////////////////////////
00211 //        End of  class  TFoamCell                               //
00212 ///////////////////////////////////////////////////////////////////

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