00001 // @(#)root/tmva $Id: Interval.cxx 37986 2011-02-04 21:42:15Z pcanal $ 00002 // Author: Peter Speckmayer 00003 00004 /********************************************************************************** 00005 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis * 00006 * Package: TMVA * 00007 * Class : TMVA::Interval * 00008 * Web : http://tmva.sourceforge.net * 00009 * * 00010 * Description: * 00011 * Implementation (see header for description) * 00012 * * 00013 * Authors (alphabetical): * 00014 * Peter Speckmayer <speckmay@mail.cern.ch> - CERN, Switzerland * 00015 * * 00016 * Copyright (c) 2005: * 00017 * CERN, Switzerland * 00018 * MPI-K Heidelberg, Germany * 00019 * * 00020 * Redistribution and use in source and binary forms, with or without * 00021 * modification, are permitted according to the terms listed in LICENSE * 00022 * (http://tmva.sourceforge.net/LICENSE) * 00023 * * 00024 * File and Version Information: * 00025 **********************************************************************************/ 00026 00027 ////////////////////////////////////////////////////////////////////////////// 00028 // // 00029 // Interval // 00030 // // 00031 // Interval definition, continuous and discrete // 00032 // // 00033 // Interval(min,max) : a continous interval [min,max] // 00034 // Interval(min,max,n): a "discrete interval" [min,max], i.e the n numbers: // 00035 // min, min+step, min+2*step,...., min+(n-1)*step, min+n*step=max // 00036 // e.g.: Interval(1,5,5)=1,2,3,4,5 // 00037 // Interval(.5,1.,6)= .5, .6., .7, .8, .9, 1.0 // 00038 // // 00039 // Note: **bin** counting starts from ZERO unlike in ROOT histograms // 00040 ////////////////////////////////////////////////////////////////////////////// 00041 /* Begin_Html 00042 <center><h2>the TMVA::Interval Class</h2></center> 00043 00044 <ul> 00045 <li> Interval definition, continuous and discrete 00046 <ul> 00047 <li> Interval(min,max) : a continous interval [min,max] 00048 <li> Interval(min,max,n): a "discrete interval" [min,max], i.e the n numbers:<br> 00049 min, min+step, min+2*step,...., min+(n-1)*step=max <br> 00050 e.g.: Interval(1,5,5)=1,2,3,4,5 <br> 00051 Interval(.5,1.,6)= .5, .6., .7, .8, .9, 1.0 <br> 00052 00053 </ul> 00054 </ul> 00055 <pre> 00056 00057 Example: Interval(.5,1.,6) 00058 00059 [ min max ] 00060 ------------------------------------------------------------ 00061 | | | | | | 00062 .5 .6 .7 .8 .9 1.0 00063 00064 bin 0 1 2 3 4 5 00065 00066 00067 </pre> 00068 End_Html */ 00069 00070 #include "TMath.h" 00071 #include "TRandom3.h" 00072 00073 #include "TMVA/Interval.h" 00074 #include "TMVA/MsgLogger.h" 00075 00076 ClassImp(TMVA::Interval) 00077 00078 TMVA::MsgLogger* TMVA::Interval::fgLogger = 0; 00079 00080 //_______________________________________________________________________ 00081 TMVA::Interval::Interval( Double_t min, Double_t max, Int_t nbins ) : 00082 fMin(min), 00083 fMax(max), 00084 fNbins(nbins) 00085 { 00086 if (!fgLogger) fgLogger = new MsgLogger("Interval"); 00087 00088 // defines minimum and maximum of an interval 00089 // when nbins == 0, interval describes a discrete distribution (equally distributed in the interval) 00090 // when nbins > 0, interval describes a continous interval 00091 // 00092 if (fMax - fMin < 0) Log() << kFATAL << "maximum lower than minimum" << Endl; 00093 if (nbins < 0) { 00094 Log() << kFATAL << "nbins < 0" << Endl; 00095 return; 00096 } 00097 else if (nbins == 1) { 00098 Log() << kFATAL << "interval has to have at least 2 bins if discrete" << Endl; 00099 return; 00100 } 00101 } 00102 00103 TMVA::Interval::Interval( const Interval& other ) : 00104 fMin ( other.fMin ), 00105 fMax ( other.fMax ), 00106 fNbins( other.fNbins ) 00107 { 00108 if (!fgLogger) fgLogger = new MsgLogger("Interval"); 00109 } 00110 00111 //_______________________________________________________________________ 00112 TMVA::Interval::~Interval() 00113 { 00114 // destructor 00115 } 00116 00117 //_______________________________________________________________________ 00118 Double_t TMVA::Interval::GetElement( Int_t bin ) const 00119 { 00120 // calculates the value of the "number" bin in a discrete interval. 00121 // Parameters: 00122 // Double_t position 00123 // 00124 if (fNbins <= 0) { 00125 Log() << kFATAL << "GetElement only defined for discrete value Intervals" << Endl; 00126 return 0.0; 00127 } 00128 else if (bin < 0 || bin >= fNbins) { 00129 Log() << kFATAL << "bin " << bin << " out of range: interval *bins* count from 0 to " << fNbins-1 << Endl; 00130 return 0.0; 00131 } 00132 return fMin + ( (Double_t(bin)/(fNbins-1)) *(fMax - fMin) ); 00133 } 00134 00135 //_______________________________________________________________________ 00136 Double_t TMVA::Interval::GetStepSize( ) const 00137 { 00138 // retuns the step size between the numbers of a "discrete Interval" 00139 if (fNbins <= 0) { 00140 Log() << kFATAL << "GetElement only defined for discrete value Intervals" << Endl; 00141 return 0.0; 00142 } 00143 else { 00144 return (fMax-fMin)/(Double_t)(fNbins-1); 00145 } 00146 00147 } 00148 00149 //_______________________________________________________________________ 00150 Double_t TMVA::Interval::GetRndm( TRandom3& rnd ) const 00151 { 00152 // get uniformely distributed number within interval 00153 return rnd.Rndm()*(fMax - fMin) + fMin; 00154 } 00155 00156