Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 * *
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 * (see tmva/doc/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(TString::Format("Results%s",resultsName.Data()).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 (auto p = l()) {
91 if(p == obj)
92 *fLogger << kFATAL << "Histogram pointer " << (void *) p << " already exists in results storage" << Endl;
93 }
94
95 TString as = obj->GetName();
96 if (alias) 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(nullptr);
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
static char * Format(const char *format, va_list ap)
Format a string in a circular formatting buffer (using a printf style format descriptor).
Definition TString.cxx:2442
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:59
static TClass * Class()
Service class for 2-D histogram classes.
Definition TH2.h:30
Iterator of linked list.
Definition TList.h:191
A doubly linked list.
Definition TList.h:38
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:90
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
void Store(TObject *obj, const char *alias=nullptr)
Definition Results.cxx:86
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 Delete(Option_t *option="") override
delete all stored histograms
Definition Results.cxx:162
Singleton class for Global types used by TMVA.
Definition Types.h:71
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:444
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:530
Basic string class.
Definition TString.h:139
create variable transformations
MsgLogger & Endl(MsgLogger &ml)
Definition MsgLogger.h:148
TLine l
Definition textangle.C:4