RuleCut.h

Go to the documentation of this file.
00001 // @(#)root/tmva $Id: RuleCut.h 35732 2010-09-25 11:49:37Z stelzer $
00002 // Author: Andreas Hoecker, Joerg Stelzer, Fredrik Tegenfeldt, Helge Voss
00003 
00004 /**********************************************************************************
00005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
00006  * Package: TMVA                                                                  *
00007  * Class  : Rule                                                                  *
00008  *                                                                                *
00009  * Description:                                                                   *
00010  *      A class describing a 'rule cut'                                           *
00011  *                                                                                *
00012  *                                                                                *
00013  * Authors (alphabetical):                                                        *
00014  *      Fredrik Tegenfeldt <Fredrik.Tegenfeldt@cern.ch> - Iowa State U., USA      *
00015  *                                                                                *
00016  * Copyright (c) 2005:                                                            *
00017  *      CERN, Switzerland                                                         *
00018  *      Iowa State U.                                                             *
00019  *                                                                                *
00020  * Redistribution and use in source and binary forms, with or without             *
00021  * modification, are permitted according to the terms listed in LICENSE           *
00022  * (http://tmva.sourceforge.net/LICENSE)                                          *
00023  **********************************************************************************/
00024 #ifndef ROOT_TMVA_RuleCut
00025 #define ROOT_TMVA_RuleCut
00026 
00027 #ifndef ROOT_TMVA_Event
00028 #include "TMVA/Event.h"
00029 #endif
00030 
00031 namespace TMVA {
00032 
00033    class Node;
00034    class MsgLogger;
00035 
00036    class RuleCut {
00037 
00038    public:
00039 
00040       // main constructor
00041       RuleCut( const std::vector< const TMVA::Node * > & nodes );
00042 
00043       // copy constructor
00044       RuleCut( const RuleCut & other ) : fLogger(0) { Copy( other ); }
00045 
00046       // empty constructor
00047       RuleCut();
00048 
00049       // destructor
00050       virtual ~RuleCut();
00051 
00052       // evaluate an event
00053       inline Bool_t EvalEvent( const Event &eve );
00054 
00055       // get cut range for a given selector
00056       Bool_t GetCutRange(Int_t sel,Double_t &rmin, Double_t &rmax, Bool_t &dormin, Bool_t &dormax) const;
00057 
00058       // number of cuts
00059       UInt_t GetNcuts() const;
00060 
00061       // set members
00062       inline void SetNvars( UInt_t nc );
00063       void SetNeve( Double_t n )                   { fCutNeve     = n;   }
00064       void SetPurity( Double_t ssb )               { fPurity      = ssb; }
00065       void SetSelector( Int_t i, UInt_t s )        { fSelector[i] = s; }
00066       void SetCutMin( Int_t i, Double_t v )        { fCutMin[i]   = v; }
00067       void SetCutMax( Int_t i, Double_t v )        { fCutMax[i]   = v; }
00068       void SetCutDoMin( Int_t i, Bool_t v )        { fCutDoMin[i] = v; }
00069       void SetCutDoMax( Int_t i, Bool_t v )        { fCutDoMax[i] = v; }
00070 
00071       // accessors
00072       UInt_t   GetNvars()              const { return fSelector.size(); }
00073       UInt_t   GetSelector(Int_t is)   const { return fSelector[is]; }
00074       Double_t GetCutMin(Int_t is)     const { return fCutMin[is]; }
00075       Double_t GetCutMax(Int_t is)     const { return fCutMax[is]; }
00076       Char_t   GetCutDoMin(Int_t is)   const { return fCutDoMin[is]; }
00077       Char_t   GetCutDoMax(Int_t is)   const { return fCutDoMax[is]; }
00078       Double_t GetCutNeve()            const { return fCutNeve; }
00079       Double_t GetPurity()             const { return fPurity; }
00080 
00081    private:
00082       // copy
00083       inline void Copy( const RuleCut & other);
00084 
00085       // make the cuts from the array of nodes
00086       void MakeCuts( const std::vector< const TMVA::Node * > & nodes );
00087 
00088       std::vector<UInt_t>   fSelector; // array of selectors (expressions)
00089       std::vector<Double_t> fCutMin;   // array of lower limits
00090       std::vector<Double_t> fCutMax;   // array of upper limits
00091       std::vector<Char_t>   fCutDoMin; // array of usage flags for lower limits <--- stores boolean
00092       std::vector<Char_t>   fCutDoMax; // array of usage flags for upper limits <--- stores boolean
00093       Double_t              fCutNeve;  // N(events) after cut (possibly weighted)
00094       Double_t              fPurity;  // S/(S+B) on training data
00095 
00096 
00097       mutable MsgLogger*    fLogger;   // message logger
00098       MsgLogger& Log() const { return *fLogger; }
00099    };
00100 }
00101 
00102 //_______________________________________________________________________
00103 inline void TMVA::RuleCut::Copy( const TMVA::RuleCut & other )
00104 {
00105    // copy from another
00106    if (&other != this) {
00107       for (UInt_t ns=0; ns<other.GetNvars(); ns++) {
00108          fSelector.push_back( other.GetSelector(ns) );
00109          fCutMin.push_back( other.GetCutMin(ns) );
00110          fCutMax.push_back( other.GetCutMax(ns) );
00111          fCutDoMin.push_back( other.GetCutDoMin(ns) );
00112          fCutDoMax.push_back( other.GetCutDoMax(ns) );
00113       }
00114       fCutNeve = other.GetCutNeve();
00115       fPurity = other.GetPurity();
00116    }
00117 }
00118 
00119 //_______________________________________________________________________
00120 inline Bool_t TMVA::RuleCut::EvalEvent( const Event &eve )
00121 {
00122    // evaluate event using the cut
00123 
00124    // Loop over all cuts
00125    Int_t    sel;
00126    Double_t val;
00127    Bool_t done=kFALSE;
00128    Bool_t minOK, cutOK;
00129    UInt_t nc=0;
00130    while (!done) {
00131       sel = fSelector[nc];
00132       val = eve.GetValue(sel);
00133       minOK = (fCutDoMin[nc] ? (val>fCutMin[nc]):kTRUE); // min cut ok
00134       cutOK = (minOK ? ((fCutDoMax[nc] ? (val<fCutMax[nc]):kTRUE)) : kFALSE); // cut ok
00135       nc++;
00136       done = ((!cutOK) || (nc==fSelector.size())); // done if 
00137    }
00138    //   return ( cutOK ? 1.0: 0.0 );
00139    return cutOK;
00140 }
00141 
00142 //_______________________________________________________________________
00143 inline void TMVA::RuleCut::SetNvars( UInt_t nc )
00144 {
00145    // set the number of cuts
00146    fSelector.clear();
00147    fCutMin.clear();
00148    fCutMax.clear();
00149    fCutDoMin.clear();
00150    fCutDoMax.clear();
00151    //
00152    fSelector.resize(nc);
00153    fCutMin.resize(nc);
00154    fCutMax.resize(nc);
00155    fCutDoMin.resize(nc);
00156    fCutDoMax.resize(nc);
00157 }
00158 
00159 #endif

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