00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "TMVA/Event.h"
00031 #include "TMVA/Tools.h"
00032 #include <iostream>
00033 #include "assert.h"
00034 #include <iomanip>
00035 #include <cassert>
00036 #include "TCut.h"
00037
00038
00039 TMVA::Event::Event()
00040 : fValues(),
00041 fValuesDynamic(0),
00042 fTargets(),
00043 fSpectators(),
00044 fVariableArrangement(0),
00045 fClass(0),
00046 fWeight(1.0),
00047 fBoostWeight(1.0),
00048 fDynamic(kFALSE)
00049 {
00050
00051 }
00052
00053
00054 TMVA::Event::Event( const std::vector<Float_t>& ev,
00055 const std::vector<Float_t>& tg,
00056 UInt_t cls,
00057 Double_t weight,
00058 Double_t boostweight )
00059 : fValues(ev),
00060 fValuesDynamic(0),
00061 fTargets(tg),
00062 fSpectators(0),
00063 fVariableArrangement(0),
00064 fClass(cls),
00065 fWeight(weight),
00066 fBoostWeight(boostweight),
00067 fDynamic(kFALSE)
00068 {
00069
00070 }
00071
00072
00073 TMVA::Event::Event( const std::vector<Float_t>& ev,
00074 const std::vector<Float_t>& tg,
00075 const std::vector<Float_t>& vi,
00076 UInt_t cls,
00077 Double_t weight,
00078 Double_t boostweight )
00079 : fValues(ev),
00080 fValuesDynamic(0),
00081 fTargets(tg),
00082 fSpectators(vi),
00083 fVariableArrangement(0),
00084 fClass(cls),
00085 fWeight(weight),
00086 fBoostWeight(boostweight),
00087 fDynamic(kFALSE)
00088 {
00089
00090 }
00091
00092
00093 TMVA::Event::Event( const std::vector<Float_t>& ev,
00094 UInt_t cls,
00095 Double_t weight,
00096 Double_t boostweight )
00097 : fValues(ev),
00098 fValuesDynamic(0),
00099 fTargets(0),
00100 fSpectators(0),
00101 fVariableArrangement(0),
00102 fClass(cls),
00103 fWeight(weight),
00104 fBoostWeight(boostweight),
00105 fDynamic(kFALSE)
00106 {
00107
00108 }
00109
00110
00111 TMVA::Event::Event( const std::vector<Float_t*>*& evdyn, UInt_t nvar )
00112 : fValues(nvar),
00113 fValuesDynamic(0),
00114 fTargets(0),
00115 fSpectators(evdyn->size()-nvar),
00116 fVariableArrangement(0),
00117 fClass(0),
00118 fWeight(0),
00119 fBoostWeight(0),
00120 fDynamic(true)
00121 {
00122
00123
00124
00125 fValuesDynamic = (std::vector<Float_t*>*) evdyn;
00126 }
00127
00128
00129 TMVA::Event::Event( const Event& event )
00130 : fValues(event.fValues),
00131 fValuesDynamic(0),
00132 fTargets(event.fTargets),
00133 fSpectators(event.fSpectators),
00134 fVariableArrangement(event.fVariableArrangement),
00135 fClass(event.fClass),
00136 fWeight(event.fWeight),
00137 fBoostWeight(event.fBoostWeight),
00138 fDynamic(event.fDynamic)
00139 {
00140
00141 }
00142
00143
00144 TMVA::Event::~Event()
00145 {
00146
00147 }
00148
00149
00150 void TMVA::Event::ClearDynamicVariables()
00151 {
00152
00153
00154
00155
00156
00157
00158 }
00159
00160
00161 void TMVA::Event::SetVariableArrangement( std::vector<UInt_t>* const m ) const {
00162
00163
00164
00165
00166
00167 fVariableArrangement = m;
00168 }
00169
00170
00171
00172
00173 void TMVA::Event::CopyVarValues( const Event& other )
00174 {
00175
00176 fValues = other.fValues;
00177 fClass = other.fClass;
00178 fWeight = other.fWeight;
00179 fBoostWeight = other.fBoostWeight;
00180 }
00181
00182
00183 Float_t TMVA::Event::GetValue( UInt_t ivar ) const
00184 {
00185
00186 Float_t retval;
00187 if (fVariableArrangement==0) {
00188
00189
00190 retval = fDynamic ?( *(*fValuesDynamic)[ivar] ) : fValues[ivar];
00191 }
00192 else {
00193 UInt_t mapIdx = (*fVariableArrangement)[ivar];
00194 if (fDynamic) {
00195 retval = *(*fValuesDynamic)[mapIdx];
00196 }
00197 else {
00198 retval = ( mapIdx<fValues.size() ) ? fValues[mapIdx] : fSpectators[mapIdx-fValues.size()];
00199 }
00200 }
00201 return retval;
00202 }
00203
00204
00205 Float_t TMVA::Event::GetSpectator( UInt_t ivar) const
00206 {
00207
00208 if (fDynamic) return *(fValuesDynamic->at(GetNVariables()+ivar));
00209 else return fSpectators.at(ivar);
00210 }
00211
00212
00213 const std::vector<Float_t>& TMVA::Event::GetValues() const
00214 {
00215
00216 if (fVariableArrangement!=0) {
00217 assert(0);
00218 }
00219 if (fDynamic) {
00220
00221
00222
00223
00224 fValues.clear();
00225 for (std::vector<Float_t*>::const_iterator it = fValuesDynamic->begin();
00226 it != fValuesDynamic->end()-GetNSpectators(); it++) {
00227 Float_t val = *(*it);
00228 fValues.push_back( val );
00229 }
00230 }
00231 return fValues;
00232 }
00233
00234
00235 UInt_t TMVA::Event::GetNVariables() const
00236 {
00237
00238
00239
00240
00241
00242 if (fVariableArrangement==0) return fValues.size();
00243 else return fVariableArrangement->size();
00244 }
00245
00246
00247 UInt_t TMVA::Event::GetNTargets() const
00248 {
00249
00250 return fTargets.size();
00251 }
00252
00253
00254 UInt_t TMVA::Event::GetNSpectators() const
00255 {
00256
00257
00258
00259
00260
00261 if (fVariableArrangement==0) return fSpectators.size();
00262 else return fValues.size()-fVariableArrangement->size();
00263 }
00264
00265
00266
00267 void TMVA::Event::SetVal( UInt_t ivar, Float_t val )
00268 {
00269
00270 if ((fDynamic ?( (*fValuesDynamic).size() ) : fValues.size())<=ivar)
00271 (fDynamic ?( (*fValuesDynamic).resize(ivar+1) ) : fValues.resize(ivar+1));
00272
00273 (fDynamic ?( *(*fValuesDynamic)[ivar] ) : fValues[ivar])=val;
00274 }
00275
00276
00277 void TMVA::Event::Print( std::ostream& o ) const
00278 {
00279
00280 o << *this << std::endl;
00281 }
00282
00283
00284 void TMVA::Event::SetTarget( UInt_t itgt, Float_t value )
00285 {
00286
00287
00288 if (fTargets.size() <= itgt) fTargets.resize( itgt+1 );
00289 fTargets.at(itgt) = value;
00290 }
00291
00292
00293 void TMVA::Event::SetSpectator( UInt_t ivar, Float_t value )
00294 {
00295
00296
00297 if (fSpectators.size() <= ivar) fSpectators.resize( ivar+1 );
00298 fSpectators.at(ivar) = value;
00299 }
00300
00301
00302 ostream& TMVA::operator << ( ostream& os, const TMVA::Event& event )
00303 {
00304
00305 os << "Variables [" << event.fValues.size() << "]:";
00306 for (UInt_t ivar=0; ivar<event.fValues.size(); ++ivar)
00307 os << " " << std::setw(10) << event.GetValue(ivar);
00308 os << ", targets [" << event.fTargets.size() << "]:";
00309 for (UInt_t ivar=0; ivar<event.fTargets.size(); ++ivar)
00310 os << " " << std::setw(10) << event.GetTarget(ivar);
00311 os << ", spectators ["<< event.fSpectators.size() << "]:";
00312 for (UInt_t ivar=0; ivar<event.fSpectators.size(); ++ivar)
00313 os << " " << std::setw(10) << event.GetSpectator(ivar);
00314 os << ", weight: " << event.GetWeight();
00315 os << ", class: " << event.GetClass();
00316 return os;
00317 }