VariableInfo.cxx

Go to the documentation of this file.
00001 // @(#)root/tmva $Id: VariableInfo.cxx 35719 2010-09-24 17:32:57Z stelzer $
00002 // Author: Andreas Hoecker, Peter Speckmayer, Joerg Stelzer, Helge Voss
00003 
00004 /**********************************************************************************
00005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
00006  * Package: TMVA                                                                  *
00007  * Class  : VariableInfo                                                          *
00008  * Web    : http://tmva.sourceforge.net                                           *
00009  *                                                                                *
00010  * Description:                                                                   *
00011  *      Implementation (see header for description)                               *
00012  *                                                                                *
00013  * Authors (alphabetical):                                                        *
00014  *      Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland              *
00015  *      Joerg Stelzer   <Joerg.Stelzer@cern.ch>  - CERN, Switzerland              *
00016  *      Helge Voss      <Helge.Voss@cern.ch>     - MPI-K Heidelberg, Germany      *
00017  *                                                                                *
00018  * Copyright (c) 2005:                                                            *
00019  *      CERN, Switzerland                                                         *
00020  *      U. of Victoria, Canada                                                    *
00021  *      MPI-K Heidelberg, Germany                                                 *
00022  *      LAPP, Annecy, France                                                      *
00023  *                                                                                *
00024  * Redistribution and use in source and binary forms, with or without             *
00025  * modification, are permitted according to the terms listed in LICENSE           *
00026  * (http://mva.sourceforge.net/license.txt)                                       *
00027  **********************************************************************************/
00028 
00029 #include <sstream>
00030 #include <iomanip>
00031 
00032 #include "TMVA/VariableInfo.h"
00033 #include "TMVA/Tools.h"
00034 
00035 #include "TMath.h"
00036 
00037 //_______________________________________________________________________
00038 TMVA::VariableInfo::VariableInfo( const TString& expression, const TString& title, const TString& unit,
00039                                   Int_t varCounter,
00040                                   char varType, void* external,
00041                                   Double_t min, Double_t max, Bool_t normalized )
00042    : fExpression  ( expression ),
00043      fTitle       ( title ),
00044      fUnit        ( unit ),
00045      fVarType     ( varType ),
00046      fXmeanNorm   ( 0 ),
00047      fXrmsNorm    ( 0 ),
00048      fNormalized  ( normalized ),
00049      fExternalData( external ),
00050      fVarCounter  ( varCounter )
00051 {
00052    // constructor
00053 
00054    if ( TMath::Abs(max - min) <= FLT_MIN ) {
00055       fXminNorm =  FLT_MAX;
00056       fXmaxNorm = -FLT_MAX;
00057    } 
00058    else {
00059       fXminNorm =  min;
00060       fXmaxNorm =  max;
00061    }
00062 
00063    // if a label is set, than retrieve the label and the 
00064    if (expression.Contains(":=")) {
00065       Ssiz_t index  = expression.Index(":=");
00066       fExpression   = expression(index+2,expression.Sizeof()-index-2);
00067       fLabel        = expression(0,index);
00068       fLabel        = fLabel.ReplaceAll(" ","");
00069    }
00070    else fLabel = GetExpression();
00071 
00072    if (fTitle == "") fTitle = fLabel;
00073    fInternalName = gTools().ReplaceRegularExpressions( fLabel, "_" );   
00074 }
00075 
00076 //_______________________________________________________________________
00077 TMVA::VariableInfo::VariableInfo() 
00078    : fExpression  (""),
00079      fVarType     ('\0'),
00080      fXmeanNorm   ( 0 ),
00081      fXrmsNorm    ( 0 ),
00082      fNormalized  ( kFALSE ),
00083      fExternalData( 0 ),
00084      fVarCounter  ( 0 )
00085 {
00086    // default constructor
00087    fXminNorm     =  1e30;
00088    fXmaxNorm     = -1e30;
00089    fLabel        = GetExpression();
00090    fTitle        = fLabel;
00091    fUnit         = "";
00092    fInternalName = gTools().ReplaceRegularExpressions( fLabel, "_" );   
00093 }
00094 
00095 //_______________________________________________________________________
00096 TMVA::VariableInfo::VariableInfo( const VariableInfo& other ) 
00097    : fExpression  ( other.fExpression ),
00098      fInternalName( other.fInternalName ),
00099      fLabel       ( other.fLabel ),
00100      fTitle       ( other.fTitle ),
00101      fUnit        ( other.fUnit ),
00102      fVarType     ( other.fVarType ),
00103      fXminNorm    ( other.fXminNorm ),
00104      fXmaxNorm    ( other.fXmaxNorm ),
00105      fXmeanNorm   ( other.fXmeanNorm ),
00106      fXrmsNorm    ( other.fXrmsNorm ),
00107      fNormalized  ( other.fNormalized ),
00108      fExternalData( other.fExternalData ),
00109      fVarCounter  ( other.fVarCounter )
00110 {
00111    // copy constructor
00112 }
00113 
00114 //_______________________________________________________________________
00115 TMVA::VariableInfo& TMVA::VariableInfo::operator=(const VariableInfo& rhs)
00116 {
00117    // comparison operator
00118    if (this !=& rhs) {
00119       fExpression       = rhs.fExpression;
00120       fInternalName     = rhs.fInternalName;
00121       fVarType          = rhs.fVarType;
00122       fXminNorm         = rhs.fXminNorm;
00123       fXmaxNorm         = rhs.fXmaxNorm;
00124    }
00125    return *this;
00126 }
00127 
00128 //_______________________________________________________________________
00129 void TMVA::VariableInfo::WriteToStream( std::ostream& o ) const
00130 {
00131    // write VariableInfo to stream 
00132    UInt_t nc = TMath::Max( 30, TMath::Max( GetExpression().Length()+1, GetInternalName().Length()+1 ) );
00133    TString expBr(Form("\'%s\'",GetExpression().Data()));
00134    o << std::setw(nc) << GetExpression();
00135    o << std::setw(nc) << GetInternalName();
00136    o << std::setw(nc) << GetLabel();
00137    o << std::setw(nc) << GetTitle();
00138    o << std::setw(nc) << GetUnit();
00139    o << "    \'" << fVarType << "\'    ";
00140    o << "[" << std::setprecision(12) << GetMin() << "," << std::setprecision(12) << GetMax() << "]" << std::endl;
00141 }
00142 
00143 //_______________________________________________________________________
00144 void TMVA::VariableInfo::ReadFromStream( std::istream& istr )
00145 {
00146    // read VariableInfo from stream
00147 
00148    // PLEASE do not modify this, it does not have to correspond to WriteToStream
00149    // this is needed to stay like this in 397 for backward compatibility
00150    TString exp, varname, vartype, minmax, minstr, maxstr;
00151    istr >> exp >> varname >> vartype >> minmax;
00152    exp.Strip(TString::kBoth, '\'');
00153    minmax = minmax.Strip(TString::kLeading, '[');
00154    minmax = minmax.Strip(TString::kTrailing, ']');
00155    minstr = minmax(0,minmax.First(','));
00156    maxstr = minmax(1+minmax.First(','),minmax.Length());
00157    Double_t min, max;
00158    std::stringstream strmin(minstr.Data());
00159    std::stringstream strmax(maxstr.Data());
00160    strmin >> min;
00161    strmax >> max;
00162    SetExpression     ( exp );
00163    SetInternalVarName( varname );
00164    SetLabel          ( varname );
00165    SetTitle          ( varname );
00166    SetUnit           ( "" );
00167    SetVarType        ( vartype[1] );
00168    SetMin            ( min );
00169    SetMax            ( max );
00170 }
00171 
00172 //_______________________________________________________________________
00173 void TMVA::VariableInfo::AddToXML( void* varnode )
00174 {
00175    // write class to XML
00176    gTools().AddAttr( varnode, "Expression", GetExpression() );
00177    gTools().AddAttr( varnode, "Label",      GetLabel() );
00178    gTools().AddAttr( varnode, "Title",      GetTitle() );
00179    gTools().AddAttr( varnode, "Unit",       GetUnit() );
00180    gTools().AddAttr( varnode, "Internal",   GetInternalName() );
00181 
00182    TString typeStr(" ");
00183    typeStr[0] = GetVarType();
00184    gTools().AddAttr( varnode, "Type", typeStr );
00185    gTools().AddAttr( varnode, "Min", gTools().StringFromDouble(GetMin()) );
00186    gTools().AddAttr( varnode, "Max", gTools().StringFromDouble(GetMax()) );
00187 }
00188 
00189 //_______________________________________________________________________
00190 void TMVA::VariableInfo::ReadFromXML( void* varnode ) 
00191 {
00192    // read VariableInfo from stream
00193    TString type;
00194    gTools().ReadAttr( varnode, "Expression", fExpression );
00195    gTools().ReadAttr( varnode, "Label",      fLabel );
00196    gTools().ReadAttr( varnode, "Title",      fTitle );
00197    gTools().ReadAttr( varnode, "Unit",       fUnit );
00198    gTools().ReadAttr( varnode, "Internal",   fInternalName );
00199    gTools().ReadAttr( varnode, "Type",       type );
00200    gTools().ReadAttr( varnode, "Min",        fXminNorm );
00201    gTools().ReadAttr( varnode, "Max",        fXmaxNorm );
00202 
00203    SetVarType(type[0]);
00204 }

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