Volume.cxx

Go to the documentation of this file.
00001 // @(#)root/tmva $Id: Volume.cxx 29122 2009-06-22 06:51:30Z brun $
00002 // Author: Andreas Hoecker, Joerg Stelzer, Helge Voss, Kai Voss 
00003 
00004 /**********************************************************************************
00005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
00006  * Package: TMVA                                                                  *
00007  * Class  : Volume                                                                *
00008  * Web    : http://tmva.sourceforge.net                                           *
00009  *                                                                                *
00010  * Description:                                                                   *
00011  *      Implementation (see header file for description)                          *
00012  *                                                                                *
00013  * Authors (alphabetical):                                                        *
00014  *      Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland              *
00015  *      Helge Voss      <Helge.Voss@cern.ch>     - MPI-K Heidelberg, Germany      *
00016  *      Kai Voss        <Kai.Voss@cern.ch>       - U. of Victoria, Canada         *
00017  *                                                                                *
00018  * Copyright (c) 2005:                                                            *
00019  *      CERN, Switzerland                                                         * 
00020  *      U. of Victoria, Canada                                                    * 
00021  *      MPI-K Heidelberg, Germany                                                 * 
00022  *                                                                                *
00023  * Redistribution and use in source and binary forms, with or without             *
00024  * modification, are permitted according to the terms listed in LICENSE           *
00025  * (http://tmva.sourceforge.net/LICENSE)                                          *
00026  **********************************************************************************/
00027 
00028 #include <stdexcept>
00029 
00030 #include "TMVA/Volume.h"
00031 #include "TMVA/Tools.h"
00032 
00033 #ifndef ROOT_TMVA_MsgLogger
00034 #include "TMVA/MsgLogger.h"
00035 #endif
00036 
00037 //_______________________________________________________________________
00038 //                                                                      
00039 // Volume                                                               //
00040 //                                                                      //
00041 // Volume for BinarySearchTree                                          //
00042 //                                                                      //
00043 // volume element: variable space beteen upper and lower bonds of       //
00044 // nvar-dimensional variable space                                      //
00045 //_______________________________________________________________________
00046 
00047 TMVA::Volume::Volume( std::vector<Double_t>* l, std::vector<Double_t>* u ) 
00048    : fLower( l ), 
00049      fUpper( u ),
00050      fOwnerShip (kFALSE){
00051    // constructor specifying the volume by std::vectors of doubles
00052 }
00053 
00054 TMVA::Volume::Volume( std::vector<Float_t>* l, std::vector<Float_t>* u ) 
00055 {
00056    // constructor specifying the volume by std::vectors of floats
00057    fLower = new std::vector<Double_t>( l->size() );
00058    fUpper = new std::vector<Double_t>( u->size() );
00059    fOwnerShip = kTRUE;
00060   
00061    for (UInt_t ivar=0; ivar<l->size(); ivar++) {
00062       (*fLower)[ivar] = Double_t((*l)[ivar]);
00063       (*fUpper)[ivar] = Double_t((*u)[ivar]);
00064    }  
00065 }
00066 
00067 TMVA::Volume::Volume( Double_t* l, Double_t* u, Int_t nvar ) 
00068 {
00069    // constructor specifiying the volume by c-style arrays of doubles
00070    fLower = new std::vector<Double_t>( nvar );
00071    fUpper = new std::vector<Double_t>( nvar );
00072    fOwnerShip = kTRUE;
00073 
00074    for (int ivar=0; ivar<nvar; ivar++) {
00075       (*fLower)[ivar] = l[ivar];
00076       (*fUpper)[ivar] = u[ivar];
00077    }  
00078 }
00079 
00080 TMVA::Volume::Volume( Float_t* l, Float_t* u, Int_t nvar ) 
00081 {
00082    // constructor specifiying the volume by c-style arrays of floats
00083    fLower = new std::vector<Double_t>( nvar );
00084    fUpper = new std::vector<Double_t>( nvar );
00085    fOwnerShip = kTRUE;
00086 
00087    for (int ivar=0; ivar<nvar; ivar++) {
00088       (*fLower)[ivar] = Double_t(l[ivar]);
00089       (*fUpper)[ivar] = Double_t(u[ivar]);
00090    }  
00091 }
00092 
00093 TMVA::Volume::Volume( Double_t l, Double_t u ) 
00094 {
00095    // simple constructors for 1 dimensional values (double)
00096    fLower = new std::vector<Double_t>(1);
00097    fUpper = new std::vector<Double_t>(1);
00098    fOwnerShip = kTRUE;
00099    (*fLower)[0] = l;
00100    (*fUpper)[0] = u;
00101 }
00102 
00103 TMVA::Volume::Volume( Float_t l, Float_t u ) 
00104 {
00105    // simple constructors for 1 dimensional values (float)
00106    fLower = new std::vector<Double_t>(1);
00107    fUpper = new std::vector<Double_t>(1);
00108    fOwnerShip = kTRUE;
00109    (*fLower)[0] = Double_t(l);
00110    (*fUpper)[0] = Double_t(u);
00111 }
00112 
00113 TMVA::Volume::Volume( Volume& V ) 
00114 { 
00115    // copy constructor
00116    fLower = new std::vector<Double_t>( *V.fLower );
00117    fUpper = new std::vector<Double_t>( *V.fUpper );  
00118    fOwnerShip = kTRUE;
00119 }
00120 
00121 TMVA::Volume::~Volume( void )
00122 {
00123    // destructor
00124    // delete volume boundaries only if owend by the volume
00125    if (fOwnerShip) this->Delete();
00126 } 
00127 
00128 void TMVA::Volume::Delete( void )
00129 {
00130    // delete array of volume bondaries
00131    if (NULL != fLower) { delete fLower; fLower = NULL; }
00132    if (NULL != fUpper) { delete fUpper; fUpper = NULL; }
00133 }
00134 
00135 void TMVA::Volume::Scale( Double_t f )
00136 {
00137    // "scale" the volume by multiplying each upper and lower boundary by "f" 
00138    gTools().Scale(*fLower,f);
00139    gTools().Scale(*fUpper,f);
00140 }
00141 
00142 void TMVA::Volume::ScaleInterval( Double_t f ) 
00143 { 
00144    // "scale" the volume by symmetrically blowing up the interval in each dimension
00145    for (UInt_t ivar=0; ivar<fLower->size(); ivar++) {
00146       Double_t lo = 0.5*((*fLower)[ivar]*(1.0 + f) + (*fUpper)[ivar]*(1.0 - f));
00147       Double_t up = 0.5*((*fLower)[ivar]*(1.0 - f) + (*fUpper)[ivar]*(1.0 + f));
00148       (*fLower)[ivar] = lo;
00149       (*fUpper)[ivar] = up;
00150    }
00151 }
00152 
00153 void TMVA::Volume::Print( void ) const 
00154 {
00155    // printout of the volume boundaries
00156    MsgLogger fLogger( "Volume" );
00157    for (UInt_t ivar=0; ivar<fLower->size(); ivar++) {
00158       fLogger << kINFO << "... Volume: var: " << ivar << "\t(fLower, fUpper) = (" 
00159               << (*fLower)[ivar] << "\t " << (*fUpper)[ivar] <<")"<< Endl;   
00160    }
00161 }
00162 

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