Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 * *
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 * (see tmva/doc/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
85
86////////////////////////////////////////////////////////////////////////////////
87
89TMVA::Interval(min,max,nbins)
90{
91 if (min<=0) Log() << kFATAL << "logarithmic intervals have to have Min>0 !!" << Endl;
92}
93
98
99////////////////////////////////////////////////////////////////////////////////
100/// destructor
101
105
106////////////////////////////////////////////////////////////////////////////////
107/// calculates the value of the "number" bin in a discrete interval.
108///
109/// Parameters:
110/// - Double_t position
111
113{
114 if (fNbins <= 0) {
115 Log() << kFATAL << "GetElement only defined for discrete value LogIntervals" << Endl;
116 return 0.0;
117 }
118 else if (bin < 0 || bin >= fNbins) {
119 Log() << kFATAL << "bin " << bin << " out of range: interval *bins* count from 0 to " << fNbins-1 << Endl;
120 return 0.0;
121 }
122 return TMath::Exp(TMath::Log(fMin)+((Double_t)bin) /((Double_t)(fNbins-1))*log(fMax/fMin));
123}
124
125////////////////////////////////////////////////////////////////////////////////
126/// returns the step size between the numbers of a "discrete LogInterval"
127
129{
130 if (fNbins <= 0) {
131 Log() << kFATAL << "GetElement only defined for discrete value LogIntervals" << Endl;
132 }
133 if (iBin<0) {
134 Log() << kFATAL << "You asked for iBin=" << iBin
135 <<" in interval .. and.. sorry, I cannot let this happen.."<<Endl;
136 }
137 return (GetElement(TMath::Max(iBin,0))-GetElement(TMath::Max(iBin-1,0)));
138}
139
140////////////////////////////////////////////////////////////////////////////////
141/// get uniformly distributed number within interval
142
144{
145 return TMath::Exp(rnd.Rndm()*(TMath::Log(fMax/fMin) - TMath::Log(fMin)) + TMath::Log(fMin));
146}
147
148////////////////////////////////////////////////////////////////////////////////
149
151{
152 return fMax - fMin;
153}
154
155////////////////////////////////////////////////////////////////////////////////
156
158{
159 return (fMax + fMin)/2;
160}
161
162////////////////////////////////////////////////////////////////////////////////
163
165 TTHREAD_TLS_DECL_ARG(MsgLogger,logger,"LogInterval"); // message logger
166 return logger;
167}
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
The TMVA::Interval Class.
Definition LogInterval.h:83
Double_t GetWidth() const override
Double_t GetMean() const override
Double_t GetRndm(TRandom3 &) const override
get uniformly distributed number within interval
MsgLogger & Log() const
LogInterval(Double_t min, Double_t max, Int_t nbins=0)
virtual ~LogInterval()
destructor
Double_t GetStepSize(Int_t iBin=0) const override
returns the step size between the numbers of a "discrete LogInterval"
Double_t GetElement(Int_t position) const override
calculates the value of the "number" bin in a discrete interval.
ostringstream derivative to redirect and format output
Definition MsgLogger.h:57
Random number generator class based on M.
Definition TRandom3.h:27
create variable transformations
MsgLogger & Endl(MsgLogger &ml)
Definition MsgLogger.h:148
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:251
Double_t Exp(Double_t x)
Returns the base-e exponential function of x, which is e raised to the power x.
Definition TMath.h:720
Double_t Log(Double_t x)
Returns the natural logarithm of x.
Definition TMath.h:767