Logo ROOT   6.12/07
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
30 Class 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 
45 namespace TMVA {
46  class DataSetInfo;
47 }
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// constructor
51 
52 TMVA::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 {
59  fStorage->SetOwner();
60 }
61 
63 : fTreeType(Types::kTraining),
64 fDsi(0),
65 fStorage( new TList() ),
66 fHistAlias( new std::map<TString, TObject*> ),
67 fLogger( new MsgLogger("Results", kINFO))
68 {
69  fStorage->SetOwner();
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 
86 void TMVA::Results::Store( TObject* obj, const char* alias )
87 {
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 
111 {
112  std::map<TString, TObject*>::iterator it = fHistAlias->find(alias);
113 
114  if (it != fHistAlias->end()) return it->second;
115 
116  // alias does not exist
117  return 0;
118 }
119 
120 
122 {
123  TObject* test = GetObject(alias);
124 
125  return test;
126 }
127 
128 ////////////////////////////////////////////////////////////////////////////////
129 
130 TH1* TMVA::Results::GetHist(const TString & alias) const
131 {
132  TH1* out=dynamic_cast<TH1*>(GetObject(alias));
133  if (!out) Log() <<kWARNING << "You have asked for histogram " << alias << " which does not seem to exist in *Results* .. better don't use it " << Endl;
134  return out;
135 }
136 
137 ////////////////////////////////////////////////////////////////////////////////
138 
139 TH2* TMVA::Results::GetHist2D(const TString & alias) const
140 {
141  TH2* out=dynamic_cast<TH2*>(GetObject(alias));
142  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;
143  return out;
144 }
145 ////////////////////////////////////////////////////////////////////////////////
146 
148 {
149  return (TGraph*)GetObject(alias);
150 }
151 
152 
153 ////////////////////////////////////////////////////////////////////////////////
154 /// delete all stored histograms
155 
157 {
158  fStorage->Delete();
159  fHistAlias->clear();
160 }
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:467
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:158
Singleton class for Global types used by TMVA.
Definition: Types.h:73
virtual void Delete(Option_t *option="")
delete all stored histograms
Definition: Results.cxx:156
const char Option_t
Definition: RtypesCore.h:62
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
Definition: test.py:1
Basic string class.
Definition: TString.h:125
TString as(SEXP s)
Definition: RExports.h:71
bool Bool_t
Definition: RtypesCore.h:59
virtual ~Results()
destructor
Definition: Results.cxx:76
STL namespace.
Iterator of linked list.
Definition: TList.h:197
void Class()
Definition: Class.C:29
Bool_t DoesExist(const TString &alias) const
Definition: Results.cxx:121
Class that contains all the data information.
Definition: DataSetInfo.h:60
A doubly linked list.
Definition: TList.h:44
MsgLogger * fLogger
Definition: Results.h:93
Service class for 2-Dim histogram classes.
Definition: TH2.h:30
TGraph * GetGraph(const TString &alias) const
Definition: Results.cxx:147
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:443
TList * fStorage
Definition: Results.h:91
char * Form(const char *fmt,...)
std::map< TString, TObject * > * fHistAlias
Definition: Results.h:92
TH1 * GetHist(const TString &alias) const
Definition: Results.cxx:130
The TH1 histogram class.
Definition: TH1.h:56
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:59
Mother of all ROOT objects.
Definition: TObject.h:37
TObject * GetObject(const TString &alias) const
Definition: Results.cxx:110
Abstract ClassifierFactory template that handles arbitrary types.
TH2 * GetHist2D(const TString &alias) const
Definition: Results.cxx:139
Types::ETreeType fTreeType
Definition: Results.h:89
virtual void Add(TObject *obj)
Definition: TList.h:87
auto * l
Definition: textangle.C:4
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
const DataSetInfo * fDsi
Definition: Results.h:90
void Store(TObject *obj, const char *alias=0)
Definition: Results.cxx:86
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:357
MsgLogger & Log() const
message logger
Definition: Results.h:94