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
76
77////////////////////////////////////////////////////////////////////////////////
78/// defines minimum and maximum of an interval
79/// - when nbins > 0, interval describes a discrete distribution (equally distributed in the interval)
80/// - when nbins == 0, interval describes a continous interval
81
83fMin(min),
84 fMax(max),
85 fNbins(nbins)
86{
87 if (fMax - fMin < 0) Log() << kFATAL << "maximum lower than minimum" << Endl;
88 if (nbins < 0) {
89 Log() << kFATAL << "nbins < 0" << Endl;
90 return;
91 }
92 else if (nbins == 1) {
93 Log() << kFATAL << "interval has to have at least 2 bins if discrete" << Endl;
94 return;
95 }
96}
97
99 fMin ( other.fMin ),
100 fMax ( other.fMax ),
101 fNbins( other.fNbins )
102{
103}
104
105////////////////////////////////////////////////////////////////////////////////
106/// destructor
107
111
112////////////////////////////////////////////////////////////////////////////////
113/// calculates the value of the "number" bin in a discrete interval.
114/// Parameters:
115/// Double_t position
116///
117
119{
120 if (fNbins <= 0) {
121 Log() << kFATAL << "GetElement only defined for discrete value Intervals" << Endl;
122 return 0.0;
123 }
124 else if (bin < 0 || bin >= fNbins) {
125 Log() << kFATAL << "bin " << bin << " out of range: interval *bins* count from 0 to " << fNbins-1 << Endl;
126 return 0.0;
127 }
128 return fMin + ( (Double_t(bin)/(fNbins-1)) *(fMax - fMin) );
129}
130
131////////////////////////////////////////////////////////////////////////////////
132/// returns the step size between the numbers of a "discrete Interval"
133
135{
136 if (fNbins <= 0) {
137 Log() << kFATAL << "GetElement only defined for discrete value Intervals" << Endl;
138 }
139 if (iBin<0) {
140 Log() << kFATAL << "You asked for iBin=" << iBin
141 <<" in interval .. and.. sorry, I cannot let this happen.."<<Endl;
142 }
143 return (fMax-fMin)/(Double_t)(fNbins-1);
144}
145
146////////////////////////////////////////////////////////////////////////////////
147/// get uniformly distributed number within interval
148
150{
151 return rnd.Rndm()*(fMax - fMin) + fMin;
152}
153
155{
156 return fMax - fMin;
157}
159{
160 return (fMax + fMin)/2;
161}
162
163void TMVA::Interval::Print(std::ostream &os) const
164{
165 for (Int_t i=0; i<GetNbins(); i++){
166 os << "| " << GetElement(i)<<" |" ;
167 }
168}
169
171 TTHREAD_TLS_DECL_ARG(MsgLogger,logger,"Interval"); // message logger
172 return logger;
173}
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
The TMVA::Interval Class.
Definition Interval.h:61
virtual Double_t GetRndm(TRandom3 &) const
get uniformly distributed number within interval
Definition Interval.cxx:149
virtual void Print(std::ostream &os) const
Definition Interval.cxx:163
Double_t fMin
Definition Interval.h:87
MsgLogger & Log() const
Definition Interval.cxx:170
virtual ~Interval()
destructor
Definition Interval.cxx:108
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:118
virtual Double_t GetStepSize(Int_t iBin=0) const
returns the step size between the numbers of a "discrete Interval"
Definition Interval.cxx:134
virtual Double_t GetWidth() const
Definition Interval.cxx:154
Interval(Double_t min, Double_t max, Int_t nbins=0)
defines minimum and maximum of an interval
Definition Interval.cxx:82
virtual Double_t GetMean() const
Definition Interval.cxx:158
ostringstream derivative to redirect and format output
Definition MsgLogger.h:57
Random number generator class based on M.
Definition TRandom3.h:27
MsgLogger & Endl(MsgLogger &ml)
Definition MsgLogger.h:148