Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:22:49

0001 
0002 /**********************************************************************************
0003  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
0004  * Package: TMVA                                                                  *
0005  * Class  : BDTEventWrapper                                                       *
0006  *                                             *
0007  *                                                                                *
0008  * Description:                                                                   *
0009  *                                                                                *
0010  *                                                                                *
0011  * Author: Doug Schouten (dschoute@sfu.ca)                                        *
0012  *                                                                                *
0013  * Copyright (c) 2007:                                                            *
0014  *      CERN, Switzerland                                                         *
0015  *      U. of Texas at Austin, USA                                                *
0016  *                                                                                *
0017  * Redistribution and use in source and binary forms, with or without             *
0018  * modification, are permitted according to the terms listed in LICENSE           *
0019  * (see tmva/doc/LICENSE)                                          *
0020  **********************************************************************************/
0021 
0022 #ifndef ROOT_TMVA_BDTEventWrapper
0023 #define ROOT_TMVA_BDTEventWrapper
0024 
0025 #include "RtypesCore.h"
0026 #include "Event.h"
0027 #include "ThreadLocalStorage.h"
0028 
0029 namespace TMVA {
0030 
0031    class BDTEventWrapper{
0032 
0033    public:
0034 
0035       BDTEventWrapper( const Event* );
0036       ~BDTEventWrapper();
0037 
0038       // Require '<' operator to use std::sort algorithms on collection of Events
0039       Bool_t operator <( const BDTEventWrapper& other ) const;
0040 
0041       // Set the accumulated weight, for sorted signal/background events
0042       /**
0043        * @param type - true for signal, false for background
0044        * @param weight - the total weight
0045        */
0046       void SetCumulativeWeight( Bool_t type, Double_t weight );
0047 
0048       // Get the accumulated weight
0049       /**
0050        * @param type - true for signal, false for background
0051        * @return the cumulative weight for sorted signal/background events
0052        */
0053       Double_t GetCumulativeWeight( Bool_t type ) const;
0054 
0055       // Set the index of the variable to compare on
0056       /**
0057        * @param iVar - index of the variable in fEvent to use
0058        */
0059       inline static void SetVarIndex( Int_t iVar ) { if (iVar >= 0) GetVarIndex() = iVar; }
0060 
0061       // Return the value of variable fVarIndex for this event
0062       /**
0063        * @return value of variable fVarIndex for this event
0064        */
0065       inline Double_t GetVal() const { return fEvent->GetValue(GetVarIndex()); }
0066       const Event* operator*() const { return fEvent; }
0067 
0068       inline Double_t GetVal(Int_t var) const { return fEvent->GetValue(var); }
0069    private:
0070 
0071       // This is a workaround for OSx where static thread_local data members are
0072       // not supported. The C++ solution would indeed be the following:
0073       static Int_t& GetVarIndex(){TTHREAD_TLS(Int_t) fVarIndex(0); return fVarIndex;}; // index of the variable to sort on
0074 
0075       const Event* fEvent;     // pointer to the event
0076 
0077       Double_t     fBkgWeight; ///< cumulative background weight for splitting
0078       Double_t     fSigWeight; ///< same for the signal weights
0079    };
0080 }
0081 
0082 inline Bool_t TMVA::BDTEventWrapper::operator<( const BDTEventWrapper& other ) const
0083 {
0084    return GetVal() < other.GetVal();
0085 }
0086 
0087 #endif