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