Logo ROOT   6.07/09
Reference Guide
Event.h
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Peter Speckmayer, Joerg Stelzer, Helge Voss, Jan Therhaag
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : Event *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Event container *
12  * *
13  * Authors (alphabetical): *
14  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15  * Joerg Stelzer <Joerg.Stelzer@cern.ch> - CERN, Switzerland *
16  * Peter Speckmayer <Peter.Speckmayer@cern.ch> - CERN, Switzerland *
17  * Jan Therhaag <Jan.Therhaag@cern.ch> - U of Bonn, Germany *
18  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
19  * *
20  * Copyright (c) 2005-2011: *
21  * CERN, Switzerland *
22  * U. of Victoria, Canada *
23  * MPI-K Heidelberg, Germany *
24  * U. of Bonn, Germany *
25  * *
26  * Redistribution and use in source and binary forms, with or without *
27  * modification, are permitted according to the terms listed in LICENSE *
28  * (http://mva.sourceforge.net/license.txt) *
29  **********************************************************************************/
30 
31 #ifndef ROOT_TMVA_Event
32 #define ROOT_TMVA_Event
33 
34 #include <iosfwd>
35 #include <vector>
36 
37 #ifndef ROOT_Rtypes
38 #include "Rtypes.h"
39 #endif
40 #ifndef ROOT_ThreadLocalStorage
41 #include "ThreadLocalStorage.h"
42 #endif
43 #ifndef ROOT_TMVA_Types
44 #include "TMVA/Types.h"
45 #endif
46 
47 #ifndef ROOT_TObject
48 #include "TObject.h"
49 #endif
50 
51 
52 class TCut;
53 
54 namespace TMVA {
55 
56  class Event;
57 
58  std::ostream& operator<<( std::ostream& os, const Event& event );
59 
60  class Event:public TObject {
61 
62  friend std::ostream& operator<<( std::ostream& os, const Event& event );
63 
64  public:
65 
66  // constructors
67  Event();
68  Event( const Event& );
69  explicit Event( const std::vector<Float_t>& values,
70  const std::vector<Float_t>& targetValues,
71  const std::vector<Float_t>& spectatorValues,
72  UInt_t theClass = 0, Double_t weight = 1.0, Double_t boostweight = 1.0 );
73  explicit Event( const std::vector<Float_t>& values,
74  const std::vector<Float_t>& targetValues,
75  UInt_t theClass = 0, Double_t weight = 1.0, Double_t boostweight = 1.0 );
76  explicit Event( const std::vector<Float_t>&,
77  UInt_t theClass, Double_t weight = 1.0, Double_t boostweight = 1.0 );
78  explicit Event( const std::vector<Float_t*>*&, UInt_t nvar );
79 
80  ~Event();
81 
82  // accessors
83  Bool_t IsDynamic() const {return fDynamic; }
84 
85  // Double_t GetWeight() const { return fWeight*fBoostWeight; }
86  Double_t GetWeight() const;
87  Double_t GetOriginalWeight() const { return fWeight; }
89  UInt_t GetClass() const { return fClass; }
90 
91  UInt_t GetNVariables() const;
92  UInt_t GetNTargets() const;
93  UInt_t GetNSpectators() const;
94 
95  Float_t GetValue( UInt_t ivar) const;
96  std::vector<Float_t>& GetValues()
97  {
98  //For a detailed explanation, please see the heading "Avoid Duplication in const and Non-const Member Function," on p. 23, in Item 3 "Use const whenever possible," in Effective C++, 3d ed by Scott Meyers, ISBN-13: 9780321334879.
99  // http://stackoverflow.com/questions/123758/how-do-i-remove-code-duplication-between-similar-const-and-non-const-member-func
100  return const_cast<std::vector<Float_t>&>( static_cast<const Event&>(*this).GetValues() );
101  }
102  const std::vector<Float_t>& GetValues() const;
103 
104  Float_t GetTarget( UInt_t itgt ) const { return fTargets.at(itgt); }
105  std::vector<Float_t>& GetTargets() { return fTargets; }
106  const std::vector<Float_t>& GetTargets() const { return fTargets; }
107 
108  Float_t GetSpectator( UInt_t ivar) const;
109  std::vector<Float_t>& GetSpectators() { return fSpectators; }
110  const std::vector<Float_t>& GetSpectators() const { return fSpectators; }
111 
112  void SetWeight ( Double_t w ) { fWeight=w; }
115  void SetClass ( UInt_t t ) { fClass=t; }
116  void SetVal ( UInt_t ivar, Float_t val );
117  void SetTarget ( UInt_t itgt, Float_t value );
118  void SetSpectator ( UInt_t ivar, Float_t value );
119  void SetVariableArrangement( std::vector<UInt_t>* const m ) const;
120 
121  void SetDoNotBoost () const { fDoNotBoost = kTRUE; }
122  static void ClearDynamicVariables() {}
123 
124  void CopyVarValues( const Event& other );
125  using TObject::Print;
126  void Print ( std::ostream & o ) const;
127 
128  static void SetIsTraining(Bool_t);
130 
131  private:
132 
133  static Bool_t fgIsTraining; // mark if we are in an actual training or "evaluation/testing" phase --> ignoreNegWeights only in actual training !
135 
136 
137  mutable std::vector<Float_t> fValues; // the event values ; mutable, to be able to copy the dynamic values in there
138 
139  mutable std::vector<Float_t> fValuesRearranged; // the event values ; mutable, to be able to copy the dynamic values in there
140  mutable std::vector<Float_t*> *fValuesDynamic; //! the event values
141  std::vector<Float_t> fTargets; // target values for regression
142  mutable std::vector<Float_t> fSpectators; // "visisting" variables not used in MVAs ; mutable, to be able to copy the dynamic values in there
143  mutable std::vector<UInt_t> fVariableArrangement; // needed for MethodCategories, where we can train on other than the main variables
144 
145  UInt_t fClass; // class number
146  Double_t fWeight; // event weight (product of global and individual weights)
147  mutable Double_t fBoostWeight; // internal weight to be set by boosting algorithm
148  Bool_t fDynamic; // is set when the dynamic values are taken
149  mutable Bool_t fDoNotBoost; // mark event as not to be boosted (used to compensate for events with negative event weights
150  public:
151 
152  ClassDef(Event,1);
153 
154  };
155 }
156 
157 #endif
Bool_t fDoNotBoost
Definition: Event.h:149
void SetClass(UInt_t t)
Definition: Event.h:115
UInt_t fClass
Definition: Event.h:145
float Float_t
Definition: RtypesCore.h:53
void SetVariableArrangement(std::vector< UInt_t > *const m) const
set the variable arrangement
Definition: Event.cxx:188
UInt_t GetNTargets() const
accessor to the number of targets
Definition: Event.cxx:316
Float_t GetSpectator(UInt_t ivar) const
return spectator content
Definition: Event.cxx:258
std::vector< Float_t > fValues
Definition: Event.h:137
Double_t GetBoostWeight() const
Definition: Event.h:88
std::vector< Float_t * > * fValuesDynamic
Definition: Event.h:140
static void ClearDynamicVariables()
Definition: Event.h:122
std::vector< Float_t > fSpectators
Definition: Event.h:142
void SetBoostWeight(Double_t w) const
Definition: Event.h:113
UInt_t GetNSpectators() const
accessor to the number of spectators
Definition: Event.cxx:324
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
static Bool_t fgIgnoreNegWeightsInTraining
Definition: Event.h:134
Double_t fBoostWeight
Definition: Event.h:147
Event()
copy constructor
Definition: Event.cxx:45
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not...
Definition: Event.cxx:378
Float_t GetValue(UInt_t ivar) const
return value of i&#39;th variable
Definition: Event.cxx:233
static void SetIsTraining(Bool_t)
when this static function is called, it sets the flag whether events with negative event weight shoul...
Definition: Event.cxx:388
#define ClassDef(name, id)
Definition: Rtypes.h:254
Bool_t IsDynamic() const
Definition: Event.h:83
void ScaleBoostWeight(Double_t s) const
Definition: Event.h:114
Double_t fWeight
Definition: Event.h:146
void SetVal(UInt_t ivar, Float_t val)
set variable ivar to val
Definition: Event.cxx:337
const std::vector< Float_t > & GetSpectators() const
Definition: Event.h:110
Double_t GetOriginalWeight() const
Definition: Event.h:87
std::vector< UInt_t > fVariableArrangement
Definition: Event.h:143
std::vector< Float_t > & GetTargets()
Definition: Event.h:105
UInt_t GetNVariables() const
accessor to the number of variables
Definition: Event.cxx:305
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Definition: TObject.cxx:595
A specialized string object used for TTree selections.
Definition: TCut.h:27
Bool_t fDynamic
Definition: Event.h:148
std::vector< Float_t > fTargets
the event values
Definition: Event.h:141
void SetSpectator(UInt_t ivar, Float_t value)
set spectator value (dimension ivar) to value
Definition: Event.cxx:365
static Bool_t fgIsTraining
Definition: Event.h:133
std::vector< Float_t > & GetSpectators()
Definition: Event.h:109
unsigned int UInt_t
Definition: RtypesCore.h:42
TMarker * m
Definition: textangle.C:8
void SetTarget(UInt_t itgt, Float_t value)
set the target value (dimension itgt) to value
Definition: Event.cxx:356
void SetDoNotBoost() const
Definition: Event.h:121
std::ostream & operator<<(std::ostream &os, const BinaryTree &tree)
print the tree recursinvely using the << operator
Definition: BinaryTree.cxx:159
void Print(std::ostream &o) const
print method
Definition: Event.cxx:348
static void SetIgnoreNegWeightsInTraining(Bool_t)
when this static function is called, it sets the flag whether events with negative event weight shoul...
Definition: Event.cxx:397
double Double_t
Definition: RtypesCore.h:55
void CopyVarValues(const Event &other)
copies only the variable values
Definition: Event.cxx:200
std::vector< Float_t > fValuesRearranged
Definition: Event.h:139
void SetWeight(Double_t w)
Definition: Event.h:112
UInt_t GetClass() const
Definition: Event.h:89
friend std::ostream & operator<<(std::ostream &os, const Event &event)
Mother of all ROOT objects.
Definition: TObject.h:44
Float_t GetTarget(UInt_t itgt) const
Definition: Event.h:104
~Event()
Event destructor.
Definition: Event.cxx:181
Abstract ClassifierFactory template that handles arbitrary types.
std::vector< Float_t > & GetValues()
Definition: Event.h:96
const std::vector< Float_t > & GetTargets() const
Definition: Event.h:106
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:202
const Bool_t kTRUE
Definition: Rtypes.h:91