PDEFoamVect.cxx

Go to the documentation of this file.
00001 
00002 /**********************************************************************************
00003  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
00004  * Package: TMVA                                                                  *
00005  * Classes: PDEFoamVect                                                           *
00006  * Web    : http://tmva.sourceforge.net                                           *
00007  *                                                                                *
00008  * Description:                                                                   *
00009  *      Auxiliary class PDEFoamVect of n-dimensional vector, with dynamic         *
00010  *      allocation used for the cartesian geometry of the PDEFoam cells           *
00011  *                                                                                *
00012  * Authors (alphabetical):                                                        *
00013  *      S. Jadach        - Institute of Nuclear Physics, Cracow, Poland           *
00014  *      Tancredi Carli   - CERN, Switzerland                                      *
00015  *      Dominik Dannheim - CERN, Switzerland                                      *
00016  *      Alexander Voigt  - CERN, Switzerland                                      *
00017  *                                                                                *
00018  * Copyright (c) 2008:                                                            *
00019  *      CERN, Switzerland                                                         *
00020  *      MPI-K Heidelberg, Germany                                                 *
00021  *                                                                                *
00022  * Redistribution and use in source and binary forms, with or without             *
00023  * modification, are permitted according to the terms listed in LICENSE           *
00024  * (http://tmva.sourceforge.net/LICENSE)                                          *
00025  **********************************************************************************/
00026 
00027 #include <iostream>
00028 #include <iomanip>
00029 
00030 #ifndef ROOT_TMVA_PDEFoamVect
00031 #include "TMVA/PDEFoamVect.h"
00032 #endif
00033 
00034 using namespace std;
00035 
00036 //#define SW2 std::setw(12)
00037 
00038 ClassImp(TMVA::PDEFoamVect)
00039 
00040 //_____________________________________________________________________
00041 TMVA::PDEFoamVect::PDEFoamVect()
00042    : TObject(),
00043      fDim(0),
00044      fCoords(0)
00045 {
00046    // Default constructor for streamer
00047 }
00048 
00049 //_____________________________________________________________________
00050 TMVA::PDEFoamVect::PDEFoamVect(Int_t n)
00051    : TObject(),
00052      fDim(n),
00053      fCoords(0)
00054 {
00055    // User constructor creating n-dimensional vector
00056    // and allocating dynamically array of components
00057 
00058    if (n>0) {
00059       fCoords = new Double_t[fDim];
00060       for (Int_t i=0; i<n; i++) *(fCoords+i)=0.0;
00061    }
00062 }
00063 
00064 //_____________________________________________________________________
00065 TMVA::PDEFoamVect::PDEFoamVect(const PDEFoamVect &vect)
00066    : TObject(),
00067      fDim(vect.fDim),
00068      fCoords(vect.fCoords)
00069 {
00070    // Copy constructor
00071    Error( "PDEFoamVect", "COPY CONSTRUCTOR NOT IMPLEMENTED" );
00072 }
00073 
00074 //_____________________________________________________________________
00075 TMVA::PDEFoamVect::~PDEFoamVect()
00076 {
00077    // Destructor
00078    delete [] fCoords; //  free(fCoords)
00079    fCoords=0;
00080 }
00081 
00082 //////////////////////////////////////////////////////////////////////////////
00083 //                     Overloading operators                                //
00084 //////////////////////////////////////////////////////////////////////////////
00085 
00086 //_____________________________________________________________________
00087 TMVA::PDEFoamVect& TMVA::PDEFoamVect::operator =(const PDEFoamVect& Vect)
00088 {
00089    // substitution operator
00090 
00091    if (&Vect == this) return *this;
00092    if( fDim != Vect.fDim )
00093       Error( "PDEFoamVect","operator=Dims. are different: %d and %d \n ",fDim,Vect.fDim);
00094    if( fDim != Vect.fDim ) {  // cleanup
00095       delete [] fCoords;
00096       fCoords = new Double_t[fDim];
00097    }
00098    fDim=Vect.fDim;
00099    for(Int_t i=0; i<fDim; i++)
00100       fCoords[i] = Vect.fCoords[i];
00101    return *this;
00102 }
00103 
00104 //_____________________________________________________________________
00105 Double_t &TMVA::PDEFoamVect::operator[](Int_t n)
00106 {
00107    // [] is for access to elements as in ordinary matrix like a[j]=b[j]
00108    // (Perhaps against some strict rules but rather practical.)
00109    // Range protection is built in, consequently for substitution
00110    // one should use rather use a=b than explicit loop!
00111 
00112    if ((n<0) || (n>=fDim)) {
00113       Error(  "PDEFoamVect","operator[], out of range \n");
00114    }
00115    return fCoords[n];
00116 }
00117 
00118 //_____________________________________________________________________
00119 TMVA::PDEFoamVect& TMVA::PDEFoamVect::operator*=(const Double_t &x)
00120 {
00121    // unary multiplication operator *=
00122 
00123    for(Int_t i=0;i<fDim;i++)
00124       fCoords[i] = fCoords[i]*x;
00125    return *this;
00126 }
00127 
00128 //_____________________________________________________________________
00129 TMVA::PDEFoamVect& TMVA::PDEFoamVect::operator+=(const PDEFoamVect& Shift)
00130 {
00131    // unary addition operator +=; adding vector c*=x,
00132    if( fDim != Shift.fDim){
00133       Error(  "PDEFoamVect","operator+, different dimensions= %d %d \n",fDim,Shift.fDim);
00134    }
00135    for(Int_t i=0;i<fDim;i++)
00136       fCoords[i] = fCoords[i]+Shift.fCoords[i];
00137    return *this;
00138 }
00139 
00140 //_____________________________________________________________________
00141 TMVA::PDEFoamVect& TMVA::PDEFoamVect::operator-=(const PDEFoamVect& Shift)
00142 {
00143    // unary subtraction operator -=
00144    if( fDim != Shift.fDim) {
00145       Error(  "PDEFoamVect","operator+, different dimensions= %d %d \n",fDim,Shift.fDim);
00146    }
00147    for(Int_t i=0;i<fDim;i++)
00148       fCoords[i] = fCoords[i]-Shift.fCoords[i];
00149    return *this;
00150 }
00151 
00152 //_____________________________________________________________________
00153 TMVA::PDEFoamVect TMVA::PDEFoamVect::operator+(const PDEFoamVect &p2)
00154 {
00155    // addition operator +; sum of 2 vectors: c=a+b, a=a+b,
00156    // NEVER USE IT, VERY SLOW!!!
00157    PDEFoamVect temp(fDim);
00158    temp  = (*this);
00159    temp += p2;
00160    return temp;
00161 }
00162 
00163 //_____________________________________________________________________
00164 TMVA::PDEFoamVect TMVA::PDEFoamVect::operator-(const PDEFoamVect &p2)
00165 {
00166    // subtraction operator -; difference of 2 vectors; c=a-b, a=a-b,
00167    // NEVER USE IT, VERY SLOW!!!
00168    PDEFoamVect temp(fDim);
00169    temp  = (*this);
00170    temp -= p2;
00171    return temp;
00172 }
00173 
00174 //_____________________________________________________________________
00175 TMVA::PDEFoamVect& TMVA::PDEFoamVect::operator =(Double_t Vect[])
00176 {
00177    // Loading in ordinary double prec. vector, sometimes can be useful
00178    for(Int_t i=0; i<fDim; i++)
00179       fCoords[i] = Vect[i];
00180    return *this;
00181 }
00182 
00183 //_____________________________________________________________________
00184 TMVA::PDEFoamVect& TMVA::PDEFoamVect::operator =(Double_t x)
00185 {
00186    // Loading in double prec. number, sometimes can be useful
00187    if(fCoords != 0) {
00188       for(Int_t i=0; i<fDim; i++)
00189          fCoords[i] = x;
00190    }
00191    return *this;
00192 }
00193 
00194 //////////////////////////////////////////////////////////////////////////////
00195 //                          OTHER METHODS                                   //
00196 //////////////////////////////////////////////////////////////////////////////
00197 
00198 //_____________________________________________________________________
00199 void TMVA::PDEFoamVect::Print(Option_t *option) const
00200 {
00201    streamsize wid = cout.width(); // saving current field width
00202    // Printout of all vector components
00203    if(!option) Error( "Print ", "No option set \n");
00204    cout << "(";
00205    for(Int_t i=0; i<fDim-1; i++) 
00206       cout << std::setw(12) << *(fCoords+i) << ",";
00207    cout << std::setw(12) << *(fCoords+fDim-1);
00208    cout << ")";
00209    cout.width(wid);
00210 }

Generated on Tue Jul 5 15:25:29 2011 for ROOT_528-00b_version by  doxygen 1.5.1