#ifndef ROOT_TMVA_Tools
#define ROOT_TMVA_Tools
#include <vector>
#include <sstream>
#include <iostream>
#include <iomanip>
#if __cplusplus > 199711L
#include <atomic>
#endif
#ifndef ROOT_TXMLEngine
#include "TXMLEngine.h"
#endif
#ifndef ROOT_TMatrixDSymfwd
#include "TMatrixDSymfwd.h"
#endif
#ifndef ROOT_TMatrixDfwd
#include "TMatrixDfwd.h"
#endif
#ifndef ROOT_TVectorDfwd
#include "TVectorDfwd.h"
#endif
#ifndef ROOT_TVectorDfwd
#include "TVectorDfwd.h"
#endif
#ifndef ROOT_TMVA_Types
#include "TMVA/Types.h"
#endif
#ifndef ROOT_TMVA_VariableTransformBase
#include "TMVA/VariableTransformBase.h"
#endif
class TList;
class TTree;
class TString;
class TH1;
class TH2;
class TH2F;
class TSpline;
class TXMLEngine;
namespace TMVA {
class Event;
class PDF;
class MsgLogger;
class Tools {
private:
Tools();
public:
~Tools();
static Tools& Instance();
static void DestroyInstance();
template <typename T> Double_t Mean(Long64_t n, const T *a, const Double_t *w=0);
template <typename Iterator, typename WeightIterator> Double_t Mean ( Iterator first, Iterator last, WeightIterator w);
template <typename T> Double_t RMS(Long64_t n, const T *a, const Double_t *w=0);
template <typename Iterator, typename WeightIterator> Double_t RMS(Iterator first, Iterator last, WeightIterator w);
void ComputeStat( const std::vector<TMVA::Event*>&,
std::vector<Float_t>*,
Double_t&, Double_t&, Double_t&,
Double_t&, Double_t&, Double_t&, Int_t signalClass,
Bool_t norm = kFALSE );
inline Double_t ComputeVariance( Double_t sumx2, Double_t sumx, Int_t nx );
TH1* projNormTH1F( TTree* theTree, const TString& theVarName,
const TString& name, Int_t nbins,
Double_t xmin, Double_t xmax, const TString& cut );
Double_t NormHist( TH1* theHist, Double_t norm = 1.0 );
TList* ParseFormatLine( TString theString, const char * sep = ":" );
std::vector<Int_t>* ParseANNOptionString( TString theOptions, Int_t nvar,
std::vector<Int_t>* nodes );
TMatrixD* GetSQRootMatrix( TMatrixDSym* symMat );
std::vector<TMatrixDSym*>* CalcCovarianceMatrices( const std::vector<Event*>& events, Int_t maxCls, VariableTransformBase* transformBase=0 );
std::vector<TMatrixDSym*>* CalcCovarianceMatrices( const std::vector<const Event*>& events, Int_t maxCls, VariableTransformBase* transformBase=0 );
const TMatrixD* GetCorrelationMatrix( const TMatrixD* covMat );
Bool_t CheckSplines( const TH1*, const TSpline* );
Double_t NormVariable( Double_t x, Double_t xmin, Double_t xmax );
Double_t GetSeparation( TH1* S, TH1* B ) const;
Double_t GetSeparation( const PDF& pdfS, const PDF& pdfB ) const;
std::vector<Double_t> MVADiff( std::vector<Double_t>&, std::vector<Double_t>& );
void Scale( std::vector<Double_t>&, Double_t );
void Scale( std::vector<Float_t>&, Float_t );
void UsefulSortDescending( std::vector< std::vector<Double_t> >&, std::vector<TString>* vs = 0 );
void UsefulSortAscending ( std::vector< std::vector<Double_t> >&, std::vector<TString>* vs = 0 );
void UsefulSortDescending( std::vector<Double_t>& );
void UsefulSortAscending ( std::vector<Double_t>& );
Int_t GetIndexMaxElement ( std::vector<Double_t>& );
Int_t GetIndexMinElement ( std::vector<Double_t>& );
Bool_t ContainsRegularExpression( const TString& s );
TString ReplaceRegularExpressions( const TString& s, const TString& replace = "+" );
void FormattedOutput( const std::vector<Double_t>&, const std::vector<TString>&,
const TString titleVars, const TString titleValues, MsgLogger& logger,
TString format = "%+1.3f" );
void FormattedOutput( const TMatrixD&, const std::vector<TString>&, MsgLogger& logger );
void FormattedOutput( const TMatrixD&, const std::vector<TString>& vert, const std::vector<TString>& horiz,
MsgLogger& logger );
void WriteFloatArbitraryPrecision( Float_t val, std::ostream& os );
void ReadFloatArbitraryPrecision ( Float_t& val, std::istream& is );
TString GetXTitleWithUnit( const TString& title, const TString& unit );
TString GetYTitleWithUnit( const TH1& h, const TString& unit, Bool_t normalised );
Double_t GetMutualInformation( const TH2F& );
Double_t GetCorrelationRatio( const TH2F& );
TH2F* TransposeHist ( const TH2F& );
Bool_t CheckForSilentOption ( const TString& ) const;
Bool_t CheckForVerboseOption( const TString& ) const;
const TString& Color( const TString& );
enum EWelcomeMessage { kStandardWelcomeMsg = 1,
kIsometricWelcomeMsg,
kBlockWelcomeMsg,
kLeanWelcomeMsg,
kLogoWelcomeMsg,
kSmall1WelcomeMsg,
kSmall2WelcomeMsg,
kOriginalWelcomeMsgColor,
kOriginalWelcomeMsgBW };
enum ECitation { kPlainText = 1,
kBibTeX,
kLaTeX,
kHtmlLink };
void TMVAWelcomeMessage();
void TMVAWelcomeMessage( MsgLogger& logger, EWelcomeMessage m = kStandardWelcomeMsg );
void TMVAVersionMessage( MsgLogger& logger );
void ROOTVersionMessage( MsgLogger& logger );
void TMVACitation( MsgLogger& logger, ECitation citType = kPlainText );
std::vector<TString> SplitString( const TString& theOpt, const char separator ) const;
const TString fRegexp;
mutable MsgLogger* fLogger;
MsgLogger& Log() const { return *fLogger; }
#if __cplusplus > 199711L
static std::atomic<Tools*> fgTools;
#else
static Tools* fgTools;
#endif
TString StringFromInt ( Long_t i );
TString StringFromDouble ( Double_t d );
void WriteTMatrixDToXML ( void* node, const char* name, TMatrixD* mat );
void WriteTVectorDToXML ( void* node, const char* name, TVectorD* vec );
void ReadTMatrixDFromXML( void* node, const char* name, TMatrixD* mat );
void ReadTVectorDFromXML( void* node, const char* name, TVectorD* vec );
Bool_t HistoHasEquidistantBins(const TH1& h);
Bool_t HasAttr ( void* node, const char* attrname );
template<typename T>
inline void ReadAttr ( void* node, const char* , T& value );
void ReadAttr ( void* node, const char* attrname, TString& value );
template<typename T>
void AddAttr ( void* node, const char* , const T& value, Int_t precision = 16 );
void AddAttr ( void* node, const char* attrname, const char* value );
void* AddChild ( void* parent, const char* childname, const char* content = 0, bool isRootNode = false );
Bool_t AddRawLine ( void* node, const char * raw );
Bool_t AddComment ( void* node, const char* comment );
void* GetParent( void* child);
void* GetChild ( void* parent, const char* childname=0 );
void* GetNextChild( void* prevchild, const char* childname=0 );
const char* GetContent ( void* node );
const char* GetName ( void* node );
TXMLEngine& xmlengine() { return *fXMLEngine; }
int xmlenginebuffersize() { return 10000000; }
TXMLEngine* fXMLEngine;
TH1* GetCumulativeDist( TH1* h);
private:
Double_t GetYMean_binX( const TH2& , Int_t bin_x );
};
Tools& gTools();
}
template<typename T> void TMVA::Tools::ReadAttr( void* node, const char* attrname, T& value )
{
TString val;
ReadAttr( node, attrname, val );
std::stringstream s(val.Data());
s >> value;
}
template<typename T>
void TMVA::Tools::AddAttr( void* node, const char* attrname, const T& value, Int_t precision )
{
std::stringstream s;
s.precision( precision );
s << std::scientific << value;
AddAttr( node, attrname, s.str().c_str() );
}
inline Double_t TMVA::Tools::ComputeVariance( Double_t sumx2, Double_t sumx, Int_t nx )
{
if (nx<2) return 0;
return (sumx2 - ((sumx*sumx)/static_cast<Double_t>(nx)))/static_cast<Double_t>(nx-1);
}
#endif