ROOT logo
// @(#)root/tmva $Id: Event.cxx 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:                                                                   *
 *      Implementation (see header for description)                               *
 *                                                                                *
 * 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)                                       *
 **********************************************************************************/

#include "TMVA/Event.h"
#include "TMVA/Tools.h"
#include <iostream>
#include <iomanip>
 
Int_t TMVA::Event::fgCount = 0;
std::vector<Float_t*>* TMVA::Event::fgValuesDynamic = 0;

//____________________________________________________________
TMVA::Event::Event() 
   : fValues(),
     fTargets(),
     fSpectators(),
     fClass(1),
     fWeight(1.0),
     fBoostWeight(1.0),
     fDynamic(kFALSE),
     fSignalClass( 100 ) // TODO: remove this.. see "IsSignal"
{
   // copy constructor
   fgCount++; 
}

//____________________________________________________________
TMVA::Event::Event( const std::vector<Float_t>& ev,
                    const std::vector<Float_t>& tg,
                    UInt_t cls,
                    Float_t weight,
                    Float_t boostweight )
   : fValues(ev),
     fTargets(tg),
     fSpectators(0),
     fClass(cls),
     fWeight(weight),
     fBoostWeight(boostweight),
     fDynamic(kFALSE),
     fSignalClass( 100 ) // TODO: remove this.. see "IsSignal"
{
   // constructor
   fgCount++;
}

//____________________________________________________________
TMVA::Event::Event( const std::vector<Float_t>& ev,
                    const std::vector<Float_t>& tg,
                    const std::vector<Float_t>& vi,
                    UInt_t cls,
                    Float_t weight,
                    Float_t boostweight )
   : fValues(ev),
     fTargets(tg),
     fSpectators(vi),
     fClass(cls),
     fWeight(weight),
     fBoostWeight(boostweight),
     fDynamic(kFALSE),
     fSignalClass( 100 ) // TODO: remove this.. see "IsSignal"
{
   // constructor
   fgCount++;
}

//____________________________________________________________
TMVA::Event::Event( const std::vector<Float_t>& ev,
                    UInt_t cls,
                    Float_t weight,
                    Float_t boostweight )
   : fValues(ev),
     fTargets(0),
     fSpectators(0),
     fClass(cls),
     fWeight(weight),
     fBoostWeight(boostweight),
     fDynamic(kFALSE),
     fSignalClass( 100 ) // TODO: remove this.. see "IsSignal"
{
   // constructor
   fgCount++;
}

//____________________________________________________________
TMVA::Event::Event( const std::vector<Float_t*>*& evdyn )
   : fValues(evdyn->size()),
     fTargets(0),
     fSpectators(0),
     fClass(0),
     fWeight(0),
     fBoostWeight(0),
     fDynamic(true),
     fSignalClass( 100 ) // TODO: remove this.. see "IsSignal" ... !!!!!! NOT CLEAR TO ME WHAT VALUE TO SET HERE...
{

   fgValuesDynamic = (std::vector<Float_t*>*) evdyn;
   // constructor for single events
   fgCount++;
}

//____________________________________________________________
TMVA::Event::Event( const Event& event ) 
   : fValues(event.fValues),
     fTargets(event.fTargets),
     fSpectators(event.fSpectators),
     fClass(event.fClass),
     fWeight(event.fWeight),
     fBoostWeight(event.fBoostWeight),
     fDynamic(event.fDynamic),
     fSignalClass( event.fSignalClass ) // TODO: remove this.. see "IsSignal"
{
   // copy constructor
   fgCount++; 
}

//____________________________________________________________
TMVA::Event::~Event() 
{
   // Event destructor
   fgCount--;;
   if (fDynamic && fgCount==0) TMVA::Event::ClearDynamicVariables();
}
 
//____________________________________________________________
void TMVA::Event::ClearDynamicVariables() 
{ 
   // clear global variable
   if (fgValuesDynamic != 0) { 
      fgValuesDynamic->clear();
      delete fgValuesDynamic;
      fgValuesDynamic = 0;
   }
} 

//____________________________________________________________
void TMVA::Event::CopyVarValues( const Event& other )
{
   // copies only the variable values
   fValues      = other.fValues;
   fClass       = other.fClass;
   fWeight      = other.fWeight;
   fBoostWeight = other.fBoostWeight;
   fSignalClass = other.fSignalClass;      // TODO: remove this.. see "IsSignal"
}

