adding offline triggers
authorjgrosseo <jgrosseo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 23 Feb 2009 15:18:45 +0000 (15:18 +0000)
committerjgrosseo <jgrosseo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 23 Feb 2009 15:18:45 +0000 (15:18 +0000)
updating track cuts
adding nsd corrections to multiplicity spectrum
additional plots for checks of real data

31 files changed:
PWG0/AliCorrection.cxx
PWG0/AliCorrectionMatrix2D.cxx
PWG0/AliCorrectionMatrix2D.h
PWG0/AliCorrectionMatrix3D.cxx
PWG0/AliCorrectionMatrix3D.h
PWG0/AliPWG0Helper.cxx
PWG0/AliPWG0Helper.h
PWG0/CreateStandardCuts.C
PWG0/dNdEta/AlidNdEtaCorrection.h
PWG0/dNdEta/AlidNdEtaCorrectionTask.cxx
PWG0/dNdEta/AlidNdEtaCorrectionTask.h
PWG0/dNdEta/AlidNdEtaTask.cxx
PWG0/dNdEta/AlidNdEtaTask.h
PWG0/dNdEta/correct.C
PWG0/dNdEta/dNdEtaAnalysis.cxx
PWG0/dNdEta/dNdEtaAnalysis.h
PWG0/dNdEta/drawPlots.C
PWG0/dNdEta/drawSystematics.C
PWG0/dNdEta/drawSystematicsNew.C
PWG0/dNdEta/run.C
PWG0/dNdEta/run.sh [new file with mode: 0755]
PWG0/dNdEta/systematicsAnalysis.C [deleted file]
PWG0/highMultiplicity/AliHighMultiplicitySelector.cxx
PWG0/highMultiplicity/AliHighMultiplicitySelector.h
PWG0/multiplicity/AliMultiplicityCorrection.cxx
PWG0/multiplicity/AliMultiplicityCorrection.h
PWG0/multiplicity/AliMultiplicityTask.cxx
PWG0/multiplicity/AliMultiplicityTask.h
PWG0/multiplicity/correct.C
PWG0/multiplicity/plots.C
PWG0/multiplicity/run.C

index 89843e7..4b9e9a7 100644 (file)
@@ -11,6 +11,7 @@
 #include <TCanvas.h>
 #include <TH3F.h>
 #include <TH2F.h>
+#include <TMath.h>
 
 #include <AliLog.h>
 #include "AliCorrectionMatrix2D.h"
@@ -59,10 +60,18 @@ AliCorrection::AliCorrection(const Char_t* name, const Char_t* title, AliPWG0Hel
     return;
   }
 
+  // third axis for track histogram
   Int_t nBinsN2 = 1;
   Float_t binLimitsN2[]   = {-0.5, 1000};
+  const char* title3 = "Ntracks";
   //Int_t nBinsN2 = 21;
   //Float_t binLimitsN2[]   = {-0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 12.5, 14.5, 16.5, 18.5, 20.5, 25.5, 30.5, 40.5, 50.5, 100.5, 1000.5};
+  // phi
+  //Int_t nBinsN2 = 36;
+  //Float_t binLimitsN2[]   = {0.000, 0.175, 0.349, 0.524, 0.698, 0.873, 1.047, 1.222, 1.396, 1.571, 1.745, 1.920, 2.094, 2.269, 2.443, 2.618, 2.793, 2.967, 3.142, 3.316, 3.491, 3.665, 3.840, 4.014, 4.189, 4.363, 4.538, 4.712, 4.887, 5.061, 5.236, 5.411, 5.585, 5.760, 5.934, 6.109, TMath::Pi() * 2};
+  //const char* title3 = "#phi";
+
+  // mult axis for event histogram
   Int_t nBinsN = 22;
   Float_t binLimitsN[]   = {-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 12.5, 14.5, 16.5, 18.5, 20.5, 25.5, 30.5, 40.5, 50.5, 100.5, 300.5};
   //Int_t nBinsN = 52;
@@ -71,12 +80,13 @@ AliCorrection::AliCorrection(const Char_t* name, const Char_t* title, AliPWG0Hel
   //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[] = {-30,-25,-20,-15,-10,-8,-6,-4,-2,0,2,4,6,8,10,15,20,25,30};
-  Float_t binLimitsEta[] = {-3.0,-2.8,-2.6,-2.4,-2.2,
+  /*Float_t binLimitsEta[] = {-3.0,-2.8,-2.6,-2.4,-2.2,
                             -2.0,-1.8,-1.6,-1.4,-1.2,
                             -1.0,-0.8,-0.6,-0.4,-0.2, 0.0,
                              0.2, 0.4, 0.6, 0.8, 1.0,
                              1.2, 1.4, 1.6, 1.8, 2.0,
-                             2.2, 2.4, 2.6, 2.8, 3.0};
+                             2.2, 2.4, 2.6, 2.8, 3.0};*/
+  Float_t binLimitsEta[] = { -3.0, -2.9, -2.8, -2.7, -2.6, -2.5, -2.4, -2.3, -2.2, -2.1, -2.0, -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, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0 };
 //  Float_t binLimitsEta[] = {-2,-1.8,-1.6,-1.4,-1.2,-1.0,-0.8,-0.6,-0.4,-0.2,0.0,0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.6,1.8,2.0};
 //  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};
 //  Float_t binLimitsEta[] = { -7.0, -6.9, -6.8, -6.7, -6.6, -6.5, -6.4, -6.3, -6.2, -6.1, -6.0, -5.9, -5.8, -5.7, -5.6, -5.5, -5.4, -5.3, -5.2, -5.1, -5.0, -4.9, -4.8, -4.7, -4.6, -4.5, -4.4, -4.3, -4.2, -4.1, -4.0, -3.9, -3.8, -3.7, -3.6, -3.5, -3.4, -3.3, -3.2, -3.1, -3.0, -2.9, -2.8, -2.7, -2.6, -2.5, -2.4, -2.3, -2.2, -2.1, -2.0, -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, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5.0, 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0, 6.1, 6.2, 6.3, 6.4, 6.5, 6.6, 6.7, 6.8, 6.9, 7.0 };
@@ -85,21 +95,21 @@ AliCorrection::AliCorrection(const Char_t* name, const Char_t* title, AliPWG0Hel
 
   if (analysisMode == AliPWG0Helper::kSPD)
   {
-    TH3F* dummyBinning = new TH3F("dummyBinning","dummyBinning",18, binLimitsVtx, 30, binLimitsEta, nBinsN2, binLimitsN2);
+    TH3F* dummyBinning = new TH3F("dummyBinning","dummyBinning",18, binLimitsVtx, 60, binLimitsEta, nBinsN2, binLimitsN2);
     fTrackCorr = new AliCorrectionMatrix3D("TrackCorrection", Form("%s TrackCorrection", fTitle.Data()), dummyBinning);
-    fTrackCorr->SetAxisTitles("vtx z [cm]", "#eta", "Ntracks");
+    fTrackCorr->SetAxisTitles("vtx-z (cm)", "#eta", title3);
     delete dummyBinning;
   }
   else
   {
-    TH3F* dummyBinning = new TH3F("dummyBinning","dummyBinning",18, binLimitsVtx, 30, binLimitsEta , nBinsPt, binLimitsPt);
+    TH3F* dummyBinning = new TH3F("dummyBinning","dummyBinning",18, binLimitsVtx, 60, binLimitsEta , nBinsPt, binLimitsPt);
     fTrackCorr = new AliCorrectionMatrix3D("TrackCorrection", Form("%s TrackCorrection", fTitle.Data()), dummyBinning);
-    fTrackCorr->SetAxisTitles("vtx z [cm]", "#eta", "p_{T} [GeV/c]");
+    fTrackCorr->SetAxisTitles("vtx-z (cm)", "#eta", "p_{T} (GeV/c)");
     delete dummyBinning;
   }
 
 
-  fEventCorr->SetAxisTitles("vtx z [cm]", "Ntracks");
+  fEventCorr->SetAxisTitles("vtx-z (cm)", "Ntracks");
 }
 
 //____________________________________________________________________
@@ -210,7 +220,7 @@ void AliCorrection::Divide()
   fEventCorr->Divide();
   fTrackCorr->Divide();
 
-  Int_t emptyBins = fTrackCorr->CheckEmptyBins(-9.99, 9.99, -0.79, 0.79, 0.3, 4.9);
+  Int_t emptyBins = fTrackCorr->CheckEmptyBins(-9.99, 9.99, -0.79, 0.79, 0.2, 4.9);
   printf("INFO: In the central region the track correction of %s has %d empty bins\n", GetName(), emptyBins);
 }
 
index 48d5ef5..be0bc76 100644 (file)
@@ -8,6 +8,7 @@
 //
 
 #include <TH2F.h>
+#include <TMath.h>
 
 #include <AliLog.h>
 
@@ -114,7 +115,7 @@ TH2* AliCorrectionMatrix2D::GetMeasuredHistogram() const
 }
 
 //____________________________________________________________________
-TH1* AliCorrectionMatrix2D::Get1DCorrectionHistogram(const Char_t* opt, Float_t min, Float_t max)
+TH1* AliCorrectionMatrix2D::Get1DCorrectionHistogram(const Char_t* opt, Float_t min, Float_t max, Bool_t binomialErrors)
 {
   //
   // integrate the correction over one variable 
@@ -158,15 +159,24 @@ TH1* AliCorrectionMatrix2D::Get1DCorrectionHistogram(const Char_t* opt, Float_t
     return 0;
   }
 
-  gene1D->Sumw2();
-
+  if (!binomialErrors)
+  {
+    // set the errors on gene manually, and clear the ones on meas.
+    gene1D->Sumw2();
+    for (Int_t bin=0; bin <= gene1D->GetNbinsX()+1; bin++)
+    {
+      gene1D->SetBinError(bin, TMath::Sqrt(gene1D->GetBinContent(bin)));
+      meas1D->SetBinError(bin, 0);
+    }
+  }
+  
   gene1D->SetName(Form("corr_1D_%s",fName.Data()));
   gene1D->SetTitle(Form("corr_1D_%s",fName.Data()));
  
   TH1* divided = (TH1*) gene1D->Clone(Form("corr_1D_%s",fName.Data()));
   divided->Reset();
-  divided->Divide(gene1D, meas1D, 1, 1, "B");
+  
+  divided->Divide(gene1D, meas1D, 1, 1, (binomialErrors) ? "B" : "");
 
   Printf("%p %p", gene1D, meas1D);
   
index 6326469..4449226 100644 (file)
@@ -37,7 +37,7 @@ public:
   TH2* GetCorrectionHistogram() {return (TH2*)fhCorr;}
 
   TH1* Get1DCorrection(const Char_t* opt="x", Float_t min=0, Float_t max=0) {return Get1DCorrectionHistogram(opt,min,max);}
-  TH1* Get1DCorrectionHistogram(const Char_t* opt="x", Float_t min=0, Float_t max=0);
+  TH1* Get1DCorrectionHistogram(const Char_t* opt="x", Float_t min=0, Float_t max=0, Bool_t binomialErrors = kFALSE);
 
   void Rebin(Int_t x = 1, Int_t y = 1);
 
index f025b92..a54424e 100644 (file)
@@ -12,6 +12,7 @@
 #include <TH2F.h>
 #include <TH3F.h>
 #include <TString.h>
+#include <TMath.h>
 
 #include <AliLog.h>
 
@@ -227,6 +228,14 @@ AliCorrectionMatrix2D* AliCorrectionMatrix3D::Get2DCorrection(Option_t* opt, Flo
 
   TH2F* meas = (TH2F*) ((TH3F*)fhMeas)->Project3D(option)->Clone(Form("%s_meas", corr2D->GetName()));
   TH2F* gene = (TH2F*) ((TH3F*)fhGene)->Project3D(option)->Clone(Form("%s_gene", corr2D->GetName()));
+  
+  // set errors
+  for (Int_t x = 0; x<=meas->GetNbinsX()+1; x++)
+    for (Int_t y = 0; y<=meas->GetNbinsY()+1; y++)
+    {
+      gene->SetBinError(x, y, TMath::Sqrt(gene->GetBinContent(x, y)));
+      meas->SetBinError(x, y, TMath::Sqrt(meas->GetBinContent(x, y)));
+    }
 
   TH2F* corr = (TH2F*)gene->Clone(Form("%s_corr", corr2D->GetName()));
   corr->Reset();
@@ -253,16 +262,15 @@ AliCorrectionMatrix2D* AliCorrectionMatrix3D::Get2DCorrection(Option_t* opt, Flo
 TH1* AliCorrectionMatrix3D::Get1DCorrectionHistogram(Option_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;
+  AliCorrectionMatrix2D* corr2D = 0;
   if (strcmp(opt,"x")==0) {
-    corr2D = Get2DCorrection("yx",aMin1,aMax1);
-    return corr2D->Get1DCorrectionHistogram("x",aMin2,aMax2);
+    corr2D = Get2DCorrection("yx",aMin2,aMax2);
+    return corr2D->Get1DCorrectionHistogram("x",aMin1,aMax1);
   }
   if (strcmp(opt,"y")==0) {
-    corr2D = Get2DCorrection("xy",aMin1,aMax1);
-    return corr2D->Get1DCorrectionHistogram("x",aMin2,aMax2);
+    corr2D = Get2DCorrection("xy",aMin2,aMax2);
+    return corr2D->Get1DCorrectionHistogram("x",aMin1,aMax1);
   }  
   if (strcmp(opt,"z")==0) {
     corr2D = Get2DCorrection("yz",aMin1,aMax1);
index ec65176..e27167c 100644 (file)
@@ -47,7 +47,7 @@ public:
   TH3* GetCorrectionHistogram();
 
   AliCorrectionMatrix2D* Get2DCorrection(Option_t* opt, Float_t aMin, Float_t aMax);
-  TH2* Get2DCorrectionHistogram(Option_t* opt, Float_t aMin, Float_t aMax) {return Get2DCorrection(opt,aMin,aMax)->GetCorrectionHistogram();}
+  TH2* Get2DCorrectionHistogram(Option_t* opt, Float_t aMin, Float_t aMax)     {return Get2DCorrection(opt,aMin,aMax)->GetCorrectionHistogram();}
   TH1* Get1DCorrectionHistogram(Option_t* opt, Float_t aMins1=0, Float_t aMax1=0, Float_t aMins2=0, Float_t aMax2=0);
 
   void FillMeas(Float_t ax, Float_t ay, Float_t az);
index 35b3683..ef7f859 100644 (file)
 #include <AliESDEvent.h>
 #include <AliESDVertex.h>
 #include <AliVertexerTracks.h>
+#include <AliMultiplicity.h>
 
 #include <AliGenEventHeader.h>
 #include <AliGenPythiaEventHeader.h>
 #include <AliGenCocktailEventHeader.h>
 #include <AliGenDPMjetEventHeader.h>
+#include <AliESDVZERO.h>
 
 //____________________________________________________________________
 ClassImp(AliPWG0Helper)
@@ -33,12 +35,77 @@ ClassImp(AliPWG0Helper)
 Int_t AliPWG0Helper::fgLastProcessType = -1;
 
 //____________________________________________________________________
-Bool_t AliPWG0Helper::IsEventTriggered(const AliESD* aEsd, Trigger trigger)
+Bool_t AliPWG0Helper::IsEventTriggered(const AliESDEvent* aEsd, Trigger trigger)
 {
-  // see function with ULong64_t argument
+  // checks if an event has been triggered
+  // this function implements the "offline" methods that use the ESD, other trigger requests are passed to the function prototype with ULong_t
 
-  ULong64_t triggerMask = aEsd->GetTriggerMask();
-  return IsEventTriggered(triggerMask, trigger);
+  Int_t firedChips = 0;
+  Bool_t v0A = kFALSE;
+  Bool_t v0C = kFALSE;
+
+  // offline triggers have to be dealt with here, because we need the esd pointer
+  if (trigger == kOfflineFASTOR || trigger == kOfflineMB1 || trigger == kOfflineMB2 || trigger == kOfflineMB3)
+  {
+      const AliMultiplicity* mult = aEsd->GetMultiplicity();
+      if (!mult)
+      {
+        Printf("AliPWG0Helper::IsEventTriggered: ERROR: AliMultiplicity not available");
+        return kFALSE;
+      }
+      firedChips = mult->GetNumberOfFiredChips(0) + mult->GetNumberOfFiredChips(1);
+  }
+  if (trigger == kOfflineMB1 || trigger == kOfflineMB2 || trigger == kOfflineMB3)
+  {
+    AliESDVZERO* v0Data = aEsd->GetVZEROData();
+    if (!v0Data)
+    {
+      Printf("AliPWG0Helper::IsEventTriggered: ERROR: AliESDVZERO not available");
+      return kFALSE;
+    }
+    for (Int_t i=0; i<32; i++)
+    {
+      if (v0Data->BBTriggerV0A(i))
+        v0A = kTRUE;
+      if (v0Data->BBTriggerV0C(i))
+        v0C = kTRUE;
+    }
+  }
+      
+  switch (trigger)
+  {
+    case kOfflineFASTOR:
+    {
+      if (firedChips > 0)
+        return kTRUE;
+      break;
+    }
+    case kOfflineMB1:
+    {
+      if ((firedChips > 0) || v0A || v0C)
+        return kTRUE;
+      break;
+    }
+    case kOfflineMB2:
+    {
+      if ((firedChips > 0) && (v0A || v0C))
+        return kTRUE;
+      break;
+    }
+    case kOfflineMB3:
+    {
+      if ((firedChips > 0) && v0A && v0C)
+        return kTRUE;
+      break;
+    }
+    default:
+    {
+      return IsEventTriggered(aEsd->GetTriggerMask(), trigger);
+      break;
+    }
+  }
+  
+  return kFALSE;
 }
 
 //____________________________________________________________________
@@ -50,8 +117,8 @@ Bool_t AliPWG0Helper::IsEventTriggered(ULong64_t triggerMask, Trigger trigger)
   
   // definitions from p-p.cfg
   ULong64_t spdFO = (1 << 14);
-  ULong64_t v0left = (1 << 11);
-  ULong64_t v0right = (1 << 12);
+  ULong64_t v0left = (1 << 10);
+  ULong64_t v0right = (1 << 11);
 
   switch (trigger)
   {
@@ -67,12 +134,21 @@ Bool_t AliPWG0Helper::IsEventTriggered(ULong64_t triggerMask, Trigger trigger)
         return kTRUE;
       break;
     }
+    case kMB3:
+    {
+      if (triggerMask & spdFO && (triggerMask & v0left) && (triggerMask & v0right))
+        return kTRUE;
+      break;
+    }
     case kSPDFASTOR:
     {
       if (triggerMask & spdFO)
         return kTRUE;
       break;
     }
+    default:
+      Printf("IsEventTriggered: ERROR: Trigger type %d not implemented in this method", (Int_t) trigger);
+      break;
   }
 
   return kFALSE;
@@ -104,7 +180,7 @@ Bool_t AliPWG0Helper::TestVertex(const AliESDVertex* vertex, AnalysisMode analys
 }
 
 //____________________________________________________________________
-const AliESDVertex* AliPWG0Helper::GetVertex(AliESDEvent* aEsd, AnalysisMode analysisMode, Bool_t debug,Bool_t bRedoTPC)
+const AliESDVertex* AliPWG0Helper::GetVertex(AliESDEvent* aEsd, AnalysisMode analysisMode, Bool_t debug, Bool_t bRedoTPC)
 {
   // Get the vertex from the ESD and returns it if the vertex is valid
   //
@@ -121,6 +197,8 @@ const AliESDVertex* AliPWG0Helper::GetVertex(AliESDEvent* aEsd, AnalysisMode ana
   else if (analysisMode == kTPC)
   {
     if(bRedoTPC){
+      if (debug)
+        Printf("AliPWG0Helper::GetVertex: Redoing vertex");
       Double_t kBz = aEsd->GetMagneticField();
       AliVertexerTracks vertexer(kBz);
       vertexer.SetTPCMode();
@@ -569,7 +647,12 @@ void AliPWG0Helper::PrintConf(AnalysisMode analysisMode, Trigger trigger)
   {
     case kMB1 : str += "MB1"; break;
     case kMB2 : str += "MB2"; break;
+    case kMB3 : str += "MB3"; break;
     case kSPDFASTOR : str += "SPD FASTOR"; break;
+    case kOfflineMB1 : str += "Offline MB1"; break;
+    case kOfflineMB2 : str += "Offline MB2"; break;
+    case kOfflineMB3 : str += "Offline MB3"; break;
+    case kOfflineFASTOR : str += "Offline SPD FASTOR"; break;
   }
 
   str += " <<<<";
index d3aaf39..ff7dde5 100644 (file)
@@ -7,7 +7,6 @@
 
 // static helper functions
 
-class AliESD;
 class AliESDEvent;
 class AliESDVertex;
 class TParticle;
@@ -22,14 +21,14 @@ class TTree;
 class AliPWG0Helper : public TObject
 {
   public:
-    enum Trigger { kMB1 = 0, kMB2, kSPDFASTOR }; // definition from ALICE-INT-2005-025
+    enum Trigger { kMB1 = 0, kMB2, kMB3, kSPDFASTOR, kOfflineMB1, kOfflineMB2, kOfflineMB3, kOfflineFASTOR }; // MB1, MB2, MB3 definition from ALICE-INT-2005-025
     enum AnalysisMode { kInvalid = -1, kSPD = 0, kTPC, kTPCITS };
     // in case we want to use bitmaps...
     enum MCProcessType { kInvalidProcess = -1, kND = 0x1, kDD = 0x2, kSD = 0x4 };
 
-    static Bool_t IsEventTriggered(const AliESD* aEsd, Trigger trigger = kMB2);
-    static Bool_t IsEventTriggered(ULong64_t triggerMask, Trigger trigger = kMB2);
-    static const AliESDVertex* GetVertex(AliESDEvent* aEsd, AnalysisMode analysisMethod, Bool_t debug = kFALSE,Bool_t bRedoTPC = false);
+    static Bool_t IsEventTriggered(const AliESDEvent* aEsd, Trigger trigger);
+    static Bool_t IsEventTriggered(ULong64_t triggerMask, Trigger trigger);
+    static const AliESDVertex* GetVertex(AliESDEvent* aEsd, AnalysisMode analysisMethod, Bool_t debug = kFALSE, Bool_t bRedoTPC = kFALSE);
     static Bool_t TestVertex(const AliESDVertex* vertex, AnalysisMode analysisMode, Bool_t debug = kFALSE);
 
     static Bool_t IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries, Bool_t adebug = kFALSE);
index b198f24..4640f8f 100644 (file)
@@ -25,9 +25,15 @@ AliESDtrackCuts* CreateTrackCuts(AliPWG0Helper::AnalysisMode analysisMode, Bool_
   // TPC-only cuts
   if (analysisMode == AliPWG0Helper::kTPC)
   {
+    cov1 = 9;
+    cov2 = 9;
+    cov3 = 1e10;
+    cov4 = 1e10;
+    cov5 = 1e10;
+    
     tpcRefit = kFALSE;
     sigmaToVertex = kFALSE;
-
+    
     tag = "TPC-only tracking";
   }
 
@@ -43,12 +49,13 @@ AliESDtrackCuts* CreateTrackCuts(AliPWG0Helper::AnalysisMode analysisMode, Bool_
   esdTrackCuts->SetRequireSigmaToVertex(sigmaToVertex);
 
   if (sigmaToVertex) {
-    esdTrackCuts->SetMinNsigmaToVertex(nSigma);
+    esdTrackCuts->SetMaxNsigmaToVertex(nSigma);
   }
   else{
-    //    esdTrackCuts->SetDCAToVertex(3.0);
-    esdTrackCuts->SetDCAToVertexZ(3.0);
-    esdTrackCuts->SetDCAToVertexXY(3.0);
+    
+    esdTrackCuts->SetMaxDCAToVertexZ(3.2);
+    esdTrackCuts->SetMaxDCAToVertexXY(2.4);
+    esdTrackCuts->SetDCAToVertex2D(kTRUE);
   }
 
   esdTrackCuts->SetRequireTPCRefit(tpcRefit);
index 46a6ad7..875a324 100644 (file)
@@ -11,9 +11,6 @@
 // ------------------------------------------------------
 //
 // TODO:
-// - make the ntrack to npart correction 3D
-// - add documentation
-// - add status: generate or use maps
 // - add functionality to set the bin sizes
 // - update MERge function
 //
index a167463..905814b 100644 (file)
@@ -2,7 +2,6 @@
 
 #include "AlidNdEtaCorrectionTask.h"
 
-#include <TROOT.h>
 #include <TCanvas.h>
 #include <TChain.h>
 #include <TFile.h>
 
 #include "AliESDtrackCuts.h"
 #include "AliPWG0Helper.h"
-//#include "AliCorrection.h"
-//#include "AliCorrectionMatrix3D.h"
 #include "dNdEta/dNdEtaAnalysis.h"
 #include "dNdEta/AlidNdEtaCorrection.h"
-#include "AliVertexerTracks.h"
 
 ClassImp(AlidNdEtaCorrectionTask)
 
@@ -42,8 +38,11 @@ AlidNdEtaCorrectionTask::AlidNdEtaCorrectionTask() :
   fOption(),
   fAnalysisMode(AliPWG0Helper::kTPC),
   fTrigger(AliPWG0Helper::kMB1),
+  fFillPhi(kFALSE),
+  fDeltaPhiCut(-1),
   fSignMode(0),
   fOnlyPrimaries(kFALSE),
+  fStatError(0),
   fEsdTrackCuts(0),
   fdNdEtaCorrection(0),
   fdNdEtaAnalysisMC(0),
@@ -59,6 +58,7 @@ AlidNdEtaCorrectionTask::AlidNdEtaCorrectionTask() :
   fEtaCorrelationShift(0),
   fEtaProfile(0),
   fEtaResolution(0),
+  fDeltaPhiCorrelation(0),
   fpTResolution(0),
   fEsdTrackCutsPrim(0),
   fEsdTrackCutsSec(0),
@@ -73,8 +73,8 @@ AlidNdEtaCorrectionTask::AlidNdEtaCorrectionTask() :
   // Constructor. Initialization of pointers
   //
 
-  for (Int_t i=0; i<2; i++)
-    fdNdEtaCorrectionProcessType[i] = 0;
+  for (Int_t i=0; i<4; i++)
+    fdNdEtaCorrectionSpecial[i] = 0;
   
   for (Int_t i=0; i<8; i++)
     fDeltaPhi[i] = 0;
@@ -87,8 +87,11 @@ AlidNdEtaCorrectionTask::AlidNdEtaCorrectionTask(const char* opt) :
   fOption(opt),
   fAnalysisMode(AliPWG0Helper::kTPC),
   fTrigger(AliPWG0Helper::kMB1),
+  fFillPhi(kFALSE),
+  fDeltaPhiCut(0),
   fSignMode(0),
   fOnlyPrimaries(kFALSE),
+  fStatError(0),
   fEsdTrackCuts(0),
   fdNdEtaCorrection(0),
   fdNdEtaAnalysisMC(0),
@@ -104,6 +107,7 @@ AlidNdEtaCorrectionTask::AlidNdEtaCorrectionTask(const char* opt) :
   fEtaCorrelationShift(0),
   fEtaProfile(0),
   fEtaResolution(0),
+  fDeltaPhiCorrelation(0),
   fpTResolution(0),
   fEsdTrackCutsPrim(0),
   fEsdTrackCutsSec(0),
@@ -122,8 +126,8 @@ AlidNdEtaCorrectionTask::AlidNdEtaCorrectionTask(const char* opt) :
   DefineInput(0, TChain::Class());
   DefineOutput(0, TList::Class());
 
-  for (Int_t i=0; i<2; i++)
-    fdNdEtaCorrectionProcessType[i] = 0;
+  for (Int_t i=0; i<4; i++)
+    fdNdEtaCorrectionSpecial[i] = 0;
   
   for (Int_t i=0; i<8; i++)
     fDeltaPhi[i] = 0;
@@ -188,6 +192,17 @@ void AlidNdEtaCorrectionTask::CreateOutputObjects()
     Printf("INFO: Processing only negative particles.");
     fSignMode = -1;
   }
+  
+  if (fOption.Contains("stat-error-1"))
+  {
+    Printf("INFO: Evaluation statistical errors. Mode: 1.");
+    fStatError = 1;
+  }
+  else if (fOption.Contains("stat-error-2"))
+  {
+    Printf("INFO: Evaluation statistical errors. Mode: 2.");
+    fStatError = 2;
+  }
 
   fOutput = new TList;
   fOutput->SetOwner();
@@ -216,19 +231,30 @@ void AlidNdEtaCorrectionTask::CreateOutputObjects()
   }
 
   if (fOption.Contains("process-types")) {
-    fdNdEtaCorrectionProcessType[0] = new AlidNdEtaCorrection("dndeta_correction_ND", "dndeta_correction_ND", fAnalysisMode);
-    fdNdEtaCorrectionProcessType[1] = new AlidNdEtaCorrection("dndeta_correction_SD", "dndeta_correction_SD", fAnalysisMode);
-    fdNdEtaCorrectionProcessType[2] = new AlidNdEtaCorrection("dndeta_correction_DD", "dndeta_correction_DD", fAnalysisMode);
+    fdNdEtaCorrectionSpecial[0] = new AlidNdEtaCorrection("dndeta_correction_ND", "dndeta_correction_ND", fAnalysisMode);
+    fdNdEtaCorrectionSpecial[1] = new AlidNdEtaCorrection("dndeta_correction_SD", "dndeta_correction_SD", fAnalysisMode);
+    fdNdEtaCorrectionSpecial[2] = new AlidNdEtaCorrection("dndeta_correction_DD", "dndeta_correction_DD", fAnalysisMode);
 
-    fOutput->Add(fdNdEtaCorrectionProcessType[0]);
-    fOutput->Add(fdNdEtaCorrectionProcessType[1]);
-    fOutput->Add(fdNdEtaCorrectionProcessType[2]);
+    fOutput->Add(fdNdEtaCorrectionSpecial[0]);
+    fOutput->Add(fdNdEtaCorrectionSpecial[1]);
+    fOutput->Add(fdNdEtaCorrectionSpecial[2]);
+  }
+  
+  if (fOption.Contains("particle-species")) {
+    fdNdEtaCorrectionSpecial[0] = new AlidNdEtaCorrection("dndeta_correction_pi", "dndeta_correction_pi", fAnalysisMode);
+    fdNdEtaCorrectionSpecial[1] = new AlidNdEtaCorrection("dndeta_correction_K", "dndeta_correction_K", fAnalysisMode);
+    fdNdEtaCorrectionSpecial[2] = new AlidNdEtaCorrection("dndeta_correction_p", "dndeta_correction_p", fAnalysisMode);
+    fdNdEtaCorrectionSpecial[3] = new AlidNdEtaCorrection("dndeta_correction_other", "dndeta_correction_other", fAnalysisMode);
+
+    for (Int_t i=0; i<4; i++)
+      fOutput->Add(fdNdEtaCorrectionSpecial[i]);
   }
 
+  
   /*
-  fTemp1 = new TH3F("fTemp1", "fTemp1 prim;b0;b1;1/pT", 200, 0, 10, 200, 0, 10, 200, 0, 10);
+  fTemp1 = new TH2F("fTemp1", "fTemp1", 200, -0.08, 0.08, 200, -0.08, 0.08);
   fOutput->Add(fTemp1);
-  fTemp2 = new TH3F("fTemp2", "fTemp2 sec;b0;b1;1/pT", 200, 0, 10, 200, 0, 10, 200, 0, 10);
+  fTemp2 = new TH1F("fTemp2", "fTemp2", 2000, -5, 5);
   fOutput->Add(fTemp2);
   */
 
@@ -245,14 +271,14 @@ void AlidNdEtaCorrectionTask::CreateOutputObjects()
 
   fEtaCorrelation = new TH2F("fEtaCorrelation", "fEtaCorrelation;MC #eta;ESD #eta", 120, -3, 3, 120, -3, 3);
   fOutput->Add(fEtaCorrelation);
-  fEtaCorrelationShift = new TH2F("fEtaCorrelationShift", "fEtaCorrelationShift;MC #eta - ESD #eta;ESD #eta", 120, -3, 3, 100, -0.1, 0.1);
+  fEtaCorrelationShift = new TH2F("fEtaCorrelationShift", "fEtaCorrelationShift;MC #eta;MC #eta - ESD #eta", 120, -3, 3, 100, -0.1, 0.1);
   fOutput->Add(fEtaCorrelationShift);
   fEtaProfile = new TProfile("fEtaProfile", "fEtaProfile;MC #eta;MC #eta - ESD #eta", 120, -3, 3);
   fOutput->Add(fEtaProfile);
   fEtaResolution = new TH1F("fEtaResolution", "fEtaResolution;MC #eta - ESD #eta", 201, -0.2, 0.2);
   fOutput->Add(fEtaResolution);
 
-  fpTResolution = new TH1F("fpTResolution", "fpTResolution;MC p_{T} - ESD p_{T}", 201, -0.2, 0.2);
+  fpTResolution = new TH2F("fpTResolution", ";MC p_{T} (GeV/c);(MC p_{T} - ESD p_{T}) / MC p_{T}", 160, 0, 20, 201, -0.2, 0.2);
   fOutput->Add(fpTResolution);
 
   fMultAll = new TH1F("fMultAll", "fMultAll", 500, -0.5, 499.5);
@@ -264,16 +290,20 @@ void AlidNdEtaCorrectionTask::CreateOutputObjects()
 
   for (Int_t i=0; i<8; i++)
   {
-    fDeltaPhi[i] = new TH1F(Form("fDeltaPhi_%d", i), ";#Delta phi;Entries", 2000, -0.1, 0.1);
+    fDeltaPhi[i] = new TH2F(Form("fDeltaPhi_%d", i), ";#Delta phi;#phi;Entries", 2000, -0.1, 0.1, 18 * 5, 0, TMath::TwoPi());
     fOutput->Add(fDeltaPhi[i]);
   }
 
-  fEventStats = new TH2F("fEventStats", "fEventStats;event type;status;count", 104, -3.5, 100.5, 4, -0.5, 3.5);
+  fEventStats = new TH2F("fEventStats", "fEventStats;event type;status;count", 106, -5.5, 100.5, 4, -0.5, 3.5);
   fOutput->Add(fEventStats);
-  fEventStats->GetXaxis()->SetBinLabel(1, "INEL"); // x = -3
-  fEventStats->GetXaxis()->SetBinLabel(2, "NSD");  // x = -2
+  fEventStats->GetXaxis()->SetBinLabel(1, "INEL"); // x = -5
+  fEventStats->GetXaxis()->SetBinLabel(2, "NSD");  // x = -4
+  fEventStats->GetXaxis()->SetBinLabel(3, "ND");   // x = -3
+  fEventStats->GetXaxis()->SetBinLabel(4, "SD");   // x = -2
+  fEventStats->GetXaxis()->SetBinLabel(5, "DD");   // x = -1
+  
   for (Int_t i=0; i<100; i++)
-    fEventStats->GetXaxis()->SetBinLabel(4+i, Form("%d", i)); 
+    fEventStats->GetXaxis()->SetBinLabel(7+i, Form("%d", i)); 
 
   fEventStats->GetYaxis()->SetBinLabel(1, "nothing");
   fEventStats->GetYaxis()->SetBinLabel(2, "trg");
@@ -300,16 +330,19 @@ void AlidNdEtaCorrectionTask::Exec(Option_t*)
 
   if (fOnlyPrimaries)
     Printf("WARNING: Processing only primaries. For systematical studies only!");
+    
+  if (fStatError > 0)
+    Printf("WARNING: Statistical error evaluation active!");
 
   // trigger definition
-  Bool_t eventTriggered = AliPWG0Helper::IsEventTriggered(fESD->GetTriggerMask(), fTrigger);
+  Bool_t eventTriggered = AliPWG0Helper::IsEventTriggered(fESD, fTrigger);
 
   if (!eventTriggered)
     Printf("No trigger");
 
   // post the data already here
   PostData(0, fOutput);
-
+  
   // MC info
   AliMCEventHandler* eventHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
   if (!eventHandler) {
@@ -351,7 +384,6 @@ void AlidNdEtaCorrectionTask::Exec(Option_t*)
 
   // get the ESD vertex
   const AliESDVertex* vtxESD = AliPWG0Helper::GetVertex(fESD, fAnalysisMode);
-
   Bool_t eventVertex = kFALSE;
   if (vtxESD)
   {
@@ -383,17 +415,24 @@ void AlidNdEtaCorrectionTask::Exec(Option_t*)
   // fill process type
   Int_t biny = (Int_t) eventTriggered + 2 * (Int_t) eventVertex;
   // INEL
-  fEventStats->Fill(-3, biny);
+  fEventStats->Fill(-5, biny);
   // NSD
   if (processType != AliPWG0Helper::kSD)
+    fEventStats->Fill(-4, biny);
+  // SD, ND, DD
+  if (processType == AliPWG0Helper::kND)
+    fEventStats->Fill(-3, biny);
+  if (processType == AliPWG0Helper::kSD)
     fEventStats->Fill(-2, biny);
-  
+  if (processType == AliPWG0Helper::kDD)
+    fEventStats->Fill(-1, biny);
+    
   // create list of (label, eta, pt) tuples
   Int_t inputCount = 0;
   Int_t* labelArr = 0;
   Int_t* labelArr2 = 0; // only for case of SPD
   Float_t* etaArr = 0;
-  Float_t* ptArr = 0;
+  Float_t* thirdDimArr = 0;
   Float_t* deltaPhiArr = 0;
   if (fAnalysisMode == AliPWG0Helper::kSPD)
   {
@@ -408,7 +447,7 @@ void AlidNdEtaCorrectionTask::Exec(Option_t*)
     labelArr = new Int_t[mult->GetNumberOfTracklets()];
     labelArr2 = new Int_t[mult->GetNumberOfTracklets()];
     etaArr = new Float_t[mult->GetNumberOfTracklets()];
-    ptArr = new Float_t[mult->GetNumberOfTracklets()];
+    thirdDimArr = new Float_t[mult->GetNumberOfTracklets()];
     deltaPhiArr = new Float_t[mult->GetNumberOfTracklets()];
 
     // get multiplicity from SPD tracklets
@@ -416,12 +455,10 @@ void AlidNdEtaCorrectionTask::Exec(Option_t*)
     {
       //printf("%d %f %f %f\n", i, mult->GetTheta(i), mult->GetPhi(i), mult->GetDeltaPhi(i));
 
+      Float_t phi = mult->GetPhi(i);
+      if (phi < 0)
+        phi += TMath::Pi() * 2;
       Float_t deltaPhi = mult->GetDeltaPhi(i);
-      // prevent values to be shifted by 2 Pi()
-      if (deltaPhi < -TMath::Pi())
-        deltaPhi += TMath::Pi() * 2;
-      if (deltaPhi > TMath::Pi())
-        deltaPhi -= TMath::Pi() * 2;
 
       if (TMath::Abs(deltaPhi) > 1)
         printf("WARNING: Very high Delta Phi: %d %f %f %f\n", i, mult->GetTheta(i), mult->GetPhi(i), deltaPhi);
@@ -430,10 +467,13 @@ void AlidNdEtaCorrectionTask::Exec(Option_t*)
         if (mult->GetLabel(i, 0) < 0 || mult->GetLabel(i, 0) != mult->GetLabel(i, 1) || !stack->IsPhysicalPrimary(mult->GetLabel(i, 0)))
           continue;
 
+      if (fDeltaPhiCut > 0 && TMath::Abs(deltaPhi) > fDeltaPhiCut)
+        continue;
+      
       etaArr[inputCount] = mult->GetEta(i);
       labelArr[inputCount] = mult->GetLabel(i, 0);
       labelArr2[inputCount] = mult->GetLabel(i, 1);
-      ptArr[inputCount] = 0; // no pt for tracklets
+      thirdDimArr[inputCount] = phi;
       deltaPhiArr[inputCount] = deltaPhi;
       ++inputCount;
     }
@@ -446,107 +486,100 @@ void AlidNdEtaCorrectionTask::Exec(Option_t*)
       return;
     }
 
-    // get multiplicity from ESD tracks
-    TObjArray* list = fEsdTrackCuts->GetAcceptedTracks(fESD, (fAnalysisMode == AliPWG0Helper::kTPC));
-    Int_t nGoodTracks = list->GetEntries();
-
-    Printf("Accepted %d tracks", nGoodTracks);
-
-    labelArr = new Int_t[nGoodTracks];
-    labelArr2 = new Int_t[nGoodTracks];
-    etaArr = new Float_t[nGoodTracks];
-    ptArr = new Float_t[nGoodTracks];
-    deltaPhiArr = new Float_t[nGoodTracks];
-
-    // loop over esd tracks
-    for (Int_t i=0; i<nGoodTracks; i++)
-    {
-      AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*> (list->At(i));
-      if (!esdTrack)
-      {
-        AliDebug(AliLog::kError, Form("ERROR: Could not retrieve track %d.", i));
-        continue;
-      }
-
-      etaArr[inputCount] = esdTrack->Eta();
-      labelArr[inputCount] = TMath::Abs(esdTrack->GetLabel());
-      labelArr2[inputCount] = labelArr[inputCount]; // no second label for tracks
-      ptArr[inputCount] = esdTrack->Pt();
-      deltaPhiArr[inputCount] = 0; // no delta phi for tracks
-      ++inputCount;
-    }
-
-    delete list;
-
-    if (eventTriggered && vtxESD)
+    if (vtxESD)
     {
-      // collect values for primaries and secondaries
-      for (Int_t iTrack = 0; iTrack < fESD->GetNumberOfTracks(); iTrack++)
+      // get multiplicity from ESD tracks
+      TObjArray* list = fEsdTrackCuts->GetAcceptedTracks(fESD, (fAnalysisMode == AliPWG0Helper::kTPC));
+      Int_t nGoodTracks = list->GetEntries();
+  
+      Printf("Accepted %d tracks", nGoodTracks);
+  
+      labelArr = new Int_t[nGoodTracks];
+      labelArr2 = new Int_t[nGoodTracks];
+      etaArr = new Float_t[nGoodTracks];
+      thirdDimArr = new Float_t[nGoodTracks];
+      deltaPhiArr = new Float_t[nGoodTracks];
+
+      // loop over esd tracks
+      for (Int_t i=0; i<nGoodTracks; i++)
       {
-        AliESDtrack* track = 0;
-
-        if (fAnalysisMode == AliPWG0Helper::kTPC)
-          track = AliESDtrackCuts::GetTPCOnlyTrack(fESD, iTrack);
-        else if (fAnalysisMode == AliPWG0Helper::kTPCITS)
-          track = fESD->GetTrack(iTrack);
-
-        if (!track)
-          continue;
-
-        Int_t label = TMath::Abs(track->GetLabel());
-        if (!stack->Particle(label) || !stack->Particle(label)->GetPDG())
+        AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*> (list->At(i));
+        if (!esdTrack)
         {
-          Printf("WARNING: No particle for %d", label);
-          if (stack->Particle(label))
-            stack->Particle(label)->Print();
+          AliDebug(AliLog::kError, Form("ERROR: Could not retrieve track %d.", i));
           continue;
         }
+        
+        // TODO fOnlyPrimaries not implemented for TPC
+  
+        etaArr[inputCount] = esdTrack->Eta();
+        labelArr[inputCount] = TMath::Abs(esdTrack->GetLabel());
+        labelArr2[inputCount] = labelArr[inputCount]; // no second label for tracks
+        thirdDimArr[inputCount] = esdTrack->Pt();
+        deltaPhiArr[inputCount] = 0; // no delta phi for tracks
+        ++inputCount;
+      }
 
-        if (stack->Particle(label)->GetPDG()->Charge() == 0)
-          continue;
+      delete list;
 
-        if (stack->IsPhysicalPrimary(label))
+      if (eventTriggered)
+      {
+        // collect values for primaries and secondaries
+        for (Int_t iTrack = 0; iTrack < fESD->GetNumberOfTracks(); iTrack++)
         {
-          // primary
-          if (fEsdTrackCutsPrim->AcceptTrack(track)) {
-            if (track->Pt() > 0) {
-              Float_t b0, b1;
-              track->GetImpactParameters(b0, b1);
-              if (fTemp1)
-                ((TH3*) fTemp1)->Fill(b0, b1, 1.0 / track->Pt());
-              //fTemp1->Fill(TMath::Sqrt(b0*b0 + b1*b1), 1.0 / track->Pt());
-            }
-
-            if (AliESDtrackCuts::GetSigmaToVertex(track) > 900)
+          AliESDtrack* track = 0;
+  
+          if (fAnalysisMode == AliPWG0Helper::kTPC)
+            track = AliESDtrackCuts::GetTPCOnlyTrack(fESD, iTrack);
+          else if (fAnalysisMode == AliPWG0Helper::kTPCITS)
+            track = fESD->GetTrack(iTrack);
+  
+          if (!track)
+            continue;
+  
+          Int_t label = TMath::Abs(track->GetLabel());
+          if (!stack->Particle(label) || !stack->Particle(label)->GetPDG())
+          {
+            Printf("WARNING: No particle for %d", label);
+            if (stack->Particle(label))
+              stack->Particle(label)->Print();
+            continue;
+          }
+  
+          if (stack->Particle(label)->GetPDG()->Charge() == 0)
+            continue;
+  
+          if (TMath::Abs(track->Eta()) < 1)
+          {
+            if (stack->IsPhysicalPrimary(label))
             {
-              Printf("Track %d has nsigma of %f. Printing track and vertex...", iTrack, AliESDtrackCuts::GetSigmaToVertex(track));
-              Float_t b[2];
-              Float_t r[3];
-              track->GetImpactParameters(b, r);
-              Printf("Impact parameter %f %f and resolution: %f %f %f", b[0], b[1], r[0], r[1], r[2]);
-              track->Print("");
-              if (vtxESD)
-                vtxESD->Print();
+              // primary
+              if (fEsdTrackCutsPrim->AcceptTrack(track)) 
+              {
+                if (AliESDtrackCuts::GetSigmaToVertex(track) > 900)
+                {
+                  Printf("Track %d has nsigma of %f. Printing track and vertex...", iTrack, AliESDtrackCuts::GetSigmaToVertex(track));
+                  Float_t b[2];
+                  Float_t r[3];
+                  track->GetImpactParameters(b, r);
+                  Printf("Impact parameter %f %f and resolution: %f %f %f", b[0], b[1], r[0], r[1], r[2]);
+                  track->Print("");
+                  if (vtxESD)
+                    vtxESD->Print();
+                }
+              }
             }
-          }
-        }
-        else
-        {
-          // secondary
-          if (fEsdTrackCutsSec->AcceptTrack(track))  {
-            if (track->Pt() > 0) {
-              Float_t b0, b1;
-              track->GetImpactParameters(b0, b1);
-              if (fTemp2)
-                ((TH3*) fTemp2)->Fill(b0, b1, 1.0 / track->Pt());
-              //fTemp2->Fill(TMath::Sqrt(b0*b0 + b1*b1), 1.0 / track->Pt());
+            else
+            {
+              // secondary
+              fEsdTrackCutsSec->AcceptTrack(track);
             }
           }
+  
+          // TODO mem leak in the continue statements above
+          if (fAnalysisMode == AliPWG0Helper::kTPC)
+            delete track;
         }
-
-        // TODO mem leak in the continue statements above
-        if (fAnalysisMode == AliPWG0Helper::kTPC)
-          delete track;
       }
     }
   }
@@ -579,23 +612,53 @@ void AlidNdEtaCorrectionTask::Exec(Option_t*)
       fPIDParticles->Fill(particle->GetPdgCode());
 
     Float_t eta = particle->Eta();
-    Float_t thirdDim = (fAnalysisMode == AliPWG0Helper::kSPD) ? inputCount : particle->Pt();
+    
+    Float_t thirdDim = -1;
+    if (fAnalysisMode == AliPWG0Helper::kSPD)
+    {
+      if (fFillPhi)
+      {
+        thirdDim = particle->Phi();
+      }
+      else
+        thirdDim = inputCount;
+    }
+    else
+      thirdDim = particle->Pt();
+
+    // calculate y
+    //Float_t y = 0.5 * TMath::Log((particle->Energy() + particle->Pz()) / (particle->Energy() - particle->Pz()));
+    //fTemp1->Fill(eta);
+    //fTemp2->Fill(y);
 
     fdNdEtaCorrection->FillMCParticle(vtxMC[2], eta, thirdDim, eventTriggered, eventVertex, processType);
 
-    if (fdNdEtaCorrectionProcessType[0])
+    if (fOption.Contains("process-types"))
     {
       // non diffractive
       if (processType==AliPWG0Helper::kND)
-        fdNdEtaCorrectionProcessType[0]->FillMCParticle(vtxMC[2], eta, thirdDim, eventTriggered, eventVertex, processType);
+        fdNdEtaCorrectionSpecial[0]->FillMCParticle(vtxMC[2], eta, thirdDim, eventTriggered, eventVertex, processType);
 
       // single diffractive
       if (processType==AliPWG0Helper::kSD)
-        fdNdEtaCorrectionProcessType[1]->FillMCParticle(vtxMC[2], eta, thirdDim, eventTriggered, eventVertex, processType);
+        fdNdEtaCorrectionSpecial[1]->FillMCParticle(vtxMC[2], eta, thirdDim, eventTriggered, eventVertex, processType);
 
       // double diffractive
       if (processType==AliPWG0Helper::kDD)
-        fdNdEtaCorrectionProcessType[2]->FillMCParticle(vtxMC[2], eta, thirdDim, eventTriggered, eventVertex, processType);
+        fdNdEtaCorrectionSpecial[2]->FillMCParticle(vtxMC[2], eta, thirdDim, eventTriggered, eventVertex, processType);
+    }
+    
+    if (fOption.Contains("particle-species"))
+    {
+      Int_t id = -1;
+      switch (TMath::Abs(particle->GetPdgCode()))
+      {
+        case 211:   id = 0; break;
+        case 321:   id = 1; break;
+        case 2212:  id = 2; break;
+        default:    id = 3; break;
+      }
+      fdNdEtaCorrectionSpecial[id]->FillMCParticle(vtxMC[2], eta, thirdDim, eventTriggered, eventVertex, processType);
     }
 
     if (eventTriggered)
@@ -607,8 +670,7 @@ void AlidNdEtaCorrectionTask::Exec(Option_t*)
       nAccepted++;
   }
 
-  if (nAccepted == 0)
-    fEventStats->Fill(AliPWG0Helper::GetLastProcessType(), biny);
+  fEventStats->Fill(AliPWG0Helper::GetLastProcessType(), biny);
 
   fMultAll->Fill(nAccepted);
   if (eventTriggered) {
@@ -618,6 +680,14 @@ void AlidNdEtaCorrectionTask::Exec(Option_t*)
   }
 
   Int_t processed = 0;
+  
+  Bool_t* primCount = 0;
+  if (fStatError > 0)
+  {
+    primCount = new Bool_t[nPrim];
+    for (Int_t i=0; i<nPrim; ++i)
+      primCount[i] = kFALSE;
+  }
 
   for (Int_t i=0; i<inputCount; ++i)
   {
@@ -671,7 +741,10 @@ void AlidNdEtaCorrectionTask::Exec(Option_t*)
 
       // resolutions
       fEtaResolution->Fill(particle->Eta() - etaArr[i]);
-      fpTResolution->Fill(particle->Pt() - ptArr[i]);
+
+      if (fAnalysisMode == AliPWG0Helper::kTPC || fAnalysisMode == AliPWG0Helper::kTPCITS)
+        if (TMath::Abs(particle->Eta() < 0.9) && particle->Pt() > 0)
+          fpTResolution->Fill(particle->Pt(), (particle->Pt() - thirdDimArr[i]) / particle->Pt());
 
       Float_t eta = -999;
       Float_t thirdDim = -1;
@@ -680,57 +753,106 @@ void AlidNdEtaCorrectionTask::Exec(Option_t*)
       // in case of primary the MC values are filled, otherwise (background) the reconstructed values
       if (label == label2 && firstIsPrim)
       {
-        thirdDim = particle->Pt();
         eta = particle->Eta();
+        
+        if (fAnalysisMode == AliPWG0Helper::kSPD)
+        {
+          if (fFillPhi)
+          {
+            thirdDim = particle->Phi();
+          }
+          else
+            thirdDim = inputCount;
+        }
+        else
+          thirdDim = particle->Pt();
       }
       else
       {
-        thirdDim = ptArr[i];
+        if (fAnalysisMode == AliPWG0Helper::kSPD && !fFillPhi)
+        {
+          thirdDim = inputCount;
+        }
+        else
+          thirdDim = thirdDimArr[i];
+
         eta = etaArr[i];
       }
 
-      if (fAnalysisMode == AliPWG0Helper::kSPD)
-        thirdDim = inputCount;
+      Bool_t fillTrack = kTRUE;
 
-      fdNdEtaCorrection->FillTrackedParticle(vtxMC[2], eta, thirdDim);
+      // statistical error evaluation active?
+      if (fStatError > 0)
+      {
+        Bool_t statErrorDecision = kFALSE;
+        
+        // primary and not yet counted
+        if (label == label2 && firstIsPrim && !primCount[label])
+        {
+          statErrorDecision = kTRUE;
+          primCount[label] = kTRUE;
+        }
+  
+        // in case of 1 we count only unique primaries, in case of 2 all the rest
+        if (fStatError == 1)
+        {
+          fillTrack = statErrorDecision;
+        }
+        else if (fStatError == 2)
+          fillTrack = !statErrorDecision;
+      }
+
+      if (fillTrack)
+        fdNdEtaCorrection->FillTrackedParticle(vtxMC[2], eta, thirdDim);
 
       // eta comparison for tracklets with the same label (others are background)
       if (label == label2)
       {
         fEtaProfile->Fill(particle->Eta(), particle->Eta() - etaArr[i]);
         fEtaCorrelation->Fill(etaArr[i], particle->Eta());
-        fEtaCorrelationShift->Fill(etaArr[i], particle->Eta() - etaArr[i]);
+        fEtaCorrelationShift->Fill(particle->Eta(), particle->Eta() - etaArr[i]);
       }
 
       fdNdEtaAnalysisESD->FillTrack(vtxMC[2], particle->Eta(), thirdDim);
 
-      if (particle->Pt() > 0.1 && particle->Pt() < 0.2)
-      {
-        fPIDTracks->Fill(particle->GetPdgCode());
-      }
-
-      if (fdNdEtaCorrectionProcessType[0])
+      if (fOption.Contains("process-types"))
       {
         // non diffractive
         if (processType == AliPWG0Helper::kND)
-          fdNdEtaCorrectionProcessType[0]->FillTrackedParticle(vtxMC[2], eta, thirdDim);
+          fdNdEtaCorrectionSpecial[0]->FillTrackedParticle(vtxMC[2], eta, thirdDim);
 
         // single diffractive
         if (processType == AliPWG0Helper::kSD)
-          fdNdEtaCorrectionProcessType[1]->FillTrackedParticle(vtxMC[2], eta, thirdDim);
+          fdNdEtaCorrectionSpecial[1]->FillTrackedParticle(vtxMC[2], eta, thirdDim);
 
         // double diffractive
         if (processType == AliPWG0Helper::kDD)
-          fdNdEtaCorrectionProcessType[2]->FillTrackedParticle(vtxMC[2], eta, thirdDim);
+          fdNdEtaCorrectionSpecial[2]->FillTrackedParticle(vtxMC[2], eta, thirdDim);
+      }
+
+      if (fOption.Contains("particle-species"))
+      {
+        // find mother first
+        TParticle* mother = AliPWG0Helper::FindPrimaryMother(stack, label);
+        
+        Int_t id = -1;
+        switch (TMath::Abs(mother->GetPdgCode()))
+        {
+          case 211:   id = 0; break;
+          case 321:   id = 1; break;
+          case 2212:  id = 2; break;
+          default:    id = 3; break;
+        }
+        fdNdEtaCorrectionSpecial[id]->FillTrackedParticle(vtxMC[2], eta, thirdDim);
       }
 
       // control histograms
       Int_t hist = -1;
       if (label == label2)
       {
-       if (firstIsPrim)
+        if (firstIsPrim)
         {
-         hist = 0;
+          hist = 0;
         }
         else
           hist = 1; 
@@ -745,7 +867,7 @@ void AlidNdEtaCorrectionTask::Exec(Option_t*)
         else if (firstIsPrim && !secondIsPrim)
         {
           hist = 3;
-         
+
           // check if secondary is caused by the primary or it is a fake combination
           //Printf("PS case --> Label 1 is %d, label 2 is %d", label, label2);
           Int_t mother = label2;
@@ -777,9 +899,15 @@ void AlidNdEtaCorrectionTask::Exec(Option_t*)
       else
         hist = 7;
       
-      fDeltaPhi[hist]->Fill(deltaPhiArr[i]);
+      fDeltaPhi[hist]->Fill(deltaPhiArr[i], thirdDimArr[i]);
     }
   }
+  
+  if (primCount)
+  {
+    delete[] primCount;
+    primCount = 0;
+  }
 
   if (processed < inputCount)
     Printf("Only %d out of %d track(let)s were used", processed, inputCount); 
@@ -793,26 +921,35 @@ void AlidNdEtaCorrectionTask::Exec(Option_t*)
    // stuff regarding the vertex reco correction and trigger bias correction
   fdNdEtaCorrection->FillEvent(vtxMC[2], inputCount, eventTriggered, eventVertex, processType);
 
-  if (fdNdEtaCorrectionProcessType[0])
+  if (fOption.Contains("process-types"))
   {
     // non diffractive
     if (processType == AliPWG0Helper::kND )
-      fdNdEtaCorrectionProcessType[0]->FillEvent(vtxMC[2], inputCount, eventTriggered, eventVertex, processType);
+      fdNdEtaCorrectionSpecial[0]->FillEvent(vtxMC[2], inputCount, eventTriggered, eventVertex, processType);
 
     // single diffractive
     if (processType == AliPWG0Helper::kSD)
-      fdNdEtaCorrectionProcessType[1]->FillEvent(vtxMC[2], inputCount, eventTriggered, eventVertex, processType);
+      fdNdEtaCorrectionSpecial[1]->FillEvent(vtxMC[2], inputCount, eventTriggered, eventVertex, processType);
 
     // double diffractive
     if (processType == AliPWG0Helper::kDD)
-      fdNdEtaCorrectionProcessType[2]->FillEvent(vtxMC[2], inputCount, eventTriggered, eventVertex, processType);
+      fdNdEtaCorrectionSpecial[2]->FillEvent(vtxMC[2], inputCount, eventTriggered, eventVertex, processType);
   }
-
-  delete[] etaArr;
-  delete[] labelArr;
-  delete[] labelArr2;
-  delete[] ptArr;
-  delete[] deltaPhiArr;
+  
+  if (fOption.Contains("particle-species"))
+    for (Int_t id=0; id<4; id++)
+      fdNdEtaCorrectionSpecial[id]->FillEvent(vtxMC[2], inputCount, eventTriggered, eventVertex, processType);
+
+  if (etaArr)
+    delete[] etaArr;
+  if (labelArr)
+    delete[] labelArr;
+  if (labelArr2)
+    delete[] labelArr2;
+  if (thirdDimArr)
+    delete[] thirdDimArr;
+  if (deltaPhiArr)
+    delete[] deltaPhiArr;
 }
 
 void AlidNdEtaCorrectionTask::Terminate(Option_t *)
@@ -858,12 +995,22 @@ void AlidNdEtaCorrectionTask::Terminate(Option_t *)
   fdNdEtaAnalysisMC->SaveHistograms();
   fdNdEtaAnalysisESD->SaveHistograms();
 
-  fdNdEtaCorrectionProcessType[0] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_ND"));
-  fdNdEtaCorrectionProcessType[1] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_SD"));
-  fdNdEtaCorrectionProcessType[2] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_DD"));
-  for (Int_t i=0; i<3; ++i)
-    if (fdNdEtaCorrectionProcessType[i])
-      fdNdEtaCorrectionProcessType[i]->SaveHistograms();
+  if (fOutput->FindObject("dndeta_correction_ND"))
+  {
+    fdNdEtaCorrectionSpecial[0] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_ND"));
+    fdNdEtaCorrectionSpecial[1] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_SD"));
+    fdNdEtaCorrectionSpecial[2] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_DD"));
+  }
+  else
+  {
+    fdNdEtaCorrectionSpecial[0] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_pi"));
+    fdNdEtaCorrectionSpecial[1] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_K"));
+    fdNdEtaCorrectionSpecial[2] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_p"));
+    fdNdEtaCorrectionSpecial[3] = dynamic_cast<AlidNdEtaCorrection*> (fOutput->FindObject("dndeta_correction_other"));
+  }
+  for (Int_t i=0; i<4; ++i)
+    if (fdNdEtaCorrectionSpecial[i])
+      fdNdEtaCorrectionSpecial[i]->SaveHistograms();
 
   fTemp1 = dynamic_cast<TH1*> (fOutput->FindObject("fTemp1"));
   if (fTemp1)
@@ -900,9 +1047,12 @@ void AlidNdEtaCorrectionTask::Terminate(Option_t *)
   fEtaResolution = dynamic_cast<TH1F*> (fOutput->FindObject("fEtaResolution"));
   if (fEtaResolution)
     fEtaResolution->Write();
-  fpTResolution = dynamic_cast<TH1F*> (fOutput->FindObject("fpTResolution"));
+  fpTResolution = dynamic_cast<TH2F*> (fOutput->FindObject("fpTResolution"));
   if (fpTResolution)
+  {
+    fpTResolution->FitSlicesY();
     fpTResolution->Write();
+  }
 
   fMultAll = dynamic_cast<TH1F*> (fOutput->FindObject("fMultAll"));
   if (fMultAll)
@@ -918,7 +1068,7 @@ void AlidNdEtaCorrectionTask::Terminate(Option_t *)
 
   for (Int_t i=0; i<8; ++i)
   {
-    fDeltaPhi[i] = dynamic_cast<TH1F*> (fOutput->FindObject(Form("fDeltaPhi_%d", i)));
+    fDeltaPhi[i] = dynamic_cast<TH2*> (fOutput->FindObject(Form("fDeltaPhi_%d", i)));
     if (fDeltaPhi[i])
       fDeltaPhi[i]->Write();
   }
index ddc15a8..e8ae725 100644 (file)
@@ -32,6 +32,8 @@ class AlidNdEtaCorrectionTask : public AliAnalysisTask {
     void SetAnalysisMode(AliPWG0Helper::AnalysisMode mode) { fAnalysisMode = mode; }
     void SetOnlyPrimaries(Bool_t flag = kTRUE) { fOnlyPrimaries = flag; }
     void SetTrigger(AliPWG0Helper::Trigger trigger) { fTrigger = trigger; }
+    void SetFillPhi(Bool_t flag = kTRUE) { fFillPhi = flag; }
+    void SetDeltaPhiCut(Float_t cut) { fDeltaPhiCut = cut; }
 
     void SetOption(const char* opt) { fOption = opt; }
 
@@ -44,8 +46,12 @@ class AlidNdEtaCorrectionTask : public AliAnalysisTask {
     TString fOption;                 // option string
     AliPWG0Helper::AnalysisMode fAnalysisMode;    // detector that is used for analysis
     AliPWG0Helper::Trigger fTrigger; // trigger used in the analysis
+    Bool_t fFillPhi;                           // if true phi is filled as 3rd coordinate in all maps
+    Float_t fDeltaPhiCut;                      // cut in delta phi (only SPD)
+
     Int_t fSignMode;                 // if 0 process all particles, if +-1 process only particles with that sign
     Bool_t fOnlyPrimaries;           // only process primaries (syst. studies)
+    Int_t fStatError;                // statistical error evaluation: if set to 1 we only count unique primaries (binomial errors are valid), for 2 all the rest
 
     AliESDtrackCuts*  fEsdTrackCuts;             // Object containing the parameters of the esd track cuts
 
@@ -68,8 +74,9 @@ class AlidNdEtaCorrectionTask : public AliAnalysisTask {
     TH2F* fEtaCorrelationShift;                  //! (MC eta - ESD eta) vs MC eta
     TProfile* fEtaProfile;                       //! Profile of MC eta - ESD eta vs. MC eta
     TH1F* fEtaResolution;                        //! MC eta - ESD eta in |eta| < 1
+    TH2F* fDeltaPhiCorrelation;                  //! delta phi ESD vs. MC
 
-    TH1F* fpTResolution;                         //! MC pT - ESD pT in |eta| < 1
+    TH2F* fpTResolution;                         //! (MC pT - ESD pT) / MC pT vs. MC pT in |eta| < 0.9
 
     AliESDtrackCuts*  fEsdTrackCutsPrim;         //! control histograms for primaries
     AliESDtrackCuts*  fEsdTrackCutsSec;          //! control histograms for secondaries
@@ -83,12 +90,13 @@ class AlidNdEtaCorrectionTask : public AliAnalysisTask {
     TH1F* fMultTr; //! primary particles  in |eta| < 1 and pT > 0.2 in triggered events
     TH1F* fMultVtx; //! primary particles  in |eta| < 1 and pT > 0.2 in triggered events with vertex
 
-    TH1F* fDeltaPhi[8]; //! delta phi of primaries, secondaries, other (= unclear cases)
+    TH2* fDeltaPhi[8]; //! delta phi of primaries, secondaries, other (= unclear cases)
 
-    TH2F* fEventStats;  //! some stats on number of events
+    TH2F* fEventStats;  //! some stats on number of events, see CreateOutputObjects for a detailed definition
 
-    AlidNdEtaCorrection* fdNdEtaCorrectionProcessType[3]; //! correction for specific process type (ND, SD, DD)
-                                                          // enable with option: process-types
+    AlidNdEtaCorrection* fdNdEtaCorrectionSpecial[4];   //! correction maps used for systematic studies, may contain:
+                                                        // for specific process type (ND, SD, DD), enable with option: process-types
+                                                        // for particle species (pi, K, p, rest), enable with: particle-species
 
  private:
     AlidNdEtaCorrectionTask(const AlidNdEtaCorrectionTask&);
index 0cf621a..32eceab 100644 (file)
@@ -16,6 +16,7 @@
 #include <TNtuple.h>
 #include <TObjString.h>
 #include <TF1.h>
+#include <TGraph.h>
 
 #include <AliLog.h>
 #include <AliESDVertex.h>
@@ -28,6 +29,7 @@
 #include <AliMCEventHandler.h>
 #include <AliMCEvent.h>
 #include <AliESDInputHandler.h>
+#include <AliESDHeader.h>
 
 #include "AliESDtrackCuts.h"
 #include "AliPWG0Helper.h"
@@ -44,6 +46,8 @@ AlidNdEtaTask::AlidNdEtaTask(const char* opt) :
   fOption(opt),
   fAnalysisMode(AliPWG0Helper::kTPC),
   fTrigger(AliPWG0Helper::kMB1),
+  fFillPhi(kFALSE),
+  fDeltaPhiCut(-1),
   fReadMC(kFALSE),
   fUseMCVertex(kFALSE),
   fOnlyPrimaries(kFALSE),
@@ -55,6 +59,7 @@ AlidNdEtaTask::AlidNdEtaTask(const char* opt) :
   fEvents(0),
   fVertexResolution(0),
   fdNdEtaAnalysis(0),
+  fdNdEtaAnalysisND(0),
   fdNdEtaAnalysisNSD(0),
   fdNdEtaAnalysisTr(0),
   fdNdEtaAnalysisTrVtx(0),
@@ -62,8 +67,12 @@ AlidNdEtaTask::AlidNdEtaTask(const char* opt) :
   fPartPt(0),
   fVertex(0),
   fPhi(0),
+  fRawPt(0),
   fEtaPhi(0),
-  fDeltaPhi(0)
+  fDeltaPhi(0),
+  fFiredChips(0),
+  fTriggerVsTime(0),
+  fStats(0)
 {
   //
   // Constructor. Initialization of pointers
@@ -72,6 +81,9 @@ AlidNdEtaTask::AlidNdEtaTask(const char* opt) :
   // Define input and output slots here
   DefineInput(0, TChain::Class());
   DefineOutput(0, TList::Class());
+  
+  fZPhi[0] = 0;
+  fZPhi[1] = 0;
 
   AliLog::SetClassDebugLevel("AlidNdEtaTask", AliLog::kWarning);
 }
@@ -95,7 +107,7 @@ Bool_t AlidNdEtaTask::Notify()
 {
   static Int_t count = 0;
   count++;
-  Printf("Processing %d. file", count);
+  Printf("Processing %d. file: %s", count, ((TTree*) GetInputData(0))->GetCurrentFile()->GetName());
   return kTRUE;
 }
 
@@ -166,7 +178,8 @@ void AlidNdEtaTask::CreateOutputObjects()
   fEvents = new TH1F("dndeta_check_vertex", "dndeta_check_vertex", 800, -40, 40);
   fOutput->Add(fEvents);
 
-  fVertexResolution = new TH1F("dndeta_vertex_resolution_z", "dndeta_vertex_resolution_z", 1000, 0, 10);
+  Float_t resMax = (fAnalysisMode == AliPWG0Helper::kSPD) ? 0.2 : 2;
+  fVertexResolution = new TH1F("dndeta_vertex_resolution_z", "dndeta_vertex_resolution_z", 1000, 0, resMax);
   fOutput->Add(fVertexResolution);
 
   fPhi = new TH1F("fPhi", "fPhi;#phi in rad.;count", 720, 0, 2 * TMath::Pi());
@@ -175,8 +188,35 @@ void AlidNdEtaTask::CreateOutputObjects()
   fEtaPhi = new TH2F("fEtaPhi", "fEtaPhi;#eta;#phi in rad.;count", 80, -4, 4, 18*5, 0, 2 * TMath::Pi());
   fOutput->Add(fEtaPhi);
 
+  fTriggerVsTime = new TGraph; //TH1F("fTriggerVsTime", "fTriggerVsTime;trigger time;count", 100, 0, 100);
+  fTriggerVsTime->SetName("fTriggerVsTime");
+  fTriggerVsTime->GetXaxis()->SetTitle("trigger time");
+  fTriggerVsTime->GetYaxis()->SetTitle("count");
+  fOutput->Add(fTriggerVsTime);
+
+  fStats = new TH1F("fStats", "fStats", 2, 0.5, 2.5);
+  fStats->GetXaxis()->SetBinLabel(1, "vertexer 3d");
+  fStats->GetXaxis()->SetBinLabel(2, "vertexer z");
+  fOutput->Add(fStats);
+
   if (fAnalysisMode == AliPWG0Helper::kSPD)
-    fDeltaPhi = new TH1F("fDeltaPhi", "fDeltaPhi;#Delta #phi;Entries", 18*50, -3.14, 3.14);
+  {
+    fDeltaPhi = new TH1F("fDeltaPhi", "fDeltaPhi;#Delta #phi;Entries", 500, -0.2, 0.2);
+    fOutput->Add(fDeltaPhi);
+    fFiredChips = new TH2F("fFiredChips", "fFiredChips;Chips L1 + L2;tracklets", 1201, -0.5, 1201, 50, -0.5, 49.5);
+    fOutput->Add(fFiredChips);
+    for (Int_t i=0; i<2; i++)
+    {
+      fZPhi[i] = new TH2F(Form("fZPhi_%d", i), Form("fZPhi Layer %d;z (cm);#phi (rad.)", i), 200, -20, 20, 180, 0, TMath::Pi() * 2);
+      fOutput->Add(fZPhi[i]);
+    }
+  }
+
+  if (fAnalysisMode == AliPWG0Helper::kTPC || fAnalysisMode == AliPWG0Helper::kTPCITS)
+  {
+    fRawPt =  new TH1F("fRawPt", "raw pt;p_{T};Count", 2000, 0, 100);
+    fOutput->Add(fRawPt);
+  }
 
   fVertex = new TH3F("vertex_check", "vertex_check", 100, -1, 1, 100, -1, 1, 100, -30, 30);
   fOutput->Add(fVertex);
@@ -186,6 +226,9 @@ void AlidNdEtaTask::CreateOutputObjects()
     fdNdEtaAnalysis = new dNdEtaAnalysis("dndeta", "dndeta", fAnalysisMode);
     fOutput->Add(fdNdEtaAnalysis);
 
+    fdNdEtaAnalysisND = new dNdEtaAnalysis("dndetaND", "dndetaND", fAnalysisMode);
+    fOutput->Add(fdNdEtaAnalysisND);
+
     fdNdEtaAnalysisNSD = new dNdEtaAnalysis("dndetaNSD", "dndetaNSD", fAnalysisMode);
     fOutput->Add(fdNdEtaAnalysisNSD);
 
@@ -224,8 +267,25 @@ void AlidNdEtaTask::Exec(Option_t*)
   // ESD analysis
   if (fESD)
   {
+    // check event type (should be PHYSICS = 7)
+    AliESDHeader* esdHeader = fESD->GetHeader();
+    if (!esdHeader)
+    {
+      Printf("ERROR: esdHeader could not be retrieved");
+      return;
+    }
+
+    /*
+    UInt_t eventType = esdHeader->GetEventType();
+    if (eventType != 7)
+    {
+      Printf("Skipping event because it is of type %d", eventType);
+      return;
+    }
+    */
+
     // trigger definition
-    eventTriggered = AliPWG0Helper::IsEventTriggered(fESD->GetTriggerMask(), fTrigger);
+    eventTriggered = AliPWG0Helper::IsEventTriggered(fESD, fTrigger);
 
     // get the ESD vertex
     vtxESD = AliPWG0Helper::GetVertex(fESD, fAnalysisMode);
@@ -241,6 +301,14 @@ void AlidNdEtaTask::Exec(Option_t*)
       if (AliPWG0Helper::TestVertex(vtxESD, fAnalysisMode))
       {
           vtxESD->GetXYZ(vtx);
+
+          // vertex stats
+          if (strcmp(vtxESD->GetTitle(), "vertexer: 3D") == 0)
+          {
+            fStats->Fill(1);
+          }
+          else if (strcmp(vtxESD->GetTitle(), "vertexer: Z") == 0)
+            fStats->Fill(2);
       }
       else
         vtxESD = 0;
@@ -299,7 +367,7 @@ void AlidNdEtaTask::Exec(Option_t*)
     Int_t inputCount = 0;
     Int_t* labelArr = 0;
     Float_t* etaArr = 0;
-    Float_t* ptArr = 0;
+    Float_t* thirdDimArr = 0;
     if (fAnalysisMode == AliPWG0Helper::kSPD)
     {
       // get tracklets
@@ -312,9 +380,9 @@ void AlidNdEtaTask::Exec(Option_t*)
 
       labelArr = new Int_t[mult->GetNumberOfTracklets()];
       etaArr = new Float_t[mult->GetNumberOfTracklets()];
-      ptArr = new Float_t[mult->GetNumberOfTracklets()];
+      thirdDimArr = new Float_t[mult->GetNumberOfTracklets()];
 
-      // get multiplicity from ITS tracklets
+      // get multiplicity from SPD tracklets
       for (Int_t i=0; i<mult->GetNumberOfTracklets(); ++i)
       {
         //printf("%d %f %f %f\n", i, mult->GetTheta(i), mult->GetPhi(i), mult->GetDeltaPhi(i));
@@ -333,16 +401,30 @@ void AlidNdEtaTask::Exec(Option_t*)
         if (TMath::Abs(deltaPhi) > 1)
           printf("WARNING: Very high Delta Phi: %d %f %f %f\n", i, mult->GetTheta(i), mult->GetPhi(i), deltaPhi);
 
+        Int_t label = mult->GetLabel(i, 0);
+        Float_t eta = mult->GetEta(i);
+
+        // control histograms
         Float_t phi = mult->GetPhi(i);
         if (phi < 0)
           phi += TMath::Pi() * 2;
         fPhi->Fill(phi);
-        fEtaPhi->Fill(mult->GetEta(i), phi);
+        fEtaPhi->Fill(eta, phi);
+        
+        if (deltaPhi < 0.01)
+        {
+          // layer 0
+          Float_t z = vtx[2] + 3.9 / TMath::Tan(2 * TMath::ATan(TMath::Exp(- eta)));
+          fZPhi[0]->Fill(z, phi);
+          // layer 1
+          z = vtx[2] + 7.6 / TMath::Tan(2 * TMath::ATan(TMath::Exp(- eta)));
+          fZPhi[1]->Fill(z, phi);
+        }
 
         fDeltaPhi->Fill(deltaPhi);
 
-        Int_t label = mult->GetLabel(i, 0);
-        Float_t eta = mult->GetEta(i);
+        if (fDeltaPhiCut > 0 && TMath::Abs(deltaPhi) > fDeltaPhiCut)
+          continue;
 
         if (fUseMCKine)
         {
@@ -350,22 +432,28 @@ void AlidNdEtaTask::Exec(Option_t*)
           {
             TParticle* particle = stack->Particle(label);
             eta = particle->Eta();
+            phi = particle->Phi();
           }
           else
             Printf("WARNING: fUseMCKine set without fOnlyPrimaries and no label found");
         }
-
+        
         etaArr[inputCount] = eta;
         labelArr[inputCount] = label;
-        ptArr[inputCount] = 0; // no pt for tracklets
+        thirdDimArr[inputCount] = phi;
         ++inputCount;
       }
 
-      // fill multiplicity in pt bin
-      for (Int_t i=0; i<inputCount; ++i)
-        ptArr[i] = inputCount;
+      if (!fFillPhi)
+      {
+        // fill multiplicity in third axis
+        for (Int_t i=0; i<inputCount; ++i)
+          thirdDimArr[i] = inputCount;
+      }
 
-      Printf("Accepted %d tracklets", inputCount);
+      Int_t firedChips = mult->GetNumberOfFiredChips(0) + mult->GetNumberOfFiredChips(1);
+      fFiredChips->Fill(firedChips, inputCount);
+      Printf("Accepted %d tracklets (%d fired chips)", inputCount, firedChips);
     }
     else if (fAnalysisMode == AliPWG0Helper::kTPC || fAnalysisMode == AliPWG0Helper::kTPCITS)
     {
@@ -375,58 +463,65 @@ void AlidNdEtaTask::Exec(Option_t*)
         return;
       }
 
-      // get multiplicity from ESD tracks
-      TObjArray* list = fEsdTrackCuts->GetAcceptedTracks(fESD, (fAnalysisMode == AliPWG0Helper::kTPC));
-      Int_t nGoodTracks = list->GetEntries();
-
-      labelArr = new Int_t[nGoodTracks];
-      etaArr = new Float_t[nGoodTracks];
-      ptArr = new Float_t[nGoodTracks];
-
-      // loop over esd tracks
-      for (Int_t i=0; i<nGoodTracks; i++)
+      if (vtxESD)
       {
-        AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*> (list->At(i));
-        if (!esdTrack)
+        // get multiplicity from ESD tracks
+        TObjArray* list = fEsdTrackCuts->GetAcceptedTracks(fESD, (fAnalysisMode == AliPWG0Helper::kTPC));
+        Int_t nGoodTracks = list->GetEntries();
+        Printf("Accepted %d tracks", nGoodTracks);
+  
+        labelArr = new Int_t[nGoodTracks];
+        etaArr = new Float_t[nGoodTracks];
+        thirdDimArr = new Float_t[nGoodTracks];
+  
+        // loop over esd tracks
+        for (Int_t i=0; i<nGoodTracks; i++)
         {
-          AliDebug(AliLog::kError, Form("ERROR: Could not retrieve track %d.", i));
-          continue;
-        }
-
-        Float_t phi = esdTrack->Phi();
-        if (phi < 0)
-          phi += TMath::Pi() * 2;
-        fPhi->Fill(phi);
-        fEtaPhi->Fill(esdTrack->Eta(), phi);
-
-        Float_t eta = esdTrack->Eta();
-        Int_t label = TMath::Abs(esdTrack->GetLabel());
-        Float_t pT  = esdTrack->Pt();
-
-        if (fOnlyPrimaries && label == 0)
-          continue;
-
-        if (fUseMCKine)
-        {
-          if (label > 0)
+          AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*> (list->At(i));
+          if (!esdTrack)
           {
-            TParticle* particle = stack->Particle(label);
-            eta = particle->Eta();
-            pT = particle->Pt();
+            AliDebug(AliLog::kError, Form("ERROR: Could not retrieve track %d.", i));
+            continue;
           }
-          else
-            Printf("WARNING: fUseMCKine set without fOnlyPrimaries and no label found");
+          
+          Float_t phi = esdTrack->Phi();
+          if (phi < 0)
+            phi += TMath::Pi() * 2;
+  
+          Float_t eta = esdTrack->Eta();
+          Int_t label = TMath::Abs(esdTrack->GetLabel());
+          Float_t pT  = esdTrack->Pt();
+  
+          fPhi->Fill(phi);
+          fEtaPhi->Fill(eta, phi);
+          if (eventTriggered && vtxESD)
+            fRawPt->Fill(pT);
+  
+          if (fOnlyPrimaries && label == 0)
+            continue;
+  
+          if (fUseMCKine)
+          {
+            if (label > 0)
+            {
+              TParticle* particle = stack->Particle(label);
+              eta = particle->Eta();
+              pT = particle->Pt();
+            }
+            else
+              Printf("WARNING: fUseMCKine set without fOnlyPrimaries and no label found");
+          }
+  
+          etaArr[inputCount] = eta;
+          labelArr[inputCount] = TMath::Abs(esdTrack->GetLabel());
+          thirdDimArr[inputCount] = pT;
+          ++inputCount;
         }
-
-        etaArr[inputCount] = eta;
-        labelArr[inputCount] = TMath::Abs(esdTrack->GetLabel());
-        ptArr[inputCount] = pT;
-        ++inputCount;
+        
+        // TODO restrict inputCount used as measure for the multiplicity to |eta| < 1
+  
+        delete list;
       }
-
-      Printf("Accepted %d tracks", nGoodTracks);
-
-      delete list;
     }
     else
       return;
@@ -438,6 +533,8 @@ void AlidNdEtaTask::Exec(Option_t*)
       fMult->Fill(inputCount);
       fdNdEtaAnalysisESD->FillTriggeredEvent(inputCount);
 
+      fTriggerVsTime->SetPoint(fTriggerVsTime->GetN(), fESD->GetTimeStamp(), 1);
+
       if (vtxESD)
       {
         // control hist
@@ -446,11 +543,11 @@ void AlidNdEtaTask::Exec(Option_t*)
         for (Int_t i=0; i<inputCount; ++i)
         {
           Float_t eta = etaArr[i];
-          Float_t pt  = ptArr[i];
+          Float_t thirdDim = thirdDimArr[i];
 
-          fdNdEtaAnalysisESD->FillTrack(vtx[2], eta, pt);
+          fdNdEtaAnalysisESD->FillTrack(vtx[2], eta, thirdDim);
 
-          if (TMath::Abs(vtx[2]) < 20)
+          if (TMath::Abs(vtx[2]) < 10)
           {
             fPartEta[0]->Fill(eta);
 
@@ -486,7 +583,20 @@ void AlidNdEtaTask::Exec(Option_t*)
               continue;
             }
 
-            fdNdEtaAnalysisTracks->FillTrack(vtxMC[2], particle->Eta(), (fAnalysisMode == AliPWG0Helper::kSPD) ? inputCount : particle->Pt());
+            Float_t thirdDim = -1;
+            if (fAnalysisMode == AliPWG0Helper::kSPD)
+            {
+              if (fFillPhi)
+              {
+                thirdDim = particle->Phi();
+              }
+              else
+                thirdDim = inputCount;
+            }
+            else
+              thirdDim = particle->Pt();
+
+            fdNdEtaAnalysisTracks->FillTrack(vtxMC[2], particle->Eta(), thirdDim);
           } // end of track loop
 
           // for event count per vertex
@@ -495,9 +605,12 @@ void AlidNdEtaTask::Exec(Option_t*)
       }
     }
 
-    delete[] etaArr;
-    delete[] labelArr;
-    delete[] ptArr;
+    if (etaArr)
+      delete[] etaArr;
+    if (labelArr)
+      delete[] labelArr;
+    if (thirdDimArr)
+      delete[] thirdDimArr;
   }
 
   if (fReadMC)   // Processing of MC information (optional)
@@ -589,13 +702,28 @@ void AlidNdEtaTask::Exec(Option_t*)
         continue;
 
       Float_t eta = particle->Eta();
-      Float_t thirdDim = (fAnalysisMode == AliPWG0Helper::kSPD) ? nAcceptedParticles : particle->Pt();
+      Float_t thirdDim = -1;
+
+      if (fAnalysisMode == AliPWG0Helper::kSPD)
+      {
+        if (fFillPhi)
+        {
+          thirdDim = particle->Phi();
+        }
+        else
+          thirdDim = nAcceptedParticles;
+      }
+      else
+        thirdDim = particle->Pt();
 
       fdNdEtaAnalysis->FillTrack(vtxMC[2], eta, thirdDim);
 
-      if (processType != AliPWG0Helper::kSD )
+      if (processType != AliPWG0Helper::kSD)
         fdNdEtaAnalysisNSD->FillTrack(vtxMC[2], eta, thirdDim);
 
+      if (processType == AliPWG0Helper::kND)
+        fdNdEtaAnalysisND->FillTrack(vtxMC[2], eta, thirdDim);
+
       if (eventTriggered)
       {
         fdNdEtaAnalysisTr->FillTrack(vtxMC[2], eta, thirdDim);
@@ -603,13 +731,15 @@ void AlidNdEtaTask::Exec(Option_t*)
           fdNdEtaAnalysisTrVtx->FillTrack(vtxMC[2], eta, thirdDim);
       }
 
-      if (TMath::Abs(eta) < 0.8)
+      if (TMath::Abs(eta) < 1.0)
         fPartPt->Fill(particle->Pt());
     }
 
     fdNdEtaAnalysis->FillEvent(vtxMC[2], nAcceptedParticles);
     if (processType != AliPWG0Helper::kSD)
       fdNdEtaAnalysisNSD->FillEvent(vtxMC[2], nAcceptedParticles);
+    if (processType == AliPWG0Helper::kND)
+      fdNdEtaAnalysisND->FillEvent(vtxMC[2], nAcceptedParticles);
 
     if (eventTriggered)
     {
@@ -641,8 +771,14 @@ void AlidNdEtaTask::Terminate(Option_t *)
     fVertexResolution = dynamic_cast<TH1F*> (fOutput->FindObject("dndeta_vertex_resolution_z"));
 
     fPhi = dynamic_cast<TH1F*> (fOutput->FindObject("fPhi"));
+    fRawPt = dynamic_cast<TH1F*> (fOutput->FindObject("fRawPt"));
     fEtaPhi = dynamic_cast<TH2F*> (fOutput->FindObject("fEtaPhi"));
+    for (Int_t i=0; i<2; ++i)
+      fZPhi[i] = dynamic_cast<TH2F*> (fOutput->FindObject(Form("fZPhi_%d", i)));
     fDeltaPhi = dynamic_cast<TH1F*> (fOutput->FindObject("fDeltaPhi"));
+    fFiredChips = dynamic_cast<TH2F*> (fOutput->FindObject("fFiredChips"));
+    fTriggerVsTime = dynamic_cast<TGraph*> (fOutput->FindObject("fTriggerVsTime"));
+    fStats = dynamic_cast<TH1F*> (fOutput->FindObject("fStats"));
 
     fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fEsdTrackCuts"));
   }
@@ -661,6 +797,12 @@ void AlidNdEtaTask::Terminate(Option_t *)
       fMultVtx->Draw("SAME");
     }
 
+    if (fFiredChips)
+    {
+      new TCanvas;
+      fFiredChips->Draw("COLZ");
+    }
+
     if (fPartEta[0])
     {
       Int_t events1 = (Int_t) fEvents->Integral(fEvents->GetXaxis()->FindBin(-19.9), fEvents->GetXaxis()->FindBin(-0.001));
@@ -722,9 +864,25 @@ void AlidNdEtaTask::Terminate(Option_t *)
     if (fPhi)
       fPhi->Write();
 
+    if (fRawPt)
+      fRawPt->Write();
+
     if (fEtaPhi)
       fEtaPhi->Write();
 
+    for (Int_t i=0; i<2; ++i)
+      if (fZPhi[i])
+        fZPhi[i]->Write();
+    
+    if (fFiredChips)
+      fFiredChips->Write();
+
+    if (fTriggerVsTime)
+      fTriggerVsTime->Write();
+
+    if (fStats)
+      fStats->Write();
+
     fVertex = dynamic_cast<TH3F*> (fOutput->FindObject("vertex_check"));
     if (fVertex)
       fVertex->Write();
@@ -740,6 +898,7 @@ void AlidNdEtaTask::Terminate(Option_t *)
     if (fOutput)
     {
       fdNdEtaAnalysis = dynamic_cast<dNdEtaAnalysis*> (fOutput->FindObject("dndeta"));
+      fdNdEtaAnalysisND = dynamic_cast<dNdEtaAnalysis*> (fOutput->FindObject("dndetaND"));
       fdNdEtaAnalysisNSD = dynamic_cast<dNdEtaAnalysis*> (fOutput->FindObject("dndetaNSD"));
       fdNdEtaAnalysisTr = dynamic_cast<dNdEtaAnalysis*> (fOutput->FindObject("dndetaTr"));
       fdNdEtaAnalysisTrVtx = dynamic_cast<dNdEtaAnalysis*> (fOutput->FindObject("dndetaTrVtx"));
@@ -754,6 +913,7 @@ void AlidNdEtaTask::Terminate(Option_t *)
     }
 
     fdNdEtaAnalysis->Finish(0, -1, AlidNdEtaCorrection::kNone);
+    fdNdEtaAnalysisND->Finish(0, -1, AlidNdEtaCorrection::kNone);
     fdNdEtaAnalysisNSD->Finish(0, -1, AlidNdEtaCorrection::kNone);
     fdNdEtaAnalysisTr->Finish(0, -1, AlidNdEtaCorrection::kNone);
     fdNdEtaAnalysisTrVtx->Finish(0, -1, AlidNdEtaCorrection::kNone);
@@ -766,6 +926,7 @@ void AlidNdEtaTask::Terminate(Option_t *)
     TFile* fout = new TFile("analysis_mc.root","RECREATE");
 
     fdNdEtaAnalysis->SaveHistograms();
+    fdNdEtaAnalysisND->SaveHistograms();
     fdNdEtaAnalysisNSD->SaveHistograms();
     fdNdEtaAnalysisTr->SaveHistograms();
     fdNdEtaAnalysisTrVtx->SaveHistograms();
index f61fa83..b9ee6d0 100644 (file)
@@ -13,6 +13,7 @@ class TH1F;
 class TH2F;
 class TH3F;
 class AliESDEvent;
+class TGraph;
 
 class AlidNdEtaTask : public AliAnalysisTask {
   public:
@@ -32,6 +33,8 @@ class AlidNdEtaTask : public AliAnalysisTask {
     void SetOnlyPrimaries(Bool_t flag = kTRUE) { fOnlyPrimaries = flag; }
     void SetUseMCKine(Bool_t flag = kTRUE) { fUseMCKine = flag; }
     void SetTrigger(AliPWG0Helper::Trigger trigger) { fTrigger = trigger; }
+    void SetFillPhi(Bool_t flag = kTRUE) { fFillPhi = flag; }
+    void SetDeltaPhiCut(Float_t cut) { fDeltaPhiCut = cut; }
 
     void SetOption(const char* opt) { fOption = opt; }
 
@@ -42,6 +45,8 @@ class AlidNdEtaTask : public AliAnalysisTask {
     TString fOption;      // option string
     AliPWG0Helper::AnalysisMode fAnalysisMode; // detector that is used for analysis
     AliPWG0Helper::Trigger fTrigger;           // trigger that is used
+    Bool_t fFillPhi;                           // if true phi is filled as 3rd coordinate in all maps
+    Float_t fDeltaPhiCut;                      // cut in delta phi (only SPD)
 
     Bool_t  fReadMC;       // if true reads MC data (to build correlation maps)
     Bool_t  fUseMCVertex;  // the MC vtx is used instead of the ESD vertex (for syst. check)
@@ -61,7 +66,8 @@ class AlidNdEtaTask : public AliAnalysisTask {
 
     // Gathered from MC (when fReadMC is set)
     dNdEtaAnalysis* fdNdEtaAnalysis;        //! contains the dndeta from the full sample
-    dNdEtaAnalysis* fdNdEtaAnalysisNSD;        //! contains the dndeta for the NSD sample
+    dNdEtaAnalysis* fdNdEtaAnalysisND;      //! contains the dndeta for the ND sample
+    dNdEtaAnalysis* fdNdEtaAnalysisNSD;     //! contains the dndeta for the NSD sample
     dNdEtaAnalysis* fdNdEtaAnalysisTr;      //! contains the dndeta from the triggered events
     dNdEtaAnalysis* fdNdEtaAnalysisTrVtx;   //! contains the dndeta from the triggered events with vertex
     dNdEtaAnalysis* fdNdEtaAnalysisTracks;  //! contains the dndeta from the triggered events with vertex counted from the mc particles associated to the tracks (comparing this to the raw values from the esd shows the effect of the detector resolution)
@@ -72,8 +78,13 @@ class AlidNdEtaTask : public AliAnalysisTask {
     // control histograms (ESD)
     TH3F* fVertex;                //! 3d vertex distribution
     TH1F* fPhi;                   //! raw phi distribution
+    TH1F* fRawPt;                 //! raw pt distribution
     TH2F* fEtaPhi;                //! raw eta - phi distribution
+    TH2F* fZPhi[2];               //! raw z - phi distribution from tracklets per layer (only SPD)
     TH1F* fDeltaPhi;              //! histogram of delta_phi values for tracklets (only for SPD analysis)
+    TH2F* fFiredChips;            //! fired chips l1+l2 vs. number of tracklets (only for SPD analysis)
+    TGraph* fTriggerVsTime;       //! trigger as function of event time
+    TH1F* fStats;                 //! further statistics : bin 1 = vertexer 3d, bin 2 = vertexer z
 
  private:
     AlidNdEtaTask(const AlidNdEtaTask&);
index 6be5ada..d484ace 100644 (file)
@@ -27,7 +27,7 @@ void FinishAnalysisAll(const char* dataInput = "analysis_esd_raw.root", const ch
   // Note: the last parameter does not define which analysis is going to happen, the histograms will be overwritten when loading from the f
   dNdEtaAnalysis* fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaNSD", "dndetaNSD");
   fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
-  fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.3, AlidNdEtaCorrection::kNSD, "ESD -> NSD");
+  fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.21, AlidNdEtaCorrection::kNSD, "ESD -> NSD");
   //fdNdEtaAnalysis->DrawHistograms(kTRUE);
   TFile* file2 = TFile::Open(dataOutput, "RECREATE");
   fdNdEtaAnalysis->SaveHistograms();
@@ -35,7 +35,7 @@ void FinishAnalysisAll(const char* dataInput = "analysis_esd_raw.root", const ch
   file->cd();
   dNdEtaAnalysis* fdNdEtaAnalysis = new dNdEtaAnalysis("dndeta", "dndeta");
   fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
-  fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.3, AlidNdEtaCorrection::kINEL, "ESD -> full inelastic");
+  fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.21, AlidNdEtaCorrection::kINEL, "ESD -> full inelastic");
   //fdNdEtaAnalysis->DrawHistograms(kTRUE);
   file2->cd();
   fdNdEtaAnalysis->SaveHistograms();
@@ -43,7 +43,7 @@ void FinishAnalysisAll(const char* dataInput = "analysis_esd_raw.root", const ch
   file->cd();
   fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaTr", "dndetaTr");
   fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
-  fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.3, AlidNdEtaCorrection::kVertexReco, "ESD -> minimum bias");
+  fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.21, AlidNdEtaCorrection::kVertexReco, "ESD -> minimum bias");
   //fdNdEtaAnalysis->DrawHistograms(kTRUE);
   file2->cd();
   fdNdEtaAnalysis->SaveHistograms();
@@ -51,7 +51,7 @@ void FinishAnalysisAll(const char* dataInput = "analysis_esd_raw.root", const ch
   file->cd();
   fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaTrVtx", "dndetaTrVtx");
   fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
-  fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.3, AlidNdEtaCorrection::kTrack2Particle, "ESD -> MB with vertex");
+  fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.21, AlidNdEtaCorrection::kTrack2Particle, "ESD -> MB with vertex");
   //fdNdEtaAnalysis->DrawHistograms(kTRUE);
   file2->cd();
   fdNdEtaAnalysis->SaveHistograms();
@@ -59,7 +59,7 @@ void FinishAnalysisAll(const char* dataInput = "analysis_esd_raw.root", const ch
   file->cd();
   fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaTracks", "dndetaTracks");
   fdNdEtaAnalysis->LoadHistograms("fdNdEtaAnalysisESD");
-  fdNdEtaAnalysis->Finish(0, 0.3, AlidNdEtaCorrection::kNone, "ESD raw with pt cut");
+  fdNdEtaAnalysis->Finish(0, 0.21, AlidNdEtaCorrection::kNone, "ESD raw with pt cut");
   //fdNdEtaAnalysis->DrawHistograms(kTRUE);
   file2->cd();
   fdNdEtaAnalysis->SaveHistograms();
@@ -91,12 +91,12 @@ void* FinishAnalysis(const char* analysisFile = "analysis_esd_raw.root", const c
     TFile::Open(correctionMapFile);
     dNdEtaCorrection->LoadHistograms();
 
-    fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.3, AlidNdEtaCorrection::kINEL);
+    fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0.21, AlidNdEtaCorrection::kINEL);
     //fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0, AlidNdEtaCorrection::kINEL);
     //fdNdEtaAnalysis->Finish(dNdEtaCorrection, 0, AlidNdEtaCorrection::kTrack2Particle);
   }
   else
-    fdNdEtaAnalysis->Finish(0, 0.3, AlidNdEtaCorrection::kNone);
+    fdNdEtaAnalysis->Finish(0, 0.21, AlidNdEtaCorrection::kNone);
 
   fdNdEtaAnalysis->DrawHistograms(simple);
 
@@ -114,11 +114,11 @@ void* FinishAnalysis(const char* analysisFile = "analysis_esd_raw.root", const c
   return fdNdEtaAnalysis;
 }
 
-void correct()
+void correct(Bool_t onlyESD = kFALSE)
 {
   FinishAnalysisAll();
   gROOT->ProcessLine(".L $ALICE_ROOT/PWG0/dNdEta/drawPlots.C");
-  dNdEta();
+  dNdEta(onlyESD);
 }
 
 
index ac51813..40d02f3 100644 (file)
@@ -308,7 +308,7 @@ void dNdEtaAnalysis::Finish(AlidNdEtaCorrection* correction, Float_t ptCut, Alid
     }
 
     //new TCanvas; correctedEvents->DrawCopy("TEXT");
-    //new TCanvas; kineBias->Draw();
+    //new TCanvas; kineBias->DrawCopy();
   }
 
   fData->PrintInfo(ptCut);
@@ -364,10 +364,15 @@ void dNdEtaAnalysis::Finish(AlidNdEtaCorrection* correction, Float_t ptCut, Alid
   Int_t ptLowBin = 1;
   if (ptCut > 0 && fAnalysisMode != AliPWG0Helper::kSPD)
     ptLowBin = dataHist->GetZaxis()->FindBin(ptCut);
+    
+  //new TCanvas; dataHist->DrawCopy();
 
+  //dataHist->Sumw2();
   dataHist->GetZaxis()->SetRange(ptLowBin, dataHist->GetZaxis()->GetNbins()+1);
   printf("pt/multiplicity range %d %d\n", ptLowBin, dataHist->GetZaxis()->GetNbins()+1);
   TH2D* vtxVsEta = dynamic_cast<TH2D*> (dataHist->Project3D("yx2e"));
+  
+  //new TCanvas; vtxVsEta->Draw("COLZ");
 
   dataHist->GetZaxis()->SetRange(0, 0);
   vtxVsEta->GetXaxis()->SetTitle(dataHist->GetXaxis()->GetTitle());
@@ -400,22 +405,26 @@ void dNdEtaAnalysis::Finish(AlidNdEtaCorrection* correction, Float_t ptCut, Alid
       Int_t vertexBinEnd   = vertexHist->GetXaxis()->FindBin(vertexRangeEnd[vertexPos]);
 
       const Int_t *binBegin = 0;
+      const Int_t maxBins = 60;
 
       // adjust acceptance range
+      // produce with drawPlots.C: DetermineAcceptance(...)
       if (fAnalysisMode == AliPWG0Helper::kSPD)
       {
         //const Int_t binBeginSPD[30] = { 18, 16, 15, 14, 13, 13, 12, 11, 9, 7, 6, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 1 }; // by eye
-        const Int_t binBeginSPD[30] = { -1, -1, -1, -1, 16, 14, 12, 10, 9, 7, 6, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, -1, -1, -1, -1}; // limit in correction map is 5
+        //const Int_t binBeginSPD[30] = { -1, -1, -1, -1, 16, 14, 12, 10, 9, 7, 6, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, -1, -1, -1, -1}; // limit in correction map is 5
 
         //const Int_t binBegin[30] = { -1, -1, -1, 17, 15, 14, 12, 10, 8, 7, 6, 5, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, -1, -1, -1};  // limit in correction map is 10
 
         //const Int_t binBeginSPD[30] = { -1, -1, -1, -1, 16, 15, 13, 11, 9, 8, 7, 6, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, -1, -1, -1, -1}; // limit 2
+        const Int_t binBeginSPD[maxBins] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, 14, 13, 12, 11, 10, 9, 9, 8, 7, 7, 6, 6, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; //limit 5
 
         binBegin = binBeginSPD;
       }
       else if (fAnalysisMode == AliPWG0Helper::kTPC)
       {
-        const Int_t binBeginTPC[30] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1}; // limit 5, pt cut off 0.2 mev/c
+        //const Int_t binBeginTPC[30] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1}; // limit 5, pt cut off 0.2 mev/c
+        const Int_t binBeginTPC[maxBins] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 9, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; // limit 5
 
         binBegin = binBeginTPC;
       }
@@ -425,12 +434,12 @@ void dNdEtaAnalysis::Finish(AlidNdEtaCorrection* correction, Float_t ptCut, Alid
       }
 
       Int_t vtxBegin = 1;
-      Int_t vtxEnd   = 30;
+      Int_t vtxEnd   = maxBins;
 
       if (binBegin)
       {
         vtxBegin = binBegin[iEta - 1];
-        vtxEnd = 18 + 1 - binBegin[30 - iEta];
+        vtxEnd = 18 + 1 - binBegin[maxBins - iEta];
       }
       else
         Printf("WARNING: No acceptance applied!");
@@ -479,7 +488,7 @@ void dNdEtaAnalysis::Finish(AlidNdEtaCorrection* correction, Float_t ptCut, Alid
         else
         {
           unusedTracks += vtxVsEta->GetBinContent(iVtx, iEta);
-          unusedEvents +=vertexHist->GetBinContent(iVtx);
+          unusedEvents += vertexHist->GetBinContent(iVtx);
         }
       }
 
@@ -504,7 +513,7 @@ void dNdEtaAnalysis::Finish(AlidNdEtaCorrection* correction, Float_t ptCut, Alid
         }
       }
 
-      //printf("Eta: %d Vertex Range: %d %d, Event Count %f, Track Sum: %f, Track Sum corrected: %f\n", iEta, vertexBinBegin, vertexBinEnd, totalEvents, sum, sum / ptCutOffCorrection);
+      //printf("Eta: %d (%f) Vertex Range: %d %d, Event Count %f, Track Sum: %f, Track Sum corrected: %f \n", iEta, vtxVsEta->GetYaxis()->GetBinCenter(iEta), vertexBinBegin, vertexBinEnd, totalEvents, sum, sum / ptCutOffCorrection);
 
       Int_t bin = fdNdEta[vertexPos]->FindBin(vtxVsEta->GetYaxis()->GetBinCenter(iEta));
       if (bin > 0 && bin <= fdNdEta[vertexPos]->GetNbinsX())
index a82f3d0..8db7e0b 100644 (file)
@@ -60,6 +60,7 @@ public:
   TH1F* GetdNdEtaPtCutOffCorrectedHistogram(Int_t i = 0) const { return fdNdEtaPtCutOffCorrected[i]; }
 
   void SetAnalysisMode(AliPWG0Helper::AnalysisMode mode) { fAnalysisMode = mode; }
+  AliPWG0Helper::AnalysisMode GetAnalysisMode() { return fAnalysisMode; }
 
 protected:
   Float_t GetVtxMin(Float_t eta);
index 436a923..a4a684f 100644 (file)
@@ -22,18 +22,30 @@ extern TSystem* gSystem;
 
 void loadlibs()
 {
+  gSystem->Load("libVMC");
+  gSystem->Load("libTree");
+  gSystem->Load("libSTEERBase");
+  gSystem->Load("libESD");
+  gSystem->Load("libAOD");
   gSystem->Load("libANALYSIS");
+  gSystem->Load("libANALYSISalice");
   gSystem->Load("libPWG0base");
 }
 
 void SetRanges(TAxis* axis)
 {
   if (strcmp(axis->GetTitle(), "#eta") == 0)
-    axis->SetRangeUser(-1.7999, 1.7999);
-  if (strcmp(axis->GetTitle(), "p_{T} [GeV/c]") == 0)
+    axis->SetRangeUser(-1.4999, 1.4999);
+  if (strcmp(axis->GetTitle(), "p_{T} [GeV/c]") == 0 || strcmp(axis->GetTitle(), "p_{T} (GeV/c)") == 0)
+  {
     axis->SetRangeUser(0, 4.9999);
-  if (strcmp(axis->GetTitle(), "vtx z [cm]") == 0)
+    axis->SetTitle("p_{T} (GeV/c)");
+  }
+  if (strcmp(axis->GetTitle(), "vtx z [cm]") == 0 || strcmp(axis->GetTitle(), "vtx z (cm)") == 0)
+  {
     axis->SetRangeUser(-15, 14.9999);
+    axis->SetTitle("vtx-z (cm)");
+  }
   if (strcmp(axis->GetTitle(), "Ntracks") == 0)
     axis->SetRangeUser(0, 99.9999);
 }
@@ -317,17 +329,121 @@ void dNdEtaNoResolution()
 
 TH1* GetMCHist(const char* folder, Float_t ptCut, const char* tag)
 {
+  loadlibs();
+  
   dNdEtaAnalysis* fdNdEtaAnalysis = new dNdEtaAnalysis(folder, folder);
   fdNdEtaAnalysis->LoadHistograms();
   fdNdEtaAnalysis->Finish(0, ptCut, AlidNdEtaCorrection::kNone, tag);
   return fdNdEtaAnalysis->GetdNdEtaHistogram(0);
 }
 
+void dNdEtaFinal(Bool_t spd = kTRUE)
+{
+  TFile* file = TFile::Open("analysis_esd.root");
+  TH1* histESD = (TH1*) file->Get("dndeta/dNdEta_corrected");
+  TH1* histESDnsd = (TH1*) file->Get("dndetaNSD/dNdEta_corrected");
+  Prepare1DPlot(histESD);
+  Prepare1DPlot(histESDnsd);
+  
+  TCanvas* canvas = new TCanvas("dNdEtaFinal", "dNdEtaFinal", 600, 600);
+  gPad->SetTopMargin(0.05);
+  gPad->SetRightMargin(0.05);
+  gPad->SetLeftMargin(0.12);
+  gPad->SetBottomMargin(0.12);
+  gPad->SetGridx();
+  gPad->SetGridy();
+  
+  Float_t etaMax = 1.9;
+  Float_t histMax = 1.39;
+  Float_t systErrorValue = 0.023;
+  Float_t systErrorNSDValue = 0.081;
+  if (!spd)
+  {
+    //etaMax = 1.5;
+    histMax = 0.99;
+    systErrorValue = 0.043;
+    systErrorNSDValue = 0.088;
+  }
+  
+  dummy = new TH2F("dummy", ";#eta;dN_{ch}/d#eta", 100, -etaMax, etaMax, 100, 3, 8);
+  dummy->SetStats(0);
+  dummy->GetYaxis()->SetTitleOffset(1.3);
+  
+  histESD->SetMarkerStyle(20);
+  histESDnsd->SetMarkerStyle(21);
+  histESDnsd->SetMarkerColor(4);
+  histESDnsd->SetLineColor(4);
+  histESD->SetMarkerSize(1.5);
+  histESDnsd->SetMarkerSize(1.5);
+  
+  histESD->GetXaxis()->SetRangeUser(-histMax, histMax);
+  histESDnsd->GetXaxis()->SetRangeUser(-histMax, histMax);
+  
+  legend = new TLegend(0.3, 0.2, 0.78, 0.4);
+  legend->SetFillColor(0);
+  legend->SetTextSize(0.04);
+  legend->AddEntry(histESD, "Inelastic events", "P");
+  legend->AddEntry(histESDnsd, "NSD events", "P");
+  
+  dummy->Draw();
+  
+  // syst errors.
+  TH1* systError = (TH1*) histESD->Clone("systError");
+  for (Int_t i=1; i<=systError->GetNbinsX(); ++i)
+    systError->SetBinError(i, systError->GetBinContent(i) * systErrorValue);
+  // change error drawing style
+  systError->SetFillColor(15);    
+  systError->DrawCopy("SAME E2 ][");
+  
+  // syst error NSD
+  for (Int_t i=1; i<=systError->GetNbinsX(); ++i)
+  {
+    systError->SetBinContent(i, histESDnsd->GetBinContent(i));
+    systError->SetBinError(i, systError->GetBinContent(i) * systErrorNSDValue);
+  }
+  systError->DrawCopy("SAME E2 ][");
+  
+  histESD->Draw("SAME");
+  histESDnsd->Draw("SAME");
+  legend->Draw();  
+  
+  canvas->SaveAs(Form("%s_dndeta_final.eps", (spd) ? "spd" : "tpc"));
+}
+
+void dNdEtaPythiaPhojet()
+{
+  // evtl. deactivate acceptance maps in dNdEtaAnalysis.cxx
+
+  loadlibs();
+
+  TH1* hist[4];
+  
+  TFile::Open("LHC08c11_10TeV_0.5T/mb1/spd/analysis_mc.root");
+  hist[0] =         (TH1*) GetMCHist("dndeta", -1, "MC: full inelastic")->Clone("histMC");
+  hist[1] =         (TH1*) GetMCHist("dndetaNSD", -1, "MC: NSD")->Clone("histMCnsd");
+
+  TFile::Open("LHC08c15_10TeV_0.5T_Phojet/mb1/spd/analysis_mc.root");
+  hist[2] =         (TH1*) GetMCHist("dndeta", -1, "MC: full inelastic")->Clone("histMCPhojet");
+  hist[3] =         (TH1*) GetMCHist("dndetaNSD", -1, "MC: NSD")->Clone("histMCnsdPhojet");
+  
+  file = TFile::Open("pythia_phojet_dndeta.root", "RECREATE");
+  for (Int_t i=0; i<4; i++)
+    hist[i]->Write();
+  file->Close();
+}
 void dNdEta(Bool_t onlyESD = kFALSE, Bool_t save = kTRUE)
 {
+  loadlibs();
+
   TFile* file = TFile::Open("analysis_esd.root");
+  
+  dNdEtaAnalysis* fdNdEtaAnalysis = new dNdEtaAnalysis("dndeta", "dndeta");
+  fdNdEtaAnalysis->LoadHistograms("dndeta");
+  
   TH1* histESD = (TH1*) file->Get("dndeta/dNdEta_corrected");
   TH1* histESDnsd = (TH1*) file->Get("dndetaNSD/dNdEta_corrected");
+  TH1* histESDnsdNoPt = (TH1*) file->Get("dndetaNSD/dNdEta");
   TH1* histESDNoPt = (TH1*) file->Get("dndeta/dNdEta");
   TH1* histESDMB = (TH1*) file->Get("dndetaTr/dNdEta_corrected");
   TH1* histESDMBNoPt = (TH1*) file->Get("dndetaTr/dNdEta");
@@ -357,17 +473,17 @@ void dNdEta(Bool_t onlyESD = kFALSE, Bool_t save = kTRUE)
   histESD->SetMarkerColor(1);
   histESDnsd->SetMarkerColor(6);
   histESDMB->SetMarkerColor(2);
-  histESDMBVtx->SetMarkerColor(3);
+  histESDMBVtx->SetMarkerColor(4);
 
   histESD->SetLineColor(1);
   histESDnsd->SetLineColor(6);
   histESDMB->SetLineColor(2);
-  histESDMBVtx->SetLineColor(3);
+  histESDMBVtx->SetLineColor(4);
 
   histESDNoPt->SetMarkerColor(1);
   histESDMBNoPt->SetMarkerColor(2);
-  histESDMBVtxNoPt->SetMarkerColor(3);
-  histESDMBTracksNoPt->SetMarkerColor(4);
+  histESDMBVtxNoPt->SetMarkerColor(4);
+  histESDMBTracksNoPt->SetMarkerColor(3);
 
   histESD->SetMarkerStyle(20);
   histESDnsd->SetMarkerStyle(29);
@@ -379,9 +495,10 @@ void dNdEta(Bool_t onlyESD = kFALSE, Bool_t save = kTRUE)
   histESDMBVtxNoPt->SetMarkerStyle(22);
   histESDMBTracksNoPt->SetMarkerStyle(23);
   
-  //Float_t etaLimit = 1.2999;
-  Float_t etaLimit = 2.41;
-  Float_t etaPlotLimit = 2.6;
+  Float_t etaLimit = (fdNdEtaAnalysis->GetAnalysisMode() == AliPWG0Helper::kTPC) ? 0.89 : 1.79;
+  Float_t etaPlotLimit = (fdNdEtaAnalysis->GetAnalysisMode() == AliPWG0Helper::kTPC) ? 1.2 : 2.3;
+  //Float_t etaLimit = (fdNdEtaAnalysis->GetAnalysisMode() == AliPWG0Helper::kTPC) ? 0.89 : 1.39;
+  //Float_t etaPlotLimit = (fdNdEtaAnalysis->GetAnalysisMode() == AliPWG0Helper::kTPC) ? 1.2 : 1.9;
 
   histESDMBVtx->GetXaxis()->SetRangeUser(-etaLimit, etaLimit);
   histESDMB->GetXaxis()->SetRangeUser(-etaLimit, etaLimit);
@@ -396,7 +513,13 @@ void dNdEta(Bool_t onlyESD = kFALSE, Bool_t save = kTRUE)
   Float_t max = TMath::Max(histESDMBVtx->GetMaximum(), histESDMB->GetMaximum());
   max = TMath::Max(max, histESD->GetMaximum());
 
-  TH2F* dummy = new TH2F("dummy", "", 100, -etaPlotLimit, etaPlotLimit, 1000, 0, max * 1.1);
+  TLegend* legend = new TLegend(0.35, 0.05, 0.75, 0.4);
+  legend->SetFillColor(0);
+  legend->AddEntry(histESDMBVtx, "Triggered, vertex");
+  legend->AddEntry(histESDMB, "Triggered");
+  legend->AddEntry(histESD, "All events");
+
+  TH2F* dummy = new TH2F("dummy", "", 100, -etaPlotLimit, etaPlotLimit, 1000, 2.1, max * 1.1);
   Prepare1DPlot(dummy);
   dummy->SetStats(kFALSE);
   dummy->SetXTitle("#eta");
@@ -409,6 +532,7 @@ void dNdEta(Bool_t onlyESD = kFALSE, Bool_t save = kTRUE)
   histESDMBVtx->Draw("SAME");
   histESDMB->Draw("SAME");
   histESD->Draw("SAME");
+  legend->Draw();
 
   if (save)
   {
@@ -423,15 +547,18 @@ void dNdEta(Bool_t onlyESD = kFALSE, Bool_t save = kTRUE)
 
   TFile* file2 = TFile::Open("analysis_mc.root");
 
+  TH1* histMCTrVtx =       (TH1*) GetMCHist("dndetaTrVtx", -1, "MC: MB with trigger")->Clone("histMCTrVtx");
+  TH1* ratioTrVtx = (TH1*) DrawdNdEtaRatio(histESDMBVtx, histMCTrVtx, "triggered_vertex", etaPlotLimit)->Clone();
+  
   TH1* histMC =            (TH1*) GetMCHist("dndeta", -1, "MC: full inelastic")->Clone("histMC");
   TH1* histMCTr =          (TH1*) GetMCHist("dndetaTr", -1, "MC: minimum bias")->Clone("histMCTr");
-  TH1* histMCTrVtx =       (TH1*) GetMCHist("dndetaTrVtx", -1, "MC: MB with trigger")->Clone("histMCTrVtx");
   TH1* histMCnsd =         (TH1*) GetMCHist("dndetaNSD", -1, "MC: NSD")->Clone("histMCnsd");
 
-  TH1* histMCPtCut =       (TH1*) GetMCHist("dndeta", 0.3, "MC: full inelastic, pt cut")->Clone("histMCPtCut");
-  TH1* histMCTrPtCut =     (TH1*) GetMCHist("dndetaTr", 0.3, "MC: minimum bias, pt cut")->Clone("histMCTrPtCut");
-  TH1* histMCTrVtxPtCut =  (TH1*) GetMCHist("dndetaTrVtx", 0.3, "MC: MB with trigger, pt cut")->Clone("histMCTrVtxPtCut");
-  TH1* histMCTracksPtCut = (TH1*) GetMCHist("dndetaTracks", 0.3, "MC: Tracks w/o resolution effect, pt cut")->Clone("histMCTracksPtCut");
+  TH1* histMCPtCut =       (TH1*) GetMCHist("dndeta", 0.21, "MC: full inelastic, pt cut")->Clone("histMCPtCut");
+  TH1* histMCTrPtCut =     (TH1*) GetMCHist("dndetaTr", 0.21, "MC: minimum bias, pt cut")->Clone("histMCTrPtCut");
+  TH1* histMCTrVtxPtCut =  (TH1*) GetMCHist("dndetaTrVtx", 0.21, "MC: MB with trigger, pt cut")->Clone("histMCTrVtxPtCut");
+  TH1* histMCnsdNoPt =     (TH1*) GetMCHist("dndetaNSD", 0.21, "MC: NSD, put cut")->Clone("histMCnsdNoPt");
+  TH1* histMCTracksPtCut = (TH1*) GetMCHist("dndetaTracks", 0.21, "MC: Tracks w/o resolution effect, pt cut")->Clone("histMCTracksPtCut");
 
   Prepare1DPlot(histMC);
   Prepare1DPlot(histMCnsd);
@@ -456,13 +583,13 @@ void dNdEta(Bool_t onlyESD = kFALSE, Bool_t save = kTRUE)
   histMC->SetLineColor(1);
   histMCnsd->SetLineColor(6);
   histMCTr->SetLineColor(2);
-  histMCTrVtx->SetLineColor(3);
+  histMCTrVtx->SetLineColor(4);
 
   histMCPtCut->SetLineColor(1);
   histMCTrPtCut->SetLineColor(2);
-  histMCTrVtxPtCut->SetLineColor(3);
+  histMCTrVtxPtCut->SetLineColor(4);
   if (histMCTracksPtCut)
-    histMCTracksPtCut->SetLineColor(4);
+    histMCTracksPtCut->SetLineColor(3);
 
   TCanvas* canvas2 = new TCanvas("dNdEta2", "dNdEta2", 500, 500);
 
@@ -494,17 +621,99 @@ void dNdEta(Bool_t onlyESD = kFALSE, Bool_t save = kTRUE)
     canvas2->SaveAs("dNdEta2.eps");
   }
 
-  DrawdNdEtaRatio(histESD, histMC, "full_inelastic", etaPlotLimit);
-  DrawdNdEtaRatio(histESDMB, histMCTr, "triggered", etaPlotLimit);
-  DrawdNdEtaRatio(histESDMBVtx, histMCTrVtx, "triggered_vertex", etaPlotLimit);
-  DrawdNdEtaRatio(histESDnsd, histMCnsd, "NSD", etaPlotLimit);
+  TH1* ratio = (TH1*) DrawdNdEtaRatio(histESD, histMC, "full_inelastic", etaPlotLimit)->Clone();
+  TH1* ratioTr = (TH1*) DrawdNdEtaRatio(histESDMB, histMCTr, "triggered", etaPlotLimit)->Clone();
+  TH1* ratioTrVtx = (TH1*) DrawdNdEtaRatio(histESDMBVtx, histMCTrVtx, "triggered_vertex", etaPlotLimit)->Clone();
+  TH1* ratioTrVtxNoPt = (TH1*) DrawdNdEtaRatio(histESDMBVtxNoPt, histMCTrVtxPtCut, "triggered_vertex_nopt", etaPlotLimit)->Clone();
+  TH1* ratioNSD = (TH1*) DrawdNdEtaRatio(histESDnsd, histMCnsd, "NSD", etaPlotLimit)->Clone();
+
+  // draw ratios of single steps
+  c7 = new TCanvas("all_ratios", "all_ratios", 600, 600);
+  c7->SetRightMargin(0.05);
+  c7->SetTopMargin(0.05);
+  c7->SetGridx();
+  c7->SetGridy();
+  
+  ratioTrVtxNoPt->SetMarkerStyle(20);
+  ratioTrVtx->SetMarkerStyle(21);
+  ratioTr->SetMarkerStyle(23);
+  ratio->SetMarkerStyle(22);
+  ratioNSD->SetMarkerStyle(26);
+  
+  ratioTrVtxNoPt->SetMarkerSize(2);
+  ratioTrVtx->SetMarkerSize(2);
+  ratioTr->SetMarkerSize(2);
+  ratio->SetMarkerSize(2);
+  ratioNSD->SetMarkerSize(2);
+  
+  ratioTrVtxNoPt->SetMarkerColor(1);
+  ratioTrVtx->SetMarkerColor(2);
+  ratioTr->SetMarkerColor(4);
+  ratio->SetMarkerColor(2);
+  ratioNSD->SetMarkerColor(1);
+  
+  ratioTrVtxNoPt->SetLineColor(1);
+  ratioTrVtx->SetLineColor(2);
+  ratioTr->SetLineColor(4);
+  ratio->SetLineColor(2);
+  ratioNSD->SetLineColor(1);
+  
+  legend7 = new TLegend(0.13, 0.7, 0.94, 0.9);
+  legend7->SetFillColor(0);
+  legend7->SetTextSize(0.035);
+  legend7->SetNColumns(2);
+  
+  flat = new TF1("flat", "-1", -5, 5);
+  ratioTrVtxNoPt->Add(flat);
+  ratioTrVtx->Add(flat);
+  ratioTr->Add(flat);
+  ratio->Add(flat);
+  ratioNSD->Add(flat);
+  
+  ratioTrVtxNoPt->Scale(100);
+  ratioTrVtx->Scale(100);
+  ratioTr->Scale(100);
+  ratio->Scale(100);
+  ratioNSD->Scale(100);
+  
+  ratio->Add(ratioTr, -1);
+  ratioNSD->Add(ratioTr, -1);
+  ratioTr->Add(ratioTrVtx, -1);
+  ratioTrVtx->Add(ratioTrVtxNoPt, -1);
+  
+  legend7->AddEntry(ratioTrVtxNoPt, "Track-to-particle", "P");
+  legend7->AddEntry(ratio, "Trigger-bias INEL", "P");
+  legend7->AddEntry(ratioTr, "Vertex-reconstruction", "P");
+  legend7->AddEntry(ratioNSD, "Trigger-bias NSD", "P");
+  if (fdNdEtaAnalysis->GetAnalysisMode() == AliPWG0Helper::kTPC)
+    legend7->AddEntry(ratioTrVtx, "p_{T} cut-off", "P");
+  
+  TH1* dummy7 = new TH2F("dummy7", ";#eta;Deviation in %", 100, -etaPlotLimit, etaPlotLimit, 100, -5, 7);
+  dummy7->SetStats(0);
+  dummy7->Draw();
+  
+  ratio->GetXaxis()->SetRangeUser(-etaLimit, etaLimit);
+  ratioTr->GetXaxis()->SetRangeUser(-etaLimit, etaLimit);
+  ratioTrVtx->GetXaxis()->SetRangeUser(-etaLimit, etaLimit);
+  ratioTrVtxNoPt->GetXaxis()->SetRangeUser(-etaLimit, etaLimit);
+  ratioNSD->GetXaxis()->SetRangeUser(-etaLimit, etaLimit);
+  
+  ratio->Draw("HIST EP SAME");
+  ratioTr->Draw("HIST EP SAME");
+  if (fdNdEtaAnalysis->GetAnalysisMode() == AliPWG0Helper::kTPC)
+    ratioTrVtx->Draw("HIST EP SAME");
+  ratioTrVtxNoPt->Draw("HIST EP SAME");
+  ratioNSD->Draw("HIST EP SAME");
+  legend7->Draw();
+  
+  c7->SaveAs("ratios.eps");
 
   new TCanvas;
   dummy2->DrawCopy();
   histMCnsd->Draw("SAME");
   histESDnsd->Draw("SAME");
 
-  TH1* ratio = (TH1*) histMC->Clone("ratio");
+  ratio = (TH1*) histMC->Clone("ratio");
   TH1* ratioNoPt = (TH1*) histMCPtCut->Clone("ratioNoPt");
 
   ratio->Divide(histESD);
@@ -527,66 +736,70 @@ void dNdEta(Bool_t onlyESD = kFALSE, Bool_t save = kTRUE)
   PrintIntegratedDeviation(histMCTr, histESDMB, "triggered");
   PrintIntegratedDeviation(histMCTrVtx, histESDMBVtx, "trigger, vertex");
   PrintIntegratedDeviation(histMCPtCut, histESDNoPt, "all events (no pt corr)");
+  PrintIntegratedDeviation(histMCnsdNoPt, histESDnsdNoPt, "all events (NSD) (no pt corr)");
   PrintIntegratedDeviation(histMCTrPtCut, histESDMBNoPt, "triggered (no pt corr)");
   PrintIntegratedDeviation(histMCTrVtxPtCut, histESDMBVtxNoPt, "trigger, vertex (no pt corr)");
 
-  TCanvas* canvas3 = new TCanvas("dNdEta", "dNdEta", 700, 600);
+  TCanvas* canvas3 = new TCanvas("dNdEta", "dNdEta", 600, 600);
   canvas3->Range(0, 0, 1, 1);
   //canvas3->Divide(1, 2, 0, 0);
 
   //canvas3->cd(1);
   TPad* pad1 = new TPad("dNdEta_1", "", 0, 0.5, 0.98, 0.98);
+  pad1->SetTopMargin(0.05);
+  pad1->SetLeftMargin(0.13);
   pad1->Draw();
 
   TPad* pad2 = new TPad("dNdEta_2", "", 0, 0.02, 0.98, 0.5);
+  pad2->SetLeftMargin(0.13);
   pad2->Draw();
 
-  pad1->SetRightMargin(0.05);
-  pad2->SetRightMargin(0.05);
+  pad1->SetRightMargin(0.01);
+  pad2->SetRightMargin(0.01);
 
   // no border between them
   pad1->SetBottomMargin(0);
   pad2->SetTopMargin(0);
 
   pad1->cd();
+  pad1->SetGridx();
+  pad1->SetGridy();
 
-  TLegend* legend = new TLegend(0.4, 0.05, 0.65, 0.3);
-  legend->SetFillColor(0);
-  legend->AddEntry(histESDMBVtx, "triggered, vertex");
-  legend->AddEntry(histESDMB, "triggered");
-  legend->AddEntry(histESD, "all events");
   legend->AddEntry(histMC, "MC prediction");
 
-  dummy->GetXaxis()->SetLabelSize(0.06);
-  dummy->GetYaxis()->SetLabelSize(0.06);
-  dummy->GetXaxis()->SetTitleSize(0.06);
-  dummy->GetYaxis()->SetTitleSize(0.06);
-  dummy->GetYaxis()->SetTitleOffset(0.7);
+  dummy->GetXaxis()->SetLabelSize(0.08);
+  dummy->GetYaxis()->SetLabelSize(0.08);
+  dummy->GetXaxis()->SetTitleSize(0.08);
+  dummy->GetYaxis()->SetTitleSize(0.08);
+  dummy->GetYaxis()->SetTitleOffset(0.8);
   dummy->DrawCopy();
   histESDMBVtx->Draw("SAME");
   histESDMB->Draw("SAME");
   histESD->Draw("SAME");
   histMC->Draw("SAME");
 
+  legend->SetTextSize(0.08);
   legend->Draw();
 
   pad2->cd();
   pad2->SetBottomMargin(0.15);
+  //pad2->SetGridx();
+  //pad2->SetGridy();
 
-  Float_t minR = 0.9; //TMath::Min(0.961, ratio->GetMinimum() * 0.95);
-  Float_t maxR = 1.1; //TMath::Max(1.049, ratio->GetMaximum() * 1.05);
+  Float_t minR = 0.91; //TMath::Min(0.961, ratio->GetMinimum() * 0.95);
+  Float_t maxR = 1.09; //TMath::Max(1.049, ratio->GetMaximum() * 1.05);
 
-  TH1F dummy3("dummy3", ";#eta;Ratio: MC / ESD", 100, -etaPlotLimit, etaPlotLimit);
+  TH1F dummy3("dummy3", ";#eta;Ratio: MC / corr", 100, -etaPlotLimit, etaPlotLimit);
   dummy3.SetStats(kFALSE);
   for (Int_t i=1; i<=100; ++i)
     dummy3.SetBinContent(i, 1);
   dummy3.GetYaxis()->SetRangeUser(minR, maxR);
   dummy3.SetLineWidth(2);
-  dummy3.GetXaxis()->SetLabelSize(0.06);
-  dummy3.GetYaxis()->SetLabelSize(0.06);
-  dummy3.GetXaxis()->SetTitleSize(0.06);
-  dummy3.GetYaxis()->SetTitleSize(0.06);
-  dummy3.GetYaxis()->SetTitleOffset(0.7);
+  dummy3.GetXaxis()->SetLabelSize(0.08);
+  dummy3.GetYaxis()->SetLabelSize(0.08);
+  dummy3.GetXaxis()->SetTitleSize(0.08);
+  dummy3.GetYaxis()->SetTitleSize(0.08);
+  dummy3.GetYaxis()->SetTitleOffset(0.8);
   dummy3.DrawCopy();
 
   ratio->Draw("SAME");
@@ -613,9 +826,9 @@ void dNdEta(Bool_t onlyESD = kFALSE, Bool_t save = kTRUE)
   legend->Draw();
 }
 
-void DrawdNdEtaRatio(TH1* corr, TH1* mc, const char* name, Float_t etaPlotLimit)
+TH1* DrawdNdEtaRatio(TH1* corr, TH1* mc, const char* name, Float_t etaPlotLimit)
 {
-  TCanvas* canvas3 = new TCanvas(name, name, 700, 600);
+  TCanvas* canvas3 = new TCanvas(name, name, 600, 600);
   canvas3->Range(0, 0, 1, 1);
 
   TPad* pad1 = new TPad(Form("%s_1", name), "", 0, 0.5, 0.98, 0.98);
@@ -624,32 +837,39 @@ void DrawdNdEtaRatio(TH1* corr, TH1* mc, const char* name, Float_t etaPlotLimit)
   TPad* pad2 = new TPad(Form("%s_2", name), "", 0, 0.02, 0.98, 0.5);
   pad2->Draw();
 
-  pad1->SetRightMargin(0.05);
-  pad2->SetRightMargin(0.05);
-
+  pad1->SetRightMargin(0.01);
+  pad2->SetRightMargin(0.01);
+  pad1->SetTopMargin(0.05);
+  pad1->SetLeftMargin(0.13);
+  pad2->SetLeftMargin(0.13);
+  pad2->SetBottomMargin(0.15);
+  
   // no border between them
   pad1->SetBottomMargin(0);
   pad2->SetTopMargin(0);
 
   pad1->cd();
+  pad1->SetGridx();
+  pad1->SetGridy();
 
-  TLegend* legend = new TLegend(0.4, 0.05, 0.65, 0.3);
+  TLegend* legend = new TLegend(0.35, 0.05, 0.75, 0.3);
   legend->SetFillColor(0);
-  legend->AddEntry(corr, "corrected");
+  legend->AddEntry(corr, "Corrected");
   legend->AddEntry(mc, "MC prediction");
+  legend->SetTextSize(0.08);
 
-  TH2F* dummy = new TH2F("dummy", "", 100, -etaPlotLimit, etaPlotLimit, 1000, 0, corr->GetMaximum() * 1.1);
+  TH2F* dummy = new TH2F("dummy", "", 100, -etaPlotLimit, etaPlotLimit, 1000, 3.1, corr->GetMaximum() * 1.1);
   Prepare1DPlot(dummy);
   dummy->SetStats(kFALSE);
   dummy->SetXTitle("#eta");
   dummy->SetYTitle("dN_{ch}/d#eta");
   dummy->GetYaxis()->SetTitleOffset(1);
 
-  dummy->GetXaxis()->SetLabelSize(0.06);
-  dummy->GetYaxis()->SetLabelSize(0.06);
-  dummy->GetXaxis()->SetTitleSize(0.06);
-  dummy->GetYaxis()->SetTitleSize(0.06);
-  dummy->GetYaxis()->SetTitleOffset(0.7);
+  dummy->GetXaxis()->SetLabelSize(0.08);
+  dummy->GetYaxis()->SetLabelSize(0.08);
+  dummy->GetXaxis()->SetTitleSize(0.08);
+  dummy->GetYaxis()->SetTitleSize(0.08);
+  dummy->GetYaxis()->SetTitleOffset(0.8);
   dummy->DrawCopy();
 
   corr->Draw("SAME");
@@ -659,12 +879,14 @@ void DrawdNdEtaRatio(TH1* corr, TH1* mc, const char* name, Float_t etaPlotLimit)
 
   pad2->cd();
   pad2->SetBottomMargin(0.15);
+  //pad2->SetGridx();
+  //pad2->SetGridy();
 
   TH1* ratio = (TH1*) mc->Clone("ratio");
   ratio->Divide(corr);
 
-  Float_t minR = TMath::Min(0.961, ratio->GetMinimum() * 0.95);
-  Float_t maxR = TMath::Max(1.049, ratio->GetMaximum() * 1.05);
+  Float_t minR = TMath::Min(0.91, ratio->GetMinimum() * 0.95);
+  Float_t maxR = TMath::Max(1.09, ratio->GetMaximum() * 1.05);
 
   TH1F dummy3("dummy3", ";#eta;Ratio: MC / corr", 100, -etaPlotLimit, etaPlotLimit);
   dummy3.SetStats(kFALSE);
@@ -672,16 +894,18 @@ void DrawdNdEtaRatio(TH1* corr, TH1* mc, const char* name, Float_t etaPlotLimit)
        dummy3.SetBinContent(i, 1);
   dummy3.GetYaxis()->SetRangeUser(minR, maxR);
   dummy3.SetLineWidth(2);
-  dummy3.GetXaxis()->SetLabelSize(0.06);
-  dummy3.GetYaxis()->SetLabelSize(0.06);
-  dummy3.GetXaxis()->SetTitleSize(0.06);
-  dummy3.GetYaxis()->SetTitleSize(0.06);
-  dummy3.GetYaxis()->SetTitleOffset(0.7);
+  dummy3.GetXaxis()->SetLabelSize(0.08);
+  dummy3.GetYaxis()->SetLabelSize(0.08);
+  dummy3.GetXaxis()->SetTitleSize(0.08);
+  dummy3.GetYaxis()->SetTitleSize(0.08);
+  dummy3.GetYaxis()->SetTitleOffset(0.8);
   dummy3.DrawCopy();
 
   ratio->Draw("SAME");
 
   canvas3->Modified();
+
+  return ratio;
 }
 
 void ptSpectrum()
@@ -921,8 +1145,8 @@ void VtxRecon1D(const char* fileName = "correction_map.root", const char* folder
   corrX->SetTitle("a) z projection");
   corrZ->SetTitle("b) p_{T} projection");
 
-  corrX->GetYaxis()->SetTitle("correction factor");
-  corrZ->GetYaxis()->SetTitle("correction factor");
+  corrX->GetYaxis()->SetTitle("Correction factor");
+  corrZ->GetYaxis()->SetTitle("Correction factor");
 
   corrZ->GetXaxis()->SetRangeUser(0.11, 9.9);
 
@@ -985,14 +1209,17 @@ void Track2ParticleAsNumber(const char* fileName = "correction_map.root")
   printf("Correction with 0.3 < pT < 0.5: %f +- %f\n", eff3, error3);
 }
 
-void Correction1DCreatePlots(const char* fileName = "correction_map.root", const char* folderName = "dndeta_correction", Float_t upperPtLimit = 9.9, Int_t correctionType = 0)
+void Correction1DCreatePlots(const char* fileName = "correction_map.root", const char* folderName = "dndeta_correction", Float_t upperPtLimit = 9.9, Int_t correctionType = 0, Int_t correctionType2 = -1)
 {
+  if (correctionType2 == -1)
+    correctionType2 = correctionType;
+
   TFile::Open(fileName);
   AlidNdEtaCorrection* dNdEtaCorrection = new AlidNdEtaCorrection(folderName, folderName);
   dNdEtaCorrection->LoadHistograms();
 
   TH3F* gene = dNdEtaCorrection->GetCorrection(correctionType)->GetTrackCorrection()->GetGeneratedHistogram();
-  TH3F* meas = dNdEtaCorrection->GetCorrection(correctionType)->GetTrackCorrection()->GetMeasuredHistogram();
+  TH3F* meas = dNdEtaCorrection->GetCorrection(correctionType2)->GetTrackCorrection()->GetMeasuredHistogram();
 
   gene->GetZaxis()->SetRangeUser(0.3, upperPtLimit);
   meas->GetZaxis()->SetRangeUser(0.3, upperPtLimit);
@@ -1013,11 +1240,11 @@ void Correction1DCreatePlots(const char* fileName = "correction_map.root", const
   AliPWG0Helper::CreateDividedProjections(gene, meas, "z", kFALSE);
 }
 
-TCanvas* Correction1D(Int_t correctionType = 0, const char* fileName = "correction_map.root", const char* folder = "dndeta_correction", Float_t upperPtLimit = 9.9)
+TCanvas* Correction1D(Int_t correctionType = 0, const char* fileName = "correction_map.root", const char* folder = "dndeta_correction", Float_t upperPtLimit = 9.9, Int_t correctionType2 = -1)
 {
   gSystem->Load("libPWG0base");
 
-  Correction1DCreatePlots(fileName, folder, upperPtLimit, correctionType);
+  Correction1DCreatePlots(fileName, folder, upperPtLimit, correctionType, correctionType2);
 
   TH1* corrX = dynamic_cast<TH1*> (gROOT->FindObject(Form("generated_x_div_measured_x", folder, folder)));
   TH1* corrY = dynamic_cast<TH1*> (gROOT->FindObject(Form("generated_y_div_measured_y", folder, folder)));
@@ -1027,16 +1254,29 @@ TCanvas* Correction1D(Int_t correctionType = 0, const char* fileName = "correcti
   Prepare1DPlot(corrY);
   Prepare1DPlot(corrZ);
 
+  /*
   corrX->SetTitle("a) z projection");
   corrY->SetTitle("b) #eta projection");
   corrZ->SetTitle("c) p_{T} projection");
-
-  corrX->GetYaxis()->SetTitle("correction factor");
-  corrY->GetYaxis()->SetTitle("correction factor");
-  corrZ->GetYaxis()->SetTitle("correction factor");
-  corrX->GetYaxis()->SetTitleOffset(1.7);
-  corrY->GetYaxis()->SetTitleOffset(1.7);
-  corrZ->GetYaxis()->SetTitleOffset(1.7);
+  */
+  
+  corrX->SetTitle("");
+  corrY->SetTitle("");
+  corrZ->SetTitle("");
+
+  corrX->SetTitleSize(0.06, "xyz");
+  corrX->SetLabelSize(0.06, "xyz");
+  corrY->SetTitleSize(0.06, "xyz");
+  corrY->SetLabelSize(0.06, "xyz");
+  corrZ->SetTitleSize(0.06, "xyz");
+  corrZ->SetLabelSize(0.06, "xyz");
+
+  corrX->GetYaxis()->SetTitle("Correction factor");
+  corrY->GetYaxis()->SetTitle("Correction factor");
+  corrZ->GetYaxis()->SetTitle("Correction factor");
+  //corrX->GetYaxis()->SetTitleOffset(1.7);
+  //corrY->GetYaxis()->SetTitleOffset(1.7);
+  //corrZ->GetYaxis()->SetTitleOffset(1.7);
   corrX->GetYaxis()->SetRangeUser(0.8, 1.5);
   corrY->GetYaxis()->SetRangeUser(0.8, 1.5);
   corrZ->GetYaxis()->SetRangeUser(0.8, 1.5);
@@ -1049,27 +1289,35 @@ TCanvas* Correction1D(Int_t correctionType = 0, const char* fileName = "correcti
   canvas->Divide(3, 1);
 
   TLatex* Tl = new TLatex;
-  Tl->SetTextSize(0.04);
+  Tl->SetTextSize(0.06);
   Tl->SetBit(TLatex::kTextNDC);
 
   canvas->cd(1);
   InitPad();
+  gPad->SetTopMargin(0.05);
+  gPad->SetBottomMargin(0.15);
   corrX->DrawCopy();
-  Tl->DrawLatex(0.6, 0.8, "0.3 < p_{T} < 10");
-  Tl->DrawLatex(0.6, 0.75, "|#eta| < 0.8");
+  Tl->DrawLatex(0.5, 0.88, "0.3 < p_{T} < 10");
+  Tl->DrawLatex(0.5, 0.8, "|#eta| < 0.8");
 
   canvas->cd(2);
   InitPad();
+  gPad->SetTopMargin(0.05);
+  gPad->SetBottomMargin(0.15);
   corrY->Draw();
-  Tl->DrawLatex(0.6, 0.8, "0.3 < p_{T} < 10");
-  Tl->DrawLatex(0.6, 0.75, "|vtx-z| < 10");
+  Tl->DrawLatex(0.5, 0.88, "0.3 < p_{T} < 10");
+  Tl->DrawLatex(0.5, 0.8, "|vtx-z| < 10 cm");
 
   canvas->cd(3);
   InitPad();
+  gPad->SetTopMargin(0.05);
+  gPad->SetBottomMargin(0.15);
   gPad->SetLogx();
   corrZ->Draw();
-  Tl->DrawLatex(0.6, 0.8, "|vtx-z| < 10");
-  Tl->DrawLatex(0.6, 0.75, "|#eta| < 0.8");
+  corrZ->GetXaxis()->SetLabelOffset(0.005);
+  corrZ->GetXaxis()->SetTitleOffset(1.2);
+  Tl->DrawLatex(0.5, 0.88, "|vtx-z| < 10 cm");
+  Tl->DrawLatex(0.5, 0.8, "|#eta| < 0.8");
 
   return canvas;
 }
@@ -1150,6 +1398,7 @@ void Track2Particle1D(const char* fileName = "correction_map.root", const char*
   canvas->SaveAs(Form("Track2Particle1D_etapt_%s_%f.gif", fileName, upperPtLimit));
 }
 
+/*
 void CompareTrack2Particle1D(Float_t upperPtLimit = 9.9)
 {
   gSystem->Load("libPWG0base");
@@ -1227,6 +1476,7 @@ void CompareTrack2Particle1D(Float_t upperPtLimit = 9.9)
     canvas->SaveAs(Form("%s.eps", canvas->GetName()));
   }
 }
+*/
 
 void CompareTrack2Particle1D(const char* file1, const char* file2, Float_t upperPtLimit = 9.9)
 {
@@ -1275,8 +1525,8 @@ void Track2Particle2DCreatePlots(const char* fileName = "correction_map.root")
   TH3F* gene = dNdEtaCorrection->GetTrack2ParticleCorrection()->GetTrackCorrection()->GetGeneratedHistogram();
   TH3F* meas = dNdEtaCorrection->GetTrack2ParticleCorrection()->GetTrackCorrection()->GetMeasuredHistogram();
 
-  gene->GetZaxis()->SetRangeUser(0.3, 10);
-  meas->GetZaxis()->SetRangeUser(0.3, 10);
+  gene->GetZaxis()->SetRangeUser(0.2, 10);
+  meas->GetZaxis()->SetRangeUser(0.2, 10);
   AliPWG0Helper::CreateDividedProjections(gene, meas, "yx");
   gene->GetZaxis()->SetRange(0, 0);
   meas->GetZaxis()->SetRange(0, 0);
@@ -1610,7 +1860,7 @@ void drawPlots()
   drawPlots(2);
 }
 
-void CompareCorrection2Measured(const char* dataInput = "analysis_esd_raw.root", const char* correctionMapFile = "correction_map.root", const char* correctionMapFolder = "dndeta_correction")
+void CompareCorrection2Measured(Float_t ptMin = 0.301, const char* dataInput = "analysis_esd_raw.root", const char* correctionMapFile = "correction_map.root", const char* correctionMapFolder = "dndeta_correction")
 {
   loadlibs();
 
@@ -1634,12 +1884,57 @@ void CompareCorrection2Measured(const char* dataInput = "analysis_esd_raw.root",
   TH3* hist1 = (TH3*) dNdEtaCorrection->GetTrack2ParticleCorrection()->GetTrackCorrection()->GetMeasuredHistogram()->Clone("mc");
   hist1->SetTitle("mc");
   Printf("mc contains %f entries", hist1->Integral());
-  Printf("mc contains %f entries in |vtx-z| < 10, pt > 0.3", hist1->Integral(hist1->GetXaxis()->FindBin(-9.9), hist1->GetXaxis()->FindBin(9.9), 1, hist1->GetNbinsY(), hist1->GetZaxis()->FindBin(0.301), hist1->GetNbinsZ()));
+  Printf("mc contains %f entries in |vtx-z| < 10, pt > 0.3", hist1->Integral(hist1->GetXaxis()->FindBin(-9.9), hist1->GetXaxis()->FindBin(9.9), hist1->GetYaxis()->FindBin(-0.99), hist1->GetYaxis()->FindBin(0.99), hist1->GetZaxis()->FindBin(ptMin), hist1->GetNbinsZ()));
 
   TH3* hist2 = (TH3*) fdNdEtaAnalysis->GetData()->GetTrackCorrection()->GetMeasuredHistogram()->Clone("esd");
   hist2->SetTitle("esd");
   Printf("esd contains %f entries", hist2->Integral());
-  Printf("esd contains %f entries in |vtx-z| < 10, pt > 0.3", hist2->Integral(hist2->GetXaxis()->FindBin(-9.9), hist2->GetXaxis()->FindBin(9.9), 1, hist2->GetNbinsY(), hist2->GetZaxis()->FindBin(0.301), hist2->GetNbinsZ()));
+  Printf("esd contains %f entries in |vtx-z| < 10, pt > 0.3", hist2->Integral(hist2->GetXaxis()->FindBin(-9.9), hist2->GetXaxis()->FindBin(9.9), hist2->GetYaxis()->FindBin(-0.99), hist2->GetYaxis()->FindBin(0.99), hist2->GetZaxis()->FindBin(ptMin), hist2->GetNbinsZ()));
+
+  AliPWG0Helper::CreateDividedProjections(hist1, hist2);
+  AliPWG0Helper::CreateDividedProjections(hist1, hist2, "x");
+
+  hist1->GetXaxis()->SetRange(hist1->GetXaxis()->FindBin(-10), hist2->GetXaxis()->FindBin(10));
+  hist2->GetXaxis()->SetRange(hist1->GetXaxis()->FindBin(-10), hist2->GetXaxis()->FindBin(10));
+  AliPWG0Helper::CreateDividedProjections(hist1, hist2, "y");
+
+  new TCanvas; gROOT->FindObject("mc_yx_div_esd_yx")->Draw("COLZ");
+  new TCanvas; gROOT->FindObject("mc_zx_div_esd_zx")->Draw("COLZ");
+  new TCanvas; gROOT->FindObject("mc_zy_div_esd_zy")->Draw("COLZ");
+  new TCanvas; gROOT->FindObject("mc_x_div_esd_x")->Draw("COLZ");
+  new TCanvas; gROOT->FindObject("mc_y_div_esd_y")->Draw("COLZ");
+}
+
+void CompareCorrection2Generated(Float_t ptMin = 0.301, const char* dataInput = "analysis_mc.root", const char* correctionMapFile = "correction_map.root", const char* correctionMapFolder = "dndeta_correction")
+{
+  loadlibs();
+
+  AlidNdEtaCorrection* dNdEtaCorrection = new AlidNdEtaCorrection(correctionMapFolder, correctionMapFolder);
+  TFile::Open(correctionMapFile);
+  dNdEtaCorrection->LoadHistograms();
+
+  TFile* file = TFile::Open(dataInput);
+
+  if (!file)
+  {
+    cout << "Error. File not found" << endl;
+    return;
+  }
+
+  dNdEtaAnalysis* fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaTrVtx", "dndetaTrVtx");
+  fdNdEtaAnalysis->LoadHistograms("dndetaTrVtx");
+
+  gROOT->cd();
+  
+  TH3* hist1 = (TH3*) dNdEtaCorrection->GetTrack2ParticleCorrection()->GetTrackCorrection()->GetGeneratedHistogram()->Clone("mc");
+  hist1->SetTitle("mc");
+  Printf("mc contains %f entries", hist1->Integral());
+  Printf("mc contains %f entries in |vtx-z| < 10, pt > 0.3", hist1->Integral(hist1->GetXaxis()->FindBin(-9.9), hist1->GetXaxis()->FindBin(9.9), hist1->GetYaxis()->FindBin(-0.99), hist1->GetYaxis()->FindBin(0.99), hist1->GetZaxis()->FindBin(ptMin), hist1->GetNbinsZ()));
+
+  TH3* hist2 = (TH3*) fdNdEtaAnalysis->GetData()->GetTrackCorrection()->GetGeneratedHistogram()->Clone("esd");
+  hist2->SetTitle("esd");
+  Printf("esd contains %f entries", hist2->Integral());
+  Printf("esd contains %f entries in |vtx-z| < 10, pt > 0.3", hist2->Integral(hist2->GetXaxis()->FindBin(-9.9), hist2->GetXaxis()->FindBin(9.9), hist2->GetYaxis()->FindBin(-0.99), hist2->GetYaxis()->FindBin(0.99), hist2->GetZaxis()->FindBin(ptMin), hist2->GetNbinsZ()));
 
   AliPWG0Helper::CreateDividedProjections(hist1, hist2);
   AliPWG0Helper::CreateDividedProjections(hist1, hist2, "x");
@@ -1722,41 +2017,104 @@ void CompareMeasured2Measured(const char* dataInput = "analysis_esd_raw.root", c
 
 }
 
-void DrawTrackletOrigin()
+void DrawTrackletOrigin(const char* fileName = "correction_map.root", Bool_t myFile = kTRUE)
 {
-  TFile::Open("correction_map.root");
-
-  Int_t colors[]  = {1,2,3,4,6,7,8,102};
+  TFile::Open(fileName);
 
   Int_t maxHists = 8;
   TH1* hist[8];
+  
+  const Int_t kRebin = 8;
 
-  const char* titles[] = { "PP", "SS", "PP'", "PS", "PS*", "SP", "SS'", "" };
+  const char* titles[] = { "PP", "SS", "PP'", "PS'", "PS", "SP'", "SS'", "" };
 
-  TLegend* legend = new TLegend(0.75, 0.6, 0.95, 0.95);
+  if (myFile)
+  {
+    for (Int_t i=0; i<maxHists; i++)
+    {
+      hist[i] = (TH1*) gFile->Get(Form("fDeltaPhi_%d", i));
+      if (hist[i]->GetDimension() == 2)
+        hist[i] = ((TH2*) hist[i])->ProjectionX(Form("fDeltaPhi_clone_%d", i));
+    }
+  }
+  else
+  {
+    maxHists = 6;
+    const char* names[] = { "DePhiPPTracklets", "DePhiSecTracklets", "DePhiPpTracklets", "DePhiPSTracklets", "DePhiPSdaugTracklets", "DePhiSPTracklets" }; 
+    for (Int_t i=0; i<maxHists; i++)
+      hist[i] = (TH1*) gFile->Get(names[i]);
+  }
+  
+  // clone before rebinning
+  good = (TH1*) hist[0]->Clone("good");
+  good->Add(hist[4]);
+  
+  bad = (TH1*) hist[1]->Clone("bad");
+  bad->Add(hist[2]);
+  bad->Add(hist[3]);
+  bad->Add(hist[5]);
+  if (myFile)
+    bad->Add(hist[6]);
+  
+  c = (TCanvas*) gROOT->GetListOfCanvases()->FindObject("c");
+  TH1* ref = 0;
+  Bool_t nw = kFALSE;
+  if (!c)
+  {
+    c = new TCanvas("c", "c", 600, 600);
+    nw = kTRUE;
+    ref = (TH1*) c->GetListOfPrimitives()->At(1);
+  }  
+  c->cd();
+  c->SetRightMargin(0.05);
+  c->SetTopMargin(0.05);
+  c->SetLogy();
+  c->SetGridx();
+  c->SetGridy();
+  
+  Int_t order[] = { 0, 4, 1, 2, 3, 5, 6, 7 };
+  //Int_t colors[]  = {1,2,4,1,2,4,1,2,4};
+  Int_t colors[]  = {1,2,3,4,6,7,8,102};
+  Int_t markers[]  = {20, 21, 22, 23, 24, 25, 26, 27, 28};
+  
+  TLegend* legend = new TLegend(0.75, 0.6, 0.93, 0.93);
+  legend->SetFillColor(0);
+  legend->SetTextSize(0.04);
 
   Int_t total = 0;
-  for (Int_t i=0; i<maxHists; i++)
+  for (Int_t ii=0; ii<maxHists; ii++)
   {
-    hist[i] = (TH1*) gFile->Get(Form("fDeltaPhi_%d", i));
-    //hist[i]->Rebin(20);
+    i = order[ii];
+    
+    hist[i]->Rebin(kRebin);
     hist[i]->SetStats(kFALSE);
     hist[i]->SetLineColor(colors[i]);
-    hist[i]->GetXaxis()->SetRangeUser(-0.2, 0.2);
-    hist[i]->Draw(((i == 0) ? "" : "SAME"));
+    hist[i]->SetLineWidth(2);
+    //hist[i]->SetMarkerStyle(markers[i]);
+    //hist[i]->SetMarkerColor(colors[i]);
+    //hist[i]->SetLineStyle(ii+1);
+    hist[i]->GetXaxis()->SetRangeUser(-0.09, 0.09);
+    hist[i]->GetYaxis()->SetRangeUser(5, hist[i]->GetMaximum() * 2);
+    hist[i]->GetYaxis()->SetTitleOffset(1.3);
+    hist[i]->GetXaxis()->SetTitle("#Delta#varphi (rad.)");
+    
+    if (i == 0 && ref)
+      hist[i]->Scale(1.0 / hist[i]->GetMaximum() * ref->GetMaximum());
+    
+    hist[i]->DrawCopy(((i == 0 && nw) ? "" : "SAME"));
 
     total += hist[i]->GetEntries();
 
     if (i != 7)
-      legend->AddEntry(hist[i], titles[i]);
+      legend->AddEntry(hist[i], titles[i], "L");
   }
 
   legend->Draw();
-  gPad->SetLogy();
+  c->SaveAs("spd_tracklets_deltaphi_detailed.eps");
 
   Printf("Total: %d", total);
   for (Int_t i=0; i<maxHists; i++)
-    Printf("Histogram %d (%s) containts %.2f %% of the entries", i, titles[i], 100.0 * hist[i]->GetEntries() / total);
+    Printf("Histogram %d (%s) contains %.2f %% of the entries", i, titles[i], 100.0 * hist[i]->GetEntries() / total);
 
   printf("|  Delta phi  |  Acc. %%  |  ");
   for (Int_t i=0; i<maxHists; i++)
@@ -1778,6 +2136,127 @@ void DrawTrackletOrigin()
       printf("%6.2f  |  ", (hist[i]->GetEntries() > 0) ? (100.0 * hist[i]->Integral(integralBegin, integralEnd) / hist[i]->GetEntries()) : -1.0);
     Printf("");
   }
+  
+  eff = new TH1F("eff", ";#Delta#varphi cut (rad.)", 101,-0.0005, 0.1005);
+  cont = new TH1F("cont", "cont", 101,-0.0005, 0.1005);
+  signalOverBg = new TH1F("signalOverBg", "signalOverBg", 101,-0.0005, 0.1005);
+  for (Float_t cut=0.000; cut<0.10; cut += 0.001)
+  {
+    Float_t accGood = good->Integral(good->GetXaxis()->FindBin(-cut), good->GetXaxis()->FindBin(cut));
+    Float_t accBad = bad->Integral(bad->GetXaxis()->FindBin(-cut), bad->GetXaxis()->FindBin(cut));
+    Float_t sB = accGood / accBad;
+    eff->Fill(cut, 100.0 * accGood / good->Integral());
+    cont->Fill(cut, 100.0 * accBad / (accGood + accBad));
+    signalOverBg->Fill(cut, sB);
+  }
+  
+  //new TCanvas; signalOverBg->Draw();
+  
+  c = (TCanvas*) gROOT->GetListOfCanvases()->FindObject("c2");
+  Bool_t nw = kFALSE;
+  if (!c)
+  {
+    c = new TCanvas("c2", "c2", 600, 600);
+    nw = kTRUE;
+  }
+  c->cd();
+  c->SetRightMargin(0.05);
+  c->SetTopMargin(0.05);
+  c->SetGridx();
+  c->SetGridy();
+  gPad->SetLogy();
+  good->Rebin(kRebin);
+  bad->Rebin(kRebin);
+  good->GetXaxis()->SetRangeUser(-0.09, 0.09);
+  good->GetYaxis()->SetTitleOffset(1.3);
+  good->SetStats(0);
+  good->GetXaxis()->SetTitle("#Delta#varphi (rad.)");  
+  good->DrawCopy((nw) ? "" : "SAME");
+  
+  bad->SetLineColor(2);
+  bad->SetLineStyle(2);
+  bad->SetLineWidth(2);
+  //bad->SetMarkerColor(2);
+  //bad->SetMarkerStyle(7);
+  bad->DrawCopy("SAME");
+  
+  TLegend* legend = new TLegend(0.2, 0.13, 0.85, 0.25);
+  legend->SetFillColor(0);
+  legend->SetTextSize(0.04);
+  legend->AddEntry(good, "Primaries", "L");
+  legend->AddEntry(bad, "Secondaries + Background", "L");
+  legend->Draw();
+  
+  c->SaveAs("spd_tracklets_deltaphi.eps");
+  
+  c = (TCanvas*) gROOT->GetListOfCanvases()->FindObject("c3");
+  Bool_t nw = kFALSE;
+  if (!c)
+  {
+    c = new TCanvas("c3", "c3", 600, 600);
+    nw = kTRUE;
+  }
+  c->cd();
+  c->SetRightMargin(0.05);
+  c->SetTopMargin(0.05);
+  c->SetGridx();
+  c->SetGridy();
+  
+  TLegend* legend = new TLegend(0.5, 0.6, 0.93, 0.75);
+  legend->SetFillColor(0);
+  legend->SetTextSize(0.04);
+  legend->AddEntry(eff, "Efficiency (%)", "L");
+  legend->AddEntry(cont, "Contamination (%)", "L");
+  
+  eff->SetStats(0);
+  eff->GetXaxis()->SetRangeUser(0, 0.08);
+  eff->GetYaxis()->SetRangeUser(1e-3, 105);
+  eff->SetLineWidth(2);
+  eff->DrawCopy((nw) ? "" : "SAME");
+  cont->SetLineStyle(2);
+  cont->SetLineWidth(2);
+  cont->SetLineColor(2);
+  cont->DrawCopy("SAME");
+  legend->Draw();
+  
+  c->SaveAs("spd_tracklets_efficiency.eps");
+  
+  
+}
+
+void Tracklets_Asymmetry()
+{
+  TFile::Open("correction_map.root");
+
+  Int_t maxHists = 7;
+  TH1* hist[8];
+
+  Int_t colors[]  = {1,2,3,4,6,7,8,102};
+  const char* titles[] = { "PP", "SS", "PP'", "PS'", "PS", "SP'", "SS'", "" };
+
+  TLegend* legend = new TLegend(0.75, 0.6, 0.93, 0.93);
+  
+  for (Int_t i=0; i<maxHists; i++)
+  {
+    hist[i] = (TH1*) gFile->Get(Form("fDeltaPhi_%d", i));
+    hist[i]->Rebin(10);
+    
+    for (Int_t j=hist[i]->GetNbinsX()/2; j<=hist[i]->GetNbinsX(); j++)
+      if (hist[i]->GetBinContent(j) > 0)
+        hist[i]->SetBinContent(j, (hist[i]->GetBinContent(j) -  hist[i]->GetBinContent(hist[i]->GetXaxis()->FindBin(-hist[i]->GetXaxis()->GetBinCenter(j)))) / hist[i]->GetBinContent(j));
+      
+    hist[i]->SetStats(kFALSE);
+    hist[i]->SetLineColor(colors[i]);
+    hist[i]->GetXaxis()->SetRangeUser(0.001, 0.09);
+    //hist[i]->GetYaxis()->SetRangeUser(5, hist[i]->GetMaximum() * 2);
+    hist[i]->GetYaxis()->SetTitleOffset(1.3);
+    hist[i]->GetXaxis()->SetTitle("#Delta#varphi (rad.)");
+    hist[i]->Draw(((i == 0) ? "" : "SAME"));
+    
+    legend->AddEntry(hist[i], titles[i], "L");
+  }
+  
+  legend->Draw();
 }
 
 TH2* GetCorrection(const char* fileName = "correction_map.root", const char* dirName = "dndeta_correction", Double_t ptmin=0.2)
@@ -1911,7 +2390,7 @@ void GetAverageCorrectionFactor(Float_t etaRange = 1.5, Float_t vertexRange = 9.
   mcH->Fit("pol0", "", "", -etaRange, etaRange);
 }
 
-void TrackCuts_Comparison(char* histName, Int_t plotWhich = 0, const char* fileName = "correction_map.root")
+void TrackCuts_Comparison(char* histName, Int_t plotWhich = 0, const char* fileName = "correction_map.root", Bool_t mirror = kFALSE)
 {
   // for the nsigmaplot it is needed to run with all cuts except the nsigmatovertex
   //    --> manually disable it in the run.C
@@ -1919,6 +2398,9 @@ void TrackCuts_Comparison(char* histName, Int_t plotWhich = 0, const char* fileN
   // plotWhich: 0 = only before
   //            1 = both
   //            2 = only after
+  //
+  // mirror: kTRUE --> project negative values on the positive side
+  
 
   file = TFile::Open(fileName);
 
@@ -1929,7 +2411,7 @@ void TrackCuts_Comparison(char* histName, Int_t plotWhich = 0, const char* fileN
   TLegend* legend2 = new TLegend(0.4, 0.6, 1, 1);
   TLegend* legend3 = new TLegend(0.6, 0.5, 1, 0.7);
 
-  TCanvas* c1 = new TCanvas("c1", "c1", 800, 1200);
+  TCanvas* c1 = new TCanvas(histName, histName, 800, 1200);
   c1->Divide(1, 2);
   //TCanvas* c2 = new TCanvas("c2", "c2", 800, 600);
   //TCanvas* c3 = new TCanvas("c3", "c3", 800, 600);
@@ -1948,6 +2430,20 @@ void TrackCuts_Comparison(char* histName, Int_t plotWhich = 0, const char* fileN
       TString folder;
       folder.Form("%s/%s/%s", folders1[i], folders2[j], histName);
       TH1* hist = (TH1*) file->Get(folder);
+      
+      if (mirror)
+      {
+        for (Int_t bin=1; bin<=hist->GetXaxis()->FindBin(-0.0001); bin++)
+        {
+          Int_t newBin = hist->GetXaxis()->FindBin(-hist->GetXaxis()->GetBinCenter(bin));
+          if (bin != newBin)
+          {
+            hist->Fill(-hist->GetXaxis()->GetBinCenter(bin), hist->GetBinContent(bin));
+            hist->SetBinContent(bin, 0);
+          }
+        }
+      }
+      
       legend->AddEntry(hist, Form("%s %s", names[i], folders2[j]));
 
       c1->cd(1);
@@ -2002,7 +2498,7 @@ void TrackCuts_Comparison(char* histName, Int_t plotWhich = 0, const char* fileN
   c1->cd(2)->SetGridy();
   legend3->Draw();
 
-  c1->SaveAs(Form("%s.png", histName));
+  //c1->SaveAs(Form("%s.png", histName));
 }
 
 void TrackCuts_DCA()
@@ -2100,3 +2596,240 @@ void MakeGaussianProfile(const char* histName = "fVertexCorrelation", Bool_t sub
     result->GetYaxis()->SetRangeUser(-0.2, 0.2);
     result->Draw();
 }
+
+TH2* GetAcceptance(void* corr2d_void)
+{
+        corr2d = (AliCorrectionMatrix2D*) corr2d_void;
+        corr_xy = (TH2*) corr2d->GetCorrectionHistogram()->Clone("acceptance");
+
+        // fold in acceptance
+        for (Int_t x=1; x<=corr_xy->GetNbinsX(); ++x)
+                for (Int_t y=1; y<=corr_xy->GetNbinsY(); ++y)
+                {
+                        if (corr_xy->GetBinContent(x, y) > 1.5)
+                                corr_xy->SetBinContent(x, y, 0);
+
+                        if (corr_xy->GetBinContent(x, y) > 0)
+                                corr_xy->SetBinContent(x, y, 1);
+
+                        corr_xy->SetBinError(x, y, 0);
+                }
+
+        return corr_xy;
+}
+
+void ZeroOutsideAcceptance(TH2* acc, TH3* hist)
+{
+  for (Int_t x=0; x<=acc->GetNbinsX()+1; ++x)
+    for (Int_t y=0; y<=acc->GetNbinsY()+1; ++y)
+    {
+      if (acc->GetBinContent(x, y) > 1.5 || acc->GetBinContent(x, y) == 0)
+      {
+        for (Int_t z=0; z<=hist->GetNbinsZ()+1; ++z)
+        {
+          hist->SetBinContent(x, y, z, 0);
+          hist->SetBinError(x, y, z, 0);
+        }
+      }
+    }
+}
+
+void DrawPhi()
+{
+  loadlibs();
+
+  TFile::Open("correction_map.root");
+  AlidNdEtaCorrection* dNdEtaCorrection = new AlidNdEtaCorrection("dndeta_correction", "dndeta_correction");
+  if (!dNdEtaCorrection->LoadHistograms())
+    return 0;
+
+  TFile::Open("analysis_esd.root");
+  dNdEtaAnalysis* fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaTrVtx", "dndetaTrVtx");
+  fdNdEtaAnalysis->LoadHistograms();
+
+  // acc. map!
+  //acc = GetAcceptance(dNdEtaCorrection->GetCorrection(1)->GetTrackCorrection()->Get2DCorrection("yx", 0, 1000));
+  acc = dNdEtaCorrection->GetCorrection(1)->GetTrackCorrection()->Get2DCorrection("yx", 0, 1000)->GetCorrectionHistogram();
+  //new TCanvas; acc->Draw("COLZ");
+
+  histG = fdNdEtaAnalysis->GetData()->GetTrackCorrection()->GetGeneratedHistogram();
+  ZeroOutsideAcceptance(acc, histG);
+  //new TCanvas; histG->Project3D("yx")->Draw("COLZ");
+  //histG->GetYaxis()->SetRangeUser(-0.9, 0.9);
+
+  histM = fdNdEtaAnalysis->GetData()->GetTrackCorrection()->GetMeasuredHistogram();
+  ZeroOutsideAcceptance(acc, histM);
+  //histM->GetYaxis()->SetRangeUser(-0.9, 0.9);
+
+  TFile::Open("analysis_mc.root");
+  dNdEtaAnalysis* fdNdEtaAnalysis2 = new dNdEtaAnalysis("dndetaTrVtxMC", "dndetaTrVtxMC");
+  fdNdEtaAnalysis2->LoadHistograms("dndetaTrVtx");
+
+  histMC = fdNdEtaAnalysis2->GetData()->GetTrackCorrection()->GetMeasuredHistogram();
+  ZeroOutsideAcceptance(acc, histMC);
+  //new TCanvas; histMC->Project3D("yx2")->Draw("COLZ");
+
+  //histG->GetZaxis()->SetRangeUser(1,2); histMC->GetZaxis()->SetRangeUser(1,2);
+  new TCanvas; a = histG->Project3D("yx3"); a->Add(histMC->Project3D("yx4"), -1); a->Draw("COLZ");
+
+  //histMC->GetYaxis()->SetRangeUser(-0.9, 0.9);
+
+  c = new TCanvas;
+
+  histG->GetXaxis()->SetRangeUser(-9.9, 9.9);
+  histG->Project3D("z")->Draw();
+
+  histM->GetXaxis()->SetRangeUser(-9.9, 9.9);
+  proj = histM->Project3D("z2");
+  proj->SetLineColor(2);
+  proj->Draw("SAME");
+
+  histMC->GetXaxis()->SetRangeUser(-9.9, 9.9);
+  projMC = histMC->Project3D("z3");
+  projMC->SetLineColor(3);
+  projMC->Draw("SAME");
+}
+
+void PrintEventStats(Int_t corrID = 3)
+{
+  loadlibs();
+
+  /*
+  TFile::Open("analysis_mc.root");
+  fdNdEtaAnalysis = new dNdEtaAnalysis("dndetaNSD", "dndetaNSD");
+  fdNdEtaAnalysis->LoadHistograms();
+  trackHist = fdNdEtaAnalysis->GetData()->GetTrackCorrection()->GetGeneratedHistogram();
+  eventHist = fdNdEtaAnalysis->GetData()->GetEventCorrection()->GetGeneratedHistogram();
+  */
+
+  TFile::Open("correction_map.root");
+  AlidNdEtaCorrection* dNdEtaCorrection = new AlidNdEtaCorrection("dndeta_correction", "dndeta_correction");
+  if (!dNdEtaCorrection->LoadHistograms())
+    return;
+  trackHist = dNdEtaCorrection->GetCorrection(corrID)->GetTrackCorrection()->GetGeneratedHistogram();
+  eventHist = dNdEtaCorrection->GetCorrection(corrID)->GetEventCorrection()->GetGeneratedHistogram();
+
+  trackHist->GetXaxis()->SetRange(0, trackHist->GetNbinsX()+1);
+  trackHist->GetZaxis()->SetRange(0, trackHist->GetNbinsZ()+1);
+  eta = trackHist->Project3D("y");
+
+  events = eventHist->Integral(0, eventHist->GetNbinsX()+1, 0, eventHist->GetNbinsY()+1);
+
+  eta->Scale(1.0 / events);
+
+  Float_t avgN = eta->Integral(0, eta->GetNbinsX()+1);
+  Printf("<N> = %f", avgN);
+
+  eta->Scale(1.0 / eta->GetXaxis()->GetBinWidth(1));
+
+  Printf("dndeta | eta = 0 is %f", (eta->GetBinContent(eta->FindBin(0.01)) + eta->GetBinContent(eta->FindBin(-0.01))) / 2);
+  Printf("dndeta in |eta| < 1 is %f", eta->Integral(eta->FindBin(-0.99), eta->FindBin(0.99)) / (eta->FindBin(0.99) - eta->FindBin(-0.99) + 1));
+  Printf("dndeta in |eta| < 1.5 is %f", eta->Integral(eta->FindBin(-1.49), eta->FindBin(1.49)) / (eta->FindBin(1.49) - eta->FindBin(-1.49) + 1));
+
+  stats = (TH2*) gFile->Get("fEventStats");
+  proj = stats->ProjectionX();
+  gROOT->ProcessLine(".L PrintHist.C");
+  PrintHist2D(stats);
+  PrintHist(proj);
+  
+  Printf("+++ TRIGGER EFFICIENCIES +++");
+  
+  Printf("INEL = %.1f", 100. * (proj->GetBinContent(1) - stats->GetBinContent(1, 1)) / proj->GetBinContent(1));
+  Printf("NSD  = %.1f", 100. * (proj->GetBinContent(2) - stats->GetBinContent(2, 1)) / proj->GetBinContent(2));
+  Printf("ND  = %.1f",  100. * (proj->GetBinContent(3) - stats->GetBinContent(3, 1)) / proj->GetBinContent(3));
+  Printf("SD  = %.1f",  100. * (proj->GetBinContent(4) - stats->GetBinContent(4, 1)) / proj->GetBinContent(4));
+  Printf("DD  = %.1f",  100. * (proj->GetBinContent(5) - stats->GetBinContent(5, 1)) / proj->GetBinContent(5));
+  
+  for (Int_t i=7; i<=proj->GetNbinsX(); i++)
+    if (proj->GetBinContent(i) > 0)
+      Printf("bin %d (process type %d) = %.2f", i, (Int_t) proj->GetXaxis()->GetBinCenter(i), 100.0 * (proj->GetBinContent(i) - stats->GetBinContent(i, 1)) / proj->GetBinContent(i));
+  
+  //eta->Draw();
+}
+
+void TestAsymmetry()
+{
+  loadlibs();
+
+  TFile* file2 = TFile::Open("analysis_mc.root");
+  
+  dNdEtaAnalysis* fdNdEtaAnalysis = new dNdEtaAnalysis("dndeta", "dndeta");
+  fdNdEtaAnalysis->LoadHistograms();
+  fdNdEtaAnalysis->Finish(0, 0, AlidNdEtaCorrection::kNone, "...");
+  
+  fdNdEtaAnalysis->GetdNdEtaHistogram(0)->DrawCopy();
+  
+  hist = (TH1*) fdNdEtaAnalysis->GetData()->GetTrackCorrection()->GetMeasuredHistogram();
+  hist2 = (TH1*) hist->Clone("hist2");
+  for (Int_t x=1; x<=hist->GetNbinsX(); x++)
+    for (Int_t y=1; y<=hist->GetNbinsY(); y++)
+      for (Int_t z=1; z<=hist->GetNbinsZ(); z++)
+      {
+        Printf("%d %d %d %d", x, y, z, hist->GetNbinsY() + 1 - y);
+        hist->SetBinContent(x, y, z, hist2->GetBinContent(hist->GetNbinsX() / 2, TMath::Min(y, hist->GetNbinsY() + 1 - y), z));
+      }
+  
+  hist = fdNdEtaAnalysis->GetData()->GetEventCorrection()->GetMeasuredHistogram();
+  for (Int_t x=1; x<=hist->GetNbinsX(); x++)
+    for (Int_t y=1; y<=hist->GetNbinsY(); y++)
+      {
+        //Printf("%d %d %d %d", x, y, z, hist->GetNbinsY() + 1 - y);
+        hist->SetBinContent(x, y, hist->GetBinContent(hist->GetNbinsX() / 2, y));
+      }
+  
+  fdNdEtaAnalysis->Finish(0, 0, AlidNdEtaCorrection::kNone, "...");
+  fdNdEtaAnalysis->GetdNdEtaHistogram(0)->SetMarkerColor(2);
+  fdNdEtaAnalysis->GetdNdEtaHistogram(0)->SetLineColor(2);
+  fdNdEtaAnalysis->GetdNdEtaHistogram(0)->SetMarkerStyle(5);
+  fdNdEtaAnalysis->GetdNdEtaHistogram(0)->DrawCopy("SAMEP");
+}
+
+void DeltaPhiFromPt(Float_t smearing = 0.005)
+{
+  loadlibs();
+
+  TFile::Open("analysis_mc.root");
+  hist = (TH1*) gFile->Get("dndeta_check_pt");
+  
+  dPhiHist = new TH1F("dPhiHist", ";#Delta phi", 400, -0.1, 0.1);
+  dPhiHist2 = new TH1F("dPhiHist2", ";#Delta phi", 400, -0.1, 0.1);
+  
+  for (Int_t i=1; i<=hist->GetNbinsX(); i++)
+  {
+    Float_t pt = hist->GetBinCenter(i);
+    Float_t deltaPhi = (0.076 - 0.039) / 2 / (pt / 0.15);
+    
+    if (smearing > 0)
+    {
+      gaus = new TF1("mygaus", "gaus(0)", -0.1, 0.1);
+      gaus->SetParameters(1, -deltaPhi, smearing);
+    
+      dPhiHist->FillRandom("mygaus", hist->GetBinContent(i) / 2 * 1000);
+    
+      dPhiHist2->FillRandom("mygaus", hist->GetBinContent(i) / 2 * 1000);
+      gaus->SetParameters(1, deltaPhi, smearing);
+      dPhiHist2->FillRandom("mygaus", hist->GetBinContent(i) / 2 * 1000);
+    }
+    else
+{
+dPhiHist->Fill(deltaPhi, hist->GetBinContent(i) / 2);
+dPhiHist2->Fill(deltaPhi, hist->GetBinContent(i) / 2);
+dPhiHist2->Fill(-deltaPhi, hist->GetBinContent(i) / 2);
+}
+  }
+  
+  new TCanvas;
+  dPhiHist->Draw();
+  dPhiHist2->SetLineColor(2);
+  dPhiHist2->Draw("SAME");
+  gPad->SetLogy();
+  
+  TFile::Open("trackletsDePhi.root");
+  //TFile::Open("tmp/correction_maponly-positive.root");
+  //TFile::Open("tmp/correction_map.root");
+  //tracklets = (TH1*) gFile->Get(Form("fDeltaPhi_%d", 0));
+  tracklets = (TH1*) gFile->Get("DePhiPPTracklets");
+  tracklets->Scale(1.0 / tracklets->GetMaximum() * dPhiHist->GetMaximum());
+  tracklets->SetLineColor(4);
+  tracklets->Draw("SAME");
+}
index 8431281..29a114a 100644 (file)
@@ -145,11 +145,11 @@ void Track2Particle1DComposition(const char** fileNames, Int_t folderCount, cons
 
   for (Int_t i=0; i<folderCount; ++i)
   {
-    Track2Particle1DCreatePlots(fileNames[i], folderNames[i], upperPtLimit);
+    Correction1DCreatePlots(fileNames[i], folderNames[i], upperPtLimit);
 
-    TH1* corrX = dynamic_cast<TH1*> (gROOT->FindObject(Form("gene_%s_nTrackToNPart_x_div_meas_%s_nTrackToNPart_x", folderNames[i], folderNames[i])));
-    TH1* corrY = dynamic_cast<TH1*> (gROOT->FindObject(Form("gene_%s_nTrackToNPart_y_div_meas_%s_nTrackToNPart_y", folderNames[i], folderNames[i])));
-    TH1* corrZ = dynamic_cast<TH1*> (gROOT->FindObject(Form("gene_%s_nTrackToNPart_z_div_meas_%s_nTrackToNPart_z", folderNames[i], folderNames[i])));
+    TH1* corrX = dynamic_cast<TH1*> (gROOT->FindObject("generated_x_div_measured_x"));
+    TH1* corrY = dynamic_cast<TH1*> (gROOT->FindObject("generated_y_div_measured_y"));
+    TH1* corrZ = dynamic_cast<TH1*> (gROOT->FindObject("generated_z_div_measured_z"));
 
     Prepare1DPlot(corrX);
     Prepare1DPlot(corrY);
@@ -504,20 +504,35 @@ const char* ChangeComposition(void** correctionPointer, Int_t index)
       break;
 
       // one species enhanced / reduced
-    case 2: // + 50% pions
-    case 3: // - 50% pions
-    case 4: // + 50% kaons
-    case 5: // - 50% kaons
-    case 6: // + 50% protons
-    case 7: // - 50% protons
-      Int_t correctionIndex = (index - 2) / 2;
-      Double_t scaleFactor = (index % 2 == 0) ? 1.5 : 0.5;
-
-      fdNdEtaCorrection[correctionIndex]->GetTrack2ParticleCorrection()->GetMeasuredHistogram()->Scale(scaleFactor);
-      fdNdEtaCorrection[correctionIndex]->GetTrack2ParticleCorrection()->GetGeneratedHistogram()->Scale(scaleFactor);
-
+    case 2: // + 50% kaons
+    case 3: // - 50% kaons
+    case 4: // + 50% protons
+    case 5: // - 50% protons
+    case 6: // + 50% kaons + 50% protons
+    case 7: // - 50% kaons - 50% protons
+    case 8: // + 50% kaons - 50% protons
+    case 9: // - 50% kaons + 50% protons
       TString* str = new TString;
-      str->Form("%s%s", (correctionIndex == 0) ? "Pi" : ((correctionIndex == 1) ? "K" : "p"), (index % 2 == 0) ? "Boosted" : "Reduced");
+      if (index < 6)
+      {
+        Int_t correctionIndex = index / 2;
+        Double_t scaleFactor = (index % 2 == 0) ? 1.5 : 0.5;
+  
+        fdNdEtaCorrection[correctionIndex]->GetTrack2ParticleCorrection()->GetTrackCorrection()->Scale(scaleFactor);
+        str->Form("%s%s", (correctionIndex == 0) ? "Pi" : ((correctionIndex == 1) ? "K" : (correctionIndex == 2) ? "p" : "others"), (index % 2 == 0) ? "Boosted" : "Reduced");
+      }
+      else
+      {
+        Double_t scaleFactor = (index % 2 == 0) ? 1.5 : 0.5;
+        fdNdEtaCorrection[1]->GetTrack2ParticleCorrection()->GetTrackCorrection()->Scale(scaleFactor);
+        str->Form("%s%s", "K", (scaleFactor > 1) ? "Boosted" : "Reduced");
+        
+        if (index >= 8)
+          scaleFactor = (index % 2 == 0) ? 0.5 : 1.5;
+        fdNdEtaCorrection[2]->GetTrack2ParticleCorrection()->GetTrackCorrection()->Scale(scaleFactor);
+        *str += Form("%s%s", "p", (scaleFactor > 1) ? "Boosted" : "Reduced");
+      }
+
       return str->Data();
       break;
 
@@ -535,8 +550,8 @@ const char* ChangeComposition(void** correctionPointer, Int_t index)
 
       for (Int_t i=0; i<3; ++i)
       {
-        ScalePtDependent(fdNdEtaCorrection[i]->GetTrack2ParticleCorrection()->GetMeasuredHistogram(), ptDists[i]);
-        ScalePtDependent(fdNdEtaCorrection[i]->GetTrack2ParticleCorrection()->GetGeneratedHistogram(), ptDists[i]);
+        ScalePtDependent(fdNdEtaCorrection[i]->GetTrack2ParticleCorrection()->GetTrackCorrection()->GetMeasuredHistogram(), ptDists[i]);
+        ScalePtDependent(fdNdEtaCorrection[i]->GetTrack2ParticleCorrection()->GetTrackCorrection()->GetGeneratedHistogram(), ptDists[i]);
       }
       TString* str = new TString;
       str->Form("%s%s", (functionIndex == 0) ? "Pi" : ((functionIndex == 1) ? "K" : "p"), (index % 2 == 0) ? "Boosted" : "Reduced");
@@ -545,8 +560,8 @@ const char* ChangeComposition(void** correctionPointer, Int_t index)
 
     case 999:
       TF1* ptDependence = new TF1("simple", "x", 0, 100);
-      ScalePtDependent(fdNdEtaCorrection[0]->GetTrack2ParticleCorrection()->GetGeneratedHistogram(), ptDependence);
-      ScalePtDependent(fdNdEtaCorrection[0]->GetTrack2ParticleCorrection()->GetMeasuredHistogram(), ptDependence);
+      ScalePtDependent(fdNdEtaCorrection[0]->GetTrack2ParticleCorrection()->GetTrackCorrection()->GetGeneratedHistogram(), ptDependence);
+      ScalePtDependent(fdNdEtaCorrection[0]->GetTrack2ParticleCorrection()->GetTrackCorrection()->GetMeasuredHistogram(), ptDependence);
       break;
 
   }
@@ -556,23 +571,28 @@ const char* ChangeComposition(void** correctionPointer, Int_t index)
 
 void Composition()
 {
-  gSystem->Load("libPWG0base");
+  loadlibs();
 
   gSystem->Unlink("new_compositions.root");
+  gSystem->Unlink("new_compositions_analysis.root");
+  
+  const char* names[] = { "pi", "K", "p", "other" };
+  TH1* hRatios[20];
 
-  Int_t nCompositions = 8;
-  for (Int_t comp = 0; comp < nCompositions; ++comp)
+  Int_t nCompositions = 10;
+  Int_t counter = 0;
+  for (Int_t comp = 1; comp < nCompositions; ++comp)
   {
     AlidNdEtaCorrection* fdNdEtaCorrection[4];
 
-    TFile::Open("systematics.root");
+    TFile::Open("correction_mapparticle-species.root");
 
     for (Int_t i=0; i<4; ++i)
     {
       TString name;
-      name.Form("correction_%d", i);
+      name.Form("dndeta_correction_%s", names[i]);
       fdNdEtaCorrection[i] = new AlidNdEtaCorrection(name, name);
-      fdNdEtaCorrection[i]->LoadHistograms("systematics.root", name);
+      fdNdEtaCorrection[i]->LoadHistograms();
     }
 
     const char* newName = ChangeComposition(fdNdEtaCorrection, comp);
@@ -584,8 +604,8 @@ void Composition()
 
     for (Int_t i=0; i<4; ++i)
     {
-      geneCount[i] = fdNdEtaCorrection[i]->GetTrack2ParticleCorrection()->GetGeneratedHistogram()->Integral();
-      measCount[i] = fdNdEtaCorrection[i]->GetTrack2ParticleCorrection()->GetMeasuredHistogram()->Integral();
+      geneCount[i] = fdNdEtaCorrection[i]->GetTrack2ParticleCorrection()->GetTrackCorrection()->GetGeneratedHistogram()->Integral();
+      measCount[i] = fdNdEtaCorrection[i]->GetTrack2ParticleCorrection()->GetTrackCorrection()->GetMeasuredHistogram()->Integral();
 
       geneCount[4] += geneCount[i];
       measCount[4] += measCount[i];
@@ -599,27 +619,55 @@ void Composition()
 
     TList* collection = new TList;
 
-    for (Int_t i=0; i<4; ++i)
+    // skip "other" particle correction here
+    // with them has to be dealt differently, maybe just increasing the neutral particles...
+    for (Int_t i=1; i<3; ++i)
       collection->Add(fdNdEtaCorrection[i]);
 
-    AlidNdEtaCorrection* newComposition = new AlidNdEtaCorrection(newName, newName);
-    newComposition->Merge(collection);
-    newComposition->Finish();
+    fdNdEtaCorrection[0]->Merge(collection);
+    fdNdEtaCorrection[0]->Finish();
 
     delete collection;
 
+    // save everything
     TFile* file = TFile::Open("new_compositions.root", "UPDATE");
-    newComposition->SaveHistograms();
+    fdNdEtaCorrection[0]->SetName(newName);
+    fdNdEtaCorrection[0]->SaveHistograms();
     //file->Write();
     file->Close();
+    
+    // correct dNdeta distribution with modified correction map
+    TFile::Open("analysis_esd_raw.root");
+
+    dNdEtaAnalysis* fdNdEtaAnalysis = new dNdEtaAnalysis("fdNdEtaAnalysisESD", "fdNdEtaAnalysisESD");
+    fdNdEtaAnalysis->LoadHistograms();
+
+    fdNdEtaAnalysis->Finish(fdNdEtaCorrection[0], 0.2, 3, newName);
+    
+    hRatios[counter] = (TH1F*) fdNdEtaAnalysis->GetdNdEtaHistogram()->Clone(newName);
+    hRatios[counter]->SetTitle(newName);
+    hRatios[counter]->SetYTitle("dN_{ch}/d#eta ratio #frac{default composition}{modified composition}");
+
+    if (counter > 0)
+      hRatios[counter]->Divide(hRatios[0],hRatios[counter],1,1);
+
+    file = TFile::Open("new_compositions_analysis.root", "UPDATE");
+    hRatios[counter]->Write();
+    file->Close();
+    
+    delete fdNdEtaAnalysis;
+
+    counter++;
   }
 
+  /*
   gROOT->ProcessLine(".L drawPlots.C");
 
   const char* fileNames[] = {"new_compositions.root", "new_compositions.root", "new_compositions.root", "new_compositions.root", "new_compositions.root", "new_compositions.root", "new_compositions.root", "new_compositions.root" };
-  const char* folderNames[] = { "Pythia", "PythiaRatios", "PiBoosted", "PiReduced", "KBoosted", "KReduced", "pBoosted", "pReduced" };
+  const char* folderNames[] = { "PythiaRatios", "PiBoosted", "PiReduced", "KBoosted", "KReduced", "pBoosted", "pReduced" };
 
   Track2Particle1DComposition(fileNames, nCompositions, folderNames);
+  */
 }
 
 
@@ -748,7 +796,7 @@ void mergeCorrectionsWithDifferentCrosssections(Int_t correctionTarget = 3, Char
 
 
 
-  const Char_t* changes[]  = { "pythia","ddmore","ddless","sdmore","sdless", "dmore", "dless", "sdmoreddless", "sdlessddmore", "ddmore25","ddless25","sdmore25","sdless25", "dmore25", "dless25", "sdmoreddless25", "sdlessddmore25"};
+  const Char_t* changes[]  = { "pythia","ddmore","ddless","sdmore","sdless", "dmore", "dless", "sdlessddmore", "sdmoreddless", "ddmore25","ddless25","sdmore25","sdless25", "dmore25", "dless25", "sdlessddmore25", "sdmoreddless25"};
   Float_t scalesND[] = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0 };
   Float_t scalesDD[] = {1.0, 1.5, 0.5, 1.0, 1.0, 1.5, 0.5, 1.5, 0.5, 1.25, 0.75, 1.0,  1.0,  1.25, 0.75, 1.25, 0.75};
   Float_t scalesSD[] = {1.0, 1.0, 1.0, 1.5, 0.5, 1.5, 0.5, 0.5, 1.5, 1.0,  1.0,  1.25, 0.75, 1.25, 0.75, 0.75, 1.25};
@@ -868,9 +916,9 @@ void mergeCorrectionsWithDifferentCrosssections(Int_t correctionTarget = 3, Char
 
       hRatios[counter] = (TH1F*) fdNdEtaAnalysis->GetdNdEtaHistogram()->Clone(name);
 
-      name.Append(Form(" (DD #times %0.2f, SD #times %0.2f)",scalesDD[i],scalesSD[i]));
+      name.Form("DD #times %0.2f, SD #times %0.2f",scalesDD[i],scalesSD[i]);
       hRatios[counter]->SetTitle(name.Data());
-      hRatios[counter]->SetYTitle("ratio (Pythia x-sections)/(changed x-sections)");
+      hRatios[counter]->SetYTitle("dN_{ch}/d#eta ratio #frac{default cross-section}{modified cross-sections}");
 
       if (counter > 0)
         hRatios[counter]->Divide(hRatios[0],hRatios[counter],1,1);
@@ -896,133 +944,6 @@ void mergeCorrectionsWithDifferentCrosssections(Int_t correctionTarget = 3, Char
   fout->Close();
 }
 
-
-DrawVertexRecoSyst() {
-  // Draws the ratio of the dN/dEta obtained with changed SD and DD
-  // cross-sections vertex reco corrections to the dN/dEta obtained
-  // from the standard pythia cross-sections 
-  //
-  // The files with the vertex reco corrections for different
-  // processes (and with the other standard corrections) are expected
-  // to have the names "analysis_esd_X.root", where the Xs are defined
-  // in the array changes below.
-
-  Char_t* changes[]  = {"pythia","ddmore","ddless","sdmore","sdless", "dmore", "dless"};
-  Char_t* descr[]  =   {"",
-                       "#sigma_{DD}' = 1.5#times#sigma_{DD}",
-                       "#sigma_{DD}' = 0.5#times#sigma_{DD}",
-                       "#sigma_{SD}' = 1.5#times#sigma_{SD}",
-                       "#sigma_{SD}' = 0.5#times#sigma_{SD}",
-                       "#sigma_{D}' = 1.5#times#sigma_{D}",
-                       "#sigma_{D}' = 0.5#times#sigma_{D}"};
-
-  Float_t scalesDD[] = {1.0, 1.5, 0.5, 1.5, 0.5, 1.5, 0.5};
-  Float_t scalesSD[] = {1.0, 1.0, 1.0, 1.0, 1.0, 1.5, 0.5};
-
-  Int_t markers[] = {20,20,21,22,23,28,29};
-  Int_t colors[]  = {1,2,3,4,6,8,102};
-
-  // cross section from Pythia
-  Float_t sigmaND = 55.2;
-  Float_t sigmaDD = 9.78;
-  Float_t sigmaSD = 14.30;
-
-  TH1F* dNdEta[7];
-  TH1F* ratios[7];
-
-  TFile* fin;
-
-  for (Int_t i=0; i<7; i++) {
-    // calculating relative
-    fin = TFile::Open(Form("analysis_esd_%s.root",changes[i]));
-
-    dNdEta[i] = (TH1F*)(fin->Get("dndeta/dndeta_dNdEta_corrected_2"))->Clone();
-
-    for (Int_t b=0; b<dNdEta[i]->GetNbinsX(); b++) {
-      if (TMath::Abs(dNdEta[i]->GetBinCenter(b))>0.9) {
-       dNdEta[i]->SetBinContent(b,0);
-       dNdEta[i]->SetBinError(b,0);
-      }
-    }
-
-    dNdEta[i]->Rebin(4);
-
-    dNdEta[i]->SetLineWidth(2);
-    dNdEta[i]->SetLineColor(colors[i]);
-    dNdEta[i]->SetMarkerStyle(markers[i]);
-    dNdEta[i]->SetMarkerSize(0.9);
-    dNdEta[i]->SetMarkerColor(colors[i]);
-
-    ratios[i] = (TH1F*)dNdEta[i]->Clone("ratio");
-    ratios[i]->Divide(ratios[i],dNdEta[0],1,1,"B");
-    
-    ratios[i]->SetName(changes[i]);
-    ratios[i]->SetTitle(changes[i]);
-  }
-  
-  //##########################################################
-  
-  gStyle->SetOptStat(0);
-  gStyle->SetOptTitle(0);
-  gStyle->SetOptFit(0);
-
-  gStyle->SetTextSize(0.2);
-  gStyle->SetTitleSize(0.05,"xyz");
-  gStyle->SetLabelOffset(0.01, "xyz");
-
-
-  gStyle->SetTitleOffset(1.2, "y");
-  gStyle->SetTitleOffset(1.2, "x");
-  gStyle->SetEndErrorSize(0.0);
-
-  //##############################################
-
-  //making canvas and pads
-  TCanvas *c = new TCanvas(Form("vertex_reco_syst_%s", plot), Form("vertex_reco_syst_%s", plot),600,500);
-
-  TPad* p1 = new TPad("pad1","", 0, 0.0, 1.0, 1.0, 0, 0, 0);
-
-  p1->SetBottomMargin(0.15);
-  p1->SetTopMargin(0.03);
-  p1->SetLeftMargin(0.15);
-  p1->SetRightMargin(0.03);
-
-  p1->SetGridx();
-  p1->SetGridy();
-
-  p1->Draw();
-  p1->cd();
-  
-  
-  TH2F* null = new TH2F("","",100,-1.5,1.5,100,0.9601,1.099);
-  null->SetXTitle("#eta");
-  null->GetXaxis()->CenterTitle(kTRUE);
-  null->SetYTitle("dN/d#eta / dN/d#eta_{pythia}");
-  null->GetYaxis()->CenterTitle(kTRUE);
-  null->Draw();
-
-  for (Int_t i=1; i<7; i++) 
-    ratios[i]->Draw("same");
-
-  TLegend* legend = new TLegend(0.6, 0.6, 0.95, 0.95);
-  legend->SetFillColor(0);
-
-  TLatex* text[7];
-  for (Int_t i=1; i<7; i++) {
-    legend->AddEntry(dNdEta[i], descr[i]);
-  }
-
-  legend->Draw();
-  //text(0.2,0.88,"Effect of changing",0.045,1,kTRUE);
-  //text(0.2,0.83,"relative cross-sections",0.045,1,kTRUE);
-  //text(0.2,0.78,"(vertex reconstruction corr.)",0.043,13,kTRUE);
-
-  c->SaveAs(Form("%s.gif", c->GetName()));
-  c->SaveAs(Form("%s.eps", c->GetName()));
-}
-
-
-
 DrawTriggerEfficiency(Char_t* fileName) {
 
   gStyle->SetOptStat(0);
@@ -1170,10 +1091,22 @@ DrawSpectraPID(Char_t* fileName) {
   generatedPt[0]->Draw("same");
 }
 
-void changePtSpectrum(const char* fileName = "analysis_mc.root")
+void changePtSpectrum(const char* fileName = "analysis_mc.root", Float_t ptCutOff = 0.2, const char* fileName2 = 0)
 {
+  Float_t factor = 0.5;
+
   TFile* file = TFile::Open(fileName);
-  TH1F* hist = dynamic_cast<TH1F*> (file->Get("dndeta_check_pt"));
+  TH1F* hist = dynamic_cast<TH1F*> (file->Get("dndeta_check_pt")->Clone());
+  
+  TH1* hist2 = 0;
+  if (fileName2)
+  {
+    file2 = TFile::Open(fileName2);
+    hist2 = dynamic_cast<TH1*> (file2->Get("dndeta_check_pt")->Clone());
+    hist2->Scale(hist->GetBinContent(hist->FindBin(ptCutOff)) / hist2->GetBinContent(hist2->FindBin(ptCutOff)));
+  }
+  
+  //hist->Scale(1.0 / hist->Integral());
 
   //hist->Rebin(3);
   //hist->Scale(1.0/3);
@@ -1184,8 +1117,6 @@ void changePtSpectrum(const char* fileName = "analysis_mc.root")
   TH1F* scale1 =  dynamic_cast<TH1F*> (hist->Clone("scale1"));
   TH1F* scale2 =  dynamic_cast<TH1F*> (hist->Clone("scale2"));
 
-  Float_t ptCutOff = 0.3;
-
   for (Int_t i=1; i <= hist->GetNbinsX(); ++i)
   {
     if (hist->GetBinCenter(i) > ptCutOff)
@@ -1196,20 +1127,21 @@ void changePtSpectrum(const char* fileName = "analysis_mc.root")
     else
     {
       // 90 % at pt = 0, 0% at pt = ptcutoff
-      scale1->SetBinContent(i, 1 - (ptCutOff - hist->GetBinCenter(i)) / ptCutOff * 0.3);
+      scale1->SetBinContent(i, 1 - (ptCutOff - hist->GetBinCenter(i)) / ptCutOff * factor);
 
       // 110% at pt = 0, ...
-      scale2->SetBinContent(i, 1 + (ptCutOff - hist->GetBinCenter(i)) / ptCutOff * 0.3);
+      scale2->SetBinContent(i, 1 + (ptCutOff - hist->GetBinCenter(i)) / ptCutOff * factor);
     }
     scale1->SetBinError(i, 0);
     scale2->SetBinError(i, 0);
   }
 
+  /*
   new TCanvas;
-
   scale1->Draw();
   scale2->SetLineColor(kRed);
   scale2->Draw("SAME");
+  */
 
   clone1->Multiply(scale1);
   clone2->Multiply(scale2);
@@ -1223,11 +1155,15 @@ void changePtSpectrum(const char* fileName = "analysis_mc.root")
   clone2->SetMarkerStyle(markers[0]);*/
 
   hist->SetTitle(";p_{T} in GeV/c;dN_{ch}/dp_{T} in c/GeV");
-  hist->GetXaxis()->SetRangeUser(0, 0.7);
+  hist->GetXaxis()->SetRangeUser(0, 0.5);
   hist->GetYaxis()->SetRangeUser(0.01, clone2->GetMaximum() * 1.1);
   hist->GetYaxis()->SetTitleOffset(1);
 
-  TCanvas* canvas = new TCanvas;
+  TCanvas* canvas = new TCanvas("c", "c", 600, 600);
+  gPad->SetGridx();
+  gPad->SetGridy();
+  gPad->SetTopMargin(0.05);
+  gPad->SetRightMargin(0.05);
   gPad->SetBottomMargin(0.12);
   hist->Draw("H");
   clone1->SetLineColor(kRed);
@@ -1235,6 +1171,13 @@ void changePtSpectrum(const char* fileName = "analysis_mc.root")
   clone2->SetLineColor(kBlue);
   clone2->Draw("HSAME");
   hist->Draw("HSAME");
+  
+  if (hist2)
+  {
+    Prepare1DPlot(hist2);
+    hist2->SetLineStyle(2);
+    hist2->Draw("HSAME");
+  }
 
   Float_t fraction =  hist->Integral(hist->GetXaxis()->FindBin(ptCutOff), hist->GetNbinsX()) / hist->Integral(1, hist->GetNbinsX());
   Float_t fraction1 = clone1->Integral(clone1->GetXaxis()->FindBin(ptCutOff), clone1->GetNbinsX()) / clone1->Integral(1, clone1->GetNbinsX());
@@ -1243,7 +1186,7 @@ void changePtSpectrum(const char* fileName = "analysis_mc.root")
   printf("%f %f %f\n", fraction, fraction1, fraction2);
   printf("Rel. %f %f\n", fraction1 / fraction, fraction2 / fraction);
 
-  canvas->SaveAs("changePtSpectrum.gif");
+  //canvas->SaveAs("changePtSpectrum.gif");
   canvas->SaveAs("changePtSpectrum.eps");
 }
 
index 3fc4c24..cf73e98 100644 (file)
@@ -64,101 +64,81 @@ void DrawpiKpAndCombinedZOnly(Float_t upperPtLimit=0.99)
   
 }
 
+TPad* DrawChange(Bool_t spd, const char* basename, const char** changes, Int_t nChanges, Int_t nDraw, Int_t* colors, const char** names = 0, Float_t scale = 0.10)
+{  
+  Float_t etaMax = 1.05;
+  if (spd)
+    etaMax = 1.79;
 
-void DrawEffectOfChangeInCrossSection(const char* fileName = "systematics_vtxtrigger_compositions.root") {
-  
-  //get the data
-  TFile* fin = TFile::Open(fileName);
-
-  const Char_t* changes[]  = {"pythia","ddmore","ddless","sdmore","sdless", "dmore", "dless", "sdmoreddless", "sdlessddmore" };
-  //const Char_t* changes[]  = {"pythia","ddmore25","ddless25","sdmore25","sdless25", "dmore25", "dless25", "sdmoreddless25", "sdlessddmore25" };
-  const Int_t nChanges = 9;
-  //const Char_t* changes[]  = { "pythia", "qgsm", "phojet" };
-  //const Int_t nChanges = 3;
-  Int_t colors[] = {1,1,kRed,kBlue,kGreen,kPink,1,kRed,kBlue};
-
-  TH1F* hRatios[9];
+  TH1F* hRatios[100];
   for(Int_t i=0; i<nChanges; i++) {
-    hRatios[i] = (TH1F*)fin->Get(Form("ratio_vertexReco_triggerBias_%s",changes[i]));
-    hRatios[i]->SetLineWidth(2);
-    hRatios[i]->SetLineColor(colors[i]);
+    hRatios[i] = (TH1F*)gFile->Get(Form("%s%s",basename,changes[i]));
+    hRatios[i]->SetLineWidth(1);
     hRatios[i]->SetMarkerStyle(22);
     hRatios[i]->SetMarkerSize(0.8);
 
     Float_t average = hRatios[i]->Integral(hRatios[i]->FindBin(-1), hRatios[i]->FindBin(1)) / (hRatios[i]->FindBin(1) - hRatios[i]->FindBin(-1) + 1);
     Printf("%s: %.2f %%" , hRatios[i]->GetTitle(), (average - 1) * 100);
   }
-
+  
   TPad* p = DrawCanvasAndPad("syst_changeInXsection",700,400);
   p->SetRightMargin(0.2);
   p->SetLeftMargin(0.13);
-
-  TH2F* null = new TH2F("","",100,-1.05,1.05,100,0.9,1.1);
+  
+  TH2F* null = new TH2F("","",100,-etaMax, etaMax,100,1. - scale,1. + scale);
   null->GetXaxis()->SetTitle("#eta");
-  null->GetYaxis()->SetTitle("Ratio pythia/modified cross-sections");
+  null->GetYaxis()->SetTitle(hRatios[0]->GetYaxis()->GetTitle());
   null->Draw();
+  
+  line = new TLine(-etaMax, 1, etaMax, 1);
+  line->Draw();
 
-  TLatex* text[9];
+  TLatex* text[100];
 
-  for(Int_t i=1; i<nChanges; i++) {
-    hRatios[i]->Draw("same");
+  for(Int_t i=1; i<nDraw; i++) {
+    hRatios[i]->SetLineColor(colors[i]);
+    hRatios[i]->SetMarkerColor(colors[i]);
+    hRatios[i]->Draw("HISTPL SAME");
     
     TString str(hRatios[i]->GetTitle());
-    str.Remove(0,str.First("DD"));
-    str.Remove(str.First(")"),1);
-    text[i] = new TLatex(1.08,hRatios[i]->GetBinContent(hRatios[i]->FindBin(0.))-0.002,str.Data());
+    
+    if (names)
+      str = names[i];
+    
+    text[i] = new TLatex(etaMax + 0.03,hRatios[i]->GetBinContent(hRatios[i]->FindBin(etaMax-0.1))-0.002,str.Data());
+    text[i]->SetTextAlign(11);
     text[i]->SetTextColor(colors[i]);
     text[i]->Draw();
   }
-}
-
-
-void DrawEffectOfChangeInComposition() {
   
-  //get the data
-  TFile* fin = TFile::Open("systematics_composition.root");
-
-  Int_t colors[] = {1,2,103,102,4,6,1};
-
-  TH1F* hRatios[6];
-
-  Float_t etaRange = 0.899;
-
-  for (Int_t i=0; i<6; i++) {
-    hRatios[i] = (TH1F*)fin->Get(Form("ratio_%d",i));
-
-    hRatios[i]->SetLineWidth(2);
-    hRatios[i]->SetLineColor(colors[i]);
-    hRatios[i]->SetMarkerStyle(22);
-    hRatios[i]->SetMarkerSize(0.8);
-
-    hRatios[i]->GetXaxis()->SetRangeUser(-etaRange, etaRange);
-  }
+  return p;
+}
 
-  TPad* p = DrawCanvasAndPad("syst_changeOfComposition",700,400);
-  p->SetRightMargin(0.2);
-  p->SetLeftMargin(0.13);
+void DrawEffectOfChangeInCrossSection(Bool_t spd = kFALSE, const char* fileName = "systematics_vtxtrigger_compositions.root") 
+{
+  TFile::Open(fileName);
 
-  TH2F* null = new TH2F("","",100,-1.05,1.05,100,0.97,1.03);
-  null->GetXaxis()->SetTitle("#eta");
-  null->GetYaxis()->SetTitle("Ratio pythia/modified composition");
-  null->Draw();
+  const Char_t* changes[]  = {"pythia","ddmore","ddless","sdmore","sdless", "dmore", "dless", "sdmoreddless", "sdlessddmore", "ddmore25","ddless25","sdmore25","sdless25", "dmore25", "dless25", "sdmoreddless25", "sdlessddmore25" };
+  //const Char_t* changes[]  = { "pythia", "qgsm", "phojet" };
+  //const Int_t nChanges = 3;
+  Int_t colors[] = {1,1,4,1,2,2,4,2,1};
 
-  TLatex* text[6];
+  c = DrawChange(spd, "ratio_vertexReco_triggerBias_", changes, 17, 9, colors, 0);
+  c->SaveAs("cross_sections.eps");
+}
 
-  for(Int_t i=0; i<6; i++) {
-    hRatios[i]->Draw("same");
-    
-    TString str(hRatios[i]->GetTitle());
-    str.Remove(0,16);
-    text[i] = new TLatex(1.08,hRatios[i]->GetBinContent(hRatios[i]->FindBin(0))-0.002,str.Data());
-    text[i]->SetTextColor(colors[i]);
-    text[i]->SetTextSize(0.053);
-    
-    text[i]->Draw();
-  }
+void DrawEffectOfChangeInComposition(Bool_t spd = kFALSE, const char* fileName = "new_compositions_analysis.root") 
+{
+  TFile::Open(fileName);
 
+  const Char_t* changes[]  = { "PythiaRatios", "KBoosted", "KReduced", "pBoosted", "pReduced", "KBoostedpBoosted", "KReducedpReduced", "KBoostedpReduced", "KReducedpBoosted"};
+  const char*   names[]    = { "",             "K #times 1.5", "K #times 0.5", "p #times 1.5", "p #times 0.5", "K #times 1.5, p #times 1.5", "K #times 0.5, p #times 0.5", "K #times 1.5, p #times 0.5", "K #times 0.5, p #times 1.5" };
+  //const Char_t* changes[]  = { "PythiaRatios", "PiBoosted",      "PiReduced", "KBoosted", "KReduced", "pBoosted", "pReduced", "othersBoosted", "othersReduced" };
+  //const char*   names[]    = { "",             "#pi #times 1.5", "#pi #times 0.5", "K #times 1.5", "K #times 0.5", "p #times 1.5", "p #times 0.5",  "others #times 1.5", "others #times 0.5" };
+  Int_t colors[] = {1,1,2,2,1,2,1,4,4};
 
+  c = DrawChange(spd, "", changes, 9, 9, colors, names, 0.03);
+  c->SaveAs("compositions.eps");
 }
 
 TPad* DrawCanvasAndPad(const Char_t* name, Int_t sizeX=600, Int_t sizeY=500) {
index fbf579a..fd90f09 100644 (file)
@@ -28,7 +28,7 @@ void run(Int_t runWhat, const Char_t* data, Int_t nRuns=20, Int_t offset=0, Bool
   // aProof option: 0 no proof
   //                1 proof with chain
   //                2 proof with dataset
-
+  
   TString taskName;
   if (runWhat == 0 || runWhat == 2)
   {
@@ -49,7 +49,7 @@ void run(Int_t runWhat, const Char_t* data, Int_t nRuns=20, Int_t offset=0, Bool
 
   if (aProof)
   {
-    TProof::Open("lxb6046");
+    TProof::Open("alicecaf");
     //gProof->SetParallel(1);
 
     // Enable the needed package
@@ -68,8 +68,8 @@ void run(Int_t runWhat, const Char_t* data, Int_t nRuns=20, Int_t offset=0, Bool
     }
     else
     {
-      gProof->UploadPackage("/afs/cern.ch/alice/caf/sw/ALICE/PARs/v4-14-Release/AF-v4-14");
-      gProof->EnablePackage("/afs/cern.ch/alice/caf/sw/ALICE/PARs/v4-14-Release/AF-v4-14");
+      gProof->UploadPackage("/afs/cern.ch/alice/caf/sw/ALICE/PARs/v4-16-Release/AF-v4-16");
+      gProof->EnablePackage("AF-v4-16");
     }
 
     gProof->UploadPackage("$ALICE_ROOT/PWG0base");
@@ -77,8 +77,10 @@ void run(Int_t runWhat, const Char_t* data, Int_t nRuns=20, Int_t offset=0, Bool
   }
   else
   {
+    gSystem->AddIncludePath("-I${ALICE_ROOT}/include/ -I${ALICE_ROOT}/PWG0/ -I${ALICE_ROOT}/PWG0/dNdEta/"); 
     gSystem->Load("libVMC");
     gSystem->Load("libTree");
+    gSystem->Load("libProof");
     gSystem->Load("libSTEERBase");
     gSystem->Load("libESD");
     gSystem->Load("libAOD");
@@ -95,7 +97,6 @@ void run(Int_t runWhat, const Char_t* data, Int_t nRuns=20, Int_t offset=0, Bool
   esdH->SetInactiveBranches("AliESDACORDE FMD ALIESDTZERO ALIESDVZERO ALIESDZDC AliRawDataErrorLogs CaloClusters Cascades EMCALCells EMCALTrigger ESDfriend Kinks Kinks Cascades AliESDTZERO ALIESDACORDE MuonTracks TrdTracks CaloClusters");
   mgr->SetInputEventHandler(esdH);
 
-
   AliPWG0Helper::AnalysisMode analysisMode = AliPWG0Helper::kSPD;
   AliPWG0Helper::Trigger      trigger      = AliPWG0Helper::kMB1;
 
@@ -130,10 +131,12 @@ void run(Int_t runWhat, const Char_t* data, Int_t nRuns=20, Int_t offset=0, Bool
     //task->SetUseMCVertex();
     //task->SetUseMCKine();
     //task->SetOnlyPrimaries();
-
+    //task->SetFillPhi();
+    
     task->SetTrigger(trigger);
     task->SetAnalysisMode(analysisMode);
     task->SetTrackCuts(esdTrackCuts);
+    task->SetDeltaPhiCut(0.05);
 
     mgr->AddTask(task);
 
@@ -150,11 +153,13 @@ void run(Int_t runWhat, const Char_t* data, Int_t nRuns=20, Int_t offset=0, Bool
     task2 = new AlidNdEtaCorrectionTask(option);
 
     // syst. error flags
+    //task2->SetFillPhi();
     //task2->SetOnlyPrimaries();
 
     task2->SetTrigger(trigger);
     task2->SetAnalysisMode(analysisMode);
     task2->SetTrackCuts(esdTrackCuts);
+    //task2->SetDeltaPhiCut(0.05);
 
     mgr->AddTask(task2);
 
@@ -189,8 +194,8 @@ void run(Int_t runWhat, const Char_t* data, Int_t nRuns=20, Int_t offset=0, Bool
   }
   else if (aProof == 3)
   {
-    ROOT->ProcessLine(".L CreateChainFromDataSet.C");
-    ds = gProof->GetDataSet(data);
+    gROOT->ProcessLine(".L CreateChainFromDataSet.C");
+    ds = gProof->GetDataSet(data)->GetStagedSubset();
     chain = CreateChainFromDataSet(ds);
     mgr->StartAnalysis("local", chain, nRuns, offset);
   }
diff --git a/PWG0/dNdEta/run.sh b/PWG0/dNdEta/run.sh
new file mode 100755 (executable)
index 0000000..1d3ad5d
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/bash
+rm analysis_{mc,esd,esd_raw}.root correction_map.root
+root.exe -b -q 'run.C(2,"'$1'",-1,0,0,2,1,"")'
+aliroot correct.C
diff --git a/PWG0/dNdEta/systematicsAnalysis.C b/PWG0/dNdEta/systematicsAnalysis.C
deleted file mode 100644 (file)
index 3042228..0000000
+++ /dev/null
@@ -1,181 +0,0 @@
-changeProductionCrossSections() {
-  //
-  // calculates dN/dEta from the standard correction and from
-  // corrections that has been evaluated with different relative cross
-  // sections (of single diff, double diff and non diff). The ratios
-  // (standard to changed x-section) of the different dN/deta
-  // distributions are saved to a file.
-  //
-
-  gSystem->Load("libPWG0base");
-
-  // folder names in systematics root file
-  const Char_t* folderNames[] = {"triggerBiasDD","triggerBiasSD","triggerBiasND","vertexRecoDD","vertexRecoSD","vertexRecoND"};
-
-  const Char_t* changes[]  = {"pythia","ddmore","ddless","sdmore","sdless", "dmore", "dless"};
-
-  Float_t scalesDD[] = {1.0, 1.5, 0.5, 1.0, 1.0, 1.5, 0.5};
-  Float_t scalesSD[] = {1.0, 1.0, 1.0, 1.5, 0.5, 1.5, 0.5};
-
-  // cross section from Pythia
-  //Float_t sigmaND = 55.2;
-  //Float_t sigmaDD = 9.78;
-  //Float_t sigmaSD = 14.30;
-
-  // getting data
-  TFile* finCorr = TFile::Open("analysis_esd.root");
-  dNdEtaAnalysis* analysis = new dNdEtaAnalysis("dndeta", "dndeta");
-  analysis->LoadHistograms();
-
-  // getting corrections
-  AlidNdEtaCorrection* correctionStandard = new AlidNdEtaCorrection("dndeta_correction","dndeta_correction");
-
-  TFile* finCorr = TFile::Open("correction_map.root");
-  correctionStandard->LoadHistograms();
-
-  // getting corrections for pure SD, DD and ND
-  TFile* finSyst = TFile::Open("systematics.root");
-  AlidNdEtaCorrection* correctionsSyst[7];
-  for (Int_t i=0; i<6; i++) {
-    correctionsSyst[i] = new AlidNdEtaCorrection(folderNames[i],folderNames[i]);
-    correctionsSyst[i]->LoadHistograms();
-  }
-
-  TH1F* hRatios[21];
-  for (Int_t j=0; j<3; j++) { // j = 0 (change vtx), j = 1 (change trg), j = 2 (change both)    
-
-    for (Int_t i=0; i<7; i++) { // changes in cross section
-      
-      // temporary correction with changed cross sections
-      AlidNdEtaCorrection* correctionTmp = (AlidNdEtaCorrection*)correctionStandard->Clone();;
-
-      correctionTmp->Reset();
-
-      if (j==0 || j==2) {
-       //correctionTmp->GetVertexRecoCorrection()->Reset();
-       //correctionTmp->GetVertexRecoCorrection()->Add(correctionsSyst[3]->GetVertexRecoCorrection(),scalesDD[i]);
-       //correctionTmp->GetVertexRecoCorrection()->Add(correctionsSyst[4]->GetVertexRecoCorrection(),scalesSD[i]);
-       //correctionTmp->GetVertexRecoCorrection()->Add(correctionsSyst[5]->GetVertexRecoCorrection(),1);
-
-       correctionTmp->Add(correctionsSyst[3], scalesDD[i]);
-       correctionTmp->Add(correctionsSyst[4], scalesSD[i]);
-       correctionTmp->Add(correctionsSyst[5], 1);      
-      }
-      if (j==1 || j==2) {
-       //correctionTmp->GetTriggerBiasCorrectionINEL()->Reset();
-       //correctionTmp->GetTriggerBiasCorrectionINEL()->Add(correctionsSyst[0]->GetTriggerBiasCorrectionINEL(),scalesDD[i]);
-       //correctionTmp->GetTriggerBiasCorrectionINEL()->Add(correctionsSyst[1]->GetTriggerBiasCorrectionINEL(),scalesSD[i]);
-       //correctionTmp->GetTriggerBiasCorrectionINEL()->Add(correctionsSyst[2]->GetTriggerBiasCorrectionINEL(),1);
-
-       correctionTmp->Add(correctionsSyst[0], scalesDD[i]);
-       correctionTmp->Add(correctionsSyst[1], scalesSD[i]);
-       correctionTmp->Add(correctionsSyst[2], 1);
-      }
-      correctionTmp->Finish();
-
-      dNdEtaAnalysis* analysisTmp = (dNdEtaAnalysis*)analysis->Clone();
-      analysisTmp->Finish(correctionTmp, 0.3, AlidNdEtaCorrection::kINEL);
-
-      Int_t counter = i + j*7;
-      
-      hRatios[counter] = (TH1F*)analysisTmp->GetdNdEtaHistogram(2)->Clone();
-      
-      TString name("ratio");
-      if (j==0) name.Append("_vetexReco_");
-      if (j==1) name.Append("_triggerBias_");
-      if (j==2) name.Append("_vertexReco_triggerBias_");
-      name.Append(changes[i]);
-      hRatios[counter]->SetName(name.Data());
-      name.Append(Form(" (DD #times %0.1f, SD #times %0.1f)",scalesDD[i],scalesSD[i]));
-      hRatios[counter]->SetTitle(name.Data());
-      hRatios[counter]->SetYTitle("ratio (Pythia x-sections)/(changed x-sections)");
-      
-      delete analysisTmp;
-      delete correctionTmp;
-    }
-  }
-
-  for (Int_t i=1; i<21; i++) 
-    hRatios[i]->Divide(hRatios[0],hRatios[i],1,1);
-  hRatios[0]->Divide(hRatios[0],hRatios[0],1,1);
-
-  TFile* fout = new TFile("systematics_xsections.root","RECREATE");
-  
-  for (Int_t i=0; i<21; i++) 
-    hRatios[i]->Write();
-  
-  fout->Write();
-  fout->Close();
-}
-
-changeParticleComposition() {
-  //
-  // calculates dN/dEta from the standard correction and from
-  // corrections that has been evaluated with different relative
-  // abundancies of kaons and protons and save the ratios in a file
-
-  gSystem->Load("libPWG0base");
-
-  const Char_t* folderNames[] = {"correction_0","correction_1","correction_2","correction_3"};
-  Float_t  scalesPi[] = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
-  Float_t  scalesK[]  = {0.5, 1.5, 1.0, 1.0, 0.5, 1.5};
-  Float_t  scalesP[]  = {1.0, 1.0, 0.5, 1.5, 0.5, 1.5};
-
-  // getting data
-  TFile* finCorr = TFile::Open("analysis_esd.root");
-  dNdEtaAnalysis* analysis = new dNdEtaAnalysis("dndeta", "dndeta");
-  analysis->LoadHistograms();
-
-  // getting corrections for pi, K, p and other particles
-  TFile* finSyst = TFile::Open("systematics.root");
-  AlidNdEtaCorrection* correctionsSyst[4];
-  for (Int_t i=0; i<4; i++) {
-    correctionsSyst[i] = new AlidNdEtaCorrection(folderNames[i],folderNames[i]);
-    correctionsSyst[i]->LoadHistograms();
-  }
-  AlidNdEtaCorrection* correctionAll = (AlidNdEtaCorrection*) correctionsSyst[0]->Clone();
-  correctionAll->Reset();
-  correctionAll->Add(correctionsSyst[0]);
-  correctionAll->Add(correctionsSyst[1]);
-  correctionAll->Add(correctionsSyst[2]);
-  correctionAll->Add(correctionsSyst[3]);
-  correctionAll->Finish();
-  analysis->Finish(correctionAll, 0.3, AlidNdEtaCorrection::kINEL);
-
-  TH1F* hRatios[6];
-  for (Int_t i=0; i<6; i++) { 
-    // temporary correction with changed particle composistion
-    AlidNdEtaCorrection* correctionTmp = (AlidNdEtaCorrection*)correctionAll->Clone();
-    
-    correctionTmp->Reset();
-    
-    correctionTmp->Add(correctionsSyst[0],scalesPi[i]);    
-    correctionTmp->Add(correctionsSyst[1],scalesK[i]);    
-    correctionTmp->Add(correctionsSyst[2],scalesP[i]);    
-    correctionTmp->Add(correctionsSyst[3],1);    
-    
-    correctionTmp->Finish();
-
-    dNdEtaAnalysis* analysisTmp = (dNdEtaAnalysis*)analysis->Clone();
-    analysisTmp->Finish(correctionTmp, 0.3, AlidNdEtaCorrection::kINEL);
-    
-    hRatios[i] = (TH1F*)analysisTmp->GetdNdEtaHistogram(2)->Clone();
-    hRatios[i]->Divide((TH1F*)analysis->GetdNdEtaHistogram(2)->Clone(),hRatios[i],1,1,"B"); 
-
-    TString name(Form("ratio_%d",i));
-    hRatios[i]->SetName(name.Data());
-    name = TString(Form("#pi #times %0.1f, K #times %0.1f, p #times %0.1f",scalesPi[i],scalesK[i],scalesP[i]));
-    hRatios[i]->SetTitle(name.Data());
-    hRatios[i]->SetYTitle("ratio (standard/changed compositions)");    
-  }
-
-  TFile* fout = new TFile("systematics_composition.root","RECREATE");
-  
-  for (Int_t i=0; i<6; i++) 
-    hRatios[i]->Write();
-  
-  fout->Write();
-  fout->Close();
-
-
-}
index d0245b6..49a1bfa 100644 (file)
@@ -123,7 +123,7 @@ Bool_t AliHighMultiplicitySelector::Process(Long64_t entry)
     return kFALSE;
   }
 
-  Bool_t eventTriggered = AliPWG0Helper::IsEventTriggered(fESD, AliPWG0Helper::kMB1);
+  Bool_t eventTriggered = AliPWG0Helper::IsEventTriggered(fESD->GetTriggerMask(), AliPWG0Helper::kMB1);
 
   if (!eventTriggered)
   {
@@ -1049,8 +1049,6 @@ void AliHighMultiplicitySelector::Ntrigger(Bool_t relative)
 void AliHighMultiplicitySelector::Contamination()
 {
   //
-  // produces a spectrum created with N triggers
-  // number of triggers and thresholds for the moment fixed
   //
 
   /*
@@ -1109,8 +1107,8 @@ void AliHighMultiplicitySelector::Contamination()
       //Double_t rate = rates[3];
 
       // coll. in 100 ns window
-      //Double_t windowSize = 100e-9;
-      Double_t windowSize = 25e-9;
+      Double_t windowSize = 100e-9;
+      //Double_t windowSize = 25e-9;
       Double_t collPerWindow = windowSize * rate;
       Printf("coll/window = %f", collPerWindow);
       Double_t windowsPerSecond = 1.0 / windowSize;
@@ -1294,7 +1292,7 @@ void AliHighMultiplicitySelector::Contamination2()
 
       Printf("Raw value for 2 collisions is %e", triggerRate2);
 
-      for (Double_t doubleRate = 0; doubleRate <= 0.2; doubleRate += 0.005)
+      for (Double_t doubleRate = 0; doubleRate <= 0.3; doubleRate += 0.005)
       {
         Float_t totalContamination = (triggerRate2 * doubleRate) / (triggerRate + triggerRate2 * doubleRate);
 
@@ -1309,6 +1307,119 @@ void AliHighMultiplicitySelector::Contamination2()
   }
 }
 
+void AliHighMultiplicitySelector::Contamination3()
+{
+  //
+  //
+
+  /*
+
+  gSystem->Load("libANALYSIS");
+  gSystem->Load("libPWG0base");
+  .L AliHighMultiplicitySelector.cxx+g
+  x = new AliHighMultiplicitySelector();
+  x->ReadHistograms("highmult_hijing100k.root");
+  x->Contamination3();
+
+  */
+
+  // get x-sections
+  TFile* file = TFile::Open("crosssectionEx.root");
+  if (!file)
+    return;
+
+  TH1* xSections[2];
+  xSections[0] = dynamic_cast<TH1*> (gFile->Get("xSection2Ex"));
+  xSections[1] = dynamic_cast<TH1*> (gFile->Get("xSection15Ex"));
+
+  // prob for a collision in a bunch crossing
+  Int_t nRates = 3;
+  Float_t rates[] = {0.07, 0.1, 0.2};
+
+  new TCanvas;
+
+  Int_t colors[] = { 2, 3, 4, 6, 7, 8 };
+  Int_t markers[] = { 7, 2, 4, 5, 6, 27 };
+
+  // put to 2 for second layer
+  for (Int_t i=0; i<1; ++i)
+  {
+    if (!xSections[i])
+      continue;
+
+    // relative x-section, once we have a collision
+    xSections[i]->Scale(1.0 / xSections[i]->Integral());
+
+    Int_t max = xSections[i]->GetNbinsX();
+    max = 500;
+
+    Float_t* xSection = new Float_t[max];
+    for (Int_t mult = 0; mult < max; mult++)
+      xSection[mult] = xSections[i]->GetBinContent(mult+1);
+
+    TH2* fMvsL = (i == 0) ? fMvsL1: fMvsL2;
+
+    for (Int_t currentRate = 0; currentRate<nRates; ++currentRate)
+    {
+      TGraph* graph = new TGraph;
+      graph->SetMarkerColor(colors[currentRate]);
+      graph->SetMarkerStyle(markers[currentRate]);
+
+      Float_t rate = rates[currentRate];
+
+      for (Int_t cut = 100; cut <= 201; cut += 10)
+      {
+        Printf("cut at %d", cut);
+
+      TH1* triggerEffHist = (TH1*) GetTriggerEfficiency(fMvsL, cut)->Clone("triggerEff");
+      Float_t* triggerEff = new Float_t[max];
+      for (Int_t mult = 0; mult < max; mult++)
+        triggerEff[mult] = triggerEffHist->GetBinContent(mult+1);
+
+      Double_t triggerRate = 0;
+      for (Int_t mult = 0; mult < max; mult++)
+        triggerRate += xSection[mult] * triggerEff[mult];
+
+      Printf("Raw value for 1 collision is %e", triggerRate);
+
+      Double_t triggerRate2 = 0;
+      for (Int_t mult = 0; mult < max; mult++)
+        for (Int_t mult2 = mult; mult2 < max; mult2++)
+          if (mult+mult2 < max)
+            triggerRate2 += ((mult2 > mult) ? 2. : 1.) * xSection[mult] * xSection[mult2] * triggerEff[mult+mult2];
+
+      Printf("Raw value for 2 collisions is %e", triggerRate2);
+
+      Double_t triggerRate3 = 0;
+      for (Int_t mult = 0; mult < max; mult++)
+        for (Int_t mult2 = 0; mult2 < max; mult2++)
+          for (Int_t mult3 = 0; mult3 < max; mult3++)
+            if (mult+mult2+mult3 < max)
+              triggerRate3 += xSection[mult] * xSection[mult2] * xSection[mult3] * triggerEff[mult+mult2+mult3];
+
+      Printf("Raw value for 3 collisions is %e", triggerRate3);
+
+      Double_t singleRate = TMath::Poisson(1, rate);
+      Double_t doubleRate = TMath::Poisson(2, rate);
+      Double_t tripleRate = TMath::Poisson(3, rate);
+
+      Printf("single = %f, double = %f, triple = %f", singleRate, doubleRate, tripleRate);
+
+      Float_t totalContamination = (triggerRate2 * doubleRate + triggerRate3 * tripleRate) / (triggerRate * singleRate + triggerRate2 * doubleRate + triggerRate3 * tripleRate);
+
+        //Printf("Total contamination is %.1f%%", totalContamination * 100);
+
+      graph->SetPoint(graph->GetN(), cut, totalContamination);
+      }
+
+      graph->Draw((currentRate == 0) ? "A*" : "* SAME");
+      graph->GetXaxis()->SetTitle("layer 1 threshold");
+      graph->GetYaxis()->SetTitle("contamination");
+      graph->GetYaxis()->SetRangeUser(0, 1);
+    }
+  }
+}
+
 void AliHighMultiplicitySelector::DrawHistograms()
 {
   // draws the histograms
index bad641a..110d857 100644 (file)
@@ -37,6 +37,7 @@ class AliHighMultiplicitySelector : public AliSelectorRL {
     TGraph* IntFractRate();
     void Contamination();
     void Contamination2();
+    void Contamination3();
     void MBComparison();
 
  protected:
index 93caa8b..cc6f34a 100644 (file)
@@ -43,8 +43,8 @@
 
 ClassImp(AliMultiplicityCorrection)
 
-const Int_t AliMultiplicityCorrection::fgkMaxInput  = 250;  // bins in measured histogram
-const Int_t AliMultiplicityCorrection::fgkMaxParams = 250;  // bins in unfolded histogram = number of fit params
+const Int_t AliMultiplicityCorrection::fgkMaxInput  = 120;  // bins in measured histogram
+const Int_t AliMultiplicityCorrection::fgkMaxParams = 120;  // bins in unfolded histogram = number of fit params
 
 TMatrixD* AliMultiplicityCorrection::fgCorrelationMatrix = 0;
 TMatrixD* AliMultiplicityCorrection::fgCorrelationCovarianceMatrix = 0;
@@ -59,15 +59,15 @@ Int_t AliMultiplicityCorrection::fgNParamsMinuit = AliMultiplicityCorrection::fg
 TF1* AliMultiplicityCorrection::fgNBD = 0;
 
 Float_t AliMultiplicityCorrection::fgBayesianSmoothing  = 1;           // smoothing parameter (0 = no smoothing)
-Int_t   AliMultiplicityCorrection::fgBayesianIterations = 100;         // number of iterations in Bayesian method
+Int_t   AliMultiplicityCorrection::fgBayesianIterations = 10;         // number of iterations in Bayesian method
 
 // These are the areas where the quality of the unfolding results are evaluated
 // Default defined here, call SetQualityRegions to change them
 // unit is in multiplicity (not in bin!)
 
 // SPD:   peak area - flat area - low stat area
-Int_t AliMultiplicityCorrection::fgQualityRegionsB[kQualityRegions] = {4,  60,  180};
-Int_t AliMultiplicityCorrection::fgQualityRegionsE[kQualityRegions] = {20, 140, 210};
+Int_t AliMultiplicityCorrection::fgQualityRegionsB[kQualityRegions] = {1,  20, 70};
+Int_t AliMultiplicityCorrection::fgQualityRegionsE[kQualityRegions] = {10, 65, 80};
 
 //____________________________________________________________________
 void AliMultiplicityCorrection::SetQualityRegions(Bool_t SPDStudy)
@@ -79,14 +79,14 @@ void AliMultiplicityCorrection::SetQualityRegions(Bool_t SPDStudy)
   if (SPDStudy)
   {
     // SPD:   peak area - flat area - low stat area
-    fgQualityRegionsB[0] = 4;
-    fgQualityRegionsE[0] = 20;
+    fgQualityRegionsB[0] = 1;
+    fgQualityRegionsE[0] = 10;
 
-    fgQualityRegionsB[1] = 60;
-    fgQualityRegionsE[1] = 140;
+    fgQualityRegionsB[1] = 20;
+    fgQualityRegionsE[1] = 65;
 
-    fgQualityRegionsB[2] = 180;
-    fgQualityRegionsE[2] = 210;
+    fgQualityRegionsB[2] = 70;
+    fgQualityRegionsE[2] = 80;
 
     Printf("AliMultiplicityCorrection::SetQualityRegions --> Enabled quality regions for SPD");
   }
@@ -122,6 +122,7 @@ AliMultiplicityCorrection::AliMultiplicityCorrection() :
     fMultiplicityVtx[i] = 0;
     fMultiplicityMB[i] = 0;
     fMultiplicityINEL[i] = 0;
+    fMultiplicityNSD[i] = 0;
   }
 
   for (Int_t i = 0; i < kCorrHists; ++i)
@@ -135,6 +136,26 @@ AliMultiplicityCorrection::AliMultiplicityCorrection() :
 }
 
 //____________________________________________________________________
+AliMultiplicityCorrection* AliMultiplicityCorrection::Open(const char* fileName, const char* folderName)
+{
+  // opens the given file, reads the multiplicity from the given folder and returns the object
+  
+  TFile* file = TFile::Open(fileName);
+  if (!file)
+  {
+    Printf("ERROR: Could not open %s", fileName);
+    return 0;
+  }
+  
+  AliMultiplicityCorrection* mult = new AliMultiplicityCorrection(folderName, folderName);
+  mult->LoadHistograms();
+  
+  // TODO closing the file does not work here, because the histograms cannot be read anymore. LoadHistograms need to be adapted
+  
+  return mult;
+}
+
+//____________________________________________________________________
 AliMultiplicityCorrection::AliMultiplicityCorrection(const Char_t* name, const Char_t* title) :
   TNamed(name, title),
   fCurrentESD(0),
@@ -172,8 +193,8 @@ AliMultiplicityCorrection::AliMultiplicityCorrection(const Char_t* name, const C
   #define VTXBINNING 10, binLimitsVtx
   #define NBINNING fgkMaxParams, binLimitsN*/
 
-  #define NBINNING 501, -0.5, 500.5
-  #define VTXBINNING 1, -10, 10
+  #define NBINNING 201, -0.5, 200.5
+  #define VTXBINNING 1, -6, 6
 
   for (Int_t i = 0; i < kESDHists; ++i)
     fMultiplicityESD[i] = new TH2F(Form("fMultiplicityESD%d", i), "fMultiplicityESD;vtx-z;Ntracks;Count", VTXBINNING, NBINNING);
@@ -188,6 +209,9 @@ AliMultiplicityCorrection::AliMultiplicityCorrection(const Char_t* name, const C
 
     fMultiplicityINEL[i] = dynamic_cast<TH2F*> (fMultiplicityVtx[0]->Clone(Form("fMultiplicityINEL%d", i)));
     fMultiplicityINEL[i]->SetTitle("fMultiplicityINEL");
+    
+    fMultiplicityNSD[i] = dynamic_cast<TH2F*> (fMultiplicityVtx[0]->Clone(Form("fMultiplicityNSD%d", i)));
+    fMultiplicityNSD[i]->SetTitle("fMultiplicityNSD");
   }
 
   for (Int_t i = 0; i < kCorrHists; ++i)
@@ -228,7 +252,11 @@ AliMultiplicityCorrection::~AliMultiplicityCorrection()
     if (fMultiplicityINEL[i])
       delete fMultiplicityINEL[i];
     fMultiplicityINEL[i] = 0;
-  }
+  
+    if (fMultiplicityNSD[i])
+      delete fMultiplicityNSD[i];
+    fMultiplicityNSD[i] = 0;
+}
 
   for (Int_t i = 0; i < kCorrHists; ++i)
   {
@@ -259,7 +287,7 @@ Long64_t AliMultiplicityCorrection::Merge(TCollection* list)
   TObject* obj;
 
   // collections of all histograms
-  TList collections[kESDHists+kMCHists*3+kCorrHists*2];
+  TList collections[kESDHists+kMCHists*4+kCorrHists*2];
 
   Int_t count = 0;
   while ((obj = iter->Next())) {
@@ -276,13 +304,14 @@ Long64_t AliMultiplicityCorrection::Merge(TCollection* list)
       collections[kESDHists+i].Add(entry->fMultiplicityVtx[i]);
       collections[kESDHists+kMCHists+i].Add(entry->fMultiplicityMB[i]);
       collections[kESDHists+kMCHists*2+i].Add(entry->fMultiplicityINEL[i]);
+      collections[kESDHists+kMCHists*3+i].Add(entry->fMultiplicityNSD[i]);
     }
 
     for (Int_t i = 0; i < kCorrHists; ++i)
-      collections[kESDHists+kMCHists*3+i].Add(entry->fCorrelation[i]);
+      collections[kESDHists+kMCHists*4+i].Add(entry->fCorrelation[i]);
 
     for (Int_t i = 0; i < kCorrHists; ++i)
-      collections[kESDHists+kMCHists*3+kCorrHists+i].Add(entry->fMultiplicityESDCorrected[i]);
+      collections[kESDHists+kMCHists*4+kCorrHists+i].Add(entry->fMultiplicityESDCorrected[i]);
 
     count++;
   }
@@ -295,13 +324,14 @@ Long64_t AliMultiplicityCorrection::Merge(TCollection* list)
     fMultiplicityVtx[i]->Merge(&collections[kESDHists+i]);
     fMultiplicityMB[i]->Merge(&collections[kESDHists+kMCHists+i]);
     fMultiplicityINEL[i]->Merge(&collections[kESDHists+kMCHists*2+i]);
+    fMultiplicityNSD[i]->Merge(&collections[kESDHists+kMCHists*3+i]);
   }
 
   for (Int_t i = 0; i < kCorrHists; ++i)
-    fCorrelation[i]->Merge(&collections[kESDHists+kMCHists*3+i]);
+    fCorrelation[i]->Merge(&collections[kESDHists+kMCHists*4+i]);
 
   for (Int_t i = 0; i < kCorrHists; ++i)
-    fMultiplicityESDCorrected[i]->Merge(&collections[kESDHists+kMCHists*3+kCorrHists+i]);
+    fMultiplicityESDCorrected[i]->Merge(&collections[kESDHists+kMCHists*4+kCorrHists+i]);
 
   delete iter;
 
@@ -337,6 +367,8 @@ Bool_t AliMultiplicityCorrection::LoadHistograms(const Char_t* dir)
       oldObjects.Add(fMultiplicityMB[i]);
     if (fMultiplicityINEL[i])
       oldObjects.Add(fMultiplicityINEL[i]);
+    if (fMultiplicityNSD[i])
+      oldObjects.Add(fMultiplicityNSD[i]);
   }
 
   for (Int_t i = 0; i < kCorrHists; ++i)
@@ -359,6 +391,7 @@ Bool_t AliMultiplicityCorrection::LoadHistograms(const Char_t* dir)
     fMultiplicityVtx[i] = dynamic_cast<TH2F*> (gDirectory->Get(fMultiplicityVtx[i]->GetName()));
     fMultiplicityMB[i] = dynamic_cast<TH2F*> (gDirectory->Get(fMultiplicityMB[i]->GetName()));
     fMultiplicityINEL[i] = dynamic_cast<TH2F*> (gDirectory->Get(fMultiplicityINEL[i]->GetName()));
+    fMultiplicityNSD[i] = dynamic_cast<TH2F*> (gDirectory->Get(fMultiplicityNSD[i]->GetName()));
     if (!fMultiplicityVtx[i] || !fMultiplicityMB[i] || !fMultiplicityINEL[i])
       success = kFALSE;
   }
@@ -396,16 +429,33 @@ void AliMultiplicityCorrection::SaveHistograms(const char* dir)
 
   for (Int_t i = 0; i < kESDHists; ++i)
     if (fMultiplicityESD[i])
+    {
       fMultiplicityESD[i]->Write();
+      fMultiplicityESD[i]->ProjectionY(Form("%s_px", fMultiplicityESD[i]->GetName()), 1, fMultiplicityESD[i]->GetNbinsX())->Write();
+    }
 
   for (Int_t i = 0; i < kMCHists; ++i)
   {
     if (fMultiplicityVtx[i])
+    {
       fMultiplicityVtx[i]->Write();
+      fMultiplicityVtx[i]->ProjectionY(Form("%s_px", fMultiplicityVtx[i]->GetName()), 1, fMultiplicityVtx[i]->GetNbinsX())->Write();
+    }
     if (fMultiplicityMB[i])
+    {
       fMultiplicityMB[i]->Write();
+      fMultiplicityMB[i]->ProjectionY(Form("%s_px", fMultiplicityMB[i]->GetName()), 1, fMultiplicityMB[i]->GetNbinsX())->Write();
+    }
     if (fMultiplicityINEL[i])
+    {
       fMultiplicityINEL[i]->Write();
+      fMultiplicityINEL[i]->ProjectionY(Form("%s_px", fMultiplicityINEL[i]->GetName()), 1, fMultiplicityINEL[i]->GetNbinsX())->Write();
+    }
+    if (fMultiplicityNSD[i])
+    {
+      fMultiplicityNSD[i]->Write();
+      fMultiplicityNSD[i]->ProjectionY(Form("%s_px", fMultiplicityNSD[i]->GetName()), 1, fMultiplicityNSD[i]->GetNbinsX())->Write();
+    }
   }
 
   for (Int_t i = 0; i < kCorrHists; ++i)
@@ -420,7 +470,7 @@ void AliMultiplicityCorrection::SaveHistograms(const char* dir)
 }
 
 //____________________________________________________________________
-void AliMultiplicityCorrection::FillGenerated(Float_t vtx, Bool_t triggered, Bool_t vertex, Int_t generated05, Int_t generated10, Int_t generated15, Int_t generated20, Int_t generatedAll)
+void AliMultiplicityCorrection::FillGenerated(Float_t vtx, Bool_t triggered, Bool_t vertex, AliPWG0Helper::MCProcessType processType, Int_t generated05, Int_t generated10, Int_t generated15, Int_t generated20, Int_t generatedAll)
 {
   //
   // Fills an event from MC
@@ -449,6 +499,15 @@ void AliMultiplicityCorrection::FillGenerated(Float_t vtx, Bool_t triggered, Boo
   fMultiplicityINEL[2]->Fill(vtx, generated15);
   fMultiplicityINEL[3]->Fill(vtx, generated20);
   fMultiplicityINEL[4]->Fill(vtx, generatedAll);
+  
+  if (processType != AliPWG0Helper::kSD)
+  {
+    fMultiplicityNSD[0]->Fill(vtx, generated05);
+    fMultiplicityNSD[1]->Fill(vtx, generated10);
+    fMultiplicityNSD[2]->Fill(vtx, generated15);
+    fMultiplicityNSD[3]->Fill(vtx, generated20);
+    fMultiplicityNSD[4]->Fill(vtx, generatedAll);
+  }
 }
 
 //____________________________________________________________________
@@ -628,7 +687,9 @@ Double_t AliMultiplicityCorrection::RegularizationEntropy(TVectorD& params)
     //Double_t tmp = params[i] / paramSum;
     Double_t tmp = params[i];
     if (tmp > 0 && (*fgEntropyAPriori)[i] > 0)
+    {
       chi2 += tmp * TMath::Log(tmp / (*fgEntropyAPriori)[i]);
+    }
   }
 
   return 100.0 + chi2;
@@ -711,7 +772,7 @@ void AliMultiplicityCorrection::MinuitFitFunction(Int_t&, Double_t*, Double_t& c
   //measGuessVector.Print();
 
   // reduce influence of first bin
-  copy(0) *= 0.01;
+  //copy(0) *= 0.01;
 
   // (Ad - m) W (Ad - m)
   // the factor 1e6 prevents that a very small number (measGuessVector[i]) is multiplied with a very
@@ -745,6 +806,7 @@ void AliMultiplicityCorrection::DrawGuess(Double_t *params)
   measGuessVector -= (*fgCurrentESDVector);
 
   TVectorD copy(measGuessVector);
+  //copy.Print();
 
   // (Ad - m) W
   // this step can be optimized because currently only the diagonal elements of fgCorrelationCovarianceMatrix are used
@@ -773,7 +835,7 @@ void AliMultiplicityCorrection::DrawGuess(Double_t *params)
 
   TH1* penalty = new TH1F("penalty", "penalty", fgNParamsMinuit, -0.5, fgNParamsMinuit - 0.5);
 
-  for (Int_t i=2; i<fgNParamsMinuit; ++i)
+  for (Int_t i=2+1; i<fgNParamsMinuit; ++i)
   {
     if (params[i-1] == 0)
       continue;
@@ -787,7 +849,9 @@ void AliMultiplicityCorrection::DrawGuess(Double_t *params)
 
     Double_t diff = (der1 - der2) / middle;
 
-    penalty->SetBinContent(i, diff * diff);
+    penalty->SetBinContent(i-1, diff * diff);
+    
+    //Printf("%d %f %f %f %f", i-1, left, middle, right, diff);
   }
   new TCanvas; penalty->DrawCopy(); gPad->SetLogy();
 }
@@ -823,24 +887,24 @@ void AliMultiplicityCorrection::SetupCurrentHists(Int_t inputRange, Bool_t fullP
   }
 
   fCurrentCorrelation = hist->Project3D("zy");
-  //((TH2*) fCurrentCorrelation)->Rebin2D(2, 1);
-  //fMultiplicityESDCorrected[correlationID]->Rebin(2);
   fCurrentCorrelation->Sumw2();
-
+  
   Printf("AliMultiplicityCorrection::SetupCurrentHists: Statistics information: %.f entries in correlation map; %.f entries in measured spectrum", fCurrentCorrelation->Integral(), fCurrentESD->Integral());
 
-  if (createBigBin)
+  fLastBinLimit = 0;
+  for (Int_t i=1; i<=fCurrentESD->GetNbinsX(); ++i)
   {
-    fLastBinLimit = 0;
-    for (Int_t i=1; i<=fCurrentESD->GetNbinsX(); ++i)
+    if (fCurrentESD->GetBinContent(i) <= 5)
     {
-      if (fCurrentESD->GetBinContent(i) <= 5)
-      {
-        fLastBinLimit = i;
-        break;
-      }
+      fLastBinLimit = i;
+      break;
     }
+  }
+  
+  Printf("AliMultiplicityCorrection::SetupCurrentHists: Bin limit in measured spectrum determined to be %d", fLastBinLimit);
 
+  if (createBigBin)
+  {
     if (fLastBinLimit > 0)
     {
       TCanvas* canvas = 0;
@@ -932,15 +996,37 @@ TH1* AliMultiplicityCorrection::GetEfficiency(Int_t inputRange, EventType eventT
   //
   // calculates efficiency for given event type
   //
-
+  
   TH1* divisor = 0;
   switch (eventType)
   {
-    case kTrVtx : divisor = fMultiplicityVtx[inputRange]->ProjectionY("divisor", -1, -1, "e"); break;
-    case kMB: divisor = fMultiplicityMB[inputRange]->ProjectionY("divisor", -1, -1, "e"); break;
-    case kINEL: divisor = fMultiplicityINEL[inputRange]->ProjectionY("divisor", -1, -1, "e"); break;
+    case kTrVtx : break;
+    case kMB: divisor = fMultiplicityMB[inputRange]->ProjectionY("divisor", 1, fMultiplicityMB[inputRange]->GetNbinsX(), "e"); break;
+    case kINEL: divisor = fMultiplicityINEL[inputRange]->ProjectionY("divisor", 1, fMultiplicityINEL[inputRange]->GetNbinsX(), "e"); break;
+    case kNSD: divisor = fMultiplicityNSD[inputRange]->ProjectionY("divisor", 1, fMultiplicityNSD[inputRange]->GetNbinsX(), "e"); break;
+  }
+  TH1* eff = fMultiplicityVtx[inputRange]->ProjectionY("CurrentEfficiency", 1, fMultiplicityVtx[inputRange]->GetNbinsX(), "e");
+  
+  if (eventType == kTrVtx)
+  {
+    for (Int_t i=0; i<= eff->GetNbinsX()+1; i++)
+      eff->SetBinContent(i, 1);
   }
-  TH1* eff = fMultiplicityVtx[inputRange]->ProjectionY("CurrentEfficiency", -1, -1, "e");
+  else
+    eff->Divide(eff, divisor, 1, 1, "B");
+    
+  return eff;
+}
+
+//____________________________________________________________________
+TH1* AliMultiplicityCorrection::GetTriggerEfficiency(Int_t inputRange)
+{
+  //
+  // calculates efficiency for given event type
+  //
+
+  TH1* divisor = fMultiplicityINEL[inputRange]->ProjectionY("divisor", 1, fMultiplicityINEL[inputRange]->GetNbinsX(), "e");
+  TH1* eff = fMultiplicityMB[inputRange]->ProjectionY("CurrentEfficiency", 1, fMultiplicityMB[inputRange]->GetNbinsX(), "e");
   eff->Divide(eff, divisor, 1, 1, "B");
   return eff;
 }
@@ -981,7 +1067,7 @@ void AliMultiplicityCorrection::SetBayesianParameters(Float_t smoothing, Int_t n
 Int_t AliMultiplicityCorrection::UnfoldWithMinuit(TH1* correlation, TH1* aEfficiency, TH1* measured, TH1* initialConditions, TH1* result, Bool_t check)
 {
   //
-  // implemenation of unfolding (internal function)
+  // implementation of unfolding (internal function)
   //
   // unfolds <measured> using response from <correlation> and effiency <aEfficiency>
   // output is in <result>
@@ -1096,16 +1182,17 @@ Int_t AliMultiplicityCorrection::UnfoldWithMinuit(TH1* correlation, TH1* aEffici
 
     if ((*fgCorrelationCovarianceMatrix)(i, i) > 1e7)
       (*fgCorrelationCovarianceMatrix)(i, i) = 0;
+    //Printf("%d, %e", i, (*fgCorrelationCovarianceMatrix)(i, i));
   }
 
   Int_t dummy = 0;
   Double_t chi2 = 0;
   MinuitFitFunction(dummy, 0, chi2, results, 0);
-  DrawGuess(results);
   printf("Chi2 of initial parameters is = %f\n", chi2);
 
   if (check)
   {
+    DrawGuess(results);
     delete[] results;
     return -1;
   }
@@ -1121,11 +1208,13 @@ Int_t AliMultiplicityCorrection::UnfoldWithMinuit(TH1* correlation, TH1* aEffici
   //printf("!!!!!!!!!!!!!! MIGRAD finished: Starting MINOS !!!!!!!!!!!!!!");
   //minuit->ExecuteCommand("MINOS", arglist, 0);
 
+  //new TCanvas; aEfficiency->Draw();
+
   for (Int_t i=0; i<fgNParamsMinuit; ++i)
   {
+    results[i] = minuit->GetParameter(i);
     if (aEfficiency->GetBinContent(i+1) > 0)
     {
-      results[i] = minuit->GetParameter(i);
       result->SetBinContent(i+1, results[i] * results[i] / aEfficiency->GetBinContent(i+1));
       // error is : (relError) * (value) = (minuit->GetParError(i) / minuit->GetParameter(i)) * (minuit->GetParameter(i) * minuit->GetParameter(i))
       result->SetBinError(i+1, minuit->GetParError(i) * results[i] /  aEfficiency->GetBinContent(i+1));
@@ -1136,7 +1225,7 @@ Int_t AliMultiplicityCorrection::UnfoldWithMinuit(TH1* correlation, TH1* aEffici
       result->SetBinError(i+1, 0);
     }
   }
-  DrawGuess(results);
+  //DrawGuess(results);
 
   delete[] results;
 
@@ -1331,7 +1420,7 @@ void AliMultiplicityCorrection::DrawComparison(const char* name, Int_t inputRang
       break;
   }
   Printf("AliMultiplicityCorrection::DrawComparison: MC bin limit is %d", mcBinLimit);
-
+  
   // scale to 1
   mcHist->Sumw2();
   if (mcHist->Integral() > 0)
@@ -1393,7 +1482,7 @@ void AliMultiplicityCorrection::DrawComparison(const char* name, Int_t inputRang
   TCanvas* canvas1 = 0;
   if (simple)
   {
-    canvas1 = new TCanvas(tmpStr, tmpStr, 900, 400);
+    canvas1 = new TCanvas(tmpStr, tmpStr, 1200, 600);
     canvas1->Divide(2, 1);
   }
   else
@@ -1403,16 +1492,27 @@ void AliMultiplicityCorrection::DrawComparison(const char* name, Int_t inputRang
   }
 
   canvas1->cd(1);
+  canvas1->cd(1)->SetGridx();
+  canvas1->cd(1)->SetGridy();
+  canvas1->cd(1)->SetTopMargin(0.05);
+  canvas1->cd(1)->SetRightMargin(0.05);
+  canvas1->cd(1)->SetLeftMargin(0.12);
+  canvas1->cd(1)->SetBottomMargin(0.12);
   TH1* proj = (TH1*) mcHist->Clone("proj");
 
   // normalize without 0 bin
   proj->Scale(1.0 / proj->Integral(2, proj->GetNbinsX()));
   Printf("Normalized without 0 bin!");
   proj->GetXaxis()->SetRangeUser(0, 200);
-  proj->SetTitle(";true multiplicity;Entries");
+  proj->GetYaxis()->SetTitleOffset(1.4);
+  //proj->SetLabelSize(0.05, "xy");
+  //proj->SetTitleSize(0.05, "xy");
+  proj->SetTitle(Form(";True multiplicity in |#eta| < %.1f;Entries", (inputRange+1)*0.5));
   proj->SetStats(kFALSE);
 
   fMultiplicityESDCorrected[esdCorrId]->SetLineColor(2);
+  fMultiplicityESDCorrected[esdCorrId]->SetMarkerColor(2);
+  //fMultiplicityESDCorrected[esdCorrId]->SetMarkerStyle(5);
   // normalize without 0 bin
   fMultiplicityESDCorrected[esdCorrId]->Scale(1.0 / fMultiplicityESDCorrected[esdCorrId]->Integral(2, fMultiplicityESDCorrected[esdCorrId]->GetNbinsX()));
   Printf("Normalized without 0 bin!");
@@ -1427,30 +1527,43 @@ void AliMultiplicityCorrection::DrawComparison(const char* name, Int_t inputRang
   gPad->SetLogy();
 
   TLegend* legend = new TLegend(0.3, 0.8, 0.93, 0.93);
-  legend->AddEntry(proj, "true distribution");
-  legend->AddEntry(fMultiplicityESDCorrected[esdCorrId], "unfolded distribution");
+  legend->AddEntry(proj, "True distribution");
+  legend->AddEntry(fMultiplicityESDCorrected[esdCorrId], "Unfolded distribution");
   legend->SetFillColor(0);
+  legend->SetTextSize(0.04);
   legend->Draw();
   // unfortunately does not work. maybe a bug? --> legend->SetTextSizePixels(14);
 
   canvas1->cd(2);
+  canvas1->cd(2)->SetGridx();
+  canvas1->cd(2)->SetGridy();
+  canvas1->cd(2)->SetTopMargin(0.05);
+  canvas1->cd(2)->SetRightMargin(0.05);
+  canvas1->cd(2)->SetLeftMargin(0.12);
+  canvas1->cd(2)->SetBottomMargin(0.12);
 
   gPad->SetLogy();
   fCurrentESD->GetXaxis()->SetRangeUser(0, 200);
   //fCurrentESD->SetLineColor(2);
-  fCurrentESD->SetTitle(";measured multiplicity;Entries");
+  fCurrentESD->SetTitle(Form(";Measured multiplicity in |#eta| < %.1f;Entries", (inputRange+1)*0.5));
   fCurrentESD->SetStats(kFALSE);
+  fCurrentESD->GetYaxis()->SetTitleOffset(1.4);
+  //fCurrentESD->SetLabelSize(0.05, "xy");
+  //fCurrentESD->SetTitleSize(0.05, "xy");
   fCurrentESD->DrawCopy("HIST E");
 
   convolutedProj->SetLineColor(2);
+  convolutedProj->SetMarkerColor(2);
+  convolutedProj->SetMarkerStyle(5);
   //proj2->SetMarkerColor(2);
   //proj2->SetMarkerStyle(5);
-  convolutedProj->DrawCopy("HIST SAME");
+  convolutedProj->DrawCopy("HIST SAME P");
 
   legend = new TLegend(0.3, 0.8, 0.93, 0.93);
-  legend->AddEntry(fCurrentESD, "measured distribution");
-  legend->AddEntry(convolutedProj, "R #otimes unfolded distribution");
+  legend->AddEntry(fCurrentESD, "Measured distribution");
+  legend->AddEntry(convolutedProj, "R #otimes unfolded distribution", "P");
   legend->SetFillColor(0);
+  legend->SetTextSize(0.04);
   legend->Draw();
 
   //TH1* diffMCUnfolded = dynamic_cast<TH1*> (proj->Clone("diffMCUnfolded"));
@@ -1856,12 +1969,29 @@ TH2F* AliMultiplicityCorrection::GetMultiplicityMC(Int_t i, EventType eventType)
     case kTrVtx : return fMultiplicityVtx[i]; break;
     case kMB : return fMultiplicityMB[i]; break;
     case kINEL : return fMultiplicityINEL[i]; break;
+    case kNSD : return fMultiplicityNSD[i]; break;
   }
 
   return 0;
 }
 
 //____________________________________________________________________
+void AliMultiplicityCorrection::SetMultiplicityMC(Int_t i, EventType eventType, TH2F* hist)
+{
+  //
+  // returns the corresponding MC spectrum
+  //
+
+  switch (eventType)
+  {
+    case kTrVtx : fMultiplicityVtx[i] = hist; break;
+    case kMB : fMultiplicityMB[i] = hist; break;
+    case kINEL : fMultiplicityINEL[i] = hist; break;
+    case kNSD : fMultiplicityNSD[i] = hist; break;
+  }
+}
+
+//____________________________________________________________________
 TH1* AliMultiplicityCorrection::CalculateStdDev(TH1** results, Int_t max)
 {
   // calculate standard deviation of (results[0] - results[k]) k=1...max-1
@@ -2049,7 +2179,7 @@ TH1* AliMultiplicityCorrection::StatisticalUncertainty(MethodType methodType, In
     for (Int_t x=1; x<=results[n]->GetNbinsX(); x++)
       average->Fill(results[n]->GetXaxis()->GetBinCenter(x), results[n]->GetBinContent(x));
   //new TCanvas; average->DrawClone();
-
+  
   // find cov. matrix
   TProfile2D* covMatrix = new TProfile2D("covMatrix", "covMatrix", nBins, lowEdge, upEdge, nBins, lowEdge, upEdge);
 
@@ -2061,7 +2191,7 @@ TH1* AliMultiplicityCorrection::StatisticalUncertainty(MethodType methodType, In
         Float_t cov = (results[n]->GetBinContent(x) - average->GetBinContent(x)) * (results[n]->GetBinContent(y) - average->GetBinContent(y));
         covMatrix->Fill(results[n]->GetXaxis()->GetBinCenter(x), results[n]->GetXaxis()->GetBinCenter(y), cov);
       }
-  new TCanvas; covMatrix->DrawClone("COLZ");
+  TCanvas* c = new TCanvas; c->cd(); covMatrix->DrawCopy("COLZ");
 
 //   // fill 2D histogram that contains deviation from first
 //   TH2F* deviations = new TH2F("deviations", "deviations", nBins, lowEdge, upEdge, 1000, -0.01, 0.01);
@@ -2113,6 +2243,24 @@ TH1* AliMultiplicityCorrection::StatisticalUncertainty(MethodType methodType, In
   //new TCanvas; results[0]->DrawCopy(); average->SetLineColor(2); average->DrawClone("SAME");
   //new TCanvas; averageFirstRatio->DrawCopy();
 
+  static TH1* temp = 0;
+  if (!temp)
+  {
+    temp = (TH1*) standardDeviation->Clone("temp");
+    for (Int_t x=1; x<=results[0]->GetNbinsX(); x++)
+      temp->SetBinContent(x, temp->GetBinContent(x) * results[0]->GetBinContent(x));
+  }
+  else
+  {
+    // find difference from result[0] as TH2
+    TH2F* pulls = new TH2F("pulls", "pulls;multiplicity;difference", nBins, lowEdge, upEdge, 1000, -10, 10);
+    for (Int_t n=1; n<kErrorIterations; ++n)
+      for (Int_t x=1; x<=results[n]->GetNbinsX(); x++)
+        if (temp->GetBinContent(x) > 0)
+          pulls->Fill(results[n]->GetXaxis()->GetBinCenter(x), (results[0]->GetBinContent(x) - results[n]->GetBinContent(x)) / temp->GetBinContent(x));
+    new TCanvas("pulls", "pulls", 800, 600); pulls->DrawCopy(); pulls->FitSlicesY();
+  }
+
   // clean up
   for (Int_t n=0; n<kErrorIterations; ++n)
     delete results[n];
@@ -2229,7 +2377,7 @@ Int_t AliMultiplicityCorrection::UnfoldWithBayesian(TH1* correlation, TH1* aEffi
   //
   // unfolds a spectrum
   //
-
+  
   if (measured->Integral() <= 0)
   {
     Printf("AliMultiplicityCorrection::UnfoldWithBayesian: ERROR: The measured spectrum is empty");
@@ -2286,7 +2434,7 @@ Int_t AliMultiplicityCorrection::UnfoldWithBayesian(TH1* correlation, TH1* aEffi
   }
 
   //TH1F* convergence = new TH1F("convergence", "convergence", 200, 0.5, 200.5);
-
+  
   // unfold...
   for (Int_t i=0; i<nIterations || nIterations < 0; i++)
   {
@@ -2333,14 +2481,24 @@ Int_t AliMultiplicityCorrection::UnfoldWithBayesian(TH1* correlation, TH1* aEffi
       else
         result[t] = 0;
     }
+    
+    // draw intermediate result
+    /*
+    for (Int_t t=0; t<kMaxT; t++)
+      aResult->SetBinContent(t+1, result[t]);
+    aResult->SetMarkerStyle(20+i);
+    aResult->SetMarkerColor(2);
+    aResult->DrawCopy("P SAME HIST");
+    */
 
     Double_t chi2LastIter = 0;
     // regularization (simple smoothing)
     for (Int_t t=kStartBin; t<kMaxT; t++)
     {
       Float_t newValue = 0;
+      
       // 0 bin excluded from smoothing
-      if (t > kStartBin+1 && t<kMaxT-1)
+      if (t > kStartBin+2 && t<kMaxT-1)
       {
         Float_t average = (result[t-1] + result[t] + result[t+1]) / 3;
 
@@ -2814,23 +2972,47 @@ void AliMultiplicityCorrection::SetGenMeasFromFunc(TF1* inputMC, Int_t id)
   if (id < 0 || id >= kESDHists)
     return;
 
-  TH2F* mc = fMultiplicityVtx[id];
-
+  // fill histogram used for random generation
+  TH1* tmp = fMultiplicityVtx[id]->ProjectionY("tmp");
+  tmp->Reset();
+
+  for (Int_t i=1; i<=tmp->GetNbinsX(); ++i)
+    tmp->SetBinContent(i, inputMC->Eval(tmp->GetXaxis()->GetBinCenter(i)) * tmp->GetXaxis()->GetBinWidth(i));
+    
+  TH1* mcRnd = fMultiplicityVtx[id]->ProjectionY("mcRnd");
+  mcRnd->Reset();
+  mcRnd->FillRandom(tmp, tmp->Integral());
+  
+  //new TCanvas; tmp->Draw();
+  //new TCanvas; mcRnd->Draw();
+  
+  // and move into 2d histogram
+  TH1* mc = fMultiplicityVtx[id];
   mc->Reset();
-
   for (Int_t i=1; i<=mc->GetNbinsY(); ++i)
   {
-    mc->SetBinContent(mc->GetNbinsX() / 2 + 1, i, inputMC->Eval(mc->GetYaxis()->GetBinCenter(i)) * mc->GetYaxis()->GetBinWidth(i));
-    mc->SetBinError(mc->GetNbinsX() / 2 + 1, i, 0);
+    mc->SetBinContent(mc->GetNbinsX() / 2 + 1, i, mcRnd->GetBinContent(i));
+    mc->SetBinError(mc->GetNbinsX() / 2 + 1, i, TMath::Sqrt(mcRnd->GetBinContent(i)));
+  }
+  
+  //new TCanvas; mc->Draw("COLZ");
+
+  // now randomize the measured histogram; funcMeasured is used as pilot function to generated the measured entries
+  TH1* funcMeasured = CalculateMultiplicityESD(tmp, id)->ProjectionY("funcMeasured");
+  
+  //new TCanvas; funcMeasured->Draw();
+  
+  fMultiplicityESD[id]->Reset();
+  
+  TH1* measRnd = fMultiplicityESD[id]->ProjectionY("measRnd");
+  measRnd->FillRandom(funcMeasured, tmp->Integral());
+  
+  //new TCanvas; measRnd->Draw();
+  
+  fMultiplicityESD[id]->Reset();
+  for (Int_t i=1; i<=fMultiplicityESD[id]->GetNbinsY(); ++i)
+  {
+    fMultiplicityESD[id]->SetBinContent(fMultiplicityESD[id]->GetNbinsX() / 2 + 1, i, measRnd->GetBinContent(i));
+    fMultiplicityESD[id]->SetBinError(fMultiplicityESD[id]->GetNbinsX() / 2 + 1, i, TMath::Sqrt(measRnd->GetBinContent(i)));
   }
-
-  //new TCanvas;
-  //mc->Draw("COLZ");
-
-  TH1* proj = mc->ProjectionY();
-
-  TString tmp(fMultiplicityESD[id]->GetName());
-  delete fMultiplicityESD[id];
-  fMultiplicityESD[id] = CalculateMultiplicityESD(proj, id);
-  fMultiplicityESD[id]->SetName(tmp);
 }
index d6f0e52..fede05b 100644 (file)
@@ -26,10 +26,11 @@ class TCollection;
 
 #include <TMatrixD.h>
 #include <TVectorD.h>
+#include <AliPWG0Helper.h>
 
 class AliMultiplicityCorrection : public TNamed {
   public:
-    enum EventType { kTrVtx = 0, kMB, kINEL };
+    enum EventType { kTrVtx = 0, kMB, kINEL, kNSD };
     enum RegularizationType { kNone = 0, kPol0, kPol1, kLog, kEntropy, kCurvature };
     enum MethodType { kChi2Minimization = 0, kBayesian = 1 };
     enum { kESDHists = 4, kMCHists = 5, kCorrHists = 8, kQualityRegions = 3 };
@@ -37,11 +38,13 @@ class AliMultiplicityCorrection : public TNamed {
     AliMultiplicityCorrection();
     AliMultiplicityCorrection(const Char_t* name, const Char_t* title);
     virtual ~AliMultiplicityCorrection();
+    
+    static AliMultiplicityCorrection* Open(const char* fileName, const char* folderName = "Multiplicity");
 
     virtual Long64_t Merge(TCollection* list);
 
     void FillMeasured(Float_t vtx, Int_t measured05, Int_t measured10, Int_t measured15, Int_t measured20);
-    void FillGenerated(Float_t vtx, Bool_t triggered, Bool_t vertex, Int_t generated05, Int_t generated10, Int_t generated15, Int_t generated20, Int_t generatedAll);
+    void FillGenerated(Float_t vtx, Bool_t triggered, Bool_t vertex, AliPWG0Helper::MCProcessType processType, Int_t generated05, Int_t generated10, Int_t generated15, Int_t generated20, Int_t generatedAll);
 
     void FillCorrection(Float_t vtx, Int_t generated05, Int_t generated10, Int_t generated15, Int_t generated20, Int_t generatedAll, Int_t measured05, Int_t measured10, Int_t measured15, Int_t measured20);
 
@@ -71,6 +74,7 @@ class AliMultiplicityCorrection : public TNamed {
     TH2F* GetMultiplicityVtx(Int_t i) { return fMultiplicityVtx[i]; }
     TH2F* GetMultiplicityMB(Int_t i) { return fMultiplicityMB[i]; }
     TH2F* GetMultiplicityINEL(Int_t i) { return fMultiplicityINEL[i]; }
+    TH2F* GetMultiplicityNSD(Int_t i) { return fMultiplicityNSD[i]; }
     TH2F* GetMultiplicityMC(Int_t i, EventType eventType);
     TH3F* GetCorrelation(Int_t i) { return fCorrelation[i]; }
     TH1F* GetMultiplicityESDCorrected(Int_t i) { return fMultiplicityESDCorrected[i]; }
@@ -79,6 +83,8 @@ class AliMultiplicityCorrection : public TNamed {
     void SetMultiplicityVtx(Int_t i, TH2F* hist)  { fMultiplicityVtx[i]  = hist; }
     void SetMultiplicityMB(Int_t i, TH2F* hist)   { fMultiplicityMB[i]   = hist; }
     void SetMultiplicityINEL(Int_t i, TH2F* hist) { fMultiplicityINEL[i] = hist; }
+    void SetMultiplicityNSD(Int_t i, TH2F* hist) { fMultiplicityNSD[i] = hist; }
+    void SetMultiplicityMC(Int_t i, EventType eventType, TH2F* hist);
     void SetCorrelation(Int_t i, TH3F* hist) { fCorrelation[i] = hist; }
     void SetMultiplicityESDCorrected(Int_t i, TH1F* hist) { fMultiplicityESDCorrected[i] = hist; }
 
@@ -88,6 +94,7 @@ class AliMultiplicityCorrection : public TNamed {
     void GetComparisonResults(Float_t* mc = 0, Int_t* mcLimit = 0, Float_t* residuals = 0, Float_t* ratioAverage = 0) const;
 
     TH1* GetEfficiency(Int_t inputRange, EventType eventType);
+    TH1* GetTriggerEfficiency(Int_t inputRange);
 
     static void SetQualityRegions(Bool_t SPDStudy);
     Float_t GetQuality(Int_t region) const { return fQuality[region]; }
@@ -137,11 +144,12 @@ class AliMultiplicityCorrection : public TNamed {
     static Int_t   fgBayesianIterations;            //! number of iterations in Bayesian method
     // end of configuration
 
-    TH2F* fMultiplicityESD[kESDHists]; // multiplicity histogram: vtx vs multiplicity; array: |eta| < 0.5, 0.9, 1.5, 2 (0..3)
+    TH2F* fMultiplicityESD[kESDHists]; // multiplicity histogram: vtx vs multiplicity; array: |eta| < 0.5, 1.0, 1.5, 2 (0..3)
 
-    TH2F* fMultiplicityVtx[kMCHists];  // multiplicity histogram of events that have a reconstructed vertex : vtx vs multiplicity; array: |eta| < 0.5, 0.9, 1.5, 2, inf (0..4)
-    TH2F* fMultiplicityMB[kMCHists];   // multiplicity histogram of triggered events                        : vtx vs multiplicity; array: |eta| < 0.5, 0.9, 1.5, 2, inf (0..4)
-    TH2F* fMultiplicityINEL[kMCHists]; // multiplicity histogram of all (inelastic) events                  : vtx vs multiplicity; array: |eta| < 0.5, 0.9, 1.5, 2, inf (0..4)
+    TH2F* fMultiplicityVtx[kMCHists];  // multiplicity histogram of events that have a reconstructed vertex : vtx vs multiplicity; array: |eta| < 0.5, 1.0, 1.5, 2, inf (0..4)
+    TH2F* fMultiplicityMB[kMCHists];   // multiplicity histogram of triggered events                        : vtx vs multiplicity; array: |eta| < 0.5, 1.0, 1.5, 2, inf (0..4)
+    TH2F* fMultiplicityINEL[kMCHists]; // multiplicity histogram of all (inelastic) events                  : vtx vs multiplicity; array: |eta| < 0.5, 1.0, 1.5, 2, inf (0..4)
+    TH2F* fMultiplicityNSD[kMCHists]; // multiplicity histogram of NSD events                  : vtx vs multiplicity; array: |eta| < 0.5, 1.0, 1.5, 2, inf (0..4)
 
     TH3F* fCorrelation[kCorrHists];              // vtx vs. (gene multiplicity (trig+vtx)) vs. (meas multiplicity); array: |eta| < 0.5, 1, 1.5, 2 (0..3 and 4..7), the first corrects to the eta range itself, the second to full phase space
 
@@ -161,7 +169,7 @@ class AliMultiplicityCorrection : public TNamed {
     AliMultiplicityCorrection(const AliMultiplicityCorrection&);
     AliMultiplicityCorrection& operator=(const AliMultiplicityCorrection&);
 
-  ClassDef(AliMultiplicityCorrection, 2);
+  ClassDef(AliMultiplicityCorrection, 4);
 };
 
 #endif
index d4a3ccc..621b30c 100644 (file)
@@ -8,6 +8,7 @@
 #include <TVector3.h>
 #include <TChain.h>
 #include <TFile.h>
+#include <TH1D.h>
 #include <TH2F.h>
 #include <TH3F.h>
 #include <TParticle.h>
@@ -42,6 +43,7 @@ AliMultiplicityTask::AliMultiplicityTask(const char* opt) :
   fOption(opt),
   fAnalysisMode(AliPWG0Helper::kSPD),
   fTrigger(AliPWG0Helper::kMB1),
+  fDeltaPhiCut(-1),
   fReadMC(kFALSE),
   fUseMCVertex(kFALSE),
   fMultiplicity(0),
@@ -49,6 +51,7 @@ AliMultiplicityTask::AliMultiplicityTask(const char* opt) :
   fSystSkipParticles(kFALSE),
   fSelectProcessType(0),
   fParticleSpecies(0),
+  fdNdpT(0),
   fPtSpectrum(0),
   fOutput(0)
 {
@@ -56,7 +59,7 @@ AliMultiplicityTask::AliMultiplicityTask(const char* opt) :
   // Constructor. Initialization of pointers
   //
 
-  for (Int_t i = 0; i<4; i++)
+  for (Int_t i = 0; i<8; i++)
     fParticleCorrection[i] = 0;
 
   // Define input and output slots here
@@ -92,6 +95,7 @@ void AliMultiplicityTask::ConnectInputData(Option_t *)
     Printf("ERROR: Could not read tree from input slot 0");
   } else {
     // Disable all branches and enable only the needed ones
+    /*
     tree->SetBranchStatus("*", 0);
 
     tree->SetBranchStatus("AliESDHeader*", 1);
@@ -105,6 +109,7 @@ void AliMultiplicityTask::ConnectInputData(Option_t *)
       //AliESDtrackCuts::EnableNeededBranches(tree);
       tree->SetBranchStatus("Tracks*", 1);
     }
+    */
 
     AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
 
@@ -127,6 +132,10 @@ void AliMultiplicityTask::CreateOutputObjects()
 
   fMultiplicity = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
   fOutput->Add(fMultiplicity);
+  
+  fdNdpT = new TH1F("fdNdpT", "fdNdpT", 1000, 0, 10);
+  fdNdpT->Sumw2();
+  fOutput->Add(fdNdpT);
 
   if (fOption.Contains("skip-particles"))
   {
@@ -135,7 +144,7 @@ void AliMultiplicityTask::CreateOutputObjects()
   }
 
   if (fOption.Contains("particle-efficiency"))
-    for (Int_t i = 0; i<4; i++)
+    for (Int_t i = 0; i<8; i++)
     {
       fParticleCorrection[i] = new AliCorrection(Form("correction_%d", i), Form("correction_%d", i));
       fOutput->Add(fParticleCorrection[i]);
@@ -161,33 +170,31 @@ void AliMultiplicityTask::CreateOutputObjects()
       TString subStr(fOption(fOption.Index("pt-spectrum")+17, 3));
       TString histName(Form("ptspectrum_%s", subStr.Data()));
       AliInfo(Form("Pt-Spectrum modification. Using %s.", histName.Data()));
-      fPtSpectrum = (TH1*) file->Get(histName);
-      if (!fPtSpectrum)
-       AliError("Histogram not found");
+      fPtSpectrum = (TH1D*) file->Get(histName);
+      if (!fPtSpectrum)   
+        AliError("Histogram not found");
     }
     else
       AliError("Could not open ptspectrum_fit.root. Pt Spectrum study could not be enabled.");
-
-    if (fPtSpectrum)
-      AliInfo("WARNING: Systematic study enabled. Pt spectrum will be modified");
   }
 
   if (fOption.Contains("pt-spectrum-func"))
   {
     if (fPtSpectrum)
     {
-      Printf("Using function from input list for systematic p_t study");
+      Printf("Using function for systematic p_t study");
     }
     else
     {
-      fPtSpectrum = new TH1F("fPtSpectrum", "fPtSpectrum", 1, 0, 100);
+      Printf("ERROR: Could not find function for systematic p_t study");
+      fPtSpectrum = new TH1D("fPtSpectrum", "fPtSpectrum", 1, 0, 100);
       fPtSpectrum->SetBinContent(1, 1);
     }
-
-    if (fPtSpectrum)
-      AliInfo("WARNING: Systematic study enabled. Pt spectrum will be modified");
   }
 
+  if (fPtSpectrum)
+    Printf("WARNING: Systematic study enabled. Pt spectrum will be modified");
+  
   if (fOption.Contains("particle-species")) {
     fParticleSpecies = new TNtuple("fParticleSpecies", "fParticleSpecies", "vtx:Pi_True:K_True:p_True:o_True:Pi_Rec:K_Rec:p_Rec:o_Rec:nolabel:doublePrim:doubleCount");
     fOutput->Add(fParticleSpecies);
@@ -207,7 +214,7 @@ void AliMultiplicityTask::Exec(Option_t*)
     return;
   }
 
-  Bool_t eventTriggered = AliPWG0Helper::IsEventTriggered(fESD->GetTriggerMask(), fTrigger);
+  Bool_t eventTriggered = AliPWG0Helper::IsEventTriggered(fESD, fTrigger);
 
   const AliESDVertex* vtxESD = AliPWG0Helper::GetVertex(fESD, fAnalysisMode);
   Bool_t eventVertex = (vtxESD != 0);
@@ -218,7 +225,7 @@ void AliMultiplicityTask::Exec(Option_t*)
 
   // post the data already here
   PostData(0, fOutput);
-
+  
   //const Float_t kPtCut = 0.3;
 
   // create list of (label, eta) tuples
@@ -243,13 +250,19 @@ void AliMultiplicityTask::Exec(Option_t*)
     {
       //printf("%d %f %f %f\n", i, mult->GetTheta(i), mult->GetPhi(i), mult->GetDeltaPhi(i));
 
-      // This removes non-tracklets in PDC06 data. Very bad solution. New solution is implemented for newer data. Keeping this for compatibility.
-      if (mult->GetDeltaPhi(i) < -1000)
+      Float_t deltaPhi = mult->GetDeltaPhi(i);
+      
+      if (fDeltaPhiCut > 0 && TMath::Abs(deltaPhi) > fDeltaPhiCut)
         continue;
 
       etaArr[inputCount] = mult->GetEta(i);
-      // TODO add second label array
-      labelArr[inputCount] = mult->GetLabel(i, 0);
+      if (mult->GetLabel(i, 0) == mult->GetLabel(i, 1))
+      {
+        labelArr[inputCount] = mult->GetLabel(i, 0);
+      }
+      else
+        labelArr[inputCount] = -1;
+        
       ++inputCount;
     }
   }
@@ -261,29 +274,32 @@ void AliMultiplicityTask::Exec(Option_t*)
       return;
     }
 
-    // get multiplicity from ESD tracks
-    TObjArray* list = fEsdTrackCuts->GetAcceptedTracks(fESD, (fAnalysisMode == AliPWG0Helper::kTPC));
-    Int_t nGoodTracks = list->GetEntries();
-
-    labelArr = new Int_t[nGoodTracks];
-    etaArr = new Float_t[nGoodTracks];
-
-    // loop over esd tracks
-    for (Int_t i=0; i<nGoodTracks; i++)
+    if (vtxESD)
     {
-      AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*> (list->At(i));
-      if (!esdTrack)
+      // get multiplicity from ESD tracks
+      TObjArray* list = fEsdTrackCuts->GetAcceptedTracks(fESD, (fAnalysisMode == AliPWG0Helper::kTPC));
+      Int_t nGoodTracks = list->GetEntries();
+  
+      labelArr = new Int_t[nGoodTracks];
+      etaArr = new Float_t[nGoodTracks];
+  
+      // loop over esd tracks
+      for (Int_t i=0; i<nGoodTracks; i++)
       {
-        AliDebug(AliLog::kError, Form("ERROR: Could not retrieve track %d.", i));
-        continue;
+        AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*> (list->At(i));
+        if (!esdTrack)
+        {
+          AliDebug(AliLog::kError, Form("ERROR: Could not retrieve track %d.", i));
+          continue;
+        }
+  
+        etaArr[inputCount] = esdTrack->Eta();
+        labelArr[inputCount] = TMath::Abs(esdTrack->GetLabel());
+        ++inputCount;
       }
-
-      etaArr[inputCount] = esdTrack->Eta();
-      labelArr[inputCount] = TMath::Abs(esdTrack->GetLabel());
-      ++inputCount;
+  
+      delete list;
     }
-
-    delete list;
   }
 
   // eta range for nMCTracksSpecies, nESDTracksSpecies
@@ -292,8 +308,8 @@ void AliMultiplicityTask::Exec(Option_t*)
     case AliPWG0Helper::kInvalid: break;
     case AliPWG0Helper::kTPC:
     case AliPWG0Helper::kTPCITS:
-       etaRange = 0.9; break;
-    case AliPWG0Helper::kSPD: etaRange = 2.0; break;
+       etaRange = 1.0; break;
+    case AliPWG0Helper::kSPD: etaRange = 1.0; break;
   }
 
   if (!fReadMC) // Processing of ESD information
@@ -301,7 +317,7 @@ void AliMultiplicityTask::Exec(Option_t*)
     if (eventTriggered && eventVertex)
     {
       Int_t nESDTracks05 = 0;
-      Int_t nESDTracks09 = 0;
+      Int_t nESDTracks10 = 0;
       Int_t nESDTracks15 = 0;
       Int_t nESDTracks20 = 0;
 
@@ -312,8 +328,8 @@ void AliMultiplicityTask::Exec(Option_t*)
         if (TMath::Abs(eta) < 0.5)
           nESDTracks05++;
 
-        if (TMath::Abs(eta) < 0.9)
-          nESDTracks09++;
+        if (TMath::Abs(eta) < 1.0)
+          nESDTracks10++;
 
         if (TMath::Abs(eta) < 1.5)
           nESDTracks15++;
@@ -322,7 +338,7 @@ void AliMultiplicityTask::Exec(Option_t*)
           nESDTracks20++;
       }
 
-      fMultiplicity->FillMeasured(vtx[2], nESDTracks05, nESDTracks09, nESDTracks15, nESDTracks20);
+      fMultiplicity->FillMeasured(vtx[2], nESDTracks05, nESDTracks10, nESDTracks15, nESDTracks20);
     }
   }
   else if (fReadMC)   // Processing of MC information
@@ -345,7 +361,7 @@ void AliMultiplicityTask::Exec(Option_t*)
       AliDebug(AliLog::kError, "Stack not available");
       return;
     }
-
+    
     AliHeader* header = mcEvent->Header();
     if (!header)
     {
@@ -363,35 +379,31 @@ void AliMultiplicityTask::Exec(Option_t*)
 
       vtx[2] = vtxMC[2];
     }
+    
+    // get process information
+    AliPWG0Helper::MCProcessType processType = AliPWG0Helper::GetEventProcessType(header);
 
     Bool_t processEvent = kTRUE;
     if (fSelectProcessType > 0)
     {
-      // getting process information; NB: this only works for Pythia
-      Int_t processtype = AliPWG0Helper::GetEventProcessType(header);
-
       processEvent = kFALSE;
 
       // non diffractive
-      if (fSelectProcessType == 1 && processtype == AliPWG0Helper::kND )
+      if (fSelectProcessType == 1 && processType == AliPWG0Helper::kND)
         processEvent = kTRUE;
 
       // single diffractive
-      if (fSelectProcessType == 2 && processtype == AliPWG0Helper::kSD )
+      if (fSelectProcessType == 2 && processType == AliPWG0Helper::kSD)
         processEvent = kTRUE;
 
       // double diffractive
-      if (fSelectProcessType == 3 && processtype == AliPWG0Helper::kDD )
+      if (fSelectProcessType == 3 && processType == AliPWG0Helper::kDD)
         processEvent = kTRUE;
 
       if (!processEvent)
-        AliDebug(AliLog::kDebug, Form("Skipping this event, because it is not of the requested process type (%d)", processtype));
+        Printf("Skipping this event, because it is not of the requested process type (%d)", (Int_t) processType);
     }
 
-    // systematic study: 10% lower efficiency
-    if (fSystSkipParticles && (gRandom->Uniform() < 0.1))
-      processEvent = kFALSE;
-
     if (processEvent)
     {
       // get the MC vertex
@@ -406,7 +418,7 @@ void AliMultiplicityTask::Exec(Option_t*)
 
       // tracks in different eta ranges
       Int_t nMCTracks05 = 0;
-      Int_t nMCTracks09 = 0;
+      Int_t nMCTracks10 = 0;
       Int_t nMCTracks15 = 0;
       Int_t nMCTracks20 = 0;
       Int_t nMCTracksAll = 0;
@@ -474,8 +486,8 @@ void AliMultiplicityTask::Exec(Option_t*)
         if (TMath::Abs(particle->Eta()) < 0.5)
           nMCTracks05 += particleWeight;
 
-        if (TMath::Abs(particle->Eta()) < 0.9)
-          nMCTracks09 += particleWeight;
+        if (TMath::Abs(particle->Eta()) < 1.0)
+          nMCTracks10 += particleWeight;
 
         if (TMath::Abs(particle->Eta()) < 1.5)
           nMCTracks15 += particleWeight;
@@ -484,6 +496,9 @@ void AliMultiplicityTask::Exec(Option_t*)
           nMCTracks20 += particleWeight;
 
         nMCTracksAll += particleWeight;
+        
+        if (particle->Pt() > 0 && TMath::Abs(particle->Eta()) < 1.0)
+          fdNdpT->Fill(particle->Pt(), 1.0 / particle->Pt());
 
         if (fParticleCorrection[0] || fParticleSpecies)
         {
@@ -504,12 +519,12 @@ void AliMultiplicityTask::Exec(Option_t*)
         }
       } // end of mc particle
 
-      fMultiplicity->FillGenerated(vtxMC[2], eventTriggered, eventVertex, (Int_t) nMCTracks05, (Int_t) nMCTracks09, (Int_t) nMCTracks15, (Int_t) nMCTracks20, (Int_t) nMCTracksAll);
+      fMultiplicity->FillGenerated(vtxMC[2], eventTriggered, eventVertex, processType, (Int_t) nMCTracks05, (Int_t) nMCTracks10, (Int_t) nMCTracks15, (Int_t) nMCTracks20, (Int_t) nMCTracksAll);
 
       if (eventTriggered && eventVertex)
       {
         Int_t nESDTracks05 = 0;
-        Int_t nESDTracks09 = 0;
+        Int_t nESDTracks10 = 0;
         Int_t nESDTracks15 = 0;
         Int_t nESDTracks20 = 0;
 
@@ -522,6 +537,10 @@ void AliMultiplicityTask::Exec(Option_t*)
         for (Int_t i=0; i<nPrim; i++)
           foundPrimaries[i] = kFALSE;
 
+        Bool_t* foundPrimaries2 = new Bool_t[nPrim];   // to prevent double counting
+        for (Int_t i=0; i<nPrim; i++)
+          foundPrimaries2[i] = kFALSE;
+
         Bool_t* foundTracks = new Bool_t[nMCPart];    // to prevent double counting
         for (Int_t i=0; i<nMCPart; i++)
           foundTracks[i] = kFALSE;
@@ -533,6 +552,10 @@ void AliMultiplicityTask::Exec(Option_t*)
 
           Int_t particleWeight = 1;
 
+          // systematic study: 5% lower efficiency
+          if (fSystSkipParticles && (gRandom->Uniform() < 0.05))
+            continue;
+      
           // in case of systematic study, weight according to the change of the pt spectrum
           if (fPtSpectrum)
           {
@@ -574,8 +597,8 @@ void AliMultiplicityTask::Exec(Option_t*)
           if (TMath::Abs(eta) < 0.5)
             nESDTracks05 += particleWeight;
 
-          if (TMath::Abs(eta) < 0.9)
-            nESDTracks09 += particleWeight;
+          if (TMath::Abs(eta) < 1.0)
+            nESDTracks10 += particleWeight;
 
           if (TMath::Abs(eta) < 1.5)
             nESDTracks15 += particleWeight;
@@ -584,7 +607,7 @@ void AliMultiplicityTask::Exec(Option_t*)
             nESDTracks20 += particleWeight;
 
 
-          if (fParticleCorrection[0] || fParticleSpecies)
+          if (fParticleSpecies)
           {
             Int_t motherLabel = -1;
             TParticle* mother = 0;
@@ -600,61 +623,181 @@ void AliMultiplicityTask::Exec(Option_t*)
               // count tracks that did not have a label
               if (TMath::Abs(eta) < etaRange)
                 nESDTracksSpecies[4]++;
-              continue;
             }
-
-            // get particle type (pion, proton, kaon, other)
-            Int_t id = -1;
-            switch (TMath::Abs(mother->GetPdgCode()))
+            else
             {
-              case 211: id = 0; break;
-              case 321: id = 1; break;
-              case 2212: id = 2; break;
-              default: id = 3; break;
+              // get particle type (pion, proton, kaon, other) of mother
+              Int_t idMother = -1;
+              switch (TMath::Abs(mother->GetPdgCode()))
+              {
+                case 211: idMother = 0; break;
+                case 321: idMother = 1; break;
+                case 2212: idMother = 2; break;
+                default: idMother = 3; break;
+              }
+
+              // double counting is ok for particle ratio study
+              if (TMath::Abs(eta) < etaRange)
+                nESDTracksSpecies[idMother]++;
+
+              // double counting is not ok for efficiency study
+
+              // check if we already counted this particle, this way distinguishes double counted particles (bug/artefact in tracking) or double counted primaries due to secondaries (physics)
+              if (foundTracks[label])
+              {
+                if (TMath::Abs(eta) < etaRange)
+                  nESDTracksSpecies[6]++;
+              }
+              else
+              {
+                foundTracks[label] = kTRUE;
+
+                // particle (primary) already counted?
+                if (foundPrimaries[motherLabel])
+                {
+                  if (TMath::Abs(eta) < etaRange)
+                    nESDTracksSpecies[5]++;
+                }
+                else
+                  foundPrimaries[motherLabel] = kTRUE;
+              }
             }
+          }
+
+          if (fParticleCorrection[0])
+          {
+            if (label >= 0 && stack->IsPhysicalPrimary(label))
+            {
+              TParticle* particle = stack->Particle(label);
 
-            // double counting is ok for particle ratio study
-            if (TMath::Abs(eta) < etaRange)
-              nESDTracksSpecies[id]++;
+              // get particle type (pion, proton, kaon, other)
+              Int_t id = -1;
+              switch (TMath::Abs(particle->GetPdgCode()))
+              {
+                case 211: id = 0; break;
+                case 321: id = 1; break;
+                case 2212: id = 2; break;
+                default: id = 3; break;
+              }
 
-            // double counting is not ok for efficiency study
+              // todo check if values are not completely off??
 
-            // check if we already counted this particle, this way distinguishes double counted particles (bug/artefact in tracking) or double counted primaries due to secondaries (physics)
-            if (foundTracks[label])
+              // particle (primary) already counted?
+              if (!foundPrimaries2[label])
+              {
+                foundPrimaries2[label] = kTRUE;
+                fParticleCorrection[id]->GetTrackCorrection()->FillMeas(vtxMC[2], particle->Eta(), particle->Pt());
+              }
+            }
+          }
+        }
+          
+        if (fParticleCorrection[0])
+        {
+          // if the particle decays/stops before this radius we do not see it
+          // 8cm larger than SPD layer 2
+          // 123cm TPC radius where a track has about 50 clusters (cut limit)          
+          const Float_t endRadius = (fAnalysisMode == AliPWG0Helper::kSPD) ? 8. : 123;
+                  
+          // loop over all primaries that have not been found
+          for (Int_t i=0; i<nPrim; i++)
+          {
+            // already found
+            if (foundPrimaries2[i])
+              continue;
+              
+            TParticle* particle = 0;
+            TClonesArray* trackrefs = 0;
+            mcEvent->GetParticleAndTR(i, particle, trackrefs);
+            
+            // true primary and charged
+            if (!AliPWG0Helper::IsPrimaryCharged(particle, nPrim))
+              continue;              
+            
+            //skip particles with larger |eta| than 3, to keep the log clean, is anyway not included in correction map
+            if (TMath::Abs(particle->Eta()) > 3)
+              continue;
+            
+            // skipping checking of process type of daughter: Neither kPBrem, kPDeltaRay nor kPCerenkov should appear in the event generation
+            
+            // get particle type (pion, proton, kaon, other)
+            Int_t id = -1;
+            switch (TMath::Abs(particle->GetPdgCode()))
             {
-              if (TMath::Abs(eta) < etaRange)
-                nESDTracksSpecies[6]++;
+              case 211: id = 4; break;
+              case 321: id = 5; break;
+              case 2212: id = 6; break;
+              default: id = 7; break;
+            }            
+            
+            if (!fParticleCorrection[id])
+              continue;
+              
+            // get last track reference
+            AliTrackReference* trackref = dynamic_cast<AliTrackReference*> (trackrefs->Last());
+            
+            if (!trackref)
+            {
+              Printf("ERROR: Could not get trackref of %d (count %d)", i, trackrefs->GetEntries());
+              particle->Print();
               continue;
             }
-            foundTracks[label] = kTRUE;
-
-            // particle (primary) already counted?
-            if (foundPrimaries[motherLabel])
+              
+            // particle in tracking volume long enough...
+            if (trackref->R() > endRadius)
+              continue;  
+            
+            if (particle->GetLastDaughter() >= 0)
             {
-              if (TMath::Abs(eta) < etaRange)
-                nESDTracksSpecies[5]++;
+              Int_t uID = stack->Particle(particle->GetLastDaughter())->GetUniqueID();
+              //if (uID != kPBrem && uID != kPDeltaRay && uID < kPCerenkov)
+              if (uID == kPDecay)
+              {
+                // decayed
+                
+                Printf("Particle %d (%s) decayed at %f, daugher uniqueID: %d:", i, particle->GetName(), trackref->R(), uID);
+                particle->Print();
+                Printf("Daughers:");
+                for (Int_t d = particle->GetFirstDaughter(); d <= particle->GetLastDaughter(); d++)
+                  stack->Particle(d)->Print();
+                Printf("");
+                
+                fParticleCorrection[id]->GetTrackCorrection()->FillGene(vtxMC[2], particle->Eta(), particle->Pt());
+                continue;
+              }
+            }
+            
+            if (trackref->DetectorId() == -1)
+            {
+              // stopped
+              Printf("Particle %d stopped at %f:", i, trackref->R());
+              particle->Print();
+              Printf("");
+              
+              fParticleCorrection[id]->GetTrackCorrection()->FillMeas(vtxMC[2], particle->Eta(), particle->Pt());
               continue;
             }
-            foundPrimaries[motherLabel] = kTRUE;
-
-            if (fParticleCorrection[id])
-              fParticleCorrection[id]->GetTrackCorrection()->FillMeas(vtxMC[2], mother->Eta(), mother->Pt());
+            
+            Printf("Particle %d simply not tracked", i);
+            particle->Print();
+            Printf("");
           }
         }
-
+        
         delete[] foundTracks;
         delete[] foundPrimaries;
+        delete[] foundPrimaries2;
 
-        if ((Int_t) nMCTracks15 > 15 && nESDTracks15 <= 3)
+        if ((Int_t) nMCTracks15 > 10 && nESDTracks15 <= 3)
         {
             TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
-            printf("WARNING: Event %lld %s (vtx-z = %f) has %d generated and %d reconstructed...\n", tree->GetReadEntry(), tree->GetCurrentFile()->GetName(), vtxMC[2], nMCTracks15, nESDTracks15);
+            printf("WARNING: Event %lld %s (vtx-z = %f, recon: %f, contrib: %d, res: %f) has %d generated and %d reconstructed...\n", tree->GetReadEntry(), tree->GetCurrentFile()->GetName(), vtxMC[2], vtx[2], vtxESD->GetNContributors(), vtxESD->GetZRes(), nMCTracks15, nESDTracks15);
         }
 
         // fill response matrix using vtxMC (best guess)
-        fMultiplicity->FillCorrection(vtxMC[2],  nMCTracks05,  nMCTracks09,  nMCTracks15,  nMCTracks20,  nMCTracksAll,  nESDTracks05,  nESDTracks09,  nESDTracks15,  nESDTracks20);
+        fMultiplicity->FillCorrection(vtxMC[2],  nMCTracks05,  nMCTracks10,  nMCTracks15,  nMCTracks20,  nMCTracksAll,  nESDTracks05,  nESDTracks10,  nESDTracks15,  nESDTracks20);
 
-        fMultiplicity->FillMeasured(vtx[2], nESDTracks05, nESDTracks09, nESDTracks15, nESDTracks20);
+        fMultiplicity->FillMeasured(vtx[2], nESDTracks05, nESDTracks10, nESDTracks15, nESDTracks20);
 
         if (fParticleSpecies)
           fParticleSpecies->Fill(vtxMC[2], nMCTracksSpecies[0], nMCTracksSpecies[1], nMCTracksSpecies[2], nMCTracksSpecies[3], nESDTracksSpecies[0], nESDTracksSpecies[1], nESDTracksSpecies[2], nESDTracksSpecies[3], nESDTracksSpecies[4], nESDTracksSpecies[5], nESDTracksSpecies[6]);
@@ -662,8 +805,10 @@ void AliMultiplicityTask::Exec(Option_t*)
     }
   }
 
-  delete etaArr;
-  delete labelArr;
+  if (etaArr)
+    delete[] etaArr;
+  if (labelArr)
+    delete[] labelArr;
 }
 
 void AliMultiplicityTask::Terminate(Option_t *)
@@ -679,9 +824,11 @@ void AliMultiplicityTask::Terminate(Option_t *)
   }
 
   fMultiplicity = dynamic_cast<AliMultiplicityCorrection*> (fOutput->FindObject("Multiplicity"));
-  for (Int_t i = 0; i < 4; ++i)
+  for (Int_t i = 0; i < 8; ++i)
     fParticleCorrection[i] = dynamic_cast<AliCorrection*> (fOutput->FindObject(Form("correction_%d", i)));
   fParticleSpecies = dynamic_cast<TNtuple*> (fOutput->FindObject("fParticleSpecies"));
+  
+  fdNdpT = dynamic_cast<TH1*> (fOutput->FindObject("fdNdpT"));
 
   if (!fMultiplicity)
   {
@@ -692,11 +839,13 @@ void AliMultiplicityTask::Terminate(Option_t *)
   TFile* file = TFile::Open("multiplicity.root", "RECREATE");
 
   fMultiplicity->SaveHistograms();
-  for (Int_t i = 0; i < 4; ++i)
+  for (Int_t i = 0; i < 8; ++i)
     if (fParticleCorrection[i])
       fParticleCorrection[i]->SaveHistograms();
   if (fParticleSpecies)
     fParticleSpecies->Write();
+  if (fdNdpT)
+    fdNdpT->Write();
 
   TObjString option(fOption);
   option.Write();
index c71cf0c..825b0a4 100644 (file)
@@ -13,6 +13,7 @@ class AliMultiplicityCorrection;
 class TNtuple;
 class AliCorrection;
 class TH1;
+class TH1D;
 class AliESDEvent;
 
 class AliMultiplicityTask : public AliAnalysisTask {
@@ -26,10 +27,11 @@ class AliMultiplicityTask : public AliAnalysisTask {
     virtual void   Terminate(Option_t *);
 
     void SetTrackCuts(AliESDtrackCuts* cuts) { fEsdTrackCuts = cuts; }
-    void SetPtSpectrum(TH1* hist) { fPtSpectrum = hist; }
+    void SetPtSpectrum(TH1D* hist) { fPtSpectrum = hist; }
 
     void SetAnalysisMode(AliPWG0Helper::AnalysisMode mode) { fAnalysisMode = mode; }
     void SetTrigger(AliPWG0Helper::Trigger trigger) { fTrigger = trigger; }
+    void SetDeltaPhiCut(Float_t cut) { fDeltaPhiCut = cut; }
 
     void SetReadMC(Bool_t flag = kTRUE) { fReadMC = flag; }
     void SetUseMCVertex(Bool_t flag = kTRUE) { fUseMCVertex = flag; }
@@ -40,6 +42,7 @@ class AliMultiplicityTask : public AliAnalysisTask {
     TString fOption;      // option string
     AliPWG0Helper::AnalysisMode fAnalysisMode; // detector that is used for analysis
     AliPWG0Helper::Trigger fTrigger;           // trigger that is used
+    Float_t fDeltaPhiCut;                      // cut in delta phi (only SPD)
 
     Bool_t  fReadMC;       // if true reads MC data (to build correlation maps)
     Bool_t  fUseMCVertex;  // the MC vtx is used instead of the ESD vertex (for syst. check)
@@ -48,17 +51,19 @@ class AliMultiplicityTask : public AliAnalysisTask {
     AliESDtrackCuts* fEsdTrackCuts;           // Object containing the parameters of the esd track cuts
 
     Bool_t fSystSkipParticles;     //! if true skips particles (systematic study)
-    AliCorrection* fParticleCorrection[4]; //! correction from measured to generated particles for different particles for trigger, vertex sample in |eta| < 2; switch on with particle-efficiency
-                                           // for each of the species: pi, k, p, other; for systematic study of pt cut off
+    AliCorrection* fParticleCorrection[8]; //! correction from measured to generated particles for different particles for trigger, vertex sample in |eta| < 2; switch on with "particle-efficiency"
+                                           // for each of the species (0..3): pi, k, p, other; for systematic study of pt cut off
+                                           // 4..7 counts for the same species the decayed particles (in generated) and stopped (in measured)
     Int_t fSelectProcessType;        //! 0 = all (default), 1 = ND, 2 = SD, 3 = DD (for systematic study)
-    TNtuple *fParticleSpecies;       //! per event: vtx_mc, (pi, k, p, rest (in |eta| < 2)) X (true, recon) + (nolabel,
+    TNtuple *fParticleSpecies;       //! per event: vtx_mc, (pi, k, p, rest (in |eta| < 1)) X (true, recon) + (nolabel,
                                      // doubleTracks, doublePrimaries) [doubleTracks + doublePrimaries are already part of
-                                     // rec. particles!)
+                                     // rec. particles!); enable with: particle-species
+    TH1* fdNdpT;                     //! true pT spectrum (MC)
 
-    TH1* fPtSpectrum;                //! function that modifies the pt spectrum (syst. study)
+    TH1D* fPtSpectrum;               // function that modifies the pt spectrum (syst. study)
 
     TList* fOutput;                  //! list send on output slot 0
-
+    
  private:
     AliMultiplicityTask(const AliMultiplicityTask&);
     AliMultiplicityTask& operator=(const AliMultiplicityTask&);
index d4a7518..c692553 100644 (file)
@@ -10,6 +10,22 @@ void SetTPC()
   AliMultiplicityCorrection::SetQualityRegions(kFALSE);
 }
 
+const char* GetMultLabel(Int_t etaR = -1, Bool_t trueM = kTRUE)
+{
+       if (etaR == -1)
+               etaR = etaRange;
+               
+       TString tmpStr((trueM) ? "True " : "Measured ");
+               
+       if (etaR == 4)
+       {
+               tmpStr += "multiplicity (full phase space)";
+       }
+       else
+               tmpStr += Form("multiplicity in |#eta| < %.1f", (etaR+1)* 0.5);
+       return Form("%s", tmpStr.Data());
+}
+
 void draw(const char* fileName = "multiplicity.root", const char* folder = "Multiplicity")
 {
   loadlibs();
@@ -44,20 +60,16 @@ void loadlibs()
   gSystem->Load("libPWG0base");
 }
 
-void correct(const char* fileNameMC = "multiplicityMC.root", const char* folder = "Multiplicity", const char* fileNameESD = "multiplicityESD.root", Bool_t chi2 = kTRUE, Int_t histID = 2, Bool_t fullPhaseSpace = kFALSE, Float_t beta  = 1e3, Int_t eventType = 0 /* AliMultiplicityCorrection::kTrVtx */)
+void correct(const char* fileNameMC = "multiplicityMC.root", const char* folder = "Multiplicity", const char* fileNameESD = "multiplicityESD.root", Bool_t chi2 = kFALSE, Int_t histID = 1, Bool_t fullPhaseSpace = kFALSE, Float_t beta  = 1e5, Int_t eventType = 0 /* AliMultiplicityCorrection::kTrVtx */, const char* targetFile = "unfolded.root", const char* folderESD = "Multiplicity")
 {
   loadlibs();
 
-  AliMultiplicityCorrection* mult = new AliMultiplicityCorrection(folder, folder);
-  TFile::Open(fileNameMC);
-  mult->LoadHistograms();
-
-  AliMultiplicityCorrection* esd = new AliMultiplicityCorrection(folder, folder);
-  TFile::Open(fileNameESD);
-  esd->LoadHistograms();
+  AliMultiplicityCorrection* mult = AliMultiplicityCorrection::Open(fileNameMC, folder);
+  AliMultiplicityCorrection* esd = AliMultiplicityCorrection::Open(fileNameESD, folderESD);
 
   TH2F* hist = esd->GetMultiplicityESD(histID);
   TH2F* hist2 = esd->GetMultiplicityMC(histID, eventType);
+  TH1* mcCompare = hist2->ProjectionY("mcmchist", 1, hist2->GetNbinsX());
 
   mult->SetMultiplicityESD(histID, hist);
 
@@ -76,26 +88,150 @@ void correct(const char* fileNameMC = "multiplicityMC.root", const char* folder
 
   if (chi2)
   {
-    mult->SetRegularizationParameters(AliMultiplicityCorrection::kPol1, beta);
+    mult->SetRegularizationParameters(AliMultiplicityCorrection::kPol0, beta);
     //mult->SetCreateBigBin(kFALSE);
     //mult->SetRegularizationParameters(AliMultiplicityCorrection::kNone, 0); //mult->SetCreateBigBin(kFALSE);
     //mult->SetRegularizationParameters(AliMultiplicityCorrection::kNone, 0, 125); mult->SetCreateBigBin(kFALSE);
-    //mult->SetRegularizationParameters(AliMultiplicityCorrection::kEntropy, 1e5);
+    //mult->SetRegularizationParameters(AliMultiplicityCorrection::kEntropy, 1e4);
     //mult->SetRegularizationParameters(AliMultiplicityCorrection::kLog, 1e5);
-    //mult->ApplyMinuitFit(histID, fullPhaseSpace, AliMultiplicityCorrection::kTrVtx, kTRUE, hist2->ProjectionY("mymchist"));
+    
+    //mult->ApplyMinuitFit(histID, fullPhaseSpace, AliMultiplicityCorrection::kTrVtx, kTRUE, mcCompare);
+    //mult->SetMultiplicityESDCorrected(histID, (TH1F*) mcCompare);
+    
     mult->ApplyMinuitFit(histID, fullPhaseSpace, eventType, kFALSE); //hist2->ProjectionY("mymchist"));
   }
   else
   {
-    mult->ApplyBayesianMethod(histID, fullPhaseSpace, eventType, 0.2, 100);
+    mult->ApplyBayesianMethod(histID, fullPhaseSpace, eventType, 1, 10, 0, kTRUE);
   }
 
-  TFile* file = TFile::Open("unfolded.root", "RECREATE");
+  mult->SetMultiplicityMC(histID, eventType, hist2);
+  
+  Printf("Writing result to %s", targetFile);
+  TFile* file = TFile::Open(targetFile, "RECREATE");
   mult->SaveHistograms();
   file->Write();
   file->Close();
 
-  mult->DrawComparison((chi2) ? "MinuitChi2" : "Bayesian", histID, fullPhaseSpace, kTRUE, hist2->ProjectionY("mymchist"));
+  mult->DrawComparison((chi2) ? "MinuitChi2" : "Bayesian", histID, fullPhaseSpace, kTRUE, mcCompare);
+}
+
+void DrawBayesianIterations(const char* fileNameMC = "multiplicityMC.root", const char* fileNameESD = "multiplicityESD.root", Int_t histID = 1, Int_t eventType = 0 /* AliMultiplicityCorrection::kTrVtx */)
+{
+  loadlibs();
+  
+  const char* folder = "Multiplicity";
+
+  AliMultiplicityCorrection* mult = new AliMultiplicityCorrection(folder, folder);
+  TFile::Open(fileNameMC);
+  mult->LoadHistograms();
+
+  AliMultiplicityCorrection* esd = new AliMultiplicityCorrection(folder, folder);
+  TFile::Open(fileNameESD);
+  esd->LoadHistograms();
+
+  TH2F* hist = esd->GetMultiplicityESD(histID);
+  TH2F* hist2 = esd->GetMultiplicityMC(histID, eventType);
+  
+  mult->SetMultiplicityESD(histID, hist);
+  mult->SetMultiplicityMC(histID, eventType, hist2);
+  
+  TH1* mcCompare = hist2->ProjectionY("mcmchist", 1, hist2->GetNbinsX());
+  //mcCompare->Scale(1.0 / mcCompare->Integral());
+
+  TH1* esdHist = (TH1*) hist->ProjectionY("myesd", 1, 1)->Clone("myesd");
+  //esdHist->Scale(1.0 / esdHist->Integral());
+  
+  c = new TCanvas("c", "c", 1200, 600);
+  c->Divide(2, 1);
+  
+  c->cd(1);
+  gPad->SetLeftMargin(0.12);
+  gPad->SetTopMargin(0.05);
+  gPad->SetRightMargin(0.05);
+  gPad->SetLogy();
+  gPad->SetGridx();
+  gPad->SetGridy();
+    
+  mcCompare->GetXaxis()->SetRangeUser(0, 80);
+  mcCompare->SetStats(0);
+  mcCompare->SetFillColor(5);
+  mcCompare->SetLineColor(5);
+  mcCompare->SetTitle(Form(";%s;Entries", GetMultLabel(1)));
+  mcCompare->GetYaxis()->SetRangeUser(2, esdHist->GetMaximum() * 2);
+  mcCompare->GetYaxis()->SetTitleOffset(1.3);
+  mcCompare->Draw("HIST");
+  esdHist->SetMarkerStyle(5);
+  esdHist->Draw("P HIST SAME");
+  
+  c->cd(2);
+  gPad->SetTopMargin(0.05);
+  gPad->SetRightMargin(0.05);
+  gPad->SetGridx();
+  gPad->SetGridy();
+  
+  trueMeasuredRatio = (TH1*) mcCompare->Clone("trueMeasuredRatio");
+  trueMeasuredRatio->Divide(esdHist);
+  trueMeasuredRatio->SetStats(0);
+  trueMeasuredRatio->SetTitle(Form(";%s;Ratio", GetMultLabel(1)));
+  trueMeasuredRatio->GetYaxis()->SetTitleOffset(1.3);
+  trueMeasuredRatio->GetYaxis()->SetRangeUser(0, 2);
+  // ROOT displays all values > 2 at 2 which looks weird
+  for (Int_t i=1; i<=trueMeasuredRatio->GetNbinsX(); i++)
+    if (trueMeasuredRatio->GetBinContent(i) > 2)
+      trueMeasuredRatio->SetBinContent(i, 0);
+  trueMeasuredRatio->SetMarkerStyle(5);
+  trueMeasuredRatio->Draw("P");
+
+  Int_t colors[] = {1, 2, 4, 6};
+  
+  legend = new TLegend(0.15, 0.13, 0.5, 0.5);
+  legend->SetFillColor(0);
+  legend->SetTextSize(0.04);
+  
+  legend->AddEntry(mcCompare, "True", "F");
+  legend->AddEntry(esdHist, "Measured", "P");
+
+  legend2 = new TLegend(0.15, 0.13, 0.5, 0.4);
+  legend2->SetFillColor(0);
+  legend2->SetTextSize(0.04);
+    
+  legend2->AddEntry(trueMeasuredRatio, "Measured", "P");
+  
+  Int_t iters[] = {1, 3, 10, -1};
+  for (Int_t i = 0; i<4; i++)
+  {
+    Int_t iter = iters[i];
+    mult->ApplyBayesianMethod(histID, kFALSE, eventType, 1, iter, 0, 0);
+    corr = mult->GetMultiplicityESDCorrected(histID);
+    corr->Scale(1.0 / corr->Integral());
+    corr->Scale(mcCompare->Integral());
+    corr->GetXaxis()->SetRangeUser(0, 80);
+    //corr->SetMarkerStyle(20+iter);
+    corr->SetLineColor(colors[i]);
+    corr->SetLineStyle(i+1);
+    corr->SetLineWidth(2);
+    
+    c->cd(1);
+    corr->DrawCopy("SAME HIST");
+    
+    c->cd(2);
+    clone = (TH1*) corr->Clone("clone");
+    clone->Divide(mcCompare, corr);
+    clone->GetYaxis()->SetRangeUser(0, 2);
+    clone->DrawCopy("SAME HIST");
+    
+    legend->AddEntry((TH1*) corr->Clone(), (iter > -1) ? Form("%d iteration%s", iter, (iter == 1) ? "" : "s") : "Convergence", "L");
+    legend2->AddEntry((TH1*) corr->Clone(), (iter > -1) ? Form("%d iteration%s", iter, (iter == 1) ? "" : "s") : "Convergence", "L");
+  }
+  
+  c->cd(1);
+  legend->Draw();
+  
+  c->cd(2);
+  legend2->Draw();
+  
+  c->SaveAs("bayesian_iterations.eps");
 }
 
 void CompareChi2Bayesian(Int_t histID = 2, const char* chi2File = "chi2.root", const char* bayesianFile = "bayesian.root", const char* label1 = "Chi2", const char* label2 = "Bayesian", const char* mcFile = 0, Float_t simpleCorrect = 0)
@@ -376,7 +512,7 @@ const char* GetEventTypeName(Int_t type)
   return 0;
 }
 
-void EvaluateBayesianMethodIterationsSmoothing(const char* fileNameMC = "multiplicityMC.root", const char* fileNameESD = "multiplicityMC.root", const char* targetDir, Int_t histID = 3)
+void EvaluateBayesianMethodIterationsSmoothing(const char* fileNameMC = "multiplicityMC.root", const char* fileNameESD = "multiplicityESD.root", const char* targetDir = "bayesian", Int_t histID = 1)
 {
   gSystem->mkdir(targetDir);
 
@@ -395,8 +531,8 @@ void EvaluateBayesianMethodIterationsSmoothing(const char* fileNameMC = "multipl
 
   TFile* graphFile = TFile::Open(Form("%s/EvaluateBayesianMethodIterationsSmoothing.root", targetDir), "RECREATE");
 
-  Int_t colors[3] = {1, 2, 4};
-  Int_t markers[20] = {20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 3, 4, 5, 6};
+  Int_t colors[] =  {1, 2, 3, 4, 6};
+  Int_t markers[] = {20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 3, 4, 5, 6};
 
   for (AliMultiplicityCorrection::EventType type = AliMultiplicityCorrection::kTrVtx; type <= AliMultiplicityCorrection::kTrVtx; ++type)
   //for (AliMultiplicityCorrection::EventType type = AliMultiplicityCorrection::kTrVtx; type <= AliMultiplicityCorrection::kINEL; ++type)
@@ -408,22 +544,22 @@ void EvaluateBayesianMethodIterationsSmoothing(const char* fileNameMC = "multipl
 
     for (Int_t i = 1; i <= 5; i++)
     {
-      Int_t iterArray[5] = {5, 20, 50, 100, -1};
-      //Int_t iter = i * 40 - 20;
+      Int_t iterArray[5] = {2, 5, 10, 20, -1};
       Int_t iter = iterArray[i-1];
 
       TGraph* fitResultsMC[3];
       for (Int_t region=0; region<AliMultiplicityCorrection::kQualityRegions; ++region)
       {
         fitResultsMC[region] = new TGraph;
-        fitResultsMC[region]->SetTitle(Form("%d iter. - reg. %d", iter, region+1));
+        fitResultsMC[region]->SetTitle(Form("%d iterations - reg. %d", iter, region+1));
         fitResultsMC[region]->GetXaxis()->SetTitle("smoothing parameter #alpha");
         fitResultsMC[region]->GetYaxis()->SetTitle(Form("P_{1} in region %d", region));
         fitResultsMC[region]->SetName(Form("%s_MC_%d", tmp.Data(), i * AliMultiplicityCorrection::kQualityRegions + region - 2));
         fitResultsMC[region]->SetFillColor(0);
         //fitResultsMC[region]->SetMarkerStyle(markers[(i-1) * AliMultiplicityCorrection::kQualityRegions + region]);
-        fitResultsMC[region]->SetMarkerStyle(markers[(i-1)]);
-        fitResultsMC[region]->SetLineColor(colors[region]);
+        fitResultsMC[region]->SetMarkerStyle(markers[i-1]);
+        fitResultsMC[region]->SetLineColor(colors[i-1]);
+        fitResultsMC[region]->SetMarkerColor(colors[i-1]);
       }
 
       TGraph* fitResultsRes = new TGraph;
@@ -433,9 +569,9 @@ void EvaluateBayesianMethodIterationsSmoothing(const char* fileNameMC = "multipl
       fitResultsRes->GetYaxis()->SetTitle("P_{2}");
 
       fitResultsRes->SetFillColor(0);
-      fitResultsRes->SetMarkerStyle(19+i);
-      fitResultsRes->SetMarkerColor(1);
-      fitResultsRes->SetLineColor(1);
+      fitResultsRes->SetMarkerStyle(markers[i-1]);
+      fitResultsRes->SetMarkerColor(colors[i-1]);
+      fitResultsRes->SetLineColor(colors[i-1]);
 
       for (Float_t weight = 0.0; weight < 1.01; weight += 0.2)
       {
@@ -609,7 +745,7 @@ void EvaluateDrawResult(const char* targetDir, Int_t type = 0, Bool_t plotRes =
 
 void EvaluateDrawResultRegions(const char* targetDir, Int_t type = 0)
 {
-  gSystem->Load("libPWG0base");
+  loadlibs();
 
   TString name;
   TFile* graphFile = 0;
@@ -624,43 +760,43 @@ void EvaluateDrawResultRegions(const char* targetDir, Int_t type = 0)
     graphFile = TFile::Open(Form("%s/EvaluateBayesianMethodIterationsSmoothing.root", targetDir));
   }
 
-  TCanvas* canvas = new TCanvas(name, name, 800, 1200);
+  TCanvas* canvas = new TCanvas(name, name, 1200, 800);
   //canvas->Divide(1, AliMultiplicityCorrection::kQualityRegions, 0, 0);
+  canvas->SetTopMargin(0);
+  canvas->SetBottomMargin(0);
+  canvas->SetRightMargin(0.05);
   canvas->Range(0, 0, 1, 1);
 
-  TPad* pad[3];
-  pad[0] = new TPad(Form("%s_pad1", name.Data()), "", 0.02, 0.05, 0.98, 0.35);
-  pad[1] = new TPad(Form("%s_pad2", name.Data()), "", 0.02, 0.35, 0.98, 0.65);
-  pad[2] = new TPad(Form("%s_pad3", name.Data()), "", 0.02, 0.65, 0.98, 0.95);
+  TPad* pad[4];
+  pad[3] = new TPad(Form("%s_pad1", name.Data()), "", 0, 0, 0.5, 0.5); pad[3]->SetTopMargin(0); pad[3]->SetBottomMargin(0.15);
+  pad[1] = new TPad(Form("%s_pad2", name.Data()), "", 0, 0.5, 0.5, 1); pad[1]->SetBottomMargin(0); 
+  pad[0] = new TPad(Form("%s_pad3", name.Data()), "", 0.5, 0, 1, 0.5); pad[0]->SetTopMargin(0); pad[0]->SetBottomMargin(0.15);
+  pad[2] = new TPad(Form("%s_pad4", name.Data()), "", 0.5, 0.5, 1, 1); pad[2]->SetBottomMargin(0); 
 
   Float_t yMinRegion[3];
   for (Int_t i=0; i<AliMultiplicityCorrection::kQualityRegions; ++i)
     yMinRegion[i] = 1e20;
 
-  for (Int_t region = 1; region <= AliMultiplicityCorrection::kQualityRegions; region++)
+  for (Int_t region = 0; region <= AliMultiplicityCorrection::kQualityRegions; region++)
   {
     canvas->cd();
-    pad[region-1]->Draw();
-    pad[region-1]->cd();
-    pad[region-1]->SetRightMargin(0.05);
-
-    if (region != 1)
-      pad[region-1]->SetBottomMargin(0);
-    if (region != AliMultiplicityCorrection::kQualityRegions)
-      pad[region-1]->SetTopMargin(0);
-
+    pad[region]->Draw();
+    pad[region]->cd();
+    pad[region]->SetRightMargin(0.05);
+    
     if (type == -1)
     {
-      pad[region-1]->SetLogx();
-      pad[region-1]->SetLogy();
+      pad[region]->SetLogx();
     }
-    pad[region-1]->SetTopMargin(0.05);
-    pad[region-1]->SetGridx();
-    pad[region-1]->SetGridy();
+    pad[region]->SetLogy();
+    
+    pad[region]->SetGridx();
+    pad[region]->SetGridy();
 
-    TLegend* legend = new TLegend(0.8, 0.15, 0.98, 0.98);
+    TLegend* legend = new TLegend(0.5, 0.4, 0.85, 0.85);
     legend->SetFillColor(0);
-
+    //legend->SetNColumns(3);
+    legend->SetTextSize(0.06);
     Int_t count = 0;
 
     Float_t xMin = 1e20;
@@ -675,49 +811,87 @@ void EvaluateDrawResultRegions(const char* targetDir, Int_t type = 0)
     {
       count++;
 
-      TGraph* mc = (TGraph*) graphFile->Get(Form("%s_MC_%d", name.Data(), count));
-      if (!mc)
-        break;
-
-      if (TString(mc->GetTitle()).Contains(Form("reg. %d", region)) == kFALSE)
-        continue;
+      if (region > 0)
+      {
+        TGraph* mc = (TGraph*) graphFile->Get(Form("%s_MC_%d", name.Data(), count));
+        if (!mc)
+          break;
+  
+        if (TString(mc->GetTitle()).Contains(Form("reg. %d", region)) == kFALSE)
+          continue;
+      
+        for (Int_t i=0; i<mc->GetN(); ++i)
+          yMinRegion[(count-1) % 3] = TMath::Min(yMinRegion[(count-1) % 3], mc->GetY()[i]);
+      }
+      else
+      {
+        TGraph* mc = (TGraph*) graphFile->Get(Form("%s_Res_%d", name.Data(), count));
+        if (!mc)
+          break;
+      }
 
       xaxis = mc->GetXaxis()->GetTitle();
       yaxis = mc->GetYaxis()->GetTitle();
 
-      mc->Print();
+      //mc->Print();
 
       xMin = TMath::Min(xMin, mc->GetXaxis()->GetXmin());
-      yMin = TMath::Min(yMin, mc->GetYaxis()->GetXmin());
+      yMin = TMath::Min(yMin, TMath::MinElement(mc->GetN(), mc->GetY()));
 
       xMax = TMath::Max(xMax, mc->GetXaxis()->GetXmax());
       yMax = TMath::Max(yMax, mc->GetYaxis()->GetXmax());
-
-      for (Int_t i=0; i<mc->GetN(); ++i)
-        yMinRegion[(count-1) % 3] = TMath::Min(yMinRegion[(count-1) % 3], mc->GetY()[i]);
+      
+      //Printf("%f %f %f %f", xMin, xMax, yMin, yMax);
     }
 
     if (type >= 0)
     {
-      xaxis = "smoothing parameter";
+      xaxis = "Smoothing parameter #alpha";
     }
     else if (type == -1)
     {
-      xaxis = "weight parameter";
-      xMax *= 5;
+      xaxis = "Weight parameter #beta";
+      //xMax *= 5;
+    }
+    if (region > 0)
+    {
+      yaxis = Form("Q_{1} in region %d ", region); // (2 <= t <= 150)";
     }
-    yaxis = "P_{1}"; // (2 <= t <= 150)";
+    else
+      yaxis = "Q_{2} ";
 
     printf("%f %f %f %f\n", xMin, xMax, yMin, yMax);
 
-    TGraph* dummy = new TGraph;
-    dummy->SetPoint(0, xMin, yMin);
-    dummy->SetPoint(1, xMax, yMax);
+    if (region > 0)
+    {
+      if (type == -1)
+      {
+        yMin = 0.534622;
+        yMax = 19.228941;
+      }
+      else
+      {
+        yMin = 0.759109;
+        yMax = 10;
+      }
+    }
+    
+    if (type != -1)
+      xMax = 1.0;
+
+    TH1* dummy = new TH2F("dummy", "dummy", 100, xMin, xMax, 100, yMin * 0.9, yMax * 1.1);
     dummy->SetTitle(Form(";%s;%s", xaxis.Data(), yaxis.Data()));
 
-    dummy->SetMarkerColor(0);
-    dummy->Draw("AP");
-    dummy->GetYaxis()->SetMoreLogLabels(1);
+    if (region == 0 && type != -1)
+      dummy->GetYaxis()->SetMoreLogLabels(1);
+    dummy->SetLabelSize(0.06, "xy");
+    dummy->SetTitleSize(0.06, "xy");
+    dummy->GetXaxis()->SetTitleOffset(1.2);
+    dummy->GetYaxis()->SetTitleOffset(0.8);
+    dummy->SetStats(0);
+    
+    dummy->DrawCopy();
+   
 
     count = 0;
 
@@ -725,26 +899,47 @@ void EvaluateDrawResultRegions(const char* targetDir, Int_t type = 0)
     {
       count++;
 
-      TGraph* mc = (TGraph*) graphFile->Get(Form("%s_MC_%d", name.Data(), count));
+      if (region > 0)
+      {
+        TGraph* mc = (TGraph*) graphFile->Get(Form("%s_MC_%d", name.Data(), count));
+        if (mc && TString(mc->GetTitle()).Contains(Form("reg. %d", region)) == kFALSE)
+          continue;
+      }
+      else
+        TGraph* mc = (TGraph*) graphFile->Get(Form("%s_Res_%d", name.Data(), count));
+
       if (!mc)
         break;
-      if (TString(mc->GetTitle()).Contains(Form("reg. %d", region)) == kFALSE)
-        continue;
-
-      printf("Loaded %d sucessful.\n", count);
+      //printf("Loaded %d sucessful.\n", count);
 
       if (type == -1)
       {
-        legend->AddEntry(mc, Form("Eq. (%d) - reg. %d", 10 + (count-1) / 3, 1+ (count-1) % 3));
+        //legend->AddEntry(mc, Form("Eq. (%d) - reg. %d", 10 + (count-1) / 3, 1+ (count-1) % 3));
+        //legend->AddEntry(mc, Form("Eq. (7.%d)", 11 + (count-1) / 3));
+        const char* names[] = { "Const", "Linear", "Log" };
+        legend->AddEntry(mc, names[(count-1) / 3], "PL");
       }
       else
-        legend->AddEntry(mc);
+      {
+        TString label(mc->GetTitle());
+        TString newLabel(label(0, label.Index(" ")));
+        //Printf("%s", newLabel.Data());
+        if (newLabel.Atoi() == -1)
+        {
+          newLabel = "Convergence";
+        }
+        else
+          newLabel = label(0, label.Index("iterations") + 10);
+          
+        legend->AddEntry(mc, newLabel, "PL");
+      }
 
       mc->Draw("SAME PC");
 
-     }
+    }
 
-     legend->Draw();
+    if (region == 2)
+      legend->Draw();
   }
 
   for (Int_t i=0; i<AliMultiplicityCorrection::kQualityRegions; ++i)
@@ -755,7 +950,7 @@ void EvaluateDrawResultRegions(const char* targetDir, Int_t type = 0)
   canvas->SaveAs(Form("%s/%s.eps", targetDir, canvas->GetName()));
 }
 
-void EvaluateChi2Method(const char* fileNameMC = "multiplicityMC_2M.root", const char* fileNameESD = "multiplicityMC_1M_3.root", const char* targetDir, Int_t histID = 3)
+void EvaluateChi2Method(const char* fileNameMC = "multiplicityMC.root", const char* fileNameESD = "multiplicityESD.root", const char* targetDir = "chi2compare", Int_t histID = 1)
 {
   gSystem->mkdir(targetDir);
 
@@ -773,16 +968,16 @@ void EvaluateChi2Method(const char* fileNameMC = "multiplicityMC_2M.root", const
   mult->SetMultiplicityESD(histID, hist);
 
   Int_t count = 0; // just to order the saved images...
-  Int_t colors[3] = {1, 2, 4};
-  Int_t markers[12] = {20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 3};
+  Int_t colors[] = {1, 2, 4, 3};
+  Int_t markers[] = {20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 3};
 
   TGraph* fitResultsRes = 0;
 
   TFile* graphFile = TFile::Open(Form("%s/EvaluateChi2Method.root", targetDir), "RECREATE");
 
-  for (AliMultiplicityCorrection::RegularizationType type = AliMultiplicityCorrection::kPol0; type <= AliMultiplicityCorrection::kEntropy; ++type)
-//  for (AliMultiplicityCorrection::RegularizationType type = AliMultiplicityCorrection::kEntropy; type <= AliMultiplicityCorrection::kEntropy; ++type)
-  //for (AliMultiplicityCorrection::RegularizationType type = AliMultiplicityCorrection::kPol1; type <= AliMultiplicityCorrection::kPol1; ++type)
+  //for (AliMultiplicityCorrection::RegularizationType type = AliMultiplicityCorrection::kPol0; type <= AliMultiplicityCorrection::kLog; ++type)
+  //for (AliMultiplicityCorrection::RegularizationType type = AliMultiplicityCorrection::kEntropy; type <= AliMultiplicityCorrection::kEntropy; ++type)
+  for (AliMultiplicityCorrection::RegularizationType type = AliMultiplicityCorrection::kPol1; type <= AliMultiplicityCorrection::kPol1; ++type)
   {
     TGraph* fitResultsMC[3];
     for (Int_t region=0; region<AliMultiplicityCorrection::kQualityRegions; ++region)
@@ -793,8 +988,11 @@ void EvaluateChi2Method(const char* fileNameMC = "multiplicityMC_2M.root", const
       fitResultsMC[region]->GetYaxis()->SetTitle(Form("P_{1} in region %d", region));
       fitResultsMC[region]->SetName(Form("EvaluateChi2Method_MC_%d", type * AliMultiplicityCorrection::kQualityRegions + region - 2));
       fitResultsMC[region]->SetFillColor(0);
-      fitResultsMC[region]->SetMarkerStyle(markers[(type-1) * AliMultiplicityCorrection::kQualityRegions + region]);
-      fitResultsMC[region]->SetLineColor(colors[region]);
+      //fitResultsMC[region]->SetMarkerStyle(markers[(type-1) * AliMultiplicityCorrection::kQualityRegions + region]);
+      //fitResultsMC[region]->SetLineColor(colors[region]);
+      fitResultsMC[region]->SetMarkerStyle(markers[type-1]);
+      fitResultsMC[region]->SetMarkerColor(colors[type-1]);
+      fitResultsMC[region]->SetLineColor(colors[type-1]);
     }
 
     fitResultsRes = new TGraph;
@@ -803,13 +1001,13 @@ void EvaluateChi2Method(const char* fileNameMC = "multiplicityMC_2M.root", const
     fitResultsRes->GetXaxis()->SetTitle("Weight Parameter");
 
     fitResultsRes->SetFillColor(0);
-    fitResultsRes->SetMarkerStyle(23+type);
-    fitResultsRes->SetMarkerColor(kRed);
-    fitResultsRes->SetLineColor(kRed);
+    fitResultsRes->SetMarkerStyle(markers[type-1]);
+    fitResultsRes->SetMarkerColor(colors[type-1]);
+    fitResultsRes->SetLineColor(colors[type-1]);
 
-    for (Int_t i=0; i<7; ++i)
+    for (Int_t i=0; i<15; ++i)
     {
-      Float_t weight = TMath::Power(TMath::Sqrt(10), i+6);
+      Float_t weight = TMath::Power(TMath::Sqrt(10), i+1);
       //Float_t weight = TMath::Power(10, i+2);
 
       //if (type == AliMultiplicityCorrection::kEntropy) weight = 1e4 * (i+1) * 1.5;
@@ -823,7 +1021,7 @@ void EvaluateChi2Method(const char* fileNameMC = "multiplicityMC_2M.root", const
 
       mult->SetRegularizationParameters(type, weight);
       Int_t status = mult->ApplyMinuitFit(histID, kFALSE, AliMultiplicityCorrection::kTrVtx);
-      mult->DrawComparison(Form("%s/%s", targetDir, runName.Data()), histID, kFALSE, kTRUE, hist2->ProjectionY());
+      mult->DrawComparison(Form("%s/%s", targetDir, runName.Data()), histID, kFALSE, kTRUE, hist2->ProjectionY("mymc", 1, hist2->GetNbinsX()));
       if (status != 0)
       {
         printf("MINUIT did not succeed. Skipping...\n");
@@ -1119,23 +1317,23 @@ void StatisticsPlot(const char* fileNameMC = "multiplicityMC_2M.root", Int_t his
   file->Close();
 }
 
-void StartingConditions(const char* fileNameMC = "multiplicityMC_2M.root", Int_t histID = 3)
+void StartingConditions(const char* fileNameMC = "multiplicityMC.root", Int_t histID = 1)
 {
-  gSystem->Load("libPWG0base");
+  loadlibs();
 
   AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
 
   TFile::Open(fileNameMC);
   mult->LoadHistograms("Multiplicity");
 
-  const char* files[] = { "multiplicityMC_1M_3.root", "multiplicityMC_100k_1.root", "multiplicityMC_100k_2.root", "multiplicityMC_100k_3.root", "multiplicityMC_100k_4.root" }
+  const char* files[] = { "multiplicityESD.root", "multiplicityESD_100k_1.root", "multiplicityESD_100k_2.root", "multiplicityESD_100k_1.root", "multiplicityESD_100k_2.root" }
 
   // this one we try to unfold
   TFile::Open(files[0]);
   AliMultiplicityCorrection* multESD = new AliMultiplicityCorrection("MultiplicityESD", "MultiplicityESD");
   multESD->LoadHistograms("Multiplicity");
   mult->SetMultiplicityESD(histID, multESD->GetMultiplicityESD(histID));
-  TH1* mc = multESD->GetMultiplicityMC(histID, AliMultiplicityCorrection::kTrVtx)->ProjectionY("mc");
+  TH1* mc = multESD->GetMultiplicityMC(histID, AliMultiplicityCorrection::kTrVtx)->ProjectionY("mc", 1, 1);
 
   TGraph* fitResultsChi2 = new TGraph;
   fitResultsChi2->SetTitle(";Input Dist ID;Chi2");
@@ -1180,7 +1378,8 @@ void StartingConditions(const char* fileNameMC = "multiplicityMC_2M.root", Int_t
     }
     else if (i == 6)
     {
-      func = new TF1("nbd", "[0] * TMath::Binomial([2]+TMath::Nint(x)-1, [2]-1) * pow([1] / ([1]+[2]), TMath::Nint(x)) * pow(1 + [1]/[2], -[2])", 0, 50);
+      func = new TF1("nbd", "exp(log([0]) + TMath::LnGamma([2]+x) - TMath::LnGamma([2]) - TMath::LnGamma(x+1) + log([1] / ([1]+[2])) * x + log(1.0 + [1]/[2]) * -[2])", 0, 50);
+      
       func->SetParNames("scaling", "averagen", "k");
       func->SetParLimits(0, 1e-3, 1e10);
       func->SetParLimits(1, 0.001, 1000);
@@ -1196,9 +1395,9 @@ void StartingConditions(const char* fileNameMC = "multiplicityMC_2M.root", Int_t
         startCond->SetBinContent(j, 1);
     }
 
-    mult->SetRegularizationParameters(AliMultiplicityCorrection::kPol1, 10000);
+    mult->SetRegularizationParameters(AliMultiplicityCorrection::kPol0, 1e5);
     mult->ApplyMinuitFit(histID, kFALSE, AliMultiplicityCorrection::kTrVtx, kFALSE, startCond);
-    mult->DrawComparison(Form("StartingConditions_%d_MinuitChi2", i), histID, kFALSE, kTRUE, mc);
+    //mult->DrawComparison(Form("StartingConditions_%d_MinuitChi2", i), histID, kFALSE, kTRUE, mc);
 
     Float_t chi2MC = 0;
     Int_t chi2MCLimit = 0;
@@ -1212,8 +1411,8 @@ void StartingConditions(const char* fileNameMC = "multiplicityMC_2M.root", Int_t
     if (!firstChi)
       firstChi = (TH1*) chi2Result->Clone("firstChi");
 
-    mult->ApplyBayesianMethod(histID, kFALSE, AliMultiplicityCorrection::kTrVtx, 1, 100, startCond);
-    mult->DrawComparison(Form("StartingConditions_%d_Bayesian", i), histID, kFALSE, kTRUE, mc);
+    mult->ApplyBayesianMethod(histID, kFALSE, AliMultiplicityCorrection::kTrVtx, 1, 10, startCond);
+    //mult->DrawComparison(Form("StartingConditions_%d_Bayesian", i), histID, kFALSE, kTRUE, mc);
     TH1* bayesResult = (TH1*) mult->GetMultiplicityESDCorrected(histID)->Clone(Form("bayesResult_%d", i));
     if (!firstBayesian)
       firstBayesian = (TH1*) bayesResult->Clone("firstBayesian");
@@ -1317,212 +1516,6 @@ void StartingConditions(const char* fileNameMC = "multiplicityMC_2M.root", Int_t
   canvas3->SaveAs(Form("%s.gif", canvas3->GetName()));
 }
 
-void DifferentSamples(const char* fileNameMC = "multiplicityMC_2M.root", Int_t histID = 3)
-{
-  gSystem->Load("libPWG0base");
-
-  AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
-
-  TFile::Open(fileNameMC);
-  mult->LoadHistograms("Multiplicity");
-
-  const char* files[] = { "multiplicityMC_100k_1.root", "multiplicityMC_100k_2.root", "multiplicityMC_100k_3.root", "multiplicityMC_100k_4.root", "multiplicityMC_100k_5.root", "multiplicityMC_100k_6.root", "multiplicityMC_100k_7.root", "multiplicityMC_100k_8.root" };
-
-  TGraph* fitResultsChi2 = new TGraph;
-  fitResultsChi2->SetTitle(";Input Dist ID;Chi2");
-  TGraph* fitResultsBayes = new TGraph;
-  fitResultsBayes->SetTitle(";Input Dist ID;Chi2");
-  TGraph* fitResultsChi2Limit = new TGraph;
-  fitResultsChi2Limit->SetTitle(";Input Dist ID;Multiplicity reach");
-  TGraph* fitResultsBayesLimit = new TGraph;
-  fitResultsBayesLimit->SetTitle(";Input Dist ID;Multiplicity reach");
-
-  TCanvas* canvasA = new TCanvas("DifferentSamplesA", "DifferentSamplesA", 1200, 600);
-  canvasA->Divide(4, 2);
-
-  TCanvas* canvasB = new TCanvas("DifferentSamplesB", "DifferentSamplesB", 1200, 600);
-  canvasB->Divide(4, 2);
-
-  TCanvas* canvas4 = new TCanvas("DifferentSamples4", "DifferentSamples4", 1000, 400);
-  canvas4->Divide(2, 1);
-
-  TCanvas* canvas3 = new TCanvas("DifferentSamples3", "DifferentSamples3", 1000, 400);
-  canvas3->Divide(2, 1);
-
-  Float_t min = 1e10;
-  Float_t max = 0;
-
-  TH1* firstChi = 0;
-  TH1* firstBayesian = 0;
-
-  TLegend* legend = new TLegend(0.7, 0.7, 1, 1);
-
-  TFile* file = TFile::Open("DifferentSamples.root", "RECREATE");
-  file->Close();
-
-  for (Int_t i=0; i<8; ++i)
-  {
-    TFile::Open(files[i]);
-    AliMultiplicityCorrection* multESD = new AliMultiplicityCorrection("MultiplicityESD2", "MultiplicityESD2");
-    multESD->LoadHistograms("Multiplicity");
-    mult->SetMultiplicityESD(histID, multESD->GetMultiplicityESD(histID));
-    TH1* mc = multESD->GetMultiplicityMC(histID, AliMultiplicityCorrection::kTrVtx)->ProjectionY(Form("mc_%d", i));
-    mc->Sumw2();
-
-    mult->SetRegularizationParameters(AliMultiplicityCorrection::kPol1, 10000);
-    mult->ApplyMinuitFit(histID, kFALSE, AliMultiplicityCorrection::kTrVtx, kFALSE);
-    mult->DrawComparison(Form("DifferentSamples_%d_MinuitChi2", i), histID, kFALSE, kTRUE, mc);
-
-    Float_t chi2MC = 0;
-    Int_t chi2MCLimit = 0;
-    mult->GetComparisonResults(&chi2MC, &chi2MCLimit, 0);
-    fitResultsChi2->SetPoint(fitResultsChi2->GetN(), i, chi2MC);
-    fitResultsChi2Limit->SetPoint(fitResultsChi2Limit->GetN(), i, chi2MCLimit);
-    min = TMath::Min(min, chi2MC);
-    max = TMath::Max(max, chi2MC);
-
-    TH1* chi2Result = (TH1*) mult->GetMultiplicityESDCorrected(histID)->Clone(Form("chi2Result_%d", i));
-    if (!firstChi)
-      firstChi = (TH1*) chi2Result->Clone("firstChi");
-
-    mult->ApplyBayesianMethod(histID, kFALSE, AliMultiplicityCorrection::kTrVtx, 1, 100);
-    mult->DrawComparison(Form("DifferentSamples_%d_Bayesian", i), histID, kFALSE, kTRUE, mc);
-    TH1* bayesResult = (TH1*) mult->GetMultiplicityESDCorrected(histID)->Clone(Form("bayesResult_%d", i));
-    if (!firstBayesian)
-      firstBayesian = (TH1*) bayesResult->Clone("firstBayesian");
-
-    TFile* file = TFile::Open("DifferentSamples.root", "UPDATE");
-    mc->Write();
-    chi2Result->Write();
-    bayesResult->Write();
-    file->Close();
-
-    mult->GetComparisonResults(&chi2MC, &chi2MCLimit, 0);
-    fitResultsBayes->SetPoint(fitResultsBayes->GetN(), i, chi2MC);
-    fitResultsBayesLimit->SetPoint(fitResultsBayesLimit->GetN(), i, chi2MCLimit);
-
-    min = TMath::Min(min, chi2MC);
-    max = TMath::Max(max, chi2MC);
-    mc->GetXaxis()->SetRangeUser(0, 150);
-    chi2Result->GetXaxis()->SetRangeUser(0, 150);
-
-    // skip errors for now
-    for (Int_t j=0; j<=chi2Result->GetNbinsX(); ++j)
-    {
-      chi2Result->SetBinError(j, 0);
-      bayesResult->SetBinError(j, 0);
-    }
-
-    canvas4->cd(1);
-    TH1* tmp = (TH1*) chi2Result->Clone("tmp");
-    tmp->SetTitle("Unfolded/MC;Npart;Ratio");
-    tmp->Divide(mc);
-    tmp->GetYaxis()->SetRangeUser(0.5, 1.5);
-    tmp->GetXaxis()->SetRangeUser(0, 200);
-    tmp->SetLineColor(i+1);
-    tmp->DrawCopy((i > 0) ? "SAME HIST" : "HIST");
-
-    canvas4->cd(2);
-    tmp = (TH1*) bayesResult->Clone("tmp");
-    tmp->SetTitle("Unfolded/MC;Npart;Ratio");
-    tmp->Divide(mc);
-    tmp->SetLineColor(i+1);
-    tmp->GetYaxis()->SetRangeUser(0.5, 1.5);
-    tmp->GetXaxis()->SetRangeUser(0, 200);
-    tmp->DrawCopy((i > 0) ? "SAME HIST" : "HIST");
-
-    canvas3->cd(1);
-    TH1* tmp = (TH1*) chi2Result->Clone("tmp");
-    tmp->SetTitle("Ratio to first result;Npart;Ratio");
-    tmp->Divide(firstChi);
-    tmp->GetYaxis()->SetRangeUser(0.5, 1.5);
-    tmp->GetXaxis()->SetRangeUser(0, 200);
-    tmp->SetLineColor(i+1);
-    legend->AddEntry(tmp, Form("%d", i));
-    tmp->DrawCopy((i > 0) ? "SAME HIST" : "HIST");
-
-    canvas3->cd(2);
-    tmp = (TH1*) bayesResult->Clone("tmp");
-    tmp->SetTitle("Ratio to first result;Npart;Ratio");
-    tmp->Divide(firstBayesian);
-    tmp->SetLineColor(i+1);
-    tmp->GetYaxis()->SetRangeUser(0.5, 1.5);
-    tmp->GetXaxis()->SetRangeUser(0, 200);
-    tmp->DrawCopy((i > 0) ? "SAME HIST" : "HIST");
-
-    if (i < 4)
-    {
-      canvasA->cd(i+1);
-    }
-    else
-      canvasB->cd(i+1-4);
-
-    mc->SetFillColor(kYellow);
-    mc->DrawCopy();
-    chi2Result->SetLineColor(kRed);
-    chi2Result->DrawCopy("SAME");
-    bayesResult->SetLineColor(kBlue);
-    bayesResult->DrawCopy("SAME");
-    gPad->SetLogy();
-
-    if (i < 4)
-    {
-      canvasA->cd(i+5);
-    }
-    else
-      canvasB->cd(i+5-4);
-
-    chi2Result->Divide(chi2Result, mc, 1, 1, "B");
-    bayesResult->Divide(bayesResult, mc, 1, 1, "B");
-
-    // skip errors for now
-    for (Int_t j=0; j<=chi2Result->GetNbinsX(); ++j)
-    {
-      chi2Result->SetBinError(j, 0);
-      bayesResult->SetBinError(j, 0);
-    }
-
-    chi2Result->SetTitle("Ratios;Npart;unfolded measured/MC");
-    chi2Result->GetYaxis()->SetRangeUser(0.5, 1.5);
-
-    chi2Result->DrawCopy("");
-    bayesResult->DrawCopy("SAME");
-  }
-
-  canvas3->cd(1);
-  legend->Draw();
-
-  canvasA->SaveAs(Form("%s.gif", canvasA->GetName()));
-  canvasB->SaveAs(Form("%s.gif", canvasB->GetName()));
-
-  TCanvas* canvas2 = new TCanvas("DifferentSamples2", "DifferentSamples2", 800, 400);
-  canvas2->Divide(2, 1);
-
-  canvas2->cd(1);
-  fitResultsChi2->SetMarkerStyle(20);
-  fitResultsChi2->GetYaxis()->SetRangeUser(0.5 * min, 1.5 * max);
-  fitResultsChi2->Draw("AP");
-
-  fitResultsBayes->SetMarkerStyle(3);
-  fitResultsBayes->SetMarkerColor(2);
-  fitResultsBayes->Draw("P SAME");
-
-  gPad->SetLogy();
-
-  canvas2->cd(2);
-  fitResultsChi2Limit->SetMarkerStyle(20);
-  fitResultsChi2Limit->GetYaxis()->SetRangeUser(0.9 * TMath::Min(fitResultsChi2Limit->GetYaxis()->GetXmin(), fitResultsBayesLimit->GetYaxis()->GetXmin()), 1.1 * TMath::Max(fitResultsChi2Limit->GetYaxis()->GetXmax(), fitResultsBayesLimit->GetYaxis()->GetXmax()));
-  fitResultsChi2Limit->Draw("AP");
-
-  fitResultsBayesLimit->SetMarkerStyle(3);
-  fitResultsBayesLimit->SetMarkerColor(2);
-  fitResultsBayesLimit->Draw("P SAME");
-
-  canvas2->SaveAs(Form("%s.gif", canvas2->GetName()));
-  canvas3->SaveAs(Form("%s.gif", canvas3->GetName()));
-  canvas4->SaveAs(Form("%s.gif", canvas4->GetName()));
-}
-
 void Merge(Int_t n, const char** files, const char* output)
 {
   // const char* files[] = { "multiplicityMC_100k_1.root",  "multiplicityMC_100k_2.root",  "multiplicityMC_100k_3.root", "multiplicityMC_100k_4.root",  "multiplicityMC_100k_5.root",  "multiplicityMC_100k_6.root",  "multiplicityMC_100k_7.root",  "multiplicityMC_100k_8.root" };
@@ -1556,7 +1549,7 @@ void Merge(Int_t n, const char** files, const char* output)
 
 void testMethod(Int_t caseNo, const char* fileName = "multiplicityMC.root")
 {
-  gSystem->Load("libPWG0base");
+  loadlibs();
 
   AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
 
@@ -1567,7 +1560,8 @@ void testMethod(Int_t caseNo, const char* fileName = "multiplicityMC.root")
 
   if (caseNo >= 4)
   {
-    func = new TF1("nbd", "[0] * TMath::Binomial([2]+TMath::Nint(x)-1, [2]-1) * pow([1] / ([1]+[2]), TMath::Nint(x)) * pow(1 + [1]/[2], -[2])", 0, 500);
+    TF1* func = new TF1("nbd", "exp(log([0]) + TMath::LnGamma([2]+x) - TMath::LnGamma([2]) - TMath::LnGamma(x+1) + log([1] / ([1]+[2])) * x + log(1.0 + [1]/[2]) * -[2])", 0, 200);
+    //func = new TF1("nbd", "[0] * TMath::Binomial([2]+TMath::Nint(x)-1, [2]-1) * pow([1] / ([1]+[2]), TMath::Nint(x)) * pow(1 + [1]/[2], -[2])", 0, 200);
     func->SetParNames("scaling", "averagen", "k");
   }
 
@@ -1577,7 +1571,7 @@ void testMethod(Int_t caseNo, const char* fileName = "multiplicityMC.root")
     case 1: func = new TF1("flat", "501-x"); break;
     case 2: func = new TF1("flat", "1000 * 1/(x+1)"); break;
     case 3: func = new TF1("flat", "1000 * TMath::Landau(x, 10, 5)"); break;
-    case 4: func->SetParameters(1e7, 10, 2); break;
+    case 4: func->SetParameters(2e5, 15, 2); break;
     case 5: func->SetParameters(1, 13, 7); break;
     case 6: func->SetParameters(1e7, 30, 4); break;
     case 7: func->SetParameters(1e7, 30, 2); break; // ***
@@ -1589,13 +1583,13 @@ void testMethod(Int_t caseNo, const char* fileName = "multiplicityMC.root")
   new TCanvas;
   func->Draw();
 
-  mult->SetGenMeasFromFunc(func, 3);
+  mult->SetGenMeasFromFunc(func, 1);
 
   TFile::Open("out.root", "RECREATE");
   mult->SaveHistograms();
 
-  new TCanvas; mult->GetMultiplicityESD(3)->ProjectionY()->DrawCopy();
-  new TCanvas; mult->GetMultiplicityVtx(3)->ProjectionY()->DrawCopy();
+  new TCanvas; mult->GetMultiplicityESD(1)->ProjectionY()->DrawCopy();
+  new TCanvas; mult->GetMultiplicityVtx(1)->ProjectionY("mc", 1, mult->GetMultiplicityVtx(1)->GetNbinsX())->DrawCopy();
 
   //mult->ApplyBayesianMethod(2, kFALSE);
   //mult->ApplyMinuitFit(2, kFALSE);
@@ -1945,9 +1939,10 @@ void BuildResponseFromTree(const char* fileName, const char* target)
 {
   //
   // builds several response matrices with different particle ratios (systematic study)
-  //
+  // 
+  // WARNING doesn't work uncompiled, see test.C
 
-  gSystem->Load("libPWG0base");
+  loadlibs();
 
   TFile::Open(fileName);
   TNtuple* fParticleSpecies = (TNtuple*) gFile->Get("fParticleSpecies");
@@ -1960,9 +1955,11 @@ void BuildResponseFromTree(const char* fileName, const char* target)
   Int_t secondaries = 0;
   Int_t doubleCount = 0;
 
-  for (Int_t num = 0; num < 7; num++)
+  for (Int_t num = 0; num < 9; num++)
   {
-    AliMultiplicityCorrection* fMultiplicity = new AliMultiplicityCorrection(Form("Multiplicity_%d", num), Form("Multiplicity_%d", num));
+    TString name;
+    name.Form("Multiplicity_%d", num);
+    AliMultiplicityCorrection* fMultiplicity = new AliMultiplicityCorrection(name, name);
 
     Float_t ratio[4]; // pi, K, p, other
     for (Int_t i = 0; i < 4; i++)
@@ -1971,11 +1968,13 @@ void BuildResponseFromTree(const char* fileName, const char* target)
     switch (num)
     {
       case 1 : ratio[1] = 0.5; break;
-      case 2 : ratio[2] = 0.5; break;
-      case 3 : ratio[1] = 1.5; break;
+      case 2 : ratio[1] = 1.5; break;
+      case 3 : ratio[2] = 0.5; break;
       case 4 : ratio[2] = 1.5; break;
       case 5 : ratio[1] = 0.5; ratio[2] = 0.5; break;
       case 6 : ratio[1] = 1.5; ratio[2] = 1.5; break;
+      case 7 : ratio[1] = 0.5; ratio[2] = 1.5; break;
+      case 8 : ratio[1] = 1.5; ratio[2] = 0.5; break;
     }
 
     for (Int_t i=0; i<fParticleSpecies->GetEntries(); i++)
@@ -2010,7 +2009,8 @@ void BuildResponseFromTree(const char* fileName, const char* target)
       //Printf("%.f %.f %.f %.f %.f", f[5], f[6], f[7], f[8], f[9]);
 
       fMultiplicity->FillCorrection(f[0], gene, gene, gene, gene, 0, meas, meas, meas, meas);
-      fMultiplicity->FillGenerated(f[0], kTRUE, kTRUE, gene, gene, gene, gene, 0);
+      // HACK all as kND = 1
+      fMultiplicity->FillGenerated(f[0], kTRUE, kTRUE, 1, gene, gene, gene, gene, 0);
       fMultiplicity->FillMeasured(f[0], meas, meas, meas, meas);
     }
 
@@ -2029,16 +2029,28 @@ void BuildResponseFromTree(const char* fileName, const char* target)
   }
 }
 
-void MergeModifyCrossSection(const char* output)
+void ParticleRatioStudy()
 {
-  const char* files[] = { "multiplicityMC_400k_syst_nd.root", "multiplicityMC_400k_syst_sd.root", "multiplicityMC_400k_syst_dd.root" };
+  loadlibs();
 
-  gSystem->Load("libPWG0base");
+  for (Int_t num = 0; num < 9; num++)
+  {
+    TString target;
+    target.Form("chi2_species_%d.root", num);
+    correct("species.root", Form("Multiplicity_%d", num), "species.root", 1, 1, 0, 1e5, 0, target, "Multiplicity_0");
+  }
+}
+
+void MergeModifyCrossSection(const char* output = "multiplicityMC_xsection.root")
+{
+  const char* files[] = { "multiplicityMC_nd.root", "multiplicityMC_sd.root", "multiplicityMC_dd.root" };
+
+  loadlibs();
 
   TFile::Open(output, "RECREATE");
   gFile->Close();
 
-  for (Int_t num=0; num<7; ++num)
+  for (Int_t num = 0; num < 7; num++)
   {
     AliMultiplicityCorrection* data[3];
     TList list;
@@ -2073,6 +2085,7 @@ void MergeModifyCrossSection(const char* output)
         data[i]->GetMultiplicityVtx(j)->Scale(ratio[i]);
         data[i]->GetMultiplicityMB(j)->Scale(ratio[i]);
         data[i]->GetMultiplicityINEL(j)->Scale(ratio[i]);
+        data[i]->GetMultiplicityNSD(j)->Scale(ratio[i]);
       }
 
       for (Int_t j=0; j<AliMultiplicityCorrection::kESDHists; j++)
index 24f6e24..1005a0d 100644 (file)
 
 #endif
 
-const char* correctionFile = "multiplicity.root";
-const char* measuredFile   = "multiplicityMC_1M_3.root";
-Int_t etaRange = 2;
-Int_t displayRange = 200; // axis range
+const char* correctionFile = "multiplicityMC.root";
+const char* measuredFile   = "multiplicityESD.root";
+Int_t etaRange = 1;
+Int_t displayRange = 80; // axis range
 Int_t ratioRange = 151;   // range to calculate difference
-Int_t longDisplayRange = 200;
+Int_t longDisplayRange = 120;
 
 const char* correctionFileTPC = "multiplicityMC_TPC_1.4M.root";
 const char* measuredFileTPC   = "multiplicityMC_TPC_0.6M.root";
@@ -57,6 +57,25 @@ void SetTPC()
   longDisplayRange = 100;
 }
 
+const char* GetMultLabel(Int_t etaR = -1, Bool_t trueM = kTRUE)
+{
+       if (etaR == -1)
+               etaR = etaRange;
+               
+       TString tmpStr((trueM) ? "True " : "Measured ");
+
+        tmpStr += "multiplicity";
+        //return Form("%s", tmpStr.Data());
+               
+       if (etaR == 4)
+       {
+               tmpStr += " (full phase space)";
+       }
+       else
+               tmpStr += Form(" in |#eta| < %.1f", (etaR+1)* 0.5);
+       return Form("%s", tmpStr.Data());
+}
+
 void Smooth(TH1* hist, Int_t windowWidth = 20)
 {
   TH1* clone = (TH1*) hist->Clone("clone");
@@ -73,23 +92,39 @@ void Smooth(TH1* hist, Int_t windowWidth = 20)
   delete clone;
 }
 
-void responseMatrixPlot()
+void responseMatrixPlot(const char* fileName = 0)
 {
-  gSystem->Load("libPWG0base");
+  loadlibs();
 
   AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
 
-  TFile::Open(correctionFile);
+  if (fileName == 0)
+    fileName = correctionFile;
+  
+  TFile::Open(fileName);
   mult->LoadHistograms("Multiplicity");
 
-  TH1* hist = mult->GetCorrelation(etaRange)->Project3D("zy");
+  // empty under/overflow bins in x, otherwise Project3D takes them into account
+  TH1* hist = mult->GetCorrelation(etaRange);
+  for (Int_t y=0; y<=hist->GetYaxis()->GetNbins()+1; ++y)
+  {
+    for (Int_t z=0; z<=hist->GetZaxis()->GetNbins()+1; ++z)
+    {
+      hist->SetBinContent(0, y, z, 0);
+      hist->SetBinContent(hist->GetXaxis()->GetNbins()+1, y, z, 0);
+    }
+  }
+  hist = ((TH3*) mult->GetCorrelation(etaRange))->Project3D("zy");
   hist->SetStats(kFALSE);
 
-  hist->SetTitle(";true multiplicity;measured multiplicity;Entries");
+  hist->SetTitle(Form(";%s;%s;Entries", GetMultLabel(), GetMultLabel(etaRange, kFALSE)));
   hist->GetXaxis()->SetRangeUser(0, longDisplayRange);
   hist->GetYaxis()->SetRangeUser(0, longDisplayRange);
+  
+  hist->GetYaxis()->SetTitleOffset(1.3);
+  hist->GetZaxis()->SetTitleOffset(1.2);
 
-  TCanvas* canvas = new TCanvas("c1", "c1", 800, 600);
+  TCanvas* canvas = new TCanvas("c1", "c1", 600, 600);
   canvas->SetRightMargin(0.15);
   canvas->SetTopMargin(0.05);
 
@@ -99,11 +134,64 @@ void responseMatrixPlot()
   canvas->SaveAs("responsematrix.eps");
 }
 
+void multPythiaPhojet()
+{
+  loadlibs();
+  
+  TFile::Open("LHC08c11_10TeV_0.5T/mb1/spd/multiplicity.root");
+  AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
+  mult->LoadHistograms("Multiplicity");
+  hist1 = mult->GetMultiplicityINEL(1)->ProjectionY();
+  hist1->Sumw2();
+  
+  TFile::Open("LHC08c15_10TeV_0.5T_Phojet/mb1/spd/multiplicity.root");
+  AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
+  mult->LoadHistograms("Multiplicity");
+  hist2 = mult->GetMultiplicityINEL(1)->ProjectionY();
+  hist2->Sumw2();
+  
+  legend = new TLegend(0.6, 0.7, 0.9, 0.9);
+  legend->SetFillColor(0);
+  legend->SetTextSize(0.04);
+  legend->AddEntry(hist1, "Pythia", "L");
+  legend->AddEntry(hist2, "Phojet", "L");
+
+  c1 = new TCanvas("c", "c", 600, 600);
+  c1->SetTopMargin(0.05);
+  c1->SetRightMargin(0.05);
+  c1->SetLeftMargin(0.12);
+  c1->SetGridx();
+  c1->SetGridy(); 
+  c1->SetLogy();
+  
+  //hist1->SetMarkerStyle(20);
+  //hist2->SetMarkerStyle(24);
+  //hist2->SetMarkerColor(2);
+  hist1->SetLineWidth(2);
+  hist2->SetLineWidth(2);
+  hist2->SetLineStyle(2);
+  hist2->SetLineColor(2);
+  
+  hist1->Scale(1.0 / hist1->Integral());
+  hist2->Scale(1.0 / hist2->Integral());
+  
+  hist1->SetStats(0);
+  hist1->GetYaxis()->SetTitleOffset(1.3);
+  hist1->GetXaxis()->SetRangeUser(0, 100);
+  hist1->SetTitle(";N_{ch};P(N_{ch})");
+  
+  hist1->Draw("");
+  hist2->Draw("SAME");
+  legend->Draw();
+  
+  c1->SaveAs("mult_pythia_phojet.eps");
+}
+
 TCanvas* DrawResultRatio(TH1* mcHist, TH1* result, TString epsName)
 {
   // normalize unfolded result to mc hist
-  result->Scale(1.0 / result->Integral(2, 200));
-  result->Scale(mcHist->Integral(2, 200));
+  result->Scale(1.0 / result->Integral(2, displayRange));
+  result->Scale(mcHist->Integral(2, displayRange));
 
   TCanvas* canvas = new TCanvas(epsName, epsName, 800, 600);
   canvas->Range(0, 0, 1, 1);
@@ -122,6 +210,8 @@ TCanvas* DrawResultRatio(TH1* mcHist, TH1* result, TString epsName)
   pad2->SetTopMargin(0);
 
   pad1->cd();
+  pad1->SetGridx();
+  pad1->SetGridy();
 
   mcHist->GetXaxis()->SetLabelSize(0.06);
   mcHist->GetYaxis()->SetLabelSize(0.06);
@@ -131,18 +221,20 @@ TCanvas* DrawResultRatio(TH1* mcHist, TH1* result, TString epsName)
 
   mcHist->GetXaxis()->SetRangeUser(0, displayRange);
 
-  mcHist->SetTitle(";true multiplicity;Entries");
+  mcHist->SetTitle(Form(";%s;Entries", GetMultLabel()));
   mcHist->SetStats(kFALSE);
 
   mcHist->DrawCopy("HIST E");
   gPad->SetLogy();
 
   result->SetLineColor(2);
-  result->DrawCopy("SAME HISTE");
+  result->SetMarkerColor(2);
+  result->SetMarkerStyle(5);
+  result->DrawCopy("SAME PE");
 
   TLegend* legend = new TLegend(0.6, 0.65, 0.95, 0.9);
-  legend->AddEntry(mcHist, "true distribution");
-  legend->AddEntry(result, "unfolded distribution");
+  legend->AddEntry(mcHist, "True distribution");
+  legend->AddEntry(result, "Unfolded distribution", "P");
   legend->SetFillColor(0);
   legend->Draw();
 
@@ -195,6 +287,127 @@ TCanvas* Draw2ResultRatio(TH1* mcHist, TH1* result1, TH1* result2, TString epsNa
   // draws the ratio between result1 and result2 in the lower plot
 
   // normalize unfolded result to mc hist
+  result1->Scale(1.0 / result1->Integral(2, displayRange));
+  result1->Scale(mcHist->Integral(2, displayRange));
+  result2->Scale(1.0 / result2->Integral(2, displayRange));
+  result2->Scale(mcHist->Integral(2, displayRange));
+
+  TCanvas* canvas = new TCanvas(epsName, epsName, 800, 600);
+  canvas->Range(0, 0, 1, 1);
+
+  TPad* pad1 = new TPad(Form("%s_pad1", epsName.Data()), "", 0, 0.5, 0.98, 0.98);
+  pad1->Draw();
+
+  TPad* pad2 = new TPad(Form("%s_pad2", epsName.Data()), "", 0, 0.02, 0.98, 0.5);
+  pad2->Draw();
+
+  pad1->SetRightMargin(0.05);
+  pad2->SetRightMargin(0.05);
+
+  // no border between them
+  pad1->SetBottomMargin(0);
+  pad2->SetTopMargin(0);
+
+  pad1->cd();
+  gPad->SetGridx();
+  gPad->SetGridy();
+
+  mcHist->GetXaxis()->SetLabelSize(0.06);
+  mcHist->GetYaxis()->SetLabelSize(0.06);
+  mcHist->GetXaxis()->SetTitleSize(0.06);
+  mcHist->GetYaxis()->SetTitleSize(0.06);
+  mcHist->GetYaxis()->SetTitleOffset(0.6);
+
+  mcHist->GetXaxis()->SetRangeUser(0, displayRange);
+
+  mcHist->SetTitle(";true multiplicity;Entries");
+  mcHist->SetStats(kFALSE);
+
+  mcHist->DrawCopy("HIST E");
+  gPad->SetLogy();
+
+  result1->SetLineColor(2);
+  result1->SetMarkerStyle(24);
+  result1->DrawCopy("SAME HISTE");
+
+  result2->SetLineColor(4);
+  result2->SetMarkerColor(4);
+  result2->DrawCopy("SAME HISTE");
+
+  TLegend* legend = new TLegend(0.5, 0.6, 0.95, 0.9);
+  legend->AddEntry(mcHist, "True distribution");
+  legend->AddEntry(result1, "Unfolded distribution (syst)", "P");
+  legend->AddEntry(result2, "Unfolded distribution (normal)", "P");
+  legend->SetFillColor(0);
+  legend->SetTextSize(0.06);
+  legend->Draw();
+
+  pad2->cd();
+  pad2->SetBottomMargin(0.15);
+  //gPad->SetGridx();
+  //gPad->SetGridy();
+
+  result1->GetXaxis()->SetLabelSize(0.06);
+  result1->GetYaxis()->SetLabelSize(0.06);
+  result1->GetXaxis()->SetTitleSize(0.06);
+  result1->GetYaxis()->SetTitleSize(0.06);
+  result1->GetYaxis()->SetTitleOffset(0.6);
+
+  result1->GetXaxis()->SetRangeUser(0, displayRange);
+
+  result1->SetTitle(Form(";%s;Entries", GetMultLabel()));
+  result1->SetStats(kFALSE);
+
+  // calculate ratio
+  result1->Sumw2();
+  TH1* ratio = (TH1*) result1->Clone("ratio");
+  result2->Sumw2();
+  ratio->Divide(ratio, result2, 1, 1, "");
+  ratio->SetLineColor(1);
+  ratio->SetMarkerColor(1);
+  ratio->SetMarkerStyle(0);
+  ratio->GetYaxis()->SetTitle("Ratio (syst / normal)");
+  ratio->GetYaxis()->SetRangeUser(0.55, 1.45);
+
+  ratio->DrawCopy();
+
+  // get average of ratio
+  Float_t sum = 0;
+  for (Int_t i=2; i<=ratioRange; ++i)
+  {
+    sum += TMath::Abs(ratio->GetBinContent(i) - 1);
+  }
+  sum /= ratioRange-1;
+
+  printf("Average (2..%d) of |ratio - 1| is %f\n", ratioRange, sum);
+
+  TLine* line = new TLine(0, 1, displayRange, 1);
+  line->SetLineWidth(2);
+  line->Draw();
+
+  line = new TLine(0, 1.1, displayRange, 1.1);
+  line->SetLineWidth(2);
+  line->SetLineStyle(2);
+  line->Draw();
+  line = new TLine(0, 0.9, displayRange, 0.9);
+  line->SetLineWidth(2);
+  line->SetLineStyle(2);
+  line->Draw();
+
+  canvas->Modified();
+
+  canvas->SaveAs(epsName);
+
+  return canvas;
+}
+
+TCanvas* Draw2ResultRatios(TH1* mcHist, TH1* result1, TH1* result2, TH1* ratio2, TH1* ratio3, TString epsName)
+{
+  // draws the 3 plots in the upper plot
+  // draws the ratio between result1 and result2 in the lower plot
+  // also draws ratio2 and ratio3 in the lower plot, uses their name for the legend
+
+  // normalize unfolded result to mc hist
   result1->Scale(1.0 / result1->Integral(2, 200));
   result1->Scale(mcHist->Integral(2, 200));
   result2->Scale(1.0 / result2->Integral(2, 200));
@@ -217,6 +430,8 @@ TCanvas* Draw2ResultRatio(TH1* mcHist, TH1* result1, TH1* result2, TString epsNa
   pad2->SetTopMargin(0);
 
   pad1->cd();
+  gPad->SetGridx();
+  gPad->SetGridy();
 
   mcHist->GetXaxis()->SetLabelSize(0.06);
   mcHist->GetYaxis()->SetLabelSize(0.06);
@@ -226,27 +441,34 @@ TCanvas* Draw2ResultRatio(TH1* mcHist, TH1* result1, TH1* result2, TString epsNa
 
   mcHist->GetXaxis()->SetRangeUser(0, displayRange);
 
-  mcHist->SetTitle(";true multiplicity;Entries");
+  mcHist->SetTitle(";True multiplicity;Entries");
   mcHist->SetStats(kFALSE);
 
   mcHist->DrawCopy("HIST E");
   gPad->SetLogy();
 
   result1->SetLineColor(2);
+  result1->SetMarkerColor(2);
+  result1->SetMarkerStyle(24);
   result1->DrawCopy("SAME HISTE");
 
   result2->SetLineColor(4);
+  result2->SetMarkerColor(4);
+  result2->SetMarkerStyle(5);
   result2->DrawCopy("SAME HISTE");
 
   TLegend* legend = new TLegend(0.55, 0.6, 0.95, 0.9);
-  legend->AddEntry(mcHist, "true distribution");
-  legend->AddEntry(result1, "unfolded distribution (syst)");
-  legend->AddEntry(result2, "unfolded distribution (normal)");
+  legend->AddEntry(mcHist, "True distribution");
+  legend->AddEntry(result1, "Unfolded distribution (5%)", "P");
+  legend->AddEntry(result2, "Unfolded distribution (normal)", "P");
   legend->SetFillColor(0);
+  legend->SetTextSize(0.06);
   legend->Draw();
 
   pad2->cd();
   pad2->SetBottomMargin(0.15);
+  //gPad->SetGridx();
+  //gPad->SetGridy();
 
   result1->GetXaxis()->SetLabelSize(0.06);
   result1->GetYaxis()->SetLabelSize(0.06);
@@ -256,7 +478,7 @@ TCanvas* Draw2ResultRatio(TH1* mcHist, TH1* result1, TH1* result2, TString epsNa
 
   result1->GetXaxis()->SetRangeUser(0, displayRange);
 
-  result1->SetTitle(";true multiplicity;Entries");
+  result1->SetTitle(Form(";%s;Entries", GetMultLabel()));
   result1->SetStats(kFALSE);
 
   // calculate ratio
@@ -264,10 +486,32 @@ TCanvas* Draw2ResultRatio(TH1* mcHist, TH1* result1, TH1* result2, TString epsNa
   TH1* ratio = (TH1*) result1->Clone("ratio");
   result2->Sumw2();
   ratio->Divide(ratio, result2, 1, 1, "");
-  ratio->GetYaxis()->SetTitle("Ratio (syst / normal)");
+  ratio->SetLineColor(1);
+  ratio->SetMarkerColor(1);
+  ratio->SetMarkerStyle(24);
+  ratio->GetYaxis()->SetTitle("Ratio (change / normal)");
   ratio->GetYaxis()->SetRangeUser(0.55, 1.45);
 
+  ratio2->SetLineColor(2);
+  ratio2->SetMarkerColor(2);
+  ratio2->SetMarkerStyle(25);
+
+  ratio3->SetLineColor(4);
+  ratio3->SetMarkerColor(4);
+  ratio3->SetMarkerStyle(26);
+  
   ratio->DrawCopy();
+  ratio2->DrawCopy("SAME");
+  ratio3->DrawCopy("SAME");
+  
+  legend2 = new TLegend(0.3, 0.8, 0.8, 0.95);
+  legend2->SetNColumns(3);
+  legend2->SetFillColor(0);
+  legend2->SetTextSize(0.06);
+  legend2->AddEntry(ratio, "5% change", "P");
+  legend2->AddEntry(ratio2, "2% change", "P");
+  legend2->AddEntry(ratio3, "1% change", "P");
+  legend2->Draw();
 
   // get average of ratio
   Float_t sum = 0;
@@ -307,9 +551,11 @@ TCanvas* DrawRatio(TH1* result, Int_t nResultSyst, TH1** resultSyst, TString eps
   // normalize results
   result->Scale(1.0 / result->Integral(2, 200));
 
-  TCanvas* canvas = new TCanvas(epsName, epsName, 800, 400);
+  TCanvas* canvas = new TCanvas(epsName, epsName, 800, 500);
   canvas->SetTopMargin(0.05);
   canvas->SetRightMargin(0.05);
+  canvas->SetGridx();
+  canvas->SetGridy();
 
   result->GetXaxis()->SetRangeUser(0, displayRange);
   result->GetYaxis()->SetRangeUser(0.55, 1.45);
@@ -318,14 +564,17 @@ TCanvas* DrawRatio(TH1* result, Int_t nResultSyst, TH1** resultSyst, TString eps
   // to get the axis how we want it
   TH1* dummy = (TH1*) result->Clone("dummy");
   dummy->Reset();
-  dummy->SetTitle(";true multiplicity;Ratio");
+  dummy->SetTitle(Form(";%s;Ratio", GetMultLabel()));
   dummy->DrawCopy();
   delete dummy;
 
   Int_t colors[] = {1, 2, 4, 6, 7, 8, 9, 10};
 
-  TLegend* legend = new TLegend(0.2, 0.75, 0.35, 0.95);
+  TLegend* legend = new TLegend(0.2, 0.7, 0.7, 0.93);
   legend->SetFillColor(0);
+  legend->SetTextSize(0.04);
+  if (nResultSyst > 6)
+    legend->SetNColumns(2);
 
   for (Int_t n=0; n<nResultSyst; ++n)
   {
@@ -334,7 +583,7 @@ TCanvas* DrawRatio(TH1* result, Int_t nResultSyst, TH1** resultSyst, TString eps
     // calculate ratio
     TH1* ratio = (TH1*) result->Clone("ratio");
     ratio->Divide(ratio, resultSyst[n], 1, 1, "");
-    ratio->GetXaxis()->SetRangeUser(1, displayRange);
+    ratio->GetXaxis()->SetRangeUser(0, displayRange);
 
     if (firstMarker)
       ratio->SetMarkerStyle(5);
@@ -352,7 +601,7 @@ TCanvas* DrawRatio(TH1* result, Int_t nResultSyst, TH1** resultSyst, TString eps
     ratio->DrawCopy(drawStr);
 
     if (legendStrings && legendStrings[n])
-      legend->AddEntry(ratio, legendStrings[n]);
+      legend->AddEntry(ratio, legendStrings[n], "L");
 
     // get average of ratio
     Float_t sum = 0;
@@ -366,15 +615,15 @@ TCanvas* DrawRatio(TH1* result, Int_t nResultSyst, TH1** resultSyst, TString eps
   if (legendStrings)
     legend->Draw();
 
-  TLine* line = new TLine(0, 1, displayRange, 1);
+  TLine* line = new TLine(-0.5, 1, displayRange, 1);
   line->SetLineWidth(2);
   line->Draw();
 
-  line = new TLine(0, 1.1, displayRange, 1.1);
+  line = new TLine(-0.5, 1.1, displayRange, 1.1);
   line->SetLineWidth(2);
   line->SetLineStyle(2);
   line->Draw();
-  line = new TLine(0, 0.9, displayRange, 0.9);
+  line = new TLine(-0.5, 0.9, displayRange, 0.9);
   line->SetLineWidth(2);
   line->SetLineStyle(2);
   line->Draw();
@@ -598,21 +847,30 @@ TCanvas* DrawRatioDeductSmooth(TH1* mcBase, TH1* resultBase, Int_t nResultSyst,
   return canvas;
 }
 
-void DrawResiduals(TH1* measured, TH1* unfoldedFolded, const char* epsName)
+void DrawResiduals(const char* fileName, const char* epsName)
 {
+  loadlibs();
+
+  AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
+  TFile::Open(fileName);
+  mult->LoadHistograms("Multiplicity");
+
+  TH1* measured = mult->GetMultiplicityESD(etaRange)->ProjectionY("myesd", 1, 1);
+  TH1* unfoldedFolded = mult->CalculateMultiplicityESD(mult->GetMultiplicityESDCorrected(etaRange), etaRange)->ProjectionY("myfolded", 1, 1);
+  
   // normalize
-  unfoldedFolded->Scale(1.0 / unfoldedFolded->Integral(2, 200));
-  unfoldedFolded->Scale(measured->Integral(2, 200));
+  unfoldedFolded->Scale(1.0 / unfoldedFolded->Integral(2, displayRange+1));
+  unfoldedFolded->Scale(measured->Integral(2, displayRange+1));
 
   TCanvas* canvas = new TCanvas(epsName, epsName, 800, 600);
   canvas->Range(0, 0, 1, 1);
 
-  TPad* pad1 = new TPad(Form("%s_pad1", epsName), "", 0, 0.5, 0.98, 0.98);
+  TPad* pad1 = new TPad(Form("%s_pad1", epsName), "", 0, 0.5, 1, 1);
   pad1->Draw();
   pad1->SetGridx();
   pad1->SetGridy();
 
-  TPad* pad2 = new TPad(Form("%s_pad2", epsName), "", 0, 0.02, 0.98, 0.5);
+  TPad* pad2 = new TPad(Form("%s_pad2", epsName), "", 0, 0.02, 1, 0.5);
   pad2->Draw();
   pad2->SetGridx();
   pad2->SetGridy();
@@ -639,9 +897,9 @@ void DrawResiduals(TH1* measured, TH1* unfoldedFolded, const char* epsName)
   measured->GetYaxis()->SetTitleSize(0.06);
   measured->GetYaxis()->SetTitleOffset(0.6);
 
-  measured->GetXaxis()->SetRangeUser(0, 150);
+  measured->GetXaxis()->SetRangeUser(0, displayRange);
 
-  measured->SetTitle(";measured multiplicity;Entries");
+  measured->SetTitle(Form(";%s;Entries", GetMultLabel(etaRange, kFALSE)));
   measured->SetStats(kFALSE);
 
   measured->DrawCopy("HIST");
@@ -649,13 +907,14 @@ void DrawResiduals(TH1* measured, TH1* unfoldedFolded, const char* epsName)
 
   unfoldedFolded->SetMarkerStyle(5);
   unfoldedFolded->SetMarkerColor(2);
-  unfoldedFolded->SetLineColor(0);
-  unfoldedFolded->DrawCopy("SAME P");
+  unfoldedFolded->SetLineColor(2);
+  unfoldedFolded->DrawCopy("SAME PHIST");
 
   TLegend* legend = new TLegend(0.6, 0.65, 0.95, 0.9);
-  legend->AddEntry(measured, "measured distribution");
-  legend->AddEntry(unfoldedFolded, "R #otimes unfolded distribution");
+  legend->AddEntry(measured, "Measured distribution", "L");
+  legend->AddEntry(unfoldedFolded, "R #otimes unfolded distribution", "P");
   legend->SetFillColor(0);
+  legend->SetTextSize(0.06);
   legend->Draw();
 
   pad2->cd();
@@ -669,9 +928,9 @@ void DrawResiduals(TH1* measured, TH1* unfoldedFolded, const char* epsName)
   residual->Add(unfoldedFolded, -1);
 
   // projection
-  TH1* residualHist = new TH1F("residualHist", ";", 15, -3, 3);
+  TH1* residualHist = new TH1F("residualHist", ";", 11, -3, 3);
 
-  for (Int_t i=1; i<=residual->GetNbinsX(); ++i)
+  for (Int_t i=1; i<=displayRange+1; ++i)
   {
     if (measured->GetBinError(i) > 0)
     {
@@ -687,17 +946,17 @@ void DrawResiduals(TH1* measured, TH1* unfoldedFolded, const char* epsName)
     }
   }
 
-  residual->GetYaxis()->SetTitle("Residuals   1/e (M - R #otimes U)");
+  residual->GetYaxis()->SetTitle("Residuals:   (1/e) (M - R  #otimes U)");
   residual->GetYaxis()->SetRangeUser(-4.5, 4.5);
   residual->DrawCopy();
 
-  TLine* line = new TLine(-0.5, 0, 150.5, 0);
+  TLine* line = new TLine(-0.5, 0, displayRange + 0.5, 0);
   line->SetLineWidth(2);
   line->Draw();
 
   pad3->cd();
   residualHist->SetStats(kFALSE);
-  residualHist->GetXaxis()->SetLabelSize(0.08);
+  residualHist->SetLabelSize(0.08, "xy");
   residualHist->Fit("gaus");
   residualHist->Draw();
 
@@ -712,224 +971,108 @@ void DrawResiduals(TH1* measured, TH1* unfoldedFolded, const char* epsName)
   //canvas->SaveAs(canvas->GetName());
 }
 
-void bayesianExample()
-{
-  TStopwatch watch;
-  watch.Start();
-
-  gSystem->Load("libPWG0base");
-
-  TFile::Open(correctionFile);
-  AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
-  mult->LoadHistograms("Multiplicity");
-
-  TFile::Open(measuredFile);
-  AliMultiplicityCorrection* mult2 = new AliMultiplicityCorrection("Multiplicity2", "Multiplicity2");
-  mult2->LoadHistograms("Multiplicity");
-
-  mult->SetMultiplicityESD(etaRange, mult2->GetMultiplicityESD(etaRange));
-
-  mult->ApplyBayesianMethod(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx, 1, 100);
-
-  TH1* mcHist = mult2->GetMultiplicityVtx(etaRange)->ProjectionY("mymc");
-  TH1* result = mult->GetMultiplicityESDCorrected(etaRange);
-
-  //mult->DrawComparison("bayesianExample", etaRange, kFALSE, kTRUE, mcHist, kTRUE);
-  DrawResultRatio(mcHist, result, "bayesianExample.eps");
-
-  //Printf("KolmogorovTest says PROB = %f", mcHist->KolmogorovTest(result, "D"));
-  //Printf("Chi2Test says PROB = %f", mcHist->Chi2Test(result));
-
-  // draw residual plot
-
-  // TODO take out efficiency correction if other than AliMultiplicityCorrection::kTrVtx
-  TH2* convoluted = mult->CalculateMultiplicityESD(result, etaRange);
-  TH1* convolutedProj = convoluted->ProjectionY("convolutedProj", -1, -1, "e");
-
-  TH1* measured = mult2->GetMultiplicityESD(etaRange)->ProjectionY("measured");
-
-  DrawResiduals(measured, convolutedProj, "bayesianResiduals.eps");
-
-  watch.Stop();
-  watch.Print();
-}
-
 void chi2FluctuationResult()
 {
-  gSystem->Load("libPWG0base");
+  loadlibs();
 
-  TFile::Open(correctionFile);
+  TFile::Open("chi2_noregularization.root");
   AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
   mult->LoadHistograms("Multiplicity");
 
-  TFile::Open(measuredFile);
-  AliMultiplicityCorrection* mult2 = new AliMultiplicityCorrection("Multiplicity2", "Multiplicity2");
-  mult2->LoadHistograms("Multiplicity");
-
-  mult->SetMultiplicityESD(etaRange, mult2->GetMultiplicityESD(etaRange));
-  mult->SetRegularizationParameters(AliMultiplicityCorrection::kNone, 0);
-  mult->ApplyMinuitFit(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx);
-
-  TH1* mcHist = mult2->GetMultiplicityVtx(etaRange)->ProjectionY("mymc");
-  //TH1* result = mult->GetMultiplicityESDCorrected(etaRange);
+  TH1* mcHist = mult->GetMultiplicityVtx(etaRange)->ProjectionY("mymc", 1, 1);
 
   mult->DrawComparison("MinuitChi2", etaRange, kFALSE, kTRUE, mcHist, kTRUE);
 
-  TCanvas* canvas = (TCanvas*) gROOT->FindObject("MinuitChi2_DrawComparison_3");
+  TCanvas* canvas = (TCanvas*) gROOT->FindObject("MinuitChi2_DrawComparison_1");
+  ((TH1*) canvas->FindObject("proj"))->GetXaxis()->SetRangeUser(0, displayRange);
+  ((TH1*) canvas->FindObject("fCurrentESD"))->GetXaxis()->SetRangeUser(0, displayRange);
+  //((TH1*) canvas->FindObject("proj"))->GetXaxis()->SetTitle(GetMultTitle());
+  //((TH1*) canvas->FindObject("fCurrentESD"))->GetXaxis()->->SetTitle(GetMultTitle(etaRange, kFALSE));
   canvas->SaveAs("chi2FluctuationResult.eps");
 }
 
-void chi2Example()
+void DrawUnfolded(const char* fileName, const char* eps)
 {
-  TStopwatch watch;
-  watch.Start();
-
-  gSystem->Load("libPWG0base");
-
-  TFile::Open(correctionFile);
-  AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
-  mult->LoadHistograms("Multiplicity");
-
-  TFile::Open(measuredFile);
-  AliMultiplicityCorrection* mult2 = new AliMultiplicityCorrection("Multiplicity2", "Multiplicity2");
-  mult2->LoadHistograms("Multiplicity");
-
-  mult->SetMultiplicityESD(etaRange, mult2->GetMultiplicityESD(etaRange));
-  mult->SetRegularizationParameters(AliMultiplicityCorrection::kPol1, 10000);
-  mult->ApplyMinuitFit(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx);
-
-  TH1* mcHist = mult2->GetMultiplicityVtx(etaRange)->ProjectionY("mymc");
-  TH1* result = mult->GetMultiplicityESDCorrected(etaRange);
-
-  DrawResultRatio(mcHist, result, "chi2Example.eps");
-
-  watch.Stop();
-  watch.Print();
-}
-
-void chi2ExampleTPC()
-{
-  TStopwatch watch;
-  watch.Start();
-
-  gSystem->Load("libPWG0base");
-
-  TFile::Open(correctionFileTPC);
-  AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
-  mult->LoadHistograms("Multiplicity");
-
-  TFile::Open(measuredFileTPC);
-  AliMultiplicityCorrection* mult2 = new AliMultiplicityCorrection("Multiplicity2", "Multiplicity2");
-  mult2->LoadHistograms("Multiplicity");
-
-  mult->SetMultiplicityESD(etaRangeTPC, mult2->GetMultiplicityESD(etaRangeTPC));
-  mult->SetRegularizationParameters(AliMultiplicityCorrection::kPol1, 10000);
-  mult->ApplyMinuitFit(etaRangeTPC, kFALSE, AliMultiplicityCorrection::kTrVtx);
-
-  TH1* mcHist = mult2->GetMultiplicityVtx(etaRangeTPC)->ProjectionY("mymc");
-  TH1* result = mult->GetMultiplicityESDCorrected(etaRangeTPC);
-
-  DrawResultRatio(mcHist, result, "chi2ExampleTPC.eps");
-
-  watch.Stop();
-  watch.Print();
-}
-
-void bayesianNBD()
-{
-  gSystem->Load("libPWG0base");
-  TFile::Open("multiplicityMC_3M.root");
-
-  AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
-  mult->LoadHistograms("Multiplicity");
-
-  TFile::Open("multiplicityMC_3M_NBD.root");
-  AliMultiplicityCorrection* mult2 = new AliMultiplicityCorrection("Multiplicity2", "Multiplicity2");
-  mult2->LoadHistograms("Multiplicity");
-
-  mult->SetMultiplicityESD(etaRange, mult2->GetMultiplicityESD(etaRange));
-  mult->ApplyBayesianMethod(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx, 1.0, 100);
-
-  TH1* mcHist = mult2->GetMultiplicityVtx(etaRange)->ProjectionY("mymc");
-
-  mcHist->Sumw2();
-  TH1* result = mult->GetMultiplicityESDCorrected(etaRange);
-
-  //mult->DrawComparison("bayesianNBD", etaRange, kFALSE, kTRUE, mcHist);
-  DrawResultRatio(mcHist, result, "bayesianNBD.eps");
-}
-
-void minimizationNBD()
-{
-  gSystem->Load("libPWG0base");
-  TFile::Open("multiplicityMC_3M.root");
+  loadlibs();
+  
+  TFile::Open(fileName);
 
   AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
   mult->LoadHistograms("Multiplicity");
 
-  TFile::Open("multiplicityMC_3M_NBD.root");
-  AliMultiplicityCorrection* mult2 = new AliMultiplicityCorrection("Multiplicity2", "Multiplicity2");
-  mult2->LoadHistograms("Multiplicity");
-
-  mult->SetMultiplicityESD(etaRange, mult2->GetMultiplicityESD(etaRange));
-  mult->SetRegularizationParameters(AliMultiplicityCorrection::kPol1, 10000);
-  mult->ApplyMinuitFit(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx);
-
-  TH1* mcHist = mult2->GetMultiplicityVtx(etaRange)->ProjectionY("mymc");
-
-  mcHist->Sumw2();
+  TH1* mcHist = mult->GetMultiplicityVtx(etaRange)->ProjectionY("mymc", 1, mult->GetMultiplicityVtx(etaRange)->GetNbinsX());
   TH1* result = mult->GetMultiplicityESDCorrected(etaRange);
 
-  //mult->DrawComparison("minimizationNBD", etaRange, kFALSE, kTRUE, mcHist);
-  DrawResultRatio(mcHist, result, "minimizationNBD.eps");
+  DrawResultRatio(mcHist, result, eps);
 }
 
 void minimizationInfluenceAlpha()
 {
-  gSystem->Load("libPWG0base");
+  loadlibs();
 
   TFile::Open(measuredFile);
   AliMultiplicityCorrection* mult2 = new AliMultiplicityCorrection("Multiplicity2", "Multiplicity2");
   mult2->LoadHistograms("Multiplicity");
 
-  TH1* mcHist = mult2->GetMultiplicityVtx(etaRange)->ProjectionY("mymc");
+  TH1* mcHist = mult2->GetMultiplicityVtx(etaRange)->ProjectionY("mymc", 1, mult2->GetMultiplicityVtx(etaRange)->GetNbinsX());
   mcHist->Scale(1.0 / mcHist->Integral());
-  mcHist->GetXaxis()->SetRangeUser(0, 200);
   mcHist->SetStats(kFALSE);
-  mcHist->SetTitle(";true multiplicity;P_{N}");
-
-  TCanvas* canvas = new TCanvas("minimizationInfluenceAlpha", "minimizationInfluenceAlpha", 1000, 300);
-  canvas->Divide(3, 1);
+  mcHist->SetTitle(";True multiplicity n in |#eta| < 1.0;P(n)");
 
-  TFile::Open("eval-2M-1M/EvaluateChi2MethodDetail.root");
+  TCanvas* canvas = new TCanvas("minimizationInfluenceAlpha", "minimizationInfluenceAlpha", 1000, 350);
+  canvas->Divide(3, 1, 0.005);
 
-  TH1* hist1 = (TH1*) gFile->Get("MinuitChi2_00_2_100.000000");
-  TH1* hist2 = (TH1*) gFile->Get("MinuitChi2_03_2_100000.000000");
-  TH1* hist3 = (TH1*) gFile->Get("MinuitChi2_06_2_100000000.000000");
+  TFile::Open("chi2compare-influencealpha/EvaluateChi2Method.root");
+  
+  TH1* hist1 = (TH1*) gFile->Get("MinuitChi2_00_2_3.162278");
+  TH1* hist2 = (TH1*) gFile->Get("MinuitChi2_07_2_10000.000000");
+  TH1* hist3 = (TH1*) gFile->Get("MinuitChi2_13_2_10000000.000000");
 
-  mcHist->Rebin(2);  mcHist->Scale(0.5);
+  /*mcHist->Rebin(2);  mcHist->Scale(0.5);
   hist1->Rebin(2);   hist1->Scale(0.5);
   hist2->Rebin(2);   hist2->Scale(0.5);
-  hist3->Rebin(2);   hist3->Scale(0.5);
-
-  mcHist->GetXaxis()->SetRangeUser(0, 200);
+  hist3->Rebin(2);   hist3->Scale(0.5);*/
 
+  mcHist->GetXaxis()->SetRangeUser(0, displayRange);
+  mcHist->SetLabelSize(0.06, "xy");
+  mcHist->SetTitleSize(0.06, "xy");
+  mcHist->GetYaxis()->SetTitleOffset(1.5);
+  
   canvas->cd(1);
+  
   gPad->SetLogy();
+  gPad->SetRightMargin(0.03);
+  gPad->SetLeftMargin(0.19);
+  gPad->SetTopMargin(0.05);
+  gPad->SetBottomMargin(0.13);
+  gPad->SetGridx();
+  gPad->SetGridy();
   mcHist->Draw();
   hist1->SetMarkerStyle(5);
   hist1->SetMarkerColor(2);
   hist1->Draw("SAME PE");
 
   canvas->cd(2);
+  gPad->SetRightMargin(0.03);
+  gPad->SetLeftMargin(0.19);
+  gPad->SetTopMargin(0.05);
+  gPad->SetBottomMargin(0.13);
   gPad->SetLogy();
+  gPad->SetGridx();
+  gPad->SetGridy();
   mcHist->Draw();
   hist2->SetMarkerStyle(5);
   hist2->SetMarkerColor(2);
   hist2->Draw("SAME PE");
 
   canvas->cd(3);
+  gPad->SetRightMargin(0.03);
+  gPad->SetLeftMargin(0.19);
+  gPad->SetTopMargin(0.05);
+  gPad->SetBottomMargin(0.13);
   gPad->SetLogy();
+  gPad->SetGridx();
+  gPad->SetGridy();
   mcHist->Draw();
   hist3->SetMarkerStyle(5);
   hist3->SetMarkerColor(2);
@@ -984,50 +1127,6 @@ void NBDFit()
   canvas->SaveAs("NBDFit.eps");
 }
 
-void DifferentSamples()
-{
-  // data generated by runMultiplicitySelector.C DifferentSamples
-
-  const char* name = "DifferentSamples";
-
-  TFile* file = TFile::Open(Form("%s.root", name));
-
-  TCanvas* canvas = new TCanvas(name, name, 800, 600);
-  canvas->Divide(2, 2);
-
-  for (Int_t i=0; i<4; ++i)
-  {
-    canvas->cd(i+1);
-    gPad->SetTopMargin(0.05);
-    gPad->SetRightMargin(0.05);
-    TH1* chi2Result = (TH1*) file->Get(Form("chi2Result_%d", i));
-    TH1* bayesResult = (TH1*) file->Get(Form("bayesResult_%d", i));
-    TH1* mc = (TH1*) file->Get(Form("mc_%d", i));
-    mc->Sumw2();
-
-    chi2Result->Divide(chi2Result, mc, 1, 1, "");
-    bayesResult->Divide(bayesResult, mc, 1, 1, "");
-
-    chi2Result->SetTitle(";true multiplicity;unfolded measured/MC");
-    chi2Result->GetXaxis()->SetRangeUser(0, 150);
-    chi2Result->GetYaxis()->SetRangeUser(0.5, 1.5);
-    chi2Result->GetYaxis()->SetTitleOffset(1.2);
-    chi2Result->SetLineColor(1);
-    chi2Result->SetStats(kFALSE);
-
-    bayesResult->SetStats(kFALSE);
-    bayesResult->SetLineColor(2);
-
-    chi2Result->DrawCopy("HIST");
-    bayesResult->DrawCopy("SAME HIST");
-
-    TLine* line = new TLine(0, 1, 150, 1);
-    line->Draw();
-  }
-
-  canvas->SaveAs(Form("%s.eps", canvas->GetName()));
-}
-
 void StartingConditions()
 {
   // data generated by runMultiplicitySelector.C StartingConditions
@@ -1036,18 +1135,19 @@ void StartingConditions()
 
   TFile* file = TFile::Open(Form("%s.root", name));
 
-  TCanvas* canvas = new TCanvas(name, name, 800, 400);
+  TCanvas* canvas = new TCanvas(name, name, 1200, 600);
   canvas->Divide(2, 1);
 
   TH1* mc = (TH1*) file->Get("mc");
   mc->Sumw2();
-  mc->Scale(1.0 / mc->Integral());
+  mc->Scale(1.0 / mc->Integral(2, displayRange));
 
   //Int_t marker[] = {24, 25, 26, 27, 28, 2, 3, 4, 5};
 
-  TLegend* legend = new TLegend(0.6, 0.7, 0.95, 0.95);
+  TLegend* legend = new TLegend(0.6, 0.7, 0.99, 0.99);
   legend->SetFillColor(0);
-
+  legend->SetTextSize(0.04);
+  
   const char* names[] = { "True", "Measured 1", "Measured 2", "Measured 3", "NBD", "Flat" };
 
   for (Int_t i=0; i<6; ++i)
@@ -1058,33 +1158,42 @@ void StartingConditions()
 
     TH1* chi2Result = (TH1*) file->Get(Form("chi2Result_%d", id));
     TH1* bayesResult = (TH1*) file->Get(Form("bayesResult_%d", id));
+    
+    chi2Result->Scale(1.0 / chi2Result->Integral(2, displayRange));
+    bayesResult->Scale(1.0 / bayesResult->Integral(2, displayRange));
 
-    chi2Result->Divide(chi2Result, mc, 1, 1, "");
-    bayesResult->Divide(bayesResult, mc, 1, 1, "");
+    chi2Result->Divide(mc, chi2Result, 1, 1, "");
+    bayesResult->Divide(mc, bayesResult, 1, 1, "");
 
-    chi2Result->SetTitle("a) #chi^{2} minimization;true multiplicity;unfolded / MC");
-    chi2Result->GetXaxis()->SetRangeUser(0, 150);
-    chi2Result->GetYaxis()->SetRangeUser(0.8, 1.2);
-    chi2Result->GetYaxis()->SetTitleOffset(1.5);
+    chi2Result->SetTitle(Form("a) #chi^{2}-minimization;%s;MC / unfolded", GetMultLabel()));
+    chi2Result->GetXaxis()->SetRangeUser(0, displayRange);
+    chi2Result->GetYaxis()->SetRangeUser(0.7, 1.3);
+    chi2Result->GetYaxis()->SetTitleOffset(1.7);
     //chi2Result->SetMarkerStyle(marker[i]);
     chi2Result->SetLineColor(i+1);
     chi2Result->SetMarkerColor(i+1);
     chi2Result->SetStats(kFALSE);
 
-    bayesResult->SetTitle("b) Bayesian method;true multiplicity;unfolded / MC");
-    bayesResult->GetXaxis()->SetRangeUser(0, 150);
-    bayesResult->GetYaxis()->SetRangeUser(0.8, 1.2);
-    bayesResult->GetYaxis()->SetTitleOffset(1.5);
+    bayesResult->SetTitle(Form("b) Bayesian unfolding;%s;MC / unfolded", GetMultLabel()));
+    bayesResult->GetXaxis()->SetRangeUser(0, displayRange);
+    bayesResult->GetYaxis()->SetRangeUser(0.7, 1.3);
+    bayesResult->GetYaxis()->SetTitleOffset(1.7);
     bayesResult->SetStats(kFALSE);
     //bayesResult->SetLineColor(2);
     bayesResult->SetLineColor(i+1);
 
     canvas->cd(1);
+    gPad->SetRightMargin(0.05);
     gPad->SetLeftMargin(0.12);
+    gPad->SetGridx();
+    gPad->SetGridy();
     chi2Result->DrawCopy((i == 0) ? "HIST" : "HIST SAME");
 
     canvas->cd(2);
+    gPad->SetRightMargin(0.05);
     gPad->SetLeftMargin(0.12);
+    gPad->SetGridx();
+    gPad->SetGridy();
     bayesResult->DrawCopy((i == 0) ? "HIST" : "HIST SAME");
 
     //TLine* line = new TLine(0, 1, 150, 1);
@@ -1095,6 +1204,8 @@ void StartingConditions()
 
   canvas->cd(1);
   legend->Draw();
+  canvas->cd(2);
+  legend->Draw();
   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
 }
 
@@ -1134,40 +1245,94 @@ void StatisticsPlot()
   }
 }
 
-void SystematicLowEfficiency()
+void Draw2Unfolded(const char* file1, const char* file2, const char* output)
 {
-  gSystem->Load("libPWG0base");
-
-  TFile::Open(correctionFile);
+  loadlibs();
+  
+  TFile::Open(file1);
   AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
   mult->LoadHistograms("Multiplicity");
 
-  // calculate result with systematic effect
-  TFile::Open("multiplicityMC_100k_1_loweff.root");
+  // result with systematic effect
+  TFile::Open(file2);
   AliMultiplicityCorrection* mult2 = new AliMultiplicityCorrection("Multiplicity2", "Multiplicity2");
   mult2->LoadHistograms("Multiplicity");
 
-  mult->SetMultiplicityESD(etaRange, mult2->GetMultiplicityESD(etaRange));
-  mult->SetRegularizationParameters(AliMultiplicityCorrection::kPol1, 10000);
-  mult->ApplyMinuitFit(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx);
+  TH1* mcHist = mult2->GetMultiplicityVtx(etaRange)->ProjectionY("mymc", 1, 1);
+  TH1* result1 = (TH1*) mult2->GetMultiplicityESDCorrected(etaRange)->Clone("result1"); // from file2 (with syst)
+  TH1* result2 = (TH1*) mult->GetMultiplicityESDCorrected(etaRange)->Clone("result2");  // from file1 (without syst)
 
-  TH1* mcHist = mult2->GetMultiplicityVtx(etaRange)->ProjectionY("mymc");
-  TH1* result1 = (TH1*) mult->GetMultiplicityESDCorrected(etaRange)->Clone("result1");
+  DrawResultRatio(mcHist, result1, "tmp1.eps");
+  DrawResultRatio(mcHist, result2, "tmp2.eps");
+  Draw2ResultRatio(mcHist, result1, result2, output);
+}
 
-  DrawResultRatio(mcHist, result1, "SystematicLowEfficiencyLow.eps");
+void PythiaPhojet()
+{
+  loadlibs();
+  
+  displayRange = 55;
+  Draw2Unfolded("self.root", "pythia.root", "test.eps");
+  
+  canvas = (TCanvas*) gROOT->GetListOfCanvases()->Last();
+  pad1 = (TCanvas*)canvas->GetListOfPrimitives()->First();
+  pad2 = (TCanvas*)canvas->GetListOfPrimitives()->Last();
+  legend = (TLegend*)pad1->GetListOfPrimitives()->Last();
+  
+  ((TH1*)pad2->GetListOfPrimitives()->At(1))->GetYaxis()->SetTitle("Ratio (Pythia / Phojet)");
+  ((TLegendEntry*)legend->GetListOfPrimitives()->At(1))->SetLabel("Unfolded distribution (Pythia)");
+  ((TLegendEntry*)legend->GetListOfPrimitives()->At(2))->SetLabel("Unfolded distribution (Phojet)");
+  canvas->SaveAs("PythiaPhojet.eps");
+}
 
-  // calculate normal result
-  TFile::Open("multiplicityMC_100k_1.root");
-  mult2->LoadHistograms("Multiplicity");
+void Misalignment()
+{
+  loadlibs();
+  
+  Draw2Unfolded("chi2_ideal.root", "chi2_misaligned.root", "test.eps");
+  
+  canvas = (TCanvas*) gROOT->GetListOfCanvases()->Last();
+  pad1 = (TCanvas*)canvas->GetListOfPrimitives()->First();
+  pad2 = (TCanvas*)canvas->GetListOfPrimitives()->Last();
+  legend = (TLegend*)pad1->GetListOfPrimitives()->Last();
+
+  ((TH1*)pad2->GetListOfPrimitives()->At(1))->GetYaxis()->SetTitle("Ratio (misaligned / realigned)");
+  ((TLegendEntry*)legend->GetListOfPrimitives()->At(1))->SetLabel("Unfolded distribution (misaligned)");
+  ((TLegendEntry*)legend->GetListOfPrimitives()->At(2))->SetLabel("Unfolded distribution (realigned)");
+  canvas->SaveAs("SystematicMisalignment.eps");
+}
 
-  mult->SetMultiplicityESD(etaRange, mult2->GetMultiplicityESD(etaRange));
-  mult->ApplyMinuitFit(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx);
+void SystematicLowEfficiency()
+{
+  Draw2Unfolded("chi2.root", "chi2_loweff_5.root", "SystematicLowEfficiency.eps");
+}
 
+void SystematicLowEfficiency2()
+{
+  loadlibs();
+  
+  AliMultiplicityCorrection* mult = AliMultiplicityCorrection::Open("chi2.root");
   TH1* result2 = (TH1*) mult->GetMultiplicityESDCorrected(etaRange)->Clone("result2");
-
-  DrawResultRatio(mcHist, result2, "SystematicLowEfficiencyOK.eps");
-
-  Draw2ResultRatio(mcHist, result1, result2, "SystematicLowEfficiency.eps");
+  TH1* mcHist = mult->GetMultiplicityVtx(etaRange)->ProjectionY("mymc", 1, 1);
+  result2->Scale(1.0 / result2->Integral(2, displayRange));
+  result2->Scale(mcHist->Integral(2, displayRange));
+  
+  mult = AliMultiplicityCorrection::Open("chi2_loweff_5.root");
+  TH1* result1 = (TH1*) mult->GetMultiplicityESDCorrected(etaRange)->Clone("result1");
+  
+  mult = AliMultiplicityCorrection::Open("chi2_loweff_2.root");
+  TH1* ratio2 = (TH1*) mult->GetMultiplicityESDCorrected(etaRange)->Clone("ratio2");
+  ratio2->Scale(1.0 / ratio2->Integral(2, displayRange));
+  ratio2->Scale(mcHist->Integral(2, displayRange));
+  ratio2->Divide(result2);
+  
+  mult = AliMultiplicityCorrection::Open("chi2_loweff_1.root");
+  TH1* ratio3 = (TH1*) mult->GetMultiplicityESDCorrected(etaRange)->Clone("ratio3");
+  ratio3->Scale(1.0 / ratio3->Integral(2, displayRange));
+  ratio3->Scale(mcHist->Integral(2, displayRange));
+  ratio3->Divide(result2);
+  
+  Draw2ResultRatios(mcHist, result1, result2, ratio2, ratio3, "SystematicLowEfficiency2.eps");
 }
 
 void SystematicMisalignment()
@@ -1216,38 +1381,139 @@ void SystematicMisalignmentTPC()
   DrawResultRatio(mcHist, result, "SystematicMisalignmentTPC.eps");
 }
 
-void EfficiencySpecies()
+void LowMomentumEffectSPD()
+{
+  // this function increases/reduces the correction as function of pt between 0 and 0.2 gev by +-50% to 0% and checks the effect on the overall correction factor
+  // only a normal acceptance region is considered to not get a bias by the edges
+  
+  loadlibs();
+  TFile::Open("multiplicity.root");
+  
+    
+  AliCorrection* correction[8];
+  Float_t values[3];
+  
+  for (Int_t loop=0; loop<3; loop++)
+  {
+    Float_t sumGen = 0;
+    Float_t sumMeas = 0;
+    
+    Printf("loop %d", loop);
+    for (Int_t i=0; i<4; ++i)
+    {
+      Printf("correction %d", i);
+  
+      TString name; name.Form("correction_%d", i);
+      correction[i] = new AliCorrection(name, name);
+      correction[i]->LoadHistograms();
+      
+      TH3* gene = correction[i]->GetTrackCorrection()->GetGeneratedHistogram();
+      TH3* meas = correction[i]->GetTrackCorrection()->GetMeasuredHistogram();
+  
+      Float_t vtxRange = 5.9;
+      gene->GetXaxis()->SetRangeUser(-vtxRange, vtxRange);
+      meas->GetXaxis()->SetRangeUser(-vtxRange, vtxRange);
+      
+      Float_t etaRange = 0.99;
+      gene->GetYaxis()->SetRangeUser(-etaRange, etaRange);
+      meas->GetYaxis()->SetRangeUser(-etaRange, etaRange);
+  
+      TH1* genePt = gene->Project3D(Form("z_%d", i));
+      TH1* measPt = meas->Project3D(Form("z_%d", i));
+  
+      if (loop > 0)
+      {
+        for (Int_t x=1; x<=genePt->GetNbinsX(); x++)
+        {
+          Float_t pt = genePt->GetXaxis()->GetBinCenter(x);
+          //Printf("%f", pt);
+          if (pt < 0.2)
+          {
+            Float_t factor = 1;
+            if (loop == 1)
+              factor = 1.5 - pt / 0.2 * 0.5;
+            if (loop == 2)
+              factor = 0.5 + pt / 0.2 * 0.5;
+            //Printf("%f", factor);
+            genePt->SetBinContent(x, genePt->GetBinContent(x) * factor);
+            measPt->SetBinContent(x, measPt->GetBinContent(x) * factor);
+          }
+        }
+      }
+      
+      //new TCanvas; genePt->DrawCopy(); measPt->DrawCopy("SAME");
+  
+      sumGen += genePt->Integral();
+      sumMeas += measPt->Integral();  
+      
+      Float_t average = measPt->Integral() / genePt->Integral();
+      
+      Printf("The average efficiency of this correction is %f", average);
+    }
+    
+    Float_t average = sumMeas / sumGen;
+      
+    Printf("The average efficiency of all corrections is %f", average);
+    values[loop] = average;
+  }
+  
+  Printf("relative is %f and %f", values[1] / values[0], values[2] / values[0]);
+}
+  
+
+void EfficiencySpecies(Bool_t addDecayStopped = kFALSE)
 {
   loadlibs();
 
-  Int_t marker[] = {24, 25, 26};
-  Int_t color[] = {1, 2, 4};
+  Int_t marker[] = {24, 25, 26, 27};
+  Int_t color[] = {1, 2, 4, 3};
 
   // SPD TPC
   //const char* fileName[] = { "multiplicityMC_400k_syst.root", "multiplicityMC_TPC_4kfiles_syst.root" };
-  const char* fileName[] = { "spd/multiplicity.root", "tpc/multiplicity.root" };
-  Float_t etaRange[] = {0.49, 0.9};
+  //const char* fileName[] = { "spd/multiplicity.root", "tpc/multiplicity.root" };
+  const char* fileName[] = { "multiplicity.root", "multiplicity.root" };
+  Float_t etaRangeArr[] = {0.49, 0.9};
   const char* titles[] = { "SPD Tracklets", "TPC Tracks" };
 
   TCanvas* canvas = new TCanvas("EfficiencySpecies", "EfficiencySpecies", 1000, 500);
   canvas->Divide(2, 1);
 
-  for (Int_t loop=0; loop<2; ++loop)
+  TCanvas* canvas3 = new TCanvas("EfficiencySpecies_comb", "EfficiencySpecies_comb", 600, 600);
+  gPad->SetGridx();
+  gPad->SetGridy();
+  gPad->SetRightMargin(0.05);
+  gPad->SetTopMargin(0.05);
+  
+  TLegend* legends[2];
+  
+  for (Int_t loop=1; loop<2; ++loop)
   {
     Printf("%s", fileName[loop]);
 
-    AliCorrection* correction[4];
+    TCanvas* canvas2 = new TCanvas(Form("EfficiencySpecies_%d", loop), Form("EfficiencySpecies_%d", loop), 600, 600);
+    gPad->SetGridx();
+    gPad->SetGridy();
+    gPad->SetRightMargin(0.05);
+    gPad->SetTopMargin(0.05);
+    
+    AliCorrection* correction[8];
 
     canvas->cd(loop+1);
 
     gPad->SetGridx();
     gPad->SetGridy();
     gPad->SetRightMargin(0.05);
-    //gPad->SetTopMargin(0.05);
 
-    TLegend* legend = new TLegend(0.7, 0.4, 0.85, 0.6);
+    TLegend* legend = new TLegend(0.6, 0.4, 0.85, 0.6);
     legend->SetFillColor(0);
     legend->SetEntrySeparation(0.2);
+    legend->SetTextSize(gStyle->GetTextSize());
+    
+    legends[loop] = new TLegend(0.4+loop*0.3, 0.2, 0.6+loop*0.3, 0.5);
+    legends[loop]->SetFillColor(0);
+    legends[loop]->SetEntrySeparation(0.2);
+    legends[loop]->SetTextSize(gStyle->GetTextSize());
+    legends[loop]->SetHeader((loop == 0) ? "SPD" : "TPC");
 
     Float_t below = 0;
     Float_t total = 0;
@@ -1269,13 +1535,14 @@ void EfficiencySpecies()
       TString name; name.Form("correction_%d", i);
       correction[i] = new AliCorrection(name, name);
       correction[i]->LoadHistograms();
-
+      
       TH3* gene = correction[i]->GetTrackCorrection()->GetGeneratedHistogram();
       TH3* meas = correction[i]->GetTrackCorrection()->GetMeasuredHistogram();
 
       // limit vtx axis
-      gene->GetXaxis()->SetRangeUser(-3.9, 3.9);
-      meas->GetXaxis()->SetRangeUser(-3.9, 3.9);
+      Float_t vtxRange = 3.9;
+      gene->GetXaxis()->SetRangeUser(-vtxRange, vtxRange);
+      meas->GetXaxis()->SetRangeUser(-vtxRange, vtxRange);
 
       // empty over/underflow bin in eta, setting range to +-2 is not enough because this is the maximum range, Project3D takes them into account then (might be a bug)
       /*for (Int_t x = 1; x <= gene->GetNbinsX(); x++)
@@ -1288,15 +1555,25 @@ void EfficiencySpecies()
         }*/
 
       // limit eta axis
-      gene->GetYaxis()->SetRangeUser(-etaRange[loop], etaRange[loop]);
-      meas->GetYaxis()->SetRangeUser(-etaRange[loop], etaRange[loop]);
+      Float_t etaBegin = -etaRangeArr[loop];
+      Float_t etaEnd   = etaRangeArr[loop];
+      //etaBegin = 0.01;
+      //etaEnd = -0.01;
+      gene->GetYaxis()->SetRangeUser(etaBegin, etaEnd);
+      meas->GetYaxis()->SetRangeUser(etaBegin, etaEnd);
 
       TH1* genePt = gene->Project3D(Form("z_%d", i));
       TH1* measPt = meas->Project3D(Form("z_%d", i));
 
       genePt->Sumw2();
       measPt->Sumw2();
-
+      
+      for (Int_t x=0; x<=genePt->GetNbinsX()+1; x++)
+      {
+       genePt->SetBinError(x, TMath::Sqrt(genePt->GetBinContent(x)));
+       measPt->SetBinError(x, TMath::Sqrt(measPt->GetBinContent(x)));
+      }
+      
       sumGen += genePt->Integral();
       sumMeas += measPt->Integral();
 
@@ -1318,83 +1595,151 @@ void EfficiencySpecies()
 
       below += genePt->Integral(1, bin);
       total += genePt->Integral();
-
+      
       effPt->SetLineColor(color[i]);
       effPt->SetMarkerColor(color[i]);
       effPt->SetMarkerStyle(marker[i]);
+      effPt->SetMarkerSize(2);
 
-      effPt->GetXaxis()->SetRangeUser(0.06, 1);
-      effPt->GetYaxis()->SetRangeUser(0, 1);
+      effPt->GetXaxis()->SetRangeUser(0, 1);
+      effPt->GetYaxis()->SetRangeUser(0.001, 1);
 
       effPt->GetXaxis()->SetTitleOffset(1.1);
       effPt->GetYaxis()->SetTitleOffset(1.2);
+      
+      effPt->GetXaxis()->SetTitle("p_{T} (GeV/c)");
 
       effPt->SetStats(kFALSE);
       effPt->SetTitle(titles[loop]);
       effPt->GetYaxis()->SetTitle("Efficiency");
 
+      canvas->cd(loop+1);
       effPt->DrawCopy((i == 0) ? "" : "SAME");
+      canvas2->cd();
+      effPt->SetTitle("");
+      effPt->DrawCopy((i == 0) ? "" : "SAME");
+      
+      canvas3->cd();
+      effPtClone = (TH1*) effPt->Clone("effPtClone");
+      effPtClone->SetMarkerStyle(marker[i]-4*loop);
+      effPtClone->DrawCopy((i == 0 && loop == 0) ? "" : "SAME");
 
-      legend->AddEntry(effPt, ((i == 0) ? "#pi^{#pm}" : ((i == 1) ? "K^{#pm}" : "p,#bar{p}")));
+      legend->AddEntry(effPt, ((i == 0) ? "#pi^{#pm}" : ((i == 1) ? "K^{#pm}" : "p,#bar{p}")), "P");
+      legends[loop]->AddEntry(effPtClone, ((i == 0) ? "#pi^{#pm}" : ((i == 1) ? "K^{#pm}" : "p,#bar{p}")), "P");
+      //legend2->AddEntry(effPt, Form("%s %s", (loop == 0) ? "SPD" : "TPC", ((i == 0) ? "#pi^{#pm}" : ((i == 1) ? "K^{#pm}" : "p,#bar{p}"))), "P");
+
+      if (addDecayStopped)
+      {
+        name.Form("correction_%d", i+4);
+        corr = new AliCorrection(name, name);
+        corr->LoadHistograms();
+        
+        TH3* gene = corr->GetTrackCorrection()->GetGeneratedHistogram();
+        TH3* meas = corr->GetTrackCorrection()->GetMeasuredHistogram();
+        
+        // limit axes
+        gene->GetXaxis()->SetRangeUser(-vtxRange, vtxRange);
+        meas->GetXaxis()->SetRangeUser(-vtxRange, vtxRange);
+        gene->GetYaxis()->SetRangeUser(-etaRangeArr[loop], etaRangeArr[loop]);
+        meas->GetYaxis()->SetRangeUser(-etaRangeArr[loop], etaRangeArr[loop]);
+        
+        TH1* decayed = gene->Project3D(Form("z_%d", i+4));
+        TH1* stopped = meas->Project3D(Form("z_%d", i+4));
+        
+        Printf("%d: %d decayed, %d stopped, out of %d", i, (Int_t) decayed->Integral(), (Int_t) stopped->Integral(), (Int_t) genePt->Integral());
+        
+        decayed->Divide(decayed, genePt, 1, 1, "B");
+        stopped->Divide(stopped, genePt, 1, 1, "B");
+        
+        decayed->SetMarkerStyle(20);
+        stopped->SetMarkerStyle(21);
+        stopped->SetMarkerColor(2);
+        
+        new TCanvas(Form("all_%d_%d", loop, i), Form("all_%d_%d", loop, i), 600, 600);
+        effPt->DrawCopy();
+        decayed->DrawCopy("SAME");
+        stopped->DrawCopy("SAME");
+        
+        decayed->Add(stopped);
+        decayed->Add(effPt);
+        decayed->SetMarkerStyle(22);
+        decayed->SetMarkerColor(4);
+        decayed->DrawCopy("SAME");
+      }
+      
     }
 
     Printf("In total %.4f of the particles are below their effective pt cut off", (Float_t) below / total);
 
     Printf("%f measured, %f generated, effiency: %f", sumGen, sumMeas, sumMeas / sumGen);
 
+    canvas->cd(loop+1);
+    legend->Draw();
+  
+    canvas2->cd();
     legend->Draw();
+    canvas2->SaveAs(Form("%s.eps", canvas2->GetName()));  
   }
 
+  canvas->cd();
   canvas->SaveAs(Form("%s.eps", canvas->GetName()));
+
+  canvas3->cd();
+  legends[0]->Draw();
+  legends[1]->Draw();
+  canvas3->SaveAs(Form("%s.eps", canvas3->GetName()));
 }
 
-void ParticleSpeciesComparison1(Bool_t chi2 = kTRUE, const char* fileNameMC = "multiplicityMC_400k_syst_species.root", const char* fileNameESD = "multiplicityMC_100k_syst.root")
+void DrawpTCutOff()
 {
-  gSystem->Load("libPWG0base");
-
-  TFile::Open(fileNameESD);
-  TH2F* hist = (TH2F*) gFile->Get(Form("Multiplicity/fMultiplicityESD%d", etaRange));
-  TH2F* hist2 = (TH2F*) gFile->Get(Form("Multiplicity/fMultiplicityVtx%d", etaRange));
+/*
+aliroot -b -q $ALICE_ROOT/PWG0/multiplicity/correct.C'("multiplicityMC_pt_ref.root", "Multiplicity", "multiplicityESD.root", kTRUE)'
+mv unfolded.root chi2_ptref.root
+aliroot -b -q $ALICE_ROOT/PWG0/multiplicity/correct.C'("multiplicityMC_pt0.root", "Multiplicity", "multiplicityESD.root", kTRUE)'
+mv unfolded.root chi2_pt0.root
+aliroot -b -q $ALICE_ROOT/PWG0/multiplicity/correct.C'("multiplicityMC_pt1.root", "Multiplicity", "multiplicityESD.root", kTRUE)'
+mv unfolded.root chi2_pt1.root
+aliroot -b -q $ALICE_ROOT/PWG0/multiplicity/correct.C'("multiplicityMC_pt0_25.root", "Multiplicity", "multiplicityESD.root", kTRUE)'
+mv unfolded.root chi2_pt0_25.root
+aliroot -b -q $ALICE_ROOT/PWG0/multiplicity/correct.C'("multiplicityMC_pt1_25.root", "Multiplicity", "multiplicityESD.root", kTRUE)'
+mv unfolded.root chi2_pt1_25.root
+*/
 
+  loadlibs();
+  
   TH1* results[10];
-
-  // loop over cases (normal, enhanced/reduced ratios)
-  Int_t nMax = 7;
+  const char* files[] = { "chi2_ptref.root", "chi2_pt0.root", "chi2_pt1.root", "chi2_pt0_25.root", "chi2_pt1_25.root"};
+  
+  Int_t nMax = 5;
   for (Int_t i = 0; i<nMax; ++i)
   {
-    TString folder;
-    folder.Form("Multiplicity_%d", i);
-
-    AliMultiplicityCorrection* mult = new AliMultiplicityCorrection(folder, folder);
-
-    TFile::Open(fileNameMC);
-    mult->LoadHistograms();
-
-    mult->SetMultiplicityESD(etaRange, hist);
-
-    if (chi2)
-    {
-      mult->SetRegularizationParameters(AliMultiplicityCorrection::kPol1, 1e4);
-      mult->ApplyMinuitFit(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx, kFALSE);
-      //mult->DrawComparison(Form("ParticleSpeciesComparison_MinuitChi2_%d", i), etaRange, kFALSE, kTRUE, hist2->ProjectionY("mymchist"));
-    }
-    else
-    {
-      mult->ApplyBayesianMethod(etaRange, kFALSE, AliMultiplicityCorrection::kTrVtx, 1, 100);
-      //mult->DrawComparison(Form("ParticleSpeciesComparison_Bayesian_%d", i), etaRange, kFALSE, kTRUE, hist2->ProjectionY("mymchist2"));
-    }
+    AliMultiplicityCorrection* mult = AliMultiplicityCorrection::Open(files[i]);
+    results[i] = (TH1*) mult->GetMultiplicityESDCorrected(etaRange)->Clone(Form("result_%d", i));
+  }
+  
+  const char* legendStrings[] = { "Reduced 50%", "Enhanced 50%", "Reduced 25%", "Enhanced 25%" };
+  DrawRatio(results[0], nMax-1, results+1, "LowMomentumSyst.eps", kFALSE, legendStrings);
+}
 
-    //Float_t averageRatio = 0;
-    //mult->GetComparisonResults(0, 0, 0, &averageRatio);
+void ParticleSpeciesComparison()
+{
+  loadlibs();
 
+  TH1* results[10];
+  TH1* mc = 0;
+  
+  // loop over cases (normal, enhanced/reduced ratios)
+  Int_t nMax = 9;
+  for (Int_t i = 0; i<nMax; ++i)
+  {
+    AliMultiplicityCorrection* mult = AliMultiplicityCorrection::Open(Form("chi2_species_%d.root", i), Form("Multiplicity_%d", i));
+    if (i == 0)
+      mc = mult->GetMultiplicityVtx(etaRange)->ProjectionY("mymchist", 1, 1);
     results[i] = (TH1*) mult->GetMultiplicityESDCorrected(etaRange)->Clone(Form("result_%d", i));
-
-    //Printf("Case %d. Average ratio is %f", i, averageRatio);
   }
 
-  DrawResultRatio(hist2->ProjectionY("mymchist", -1, -1, "e"), results[0], "ParticleSpeciesComparison1_1.eps");
-
-  TH1* mc = hist2->ProjectionY("mymchist2", -1, -1, "e");
+  DrawResultRatio(mc, results[0], "ParticleSpeciesComparison1_1.eps");
 
   for (Int_t i=1; i<=results[0]->GetNbinsX(); i++)
   {
@@ -1402,7 +1747,7 @@ void ParticleSpeciesComparison1(Bool_t chi2 = kTRUE, const char* fileNameMC = "m
     mc->SetBinError(i, 0);
   }
 
-  const char* legendStrings[] = { "#pi^{#pm}", 0, "K^{#pm}", 0, "p,#bar{p}", 0 };
+  const char* legendStrings[] = { "K #times 0.5", "K #times 1.5", "p #times 0.5", "p #times 1.5", "K #times 0.5, p #times 0.5", "K #times 1.5, p #times 1.5", "K #times 0.5, p #times 1.5", "K #times 1.5, p #times 0.5" };
 
   DrawRatio(results[0], nMax-1, results+1, "ParticleSpeciesComparison1_2.eps", kFALSE, legendStrings);
 
@@ -1514,21 +1859,26 @@ void TriggerVertexCorrection()
   // plots the correction performed on the unfolded spectrum to gain the spectrum for the full inelastic sample
   //
 
-  gSystem->Load("libPWG0base");
+  loadlibs();
 
   TFile::Open(correctionFile);
   AliMultiplicityCorrection* mult = new AliMultiplicityCorrection("Multiplicity", "Multiplicity");
   mult->LoadHistograms("Multiplicity");
 
   TH1* corrINEL = Invert(mult->GetEfficiency(etaRange, AliMultiplicityCorrection::kINEL));
+  TH1* corrNSD = Invert(mult->GetEfficiency(etaRange, AliMultiplicityCorrection::kNSD));
   TH1* corrMB   = Invert(mult->GetEfficiency(etaRange, AliMultiplicityCorrection::kMB));
 
-  TCanvas* canvas = new TCanvas("TriggerVertexCorrection", "TriggerVertexCorrection", 800, 600);
+  TCanvas* canvas = new TCanvas("TriggerVertexCorrection", "TriggerVertexCorrection", 800, 500);
+  gPad->SetGridx();
+  gPad->SetGridy();
+  gPad->SetTopMargin(0.05);
+  gPad->SetRightMargin(0.05);
 
   corrINEL->SetStats(kFALSE);
-  corrINEL->GetXaxis()->SetRangeUser(0, 20);
-  corrINEL->GetYaxis()->SetRangeUser(0.5, 2.5);
-  corrINEL->SetTitle(";true multiplicity;correction factor");
+  corrINEL->GetXaxis()->SetRangeUser(0, 12);
+  corrINEL->GetYaxis()->SetRangeUser(0, 8);
+  corrINEL->SetTitle(Form(";%s;Correction factor", GetMultLabel()));
   corrINEL->SetMarkerStyle(22);
   corrINEL->Draw("PE");
 
@@ -1537,11 +1887,22 @@ void TriggerVertexCorrection()
   corrMB->SetMarkerStyle(25);
   corrMB->SetMarkerColor(2);
   corrMB->Draw("SAME PE");
+  
+  corrNSD->SetLineColor(4);
+  corrNSD->SetMarkerStyle(24);
+  corrNSD->SetMarkerColor(4);
+  corrNSD->Draw("SAME PE");
+  
+  Printf("       MB  INEL  NSD");
+  Printf("bin 0: %f %f %f", corrMB->GetBinCo