Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:59

0001 // @(#)root/tmva $Id$
0002 // Author: Andreas Hoecker, Peter Speckmayer, Joerg Stelzer, Helge Voss, Jan Therhaag
0003 
0004 /**********************************************************************************
0005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
0006  * Package: TMVA                                                                  *
0007  * Class  : Event                                                                 *
0008  *                                             *
0009  *                                                                                *
0010  * Description:                                                                   *
0011  *      Event container                                                           *
0012  *                                                                                *
0013  * Authors (alphabetical):                                                        *
0014  *      Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland              *
0015  *      Joerg Stelzer   <Joerg.Stelzer@cern.ch>  - CERN, Switzerland              *
0016  *      Peter Speckmayer <Peter.Speckmayer@cern.ch>  - CERN, Switzerland          *
0017  *      Jan Therhaag       <Jan.Therhaag@cern.ch>     - U of Bonn, Germany        *
0018  *      Helge Voss      <Helge.Voss@cern.ch>     - MPI-K Heidelberg, Germany      *
0019  *                                                                                *
0020  * Copyright (c) 2005-2011:                                                       *
0021  *      CERN, Switzerland                                                         *
0022  *      U. of Victoria, Canada                                                    *
0023  *      MPI-K Heidelberg, Germany                                                 *
0024  *      U. of Bonn, Germany                                                       *
0025  *                                                                                *
0026  * Redistribution and use in source and binary forms, with or without             *
0027  * modification, are permitted according to the terms listed in LICENSE           *
0028  * (http://mva.sourceforge.net/license.txt)                                       *
0029  **********************************************************************************/
0030 
0031 #ifndef ROOT_TMVA_Event
0032 #define ROOT_TMVA_Event
0033 
0034 #include <iosfwd>
0035 #include <vector>
0036 
0037 #include "Rtypes.h"
0038 #include "TMVA/Types.h"
0039 
0040 #include "TObject.h"
0041 
0042 
0043 class TCut;
0044 
0045 namespace TMVA {
0046 
0047    class Event;
0048 
0049    std::ostream& operator<<( std::ostream& os, const Event& event );
0050 
0051    class Event:public TObject {
0052 
0053       friend std::ostream& operator<<( std::ostream& os, const Event& event );
0054 
0055    public:
0056 
0057       // constructors
0058       Event();
0059       Event( const Event& );
0060       explicit Event( const std::vector<Float_t>& values,
0061                       const std::vector<Float_t>& targetValues,
0062                       const std::vector<Float_t>& spectatorValues,
0063                       UInt_t theClass = 0, Double_t weight = 1.0, Double_t boostweight = 1.0 );
0064       explicit Event( const std::vector<Float_t>& values,
0065                       const std::vector<Float_t>& targetValues,
0066                       UInt_t theClass = 0, Double_t weight = 1.0, Double_t boostweight = 1.0 );
0067       explicit Event( const std::vector<Float_t>&,
0068                       UInt_t theClass, Double_t weight = 1.0, Double_t boostweight = 1.0 );
0069       explicit Event( const std::vector<Float_t*>*&, UInt_t nvar );
0070 
0071       ~Event();
0072 
0073       // operators
0074       // NOTE: Because we do not want to change the behaviour of the Event class
0075       // as a public interface, we use the explicit default assignment operator,
0076       // which is similar to the implicit one but silences gcc9 warnings.
0077       Event& operator=( const Event& ) = default;
0078 
0079       // accessors
0080       Bool_t  IsDynamic()         const {return fDynamic; }
0081 
0082       //      Double_t GetWeight()         const { return fWeight*fBoostWeight; }
0083       Double_t GetWeight()         const;
0084       Double_t GetOriginalWeight() const { return fWeight; }
0085       Double_t GetBoostWeight()    const { return TMath::Max(Double_t(0.0001),fBoostWeight); }
0086       UInt_t   GetClass()          const { return fClass; }
0087 
0088       UInt_t   GetNVariables()        const;
0089       UInt_t   GetNTargets()          const;
0090       UInt_t   GetNSpectators()       const;
0091 
0092       Float_t  GetValue( UInt_t ivar) const;
0093       Float_t  GetValueFast(UInt_t ivar) const { return fDynamic ? *(*fValuesDynamic)[ivar] : fValues[ivar]; }
0094       std::vector<Float_t>& GetValues()
0095          {
0096             //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.
0097             // http://stackoverflow.com/questions/123758/how-do-i-remove-code-duplication-between-similar-const-and-non-const-member-func
0098             return const_cast<std::vector<Float_t>&>( static_cast<const Event&>(*this).GetValues() );
0099          }
0100       const std::vector<Float_t>& GetValues() const;
0101 
0102       Float_t  GetTarget( UInt_t itgt ) const { return fTargets.at(itgt); }
0103       std::vector<Float_t>& GetTargets()  { return fTargets; }
0104       const std::vector<Float_t>& GetTargets() const { return fTargets; }
0105 
0106       Float_t  GetSpectator( UInt_t ivar) const;
0107       std::vector<Float_t>& GetSpectators()  { return fSpectators; }
0108       const std::vector<Float_t>& GetSpectators() const { return fSpectators; }
0109 
0110       void     SetWeight             ( Double_t w ) { fWeight=w; }
0111       void     SetBoostWeight        ( Double_t w ) const { fDoNotBoost ? fDoNotBoost = kFALSE : fBoostWeight=w; }
0112       void     ScaleBoostWeight      ( Double_t s ) const { fDoNotBoost ? fDoNotBoost = kFALSE : fBoostWeight *= s; }
0113       void     SetClass              ( UInt_t t )  { fClass=t; }
0114       void     SetVal                ( UInt_t ivar, Float_t val );
0115       void     SetTarget             ( UInt_t itgt, Float_t value );
0116       void     SetSpectator          ( UInt_t ivar, Float_t value );
0117       void     SetVariableArrangement( std::vector<UInt_t>* const m ) const;
0118 
0119       void SetSpectatorTypes(const std::vector<char> &types) { fSpectatorTypes = types; }
0120 
0121       void     SetDoNotBoost         () const  { fDoNotBoost = kTRUE; }
0122       static void ClearDynamicVariables() {}
0123 
0124       void     CopyVarValues( const Event& other );
0125       using TObject::Print;
0126       void     Print        ( std::ostream & o ) const;
0127 
0128       static   void SetIsTraining(Bool_t);
0129       static   void SetIgnoreNegWeightsInTraining(Bool_t);
0130 
0131    private:
0132 
0133       static   Bool_t          fgIsTraining;    // mark if we are in an actual training or "evaluation/testing" phase --> ignoreNegWeights only in actual training !
0134       static   Bool_t          fgIgnoreNegWeightsInTraining;
0135 
0136 
0137       mutable std::vector<Float_t>   fValues;              ///< the event values ; mutable, to be able to copy the dynamic values in there
0138 
0139       mutable std::vector<Float_t>   fValuesRearranged;    ///< the event values ; mutable, to be able to copy the dynamic values in there
0140       mutable std::vector<Float_t*> *fValuesDynamic;       ///<! the event values
0141       std::vector<Float_t>           fTargets;             ///< target values for regression
0142       mutable std::vector<Float_t>   fSpectators;          ///< "visiting" variables not used in MVAs ; mutable, to be able to copy the dynamic values in there
0143       mutable std::vector<UInt_t>    fVariableArrangement; ///< needed for MethodCategories, where we can train on other than the main variables
0144       std::vector<char>              fSpectatorTypes;      ///< type of the spectator variable (typically F or I). Used ony for dynamic events
0145 
0146       UInt_t                         fClass;               ///< class number
0147       Double_t                       fWeight;              ///< event weight (product of global and individual weights)
0148       mutable Double_t               fBoostWeight;         ///< internal weight to be set by boosting algorithm
0149       Bool_t                         fDynamic;             ///< is set when the dynamic values are taken
0150       mutable Bool_t                 fDoNotBoost;          ///< mark event as not to be boosted (used to compensate for events with negative event weights
0151    public:
0152 
0153        ClassDef(Event,1);
0154 
0155    };
0156 }
0157 
0158 #endif