//____________________________________________________________
Float_t TMVA::Event::GetVal( UInt_t ivar ) const 
{ 
   // return value of i'th variable
   return ( fDynamic ?( *(*fgValuesDynamic)[ivar] ) : fValues[ivar] ); 
}

//____________________________________________________________
const std::vector<Float_t>& TMVA::Event::GetValues() const 
{  
   // return va;lue vector
   if (fDynamic) {
      fValues.clear();
      for (std::vector<Float_t*>::const_iterator it = fgValuesDynamic->begin(); 
           it != fgValuesDynamic->end(); it++) { 
         Float_t val = *(*it); 
         fValues.push_back( val ); 
      }
   }
   return fValues;
}

//____________________________________________________________
void TMVA::Event::SetVal( UInt_t ivar, Float_t val ) 
{
   // set variable ivar to val
   if ((fDynamic ?( (*fgValuesDynamic).size() ) : fValues.size())<=ivar)
      (fDynamic ?( (*fgValuesDynamic).resize(ivar+1) ) : fValues.resize(ivar+1));
   (fDynamic ?( *(*fgValuesDynamic)[ivar] ) : fValues[ivar])=val;
}

//____________________________________________________________
void TMVA::Event::Print( std::ostream& o ) const
{
   // print method
   if (!fDynamic) {
      o << fValues.size() << " variables: ";
      for (UInt_t ivar=0; ivar<fValues.size(); ivar++)
         o << " " << std::setw(10) << GetValue(ivar);
      o << ", weight = " << GetWeight();
      o << std::setw(10) << "class: " << std::setw(10) << GetClass() << " , ";
      o << fTargets.size() << " targets: ";
      for (UInt_t ivar=0; ivar<fTargets.size(); ivar++)
         o << " " << std::setw(10) << GetTarget(ivar);
      o << fSpectators.size() << " spectators: ";
      for (UInt_t ivar=0; ivar<fSpectators.size(); ivar++)
         o << " " << std::setw(10) << GetSpectator(ivar);
      o << std::endl;
   }
   else {
      o << "|dynamic variables|" << std::endl;
   }
}

//_______________________________________________________________________
ostream& TMVA::operator << ( ostream& os, const TMVA::Event& event )
{ 
   // Outputs the data of an event
   
   event.Print(os);
   return os;
}

