More code clean up.
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / AliFMDCorrections.cxx
index bec656673806887e14d7e4b8195301789e8bb5bb..4db648a173954d99261832d72b7799f08e2c3925 100644 (file)
@@ -3,9 +3,13 @@
 #include <TAxis.h>
 #include <TList.h>
 #include <TMath.h>
 #include <TAxis.h>
 #include <TList.h>
 #include <TMath.h>
-#include "AliFMDAnaParameters.h"
+#include "AliForwardCorrectionManager.h"
+// #include "AliFMDAnaParameters.h"
 #include "AliLog.h"
 #include <TH2D.h>
 #include "AliLog.h"
 #include <TH2D.h>
+#include <TROOT.h>
+#include <iostream>
+#include <iomanip>
 
 ClassImp(AliFMDCorrections)
 #if 0
 
 ClassImp(AliFMDCorrections)
 #if 0
@@ -16,14 +20,14 @@ ClassImp(AliFMDCorrections)
 AliFMDCorrections::AliFMDCorrections()
   : TNamed(), 
     fRingHistos(),
 AliFMDCorrections::AliFMDCorrections()
   : TNamed(), 
     fRingHistos(),
-    fMultCut(0.3)
+    fDebug(0)
 {}
 
 //____________________________________________________________________
 AliFMDCorrections::AliFMDCorrections(const char* title)
   : TNamed("fmdCorrections", title), 
     fRingHistos(), 
 {}
 
 //____________________________________________________________________
 AliFMDCorrections::AliFMDCorrections(const char* title)
   : TNamed("fmdCorrections", title), 
     fRingHistos(), 
