Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 * *
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 * (see tmva/doc/LICENSE) *
23 * *
24 * File and Version Information: *
25 **********************************************************************************/
26
27/*! \class TMVA::Interval
28\ingroup TMVA
29
30The TMVA::Interval Class
31
32Interval 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 "TRandom3.h"
70#include "ThreadLocalStorage.h"
71
72#include "TMVA/Interval.h"
73#include "TMVA/MsgLogger.h"
74#include "TMVA/Types.h"
75
77
78////////////////////////////////////////////////////////////////////////////////
79/// defines minimum and maximum of an interval
80/// - when nbins > 0, interval describes a discrete distribution (equally distributed in the interval)
81/// - when nbins == 0, interval describes a continous interval
82
84fMin(min),
85 fMax(max),
86 fNbins(nbins)
87{
88 if (fMax - fMin < 0) Log() << kFATAL << "maximum lower than minimum" << Endl;
89 if (nbins < 0) {
90 Log() << kFATAL << "nbins < 0" << Endl;
91 return;
92 }
93 else if (nbins == 1) {
94 Log() << kFATAL << "interval has to have at least 2 bins if discrete" << Endl;
95 return;
96 }
97}
98
100 fMin ( other.fMin ),
101 fMax ( other.fMax ),
102 fNbins( other.fNbins )
103{
104}
105
106////////////////////////////////////////////////////////////////////////////////
107/// destructor
108
110{
111}
112
113////////////////////////////////////////////////////////////////////////////////
114/// calculates the value of the "number" bin in a discrete interval.
115/// Parameters:
116/// Double_t position
117///
118
120{
121 if (fNbins <= 0) {
122 Log() << kFATAL << "GetElement only defined for discrete value Intervals" << Endl;
123 return 0.0;
124 }
125 else if (bin < 0 || bin >= fNbins) {
126 Log() << kFATAL << "bin " << bin << " out of range: interval *bins* count from 0 to " << fNbins-1 << Endl;
127 return 0.0;
128 }
129 return fMin + ( (Double_t(bin)/(fNbins-1)) *(fMax - fMin) );
130}
131
132////////////////////////////////////////////////////////////////////////////////
133/// returns the step size between the numbers of a "discrete Interval"
134
136{
137 if (fNbins <= 0) {
138 Log() << kFATAL << "GetElement only defined for discrete value Intervals" << Endl;
139 }
140 if (iBin<0) {
141 Log() << kFATAL << "You asked for iBin=" << iBin
142 <<" in interval .. and.. sorry, I cannot let this happen.."<<Endl;
143 }
144 return (fMax-fMin)/(Double_t)(fNbins-1);
145}
146
147////////////////////////////////////////////////////////////////////////////////
148/// get uniformly distributed number within interval
149
151{
152 return rnd.Rndm()*(fMax - fMin) + fMin;
153}
154
156{
157 return fMax - fMin;
158}
160{
161 return (fMax + fMin)/2;
162}
163
164void TMVA::Interval::Print(std::ostream &os) const
165{
166 for (Int_t i=0; i<GetNbins(); i++){
167 os << "| " << GetElement(i)<<" |" ;
168 }
169}
170
172 TTHREAD_TLS_DECL_ARG(MsgLogger,logger,"Interval"); // message logger
173 return logger;
174}
double Double_t
Definition RtypesCore.h:59
#define ClassImp(name)
Definition Rtypes.h:382
The TMVA::Interval Class.
Definition Interval.h:61
virtual Double_t GetRndm(TRandom3 &) const
get uniformly distributed number within interval
Definition Interval.cxx:150
virtual void Print(std::ostream &os) const
Definition Interval.cxx:164
Double_t fMin
Definition Interval.h:87
MsgLogger & Log() const
Definition Interval.cxx:171
virtual ~Interval()
destructor
Definition Interval.cxx:109
Double_t fMax
the constraints of the Interval
Definition Interval.h:87
virtual Double_t GetElement(Int_t position) const
calculates the value of the "number" bin in a discrete interval.
Definition Interval.cxx:119
virtual Double_t GetStepSize(Int_t iBin=0) const
returns the step size between the numbers of a "discrete Interval"
Definition Interval.cxx:135
virtual Double_t GetWidth() const
Definition Interval.cxx:155
Interval(Double_t min, Double_t max, Int_t nbins=0)
defines minimum and maximum of an interval
Definition Interval.cxx:83
virtual Double_t GetMean() const
Definition Interval.cxx:159
ostringstream derivative to redirect and format output
Definition MsgLogger.h:57
Random number generator class based on M.
Definition TRandom3.h:27
Double_t Rndm() override
Machine independent random number generator.
Definition TRandom3.cxx:99
MsgLogger & Endl(MsgLogger &ml)
Definition MsgLogger.h:148