StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
franks2Histo.cc
1 #ifndef Solaris
2 #include <stdlib.h>
3 
4 #include "franks2Histo.hh"
5 
6 // ***********
7 // constructor
8 // ***********
9 template<class T>
10 franks2Histo<T>::franks2Histo(const char* c1, const char* c2,
11  int xbins, T xmin, T xmax,
12  int ybins, T ymin, T ymax) {
13  mC1 = (char*) c1;
14  mC2 = (char*) c2;
15  // X
16  mXbins = xbins;
17  mXmin = xmin;
18  mXmax = xmax;
19  mXstep = (xmax-xmin)/xbins;
20  // Y
21  mYbins = ybins;
22  mYmin = ymin;
23  mYmax = ymax;
24  mYstep = (ymax-ymin)/ybins;
25  // X*Y
26  mBins = xbins*ybins;
27  // check
28  if ( (xbins<=0 || xmax <= xmin) || (ybins<=0 || ymax <= ymin) ) {
29  cout << " franks2Histo<T>() can not create histogram with this parameters";
30  cout << " xbins=" << xbins;
31  cout << " xmin=" << xmin;
32  cout << " xmax=" << xmax;
33  cout << " ybins=" << ybins;
34  cout << " ymin=" << ymin;
35  cout << " ymax=" << ymax;
36  exit(-1);
37  }
38  // create
39  vec = new T[xbins*ybins];
40 }
41 // *************
42 // deconstructor
43 // *************
44 template<class T>
46  delete vec;
47 }
48 // ******************************
49 // definition of member functions
50 // ******************************
51 template<class T>
52 template<class X, class Y, class Z>
53 void franks2Histo<T>::Add( franks2Histo<X>* h1, franks2Histo<X>* h2, Y w1, Z w2, const char* c) {
54  for (int i=0; i < mBins; i++) {
55  vec[i] = h1->vec[i]*w1 + h2->vec[i]*w2;
56  }
57 }
58 // *************************************************************************************************
59 template<class T>
60 template<class X, class Y, class Z>
61 void franks2Histo<T>::Divide( franks2Histo<X>* h1, franks2Histo<X>* h2, Y w1, Z w2, const char* c) {
62  for (int i=0; i < mBins; i++) {
63  if (h2->vec[i]*w2 !=0 )
64  vec[i] = h1->vec[i]*w1 / h2->vec[i]*w2;
65  else
66  vec[i]=0;
67  }
68 }
69 // *************************************************************************************************
70 template<class T>
71 void franks2Histo<T>::Draw(const char* c) {
72  cout << c << " " << mC1 << " " << mC2 << endl;
73  T min=GetMinimum();
74  T max=GetMaximum();
75  T step = (max-min)/10.;
76  cout << " minimum=" << min << " maximum=" << max << " step=" << step << endl;
77  for (int y=mYbins-1; y>=0; y--) {
78  for (int x=0; x<mXbins; x++) {
79  T v = floor( (vec[x+y*mYbins]-min)/step );
80  cout << v;
81  }
82  cout << endl;
83  }
84 };
85 // *************************************************************************************************
86 // *************************************************************************************************
87 template<class T>
88 template<class X, class Y, class Z>
89 void franks2Histo<T>::Fill( X x, Y y, Z w) {
90  if ( x>=mXmin && x<=mXmax && y>=mYmin && y<=mYmax) {
91  mXpos = (int) floor( (x-mXmin)/mXstep );
92  mYpos = (int) floor( (y-mYmin)/mYstep );
93  if ( mXpos+mYpos*mYbins <= mBins) {
94  vec[mXpos+mYpos*mYbins] = vec[mXpos+mYpos*mYbins] + w;
95  }
96  }
97 }
98 // *************************************************************************************************
99 template<class T>
101  T Integral=0;
102  for (int i=0; i < mBins; i++) {
103  Integral+=vec[i];
104  cout << i << " " << vec[i] << " " << Integral << endl;
105  }
106  return Integral;
107 }
108 // *************************************************************************************************
109 template<class T>
110 template<class X>
111 int franks2Histo<T>::GetBin(X x) {
112  int bin = (int) floor( (x-mXmin)/mXstep );
113  if( !(bin >=0 && bin < mXbins) ) bin=-1;
114  return bin;
115 }
116 // *************************************************************************************************
117 template<class T>
119  T center=0;
120  if ( bin >=0 && bin < mXbins)
121  center= mXmin + (0.5+bin)*mXstep;
122  return center;
123 }
124 // *************************************************************************************************
125 template<class T>
127  T mean=0;
128  for (int i=0; i< mBins; i++)
129  mean+=vec[i]*GetBinCenter(i);
130  mean/=mBins;
131  return mean;
132 }
133 // *************************************************************************************************
134 template<class T>
136  T max=vec[0];
137  for (int i=0; i< mBins; i++) {
138  if (vec[i] > max)
139  max=vec[i];
140  }
141  return max;
142 }
143 // *************************************************************************************************
144 template<class T>
146  T min=vec[0];
147  for (int i=0; i< mBins; i++) {
148  if (vec[i] < min)
149  min=vec[i];
150  }
151  return min;
152 }
153 // *************************************************************************************************
154 template<class T>
156  T mean = GetMean();
157  for (int i=0; i< mBins; i++)
158  mean+=vec[i]*GetBinCenter(i);
159  mean/=mBins;
160  return mean;
161 }
162 // *************************************************************************************************
163 template<class T>
164 void franks2Histo<T>::Reset(const char* c) {
165  for (int i=0; i < mBins; i++)
166  vec[i] = 0;
167 }
168 // *************************************************************************************************
169 template<class T>
170 template<class X>
171 void franks2Histo<T>::Scale(X scale) {
172  for (int i=0; i < mBins; i++)
173  vec[i] *=scale;
174 }
175 
176 
177 #endif // Solaris