3 #include "StHbtMaker/Infrastructure/franks2HistoD.hh"
8 franks2HistoD::franks2HistoD(
const char* c1,
const char* c2,
9 int xbins,
double xmin,
double xmax,
10 int ybins,
double ymin,
double ymax) {
17 mXstep = (xmax-xmin)/xbins;
22 mYstep = (ymax-ymin)/ybins;
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;
37 vec =
new double[xbins*ybins];
43 franks2HistoD::~franks2HistoD() {
50 for (
int i=0; i < mBins; i++) {
51 vec[i] = h1->vec[i]*w1 + h2->vec[i]*w2;
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;
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 );
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;
90 double franks2HistoD::Integral() {
92 for (
int i=0; i < mBins; i++) {
94 cout << i <<
" " << vec[i] <<
" " << Integral << endl;
99 int franks2HistoD::GetBin(
double x) {
100 int bin = (int) floor( (x-mXmin)/mXstep );
101 if( !(bin >=0 && bin < mXbins) ) bin=-1;
105 double franks2HistoD::GetBinCenter(
int bin) {
107 if ( bin >=0 && bin < mXbins)
108 center= mXmin + (0.5+bin)*mXstep;
112 double franks2HistoD::GetMean() {
114 for (
int i=0; i< mBins; i++)
115 mean+=vec[i]*GetBinCenter(i);
120 double franks2HistoD::GetMaximum() {
122 for (
int i=0; i< mBins; i++) {
129 double franks2HistoD::GetMinimum() {
131 for (
int i=0; i< mBins; i++) {
138 double franks2HistoD::GetRMS() {
139 double mean = GetMean();
140 for (
int i=0; i< mBins; i++)
141 mean+=vec[i]*GetBinCenter(i);
146 void franks2HistoD::Reset(
const char* c) {
147 for (
int i=0; i < mBins; i++)
151 void franks2HistoD::Scale(
double scale) {
152 for (
int i=0; i < mBins; i++)