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
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 {
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 
136 TH1* 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 
145 TH2* TMVA::Results::GetHist2D(const TString & alias) const
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 }
l
auto * l
Definition: textangle.C:4
Option_t
const char Option_t
Definition: RtypesCore.h:66
Form
char * Form(const char *fmt,...)
TGraph.h
TMath::Log
Double_t Log(Double_t x)
Definition: TMath.h:760
TCollection::SetOwner
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
Definition: TCollection.cxx:746
TMVA::Results::GetHist
TH1 * GetHist(const TString &alias) const
Definition: Results.cxx:136
TList.h
TString
Basic string class.
Definition: TString.h:136
TMVA::Results::fStorage
TList * fStorage
Definition: Results.h:91
TObject::InheritsFrom
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
test
Definition: test.py:1
bool
TListIter
Iterator of linked list.
Definition: TList.h:200
TObject::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:359
TMVA::DataSetInfo
Class that contains all the data information.
Definition: DataSetInfo.h:62
TMVA::Results::Store
void Store(TObject *obj, const char *alias=0)
Definition: Results.cxx:86
MsgLogger.h
TMVA::Results::GetObject
TObject * GetObject(const TString &alias) const
Returns a stored object if it exists.
Definition: Results.cxx:112
TH2
Service class for 2-Dim histogram classes.
Definition: TH2.h:30
TMVA::Results::DoesExist
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
TMVA::Types
Singleton class for Global types used by TMVA.
Definition: Types.h:73
Types.h
TH2.h
TMVA::Results::Delete
virtual void Delete(Option_t *option="")
delete all stored histograms
Definition: Results.cxx:162
TMVA::Results::~Results
virtual ~Results()
destructor
Definition: Results.cxx:76
TMVA::Endl
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:158
TGraph
A TGraph is an object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
Rcpp::as
TString as(SEXP s)
Definition: RExports.h:71
TMVA::MsgLogger
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:59
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
TH1
TH1 is the base class of all histogramm classes in ROOT.
Definition: TH1.h:58
TMVA::Results::Results
Results()
Definition: Results.cxx:62
TMVA::Results::GetHist2D
TH2 * GetHist2D(const TString &alias) const
Definition: Results.cxx:145
TMVA::Results::GetGraph
TGraph * GetGraph(const TString &alias) const
Definition: Results.cxx:153
Class
void Class()
Definition: Class.C:29
Results.h
TH1.h
TList
A doubly linked list.
Definition: TList.h:44
TMVA
create variable transformations
Definition: GeneticMinimizer.h:22