 ROOT   6.14/05 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 *
23  * *
24  * File and Version Information: *
25  **********************************************************************************/
26
27 /*! \class TMVA::Interval
28 \ingroup TMVA
29
30 The TMVA::Interval Class
31
32 Interval definition, continuous and discrete
33
34  - Interval(min,max) : a continous interval [min,max]
35  - Interval(min,max,n): a "discrete interval" [min,max], i.e the n numbers:
36  min, min+step, min+2*step,...., min+(n-1)*step, min+n*step=max
37
38  e.g.:
39
40  - Interval(1,5,5) = 1,2,3,4,5
41  - Interval(.5,1.,6) = .5, .6., .7, .8, .9, 1.0
42
43  Note: **bin** counting starts from ZERO unlike in ROOT histograms
44
45  - Interval definition, continuous and discrete
46
47  - Interval(min,max) : a continous interval [min,max]
48  - Interval(min,max,n): a "discrete interval" [min,max], i.e the n numbers:
49
50  min, min+step, min+2*step,...., min+(n-1)*step=max
51
52  e.g.:
53
54  - Interval(1,5,5)=1,2,3,4,5 <br>
55  - Interval(.5,1.,6)= .5, .6., .7, .8, .9, 1.0 <br>
56
57 ~~~ {.cpp}
58  Example: Interval(.5,1.,6)
59
60  [ min max ]
61  -----------------------------------------------
62  | | | | | |
63  .5 .6 .7 .8 .9 1.0
64
65  bin 0 1 2 3 4 5
66 ~~~
67 */
68
69 #include "TMath.h"
70 #include "TRandom3.h"
72
73 #include "TMVA/Interval.h"
74 #include "TMVA/MsgLogger.h"
75 #include "TMVA/Types.h"
76
78
79 ////////////////////////////////////////////////////////////////////////////////
80 /// defines minimum and maximum of an interval
81 /// - when nbins > 0, interval describes a discrete distribution (equally distributed in the interval)
82 /// - when nbins == 0, interval describes a continous interval
83
85 fMin(min),
86  fMax(max),
87  fNbins(nbins)
88 {
89  if (fMax - fMin < 0) Log() << kFATAL << "maximum lower than minimum" << Endl;
90  if (nbins < 0) {
91  Log() << kFATAL << "nbins < 0" << Endl;
92  return;
93  }
94  else if (nbins == 1) {
95  Log() << kFATAL << "interval has to have at least 2 bins if discrete" << Endl;
96  return;
97  }
98 }
99
101  fMin ( other.fMin ),
102  fMax ( other.fMax ),
103  fNbins( other.fNbins )
104 {
105 }
106
107 ////////////////////////////////////////////////////////////////////////////////
108 /// destructor
109
111 {
112 }
113
114 ////////////////////////////////////////////////////////////////////////////////
115 /// calculates the value of the "number" bin in a discrete interval.
116 /// Parameters:
117 /// Double_t position
118 ///
119
121 {
122  if (fNbins <= 0) {
123  Log() << kFATAL << "GetElement only defined for discrete value Intervals" << Endl;
124  return 0.0;
125  }
126  else if (bin < 0 || bin >= fNbins) {
127  Log() << kFATAL << "bin " << bin << " out of range: interval *bins* count from 0 to " << fNbins-1 << Endl;
128  return 0.0;
129  }
130  return fMin + ( (Double_t(bin)/(fNbins-1)) *(fMax - fMin) );
131 }
132
133 ////////////////////////////////////////////////////////////////////////////////
134 /// returns the step size between the numbers of a "discrete Interval"
135
137 {
138  if (fNbins <= 0) {
139  Log() << kFATAL << "GetElement only defined for discrete value Intervals" << Endl;
140  }
141  if (iBin<0) {
142  Log() << kFATAL << "You asked for iBin=" << iBin
143  <<" in interval .. and.. sorry, I cannot let this happen.."<<Endl;
144  }
145  return (fMax-fMin)/(Double_t)(fNbins-1);
146 }
147
148 ////////////////////////////////////////////////////////////////////////////////
149 /// get uniformly distributed number within interval
150
152 {
153  return rnd.Rndm()*(fMax - fMin) + fMin;
154 }
155
157 {
158  return fMax - fMin;
159 }
161 {
162  return (fMax + fMin)/2;
163 }
164
165 void TMVA::Interval::Print(std::ostream &os) const
166 {
167  for (Int_t i=0; i<GetNbins(); i++){
168  os << "| " << GetElement(i)<<" |" ;
169  }
170 }
171
174  return logger;
175 }
Double_t fMin
Definition: Interval.h:87
Random number generator class based on M.
Definition: TRandom3.h:27
Double_t fMax
Definition: Interval.h:87
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:158
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandom3.cxx:100
virtual Double_t GetElement(Int_t position) const
calculates the value of the "number" bin in a discrete interval.
Definition: Interval.cxx:120
int Int_t
Definition: RtypesCore.h:41
virtual Double_t GetStepSize(Int_t iBin=0) const
returns the step size between the numbers of a "discrete Interval"
Definition: Interval.cxx:136
Int_t fNbins
Definition: Interval.h:88
virtual void Print(std::ostream &os) const
Definition: Interval.cxx:165
virtual ~Interval()
destructor
Definition: Interval.cxx:110
virtual Double_t GetWidth() const
Definition: Interval.cxx:156
Interval(Double_t min, Double_t max, Int_t nbins=0)
defines minimum and maximum of an interval
Definition: Interval.cxx:84
MsgLogger & Log() const
Definition: Interval.cxx:172
virtual Int_t GetNbins() const
Definition: Interval.h:74
The TMVA::Interval Class.
Definition: Interval.h:61
virtual Double_t GetMean() const
Definition: Interval.cxx:160
#define ClassImp(name)
Definition: Rtypes.h:359
double Double_t
Definition: RtypesCore.h:55
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:59
virtual Double_t GetRndm(TRandom3 &) const
get uniformly distributed number within interval
Definition: Interval.cxx:151