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