]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/tracking/AliHLTTPCHistogram1D.cxx
New task for D* pt-dep analysis (A. Grelli)
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking / AliHLTTPCHistogram1D.cxx
1 // @(#) $Id$
2 // origin: hough/AliL3Histogram1D.cxx,v 1.11 Tue Jun 14 10:55:20 2005 UTC by cvetan 
3
4 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
5 //*-- Copyright &copy ALICE HLT Group
6
7 #include <strings.h>
8 #include "AliHLTStdIncludes.h"
9
10 #include "AliHLTTPCLogging.h"
11 #include "AliHLTTPCHistogram1D.h"
12
13 #include <TH1.h>
14
15 #if __GNUC__ >= 3
16 using namespace std;
17 #endif
18
19 //_____________________________________________________________
20 // AliHLTTPCHistogram1D
21 //
22 // 1D histogram class.
23
24 ClassImp(AliHLTTPCHistogram1D)
25
26 AliHLTTPCHistogram1D::AliHLTTPCHistogram1D()
27 {
28   //default ctor
29   fNbins = 0;
30   fNcells = 0;
31   fEntries = 0;
32   fXmin = 0;
33   fXmax = 0;
34   fRootHisto = 0;
35   fThreshold = 0;
36   fContent = 0;
37   
38 }
39   
40 AliHLTTPCHistogram1D::AliHLTTPCHistogram1D(Char_t *name,Char_t */*id*/,Int_t nxbin,Double_t xmin,Double_t xmax)
41
42 {
43   //normal ctor
44   strcpy(fName,name);
45   fNbins = nxbin;
46   fNcells = fNbins + 2;
47   fEntries = 0;
48   fXmin = xmin;
49   fXmax = xmax;
50   fRootHisto = 0;
51   fThreshold = 0;
52   
53   fContent = new Double_t[fNcells];
54   Reset();
55 }
56
57 AliHLTTPCHistogram1D::~AliHLTTPCHistogram1D()
58 {
59   //Destructor
60   if(fContent)
61     delete [] fContent;
62   if(fRootHisto)
63     delete fRootHisto;
64 }
65
66
67 void AliHLTTPCHistogram1D::Reset()
68 {
69   //Reset histogram contents
70 #if defined(__DECCXX)
71   bzero((char *)fContent,fNcells*sizeof(Double_t));
72 #else
73   bzero(fContent,fNcells*sizeof(Double_t));
74 #endif
75   fEntries=0;
76 }
77
78 void AliHLTTPCHistogram1D::Fill(Double_t x,Int_t weight)
79 {
80   //Fill a given bin with weight
81   Int_t bin = FindBin(x);
82   AddBinContent(bin,weight);
83 }
84
85
86 Int_t AliHLTTPCHistogram1D::FindBin(Double_t x) const
87 {
88   //Find a given bin
89   if(x < fXmin || x > fXmax)
90     return 0;
91   
92   return 1 + (Int_t)(fNbins*(x-fXmin)/(fXmax-fXmin));
93
94 }
95
96 Int_t AliHLTTPCHistogram1D::GetMaximumBin() const
97 {
98   //Find the bin with the largest content
99   Double_t maxvalue=0;
100   Int_t maxbin=0;
101   for(Int_t i=0; i<fNcells; i++)
102     {
103       if(fContent[i] > maxvalue)
104         {
105           maxvalue=fContent[i];
106           maxbin = i;
107         }
108     }
109   return maxbin;
110 }
111
112 Double_t AliHLTTPCHistogram1D::GetBinContent(Int_t bin) const
113 {
114   //Get bin content
115   if(bin >= fNcells)
116     {
117       LOG(AliHLTTPCLog::kError,"AliHLTTPCHistogram::GetBinContent","array")<<AliHLTTPCLog::kDec<<
118         "bin out of range "<<bin<<ENDLOG;
119       return 0;
120     }
121   
122   if(fContent[bin] < fThreshold)
123     return 0;
124   return fContent[bin];
125 }
126
127
128 void AliHLTTPCHistogram1D::SetBinContent(Int_t bin,Int_t value)
129 {
130   //Set bin content
131   if(bin >= fNcells)
132     {
133       LOG(AliHLTTPCLog::kError,"AliHLTTPCHistogram::SetBinContent","array")<<AliHLTTPCLog::kDec<<
134         "bin out of range "<<bin<<ENDLOG;
135       return;
136     }
137   if(bin == 0)
138     return;
139   fContent[bin]=value;
140   
141 }
142
143 void AliHLTTPCHistogram1D::AddBinContent(Int_t bin,Int_t weight)
144 {
145   //Add weight to bin content
146   if(bin < 0 || bin > fNcells)
147     {
148       LOG(AliHLTTPCLog::kError,"AliHLTTPCHistogram::AddBinContent","array")<<AliHLTTPCLog::kDec<<
149         "bin-value out of range "<<bin<<ENDLOG;
150       return;
151     }
152   if(bin == 0)
153     return;
154   fEntries++;
155   fContent[bin] += weight;
156 }
157
158 Double_t AliHLTTPCHistogram1D::GetBinCenter(Int_t bin) const
159 {
160   //Get bin center  
161   Double_t binwidth = (fXmax - fXmin) / fNbins;
162   return fXmin + (bin-1) * binwidth + 0.5*binwidth;
163   
164 }
165
166 void AliHLTTPCHistogram1D::Draw(Char_t *option)
167 {
168   //Draw the histogram
169   fRootHisto = new TH1F(fName,"",fNbins,fXmin,fXmax);
170   for(Int_t bin=0; bin<fNcells; bin++)
171     fRootHisto->AddBinContent(bin,GetBinContent(bin));
172   
173   fRootHisto->Draw(option);
174   
175 }