ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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" invarvals *
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 /* Begin_Html
24 <center><h2>the TMVA::Interval Class</h2></center>
25 
26 <ul>
27  <li> LogInterval definition, continuous and discrete
28  <ul>
29  <li> LogInterval(min,max) : a continous interval [min,max]
30  <li> LogInterval(min,max,n): a "discrete interval" [min,max], i.e the n numbers:<br>
31  1,10,100,1000 <br>
32  1,2,4,8,16,32,64,128,512,1024 <br>
33  or alike .. <br>
34 
35  </ul>
36 </ul>
37 <pre>
38  Example:
39  LogInterval(1,10000,5)
40  i=0 --> 1 note: StepSize(ibin=0) = not defined !!
41  i=1 --> 10 StepSize(ibin=1) = 9
42  i=2 --> 100 StepSize(ibin=2) = 99
43  i=3 --> 1000 StepSize(ibin=3) = 999
44  i=4 --> 10000 StepSize(ibin=4) = 9999
45 
46  LogInterval(1,1000,11)
47  i=0 --> 1
48  i=1 --> 1.99526
49  i=2 --> 3.98107
50  i=3 --> 7.94328
51  i=4 --> 15.8489
52  i=5 --> 31.6228
53  i=6 --> 63.0957
54  i=7 --> 125.893
55  i=8 --> 251.189
56  i=9 --> 501.187
57  i=10 --> 1000
58 
59  LogInterval(1,1024,11)
60  i=0 --> 1
61  i=1 --> 2
62  i=2 --> 4
63  i=3 --> 8
64  i=4 --> 16
65  i=5 --> 32
66  i=6 --> 64
67  i=7 --> 128
68  i=8 --> 256
69  i=9 --> 512
70  i=10 --> 1024
71 
72 
73 </pre>
74 End_Html */
75 
76 #include "TMath.h"
77 #include "TRandom3.h"
78 #include "ThreadLocalStorage.h"
79 
80 #include "TMVA/LogInterval.h"
81 #include "TMVA/MsgLogger.h"
82 #include "TMVA/Types.h"
83 
85 
86 ////////////////////////////////////////////////////////////////////////////////
87 
88 TMVA::LogInterval::LogInterval( Double_t min, Double_t max, Int_t nbins ) :
89 TMVA::Interval(min,max,nbins)
90 {
91  if (min<=0) Log() << kFATAL << "logarithmic intervals have to have Min>0 !!" << Endl;
92 }
93 
95  TMVA::Interval(other)
96 {
97 }
98 
99 ////////////////////////////////////////////////////////////////////////////////
100 /// destructor
101 
103 {
104 }
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// calculates the value of the "number" bin in a discrete interval.
108 /// Parameters:
109 /// Double_t position
110 ///
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 /// retuns 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 uniformely distributed number within interval
142 
144 {
145  return TMath::Exp(rnd.Rndm()*(TMath::Log(fMax/fMin) - TMath::Log(fMin)) + TMath::Log(fMin));
146 }
147 
149 {
150  return fMax - fMin;
151 }
153 {
154  return (fMax + fMin)/2;
155 }
156 
158  TTHREAD_TLS_DECL_ARG(MsgLogger,logger,"LogInterval"); // message logger
159  return logger;
160 }
LogInterval(Double_t min, Double_t max, Int_t nbins=0)
Random number generator class based on M.
Definition: TRandom3.h:29
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
Definition: vector.h:433
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:162
Double_t Log(Double_t x)
Definition: TMath.h:526
int Int_t
Definition: RtypesCore.h:41
int nbins[3]
virtual Double_t Rndm(Int_t i=0)
Machine independent random number generator.
Definition: TRandom3.cxx:94
virtual Double_t GetWidth() const
MsgLogger & Log() const
virtual Double_t GetRndm(TRandom3 &) const
get uniformely distributed number within interval
virtual Double_t GetStepSize(Int_t iBin=0) const
retuns the step size between the numbers of a "discrete LogInterval"
Double_t Exp(Double_t x)
Definition: TMath.h:495
ClassImp(TMVA::LogInterval) TMVA
Definition: LogInterval.cxx:84
double Double_t
Definition: RtypesCore.h:55
virtual Double_t GetElement(Int_t position) const
calculates the value of the "number" bin in a discrete interval.
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Definition: vector.h:440
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:202
virtual Double_t GetMean() const
virtual ~LogInterval()
destructor
Definition: math.cpp:60
double log(double)