-    fMultCut(0.3)
+    fDebug(0)
 {
   fRingHistos.SetName(GetName());
   fRingHistos.Add(new RingHistos(1, 'I'));
 {
   fRingHistos.SetName(GetName());
   fRingHistos.Add(new RingHistos(1, 'I'));
@@ -37,7 +41,7 @@ AliFMDCorrections::AliFMDCorrections(const char* title)
 AliFMDCorrections::AliFMDCorrections(const AliFMDCorrections& o)
   : TNamed(o), 
     fRingHistos(), 
 AliFMDCorrections::AliFMDCorrections(const AliFMDCorrections& o)
   : TNamed(o), 
     fRingHistos(), 
-    fMultCut(o.fMultCut)
+    fDebug(o.fDebug)
 {
   TIter    next(&o.fRingHistos);
   TObject* obj = 0;
 {
   TIter    next(&o.fRingHistos);
   TObject* obj = 0;
@@ -54,11 +58,9 @@ AliFMDCorrections::~AliFMDCorrections()
 AliFMDCorrections&
 AliFMDCorrections::operator=(const AliFMDCorrections& o)
 {
 AliFMDCorrections&
 AliFMDCorrections::operator=(const AliFMDCorrections& o)
 {
-  SetName(o.GetName());
-  SetTitle(o.GetTitle());
-
-  fMultCut = o.fMultCut;
+  TNamed::operator=(o);
 
 
+  fDebug   = o.fDebug;
   fRingHistos.Delete();
   TIter    next(&o.fRingHistos);
   TObject* obj = 0;
   fRingHistos.Delete();
   TIter    next(&o.fRingHistos);
   TObject* obj = 0;
@@ -85,26 +87,30 @@ AliFMDCorrections::GetRingHistos(UShort_t d, Char_t r) const
 //____________________________________________________________________
 Bool_t
 AliFMDCorrections::Correct(AliForwardUtil::Histos& hists,
 //____________________________________________________________________
 Bool_t
 AliFMDCorrections::Correct(AliForwardUtil::Histos& hists,
-                          Int_t                   vtxbin)
+                          UShort_t                vtxbin)
 {
 {
-  AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
+  // AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
+  AliForwardCorrectionManager& fcm = AliForwardCorrectionManager::Instance();
 
 
+  UShort_t uvb = vtxbin;
   for (UShort_t d=1; d<=3; d++) { 
     UShort_t nr = (d == 1 ? 1 : 2);
     for (UShort_t q=0; q<nr; q++) { 
       Char_t      r = (q == 0 ? 'I' : 'O');
       TH2D*       h = hists.Get(d,r);
       RingHistos* rh= GetRingHistos(d,r);
   for (UShort_t d=1; d<=3; d++) { 
     UShort_t nr = (d == 1 ? 1 : 2);
     for (UShort_t q=0; q<nr; q++) { 
       Char_t      r = (q == 0 ? 'I' : 'O');
       TH2D*       h = hists.Get(d,r);
       RingHistos* rh= GetRingHistos(d,r);
-      TH2F*       bg= pars->GetBackgroundCorrection(d, r, vtxbin);
-      TH2F*       ef= pars->GetEventSelectionEfficiency("INEL",vtxbin,r);
+      //TH2F*       bg= pars->GetBackgroundCorrection(d, r, vtxbin);
+      //TH2F*       ef= pars->GetEventSelectionEfficiency("INEL",vtxbin,r);
+      TH2D* bg = fcm.GetSecondaryMap()->GetCorrection(d,r,uvb);
+      TH2D* ef = fcm.GetVertexBias()->GetCorrection(r, uvb);
       if (!bg) { 
        AliWarning(Form("No secondary correction for FMDM%d%c in vertex bin %d",
       if (!bg) { 
        AliWarning(Form("No secondary correction for FMDM%d%c in vertex bin %d",
-                       d, r, vtxbin));
+                       d, r, uvb));
        continue;
       }
       if (!ef) { 
        continue;
       }
       if (!ef) { 
-       AliWarning(Form("No event %s selection efficiency in vertex bin %d",
-                       "INEL", vtxbin));
+       AliWarning(Form("No event vertex bias correction in vertex bin %d",
+                       uvb));
        continue;
       }
 
        continue;
       }
 
@@ -114,12 +120,23 @@ AliFMDCorrections::Correct(AliForwardUtil::Histos& hists,
       // Divide by the event selection efficiency 
       h->Divide(ef);
 
       // Divide by the event selection efficiency 
       h->Divide(ef);
 
-      if(!pars->SharingEffPresent()) { 
-       AliWarning("No sharing efficiencies");
+      
+      // if(!pars->SharingEffPresent()) { 
+      //   AliWarning("No sharing efficiencies");
+      //   continue;
+      // }
+      // TH1F* sf = pars->GetSharingEfficiencyTrVtx(d,r,vtxbin); 
+      if (!fcm.GetMergingEfficiency()) { 
+       AliWarning("No merging efficiencies");
+       continue;
+      }
+      TH1D* sf = fcm.GetMergingEfficiency()->GetCorrection(d,r,uvb);
+      if (!fcm.GetMergingEfficiency()->GetCorrection(d,r,uvb)) { 
+       AliWarning(Form("No merging efficiency for FMD%d%c at vertex bin %d",
+                       d, r, uvb));
        continue;
       }
 
        continue;
       }
 
-      TH1F* sf = pars->GetSharingEfficiencyTrVtx(d,r,vtxbin); 
       
       for (Int_t ieta = 1; ieta <= h->GetNbinsX(); ieta++) {
        Float_t c  = sf->GetBinContent(ieta);
       
       for (Int_t ieta = 1; ieta <= h->GetNbinsX(); ieta++) {
        Float_t c  = sf->GetBinContent(ieta);
@@ -147,20 +164,20 @@ AliFMDCorrections::Correct(AliForwardUtil::Histos& hists,
 
 //____________________________________________________________________
 void
 
 //____________________________________________________________________
 void
-AliFMDCorrections::ScaleHistograms(Int_t nEvents)
+AliFMDCorrections::ScaleHistograms(TList* dir, Int_t nEvents)
 {
   if (nEvents <= 0) return;
 {
   if (nEvents <= 0) return;
+  TList* d = static_cast<TList*>(dir->FindObject(GetName()));
+  if (!d) return;
 
   TIter    next(&fRingHistos);
   RingHistos* o = 0;
 
   TIter    next(&fRingHistos);
   RingHistos* o = 0;
-  while ((o = static_cast<RingHistos*>(next()))) {
-    o->fDensity->Scale(1. / nEvents);
-  }
+  while ((o = static_cast<RingHistos*>(next())))
+    o->ScaleHistograms(d, nEvents);
 }
 }
-
 //____________________________________________________________________
 void
 //____________________________________________________________________
 void
-AliFMDCorrections::Output(TList* dir)
+AliFMDCorrections::DefineOutput(TList* dir)
 {
   TList* d = new TList;
   d->SetName(GetName());
 {
   TList* d = new TList;
   d->SetName(GetName());
@@ -172,17 +189,25 @@ AliFMDCorrections::Output(TList* dir)
   }
 }
 
   }
 }
 
+//____________________________________________________________________
+void
+AliFMDCorrections::Print(Option_t* /* option */) const
+{
+  char ind[gROOT->GetDirLevel()+1];
+  for (Int_t i = 0; i < gROOT->GetDirLevel(); i++) ind[i] = ' ';
+  ind[gROOT->GetDirLevel()] = '\0';
+  std::cout << ind << "AliFMDCorrections: " << GetName() <<  std::endl;
+}
+
 //====================================================================
 AliFMDCorrections::RingHistos::RingHistos()
 //====================================================================
 AliFMDCorrections::RingHistos::RingHistos()
-  : fDet(0),
-    fRing('\0'),
+  : AliForwardUtil::RingHistos(), 
     fDensity(0)
 {}
 
 //____________________________________________________________________
 AliFMDCorrections::RingHistos::RingHistos(UShort_t d, Char_t r)
     fDensity(0)
 {}
 
 //____________________________________________________________________
 AliFMDCorrections::RingHistos::RingHistos(UShort_t d, Char_t r)
-  : fDet(d), 
-    fRing(r),
+  : AliForwardUtil::RingHistos(d,r), 
     fDensity(0)
 {
   fDensity = new TH2D(Form("FMD%d%c_Primary_Density", d, r), 
     fDensity(0)
 {
   fDensity = new TH2D(Form("FMD%d%c_Primary_Density", d, r), 
@@ -196,9 +221,7 @@ AliFMDCorrections::RingHistos::RingHistos(UShort_t d, Char_t r)
 }
 //____________________________________________________________________
 AliFMDCorrections::RingHistos::RingHistos(const RingHistos& o)
 }
 //____________________________________________________________________
 AliFMDCorrections::RingHistos::RingHistos(const RingHistos& o)
-  : TObject(o), 
-    fDet(o.fDet), 
-    fRing(o.fRing),
+  : AliForwardUtil::RingHistos(o), 
     fDensity(o.fDensity)
 {}
 
     fDensity(o.fDensity)
 {}
 
@@ -206,8 +229,7 @@ AliFMDCorrections::RingHistos::RingHistos(const RingHistos& o)
 AliFMDCorrections::RingHistos&
 AliFMDCorrections::RingHistos::operator=(const RingHistos& o)
 {
 AliFMDCorrections::RingHistos&
 AliFMDCorrections::RingHistos::operator=(const RingHistos& o)
 {
-  fDet  = o.fDet;
-  fRing = o.fRing;
+  AliForwardUtil::RingHistos::operator=(o);
   
   if (fDensity) delete fDensity;
   
   
   if (fDensity) delete fDensity;
   
@@ -225,10 +247,19 @@ AliFMDCorrections::RingHistos::~RingHistos()
 void
 AliFMDCorrections::RingHistos::Output(TList* dir)
 {
 void
 AliFMDCorrections::RingHistos::Output(TList* dir)
 {
-  TList* d = new TList;
-  d->SetName(Form("FMD%d%c", fDet, fRing)); 
+  TList* d = DefineOutputList(dir);
   d->Add(fDensity);
   d->Add(fDensity);
-  dir->Add(d);
+}
+
+//____________________________________________________________________
+void
+AliFMDCorrections::RingHistos::ScaleHistograms(TList* dir, Int_t nEvents)
+{ 
+  TList* l = GetOutputList(dir);
+  if (!l) return; 
+
+  TH1* density = GetOutputHist(l,Form("%s_Primary_Density", fName.Data()));
+  if (density) density->Scale(1./nEvents);
 }
 
 //____________________________________________________________________
 }
 
 //____________________________________________________________________