ROOT logo
// @(#)root/tmva $Id: Event.h 29205 2009-06-24 19:33:19Z brun $   
// Author: Andreas Hoecker, Joerg Stelzer, Helge Voss

/**********************************************************************************
 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
 * Package: TMVA                                                                  *
 * Class  : Event                                                                 *
 * Web    : http://tmva.sourceforge.net                                           *
 *                                                                                *
 * Description:                                                                   *
 *      Event container                                                           *
 *                                                                                *
 * Authors (alphabetical):                                                        *
 *      Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland              *
 *      Joerg Stelzer   <Joerg.Stelzer@cern.ch>  - CERN, Switzerland              *
 *      Helge Voss      <Helge.Voss@cern.ch>     - MPI-K Heidelberg, Germany      *
 *                                                                                *
 * Copyright (c) 2005:                                                            *
 *      CERN, Switzerland                                                         * 
 *      U. of Victoria, Canada                                                    * 
 *      MPI-K Heidelberg, Germany                                                 * 
 *      LAPP, Annecy, France                                                      *
 *                                                                                *
 * Redistribution and use in source and binary forms, with or without             *
 * modification, are permitted according to the terms listed in LICENSE           *
 * (http://mva.sourceforge.net/license.txt)                                       *
 **********************************************************************************/

#ifndef ROOT_TMVA_Event
#define ROOT_TMVA_Event

#include <iosfwd>
#include <vector>

#ifndef ROOT_Rtypes
#include "Rtypes.h"
#endif
#ifndef ROOT_TMVA_Types
#include "TMVA/Types.h"
#endif

namespace TMVA {

   class Event;

   std::ostream& operator<<( std::ostream& os, const Event& event );
   std::ostream& operator<<( std::ostream& os, const Event* event );

   class Event {

      friend std::ostream& operator<<( std::ostream& os, const Event& event );
      friend std::ostream& operator<<( std::ostream& os, const Event* event );

   public:

      // constructors
      Event();
      Event( const Event& );
      explicit Event( const std::vector<Float_t>&, 
                      const std::vector<Float_t>& targetValues, 
                      const std::vector<Float_t>& spectatorValues, 
                      UInt_t theClass = 0, Float_t weight = 1.0, Float_t boostweight = 1.0 );
      explicit Event( const std::vector<Float_t>&, 
                      const std::vector<Float_t>& targetValues, 
                      UInt_t theClass = 0, Float_t weight = 1.0, Float_t boostweight = 1.0 );
      explicit Event( const std::vector<Float_t>&, 
                      UInt_t theClass, Float_t weight = 1.0, Float_t boostweight = 1.0 );
      explicit Event( const std::vector<Float_t*>*& );

      ~Event();

      // accessors
      Bool_t  IsSignal()          const { return (fClass==fSignalClass); } // deprecated: use <DataSetInfo>.IsSignal( Event* )

      Float_t GetWeight()         const { return fWeight*fBoostWeight; }
      Float_t GetOriginalWeight() const { return fWeight; }
      Float_t GetBoostWeight()    const { return TMath::Max(Float_t(0.0001),fBoostWeight); }
      UInt_t  GetType()           const { return GetClass(); }  // better use GetClass()
      UInt_t  GetClass()          const { return fClass; }  
      UInt_t  Type()              const { return fClass; }  // backward compatible -> to be removed

      UInt_t  GetNVariables()     const { return fValues.size(); }
      UInt_t  GetNTargets()       const { return fTargets.size(); }
      UInt_t  GetNSpectators()    const { return fSpectators.size(); }
      UInt_t  GetNVars()          const { return fValues.size(); }  // backward compatible -> to be removed

      Float_t GetVal(UInt_t ivar) const;
      Int_t   GetSignalClass()    const { return fSignalClass; } // intermediate solution to keep IsSignal() of Event working
      
      const std::vector<Float_t>& GetValues() const;

      Float_t GetValue          ( UInt_t ivar) const { return GetVal( ivar ); }

      void    ScaleWeight       ( Float_t s ) { fWeight*=s; }
      void    SetWeight         ( Float_t w ) { fWeight=w; }
      void    SetBoostWeight    ( Float_t w ) { fBoostWeight=w; }
      void    ScaleBoostWeight  ( Float_t s ) { fBoostWeight *= s; }
      void    SetType           ( Int_t t  )  { SetClass(t); }
      void    SetClass          ( UInt_t t )  { fClass=t; }
      void    SetType           ( Types::ESBType t ) { fClass=(t==Types::kSignal) ? 1 : 0; }
      void    SetVal            ( UInt_t ivar, Float_t val );
      void    SetValFloatNoCheck( UInt_t ivar, Float_t val ) { fValues[ivar] = val; }

