Logo ROOT   6.18/05
Reference Guide
LogInterval.cxx
Go to the documentation of this file.
1/**********************************************************************************
2 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
3 * Package: TMVA *
4 * Class : Interval *
5 * Web : http://tmva.sourceforge.net *
6 * *
7 * Description: *
8 * Extension of the Interval to "logarithmic" intervals *
9 * *
10 * *
11 * *
12 * Authors (alphabetical): *
13 * Helge Voss <helge.voss@cern.ch> - MPI-K Heidelberg, Germany *
14 * *
15 * Copyright (c) 2005: *
16 * CERN, Switzerland *
17 * MPI-K Heidelberg, Germany *
18 * *
19 * Redistribution and use in source and binary forms, with or without *
20 * modification, are permitted according to the terms listed in LICENSE *
21 * (http://tmva.sourceforge.net/LICENSE) *
22 **********************************************************************************/
23
24/*! \class TMVA::LogInterval
25\ingroup TMVA
26
27The TMVA::Interval Class.
28
29 - LogInterval definition, continuous and discrete
30
31 - LogInterval(min,max) : a continous interval [min,max]
32 - LogInterval(min,max,n): a "discrete interval" [min,max], i.e the n numbers:
33
34 1,10,100,1000
35
36 1,2,4,8,16,32,64,128,512,1024
37
38 or alike ..
39
40~~~ {.cpp}
41 Example:
42 LogInterval(1,10000,5)
43 i=0 --> 1 note: StepSize(ibin=0) = not defined !!
44 i=1 --> 10 StepSize(ibin=1) = 9
45 i=2 --> 100 StepSize(ibin=2) = 99
46 i=3 --> 1000 StepSize(ibin=3) = 999
47 i=4 --> 10000 StepSize(ibin=4) = 9999
48
49 LogInterval(1,1000,11)
50 i=0 --> 1
51 i=1 --> 1.99526
52 i=2 --> 3.98107
53 i=3 --> 7.94328
54 i=4 --> 15.8489
55 i=5 --> 31.6228
56 i=6 --> 63.0957
57 i=7 --> 125.893
58 i=8 --> 251.189
59 i=9 --> 501.187
60 i=10 --> 1000
61
62 LogInterval(1,1024,11)
63 i=0 --> 1
64 i=1 --> 2
65 i=2 --> 4
66 i=3 --> 8
67 i=4 --> 16
68 i=5 --> 32
69 i=6 --> 64
70 i=7 --> 128
71 i=8 --> 256
72 i=9 --> 512
73 i=10 --> 1024
74~~~
75*/
76
77#include "TMath.h"
78#include "TRandom3.h"
79#include "ThreadLocalStorage.h"
80
81#include "TMVA/LogInterval.h"
82#include "TMVA/MsgLogger.h"
83#include "TMVA/Types.h"
84
86
87////////////////////////////////////////////////////////////////////////////////
88
90TMVA::Interval(min,max,nbins)
91{
92 if (min<=0) Log() << kFATAL << "logarithmic intervals have to have Min>0 !!" << Endl;
93}
94
96 TMVA::Interval(other)
97{
98}
99
100////////////////////////////////////////////////////////////////////////////////
101/// destructor
102
104{
105}
106
107////////////////////////////////////////////////////////////////////////////////
108/// calculates the value of the "number" bin in a discrete interval.
109///
110/// Parameters:
111/// - Double_t position
112
114{
115 if (fNbins <= 0) {
116 Log() << kFATAL << "GetElement only defined for discrete value LogIntervals" << Endl;
117 return 0.0;
118 }
119 else if (bin < 0 || bin >= fNbins) {
120 Log() << kFATAL << "bin " << bin << " out of range: interval *bins* count from 0 to " << fNbins-1 << Endl;
121 return 0.0;
122 }
123 return TMath::Exp(TMath::Log(fMin)+((Double_t)bin) /((Double_t)(fNbins-1))*log(fMax/fMin));
124}
125
126////////////////////////////////////////////////////////////////////////////////
127/// returns the step size between the numbers of a "discrete LogInterval"
128
130{
131 if (fNbins <= 0) {
132 Log() << kFATAL << "GetElement only defined for discrete value LogIntervals" << Endl;
133 }
134 if (iBin<0) {
135 Log() << kFATAL << "You asked for iBin=" << iBin
136 <<" in interval .. and.. sorry, I cannot let this happen.."<<Endl;
137 }
138 return (GetElement(TMath::Max(iBin,0))-GetElement(TMath::Max(iBin-1,0)));
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// get uniformly distributed number within interval
143
145{
146 return TMath::Exp(rnd.Rndm()*(TMath::Log(fMax/fMin) - TMath::Log(fMin)) + TMath::Log(fMin));
147}
148
149////////////////////////////////////////////////////////////////////////////////
150
152{
153 return fMax - fMin;
154}
155
156////////////////////////////////////////////////////////////////////////////////
157
159{
160 return (fMax + fMin)/2;
161}
162
163////////////////////////////////////////////////////////////////////////////////
164
166 TTHREAD_TLS_DECL_ARG(MsgLogger,logger,"LogInterval"); // message logger
167 return logger;
168}
int Int_t
Definition: RtypesCore.h:41
double Double_t
Definition: RtypesCore.h:55
#define ClassImp(name)
Definition: Rtypes.h:365
double log(double)
The TMVA::Interval Class.
Definition: Interval.h:61
The TMVA::Interval Class.
Definition: LogInterval.h:83
virtual Double_t GetMean() const
MsgLogger & Log() const
virtual Double_t GetStepSize(Int_t iBin=0) const
returns the step size between the numbers of a "discrete LogInterval"
virtual Double_t GetRndm(TRandom3 &) const
get uniformly distributed number within interval
LogInterval(Double_t min, Double_t max, Int_t nbins=0)
Definition: LogInterval.cxx:89
virtual Double_t GetWidth() const
virtual Double_t GetElement(Int_t position) const
calculates the value of the "number" bin in a discrete interval.
virtual ~LogInterval()
destructor
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:59
Random number generator class based on M.
Definition: TRandom3.h:27
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandom3.cxx:100
create variable transformations
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:158
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
Double_t Exp(Double_t x)
Definition: TMath.h:715
Double_t Log(Double_t x)
Definition: TMath.h:748