//_______________________________________________________________________
ostream& TMVA::operator << ( ostream& os, const TMVA::Event* event )
{
   // Outputs the data of an event
   return os << *event;
}
 Event.cxx:1
 Event.cxx:2
 Event.cxx:3
 Event.cxx:4
 Event.cxx:5
 Event.cxx:6
 Event.cxx:7
 Event.cxx:8
 Event.cxx:9
 Event.cxx:10
 Event.cxx:11
 Event.cxx:12
 Event.cxx:13
 Event.cxx:14
 Event.cxx:15
 Event.cxx:16
 Event.cxx:17
 Event.cxx:18
 Event.cxx:19
 Event.cxx:20
 Event.cxx:21
 Event.cxx:22
 Event.cxx:23
 Event.cxx:24
 Event.cxx:25
 Event.cxx:26
 Event.cxx:27
 Event.cxx:28
 Event.cxx:29
 Event.cxx:30
 Event.cxx:31
 Event.cxx:32
 Event.cxx:33
 Event.cxx:34
 Event.cxx:35
 Event.cxx:36
 Event.cxx:37
 Event.cxx:38
 Event.cxx:39
 Event.cxx:40
 Event.cxx:41
 Event.cxx:42
 Event.cxx:43
 Event.cxx:44
 Event.cxx:45
 Event.cxx:46
 Event.cxx:47
 Event.cxx:48
 Event.cxx:49
 Event.cxx:50
 Event.cxx:51
 Event.cxx:52
 Event.cxx:53
 Event.cxx:54
 Event.cxx:55
 Event.cxx:56
 Event.cxx:57
 Event.cxx:58
 Event.cxx:59
 Event.cxx:60
 Event.cxx:61
 Event.cxx:62
 Event.cxx:63
 Event.cxx:64
 Event.cxx:65
 Event.cxx:66
 Event.cxx:67
 Event.cxx:68
 Event.cxx:69
 Event.cxx:70
 Event.cxx:71
 Event.cxx:72
 Event.cxx:73
 Event.cxx:74
 Event.cxx:75
 Event.cxx:76
 Event.cxx:77
 Event.cxx:78
 Event.cxx:79
 Event.cxx:80
 Event.cxx:81
 Event.cxx:82
 Event.cxx:83
 Event.cxx:84
 Event.cxx:85
 Event.cxx:86
 Event.cxx:87
 Event.cxx:88
 Event.cxx:89
 Event.cxx:90
 Event.cxx:91
 Event.cxx:92
 Event.cxx:93
 Event.cxx:94
 Event.cxx:95
 Event.cxx:96
 Event.cxx:97
 Event.cxx:98
 Event.cxx:99
 Event.cxx:100
 Event.cxx:101
 Event.cxx:102
 Event.cxx:103
 Event.cxx:104
 Event.cxx:105
 Event.cxx:106
 Event.cxx:107
 Event.cxx:108
 Event.cxx:109
 Event.cxx:110
 Event.cxx:111
 Event.cxx:112
 Event.cxx:113
 Event.cxx:114
 Event.cxx:115
 Event.cxx:116
 Event.cxx:117
 Event.cxx:118
 Event.cxx:119
 Event.cxx:120
 Event.cxx:121
 Event.cxx:122
 Event.cxx:123
 Event.cxx:124
 Event.cxx:125
 Event.cxx:126
 Event.cxx:127
 Event.cxx:128
 Event.cxx:129
 Event.cxx:130
 Event.cxx:131
 Event.cxx:132
 Event.cxx:133
 Event.cxx:134
 Event.cxx:135
 Event.cxx:136
 Event.cxx:137
 Event.cxx:138
 Event.cxx:139
 Event.cxx:140
 Event.cxx:141
 Event.cxx:142
 Event.cxx:143
 Event.cxx:144
 Event.cxx:145
 Event.cxx:146
 Event.cxx:147
 Event.cxx:148
 Event.cxx:149
 Event.cxx:150
 Event.cxx:151
 Event.cxx:152
 Event.cxx:153
 Event.cxx:154
 Event.cxx:155
 Event.cxx:156
 Event.cxx:157
 Event.cxx:158
 Event.cxx:159
 Event.cxx:160
 Event.cxx:161
 Event.cxx:162
 Event.cxx:163
 Event.cxx:164
 Event.cxx:165
 Event.cxx:166
 Event.cxx:167
 Event.cxx:168
 Event.cxx:169
 Event.cxx:170
 Event.cxx:171
 Event.cxx:172
 Event.cxx:173
 Event.cxx:174
 Event.cxx:175
 Event.cxx:176
 Event.cxx:177
 Event.cxx:178
 Event.cxx:179
 Event.cxx:180
 Event.cxx:181
 Event.cxx:182
 Event.cxx:183
 Event.cxx:184
 Event.cxx:185
 Event.cxx:186
 Event.cxx:187
 Event.cxx:188
 Event.cxx:189
 Event.cxx:190
 Event.cxx:191
 Event.cxx:192
 Event.cxx:193
 Event.cxx:194
 Event.cxx:195
 Event.cxx:196
 Event.cxx:197
 Event.cxx:198
 Event.cxx:199
 Event.cxx:200
 Event.cxx:201
 Event.cxx:202
 Event.cxx:203
 Event.cxx:204
 Event.cxx:205
 Event.cxx:206
 Event.cxx:207
 Event.cxx:208
 Event.cxx:209
 Event.cxx:210
 Event.cxx:211
 Event.cxx:212
 Event.cxx:213
 Event.cxx:214
 Event.cxx:215
 Event.cxx:216
 Event.cxx:217
 Event.cxx:218
 Event.cxx:219
 Event.cxx:220
 Event.cxx:221
 Event.cxx:222
 Event.cxx:223
 Event.cxx:224
 Event.cxx:225
 Event.cxx:226
 Event.cxx:227
 Event.cxx:228
 Event.cxx:229
 Event.cxx:230
 Event.cxx:231
 Event.cxx:232
 Event.cxx:233
 Event.cxx:234
 Event.cxx:235
 Event.cxx:236
 Event.cxx:237
 Event.cxx:238
 Event.cxx:239