]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/hough/AliL3Histogram.cxx
Wrote a new class
[u/mrichter/AliRoot.git] / HLT / hough / AliL3Histogram.cxx
1 //Author:        Anders Strand Vestbo
2 //Last Modified: 28.6.01
3
4 #include "AliL3Logging.h"
5 #include "AliL3Histogram.h"
6
7 //2D histogram class.
8
9 ClassImp(AliL3Histogram)
10
11 AliL3Histogram::AliL3Histogram()
12 {
13   fNxbins = 0;
14   fNybins = 0;
15   fNcells = 0;
16   fXmin = 0;
17   fYmin = 0;
18   fXmax = 0;
19   fYmax = 0;
20   fEntries = 0;
21   fContent = 0;
22 }
23
24   
25 AliL3Histogram::AliL3Histogram(Char_t *name,Char_t *id,Int_t nxbin,Double_t xmin,Double_t xmax,Int_t nybin,Double_t ymin,Double_t ymax) : TH2F(name,id,nxbin,xmin,xmax,nybin,ymin,ymax)
26 {
27   
28   strcpy(fName,name);
29   fNxbins = nxbin;
30   fNybins = nybin;
31   fNcells = (nxbin+2)*(nybin+2);
32   
33   fXmin = xmin;
34   fYmin = ymin;
35   fXmax = xmax;
36   fYmax = ymax;
37   fEntries = 0;
38   
39   fContent = new Double_t[fNcells];
40   Reset();
41 }
42
43 AliL3Histogram::~AliL3Histogram()
44 {
45   //Destructor
46   if(fContent)
47     delete [] fContent;
48 }
49
50
51 void AliL3Histogram::Reset()
52 {
53   
54   for(Int_t i=0; i<fNcells; i++)
55     fContent[i] = 0;
56   fEntries=0;
57 }
58
59 void AliL3Histogram::Fill(Double_t x,Double_t y,Int_t weight)
60 {
61   Int_t bin = FindBin(x,y);
62   AddBinContent(bin,weight);
63
64 }
65
66 Int_t AliL3Histogram::FindBin(Double_t x,Double_t y)
67 {
68   if(x < fXmin || x > fXmax)
69     {
70       LOG(AliL3Log::kError,"AliL3Histogram::FindBin","array")<<AliL3Log::kDec<<
71         "x-value out of range "<<x<<ENDLOG;
72       return 0;
73     }
74   if(y < fYmin || y > fYmax)
75     {
76       LOG(AliL3Log::kError,"AliL3Histogram::FindBin","array")<<AliL3Log::kDec<<
77         "y-value out of range "<<y<<ENDLOG;
78       return 0;
79     }
80   
81   Int_t xbin = 1 + (Int_t)(fNxbins*(x-fXmin)/(fXmax-fXmin));
82   Int_t ybin = 1 + (Int_t)(fNybins*(y-fYmin)/(fYmax-fYmin));
83
84   return xbin + ybin*(fNxbins+2);
85   
86 }
87
88 void AliL3Histogram::AddBinContent(Int_t xbin,Int_t ybin,Int_t weight)
89 {
90   Int_t bin = xbin + ybin*(fNxbins+2);
91   AddBinContent(bin,weight);
92
93 }
94
95 void AliL3Histogram::AddBinContent(Int_t bin,Int_t weight)
96 {
97   if(bin < 0 || bin > fNcells)
98     {
99       LOG(AliL3Log::kError,"AliL3Histogram::AddBinContent","array")<<AliL3Log::kDec<<
100         "bin-value out of range "<<bin<<ENDLOG;
101       return;
102     }
103   fEntries++;
104   fContent[bin] += weight;
105 }
106
107 Double_t AliL3Histogram::GetXBinCenter(Int_t xbin)
108 {
109   
110   Double_t binwidth = (fXmax - fXmin) / fNxbins;
111   return fXmin + (xbin-1) * binwidth + 0.5*binwidth;
112   
113 }
114
115 Double_t AliL3Histogram::GetYBinCenter(Int_t ybin)
116 {
117   
118   Double_t binwidth = (fYmax - fYmin) / fNybins;
119   return fYmin + (ybin-1) * binwidth + 0.5*binwidth;
120   
121 }
122
123
124 void AliL3Histogram::Draw()
125 {
126   TH2F *hist = new TH2F(fName,"",fNxbins,fXmin,fXmax,fNybins,fYmin,fYmax);
127   for(Int_t bin=0; bin<fNcells; bin++)
128     {
129       hist->AddBinContent(bin,fContent[bin]);
130       if(fContent[bin]!=0) printf("bin %d\n",bin);
131     }
132   //printf("ncells %d %d\n",(hist->GetNbinsX()+2)*(hist->GetNbinsY()+2),fNcells);
133   printf("maxbin %d\n",hist->GetMaximumBin());
134   
135   hist->Draw();
136 }