added new conversion task (gamma, gamma & dalitz task) + corresponding dependencies
authorfbock <fbock@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 17 Sep 2012 08:39:06 +0000 (08:39 +0000)
committerfbock <fbock@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 17 Sep 2012 08:39:06 +0000 (08:39 +0000)
19 files changed:
PWGGA/CMakelibPWGGAGammaConv.pkg
PWGGA/GammaConv/AliAnalysisTaskConversionQA.cxx [new file with mode: 0644]
PWGGA/GammaConv/AliAnalysisTaskConversionQA.h [new file with mode: 0644]
PWGGA/GammaConv/AliAnalysisTaskGammaConvDalitzV1.cxx [new file with mode: 0644]
PWGGA/GammaConv/AliAnalysisTaskGammaConvDalitzV1.h [new file with mode: 0644]
PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.cxx [new file with mode: 0644]
PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.h [new file with mode: 0644]
PWGGA/GammaConv/AliConversionCuts.cxx
PWGGA/GammaConv/AliConversionCuts.h
PWGGA/GammaConv/AliConversionMesonCuts.cxx [new file with mode: 0644]
PWGGA/GammaConv/AliConversionMesonCuts.h [new file with mode: 0644]
PWGGA/GammaConv/AliConversionSelection.cxx
PWGGA/GammaConv/AliDalitzElectronCuts.cxx [new file with mode: 0644]
PWGGA/GammaConv/AliDalitzElectronCuts.h [new file with mode: 0644]
PWGGA/GammaConv/AliDalitzElectronSelector.cxx [new file with mode: 0644]
PWGGA/GammaConv/AliDalitzElectronSelector.h [new file with mode: 0644]
PWGGA/GammaConv/AliGammaConversionAODBGHandler.cxx [new file with mode: 0644]
PWGGA/GammaConv/AliGammaConversionAODBGHandler.h [new file with mode: 0644]
PWGGA/PWGGAGammaConvLinkDef.h

