Added get 1d correction and get 2d correction methods to AliCorrectionMatrix...
authorekman <ekman@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 12 Dec 2006 13:32:12 +0000 (13:32 +0000)
committerekman <ekman@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 12 Dec 2006 13:32:12 +0000 (13:32 +0000)
PWG0/AliCorrection.cxx
PWG0/AliCorrectionMatrix.cxx
PWG0/AliCorrectionMatrix2D.cxx
PWG0/AliCorrectionMatrix2D.h
PWG0/AliCorrectionMatrix3D.cxx
PWG0/AliCorrectionMatrix3D.h

index 314ab3a..a29dd0d 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <TFile.h>
 #include <TCanvas.h>
+#include <TH3F.h>
 #include <TH2F.h>
 
 #include <AliLog.h>
@@ -40,9 +41,15 @@ AliCorrection::AliCorrection(const Char_t* name, const Char_t* title) : TNamed(n
   //Float_t binLimitsVtx[] = {-20,-15,-10,-6,-3,0,3,6,10,15,20};
   //Float_t binLimitsVtx[] = {-20,-19,-18,-17,-16,-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
   Float_t binLimitsVtx[] = {-20,-15,-10,-8,-6,-4,-2,0,2,4,6,8,10,15,20};
+  Float_t binLimitsEta[] = {-2,-1.9,-1.8,-1.7,-1.6,-1.5,-1.4,-1.3,-1.2,-1.1,-1.0,-0.9,-0.8,-0.7,-0.6,-0.5,-0.4,-0.3,-0.2,-0.1,0.0,
+                           0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0};
+
+  TH3F* dummyBinning = new TH3F("","",14, binLimitsVtx, 40, binLimitsEta , 28, binLimitsPt);
 
   fEventCorr = new AliCorrectionMatrix2D("EventCorrection", Form("%s EventCorrection", title), 14, binLimitsVtx, 22, binLimitsN);
-  fTrackCorr = new AliCorrectionMatrix3D("TrackCorrection", Form("%s TrackCorrection", title), 14, binLimitsVtx, 40, -2, 2, 28, binLimitsPt);
+  fTrackCorr = new AliCorrectionMatrix3D("TrackCorrection", Form("%s TrackCorrection", title), dummyBinning);
+
+  delete dummyBinning;
 
   fEventCorr->SetAxisTitles("vtx z [cm]", "Ntracks");
   fTrackCorr->SetAxisTitles("vtx z [cm]", "#eta", "p_{T} [GeV/c]");
index 2407b4f..28061c3 100644 (file)
@@ -160,8 +160,16 @@ void AliCorrectionMatrix::Divide()
   // divides generated by measured to get the correction
   //
 
-  if (!fhMeas || !fhGene || !fhCorr)
+//   if (!fhCorr) {
+//     fhCorr = (TH1*)fhGene->Clone("correction");
+//     fhCorr->SetTitle(Form("%s correction",GetTitle()));
+//     fhCorr->Reset();
+//   }
+
+  if (!fhMeas || !fhGene || !fhCorr) {
+    AliDebug(AliLog::kError, "measured or generated histograms not available");
     return;
+  }
 
   fhCorr->Divide(fhGene, fhMeas, 1, 1, "B");
 
index cdb5307..c650d6f 100644 (file)
@@ -114,7 +114,7 @@ TH2F* AliCorrectionMatrix2D::GetMeasuredHistogram() const
 }
 
 //____________________________________________________________________
