00001 #ifndef FRANKS1HISTO__HH
00002 #define FRANKS1HISTO__HH
00003
00004
00005 #ifndef __CINT__
00006 #include <Stiostream.h>
00007 #include <stdio>
00008 #include <math.h>
00009 #ifdef GNU_GCC
00010 # include <stddef.h>
00011 #endif
00012 #endif
00013
00014
00015
00016
00017
00018 #ifdef ST_NO_TEMPLATE_DEF_ARGS
00019 template<class T>
00020 #else
00021 template<class T = double>
00022 #endif
00023
00024 class franks1Histo {
00025 private:
00026 char* mC1;
00027 char* mC2;
00028 int mBins;
00029 int mPos;
00030 T mXmin;
00031 T mXmax;
00032 T mStep;
00033 T *vec;
00034 int mEntries;
00035
00036 public:
00037
00038 franks1Histo(const char* c1, const char* c2,
00039 int bins, T xmin, T xmax);
00040 ~franks1Histo();
00041
00042
00043 #ifndef ST_NO_MEMBER_TEMPLATES
00044 template<class X, class Y> void Add( franks1Histo<X>* , franks1Histo<X>* , Y w1=1., Y w2=1., const char* c="");
00045 template<class X, class Y> void Divide( franks1Histo<X>* , franks1Histo<X>* , Y w1=1., Y w2=1., const char* c="");
00046 template<class X> void Fill( X value);
00047 template<class X, class Y> void Fill( X value, Y weight);
00048 template<class X> int GetBin(X value);
00049 template<class X> void Scale(X scale);
00050 #endif
00051
00052 void Draw(const char* c="");
00053 void SetDirectory(int dummy) { };
00054 void Sumw2() {};
00055 int GetNbinsX() { return mBins; }
00056 T GetBinContent(int bin) { return vec[bin]; }
00057 T GetBinCenter(int bin);
00058 T GetMaximum();
00059 T GetMinimum();
00060 T GetMean();
00061 T GetRMS();
00062 T GetEntries();
00063 T Integral();
00064 void Reset(const char* c="");
00065 };
00066
00067 #ifndef __CINT__
00068
00069
00070
00071
00072 template<class T>
00073 inline franks1Histo<T>::franks1Histo(const char* c1, const char* c2, int bins, T xmin, T xmax) {
00074 mC1 = c1;
00075 mC2 = c2;
00076 mBins = bins;
00077 mXmin = xmin;
00078 mXmax = xmax;
00079 mStep = (xmax-xmin)/bins;
00080 vec = new T[bins];
00081 }
00082
00083
00084
00085 template<class T>
00086 inline franks1Histo<T>::~franks1Histo() {
00087 delete vec;
00088 }
00089
00090
00091
00092
00093 #ifndef ST_NO_MEMBER_TEMPLATES
00094
00095 template<class T>
00096 template<class X, class Y>
00097 inline void franks1Histo<T>::Add( franks1Histo<X>* h1, franks1Histo<X>* h2, Y w1, Y w2, const char* c) {
00098 for (int i=0; i < mBins; i++) {
00099 vec[i] = h1->vec[i]*w1 + h2->vec[i]*w2;
00100 }
00101 }
00102
00103 template<class T>
00104 template<class X, class Y>
00105 inline void franks1Histo<T>::Divide( franks1Histo<X>* h1, franks1Histo<X>* h2, Y w1, Y w2, const char* c) {
00106 for (int i=0; i < mBins; i++) {
00107 if (h2->vec[i]*w2 !=0 )
00108 vec[i] = h1->vec[i]*w1 / h2->vec[i]*w2;
00109 else
00110 vec[i]=0;
00111 }
00112 }
00113
00114 template<class T>
00115 inline void franks1Histo<T>::Draw(const char* c) {
00116 cout << c << " " << mC1 << " " << endl;
00117 T min=GetMinimum();
00118 T max=GetMaximum();
00119 T step = (max-min)/50.;
00120 cout << " minimum=" << min << " maximum=" << max << " step=" << step << endl;
00121 for (int i=0; i < mBins; i++) {
00122 printf(" (%3i) %+e %+e ",i, GetBinCenter(i), vec[i]);
00123 for ( int j=0; j < floor( (vec[i]-min)/step ); j++) {
00124 cout << "*";
00125 }
00126 cout << endl;
00127 }
00128 };
00129
00130 template<class T>
00131 template<class X>
00132 inline void franks1Histo<T>::Fill( X value) {
00133 mPos = (int) abs( (value-mXmin)/mStep );
00134 if ( mPos>=0 && mPos < mBins)
00135 vec[mPos]++;
00136 cout << ".";
00137 }
00138
00139 template<class T>
00140 template<class X, class Y>
00141 inline void franks1Histo<T>::Fill( X value, Y weight) {
00142 mPos = (int) abs( (value-mXmin)/mStep );
00143 if ( mPos>=0 && mPos < mBins)
00144 vec[mPos] = vec[mPos] + weight;
00145 cout << ".";
00146 }
00147
00148 template<class T>
00149 template<class X>
00150 inline int franks1Histo<T>::GetBin(X value) {
00151 int bin = (int) floor( (value-mXmin)/mStep );
00152 if( !(bin >=0 && bin < mBins) ) bin=-1;
00153 return bin;
00154 }
00155
00156 template<class T>
00157 inline T franks1Histo<T>::GetBinCenter(int bin) {
00158 double center=0;
00159 if ( bin >=0 && bin < mBins)
00160 center= mXmin + (0.5+bin)*mStep;
00161 return center;
00162 }
00163
00164 template<class T>
00165 inline T franks1Histo<T>::GetMean() {
00166 T mean=0;
00167 for (int i=0; i< mBins; i++)
00168 mean+=vec[i]*GetBinCenter(i);
00169 mean/=mBins;
00170 return mean;
00171 }
00172
00173 template<class T>
00174 inline T franks1Histo<T>::GetMaximum() {
00175 T max=vec[0];
00176 for (int i=0; i< mBins; i++) {
00177 if (vec[i] > max)
00178 max=vec[i];
00179 }
00180 return max;
00181 }
00182
00183 template<class T>
00184 inline T franks1Histo<T>::GetMinimum() {
00185 T min=vec[0];
00186 for (int i=0; i< mBins; i++) {
00187 if (vec[i] < min)
00188 min=vec[i];
00189 }
00190 return min;
00191 }
00192
00193 template<class T>
00194 inline T franks1Histo<T>::GetRMS() {
00195 T mean = GetMean();
00196 for (int i=0; i< mBins; i++)
00197 mean+=vec[i]*GetBinCenter(i);
00198 mean/=mBins;
00199 return mean;
00200 }
00201
00202 template<class T>
00203 inline void franks1Histo<T>::Reset(const char*) {
00204 for (int i=0; i < mBins; i++)
00205 vec[i] = 0;
00206 }
00207
00208 template<class T>
00209 template<class X>
00210 inline void franks1Histo<T>::Scale(X scale) {
00211 for (int i=0; i < mBins; i++)
00212 vec[i] *=scale;
00213 }
00214
00215 template<class T>
00216 inline T franks1Histo<T>::Integral() {
00217 T Integral=0;
00218 for (int i=0; i < mBins; i++) {
00219 Integral+=vec[i];
00220
00221 }
00222 return Integral;
00223 }
00224 #endif
00225
00226 #endif // __CINT__
00227
00228 #endif // FRANKS2DHISTO_HH