      void    SetSignalClass    ( UInt_t cls ){ fSignalClass = cls; } // intermediate solution to keep IsSignal() of Event working. TODO: remove IsSignal() from Event

      void    SetTarget( UInt_t itgt, Float_t value ) { 
         if (fTargets.size() <= itgt) fTargets.resize( itgt+1 );
         fTargets.at(itgt) = value;
      }
      std::vector<Float_t>& GetTargets()             const { return fTargets; }
      Float_t               GetTarget( UInt_t itgt ) const { return fTargets.at(itgt); }

      void    SetSpectator( UInt_t ivar, Float_t value ) { 
         if (fSpectators.size() <= ivar) fSpectators.resize( ivar+1 );
         fSpectators.at(ivar) = value;
      }
      std::vector<Float_t>& GetSpectators()            const { return fSpectators; }
      Float_t               GetSpectator( UInt_t ivar) const { return fSpectators.at(ivar); }

      static void ClearDynamicVariables();

      void    CopyVarValues( const Event& other );
      void    Print        ( std::ostream & o ) const;

   private:

      mutable std::vector<Float_t>   fValues;          // the event values
      static  std::vector<Float_t*>* fgValuesDynamic;  // the event values
      mutable std::vector<Float_t>   fTargets;         // target values for regression

      mutable std::vector<Float_t>   fSpectators;        // "visisting" variables which are never used for any calculation


      UInt_t                         fClass;           // signal or background type: signal=1, background=0
      Float_t                        fWeight;          // event weight (product of global and individual weights)
      Float_t                        fBoostWeight;     // internal weight to be set by boosting algorithm
      Bool_t                         fDynamic;         // is set when the dynamic values are taken

      UInt_t                         fSignalClass;     // intermediate solution to keep IsSignal() of Event working. TODO: remove IsSignal() from Event
      
      static Int_t                   fgCount;          // count instances of Event
   };
}

#endif
 Event.h:1
 Event.h:2
 Event.h:3
 Event.h:4
 Event.h:5
 Event.h:6
 Event.h:7
 Event.h:8
 Event.h:9
 Event.h:10
 Event.h:11
 Event.h:12
 Event.h:13
 Event.h:14
 Event.h:15
 Event.h:16
 Event.h:17
 Event.h:18
 Event.h:19
 Event.h:20
 Event.h:21
 Event.h:22
 Event.h:23
 Event.h:24
 Event.h:25
 Event.h:26
 Event.h:27
 Event.h:28
 Event.h:29
 Event.h:30
 Event.h:31
 Event.h:32
 Event.h:33
 Event.h:34
 Event.h:35
 Event.h:36
 Event.h:37
 Event.h:38
 Event.h:39
 Event.h:40
 Event.h:41
 Event.h:42
 Event.h:43
 Event.h:44
 Event.h:45
 Event.h:46
 Event.h:47
 Event.h:48
 Event.h:49
 Event.h:50
 Event.h:51
 Event.h:52
 Event.h:53
 Event.h:54
 Event.h:55
 Event.h:56
 Event.h:57
 Event.h:58
 Event.h:59
 Event.h:60
 Event.h:61
 Event.h:62
 Event.h:63
 Event.h:64
 Event.h:65
 Event.h:66
 Event.h:67
 Event.h:68
 Event.h:69
 Event.h:70
 Event.h:71
 Event.h:72
 Event.h:73
 Event.h:74
 Event.h:75
 Event.h:76
 Event.h:77
 Event.h:78
 Event.h:79
 Event.h:80
 Event.h:81
 Event.h:82
 Event.h:83
 Event.h:84
 Event.h:85
 Event.h:86
 Event.h:87
 Event.h:88
 Event.h:89
 Event.h:90
 Event.h:91
 Event.h:92
 Event.h:93
 Event.h:94
 Event.h:95
 Event.h:96
 Event.h:97
 Event.h:98
 Event.h:99
 Event.h:100
 Event.h:101
 Event.h:102
 Event.h:103
 Event.h:104
 Event.h:105
 Event.h:106
 Event.h:107
 Event.h:108
 Event.h:109
 Event.h:110
 Event.h:111
 Event.h:112
 Event.h:113
 Event.h:114
 Event.h:115
 Event.h:116
 Event.h:117
 Event.h:118
 Event.h:119
 Event.h:120
 Event.h:121
 Event.h:122
 Event.h:123
 Event.h:124
 Event.h:125
 Event.h:126
 Event.h:127
 Event.h:128
 Event.h:129
 Event.h:130
 Event.h:131
 Event.h:132
 Event.h:133
 Event.h:134
 Event.h:135
 Event.h:136
 Event.h:137
 Event.h:138
 Event.h:139
 Event.h:140
 Event.h:141
 Event.h:142
 Event.h:143
 Event.h:144
 Event.h:145