Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files 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" 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 
27 The 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 ClassImp(TMVA::LogInterval);
86 
87 ////////////////////////////////////////////////////////////////////////////////
88 
89 TMVA::LogInterval::LogInterval( Double_t min, Double_t max, Int_t nbins ) :
90 TMVA::Interval(min,max,nbins)
91 {
92  if (min<=0) Log() << kFATAL << "logarithmic intervals have to have Min>0 !!" << Endl;
93 }
94 
95 TMVA::LogInterval::LogInterval( const LogInterval& other ) :
96  TMVA::Interval(other)
97 {
98 }
99 
100 ////////////////////////////////////////////////////////////////////////////////
101 /// destructor
102 
103 TMVA::LogInterval::~LogInterval()
104 {
105 }
106 
107 ////////////////////////////////////////////////////////////////////////////////
108 /// calculates the value of the "number" bin in a discrete interval.
109 ///
110 /// Parameters:
111 /// - Double_t position
112 
113 Double_t TMVA::LogInterval::GetElement( Int_t bin ) const
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 
129 Double_t TMVA::LogInterval::GetStepSize( Int_t iBin ) const
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 
144 Double_t TMVA::LogInterval::GetRndm( TRandom3& rnd ) const
145 {
146  return TMath::Exp(rnd.Rndm()*(TMath::Log(fMax/fMin) - TMath::Log(fMin)) + TMath::Log(fMin));
147 }
148 
149 ////////////////////////////////////////////////////////////////////////////////
150 
151 Double_t TMVA::LogInterval::GetWidth() const
152 {
153  return fMax - fMin;
154 }
155 
156 ////////////////////////////////////////////////////////////////////////////////
157 
158 Double_t TMVA::LogInterval::GetMean() const
159 {
160  return (fMax + fMin)/2;
161 }
162 
163 ////////////////////////////////////////////////////////////////////////////////
164 
165 TMVA::MsgLogger& TMVA::LogInterval::Log() const {
166  TTHREAD_TLS_DECL_ARG(MsgLogger,logger,"LogInterval"); // message logger
167  return logger;
168 }