index 3be8b216b98cfa89337ebd2c2162c60c7829a0eb..4b65900d9e4cdd54757c05f39aac6f6f02ca4efa 100644 (file)
@@ -35,13 +35,19 @@ set ( SRCS
        GammaConv/AliKFConversionMother.cxx
        GammaConv/AliConversionCuts.cxx
        GammaConv/AliConversionSelection.cxx
+   GammaConv/AliConversionMesonCuts.cxx
+   GammaConv/AliDalitzElectronCuts.cxx
+   GammaConv/AliDalitzElectronSelector.cxx
        GammaConv/AliV0ReaderV1.cxx
        GammaConv/AliConversionAODBGHandlerRP.cxx
        GammaConv/AliConversionTrackCuts.cxx
-
+   GammaConv/AliGammaConversionAODBGHandler.cxx
+   GammaConv/AliAnalysisTaskConversionQA.cxx
        GammaConv/AliAnalysisTaskGammaConvDalitz.cxx
        GammaConv/AliAnalysisTaskPi0v2.cxx
-        GammaConv/AliAnaConvIsolation.cxx
+   GammaConv/AliAnalysisTaskGammaConvV1.cxx
+   GammaConv/AliAnalysisTaskGammaConvDalitzV1.cxx
+   GammaConv/AliAnaConvIsolation.cxx
        GammaConv/AliAnaConvCorrBase.cxx
        GammaConv/AliAnaConvCorrPion.cxx
        GammaConv/AliAnaConvCorrPhoton.cxx
@@ -53,7 +59,6 @@ set ( SRCS
        GammaConv/AliGammaConversionHistograms.cxx
        GammaConv/AliGammaConversionBGHandler.cxx
        GammaConv/AliAnalysisTaskGCPartToPWG4Part.cxx
-
        )
 
 string ( REPLACE ".cxx" ".h" HDRS "${SRCS}" )
diff --git a/PWGGA/GammaConv/AliAnalysisTaskConversionQA.cxx b/PWGGA/GammaConv/AliAnalysisTaskConversionQA.cxx
new file mode 100644 (file)
index 0000000..4eec977
--- /dev/null
@@ -0,0 +1,168 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                                                                                                                                             *
+ * Authors: Svein Lindal, Daniel Lohner                                                                                        *
+ * Version 1.0                                                                                                                                                         *
+ *                                                                                                                                                                                             *
+ * Permission to use, copy, modify and distribute this software and its         *
+ * documentation strictly for non-commercial purposes is hereby granted         *
+ * without fee, provided that the above copyright notice appears in all         *
+ * copies and that both the copyright notice and this permission notice         *
+ * appear in the supporting documentation. The authors make no claims   *
+ * about the suitability of this software for any purpose. It is                       *
+ * provided "as is" without express or implied warranty.                                               *
+ **************************************************************************/
+
+////////////////////////////////////////////////
+//---------------------------------------------
+// QA Task for V0 Reader V1
+//---------------------------------------------
+////////////////////////////////////////////////
+
+#include "AliAnalysisTaskConversionQA.h"
+#include "TChain.h"
+#include "AliAnalysisManager.h"
+#include "TParticle.h"
+#include "TVectorF.h"
+#include "AliPIDResponse.h"
+#include "TFile.h"
+
+class iostream;
+
+using namespace std;
+
+ClassImp(AliAnalysisTaskConversionQA)
+
+//________________________________________________________________________
+AliAnalysisTaskConversionQA::AliAnalysisTaskConversionQA(const char *name) : AliAnalysisTaskSE(name),
+   fConversionGammas(NULL),
+   fConversionCuts(NULL),
+   fStreamQA(NULL),
+   fIsHeavyIon(kFALSE),
+   fOutputList(NULL)
+{
+   // Default constructor
+
+   DefineInput(0, TChain::Class());
+   DefineOutput(1, TList::Class());
+}
+
+//________________________________________________________________________
+AliAnalysisTaskConversionQA::~AliAnalysisTaskConversionQA()
+{
+   // default deconstructor
+   if(fStreamQA){
+      delete fStreamQA;
+      fStreamQA = 0x0;
+   }
+}
+//________________________________________________________________________
+void AliAnalysisTaskConversionQA::UserCreateOutputObjects()
+{
+   // Create User Output Objects
+
+   if(fOutputList != NULL){
+      delete fOutputList;
+      fOutputList = NULL;
+   }
+   if(fOutputList == NULL){
+      fOutputList = new TList();
+      fOutputList->SetOwner(kTRUE);
+   }
+
+   // V0 Reader Cuts
+   TString cutnumber = fConversionCuts->GetCutNumber();
+
+   fStreamQA = new TTreeSRedirector(Form("GammaConvV1_QA_%s.root",cutnumber.Data()));
+   PostData(1, fOutputList);
+
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskConversionQA::UserExec(Option_t *){
+
+   fV0Reader=(AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask("V0ReaderV1");
+
+   Int_t eventQuality = ((AliConversionCuts*)fV0Reader->GetConversionCuts())->GetEventQuality();
+   if(eventQuality != 0){// Event Not Accepted
+      return;
+   }
+   AliESDEvent* event = (AliESDEvent*) InputEvent();
+   if(fIsHeavyIon && !fConversionCuts->IsCentralitySelected(event)) return;
+
+   fConversionGammas=fV0Reader->GetReconstructedGammas();
+
+   ProcessQA();
+   PostData(1, fOutputList);
+}
+
+
+///________________________________________________________________________
+void AliAnalysisTaskConversionQA::ProcessQA(){
+
+   // Fill Histograms for QA and MC
+   AliESDEvent* event = (AliESDEvent*) InputEvent();
+   AliPIDResponse* pidResonse = ((AliConversionCuts*)fV0Reader->GetConversionCuts())->GetPIDResponse();
+   for(Int_t firstGammaIndex=0;firstGammaIndex<fConversionGammas->GetEntriesFast();firstGammaIndex++){
+      AliAODConversionPhoton *gamma=dynamic_cast<AliAODConversionPhoton*>(fConversionGammas->At(firstGammaIndex));
+      if(!fConversionCuts->PhotonIsSelected(gamma,event)) continue;
+      Float_t gammaPt = gamma->GetPhotonPt();
+      Float_t gammaPhi = gamma->GetPhotonPhi();
+      Float_t gammaTheta = gamma->Theta();
+      Float_t gammaChi2NDF = gamma->GetChi2perNDF();
+      Float_t gammaQt = gamma->GetArmenterosQt();
+      Float_t gammaAlpha = gamma->GetArmenterosAlpha();
+      Float_t gammaPsiPair = gamma->GetPsiPair();
+      TVectorF daughterProp(14);
+      AliVTrack * negTrack = fConversionCuts->GetTrack(event, gamma->GetTrackLabelNegative());
+      AliVTrack * posTrack = fConversionCuts->GetTrack(event, gamma->GetTrackLabelPositive());
+      if(!negTrack||!posTrack)return;
+
+      daughterProp(0) = posTrack->Pt();
+      daughterProp(7) = negTrack->Pt();
+      daughterProp(1) = posTrack->Theta();
+      daughterProp(8) = negTrack->Theta();
+      daughterProp(2) = posTrack->GetTPCsignal();
+      daughterProp(9) = negTrack->GetTPCsignal();
+      daughterProp(3) = pidResonse->NumberOfSigmasTPC(posTrack,AliPID::kElectron);
+      daughterProp(10) = pidResonse->NumberOfSigmasTPC(posTrack,AliPID::kElectron);
+      if((posTrack->GetStatus() & AliESDtrack::kTOFpid) && !(posTrack->GetStatus() & AliESDtrack::kTOFmismatch)){
+         daughterProp(4) = posTrack->GetTOFsignal();
+         daughterProp(5) = pidResonse->NumberOfSigmasTOF(posTrack, AliPID::kElectron);
+      } else {
+         daughterProp(4) = 20000;
+         daughterProp(5) = -20;
+      }
+      if((negTrack->GetStatus() & AliESDtrack::kTOFpid) && !(negTrack->GetStatus() & AliESDtrack::kTOFmismatch)){
+         daughterProp(11) = negTrack->GetTOFsignal();
+         daughterProp(12) = pidResonse->NumberOfSigmasTOF(negTrack, AliPID::kElectron);
+      } else {
+         daughterProp(11) = 20000;
+         daughterProp(12) = -20;
+      }
+      daughterProp(6) = (Float_t)posTrack->GetNcls(1)/(Float_t)posTrack->GetTPCNclsF();
+      daughterProp(13) = (Float_t)negTrack->GetNcls(1)/(Float_t)negTrack->GetTPCNclsF();
+
+      if (fStreamQA){
+         (*fStreamQA)<<"PhotonQA"
+                     << "pt=" << gammaPt
+                     << "phi=" << gammaPhi
+                     << "theta=" << gammaTheta
+                     << "chi2ndf=" << gammaChi2NDF
+                     << "qt="<< gammaQt
+                     << "alpha=" << gammaAlpha
+                     << "psipair=" << gammaPsiPair
+                     << "daugtherProp.=" << &daughterProp
+                     << "\n";
+      }
+   }
+}
+
+
+//________________________________________________________________________
+void AliAnalysisTaskConversionQA::Terminate(Option_t *)
+{
+   if (fStreamQA){
+      fStreamQA->GetFile()->Write();
+   }
+}
diff --git a/PWGGA/GammaConv/AliAnalysisTaskConversionQA.h b/PWGGA/GammaConv/AliAnalysisTaskConversionQA.h
new file mode 100644 (file)
index 0000000..9ee37a5
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef AliAnalysisConversionQA_cxx
+#define AliAnalysisConversionQA_cxx
+
+#include "AliAnalysisTaskSE.h"
+#include "AliConversionPhotonBase.h"
+#include "TH1.h"
+#include "TH2.h"
+#include "TTreeStream.h"
+#include "AliLog.h"
+#include <vector>
+#include "AliV0ReaderV1.h"
+#include "AliConversionCuts.h"
+#include "TList.h"
+#include "AliStack.h"
+#include "TClonesArray.h"
+
+
+using namespace std;
+
+
+class AliAnalysisTaskConversionQA : public AliAnalysisTaskSE{
+
+public:
+
+    AliAnalysisTaskConversionQA(const char *name);
+    virtual ~AliAnalysisTaskConversionQA();
+
+    virtual void   UserCreateOutputObjects();
+    virtual void   UserExec(Option_t *option);
+    virtual void   Terminate(Option_t *);
+
+    void SetV0Reader(AliV0ReaderV1 *v0Reader){fV0Reader=v0Reader;}
+    void SetConversionCuts(AliConversionCuts* conversionCuts,Bool_t IsHeavyIon ){
+       fConversionCuts=conversionCuts;
+       fIsHeavyIon = IsHeavyIon;
+    }
+    
+private:
+
+    void ProcessQA();
+
+    AliV0ReaderV1 *fV0Reader;
+    TClonesArray *fConversionGammas; //Reconstructed Photons;
+    AliConversionCuts *fConversionCuts; // Cuts used by the V0Reader
+    TTreeSRedirector *fStreamQA;
+    Bool_t fIsHeavyIon;
+    TList *fOutputList;
+
+    ClassDef(AliAnalysisTaskConversionQA, 0);
+};
+
+#endif
+
diff --git a/PWGGA/GammaConv/AliAnalysisTaskGammaConvDalitzV1.cxx b/PWGGA/GammaConv/AliAnalysisTaskGammaConvDalitzV1.cxx
new file mode 100644 (file)
index 0000000..f78ea3d
--- /dev/null
@@ -0,0 +1,1222 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: Pedro González, Pedro Ladrón de Guevara, Ernesto López Torres, *
+ *         Eulogio Serradilla                                             *
+ * Version 2                                                           *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+// Analysis task for pi0->e+e-gamma (Dalitz decay)
+
+#include <vector>
+
+#include "TParticle.h"
+#include "TPDGCode.h"
+#include "TMCProcess.h"
+#include "TDatabasePDG.h"
+#include "TList.h"
+#include "TChain.h"
+#include "TDirectory.h"
+
+#include "AliStack.h"
+#include "AliAnalysisManager.h"
+#include "AliESDInputHandler.h"
+#include "AliESDtrack.h"
+#include "AliMCEvent.h"
+#include "AliStack.h"
+#include "AliMCEventHandler.h"
+#include "AliPID.h"
+#include "AliLog.h"
+#include "AliESDtrackCuts.h"
+#include "AliESDpidCuts.h"
+#include "AliMCEvent.h"
+#include "AliESDv0.h"
+#include "AliESDEvent.h"
+#include "AliESDpid.h"
+#include "AliKFParticle.h"
+#include "AliMCEventHandler.h"
+#include "AliKFVertex.h"
+#include "AliTriggerAnalysis.h"
+#include "AliCentrality.h"
+#include "AliMultiplicity.h"
+#include "AliAnalysisTaskGammaConvDalitzV1.h"
+#include "TH1.h"
+#include "TH2F.h"
+#include "THnSparse.h"
+
+ClassImp( AliAnalysisTaskGammaConvDalitzV1 )
+
+//-----------------------------------------------------------------------------------------------
+AliAnalysisTaskGammaConvDalitzV1::AliAnalysisTaskGammaConvDalitzV1():
+   fV0Reader(NULL),
+   fElecSelector(NULL),
+   fBGHandler(NULL),
+   fESDEvent(NULL),
+   fMCEvent(NULL),
+   fMCStack(NULL),
+   fCutFolder(NULL),
+   fESDList(NULL),
+   fBackList(NULL),
+   fTrueList(NULL),
+   fMCList(NULL),
+   fOutputContainer(0),
+   fReaderGammas(NULL),
+   fSelectorElectronIndex(0),
+   fSelectorPositronIndex(0),
+   fGoodGammas(NULL),
+   fGoodVirtualGammas(NULL),
+   fGoodElectrons(NULL),
+   fGoodPositrons(NULL),
+   fCutGammaArray(NULL),
+   fCutElectronArray(NULL),
+   fCutMesonArray(NULL),
+   fGammasPool(NULL),
+   fConversionCuts(NULL),
+   hESDConvGammaPt(NULL),
+   hESDDalitzElectronPt(NULL),
+   hESDDalitzPositronPt(NULL),
+   hESDEposEnegPsiPairDPhi(NULL),
+   hESDMotherInvMassPt(NULL),
+   sESDMotherInvMassPtZM(NULL),
+   hESDMotherBackInvMassPt(NULL),
+   sESDMotherBackInvMassPtZM(NULL),
+   hMCPi0Pt(NULL),
+   hMCEtaPt(NULL),
+   hMCPi0InAccPt(NULL),
+   hMCEtaInAccPt(NULL),
+   hESDTrueMotherInvMassPt(NULL),
+   hESDTrueMotherPi0GGInvMassPt(NULL),
+   hESDTruePrimaryMotherInvMassMCPt(NULL),
+   hESDTruePrimaryPi0DalitzESDPtMCPt(NULL),
+   hESDTrueSecondaryMotherInvMassPt(NULL),
+   hESDTrueSecondaryMotherFromK0sInvMassPt(NULL),
+   hESDTrueBckGGInvMassPt(NULL),
+   hESDTrueBckContInvMassPt(NULL),
+   hESDTrueMotherGGInvMassPt(NULL),
+   hESDTrueConvGammaPt(NULL),
+   hNEvents(NULL),
+   hNGoodESDTracks(NULL),
+   fRandom(0),
+   fUnsmearedPx(NULL),
+   fUnsmearedPy(NULL),
+   fUnsmearedPz(NULL),
+   fUnsmearedE(NULL),
+   fnCuts(0),
+   fiCut(0),
+   fNumberOfESDTracks(0),
+   fMoveParticleAccordingToVertex(kFALSE),
+   fIsHeavyIon(kFALSE),
+   fDoMesonAnalysis(kTRUE)
+{
+   // Define input and output slots here
+  // DefineInput(0, TChain::Class());
+  // DefineOutput(1, TList::Class());
+}
+
+//-----------------------------------------------------------------------------------------------
+AliAnalysisTaskGammaConvDalitzV1::AliAnalysisTaskGammaConvDalitzV1( const char* name ):
+   AliAnalysisTaskSE(name),
+   fV0Reader(NULL),
+   fElecSelector(NULL),
+   fBGHandler(NULL),
+   fESDEvent(NULL),
+   fMCEvent(NULL),
+   fMCStack(NULL),
+   fCutFolder(NULL),
+   fESDList(NULL),
+   fBackList(NULL),
+   fTrueList(NULL),
+   fMCList(NULL),
+   fOutputContainer(0),
+   fReaderGammas(NULL),
+   fSelectorElectronIndex(0),
+   fSelectorPositronIndex(0),
+   fGoodGammas(NULL),
+   fGoodVirtualGammas(NULL),
+   fGoodElectrons(NULL),
+   fGoodPositrons(NULL),
+   fCutGammaArray(NULL),
+   fCutElectronArray(NULL),
+   fCutMesonArray(NULL),
+   fGammasPool(NULL),
+   fConversionCuts(NULL),
+   hESDConvGammaPt(NULL),
+   hESDDalitzElectronPt(NULL),
+   hESDDalitzPositronPt(NULL),
+   hESDEposEnegPsiPairDPhi(NULL),
+   hESDMotherInvMassPt(NULL),
+   sESDMotherInvMassPtZM(NULL),
+   hESDMotherBackInvMassPt(NULL),
+   sESDMotherBackInvMassPtZM(NULL),
+   hMCPi0Pt(NULL),
+   hMCEtaPt(NULL),
+   hMCPi0InAccPt(NULL),
+   hMCEtaInAccPt(NULL),
+   hESDTrueMotherInvMassPt(NULL),
+   hESDTrueMotherPi0GGInvMassPt(NULL),
+   hESDTruePrimaryMotherInvMassMCPt(NULL),
+   hESDTruePrimaryPi0DalitzESDPtMCPt(NULL),
+   hESDTrueSecondaryMotherInvMassPt(NULL),
+   hESDTrueSecondaryMotherFromK0sInvMassPt(NULL),
+   hESDTrueBckGGInvMassPt(NULL),
+   hESDTrueBckContInvMassPt(NULL),
+   hESDTrueMotherGGInvMassPt(NULL),
+   hESDTrueConvGammaPt(NULL),
+   hNEvents(NULL),
+   hNGoodESDTracks(NULL),
+   fRandom(0),
+   fUnsmearedPx(NULL),
+   fUnsmearedPy(NULL),
+   fUnsmearedPz(NULL),
+   fUnsmearedE(NULL),
+   fnCuts(0),
+   fiCut(0),
+   fNumberOfESDTracks(0),
+   fMoveParticleAccordingToVertex(kFALSE),
+   fIsHeavyIon(kFALSE),
+   fDoMesonAnalysis(kTRUE)
+{
+        DefineInput(0, TChain::Class());
+        DefineOutput(1, TList::Class());
+       // DefineOutput(2, TList::Class());
+
+}
+
+//-----------------------------------------------------------------------------------------------
+AliAnalysisTaskGammaConvDalitzV1::~AliAnalysisTaskGammaConvDalitzV1()
+{
+//
+// virtual destructor
+//
+
+   if(fGoodGammas){
+      delete fGoodGammas;
+      fGoodGammas = 0x0;
+   }
+   if(fGoodVirtualGammas){
+      delete fGoodVirtualGammas;
+      fGoodGammas = 0x0;
+   }
+   if(fGoodElectrons){
+      delete fGoodGammas;
+      fGoodGammas = 0x0;
+   }
+   if(fGoodPositrons){
+      delete fGoodGammas;
+      fGoodGammas = 0x0;
+   }
+   if(fBGHandler){
+      delete[] fBGHandler;
+      fBGHandler = 0x0;
+   }
+}
+
+//___________________________________________________________
+void AliAnalysisTaskGammaConvDalitzV1::InitBack(){
+
+   Double_t *zBinLimitsArray = new Double_t[9];
+   zBinLimitsArray[0] = -50.00;
+   zBinLimitsArray[1] = -3.375;
+   zBinLimitsArray[2] = -1.605;
+   zBinLimitsArray[3] = -0.225;
+   zBinLimitsArray[4] = 1.065;
+   zBinLimitsArray[5] = 2.445;
+   zBinLimitsArray[6] = 4.245;
+   zBinLimitsArray[7] = 50.00;
+   zBinLimitsArray[8] = 1000.00;
+
+   Double_t *multiplicityBinLimitsArrayTracks = new Double_t[6];
+   multiplicityBinLimitsArrayTracks[0] = 0;
+   multiplicityBinLimitsArrayTracks[1] = 8.5;
+   multiplicityBinLimitsArrayTracks[2] = 16.5;
+   multiplicityBinLimitsArrayTracks[3] = 27.5;
+   multiplicityBinLimitsArrayTracks[4] = 41.5;
+   multiplicityBinLimitsArrayTracks[5] = 200.;
+   if(fIsHeavyIon){
+      multiplicityBinLimitsArrayTracks[0] = 0;
+      multiplicityBinLimitsArrayTracks[1] = 200.;
+      multiplicityBinLimitsArrayTracks[2] = 500.;
+      multiplicityBinLimitsArrayTracks[3] = 1000.;
+      multiplicityBinLimitsArrayTracks[4] = 1500.;
+      multiplicityBinLimitsArrayTracks[5] = 5000.;
+   }
+
+   Double_t *multiplicityBinLimitsArrayV0s = new Double_t[5];
+   multiplicityBinLimitsArrayV0s[0] = 2;
+   multiplicityBinLimitsArrayV0s[1] = 3;
+   multiplicityBinLimitsArrayV0s[2] = 4;
+   multiplicityBinLimitsArrayV0s[3] = 5;
+   multiplicityBinLimitsArrayV0s[4] = 9999;
+   if(fIsHeavyIon){
+      multiplicityBinLimitsArrayV0s[0] = 2;
+      multiplicityBinLimitsArrayV0s[1] = 10;
+      multiplicityBinLimitsArrayV0s[2] = 30;
+      multiplicityBinLimitsArrayV0s[3] = 50;
+      multiplicityBinLimitsArrayV0s[4] = 9999;
+   }
+
+   const Int_t nDim = 4;
+   Int_t nBins[nDim] = {1000,250,8,5};
+   Double_t xMin[nDim] = {0,0, 0,0};
+   Double_t xMax[nDim] = {1,25,8,5};
+
+   sESDMotherInvMassPtZM = new THnSparseF*[fnCuts];
+   sESDMotherBackInvMassPtZM = new THnSparseF*[fnCuts];
+
+   fBGHandler = new AliGammaConversionAODBGHandler*[fnCuts];
+
+   for(Int_t iCut = 0; iCut<fnCuts;iCut++){
+
+
+      TString cutstringElectron =((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->GetCutNumber();
+      TString cutstringMeson= ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->GetCutNumber();
+      TString cutstringGamma = ((AliConversionCuts*)fCutGammaArray->At(iCut))->GetCutNumber();
+
+
+      fBackList[iCut] = new TList();
+      fBackList[iCut]->SetName(Form("%s_%s_%s Back histograms",cutstringGamma.Data(),cutstringElectron.Data(),cutstringMeson.Data()));
+      fBackList[iCut]->SetOwner(kTRUE);
+      fCutFolder[iCut]->Add(fBackList[iCut]);
+
+
+
+
+      sESDMotherInvMassPtZM[iCut] = new THnSparseF("Back_Mother_InvMass_Pt_z_m","Back_Mother_InvMass_Pt_z_m",nDim,nBins,xMin,xMax);
+      sESDMotherInvMassPtZM[iCut]->Sumw2();
+      fBackList[iCut]->Add(sESDMotherInvMassPtZM[iCut]);
+      sESDMotherBackInvMassPtZM[iCut] = new THnSparseF("Back_Back_InvMass_Pt_z_m","Back_Back_InvMass_Pt_z_m",nDim,nBins,xMin,xMax);
+      sESDMotherBackInvMassPtZM[iCut]->Sumw2();
+      fBackList[iCut]->Add(sESDMotherBackInvMassPtZM[iCut]);
+
+      if(((AliConversionCuts*)fCutGammaArray->At(iCut))->UseTrackMultiplicity()){
+         fBGHandler[iCut] = new AliGammaConversionAODBGHandler(9,6,((AliConversionCuts*)fCutGammaArray->At(iCut))->NumberOfRotationEvents());
+         fBGHandler[iCut]->Initialize(zBinLimitsArray, multiplicityBinLimitsArrayTracks);
+      }
+      else{
+         fBGHandler[iCut] = new AliGammaConversionAODBGHandler(9,5,((AliConversionCuts*)fCutGammaArray->At(iCut))->NumberOfRotationEvents());
+         fBGHandler[iCut]->Initialize(zBinLimitsArray, multiplicityBinLimitsArrayV0s);
+      }
+   }
+}
+
+//______________________________________________________________________
+void AliAnalysisTaskGammaConvDalitzV1::UserCreateOutputObjects()
+{
+//
+// Create ouput objects
+//
+
+       // Create the output container
+       if(fOutputContainer != NULL){
+               delete fOutputContainer;
+               fOutputContainer = NULL;
+       }
+       if(fOutputContainer == NULL){
+               fOutputContainer = new TList();
+               fOutputContainer->SetOwner(kTRUE);
+       }
+
+       fGoodGammas = new TList();
+        //fGoodGammas->SetOwner(kTRUE);
+
+       
+        fGoodVirtualGammas = new TList();
+           //fGoodVirtualGammas->SetOwner(kTRUE);
+
+
+       
+
+
+        fGammasPool = new TList*[fnCuts];
+
+       fCutFolder = new TList*[fnCuts];
+       fESDList = new TList*[fnCuts];
+       fBackList = new TList*[fnCuts];
+       hNEvents = new TH1I*[fnCuts];
+       hNGoodESDTracks = new TH1I*[fnCuts];
+       hESDConvGammaPt = new TH1F*[fnCuts];
+       hESDDalitzElectronPt = new TH1F*[fnCuts];
+       hESDDalitzPositronPt = new TH1F*[fnCuts];
+        hESDEposEnegPsiPairDPhi = new TH2F*[fnCuts];
+       
+       //if(fDoMesonAnalysis){
+               hESDMotherInvMassPt = new TH2F*[fnCuts];
+               hESDMotherBackInvMassPt = new TH2F*[fnCuts];
+       //}
+       for(Int_t iCut = 0; iCut<fnCuts;iCut++){
+
+
+               TString cutstringElectron =((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->GetCutNumber();
+               TString cutstringMeson= ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->GetCutNumber();
+               TString cutstringGamma = ((AliConversionCuts*)fCutGammaArray->At(iCut))->GetCutNumber();
+
+               fCutFolder[iCut] = new TList();
+               fCutFolder[iCut]->SetName(Form("Cut Number %s_%s_%s",cutstringGamma.Data(),cutstringElectron.Data(),cutstringMeson.Data()));
+               fCutFolder[iCut]->SetOwner(kTRUE);
+               fOutputContainer->Add(fCutFolder[iCut]);
+               fESDList[iCut] = new TList();
+               fESDList[iCut]->SetName(Form("%s_%s_%s ESD histograms",cutstringGamma.Data(),cutstringElectron.Data(),cutstringMeson.Data()));
+               fESDList[iCut]->SetOwner(kTRUE);
+               hNEvents[iCut] = new TH1I("NEvents","NEvents",7,-0.5,6.5);
+               fESDList[iCut]->Add(hNEvents[iCut]);
+               if(fIsHeavyIon) hNGoodESDTracks[iCut] = new TH1I("GoodESDTracks","GoodESDTracks",3000,0,3000);
+               else hNGoodESDTracks[iCut] = new TH1I("GoodESDTracks","GoodESDTracks",200,0,200);
+               fESDList[iCut]->Add(hNGoodESDTracks[iCut]);
+               hESDConvGammaPt[iCut] = new TH1F("ESD_ConvGamma_Pt","ESD_ConvGamma_Pt",250,0,25);
+                fESDList[iCut]->Add(hESDConvGammaPt[iCut]);
+               hESDDalitzElectronPt[iCut] = new TH1F("ESD_DalitzElectron_Pt","ESD_DalitzElectron_Pt",250,0,25);
+                fESDList[iCut]->Add(hESDDalitzElectronPt[iCut]);
+               hESDDalitzPositronPt[iCut] = new TH1F("ESD_DalitzPositron_Pt","ESD_DalitzPositron_Pt",250,0,25);
+                fESDList[iCut]->Add(hESDDalitzPositronPt[iCut]);
+                
+         
+                hESDEposEnegPsiPairDPhi[iCut] = new TH2F("ESD_EposEneg_PsiPair_DPhi","ESD_EposEneg_PsiPair_DPhi", 100, -1.0*TMath::Pi(), TMath::Pi(),100,-1.0*TMath::Pi(), TMath::Pi() );
+                fESDList[iCut]->Add(hESDEposEnegPsiPairDPhi[iCut]);
+                
+                 
+
+
+               // hESDDalitzPositronPt[iCut] = new TH1F("ESD_EposEneg_PsiPair_vs_DPhi","ESD_EposEneg_PsiPair_vs_DPhi",250,0,25);
+     
+//             if(fDoMesonAnalysis){
+                       hESDMotherInvMassPt[iCut] = new TH2F("ESD_DalitzMother_InvMass_Pt","ESD_DalitzMother_InvMass_Pt",1000,0,1,250,0,25);
+                       fESDList[iCut]->Add(hESDMotherInvMassPt[iCut]);
+                       hESDMotherBackInvMassPt[iCut] = new TH2F("ESD_DalitzBackground_InvMass_Pt","ESD_DalitzBackground_InvMass_Pt",1000,0,1,250,0,25);
+                       fESDList[iCut]->Add(hESDMotherBackInvMassPt[iCut]);
+//             }
+               fCutFolder[iCut]->Add(fESDList[iCut]);
+
+
+             if( fCutElectronArray ){
+                if( ((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->GetCutHistograms() ) {
+                    fCutFolder[iCut]->Add( ((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->GetCutHistograms() );
+                }
+            }
+
+             if( fCutMesonArray  ) {
+                if( ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->GetCutHistograms() ) {
+                    fCutFolder[iCut]->Add( ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->GetCutHistograms());
+                }
+             }
+
+            if( fCutGammaArray ) {
+                if( ((AliConversionCuts*)fCutGammaArray->At(iCut))->GetCutHistograms() ) {
+                    fCutFolder[iCut]->Add( ((AliConversionCuts*)fCutGammaArray->At(iCut))->GetCutHistograms()  );
+                }
+            }
+
+
+       }
+
+       //if(fDoMesonAnalysis){
+               InitBack(); // Init Background Handler
+       //}
+
+       if(MCEvent()){
+               // MC Histogramms
+               fMCList = new TList*[fnCuts];
+               // True Histogramms
+               fTrueList = new TList*[fnCuts];
+               hESDTrueConvGammaPt = new TH1F*[fnCuts];        
+               //if(fDoMesonAnalysis){
+                       hMCPi0Pt = new TH1F*[fnCuts];
+                       hMCEtaPt = new TH1F*[fnCuts];
+                       hMCPi0InAccPt = new TH1F*[fnCuts];
+                       hMCEtaInAccPt = new TH1F*[fnCuts];
+
+                       hESDTrueMotherInvMassPt = new TH2F*[fnCuts];
+                        hESDTrueMotherPi0GGInvMassPt = new TH2F*[fnCuts];
+                       hESDTruePrimaryPi0DalitzESDPtMCPt = new TH2F*[fnCuts];
+                       hESDTruePrimaryMotherInvMassMCPt = new TH2F*[fnCuts];
+                       hESDTrueSecondaryMotherInvMassPt = new TH2F*[fnCuts];
+                       hESDTrueSecondaryMotherFromK0sInvMassPt = new TH2F*[fnCuts];
+                       hESDTrueBckGGInvMassPt = new TH2F*[fnCuts];
+                       hESDTrueBckContInvMassPt = new TH2F*[fnCuts];
+                       hESDTrueMotherGGInvMassPt = new TH2F*[fnCuts];
+               //}
+
+               for(Int_t iCut = 0; iCut<fnCuts;iCut++){
+                       TString cutstringElectron =((AliDalitzElectronCuts*)fCutElectronArray->At(iCut))->GetCutNumber();
+                       TString cutstringMeson= ((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->GetCutNumber();
+                       TString cutstringGamma = ((AliConversionCuts*)fCutGammaArray->At(iCut))->GetCutNumber();
+
+                       fMCList[iCut] = new TList();
+                       fMCList[iCut]->SetName(Form("%s_%s_%s MC histograms",cutstringGamma.Data(),cutstringElectron.Data(),cutstringMeson.Data()));
+                       fMCList[iCut]->SetOwner(kTRUE);
+                       fCutFolder[iCut]->Add(fMCList[iCut]);
+                       
+                               hMCPi0Pt[iCut] = new TH1F("MC_Pi0_Pt","MC_Pi0_Pt",250,0,25);
+                               fMCList[iCut]->Add(hMCPi0Pt[iCut]);
+                               hMCEtaPt[iCut] = new TH1F("MC_Eta_Pt","MC_Eta_Pt",250,0,25);
+                               fMCList[iCut]->Add(hMCEtaPt[iCut]);
+                               hMCPi0InAccPt[iCut] = new TH1F("MC_Pi0DalitzInAcc_Pt","MC_Pi0DalitzInAcc_Pt",250,0,25);
+                               fMCList[iCut]->Add(hMCPi0InAccPt[iCut]);
+                               hMCEtaInAccPt[iCut] = new TH1F("MC_EtaDalitzInAcc_Pt","MC_EtaDalitzInAcc_Pt",250,0,25);
+                               fMCList[iCut]->Add(hMCEtaInAccPt[iCut]);
+                       
+                       fTrueList[iCut] = new TList();
+                       fTrueList[iCut]->SetName(Form("%s_%s_%s True histograms",cutstringGamma.Data(),cutstringElectron.Data(),cutstringMeson.Data()));
+                       fTrueList[iCut]->SetOwner(kTRUE);
+                       fCutFolder[iCut]->Add(fTrueList[iCut]);
+
+                       hESDTrueConvGammaPt[iCut] = new TH1F("ESD_TrueConvGamma_Pt","ESD_TrueConvGamma_Pt",250,0,25);
+                        fTrueList[iCut]->Add(hESDTrueConvGammaPt[iCut]);
+
+                       hESDTrueMotherInvMassPt[iCut] = new TH2F("ESD_TrueMother_InvMass_Pt","ESD_TrueMother_InvMass_Pt",1000,0,1,250,0,25);
+                       fTrueList[iCut]->Add(hESDTrueMotherInvMassPt[iCut]);
+
+                        hESDTrueMotherPi0GGInvMassPt[iCut] = new TH2F("ESD_TrueMotherPi0GG_InvMass_Pt","ESD_TrueMotherPi0GG_InvMass_Pt",1000,0,1,250,0,25);
+                                fTrueList[iCut]->Add(hESDTrueMotherPi0GGInvMassPt[iCut]);
+                               hESDTruePrimaryPi0DalitzESDPtMCPt[iCut] = new TH2F("ESD_TruePrimaryPi0Dalitz_ESDPt_MCPt","ESD_TruePrimaryPi0Dalitz_ESDPt_MCPt",250,0,25,250,0,25);
+                               fTrueList[iCut]->Add(hESDTruePrimaryPi0DalitzESDPtMCPt[iCut]);
+                               hESDTruePrimaryMotherInvMassMCPt[iCut] = new TH2F("ESD_TruePrimaryMother_InvMass_MCPt","ESD_TrueDalitzPrimaryMother_InvMass_MCPt",1000,0,1,250,0,25);
+                               fTrueList[iCut]->Add(hESDTruePrimaryMotherInvMassMCPt[iCut]);
+                               hESDTrueSecondaryMotherInvMassPt[iCut] = new TH2F("ESD_TrueDalitzSecondaryMother_InvMass_Pt","ESD_TrueDalitzSecondaryMother_InvMass_Pt",1000,0,1,250,0,25);
+                               fTrueList[iCut]->Add(hESDTrueSecondaryMotherInvMassPt[iCut]);
+//                             hESDTrueSecondaryMotherFromK0sInvMassPt[iCut] = new TH2F("ESD_TrueDalitzSecondaryMotherFromK0s_InvMass_Pt","ESD_TrueDalitzSecondaryMotherFromK0s_InvMass_Pt",1000,0,1,250,0,25);
+//                             fTrueList[iCut]->Add(hESDTrueSecondaryMotherFromK0sInvMassPt[iCut]);
+                               hESDTrueBckGGInvMassPt[iCut] = new TH2F("ESD_TrueDalitzBckGG_InvMass_Pt","ESD_TrueDalitzBckGG_InvMass_Pt",1000,0,1,250,0,25);
+                               fTrueList[iCut]->Add(hESDTrueBckGGInvMassPt[iCut]);
+                               hESDTrueBckContInvMassPt[iCut] = new TH2F("ESD_TrueDalitzBckCont_InvMass_Pt","ESD_TrueDalitzBckCont_InvMass_Pt",1000,0,1,250,0,25);
+                               fTrueList[iCut]->Add(hESDTrueBckContInvMassPt[iCut]);
+//                             hESDTrueMotherGGInvMassPt[iCut] = new TH2F("ESD_TrueGammaGamma_InvMass_Pt","ESD_TrueGammaGamma_InvMass_Pt",1000,0,1,250,0,25);
+//                             fTrueList[iCut]->Add(hESDTrueMotherGGInvMassPt[iCut]);
+                       
+               }
+       }
+
+       PostData(1, fOutputContainer);
+
+}
+
+//______________________________________________________________________
+void AliAnalysisTaskGammaConvDalitzV1::UserExec(Option_t *)
+{
+//
+// Execute analysis for current event
+//        
+
+   fV0Reader=(AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask("V0ReaderV1");
+   if(!fV0Reader){printf("Error: No V0 Reader");return;} // GetV0Reader
+
+   Int_t eventQuality = ((AliConversionCuts*)fV0Reader->GetConversionCuts())->GetEventQuality();
+
+   if(eventQuality != 0){// Event Not Accepted
+      for(Int_t iCut = 0; iCut<fnCuts; iCut++){
+         hNEvents[iCut]->Fill(eventQuality);
+      }
+      return;
+   }
+
+   fElecSelector=(AliDalitzElectronSelector*)AliAnalysisManager::GetAnalysisManager()->GetTask("ElectronSelector");
+   if(!fElecSelector){printf("Error: No ElectronSelector");return;} // GetV0Reader
+
+
+   
+   fMCEvent = MCEvent();
+   fESDEvent = (AliESDEvent*) InputEvent();
+   fReaderGammas = fV0Reader->GetReconstructedGammas(); // Gammas from default Cut
+   fSelectorElectronIndex = fElecSelector->GetReconstructedElectronsIndex(); // Electrons from default Cut
+   fSelectorPositronIndex = fElecSelector->GetReconstructedPositronsIndex(); // Positrons from default Cut
+   CountESDTracks(); // Estimate Event Multiplicity
+
+   AddTaskContainers(); //Add conatiner
+
+    for(Int_t iCut = 0; iCut<fnCuts; iCut++){
+      fiCut = iCut;
+
+      if(fIsHeavyIon && !((AliConversionCuts*)fCutGammaArray->At(iCut))->IsCentralitySelected(fESDEvent)){
+
+         hNEvents[iCut]->Fill(1); // Check Centrality --> Not Accepted => eventQuality = 1
+         continue;
+
+      }
+      hNEvents[iCut]->Fill(eventQuality);
+
+      hNGoodESDTracks[iCut]->Fill(fNumberOfESDTracks);
+
+      if(fMCEvent){ // Process MC Particle
+         fMCStack = fMCEvent->Stack();
+         ProcessMCParticles();
+      }
+
+      ProcessPhotonCandidates(); // Process this cuts gammas
+      ProcessElectronCandidates(); // Process this cuts gammas
+      CalculatePi0DalitzCandidates();
+      CalculateBackground();
+      UpdateEventByEventData();
+      
+               
+//       if(fDoMesonAnalysis){ // Meson Analysis
+//          CalculatePi0Candidates(); // Combine Gammas
+//          CalculateBackground(); // Combinatorial Background
+//          UpdateEventByEventData(); // Store Event for mixed Events  
+//        }
+      fGoodGammas->Clear(); // delete this cuts good gammas
+      fGoodVirtualGammas->Clear(); // delete this cuts good gammas
+   }
+
+    fSelectorElectronIndex.clear();
+    fSelectorPositronIndex.clear();
+
+    PostData( 1, fOutputContainer );
+}
+
+void AliAnalysisTaskGammaConvDalitzV1::Terminate(const Option_t *)
+{
+
+
+}
+
+void AliAnalysisTaskGammaConvDalitzV1::AddTaskContainers()
+{
+//
+
+
+   // cout<<"Entro a dfdsfasdfdsfasdfsdfds terminate: "<<endl;
+
+
+    if( fElecSelector ){
+        
+         //cout<<"Entro al fElecSelector: "<<endl;
+
+         TList *temp0 =  ((AliDalitzElectronCuts*)fElecSelector->GetDalitzElectronCuts())->GetCutHistograms(); 
+
+        if (  temp0 ) {
+
+               if( ! fOutputContainer->Contains( temp0 ) ) { 
+                       fOutputContainer->Add( temp0 );
+                       cout<<" Add fElecSelector: "<<endl;
+               }
+
+        }
+    }
+
+
+    if ( fV0Reader ) {
+
+       TList *temp1 = ((AliConversionCuts*)fV0Reader->GetConversionCuts())->GetCutHistograms();
+
+        if(  temp1  ) {
+               if( ! fOutputContainer->Contains( temp1 ) ) {
+
+                       fOutputContainer->Add( temp1 );
+                       cout<<"Add GammaConv"<<endl;
+               }
+        }
+    }
+
+
+   // fOutputContainer->Print();
+
+   // if( fDebug ) AliInfo("Not to do anything in Terminate");
+}
+
+
+//________________________________________________________________________
+void AliAnalysisTaskGammaConvDalitzV1::ProcessPhotonCandidates()
+{
+   Int_t nV0 = 0;
+   TList *GoodGammasStepOne = new TList();
+   TList *GoodGammasStepTwo = new TList();
+   // Loop over Photon Candidates allocated by ReaderV1
+   for(Int_t i = 0; i < fReaderGammas->GetEntriesFast(); i++){
+      AliAODConversionPhoton* PhotonCandidate = (AliAODConversionPhoton*) fReaderGammas->At(i);
+      if(!PhotonCandidate) continue;
+      if(!((AliConversionCuts*)fCutGammaArray->At(fiCut))->PhotonIsSelected(PhotonCandidate,fESDEvent)) continue;
+      
+      if(!((AliConversionCuts*)fCutGammaArray->At(fiCut))->UseElecSharingCut() && 
+         !((AliConversionCuts*)fCutGammaArray->At(fiCut))->UseToCloseV0sCut()){ // if no post reader loop is required add to events good gammas
+         fGoodGammas->Add(PhotonCandidate);
+         hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt());
+         if(fMCEvent){
+            ProcessTruePhotonCandidates(PhotonCandidate);
+         }
+      }
+      else if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->UseElecSharingCut()){ // if Shared Electron cut is enabled, Fill array, add to step one
+         ((AliConversionCuts*)fCutGammaArray->At(fiCut))->FillElectonLabelArray(PhotonCandidate,nV0);
+         nV0++;
+         GoodGammasStepOne->Add(PhotonCandidate);
+      }
+      else if(!((AliConversionCuts*)fCutGammaArray->At(fiCut))->UseElecSharingCut() && 
+              ((AliConversionCuts*)fCutGammaArray->At(fiCut))->UseToCloseV0sCut()){ // shared electron is disabled, step one not needed -> step two
+         GoodGammasStepTwo->Add(PhotonCandidate);
+      }
+   }
+   if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->UseElecSharingCut()){
+      for(Int_t i = 0;i<GoodGammasStepOne->GetEntries();i++){
+         AliAODConversionPhoton *PhotonCandidate= (AliAODConversionPhoton*) GoodGammasStepOne->At(i);
+         if(!PhotonCandidate) continue;
+         if(!((AliConversionCuts*)fCutGammaArray->At(fiCut))->RejectSharedElectronV0s(PhotonCandidate,i,GoodGammasStepOne->GetEntries())) continue;
+         if(!((AliConversionCuts*)fCutGammaArray->At(fiCut))->UseToCloseV0sCut()){ // To Colse v0s cut diabled, step two not needed 
+            fGoodGammas->Add(PhotonCandidate);
+            hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt());
+            if(fMCEvent){
+               ProcessTruePhotonCandidates(PhotonCandidate);
+            }
+         }
+         else GoodGammasStepTwo->Add(PhotonCandidate); // Close v0s cut enabled -> add to list two
+      }
+   }
+   if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->UseToCloseV0sCut()){
+      for(Int_t i = 0;i<GoodGammasStepTwo->GetEntries();i++){
+         AliAODConversionPhoton* PhotonCandidate = (AliAODConversionPhoton*) GoodGammasStepTwo->At(i);
+         if(!PhotonCandidate) continue;
+         if(!((AliConversionCuts*)fCutGammaArray->At(fiCut))->RejectToCloseV0s(PhotonCandidate,GoodGammasStepTwo,i)) continue;
+         fGoodGammas->Add(PhotonCandidate); // Add gamma to current cut TList
+         hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt()); // Differences to old V0Reader in p_t due to conversion KF->TLorentzVector
+         if(fMCEvent){
+            ProcessTruePhotonCandidates(PhotonCandidate);
+         }
+      }
+   }
+
+   delete GoodGammasStepOne;
+   GoodGammasStepOne = 0x0;
+   delete GoodGammasStepTwo;
+   GoodGammasStepTwo = 0x0;
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskGammaConvDalitzV1::ProcessTruePhotonCandidates(AliAODConversionPhoton *TruePhotonCandidate)
+{
+   // Process True Photons
+   AliStack *MCStack = fMCEvent->Stack();
+   TParticle *posDaughter = TruePhotonCandidate->GetPositiveMCDaughter(MCStack);
+   TParticle *negDaughter = TruePhotonCandidate->GetNegativeMCDaughter(MCStack);
+
+   if(posDaughter == NULL || negDaughter == NULL) return; // One particle does not exist
+   if(posDaughter->GetMother(0) != negDaughter->GetMother(0)){  // Not Same Mother == Combinatorial Bck
+      return;
+   }
+   if(TMath::Abs(posDaughter->GetPdgCode())!=11 || TMath::Abs(negDaughter->GetPdgCode())!=11) return; //One Particle is not electron
+   if(posDaughter->GetPdgCode()==negDaughter->GetPdgCode()) return; // Same Charge
+   if(posDaughter->GetUniqueID() != 5 || negDaughter->GetUniqueID() !=5) return;// check if the daughters come from a conversion
+
+   TParticle *Photon = TruePhotonCandidate->GetMCParticle(MCStack);
+   if(Photon->GetPdgCode() != 22) return; // Mother is no Photon
+
+   // True Photon
+   hESDTrueConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
+}
+
+
+//________________________________________________________________________
+void AliAnalysisTaskGammaConvDalitzV1::ProcessElectronCandidates(){
+
+   Float_t magField = fInputEvent->GetMagneticField();
+
+
+   if( magField  < 0.0 ){
+       magField =  1.0;
+   }
+   else {
+       magField =  -1.0;  
+   }
+    
+
+  
+
+  
+    vector<Int_t> lGoodElectronIndex(0);
+    vector<Int_t> lGoodPositronIndex(0);
+
+
+    lGoodElectronIndex.clear();
+    lGoodPositronIndex.clear();
+
+    
+    for(UInt_t i = 0; i < fSelectorElectronIndex.size(); i++){
+
+        AliESDtrack* electronCandidate = fESDEvent->GetTrack(fSelectorElectronIndex[i]);
+        if(! ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->ElectronIsSelected(electronCandidate) ) continue;
+        lGoodElectronIndex.push_back(   fSelectorElectronIndex[i] );
+        hESDDalitzElectronPt[fiCut]->Fill(electronCandidate->Pt());
+
+    }
+
+    for(UInt_t i = 0; i < fSelectorPositronIndex.size(); i++){
+
+        AliESDtrack* positronCandidate = fESDEvent->GetTrack(fSelectorPositronIndex[i]);
+        if(! ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->ElectronIsSelected(positronCandidate) ) continue;
+        lGoodPositronIndex.push_back(   fSelectorPositronIndex[i] );
+        hESDDalitzPositronPt[fiCut]->Fill(positronCandidate->Pt());
+
+    }
+
+
+
+
+
+       
+   for(UInt_t i = 0; i < lGoodElectronIndex.size(); i++){
+
+
+               AliESDtrack* electronCandidate = fESDEvent->GetTrack(lGoodElectronIndex[i]);
+
+               AliKFParticle electronCandidateKF( *electronCandidate->GetConstrainedParam(), ::kElectron );
+                
+               for(UInt_t j = 0; j < lGoodPositronIndex.size(); j++){
+                   AliESDtrack* positronCandidate = fESDEvent->GetTrack(lGoodPositronIndex[j]);
+                        AliKFParticle positronCandidateKF( *positronCandidate->GetConstrainedParam(), ::kPositron );
+                       
+                        if( ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->DoPsiPairCut() == kTRUE ){
+
+                           
+
+                            
+                            Double_t psiPair = ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->GetPsiPair(electronCandidate,positronCandidate);
+                            Double_t deltaPhi = magField * TVector2::Phi_mpi_pi( electronCandidate->GetConstrainedParam()->Phi()-positronCandidate->GetConstrainedParam()->Phi());
+
+                           
+
+                            if( ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->IsFromGammaConversion(psiPair,deltaPhi ) ){
+                                 continue;
+                            }
+                              hESDEposEnegPsiPairDPhi[fiCut]->Fill(deltaPhi,psiPair);
+
+                          }
+
+
+                          AliKFConversionPhoton* virtualPhoton = new AliKFConversionPhoton(electronCandidateKF,positronCandidateKF);
+
+                         //if(fUseImprovedVertex == kTRUE){
+                                AliKFVertex primaryVertexImproved(*fInputEvent->GetPrimaryVertex());
+                                primaryVertexImproved+=*virtualPhoton;
+                                virtualPhoton->SetProductionVertex(primaryVertexImproved);
+                         //}
+                          
+                          virtualPhoton->SetTrackLabels( lGoodPositronIndex[j], lGoodElectronIndex[i]);
+
+                          if(fMCEvent){
+
+                               // AliStack *fMCStack= fMCEvent->Stack();
+                                Int_t labeln=TMath::Abs(electronCandidate->GetLabel());
+                                Int_t labelp=TMath::Abs(positronCandidate->GetLabel());
+                                TParticle *fNegativeMCParticle = fMCStack->Particle(labeln);
+                                TParticle *fPositiveMCParticle = fMCStack->Particle(labelp);
+                                if( fPositiveMCParticle && fNegativeMCParticle) {
+                                    virtualPhoton->SetMCLabelPositive(labelp);
+                                    virtualPhoton->SetMCLabelNegative(labeln);
+                                }
+                          }
+                          AliAODConversionPhoton *vphoton = new AliAODConversionPhoton(virtualPhoton); //To Apply PsiPairCut
+                          fGoodVirtualGammas->Add(  vphoton );
+            }
+   }
+   
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskGammaConvDalitzV1::CalculatePi0DalitzCandidates(){
+
+   // Conversion Gammas
+
+  
+
+
+   if( fGoodGammas->GetEntries() > 0 && fGoodVirtualGammas->GetEntries() > 0 ){
+
+   
+      for(Int_t GammaIndex=0; GammaIndex<fGoodGammas->GetEntries(); GammaIndex++){
+
+         AliAODConversionPhoton *gamma=dynamic_cast<AliAODConversionPhoton*>(fGoodGammas->At(GammaIndex));
+
+         for(Int_t virtualGammaIndex=0;virtualGammaIndex<fGoodVirtualGammas->GetEntries();virtualGammaIndex++){
+
+            AliAODConversionPhoton *Vgamma=dynamic_cast<AliAODConversionPhoton*>(fGoodVirtualGammas->At(virtualGammaIndex));
+            //Check for same Electron ID
+            if(gamma->GetTrackLabelPositive() == Vgamma->GetTrackLabelPositive() ||
+               gamma->GetTrackLabelNegative() == Vgamma->GetTrackLabelNegative() ||
+               gamma->GetTrackLabelNegative() == Vgamma->GetTrackLabelPositive() ||
+               gamma->GetTrackLabelPositive() == Vgamma->GetTrackLabelNegative() ) continue;
+
+            AliAODConversionMother *pi0cand = new AliAODConversionMother(gamma,Vgamma);
+            pi0cand->SetLabels(GammaIndex,virtualGammaIndex);
+
+              if( ( ((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelected(pi0cand,kTRUE)) ){
+               hESDMotherInvMassPt[fiCut]->Fill(pi0cand->M(),pi0cand->Pt());
+              // if(pi0cand->GetAlpha()<0.1){
+              //    hESDMotherInvMassEalpha[fiCut]->Fill(pi0cand->M(),pi0cand->E());
+              // }
+               Int_t zbin= fBGHandler[fiCut]->GetZBinIndex(fESDEvent->GetPrimaryVertex()->GetZ());
+               Int_t mbin = 0;
+               if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->UseTrackMultiplicity()){
+                  mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fNumberOfESDTracks);
+               } else {
+                  mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fGoodGammas->GetEntries());
+               }
+               Double_t sparesFill[4] = {pi0cand->M(),pi0cand->Pt(),zbin,mbin};
+               sESDMotherInvMassPtZM[fiCut]->Fill(sparesFill,1);
+               if(fMCEvent){
+                  ProcessTrueMesonCandidates(pi0cand,gamma,Vgamma);
+               }
+              }
+            delete pi0cand;
+            pi0cand=0x0;
+         }
+      }
+    }
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskGammaConvDalitzV1::CalculateBackground(){
+
+   Int_t zbin= fBGHandler[fiCut]->GetZBinIndex(fESDEvent->GetPrimaryVertex()->GetZ());
+   Int_t mbin = 0;
+   
+   Int_t method = 0;
+
+   method = ((AliDalitzElectronCuts*) fCutElectronArray->At(fiCut))->GetBKGMethod();
+
+
+   if(((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->UseTrackMultiplicity()){
+      mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fNumberOfESDTracks);
+   } else {
+      mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fGoodGammas->GetEntries());
+   }
+
+   if( method == 1 || method == 2 ) {
+
+      AliGammaConversionAODBGHandler::GammaConversionVertex *bgEventVertex = NULL;
+
+      if( ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->UseTrackMultiplicity() ) {
+
+         for(Int_t nEventsInBG=0;nEventsInBG<fBGHandler[fiCut]->GetNBGEvents();nEventsInBG++){
+
+            AliGammaConversionAODVector *previousEventV0s = fBGHandler[fiCut]->GetBGGoodV0s(zbin,mbin,nEventsInBG);
+
+            if(fMoveParticleAccordingToVertex == kTRUE && method == 1){
+               bgEventVertex = fBGHandler[fiCut]->GetBGEventVertex(zbin,mbin,nEventsInBG);
+            }
+
+            for(Int_t iCurrent=0;iCurrent<fGoodVirtualGammas->GetEntries();iCurrent++){
+               AliAODConversionPhoton currentEventGoodV0 = *(AliAODConversionPhoton*)(fGoodVirtualGammas->At(iCurrent));
+               
+                for(UInt_t iPrevious=0;iPrevious<previousEventV0s->size();iPrevious++){
+                  AliAODConversionPhoton previousGoodV0 = (AliAODConversionPhoton)(*(previousEventV0s->at(iPrevious)));
+
+                  if(fMoveParticleAccordingToVertex == kTRUE && method == 1 ){
+                     MoveParticleAccordingToVertex(&previousGoodV0,bgEventVertex);
+                  }
+
+                  AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&previousGoodV0);
+                  if( ( ((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelected(backgroundCandidate,kFALSE) ) ){
+                     hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
+                     Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),zbin,mbin};
+                     sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
+                  }
+                  delete backgroundCandidate;
+                  backgroundCandidate = 0x0;
+               }
+            }
+         }
+      }
+      else{
+         for(Int_t nEventsInBG=0;nEventsInBG <fBGHandler[fiCut]->GetNBGEvents();nEventsInBG++){
+            AliGammaConversionAODVector *previousEventV0s = fBGHandler[fiCut]->GetBGGoodV0s(zbin,mbin,nEventsInBG);
+            if(previousEventV0s){
+               if(fMoveParticleAccordingToVertex == kTRUE && method == 1){
+                  bgEventVertex = fBGHandler[fiCut]->GetBGEventVertex(zbin,mbin,nEventsInBG);
+               }
+               for(Int_t iCurrent=0;iCurrent<fGoodVirtualGammas->GetEntries();iCurrent++){
+                  AliAODConversionPhoton currentEventGoodV0 = *(AliAODConversionPhoton*)(fGoodVirtualGammas->At(iCurrent));
+                  for(UInt_t iPrevious=0;iPrevious<previousEventV0s->size();iPrevious++){
+
+                     AliAODConversionPhoton previousGoodV0 = (AliAODConversionPhoton)(*(previousEventV0s->at(iPrevious)));
+
+                     if(fMoveParticleAccordingToVertex == kTRUE && method ==1){
+                        MoveParticleAccordingToVertex(&previousGoodV0,bgEventVertex);
+                     }
+
+                     AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&previousGoodV0);
+
+                     if((((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelected(backgroundCandidate,kFALSE))){
+                        hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
+                        Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),zbin,mbin};
+                        sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
+                     }
+                     delete backgroundCandidate;
+                     backgroundCandidate = 0x0;
+                  }
+               }
+            }
+         }
+      }
+   }
+
+   else if( method == 3 ){
+
+            for(Int_t iCurrent=0;iCurrent<fGoodVirtualGammas->GetEntries();iCurrent++){
+
+               AliAODConversionPhoton currentEventGoodV0 = *(AliAODConversionPhoton*)(fGoodVirtualGammas->At(iCurrent));
+
+                for(Int_t iPrevious=0;iPrevious<fGammasPool[fiCut]->GetEntries();iPrevious++){
+                
+                  AliAODConversionPhoton previousGoodV0 = *(AliAODConversionPhoton*)((fGammasPool[fiCut]->At(iPrevious) ));
+
+                
+                  AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&previousGoodV0);
+
+                  if((((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelected(backgroundCandidate,kFALSE))){
+
+                     hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
+                     Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),zbin,mbin};
+                     sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
+                  }
+                  delete backgroundCandidate;
+                  backgroundCandidate = 0x0;
+               }
+            }
+   }
+
+}
+//________________________________________________________________________
+void AliAnalysisTaskGammaConvDalitzV1::UpdateEventByEventData(){
+   //see header file for documentation
+
+   Int_t method = 0;
+
+   method = ( (AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->GetBKGMethod();
+   
+   if( method == 1 ) {
+
+   if(fGoodGammas->GetEntries() >0 ){
+
+      if(((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->UseTrackMultiplicity()){
+         fBGHandler[fiCut]->AddEvent(fGoodGammas,fESDEvent->GetPrimaryVertex()->GetX(),fESDEvent->GetPrimaryVertex()->GetY(),fESDEvent->GetPrimaryVertex()->GetZ(),fNumberOfESDTracks);
+      }
+
+      else{ // means we use #V0s for multiplicity
+         fBGHandler[fiCut]->AddEvent(fGoodGammas,fESDEvent->GetPrimaryVertex()->GetX(),fESDEvent->GetPrimaryVertex()->GetY(),fESDEvent->GetPrimaryVertex()->GetZ(),fGoodGammas->GetEntries());
+      }
+    }
+   }
+
+   else if ( method == 2 ){
+    
+    if(fGoodVirtualGammas->GetEntries() >0 ){
+      if(((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->UseTrackMultiplicity()){
+         fBGHandler[fiCut]->AddEvent(fGoodVirtualGammas,fESDEvent->GetPrimaryVertex()->GetX(),fESDEvent->GetPrimaryVertex()->GetY(),fESDEvent->GetPrimaryVertex()->GetZ(),fNumberOfESDTracks);
+      }
+      else{ // means we use #V0s for multiplicity
+         fBGHandler[fiCut]->AddEvent(fGoodVirtualGammas,fESDEvent->GetPrimaryVertex()->GetX(),fESDEvent->GetPrimaryVertex()->GetY(),fESDEvent->GetPrimaryVertex()->GetZ(),fGoodGammas->GetEntries());
+     }
+   }
+  }
+  else if ( method  == 3 ) {
+        
+               for(Int_t index = 0; index < fGoodGammas->GetEntries(); index ++){
+
+                            if ( fGammasPool[fiCut]->GetEntries() > 10 ){
+                                    fGammasPool[fiCut]->RemoveLast();
+                            }
+                 fGammasPool[fiCut]->AddFirst(dynamic_cast<AliAODConversionPhoton*>(fGoodGammas->At(index)));
+               }
+      }
+}
+//______________________________________________________________________
+void AliAnalysisTaskGammaConvDalitzV1::ProcessTrueMesonCandidates(AliAODConversionMother *Pi0Candidate, AliAODConversionPhoton *TrueGammaCandidate, AliAODConversionPhoton *TrueVirtualGammaCandidate)
+{
+
+   // Process True Mesons
+
+   AliStack *MCStack = fMCEvent->Stack();
+
+
+   if(TrueGammaCandidate->GetV0Index()<fESDEvent->GetNumberOfV0s()){
+
+
+      Bool_t isTruePi0 = kFALSE;
+      Bool_t isTrueEta = kFALSE;
+      Int_t gammaMCLabel = TrueGammaCandidate->GetMCParticleLabel(MCStack);
+      Int_t gammaMotherLabel = -1;
+
+
+
+
+      if(gammaMCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
+
+
+         // Daughters Gamma 0
+         TParticle * negativeMC = (TParticle*)TrueGammaCandidate->GetNegativeMCDaughter(MCStack);
+         TParticle * positiveMC = (TParticle*)TrueGammaCandidate->GetPositiveMCDaughter(MCStack);
+         TParticle * gammaMC = (TParticle*)MCStack->Particle(gammaMCLabel);
+
+
+         if(TMath::Abs(negativeMC->GetPdgCode())==11 && TMath::Abs(positiveMC->GetPdgCode())==11){  // Electrons ...
+
+            if(negativeMC->GetUniqueID() == 5 && positiveMC->GetUniqueID() ==5){ // ... From Conversion ...
+               
+                    if(gammaMC->GetPdgCode() == 22){ // ... with Gamma Mother
+                     gammaMotherLabel=gammaMC->GetFirstMother();
+                    }
+           }
+        }
+       }
+
+
+         Int_t virtualGammaMCLabel = TrueVirtualGammaCandidate->GetMCParticleLabel(MCStack);
+         Int_t virtualGammaMotherLabel = -1;
+         Int_t virtualGamma = 1;
+
+         if(virtualGammaMCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
+            // Daughters Gamma 1
+            TParticle * negativeMC = (TParticle*)TrueVirtualGammaCandidate->GetNegativeMCDaughter(MCStack);
+            TParticle * positiveMC = (TParticle*)TrueVirtualGammaCandidate->GetPositiveMCDaughter(MCStack);
+            TParticle * virtualGammaMotherMC = (TParticle*)MCStack->Particle(virtualGammaMCLabel);
+            if(TMath::Abs(negativeMC->GetPdgCode())==11 && TMath::Abs(positiveMC->GetPdgCode())==11){  // Electrons ...
+
+            if( virtualGammaMotherMC->GetPdgCode() != 22 ){
+                  virtualGammaMotherLabel=virtualGammaMCLabel;
+            }                  
+             
+             else if(negativeMC->GetUniqueID() == 5 && positiveMC->GetUniqueID() ==5){ // ... From Conversion ...
+               
+                    virtualGammaMotherLabel=virtualGammaMotherMC->GetFirstMother();
+                    virtualGamma = 0; //no virtual gamma
+                
+             }
+            }
+         }
+
+
+         if(gammaMotherLabel>=0 && ( gammaMotherLabel == virtualGammaMotherLabel) ){
+
+            if(((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->GetPdgCode() == 111){
+               isTruePi0=kTRUE;
+            }
+
+            if(((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->GetPdgCode() == 221){
+               isTrueEta=kTRUE;
+            }
+
+         }
+
+         if(isTruePi0 || isTrueEta ){ // True Pion or Eta
+            if ( virtualGamma == 1 ) { //True Dalitz
+            hESDTrueMotherInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
+            if(gammaMotherLabel <= MCStack->GetNprimary()){ // Only primary pi0 for efficiency calculation
+               hESDTruePrimaryMotherInvMassMCPt[fiCut]->Fill(Pi0Candidate->M(),((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->Pt());
+               if(isTruePi0){ // Only primaries for unfolding
+                  hESDTruePrimaryPi0DalitzESDPtMCPt[fiCut]->Fill(Pi0Candidate->Pt(),((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->Pt());
+               }
+            }
+            if(gammaMotherLabel > MCStack->GetNprimary()){ // Secondary Meson
+               hESDTrueSecondaryMotherInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
+               //if (((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->GetMother(0) >-1){
+               //   if(MCStack->Particle(((TParticle*)MCStack->Particle(virtualGammaMotherLabel))->GetMother(0))->GetPdgCode()==kK0Short){
+               //      hESDTrueSecondaryMotherFromK0sInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
+               //   }
+               }
+            }
+            else if ( virtualGamma == 0 ){
+              hESDTrueMotherPi0GGInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt()); // Pi0 from GG
+            }
+         }
+    
+        if(!isTruePi0 && !isTrueEta){ // Background
+            if(gammaMotherLabel>-1 && virtualGammaMotherLabel>-1 && virtualGamma == 0){ // Both Tracks are Photons and have a mother but not Pi0 or Eta
+               hESDTrueBckGGInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
+            } else { // No photon or without mother
+               hESDTrueBckContInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
+            } 
+        }
+    }
+}
+//________________________________________________________________________
+void AliAnalysisTaskGammaConvDalitzV1::MoveParticleAccordingToVertex(AliAODConversionPhoton* particle,const AliGammaConversionAODBGHandler::GammaConversionVertex *vertex){
+   //see header file for documentation
+
+   Double_t dx = vertex->fX - fESDEvent->GetPrimaryVertex()->GetX();
+   Double_t dy = vertex->fY - fESDEvent->GetPrimaryVertex()->GetY();
+   Double_t dz = vertex->fZ - fESDEvent->GetPrimaryVertex()->GetZ();
+
+   Double_t movedPlace[3] = {particle->GetConversionX() - dx,particle->GetConversionY() - dy,particle->GetConversionZ() - dz};
+   particle->SetConversionPoint(movedPlace);
+}
+
+
+//________________________________________________________________________
+void AliAnalysisTaskGammaConvDalitzV1::CountESDTracks(){
+
+   AliESDtrackCuts *EsdTrackCuts = new AliESDtrackCuts("AliESDtrackCuts");
+   // Using standard function for setting Cuts
+   Bool_t selectPrimaries=kTRUE;
+   EsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(selectPrimaries);
+   EsdTrackCuts->SetMaxDCAToVertexZ(2);
+   EsdTrackCuts->SetEtaRange(-0.8, 0.8);
+   EsdTrackCuts->SetPtRange(0.15);
+
+   fNumberOfESDTracks = 0;
+   for(Int_t iTracks = 0; iTracks < fESDEvent->GetNumberOfTracks(); iTracks++){
+      AliESDtrack* curTrack = fESDEvent->GetTrack(iTracks);
+      if(!curTrack) continue;
+      if(EsdTrackCuts->AcceptTrack(curTrack) ) fNumberOfESDTracks++;
+   }
+   delete EsdTrackCuts;
+   EsdTrackCuts=0x0;
+
+   return;
+}
+
+//_____________________________________________________________________________
+void AliAnalysisTaskGammaConvDalitzV1::ProcessMCParticles()
+{
+
+
+   // Loop over all primary MC particle
+   for(Int_t i = 0; i < fMCStack->GetNprimary(); i++) {
+      TParticle* particle = (TParticle *)fMCStack->Particle(i);
+      if (!particle) continue;
+
+     
+         if(((AliConversionMesonCuts*)fCutMesonArray->At(fiCut))->MesonIsSelectedMCDalitz(particle,fMCStack)){
+            if(particle->GetPdgCode() == 111)hMCPi0Pt[fiCut]->Fill(particle->Pt()); // All MC Pi0
+            if(particle->GetPdgCode() == 221)hMCEtaPt[fiCut]->Fill(particle->Pt()); // All MC Eta
+            // Check the acceptance for both gammas
+            if(particle->GetNDaughters() == 3){
+               TParticle* gamma    = 0;
+               TParticle* electron = 0;
+               TParticle* positron = 0;
+              
+                 
+               for(Int_t index=particle->GetFirstDaughter(); index<= particle->GetLastDaughter();index++){
+               
+                       
+                    TParticle* temp = (TParticle*)fMCStack->Particle( index );
+
+                    switch( temp->GetPdgCode() ) {
+                                case ::kPositron:
+                                        electron = temp;
+                                        break;
+                                case ::kElectron:
+                                        positron = temp;
+                                        break;
+                                case ::kGamma:
+                                        gamma    = temp;
+                                        break;
+                        }
+               }
+               if( gamma  && electron && positron ) {
+
+                 if(((AliConversionCuts*)fCutGammaArray->At(fiCut))->PhotonIsSelectedMC(gamma,fMCStack,kFALSE) &&
+                    TMath::Abs( electron->Eta() ) < ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->GetEtaCut()  &&
+                    TMath::Abs( positron->Eta() ) < ((AliDalitzElectronCuts*)fCutElectronArray->At(fiCut))->GetEtaCut() ){
+                  if(particle->GetPdgCode() == 111)hMCPi0InAccPt[fiCut]->Fill(particle->Pt()); // MC Pi0Dalitz with gamma and e+e- in acc
+                  if(particle->GetPdgCode() == 221)hMCEtaInAccPt[fiCut]->Fill(particle->Pt()); // MC EtaDalitz with gamma and e+e- in acc
+               }
+              }
+            }
+         }
+      }
+}
diff --git a/PWGGA/GammaConv/AliAnalysisTaskGammaConvDalitzV1.h b/PWGGA/GammaConv/AliAnalysisTaskGammaConvDalitzV1.h
new file mode 100644 (file)
index 0000000..1bcec15
--- /dev/null
@@ -0,0 +1,141 @@
+#ifndef ALIANALYSISTASKGAMMACONVDALITZV1_H
+#define ALIANALYSISTASKGAMMACONVDALITZV1_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+// Analysis task for pi0->e+e-gamma (Dalitz decay)
+
+#include "AliAnalysisTaskSE.h"
+#include "AliV0ReaderV1.h"
+#include "AliKFConversionPhoton.h"
+#include "AliDalitzElectronSelector.h"
+#include "AliConversionMesonCuts.h"
+#include "AliGammaConversionAODBGHandler.h"
+
+class AliESDInputHandler;
+class AliMCEventHandler;
+class AliESDEvent;
+class AliESDtrack;
+class AliESDtrackCuts;
+class AliESDpidCuts;
+class AliV0Reader;
+class AliGammaConversionHistograms;
+class AliTriggerAnalysis;
+
+class AliAnalysisTaskGammaConvDalitzV1: public AliAnalysisTaskSE
+{
+  public:
+
+       AliAnalysisTaskGammaConvDalitzV1();
+       AliAnalysisTaskGammaConvDalitzV1( const char* name );
+       virtual ~AliAnalysisTaskGammaConvDalitzV1();
+
+       virtual void UserExec(Option_t *);
+       virtual void UserCreateOutputObjects();
+       virtual void Terminate(const Option_t *);
+
+
+
+         
+         void SetMoveParticleAccordingToVertex(Bool_t flag){fMoveParticleAccordingToVertex = flag;}
+         void SetIsHeavyIon(Bool_t flag){fIsHeavyIon = flag;}
+         void SetConversionCutList(Int_t nCuts, TList *CutArray){
+                        fnCuts= nCuts;
+                        fCutGammaArray = CutArray;
+                }
+         void SetElectronCutList(TList *CutArray){
+                        fCutElectronArray = CutArray;
+                }
+         void SetMesonCutList(TList *CutArray){
+                        fCutMesonArray = CutArray;
+                }
+               
+
+       private:
+
+               void AddTaskContainers();
+               void InitBack();
+               void ProcessPhotonCandidates();
+               void ProcessTruePhotonCandidates(AliAODConversionPhoton*);
+                void ProcessTrueMesonCandidates(AliAODConversionMother *Pi0Candidate, AliAODConversionPhoton *TrueGammaCandidate, AliAODConversionPhoton *TrueVirtualGammaCandidate);
+                void MoveParticleAccordingToVertex(AliAODConversionPhoton* particle,const AliGammaConversionAODBGHandler::GammaConversionVertex *vertex);
+               void ProcessElectronCandidates();
+               void ProcessMCParticles();
+               void CountESDTracks();
+                void CalculatePi0DalitzCandidates();
+                void CalculateBackground();
+                void UpdateEventByEventData();
+               
+               
+
+    AliV0ReaderV1 *fV0Reader;
+    AliDalitzElectronSelector* fElecSelector;
+    AliGammaConversionAODBGHandler **fBGHandler;
+    AliESDEvent *fESDEvent;
+    AliMCEvent *fMCEvent;
+    AliStack *fMCStack;
+    TList **fCutFolder;
+    TList **fESDList;
+    TList **fBackList;
+    TList **fTrueList;
+    TList **fMCList;
+    TList *fOutputContainer;
+    TClonesArray *fReaderGammas;
+    vector<Int_t> fSelectorElectronIndex;
+    vector<Int_t> fSelectorPositronIndex;
+    TList *fGoodGammas;
+    TList *fGoodVirtualGammas;
+    TList *fGoodElectrons;
+    TList *fGoodPositrons;
+    TList *fCutGammaArray;
+    TList *fCutElectronArray;
+    TList *fCutMesonArray;
+    TList **fGammasPool;
+    AliConversionCuts *fConversionCuts;
+    TH1F **hESDConvGammaPt;
+    TH1F **hESDDalitzElectronPt;
+    TH1F **hESDDalitzPositronPt;
+    TH2F **hESDEposEnegPsiPairDPhi;
+    TH2F **hESDMotherInvMassPt;
+    THnSparseF **sESDMotherInvMassPtZM;
+    TH2F **hESDMotherBackInvMassPt;
+    THnSparseF **sESDMotherBackInvMassPtZM;
+    TH1F **hMCPi0Pt;
+    TH1F **hMCEtaPt;
+    TH1F **hMCPi0InAccPt;
+    TH1F **hMCEtaInAccPt;
+    TH2F **hESDTrueMotherInvMassPt;
+    TH2F **hESDTrueMotherPi0GGInvMassPt;
+    TH2F **hESDTruePrimaryMotherInvMassMCPt;
+    TH2F **hESDTruePrimaryPi0DalitzESDPtMCPt;
+    TH2F **hESDTrueSecondaryMotherInvMassPt;
+    TH2F **hESDTrueSecondaryMotherFromK0sInvMassPt;
+    TH2F **hESDTrueBckGGInvMassPt;
+    TH2F **hESDTrueBckContInvMassPt;
+    TH2F **hESDTrueMotherGGInvMassPt;
+    TH1F **hESDTrueConvGammaPt;
+    TH1I **hNEvents;
+    TH1I **hNGoodESDTracks;
+        
+    TRandom3 fRandom;
+    Double_t *fUnsmearedPx;
+    Double_t *fUnsmearedPy;
+    Double_t *fUnsmearedPz;
+    Double_t *fUnsmearedE;
+    Int_t fnCuts;
+    Int_t fiCut;
+    Int_t fNumberOfESDTracks;
+    Bool_t fMoveParticleAccordingToVertex;
+    Bool_t fIsHeavyIon;
+    Bool_t fDoMesonAnalysis;
+   
+       private:
+               AliAnalysisTaskGammaConvDalitzV1( const AliAnalysisTaskGammaConvDalitzV1& ); // Not implemented
+               AliAnalysisTaskGammaConvDalitzV1& operator=( const AliAnalysisTaskGammaConvDalitzV1& ); // Not implemented
+
+               ClassDef( AliAnalysisTaskGammaConvDalitzV1, 2 );
+};
+
+#endif // ALIANALYSISTASKGAMMACONVDALITZV1_H
+
diff --git a/PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.cxx b/PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.cxx
new file mode 100644 (file)
index 0000000..d709597
--- /dev/null
@@ -0,0 +1,1217 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                       *
+ * Author: Martin Wilde, Daniel Lohner                                   *
+ * Version 1.0                                                           *
+ *                                                                       *
+ * Permission to use, copy, modify and distribute this software and its          *
+ * documentation strictly for non-commercial purposes is hereby granted          *
+ * without fee, provided that the above copyright notice appears in all          *
+ * copies and that both the copyright notice and this permission notice          *
+ * appear in the supporting documentation. The authors make no claims    *
+ * about the suitability of this software for any purpose. It is         *
+ * provided "as is" without express or implied warranty.                         *
+ **************************************************************************/
+
+////////////////////////////////////////////////
+//---------------------------------------------
+// Class used to do analysis on conversion pairs
+//---------------------------------------------
+///////////////////////////////////////////////
+#include "TChain.h"
+#include "TTree.h"
+#include "TH1F.h"
+#include "TH2F.h"
+#include "TH3F.h"
+#include "THnSparse.h"
+#include "TCanvas.h"
+#include "TNtuple.h"
+#include "AliAnalysisTask.h"
+#include "AliAnalysisManager.h"
+#include "AliESDEvent.h"
+#include "AliESDInputHandler.h"
+#include "AliMCEventHandler.h"
+#include "AliMCEvent.h"
+#include "AliMCParticle.h"
+#include "AliCentrality.h"
+#include "AliESDVZERO.h"
+#include "AliESDpid.h"
+#include "AliAnalysisTaskGammaConvV1.h"
+#include "AliVParticle.h"
+#include "AliESDtrackCuts.h"
+#include "AliKFVertex.h"
+#include "AliV0ReaderV1.h"
+#include "AliGammaConversionAODBGHandler.h"
+
+ClassImp(AliAnalysisTaskGammaConvV1)
+
+//________________________________________________________________________
+AliAnalysisTaskGammaConvV1::AliAnalysisTaskGammaConvV1(): AliAnalysisTaskSE(),
+   fV0Reader(NULL),
+   fBGHandler(NULL),
+   fESDEvent(NULL),
+   fMCEvent(NULL),
+   fMCStack(NULL),
+   fCutFolder(NULL),
+   fESDList(NULL),
+   fBackList(NULL),
+   fTrueList(NULL),
+   fMCList(NULL),
+   fOutputContainer(0),
+   fReaderGammas(NULL),
+   fGoodGammas(NULL),
+   fCutArray(NULL),
+   fConversionCuts(NULL),
+   hESDConvGammaPt(NULL),
+   hESDMotherInvMassPt(NULL),
+   sESDMotherInvMassPtZM(NULL),
+   hESDMotherBackInvMassPt(NULL),
+   sESDMotherBackInvMassPtZM(NULL),
+   hESDMotherInvMassEalpha(NULL),
+   hMCAllGammaPt(NULL),
+   hMCAllGammaPtAddedSig(NULL),
+   hMCDecayGammaPi0Pt(NULL),
+   hMCDecayGammaPi0PtAddedSig(NULL),
+   hMCDecayGammaRhoPt(NULL),
+   hMCDecayGammaRhoPtAddedSig(NULL),
+   hMCDecayGammaEtaPt(NULL),
+   hMCDecayGammaEtaPtAddedSig(NULL),
+   hMCDecayGammaOmegaPt(NULL),
+   hMCDecayGammaOmegaPtAddedSig(NULL),
+   hMCDecayGammaEtapPt(NULL),
+   hMCDecayGammaEtapPtAddedSig(NULL),
+   hMCDecayGammaPhiPt(NULL),
+   hMCDecayGammaPhiPtAddedSig(NULL),
+   hMCConvGammaPt(NULL),
+   hMCConvGammaPtAddedSig(NULL),
+   hMCPi0Pt(NULL),
+   hMCEtaPt(NULL),
+   hMCPi0InAccPt(NULL),
+   hMCEtaInAccPt(NULL),
+   hMCPi0PtAddedSig(NULL),
+   hMCEtaPtAddedSig(NULL),
+   hMCPi0InAccPtAddedSig(NULL),
+   hMCEtaInAccPtAddedSig(NULL),
+   hESDTrueMotherInvMassPt(NULL),
+   hESDTrueMotherInvMassPtAddedSig(NULL),
+   hESDTruePrimaryMotherInvMassMCPt(NULL),
+   hESDTruePrimaryMotherInvMassMCPtAddedSig(NULL),
+   hESDTruePrimaryPi0ESDPtMCPt(NULL),
+   hESDTruePrimaryPi0ESDPtMCPtAddedSig(NULL),
+   hESDTrueSecondaryMotherInvMassPt(NULL),
+   hESDTrueSecondaryMotherInvMassPtAddedSig(NULL),
+   hESDTrueSecondaryMotherFromK0sInvMassPt(NULL),
+   hESDTrueSecondaryMotherFromK0sInvMassPtAddedSig(NULL),
+   hESDTrueBckGGInvMassPt(NULL),
+   hESDTrueBckContInvMassPt(NULL),
+   hESDTrueMotherDalitzInvMassPt(NULL),
+   hESDTrueMotherDalitzInvMassPtAddedSig(NULL),
+   hESDTrueConvGammaPt(NULL),
+   hESDTrueConvGammaPtAddedSig(NULL),
+   hESDTrueElecCombPt(NULL),
+   hESDTruePionCombPt(NULL),
+   hESDTruePrimaryConvGammaPt(NULL),
+   hESDTruePrimaryConvGammaPtAddedSig(NULL),
+   hESDTruePrimaryConvGammaESDPtMCPt(NULL),
+   hESDTruePrimaryConvGammaESDPtMCPtAddedSig(NULL),
+   hESDTrueSecondaryConvGammaPt(NULL),
+   hESDTrueSecondaryConvGammaPtAddedSig(NULL),
+   hESDTrueSecondaryConvGammaFromK0sPt(NULL),
+   hESDTrueSecondaryConvGammaFromK0sPtAddedSig(NULL),
+   hESDTrueSecondaryConvGammaFromXFromK0sPt(NULL),
+   hESDTrueSecondaryConvGammaFromXFromK0sPtAddedSig(NULL),
+   hNEvents(NULL),
+   hNGoodESDTracks(NULL),
+   hNV0Tracks(NULL),
+   fRandom(0),
+   fUnsmearedPx(NULL),
+   fUnsmearedPy(NULL),
+   fUnsmearedPz(NULL),
+   fUnsmearedE(NULL),
+   fIsHeavyIon(kFALSE),
+   fDoMesonAnalysis(kTRUE)
+
+{
+   // default Constructor
+   DefineInput(0, TChain::Class());
+   DefineOutput(1, TList::Class());
+}
+
+//________________________________________________________________________
+AliAnalysisTaskGammaConvV1::AliAnalysisTaskGammaConvV1(const char *name):
+   AliAnalysisTaskSE(name),
+   fV0Reader(NULL),
+   fBGHandler(NULL),
+   fESDEvent(NULL),
+   fMCEvent(NULL),
+   fMCStack(NULL),
+   fCutFolder(NULL),
+   fESDList(NULL),
+   fBackList(NULL),
+   fTrueList(NULL),
+   fMCList(NULL),
+   fOutputContainer(0),
+   fReaderGammas(NULL),
+   fGoodGammas(NULL),
+   fCutArray(NULL),
+   fConversionCuts(NULL),
+   hESDConvGammaPt(NULL),
+   hESDMotherInvMassPt(NULL),
+   sESDMotherInvMassPtZM(NULL),
+   hESDMotherBackInvMassPt(NULL),
+   sESDMotherBackInvMassPtZM(NULL),
+   hESDMotherInvMassEalpha(NULL),
+   hMCAllGammaPt(NULL),
+   hMCAllGammaPtAddedSig(NULL),
+   hMCDecayGammaPi0Pt(NULL),
+   hMCDecayGammaPi0PtAddedSig(NULL),
+   hMCDecayGammaRhoPt(NULL),
+   hMCDecayGammaRhoPtAddedSig(NULL),
+   hMCDecayGammaEtaPt(NULL),
+   hMCDecayGammaEtaPtAddedSig(NULL),
+   hMCDecayGammaOmegaPt(NULL),
+   hMCDecayGammaOmegaPtAddedSig(NULL),
+   hMCDecayGammaEtapPt(NULL),
+   hMCDecayGammaEtapPtAddedSig(NULL),
+   hMCDecayGammaPhiPt(NULL),
+   hMCDecayGammaPhiPtAddedSig(NULL),
+   hMCConvGammaPt(NULL),
+   hMCConvGammaPtAddedSig(NULL),
+   hMCPi0Pt(NULL),
+   hMCEtaPt(NULL),
+   hMCPi0InAccPt(NULL),
+   hMCEtaInAccPt(NULL),
+   hMCPi0PtAddedSig(NULL),
+   hMCEtaPtAddedSig(NULL),
+   hMCPi0InAccPtAddedSig(NULL),
+   hMCEtaInAccPtAddedSig(NULL),
+   hESDTrueMotherInvMassPt(NULL),
+   hESDTrueMotherInvMassPtAddedSig(NULL),
+   hESDTruePrimaryMotherInvMassMCPt(NULL),
+   hESDTruePrimaryMotherInvMassMCPtAddedSig(NULL),
+   hESDTruePrimaryPi0ESDPtMCPt(NULL),
+   hESDTruePrimaryPi0ESDPtMCPtAddedSig(NULL),
+   hESDTrueSecondaryMotherInvMassPt(NULL),
+   hESDTrueSecondaryMotherInvMassPtAddedSig(NULL),
+   hESDTrueSecondaryMotherFromK0sInvMassPt(NULL),
+   hESDTrueSecondaryMotherFromK0sInvMassPtAddedSig(NULL),
+   hESDTrueBckGGInvMassPt(NULL),
+   hESDTrueBckContInvMassPt(NULL),
+   hESDTrueMotherDalitzInvMassPt(NULL),
+   hESDTrueMotherDalitzInvMassPtAddedSig(NULL),
+   hESDTrueConvGammaPt(NULL),
+   hESDTrueConvGammaPtAddedSig(NULL),
+   hESDTrueElecCombPt(NULL),
+   hESDTruePionCombPt(NULL),
+   hESDTruePrimaryConvGammaPt(NULL),
+   hESDTruePrimaryConvGammaPtAddedSig(NULL),
+   hESDTruePrimaryConvGammaESDPtMCPt(NULL),
+   hESDTruePrimaryConvGammaESDPtMCPtAddedSig(NULL),
+   hESDTrueSecondaryConvGammaPt(NULL),
+   hESDTrueSecondaryConvGammaPtAddedSig(NULL),
+   hESDTrueSecondaryConvGammaFromK0sPt(NULL),
+   hESDTrueSecondaryConvGammaFromK0sPtAddedSig(NULL),
+   hESDTrueSecondaryConvGammaFromXFromK0sPt(NULL),
+   hESDTrueSecondaryConvGammaFromXFromK0sPtAddedSig(NULL),
+   hNEvents(NULL),
+   hNGoodESDTracks(NULL),
+   hNV0Tracks(NULL),
+   fRandom(0),
+   fUnsmearedPx(NULL),
+   fUnsmearedPy(NULL),
+   fUnsmearedPz(NULL),
+   fUnsmearedE(NULL),
+   fIsHeavyIon(kFALSE),
+   fDoMesonAnalysis(kTRUE)
+
+{
+   // Define input and output slots here
+   DefineInput(0, TChain::Class());
+   DefineOutput(1, TList::Class());
+}
+
+AliAnalysisTaskGammaConvV1::~AliAnalysisTaskGammaConvV1()
+{
+   if(fGoodGammas){
+      delete fGoodGammas;
+      fGoodGammas = 0x0;
+   }
+   if(fBGHandler){
+      delete[] fBGHandler;
+      fBGHandler = 0x0;
+   }
+}
+//___________________________________________________________
+void AliAnalysisTaskGammaConvV1::InitBack(){
+
+   Double_t *zBinLimitsArray = new Double_t[9];
+   zBinLimitsArray[0] = -50.00;
+   zBinLimitsArray[1] = -3.375;
+   zBinLimitsArray[2] = -1.605;
+   zBinLimitsArray[3] = -0.225;
+   zBinLimitsArray[4] = 1.065;
+   zBinLimitsArray[5] = 2.445;
+   zBinLimitsArray[6] = 4.245;
+   zBinLimitsArray[7] = 50.00;
+   zBinLimitsArray[8] = 1000.00;
+
+   Double_t *multiplicityBinLimitsArrayTracks = new Double_t[6];
+   multiplicityBinLimitsArrayTracks[0] = 0;
+   multiplicityBinLimitsArrayTracks[1] = 8.5;
+   multiplicityBinLimitsArrayTracks[2] = 16.5;
+   multiplicityBinLimitsArrayTracks[3] = 27.5;
+   multiplicityBinLimitsArrayTracks[4] = 41.5;
+   multiplicityBinLimitsArrayTracks[5] = 200.;
+   if(fIsHeavyIon){
+      multiplicityBinLimitsArrayTracks[0] = 0;
+      multiplicityBinLimitsArrayTracks[1] = 200.;
+      multiplicityBinLimitsArrayTracks[2] = 500.;
+      multiplicityBinLimitsArrayTracks[3] = 1000.;
+      multiplicityBinLimitsArrayTracks[4] = 1500.;
+      multiplicityBinLimitsArrayTracks[5] = 5000.;
+   }
+
+   Double_t *multiplicityBinLimitsArrayV0s = new Double_t[5];
+   multiplicityBinLimitsArrayV0s[0] = 2;
+   multiplicityBinLimitsArrayV0s[1] = 3;
+   multiplicityBinLimitsArrayV0s[2] = 4;
+   multiplicityBinLimitsArrayV0s[3] = 5;
+   multiplicityBinLimitsArrayV0s[4] = 9999;
+   if(fIsHeavyIon){
+      multiplicityBinLimitsArrayV0s[0] = 2;
+      multiplicityBinLimitsArrayV0s[1] = 10;
+      multiplicityBinLimitsArrayV0s[2] = 30;
+      multiplicityBinLimitsArrayV0s[3] = 50;
+      multiplicityBinLimitsArrayV0s[4] = 9999;
+   }
+
+   const Int_t nDim = 4;
+   Int_t nBins[nDim] = {1000,250,8,5};
+   Double_t xMin[nDim] = {0,0, 0,0};
+   Double_t xMax[nDim] = {1,25,8,5};
+
+   sESDMotherInvMassPtZM = new THnSparseF*[fnCuts];
+   sESDMotherBackInvMassPtZM = new THnSparseF*[fnCuts];
+
+   fBGHandler = new AliGammaConversionAODBGHandler*[fnCuts];
+   for(Int_t iCut = 0; iCut<fnCuts;iCut++){
+      TString cutstring = ((AliConversionCuts*)fCutArray->At(iCut))->GetCutNumber();
+
+      fBackList[iCut] = new TList();
+      fBackList[iCut]->SetName(Form("%s Back histograms",cutstring.Data()));
+      fBackList[iCut]->SetOwner(kTRUE);
+      fCutFolder[iCut]->Add(fBackList[iCut]);
+
+      sESDMotherInvMassPtZM[iCut] = new THnSparseF("Back_Mother_InvMass_Pt_z_m","Back_Mother_InvMass_Pt_z_m",nDim,nBins,xMin,xMax);
+      sESDMotherInvMassPtZM[iCut]->Sumw2();
+      fBackList[iCut]->Add(sESDMotherInvMassPtZM[iCut]);
+      sESDMotherBackInvMassPtZM[iCut] = new THnSparseF("Back_Back_InvMass_Pt_z_m","Back_Back_InvMass_Pt_z_m",nDim,nBins,xMin,xMax);
+      sESDMotherBackInvMassPtZM[iCut]->Sumw2();
+      fBackList[iCut]->Add(sESDMotherBackInvMassPtZM[iCut]);
+
+      if(((AliConversionCuts*)fCutArray->At(iCut))->UseTrackMultiplicity()){
+         fBGHandler[iCut] = new AliGammaConversionAODBGHandler(9,6,((AliConversionCuts*)fCutArray->At(iCut))->NumberOfRotationEvents());
+         fBGHandler[iCut]->Initialize(zBinLimitsArray, multiplicityBinLimitsArrayTracks);
+      }
+      else{
+         fBGHandler[iCut] = new AliGammaConversionAODBGHandler(9,5,((AliConversionCuts*)fCutArray->At(iCut))->NumberOfRotationEvents());
+         fBGHandler[iCut]->Initialize(zBinLimitsArray, multiplicityBinLimitsArrayV0s);
+      }
+   }
+}
+//________________________________________________________________________
+void AliAnalysisTaskGammaConvV1::UserCreateOutputObjects()
+{
+
+   // Create histograms
+   if(fOutputContainer != NULL){
+      delete fOutputContainer;
+      fOutputContainer = NULL;
+   }
+   if(fOutputContainer == NULL){
+      fOutputContainer = new TList();
+      fOutputContainer->SetOwner(kTRUE);
+   }
+
+   // Array of current cut's gammas
+   fGoodGammas = new TList();
+
+   fCutFolder = new TList*[fnCuts];
+   fESDList = new TList*[fnCuts];
+   fBackList = new TList*[fnCuts];
+   hESDConvGammaPt = new TH1F*[fnCuts];
+   hNEvents = new TH1I*[fnCuts];
+   hNGoodESDTracks = new TH1I*[fnCuts];
+       hNV0Tracks = new TH1I*[fnCuts];
+       
+   if(fDoMesonAnalysis){
+      hESDMotherInvMassPt = new TH2F*[fnCuts];
+      hESDMotherBackInvMassPt = new TH2F*[fnCuts];
+      hESDMotherInvMassEalpha = new TH2F*[fnCuts];
+   }
+   for(Int_t iCut = 0; iCut<fnCuts;iCut++){
+
+      TString cutstring = ((AliConversionCuts*)fCutArray->At(iCut))->GetCutNumber();
+
+      fCutFolder[iCut] = new TList();
+      fCutFolder[iCut]->SetName(Form("Cut Number %s",cutstring.Data()));
+      fCutFolder[iCut]->SetOwner(kTRUE);
+      fOutputContainer->Add(fCutFolder[iCut]);
+      fESDList[iCut] = new TList();
+      fESDList[iCut]->SetName(Form("%s ESD histograms",cutstring.Data()));
+      fESDList[iCut]->SetOwner(kTRUE);
+
+      hNEvents[iCut] = new TH1I("NEvents","NEvents",7,-0.5,6.5);
+      fESDList[iCut]->Add(hNEvents[iCut]);
+      if(fIsHeavyIon) hNGoodESDTracks[iCut] = new TH1I("GoodESDTracks","GoodESDTracks",3000,0,3000);
+      else hNGoodESDTracks[iCut] = new TH1I("GoodESDTracks","GoodESDTracks",200,0,200);
+      fESDList[iCut]->Add(hNGoodESDTracks[iCut]);
+               if(fIsHeavyIon) hNV0Tracks[iCut] = new TH1I("V0 Multiplicity","V0 Multiplicity",25000,0,25000);
+      else hNV0Tracks[iCut] = new TH1I("V0 Multiplicity","V0 Multiplicity",2000,0,2000);
+      fESDList[iCut]->Add(hNV0Tracks[iCut]);
+   
+      hESDConvGammaPt[iCut] = new TH1F("ESD_ConvGamma_Pt","ESD_ConvGamma_Pt",250,0,25);
+      fESDList[iCut]->Add(hESDConvGammaPt[iCut]);
+
+      if(fDoMesonAnalysis){
+         hESDMotherInvMassPt[iCut] = new TH2F("ESD_Mother_InvMass_Pt","ESD_Mother_InvMass_Pt",1000,0,1,250,0,25);
+         fESDList[iCut]->Add(hESDMotherInvMassPt[iCut]);
+         hESDMotherBackInvMassPt[iCut] = new TH2F("ESD_Background_InvMass_Pt","ESD_Background_InvMass_Pt",1000,0,1,250,0,25);
+         fESDList[iCut]->Add(hESDMotherBackInvMassPt[iCut]);
+         hESDMotherInvMassEalpha[iCut] = new TH2F("ESD_Mother_InvMass_vs_E_alpha","ESD_Mother_InvMass_vs_E_alpha",1000,0,1,250,0,25);
+         fESDList[iCut]->Add(hESDMotherInvMassEalpha[iCut]);
+      }
+
+      fCutFolder[iCut]->Add(fESDList[iCut]);
+   }
+
+   if(fDoMesonAnalysis){
+      InitBack(); // Init Background Handler
+   }
+
+   if(MCEvent()){
+      // MC Histogramms
+      fMCList = new TList*[fnCuts];
+      // True Histogramms
+      fTrueList = new TList*[fnCuts];
+
+      hMCAllGammaPt = new TH1F*[fnCuts];
+               hMCAllGammaPtAddedSig = new TH1F*[fnCuts];
+      hMCDecayGammaPi0Pt = new TH1F*[fnCuts];
+               hMCDecayGammaPi0PtAddedSig = new TH1F*[fnCuts];
+      hMCDecayGammaRhoPt = new TH1F*[fnCuts];
+      hMCDecayGammaRhoPtAddedSig = new TH1F*[fnCuts];
+               hMCDecayGammaEtaPt = new TH1F*[fnCuts];
+               hMCDecayGammaEtaPtAddedSig = new TH1F*[fnCuts];
+      hMCDecayGammaOmegaPt = new TH1F*[fnCuts];
+               hMCDecayGammaOmegaPtAddedSig = new TH1F*[fnCuts];
+      hMCDecayGammaEtapPt = new TH1F*[fnCuts];
+               hMCDecayGammaEtapPtAddedSig = new TH1F*[fnCuts];
+      hMCDecayGammaPhiPt = new TH1F*[fnCuts];
+               hMCDecayGammaPhiPtAddedSig = new TH1F*[fnCuts];
+      hMCConvGammaPt = new TH1F*[fnCuts];
+               hMCConvGammaPtAddedSig = new TH1F*[fnCuts];
+      hESDTrueConvGammaPt = new TH1F*[fnCuts];
+               hESDTrueConvGammaPtAddedSig = new TH1F*[fnCuts];
+      hESDTrueElecCombPt = new TH1F*[fnCuts];
+          hESDTruePionCombPt = new TH1F*[fnCuts];
+          hESDTruePrimaryConvGammaPt = new TH1F*[fnCuts];
+               hESDTruePrimaryConvGammaPtAddedSig = new TH1F*[fnCuts];
+      hESDTruePrimaryConvGammaESDPtMCPt = new TH2F*[fnCuts];
+               hESDTruePrimaryConvGammaESDPtMCPtAddedSig = new TH2F*[fnCuts];
+      hESDTrueSecondaryConvGammaPt = new TH1F*[fnCuts];
+               hESDTrueSecondaryConvGammaPtAddedSig = new TH1F*[fnCuts];
+      hESDTrueSecondaryConvGammaFromK0sPt = new TH1F*[fnCuts];
+               hESDTrueSecondaryConvGammaFromK0sPtAddedSig = new TH1F*[fnCuts];
+      hESDTrueSecondaryConvGammaFromXFromK0sPt = new TH1F*[fnCuts];
+               hESDTrueSecondaryConvGammaFromXFromK0sPtAddedSig = new TH1F*[fnCuts];
+               
+      if(fDoMesonAnalysis){
+         hMCPi0Pt = new TH1F*[fnCuts];
+         hMCEtaPt = new TH1F*[fnCuts];
+         hMCPi0InAccPt = new TH1F*[fnCuts];
+         hMCEtaInAccPt = new TH1F*[fnCuts];
+                       hMCPi0PtAddedSig = new TH1F*[fnCuts];
+         hMCEtaPtAddedSig = new TH1F*[fnCuts];
+         hMCPi0InAccPtAddedSig = new TH1F*[fnCuts];
+         hMCEtaInAccPtAddedSig = new TH1F*[fnCuts];
+
+         hESDTrueMotherInvMassPt = new TH2F*[fnCuts];
+                       hESDTrueMotherInvMassPtAddedSig = new TH2F*[fnCuts];
+         hESDTruePrimaryPi0ESDPtMCPt = new TH2F*[fnCuts];
+                       hESDTruePrimaryPi0ESDPtMCPtAddedSig = new TH2F*[fnCuts];
+         hESDTruePrimaryMotherInvMassMCPt = new TH2F*[fnCuts];
+                       hESDTruePrimaryMotherInvMassMCPtAddedSig = new TH2F*[fnCuts];
+         hESDTrueSecondaryMotherInvMassPt = new TH2F*[fnCuts];
+                       hESDTrueSecondaryMotherInvMassPtAddedSig = new TH2F*[fnCuts];
+         hESDTrueSecondaryMotherFromK0sInvMassPt = new TH2F*[fnCuts];
+                       hESDTrueSecondaryMotherFromK0sInvMassPtAddedSig = new TH2F*[fnCuts];
+         hESDTrueBckGGInvMassPt = new TH2F*[fnCuts];
+         hESDTrueBckContInvMassPt = new TH2F*[fnCuts];
+         hESDTrueMotherDalitzInvMassPt = new TH2F*[fnCuts];
+                       hESDTrueMotherDalitzInvMassPtAddedSig = new TH2F*[fnCuts];
+      }
+
+      for(Int_t iCut = 0; iCut<fnCuts;iCut++){
+         TString cutstring = ((AliConversionCuts*)fCutArray->At(iCut))->GetCutNumber();
+         fMCList[iCut] = new TList();
+         fMCList[iCut]->SetName(Form("%s MC histograms",cutstring.Data()));
+         fMCList[iCut]->SetOwner(kTRUE);
+         fCutFolder[iCut]->Add(fMCList[iCut]);
+
+         hMCAllGammaPt[iCut] = new TH1F("MC_AllGamma_Pt","MC_AllGamma_Pt",250,0,25);
+         fMCList[iCut]->Add(hMCAllGammaPt[iCut]);
+                       hMCAllGammaPtAddedSig[iCut] = new TH1F("MC_AllGamma_Pt_AddedSig","MC_AllGamma_Pt_AddedSig",250,0,25);
+         fMCList[iCut]->Add(hMCAllGammaPtAddedSig[iCut]);
+         hMCDecayGammaPi0Pt[iCut] = new TH1F("MC_DecayGammaPi0_Pt","MC_DecayGammaPi0_Pt",250,0,25);
+         fMCList[iCut]->Add(hMCDecayGammaPi0Pt[iCut]);
+         hMCDecayGammaPi0PtAddedSig[iCut] = new TH1F("MC_DecayGammaPi0_Pt_AddedSig","MC_DecayGammaPi0_Pt_AddedSig",250,0,25);
+         fMCList[iCut]->Add(hMCDecayGammaPi0PtAddedSig[iCut]);
+         hMCDecayGammaRhoPt[iCut] = new TH1F("MC_DecayGammaRho_Pt","MC_DecayGammaRho_Pt",250,0,25);
+         fMCList[iCut]->Add(hMCDecayGammaRhoPt[iCut]);
+         hMCDecayGammaRhoPtAddedSig[iCut] = new TH1F("MC_DecayGammaRho_Pt_AddedSig","MC_DecayGammaRho_Pt_AddedSig",250,0,25);
+         fMCList[iCut]->Add(hMCDecayGammaRhoPtAddedSig[iCut]);
+         hMCDecayGammaEtaPt[iCut] = new TH1F("MC_DecayGammaEta_Pt","MC_DecayGammaEta_Pt",250,0,25);
+         fMCList[iCut]->Add(hMCDecayGammaEtaPt[iCut]);
+         hMCDecayGammaEtaPtAddedSig[iCut] = new TH1F("MC_DecayGammaEta_Pt_AddedSig","MC_DecayGammaEta_Pt_AddedSig",250,0,25);
+         fMCList[iCut]->Add(hMCDecayGammaEtaPtAddedSig[iCut]);
+         hMCDecayGammaOmegaPt[iCut] = new TH1F("MC_DecayGammaOmega_Pt","MC_DecayGammaOmmega_Pt",250,0,25);
+         fMCList[iCut]->Add(hMCDecayGammaOmegaPt[iCut]);
+         hMCDecayGammaOmegaPtAddedSig[iCut] = new TH1F("MC_DecayGammaOmega_Pt_AddedSig","MC_DecayGammaOmmega_Pt_AddedSig",250,0,25);
+         fMCList[iCut]->Add(hMCDecayGammaOmegaPtAddedSig[iCut]);
+         hMCDecayGammaEtapPt[iCut] = new TH1F("MC_DecayGammaEtap_Pt","MC_DecayGammaEtap_Pt",250,0,25);
+         fMCList[iCut]->Add(hMCDecayGammaEtapPt[iCut]);
+         hMCDecayGammaEtapPtAddedSig[iCut] = new TH1F("MC_DecayGammaEtap_Pt_AddedSig","MC_DecayGammaEtap_Pt_AddedSig",250,0,25);
+         fMCList[iCut]->Add(hMCDecayGammaEtapPtAddedSig[iCut]);
+         hMCDecayGammaPhiPt[iCut] = new TH1F("MC_DecayGammaPhi_Pt","MC_DecayGammaPhi_Pt",250,0,25);
+         fMCList[iCut]->Add(hMCDecayGammaPhiPt[iCut]);
+         hMCDecayGammaPhiPtAddedSig[iCut] = new TH1F("MC_DecayGammaPhi_Pt_AddedSig","MC_DecayGammaPhi_Pt_AddedSig",250,0,25);
+         fMCList[iCut]->Add(hMCDecayGammaPhiPtAddedSig[iCut]);
+         hMCConvGammaPt[iCut] = new TH1F("MC_ConvGamma_Pt","MC_ConvGamma_Pt",250,0,25);
+         fMCList[iCut]->Add(hMCConvGammaPt[iCut]);
+         hMCConvGammaPtAddedSig[iCut] = new TH1F("MC_ConvGamma_Pt_AddedSig","MC_ConvGamma_Pt_AddedSig",250,0,25);
+         fMCList[iCut]->Add(hMCConvGammaPtAddedSig[iCut]);
+         if(fDoMesonAnalysis){
+            hMCPi0Pt[iCut] = new TH1F("MC_Pi0_Pt","MC_Pi0_Pt",250,0,25);
+            fMCList[iCut]->Add(hMCPi0Pt[iCut]);
+            hMCEtaPt[iCut] = new TH1F("MC_Eta_Pt","MC_Eta_Pt",250,0,25);
+            fMCList[iCut]->Add(hMCEtaPt[iCut]);
+            hMCPi0InAccPt[iCut] = new TH1F("MC_Pi0InAcc_Pt","MC_Pi0InAcc_Pt",250,0,25);
+            fMCList[iCut]->Add(hMCPi0InAccPt[iCut]);
+            hMCEtaInAccPt[iCut] = new TH1F("MC_EtaInAcc_Pt","MC_EtaInAcc_Pt",250,0,25);
+            fMCList[iCut]->Add(hMCEtaInAccPt[iCut]);
+                               hMCPi0PtAddedSig[iCut] = new TH1F("MC_Pi0_Pt_AddedSig","MC_Pi0_Pt_AddedSig",250,0,25);
+            fMCList[iCut]->Add(hMCPi0PtAddedSig[iCut]);
+            hMCEtaPtAddedSig[iCut] = new TH1F("MC_Eta_Pt_AddedSig","MC_Eta_Pt_AddedSig",250,0,25);
+            fMCList[iCut]->Add(hMCEtaPtAddedSig[iCut]);
+            hMCPi0InAccPtAddedSig[iCut] = new TH1F("MC_Pi0InAcc_Pt_AddedSig","MC_Pi0InAcc_Pt_AddedSig",250,0,25);
+            fMCList[iCut]->Add(hMCPi0InAccPtAddedSig[iCut]);
+            hMCEtaInAccPtAddedSig[iCut] = new TH1F("MC_EtaInAcc_Pt_AddedSig","MC_EtaInAcc_Pt_AddedSig",250,0,25);
+            fMCList[iCut]->Add(hMCEtaInAccPtAddedSig[iCut]);
+         }
+         fTrueList[iCut] = new TList();
+         fTrueList[iCut]->SetName(Form("%s True histograms",cutstring.Data()));
+         fTrueList[iCut]->SetOwner(kTRUE);
+         fCutFolder[iCut]->Add(fTrueList[iCut]);
+
+         hESDTrueConvGammaPt[iCut] = new TH1F("ESD_TrueConvGamma_Pt","ESD_TrueConvGamma_Pt",250,0,25);
+         fTrueList[iCut]->Add(hESDTrueConvGammaPt[iCut]);
+                       hESDTrueConvGammaPtAddedSig[iCut] = new TH1F("ESD_TrueConvGamma_Pt_AddedSig","ESD_TrueConvGamma_Pt_AddedSig",250,0,25);
+         fTrueList[iCut]->Add(hESDTrueConvGammaPtAddedSig[iCut]);
+         hESDTrueElecCombPt[iCut] = new TH1F("ESD_TrueElecComb_Pt","ESD_TrueElecComb_Pt",250,0,25);
+         fTrueList[iCut]->Add(hESDTrueElecCombPt[iCut]);
+         hESDTruePionCombPt[iCut] = new TH1F("ESD_TruePionComb_Pt","ESD_TruePionComb_Pt",250,0,25);
+         fTrueList[iCut]->Add(hESDTruePionCombPt[iCut]);
+         hESDTruePrimaryConvGammaPt[iCut] = new TH1F("ESD_TruePrimaryConvGamma_Pt","ESD_TruePrimaryConvGamma_Pt",250,0,25);
+         fTrueList[iCut]->Add(hESDTruePrimaryConvGammaPt[iCut]);
+         hESDTruePrimaryConvGammaPtAddedSig[iCut] = new TH1F("ESD_TruePrimaryConvGamma_Pt_AddedSig","ESD_TruePrimaryConvGamma_Pt_AddedSig",250,0,25);
+         fTrueList[iCut]->Add(hESDTruePrimaryConvGammaPtAddedSig[iCut]);
+         hESDTrueSecondaryConvGammaPt[iCut] = new TH1F("ESD_TrueSecondaryConvGamma_Pt","ESD_TrueSecondaryConvGamma_Pt",250,0,25);
+         fTrueList[iCut]->Add(hESDTrueSecondaryConvGammaPt[iCut]);
+         hESDTrueSecondaryConvGammaPtAddedSig[iCut] = new TH1F("ESD_TrueSecondaryConvGamma_Pt_AddedSig", "ESD_TrueSecondaryConvGamma_Pt_AddedSig",250,0,25);
+         fTrueList[iCut]->Add(hESDTrueSecondaryConvGammaPtAddedSig[iCut]);
+         hESDTrueSecondaryConvGammaFromK0sPt[iCut] = new TH1F("ESD_TrueSecondaryConvGammaFromK0s_Pt","ESD_TrueSecondaryConvGammaFromK0s_Pt",250,0,25);
+         fTrueList[iCut]->Add(hESDTrueSecondaryConvGammaFromK0sPt[iCut]);
+         hESDTrueSecondaryConvGammaFromK0sPtAddedSig[iCut] = new TH1F("ESD_TrueSecondaryConvGammaFromK0s_Pt_AddedSig", "ESD_TrueSecondaryConvGammaFromK0s_Pt_AddedSig",250,0,25);
+         fTrueList[iCut]->Add(hESDTrueSecondaryConvGammaFromK0sPtAddedSig[iCut]);
+         hESDTrueSecondaryConvGammaFromXFromK0sPt[iCut] = new TH1F("ESD_TrueSecondaryConvGammaFromXFromK0s_Pt", "ESD_TrueSecondaryConvGammaFromXFromK0s_Pt",250,0,25);
+         fTrueList[iCut]->Add(hESDTrueSecondaryConvGammaFromXFromK0sPt[iCut]);
+         hESDTrueSecondaryConvGammaFromXFromK0sPtAddedSig[iCut] = new TH1F("ESD_TrueSecondaryConvGammaFromXFromK0s_Pt_AddedSig", "ESD_TrueSecondaryConvGammaFromXFromK0s_Pt_AddedSig",250,0,25);
+         fTrueList[iCut]->Add(hESDTrueSecondaryConvGammaFromXFromK0sPtAddedSig[iCut]);
+         hESDTruePrimaryConvGammaESDPtMCPt[iCut] = new TH2F("ESD_TruePrimaryConvGammaESD_PtMCPt", "ESD_TruePrimaryConvGammaESD_PtMCPt",250,0,25,250,0,25);
+         fTrueList[iCut]->Add(hESDTruePrimaryConvGammaESDPtMCPt[iCut]);
+                       hESDTruePrimaryConvGammaESDPtMCPtAddedSig[iCut] = new TH2F("ESD_TruePrimaryConvGammaESD_PtMCPt_AddedSig", "ESD_TruePrimaryConvGammaESD_PtMCPt_AddedSig",250,0,25,250,0,25);
+         fTrueList[iCut]->Add(hESDTruePrimaryConvGammaESDPtMCPtAddedSig[iCut]);
+
+         if(fDoMesonAnalysis){
+            hESDTrueMotherInvMassPt[iCut] = new TH2F("ESD_TrueMother_InvMass_Pt","ESD_TrueMother_InvMass_Pt",1000,0,1,250,0,25);
+            fTrueList[iCut]->Add(hESDTrueMotherInvMassPt[iCut]);
+                               hESDTrueMotherInvMassPtAddedSig[iCut] = new TH2F("ESD_TrueMother_InvMass_Pt_AddedSig", "ESD_TrueMother_InvMass_Pt_AddedSig", 1000,0,1,250,0,25);
+            fTrueList[iCut]->Add(hESDTrueMotherInvMassPtAddedSig[iCut]);
+            hESDTruePrimaryPi0ESDPtMCPt[iCut] = new TH2F("ESD_TruePrimaryPi0_ESDPt_MCPt","ESD_TruePrimaryPi0_ESDPt_MCPt",250,0,25,250,0,25);
+            fTrueList[iCut]->Add(hESDTruePrimaryPi0ESDPtMCPt[iCut]);
+            hESDTruePrimaryPi0ESDPtMCPtAddedSig[iCut] = new TH2F("ESD_TruePrimaryPi0_ESDPt_MCPt_AddedSig", "ESD_TruePrimaryPi0_ESDPt_MCPt_AddedSig", 250,0,25,250,0,25);
+            fTrueList[iCut]->Add(hESDTruePrimaryPi0ESDPtMCPtAddedSig[iCut]);
+            hESDTruePrimaryMotherInvMassMCPt[iCut] = new TH2F("ESD_TruePrimaryMother_InvMass_MCPt", "ESD_TruePrimaryMother_InvMass_MCPt", 1000,0,1,250,0,25);
+            fTrueList[iCut]->Add(hESDTruePrimaryMotherInvMassMCPt[iCut]);
+            hESDTruePrimaryMotherInvMassMCPtAddedSig[iCut] = new TH2F("ESD_TruePrimaryMother_InvMass_MCPt_AddedSig", "ESD_TruePrimaryMother_InvMass_MCPt_AddedSig", 1000,0,1,250,0,25);
+            fTrueList[iCut]->Add(hESDTruePrimaryMotherInvMassMCPtAddedSig[iCut]);
+            hESDTrueSecondaryMotherInvMassPt[iCut] = new TH2F("ESD_TrueSecondaryMother_InvMass_Pt", "ESD_TrueSecondaryMother_InvMass_Pt", 1000,0,1,250,0,25);
+            fTrueList[iCut]->Add(hESDTrueSecondaryMotherInvMassPt[iCut]);
+            hESDTrueSecondaryMotherFromK0sInvMassPt[iCut] = new TH2F("ESD_TrueSecondaryMotherFromK0s_InvMass_Pt","ESD_TrueSecondaryMotherFromK0s_InvMass_Pt",1000,0,1,250,0,25);
+            fTrueList[iCut]->Add(hESDTrueSecondaryMotherFromK0sInvMassPt[iCut]);
+            hESDTrueSecondaryMotherInvMassPtAddedSig[iCut] = new TH2F("ESD_TrueSecondaryMother_InvMass_Pt_AddedSig","ESD_TrueSecondaryMother_InvMass_Pt_AddedSig",1000,0,1,250,0,25);
+            fTrueList[iCut]->Add(hESDTrueSecondaryMotherInvMassPtAddedSig[iCut]);
+            hESDTrueSecondaryMotherFromK0sInvMassPtAddedSig[iCut] = new TH2F("ESD_TrueSecondaryMotherFromK0s_InvMass_Pt_AddedSig","ESD_TrueSecondaryMotherFromK0s_InvMass_Pt_AddedSig",1000,0,1,250,0,25);
+            fTrueList[iCut]->Add(hESDTrueSecondaryMotherFromK0sInvMassPtAddedSig[iCut]);
+                               hESDTrueBckGGInvMassPt[iCut] = new TH2F("ESD_TrueBckGG_InvMass_Pt","ESD_TrueBckGG_InvMass_Pt",1000,0,1,250,0,25);
+            fTrueList[iCut]->Add(hESDTrueBckGGInvMassPt[iCut]);
+                hESDTrueBckContInvMassPt[iCut] = new TH2F("ESD_TrueBckCont_InvMass_Pt","ESD_TrueBckCont_InvMass_Pt",1000,0,1,250,0,25);
+            fTrueList[iCut]->Add(hESDTrueBckContInvMassPt[iCut]);
+            hESDTrueMotherDalitzInvMassPt[iCut] = new TH2F("ESD_TrueDalitz_InvMass_Pt","ESD_TrueDalitz_InvMass_Pt",1000,0,1,250,0,25);
+            fTrueList[iCut]->Add(hESDTrueMotherDalitzInvMassPt[iCut]);
+            hESDTrueMotherDalitzInvMassPtAddedSig[iCut] = new TH2F("ESD_TrueDalitz_InvMass_Pt_AddedSig", "ESD_TrueDalitz_InvMass_Pt_AddedSig", 1000,0,1,250,0,25);
+            fTrueList[iCut]->Add(hESDTrueMotherDalitzInvMassPtAddedSig[iCut]);
+
+         }
+      }
+   }
+
+   PostData(1, fOutputContainer);
+}
+
+//_____________________________________________________________________________
+void AliAnalysisTaskGammaConvV1::UserExec(Option_t *)
+{
+   //
+   // Called for each event
+   //
+   fV0Reader=(AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask("V0ReaderV1");
+   if(!fV0Reader){printf("Error: No V0 Reader");return;} // GetV0Reader
+
+   Int_t eventQuality = ((AliConversionCuts*)fV0Reader->GetConversionCuts())->GetEventQuality();
+   if(eventQuality != 0){// Event Not Accepted
+      for(Int_t iCut = 0; iCut<fnCuts; iCut++){
+         hNEvents[iCut]->Fill(eventQuality);
+      }
+      return;
+   }
+
+   fMCEvent = MCEvent();
+   fESDEvent = (AliESDEvent*) InputEvent();
+   fReaderGammas = fV0Reader->GetReconstructedGammas(); // Gammas from default Cut
+   CountESDTracks(); // Estimate Event Multiplicity
+
+   for(Int_t iCut = 0; iCut<fnCuts; iCut++){
+      fiCut = iCut;
+      if(fIsHeavyIon && !((AliConversionCuts*)fCutArray->At(iCut))->IsCentralitySelected(fESDEvent)){
+         hNEvents[iCut]->Fill(1); // Check Centrality --> Not Accepted => eventQuality = 1
+         continue;
+      }
+      hNEvents[iCut]->Fill(eventQuality);
+
+      hNGoodESDTracks[iCut]->Fill(fNumberOfESDTracks);
+               hNV0Tracks[iCut]->Fill(fESDEvent->GetVZEROData()->GetMTotV0A()+fESDEvent->GetVZEROData()->GetMTotV0C());
+      if(fMCEvent){ // Process MC Particle
+         fMCStack = fMCEvent->Stack();
+         ProcessMCParticles();
+      }
+
+      ProcessPhotonCandidates(); // Process this cuts gammas
+
+      if(fDoMesonAnalysis){ // Meson Analysis
+         if(((AliConversionCuts*)fCutArray->At(iCut))->UseMCPSmearing() && fMCEvent){
+            fUnsmearedPx = new Double_t[fGoodGammas->GetEntries()]; // Store unsmeared Momenta
+            fUnsmearedPy = new Double_t[fGoodGammas->GetEntries()];
+            fUnsmearedPz = new Double_t[fGoodGammas->GetEntries()];
+            fUnsmearedE =  new Double_t[fGoodGammas->GetEntries()];
+
+            for(Int_t gamma=0;gamma<fGoodGammas->GetEntries();gamma++){ // Smear the AODPhotons in MC
+               fUnsmearedPx[gamma] = ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->Px();
+               fUnsmearedPy[gamma] = ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->Py();
+               fUnsmearedPz[gamma] = ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->Pz();
+               fUnsmearedE[gamma] =  ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->E();
+               ((AliConversionCuts*)fCutArray->At(iCut))->SmearParticle(dynamic_cast<AliAODConversionPhoton*>(fGoodGammas->At(gamma)));
+            }
+         }
+         CalculatePi0Candidates(); // Combine Gammas
+         CalculateBackground(); // Combinatorial Background
+         UpdateEventByEventData(); // Store Event for mixed Events
+
+         if(((AliConversionCuts*)fCutArray->At(iCut))->UseMCPSmearing() && fMCEvent){
+            for(Int_t gamma=0;gamma<fGoodGammas->GetEntries();gamma++){ // Smear the AODPhotons in MC
+               ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->SetPx(fUnsmearedPx[gamma]); // Reset Unsmeared Momenta
+               ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->SetPy(fUnsmearedPy[gamma]);
+               ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->SetPz(fUnsmearedPz[gamma]);
+               ((AliAODConversionPhoton*)fGoodGammas->At(gamma))->SetE(fUnsmearedE[gamma]);
+            }
+            delete[] fUnsmearedPx; fUnsmearedPx = 0x0;
+            delete[] fUnsmearedPy; fUnsmearedPy = 0x0;
+            delete[] fUnsmearedPz; fUnsmearedPz = 0x0;
+            delete[] fUnsmearedE;  fUnsmearedE  = 0x0;
+         }
+      }
+      fGoodGammas->Clear(); // delete this cuts good gammas
+   }
+
+   PostData(1, fOutputContainer);
+}
+//________________________________________________________________________
+void AliAnalysisTaskGammaConvV1::ProcessPhotonCandidates()
+{
+   Int_t nV0 = 0;
+   TList *GoodGammasStepOne = new TList();
+   TList *GoodGammasStepTwo = new TList();
+   // Loop over Photon Candidates allocated by ReaderV1
+   for(Int_t i = 0; i < fReaderGammas->GetEntriesFast(); i++){
+      AliAODConversionPhoton* PhotonCandidate = (AliAODConversionPhoton*) fReaderGammas->At(i);
+      if(!PhotonCandidate) continue;
+      if(!((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelected(PhotonCandidate,fESDEvent)) continue;
+      
+      if(!((AliConversionCuts*)fCutArray->At(fiCut))->UseElecSharingCut() && 
+         !((AliConversionCuts*)fCutArray->At(fiCut))->UseToCloseV0sCut()){ // if no post reader loop is required add to events good gammas
+         fGoodGammas->Add(PhotonCandidate);
+         hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt());
+         if(fMCEvent){
+            ProcessTruePhotonCandidates(PhotonCandidate);
+         }
+      }
+      else if(((AliConversionCuts*)fCutArray->At(fiCut))->UseElecSharingCut()){ // if Shared Electron cut is enabled, Fill array, add to step one
+         ((AliConversionCuts*)fCutArray->At(fiCut))->FillElectonLabelArray(PhotonCandidate,nV0);
+         nV0++;
+         GoodGammasStepOne->Add(PhotonCandidate);
+      }
+      else if(!((AliConversionCuts*)fCutArray->At(fiCut))->UseElecSharingCut() && 
+              ((AliConversionCuts*)fCutArray->At(fiCut))->UseToCloseV0sCut()){ // shared electron is disabled, step one not needed -> step two
+         GoodGammasStepTwo->Add(PhotonCandidate);
+      }
+   }
+   if(((AliConversionCuts*)fCutArray->At(fiCut))->UseElecSharingCut()){
+      for(Int_t i = 0;i<GoodGammasStepOne->GetEntries();i++){
+         AliAODConversionPhoton *PhotonCandidate= (AliAODConversionPhoton*) GoodGammasStepOne->At(i);
+         if(!PhotonCandidate) continue;
+         if(!((AliConversionCuts*)fCutArray->At(fiCut))->RejectSharedElectronV0s(PhotonCandidate,i,GoodGammasStepOne->GetEntries())) continue;
+         if(!((AliConversionCuts*)fCutArray->At(fiCut))->UseToCloseV0sCut()){ // To Colse v0s cut diabled, step two not needed 
+            fGoodGammas->Add(PhotonCandidate);
+            hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt());
+            if(fMCEvent){
+               ProcessTruePhotonCandidates(PhotonCandidate);
+            }
+         }
+         else GoodGammasStepTwo->Add(PhotonCandidate); // Close v0s cut enabled -> add to list two
+      }
+   }
+   if(((AliConversionCuts*)fCutArray->At(fiCut))->UseToCloseV0sCut()){
+      for(Int_t i = 0;i<GoodGammasStepTwo->GetEntries();i++){
+         AliAODConversionPhoton* PhotonCandidate = (AliAODConversionPhoton*) GoodGammasStepTwo->At(i);
+         if(!PhotonCandidate) continue;
+         if(!((AliConversionCuts*)fCutArray->At(fiCut))->RejectToCloseV0s(PhotonCandidate,GoodGammasStepTwo,i)) continue;
+         fGoodGammas->Add(PhotonCandidate); // Add gamma to current cut TList
+         hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt()); // Differences to old V0Reader in p_t due to conversion KF->TLorentzVector
+         if(fMCEvent){
+            ProcessTruePhotonCandidates(PhotonCandidate);
+         }
+      }
+   }
+
+   delete GoodGammasStepOne;
+   GoodGammasStepOne = 0x0;
+   delete GoodGammasStepTwo;
+   GoodGammasStepTwo = 0x0;
+
+}
+//________________________________________________________________________
+void AliAnalysisTaskGammaConvV1::ProcessTruePhotonCandidates(AliAODConversionPhoton *TruePhotonCandidate)
+{
+   // Process True Photons
+   AliStack *MCStack = fMCEvent->Stack();
+   TParticle *posDaughter = TruePhotonCandidate->GetPositiveMCDaughter(MCStack);
+   TParticle *negDaughter = TruePhotonCandidate->GetNegativeMCDaughter(MCStack);
+
+   if(posDaughter == NULL || negDaughter == NULL) return; // One particle does not exist
+   if(posDaughter->GetMother(0) != negDaughter->GetMother(0)){  // Not Same Mother == Combinatorial Bck
+      if(TMath::Abs(posDaughter->GetPdgCode())==11 && TMath::Abs(negDaughter->GetPdgCode())==11)
+         hESDTrueElecCombPt[fiCut]->Fill(TruePhotonCandidate->Pt()); //Electron Combinatorial
+      if(TMath::Abs(posDaughter->GetPdgCode())==211 || TMath::Abs(negDaughter->GetPdgCode())==211)
+         hESDTruePionCombPt[fiCut]->Fill(TruePhotonCandidate->Pt()); //At least on Pion Combinatorial
+      return;
+   }
+   if(TMath::Abs(posDaughter->GetPdgCode())!=11 || TMath::Abs(negDaughter->GetPdgCode())!=11) return; //One Particle is not electron
+   if(posDaughter->GetPdgCode()==negDaughter->GetPdgCode()) return; // Same Charge
+   if(posDaughter->GetUniqueID() != 5 || negDaughter->GetUniqueID() !=5) return;// check if the daughters come from a conversion
+
+   TParticle *Photon = TruePhotonCandidate->GetMCParticle(MCStack);
+   if(Photon->GetPdgCode() != 22) return; // Mother is no Photon
+
+       if (!fMCEvent->IsFromBGEvent(TruePhotonCandidate->GetMCParticleLabel(fMCStack)) && fIsHeavyIon){
+      // True Photon
+               hESDTrueConvGammaPtAddedSig[fiCut]->Fill(TruePhotonCandidate->Pt());
+
+               if(posDaughter->GetMother(0) <= MCStack->GetNprimary()){
+                       // Count just primary MC Gammas as true --> For Ratio esdtruegamma / mcconvgamma
+                       hESDTruePrimaryConvGammaPtAddedSig[fiCut]->Fill(TruePhotonCandidate->Pt());
+                       hESDTruePrimaryConvGammaESDPtMCPtAddedSig[fiCut]->Fill(TruePhotonCandidate->Pt(),Photon->Pt());
+               }
+               else{
+                       hESDTrueSecondaryConvGammaPtAddedSig[fiCut]->Fill(TruePhotonCandidate->Pt());
+                       if(MCStack->Particle(Photon->GetMother(0))->GetPdgCode() == 310){
+                               hESDTrueSecondaryConvGammaFromK0sPtAddedSig[fiCut]->Fill(TruePhotonCandidate->Pt());
+                       }
+                       if(MCStack->Particle(Photon->GetMother(0))->GetMother(0) > -1 &&
+                               MCStack->Particle(MCStack->Particle(Photon->GetMother(0))->GetMother(0))->GetPdgCode() == 310){
+                               hESDTrueSecondaryConvGammaFromXFromK0sPtAddedSig[fiCut]->Fill(TruePhotonCandidate->Pt());
+                       }
+               }
+       } else {
+      // True Photon
+               hESDTrueConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
+
+               if(posDaughter->GetMother(0) <= MCStack->GetNprimary()){
+                       // Count just primary MC Gammas as true --> For Ratio esdtruegamma / mcconvgamma
+                       hESDTruePrimaryConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
+                       hESDTruePrimaryConvGammaESDPtMCPt[fiCut]->Fill(TruePhotonCandidate->Pt(),Photon->Pt());
+               }
+               else{
+                       hESDTrueSecondaryConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
+                       if(MCStack->Particle(Photon->GetMother(0))->GetPdgCode() == 310){
+                               hESDTrueSecondaryConvGammaFromK0sPt[fiCut]->Fill(TruePhotonCandidate->Pt());
+                       }
+                       if(MCStack->Particle(Photon->GetMother(0))->GetMother(0) > -1 &&
+                               MCStack->Particle(MCStack->Particle(Photon->GetMother(0))->GetMother(0))->GetPdgCode() == 310){
+                               hESDTrueSecondaryConvGammaFromXFromK0sPt[fiCut]->Fill(TruePhotonCandidate->Pt());
+                       }
+               }               
+       }
+}
+//________________________________________________________________________
+void AliAnalysisTaskGammaConvV1::ProcessMCParticles()
+{
+
+   // Loop over all primary MC particle
+   for(Int_t i = 0; i < fMCStack->GetNprimary(); i++) {
+      TParticle* particle = (TParticle *)fMCStack->Particle(i);
+      if (!particle) continue;
+
+               if (!fMCEvent->IsFromBGEvent(i) && fIsHeavyIon){
+                       if(((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelectedMC(particle,fMCStack,kFALSE)){
+                               hMCAllGammaPtAddedSig[fiCut]->Fill(particle->Pt()); // All MC Gamma
+                               if(particle->GetMother(0) >-1){ // Meson Decay Gamma
+                                       switch(fMCStack->Particle(particle->GetMother(0))->GetPdgCode()){
+                                       case 111: // Pi0
+                                               hMCDecayGammaPi0PtAddedSig[fiCut]->Fill(particle->Pt());
+                                               break;
+                                       case 113: // Rho0
+                                               hMCDecayGammaRhoPtAddedSig[fiCut]->Fill(particle->Pt());
+                                               break;
+                                       case 221: // Eta
+                                               hMCDecayGammaEtaPtAddedSig[fiCut]->Fill(particle->Pt());
+                                               break;
+                                       case 223: // Omega
+                                               hMCDecayGammaOmegaPtAddedSig[fiCut]->Fill(particle->Pt());
+                                               break;
+                                       case 331: // Eta'
+                                               hMCDecayGammaEtapPtAddedSig[fiCut]->Fill(particle->Pt());
+                                               break;
+                                       case 333: // Phi
+                                               hMCDecayGammaPhiPtAddedSig[fiCut]->Fill(particle->Pt());
+                                               break;
+                                       }
+                               }
+                       }
+                       if(((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelectedMC(particle,fMCStack,kTRUE)){
+                               hMCConvGammaPtAddedSig[fiCut]->Fill(particle->Pt());
+                       } // Converted MC Gamma
+                       if(fDoMesonAnalysis){
+                               if(((AliConversionCuts*)fCutArray->At(fiCut))->MesonIsSelectedMC(particle,fMCStack,kFALSE)){
+                                       if(particle->GetPdgCode() == 111)hMCPi0PtAddedSig[fiCut]->Fill(particle->Pt()); // All MC Pi0
+                                       if(particle->GetPdgCode() == 221)hMCEtaPtAddedSig[fiCut]->Fill(particle->Pt()); // All MC Eta
+                                       // Check the acceptance for both gammas
+                                       if(particle->GetNDaughters() == 2){
+                                               TParticle* daughter0 = (TParticle*)fMCStack->Particle(particle->GetFirstDaughter());
+                                               TParticle* daughter1 = (TParticle*)fMCStack->Particle(particle->GetLastDaughter());
+                                               if(((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelectedMC(daughter0,fMCStack,kFALSE) &&
+                                                       ((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelectedMC(daughter1,fMCStack,kFALSE) ){
+                                                       if(particle->GetPdgCode() == 111)hMCPi0InAccPtAddedSig[fiCut]->Fill(particle->Pt()); // MC Pi0 with gamma in acc
+                                                       if(particle->GetPdgCode() == 221)hMCEtaInAccPtAddedSig[fiCut]->Fill(particle->Pt()); // MC Eta with gamma in acc
+                                               }
+                                       }
+                               }
+                       }
+               } else {
+                       if(((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelectedMC(particle,fMCStack,kFALSE)){
+                               hMCAllGammaPt[fiCut]->Fill(particle->Pt()); // All MC Gamma
+                               if(particle->GetMother(0) >-1){ // Meson Decay Gamma
+                                       switch(fMCStack->Particle(particle->GetMother(0))->GetPdgCode()){
+                                       case 111: // Pi0
+                                               hMCDecayGammaPi0Pt[fiCut]->Fill(particle->Pt());
+                                               break;
+                                       case 113: // Rho0
+                                               hMCDecayGammaRhoPt[fiCut]->Fill(particle->Pt());
+                                               break;
+                                       case 221: // Eta
+                                               hMCDecayGammaEtaPt[fiCut]->Fill(particle->Pt());
+                                               break;
+                                       case 223: // Omega
+                                               hMCDecayGammaOmegaPt[fiCut]->Fill(particle->Pt());
+                                               break;
+                                       case 331: // Eta'
+                                               hMCDecayGammaEtapPt[fiCut]->Fill(particle->Pt());
+                                               break;
+                                       case 333: // Phi
+                                               hMCDecayGammaPhiPt[fiCut]->Fill(particle->Pt());
+                                               break;
+                                       }
+                               }
+                       }
+                       if(((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelectedMC(particle,fMCStack,kTRUE)){
+                               hMCConvGammaPt[fiCut]->Fill(particle->Pt());
+                       } // Converted MC Gamma
+                       if(fDoMesonAnalysis){
+                               if(((AliConversionCuts*)fCutArray->At(fiCut))->MesonIsSelectedMC(particle,fMCStack,kFALSE)){
+                                       if(particle->GetPdgCode() == 111)hMCPi0Pt[fiCut]->Fill(particle->Pt()); // All MC Pi0
+                                       if(particle->GetPdgCode() == 221)hMCEtaPt[fiCut]->Fill(particle->Pt()); // All MC Eta
+                                       // Check the acceptance for both gammas
+                                       if(particle->GetNDaughters() == 2){
+                                               TParticle* daughter0 = (TParticle*)fMCStack->Particle(particle->GetFirstDaughter());
+                                               TParticle* daughter1 = (TParticle*)fMCStack->Particle(particle->GetLastDaughter());
+                                               if(((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelectedMC(daughter0,fMCStack,kFALSE) &&
+                                                       ((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelectedMC(daughter1,fMCStack,kFALSE) ){
+                                                       if(particle->GetPdgCode() == 111)hMCPi0InAccPt[fiCut]->Fill(particle->Pt()); // MC Pi0 with gamma in acc
+                                                       if(particle->GetPdgCode() == 221)hMCEtaInAccPt[fiCut]->Fill(particle->Pt()); // MC Eta with gamma in acc
+                                               }
+                                       }
+                               }
+                       }
+               }
+   }
+}
+//________________________________________________________________________
+void AliAnalysisTaskGammaConvV1::CalculatePi0Candidates(){
+
+   // Conversion Gammas
+   if(fGoodGammas->GetEntries()>1){
+      for(Int_t firstGammaIndex=0;firstGammaIndex<fGoodGammas->GetEntries()-1;firstGammaIndex++){
+         AliAODConversionPhoton *gamma0=dynamic_cast<AliAODConversionPhoton*>(fGoodGammas->At(firstGammaIndex));
+         for(Int_t secondGammaIndex=firstGammaIndex+1;secondGammaIndex<fGoodGammas->GetEntries();secondGammaIndex++){
+            AliAODConversionPhoton *gamma1=dynamic_cast<AliAODConversionPhoton*>(fGoodGammas->At(secondGammaIndex));
+            //Check for same Electron ID
+            if(gamma0->GetTrackLabelPositive() == gamma1->GetTrackLabelPositive() ||
+               gamma0->GetTrackLabelNegative() == gamma1->GetTrackLabelNegative() ||
+               gamma0->GetTrackLabelNegative() == gamma1->GetTrackLabelPositive() ||
+               gamma0->GetTrackLabelPositive() == gamma1->GetTrackLabelNegative() ) continue;
+
+            AliAODConversionMother *pi0cand = new AliAODConversionMother(gamma0,gamma1);
+            pi0cand->SetLabels(firstGammaIndex,secondGammaIndex);
+
+            if((((AliConversionCuts*)fCutArray->At(fiCut))->MesonIsSelected(pi0cand,kTRUE))){
+               hESDMotherInvMassPt[fiCut]->Fill(pi0cand->M(),pi0cand->Pt());
+               if(pi0cand->GetAlpha()<0.1){
+                  hESDMotherInvMassEalpha[fiCut]->Fill(pi0cand->M(),pi0cand->E());
+               }
+               Int_t zbin= fBGHandler[fiCut]->GetZBinIndex(fESDEvent->GetPrimaryVertex()->GetZ());
+               Int_t mbin = 0;
+               if(((AliConversionCuts*)fCutArray->At(fiCut))->UseTrackMultiplicity()){
+                  mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fNumberOfESDTracks);
+               } else {
+                  mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fGoodGammas->GetEntries());
+               }
+               Double_t sparesFill[4] = {pi0cand->M(),pi0cand->Pt(),zbin,mbin};
+               sESDMotherInvMassPtZM[fiCut]->Fill(sparesFill,1);
+               if(fMCEvent){
+                  ProcessTrueMesonCandidates(pi0cand,gamma0,gamma1);
+               }
+            }
+            delete pi0cand;
+            pi0cand=0x0;
+         }
+      }
+   }
+}
+//______________________________________________________________________
+void AliAnalysisTaskGammaConvV1::ProcessTrueMesonCandidates(AliAODConversionMother *Pi0Candidate, AliAODConversionPhoton *TrueGammaCandidate0, AliAODConversionPhoton *TrueGammaCandidate1)
+{
+   // Process True Mesons
+   AliStack *MCStack = fMCEvent->Stack();
+
+   if(TrueGammaCandidate0->GetV0Index()<fESDEvent->GetNumberOfV0s()){
+      Bool_t isTruePi0 = kFALSE;
+      Bool_t isTrueEta = kFALSE;
+      Int_t gamma0MCLabel = TrueGammaCandidate0->GetMCParticleLabel(MCStack);
+      Int_t gamma0MotherLabel = -1;
+      if(gamma0MCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
+         // Daughters Gamma 0
+         TParticle * negativeMC = (TParticle*)TrueGammaCandidate0->GetNegativeMCDaughter(MCStack);
+         TParticle * positiveMC = (TParticle*)TrueGammaCandidate0->GetPositiveMCDaughter(MCStack);
+         TParticle * gammaMC0 = (TParticle*)MCStack->Particle(gamma0MCLabel);
+         if(TMath::Abs(negativeMC->GetPdgCode())==11 && TMath::Abs(positiveMC->GetPdgCode())==11){  // Electrons ...
+            if(negativeMC->GetUniqueID() == 5 && positiveMC->GetUniqueID() ==5){ // ... From Conversion ...
+               if(gammaMC0->GetPdgCode() == 22){ // ... with Gamma Mother
+                  gamma0MotherLabel=gammaMC0->GetFirstMother();
+               }
+            }
+            if(gammaMC0->GetPdgCode() ==111){ // Conversion but Pi0 Mother
+               gamma0MotherLabel=-111;
+            }
+            if(gammaMC0->GetPdgCode() ==221){ // Conversion but Eta Mother
+               gamma0MotherLabel=-221;
+            }
+         }
+      }
+      if(TrueGammaCandidate1->GetV0Index()<fESDEvent->GetNumberOfV0s()){
+         Int_t gamma1MCLabel = TrueGammaCandidate1->GetMCParticleLabel(MCStack);
+         Int_t gamma1MotherLabel = -1;
+         if(gamma1MCLabel != -1){ // Gamma is Combinatorial; MC Particles don't belong to the same Mother
+            // Daughters Gamma 1
+            TParticle * negativeMC = (TParticle*)TrueGammaCandidate1->GetNegativeMCDaughter(MCStack);
+            TParticle * positiveMC = (TParticle*)TrueGammaCandidate1->GetPositiveMCDaughter(MCStack);
+            TParticle * gammaMC1 = (TParticle*)MCStack->Particle(gamma1MCLabel);
+            if(TMath::Abs(negativeMC->GetPdgCode())==11 && TMath::Abs(positiveMC->GetPdgCode())==11){  // Electrons ...
+               if(negativeMC->GetUniqueID() == 5 && positiveMC->GetUniqueID() ==5){ // ... From Conversion ...
+                  if(gammaMC1->GetPdgCode() == 22){ // ... with Gamma Mother
+                     gamma1MotherLabel=gammaMC1->GetFirstMother();
+                  }
+               }
+               if(gammaMC1->GetPdgCode() ==111){ // Conversion but Pi0 Mother
+                  gamma1MotherLabel=-111;
+               }
+               if(gammaMC1->GetPdgCode() ==221){ // Conversion but Eta Mother
+                  gamma1MotherLabel=-221;
+               }
+            }
+         }
+         if(gamma0MotherLabel>=0 && gamma0MotherLabel==gamma1MotherLabel){
+            if(((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetPdgCode() == 111){
+               isTruePi0=kTRUE;
+            }
+            if(((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetPdgCode() == 221){
+               isTrueEta=kTRUE;
+            }
+         }
+         if(isTruePi0 || isTrueEta){ // True Pion or Eta
+                               if (!fMCEvent->IsFromBGEvent(gamma1MotherLabel) && fIsHeavyIon){
+                                       hESDTrueMotherInvMassPtAddedSig[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
+                                       if(gamma0MotherLabel > MCStack->GetNprimary()){ // Secondary Meson
+                                               hESDTrueSecondaryMotherInvMassPtAddedSig[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
+                                               if (((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetMother(0) >-1){
+                                                       if(MCStack->Particle(((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetMother(0))->GetPdgCode()==kK0Short){
+                                                               hESDTrueSecondaryMotherFromK0sInvMassPtAddedSig[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
+                                                       }
+                                               }
+                                       }                       
+                                       if(gamma0MotherLabel <= MCStack->GetNprimary()){ // Only primary pi0 for efficiency calculation
+                                               hESDTruePrimaryMotherInvMassMCPtAddedSig[fiCut]->Fill(Pi0Candidate->M(),((TParticle*)MCStack->Particle(gamma1MotherLabel))->Pt());
+                                               if(isTruePi0){ // Only primaries for unfolding
+                                                       hESDTruePrimaryPi0ESDPtMCPtAddedSig[fiCut]->Fill(Pi0Candidate->Pt(),((TParticle*)MCStack->Particle(gamma1MotherLabel))->Pt());
+                                               }
+                                       }
+                               } else {
+                                       hESDTrueMotherInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
+                                       if(gamma0MotherLabel > MCStack->GetNprimary()){ // Secondary Meson
+                                               hESDTrueSecondaryMotherInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
+                                               if (((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetMother(0) >-1){
+                                                       if(MCStack->Particle(((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetMother(0))->GetPdgCode()==kK0Short){
+                                                               hESDTrueSecondaryMotherFromK0sInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
+                                                       }
+                                               }
+                                       }
+                                       if(gamma0MotherLabel <= MCStack->GetNprimary()){ // Only primary pi0 for efficiency calculation
+                                               hESDTruePrimaryMotherInvMassMCPt[fiCut]->Fill(Pi0Candidate->M(),((TParticle*)MCStack->Particle(gamma1MotherLabel))->Pt());
+                                               if(isTruePi0){ // Only primaries for unfolding
+                                                       hESDTruePrimaryPi0ESDPtMCPt[fiCut]->Fill(Pi0Candidate->Pt(),((TParticle*)MCStack->Particle(gamma1MotherLabel))->Pt());
+                                               }
+                                       }
+                               }
+         }
+         if(!isTruePi0 && !isTrueEta){ // Background
+            if(gamma0MotherLabel>-1 && gamma1MotherLabel>-1){ // Both Tracks are Photons and have a mother but not Pi0 or Eta
+               hESDTrueBckGGInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
+            } else { // No photon or without mother
+               hESDTrueBckContInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
+            }
+            if((gamma0MotherLabel==-111 || gamma1MotherLabel==-111 || gamma0MotherLabel==-221 || gamma1MotherLabel==-221) && (!fMCEvent->IsFromBGEvent(gamma1MotherLabel) || !fMCEvent->IsFromBGEvent(gamma0MotherLabel)) && fIsHeavyIon){
+               // Dalitz
+               hESDTrueMotherDalitzInvMassPtAddedSig[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
+            } else if (gamma0MotherLabel==-111 || gamma1MotherLabel==-111 || gamma0MotherLabel==-221 || gamma1MotherLabel==-221){
+                                       // Dalitz
+               hESDTrueMotherDalitzInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
+            }
+         }
+      }
+   }
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskGammaConvV1::CalculateBackground(){
+
+   Int_t zbin= fBGHandler[fiCut]->GetZBinIndex(fESDEvent->GetPrimaryVertex()->GetZ());
+   Int_t mbin = 0;
+
+   if(((AliConversionCuts*)fCutArray->At(fiCut))->UseTrackMultiplicity()){
+      mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fNumberOfESDTracks);
+   } else {
+      mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fGoodGammas->GetEntries());
+   }
+
+   if(((AliConversionCuts*)fCutArray->At(fiCut))->UseRotationMethod()){
+
+      for(Int_t iCurrent=0;iCurrent<fGoodGammas->GetEntries();iCurrent++){
+         AliAODConversionPhoton currentEventGoodV0 = *(AliAODConversionPhoton*)(fGoodGammas->At(iCurrent));
+         for(Int_t iCurrent2=iCurrent+1;iCurrent2<fGoodGammas->GetEntries();iCurrent2++){
+            for(Int_t nRandom=0;nRandom<((AliConversionCuts*)fCutArray->At(fiCut))->NumberOfRotationEvents();nRandom++){
+               AliAODConversionPhoton currentEventGoodV02 = *(AliAODConversionPhoton*)(fGoodGammas->At(iCurrent2));
+
+               if(((AliConversionCuts*)fV0Reader->GetConversionCuts())->DoBGProbability()){
+                  AliAODConversionMother *backgroundCandidateProb = new AliAODConversionMother(&currentEventGoodV0,&currentEventGoodV02);
+                  Double_t massBGprob = backgroundCandidateProb->M();
+                  if(massBGprob>0.1 && massBGprob<0.14){
+                     if(fRandom.Rndm()>fBGHandler[fiCut]->GetBGProb(zbin,mbin)){
+                        delete backgroundCandidateProb;
+                        continue;
+                     }
+                  }
+                  delete backgroundCandidateProb;
+                  backgroundCandidateProb = 0x0;
+               }
+
+               RotateParticle(&currentEventGoodV02);
+               AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&currentEventGoodV02);
+               if((((AliConversionCuts*)fCutArray->At(fiCut))->MesonIsSelected(backgroundCandidate,kFALSE))){
+                  hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
+                  Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),zbin,mbin};
+                  sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
+               }
+               delete backgroundCandidate;
+               backgroundCandidate = 0x0;
+            }
+         }
+      }
+   }
+   else{
+      AliGammaConversionAODBGHandler::GammaConversionVertex *bgEventVertex = NULL;
+
+      if(((AliConversionCuts*)fCutArray->At(fiCut))->UseTrackMultiplicity()){
+         for(Int_t nEventsInBG=0;nEventsInBG<fBGHandler[fiCut]->GetNBGEvents();nEventsInBG++){
+            AliGammaConversionAODVector *previousEventV0s = fBGHandler[fiCut]->GetBGGoodV0s(zbin,mbin,nEventsInBG);
+            if(fMoveParticleAccordingToVertex == kTRUE){
+               bgEventVertex = fBGHandler[fiCut]->GetBGEventVertex(zbin,mbin,nEventsInBG);
+            }
+
+            for(Int_t iCurrent=0;iCurrent<fGoodGammas->GetEntries();iCurrent++){
+               AliAODConversionPhoton currentEventGoodV0 = *(AliAODConversionPhoton*)(fGoodGammas->At(iCurrent));
+               for(UInt_t iPrevious=0;iPrevious<previousEventV0s->size();iPrevious++){
+                  AliAODConversionPhoton previousGoodV0 = (AliAODConversionPhoton)(*(previousEventV0s->at(iPrevious)));
+                  if(fMoveParticleAccordingToVertex == kTRUE){
+                     MoveParticleAccordingToVertex(&previousGoodV0,bgEventVertex);
+                  }
+
+                  AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&previousGoodV0);
+                  if((((AliConversionCuts*)fCutArray->At(fiCut))->MesonIsSelected(backgroundCandidate,kFALSE))){
+                     hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
+                     Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),zbin,mbin};
+                     sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
+                  }
+                  delete backgroundCandidate;
+                  backgroundCandidate = 0x0;
+               }
+            }
+         }
+      }
+      else{
+         for(Int_t nEventsInBG=0;nEventsInBG <fBGHandler[fiCut]->GetNBGEvents();nEventsInBG++){
+            AliGammaConversionAODVector *previousEventV0s = fBGHandler[fiCut]->GetBGGoodV0s(zbin,mbin,nEventsInBG);
+            if(previousEventV0s){
+               if(fMoveParticleAccordingToVertex == kTRUE){
+                  bgEventVertex = fBGHandler[fiCut]->GetBGEventVertex(zbin,mbin,nEventsInBG);
+               }
+               for(Int_t iCurrent=0;iCurrent<fGoodGammas->GetEntries();iCurrent++){
+                  AliAODConversionPhoton currentEventGoodV0 = *(AliAODConversionPhoton*)(fGoodGammas->At(iCurrent));
+                  for(UInt_t iPrevious=0;iPrevious<previousEventV0s->size();iPrevious++){
+
+                     AliAODConversionPhoton previousGoodV0 = (AliAODConversionPhoton)(*(previousEventV0s->at(iPrevious)));
+
+                     if(fMoveParticleAccordingToVertex == kTRUE){
+                        MoveParticleAccordingToVertex(&previousGoodV0,bgEventVertex);
+                     }
+
+                     AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&previousGoodV0);
+
+                     if((((AliConversionCuts*)fCutArray->At(fiCut))->MesonIsSelected(backgroundCandidate,kFALSE))){
+                        hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
+                        Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),zbin,mbin};
+                        sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
+                     }
+                     delete backgroundCandidate;
+                     backgroundCandidate = 0x0;
+                  }
+               }
+            }
+         }
+      }
+   }
+}
+//________________________________________________________________________
+void AliAnalysisTaskGammaConvV1::RotateParticle(AliAODConversionPhoton *gamma){
+   Int_t fNDegreesPMBackground= ((AliConversionCuts*)fV0Reader->GetConversionCuts())->NDegreesRotation();
+   Double_t nRadiansPM = fNDegreesPMBackground*TMath::Pi()/180;
+   Double_t rotationValue = fRandom.Rndm()*2*nRadiansPM + TMath::Pi()-nRadiansPM;
+   gamma->RotateZ(rotationValue);
+}
+//________________________________________________________________________
+void AliAnalysisTaskGammaConvV1::MoveParticleAccordingToVertex(AliAODConversionPhoton* particle,const AliGammaConversionAODBGHandler::GammaConversionVertex *vertex){
+   //see header file for documentation
+
+   Double_t dx = vertex->fX - fESDEvent->GetPrimaryVertex()->GetX();
+   Double_t dy = vertex->fY - fESDEvent->GetPrimaryVertex()->GetY();
+   Double_t dz = vertex->fZ - fESDEvent->GetPrimaryVertex()->GetZ();
+
+   Double_t movedPlace[3] = {particle->GetConversionX() - dx,particle->GetConversionY() - dy,particle->GetConversionZ() - dz};
+   particle->SetConversionPoint(movedPlace);
+}
+//________________________________________________________________________
+void AliAnalysisTaskGammaConvV1::UpdateEventByEventData(){
+   //see header file for documentation
+   if(fGoodGammas->GetEntries() >0 ){
+      if(((AliConversionCuts*)fCutArray->At(fiCut))->UseTrackMultiplicity()){
+         fBGHandler[fiCut]->AddEvent(fGoodGammas,fESDEvent->GetPrimaryVertex()->GetX(),fESDEvent->GetPrimaryVertex()->GetY(),fESDEvent->GetPrimaryVertex()->GetZ(),fNumberOfESDTracks);
+      }
+      else{ // means we use #V0s for multiplicity
+         fBGHandler[fiCut]->AddEvent(fGoodGammas,fESDEvent->GetPrimaryVertex()->GetX(),fESDEvent->GetPrimaryVertex()->GetY(),fESDEvent->GetPrimaryVertex()->GetZ(),fGoodGammas->GetEntries());
+      }
+   }
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskGammaConvV1::CountESDTracks(){
+
+   AliESDtrackCuts *EsdTrackCuts = new AliESDtrackCuts("AliESDtrackCuts");
+   // Using standard function for setting Cuts
+   Bool_t selectPrimaries=kTRUE;
+   EsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(selectPrimaries);
+   EsdTrackCuts->SetMaxDCAToVertexZ(2);
+   EsdTrackCuts->SetEtaRange(-0.8, 0.8);
+   EsdTrackCuts->SetPtRange(0.15);
+
+   fNumberOfESDTracks = 0;
+   for(Int_t iTracks = 0; iTracks < fESDEvent->GetNumberOfTracks(); iTracks++){
+      AliESDtrack* curTrack = fESDEvent->GetTrack(iTracks);
+      if(!curTrack) continue;
+      if(EsdTrackCuts->AcceptTrack(curTrack) ) fNumberOfESDTracks++;
+   }
+   delete EsdTrackCuts;
+   EsdTrackCuts=0x0;
+
+   return;
+}
+//________________________________________________________________________
+void AliAnalysisTaskGammaConvV1::Terminate(const Option_t *)
+{
+   fOutputContainer->Add(((AliConversionCuts*)fV0Reader->GetConversionCuts())->GetCutHistograms());
+
+   for(Int_t iCut = 0; iCut<fnCuts;iCut++){
+      if(((AliConversionCuts*)fCutArray->At(iCut))->GetCutHistograms()){
+         fCutFolder[iCut]->Add(((AliConversionCuts*)fCutArray->At(iCut))->GetCutHistograms());
+      }
+   }
+   fOutputContainer->Print();
+}
+
diff --git a/PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.h b/PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.h
new file mode 100644 (file)
index 0000000..a57e381
--- /dev/null
@@ -0,0 +1,137 @@
+#ifndef ALIANLYSISTASKGAMMACONVV1_cxx
+#define ALIANLYSISTASKGAMMACONVV1_cxx
+
+#include "AliAnalysisTaskSE.h"
+#include "AliESDtrack.h"
+#include "AliV0ReaderV1.h"
+#include "AliKFConversionPhoton.h"
+#include "AliGammaConversionAODBGHandler.h"
+#include "TH3.h"
+
+
+class AliAnalysisTaskGammaConvV1 : public AliAnalysisTaskSE {
+public:
+
+    AliAnalysisTaskGammaConvV1();
+    AliAnalysisTaskGammaConvV1(const char *name);
+    virtual ~AliAnalysisTaskGammaConvV1();
+
+    virtual void   UserCreateOutputObjects();
+    virtual void   UserExec(Option_t *);
+    virtual void   Terminate(const Option_t*);
+    void InitBack();
+
+    void SetIsHeavyIon(Bool_t flag){fIsHeavyIon = flag;}
+    void SetDoMesonAnalysis(Bool_t flag){fDoMesonAnalysis = flag;}
+    void ProcessPhotonCandidates();
+    void CalculatePi0Candidates();
+    void CalculateBackground();
+    void ProcessMCParticles();
+    void ProcessTruePhotonCandidates( AliAODConversionPhoton* TruePhotonCandidate);
+    void ProcessTrueMesonCandidates( AliAODConversionMother *Pi0Candidate, AliAODConversionPhoton *TrueGammaCandidate0, AliAODConversionPhoton *TrueGammaCandidate1);   
+    void RotateParticle(AliAODConversionPhoton *gamma);
+    void SetConversionCutList(Int_t nCuts, TList *CutArray){
+       fnCuts = nCuts;
+       fCutArray = CutArray;
+    }
+    
+    // BG HandlerSettings
+    void SetMoveParticleAccordingToVertex(Bool_t flag){fMoveParticleAccordingToVertex = flag;}
+    void CountESDTracks();
+    void MoveParticleAccordingToVertex(AliAODConversionPhoton* particle,const AliGammaConversionAODBGHandler::GammaConversionVertex *vertex);
+    void UpdateEventByEventData();
+
+protected:
+    AliV0ReaderV1 *fV0Reader;
+    AliGammaConversionAODBGHandler **fBGHandler;
+    AliESDEvent *fESDEvent;
+    AliMCEvent *fMCEvent;
+    AliStack *fMCStack;
+    TList **fCutFolder;
+    TList **fESDList;
+    TList **fBackList;
+    TList **fTrueList;
+    TList **fMCList;
+    TList *fOutputContainer;
+    TClonesArray *fReaderGammas;
+    TList *fGoodGammas;
+    TList *fCutArray;
+    AliConversionCuts *fConversionCuts;
+    TH1F **hESDConvGammaPt;
+    TH2F **hESDMotherInvMassPt;
+    THnSparseF **sESDMotherInvMassPtZM;
+    TH2F **hESDMotherBackInvMassPt;
+    THnSparseF **sESDMotherBackInvMassPtZM;
+    TH2F **hESDMotherInvMassEalpha;
+    TH1F **hMCAllGammaPt;
+        TH1F **hMCAllGammaPtAddedSig;
+    TH1F **hMCDecayGammaPi0Pt;
+        TH1F **hMCDecayGammaPi0PtAddedSig;
+    TH1F **hMCDecayGammaRhoPt;
+        TH1F **hMCDecayGammaRhoPtAddedSig;
+    TH1F **hMCDecayGammaEtaPt;
+        TH1F **hMCDecayGammaEtaPtAddedSig;
+    TH1F **hMCDecayGammaOmegaPt;
+        TH1F **hMCDecayGammaOmegaPtAddedSig;
+    TH1F **hMCDecayGammaEtapPt;
+        TH1F **hMCDecayGammaEtapPtAddedSig;
+    TH1F **hMCDecayGammaPhiPt;
+        TH1F **hMCDecayGammaPhiPtAddedSig;
+    TH1F **hMCConvGammaPt;
+        TH1F **hMCConvGammaPtAddedSig;
+    TH1F **hMCPi0Pt;
+    TH1F **hMCEtaPt;
+    TH1F **hMCPi0InAccPt;
+    TH1F **hMCEtaInAccPt;
+        TH1F **hMCPi0PtAddedSig;
+    TH1F **hMCEtaPtAddedSig;
+    TH1F **hMCPi0InAccPtAddedSig;
+    TH1F **hMCEtaInAccPtAddedSig;
+    TH2F **hESDTrueMotherInvMassPt;
+        TH2F **hESDTrueMotherInvMassPtAddedSig;
+    TH2F **hESDTruePrimaryMotherInvMassMCPt;
+        TH2F **hESDTruePrimaryMotherInvMassMCPtAddedSig;
+    TH2F **hESDTruePrimaryPi0ESDPtMCPt;
+        TH2F **hESDTruePrimaryPi0ESDPtMCPtAddedSig;
+    TH2F **hESDTrueSecondaryMotherInvMassPt;
+        TH2F **hESDTrueSecondaryMotherInvMassPtAddedSig;
+    TH2F **hESDTrueSecondaryMotherFromK0sInvMassPt;
+        TH2F **hESDTrueSecondaryMotherFromK0sInvMassPtAddedSig;
+    TH2F **hESDTrueBckGGInvMassPt;
+    TH2F **hESDTrueBckContInvMassPt;
+    TH2F **hESDTrueMotherDalitzInvMassPt;
+        TH2F **hESDTrueMotherDalitzInvMassPtAddedSig;
+    TH1F **hESDTrueConvGammaPt;
+        TH1F **hESDTrueConvGammaPtAddedSig;
+    TH1F **hESDTrueElecCombPt;
+    TH1F **hESDTruePionCombPt;
+    TH1F **hESDTruePrimaryConvGammaPt;
+        TH1F **hESDTruePrimaryConvGammaPtAddedSig;
+    TH2F **hESDTruePrimaryConvGammaESDPtMCPt;
+        TH2F **hESDTruePrimaryConvGammaESDPtMCPtAddedSig;
+    TH1F **hESDTrueSecondaryConvGammaPt;
+        TH1F **hESDTrueSecondaryConvGammaPtAddedSig;
+    TH1F **hESDTrueSecondaryConvGammaFromK0sPt;
+        TH1F **hESDTrueSecondaryConvGammaFromK0sPtAddedSig;
+    TH1F **hESDTrueSecondaryConvGammaFromXFromK0sPt;
+        TH1F **hESDTrueSecondaryConvGammaFromXFromK0sPtAddedSig;
+    TH1I **hNEvents;
+    TH1I **hNGoodESDTracks;
+        TH1I **hNV0Tracks;
+        
+    TRandom3 fRandom;
+    Double_t *fUnsmearedPx;
+    Double_t *fUnsmearedPy;
+    Double_t *fUnsmearedPz;
+    Double_t *fUnsmearedE;
+    Int_t fnCuts;
+    Int_t fiCut;
+    Int_t fNumberOfESDTracks;
+    Bool_t fMoveParticleAccordingToVertex;
+    Bool_t fIsHeavyIon;
+    Bool_t fDoMesonAnalysis;
+    
+    ClassDef(AliAnalysisTaskGammaConvV1, 2);
+};
+
+#endif
index 78a34026fcc943e9e2e89933722efc64482e6f63..a9b872d40bdb80832bf8fdfdd004b69defbe4cf1 100644 (file)
@@ -579,6 +579,7 @@ Bool_t AliConversionCuts::PhotonIsSelectedMC(TParticle *particle,AliStack *fMCSt
     return kFALSE;
 }
 
+
 //________________________________________________________________________
 Bool_t AliConversionCuts::MesonIsSelectedMC(TParticle *fMCMother,AliStack *fMCStack,Bool_t bMCDaughtersInAcceptance){
     // Returns true for all pions within acceptance cuts for decay into 2 photons
@@ -1732,11 +1733,23 @@ Bool_t AliConversionCuts::SetRCut(Int_t RCut){
        fMaxR = 70.;
        fMinR = 5.;
        break;
+       // High purity cuts for PbPb (remove first layers of material)
     case 5:
        fMaxR = 180.;
-       fMinR = 10.;
+       fMinR = 10.;  
+       break;
+     case 6:
+       fMaxR = 180.;
+       fMinR = 20.;
+         break;
+    case 7:
+       fMaxR = 180.;
+       fMinR = 26.;
+       break;
+    case 8:
+       fMaxR = 180.;
+       fMinR = 35.;
        break;
-    // High purity cuts for PbPb
     case 9:
        fMaxR = 180.;
        fMinR = 60.;
index 55a8196eb123d05b25f1dcbea7257e3387273d76..1578651836cc7c7852d2b7fd7b70a4b9eb71c753 100644 (file)
@@ -122,6 +122,7 @@ class AliConversionCuts : public AliAnalysisCuts {
   Bool_t EventIsSelected(AliVEvent *fInputEvent, AliVEvent *fMCEvent);
   Bool_t PhotonIsSelected(AliConversionPhotonBase * photon, AliVEvent  * event);
   Bool_t PhotonIsSelectedMC(TParticle *particle,AliStack *fMCStack,Bool_t checkForConvertedGamma=kTRUE);
+  Bool_t ElectronIsSelectedMC(TParticle *particle,AliStack *fMCStack);
   Bool_t TracksAreSelected(AliVTrack * negTrack, AliVTrack * posTrack);
   Bool_t MesonIsSelected(AliAODConversionMother *pi0,Bool_t IsSignal=kTRUE);
   Bool_t MesonIsSelectedMC(TParticle *fMCMother,AliStack *fMCStack, Bool_t bMCDaughtersInAcceptance=kFALSE);
@@ -312,6 +313,9 @@ class AliConversionCuts : public AliAnalysisCuts {
   UInt_t fOfflineTriggerMask;   //  Task processes collision candidates only
   TRandom3 fRandom; //
   Int_t *fElectronLabelArray; // Array with elec/pos v0 label
+  Float_t fConversionPointXArray; // Array with conversion Point x
+  Float_t fConversionPointYArray; // Array with conversion Point y
+  Float_t fConversionPointZArray; // Array with conversion Point z
 
   // Histograms
   TObjString *fCutString; // cut number used for analysis
diff --git a/PWGGA/GammaConv/AliConversionMesonCuts.cxx b/PWGGA/GammaConv/AliConversionMesonCuts.cxx
new file mode 100644 (file)
index 0000000..7d4bcd8
--- /dev/null
@@ -0,0 +1,833 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                       *
+ * Authors: Svein Lindal, Daniel Lohner                                          *
+ * Version 1.0                                                           *
+ *                                                                       *
+ * Permission to use, copy, modify and distribute this software and its          *
+ * documentation strictly for non-commercial purposes is hereby granted          *
+ * without fee, provided that the above copyright notice appears in all          *
+ * copies and that both the copyright notice and this permission notice          *
+ * appear in the supporting documentation. The authors make no claims    *
+ * about the suitability of this software for any purpose. It is         *
+ * provided "as is" without express or implied warranty.                 *
+ **************************************************************************/
+
+////////////////////////////////////////////////
+//--------------------------------------------- 
+// Class handling all kinds of selection cuts for
+// Gamma Conversion analysis
+//---------------------------------------------
+////////////////////////////////////////////////
+
+#include "AliConversionMesonCuts.h"
+
+#include "AliKFVertex.h"
+#include "AliAODTrack.h"
+#include "AliESDtrack.h"
+#include "AliAnalysisManager.h"
+#include "AliInputEventHandler.h"
+#include "AliMCEventHandler.h"
+#include "AliAODHandler.h"
+#include "AliPIDResponse.h"
+#include "TH1.h"
+#include "TH2.h"
+#include "AliStack.h"
+#include "AliAODConversionMother.h"
+#include "TObjString.h"
+#include "AliAODEvent.h"
+#include "AliESDEvent.h"
+#include "AliCentrality.h"
+#include "TList.h"
+class iostream;
+
+using namespace std;
+
+ClassImp(AliConversionMesonCuts)
+
+
+const char* AliConversionMesonCuts::fgkCutNames[AliConversionMesonCuts::kNCuts] = {
+"MesonKind",
+"Chi2MesonCut",
+"AlphaMesonCut",
+"RapidityMesonCut",
+"rCut",
+"BackgroundScheme",
+"DegreesForRotationMethod",
+"NumberOfRotations",
+"SharedElectronCuts",
+"RejectToCloseV0s",
+};
+
+
+//________________________________________________________________________
+AliConversionMesonCuts::AliConversionMesonCuts(const char *name,const char *title) : AliAnalysisCuts(name,title),
+    fHistograms(NULL),
+    fMaxR(200),
+    fChi2CutMeson(1000),
+    fAlphaMinCutMeson(0),
+    fAlphaCutMeson(1),
+    fRapidityCutMeson(1),
+    fUseRotationMethodInBG(kFALSE),
+    fdoBGProbability(kFALSE),
+    fUseTrackMultiplicityForBG(kFALSE),
+    fnDegreeRotationPMForBG(0),
+    fnumberOfRotationEventsForBG(0),
+    fOpeningAngle(0.005),
+    fDoToCloseV0sCut(kFALSE),
+    fminV0Dist(200.),
+    fDoSharedElecCut(kFALSE),
+    fRandom(0),
+    fElectronLabelArray(NULL),
+    fCutString(NULL),
+    hMesonCuts(NULL),
+    hMesonBGCuts(NULL)
+{
+       for(Int_t jj=0;jj<kNCuts;jj++){fCuts[jj]=0;}
+       fCutString=new TObjString((GetCutNumber()).Data());
+       fElectronLabelArray = new Int_t[500];
+}
+
+//________________________________________________________________________
+AliConversionMesonCuts::~AliConversionMesonCuts() {
+    // Destructor
+  //Deleting fHistograms leads to seg fault it it's added to output collection of a task
+  // if(fHistograms)
+  //   delete fHistograms;
+  // fHistograms = NULL;
+   if(fCutString != NULL){
+      delete fCutString;
+      fCutString = NULL;
+   }
+   if(fElectronLabelArray){
+      delete fElectronLabelArray;
+      fElectronLabelArray = NULL;
+   }
+
+}
+
+//________________________________________________________________________
+void AliConversionMesonCuts::InitCutHistograms(TString name, Bool_t preCut){
+
+    // Initialize Cut Histograms for QA (only initialized and filled if function is called)
+
+       if(fHistograms != NULL){
+               delete fHistograms;
+               fHistograms=NULL;
+   }
+       if(fHistograms==NULL){
+               fHistograms=new TList();
+               if(name=="")fHistograms->SetName(Form("ConvMesonCuts_%s",GetCutNumber().Data()));
+               else fHistograms->SetName(Form("%s_%s",name.Data(),GetCutNumber().Data()));
+    }
+
+   
+   
+    // Meson Cuts
+    hMesonCuts=new TH1F(Form("MesonCuts %s",GetCutNumber().Data()),"MesonCuts",10,-0.5,9.5);
+    hMesonCuts->GetXaxis()->SetBinLabel(1,"in");
+    hMesonCuts->GetXaxis()->SetBinLabel(2,"undef rapidity");
+    hMesonCuts->GetXaxis()->SetBinLabel(3,"rapidity cut");
+    hMesonCuts->GetXaxis()->SetBinLabel(4,"opening angle");
+    hMesonCuts->GetXaxis()->SetBinLabel(5,"alpha max");
+    hMesonCuts->GetXaxis()->SetBinLabel(6,"alpha min");
+    hMesonCuts->GetXaxis()->SetBinLabel(7,"out");
+    fHistograms->Add(hMesonCuts);
+
+    hMesonBGCuts=new TH1F(Form("MesonBGCuts %s",GetCutNumber().Data()),"MesonBGCuts",10,-0.5,9.5);
+    hMesonBGCuts->GetXaxis()->SetBinLabel(1,"in");
+    hMesonBGCuts->GetXaxis()->SetBinLabel(2,"undef rapidity");
+    hMesonBGCuts->GetXaxis()->SetBinLabel(3,"rapidity cut");
+    hMesonBGCuts->GetXaxis()->SetBinLabel(4,"opening angle");
+    hMesonBGCuts->GetXaxis()->SetBinLabel(5,"alpha max");
+    hMesonBGCuts->GetXaxis()->SetBinLabel(6,"alpha min");
+    hMesonBGCuts->GetXaxis()->SetBinLabel(7,"out");
+    fHistograms->Add(hMesonBGCuts);
+}
+
+
+//________________________________________________________________________
+Bool_t AliConversionMesonCuts::MesonIsSelectedMC(TParticle *fMCMother,AliStack *fMCStack,Bool_t bMCDaughtersInAcceptance){
+    // Returns true for all pions within acceptance cuts for decay into 2 photons
+    // If bMCDaughtersInAcceptance is selected, it requires in addition that both daughter photons are within acceptance cuts
+
+    if(!fMCStack)return kFALSE;
+    
+    if(fMCMother->GetPdgCode()==111 || fMCMother->GetPdgCode()==221){
+       
+       if(fMCMother->R()>fMaxR)        return kFALSE; // cuts on distance from collision point
+
+       Double_t rapidity = 10.;
+       if(fMCMother->Energy() - fMCMother->Pz() == 0 || fMCMother->Energy() + fMCMother->Pz() == 0){
+          rapidity=8.;
+       }
+       else{
+          rapidity = 0.5*(TMath::Log((fMCMother->Energy()+fMCMother->Pz()) / (fMCMother->Energy()-fMCMother->Pz())));
+       }       
+       
+       // Rapidity Cut
+       if(TMath::Abs(rapidity)>fRapidityCutMeson)return kFALSE;
+
+       // Select only -> 2y decay channel
+       if(fMCMother->GetNDaughters()!=2)return kFALSE;
+
+       for(Int_t i=0;i<2;i++){
+           TParticle *MDaughter=fMCStack->Particle(fMCMother->GetDaughter(i));
+
+           // Is Daughter a Photon?
+           if(MDaughter->GetPdgCode()!=22)return kFALSE;
+            // Is Photon in Acceptance?
+//         if(bMCDaughtersInAcceptance){
+//             if(!PhotonIsSelectedMC(MDaughter,fMCStack)){return kFALSE;}
+//         }
+       }
+       return kTRUE;
+    }
+    return kFALSE;
+}
+
+//________________________________________________________________________
+Bool_t AliConversionMesonCuts::MesonIsSelectedMCDalitz(TParticle *fMCMother,AliStack *fMCStack){
+       // Returns true for all pions within acceptance cuts for decay into 2 photons
+       // If bMCDaughtersInAcceptance is selected, it requires in addition that both daughter photons are within acceptance cuts
+
+       if(!fMCStack)return kFALSE;
+       
+       if(fMCMother->GetPdgCode()==111 || fMCMother->GetPdgCode()==221){
+               
+               if(fMCMother->R()>fMaxR)        return kFALSE; // cuts on distance from collision point
+
+               Double_t rapidity = 10.;
+               if(fMCMother->Energy() - fMCMother->Pz() == 0 || fMCMother->Energy() + fMCMother->Pz() == 0){
+                       rapidity=8.;
+               }
+               else{
+                       rapidity = 0.5*(TMath::Log((fMCMother->Energy()+fMCMother->Pz()) / (fMCMother->Energy()-fMCMother->Pz())));
+               }       
+               
+               // Rapidity Cut
+               if(TMath::Abs(rapidity)>fRapidityCutMeson)return kFALSE;
+
+               // Select only -> Dalitz decay channel
+               if(fMCMother->GetNDaughters()!=3)return kFALSE;
+
+               Int_t daughterPDGs[3] = {0,0,0};
+                Int_t index = 0;
+
+//                iParticle->GetFirstDaughter(); idxPi0 <= iParticle->GetLastDaughter()
+
+               for(Int_t i=fMCMother->GetFirstDaughter(); i<= fMCMother->GetLastDaughter();i++){
+                       TParticle *MDaughter=fMCStack->Particle(i);
+                       // Is Daughter a Photon or an electron?
+                       daughterPDGs[index]=MDaughter->GetPdgCode();
+                        index++;
+               }
+               for (Int_t j=0;j<2;j++){
+
+                       for (Int_t i=0;i<2;i++){
+                               if (daughterPDGs[i] > daughterPDGs[i+1]){
+                                       Int_t interMed = daughterPDGs[i] ; 
+                                       daughterPDGs[i] = daughterPDGs[i+1];
+                                       daughterPDGs[i+1] = interMed;
+                               }
+                       }
+               }
+               if (daughterPDGs[0] == -11 && daughterPDGs[1] == 11 && daughterPDGs[2] == 22) return kTRUE;
+       }
+       return kFALSE;
+}
+
+
+///________________________________________________________________________
+Bool_t AliConversionMesonCuts::MesonIsSelected(AliAODConversionMother *pi0,Bool_t IsSignal)
+{
+       // Selection of reconstructed Meson candidates
+       // Use flag IsSignal in order to fill Fill different
+       // histograms for Signal and Background
+       TH1 *hist=0x0;
+
+       
+
+       if(IsSignal){hist=hMesonCuts;}
+       else{hist=hMesonBGCuts;}
+
+       Int_t cutIndex=0;
+
+       if(hist)hist->Fill(cutIndex);
+       cutIndex++;
+
+       // Undefined Rapidity -> Floating Point exception
+       if((pi0->E()+pi0->Pz())/(pi0->E()-pi0->Pz())<=0){
+               if(hist)hist->Fill(cutIndex);
+               cutIndex++;
+               return kFALSE;
+       }
+       else{
+               // PseudoRapidity Cut --> But we cut on Rapidity !!!
+               cutIndex++;
+               if(TMath::Abs(pi0->Rapidity())>fRapidityCutMeson){
+               //if(TMath::Abs(pi0->PseudoRapidity())>fRapidityCutMeson){
+                       if(hist)hist->Fill(cutIndex);
+                       return kFALSE;
+               }
+       }
+       cutIndex++;
+
+       // Opening Angle Cut
+       //fOpeningAngle=2*TMath::ATan(0.134/pi0->P());// physical minimum opening angle
+       if( pi0->GetOpeningAngle() < fOpeningAngle){
+               if(hist)hist->Fill(cutIndex);
+               return kFALSE;
+       }
+       cutIndex++;
+
+       // Alpha Max Cut
+       if(pi0->GetAlpha()>fAlphaCutMeson){
+               if(hist)hist->Fill(cutIndex);
+               return kFALSE;
+       }
+       cutIndex++;
+
+       // Alpha Min Cut
+       if(pi0->GetAlpha()<fAlphaMinCutMeson){
+               if(hist)hist->Fill(cutIndex);
+               return kFALSE;
+       }
+       cutIndex++;
+
+       if(hist)hist->Fill(cutIndex);
+       return kTRUE;
+}
+
+
+
+///________________________________________________________________________
+///________________________________________________________________________
+Bool_t AliConversionMesonCuts::UpdateCutString(cutIds cutID, Int_t value) {
+///Update the cut string (if it has been created yet)
+
+  if(fCutString && fCutString->GetString().Length() == kNCuts) {
+        cout << "Updating cut id in spot number " << cutID << " to " << value << endl;
+       fCutString->SetString(GetCutNumber());
+  } else {
+        cout << "fCutString not yet initialized, will not be updated" << endl;
+       return kFALSE;
+  }
+  cout << fCutString->GetString().Data() << endl;
+  return kTRUE;
+}
+
+///________________________________________________________________________
+Bool_t AliConversionMesonCuts::InitializeCutsFromCutString(const TString analysisCutSelection ) {
+       // Initialize Cuts from a given Cut string
+       cout<<"Set Cut Number: "<<analysisCutSelection.Data()<<endl;
+       if(analysisCutSelection.Length()!=kNCuts) {
+               AliError(Form("Cut selection has the wrong length! size is %d, number of cuts is %d", analysisCutSelection.Length(), kNCuts));
+               return kFALSE;
+       }
+       if(!analysisCutSelection.IsDigit()){
+               AliError("Cut selection contains characters");
+               return kFALSE;
+       }
+       
+       const char *cutSelection = analysisCutSelection.Data();
+       #define ASSIGNARRAY(i)  fCuts[i] = cutSelection[i] - '0'
+       for(Int_t ii=0;ii<kNCuts;ii++){
+                       ASSIGNARRAY(ii);
+       }
+
+  // Set Individual Cuts
+  for(Int_t ii=0;ii<kNCuts;ii++){
+      if(!SetCut(cutIds(ii),fCuts[ii]))return kFALSE;
+  }
+
+  //PrintCuts();
+  return kTRUE;
+}
+///________________________________________________________________________
+Bool_t AliConversionMesonCuts::SetCut(cutIds cutID, const Int_t value) {
+  ///Set individual cut ID
+
+  //cout << "Updating cut  " << fgkCutNames[cutID] << " (" << cutID << ") to " << value << endl;
+       switch (cutID) {
+       case kMesonKind:
+               if( SetMesonKind(value)) {
+               fCuts[kMesonKind] = value;
+               UpdateCutString(cutID, value);
+               return kTRUE;
+               } else return kFALSE;
+
+       
+       case kchi2MesonCut:
+               if( SetChi2MesonCut(value)) {
+               fCuts[kchi2MesonCut] = value;
+               UpdateCutString(cutID, value);
+               return kTRUE;
+               } else return kFALSE;
+
+       case kalphaMesonCut:
+               if( SetAlphaMesonCut(value)) {
+               fCuts[kalphaMesonCut] = value;
+               UpdateCutString(cutID, value);
+               return kTRUE;
+               } else return kFALSE;
+
+       case kRCut:
+               if( SetRCut(value)) {
+               fCuts[kRCut] = value;
+               UpdateCutString(cutID, value);
+               return kTRUE;
+               } else return kFALSE;
+
+       case kRapidityMesonCut:
+               if( SetRapidityMesonCut(value)) {
+               fCuts[kRapidityMesonCut] = value;
+               UpdateCutString(cutID, value);
+               return kTRUE;
+               } else return kFALSE;
+
+       case kBackgroundScheme:
+               if( SetBackgroundScheme(value)) {
+               fCuts[kBackgroundScheme] = value;
+               UpdateCutString(cutID, value);
+               return kTRUE;
+               } else return kFALSE;
+
+       case kDegreesForRotationMethod:
+               if( SetNDegreesForRotationMethod(value)) {
+               fCuts[kDegreesForRotationMethod] = value;
+               UpdateCutString(cutID, value);
+               return kTRUE;
+               } else return kFALSE;
+
+       case kNumberOfRotations:
+               if( SetNumberOfRotations(value)) {
+               fCuts[kNumberOfRotations] = value;
+               UpdateCutString(cutID, value);
+               return kTRUE;
+               } else return kFALSE;
+
+       case kElecShare:
+               if( SetSharedElectronCut(value)) {
+               fCuts[kElecShare] = value;
+               UpdateCutString(cutID, value);
+               return kTRUE;
+               } else return kFALSE;
+
+       case kToCloseV0s:
+               if( SetToCloseV0sCut(value)) {
+               fCuts[kToCloseV0s] = value;
+               UpdateCutString(cutID, value);
+               return kTRUE;
+               } else return kFALSE;
+
+       case kNCuts:
+               cout << "Error:: Cut id out of range"<< endl;
+               return kFALSE;
+       }
+  
+  cout << "Error:: Cut id " << cutID << " not recognized "<< endl;
+  return kFALSE;
+  
+}
+
+
+///________________________________________________________________________
+void AliConversionMesonCuts::PrintCuts() {
+       // Print out current Cut Selection
+       for(Int_t ic = 0; ic < kNCuts; ic++) {
+               printf("%-30s : %d \n", fgkCutNames[ic], fCuts[ic]);
+       }
+}
+
+///________________________________________________________________________
+Bool_t AliConversionMesonCuts::SetMesonKind(Int_t mesonKind){
+       // Set Cut
+       switch(mesonKind){
+               case 0:
+                       fMesonKind=0;
+                       break;
+               case 1:
+                       fMesonKind=1;;
+                       break;
+               default:
+                       cout<<"Warning: Meson kind not defined"<<mesonKind<<endl;
+                       return kFALSE;
+       }
+       return kTRUE;
+}
+
+///________________________________________________________________________
+Bool_t AliConversionMesonCuts::SetRCut(Int_t rCut){
+       // Set Cut
+       switch(rCut){
+               case 0:
+                       fMaxR = 180.;
+                       break;
+               case 1:
+                       fMaxR = 180.;
+                       break;
+               case 2:
+                       fMaxR = 180.;
+                       break;
+               case 3:
+                       fMaxR = 70.;                    
+                       break;
+               case 4:
+                       fMaxR = 70.;
+                       break;
+               case 5:
+                       fMaxR = 180.;
+                       break;
+                       // High purity cuts for PbPb
+               case 9:
+                       fMaxR = 180.;
+                       break;
+               default:
+                       cout<<"Warning: rCut not defined"<<rCut<<endl;
+                       return kFALSE;
+       }
+       return kTRUE;
+}
+
+///________________________________________________________________________
+Bool_t AliConversionMesonCuts::SetChi2MesonCut(Int_t chi2MesonCut){
+       // Set Cut
+       switch(chi2MesonCut){
+               case 0:  // 100.
+               fChi2CutMeson = 100.;
+               break;
+               case 1:  // 50.
+               fChi2CutMeson = 50.;
+               break;
+               case 2:  // 30.
+               fChi2CutMeson = 30.;
+               break;
+               case 3:
+               fChi2CutMeson = 200.;
+               break;
+               case 4:
+               fChi2CutMeson = 500.;
+               break;
+               case 5:
+               fChi2CutMeson = 1000.;
+               break;
+               default:
+               cout<<"Warning: Chi2MesonCut not defined "<<chi2MesonCut<<endl;
+               return kFALSE;
+       }
+       return kTRUE;
+}
+
+
+///________________________________________________________________________
+Bool_t AliConversionMesonCuts::SetAlphaMesonCut(Int_t alphaMesonCut)
+{   // Set Cut
+       switch(alphaMesonCut){
+               case 0: // 0- 0.7
+               fAlphaMinCutMeson        = 0.0;
+               fAlphaCutMeson   = 0.7;
+               break;
+                       case 1: // 0-0.5
+               fAlphaMinCutMeson        = 0.0;
+               fAlphaCutMeson   = 0.5;
+               break;
+                       case 2: // 0.5-1
+               fAlphaMinCutMeson        = 0.5;
+               fAlphaCutMeson   = 1.;
+               break;
+                       case 3: // 0.0-1
+               fAlphaMinCutMeson        = 0.0;
+               fAlphaCutMeson   = 1.;
+               break;
+                       case 4: // 0-0.65
+               fAlphaMinCutMeson        = 0.0;
+               fAlphaCutMeson   = 0.65;
+               break;
+                       case 5: // 0-0.75
+               fAlphaMinCutMeson        = 0.0;
+               fAlphaCutMeson   = 0.75;
+               break;
+                       case 6: // 0-0.8
+               fAlphaMinCutMeson        = 0.0;
+               fAlphaCutMeson   = 0.8;
+               break;
+                       case 7: // 0.0-0.85
+               fAlphaMinCutMeson        = 0.0;
+               fAlphaCutMeson   = 0.85;
+               break;
+                       case 8: // 0.0-0.6
+               fAlphaMinCutMeson        = 0.0;
+               fAlphaCutMeson   = 0.6;
+               break;
+                       default:
+                               cout<<"Warning: AlphaMesonCut not defined "<<alphaMesonCut<<endl;
+               return kFALSE;
+       }
+       return kTRUE;
+}
+
+///________________________________________________________________________
+Bool_t AliConversionMesonCuts::SetRapidityMesonCut(Int_t RapidityMesonCut){ 
+       // Set Cut
+       switch(RapidityMesonCut){
+               case 0:  //
+               fRapidityCutMeson   = 0.9;
+               break;
+               case 1:  //
+               fRapidityCutMeson   = 0.8;
+               break;
+               case 2:  //
+               fRapidityCutMeson   = 0.7;
+               break;
+
+               default:
+                       cout<<"Warning: RapidityMesonCut not defined "<<RapidityMesonCut<<endl;
+               return kFALSE;
+       }
+    return kTRUE;
+}
+
+
+///________________________________________________________________________
+Bool_t AliConversionMesonCuts::SetBackgroundScheme(Int_t BackgroundScheme){
+       // Set Cut
+       switch(BackgroundScheme){
+               case 0: //Rotation
+               fUseRotationMethodInBG=kTRUE;
+               fdoBGProbability=kFALSE;
+               break;
+               case 1: // mixed event with V0 multiplicity
+               fUseRotationMethodInBG=kFALSE;
+               fUseTrackMultiplicityForBG=kFALSE;
+               fdoBGProbability=kFALSE;
+               break;
+               case 2: // mixed event with track multiplicity
+               fUseRotationMethodInBG=kFALSE;
+               fUseTrackMultiplicityForBG=kTRUE;
+               fdoBGProbability=kFALSE;
+               break;
+               case 3: //Rotation
+               fUseRotationMethodInBG=kTRUE;
+               fdoBGProbability=kTRUE;
+               break;
+               default:
+               cout<<"Warning: BackgroundScheme not defined "<<BackgroundScheme<<endl;
+               return kFALSE;
+       }
+       return kTRUE;
+}
+
+///________________________________________________________________________
+Bool_t AliConversionMesonCuts::SetNDegreesForRotationMethod(Int_t DegreesForRotationMethod){
+    // Set Cut
+       switch(DegreesForRotationMethod){
+               case 0:
+               fnDegreeRotationPMForBG = 5;
+               break;
+               case 1:
+               fnDegreeRotationPMForBG = 10;
+               break;
+               case 2:
+               fnDegreeRotationPMForBG = 15;
+               break;
+               case 3:
+               fnDegreeRotationPMForBG = 20;
+               break;
+               default:
+                       cout<<"Warning: DegreesForRotationMethod not defined "<<DegreesForRotationMethod<<endl;
+       return kFALSE;
+       }
+       fCuts[kDegreesForRotationMethod]=DegreesForRotationMethod;
+       return kTRUE;
+}
+
+///________________________________________________________________________
+Bool_t AliConversionMesonCuts::SetNumberOfRotations(Int_t NumberOfRotations){
+       // Set Cut
+       switch(NumberOfRotations){
+               case 0:
+               fnumberOfRotationEventsForBG = 5;
+               break;
+               case 1:
+               fnumberOfRotationEventsForBG = 10;
+               break;
+               case 2:
+               fnumberOfRotationEventsForBG = 15;
+               break;
+               case 3:
+               fnumberOfRotationEventsForBG = 20;
+               break;
+               case 4:
+               fnumberOfRotationEventsForBG = 2;
+               break;
+               case 5:
+               fnumberOfRotationEventsForBG = 50;
+               break;
+               case 6:
+               fnumberOfRotationEventsForBG = 80;
+               break;
+               case 7:
+               fnumberOfRotationEventsForBG = 100;
+               break;
+               default:
+                       cout<<"Warning: NumberOfRotations not defined "<<NumberOfRotations<<endl;
+       return kFALSE;
+       }
+       return kTRUE;
+}
+
+// ///________________________________________________________________________
+// Bool_t AliConversionMesonCuts::SetPsiPairCut(Int_t psiCut) {
+//     
+//     switch(psiCut) {
+//             case 0:
+//                     fPsiPairCut = 10000; // 
+//                     break;
+//             case 1:
+//                     fPsiPairCut = 0.1; // 
+//                     break;
+//             case 2:
+//                     fPsiPairCut = 0.05; // Standard
+//                     break;
+//             case 3:
+//                     fPsiPairCut = 0.035; // 
+//                     break;
+//             case 4:
+//                     fPsiPairCut = 0.15; // 
+//                     break;
+//             case 5:
+//                     fPsiPairCut = 0.2; // 
+//                     break;
+//             case 6:
+//                     fPsiPairCut = 0.03; // 
+//                     break;
+//             case 7:
+//                     fPsiPairCut = 0.025; // 
+//                     break;
+//             case 8:
+//                     fPsiPairCut = 0.01; // 
+//                     break;
+//             default:
+//                     cout<<"Warning: PsiPairCut not defined "<<fPsiPairCut<<endl;
+//                     return kFALSE;
+//     }
+// 
+//     return kTRUE;
+// }
+
+
+///________________________________________________________________________
+Bool_t AliConversionMesonCuts::SetSharedElectronCut(Int_t sharedElec) {
+
+       switch(sharedElec){
+               case 0:
+                       fDoSharedElecCut = kFALSE;
+               break;
+               case 1:
+                       fDoSharedElecCut = kTRUE;
+               break;
+               default:
+               cout<<"Warning: Shared Electron Cut not defined "<<sharedElec<<endl;
+               return kFALSE;
+       }
+       
+       return kTRUE;
+}
+
+///________________________________________________________________________
+Bool_t AliConversionMesonCuts::SetToCloseV0sCut(Int_t toClose) {
+
+       switch(toClose){
+               case 0:
+                       fDoToCloseV0sCut = kFALSE;
+                       fminV0Dist = 250;
+                       break;
+               case 1:
+                       fDoToCloseV0sCut = kTRUE;
+                       fminV0Dist = 1;
+                       break;
+               case 2:
+                       fDoToCloseV0sCut = kTRUE;
+                       fminV0Dist = 2;
+                       break;
+               case 3:
+                       fDoToCloseV0sCut = kTRUE;
+                       fminV0Dist = 3;
+                       break;
+               default:
+               cout<<"Warning: Shared Electron Cut not defined "<<toClose<<endl;
+               return kFALSE;
+       }
+       return kTRUE;
+}
+
+// Bool_t AliConversionMesonCuts::PsiPairCut(const AliConversionPhotonBase * photon) const {
+// 
+//     if(photon->GetPsiPair() > fPsiPairCut){
+//     return kFALSE;}
+//     else{return kTRUE;}
+// 
+// }
+
+///________________________________________________________________________
+TString AliConversionMesonCuts::GetCutNumber(){
+       // returns TString with current cut number
+       TString a(kNCuts);
+       for(Int_t ii=0;ii<kNCuts;ii++){
+               a.Append(Form("%d",fCuts[ii]));
+       }
+       return a;
+}
+
+///________________________________________________________________________
+void AliConversionMesonCuts::FillElectonLabelArray(AliAODConversionPhoton* photon, Int_t nV0){
+       
+       Int_t posLabel = photon->GetTrackLabelPositive();
+       Int_t negLabel = photon->GetTrackLabelNegative();
+       
+       fElectronLabelArray[nV0*2] = posLabel;
+       fElectronLabelArray[(nV0*2)+1] = negLabel;
+}
+
+///________________________________________________________________________
+Bool_t AliConversionMesonCuts::RejectSharedElectronV0s(AliAODConversionPhoton* photon, Int_t nV0, Int_t nV0s){
+
+       Int_t posLabel = photon->GetTrackLabelPositive();
+       Int_t negLabel = photon->GetTrackLabelNegative();
+
+       for(Int_t i = 0; i<nV0s*2;i++){
+               if(i==nV0*2)     continue;
+               if(i==(nV0*2)+1) continue;
+               if(fElectronLabelArray[i] == posLabel){
+                       return kFALSE;}
+               if(fElectronLabelArray[i] == negLabel){
+                       return kFALSE;}
+       }
+
+       return kTRUE;
+}
+///________________________________________________________________________
+Bool_t AliConversionMesonCuts::RejectToCloseV0s(AliAODConversionPhoton* photon, TList *photons, Int_t nV0){
+       Double_t posX = photon->GetConversionX();
+       Double_t posY = photon->GetConversionY();
+       Double_t posZ = photon->GetConversionZ();
+
+       for(Int_t i = 0;i<photons->GetEntries();i++){
+               if(nV0 == i) continue;
+               AliAODConversionPhoton *photonComp = (AliAODConversionPhoton*) photons->At(i);
+               Double_t posCompX = photonComp->GetConversionX();
+               Double_t posCompY = photonComp->GetConversionY();
+               Double_t posCompZ = photonComp->GetConversionZ();
+               
+               Double_t dist = pow((posX - posCompX),2)+pow((posY - posCompY),2)+pow((posZ - posCompZ),2);
+
+               if(dist < fminV0Dist*fminV0Dist){
+                       if(photon->GetChi2perNDF() < photonComp->GetChi2perNDF()) return kTRUE;
+                       else {
+                               return kFALSE;}
+               }
+               
+       }
+       return kTRUE;
+}
diff --git a/PWGGA/GammaConv/AliConversionMesonCuts.h b/PWGGA/GammaConv/AliConversionMesonCuts.h
new file mode 100644 (file)
index 0000000..fc1c28b
--- /dev/null
@@ -0,0 +1,141 @@
+#ifndef ALICONVERSIONMESONCUTS_H
+#define ALICONVERSIONMESONCUTS_H
+
+// Class handling all kinds of selection cuts for Gamma Conversion analysis
+// Authors: Svein Lindal, Daniel Lohner                                                                                                *
+
+#include "AliAODpidUtil.h"
+#include "AliConversionPhotonBase.h"
+#include "AliAODConversionMother.h"
+#include "AliAODTrack.h"
+#include "AliESDtrack.h"
+#include "AliVTrack.h"
+#include "AliAODTrack.h"
+#include "AliStack.h"
+#include "AliAnalysisCuts.h"
+#include "TH1F.h"
+
+class AliESDEvent;
+class AliAODEvent;
+class AliConversionPhotonBase;
+class AliKFVertex;
+class TH1F;
+class TH2F;
+class AliPIDResponse;
+class AliAnalysisCuts;
+class iostream;
+class TList;
+class AliAnalysisManager;
+
+
+using namespace std;
+
+class AliConversionMesonCuts : public AliAnalysisCuts {
+       
+ public: 
+
+
+  enum cutIds {
+       kMesonKind,
+       kchi2MesonCut,
+       kalphaMesonCut,               
+       kRapidityMesonCut,    
+       kRCut,
+       kBackgroundScheme,            
+       kDegreesForRotationMethod,    
+       kNumberOfRotations,           
+       kElecShare,
+       kToCloseV0s,
+       kNCuts
+  };
+
+  Bool_t SetCutIds(TString cutString); 
+  Int_t fCuts[kNCuts];
+  Bool_t SetCut(cutIds cutID, Int_t cut);
+  Bool_t UpdateCutString(cutIds cutID, Int_t value);
+
+  static const char * fgkCutNames[kNCuts];
+
+  Bool_t InitializeCutsFromCutString(const TString analysisCutSelection);
+  void FillElectonLabelArray(AliAODConversionPhoton* photon, Int_t nV0);
+   
+  AliConversionMesonCuts(const char *name="MesonCuts", const char * title="Meson Cuts");
+  virtual ~AliConversionMesonCuts();                            //virtual destructor
+
+  virtual Bool_t IsSelected(TObject* /*obj*/){return kTRUE;}
+  virtual Bool_t IsSelected(TList* /*list*/) {return kTRUE;}
+
+  TString GetCutNumber();
+
+  // Cut Selection
+  Bool_t MesonIsSelected(AliAODConversionMother *pi0,Bool_t IsSignal=kTRUE);
+  Bool_t MesonIsSelectedMC(TParticle *fMCMother,AliStack *fMCStack, Bool_t bMCDaughtersInAcceptance=kFALSE);
+       Bool_t MesonIsSelectedMCDalitz(TParticle *fMCMother,AliStack *fMCStack);
+  void PrintCuts();
+
+  void InitCutHistograms(TString name="",Bool_t preCut = kTRUE);
+  void SetFillCutHistograms(TString name="",Bool_t preCut = kTRUE){if(!fHistograms){InitCutHistograms(name,preCut);};}
+  TList *GetCutHistograms(){return fHistograms;}
+
+  ///Cut functions
+  Bool_t RejectSharedElectronV0s(AliAODConversionPhoton* photon, Int_t nV0, Int_t nV0s);
+  Bool_t RejectToCloseV0s(AliAODConversionPhoton* photon, TList *photons, Int_t nV0);
+  // Set Individual Cuts
+  Bool_t SetRCut(Int_t RCut);
+  Bool_t SetMesonKind(Int_t mesonKind);
+  Bool_t SetChi2MesonCut(Int_t chi2MesonCut);
+  Bool_t SetAlphaMesonCut(Int_t alphaMesonCut);
+  Bool_t SetRapidityMesonCut(Int_t RapidityMesonCut);
+  Bool_t SetBackgroundScheme(Int_t BackgroundScheme);
+  Bool_t SetNDegreesForRotationMethod(Int_t DegreesForRotationMethod);
+  Bool_t SetNumberOfRotations(Int_t NumberOfRotations);
+  Bool_t SetSharedElectronCut(Int_t sharedElec);
+  Bool_t SetToCloseV0sCut(Int_t toClose);
+
+
+  // Request Flags
+  Bool_t UseRotationMethod(){return fUseRotationMethodInBG;}
+  Int_t NumberOfRotationEvents(){return fnumberOfRotationEventsForBG;}
+  Int_t NDegreesRotation(){return fnDegreeRotationPMForBG;}
+  Bool_t DoBGProbability(){return fdoBGProbability;}
+  Bool_t UseElecSharingCut(){return fDoSharedElecCut;}
+  Bool_t UseToCloseV0sCut(){return fDoToCloseV0sCut;}
+
+  protected:
+  TList *fHistograms;
+  //cuts
+  Int_t fMesonKind;
+  Double_t fMaxR; //r cut  
+  Double_t fChi2CutMeson; //chicut meson
+  Double_t fAlphaMinCutMeson; // min value for meson alpha cut
+  Double_t fAlphaCutMeson; // max value for meson alpha cut
+  Double_t fRapidityCutMeson; // max value for meson rapidity
+  Bool_t fUseRotationMethodInBG; // flag to apply rotation method for meson bg estimation
+  Bool_t fdoBGProbability; // flag to use probability method for meson bg estimation
+  Bool_t fUseTrackMultiplicityForBG; // flag to use track multiplicity for meson bg estimation (else V0 mult)
+  Int_t fnDegreeRotationPMForBG; //
+  Int_t fnumberOfRotationEventsForBG; //
+  Float_t fOpeningAngle; // min opening angle for meson
+  Bool_t fDoToCloseV0sCut; //
+  Double_t fminV0Dist; //
+  Bool_t fDoSharedElecCut; //
+  TRandom3 fRandom; //
+  Int_t *fElectronLabelArray; // Array with elec/pos v0 label
+  
+  // Histograms
+  TObjString *fCutString; // cut number used for analysis
+  TH1F *hMesonCuts; // bookkeeping for meson cuts
+  TH1F *hMesonBGCuts; // bookkeeping for meson bg cuts
+
+
+private:
+
+  AliConversionMesonCuts(const AliConversionMesonCuts&); // not implemented
+  AliConversionMesonCuts& operator=(const AliConversionMesonCuts&); // not implemented
+
+
+  ClassDef(AliConversionMesonCuts,2)
+};
+
+
+#endif
index ec7a25f042754a8109b2f8da21803f8fcc9c4c63..8ddc45955aaacb55907cb058bd7b5384b931fa50 100644 (file)
@@ -340,6 +340,8 @@ Double_t AliConversionSelection::GetMultiplicity(AliVEvent *inputEvent){
        return GetVZEROMult(inputEvent);
     case 3:
        return GetSPDMult(inputEvent);
+    case 9:
+        return 1; // if mult is used as a weight, this number can be used to switch off weighting
     default:
        return 0;
     }
diff --git a/PWGGA/GammaConv/AliDalitzElectronCuts.cxx b/PWGGA/GammaConv/AliDalitzElectronCuts.cxx
new file mode 100644 (file)
index 0000000..efa58f2
--- /dev/null
@@ -0,0 +1,1287 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                       *
+ * Authors: Svein Lindal, Daniel Lohner                                          *
+ * Version 1.0                                                           *
+ *                                                                       *
+ * Permission to use, copy, modify and distribute this software and its          *
+ * documentation strictly for non-commercial purposes is hereby granted          *
+ * without fee, provided that the above copyright notice appears in all          *
+ * copies and that both the copyright notice and this permission notice          *
+ * appear in the supporting documentation. The authors make no claims    *
+ * about the suitability of this software for any purpose. It is         *
+ * provided "as is" without express or implied warranty.                 *
+ **************************************************************************/
+
+////////////////////////////////////////////////
+//--------------------------------------------- 
+// Class handling all kinds of selection cuts for
+// Gamma Conversion analysis
+//---------------------------------------------
+////////////////////////////////////////////////
+
+
+#include "AliDalitzElectronCuts.h"
+#include "AliAODConversionPhoton.h"
+#include "AliKFVertex.h"
+#include "AliAODTrack.h"
+#include "AliESDtrack.h"
+#include "AliAnalysisManager.h"
+#include "AliInputEventHandler.h"
+#include "AliMCEventHandler.h"
+#include "AliAODHandler.h"
+#include "AliPIDResponse.h"
+#include "TH1.h"
+#include "TH2.h"
+#include "AliStack.h"
+#include "TObjString.h"
+#include "AliAODEvent.h"
+#include "AliESDEvent.h"
+#include "TList.h"
+class iostream;
+
+using namespace std;
+
+ClassImp(AliDalitzElectronCuts)
+
+
+const char* AliDalitzElectronCuts::fgkCutNames[AliDalitzElectronCuts::kNCuts] = {
+"GoodId",
+"ededxSigmaITSCut",
+"ededxSigmaTPCCut",
+"pidedxSigmaTPCCut",
+"piMinMomdedxSigmaTPCCut",
+"piMaxMomdedxSigmaTPCCut",
+"LowPRejectionSigmaCut",
+"kTOFelectronPID",
+"clsTPCCut",
+"EtaCut",
+"PsiPair",
+"RejectSharedElecGamma",
+"BackgroundScheme",
+};
+
+//________________________________________________________________________
+AliDalitzElectronCuts::AliDalitzElectronCuts(const char *name,const char *title) : AliAnalysisCuts(name,title),
+    fHistograms(NULL),
+    fPIDResponse(NULL),
+    fesdTrackCuts(0),
+    fEtaCut(0.9),
+    fRadiusCut(1000.0),
+    fPsiPairCut(0.45),
+    fDeltaPhiCutMin(0.),
+    fDeltaPhiCutMax(0.12),
+    fMinClsTPC(0), // minimum clusters in the TPC
+    fMinClsTPCToF(0), // minimum clusters to findable clusters
+    fDodEdxSigmaITSCut(kFALSE),
+    fDodEdxSigmaTPCCut(kTRUE),
+    fDoTOFsigmaCut(kFALSE), // RRnewTOF
+    fDoRejectSharedElecGamma(kFALSE),
+    fDoPsiPairCut(kFALSE),
+    fPIDnSigmaAboveElectronLineITS(100),
+    fPIDnSigmaBelowElectronLineITS(-100),
+    fPIDnSigmaAboveElectronLineTPC(100),
+    fPIDnSigmaBelowElectronLineTPC(-100),
+    fPIDnSigmaAbovePionLineTPC(0),
+    fPIDnSigmaAbovePionLineTPCHighPt(-100),
+    fTofPIDnSigmaAboveElectronLine(100), // RRnewTOF
+    fTofPIDnSigmaBelowElectronLine(-100), // RRnewTOF
+    fPIDMinPnSigmaAbovePionLineTPC(0),
+    fPIDMaxPnSigmaAbovePionLineTPC(0),
+    fDoKaonRejectionLowP(kFALSE),
+    fDoProtonRejectionLowP(kFALSE),
+    fDoPionRejectionLowP(kFALSE),
+    fPIDnSigmaAtLowPAroundKaonLine(0),
+    fPIDnSigmaAtLowPAroundProtonLine(0),
+    fPIDnSigmaAtLowPAroundPionLine(0),
+    fPIDMinPKaonRejectionLowP(1.5),
+    fPIDMinPProtonRejectionLowP(2.0),
+    fPIDMinPPionRejectionLowP(0.5),
+    fUseCorrectedTPCClsInfo(kFALSE),
+    fUseTOFpid(kFALSE),
+    fUseTrackMultiplicityForBG(kFALSE),
+    fBKGMethod(0),
+    fCutString(NULL),
+    hCutIndex(NULL),
+    hdEdxCuts(NULL),
+    hITSdEdxbefore(NULL),
+    hITSdEdxafter(NULL),
+    hTPCdEdxbefore(NULL),
+    hTPCdEdxafter(NULL),
+    hTOFbefore(NULL),
+    hTOFafter(NULL)
+   {
+    InitPIDResponse();
+    for(Int_t jj=0;jj<kNCuts;jj++){fCuts[jj]=0;}
+    fCutString=new TObjString((GetCutNumber()).Data());
+
+
+    fesdTrackCuts = new AliESDtrackCuts("AliESDtrackCuts");
+
+   // Using standard function for setting Cuts
+    Bool_t selectPrimaries=kTRUE;
+    fesdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(selectPrimaries);
+}
+
+//________________________________________________________________________
+AliDalitzElectronCuts::~AliDalitzElectronCuts() {
+    // Destructor
+  //Deleting fHistograms leads to seg fault it it's added to output collection of a task
+  // if(fHistograms)
+  //   delete fHistograms;
+  // fHistograms = NULL;
+
+   if(fCutString != NULL){
+      delete fCutString;
+      fCutString = NULL;
+   }
+
+
+}
+
+//________________________________________________________________________
+void AliDalitzElectronCuts::InitCutHistograms(TString name, Bool_t preCut){
+
+    // Initialize Cut Histograms for QA (only initialized and filled if function is called)
+
+
+    if(fHistograms != NULL){
+       delete fHistograms;
+       fHistograms=NULL;
+    }
+    if(fHistograms==NULL){
+       fHistograms=new TList();
+       if(name=="")fHistograms->SetName(Form("ElectronCuts_%s",GetCutNumber().Data()));
+       else fHistograms->SetName(Form("%s_%s",name.Data(),GetCutNumber().Data()));
+    }
+
+
+    hCutIndex=new TH1F(Form("IsElectronSelected %s",GetCutNumber().Data()),"IsElectronSelected",10,-0.5,9.5);
+    hCutIndex->GetXaxis()->SetBinLabel(kElectronIn+1,"in");
+    hCutIndex->GetXaxis()->SetBinLabel(kNoTracks+1,"no tracks");
+    hCutIndex->GetXaxis()->SetBinLabel(kTrackCuts+1,"Track cuts");
+    hCutIndex->GetXaxis()->SetBinLabel(kdEdxCuts+1,"dEdx");
+    hCutIndex->GetXaxis()->SetBinLabel(kElectronOut+1,"out");
+    fHistograms->Add(hCutIndex);
+
+
+
+    // dEdx Cuts
+    hdEdxCuts=new TH1F(Form("dEdxCuts %s",GetCutNumber().Data()),"dEdxCuts",10,-0.5,9.5);
+    hdEdxCuts->GetXaxis()->SetBinLabel(1,"in");
+    hdEdxCuts->GetXaxis()->SetBinLabel(2,"ITSelectron");
+    hdEdxCuts->GetXaxis()->SetBinLabel(3,"TPCelectron");
+    hdEdxCuts->GetXaxis()->SetBinLabel(4,"TPCpion");
+    hdEdxCuts->GetXaxis()->SetBinLabel(5,"TPCpionhighp");
+    hdEdxCuts->GetXaxis()->SetBinLabel(6,"TPCkaonlowprej");
+    hdEdxCuts->GetXaxis()->SetBinLabel(7,"TPCprotonlowprej");
+    hdEdxCuts->GetXaxis()->SetBinLabel(8,"TPCpionlowprej");
+    hdEdxCuts->GetXaxis()->SetBinLabel(9,"TOFelectron");
+    hdEdxCuts->GetXaxis()->SetBinLabel(10,"out");
+    fHistograms->Add(hdEdxCuts);
+    
+
+
+    TAxis *AxisBeforeITS = NULL;
+    TAxis *AxisBeforedEdx = NULL;
+    TAxis *AxisBeforeTOF = NULL;
+
+    if(preCut){
+
+
+       hITSdEdxbefore=new TH2F(Form("Electron_ITS_before %s",GetCutNumber().Data()),"ITS dEdx electron before" ,150,0.05,20,400,-10,10);
+       fHistograms->Add(hITSdEdxbefore);
+       AxisBeforeITS = hITSdEdxbefore->GetXaxis();
+
+       hTPCdEdxbefore=new TH2F(Form("Electron_dEdx_before %s",GetCutNumber().Data()),"dEdx electron before" ,150,0.05,20,400,-10,10);
+       fHistograms->Add(hTPCdEdxbefore);
+       AxisBeforedEdx = hTPCdEdxbefore->GetXaxis();
+
+       hTOFbefore=new TH2F(Form("Electron_TOF_before %s",GetCutNumber().Data()),"TOF electron before" ,150,0.05,20,400,-6,10);
+       fHistograms->Add(hTOFbefore);
+       AxisBeforeTOF = hTOFbefore->GetXaxis();
+
+    }
+
+
+    hITSdEdxafter=new TH2F(Form("Electron_ITS_after %s",GetCutNumber().Data()),"ITS dEdx electron after" ,150,0.05,20,400, -10,10);
+    fHistograms->Add(hITSdEdxafter);
+
+    hTPCdEdxafter=new TH2F(Form("Electron_dEdx_after %s",GetCutNumber().Data()),"dEdx electron after" ,150,0.05,20,400, -10,10);
+    fHistograms->Add(hTPCdEdxafter);
+
+    hTOFafter=new TH2F(Form("Electron_TOF_after %s",GetCutNumber().Data()),"TOF electron after" ,150,0.05,20,400,-6,10);
+    fHistograms->Add(hTOFafter);
+
+    TAxis *AxisAfter = hTPCdEdxafter->GetXaxis(); 
+    Int_t bins = AxisAfter->GetNbins();
+    Double_t from = AxisAfter->GetXmin();
+    Double_t to = AxisAfter->GetXmax();
+    Double_t *newBins = new Double_t[bins+1];
+    newBins[0] = from;
+    Double_t factor = TMath::Power(to/from, 1./bins);
+    for(Int_t i=1; i<=bins; ++i) newBins[i] = factor * newBins[i-1];
+    AxisAfter->Set(bins, newBins);
+    AxisAfter = hTOFafter->GetXaxis(); 
+    AxisAfter->Set(bins, newBins);
+        AxisAfter = hITSdEdxafter->GetXaxis(); 
+    AxisAfter->Set(bins, newBins);
+
+    if(preCut){
+       AxisBeforeITS->Set(bins, newBins);
+       AxisBeforedEdx->Set(bins, newBins);
+       AxisBeforeTOF->Set(bins, newBins);
+    }
+    delete [] newBins;
+
+        
+    // Event Cuts and Info
+}
+
+
+//________________________________________________________________________
+Bool_t AliDalitzElectronCuts::InitPIDResponse(){
+
+// Set Pointer to AliPIDResponse
+
+  AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
+
+  if(man) {
+
+    AliInputEventHandler* inputHandler = (AliInputEventHandler*) (man->GetInputEventHandler());
+    fPIDResponse = (AliPIDResponse*)inputHandler->GetPIDResponse();
+    if(fPIDResponse)return kTRUE;
+
+  }
+
+  return kFALSE;
+}
+
+///________________________________________________________________________
+Bool_t AliDalitzElectronCuts::ElectronIsSelected(AliESDtrack* lTrack)
+{
+    //Selection of Reconstructed electrons
+
+    if(hCutIndex)hCutIndex->Fill(kElectronIn);
+
+
+    if ( ! lTrack->GetConstrainedParam() ){
+        
+       
+
+        return kFALSE;
+
+    }
+
+
+
+    if( ! lTrack ) {
+         if(hCutIndex)hCutIndex->Fill(kNoTracks);
+         return kFALSE;
+    }
+
+    AliVTrack * track = dynamic_cast<AliVTrack*>(lTrack);
+
+
+    // Track Cuts
+    if( !TrackIsSelected(lTrack) ){
+         if(hCutIndex)hCutIndex->Fill(kTrackCuts);
+         return kFALSE;
+    }
+
+
+    // dEdx Cuts
+    if( ! dEdxCuts( track ) ) {
+         if(hCutIndex)hCutIndex->Fill(kdEdxCuts);
+         return kFALSE;
+
+    }
+
+    //Electron passed the cuts
+    if(hCutIndex)hCutIndex->Fill(kElectronOut);
+
+
+    return kTRUE;
+}
+
+///________________________________________________________________________
+Bool_t AliDalitzElectronCuts::TrackIsSelected(AliESDtrack* lTrack) {
+    // Track Selection for Photon Reconstruction
+
+
+
+    if( ! fesdTrackCuts->AcceptTrack(lTrack) ){
+
+        return kFALSE;
+    }
+
+   if(  TMath::Abs( lTrack->Eta()) > fEtaCut ) {
+
+        return kFALSE;
+    }
+
+    if( lTrack->GetNcls(1) < fMinClsTPC ) {
+
+        return kFALSE;
+    }
+
+    //Findable clusters
+
+    Double_t clsToF=0;
+
+
+    if (!fUseCorrectedTPCClsInfo ){
+        if(lTrack->GetTPCNclsF()!=0){
+
+              clsToF = (Double_t)lTrack->GetNcls(1)/(Double_t)lTrack->GetTPCNclsF();
+        }// Ncluster/Nfindablecluster
+    }
+    else {
+
+              //clsToF = lTrack->GetTPCClusterInfo(2,0,GetFirstTPCRow(photon->GetConversionRadius()));
+              clsToF = lTrack->GetTPCClusterInfo(2,1); //NOTE ask friederike
+                
+    }
+
+
+    if( clsToF < fMinClsTPCToF){
+    return kFALSE;
+    }
+
+
+
+   return kTRUE;
+}
+///________________________________________________________________________
+Bool_t AliDalitzElectronCuts::dEdxCuts(AliVTrack *fCurrentTrack){
+
+    // Electron Identification Cuts for Photon reconstruction
+
+    if(!fPIDResponse){  InitPIDResponse();  }// Try to reinitialize PID Response
+    if(!fPIDResponse){  AliError("No PID Response"); return kFALSE;}// if still missing fatal error
+
+
+
+    //cout<<"dEdxCuts: //////////////////////////////////////////////////////////////////////////"<<endl;
+
+
+
+    Int_t cutIndex=0;
+
+    if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
+    if(hITSdEdxbefore)hITSdEdxbefore->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasITS(fCurrentTrack, AliPID::kElectron));
+    if(hTPCdEdxbefore)hTPCdEdxbefore->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTPC(fCurrentTrack, AliPID::kElectron));
+
+
+    cutIndex++;
+
+
+  if( fDodEdxSigmaITSCut == kTRUE ){
+
+
+        if( fPIDResponse->NumberOfSigmasITS(fCurrentTrack,AliPID::kElectron)<fPIDnSigmaBelowElectronLineITS ||
+                fPIDResponse->NumberOfSigmasITS(fCurrentTrack,AliPID::kElectron)> fPIDnSigmaAboveElectronLineITS ){
+
+          if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
+          return kFALSE;
+      }
+     
+  }
+
+ if(hITSdEdxafter)hITSdEdxafter->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasITS(fCurrentTrack, AliPID::kElectron));
+
+
+  cutIndex++;
+
+
+  if(fDodEdxSigmaTPCCut == kTRUE){
+
+
+      // TPC Electron Line
+      if( fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)<fPIDnSigmaBelowElectronLineTPC ||
+               fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)>fPIDnSigmaAboveElectronLineTPC){
+
+         if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
+         return kFALSE;
+      }
+      cutIndex++;
+
+      // TPC Pion Line
+       if( fCurrentTrack->P()>fPIDMinPnSigmaAbovePionLineTPC && fCurrentTrack->P()<fPIDMaxPnSigmaAbovePionLineTPC ){
+         if(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)>fPIDnSigmaBelowElectronLineTPC     &&
+                fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)<fPIDnSigmaAboveElectronLineTPC &&
+                fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kPion)<fPIDnSigmaAbovePionLineTPC){
+
+             if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
+             return kFALSE;
+         }
+       }
+       cutIndex++;
+   
+       // High Pt Pion rej
+       if( fCurrentTrack->P()>fPIDMaxPnSigmaAbovePionLineTPC ){
+         if(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)>fPIDnSigmaBelowElectronLineTPC &&
+                fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)<fPIDnSigmaAboveElectronLineTPC&&
+                fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kPion)<fPIDnSigmaAbovePionLineTPCHighPt){
+
+                if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
+               return kFALSE;
+         }
+       }
+
+       cutIndex++;
+  }
+
+  else{ cutIndex+=3; }
+
+
+  if(   fDoKaonRejectionLowP == kTRUE   ){
+
+        if( fCurrentTrack->P() < fPIDMinPKaonRejectionLowP ){
+
+          if( TMath::Abs(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kKaon))<fPIDnSigmaAtLowPAroundKaonLine){
+
+              if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
+
+              return kFALSE;
+          }
+        }
+  }
+  cutIndex++;
+   
+  if(   fDoProtonRejectionLowP == kTRUE    ){
+
+        if( fCurrentTrack->P()  < fPIDMinPProtonRejectionLowP ){
+          if( TMath::Abs(   fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kProton))<fPIDnSigmaAtLowPAroundProtonLine){
+
+              if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
+              return kFALSE;
+          }
+        }
+  }
+   cutIndex++;
+   
+  if(fDoPionRejectionLowP == kTRUE){
+        if( fCurrentTrack->P() < fPIDMinPPionRejectionLowP ){
+          if( TMath::Abs( fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kPion)) < fPIDnSigmaAtLowPAroundPionLine ){
+
+              if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
+                return kFALSE;
+          }
+        }
+  }
+  cutIndex++;
+
+   
+  if((fCurrentTrack->GetStatus() & AliESDtrack::kTOFpid) && !(fCurrentTrack->GetStatus() & AliESDtrack::kTOFmismatch)){
+     if(hTOFbefore) hTOFbefore->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTOF(fCurrentTrack, AliPID::kElectron));
+     if(fUseTOFpid){
+        if(fPIDResponse->NumberOfSigmasTOF(fCurrentTrack, AliPID::kElectron)>fTofPIDnSigmaAboveElectronLine ||
+           fPIDResponse->NumberOfSigmasTOF(fCurrentTrack, AliPID::kElectron)<fTofPIDnSigmaBelowElectronLine ){
+           if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
+           return kFALSE;
+        }
+     }
+     if(hTOFafter)hTOFafter->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTOF(fCurrentTrack, AliPID::kElectron));
+  }
+     cutIndex++;
+
+  if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
+  if(hTPCdEdxafter)hTPCdEdxafter->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTPC(fCurrentTrack, AliPID::kElectron));
+
+  return kTRUE;
+}
+///________________________________________________________________________
+
+
+AliVTrack *AliDalitzElectronCuts::GetTrack(AliVEvent * event, Int_t label){
+    //Returns pointer to the track with given ESD label
+    //(Important for AOD implementation, since Track array in AOD data is different
+    //from ESD array, but ESD tracklabels are stored in AOD Tracks)
+
+  AliESDEvent * esdEvent = dynamic_cast<AliESDEvent*>(event);
+  if(esdEvent) {
+       if(label > event->GetNumberOfTracks() ) return NULL;
+       AliESDtrack * track = esdEvent->GetTrack(label);
+       return track;
+       
+  } else { 
+       for(Int_t ii=0; ii<event->GetNumberOfTracks(); ii++) {
+         AliVTrack * track = dynamic_cast<AliVTrack*>(event->GetTrack(ii));
+         
+         if(track) { 
+               if(track->GetID() == label) {
+                 return track;
+               }
+         }
+       }
+    }
+  
+  cout << "track not found " << label << " " << event->GetNumberOfTracks() << endl;
+  return NULL;
+}
+///________________________________________________________________________
+Bool_t AliDalitzElectronCuts::RejectSharedElecGamma(TList *photons, Int_t indexEle){
+
+
+     for(Int_t i = 0;i<photons->GetEntries();i++){
+
+      AliAODConversionPhoton *photonComp = (AliAODConversionPhoton*) photons->At(i);
+
+      Int_t posLabel = photonComp->GetTrackLabelPositive();
+      Int_t negLabel = photonComp->GetTrackLabelNegative();
+
+      if( (photonComp->GetConversionRadius() < fRadiusCut) && (posLabel == indexEle || negLabel == indexEle) ){
+        return kFALSE;
+      }
+     }
+
+   return kTRUE;
+}
+
+Double_t AliDalitzElectronCuts::GetPsiPair( const AliESDtrack* trackPos, const AliESDtrack* trackNeg ) const
+{
+//
+// This angle is a measure for the contribution of the opening in polar
+// direction Δ0 to the opening angle ξ Pair
+//
+// Ref. Measurement of photons via conversion pairs with the PHENIX experiment at RHIC
+//      Master Thesis. Thorsten Dahms. 2005
+// https://twiki.cern.ch/twiki/pub/ALICE/GammaPhysicsPublications/tdahms_thesis.pdf
+//
+        Double_t momPos[3];
+        Double_t momNeg[3];
+        if( trackPos->GetConstrainedPxPyPz(momPos) == 0 ) trackPos->GetPxPyPz( momPos );
+        if( trackNeg->GetConstrainedPxPyPz(momNeg) == 0 ) trackNeg->GetPxPyPz( momNeg );
+
+        TVector3 posDaughter;
+        TVector3 negDaughter;
+
+        posDaughter.SetXYZ( momPos[0], momPos[1], momPos[2] );
+        negDaughter.SetXYZ( momNeg[0], momNeg[1], momNeg[2] );
+
+        Double_t deltaTheta = negDaughter.Theta() - posDaughter.Theta();
+        Double_t openingAngle =  posDaughter.Angle( negDaughter );  //TMath::ACos( posDaughter.Dot(negDaughter)/(negDaughter.Mag()*posDaughter.Mag()) );
+        if( openingAngle < 1e-20 ) return 0.;
+        Double_t psiAngle = TMath::ASin( deltaTheta/openingAngle );
+
+        return psiAngle;
+}
+
+Bool_t AliDalitzElectronCuts::IsFromGammaConversion( Double_t psiPair, Double_t deltaPhi ) const
+{
+//
+// Returns true if it is a gamma conversion according to psi pair value
+//
+        return ( (deltaPhi > fDeltaPhiCutMin  &&  deltaPhi < fDeltaPhiCutMax) &&
+        TMath::Abs(psiPair) < ( fPsiPairCut - fPsiPairCut/fDeltaPhiCutMax * deltaPhi ) );
+}
+
+///________________________________________________________________________
+Bool_t AliDalitzElectronCuts::UpdateCutString(cutIds cutID, Int_t value) {
+///Update the cut string (if it has been created yet)
+
+  if(fCutString && fCutString->GetString().Length() == kNCuts) {
+        cout << "Updating cut id in spot number " << cutID << " to " << value << endl;
+       fCutString->SetString(GetCutNumber());
+  } else {
+        cout << "fCutString not yet initialized, will not be updated" << endl;
+       return kFALSE;
+  }
+ // cout << fCutString->GetString().Data() << endl;
+  return kTRUE;
+}
+
+///________________________________________________________________________
+Bool_t AliDalitzElectronCuts::InitializeCutsFromCutString(const TString analysisCutSelection ) {
+   // Initialize Cuts from a given Cut string
+
+  cout<<"Set Cut Number: "<<analysisCutSelection.Data()<<endl;
+  if(analysisCutSelection.Length()!=kNCuts) {
+       AliError(Form("Cut selection has the wrong length! size is %d, number of cuts is %d", analysisCutSelection.Length(), kNCuts));
+       return kFALSE;
+  }
+  if(!analysisCutSelection.IsDigit()){
+       AliError("Cut selection contains characters");
+       return kFALSE;
+  }
+  
+  const char *cutSelection = analysisCutSelection.Data();
+  #define ASSIGNARRAY(i)       fCuts[i] = cutSelection[i] - '0'
+  for(Int_t ii=0;ii<kNCuts;ii++){
+      ASSIGNARRAY(ii);
+  }
+
+  // TestFlag
+  if(fCuts[0] !=9){
+    AliError("Analysis Cut Selection does not start with 9");
+       PrintCuts();
+    return kFALSE;
+  }
+
+  // Set Individual Cuts
+  for(Int_t ii=0;ii<kNCuts;ii++){
+      if(!SetCut(cutIds(ii),fCuts[ii]))return kFALSE;
+  }
+
+  //PrintCuts();
+
+    return kTRUE;
+}
+///________________________________________________________________________
+Bool_t AliDalitzElectronCuts::SetCut(cutIds cutID, const Int_t value) {
+  ///Set individual cut ID
+
+  //cout << "Updating cut  " << fgkCutNames[cutID] << " (" << cutID << ") to " << value << endl;
+
+  switch (cutID) {
+  case kgoodId:
+       fCuts[kgoodId] = value;
+       if(value != 9) {
+         cout << "Error:: First value of cut string is wrong, aborting!!" << endl;
+         return kFALSE;
+       } else {
+         return kTRUE;
+       }
+
+  case kededxSigmaITSCut:
+       if( SetITSdEdxCutElectronLine(value)) { //NOTE SetITSdEdxCutElectronLine: To be implemented 
+         fCuts[kededxSigmaITSCut] = value;
+         UpdateCutString(cutID, value);
+         return kTRUE;
+       } else return kFALSE;
+
+ case kededxSigmaTPCCut:
+        if( SetTPCdEdxCutElectronLine(value)) { //NOTE SetITSdEdxCutElectronLine: To be implemented 
+          fCuts[kededxSigmaTPCCut] = value;
+          UpdateCutString(cutID, value);
+          return kTRUE;
+        } else return kFALSE;
+
+  case kpidedxSigmaTPCCut:
+        if( SetTPCdEdxCutPionLine(value)) { //NOTE SetITSdEdxCutPionLine: To be implemented
+          fCuts[kpidedxSigmaTPCCut] = value;
+          UpdateCutString(cutID, value);
+          return kTRUE;
+        } else return kFALSE;
+
+  case kpiMinMomdedxSigmaTPCCut:
+       if( SetMinMomPiondEdxTPCCut(value)) {
+         fCuts[kpiMinMomdedxSigmaTPCCut] = value;
+         UpdateCutString(cutID, value);
+         return kTRUE;
+       } else return kFALSE;
+
+  case kpiMaxMomdedxSigmaTPCCut:
+        if( SetMaxMomPiondEdxTPCCut(value)) {
+          fCuts[kpiMaxMomdedxSigmaTPCCut] = value;
+          UpdateCutString(cutID, value);
+          return kTRUE;
+        } else return kFALSE;
+
+  case kLowPRejectionSigmaCut:
+        if( SetLowPRejectionCuts(value) ) {
+          fCuts[kLowPRejectionSigmaCut] = value;
+          UpdateCutString(cutID, value);
+          return kTRUE;
+        } else return kFALSE;
+
+
+  case kTOFelectronPID:
+        if( SetTOFElectronPIDCut(value)) {
+          fCuts[kTOFelectronPID] = value;
+          UpdateCutString(cutID, value);
+          return kTRUE;
+        } else return kFALSE;
+
+  case kclsTPCCut:
+       if( SetTPCClusterCut(value)) {
+         fCuts[kclsTPCCut] = value;
+         UpdateCutString(cutID, value);
+         return kTRUE;
+       } else return kFALSE;
+
+  case ketaCut:
+       if( SetEtaCut(value)) {
+         fCuts[ketaCut] = value;
+         UpdateCutString(cutID, value);
+         return kTRUE;
+       } else return kFALSE;
+   case kPsiPair:
+        if( SetPsiPairCut(value)) {
+          fCuts[kPsiPair] = value;
+          UpdateCutString(cutID, value);
+          return kTRUE;
+        } else return kFALSE;
+
+  case kRejectSharedElecGamma:
+        if( SetRejectSharedElecGamma(value)) {
+          fCuts[kRejectSharedElecGamma] = value;
+          UpdateCutString(cutID, value);
+          return kTRUE;
+        } else return kFALSE;
+
+  case kBackgroundScheme:
+        if( SetBackgroundScheme(value)) {
+          fCuts[kBackgroundScheme] = value;
+          UpdateCutString(cutID, value);
+          return kTRUE;
+        } else return kFALSE;
+
+  case kNCuts:
+       cout << "Error:: Cut id out of range"<< endl;
+       return kFALSE;
+  }
+
+  cout << "Error:: Cut id " << cutID << " not recognized "<< endl;
+  return kFALSE;
+
+  //PrintCuts();
+  
+}
+
+///________________________________________________________________________
+
+void AliDalitzElectronCuts::PrintCuts() {
+    // Print out current Cut Selection
+  for(Int_t ic = 0; ic < kNCuts; ic++) {
+       printf("%-30s : %d \n", fgkCutNames[ic], fCuts[ic]);
+  }
+
+}
+
+///________________________________________________________________________
+Bool_t AliDalitzElectronCuts::SetITSdEdxCutElectronLine(Int_t ededxSigmaCut)
+{   // Set Cut
+
+       switch(ededxSigmaCut){
+
+                case 0: 
+                        fDodEdxSigmaITSCut = kFALSE;
+                        fPIDnSigmaBelowElectronLineITS=-100;
+                        fPIDnSigmaAboveElectronLineITS= 100;
+                        break;
+               case 1: // -10,10
+                        fDodEdxSigmaITSCut = kTRUE;
+                       fPIDnSigmaBelowElectronLineITS=-10;
+                       fPIDnSigmaAboveElectronLineITS=10;
+                       break;
+               case 2: // -6,7
+                        fDodEdxSigmaITSCut = kTRUE;
+                       fPIDnSigmaBelowElectronLineITS=-6;
+                       fPIDnSigmaAboveElectronLineITS=7;
+                       break;
+               case 3: // -5,5
+                        fDodEdxSigmaITSCut = kTRUE;
+                       fPIDnSigmaBelowElectronLineITS=-5;
+                       fPIDnSigmaAboveElectronLineITS=5;
+                       break;
+               case 4: // -4,5
+                        fDodEdxSigmaITSCut = kTRUE;
+                       fPIDnSigmaBelowElectronLineITS=-4;
+                       fPIDnSigmaAboveElectronLineITS=5;
+                       break;
+               case 5: // -3,5
+                        fDodEdxSigmaITSCut = kTRUE;
+                       fPIDnSigmaBelowElectronLineITS=-3;
+                       fPIDnSigmaAboveElectronLineITS=5;
+                       break;
+               case 6: // -4,4
+                        fDodEdxSigmaITSCut = kTRUE;
+                       fPIDnSigmaBelowElectronLineITS=-4;
+                       fPIDnSigmaAboveElectronLineITS=4;
+                       break;
+               case 7: // -2.5,4
+                        fDodEdxSigmaITSCut = kTRUE;
+                       fPIDnSigmaBelowElectronLineITS=-2.5;
+                       fPIDnSigmaAboveElectronLineITS=4;
+                       break;
+               case 8: // -2,3.5
+                        fDodEdxSigmaITSCut = kTRUE;
+                       fPIDnSigmaBelowElectronLineITS=-2;
+                       fPIDnSigmaAboveElectronLineITS=3.5;
+                       break;
+               default:
+                       cout<<"Warning: ITSdEdxCutElectronLine not defined"<<ededxSigmaCut<<endl;
+                       return kFALSE;
+        
+    }
+    return kTRUE;
+}
+
+///________________________________________________________________________
+Bool_t AliDalitzElectronCuts::SetTPCdEdxCutElectronLine(Int_t ededxSigmaCut)
+{   // Set Cut
+               switch(ededxSigmaCut){
+
+                case 0: fDodEdxSigmaTPCCut = kFALSE;
+                        fPIDnSigmaBelowElectronLineTPC=-10;
+                        fPIDnSigmaAboveElectronLineTPC=10;
+                        break;
+               case 1: // -10,10
+                        fDodEdxSigmaTPCCut = kTRUE;
+                       fPIDnSigmaBelowElectronLineTPC=-10;
+                       fPIDnSigmaAboveElectronLineTPC=10;
+                       break;
+               case 2: // -6,7
+                        fDodEdxSigmaTPCCut = kTRUE;
+                       fPIDnSigmaBelowElectronLineTPC=-6;
+                       fPIDnSigmaAboveElectronLineTPC=7;
+                       break;
+               case 3: // -5,5
+                        fDodEdxSigmaTPCCut = kTRUE;
+                       fPIDnSigmaBelowElectronLineTPC=-5;
+                       fPIDnSigmaAboveElectronLineTPC=5;
+                       break;
+               case 4: // -4,5
+                        fDodEdxSigmaTPCCut = kTRUE;
+                       fPIDnSigmaBelowElectronLineTPC=-4;
+                       fPIDnSigmaAboveElectronLineTPC=5;
+                       break;  
+               case 5: // -3,5
+                        fDodEdxSigmaTPCCut = kTRUE;
+                       fPIDnSigmaBelowElectronLineTPC=-3;
+                       fPIDnSigmaAboveElectronLineTPC=5;
+                       break;
+               case 6: // -4,4
+                        fDodEdxSigmaTPCCut = kTRUE;
+                       fPIDnSigmaBelowElectronLineTPC=-4;
+                       fPIDnSigmaAboveElectronLineTPC=4;
+                       break;
+               case 7: // -2.5,4
+                        fDodEdxSigmaTPCCut = kTRUE;
+                       fPIDnSigmaBelowElectronLineTPC=-2.5;
+                       fPIDnSigmaAboveElectronLineTPC=4;
+                       break;
+               case 8: // -2,3.5
+                        fDodEdxSigmaTPCCut = kTRUE;
+                       fPIDnSigmaBelowElectronLineTPC=-2;
+                       fPIDnSigmaAboveElectronLineTPC=3.5;
+                       break;
+               default:
+                       cout<<"Warning: TPCdEdxCutElectronLine not defined"<<ededxSigmaCut<<endl;
+                       return kFALSE;
+        
+    }
+    return kTRUE;
+}
+
+///________________________________________________________________________
+Bool_t AliDalitzElectronCuts::SetTPCdEdxCutPionLine(Int_t pidedxSigmaCut)
+{   // Set Cut
+
+       switch(pidedxSigmaCut){
+                
+                case 0: fPIDnSigmaAbovePionLineTPC= 0;
+                        fPIDnSigmaAbovePionLineTPCHighPt=-100;
+                        break;
+               case 1:  // -10
+                       fPIDnSigmaAbovePionLineTPC=-10;
+                       fPIDnSigmaAbovePionLineTPCHighPt=-10;
+                       break;
+               case 2:  // 1
+                       fPIDnSigmaAbovePionLineTPC=-1;
+                       fPIDnSigmaAbovePionLineTPCHighPt=-10;
+                       break;
+               case 3:   // 0
+                       fPIDnSigmaAbovePionLineTPC=0;
+                       fPIDnSigmaAbovePionLineTPCHighPt=-10;
+                       break;
+               case 4:  // 1
+                       fPIDnSigmaAbovePionLineTPC=1;
+                       fPIDnSigmaAbovePionLineTPCHighPt=-10;
+                       break;
+               case 5:  // 1
+                       fPIDnSigmaAbovePionLineTPC=2.;
+                       fPIDnSigmaAbovePionLineTPCHighPt=-10;
+                       break;
+               case 6:  // 1
+                       fPIDnSigmaAbovePionLineTPC=2.5;
+                       fPIDnSigmaAbovePionLineTPCHighPt=-10;
+                       break;
+               case 7:
+                       fPIDnSigmaAbovePionLineTPC=3.0; // We need a bit less tight cut on dE/dx
+                       fPIDnSigmaAbovePionLineTPCHighPt=-10;
+                       break;
+               case 8:  // 1
+                       fPIDnSigmaAbovePionLineTPC=3.5;
+                       fPIDnSigmaAbovePionLineTPCHighPt=-10;
+                       break;
+               case 9:  // 1
+                       fPIDnSigmaAbovePionLineTPC=1.5;
+                       fPIDnSigmaAbovePionLineTPCHighPt=-1.0;
+                       break;
+               default:
+                       cout<<"Warning: pidedxSigmaCut not defined "<<pidedxSigmaCut<<endl;
+                       return kFALSE;
+       }
+       return kTRUE;
+}
+
+///________________________________________________________________________
+Bool_t AliDalitzElectronCuts::SetMinMomPiondEdxTPCCut(Int_t piMomdedxSigmaCut)
+{   // Set Cut
+       switch(piMomdedxSigmaCut){
+                
+                case 0: fPIDMinPnSigmaAbovePionLineTPC=0.;
+                        break;
+               case 1:  // 50.0 GeV
+                       fPIDMinPnSigmaAbovePionLineTPC=50.;
+                       break;
+               case 2:  // 20.0 GeV
+                       fPIDMinPnSigmaAbovePionLineTPC=20.;
+                       break;
+               case 3:  // 1.5 GeV
+                       fPIDMinPnSigmaAbovePionLineTPC=1.5;
+                       break;
+               case 4:  // 1. GeV
+                       fPIDMinPnSigmaAbovePionLineTPC=1.;
+                       break;  
+               case 5:  // 0.5 GeV
+                       fPIDMinPnSigmaAbovePionLineTPC=0.5;
+                       break;
+               case 6:  // 0.4 GeV
+                       fPIDMinPnSigmaAbovePionLineTPC=0.4;
+                       break;    
+               case 7:  // 0.3 GeV
+                       fPIDMinPnSigmaAbovePionLineTPC=0.3;
+                       break;
+               case 8:  // 0.25 GeV
+                       fPIDMinPnSigmaAbovePionLineTPC=0.25;
+                       break;
+               default:
+                       cout<<"Warning: piMomdedxSigmaCut not defined "<<piMomdedxSigmaCut<<endl;
+                       return kFALSE;
+    }
+    return kTRUE;
+}
+
+///________________________________________________________________________
+Bool_t AliDalitzElectronCuts::SetTPCClusterCut(Int_t clsTPCCut)
+{   // Set Cut
+    switch(clsTPCCut){
+    case 0: // 0
+       fMinClsTPC= 0.;
+       break;
+    case 1:  // 70
+       fMinClsTPC= 70.;
+       break;
+    case 2:  // 80
+       fMinClsTPC= 80.;
+       break;
+    case 3:  // 100
+       fMinClsTPC= 100.;
+       break;
+    case 4:  // 0% of findable clusters
+       fMinClsTPCToF= 0.0;
+       fUseCorrectedTPCClsInfo=0;
+       break;
+    case 5:  // 35% of findable clusters
+       fMinClsTPCToF= 0.35;
+       fUseCorrectedTPCClsInfo=0;
+       break;
+    case 6:  // 60% of findable clusters
+       fMinClsTPCToF= 0.6;
+       fUseCorrectedTPCClsInfo=0;
+       break;
+    case 7:  // 70% of findable clusters
+       fMinClsTPCToF= 0.7;
+       fUseCorrectedTPCClsInfo=0;
+       break;
+    default:
+       cout<<"Warning: clsTPCCut not defined "<<clsTPCCut<<endl;
+       return kFALSE;
+    }
+    return kTRUE;
+}
+
+///________________________________________________________________________
+Bool_t AliDalitzElectronCuts::SetEtaCut(Int_t etaCut)
+{ 
+  // Set eta Cut
+       switch(etaCut){
+                case 0: fEtaCut         = 100.;
+                        break;
+               case 1: // 1.4
+                       fEtaCut         = 1.4;
+                       break;
+               case 2: // 1.2
+                       fEtaCut         = 1.2;
+                       break;
+               case 3: // 0.9
+                       fEtaCut         = 0.9;
+                       break;
+               case 4: // 0.8
+                       fEtaCut         = 0.8;
+                       break;
+               case 5: // 0.75
+                       fEtaCut         = 0.75;
+                       break;
+               default:
+                       cout<<"Warning: EtaCut not defined "<<etaCut<<endl;
+                       return kFALSE;
+    }
+    return kTRUE;
+}
+
+///________________________________________________________________________
+Bool_t AliDalitzElectronCuts::SetMaxMomPiondEdxTPCCut(Int_t piMaxMomdedxSigmaCut)
+{   // Set Cut
+   switch(piMaxMomdedxSigmaCut){
+
+                case 0: fPIDMinPnSigmaAbovePionLineTPC=0.;
+                        break;
+               case 1:  // 100. GeV
+                       fPIDMaxPnSigmaAbovePionLineTPC=100.;
+                       break;
+               case 2:  // 5. GeV
+                       fPIDMaxPnSigmaAbovePionLineTPC=5.;
+                       break;
+               case 3:  // 4. GeV
+                       fPIDMaxPnSigmaAbovePionLineTPC=4.;
+                       break;
+               case 4:  // 3.5 GeV
+                       fPIDMaxPnSigmaAbovePionLineTPC=3.5;
+                       break;
+               case 5:  // 3. GeV
+                       fPIDMaxPnSigmaAbovePionLineTPC=3.;
+                       break;
+               default:
+                       cout<<"Warning: piMaxMomdedxSigmaCut not defined "<<piMaxMomdedxSigmaCut<<endl;
+                       return kFALSE;
+    }
+    return kTRUE;
+}
+
+///________________________________________________________________________
+Bool_t AliDalitzElectronCuts::SetLowPRejectionCuts(Int_t LowPRejectionSigmaCut)
+{   // Set Cut
+    switch(LowPRejectionSigmaCut){
+       case 0:  //
+        fDoKaonRejectionLowP=kFALSE;
+        fDoProtonRejectionLowP=kFALSE;
+        fDoPionRejectionLowP=kFALSE;
+       fPIDnSigmaAtLowPAroundKaonLine=0;
+       fPIDnSigmaAtLowPAroundProtonLine=0;
+       fPIDnSigmaAtLowPAroundPionLine=0;
+       break;
+    case 1:  //
+        fDoKaonRejectionLowP=kTRUE;
+        fDoProtonRejectionLowP=kTRUE;
+        fDoPionRejectionLowP=kTRUE;
+       fPIDnSigmaAtLowPAroundKaonLine=0.5;
+       fPIDnSigmaAtLowPAroundProtonLine=0.5;
+       fPIDnSigmaAtLowPAroundPionLine=0.5;
+       break;
+    case 2:  //
+        fDoKaonRejectionLowP=kTRUE;
+        fDoProtonRejectionLowP=kTRUE;
+        fDoPionRejectionLowP=kTRUE;
+       fPIDnSigmaAtLowPAroundKaonLine=1;
+       fPIDnSigmaAtLowPAroundProtonLine=1;
+       fPIDnSigmaAtLowPAroundPionLine=1;
+       break;
+    case 3:  //
+        fDoKaonRejectionLowP=kTRUE;
+        fDoProtonRejectionLowP=kTRUE;
+        fDoPionRejectionLowP=kTRUE;
+       fPIDnSigmaAtLowPAroundKaonLine=1.5;
+       fPIDnSigmaAtLowPAroundProtonLine=1.5;
+       fPIDnSigmaAtLowPAroundPionLine=1.5;
+       break;
+    case 4:  //
+        fDoKaonRejectionLowP=kTRUE;
+        fDoProtonRejectionLowP=kTRUE;
+        fDoPionRejectionLowP=kTRUE;
+       fPIDnSigmaAtLowPAroundKaonLine=0.;
+       fPIDnSigmaAtLowPAroundProtonLine=0.;
+       fPIDnSigmaAtLowPAroundPionLine=1;
+       break;
+    case 5:  //
+        fDoKaonRejectionLowP=kTRUE;
+        fDoProtonRejectionLowP=kTRUE;
+        fDoPionRejectionLowP=kTRUE;
+       fPIDnSigmaAtLowPAroundKaonLine=0.;
+       fPIDnSigmaAtLowPAroundProtonLine=0.;
+       fPIDnSigmaAtLowPAroundPionLine=1.5;
+       break;
+    case 6:  //
+        fDoKaonRejectionLowP=kTRUE;
+        fDoProtonRejectionLowP=kTRUE;
+        fDoPionRejectionLowP=kTRUE;
+       fPIDnSigmaAtLowPAroundKaonLine=0.;
+       fPIDnSigmaAtLowPAroundProtonLine=0.;
+       fPIDnSigmaAtLowPAroundPionLine=2.;
+       break;
+    default:
+        cout<<"Warning: LowPRejectionSigmaCut not defined "<<LowPRejectionSigmaCut<<endl;
+       return kFALSE;
+    }
+    return kTRUE;
+}
+
+///________________________________________________________________________
+Bool_t AliDalitzElectronCuts::SetTOFElectronPIDCut(Int_t TOFelectronPID){
+    // Set Cut
+    switch(TOFelectronPID){ // RRnewTOF start //////////////////////////////////////////////////////////////////////////
+    case 0: // no cut
+       fUseTOFpid = kFALSE;
+       fTofPIDnSigmaBelowElectronLine=-100;
+       fTofPIDnSigmaAboveElectronLine=100;
+       break;
+    case 1: // -7,7
+       fUseTOFpid = kTRUE;
+       fTofPIDnSigmaBelowElectronLine=-7;
+       fTofPIDnSigmaAboveElectronLine=7;
+       break;
+    case 2: // -5,5
+       fUseTOFpid = kTRUE;
+       fTofPIDnSigmaBelowElectronLine=-5;
+       fTofPIDnSigmaAboveElectronLine=5;
+       break;
+    case 3: // -3,5
+       fUseTOFpid = kTRUE;
+       fTofPIDnSigmaBelowElectronLine=-3;
+       fTofPIDnSigmaAboveElectronLine=5;
+       break;
+    case 4: // -2,3
+       fUseTOFpid = kTRUE;
+       fTofPIDnSigmaBelowElectronLine=-2;
+       fTofPIDnSigmaAboveElectronLine=3;
+       break;
+    default:
+        cout<<"Warning: TOFElectronCut not defined "<<TOFelectronPID<<endl;
+       return kFALSE;
+    } //////////////////////// RRnewTOF end //////////////////////////////////////////////////////////////////////////
+    return kTRUE;
+}
+///_______________________________________________________________________________
+
+Bool_t AliDalitzElectronCuts::SetPsiPairCut(Int_t psiCut) {
+  
+
+  switch(psiCut) {
+  case 0:
+        fDoPsiPairCut = kFALSE;
+        fPsiPairCut = 10000; //
+        fDeltaPhiCutMin = -1000.;
+        fDeltaPhiCutMax =  1000.;
+        
+        break;
+  case 1:
+        fDoPsiPairCut = kTRUE;
+        fPsiPairCut = 0.45; // Standard
+        fDeltaPhiCutMin = 0.;
+        fDeltaPhiCutMax = 0.12;
+        break;
+  default:
+      cout<<"Warning: PsiPairCut not defined "<<fPsiPairCut<<endl;
+      return kFALSE;
+  }
+
+  return kTRUE;
+}
+
+///_______________________________________________________________________________
+Bool_t AliDalitzElectronCuts::SetRejectSharedElecGamma(Int_t RCut) {
+  
+
+  switch(RCut) {
+  case 0:
+        fDoRejectSharedElecGamma = kFALSE;
+        fRadiusCut = 10000; // 
+        break;
+  case 1:
+        fDoRejectSharedElecGamma = kTRUE;
+        fRadiusCut = 2.0; // cm 
+        break;
+  case 2:
+        fDoRejectSharedElecGamma = kTRUE;
+        fRadiusCut = 3.0; // Standard
+        break;
+  case 3:
+        fDoRejectSharedElecGamma = kTRUE;
+        fRadiusCut = 4.0; // 
+        break;
+  case 4:
+        fDoRejectSharedElecGamma = kTRUE;
+        fRadiusCut = 5.0; // 
+        break;
+  case 5:
+        fDoRejectSharedElecGamma = kTRUE;
+        fRadiusCut = 10.0; // 
+        break;
+  case 6:
+        fDoRejectSharedElecGamma = kTRUE;
+        fRadiusCut = 15.0; // 
+        break;
+  default:
+      cout<<"Warning: PsiPairCut not defined "<<fDoRejectSharedElecGamma<<endl;
+      return kFALSE;
+  }
+
+  return kTRUE;
+}
+///__________________________________________________________________________
+Bool_t AliDalitzElectronCuts::SetBackgroundScheme(Int_t BackgroundScheme){
+
+    // Set Cut
+    switch(BackgroundScheme){
+
+    case 0: //Rotation
+            fBKGMethod = 0;
+            fUseTrackMultiplicityForBG = kFALSE;
+        break;
+    case 1: // mixed event with V0 multiplicity
+            fBKGMethod  = 1;
+            fUseTrackMultiplicityForBG = kFALSE;
+        break;
+    case 2: // mixed event with track multiplicity
+            fUseTrackMultiplicityForBG = kTRUE;
+            fBKGMethod  = 1;
+        break;
+    case 3: //Rotation
+           fUseTrackMultiplicityForBG = kFALSE;
+            fBKGMethod  = 2;
+        break;
+    case 4: //Rotation
+            fUseTrackMultiplicityForBG = kTRUE;
+            fBKGMethod  = 2;
+        break;
+
+    default:
+        cout<<"Warning: BackgroundScheme not defined "<<BackgroundScheme<<endl;
+        return kFALSE;
+    }
+    return kTRUE;
+}
+///________________________________________________________________________
+TString AliDalitzElectronCuts::GetCutNumber(){
+    // returns TString with current cut number
+  TString a(kNCuts);
+  for(Int_t ii=0;ii<kNCuts;ii++){
+       a.Append(Form("%d",fCuts[ii]));
+  }
+  return a;
+}
+
+
+///________________________________________________________________________
+AliDalitzElectronCuts* AliDalitzElectronCuts::GetStandardCuts2010PbPb(){
+    //Create and return standard 2010 PbPb cuts
+    AliDalitzElectronCuts *cuts=new AliDalitzElectronCuts("StandardCuts2010PbPb","StandardCuts2010PbPb");
+    if(!cuts->InitializeCutsFromCutString("9069640364102")){
+       cout<<"Warning: Initialization of Standardcuts2010PbPb failed"<<endl;}
+    return cuts;
+}
+
+///________________________________________________________________________
+AliDalitzElectronCuts* AliDalitzElectronCuts::GetStandardCuts2010pp(){
+    //Create and return standard 2010 PbPb cuts
+    AliDalitzElectronCuts *cuts=new AliDalitzElectronCuts("StandardCuts2010pp","StandardCuts2010pp");
+                                          
+    if(!cuts->InitializeCutsFromCutString("9069640364102")){
+       cout<<"Warning: Initialization of Standardcuts2010pp failed"<<endl;}
+     return cuts;
+}
+
diff --git a/PWGGA/GammaConv/AliDalitzElectronCuts.h b/PWGGA/GammaConv/AliDalitzElectronCuts.h
new file mode 100644 (file)
index 0000000..d4d0e5d
--- /dev/null
@@ -0,0 +1,240 @@
+#ifndef ALIDALITZELECTRONCUTS_H
+#define ALIDALITZELECTRONCUTS_H
+
+// Class handling all kinds of selection cuts for electrons
+
+// Authors: Svein Lindal, Daniel Lohner                                                                                                *
+
+
+#include "AliAODpidUtil.h"
+//#include "AliConversionPhotonBase.h"
+//#include "AliAODConversionMother.h"
+#include "AliAODTrack.h"
+#include "AliESDtrack.h"
+#include "AliVTrack.h"
+#include "AliAODTrack.h"
+#include "AliStack.h"
+#include "AliAnalysisCuts.h"
+#include "AliESDtrackCuts.h"
+#include "TH1F.h"
+
+class AliESDEvent;
+class AliAODEvent;
+class AliConversionPhotonBase;
+class AliKFVertex;
+class AliKFParticle;
+class TH1F;
+class TH2F;
+class AliPIDResponse;
+class AliAnalysisCuts;
+class iostream;
+class TList;
+class AliAnalysisManager;
+
+
+using namespace std;
+
+class AliDalitzElectronCuts : public AliAnalysisCuts {
+       
+ public: 
+
+
+  enum cutIds {
+       kgoodId=0, 
+        kededxSigmaITSCut,
+        kededxSigmaTPCCut,
+        kpidedxSigmaTPCCut,
+        kpiMinMomdedxSigmaTPCCut,
+        kpiMaxMomdedxSigmaTPCCut,
+        kLowPRejectionSigmaCut,
+        kTOFelectronPID,
+        kclsTPCCut,
+       ketaCut,
+        kPsiPair,
+        kRejectSharedElecGamma,
+        kBackgroundScheme,
+       kNCuts
+  };
+
+
+ enum electronCuts {
+      kElectronIn=0,
+      kNoTracks,
+      kTrackCuts,
+      kdEdxCuts,
+      kElectronOut
+ };
+
+
+  Bool_t SetCutIds(TString cutString); 
+  Int_t fCuts[kNCuts];
+  Bool_t SetCut(cutIds cutID, Int_t cut);
+  Bool_t UpdateCutString(cutIds cutID, Int_t value);
+  static const char * fgkCutNames[kNCuts];
+
+
+  Bool_t InitializeCutsFromCutString(const TString analysisCutSelection); 
+  
+
+  AliDalitzElectronCuts(const char *name="ElectronCuts", const char * title="Electron Cuts");
+  virtual ~AliDalitzElectronCuts();                            //virtual destructor
+
+  virtual Bool_t IsSelected(TObject* /*obj*/){return kTRUE;}
+  virtual Bool_t IsSelected(TList* /*list*/) {return kTRUE;}
+
+  TString GetCutNumber();
+
+    // Cut Selection
+  Bool_t TrackIsSelected(AliESDtrack* lTrack);
+  Bool_t ElectronIsSelected(AliESDtrack* lTrack);
+  void InitAODpidUtil(Int_t type);
+  static AliDalitzElectronCuts * GetStandardCuts2010PbPb();
+  static AliDalitzElectronCuts * GetStandardCuts2010pp();
+  Bool_t InitPIDResponse();
+  
+  void SetPIDResponse(AliPIDResponse * pidResponse) {fPIDResponse = pidResponse;}
+  AliPIDResponse * GetPIDResponse() { return fPIDResponse;}
+  
+  void PrintCuts();
+
+  void InitCutHistograms(TString name="",Bool_t preCut = kTRUE);
+  void SetFillCutHistograms(TString name="",Bool_t preCut = kTRUE){if(!fHistograms){InitCutHistograms(name,preCut);};}
+  TList *GetCutHistograms(){return fHistograms;}
+
+  static AliVTrack * GetTrack(AliVEvent * event, Int_t label);
+
+  
+
+  ///Cut functions
+  Bool_t dEdxCuts(AliVTrack * track);
+  Bool_t PIDProbabilityCut(AliConversionPhotonBase *photon, AliVEvent * event);
+  Bool_t RejectSharedElecGamma(TList *photons, Int_t indexEle);
+  Bool_t IsFromGammaConversion( Double_t psiPair, Double_t deltaPhi ) const;
+
+  // Event Cuts
+
+  Double_t GetPsiPair( const AliESDtrack* trackPos, const AliESDtrack* trackNeg ) const;
+
+  Bool_t SetTPCdEdxCutPionLine(Int_t pidedxSigmaCut);
+  Bool_t SetTPCdEdxCutElectronLine(Int_t ededxSigmaCut);
+  Bool_t SetITSdEdxCutElectronLine(Int_t ededxSigmaCut);
+  Bool_t SetMinMomPiondEdxTPCCut(Int_t piMomdedxSigmaCut);
+  Bool_t SetMaxMomPiondEdxTPCCut(Int_t piMomdedxSigmaCut);
+  Bool_t SetTPCClusterCut(Int_t clsTPCCut);
+  Bool_t SetEtaCut(Int_t etaCut);
+  Bool_t SetMinMomPiondEdxCut(Int_t piMinMomdedxSigmaCut);
+  Bool_t SetMaxMomPiondEdxCut(Int_t piMaxMomdedxSigmaCut);
+  Bool_t SetLowPRejectionCuts(Int_t LowPRejectionSigmaCut);
+  Bool_t SetTOFElectronPIDCut(Int_t TOFelectronPID);
+  Bool_t SetPsiPairCut(Int_t psiCut);
+  Bool_t SetRejectSharedElecGamma(Int_t RCut);
+  Bool_t SetBackgroundScheme(Int_t BackgroundScheme);
+  
+  // Request Flags
+
+  Double_t GetEtaCut(){ return  fEtaCut;}
+  Double_t GetPsiPairCut(){ return fPsiPairCut; }
+  Double_t DoRejectSharedElecGamma(){ return fDoRejectSharedElecGamma;}
+  Double_t DoPsiPairCut(){return fDoPsiPairCut;}
+  Bool_t   UseTrackMultiplicity(){ return fUseTrackMultiplicityForBG;}
+  Int_t    GetBKGMethod(){ return fBKGMethod; }
+  
+
+  
+  protected:
+
+  TList *fHistograms;
+  AliPIDResponse *fPIDResponse;
+  AliESDtrackCuts *fesdTrackCuts;
+
+  Double_t fEtaCut; //eta cutç
+  Double_t fRadiusCut; // radius cut
+  Double_t fPsiPairCut;
+  Double_t fDeltaPhiCutMin;
+  Double_t fDeltaPhiCutMax;
+  Double_t fMinClsTPC; // minimum clusters in the TPC
+  Double_t fMinClsTPCToF; // minimum clusters to findable clusters
+  Bool_t   fDodEdxSigmaITSCut; // flag to use the dEdxCut ITS based on sigmas
+  Bool_t   fDodEdxSigmaTPCCut; // flag to use the dEdxCut TPC based on sigmas
+  Bool_t   fDoTOFsigmaCut; // flag to use TOF pid cut RRnewTOF
+  Bool_t   fDoRejectSharedElecGamma; //Reject electrons from the gammas with Radius < RadiusCut
+  Bool_t   fDoPsiPairCut; // PsiPair Cut
+  Double_t fPIDnSigmaAboveElectronLineITS; // sigma cut
+  Double_t fPIDnSigmaBelowElectronLineITS; // sigma cut
+  Double_t fPIDnSigmaAboveElectronLineTPC; // sigma cut
+  Double_t fPIDnSigmaBelowElectronLineTPC; // sigma cut
+  Double_t fPIDnSigmaAbovePionLineTPC;
+  Double_t fPIDnSigmaAbovePionLineTPCHighPt;
+  Double_t fTofPIDnSigmaAboveElectronLine; // sigma cut RRnewTOF
+  Double_t fTofPIDnSigmaBelowElectronLine; // sigma cut RRnewTOF 
+  Double_t fPIDMinPnSigmaAbovePionLineTPC; // sigma cut
+  Double_t fPIDMaxPnSigmaAbovePionLineTPC; // sigma cut
+  Double_t fDoKaonRejectionLowP;   // Kaon rejection at low p
+  Double_t fDoProtonRejectionLowP; // Proton rejection at low p
+  Double_t fDoPionRejectionLowP;   // Pion rejection at low p
+  Double_t fPIDnSigmaAtLowPAroundKaonLine; // sigma cut
+  Double_t fPIDnSigmaAtLowPAroundProtonLine; // sigma cut
+  Double_t fPIDnSigmaAtLowPAroundPionLine; // sigma cut
+  Double_t fPIDMinPKaonRejectionLowP; // Momentum limit to apply kaon rejection
+  Double_t fPIDMinPProtonRejectionLowP; // Momentum limit to apply proton rejection
+  Double_t fPIDMinPPionRejectionLowP; // Momentum limit to apply proton rejection
+
+  Bool_t   fUseCorrectedTPCClsInfo; // flag to use corrected tpc cl info
+  Bool_t   fUseTOFpid; // flag to use tof pid
+  Bool_t   fUseTrackMultiplicityForBG; // use multiplicity
+  Int_t    fBKGMethod;
+
+
+  // Histograms
+  TObjString *fCutString; // cut number used for analysis
+  TH1F *hCutIndex; // bookkeeping for cuts
+  TH1F *hdEdxCuts;  // bookkeeping for dEdx cuts
+  TH2F *hITSdEdxbefore; // ITS dEdx before cuts
+  TH2F *hITSdEdxafter;
+  TH2F *hTPCdEdxbefore; // TPC dEdx before cuts
+  TH2F *hTPCdEdxafter; // TPC dEdx after cuts
+  TH2F *hTOFbefore; // TOF after cuts
+  TH2F *hTOFafter; // TOF after cuts
+  
+
+private:
+
+  AliDalitzElectronCuts(const AliDalitzElectronCuts&); // not implemented
+  AliDalitzElectronCuts& operator=(const AliDalitzElectronCuts&); // not implemented
+
+
+  ClassDef(AliDalitzElectronCuts,1)
+};
+
+
+inline void AliDalitzElectronCuts::InitAODpidUtil(Int_t type) {
+  if (!fPIDResponse) fPIDResponse = new AliAODpidUtil();
+  Double_t alephParameters[5];
+  // simulation
+  alephParameters[0] = 2.15898e+00/50.;
+  alephParameters[1] = 1.75295e+01;
+  alephParameters[2] = 3.40030e-09;
+  alephParameters[3] = 1.96178e+00;
+  alephParameters[4] = 3.91720e+00;
+  fPIDResponse->GetTOFResponse().SetTimeResolution(80.);
+  
+  // data
+  if (type==1){
+    alephParameters[0] = 0.0283086/0.97;
+    alephParameters[1] = 2.63394e+01;
+    alephParameters[2] = 5.04114e-11;
+    alephParameters[3] = 2.12543e+00;
+    alephParameters[4] = 4.88663e+00;
+    fPIDResponse->GetTOFResponse().SetTimeResolution(130.);
+    fPIDResponse->GetTPCResponse().SetMip(50.);
+  }
+  
+  fPIDResponse->GetTPCResponse().SetBetheBlochParameters(
+    alephParameters[0],alephParameters[1],alephParameters[2],
+    alephParameters[3],alephParameters[4]);
+  
+  fPIDResponse->GetTPCResponse().SetSigma(3.79301e-03, 2.21280e+04);
+}
+
+
+#endif
diff --git a/PWGGA/GammaConv/AliDalitzElectronSelector.cxx b/PWGGA/GammaConv/AliDalitzElectronSelector.cxx
new file mode 100644 (file)
index 0000000..093e2e2
--- /dev/null
@@ -0,0 +1,146 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                                                                                                                                                                                                                                             *
+ * Authors: Svein Lindal, Daniel Lohner                                                                                                *
+ * Version 1.0                                                                                                                                                                                                                                         *
+ *                                                                                                                                                                                                                                                                                             *
+ * Permission to use, copy, modify and distribute this software and its         *
+ * documentation strictly for non-commercial purposes is hereby granted         *
+ * without fee, provided that the above copyright notice appears in all         *
+ * copies and that both the copyright notice and this permission notice         *
+ * appear in the supporting documentation. The authors make no claims           *
+ * about the suitability of this software for any purpose. It is                                       *
+ * provided "as is" without express or implied warranty.                                                                       *
+ **************************************************************************/
+
+////////////////////////////////////////////////
+//--------------------------------------------- 
+// Class reconstructing primary electrons
+//---------------------------------------------
+////////////////////////////////////////////////
+
+
+#include "AliDalitzElectronSelector.h"
+#include "AliDalitzElectronCuts.h"
+#include "AliAODv0.h"
+#include "AliESDv0.h"
+#include "AliAODEvent.h"
+#include "AliESDEvent.h"
+#include "TVector.h"
+#include "AliESDtrack.h"
+#include "AliAnalysisManager.h"
+#include "AliInputEventHandler.h"
+#include "TChain.h"
+#include "AliStack.h"
+
+class iostream;
+
+using namespace std;
+
+
+
+ClassImp(AliDalitzElectronSelector)
+
+//________________________________________________________________________
+AliDalitzElectronSelector::AliDalitzElectronSelector(const char *name) : AliAnalysisTaskSE(name),
+    fElectronCuts(0),
+    fPositronsIndex(),
+    fElectronsIndex(),
+    fEventIsSelected(kFALSE)
+{
+    // Default constructor
+    DefineInput(0, TChain::Class());
+}
+
+//________________________________________________________________________
+AliDalitzElectronSelector::~AliDalitzElectronSelector()
+{
+    // default deconstructor
+
+   
+}
+//________________________________________________________________________
+void AliDalitzElectronSelector::Init()
+{
+    // Initialize function to be called once before analysis
+
+    if(fElectronCuts == 0){
+    //  fElectronCuts=AliConversionCuts::GetStandardCuts2010PbPb();
+        AliError("No Cut Selection initialized");
+    }
+
+}
+
+//________________________________________________________________________
+void AliDalitzElectronSelector::UserCreateOutputObjects()
+{
+    // Create User Output Objects
+}
+
+//________________________________________________________________________
+void AliDalitzElectronSelector::UserExec(Option_t *){
+    // User Exec
+       fEventIsSelected=ProcessEvent(fInputEvent,fMCEvent);
+}
+
+//________________________________________________________________________
+Bool_t AliDalitzElectronSelector::ProcessEvent(AliVEvent *inputEvent,AliMCEvent *mcEvent)
+{
+       //Reset the index
+
+       fPositronsIndex.clear();
+       fElectronsIndex.clear();
+
+
+       fInputEvent=inputEvent;
+       fMCEvent=mcEvent;
+
+       if(!fInputEvent){
+               AliError("No Input event");
+               return kFALSE;
+       }
+
+       if(!fElectronCuts){AliError("No ConversionCuts");return kFALSE;}
+
+
+       if(fInputEvent->IsA()==AliESDEvent::Class()){
+               ProcessESDs();
+       }
+
+       //if(fInputEvent->IsA()==AliAODEvent::Class()){
+       //GetAODConversionGammas();
+       //}
+
+
+       return kTRUE;
+}
+
+///________________________________________________________________________
+Bool_t AliDalitzElectronSelector::ProcessESDs(){
+       // Process ESD V0s for conversion photon reconstruction
+       AliESDEvent *fESDEvent=dynamic_cast<AliESDEvent*>(fInputEvent);
+       if(fESDEvent){
+               for(Int_t currentTrackIndex=0;currentTrackIndex<fESDEvent->GetNumberOfTracks();currentTrackIndex++){
+                       AliESDtrack *fCurrentTrack = (AliESDtrack*)(fESDEvent->GetTrack(currentTrackIndex));
+                       if(!fCurrentTrack){
+                               printf("Requested Track does not exist");
+                               continue;
+                       }
+                       if (  fElectronCuts->ElectronIsSelected( fCurrentTrack ) ) {
+                               if( fCurrentTrack->GetSign() > 0.0 ){
+                                       fPositronsIndex.push_back(currentTrackIndex);
+                               } else {
+                                       fElectronsIndex.push_back(currentTrackIndex);
+                               }
+                       }
+               }
+       }
+       return kTRUE;
+}
+
+
+//________________________________________________________________________
+void AliDalitzElectronSelector::Terminate(Option_t *)
+{
+
+}
diff --git a/PWGGA/GammaConv/AliDalitzElectronSelector.h b/PWGGA/GammaConv/AliDalitzElectronSelector.h
new file mode 100644 (file)
index 0000000..404cd9e
--- /dev/null
@@ -0,0 +1,68 @@
+#ifndef ALIDALITZELECTRONSELECTOR_H
+#define ALIDALITZELECTRONSELECTOR_H
+
+#include "AliAnalysisTaskSE.h"
+#include "AliAODv0.h"
+#include "AliESDv0.h"
+#include "AliDalitzElectronCuts.h"
+#include "AliExternalTrackParam.h"
+
+class TRandom3;
+class AliStack;
+class TList;
+class TString;
+class TH1F;
+class TH2F;
+
+using namespace std;
+
+class AliDalitzElectronSelector : public AliAnalysisTaskSE {
+       
+ public: 
+       
+  AliDalitzElectronSelector(const char *name="ElectronSelector");
+  virtual ~AliDalitzElectronSelector();                            //virtual destructor
+  void UserCreateOutputObjects();
+
+  virtual void UserExec(Option_t *option);
+  virtual void Terminate(Option_t *);
+  virtual void Init();
+
+  Bool_t ProcessEvent(AliVEvent *inputEvent,AliMCEvent *mcEvent=NULL);
+  Bool_t IsEventSelected(){return fEventIsSelected;}
+
+  // Return selected electron/positron array 
+  vector <Int_t> GetReconstructedElectronsIndex(){ return fElectronsIndex; }
+  vector <Int_t> GetReconstructedPositronsIndex(){ return fPositronsIndex; }
+  AliDalitzElectronCuts *GetDalitzElectronCuts(){   return fElectronCuts; }
+  TList *GetCutHistograms(){ if(fElectronCuts){return fElectronCuts->GetCutHistograms();} return NULL;}
+  // Set Options
+
+  void SetDalitzElectronCuts(const TString cut);
+  void SetDalitzElectronCuts(AliDalitzElectronCuts *cuts){fElectronCuts=cuts;}
+  
+protected:
+       //selected electron arrays
+
+    Bool_t ProcessESDs();
+    AliDalitzElectronCuts *fElectronCuts; // Pointer to the ConversionCut Selection
+    vector<Int_t> fPositronsIndex;
+    vector<Int_t> fElectronsIndex;
+    Bool_t fEventIsSelected;
+
+    ClassDef(AliDalitzElectronSelector,1)
+};
+
+inline void AliDalitzElectronSelector::SetDalitzElectronCuts(const TString cut){
+   if(fElectronCuts != NULL){
+               delete fElectronCuts;
+               fElectronCuts=NULL;
+       }
+       if(fElectronCuts == NULL){
+               fElectronCuts=new AliDalitzElectronCuts("ElectronCuts","ElectronCuts");
+               fElectronCuts->InitializeCutsFromCutString(cut.Data());
+       }
+}
+
+
+#endif
diff --git a/PWGGA/GammaConv/AliGammaConversionAODBGHandler.cxx b/PWGGA/GammaConv/AliGammaConversionAODBGHandler.cxx
new file mode 100644 (file)
index 0000000..5c50ca7
--- /dev/null
@@ -0,0 +1,356 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: Ana Marin, Kathrin Koch, Kenneth Aamodt                        *
+ * Version 1.0                                                            *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+////////////////////////////////////////////////
+//--------------------------------------------- 
+// Class for handling of background calculation
+//---------------------------------------------
+////////////////////////////////////////////////
+
+#include "AliGammaConversionAODBGHandler.h"
+#include "AliKFParticle.h"
+#include "AliAODConversionPhoton.h"
+#include "AliAODConversionMother.h"
+#include "AliAnalysisTaskGammaConversion.h"
+
+using namespace std;
+
+ClassImp(AliGammaConversionAODBGHandler)
+
+AliGammaConversionAODBGHandler::AliGammaConversionAODBGHandler() :
+  TObject(),
+  fNEvents(10),
+  fBGEventCounter(NULL),
+  fBGEventENegCounter(NULL),
+  fBGProbability(NULL),
+  fBGEventVertex(NULL),
+  fNBinsZ(0),
+  fNBinsMultiplicity(0),
+  fBinLimitsArrayZ(NULL),
+  fBinLimitsArrayMultiplicity(NULL),
+  fBGEvents(),
+  fBGEventsENeg()
+{
+  // constructor
+}
+
+AliGammaConversionAODBGHandler::AliGammaConversionAODBGHandler(UInt_t binsZ,UInt_t binsMultiplicity,UInt_t nEvents) :
+  TObject(),
+  fNEvents(nEvents),
+  fBGEventCounter(NULL),
+  fBGEventENegCounter(NULL),
+  fBGProbability(NULL),
+  fBGEventVertex(NULL),
+  fNBinsZ(binsZ),
+  fNBinsMultiplicity(binsMultiplicity),
+  fBinLimitsArrayZ(NULL),
+  fBinLimitsArrayMultiplicity(NULL),
+  fBGEvents(binsZ,AliGammaConversionMultipicityVector(binsMultiplicity,AliGammaConversionBGEventVector(nEvents))),
+  fBGEventsENeg(binsZ,AliGammaConversionMultipicityVector(binsMultiplicity,AliGammaConversionBGEventVector(nEvents)))
+{
+  // constructor
+}
+
+AliGammaConversionAODBGHandler::AliGammaConversionAODBGHandler(const AliGammaConversionAODBGHandler & original) :
+  TObject(original),
+  fNEvents(original.fNEvents),
+  fBGEventCounter(original.fBGEventCounter),
+  fBGEventENegCounter(original.fBGEventENegCounter),
+  fBGProbability(original.fBGProbability),
+  fBGEventVertex(original.fBGEventVertex),
+  fNBinsZ(original.fNBinsZ),
+  fNBinsMultiplicity(original.fNBinsMultiplicity),
+  fBinLimitsArrayZ(original.fBinLimitsArrayZ),
+  fBinLimitsArrayMultiplicity(original.fBinLimitsArrayMultiplicity),
+  fBGEvents(original.fBGEvents),
+  fBGEventsENeg(original.fBGEventsENeg)
+{
+  //copy constructor   
+}
+
+AliGammaConversionAODBGHandler & AliGammaConversionAODBGHandler::operator = (const AliGammaConversionAODBGHandler & /*source*/)
+{
+  // assignment operator
+  return *this;
+}
+
+AliGammaConversionAODBGHandler::~AliGammaConversionAODBGHandler(){
+
+  //Kenneth remember to clear memory!!!!!!!!!!!!!!!!!!!!!
+  if(fBGEventCounter){
+    for(Int_t z=0;z<fNBinsZ;z++){
+      delete[] fBGEventCounter[z];
+    }
+    delete[] fBGEventCounter;
+    fBGEventCounter = NULL;
+  }
+
+  if(fBGEventVertex){
+    for(Int_t z=0;z<fNBinsZ;z++){
+      for(Int_t m=0;m<fNBinsMultiplicity;m++){
+       delete [] fBGEventVertex[z][m];
+      }
+      delete [] fBGEventVertex[z];
+    }
+    delete [] fBGEventVertex;
+  }
+
+   if(fBGEventENegCounter){
+    for(Int_t z=0;z<fNBinsZ;z++){
+      delete[] fBGEventENegCounter[z];
+    }
+    delete[] fBGEventENegCounter;
+    fBGEventENegCounter = NULL;
+  }
+
+  if(fBinLimitsArrayZ){
+    delete[] fBinLimitsArrayZ;
+  }
+
+  if(fBinLimitsArrayMultiplicity){
+    delete[] fBinLimitsArrayMultiplicity;
+  }
+}
+
+void AliGammaConversionAODBGHandler::Initialize(Double_t * const zBinLimitsArray, Double_t * const multiplicityBinLimitsArray){
+  // see header file for documantation  
+
+  if(zBinLimitsArray){
+    fBinLimitsArrayZ = zBinLimitsArray;
+  }
+  else{
+    //Print warning
+  }
+  
+  if(multiplicityBinLimitsArray){
+    fBinLimitsArrayMultiplicity = multiplicityBinLimitsArray ;
+  }
+  else{
+    //Print warning
+  }
+  if(fBGEventCounter == NULL){
+    fBGEventCounter= new Int_t*[fNBinsZ];
+  }
+  for(Int_t z=0;z<fNBinsZ;z++){
+    fBGEventCounter[z]=new Int_t[fNBinsMultiplicity];
+  }
+
+  for(Int_t z=0;z<fNBinsZ;z++){
+    for(Int_t m=0;m<fNBinsMultiplicity;m++){
+      fBGEventCounter[z][m]=0;
+    }
+  }
+
+  if(fBGEventVertex == NULL){
+    fBGEventVertex = new GammaConversionVertex**[fNBinsZ];
+  }
+  for(Int_t z=0; z < fNBinsZ; z++){
+    fBGEventVertex[z]= new GammaConversionVertex*[fNBinsMultiplicity];
+  }
+  for(Int_t z=0;z<fNBinsZ;z++){
+    for(Int_t m=0;m<fNBinsMultiplicity; m++){
+      fBGEventVertex[z][m]= new GammaConversionVertex[fNEvents];
+    }
+  }
+  if( fBGEventENegCounter == NULL){
+    fBGEventENegCounter = new Int_t*[fNBinsZ];
+  }
+
+  for(Int_t z=0; z < fNBinsZ; z++){
+    fBGEventENegCounter[z] = new Int_t[fNBinsMultiplicity];
+  }
+
+  for(Int_t z=0;z<fNBinsZ;z++){
+    for(Int_t m=0;m<fNBinsMultiplicity; m++){
+      fBGEventENegCounter[z][m] = 0;
+    }
+  }
+
+  if(fBGProbability == NULL){
+    fBGProbability = new Double_t*[fNBinsZ];
+  }
+  for(Int_t z=0; z < fNBinsZ; z++){
+    fBGProbability[z] = new Double_t[fNBinsMultiplicity];
+  }
+
+  for(Int_t z=0;z<fNBinsZ;z++){
+    for(Int_t m=0;m<fNBinsMultiplicity; m++){
+      fBGProbability[z][m] = 0;
+    }
+  }
+  //filling the probability
+  fBGProbability[0][0] = 0.243594;
+  fBGProbability[0][1] = 0.279477;
+  fBGProbability[0][2] = 0.305104;
+  fBGProbability[0][3] = 0.315927;
+  fBGProbability[1][0] = 0.241964;
+  fBGProbability[1][1] = 0.272995;
+  fBGProbability[1][2] = 0.307165;
+  fBGProbability[1][3] = 0.292248;
+  fBGProbability[2][0] = 0.241059;
+  fBGProbability[2][1] = 0.27509;
+  fBGProbability[2][2] = 0.283657;
+  fBGProbability[2][3] = 0.310512;
+  fBGProbability[3][0] = 0.23888;
+  fBGProbability[3][1] = 0.283418;
+  fBGProbability[3][2] = 0.297232;
+  fBGProbability[3][3] = 0.348188;
+  fBGProbability[4][0] = 0.245555;
+  fBGProbability[4][1] = 0.281218;
+  fBGProbability[4][2] = 0.317236;
+  fBGProbability[4][3] = 0.323495;
+  fBGProbability[5][0] = 0.244572;
+  fBGProbability[5][1] = 0.259498;
+  fBGProbability[5][2] = 0.278383;
+  fBGProbability[5][3] = 0.284696;
+  fBGProbability[6][0] = 0.24703;
+  fBGProbability[6][1] = 0.275265;
+  fBGProbability[6][2] = 0.284004;
+  fBGProbability[6][3] = 0.343584;
+}
+
+Int_t AliGammaConversionAODBGHandler::GetZBinIndex(Double_t zvalue) const{
+  // see header file for documantation
+  if(fNBinsZ<2 || zvalue<=fBinLimitsArrayZ[0]){
+     return 0;
+  }
+
+  for(Int_t i=0; i<fNBinsZ-1 ;i++){
+    if(zvalue >= fBinLimitsArrayZ[i] && zvalue <= fBinLimitsArrayZ[i+1]){
+      return i;
+    }
+  }
+  return fNBinsZ-1;
+}
+
+Int_t AliGammaConversionAODBGHandler::GetMultiplicityBinIndex(Int_t multiplicity) const{
+  // see header file for documantation  
+  if(fNBinsMultiplicity<2){
+    return 0;
+  }
+
+  for(Int_t i=0; i<fNBinsMultiplicity-1 ;i++){
+    if(multiplicity >= fBinLimitsArrayMultiplicity[i] && multiplicity < fBinLimitsArrayMultiplicity[i+1]){
+      return i;
+    }
+  }
+  return fNBinsMultiplicity-1;
+}
+
+void AliGammaConversionAODBGHandler::AddEvent(TList* const eventGammas,Double_t xvalue, Double_t yvalue, Double_t zvalue, Int_t multiplicity){
+  // see header file for documantation  
+
+  //  cout<<"Entering the AddEvent function"<<endl;
+
+  Int_t z = GetZBinIndex(zvalue);
+  Int_t m = GetMultiplicityBinIndex(multiplicity);
+
+  if(fBGEventCounter[z][m] >= fNEvents){
+    fBGEventCounter[z][m]=0;
+  }
+  Int_t eventCounter=fBGEventCounter[z][m];
+  
+  /*
+  if(fBGEventVertex[z][m][eventCounter]){
+    delete fBGEventVertex[z][m][eventCounter];
+  }
+  */
+  fBGEventVertex[z][m][eventCounter].fX = xvalue;
+  fBGEventVertex[z][m][eventCounter].fY = yvalue;
+  fBGEventVertex[z][m][eventCounter].fZ = zvalue;
+
+  //first clear the vector
+  // cout<<"Size of vector: "<<fBGEvents[z][m][eventCounter].size()<<endl;
+  //  cout<<"Checking the entries: Z="<<z<<", M="<<m<<", eventCounter="<<eventCounter<<endl;
+
+  //  cout<<"The size of this vector is: "<<fBGEvents[z][m][eventCounter].size()<<endl;
+  for(UInt_t d=0;d<fBGEvents[z][m][eventCounter].size();d++){
+    delete (AliAODConversionPhoton*)(fBGEvents[z][m][eventCounter][d]);
+  }
+  fBGEvents[z][m][eventCounter].clear();
+  
+  // add the gammas to the vector
+  for(Int_t i=0; i< eventGammas->GetEntries();i++){
+    //    AliKFParticle *t = new AliKFParticle(*(AliKFParticle*)(eventGammas->At(i)));
+    fBGEvents[z][m][eventCounter].push_back(new AliAODConversionPhoton(*(AliAODConversionPhoton*)(eventGammas->At(i))));
+  }
+  fBGEventCounter[z][m]++;
+}
+void AliGammaConversionAODBGHandler::AddElectronEvent(TClonesArray* const eventENeg, Double_t zvalue, Int_t multiplicity){
+
+  Int_t z = GetZBinIndex(zvalue);
+  Int_t m = GetMultiplicityBinIndex(multiplicity);
+
+  if(fBGEventENegCounter[z][m] >= fNEvents){
+     fBGEventENegCounter[z][m]=0;
+  }
+
+   Int_t eventENegCounter=fBGEventENegCounter[z][m];
+  
+  //first clear the vector
+  // cout<<"Size of vector: "<<fBGEvents[z][m][eventCounter].size()<<endl;
+  //  cout<<"Checking the entries: Z="<<z<<", M="<<m<<", eventCounter="<<eventCounter<<endl;
+
+  //  cout<<"The size of this vector is: "<<fBGEvents[z][m][eventCounter].size()<<endl;
+  for(UInt_t d=0;d<fBGEventsENeg[z][m][eventENegCounter].size();d++){
+    delete (AliAODConversionPhoton*)(fBGEventsENeg[z][m][eventENegCounter][d]);
+  }
+
+  fBGEventsENeg[z][m][eventENegCounter].clear();
+
+  // add the electron to the vector
+  for(Int_t i=0; i< eventENeg->GetEntriesFast();i++){
+    //    AliKFParticle *t = new AliKFParticle(*(AliKFParticle*)(eventGammas->At(i)));
+    fBGEventsENeg[z][m][eventENegCounter].push_back(new AliAODConversionPhoton(*(AliAODConversionPhoton*)(eventENeg->At(i))));
+  }
+
+  fBGEventENegCounter[z][m]++;
+
+
+}
+AliGammaConversionAODVector* AliGammaConversionAODBGHandler::GetBGGoodV0s(Int_t zbin, Int_t mbin, Int_t event){
+  //see headerfile for documentation
+  return &(fBGEvents[zbin][mbin][event]);
+}
+AliGammaConversionAODVector* AliGammaConversionAODBGHandler::GetBGGoodENeg(Int_t event, Double_t zvalue, Int_t multiplicity){
+
+
+  //see headerfile for documentation
+  Int_t z = GetZBinIndex(zvalue);
+  Int_t m = GetMultiplicityBinIndex(multiplicity);
+  return &(fBGEventsENeg[z][m][event]);
+
+
+}
+void AliGammaConversionAODBGHandler::PrintBGArray(){
+  //see headerfile for documentation
+  for(Int_t z=0;z<fNBinsZ;z++){
+    if(z==2){
+      cout<<"Getting the data for z bin: "<<z<<endl;
+      for(Int_t multiplicity=0;multiplicity<fNBinsMultiplicity;multiplicity++){
+       if(multiplicity==2){
+         cout<<"Getting the data for multiplicity bin: "<<multiplicity<<endl;  
+         for(Int_t event=0;event<fNEvents;event++){
+           if(fBGEvents[z][multiplicity][event].size()>0){
+             cout<<"Event: "<<event<<" has: "<<fBGEvents[z][multiplicity][event].size()<<endl;
+           }
+         }
+       }
+      }
+    }
+  }
+}
diff --git a/PWGGA/GammaConv/AliGammaConversionAODBGHandler.h b/PWGGA/GammaConv/AliGammaConversionAODBGHandler.h
new file mode 100644 (file)
index 0000000..2ab8a80
--- /dev/null
@@ -0,0 +1,85 @@
+//-*- Mode: C++ -*-
+#ifndef ALIGAMMACONVERSIONAODBGHANDLER_H
+#define ALIGAMMACONVERSIONAODBGHANDLER_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice     */
+
+////////////////////////////////////////////////
+//--------------------------------------------- 
+// Class  for handling of background calculation
+//---------------------------------------------
+////////////////////////////////////////////////
+
+#include <vector>
+
+
+// --- ROOT system ---
+#include <TObject.h> 
+#include "AliKFParticle.h"
+#include "AliAODConversionPhoton.h"
+#include "AliAODConversionMother.h"
+#include "TClonesArray.h"
+#include "AliESDVertex.h"
+
+#if __GNUC__ >= 3
+using namespace std;
+#endif
+
+typedef vector<AliAODConversionPhoton*> AliGammaConversionAODVector;
+
+class AliGammaConversionAODBGHandler : public TObject {
+
+ public: 
+  struct GammaConversionVertex
+  {
+    Double_t fX;
+    Double_t fY;
+    Double_t fZ;
+  };
+  typedef struct GammaConversionVertex GammaConversionVertex; //!
+
+  typedef vector<AliGammaConversionAODVector> AliGammaConversionBGEventVector;
+  typedef vector<AliGammaConversionBGEventVector> AliGammaConversionMultipicityVector;
+  typedef vector<AliGammaConversionMultipicityVector> AliGammaConversionBGVector;
+
+  AliGammaConversionAODBGHandler();                                                        //constructor
+  AliGammaConversionAODBGHandler(UInt_t binsZ,UInt_t binsMultiplicity,UInt_t fNEvents);    //constructor
+  AliGammaConversionAODBGHandler(const AliGammaConversionAODBGHandler & g);                   //copy constructor
+  AliGammaConversionAODBGHandler & operator = (const AliGammaConversionAODBGHandler & g);     //assignment operator
+  virtual ~AliGammaConversionAODBGHandler();                                               //virtual destructor
+
+  void Initialize(Double_t * const zBinLimitsArray, Double_t * const multiplicityBinLimitsArray);
+
+  Int_t GetZBinIndex(Double_t z) const;
+
+  Int_t GetMultiplicityBinIndex(Int_t mult) const;
+
+  void AddEvent(TList* const eventGammas, Double_t xvalue,Double_t yvalue,Double_t zvalue, Int_t multiplicity);
+  void AddElectronEvent(TClonesArray* const eventENeg, Double_t zvalue, Int_t multiplicity);
+
+  Int_t GetNBGEvents()const {return fNEvents;}
+
+  AliGammaConversionAODVector* GetBGGoodV0s(Int_t zbin, Int_t mbin, Int_t event);
+  AliGammaConversionAODVector* GetBGGoodENeg(Int_t event, Double_t zvalue, Int_t multiplicity);
+  void PrintBGArray();
+
+  GammaConversionVertex * GetBGEventVertex(Int_t zbin, Int_t mbin, Int_t event){return &fBGEventVertex[zbin][mbin][event];}
+
+  Double_t GetBGProb(Int_t z, Int_t m){return fBGProbability[z][m];}
+
+ private:
+
+  Int_t fNEvents; // number of events
+  Int_t ** fBGEventCounter; //! bg counter
+  Int_t ** fBGEventENegCounter;//! bg electron counter
+  Double_t ** fBGProbability; //! prob per bin
+  GammaConversionVertex *** fBGEventVertex;//! array of event vertex
+  Int_t fNBinsZ; //n z bins
+  Int_t fNBinsMultiplicity; //n bins multiplicity
+  Double_t *fBinLimitsArrayZ;//! bin limits z array
+  Double_t *fBinLimitsArrayMultiplicity;//! bin limit multiplicity array
+  AliGammaConversionBGVector fBGEvents; //background events
+  AliGammaConversionBGVector fBGEventsENeg; //background electron events
+  ClassDef(AliGammaConversionAODBGHandler,2)
+};
+#endif
index 3d89c4323f7acfea9731114b0e58e1074a6d433d..54b824a550da9bcf6fa67acaca82ba9fd7b21941 100644 (file)
 #pragma link C++ class AliV0ReaderV1+;
 #pragma link C++ class AliConversionAODBGHandlerRP+;
 #pragma link C++ class AliConversionTrackCuts++;
+#pragma link C++ class AliConversionMesonCuts+;
+#pragma link C++ class AliDalitzElectronCuts+;
+#pragma link C++ class AliDalitzElectronSelector+;
 
 // User tasks
 #pragma link C++ class AliAnalysisTaskGammaConvDalitz+;
 #pragma link C++ class AliAnalysisTaskPi0v2+;
+#pragma link C++ class AliGammaConversionAODBGHandler+;
+#pragma link C++ class AliAnalysisTaskGammaConvV1+;
+#pragma link C++ class AliAnalysisTaskGammaConvDalitzV1+;
+#pragma link C++ class AliAnalysisTaskConversionQA+;
 
 #pragma link C++ class AliAnaConvIsolation+;
 #pragma link C++ class AliAnaConvCorrBase++;
@@ -35,6 +42,4 @@
 #pragma link C++ class AliGammaConversionBGHandler+;
 #pragma link C++ class AliAnalysisTaskGCPartToPWG4Part+;
 
-
-
 #endif