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