Logo ROOT   6.08/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 #include "TMVA/Results.h"
29 
30 #include "TMVA/MsgLogger.h"
31 #include "TMVA/Types.h"
32 
33 #include "TGraph.h"
34 #include "TH1.h"
35 #include "TH2.h"
36 #include "TList.h"
37 
38 #include <vector>
39 
40 namespace TMVA {
41  class DataSetInfo;
42 }
43 
44 
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// constructor
48 
49 TMVA::Results::Results( const DataSetInfo* dsi, TString resultsName )
50  : fTreeType(Types::kTraining),
51  fDsi(dsi),
52  fStorage( new TList() ),
53  fHistAlias( new std::map<TString, TObject*> ),
54  fLogger( new MsgLogger(Form("Results%s",resultsName.Data()), kINFO) )
55 {
56  fStorage->SetOwner();
57 }
58 
60 : fTreeType(Types::kTraining),
61 fDsi(0),
62 fStorage( new TList() ),
63 fHistAlias( new std::map<TString, TObject*> ),
64 fLogger( new MsgLogger("Results", kINFO))
65 {
66  fStorage->SetOwner();
67 }
68 
69 
70 ////////////////////////////////////////////////////////////////////////////////
71 /// destructor
72 
74 {
75  // delete result-histograms
76  delete fStorage;
77  delete fHistAlias;
78  delete fLogger;
79 }
80 
81 ////////////////////////////////////////////////////////////////////////////////
82 
83 void TMVA::Results::Store( TObject* obj, const char* alias )
84 {
86  // check if object is already in list
87  while (void* p = (void*)l()) {
88  if(p==obj)
89  *fLogger << kFATAL << "Histogram pointer " << p << " already exists in results storage" << Endl;
90  }
91 
92  TString as(obj->GetName());
93  if (alias!=0) as=TString(alias);
94  if (fHistAlias->find(as) != fHistAlias->end()) {
95  // alias exists
96  *fLogger << kFATAL << "Alias " << as << " already exists in results storage" << Endl;
97  }
98  if( obj->InheritsFrom(TH1::Class()) ) {
99  ((TH1*)obj)->SetDirectory(0);
100  }
101  fStorage->Add( obj );
102  fHistAlias->insert(std::pair<TString, TObject*>(as,obj));
103 }
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 
108 {
109  std::map<TString, TObject*>::iterator it = fHistAlias->find(alias);
110 
111  if (it != fHistAlias->end()) return it->second;
112 
113  // alias does not exist
114  return 0;
115 }
116 
117 
119 {
120  TObject* test = GetObject(alias);
121 
122  return test;
123 }
124 
125 ////////////////////////////////////////////////////////////////////////////////
126 
127 TH1* TMVA::Results::GetHist(const TString & alias) const
128 {
129  TH1* out=dynamic_cast<TH1*>(GetObject(alias));
130  if (!out) Log() <<kWARNING << "You have asked for histogram " << alias << " which does not seem to exist in *Results* .. better don't use it " << Endl;
131  return out;
132 }
133 
134 ////////////////////////////////////////////////////////////////////////////////
135 
136 TH2* TMVA::Results::GetHist2D(const TString & alias) const
137 {
138  TH2* out=dynamic_cast<TH2*>(GetObject(alias));
139  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;
140  return out;
141 }
142 ////////////////////////////////////////////////////////////////////////////////
143 
144 TGraph* TMVA::Results::GetGraph(const TString & alias) const
145 {
146  return (TGraph*)GetObject(alias);
147 }
148 
149 
150 ////////////////////////////////////////////////////////////////////////////////
151 /// delete all stored histograms
152 
154 {
155  fStorage->Delete();
156  fHistAlias->clear();
157 }
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:405
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:162
virtual void Delete(Option_t *option="")
delete all stored histograms
Definition: Results.cxx:153
const char Option_t
Definition: RtypesCore.h:62
std::map< TString, TObject * > * fHistAlias
Definition: Results.h:98
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:137
bool Bool_t
Definition: RtypesCore.h:59
virtual ~Results()
destructor
Definition: Results.cxx:73
STL namespace.
const char * Class
Definition: TXMLSetup.cxx:64
Iterator of linked list.
Definition: TList.h:187
std::vector< std::vector< double > > Data
Bool_t DoesExist(const TString &alias) const
Definition: Results.cxx:118
A doubly linked list.
Definition: TList.h:47
MsgLogger * fLogger
Definition: Results.h:99
Service class for 2-Dim histogram classes.
Definition: TH2.h:36
TGraph * GetGraph(const TString &alias) const
Definition: Results.cxx:144
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:488
TList * fStorage
Definition: Results.h:97
char * Form(const char *fmt,...)
TLine * l
Definition: textangle.C:4
TH1 * GetHist(const TString &alias) const
Definition: Results.cxx:127
The TH1 histogram class.
Definition: TH1.h:80
Mother of all ROOT objects.
Definition: TObject.h:37
TObject * GetObject(const TString &alias) const
Definition: Results.cxx:107
Abstract ClassifierFactory template that handles arbitrary types.
TH2 * GetHist2D(const TString &alias) const
Definition: Results.cxx:136
Types::ETreeType fTreeType
Definition: Results.h:95
virtual void Add(TObject *obj)
Definition: TList.h:81
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:53
const DataSetInfo * fDsi
Definition: Results.h:96
void Store(TObject *obj, const char *alias=0)
Definition: Results.cxx:83
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:416
MsgLogger & Log() const
message logger
Definition: Results.h:100