]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Wrote a new class
authorvestbo <vestbo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 28 Jun 2001 16:13:00 +0000 (16:13 +0000)
committervestbo <vestbo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 28 Jun 2001 16:13:00 +0000 (16:13 +0000)
HLT/hough/AliL3Histogram.cxx
HLT/hough/AliL3Histogram.h

index ccc5460968aad3d82c611b94cb39b3e03a4268b8..382481b0809642c7136a9ed5a786b49fc1351671 100644 (file)
+//Author:        Anders Strand Vestbo
+//Last Modified: 28.6.01
 
+#include "AliL3Logging.h"
 #include "AliL3Histogram.h"
 
+//2D histogram class.
+
 ClassImp(AliL3Histogram)
 
-  
 AliL3Histogram::AliL3Histogram()
 {
-
+  fNxbins = 0;
+  fNybins = 0;
+  fNcells = 0;
+  fXmin = 0;
+  fYmin = 0;
+  fXmax = 0;
+  fYmax = 0;
+  fEntries = 0;
+  fContent = 0;
 }
 
+  
+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)
+{
+  
+  strcpy(fName,name);
+  fNxbins = nxbin;
+  fNybins = nybin;
+  fNcells = (nxbin+2)*(nybin+2);
+  
+  fXmin = xmin;
+  fYmin = ymin;
+  fXmax = xmax;
+  fYmax = ymax;
+  fEntries = 0;
+  
+  fContent = new Double_t[fNcells];
+  Reset();
+}
 
 AliL3Histogram::~AliL3Histogram()
 {
   //Destructor
+  if(fContent)
+    delete [] fContent;
+}
+
 
+void AliL3Histogram::Reset()
+{
+  
+  for(Int_t i=0; i<fNcells; i++)
+    fContent[i] = 0;
+  fEntries=0;
+}
+
+void AliL3Histogram::Fill(Double_t x,Double_t y,Int_t weight)
+{
+  Int_t bin = FindBin(x,y);
+  AddBinContent(bin,weight);
+
+}
+
+Int_t AliL3Histogram::FindBin(Double_t x,Double_t y)
+{
+  if(x < fXmin || x > fXmax)
+    {
+      LOG(AliL3Log::kError,"AliL3Histogram::FindBin","array")<<AliL3Log::kDec<<
+       "x-value out of range "<<x<<ENDLOG;
+      return 0;
+    }
+  if(y < fYmin || y > fYmax)
+    {
+      LOG(AliL3Log::kError,"AliL3Histogram::FindBin","array")<<AliL3Log::kDec<<
+       "y-value out of range "<<y<<ENDLOG;
+      return 0;
+    }
+  
+  Int_t xbin = 1 + (Int_t)(fNxbins*(x-fXmin)/(fXmax-fXmin));
+  Int_t ybin = 1 + (Int_t)(fNybins*(y-fYmin)/(fYmax-fYmin));
+
+  return xbin + ybin*(fNxbins+2);
+  
+}
+
+void AliL3Histogram::AddBinContent(Int_t xbin,Int_t ybin,Int_t weight)
+{
+  Int_t bin = xbin + ybin*(fNxbins+2);
+  AddBinContent(bin,weight);
+
+}
+
+void AliL3Histogram::AddBinContent(Int_t bin,Int_t weight)
+{
+  if(bin < 0 || bin > fNcells)
+    {
+      LOG(AliL3Log::kError,"AliL3Histogram::AddBinContent","array")<<AliL3Log::kDec<<
+       "bin-value out of range "<<bin<<ENDLOG;
+      return;
+    }
+  fEntries++;
+  fContent[bin] += weight;
+}
+
+Double_t AliL3Histogram::GetXBinCenter(Int_t xbin)
+{
+  
+  Double_t binwidth = (fXmax - fXmin) / fNxbins;
+  return fXmin + (xbin-1) * binwidth + 0.5*binwidth;
+  
+}
+
+Double_t AliL3Histogram::GetYBinCenter(Int_t ybin)
+{
+  
+  Double_t binwidth = (fYmax - fYmin) / fNybins;
+  return fYmin + (ybin-1) * binwidth + 0.5*binwidth;
+  
+}
+
+
+void AliL3Histogram::Draw()
+{
+  TH2F *hist = new TH2F(fName,"",fNxbins,fXmin,fXmax,fNybins,fYmin,fYmax);
+  for(Int_t bin=0; bin<fNcells; bin++)
+    {
+      hist->AddBinContent(bin,fContent[bin]);
+      if(fContent[bin]!=0) printf("bin %d\n",bin);
+    }
+  //printf("ncells %d %d\n",(hist->GetNbinsX()+2)*(hist->GetNbinsY()+2),fNcells);
+  printf("maxbin %d\n",hist->GetMaximumBin());
+  
+  hist->Draw();
 }
index b31e1c433a0a763bb6b49c6d5ab8e7790ed4dca2..3558b273cf24a1a90fc2056dfd8b5473386fd4c7 100644 (file)
@@ -1,20 +1,52 @@
-#ifndef ALIL3_HOUGHHISTOGRAM
-#define ALIL3_HOUGHHISTOGRAM
+#ifndef ALIL3_HISTOGRAM
+#define ALIL3_HISTOGRAM
 
 #include "AliL3RootTypes.h"
+#include <TH2.h>
 
-class AliL3HoughTransformer : public TH2F {
+class AliL3Histogram : public TH2F {
   
  private:
-
-
+  
+  Double_t *fContent; //!
+  Char_t fName[100];
+  Int_t fNxbins;
+  Int_t fNybins;
+  Int_t fNcells;
+  Int_t fEntries;
+  
+  Double_t fXmin;
+  Double_t fYmin;
+  Double_t fXmax;
+  Double_t fYmax;
+  
   
  public:
   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);
+  virtual ~AliL3Histogram();
   
+  void Reset();
+  void Fill(Double_t x,Double_t y,Int_t weight);
+  Int_t FindBin(Double_t x,Double_t y);
+  void AddBinContent(Int_t xbin,Int_t ybin,Int_t weight);
+  void AddBinContent(Int_t bin,Int_t weight);
+  void Draw();
 
-  ClassDef(AliL3Histogram,1)
+  Double_t GetXmin() {return fXmin;}
+  Double_t GetXmax() {return fXmax;}
+  Double_t GetYmin() {return fYmin;}
+  Double_t GetYmax() {return fXmax;}
+  Double_t GetXBinCenter(Int_t xbin);
+  Double_t GetYBinCenter(Int_t ybin);
+  Int_t GetFirstXbin() {return 1 + (Int_t)(fNxbins*(fXmin-fXmin)/(fXmax-fXmin));}
+  Int_t GetLastXbin() {return 1 + (Int_t)(fNxbins*(fXmax-fXmin)/(fXmax-fXmin));}
+  Int_t GetFirstYbin() {return 1 + (Int_t)(fNxbins*(fXmin-fXmin)/(fXmax-fXmin));}
+  Int_t GetLastYbin() {return 1 + (Int_t)(fNybins*(fYmax-fYmin)/(fYmax-fYmin));}
+  Int_t GetNEntries() {return fEntries;}
 
+  ClassDef(AliL3Histogram,1)
+    
 };
 
 #endif