renamed CorrectionMatrix class
authorjgrosseo <jgrosseo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 13 Jun 2006 10:20:48 +0000 (10:20 +0000)
committerjgrosseo <jgrosseo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 13 Jun 2006 10:20:48 +0000 (10:20 +0000)
extended to have 2D and 3D corrections with proper baseclass

PWG0/AliCorrectionMatrix.cxx [new file with mode: 0644]
PWG0/AliCorrectionMatrix.h [new file with mode: 0644]
PWG0/AliCorrectionMatrix2D.cxx [new file with mode: 0644]
PWG0/AliCorrectionMatrix2D.h [new file with mode: 0644]
PWG0/AliCorrectionMatrix3D.cxx [new file with mode: 0644]
PWG0/AliCorrectionMatrix3D.h [new file with mode: 0644]
PWG0/CorrectionMatrix2D.cxx [deleted file]
PWG0/CorrectionMatrix2D.h [deleted file]

diff --git a/PWG0/AliCorrectionMatrix.cxx b/PWG0/AliCorrectionMatrix.cxx
new file mode 100644 (file)
index 0000000..85070dd
--- /dev/null
@@ -0,0 +1,241 @@
+/* $Id$ */
+
+// ------------------------------------------------------
+//
+// Class to handle corrections.
+//
+// ------------------------------------------------------
+//
+
+#include <TFile.h>
+#include <TCanvas.h>
+#include <TH2F.h>
+
+#include <AliLog.h>
+
+#include "AliCorrectionMatrix.h"
+
+//____________________________________________________________________
+ClassImp(AliCorrectionMatrix)
+
+//____________________________________________________________________
+AliCorrectionMatrix::AliCorrectionMatrix() : TNamed(),
+  fhMeas(0),
+  fhGene(0),
+  fhCorr(0)
+{
+  // default constructor
+}
+
+AliCorrectionMatrix::AliCorrectionMatrix(const Char_t* name, const Char_t* title) : TNamed(name, title),
+  fhMeas(0),
+  fhGene(0),
+  fhCorr(0)
+{
+  // constructor initializing tnamed
+}
+
+//____________________________________________________________________
+AliCorrectionMatrix::AliCorrectionMatrix(const AliCorrectionMatrix& c)
+  : TNamed(c)
+{
+  // copy constructor
+  ((AliCorrectionMatrix &)c).Copy(*this);
+}
+
+//____________________________________________________________________
+AliCorrectionMatrix::~AliCorrectionMatrix()
+{
+  //
+  // destructor
+  //
+
+  if (fhMeas)
+  {
+    delete fhMeas;
+    fhMeas = 0;
+  }
+
+  if (fhGene)
+  {
+    delete fhGene;
+    fhGene = 0;
+  }
+
+  if (fhCorr)
+  {
+    delete fhCorr;
+    fhCorr = 0;
+  }
+}
+
+//____________________________________________________________________
+AliCorrectionMatrix &AliCorrectionMatrix::operator=(const AliCorrectionMatrix &c)
+{
+  // assigment operator
+
+  if (this != &c) 
+    ((AliCorrectionMatrix &) c).Copy(*this);
+
+  return *this;
+}
+
+//____________________________________________________________________
+void AliCorrectionMatrix::Copy(TObject& c) const
+{
+  // copy function
+
+  AliCorrectionMatrix& target = (AliCorrectionMatrix &) c;
+
+  if (fhMeas)
+    target.fhMeas = dynamic_cast<TH1*> (fhMeas->Clone());
+
+  if (fhGene)
+    target.fhGene = dynamic_cast<TH1*> (fhGene->Clone());
+
+  if (fhCorr)
+    target.fhCorr = dynamic_cast<TH1*> (fhCorr->Clone());
+}
+
+//________________________________________________________________________
+void AliCorrectionMatrix::SetAxisTitles(const Char_t* titleX, const Char_t* titleY, const Char_t* titleZ)
+{ 
+  //
+  // method for setting the axis titles of the histograms
+  //
+
+  fhMeas ->SetXTitle(titleX);  fhMeas ->SetYTitle(titleY);  fhMeas ->SetZTitle(titleZ);
+  fhGene ->SetXTitle(titleX);  fhGene ->SetYTitle(titleY);  fhGene ->SetZTitle(titleZ);
+  fhCorr ->SetXTitle(titleX);  fhCorr ->SetYTitle(titleY);  fhCorr ->SetZTitle(titleZ);
+}
+
+//____________________________________________________________________
+Long64_t AliCorrectionMatrix::Merge(TCollection* list)
+{
+  // Merge a list of AliCorrectionMatrix objects with this (needed for
+  // PROOF). 
+  // Returns the number of merged objects (including this).
+
+  if (!list)
+    return 0;
+  
+  if (list->IsEmpty())
+    return 1;
+
+  TIterator* iter = list->MakeIterator();
+  TObject* obj;
+
+  // collections of measured and generated histograms
+  TList* collectionMeas = new TList;
+  TList* collectionGene = new TList;
+  
+  Int_t count = 0;
+  while ((obj = iter->Next())) {
+    
+    AliCorrectionMatrix* entry = dynamic_cast<AliCorrectionMatrix*> (obj);
+    if (entry == 0) 
+      continue;
+
+    collectionMeas->Add(entry->GetMeasuredHistogram());
+    collectionGene->Add(entry->GetGeneratedHistogram());
+
+    count++;
+  }
+  fhMeas->Merge(collectionMeas);
+  fhGene->Merge(collectionGene);
+
+  delete collectionMeas;
+  delete collectionGene;
+
+  return count+1;
+}
+
+//____________________________________________________________________
+void AliCorrectionMatrix::Divide()
+{
+  //
+  // divide the histograms to get the correction
+  // 
+
+  if (!fhMeas || !fhGene)
+    return;
+
+  fhCorr->Divide(fhGene, fhMeas, 1, 1, "B");
+
+}
+
+//____________________________________________________________________
+Bool_t AliCorrectionMatrix::LoadHistograms(Char_t* fileName, Char_t* dir)
+{
+  //
+  // loads the histograms from a file
+  //
+  
+  TFile* fin = TFile::Open(fileName);  
+  
+  if(!fin) {
+    //Info("LoadHistograms",Form(" %s file does not exist",fileName));
+    return kFALSE;
+  }
+  
+  if(fhGene)  {delete fhGene;  fhGene=0;}
+  if(fhCorr)  {delete fhCorr;  fhCorr=0;}
+  if(fhMeas)  {delete fhMeas;  fhMeas=0;}
+  
+  fhMeas  = (TH2F*)fin->Get(Form("%s/meas_%s", dir,GetName()));
+  if(!fhMeas)  Info("LoadHistograms","No meas  hist available");
+  
+  fhGene  = (TH2F*)fin->Get(Form("%s/gene_%s",dir, GetName()));
+  if(!fhGene)  Info("LoadHistograms","No gene  hist available");
+  
+  fhCorr  = (TH2F*)fin->Get(Form("%s/corr_%s",dir, GetName()));
+  if(!fhCorr) 
+  {
+    Info("LoadHistograms","No corr  hist available");
+    return kFALSE;
+  }
+      
+  return kTRUE;
+}
+
+//____________________________________________________________________
+void AliCorrectionMatrix::SaveHistograms()
+{
+  //
+  // saves the histograms
+  //
+
+  fhMeas ->Write();
+  fhGene ->Write();
+
+  if (fhCorr)
+    fhCorr->Write();
+}
+
+//____________________________________________________________________
+void AliCorrectionMatrix::DrawHistograms()
+{
+  //
+  // draws all the four histograms on one TCanvas
+  //
+
+  TCanvas* canvas = new TCanvas(Form("correction_%s",fName.Data()), 
+                               Form("correction_%s",fName.Data()), 800, 800);
+  canvas->Divide(2, 2);
+
+  canvas->cd(1);
+  if (fhMeas)
+    fhMeas->Draw("COLZ");
+  
+  canvas->cd(2);
+  if (fhGene)
+    fhGene->Draw("COLZ");
+
+  canvas->cd(3);
+  if (fhCorr)
+    fhCorr->Draw("COLZ");
+
+  canvas->cd(4);
+
+  // add: draw here the stat. errors of the correction histogram
+}
diff --git a/PWG0/AliCorrectionMatrix.h b/PWG0/AliCorrectionMatrix.h
new file mode 100644 (file)
index 0000000..3507b58
--- /dev/null
@@ -0,0 +1,58 @@
+#ifndef ALICORRECTIONMATRIX_H
+#define ALICORRECTIONMATRIX_H
+
+/* $Id$ */
+
+// ------------------------------------------------------
+//
+// Class to handle corrections.
+//
+// ------------------------------------------------------
+//
+// TODO:
+//
+// - add options in draw method
+//
+
+#include <TNamed.h>
+
+class TH1;
+
+class AliCorrectionMatrix : public TNamed
+{
+public:
+  AliCorrectionMatrix();
+  AliCorrectionMatrix(const Char_t* name, const Char_t* title);
+  AliCorrectionMatrix(const AliCorrectionMatrix& c);
+  virtual ~AliCorrectionMatrix();
+
+  AliCorrectionMatrix& operator=(const AliCorrectionMatrix& corrMatrix);
+  virtual void Copy(TObject& c) const;
+  virtual Long64_t Merge(TCollection* list);
+
+  TH1* GetGeneratedHistogram() { return fhGene; }
+  TH1* GetMeasuredHistogram()  { return fhMeas; }
+
+  void SetGeneratedHistogram(TH1* agene) { fhGene = agene; }
+  void SetMeasuredHistogram(TH1* ameas)  { fhMeas = ameas; }
+
+  void Divide();
+
+  void SetAxisTitles(const Char_t* titleX="", const Char_t* titleY="", const Char_t* titleZ="");
+
+  virtual Bool_t LoadHistograms(Char_t* fileName, Char_t* dir = ".");
+  virtual void SaveHistograms();
+
+  virtual void DrawHistograms();
+
+protected:
+  TH1*    fhMeas;  // histogram of measured particles (or tracks)
+  TH1*    fhGene;  // histogram of generated particles
+
+  TH1*    fhCorr;  // correction histogram (ratio generated/measured)
+
+  ClassDef(AliCorrectionMatrix,1)
+};
+
+#endif
+
diff --git a/PWG0/AliCorrectionMatrix2D.cxx b/PWG0/AliCorrectionMatrix2D.cxx
new file mode 100644 (file)
index 0000000..a407cc5
--- /dev/null
@@ -0,0 +1,202 @@
+/* $Id$ */
+
+// ------------------------------------------------------
+//
+// Class to handle 2d-corrections.
+//
+// ------------------------------------------------------
+//
+
+#include <TH2F.h>
+
+#include <AliLog.h>
+
+#include "AliCorrectionMatrix2D.h"
+
+//____________________________________________________________________
+ClassImp(AliCorrectionMatrix2D)
+
+//____________________________________________________________________
+AliCorrectionMatrix2D::AliCorrectionMatrix2D() :
+  AliCorrectionMatrix()
+{
+  // default constructor
+}
+
+//____________________________________________________________________
+AliCorrectionMatrix2D::AliCorrectionMatrix2D(const AliCorrectionMatrix2D& c)
+  : AliCorrectionMatrix(c)
+{
+  // copy constructor
+  ((AliCorrectionMatrix2D &)c).Copy(*this);
+}
+
+//____________________________________________________________________
+AliCorrectionMatrix2D::AliCorrectionMatrix2D(const Char_t* name, const Char_t* title,
+                                      Int_t nBinX, Float_t Xmin, Float_t Xmax,
+                                      Int_t nBinY, Float_t Ymin, Float_t Ymax) 
+  : AliCorrectionMatrix(name, title)
+{
+  //
+  // constructor
+  //
+
+  fhMeas  = new TH2F(Form("meas_%s",name), Form("meas_%s",title),  nBinX, Xmin, Xmax, nBinY, Ymin, Ymax);
+  fhGene  = new TH2F(Form("gene_%s",name), Form("gene_%s",title),  nBinX, Xmin, Xmax, nBinY, Ymin, Ymax);
+  fhCorr  = new TH2F(Form("corr_%s",name), Form("corr_%s",title),  nBinX, Xmin, Xmax, nBinY, Ymin, Ymax);
+
+  fhMeas->Sumw2();
+  fhGene->Sumw2();
+  fhCorr->Sumw2();
+}
+
+//____________________________________________________________________
+AliCorrectionMatrix2D::AliCorrectionMatrix2D(const Char_t* name, const Char_t* title,
+                                      Int_t nBinX, Float_t *X, Int_t nBinY, Float_t *Y) 
+  : AliCorrectionMatrix(name, title)
+{
+  //
+  // constructor
+  //
+
+  fhMeas  = new TH2F(Form("meas_%s",name), Form("meas_%s",title),  nBinX, X, nBinY, Y);
+  fhGene  = new TH2F(Form("gene_%s",name), Form("gene_%s",title),  nBinX, X, nBinY, Y);
+  fhCorr  = new TH2F(Form("corr_%s",name), Form("corr_%s",title),  nBinX, X, nBinY, Y);
+
+  fhMeas->Sumw2();
+  fhGene->Sumw2();
+  fhCorr->Sumw2();
+}
+
+//____________________________________________________________________
+AliCorrectionMatrix2D::~AliCorrectionMatrix2D()
+{
+  //
+  // destructor
+  //
+
+  // histograms already deleted in base class
+}
+
+TH2F* AliCorrectionMatrix2D::GetGeneratedHistogram() const
+{
+  // return generated histogram casted to correct type
+  return dynamic_cast<TH2F*> (fhGene);
+}
+
+TH2F* AliCorrectionMatrix2D::GetMeasuredHistogram() const
+{
+  // return measured histogram casted to correct type
+  return dynamic_cast<TH2F*> (fhMeas);
+}
+
+//____________________________________________________________________
+TH1F* AliCorrectionMatrix2D::Get1DCorrection(Char_t* opt)
+{
+  //
+  // integrate the correction over one variable 
+  // 
+
+  TH1D* meas1D = 0;
+  TH1D* gene1D = 0; 
+
+  if (strcmp(opt,"x")==0) {
+    meas1D = GetMeasuredHistogram()->ProjectionX();
+    gene1D = GetGeneratedHistogram()->ProjectionX();
+  }
+  if (strcmp(opt,"y")==0) {
+    meas1D = GetMeasuredHistogram()->ProjectionY();
+    gene1D = GetGeneratedHistogram()->ProjectionY();
+  }
+  gene1D->Sumw2();
+
+  gene1D->SetName(Form("corr_1D_%s",fName.Data()));
+  gene1D->SetTitle(Form("corr_1D_%s",fName.Data()));
+
+  gene1D->Divide(gene1D, meas1D, 1, 1, "B");
+  
+  return (TH1F*)gene1D;   
+}
+
+//____________________________________________________________________
+void AliCorrectionMatrix2D::FillMeas(Float_t ax, Float_t ay)
+{
+  // add value to measured histogram
+  GetMeasuredHistogram()->Fill(ax, ay);
+}
+
+//____________________________________________________________________
+void AliCorrectionMatrix2D::FillGene(Float_t ax, Float_t ay)
+{
+  // add value to generated histogram
+  GetGeneratedHistogram()->Fill(ax, ay);
+}
+
+//____________________________________________________________________
+Float_t AliCorrectionMatrix2D::GetCorrection(Float_t ax, Float_t ay) const
+{
+  // returns a value of the correction map
+  return fhCorr->GetBinContent(fhCorr->FindBin(ax,ay));
+}
+
+//____________________________________________________________________
+void AliCorrectionMatrix2D::RemoveEdges(Float_t cut, Int_t nBinsXedge, Int_t nBinsYedge)
+{
+  // remove edges of correction histogram by removing 
+  // - bins with content less than cut
+  // - bins next to bins with zero bin content
+  
+  Int_t nBinsX = fhCorr->GetNbinsX();
+  Int_t nBinsY = fhCorr->GetNbinsY();
+
+  // set bin content to zero for bins with content smaller cut
+  for (Int_t bx=0; bx<=nBinsX; bx++) {
+    for (Int_t by=0; by<=nBinsY; by++) {
+      if (fhCorr->GetBinContent(bx,by)>cut) {
+         fhCorr->SetBinContent(bx,by,0);
+         fhCorr->SetBinError(bx,by,0);
+      }
+    }
+  }
+
+  // set bin content to zero for bins next to bins with zero
+  TH2F* tmp = (TH2F*)fhCorr->Clone("tmp");
+  tmp->Reset();
+  
+  Bool_t done = kFALSE;
+  Int_t nBinsXCount = 0;
+  Int_t nBinsYCount = 0;
+  while (!done) {    
+    if (nBinsXCount<nBinsXedge) 
+      for (Int_t bx=0; bx<=nBinsX; bx++) {
+       for (Int_t by=0; by<=nBinsY; by++) {
+         if ((fhCorr->GetBinContent(bx+1,by)==0)|| 
+             (fhCorr->GetBinContent(bx-1,by)==0))
+           tmp->SetBinContent(bx,by,1);        
+         
+       }
+      }
+    if (nBinsYCount<nBinsYedge) 
+      for (Int_t bx=0; bx<=nBinsX; bx++) {
+       for (Int_t by=0; by<=nBinsY; by++) {
+         if ((fhCorr->GetBinContent(bx,by+1)==0)|| 
+             (fhCorr->GetBinContent(bx,by-1)==0))
+           tmp->SetBinContent(bx,by,1);        
+       }
+      }    
+    for (Int_t bx=0; bx<=nBinsX; bx++) {
+      for (Int_t by=0; by<=nBinsY; by++) {
+       if (tmp->GetBinContent(bx,by)==1) {
+         fhCorr->SetBinContent(bx,by,0);
+         fhCorr->SetBinError(bx,by,0);
+       }
+      }
+    }
+    nBinsXCount++;
+    nBinsYCount++;
+    if ((nBinsXCount>=nBinsXedge)&&(nBinsYCount>=nBinsYedge)) done=kTRUE;
+  }
+  tmp->Delete();  
+
+}
+
diff --git a/PWG0/AliCorrectionMatrix2D.h b/PWG0/AliCorrectionMatrix2D.h
new file mode 100644 (file)
index 0000000..1509555
--- /dev/null
@@ -0,0 +1,47 @@
+#ifndef ALICORRECTIONMATRIX2D_H
+#define ALICORRECTIONMATRIX2D_H
+
+/* $Id$ */
+
+// ------------------------------------------------------
+//
+// Class to handle 2d-corrections.
+//
+// ------------------------------------------------------
+
+#include <AliCorrectionMatrix.h>
+
+class TH2F;
+class TH1F;
+
+class AliCorrectionMatrix2D : public AliCorrectionMatrix
+{
+public:
+  AliCorrectionMatrix2D();
+  AliCorrectionMatrix2D(const AliCorrectionMatrix2D& c);
+  AliCorrectionMatrix2D(const Char_t* name, const Char_t* title,
+                    Int_t nBinX=10, Float_t Xmin=0., Float_t Xmax=10.,
+                    Int_t nBinY=10, Float_t Ymin=0., Float_t Ymax=10.);
+
+  AliCorrectionMatrix2D(const Char_t* name, const Char_t* title,
+                    Int_t nBinX, Float_t *X, Int_t nBinY, Float_t *Y);
+
+  virtual ~AliCorrectionMatrix2D();
+
+  TH2F* GetGeneratedHistogram() const;
+  TH2F* GetMeasuredHistogram() const;
+
+  TH1F* Get1DCorrection(Char_t* opt="x");
+
+  void FillMeas(Float_t ax, Float_t ay);
+  void FillGene(Float_t ax, Float_t ay);
+  Float_t GetCorrection(Float_t ax, Float_t ay) const;
+
+  void RemoveEdges(Float_t cut=2, Int_t nBinsX=0, Int_t nBinsY=0);
+
+protected:
+  ClassDef(AliCorrectionMatrix2D,1)
+};
+
+#endif
+
diff --git a/PWG0/AliCorrectionMatrix3D.cxx b/PWG0/AliCorrectionMatrix3D.cxx
new file mode 100644 (file)
index 0000000..48d15b2
--- /dev/null
@@ -0,0 +1,145 @@
+/* $Id$ */
+
+// ------------------------------------------------------
+//
+// Class to handle 3d-corrections.
+//
+// ------------------------------------------------------
+//
+
+#include <TH3F.h>
+
+#include <AliLog.h>
+
+#include "AliCorrectionMatrix3D.h"
+
+//____________________________________________________________________
+ClassImp(AliCorrectionMatrix3D)
+
+//____________________________________________________________________
+AliCorrectionMatrix3D::AliCorrectionMatrix3D() :
+  AliCorrectionMatrix()
+{
+  // default constructor
+}
+
+//____________________________________________________________________
+AliCorrectionMatrix3D::AliCorrectionMatrix3D(const AliCorrectionMatrix3D& c)
+  : AliCorrectionMatrix(c)
+{
+  // copy constructor
+  ((AliCorrectionMatrix3D &)c).Copy(*this);
+}
+
+//____________________________________________________________________
+AliCorrectionMatrix3D::AliCorrectionMatrix3D(const Char_t* name, const Char_t* title,
+              Int_t nBinX, Float_t Xmin, Float_t Xmax,
+              Int_t nBinY, Float_t Ymin, Float_t Ymax,
+              Int_t nBinZ, Float_t Zmin, Float_t Zmax)
+  : AliCorrectionMatrix(name, title)
+{
+  //
+  // constructor
+  //
+
+  fhMeas  = new TH3F(Form("meas_%s",name), Form("meas_%s",title),  nBinX, Xmin, Xmax, nBinY, Ymin, Ymax, nBinZ, Zmin, Zmax);
+  fhGene  = new TH3F(Form("gene_%s",name), Form("gene_%s",title),  nBinX, Xmin, Xmax, nBinY, Ymin, Ymax, nBinZ, Zmin, Zmax);
+  fhCorr  = new TH3F(Form("corr_%s",name), Form("corr_%s",title),  nBinX, Xmin, Xmax, nBinY, Ymin, Ymax, nBinZ, Zmin, Zmax);
+
+  fhMeas->Sumw2();
+  fhGene->Sumw2();
+  fhCorr->Sumw2();
+}
+
+//____________________________________________________________________
+AliCorrectionMatrix3D::~AliCorrectionMatrix3D()
+{
+  //
+  // destructor
+  //
+
+  // histograms already deleted in base class
+}
+
+//____________________________________________________________________
+TH3F* AliCorrectionMatrix3D::GetGeneratedHistogram()
+{
+  // return generated histogram casted to correct type
+  return dynamic_cast<TH3F*> (fhGene);
+}
+
+//____________________________________________________________________
+TH3F* AliCorrectionMatrix3D::GetMeasuredHistogram()
+{
+  // return measured histogram casted to correct type
+  return dynamic_cast<TH3F*> (fhMeas);
+}
+
+//____________________________________________________________________
+TH3F* AliCorrectionMatrix3D::GetCorrectionHistogram()
+{
+  // return correction histogram casted to correct type
+  return dynamic_cast<TH3F*> (fhCorr);
+}
+
+//____________________________________________________________________
+void AliCorrectionMatrix3D::FillMeas(Float_t ax, Float_t ay, Float_t az)
+{
+  // add value to measured histogram
+  GetMeasuredHistogram()->Fill(ax, ay, az);
+}
+
+//____________________________________________________________________
+void AliCorrectionMatrix3D::FillGene(Float_t ax, Float_t ay, Float_t az)
+{
+  // add value to generated histogram
+  GetGeneratedHistogram()->Fill(ax, ay, az);
+}
+
+//____________________________________________________________________
+Float_t AliCorrectionMatrix3D::GetCorrection(Float_t ax, Float_t ay, Float_t az) const
+{
+  // returns a value of the correction map
+  return fhCorr->GetBinContent(fhCorr->FindBin(ax, ay, az));
+}
+
+//____________________________________________________________________
+//void AliCorrectionMatrix3D::RemoveEdges(Float_t cut, Int_t nBinsXedge, Int_t nBinsYedge, Int_t nBinsZedge)
+void AliCorrectionMatrix3D::RemoveEdges(Float_t, Int_t, Int_t, Int_t)
+{
+  // so what do we do here...
+}
+
+//____________________________________________________________________
+void AliCorrectionMatrix3D::SaveHistograms()
+{
+  //
+  // saves the histograms
+  //
+
+  AliCorrectionMatrix::SaveHistograms();
+
+  WriteProjections(GetMeasuredHistogram());
+  WriteProjections(GetGeneratedHistogram());
+
+  if (GetCorrectionHistogram())
+    WriteProjections(GetCorrectionHistogram());
+}
+
+//____________________________________________________________________
+void AliCorrectionMatrix3D::WriteProjections(TH3F* hist)
+{
+  // write some projections to disk
+
+  TH1* proj = hist->Project3D("yx");
+  proj->SetXTitle(hist->GetXaxis()->GetTitle());
+  proj->SetYTitle(hist->GetYaxis()->GetTitle());
+
+  proj = hist->Project3D("zx");
+  proj->SetXTitle(hist->GetXaxis()->GetTitle());
+  proj->SetYTitle(hist->GetZaxis()->GetTitle());
+
+  proj = hist->Project3D("zy");
+  proj->SetXTitle(hist->GetYaxis()->GetTitle());
+  proj->SetYTitle(hist->GetZaxis()->GetTitle());
+}
diff --git a/PWG0/AliCorrectionMatrix3D.h b/PWG0/AliCorrectionMatrix3D.h
new file mode 100644 (file)
index 0000000..0ef3b57
--- /dev/null
@@ -0,0 +1,47 @@
+#ifndef ALICORRECTIONMATRIX3D_H
+#define ALICORRECTIONMATRIX3D_H
+
+/* $Id$ */
+
+// ------------------------------------------------------
+//
+// Class to handle 3d-corrections.
+//
+// ------------------------------------------------------
+
+#include <AliCorrectionMatrix.h>
+
+class TH3F;
+
+class AliCorrectionMatrix3D : public AliCorrectionMatrix
+{
+public:
+  AliCorrectionMatrix3D();
+  AliCorrectionMatrix3D(const AliCorrectionMatrix3D& c);
+  AliCorrectionMatrix3D(const Char_t* name, const Char_t* title,
+                    Int_t nBinX=10, Float_t Xmin=0., Float_t Xmax=10.,
+                    Int_t nBinY=10, Float_t Ymin=0., Float_t Ymax=10.,
+                    Int_t nBinZ=10, Float_t Zmin=0., Float_t Zmax=10.);
+
+  virtual ~AliCorrectionMatrix3D();
+
+  TH3F* GetGeneratedHistogram();
+  TH3F* GetMeasuredHistogram();
+  TH3F* GetCorrectionHistogram();
+
+  void FillMeas(Float_t ax, Float_t ay, Float_t az);
+  void FillGene(Float_t ax, Float_t ay, Float_t az);
+
+  Float_t GetCorrection(Float_t ax, Float_t ay, Float_t az) const;
+
+  void RemoveEdges(Float_t cut=2, Int_t nBinsXedge = 0, Int_t nBinsYedge = 0, Int_t nBinsZedge = 0);
+
+  virtual void SaveHistograms();
+  void WriteProjections(TH3F* hist);
+
+protected:
+  ClassDef(AliCorrectionMatrix3D,1)
+};
+
+#endif
+
diff --git a/PWG0/CorrectionMatrix2D.cxx b/PWG0/CorrectionMatrix2D.cxx
deleted file mode 100644 (file)
index 59f1dde..0000000
+++ /dev/null
@@ -1,336 +0,0 @@
-// ------------------------------------------------------
-//
-// Class to handle 2d-corrections. 
-//
-// ------------------------------------------------------
-//
-
-/* $Id$ */
-
-#include <TFile.h>
-#include <TCanvas.h>
-
-#include <AliLog.h>
-
-#include "CorrectionMatrix2D.h"
-
-//____________________________________________________________________
-ClassImp(CorrectionMatrix2D)
-
-//____________________________________________________________________
-CorrectionMatrix2D::CorrectionMatrix2D(const CorrectionMatrix2D& c) 
-  : TNamed(c)
-{
-  // copy constructor
-  ((CorrectionMatrix2D &)c).Copy(*this);
-}
-
-//____________________________________________________________________
-CorrectionMatrix2D::CorrectionMatrix2D(Char_t* name, Char_t* title,
-                                      Int_t nBinX, Float_t Xmin, Float_t Xmax,
-                                      Int_t nBinY, Float_t Ymin, Float_t Ymax) 
-  : TNamed(name, title)
-{
-  //
-  // constructor
-  //
-
-
-  fhMeas  = new TH2F(Form("meas_%s",name), Form("meas_%s",title),  nBinX, Xmin, Xmax, nBinY, Ymin, Ymax);
-  fhGene  = new TH2F(Form("gene_%s",name), Form("gene_%s",title),  nBinX, Xmin, Xmax, nBinY, Ymin, Ymax);
-  fhCorr  = new TH2F(Form("corr_%s",name), Form("corr_%s",title),  nBinX, Xmin, Xmax, nBinY, Ymin, Ymax);
-
-  fhMeas->Sumw2();
-  fhGene->Sumw2();
-  fhCorr->Sumw2();
-}
-
-//____________________________________________________________________
-CorrectionMatrix2D::CorrectionMatrix2D(Char_t* name,Char_t* title, 
-                                      Int_t nBinX, Float_t *X, Int_t nBinY, Float_t *Y) 
-  : TNamed(name, title) 
-{
-  //
-  // constructor
-  //
-
-  fhMeas  = new TH2F(Form("meas_%s",name), Form("meas_%s",title),  nBinX, X, nBinY, Y);
-  fhGene  = new TH2F(Form("gene_%s",name), Form("gene_%s",title),  nBinX, X, nBinY, Y);
-  fhCorr  = new TH2F(Form("corr_%s",name), Form("corr_%s",title),  nBinX, X, nBinY, Y);
-
-  fhMeas->Sumw2();
-  fhGene->Sumw2();
-  fhCorr->Sumw2();
-}
-
-
-//____________________________________________________________________
-CorrectionMatrix2D::~CorrectionMatrix2D() {
-  //
-  // destructor
-  //
-  if (fhMeas)  delete fhMeas;
-  if (fhGene)  delete fhGene;
-  if (fhCorr)  delete fhCorr;
-}
-
-//____________________________________________________________________
-CorrectionMatrix2D &CorrectionMatrix2D::operator=(const CorrectionMatrix2D &c)
-{
-  // assigment operator
-
-  if (this != &c) 
-    ((CorrectionMatrix2D &) c).Copy(*this);
-
-  return *this;
-}
-
-//____________________________________________________________________
-TH1F* CorrectionMatrix2D::Get1DCorrection(Char_t* opt) {
-  //
-  // integrate the correction over one variable 
-  // 
-
-  TH1D* meas1D = 0;
-  TH1D* gene1D = 0; 
-
-  if (strcmp(opt,"x")==0) {
-    meas1D = fhMeas->ProjectionX();
-    gene1D = fhGene->ProjectionX();      
-  }
-  if (strcmp(opt,"y")==0) {
-    meas1D = fhMeas->ProjectionY();
-    gene1D = fhGene->ProjectionY();      
-  }
-  gene1D->Sumw2();
-
-  gene1D->SetName(Form("corr_1D_%s",fName.Data()));
-  gene1D->SetTitle(Form("corr_1D_%s",fName.Data()));
-
-  gene1D->Divide(gene1D, meas1D, 1, 1, "B");
-  
-  return (TH1F*)gene1D;   
-}
-
-
-//____________________________________________________________________
-void
-CorrectionMatrix2D::Copy(TObject& c) const 
-{
-  // copy function
-
-  CorrectionMatrix2D& target = (CorrectionMatrix2D &) c;
-
-  target.fhMeas  = fhMeas;
-  target.fhGene  = fhGene;
-  target.fhCorr  = fhCorr;
-}
-
-
-//________________________________________________________________________
-void CorrectionMatrix2D::SetAxisTitles(Char_t* titleX, Char_t* titleY) 
-{ 
-  //
-  // method for setting the axis titles of the histograms
-  //
-
-  fhMeas ->SetXTitle(titleX);  fhMeas ->SetYTitle(titleY);
-  fhGene ->SetXTitle(titleX);  fhGene ->SetYTitle(titleY);
-  fhCorr ->SetXTitle(titleX);  fhCorr ->SetYTitle(titleY);
-}
-
-//____________________________________________________________________
-Long64_t CorrectionMatrix2D::Merge(TCollection* list) {
-  // Merge a list of CorrectionMatrix2D objects with this (needed for
-  // PROOF). 
-  // Returns the number of merged objects (including this).
-
-  if (!list)
-    return 0;
-  
-  if (list->IsEmpty())
-    return 1;
-
-  TIterator* iter = list->MakeIterator();
-  TObject* obj;
-
-  // collections of measured and generated histograms
-  TList* collectionMeas = new TList;
-  TList* collectionGene = new TList;
-  
-  Int_t count = 0;
-  while ((obj = iter->Next())) {
-    
-    CorrectionMatrix2D* entry = dynamic_cast<CorrectionMatrix2D*> (obj);
-    if (entry == 0) 
-      continue;
-
-    collectionMeas->Add(entry->GetMeasuredHistogram());
-    collectionGene->Add(entry->GetGeneratedHistogram());
-
-    count++;
-  }
-  fhMeas->Merge(collectionMeas);
-  fhGene->Merge(collectionGene);
-
-  // is this really faster than just adding the histograms in the list???
-  delete collectionMeas;
-  delete collectionGene;
-
-
-  return count+1;
-}
-
-
-//____________________________________________________________________
-void CorrectionMatrix2D::Divide() {  
-  //
-  // divide the histograms to get the correction
-  // 
-
-  if (!fhMeas || !fhGene)  return; 
-
-  fhCorr->Divide(fhGene, fhMeas, 1,1,"B");
-  
-}
-
-//____________________________________________________________________
-void
-CorrectionMatrix2D::RemoveEdges(Float_t cut, Int_t nBinsXedge, Int_t nBinsYedge) 
-{
-  // remove edges of correction histogram by removing 
-  // - bins with content less than cut
-  // - bins next to bins with zero bin content
-  
-  Int_t nBinsX = fhCorr->GetNbinsX();
-  Int_t nBinsY = fhCorr->GetNbinsY();
-
-  // set bin content to zero for bins with content smaller cut
-  for (Int_t bx=0; bx<=nBinsX; bx++) {
-    for (Int_t by=0; by<=nBinsY; by++) {
-      if (fhCorr->GetBinContent(bx,by)>cut) {
-         fhCorr->SetBinContent(bx,by,0);
-         fhCorr->SetBinError(bx,by,0);
-      }
-    }
-  }
-
-  // set bin content to zero for bins next to bins with zero
-  TH2F* tmp = (TH2F*)fhCorr->Clone("tmp");
-  tmp->Reset();
-  
-  Bool_t done = kFALSE;
-  Int_t nBinsXCount = 0;
-  Int_t nBinsYCount = 0;
-  while (!done) {    
-    if (nBinsXCount<nBinsXedge) 
-      for (Int_t bx=0; bx<=nBinsX; bx++) {
-       for (Int_t by=0; by<=nBinsY; by++) {
-         if ((fhCorr->GetBinContent(bx+1,by)==0)|| 
-             (fhCorr->GetBinContent(bx-1,by)==0))
-           tmp->SetBinContent(bx,by,1);        
-         
-       }
-      }
-    if (nBinsYCount<nBinsYedge) 
-      for (Int_t bx=0; bx<=nBinsX; bx++) {
-       for (Int_t by=0; by<=nBinsY; by++) {
-         if ((fhCorr->GetBinContent(bx,by+1)==0)|| 
-             (fhCorr->GetBinContent(bx,by-1)==0))
-           tmp->SetBinContent(bx,by,1);        
-       }
-      }    
-    for (Int_t bx=0; bx<=nBinsX; bx++) {
-      for (Int_t by=0; by<=nBinsY; by++) {
-       if (tmp->GetBinContent(bx,by)==1) {
-         fhCorr->SetBinContent(bx,by,0);
-         fhCorr->SetBinError(bx,by,0);
-       }
-      }
-    }
-    nBinsXCount++;
-    nBinsYCount++;
-    if ((nBinsXCount>=nBinsXedge)&&(nBinsYCount>=nBinsYedge)) done=kTRUE;
-  }
-  tmp->Delete();  
-
-}
-
-//____________________________________________________________________
-Bool_t CorrectionMatrix2D::LoadHistograms(Char_t* fileName, Char_t* dir) {
-  //
-  // loads the histograms from a file
-  //
-  
-  TFile* fin = TFile::Open(fileName);  
-  
-  if(!fin) {
-    //Info("LoadHistograms",Form(" %s file does not exist",fileName));
-    return kFALSE;
-  }
-  
-  if(fhGene)  {delete fhGene;  fhGene=0;}
-  if(fhCorr)  {delete fhCorr;  fhCorr=0;}
-  if(fhMeas)  {delete fhMeas;  fhMeas=0;}
-  
-  fhMeas  = (TH2F*)fin->Get(Form("%s/meas_%s", dir,GetName()));
-  if(!fhMeas)  Info("LoadHistograms","No meas  hist available");
-  
-  fhGene  = (TH2F*)fin->Get(Form("%s/gene_%s",dir, GetName()));
-  if(!fhGene)  Info("LoadHistograms","No gene  hist available");
-  
-  fhCorr  = (TH2F*)fin->Get(Form("%s/corr_%s",dir, GetName()));
-  if(!fhCorr) 
-  {
-    Info("LoadHistograms","No corr  hist available");
-    return kFALSE;
-  }
-      
-  return kTRUE;
-}
-
-
-//____________________________________________________________________
-void
-CorrectionMatrix2D::SaveHistograms() {
-  //
-  // saves the histograms 
-  //
-  
-  fhMeas ->Write();
-  fhGene ->Write();
-
-  if (fhCorr)
-    fhCorr->Write();
-}
-
-//____________________________________________________________________
-void CorrectionMatrix2D::DrawHistograms()
-{
-  //
-  // draws all the four histograms on one TCanvas
-  //
-
-  TCanvas* canvas = new TCanvas(Form("correction_%s",fName.Data()), 
-                               Form("correction_%s",fName.Data()), 800, 800);
-  canvas->Divide(2, 2);
-  
-  canvas->cd(1);
-  if (fhMeas)
-    fhMeas->Draw("COLZ");
-  
-  canvas->cd(2);
-  if (fhGene)
-    fhGene->Draw("COLZ");
-
-  canvas->cd(3);
-  if (fhCorr)
-    fhCorr->Draw("COLZ");
-
-  canvas->cd(4);
-
-  // add: draw here the stat. errors of the correction histogram
-  
-}
-
-
diff --git a/PWG0/CorrectionMatrix2D.h b/PWG0/CorrectionMatrix2D.h
deleted file mode 100644 (file)
index 06ebd25..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-// ------------------------------------------------------
-//
-// Class to handle 2d-corrections. 
-//
-// ------------------------------------------------------
-//
-// TODO:
-//
-// - change the finish method (should not be called finish)
-// - add option in draw method
-// 
-
-/* $Id$ */
-
-#ifndef CORRECTIONMATRIX2D_H
-#define CORRECTIONMATRIX2D_H
-
-
-#include <TNamed.h>
-#include <TH2.h>
-
-class TFile;
-class TCanvas;
-class AliLog;
-
-class CorrectionMatrix2D : public TNamed 
-{
-public:
-  CorrectionMatrix2D(const CorrectionMatrix2D& c);
-  CorrectionMatrix2D(Char_t* name, Char_t* title,
-                    Int_t nBinX=10, Float_t Xmin=0., Float_t Xmax=10.,
-                    Int_t nBinY=10, Float_t Ymin=0., Float_t Ymax=10.);
-  
-  CorrectionMatrix2D(Char_t* name, Char_t* title,
-                    Int_t nBinX, Float_t *X, Int_t nBinY, Float_t *Y);
-
-  virtual ~CorrectionMatrix2D(); 
-
-  CorrectionMatrix2D& operator=(const CorrectionMatrix2D& corrMatrix);
-
-  virtual void Copy(TObject& c) const;
-
-  TH2F* GetGeneratedHistogram() { return fhGene; }
-  TH2F* GetMeasuredHistogram()  { return fhMeas; }
-
-  TH1F* Get1DCorrection(Char_t* opt="x");
-
-  void SetGeneratedHistogram(TH2F* agene) { fhGene = agene; }
-  void SetMeasuredHistogram(TH2F* ameas)  { fhMeas = ameas; }
-
-  void FillMeas(Float_t ax, Float_t ay) {fhMeas->Fill(ax,ay);}
-  void FillGene(Float_t ax, Float_t ay) {fhGene->Fill(ax,ay);}
-  
-  void Divide();  
-  
-  virtual Long64_t Merge(TCollection* list);
-                
-  void SetAxisTitles(Char_t* titleX="", Char_t* titleY="");
-  
-  void SaveHistograms();
-  void DrawHistograms();  
-
-  Bool_t  LoadHistograms(Char_t* fileName, Char_t* dir = ".");
-  
-  void    RemoveEdges(Float_t cut=2, Int_t nBinsX=0, Int_t nBinsY=0);
-  
-  Float_t GetCorrection(Float_t ax, Float_t ay) {return fhCorr->GetBinContent(fhCorr->FindBin(ax,ay));}
-  
-protected:
-  
-  TH2F*    fhMeas;  // histogram of measured particles (or tracks)
-  TH2F*    fhGene;  // histogram of generated particles
-
-  TH2F*    fhCorr;  // correction histogram (ratio generated/measured)
-
-  ClassDef(CorrectionMatrix2D,1)
-};
-
-#endif
-