Logo ROOT  
Reference Guide
Results.cxx
Go to the documentation of this file.
1// @(#)root/tmva $Id$
2// Author: Andreas Hoecker, Peter Speckmayer, Joerg Stelzer, Helge Voss
3
4/**********************************************************************************
5 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6 * Package: TMVA *
7 * Class : Results *
8 * Web : http://tmva.sourceforge.net *
9 * *
10 * Description: *
11 * Implementation (see header for description) *
12 * *
13 * Authors (alphabetical): *
14 * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15 * Peter Speckmayer <Peter.Speckmayer@cern.ch> - CERN, Switzerland *
16 * Joerg Stelzer <Joerg.Stelzer@cern.ch> - CERN, Switzerland *
17 * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
18 * *
19 * Copyright (c) 2006: *
20 * CERN, Switzerland *
21 * MPI-K Heidelberg, Germany *
22 * *
23 * Redistribution and use in source and binary forms, with or without *
24 * modification, are permitted according to the terms listed in LICENSE *
25 * (http://tmva.sourceforge.net/LICENSE) *
26 **********************************************************************************/
27
28/*! \class TMVA::Results
29\ingroup TMVA
30Class that is the base-class for a vector of result
31*/
32
33#include "TMVA/Results.h"
34
35#include "TMVA/MsgLogger.h"
36#include "TMVA/Types.h"
37
38#include "TGraph.h"
39#include "TH1.h"
40#include "TH2.h"
41#include "TList.h"
42
43#include <vector>
44
45namespace TMVA {
46 class DataSetInfo;
47}
48
49////////////////////////////////////////////////////////////////////////////////
50/// constructor
51
52TMVA::Results::Results( const DataSetInfo* dsi, TString resultsName )
53 : fTreeType(Types::kTraining),
54 fDsi(dsi),
55 fStorage( new TList() ),
56 fHistAlias( new std::map<TString, TObject*> ),
57 fLogger( new MsgLogger(Form("Results%s",resultsName.Data()), kINFO) )
58{
60}
61
63: fTreeType(Types::kTraining),
64fDsi(0),
65fStorage( new TList() ),
66fHistAlias( new std::map<TString, TObject*> ),
67fLogger( new MsgLogger("Results", kINFO))
68{
70}
71
72
73////////////////////////////////////////////////////////////////////////////////
74/// destructor
75
77{
78 // delete result-histograms
79 delete fStorage;
80 delete fHistAlias;
81 delete fLogger;
82}
83
84////////////////////////////////////////////////////////////////////////////////
85
86void TMVA::Results::Store( TObject* obj, const char* alias )
87{
88 TListIter l(fStorage);
89 // check if object is already in list
90 while (void* p = (void*)l()) {
91 if(p==obj)
92 *fLogger << kFATAL << "Histogram pointer " << p << " already exists in results storage" << Endl;
93 }
94
95 TString as(obj->GetName());
96 if (alias!=0) as=TString(alias);
97 if (fHistAlias->find(as) != fHistAlias->end()) {
98 // alias exists
99 *fLogger << kFATAL << "Alias " << as << " already exists in results storage" << Endl;
100 }
101 if( obj->InheritsFrom(TH1::Class()) ) {
102 ((TH1*)obj)->SetDirectory(0);
103 }
104 fStorage->Add( obj );
105 fHistAlias->insert(std::pair<TString, TObject*>(as,obj));
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// Returns a stored object if it exists. If it does not, a nullptr is returned.
110///
111
113{
114 std::map<TString, TObject*>::iterator it = fHistAlias->find(alias);
115
116 if (it != fHistAlias->end()) return it->second;
117
118 // alias does not exist
119 return nullptr;
120}
121
122////////////////////////////////////////////////////////////////////////////////
123/// Returns true if there is an object stored in the result for a given alias,
124/// false otherwise.
125///
126
128{
129 TObject* test = GetObject(alias);
130
131 return (test != nullptr);
132}
133
134////////////////////////////////////////////////////////////////////////////////
135
136TH1* TMVA::Results::GetHist(const TString & alias) const
137{
138 TH1* out=dynamic_cast<TH1*>(GetObject(alias));
139 if (!out) Log() <<kWARNING << "You have asked for histogram " << alias << " which does not seem to exist in *Results* .. better don't use it " << Endl;
140 return out;
141}
142
143////////////////////////////////////////////////////////////////////////////////
144
146{
147 TH2* out=dynamic_cast<TH2*>(GetObject(alias));
148 if (!out) Log() <<kWARNING << "You have asked for 2D histogram " << alias << " which does not seem to exist in *Results* .. better don't use it " << Endl;
149 return out;
150}
151////////////////////////////////////////////////////////////////////////////////
152
154{
155 return (TGraph*)GetObject(alias);
156}
157
158
159////////////////////////////////////////////////////////////////////////////////
160/// delete all stored histograms
161
163{
164 fStorage->Delete();
165 fHistAlias->clear();
166}
const char Option_t
Definition: RtypesCore.h:66
winID h TVirtualViewer3D TVirtualGLPainter p
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition: TString.cxx:2447
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
A TGraph is an object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
TH1 is the base class of all histogram classes in ROOT.
Definition: TH1.h:58
static TClass * Class()
Service class for 2-D histogram classes.
Definition: TH2.h:30
Iterator of linked list.
Definition: TList.h:200
A doubly linked list.
Definition: TList.h:44
Class that contains all the data information.
Definition: DataSetInfo.h:62
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:57
TGraph * GetGraph(const TString &alias) const
Definition: Results.cxx:153
TList * fStorage
-> stores all the result-histograms
Definition: Results.h:91
Bool_t DoesExist(const TString &alias) const
Returns true if there is an object stored in the result for a given alias, false otherwise.
Definition: Results.cxx:127
TH2 * GetHist2D(const TString &alias) const
Definition: Results.cxx:145
TObject * GetObject(const TString &alias) const
Returns a stored object if it exists.
Definition: Results.cxx:112
TH1 * GetHist(const TString &alias) const
Definition: Results.cxx:136
virtual ~Results()
destructor
Definition: Results.cxx:76
void Store(TObject *obj, const char *alias=0)
Definition: Results.cxx:86
virtual void Delete(Option_t *option="")
delete all stored histograms
Definition: Results.cxx:162
Singleton class for Global types used by TMVA.
Definition: Types.h:71
@ kINFO
Definition: Types.h:58
@ kWARNING
Definition: Types.h:59
@ kFATAL
Definition: Types.h:61
Mother of all ROOT objects.
Definition: TObject.h:37
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:359
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
Basic string class.
Definition: TString.h:136
TString as(SEXP s)
Definition: RExports.h:86
create variable transformations
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:148
Double_t Log(Double_t x)
Definition: TMath.h:710
Definition: test.py:1
auto * l
Definition: textangle.C:4