Logo ROOT   6.07/09
Reference Guide
Interval.cxx
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Peter Speckmayer
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : TMVA::Interval *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Implementation (see header for description) *
12  * *
13  * Authors (alphabetical): *
14  * Peter Speckmayer <speckmay@mail.cern.ch> - CERN, Switzerland *
15  * *
16  * Copyright (c) 2005: *
17  * CERN, Switzerland *
18  * MPI-K Heidelberg, Germany *
19  * *
20  * Redistribution and use in source and binary forms, with or without *
21  * modification, are permitted according to the terms listed in LICENSE *
22  * (http://tmva.sourceforge.net/LICENSE) *
23  * *
24  * File and Version Information: *
25  **********************************************************************************/
26 
27 //////////////////////////////////////////////////////////////////////////////
28 // //
29 // Interval //
30 // //
31 // Interval definition, continuous and discrete //
32 // //
33 // Interval(min,max) : a continous interval [min,max] //
34 // Interval(min,max,n): a "discrete interval" [min,max], i.e the n numbers: //
35 // min, min+step, min+2*step,...., min+(n-1)*step, min+n*step=max //
36 // e.g.: Interval(1,5,5)=1,2,3,4,5 //
37 // Interval(.5,1.,6)= .5, .6., .7, .8, .9, 1.0 //
38 // //
39 // Note: **bin** counting starts from ZERO unlike in ROOT histograms //
40 //////////////////////////////////////////////////////////////////////////////
41 /* Begin_Html
42  <center><h2>the TMVA::Interval Class</h2></center>
43 
44  <ul>
45  <li> Interval definition, continuous and discrete
46  <ul>
47  <li> Interval(min,max) : a continous interval [min,max]
48  <li> Interval(min,max,n): a "discrete interval" [min,max], i.e the n numbers:<br>
49  min, min+step, min+2*step,...., min+(n-1)*step=max <br>
50  e.g.: Interval(1,5,5)=1,2,3,4,5 <br>
51  Interval(.5,1.,6)= .5, .6., .7, .8, .9, 1.0 <br>
52 
53  </ul>
54  </ul>
55  <pre>
56 
57  Example: Interval(.5,1.,6)
58 
59  [ min max ]
60  ------------------------------------------------------------
61  | | | | | |
62  .5 .6 .7 .8 .9 1.0
63 
64  bin 0 1 2 3 4 5
65 
66 
67  </pre>
68  End_Html */
69 
70 #include "TMath.h"
71 #include "TRandom3.h"
72 #include "ThreadLocalStorage.h"
73 
74 #include "TMVA/Interval.h"
75 #include "TMVA/MsgLogger.h"
76 #include "TMVA/Types.h"
77 
79 
80 ////////////////////////////////////////////////////////////////////////////////
81 /// defines minimum and maximum of an interval
82 /// when nbins > 0, interval describes a discrete distribution (equally distributed in the interval)
83 /// when nbins == 0, interval describes a continous interval
84 ///
85 
87 fMin(min),
88  fMax(max),
89  fNbins(nbins)
90 {
91  if (fMax - fMin < 0) Log() << kFATAL << "maximum lower than minimum" << Endl;
92  if (nbins < 0) {
93  Log() << kFATAL << "nbins < 0" << Endl;
94  return;
95  }
96  else if (nbins == 1) {
97  Log() << kFATAL << "interval has to have at least 2 bins if discrete" << Endl;
98  return;
99  }
100 }
101 
103  fMin ( other.fMin ),
104  fMax ( other.fMax ),
105  fNbins( other.fNbins )
106 {
107 }
108 
109 ////////////////////////////////////////////////////////////////////////////////
110 /// destructor
111 
113 {
114 }
115 
116 ////////////////////////////////////////////////////////////////////////////////
117 /// calculates the value of the "number" bin in a discrete interval.
118 /// Parameters:
119 /// Double_t position
120 ///
121 
123 {
124  if (fNbins <= 0) {
125  Log() << kFATAL << "GetElement only defined for discrete value Intervals" << Endl;
126  return 0.0;
127  }
128  else if (bin < 0 || bin >= fNbins) {
129  Log() << kFATAL << "bin " << bin << " out of range: interval *bins* count from 0 to " << fNbins-1 << Endl;
130  return 0.0;
131  }
132  return fMin + ( (Double_t(bin)/(fNbins-1)) *(fMax - fMin) );
133 }
134 
135 ////////////////////////////////////////////////////////////////////////////////
136 /// retuns the step size between the numbers of a "discrete Interval"
137 
139 {
140  if (fNbins <= 0) {
141  Log() << kFATAL << "GetElement only defined for discrete value Intervals" << Endl;
142  }
143  if (iBin<0) {
144  Log() << kFATAL << "You asked for iBin=" << iBin
145  <<" in interval .. and.. sorry, I cannot let this happen.."<<Endl;
146  }
147  return (fMax-fMin)/(Double_t)(fNbins-1);
148 }
149 
150 ////////////////////////////////////////////////////////////////////////////////
151 /// get uniformely distributed number within interval
152 
154 {
155  return rnd.Rndm()*(fMax - fMin) + fMin;
156 }
157 
159 {
160  return fMax - fMin;
161 }
163 {
164  return (fMax + fMin)/2;
165 }
166 
167 void TMVA::Interval::Print(std::ostream &os) const
168 {
169  for (Int_t i=0; i<GetNbins(); i++){
170  os << "| " << GetElement(i)<<" |" ;
171  }
172 }
173 
175  TTHREAD_TLS_DECL_ARG(MsgLogger,logger,"Interval"); // message logger
176  return logger;
177 }
virtual Int_t GetNbins() const
Definition: Interval.h:76
Double_t fMin
Definition: Interval.h:89
Random number generator class based on M.
Definition: TRandom3.h:29
Double_t fMax
Definition: Interval.h:89
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:162
Double_t Log(Double_t x)
Definition: TMath.h:526
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandom3.cxx:94
MsgLogger & Log() const
Definition: Interval.cxx:174
int Int_t
Definition: RtypesCore.h:41
virtual Double_t GetMean() const
Definition: Interval.cxx:162
Int_t fNbins
Definition: Interval.h:90
int nbins[3]
virtual ~Interval()
destructor
Definition: Interval.cxx:112
virtual Double_t GetWidth() const
Definition: Interval.cxx:158
virtual Double_t GetElement(Int_t position) const
calculates the value of the "number" bin in a discrete interval.
Definition: Interval.cxx:122
Interval(Double_t min, Double_t max, Int_t nbins=0)
defines minimum and maximum of an interval when nbins > 0, interval describes a discrete distribution...
Definition: Interval.cxx:86
virtual Double_t GetStepSize(Int_t iBin=0) const
retuns the step size between the numbers of a "discrete Interval"
Definition: Interval.cxx:138
virtual Double_t GetRndm(TRandom3 &) const
get uniformely distributed number within interval
Definition: Interval.cxx:153
#define ClassImp(name)
Definition: Rtypes.h:279
double Double_t
Definition: RtypesCore.h:55
Abstract ClassifierFactory template that handles arbitrary types.
virtual void Print(std::ostream &os) const
Definition: Interval.cxx:167