-TH1F* AliCorrectionMatrix2D::Get1DCorrection(Char_t* opt, Float_t min, Float_t max)
+TH1F* AliCorrectionMatrix2D::Get1DCorrectionHistogram(Char_t* opt, Float_t min, Float_t max)
 {
   //
   // integrate the correction over one variable 
@@ -124,33 +124,33 @@ TH1F* AliCorrectionMatrix2D::Get1DCorrection(Char_t* opt, Float_t min, Float_t m
   TH1D* gene1D = 0; 
 
   if (strcmp(opt,"x")==0) {
-    Int_t binMin = GetMeasuredHistogram()->GetYaxis()->FindBin(min);
-    Int_t binMax = GetMeasuredHistogram()->GetYaxis()->FindBin(max);
+    Int_t binMin = fhMeas->GetYaxis()->FindBin(min);
+    Int_t binMax = fhGene->GetYaxis()->FindBin(max);
 
-    if (min==0 && max==0) {
-      meas1D = GetMeasuredHistogram()->ProjectionX();
-      gene1D = GetGeneratedHistogram()->ProjectionX();
+    if (min>=max) {
+      meas1D = ((TH2F*)fhMeas)->ProjectionX();
+      gene1D = ((TH2F*)fhGene)->ProjectionX();
     }
     else {
       AliDebug(AliLog::kDebug+1, Form("Getting 1D map. Including y-bins %d to %d \n", binMin, binMax));
 
-      meas1D = GetMeasuredHistogram()->ProjectionX("pm",binMin,binMax);
-      gene1D = GetGeneratedHistogram()->ProjectionX("pg",binMin,binMax);
+      meas1D = ((TH2F*)fhMeas)->ProjectionX("pm",binMin,binMax);
+      gene1D = ((TH2F*)fhGene)->ProjectionX("pg",binMin,binMax);
     }
   }
   if (strcmp(opt,"y")==0) {
-    Int_t binMin = GetMeasuredHistogram()->GetXaxis()->FindBin(min);
-    Int_t binMax = GetMeasuredHistogram()->GetXaxis()->FindBin(max);
-
-    if (min==0 && max==0) {
-      meas1D = GetMeasuredHistogram()->ProjectionY();
-      gene1D = GetGeneratedHistogram()->ProjectionY();
+    Int_t binMin = fhMeas->GetXaxis()->FindBin(min);
+    Int_t binMax = fhMeas->GetXaxis()->FindBin(max);
+    
+    if (min>=max) {
+      meas1D = ((TH2F*)fhMeas)->ProjectionY();
+      gene1D = ((TH2F*)fhGene)->ProjectionY();
     }
     else {
       AliDebug(AliLog::kDebug+1, Form("Getting 1D map. Including x-bins %d to %d \n", binMin, binMax));
-
-      meas1D = GetMeasuredHistogram()->ProjectionY("pm", binMin, binMax);
-      gene1D = GetGeneratedHistogram()->ProjectionY("pg", binMin, binMax);
+      
+      meas1D = ((TH2F*)fhMeas)->ProjectionY("pm", binMin, binMax);
+      gene1D = ((TH2F*)fhGene)->ProjectionY("pg", binMin, binMax);
     }
   }
   gene1D->Sumw2();
@@ -167,14 +167,14 @@ TH1F* AliCorrectionMatrix2D::Get1DCorrection(Char_t* opt, Float_t min, Float_t m
 void AliCorrectionMatrix2D::FillMeas(Float_t ax, Float_t ay)
 {
   // add value to measured histogram
-  GetMeasuredHistogram()->Fill(ax, ay);
+  ((TH2F*)fhMeas)->Fill(ax, ay);
 }
 
 //____________________________________________________________________
 void AliCorrectionMatrix2D::FillGene(Float_t ax, Float_t ay)
 {
   // add value to generated histogram
-  GetGeneratedHistogram()->Fill(ax, ay);
+  ((TH2F*)fhGene)->Fill(ax, ay);
 }
 
 //____________________________________________________________________
index 6ffbace..9ee513f 100644 (file)
@@ -35,7 +35,9 @@ public:
   TH2F* GetMeasuredHistogram() const;
 
   TH2F* GetCorrectionHistogram() {return (TH2F*)fhCorr;}
-  TH1F* Get1DCorrection(Char_t* opt="x", Float_t min=0, Float_t max=0);
+
+  TH1F* Get1DCorrection(Char_t* opt="x", Float_t min=0, Float_t max=0) {return Get1DCorrectionHistogram(opt,min,max);}
+  TH1F* Get1DCorrectionHistogram(Char_t* opt="x", Float_t min=0, Float_t max=0);
 
   void FillMeas(Float_t ax, Float_t ay);
   void FillGene(Float_t ax, Float_t ay);
index 56ee055..d766724 100644 (file)
@@ -8,11 +8,14 @@
 //
 
 #include <TH3F.h>
+#include <TH2F.h>
 #include <TH1F.h>
+#include <TString.h>
 
 #include <AliLog.h>
 
 #include "AliCorrectionMatrix3D.h"
+#include "AliCorrectionMatrix2D.h"
 #include "AliPWG0Helper.h"
 
 //____________________________________________________________________
@@ -96,21 +99,32 @@ AliCorrectionMatrix3D::AliCorrectionMatrix3D(const Char_t* name, const Char_t* t
   delete[] binLimitsY;
 }
 
-AliCorrectionMatrix3D::AliCorrectionMatrix3D(const Char_t* name, const Char_t* title,
-      Int_t nBinX, const Float_t* xbins,
-      Int_t nBinY, Float_t Ymin, Float_t Ymax,
-      Int_t nBinZ, const Float_t* zbins)
+AliCorrectionMatrix3D::AliCorrectionMatrix3D(const Char_t* name, const Char_t* title, TH3F* hBinning)
   : AliCorrectionMatrix(name, title)
 {
-  // constructor with variable bin sizes
+  // constructor with variable bin sizes (uses binning of hBinning)
 
-  Float_t* binLimitsY = new Float_t[nBinY+1];
-  for (Int_t i=0; i<=nBinY; ++i)
-    binLimitsY[i] = Ymin + (Ymax - Ymin) / nBinY * i;
+  // do not add this hists to the directory
+  Bool_t oldStatus = TH1::AddDirectoryStatus();
+  TH1::AddDirectory(kFALSE);
 
-  CreateHists(nBinX, xbins, nBinY, binLimitsY, nBinZ, zbins);
+  fhMeas = (TH3F*)hBinning->Clone("measured");
+  fhGene = (TH3F*)hBinning->Clone("generated");
+  fhCorr = (TH3F*)hBinning->Clone("correction");
 
-  delete[] binLimitsY;
+  fhMeas->SetTitle(Form("%s measured",title)  );
+  fhGene->SetTitle(Form("%s generated",title ));
+  fhCorr->SetTitle(Form("%s correction",title));
+
+  fhMeas->Reset();
+  fhGene->Reset();
+  fhCorr->Reset();
+
+  TH1::AddDirectory(oldStatus);
+
+  fhMeas->Sumw2();
+  fhGene->Sumw2();
+  fhCorr->Sumw2();
 }
 
 //____________________________________________________________________
@@ -167,6 +181,86 @@ TH3F* AliCorrectionMatrix3D::GetCorrectionHistogram()
   return dynamic_cast<TH3F*> (fhCorr);
 }
 
+//____________________________________________________________________
+AliCorrectionMatrix2D* AliCorrectionMatrix3D::Get2DCorrection(Char_t* opt, Float_t aMin, Float_t aMax)
+{
+  // returns a 2D projection of this correction
+
+  TString option = opt;
+
+  if (aMin<aMax) {
+    if (option.Contains("xy") || option.Contains("yx")) {
+      Int_t bMin = fhMeas->GetZaxis()->FindBin(aMin);
+      Int_t bMax = fhMeas->GetZaxis()->FindBin(aMax);
+      fhMeas->GetZaxis()->SetRange(bMin, bMax);      
+    }
+    else if (option.Contains("xz") || option.Contains("zx")) {
+      Int_t bMin = fhMeas->GetYaxis()->FindBin(aMin);
+      Int_t bMax = fhMeas->GetYaxis()->FindBin(aMax);
+      fhMeas->GetYaxis()->SetRange(bMin, bMax);      
+    }
+    else if (option.Contains("yz") || option.Contains("zy")) {
+      Int_t bMin = fhMeas->GetXaxis()->FindBin(aMin);
+      Int_t bMax = fhMeas->GetXaxis()->FindBin(aMax);
+      fhMeas->GetXaxis()->SetRange(bMin, bMax);      
+    }
+    else {
+      AliDebug(AliLog::kWarning, Form("WARNING: unknown projection option %s", opt));
+      return 0;
+    }
+  }
+  AliCorrectionMatrix2D* corr2D = new AliCorrectionMatrix2D(Form("%s_%s",GetName(),opt),Form("%s projection %s",GetName(),opt),100,0,100,100,0,100);
+
+  TH2F* meas = (TH2F*) ((TH3F*)fhMeas)->Project3D(opt);
+  TH2F* gene = (TH2F*) ((TH3F*)fhGene)->Project3D(opt);
+
+  TH2F* corr = (TH2F*)gene->Clone("corr");
+  corr->Reset();
+
+  corr2D->SetGeneratedHistogram(gene);
+  corr2D->SetMeasuredHistogram(meas);
+  corr2D->SetCorrectionHistogram(corr);
+
+  corr2D->Divide();
+
+  // unzoom
+  fhMeas->GetXaxis()->UnZoom();  
+  fhMeas->GetYaxis()->UnZoom();  
+  fhMeas->GetZaxis()->UnZoom();  
+
+  fhGene->GetXaxis()->UnZoom();
+  fhGene->GetYaxis()->UnZoom();
+  fhGene->GetZaxis()->UnZoom();
+
+  return corr2D;
+}
+
+//____________________________________________________________________
+TH1F* AliCorrectionMatrix3D::Get1DCorrectionHistogram(Char_t* opt, Float_t aMin1, Float_t aMax1, Float_t aMin2, Float_t aMax2)
+{
+  // returns a 1D projection of this correction
+  AliDebug(AliLog::kWarning, Form("WARNING: test"));
+  
+  AliCorrectionMatrix2D* corr2D;
+  if (strcmp(opt,"x")==0) {  
+    corr2D = Get2DCorrection("xy",aMin1,aMax1);
+    return corr2D->Get1DCorrectionHistogram("x",aMin2,aMax2);
+  }
+  if (strcmp(opt,"y")==0) {
+    corr2D = Get2DCorrection("xy",aMin1,aMax1);
+    return corr2D->Get1DCorrectionHistogram("y",aMin2,aMax2);
+  }  
+  if (strcmp(opt,"z")==0) {
+    corr2D = Get2DCorrection("yz",aMin1,aMax1);    
+    return corr2D->Get1DCorrectionHistogram("x",aMin2,aMax2);
+  }  
+  AliDebug(AliLog::kWarning, Form("WARNING: unknown projection option %s (should be x,y or z)", opt));  
+  
+  return 0;
+}
+
+
+
 //____________________________________________________________________
 void AliCorrectionMatrix3D::FillMeas(Float_t ax, Float_t ay, Float_t az)
 {
index c8a1a5c..f1a2826 100644 (file)
 // ------------------------------------------------------
 
 #include <AliCorrectionMatrix.h>
+#include <AliCorrectionMatrix2D.h>
 
 class TH3F;
+class TH2F;
 class TH1F;
 
+
 class AliCorrectionMatrix3D : public AliCorrectionMatrix
 {
 public:
@@ -29,28 +32,24 @@ public:
          Int_t nBinY, Float_t Ymin, Float_t Ymax,
          Int_t nBinZ, const Float_t* zbins);
 
-  AliCorrectionMatrix3D(const Char_t* name, const Char_t* title,
-         Int_t nBinX, const Float_t* xbins,
-         Int_t nBinY, Float_t Ymin, Float_t Ymax,
-         Int_t nBinZ, const Float_t* zbins);
-
-  AliCorrectionMatrix3D(const Char_t* name, const Char_t* title,
-         Int_t nBinX, const Float_t* xbins,
-         Int_t nBinY, const Float_t* ybins,
-         Int_t nBinZ, const Float_t* zbins);
-
-  void CreateHists(Int_t nBinX, const Float_t* binLimitsX,
-         Int_t nBinY, const Float_t* binLimitsY,
-         Int_t nBinZ, const Float_t* binLimitsZ);
-
+  AliCorrectionMatrix3D(const Char_t* name, const Char_t* title, TH3F* hBinning);
   virtual ~AliCorrectionMatrix3D();
 
   AliCorrectionMatrix3D& operator= (const AliCorrectionMatrix3D& c);
 
+  void CreateHists(Int_t nBinX, const Float_t* binLimitsX,
+                  Int_t nBinY, const Float_t* binLimitsY,
+                  Int_t nBinZ, const Float_t* binLimitsZ);
+
   TH3F* GetGeneratedHistogram();
   TH3F* GetMeasuredHistogram();
   TH3F* GetCorrectionHistogram();
 
+  AliCorrectionMatrix2D* Get2DCorrection(Char_t* opt, Float_t aMin, Float_t aMax);
+  TH2F* Get2DCorrectionHistogram(Char_t* opt, Float_t aMin, Float_t aMax) {return Get2DCorrection(opt,aMin,aMax)->GetCorrectionHistogram();}
+  TH1F* Get1DCorrectionHistogram(Char_t* opt, Float_t aMins1, Float_t aMax1, Float_t aMins2, Float_t aMax2);
+
   void FillMeas(Float_t ax, Float_t ay, Float_t az);
   void FillGene(Float_t ax, Float_t ay, Float_t az);