sync with Gsi (from Martin)
authorloizides <loizides@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 27 Feb 2013 17:24:50 +0000 (17:24 +0000)
committerloizides <loizides@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 27 Feb 2013 17:24:50 +0000 (17:24 +0000)
21 files changed:
PWGGA/GammaConv/AliAODConversionPhoton.h
PWGGA/GammaConv/AliAnalysisTaskConversionQA.cxx
PWGGA/GammaConv/AliAnalysisTaskConversionQA.h
PWGGA/GammaConv/AliAnalysisTaskGammaConvDalitzV1.cxx
PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.cxx
PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.h
PWGGA/GammaConv/AliAnalysisTaskGammaConversion.cxx
PWGGA/GammaConv/AliAnalysisTaskMaterial.cxx
PWGGA/GammaConv/AliAnalysisTaskMaterial.h
PWGGA/GammaConv/AliAnalysisTaskPi0v2.cxx
PWGGA/GammaConv/AliAnalysisTaskPi0v2.h
PWGGA/GammaConv/AliConversionAODBGHandlerRP.cxx
PWGGA/GammaConv/AliConversionAODBGHandlerRP.h
PWGGA/GammaConv/AliConversionCuts.cxx
PWGGA/GammaConv/AliConversionCuts.h
PWGGA/GammaConv/AliConversionMesonCuts.cxx
PWGGA/GammaConv/AliConversionMesonCuts.h
PWGGA/GammaConv/AliConversionPhotonBase.h
PWGGA/GammaConv/AliConversionSelection.cxx
PWGGA/GammaConv/AliConversionSelection.h
PWGGA/GammaConv/AliV0ReaderV1.cxx

index 434db8a..06e7ae1 100644 (file)
@@ -31,6 +31,7 @@ class AliAODConversionPhoton : public AliAODConversionParticle, public AliConver
   virtual Double_t GetPhotonPt() const {return AliAODConversionParticle::Pt();}
   virtual Double_t GetPhotonP() const {return AliAODConversionParticle::P();}
   virtual Double_t GetPhotonEta() const {return AliAODConversionParticle::Eta();}
+  virtual Double_t GetPhotonTheta() const {return AliAODConversionParticle::Theta();}
   virtual Double_t GetPhotonPhi() const {return AliAODConversionParticle::Phi();}
   virtual Double_t GetPx() const { return AliAODConversionParticle::Px();}
   virtual Double_t GetPy() const { return AliAODConversionParticle::Py();}
index 3bf6c82..4cd0832 100644 (file)
@@ -1,16 +1,16 @@
 /**************************************************************************
  * 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.                                               *
+ *                                                                       *
+ * 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.                 *
  **************************************************************************/
 
 ////////////////////////////////////////////////
@@ -26,6 +26,7 @@
 #include "TVectorF.h"
 #include "AliPIDResponse.h"
 #include "TFile.h"
+#include "AliESDtrackCuts.h"
 
 class iostream;
 
@@ -35,11 +36,57 @@ ClassImp(AliAnalysisTaskConversionQA)
 
 //________________________________________________________________________
 AliAnalysisTaskConversionQA::AliAnalysisTaskConversionQA(const char *name) : AliAnalysisTaskSE(name),
+   fV0Reader(NULL),
    fConversionGammas(NULL),
    fConversionCuts(NULL),
+   fInputEvent(NULL),
+   fNumberOfESDTracks(0),
+   fMCEvent(NULL),
+   fMCStack(NULL),
    fStreamQA(NULL),
    fIsHeavyIon(kFALSE),
-   fOutputList(NULL)
+   ffillTree(kFALSE),
+   ffillHistograms(kFALSE),
+   fOutputList(NULL),
+   fESDList(NULL),
+   hVertexZ(NULL),
+   hNGoodESDTracks(NULL),
+   hNV0Tracks(NULL),
+   hNContributorsVertex(NULL),
+   hITSClusterPhi(NULL),
+   hGammaPt(NULL),
+   hGammaPhi(NULL),
+   hGammaEta(NULL),
+   hGammaChi2perNDF(NULL),
+   hGammaPsiPair(NULL),
+   hGammaQt(NULL),
+   hGammaCosinePointingAngle(NULL),
+   hGammaXY(NULL),
+   hGammaZR(NULL),
+   hElecPt(NULL),
+   hElecEta(NULL),
+   hElecPhi(NULL),
+   hElecNfindableClsTPC(NULL),
+   hPosiNfindableClsTPC(NULL),
+   fTrueList(NULL),
+   hTrueResoulutionR(NULL),
+   hTrueResoulutionZ(NULL),
+   hTrueResoulutionPhi(NULL),
+   hTrueGammaPt(NULL),
+   hTrueGammaPhi(NULL),
+   hTrueGammaEta(NULL),
+   hTrueGammaMass(NULL),
+   hTrueGammaChi2perNDF(NULL),
+   hTrueGammaPsiPair(NULL),
+   hTrueGammaQt(NULL),
+   hTrueGammaCosinePointingAngle(NULL),
+   hTrueGammaXY(NULL),
+   hTrueGammaZR(NULL),
+   hTrueElecPt(NULL),
+   hTrueElecEta(NULL),
+   hTrueElecPhi(NULL),
+   hTrueElecNfindableClsTPC(NULL),
+   hTruePosiNfindableClsTPC(NULL)
 {
    // Default constructor
 
@@ -70,42 +117,162 @@ void AliAnalysisTaskConversionQA::UserCreateOutputObjects()
       fOutputList->SetOwner(kTRUE);
    }
 
-   // V0 Reader Cuts
-   TString cutnumber = fConversionCuts->GetCutNumber();
+   if(ffillHistograms){
+      fESDList = new TList();
+      fESDList->SetOwner(kTRUE);
+      fESDList->SetName("ESD QA");
+      fOutputList->Add(fESDList);
 
-   fStreamQA = new TTreeSRedirector(Form("GammaConvV1_QA_%s.root",cutnumber.Data()));
-   PostData(1, fOutputList);
+      hVertexZ = new TH1F("Vertex_Z","Vertex_Z",300,-15,15);
+      fESDList->Add(hVertexZ);
+      hNContributorsVertex = new TH1I("ContrVertex_Z","ContrVertex_Z",3000,0,3000);
+      fESDList->Add(hNContributorsVertex);
+               if(fIsHeavyIon) hNGoodESDTracks = new TH1I("GoodESDTracks","GoodESDTracks",3000,0,3000);
+      else hNGoodESDTracks = new TH1I("GoodESDTracks","GoodESDTracks",200,0,200);
+      fESDList->Add(hNGoodESDTracks);
+      if(fIsHeavyIon) hNV0Tracks = new TH1I("V0 Multiplicity","V0 Multiplicity",30000,0,30000);
+      else hNV0Tracks = new TH1I("V0 Multiplicity","V0 Multiplicity",2000,0,2000);
+      fESDList->Add(hNV0Tracks);
+
+      hITSClusterPhi = new TH2F("ITSClusterPhi","hITSClusterPhi",72,0,2*TMath::Pi(),7,0,7);
+      fESDList->Add(hITSClusterPhi);
+      hGammaPt = new TH1F("Gamma_Pt","Gamma_Pt",250,0,25);
+      fESDList->Add(hGammaPt);
+      hGammaPhi = new TH1F("Gamma_Phi","Gamma_Phi",360,0,2*TMath::Pi());
+      fESDList->Add(hGammaPhi);
+      hGammaEta = new TH1F("Gamma_Eta","Gamma_Eta",400,-1.2,1.2);
+      fESDList->Add(hGammaEta);
+      hGammaChi2perNDF = new TH1F("Gamma_Chi2perNDF","Gamma_Chi2perNDF",500,0,100);
+      fESDList->Add(hGammaChi2perNDF);
+      hGammaPsiPair = new TH1F("Gamma_PsiPair","Gamma_PsiPair",500,0,2);
+      fESDList->Add(hGammaPsiPair);
+      hGammaQt = new TH1F("Gamma_Qt","Gamma_Qt",400,0,0.1);
+      fESDList->Add(hGammaQt);
+      hGammaCosinePointingAngle = new TH1F("Gamma_CosinePointingAngle","Gamma_CosinePointingAngle",900,0.7,1.);
+      fESDList->Add(hGammaCosinePointingAngle);
+      hGammaXY = new TH2F("Gamma_ConversionPoint_XY","Gamma_ConversionPoint_XY",960,-120,120,960,-120,120);
+      fESDList->Add(hGammaXY);
+      hGammaZR= new TH2F("Gamma_ConversionPoint_ZR","Gamma_ConversionPoint_ZR",1200,-150,150,480,0,120);
+      fESDList->Add(hGammaZR);
+
+      hElecPt = new TH2F("Electron_Positron_Pt","Electron_Positron_Pt",250,0,25,250,0,25);
+      fESDList->Add(hElecPt);
+      hElecEta = new TH2F("Electron_Positron_Eta","Electron_Positron_Eta",400,-1.2,1.2,400,-1.2,1.2);
+      fESDList->Add(hElecEta);
+      hElecPhi = new TH2F("Electron_Positron_Phi","Electron_Positron_Phi",360,0,2*TMath::Pi(),360,0,2*TMath::Pi());
+      fESDList->Add(hElecPhi);
+      hElecNfindableClsTPC = new TH1F("Electron_findableClusterTPC","Electron_findableClusterTPC",100,0,1);
+      fESDList->Add(hElecNfindableClsTPC);
+      hPosiNfindableClsTPC = new TH1F("Positron_findableClusterTPC","Positron_findableClusterTPC",100,0,1);
+      fESDList->Add(hPosiNfindableClsTPC);
+
+      if(MCEvent()){
+         fTrueList = new TList();
+         fTrueList->SetOwner(kTRUE);
+         fTrueList->SetName("True QA");
+         fOutputList->Add(fTrueList);
 
+         hTrueResoulutionR = new TH2F("True_ConversionPointResolution_R","True_ConversionPointResolution_R",240,0,120,200,-20,20);
+         fTrueList->Add(hTrueResoulutionR);
+         hTrueResoulutionZ = new TH2F("True_ConversionPointResolution_Z","True_ConversionPointResolution_Z",480,-120,120,200,-20,20);
+         fTrueList->Add(hTrueResoulutionZ);
+         hTrueResoulutionPhi = new TH2F("True_ConversionPointResolution_Phi","True_ConversionPointResolution_Phi",360,0,2*TMath::Pi(),200,-20,20);
+         fTrueList->Add(hTrueResoulutionPhi);
+
+         hTrueGammaPt = new TH1F("True_Gamma_Pt","True_Gamma_Pt",250,0,25);
+         fTrueList->Add(hTrueGammaPt);
+         hTrueGammaPhi = new TH1F("True_Gamma_Phi","True_Gamma_Phi",360,0,2*TMath::Pi());
+         fTrueList->Add(hTrueGammaPhi);
+         hTrueGammaEta = new TH1F("True_Gamma_Eta","True_Gamma_Eta",400,-1.2,1.2);
+         fTrueList->Add(hTrueGammaEta);
+         hTrueGammaMass = new TH1F("True_Gamma_Mass","True_Gamma_Mass",1000,0,0.3);
+         fTrueList->Add(hTrueGammaMass);
+         hTrueGammaChi2perNDF = new TH1F("True_Gamma_Chi2perNDF","True_Gamma_Chi2perNDF",500,0,100);
+         fTrueList->Add(hTrueGammaChi2perNDF);
+         hTrueGammaPsiPair = new TH1F("True_Gamma_PsiPair","True_Gamma_PsiPair",500,0,2);
+         fTrueList->Add(hTrueGammaPsiPair);
+         hTrueGammaQt = new TH1F("True_Gamma_Qt","True_Gamma_Qt",400,0,0.1);
+         fTrueList->Add(hTrueGammaQt);
+         hTrueGammaCosinePointingAngle = new TH1F("True_Gamma_CosinePointingAngle","True_Gamma_CosinePointingAngle",900,0.7,1.);
+         fTrueList->Add(hTrueGammaCosinePointingAngle);
+         hTrueGammaXY = new TH2F("True_Gamma_ConversionPoint_XY","True_Gamma_ConversionPoint_XY",960,-120,120,960,-120,120);
+         fTrueList->Add(hTrueGammaXY);
+         hTrueGammaZR= new TH2F("TrueGamma_ConversionPoint_ZR","TrueGamma_ConversionPoint_ZR",1200,-150,150,480,0,120);
+         fTrueList->Add(hTrueGammaZR);
+
+         hTrueElecPt = new TH2F("True_Electron_Positron_Pt","True_Electron_Positron_Pt",250,0,25,250,0,25);
+         fTrueList->Add(hTrueElecPt);
+         hTrueElecEta = new TH2F("True_Electron_Positron_Eta","True_Electron_Positron_Eta",400,-1.2,1.2,400,-1.2,1.2);
+         fTrueList->Add(hTrueElecEta);
+         hTrueElecPhi = new TH2F("True_Electron_Positron_Phi","True_Electron_Positron_Phi",360,0,2*TMath::Pi(),360,0,2*TMath::Pi());
+         fTrueList->Add(hTrueElecPhi);
+         hTrueElecNfindableClsTPC = new TH1F("True_Electron_findableClusterTPC","True_Electron_findableClusterTPC",100,0,1);
+         fTrueList->Add(hTrueElecNfindableClsTPC);
+         hTruePosiNfindableClsTPC = new TH1F("True_Positron_findableClusterTPC","True_Positron_findableClusterTPC",100,0,1);
+         fTrueList->Add(hTruePosiNfindableClsTPC);
+      }
+   }
+
+   if(ffillTree){
+      TString cutnumber = fConversionCuts->GetCutNumber();   
+      fStreamQA = new TTreeSRedirector(Form("GammaConvV1_QATree_%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;
+   fInputEvent = InputEvent();
+   fMCEvent = MCEvent();
+   if(fMCEvent) fMCStack = fMCEvent->Stack();
+
+   Int_t eventNotAccepted =
+      fConversionCuts->IsEventAcceptedByConversionCut(fV0Reader->GetConversionCuts(),fInputEvent,fMCEvent,fIsHeavyIon);
+   if(eventNotAccepted) return; // Check Centrality, PileUp, SDD and V0AND --> Not Accepted => eventQuality = 1
 
    fConversionGammas=fV0Reader->GetReconstructedGammas();
 
-   ProcessQA();
+   if(fMCEvent){
+      if(fConversionCuts->GetSignalRejection() != 0){
+         fConversionCuts->GetNotRejectedParticles(fConversionCuts->GetSignalRejection(),
+                                                  fConversionCuts->GetAcceptedHeader(),
+                                                  fMCEvent);
+      }
+   }
+
+   if(ffillTree)ProcessQATree();
+   if(ffillHistograms){
+      CountESDTracks();
+      ProcessQA();
+   }
+   
    PostData(1, fOutputList);
 }
 
 
 ///________________________________________________________________________
-void AliAnalysisTaskConversionQA::ProcessQA(){
-
+void AliAnalysisTaskConversionQA::ProcessQATree(){
+   
    // 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;
+      if(fMCEvent && fConversionCuts->GetSignalRejection() != 0){
+         if(!fConversionCuts->IsParticleFromBGEvent(gamma->GetMCLabelPositive(), fMCStack))
+            continue;
+         if(!fConversionCuts->IsParticleFromBGEvent(gamma->GetMCLabelNegative(), fMCStack))
+            continue;
+      }
       Float_t gammaPt = gamma->GetPhotonPt();
       Float_t gammaPhi = gamma->GetPhotonPhi();
       Float_t gammaTheta = gamma->Theta();
@@ -113,56 +280,269 @@ void AliAnalysisTaskConversionQA::ProcessQA(){
       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());
+      Float_t gammaCosPointing = fConversionCuts->GetCosineOfPointingAngle(gamma,event);
+      TVectorF conversionPoint(3);
+      conversionPoint(0) = gamma->GetConversionX();
+      conversionPoint(1) = gamma->GetConversionY();
+      conversionPoint(2) = gamma->GetConversionZ();
+      TVectorF daughterProp(18);
+      AliESDtrack * negTrack = fConversionCuts->GetESDTrack(event, gamma->GetTrackLabelNegative());
+      AliESDtrack * posTrack = fConversionCuts->GetESDTrack(event, gamma->GetTrackLabelPositive());
+
       if(!negTrack||!posTrack)return;
 
+      Bool_t isTruePhoton = kFALSE;
+      if(fMCEvent){
+         if(IsTruePhoton(gamma)) isTruePhoton = kTRUE;
+      }
+
       daughterProp(0) = posTrack->Pt();
       daughterProp(7) = negTrack->Pt();
       daughterProp(1) = posTrack->Theta();
       daughterProp(8) = negTrack->Theta();
-      daughterProp(2) = posTrack->GetTPCsignal();
-      daughterProp(9) = negTrack->GetTPCsignal();
+      Double32_t signalPos[4] = {0,0,0,0};
+      Char_t nclPos[3];
+      Char_t nrowsPos[3];
+      if (posTrack->GetTPCdEdxInfo()) {
+         posTrack->GetTPCdEdxInfo()->GetTPCSignalRegionInfo(signalPos,nclPos,nrowsPos);
+         daughterProp(2) = signalPos[0];
+         daughterProp(14) = signalPos[1];
+         daughterProp(16) = signalPos[2];
+      } else {
+         daughterProp(2) = posTrack->GetTPCsignal();
+         daughterProp(14) = 0;
+         daughterProp(16) = 0;
+      }
+      Double32_t signalNeg[4] = {0,0,0,0};
+      Char_t nclNeg[3];
+      Char_t nrowsNeg[3];
+      if (negTrack->GetTPCdEdxInfo()) {
+         negTrack->GetTPCdEdxInfo()->GetTPCSignalRegionInfo(signalNeg,nclNeg,nrowsNeg);
+         daughterProp(9) = signalNeg[0];
+         daughterProp(15) = signalNeg[1];
+         daughterProp(17) = signalNeg[2];
+      } else {
+         daughterProp(9) = negTrack->GetTPCsignal();
+         daughterProp(15) = 0;
+         daughterProp(17) = 0;
+      }
       daughterProp(3) = pidResonse->NumberOfSigmasTPC(posTrack,AliPID::kElectron);
       daughterProp(10) = pidResonse->NumberOfSigmasTPC(negTrack,AliPID::kElectron);
       if((posTrack->GetStatus() & AliESDtrack::kTOFpid) && !(posTrack->GetStatus() & AliESDtrack::kTOFmismatch)){
-         daughterProp(4) = posTrack->GetTOFsignal();
+         Double_t t0pos = pidResonse->GetTOFResponse().GetStartTime(posTrack->P());
+         Double_t timesPos[5];
+         posTrack->GetIntegratedTimes(timesPos);
+         Double_t TOFsignalPos =       posTrack->GetTOFsignal();
+         Double_t dTpos = TOFsignalPos - t0pos - timesPos[0];
+         daughterProp(4) = dTpos;
          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();
+         Double_t t0neg = pidResonse->GetTOFResponse().GetStartTime(negTrack->P());
+         Double_t timesNeg[5];
+         negTrack->GetIntegratedTimes(timesNeg);
+         Double_t TOFsignalNeg =       negTrack->GetTOFsignal();
+         Double_t dTneg = TOFsignalNeg - t0neg - timesNeg[0];
+         daughterProp(11) = dTneg;
          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();
+      
+      daughterProp(6) = (Float_t)posTrack->GetTPCClusterInfo(2,0,fConversionCuts->GetFirstTPCRow(gamma->GetConversionRadius()));
+      //posTrack->GetNcls(1)/(Float_t)posTrack->GetTPCNclsF();
+      daughterProp(13) = (Float_t)negTrack->GetTPCClusterInfo(2,0,fConversionCuts->GetFirstTPCRow(gamma->GetConversionRadius()));
+      //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";
+         if(fMCEvent){
+            (*fStreamQA)<<"PhotonQA"
+                        << "pt=" << gammaPt
+                        << "phi=" << gammaPhi
+                        << "theta=" << gammaTheta
+                        << "chi2ndf=" << gammaChi2NDF
+                        << "qt="<< gammaQt
+                        << "alpha=" << gammaAlpha
+                        << "psipair=" << gammaPsiPair
+                        << "cosPoint=" << gammaCosPointing
+                        << "TruePhoton=" << isTruePhoton
+                        << "conversionPoint=" << &conversionPoint
+                        << "daugtherProp.=" << &daughterProp
+                        << "\n";
+         }
+         else{
+            (*fStreamQA)<<"PhotonQA"
+                        << "pt=" << gammaPt
+                        << "phi=" << gammaPhi
+                        << "theta=" << gammaTheta
+                        << "chi2ndf=" << gammaChi2NDF
+                        << "qt="<< gammaQt
+                        << "alpha=" << gammaAlpha
+                        << "psipair=" << gammaPsiPair
+                        << "cosPoint=" << gammaCosPointing
+                        << "conversionPoint=" << &conversionPoint
+                        << "daugtherProp.=" << &daughterProp
+                        << "\n";
+         }
       }
    }
 }
+//_____________________________________________________________________________________________________
+void AliAnalysisTaskConversionQA::ProcessQA(){
+
+   hVertexZ->Fill(fInputEvent->GetPrimaryVertex()->GetZ());
+   hNContributorsVertex->Fill(fConversionCuts->GetNumberOfContributorsVtx(fInputEvent));
+   hNGoodESDTracks->Fill(fNumberOfESDTracks);
+   hNV0Tracks->Fill(fInputEvent->GetVZEROData()->GetMTotV0A()+fInputEvent->GetVZEROData()->GetMTotV0C());
 
+   // Fill Histograms for QA and MC
+   for(Int_t gammaIndex=0;gammaIndex<fConversionGammas->GetEntriesFast();gammaIndex++){
+      AliAODConversionPhoton *gamma = dynamic_cast<AliAODConversionPhoton*>(fConversionGammas->At(gammaIndex));
+      if(!fConversionCuts->PhotonIsSelected(gamma,fInputEvent)) continue;
+
+      if(fMCEvent && fConversionCuts->GetSignalRejection() != 0){
+         if(!fConversionCuts->IsParticleFromBGEvent(gamma->GetMCLabelPositive(), fMCStack))
+            continue;
+         if(!fConversionCuts->IsParticleFromBGEvent(gamma->GetMCLabelNegative(), fMCStack))
+            continue;
+      }
+      hGammaPt->Fill(gamma->GetPhotonPt());
+      hGammaPhi->Fill(gamma->GetPhotonPhi());
+      hGammaEta->Fill(gamma->Eta());
+      hGammaChi2perNDF->Fill(gamma->GetChi2perNDF());
+      hGammaPsiPair->Fill(gamma->GetPsiPair());
+      hGammaQt->Fill(gamma->GetArmenterosQt());
+      hGammaCosinePointingAngle->Fill(fConversionCuts->GetCosineOfPointingAngle(gamma,fInputEvent));
+      hGammaXY->Fill(gamma->GetConversionX(),gamma->GetConversionY());
+      hGammaZR->Fill(gamma->GetConversionZ(),gamma->GetConversionRadius());
+
+      AliESDtrack * negTrack = fConversionCuts->GetESDTrack((AliESDEvent*)fInputEvent, gamma->GetTrackLabelNegative());
+      AliESDtrack * posTrack = fConversionCuts->GetESDTrack((AliESDEvent*)fInputEvent, gamma->GetTrackLabelPositive());
+      if(!negTrack||!posTrack)return;
+
+      Double_t negtrackPhi = negTrack->Phi();
+      Double_t postrackPhi = posTrack->Phi();
+      hITSClusterPhi->Fill(negtrackPhi,6);
+      hITSClusterPhi->Fill(postrackPhi,6);
+      for(Int_t itsLayer = 0; itsLayer<6;itsLayer++){
+         if(TESTBIT(negTrack->GetITSClusterMap(),itsLayer)){
+            hITSClusterPhi->Fill(negtrackPhi,itsLayer);
+         }
+         if(TESTBIT(posTrack->GetITSClusterMap(),itsLayer)){
+            hITSClusterPhi->Fill(postrackPhi,itsLayer);
+         }
+      }
+
+      hElecPt->Fill(negTrack->Pt(),posTrack->Pt());
+      hElecEta->Fill(negTrack->Eta(),posTrack->Eta());
+      hElecPhi->Fill(negTrack->Phi(),posTrack->Phi());
+
+      hElecNfindableClsTPC->Fill((Float_t)posTrack->GetTPCClusterInfo(2,0,fConversionCuts->GetFirstTPCRow(gamma->GetConversionRadius())));
+      hPosiNfindableClsTPC->Fill((Float_t)negTrack->GetTPCClusterInfo(2,0,fConversionCuts->GetFirstTPCRow(gamma->GetConversionRadius())));
+      
+      // hElecNfindableClsTPC->Fill((Float_t)negTrack->GetNcls(1)/(Float_t)negTrack->GetTPCNclsF());
+      // hPosiNfindableClsTPC->Fill((Float_t)posTrack->GetNcls(1)/(Float_t)posTrack->GetTPCNclsF());
+      
+      if(fMCEvent)
+         ProcessTrueQA(gamma,negTrack,posTrack);
+   }
+}
+//________________________________________________________________________
+void AliAnalysisTaskConversionQA::ProcessTrueQA(AliAODConversionPhoton *TruePhotonCandidate, AliESDtrack *elec, AliESDtrack *posi)
+{
+
+   if(!IsTruePhoton(TruePhotonCandidate)) return;
+
+   TParticle *negDaughter = TruePhotonCandidate->GetNegativeMCDaughter(fMCStack);
+   TParticle *mcPhoton = TruePhotonCandidate->GetMCParticle(fMCStack);
+
+   // True Photon
+   hTrueResoulutionR->Fill(TruePhotonCandidate->GetConversionRadius(),
+                           TruePhotonCandidate->GetConversionRadius()-negDaughter->R());
+   hTrueResoulutionZ->Fill(TruePhotonCandidate->GetConversionZ(),
+                           TruePhotonCandidate->GetConversionZ()-negDaughter->Vz());
+   hTrueResoulutionPhi->Fill(TruePhotonCandidate->Phi(),
+                           TruePhotonCandidate->Phi()-mcPhoton->Phi());
+   hTrueGammaPt->Fill(TruePhotonCandidate->Pt());
+   hTrueGammaPhi->Fill(TruePhotonCandidate->Phi());
+   hTrueGammaEta->Fill(TruePhotonCandidate->Eta());
+   hTrueGammaMass->Fill(TruePhotonCandidate->GetMass());
+   hTrueGammaChi2perNDF->Fill(TruePhotonCandidate->GetChi2perNDF());
+   hTrueGammaPsiPair->Fill(TruePhotonCandidate->GetPsiPair());
+   hTrueGammaQt->Fill(TruePhotonCandidate->GetArmenterosQt());
+   hTrueGammaCosinePointingAngle->Fill(fConversionCuts->GetCosineOfPointingAngle(TruePhotonCandidate,fInputEvent));
+   hTrueGammaXY->Fill(TruePhotonCandidate->GetConversionX(),TruePhotonCandidate->GetConversionY());
+   hTrueGammaZR->Fill(TruePhotonCandidate->GetConversionZ(),TruePhotonCandidate->GetConversionRadius());
+
+   hTrueElecPt->Fill(elec->Pt(),posi->Pt());
+   hTrueElecEta->Fill(elec->Eta(),posi->Eta());
+   hTrueElecPhi->Fill(elec->Phi(),posi->Phi());
+   hTrueElecNfindableClsTPC
+      ->Fill((Float_t)elec->GetTPCClusterInfo(2,0,fConversionCuts->GetFirstTPCRow(TruePhotonCandidate->GetConversionRadius())));
+   hTruePosiNfindableClsTPC
+      ->Fill((Float_t)posi->GetTPCClusterInfo(2,0,fConversionCuts->GetFirstTPCRow(TruePhotonCandidate->GetConversionRadius())));
+   // hTrueElecNfindableClsTPC->Fill((Float_t)elec->GetNcls(1)/(Float_t)elec->GetTPCNclsF());
+   // hTruePosiNfindableClsTPC->Fill((Float_t)posi->GetNcls(1)/(Float_t)posi->GetTPCNclsF());
+   
+}
+//________________________________________________________________________
+void AliAnalysisTaskConversionQA::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 < fInputEvent->GetNumberOfTracks(); iTracks++){
+      AliESDtrack* curTrack = (AliESDtrack*)fInputEvent->GetTrack(iTracks);
+      if(!curTrack) continue;
+      // if(fMCEvent && fConversionCuts->GetSignalRejection() != 0){
+      //    if(!fConversionCuts->IsParticleFromBGEvent(abs(curTrack->GetLabel()), fMCStack)) continue;
+      // }
+      if(EsdTrackCuts->AcceptTrack(curTrack) ) fNumberOfESDTracks++;
+   }
+   delete EsdTrackCuts;
+   EsdTrackCuts=0x0;
+
+   return;
+}
+//________________________________________________________________________
+Bool_t AliAnalysisTaskConversionQA::IsTruePhoton(AliAODConversionPhoton *TruePhotonCandidate)
+{
+   TParticle *posDaughter = TruePhotonCandidate->GetPositiveMCDaughter(fMCStack);
+   TParticle *negDaughter = TruePhotonCandidate->GetNegativeMCDaughter(fMCStack);
+      
+   if(posDaughter == NULL || negDaughter == NULL) return kFALSE; // One particle does not exist
+   Int_t pdgCode[2] = {abs(posDaughter->GetPdgCode()),abs(negDaughter->GetPdgCode())};
+   if(posDaughter->GetMother(0) != negDaughter->GetMother(0)) return kFALSE;
+   else if(posDaughter->GetMother(0) == -1) return kFALSE;
+
+   if(pdgCode[0]!=11 || pdgCode[1]!=11) return kFALSE; //One Particle is not electron
+   if(posDaughter->GetPdgCode()==negDaughter->GetPdgCode()) return kFALSE; // Same Charge
+   if(posDaughter->GetUniqueID() != 5 || negDaughter->GetUniqueID() !=5) return kFALSE;// check if the daughters come from a conversion
+   
+   TParticle *Photon = TruePhotonCandidate->GetMCParticle(fMCStack);
+   if(Photon->GetPdgCode() != 22) return kFALSE; // Mother is no Photon
+
+   return kTRUE;
+}
 
 //________________________________________________________________________
 void AliAnalysisTaskConversionQA::Terminate(Option_t *)
 {
-   if (fStreamQA){
-      fStreamQA->GetFile()->Write();
+   if(ffillHistograms && fConversionCuts->GetCutHistograms()){
+      fOutputList->Add(fConversionCuts->GetCutHistograms());
    }
+   
+   // if (fStreamQA){
+   //    //fStreamQA->GetFile()->Write();
+   // }
 }
index 9ee37a5..c32aa9c 100644 (file)
@@ -34,19 +34,72 @@ public:
        fConversionCuts=conversionCuts;
        fIsHeavyIon = IsHeavyIon;
     }
+    void FillType(Bool_t fillTree, Bool_t fillHistorams){
+       ffillTree = fillTree;
+       ffillHistograms = fillHistorams;
+    }
     
 private:
 
+    void ProcessQATree();
     void ProcessQA();
-
-    AliV0ReaderV1 *fV0Reader;
-    TClonesArray *fConversionGammas; //Reconstructed Photons;
+    void ProcessTrueQA(AliAODConversionPhoton *TruePhotonCandidate, AliESDtrack *elec, AliESDtrack *posi);
+    Bool_t IsTruePhoton(AliAODConversionPhoton *TruePhotonCandidate);
+    void CountESDTracks();
+       
+    AliV0ReaderV1 *fV0Reader;    
+    TClonesArray *fConversionGammas;
     AliConversionCuts *fConversionCuts; // Cuts used by the V0Reader
+    AliVEvent *fInputEvent;
+    Int_t fNumberOfESDTracks;
+    AliMCEvent *fMCEvent;
+    AliStack *fMCStack;
     TTreeSRedirector *fStreamQA;
     Bool_t fIsHeavyIon;
+    Bool_t ffillTree;
+    Bool_t ffillHistograms;
     TList *fOutputList;
-
-    ClassDef(AliAnalysisTaskConversionQA, 0);
+    TList *fESDList;
+    TH1F *hVertexZ;
+        TH1I *hNGoodESDTracks;
+    TH1I *hNV0Tracks;
+        TH1I *hNContributorsVertex;
+    TH2F *hITSClusterPhi;
+    TH1F *hGammaPt;
+    TH1F *hGammaPhi;
+    TH1F *hGammaEta;
+    TH1F *hGammaChi2perNDF;
+    TH1F *hGammaPsiPair;
+    TH1F *hGammaQt;
+    TH1F *hGammaCosinePointingAngle;
+    TH2F *hGammaXY;
+    TH2F *hGammaZR;
+    TH2F *hElecPt;
+    TH2F *hElecEta;
+    TH2F *hElecPhi;
+    TH1F *hElecNfindableClsTPC;
+    TH1F *hPosiNfindableClsTPC;
+    TList *fTrueList;
+    TH2F *hTrueResoulutionR;
+    TH2F *hTrueResoulutionZ;
+    TH2F *hTrueResoulutionPhi;
+    TH1F *hTrueGammaPt;
+    TH1F *hTrueGammaPhi;
+    TH1F *hTrueGammaEta;
+    TH1F *hTrueGammaMass;
+    TH1F *hTrueGammaChi2perNDF;
+    TH1F *hTrueGammaPsiPair;
+    TH1F *hTrueGammaQt;
+    TH1F *hTrueGammaCosinePointingAngle;
+    TH2F *hTrueGammaXY;
+    TH2F *hTrueGammaZR;
+    TH2F *hTrueElecPt;
+    TH2F *hTrueElecEta;
+    TH2F *hTrueElecPhi;
+    TH1F *hTrueElecNfindableClsTPC;
+    TH1F *hTruePosiNfindableClsTPC;
+    
+    ClassDef(AliAnalysisTaskConversionQA, 1);
 };
 
 #endif
index cd42f1e..f21e7cd 100644 (file)
@@ -297,11 +297,11 @@ void AliAnalysisTaskGammaConvDalitzV1::InitBack(){
       fBackList[iCut]->Add(sESDMotherBackInvMassPtZM[iCut]);
 
       if(((AliConversionMesonCuts*)fCutMesonArray->At(iCut))->UseTrackMultiplicity()){
-         fBGHandler[iCut] = new AliGammaConversionAODBGHandler(9,6,((AliConversionMesonCuts*)fCutGammaArray->At(iCut))->NumberOfBGEvents());
+         fBGHandler[iCut] = new AliGammaConversionAODBGHandler(9,6,((AliConversionMesonCuts*)fCutGammaArray->At(iCut))->GetNumberOfBGEvents());
          fBGHandler[iCut]->Initialize(zBinLimitsArray, multiplicityBinLimitsArrayTracks);
       }
       else{
-         fBGHandler[iCut] = new AliGammaConversionAODBGHandler(9,5,((AliConversionMesonCuts*)fCutGammaArray->At(iCut))->NumberOfBGEvents());
+         fBGHandler[iCut] = new AliGammaConversionAODBGHandler(9,5,((AliConversionMesonCuts*)fCutGammaArray->At(iCut))->GetNumberOfBGEvents());
          fBGHandler[iCut]->Initialize(zBinLimitsArray, multiplicityBinLimitsArrayV0s);
       }
    }
@@ -854,7 +854,7 @@ void AliAnalysisTaskGammaConvDalitzV1::CalculatePi0DalitzCandidates(){
                } else {
                   mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fGoodGammas->GetEntries());
                }
-               Double_t sparesFill[4] = {pi0cand->M(),pi0cand->Pt(),zbin,mbin};
+               Double_t sparesFill[4] = {pi0cand->M(),pi0cand->Pt(),(Double_t)zbin,(Double_t)mbin};
                sESDMotherInvMassPtZM[fiCut]->Fill(sparesFill,1);
                if(fMCEvent){
                   ProcessTrueMesonCandidates(pi0cand,gamma,Vgamma);
@@ -911,7 +911,7 @@ void AliAnalysisTaskGammaConvDalitzV1::CalculateBackground(){
                   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};
+                     Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
                      sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
                   }
                   delete backgroundCandidate;
@@ -941,7 +941,7 @@ void AliAnalysisTaskGammaConvDalitzV1::CalculateBackground(){
 
                      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};
+                        Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
                         sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
                      }
                      delete backgroundCandidate;
@@ -969,7 +969,7 @@ void AliAnalysisTaskGammaConvDalitzV1::CalculateBackground(){
                   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};
+                     Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
                      sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
                   }
                   delete backgroundCandidate;
index a6c7734..871bd9e 100644 (file)
@@ -41,8 +41,8 @@
 #include "AliESDtrackCuts.h"
 #include "AliKFVertex.h"
 #include "AliV0ReaderV1.h"
-#include "AliGammaConversionAODBGHandler.h"
 #include "AliGenCocktailEventHeader.h"
+#include "AliConversionAODBGHandlerRP.h"
 
 ClassImp(AliAnalysisTaskGammaConvV1)
 
@@ -50,7 +50,8 @@ ClassImp(AliAnalysisTaskGammaConvV1)
 AliAnalysisTaskGammaConvV1::AliAnalysisTaskGammaConvV1(): AliAnalysisTaskSE(),
    fV0Reader(NULL),
    fBGHandler(NULL),
-   fESDEvent(NULL),
+   fBGHandlerRP(NULL),
+   fInputEvent(NULL),
    fMCEvent(NULL),
    fMCStack(NULL),
    fCutFolder(NULL),
@@ -68,6 +69,7 @@ AliAnalysisTaskGammaConvV1::AliAnalysisTaskGammaConvV1(): AliAnalysisTaskSE(),
    fMesonCutArray(NULL),
    fMesonCuts(NULL),
    hESDConvGammaPt(NULL),
+   hESDConvGammaR(NULL),
    hESDMotherInvMassPt(NULL),
    sESDMotherInvMassPtZM(NULL),
    hESDMotherBackInvMassPt(NULL),
@@ -80,44 +82,58 @@ AliAnalysisTaskGammaConvV1::AliAnalysisTaskGammaConvV1(): AliAnalysisTaskSE(),
    hMCDecayGammaOmegaPt(NULL),
    hMCDecayGammaEtapPt(NULL),
    hMCDecayGammaPhiPt(NULL),
+   hMCDecayGammaSigmaPt(NULL),
    hMCConvGammaPt(NULL),
    hMCConvGammaR(NULL),
    hMCConvGammaEta(NULL),
+   hMCConvGammaRSPt(NULL),
+   hMCConvGammaRSR(NULL),
+   hMCConvGammaRSEta(NULL),
    hMCPi0Pt(NULL),
    hMCEtaPt(NULL),
    hMCPi0InAccPt(NULL),
    hMCEtaInAccPt(NULL),
    hESDTrueMotherInvMassPt(NULL),
+   hESDTruePi0FromEtaInvMassPt(NULL),
    hESDTruePrimaryMotherInvMassMCPt(NULL),
    hESDTruePrimaryPi0ESDPtMCPt(NULL),
    hESDTrueSecondaryMotherInvMassPt(NULL),
    hESDTrueSecondaryMotherFromK0sInvMassPt(NULL),
+   hESDTrueK0sWithPi0DaughterMCPt(NULL),
+   hESDTrueSecondaryMotherFromEtaInvMassPt(NULL),
+   hESDTrueEtaWithPi0DaughterMCPt(NULL),
    hESDTrueBckGGInvMassPt(NULL),
    hESDTrueBckContInvMassPt(NULL),
    hESDTrueMotherDalitzInvMassPt(NULL),
    hESDTrueConvGammaPt(NULL),
-   hESDTrueTwoElecCombPt(NULL),
-   hESDTrueTwoPionCombPt(NULL),
-   hESDTrueElecPionCombPt(NULL),
-   hESDTrueCombPt(NULL),
+   hESDCombinatorialPt(NULL),
    hESDTruePrimaryConvGammaPt(NULL),
    hESDTruePrimaryConvGammaR(NULL),
    hESDTruePrimaryConvGammaEta(NULL),
    hESDTruePrimaryConvGammaESDPtMCPt(NULL),
+   hESDTruePrimaryConvGammaRSESDPtMCPt(NULL),
    hESDTrueSecondaryConvGammaPt(NULL),
-   hESDTrueSecondaryConvGammaFromK0sPt(NULL),
+   hESDTrueSecondaryConvGammaR(NULL),
    hESDTrueSecondaryConvGammaFromXFromK0sPt(NULL),
+   hESDPi0Alpha(NULL),
+   hESDBackAlpha(NULL),
+   hESDTruePi0Alpha(NULL),
    hNEvents(NULL),
    hNGoodESDTracks(NULL),
    hNV0Tracks(NULL),
    fRandom(0),
+   fnGoodGammas(0),
    fUnsmearedPx(NULL),
    fUnsmearedPy(NULL),
    fUnsmearedPz(NULL),
    fUnsmearedE(NULL),
+   fnCuts(0),
+   fiCut(0),
+   fNumberOfESDTracks(0),
+   fMoveParticleAccordingToVertex(kTRUE),
    fIsHeavyIon(kFALSE),
-   fDoMesonAnalysis(kTRUE)
-
+   fDoMesonAnalysis(kTRUE),
+   fIsFromBGEvent(kFALSE)
 {
    // default Constructor
    DefineInput(0, TChain::Class());
@@ -129,7 +145,8 @@ AliAnalysisTaskGammaConvV1::AliAnalysisTaskGammaConvV1(const char *name):
    AliAnalysisTaskSE(name),
    fV0Reader(NULL),
    fBGHandler(NULL),
-   fESDEvent(NULL),
+   fBGHandlerRP(NULL),
+   fInputEvent(NULL),
    fMCEvent(NULL),
    fMCStack(NULL),
    fCutFolder(NULL),
@@ -147,6 +164,7 @@ AliAnalysisTaskGammaConvV1::AliAnalysisTaskGammaConvV1(const char *name):
    fMesonCutArray(NULL),
    fMesonCuts(NULL),
    hESDConvGammaPt(NULL),
+   hESDConvGammaR(NULL),
    hESDMotherInvMassPt(NULL),
    sESDMotherInvMassPtZM(NULL),
    hESDMotherBackInvMassPt(NULL),
@@ -159,44 +177,58 @@ AliAnalysisTaskGammaConvV1::AliAnalysisTaskGammaConvV1(const char *name):
    hMCDecayGammaOmegaPt(NULL),
    hMCDecayGammaEtapPt(NULL),
    hMCDecayGammaPhiPt(NULL),
+   hMCDecayGammaSigmaPt(NULL),
    hMCConvGammaPt(NULL),
    hMCConvGammaR(NULL),
    hMCConvGammaEta(NULL),
+   hMCConvGammaRSPt(NULL),
+   hMCConvGammaRSR(NULL),
+   hMCConvGammaRSEta(NULL),
    hMCPi0Pt(NULL),
    hMCEtaPt(NULL),
    hMCPi0InAccPt(NULL),
    hMCEtaInAccPt(NULL),
    hESDTrueMotherInvMassPt(NULL),
+   hESDTruePi0FromEtaInvMassPt(NULL),
    hESDTruePrimaryMotherInvMassMCPt(NULL),
    hESDTruePrimaryPi0ESDPtMCPt(NULL),
    hESDTrueSecondaryMotherInvMassPt(NULL),
    hESDTrueSecondaryMotherFromK0sInvMassPt(NULL),
+   hESDTrueK0sWithPi0DaughterMCPt(NULL),
+   hESDTrueSecondaryMotherFromEtaInvMassPt(NULL),
+   hESDTrueEtaWithPi0DaughterMCPt(NULL),
    hESDTrueBckGGInvMassPt(NULL),
    hESDTrueBckContInvMassPt(NULL),
    hESDTrueMotherDalitzInvMassPt(NULL),
    hESDTrueConvGammaPt(NULL),
-   hESDTrueTwoElecCombPt(NULL),
-   hESDTrueTwoPionCombPt(NULL),
-   hESDTrueElecPionCombPt(NULL),
-   hESDTrueCombPt(NULL),
+   hESDCombinatorialPt(NULL),
    hESDTruePrimaryConvGammaPt(NULL),
    hESDTruePrimaryConvGammaR(NULL),
    hESDTruePrimaryConvGammaEta(NULL),
    hESDTruePrimaryConvGammaESDPtMCPt(NULL),
+   hESDTruePrimaryConvGammaRSESDPtMCPt(NULL),
    hESDTrueSecondaryConvGammaPt(NULL),
-   hESDTrueSecondaryConvGammaFromK0sPt(NULL),
+   hESDTrueSecondaryConvGammaR(NULL),
    hESDTrueSecondaryConvGammaFromXFromK0sPt(NULL),
+   hESDPi0Alpha(NULL),
+   hESDBackAlpha(NULL),
+   hESDTruePi0Alpha(NULL),
    hNEvents(NULL),
    hNGoodESDTracks(NULL),
    hNV0Tracks(NULL),
    fRandom(0),
+   fnGoodGammas(0),
    fUnsmearedPx(NULL),
    fUnsmearedPy(NULL),
    fUnsmearedPz(NULL),
    fUnsmearedE(NULL),
+   fnCuts(0),
+   fiCut(0),
+   fNumberOfESDTracks(0),
+   fMoveParticleAccordingToVertex(kTRUE),
    fIsHeavyIon(kFALSE),
-   fDoMesonAnalysis(kTRUE)
-
+   fDoMesonAnalysis(kTRUE),
+   fIsFromBGEvent(kFALSE)
 {
    // Define input and output slots here
    DefineInput(0, TChain::Class());
@@ -213,6 +245,10 @@ AliAnalysisTaskGammaConvV1::~AliAnalysisTaskGammaConvV1()
       delete[] fBGHandler;
       fBGHandler = 0x0;
    }
+   if(fBGHandlerRP){
+      delete[] fBGHandlerRP;
+      fBGHandlerRP = 0x0;
+   }
 }
 //___________________________________________________________
 void AliAnalysisTaskGammaConvV1::InitBack(){
@@ -259,42 +295,56 @@ void AliAnalysisTaskGammaConvV1::InitBack(){
    }
 
    const Int_t nDim = 4;
-   Int_t nBins[nDim] = {1000,250,8,5};
+   Int_t nBins[nDim] = {800,250,8,5};
    Double_t xMin[nDim] = {0,0, 0,0};
-   Double_t xMax[nDim] = {1,25,8,5};
+   Double_t xMax[nDim] = {0.8,25,8,5};
 
    sESDMotherInvMassPtZM = new THnSparseF*[fnCuts];
    sESDMotherBackInvMassPtZM = new THnSparseF*[fnCuts];
 
    fBGHandler = new AliGammaConversionAODBGHandler*[fnCuts];
+   fBGHandlerRP = new AliConversionAODBGHandlerRP*[fnCuts];
    for(Int_t iCut = 0; iCut<fnCuts;iCut++){
-      TString cutstring = ((AliConversionCuts*)fCutArray->At(iCut))->GetCutNumber();
-               TString cutstringMeson = ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetCutNumber();
-      fBackList[iCut] = new TList();
-      fBackList[iCut]->SetName(Form("%s_%s Back histograms",cutstring.Data(),cutstringMeson.Data()));
-      fBackList[iCut]->SetOwner(kTRUE);
-      fCutFolder[iCut]->Add(fBackList[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]);
-      
-      fMotherList[iCut] = new TList();
-      fMotherList[iCut]->SetName(Form("%s_%s Mother histograms",cutstring.Data(),cutstringMeson.Data()));
-      fMotherList[iCut]->SetOwner(kTRUE);
-      fCutFolder[iCut]->Add(fMotherList[iCut]);
-
-      sESDMotherInvMassPtZM[iCut] = new THnSparseF("Back_Mother_InvMass_Pt_z_m","Back_Mother_InvMass_Pt_z_m",nDim,nBins,xMin,xMax);
-      sESDMotherInvMassPtZM[iCut]->Sumw2();
-      fMotherList[iCut]->Add(sESDMotherInvMassPtZM[iCut]);
-
-      if(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->UseTrackMultiplicity()){
-         fBGHandler[iCut] = new AliGammaConversionAODBGHandler(9,6,((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->NumberOfBGEvents());
-         fBGHandler[iCut]->Initialize(zBinLimitsArray, multiplicityBinLimitsArrayTracks);
-      }
-      else{
-         fBGHandler[iCut] = new AliGammaConversionAODBGHandler(9,5,((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->NumberOfBGEvents());
-         fBGHandler[iCut]->Initialize(zBinLimitsArray, multiplicityBinLimitsArrayV0s);
+      if (((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->DoBGCalculation()){
+         TString cutstring = ((AliConversionCuts*)fCutArray->At(iCut))->GetCutNumber();
+         TString cutstringMeson = ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetCutNumber();
+         fBackList[iCut] = new TList();
+         fBackList[iCut]->SetName(Form("%s_%s Back histograms",cutstring.Data(),cutstringMeson.Data()));
+         fBackList[iCut]->SetOwner(kTRUE);
+         fCutFolder[iCut]->Add(fBackList[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]);
+
+         fMotherList[iCut] = new TList();
+         fMotherList[iCut]->SetName(Form("%s_%s Mother histograms",cutstring.Data(),cutstringMeson.Data()));
+         fMotherList[iCut]->SetOwner(kTRUE);
+         fCutFolder[iCut]->Add(fMotherList[iCut]);
+
+         sESDMotherInvMassPtZM[iCut] = new THnSparseF("Back_Mother_InvMass_Pt_z_m","Back_Mother_InvMass_Pt_z_m",nDim,nBins,xMin,xMax);
+         sESDMotherInvMassPtZM[iCut]->Sumw2();
+         fMotherList[iCut]->Add(sESDMotherInvMassPtZM[iCut]);
+
+         if(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->BackgroundHandlerType() == 0){
+            if(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->UseTrackMultiplicity()){
+               fBGHandler[iCut] = new AliGammaConversionAODBGHandler(9,6,((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetNumberOfBGEvents());
+               fBGHandler[iCut]->Initialize(zBinLimitsArray, multiplicityBinLimitsArrayTracks);
+               fBGHandlerRP[iCut] = NULL;
+            }
+            else{
+               fBGHandler[iCut] = new AliGammaConversionAODBGHandler(9,5,((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetNumberOfBGEvents());
+               fBGHandler[iCut]->Initialize(zBinLimitsArray, multiplicityBinLimitsArrayV0s);
+               fBGHandlerRP[iCut] = NULL;
+            }
+         }
+         else{
+            fBGHandlerRP[iCut] = new AliConversionAODBGHandlerRP(
+                                                                 ((AliConversionCuts*)fCutArray->At(fiCut))->IsHeavyIon(),
+                                                                 ((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity(),
+                                                                 ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetNumberOfBGEvents());
+            fBGHandler[iCut] = NULL;
+         }
       }
    }
 }
@@ -320,6 +370,7 @@ void AliAnalysisTaskGammaConvV1::UserCreateOutputObjects()
    fBackList = new TList*[fnCuts];
    fMotherList = new TList*[fnCuts];
    hESDConvGammaPt = new TH1F*[fnCuts];
+   hESDConvGammaR = new TH1F*[fnCuts];
    hNEvents = new TH1I*[fnCuts];
    hNGoodESDTracks = new TH1I*[fnCuts];
    hNV0Tracks = new TH1I*[fnCuts];
@@ -328,12 +379,15 @@ void AliAnalysisTaskGammaConvV1::UserCreateOutputObjects()
       hESDMotherInvMassPt = new TH2F*[fnCuts];
       hESDMotherBackInvMassPt = new TH2F*[fnCuts];
       hESDMotherInvMassEalpha = new TH2F*[fnCuts];
+
+      hESDPi0Alpha = new TH1F*[fnCuts];
+      hESDBackAlpha = new TH1F*[fnCuts];
    }
    for(Int_t iCut = 0; iCut<fnCuts;iCut++){
 
       TString cutstring = ((AliConversionCuts*)fCutArray->At(iCut))->GetCutNumber();
-               TString cutstringMeson = ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetCutNumber();
-               
+      TString cutstringMeson = ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetCutNumber();
+
       fCutFolder[iCut] = new TList();
       fCutFolder[iCut]->SetName(Form("Cut Number %s_%s",cutstring.Data(),cutstringMeson.Data()));
       fCutFolder[iCut]->SetOwner(kTRUE);
@@ -342,30 +396,45 @@ void AliAnalysisTaskGammaConvV1::UserCreateOutputObjects()
       fESDList[iCut]->SetName(Form("%s_%s ESD histograms",cutstring.Data(),cutstringMeson.Data()));
       fESDList[iCut]->SetOwner(kTRUE);
 
-      hNEvents[iCut] = new TH1I("NEvents","NEvents",7,-0.5,6.5);
+      hNEvents[iCut] = new TH1I("NEvents","NEvents",9,-0.5,8.5);
+      hNEvents[iCut]->GetXaxis()->SetBinLabel(1,"Accepted");
+      hNEvents[iCut]->GetXaxis()->SetBinLabel(2,"Centrality");
+      hNEvents[iCut]->GetXaxis()->SetBinLabel(3,"Missing MC");
+      hNEvents[iCut]->GetXaxis()->SetBinLabel(4,"Trigger");
+      hNEvents[iCut]->GetXaxis()->SetBinLabel(5,"Vertex Z");
+      hNEvents[iCut]->GetXaxis()->SetBinLabel(6,"Cont. Vertex");
+      hNEvents[iCut]->GetXaxis()->SetBinLabel(7,"Pile-Up");
+      hNEvents[iCut]->GetXaxis()->SetBinLabel(8,"no SDD");
+      hNEvents[iCut]->GetXaxis()->SetBinLabel(9,"no V0AND");
       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);
+      if(fIsHeavyIon) hNV0Tracks[iCut] = new TH1I("V0 Multiplicity","V0 Multiplicity",30000,0,30000);
       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]);
+      hESDConvGammaR[iCut] = new TH1F("ESD_ConvGamma_R","ESD_ConvGamma_R",800,0,200);
+      fESDList[iCut]->Add(hESDConvGammaR[iCut]);
 
       if(fDoMesonAnalysis){
-         hESDMotherInvMassPt[iCut] = new TH2F("ESD_Mother_InvMass_Pt","ESD_Mother_InvMass_Pt",1000,0,1,250,0,25);
+         hESDMotherInvMassPt[iCut] = new TH2F("ESD_Mother_InvMass_Pt","ESD_Mother_InvMass_Pt",800,0,0.8,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);
+         hESDMotherBackInvMassPt[iCut] = new TH2F("ESD_Background_InvMass_Pt","ESD_Background_InvMass_Pt",800,0,0.8,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);
+         hESDMotherInvMassEalpha[iCut] = new TH2F("ESD_Mother_InvMass_vs_E_alpha","ESD_Mother_InvMass_vs_E_alpha",800,0,0.8,250,0,25);
          fESDList[iCut]->Add(hESDMotherInvMassEalpha[iCut]);
+
+         hESDPi0Alpha[iCut] = new TH1F("ESD_Mother_Alpha_inPi0MassRange","ESD_Mother_Alpha_inPi0MassRange",100,0,1);
+         fESDList[iCut]->Add(hESDPi0Alpha[iCut]);
+         hESDBackAlpha[iCut] = new TH1F("ESD_Back_Alpha_inPi0MassRange","ESD_Back_Alpha_inPi0MassRange",100,0,1);
+         fESDList[iCut]->Add(hESDBackAlpha[iCut]);
       }
 
       fCutFolder[iCut]->Add(fESDList[iCut]);
    }
-
    if(fDoMesonAnalysis){
       InitBack(); // Init Background Handler
    }
@@ -385,20 +454,23 @@ void AliAnalysisTaskGammaConvV1::UserCreateOutputObjects()
       hMCDecayGammaOmegaPt = new TH1F*[fnCuts];
       hMCDecayGammaEtapPt = new TH1F*[fnCuts];
       hMCDecayGammaPhiPt = new TH1F*[fnCuts];
+      hMCDecayGammaSigmaPt = new TH1F*[fnCuts];
       hMCConvGammaPt = new TH1F*[fnCuts];
       hMCConvGammaR = new TH1F*[fnCuts];
       hMCConvGammaEta = new TH1F*[fnCuts];
+      hMCConvGammaRSPt = new TH1F*[fnCuts];
+      hMCConvGammaRSR = new TH1F*[fnCuts];
+      hMCConvGammaRSEta = new TH1F*[fnCuts];
       hESDTrueConvGammaPt = new TH1F*[fnCuts];
-      hESDTrueTwoElecCombPt = new TH1F*[fnCuts];
-      hESDTrueTwoPionCombPt = new TH1F*[fnCuts];
-      hESDTrueElecPionCombPt = new TH1F*[fnCuts];
-      hESDTrueCombPt = new TH1F*[fnCuts];
+
+      hESDCombinatorialPt = new TH2F*[fnCuts];
       hESDTruePrimaryConvGammaPt = new TH1F*[fnCuts];
       hESDTruePrimaryConvGammaR = new TH1F*[fnCuts];
       hESDTruePrimaryConvGammaEta = new TH1F*[fnCuts];
       hESDTruePrimaryConvGammaESDPtMCPt = new TH2F*[fnCuts];
+      hESDTruePrimaryConvGammaRSESDPtMCPt = new TH2F*[fnCuts];
       hESDTrueSecondaryConvGammaPt = new TH1F*[fnCuts];
-      hESDTrueSecondaryConvGammaFromK0sPt = new TH1F*[fnCuts];
+      hESDTrueSecondaryConvGammaR = new TH1F*[fnCuts];
       hESDTrueSecondaryConvGammaFromXFromK0sPt = new TH1F*[fnCuts];
 
       if(fDoMesonAnalysis){
@@ -407,11 +479,15 @@ void AliAnalysisTaskGammaConvV1::UserCreateOutputObjects()
          hMCPi0InAccPt = new TH1F*[fnCuts];
          hMCEtaInAccPt = new TH1F*[fnCuts];
 
+         hESDTruePi0Alpha = new TH1F*[fnCuts];
          hESDTrueMotherInvMassPt = new TH2F*[fnCuts];
          hESDTruePrimaryPi0ESDPtMCPt = new TH2F*[fnCuts];
          hESDTruePrimaryMotherInvMassMCPt = new TH2F*[fnCuts];
          hESDTrueSecondaryMotherInvMassPt = new TH2F*[fnCuts];
          hESDTrueSecondaryMotherFromK0sInvMassPt = new TH2F*[fnCuts];
+         hESDTrueK0sWithPi0DaughterMCPt = new TH1F*[fnCuts];
+         hESDTrueSecondaryMotherFromEtaInvMassPt = new TH2F*[fnCuts];
+         hESDTrueEtaWithPi0DaughterMCPt = new TH1F*[fnCuts];
          hESDTrueBckGGInvMassPt = new TH2F*[fnCuts];
          hESDTrueBckContInvMassPt = new TH2F*[fnCuts];
          hESDTrueMotherDalitzInvMassPt = new TH2F*[fnCuts];
@@ -419,9 +495,9 @@ void AliAnalysisTaskGammaConvV1::UserCreateOutputObjects()
 
       for(Int_t iCut = 0; iCut<fnCuts;iCut++){
          TString cutstring = ((AliConversionCuts*)fCutArray->At(iCut))->GetCutNumber();
-                       TString cutstringMeson = ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetCutNumber();
-         
-                       fMCList[iCut] = new TList();
+         TString cutstringMeson = ((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->GetCutNumber();
+
+         fMCList[iCut] = new TList();
          fMCList[iCut]->SetName(Form("%s_%s MC histograms",cutstring.Data(),cutstringMeson.Data()));
          fMCList[iCut]->SetOwner(kTRUE);
          fCutFolder[iCut]->Add(fMCList[iCut]);
@@ -440,12 +516,21 @@ void AliAnalysisTaskGammaConvV1::UserCreateOutputObjects()
          fMCList[iCut]->Add(hMCDecayGammaEtapPt[iCut]);
          hMCDecayGammaPhiPt[iCut] = new TH1F("MC_DecayGammaPhi_Pt","MC_DecayGammaPhi_Pt",250,0,25);
          fMCList[iCut]->Add(hMCDecayGammaPhiPt[iCut]);
+         hMCDecayGammaSigmaPt[iCut] = new TH1F("MC_DecayGammaSigma_Pt","MC_DecayGammaSigma_Pt",250,0,25);
+         fMCList[iCut]->Add(hMCDecayGammaSigmaPt[iCut]);
          hMCConvGammaPt[iCut] = new TH1F("MC_ConvGamma_Pt","MC_ConvGamma_Pt",250,0,25);
          fMCList[iCut]->Add(hMCConvGammaPt[iCut]);
-         hMCConvGammaR[iCut] = new TH1F("MC_ConvGamma_R","MC_ConvGamma_R",1000,0,250);
+         hMCConvGammaR[iCut] = new TH1F("MC_ConvGamma_R","MC_ConvGamma_R",800,0,200);
          fMCList[iCut]->Add(hMCConvGammaR[iCut]);
          hMCConvGammaEta[iCut] = new TH1F("MC_ConvGamma_Eta","MC_ConvGamma_Eta",100,-4,4);
          fMCList[iCut]->Add(hMCConvGammaEta[iCut]);
+         hMCConvGammaRSPt[iCut] = new TH1F("MC_ConvGamma_RS_Pt","MC_ConvGamma_RS_Pt",250,0,25);
+         fMCList[iCut]->Add(hMCConvGammaRSPt[iCut]);
+         hMCConvGammaRSR[iCut] = new TH1F("MC_ConvGamma_RS_R","MC_ConvGamma_RS_R",800,0,200);
+         fMCList[iCut]->Add(hMCConvGammaRSR[iCut]);
+         hMCConvGammaRSEta[iCut] = new TH1F("MC_ConvGamma_RS_Eta","MC_ConvGamma_RS_Eta",100,-4,4);
+         fMCList[iCut]->Add(hMCConvGammaRSEta[iCut]);
+
          if(fDoMesonAnalysis){
             hMCPi0Pt[iCut] = new TH1F("MC_Pi0_Pt","MC_Pi0_Pt",250,0,25);
             fMCList[iCut]->Add(hMCPi0Pt[iCut]);
@@ -463,58 +548,77 @@ void AliAnalysisTaskGammaConvV1::UserCreateOutputObjects()
 
          hESDTrueConvGammaPt[iCut] = new TH1F("ESD_TrueConvGamma_Pt","ESD_TrueConvGamma_Pt",250,0,25);
          fTrueList[iCut]->Add(hESDTrueConvGammaPt[iCut]);
-         hESDTrueTwoElecCombPt[iCut] = new TH1F("ESD_TrueTwoElecComb_Pt","ESD_TrueTwoElecComb_Pt",250,0,25);
-         fTrueList[iCut]->Add(hESDTrueTwoElecCombPt[iCut]);
-         hESDTrueTwoPionCombPt[iCut] = new TH1F("ESD_TrueTwoPionComb_Pt","ESD_TrueTwoPionComb_Pt",250,0,25);
-         fTrueList[iCut]->Add(hESDTrueTwoPionCombPt[iCut]);
-         hESDTrueElecPionCombPt[iCut] = new TH1F("ESD_TrueElecPionComb_Pt","ESD_TrueElecPionComb_Pt",250,0,25);
-         fTrueList[iCut]->Add(hESDTrueElecPionCombPt[iCut]);
-         hESDTrueCombPt[iCut] = new TH1F("ESD_TrueComb_Pt","ESD_TrueComb_Pt",250,0,25);
-         fTrueList[iCut]->Add(hESDTrueCombPt[iCut]);
+
+         hESDCombinatorialPt[iCut] = new TH2F("ESD_TrueCombinatorial_Pt","ESD_TrueCombinatorial_Pt",250,0,25,16,-0.5,15.5);
+         hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel( 1,"Elec+Elec");
+         hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel( 2,"Elec+Pion");
+         hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel( 3,"Elec+Kaon");
+         hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel( 4,"Elec+Proton");
+         hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel( 5,"Elec+Muon");
+         hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel( 6,"Pion+Pion");
+         hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel( 7,"Pion+Kaon");
+         hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel( 8,"Pion+Proton");
+         hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel( 9,"Pion+Muon");
+         hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel(10,"Kaon+Kaon");
+         hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel(11,"Kaon+Proton");
+         hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel(12,"Kaon+Muon");
+         hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel(13,"Proton+Proton");
+         hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel(14,"Proton+Muon");
+         hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel(15,"Muon+Muon");
+         hESDCombinatorialPt[iCut]->GetYaxis()->SetBinLabel(16,"Rest");
+         fTrueList[iCut]->Add(hESDCombinatorialPt[iCut]);
          hESDTruePrimaryConvGammaPt[iCut] = new TH1F("ESD_TruePrimaryConvGamma_Pt","ESD_TruePrimaryConvGamma_Pt",250,0,25);
          fTrueList[iCut]->Add(hESDTruePrimaryConvGammaPt[iCut]);
-         hESDTruePrimaryConvGammaR[iCut] = new TH1F("ESD_TruePrimaryConvGamma_R","ESD_TruePrimaryConvGamma_R",1000,0,250);
+         hESDTruePrimaryConvGammaR[iCut] = new TH1F("ESD_TruePrimaryConvGamma_R","ESD_TruePrimaryConvGamma_R",800,0,200);
          fTrueList[iCut]->Add(hESDTruePrimaryConvGammaR[iCut]);
          hESDTruePrimaryConvGammaEta[iCut] = new TH1F("ESD_TruePrimaryConvGamma_Eta","ESD_TruePrimaryConvGamma_Eta",100,-4,4);
          fTrueList[iCut]->Add(hESDTruePrimaryConvGammaEta[iCut]);
          hESDTrueSecondaryConvGammaPt[iCut] = new TH1F("ESD_TrueSecondaryConvGamma_Pt","ESD_TrueSecondaryConvGamma_Pt",250,0,25);
          fTrueList[iCut]->Add(hESDTrueSecondaryConvGammaPt[iCut]);
-         hESDTrueSecondaryConvGammaFromK0sPt[iCut] = new TH1F("ESD_TrueSecondaryConvGammaFromK0s_Pt","ESD_TrueSecondaryConvGammaFromK0s_Pt",250,0,25);
-         fTrueList[iCut]->Add(hESDTrueSecondaryConvGammaFromK0sPt[iCut]);
-         hESDTrueSecondaryConvGammaFromXFromK0sPt[iCut] = new TH1F("ESD_TrueSecondaryConvGammaFromXFromK0s_Pt", "ESD_TrueSecondaryConvGammaFromXFromK0s_Pt",250,0,25);
+         hESDTrueSecondaryConvGammaR[iCut] = new TH1F("ESD_TrueSecondaryConvGamma_R","ESD_TrueSecondaryConvGamma_R",800,0,200);
+         fTrueList[iCut]->Add(hESDTrueSecondaryConvGammaR[iCut]);
+         hESDTrueSecondaryConvGammaFromXFromK0sPt[iCut]
+            = new TH1F("ESD_TrueSecondaryConvGammaFromXFromK0s_Pt", "ESD_TrueSecondaryConvGammaFromXFromK0s_Pt",250,0,25);
          fTrueList[iCut]->Add(hESDTrueSecondaryConvGammaFromXFromK0sPt[iCut]);
          hESDTruePrimaryConvGammaESDPtMCPt[iCut] = new TH2F("ESD_TruePrimaryConvGammaESD_PtMCPt", "ESD_TruePrimaryConvGammaESD_PtMCPt",250,0,25,250,0,25);
          fTrueList[iCut]->Add(hESDTruePrimaryConvGammaESDPtMCPt[iCut]);
+         hESDTruePrimaryConvGammaRSESDPtMCPt[iCut]
+            = new TH2F("ESD_TruePrimaryConvGammaESD_RS_PtMCPt", "ESD_TruePrimaryConvGammaESD_RS_PtMCPt",250,0,25,250,0,25);
+         fTrueList[iCut]->Add(hESDTruePrimaryConvGammaRSESDPtMCPt[iCut]);
+
 
          if(fDoMesonAnalysis){
-            hESDTrueMotherInvMassPt[iCut] = new TH2F("ESD_TrueMother_InvMass_Pt","ESD_TrueMother_InvMass_Pt",1000,0,1,250,0,25);
+            hESDTrueMotherInvMassPt[iCut] = new TH2F("ESD_TrueMother_InvMass_Pt","ESD_TrueMother_InvMass_Pt",800,0,0.8,250,0,25);
             fTrueList[iCut]->Add(hESDTrueMotherInvMassPt[iCut]);
             hESDTruePrimaryPi0ESDPtMCPt[iCut] = new TH2F("ESD_TruePrimaryPi0_ESDPt_MCPt","ESD_TruePrimaryPi0_ESDPt_MCPt",250,0,25,250,0,25);
             fTrueList[iCut]->Add(hESDTruePrimaryPi0ESDPtMCPt[iCut]);
-            hESDTruePrimaryMotherInvMassMCPt[iCut] = new TH2F("ESD_TruePrimaryMother_InvMass_MCPt", "ESD_TruePrimaryMother_InvMass_MCPt", 1000,0,1,250,0,25);
+            hESDTruePrimaryMotherInvMassMCPt[iCut]
+               = new TH2F("ESD_TruePrimaryMother_InvMass_MCPt", "ESD_TruePrimaryMother_InvMass_MCPt", 800,0,0.8,250,0,25);
             fTrueList[iCut]->Add(hESDTruePrimaryMotherInvMassMCPt[iCut]);
-            hESDTrueSecondaryMotherInvMassPt[iCut] = new TH2F("ESD_TrueSecondaryMother_InvMass_Pt", "ESD_TrueSecondaryMother_InvMass_Pt", 1000,0,1,250,0,25);
+            hESDTrueSecondaryMotherInvMassPt[iCut]
+               = new TH2F("ESD_TrueSecondaryMother_InvMass_Pt", "ESD_TrueSecondaryMother_InvMass_Pt", 800,0,0.8,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);
+            hESDTrueSecondaryMotherFromK0sInvMassPt[iCut]
+               = new TH2F("ESD_TrueSecondaryMotherFromK0s_InvMass_Pt","ESD_TrueSecondaryMotherFromK0s_InvMass_Pt",800,0,0.8,250,0,25);
             fTrueList[iCut]->Add(hESDTrueSecondaryMotherFromK0sInvMassPt[iCut]);
-            hESDTrueBckGGInvMassPt[iCut] = new TH2F("ESD_TrueBckGG_InvMass_Pt","ESD_TrueBckGG_InvMass_Pt",1000,0,1,250,0,25);
+            hESDTrueK0sWithPi0DaughterMCPt[iCut] = new TH1F("ESD_TrueK0sWithPi0Daughter_MCPt","ESD_TrueK0sWithPi0Daughter_MCPt",250,0,25);
+            fTrueList[iCut]->Add(hESDTrueK0sWithPi0DaughterMCPt[iCut]);
+            hESDTrueSecondaryMotherFromEtaInvMassPt[iCut]
+               = new TH2F("ESD_TrueSecondaryMotherFromEta_InvMass_Pt","ESD_TrueSecondaryMotherFromEta_InvMass_Pt",800,0,0.8,250,0,25);
+            fTrueList[iCut]->Add(hESDTrueSecondaryMotherFromEtaInvMassPt[iCut]);
+            hESDTrueEtaWithPi0DaughterMCPt[iCut] = new TH1F("ESD_TrueEtaWithPi0Daughter_MCPt","ESD_TrueEtaWithPi0Daughter_MCPt",250,0,25);
+            fTrueList[iCut]->Add(hESDTrueEtaWithPi0DaughterMCPt[iCut]);
+            hESDTrueBckGGInvMassPt[iCut] = new TH2F("ESD_TrueBckGG_InvMass_Pt","ESD_TrueBckGG_InvMass_Pt",800,0,0.8,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);
+            hESDTrueBckContInvMassPt[iCut] = new TH2F("ESD_TrueBckCont_InvMass_Pt","ESD_TrueBckCont_InvMass_Pt",800,0,0.8,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);
+            hESDTrueMotherDalitzInvMassPt[iCut] = new TH2F("ESD_TrueDalitz_InvMass_Pt","ESD_TrueDalitz_InvMass_Pt",800,0,0.8,250,0,25);
             fTrueList[iCut]->Add(hESDTrueMotherDalitzInvMassPt[iCut]);
+            hESDTruePi0Alpha[iCut] = new TH1F("ESD_TruePi0_Alpha","ESD_TruePi0_Alpha",100,0,1);
+            fTrueList[iCut]->Add(hESDTruePi0Alpha[iCut]);
          }
-         
-         if(((AliConversionCuts*)fCutArray->At(iCut))->GetSignalRejection() == 2){
-            fHeaderNameList[iCut] = new TList();
-            TString HeaderNames = "Header";
-            for(Int_t i = 0;i<(((AliConversionCuts*)fCutArray->At(iCut))->GetAcceptedHeader())->GetEntries();i++){
-               HeaderNames = HeaderNames+"_"+ ((TObjString*)((TList*) ( (AliConversionCuts*)fCutArray->At(iCut)) ->GetAcceptedHeader())->At(i))->GetString();
-            }
-            fHeaderNameList[iCut]->SetName(HeaderNames);
-            fHeaderNameList[iCut]->SetOwner(kTRUE);
-            fCutFolder[iCut]->Add(fHeaderNameList[iCut]);
-         }
+
+
       }
    }
 
@@ -531,7 +635,7 @@ void AliAnalysisTaskGammaConvV1::UserExec(Option_t *)
    if(!fV0Reader){printf("Error: No V0 Reader");return;} // GetV0Reader
 
    Int_t eventQuality = ((AliConversionCuts*)fV0Reader->GetConversionCuts())->GetEventQuality();
-   if(eventQuality != 0){// Event Not Accepted
+   if(eventQuality == 2 || eventQuality == 3){// Event Not Accepted due to MC event missing or wrong trigger for V0ReaderV1
       for(Int_t iCut = 0; iCut<fnCuts; iCut++){
          hNEvents[iCut]->Fill(eventQuality);
       }
@@ -539,22 +643,40 @@ void AliAnalysisTaskGammaConvV1::UserExec(Option_t *)
    }
 
    fMCEvent = MCEvent();
-   fESDEvent = (AliESDEvent*) InputEvent();
+   if(fMCEvent){
+      fMCStack = fMCEvent->Stack();
+   }
+   fInputEvent = InputEvent();
+
    fReaderGammas = fV0Reader->GetReconstructedGammas(); // Gammas from default Cut
    CountESDTracks(); // Estimate Event Multiplicity
 
+   // ------------------- BeginEvent ----------------------------
+
    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
+
+      Int_t eventNotAccepted =
+         ((AliConversionCuts*)fCutArray->At(iCut))
+         ->IsEventAcceptedByConversionCut(fV0Reader->GetConversionCuts(),fInputEvent,fMCEvent,fIsHeavyIon);
+      if(eventNotAccepted){
+         // cout << "event rejected due to wrong trigger: " <<eventNotAccepted << endl;
+         hNEvents[iCut]->Fill(eventNotAccepted); // Check Centrality, PileUp, SDD and V0AND --> Not Accepted => eventQuality = 1
          continue;
       }
-      hNEvents[iCut]->Fill(eventQuality);
+
+      if(eventQuality != 0){// Event Not Accepted
+         //                    cout << "event rejected due to: " <<eventQuality << endl;
+         hNEvents[iCut]->Fill(eventQuality);
+         continue;
+      }
+      
+      hNEvents[iCut]->Fill(eventQuality); // Should be 0 here
 
       hNGoodESDTracks[iCut]->Fill(fNumberOfESDTracks);
-      hNV0Tracks[iCut]->Fill(fESDEvent->GetVZEROData()->GetMTotV0A()+fESDEvent->GetVZEROData()->GetMTotV0C());
+      hNV0Tracks[iCut]->Fill(fInputEvent->GetVZEROData()->GetMTotV0A()+fInputEvent->GetVZEROData()->GetMTotV0C());
+
       if(fMCEvent){ // Process MC Particle
-         fMCStack = fMCEvent->Stack();
          if(((AliConversionCuts*)fCutArray->At(iCut))->GetSignalRejection() != 0){
             ((AliConversionCuts*)fCutArray->At(iCut))->GetNotRejectedParticles(((AliConversionCuts*)fCutArray->At(iCut))->GetSignalRejection(),
                                                                                ((AliConversionCuts*)fCutArray->At(iCut))->GetAcceptedHeader(),
@@ -582,9 +704,16 @@ void AliAnalysisTaskGammaConvV1::UserExec(Option_t *)
          }
 
          CalculatePi0Candidates(); // Combine Gammas
-         CalculateBackground(); // Combinatorial Background
-         UpdateEventByEventData(); // Store Event for mixed Events
-
+         if(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->DoBGCalculation()){
+            if(((AliConversionMesonCuts*)fMesonCutArray->At(iCut))->BackgroundHandlerType() == 0){
+               CalculateBackground(); // Combinatorial Background
+               UpdateEventByEventData(); // Store Event for mixed Events
+            }
+            else{
+               CalculateBackgroundRP(); // Combinatorial Background
+               fBGHandlerRP[iCut]->AddEvent(fGoodGammas,fInputEvent); // Store Event for mixed Events
+            }
+         }
          if(((AliConversionMesonCuts*)fMesonCutArray->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
@@ -601,7 +730,7 @@ void AliAnalysisTaskGammaConvV1::UserExec(Option_t *)
       fGoodGammas->Clear(); // delete this cuts good gammas
 
    }
-   
+
    PostData(1, fOutputContainer);
 }
 //________________________________________________________________________
@@ -614,18 +743,27 @@ void AliAnalysisTaskGammaConvV1::ProcessPhotonCandidates()
    for(Int_t i = 0; i < fReaderGammas->GetEntriesFast(); i++){
       AliAODConversionPhoton* PhotonCandidate = (AliAODConversionPhoton*) fReaderGammas->At(i);
       if(!PhotonCandidate) continue;
-
+      fIsFromBGEvent = kFALSE;
       if(fMCEvent && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 0){
-         if(!((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCStack)) continue;
-         if(!((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCStack)) continue;
+         if(!((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCStack)){
+            if(((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 3) continue;
+            fIsFromBGEvent = kTRUE;
+         }
+         if(!((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCStack)){
+            if(((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 3) continue;
+            fIsFromBGEvent = kTRUE;
+         }
       }
 
-      if(!((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelected(PhotonCandidate,fESDEvent)) continue;
-
+      if(!((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelected(PhotonCandidate,fInputEvent)) 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());
+         !((AliConversionCuts*)fCutArray->At(fiCut))->UseToCloseV0sCut()){
+         fGoodGammas->Add(PhotonCandidate); // if no second loop is required add to events good gammas
+
+         if(!fIsFromBGEvent){
+            hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt());
+            hESDConvGammaR[fiCut]->Fill(PhotonCandidate->GetConversionRadius());
+         }
          if(fMCEvent){
             ProcessTruePhotonCandidates(PhotonCandidate);
          }
@@ -644,10 +782,22 @@ void AliAnalysisTaskGammaConvV1::ProcessPhotonCandidates()
       for(Int_t i = 0;i<GoodGammasStepOne->GetEntries();i++){
          AliAODConversionPhoton *PhotonCandidate= (AliAODConversionPhoton*) GoodGammasStepOne->At(i);
          if(!PhotonCandidate) continue;
+         fIsFromBGEvent = kFALSE;
+         if(fMCEvent && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 0){
+            if(!((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCStack)){
+               fIsFromBGEvent = kTRUE;
+            }
+            if(!((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCStack)){
+               fIsFromBGEvent = kTRUE;
+            }
+         }
          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(!fIsFromBGEvent){
+               hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt());
+               hESDConvGammaR[fiCut]->Fill(PhotonCandidate->GetConversionRadius());
+            }
             if(fMCEvent){
                ProcessTruePhotonCandidates(PhotonCandidate);
             }
@@ -659,9 +809,21 @@ void AliAnalysisTaskGammaConvV1::ProcessPhotonCandidates()
       for(Int_t i = 0;i<GoodGammasStepTwo->GetEntries();i++){
          AliAODConversionPhoton* PhotonCandidate = (AliAODConversionPhoton*) GoodGammasStepTwo->At(i);
          if(!PhotonCandidate) continue;
+         fIsFromBGEvent = kFALSE;
+         if(fMCEvent && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 0){
+            if(!((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelPositive(), fMCStack)){
+               fIsFromBGEvent = kTRUE;
+            }
+            if(!((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(PhotonCandidate->GetMCLabelNegative(), fMCStack)){
+               fIsFromBGEvent = kTRUE;
+            }
+         }
          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(!fIsFromBGEvent){
+            hESDConvGammaPt[fiCut]->Fill(PhotonCandidate->Pt());
+            hESDConvGammaR[fiCut]->Fill(PhotonCandidate->GetConversionRadius());
+         }
          if(fMCEvent){
             ProcessTruePhotonCandidates(PhotonCandidate);
          }
@@ -683,67 +845,117 @@ void AliAnalysisTaskGammaConvV1::ProcessTruePhotonCandidates(AliAODConversionPho
    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)
-         hESDTrueTwoElecCombPt[fiCut]->Fill(TruePhotonCandidate->Pt()); //Electron Combinatorial
-      else if(TMath::Abs(posDaughter->GetPdgCode())==211 && TMath::Abs(negDaughter->GetPdgCode())==211)
-         hESDTrueTwoPionCombPt[fiCut]->Fill(TruePhotonCandidate->Pt()); //At least on Pion Combinatorial
-      else if( (TMath::Abs(posDaughter->GetPdgCode())==11 && TMath::Abs(negDaughter->GetPdgCode())==211) ||
-               (TMath::Abs(posDaughter->GetPdgCode())==211 && TMath::Abs(negDaughter->GetPdgCode())==11) )
-         hESDTrueElecPionCombPt[fiCut]->Fill(TruePhotonCandidate->Pt()); //At least on Pion Combinatorial
-      else hESDTrueCombPt[fiCut]->Fill(TruePhotonCandidate->Pt()); //At least on Pion Combinatorial
+
+   Int_t pdgCode[2] = {abs(posDaughter->GetPdgCode()),abs(negDaughter->GetPdgCode())};
+
+   if(posDaughter->GetMother(0) != negDaughter->GetMother(0)){
+      // Combinatorial Bck = 0 ee, 1 ep,i 2 ek, 3 ep, 4 emu, 5 pipi, 6 pik, 7 pip, 8 pimu, 9 kk, 10 kp, 11 kmu, 12 pp, 13 pmu, 14 mumu, 15 Rest
+      if(pdgCode[0]==11   && pdgCode[1]==11){if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),0);}
+      else if( (pdgCode[0]==11   && pdgCode[1]==211) || (pdgCode[0]==211  && pdgCode[1]==11) )
+         {if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),1);}
+      else if( (pdgCode[0]==11   && pdgCode[1]==321) || (pdgCode[0]==321  && pdgCode[1]==11) )
+         {if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),2);}
+      else if( (pdgCode[0]==11   && pdgCode[1]==2212) || (pdgCode[0]==2212 && pdgCode[1]==11) )
+         {if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),3);}
+      else if( (pdgCode[0]==11   && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==11) )
+         {if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),4);}
+      else if(  pdgCode[0]==211  && pdgCode[1]==211 ){if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),5);}
+      else if( (pdgCode[0]==211  && pdgCode[1]==321) || (pdgCode[0]==321  && pdgCode[1]==211) )
+         {if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),6);}
+      else if( (pdgCode[0]==211  && pdgCode[1]==2212) || (pdgCode[0]==2212 && pdgCode[1]==211) )
+         {if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),7);}
+      else if( (pdgCode[0]==211  && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==211) )
+         {if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),8);}
+      else if(  pdgCode[0]==321  && pdgCode[1]==321 ){if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),9);}
+      else if( (pdgCode[0]==321  && pdgCode[1]==2212) || (pdgCode[0]==2212 && pdgCode[1]==321) )
+         {if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),10);}
+      else if( (pdgCode[0]==321  && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==321) )
+         {if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),11);}
+      else if(  pdgCode[0]==2212   && pdgCode[1]==2212  ){if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),12);}
+      else if( (pdgCode[0]==2212  && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==2212) )
+         {if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),13);}
+      else if(  pdgCode[0]==13   && pdgCode[1]==13  ){if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),14);}
+      else {if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),15);}
       return;
    }
    else if(posDaughter->GetMother(0) == -1){
-      if(TMath::Abs(posDaughter->GetPdgCode())==11 && TMath::Abs(negDaughter->GetPdgCode())==11)
-         hESDTrueTwoElecCombPt[fiCut]->Fill(TruePhotonCandidate->Pt()); //Electron Combinatorial
-      else if(TMath::Abs(posDaughter->GetPdgCode())==211 && TMath::Abs(negDaughter->GetPdgCode())==211)
-         hESDTrueTwoPionCombPt[fiCut]->Fill(TruePhotonCandidate->Pt()); //At least on Pion Combinatorial
-      else if( (TMath::Abs(posDaughter->GetPdgCode())==11 && TMath::Abs(negDaughter->GetPdgCode())==211) ||
-               (TMath::Abs(posDaughter->GetPdgCode())==211 && TMath::Abs(negDaughter->GetPdgCode())==11) )
-         hESDTrueElecPionCombPt[fiCut]->Fill(TruePhotonCandidate->Pt()); //At least on Pion Combinatorial
-      else hESDTrueCombPt[fiCut]->Fill(TruePhotonCandidate->Pt()); //At least on Pion Combinatorial
+      if(pdgCode[0]==11   && pdgCode[1]==11){if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),0);}
+      else if( (pdgCode[0]==11   && pdgCode[1]==211) || (pdgCode[0]==211  && pdgCode[1]==11) )
+         {if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),1);}
+      else if( (pdgCode[0]==11   && pdgCode[1]==321) || (pdgCode[0]==321  && pdgCode[1]==11) )
+         {if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),2);}
+      else if( (pdgCode[0]==11   && pdgCode[1]==2212) || (pdgCode[0]==2212 && pdgCode[1]==11) )
+         {if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),3);}
+      else if( (pdgCode[0]==11   && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==11) )
+         {if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),4);}
+      else if(  pdgCode[0]==211  && pdgCode[1]==211 ){if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),5);}
+      else if( (pdgCode[0]==211  && pdgCode[1]==321) || (pdgCode[0]==321  && pdgCode[1]==211) )
+         {if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),6);}
+      else if( (pdgCode[0]==211  && pdgCode[1]==2212) || (pdgCode[0]==2212 && pdgCode[1]==211) )
+         {if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),7);}
+      else if( (pdgCode[0]==211  && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==211) )
+         {if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),8);}
+      else if(  pdgCode[0]==321  && pdgCode[1]==321 ){if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),9);}
+      else if( (pdgCode[0]==321  && pdgCode[1]==2212) || (pdgCode[0]==2212 && pdgCode[1]==321) )
+         {if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),10);}
+      else if( (pdgCode[0]==321  && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==321) )
+         {if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),11);}
+      else if(  pdgCode[0]==2212   && pdgCode[1]==2212  ){if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),12);}
+      else if( (pdgCode[0]==2212  && pdgCode[1]==13) || (pdgCode[0]==13   && pdgCode[1]==2212) )
+         {if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),13);}
+      else if(  pdgCode[0]==13   && pdgCode[1]==13  ){if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),14);}
+      else {if(!fIsFromBGEvent)hESDCombinatorialPt[fiCut]->Fill(TruePhotonCandidate->Pt(),15);}
       return;
    }
-   if(TMath::Abs(posDaughter->GetPdgCode())!=11 || TMath::Abs(negDaughter->GetPdgCode())!=11) return; //One Particle is not electron
+
+   if(pdgCode[0]!=11 || pdgCode[1]!=11) return; //One Particle is not a 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());
+   if(!fIsFromBGEvent)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());
-      hESDTruePrimaryConvGammaR[fiCut]->Fill(TruePhotonCandidate->GetConversionRadius());
-      hESDTruePrimaryConvGammaEta[fiCut]->Fill(TruePhotonCandidate->Eta());
-      hESDTruePrimaryConvGammaESDPtMCPt[fiCut]->Fill(TruePhotonCandidate->Pt(),Photon->Pt());
+      if(!fIsFromBGEvent){
+         hESDTruePrimaryConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
+         hESDTruePrimaryConvGammaR[fiCut]->Fill(TruePhotonCandidate->GetConversionRadius());
+         hESDTruePrimaryConvGammaEta[fiCut]->Fill(TruePhotonCandidate->Eta());
+         hESDTruePrimaryConvGammaRSESDPtMCPt[fiCut]->Fill(TruePhotonCandidate->Pt(),Photon->Pt()); // Allways Filled
+      }
+      hESDTruePrimaryConvGammaESDPtMCPt[fiCut]->Fill(TruePhotonCandidate->Pt(),Photon->Pt()); // Allways Filled
+      // (Not Filled for i6, Extra Signal Gamma (parambox) are secondary)
    }
    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());
+      if(!fIsFromBGEvent){
+         hESDTrueSecondaryConvGammaPt[fiCut]->Fill(TruePhotonCandidate->Pt());
+         hESDTrueSecondaryConvGammaR[fiCut]->Fill(TruePhotonCandidate->GetConversionRadius());
+         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;
 
+      Bool_t mcIsFromBG = kFALSE;
       if(((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 0){
-         if(!((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack)) continue;
+         if(!((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(i, fMCStack)){
+            if(((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 3) continue;
+            mcIsFromBG = kTRUE;
+         }
       }
 
       if(((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelectedMC(particle,fMCStack,kFALSE)){
@@ -768,6 +980,9 @@ void AliAnalysisTaskGammaConvV1::ProcessMCParticles()
             case 333: // Phi
                hMCDecayGammaPhiPt[fiCut]->Fill(particle->Pt());
                break;
+            case 3212: // Sigma
+               hMCDecayGammaPhiPt[fiCut]->Fill(particle->Pt());
+               break;
             }
          }
       }
@@ -775,20 +990,25 @@ void AliAnalysisTaskGammaConvV1::ProcessMCParticles()
          hMCConvGammaPt[fiCut]->Fill(particle->Pt());
          hMCConvGammaR[fiCut]->Fill(((TParticle*)fMCStack->Particle(particle->GetFirstDaughter()))->R());
          hMCConvGammaEta[fiCut]->Fill(particle->Eta());
+         if(!mcIsFromBG){
+            hMCConvGammaRSPt[fiCut]->Fill(particle->Pt());
+            hMCConvGammaRSR[fiCut]->Fill(((TParticle*)fMCStack->Particle(particle->GetFirstDaughter()))->R());
+            hMCConvGammaRSEta[fiCut]->Fill(particle->Eta());
+         }
       } // Converted MC Gamma
       if(fDoMesonAnalysis){
-         if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelectedMC(particle,fMCStack,kFALSE)){
+         if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelectedMC(particle,fMCStack)){
+            TParticle* daughter0 = (TParticle*)fMCStack->Particle(particle->GetFirstDaughter());
+            TParticle* daughter1 = (TParticle*)fMCStack->Particle(particle->GetLastDaughter());
+
             if(particle->GetPdgCode() == 111)hMCPi0Pt[fiCut]->Fill(particle->Pt()); // All MC Pi0
-            if(particle->GetPdgCode() == 221)hMCEtaPt[fiCut]->Fill(particle->Pt()); // All MC Eta
+            else 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
-               }
+            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
+               else if(particle->GetPdgCode() == 221)hMCEtaInAccPt[fiCut]->Fill(particle->Pt()); // MC Eta with gamma in acc
             }
          }
       }
@@ -814,18 +1034,34 @@ void AliAnalysisTaskGammaConvV1::CalculatePi0Candidates(){
 
             if((((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(pi0cand,kTRUE))){
                hESDMotherInvMassPt[fiCut]->Fill(pi0cand->M(),pi0cand->Pt());
-               if(pi0cand->GetAlpha()<0.1){
+               if(pi0cand->M()>0.1 && pi0cand->M()<0.15)hESDPi0Alpha[fiCut]->Fill(pi0cand->GetAlpha());
+
+               if(pi0cand->GetAlpha()<0.1)
                   hESDMotherInvMassEalpha[fiCut]->Fill(pi0cand->M(),pi0cand->E());
+               
+               if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->DoBGCalculation()){
+                  Int_t zbin = 0;
+                  Int_t mbin = 0;
+                  
+                  if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->BackgroundHandlerType() == 0){
+                     zbin = fBGHandler[fiCut]->GetZBinIndex(fInputEvent->GetPrimaryVertex()->GetZ());
+                     if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
+                        mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fNumberOfESDTracks);
+                     } else {
+                        mbin = fBGHandler[fiCut]->GetMultiplicityBinIndex(fGoodGammas->GetEntries());
+                     }
+                  }
+                  else{
+                     zbin = fBGHandlerRP[fiCut]->GetZBinIndex(fInputEvent->GetPrimaryVertex()->GetZ());
+                     if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
+                        mbin = fBGHandlerRP[fiCut]->GetMultiplicityBinIndex(fNumberOfESDTracks);
+                     } else {
+                        mbin = fBGHandlerRP[fiCut]->GetMultiplicityBinIndex(fGoodGammas->GetEntries());
+                     }
+                  }
+                  Double_t sparesFill[4] = {pi0cand->M(),pi0cand->Pt(),(Double_t)zbin,(Double_t)mbin};
+                  sESDMotherInvMassPtZM[fiCut]->Fill(sparesFill,1);
                }
-               Int_t zbin= fBGHandler[fiCut]->GetZBinIndex(fESDEvent->GetPrimaryVertex()->GetZ());
-               Int_t mbin = 0;
-               if(((AliConversionMesonCuts*)fMesonCutArray->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);
                }
@@ -842,7 +1078,7 @@ void AliAnalysisTaskGammaConvV1::ProcessTrueMesonCandidates(AliAODConversionMoth
    // Process True Mesons
    AliStack *MCStack = fMCEvent->Stack();
 
-   if(TrueGammaCandidate0->GetV0Index()<fESDEvent->GetNumberOfV0s()){
+   if(TrueGammaCandidate0->GetV0Index()<fInputEvent->GetNumberOfV0s()){
       Bool_t isTruePi0 = kFALSE;
       Bool_t isTrueEta = kFALSE;
       Int_t gamma0MCLabel = TrueGammaCandidate0->GetMCParticleLabel(MCStack);
@@ -852,7 +1088,7 @@ void AliAnalysisTaskGammaConvV1::ProcessTrueMesonCandidates(AliAODConversionMoth
          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(abs(negativeMC->GetPdgCode())==11 && abs(positiveMC->GetPdgCode())==11){  // Electrons ...
             if(negativeMC->GetUniqueID() == 5 && positiveMC->GetUniqueID() ==5){ // ... From Conversion ...
                if(gammaMC0->GetPdgCode() == 22){ // ... with Gamma Mother
                   gamma0MotherLabel=gammaMC0->GetFirstMother();
@@ -866,7 +1102,7 @@ void AliAnalysisTaskGammaConvV1::ProcessTrueMesonCandidates(AliAODConversionMoth
             }
          }
       }
-      if(TrueGammaCandidate1->GetV0Index()<fESDEvent->GetNumberOfV0s()){
+      if(TrueGammaCandidate1->GetV0Index()<fInputEvent->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
@@ -874,7 +1110,7 @@ void AliAnalysisTaskGammaConvV1::ProcessTrueMesonCandidates(AliAODConversionMoth
             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(abs(negativeMC->GetPdgCode())==11 && abs(positiveMC->GetPdgCode())==11){  // Electrons ...
                if(negativeMC->GetUniqueID() == 5 && positiveMC->GetUniqueID() ==5){ // ... From Conversion ...
                   if(gammaMC1->GetPdgCode() == 22){ // ... with Gamma Mother
                      gamma1MotherLabel=gammaMC1->GetFirstMother();
@@ -896,24 +1132,33 @@ void AliAnalysisTaskGammaConvV1::ProcessTrueMesonCandidates(AliAODConversionMoth
                isTrueEta=kTRUE;
             }
          }
-         if(isTruePi0 || isTrueEta){ // True Pion or Eta
+         if(isTruePi0 || isTrueEta){// True Pion or Eta
             hESDTrueMotherInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
-            if(gamma0MotherLabel > MCStack->GetNprimary()){ // Secondary Meson
+            if(Pi0Candidate->M()>0.1 && Pi0Candidate->M()<0.15)hESDTruePi0Alpha[fiCut]->Fill(Pi0Candidate->GetAlpha());
+
+            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());
+                     hESDTrueK0sWithPi0DaughterMCPt[fiCut]
+                        ->Fill(MCStack->Particle(((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetMother(0))->Pt());
+                  }
+                  if(MCStack->Particle(((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetMother(0))->GetPdgCode()==221){
+                     hESDTrueSecondaryMotherFromEtaInvMassPt[fiCut]->Fill(Pi0Candidate->M(),Pi0Candidate->Pt());
+                     hESDTrueEtaWithPi0DaughterMCPt[fiCut]
+                        ->Fill(MCStack->Particle(((TParticle*)MCStack->Particle(gamma1MotherLabel))->GetMother(0))->Pt());
                   }
                }
             }
-            if(gamma0MotherLabel <= MCStack->GetNprimary()){ // Only primary pi0 for efficiency calculation
+            else{ // 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
+         else 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
@@ -931,7 +1176,7 @@ void AliAnalysisTaskGammaConvV1::ProcessTrueMesonCandidates(AliAODConversionMoth
 //________________________________________________________________________
 void AliAnalysisTaskGammaConvV1::CalculateBackground(){
 
-   Int_t zbin= fBGHandler[fiCut]->GetZBinIndex(fESDEvent->GetPrimaryVertex()->GetZ());
+   Int_t zbin= fBGHandler[fiCut]->GetZBinIndex(fInputEvent->GetPrimaryVertex()->GetZ());
    Int_t mbin = 0;
 
    if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
@@ -945,7 +1190,7 @@ void AliAnalysisTaskGammaConvV1::CalculateBackground(){
       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<((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->NumberOfBGEvents();nRandom++){
+            for(Int_t nRandom=0;nRandom<((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->GetNumberOfBGEvents();nRandom++){
                AliAODConversionPhoton currentEventGoodV02 = *(AliAODConversionPhoton*)(fGoodGammas->At(iCurrent2));
 
                if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->DoBGProbability()){
@@ -965,8 +1210,10 @@ void AliAnalysisTaskGammaConvV1::CalculateBackground(){
                AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&currentEventGoodV02);
                if((((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(backgroundCandidate,kFALSE))){
                   hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
-                  Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),zbin,mbin};
+                  Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
                   sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
+                  if(backgroundCandidate->M()>0.1 && backgroundCandidate->M()<0.15)
+                     hESDBackAlpha[fiCut]->Fill(backgroundCandidate->GetAlpha());
                }
                delete backgroundCandidate;
                backgroundCandidate = 0x0;
@@ -994,8 +1241,10 @@ void AliAnalysisTaskGammaConvV1::CalculateBackground(){
                   AliAODConversionMother *backgroundCandidate = new AliAODConversionMother(&currentEventGoodV0,&previousGoodV0);
                   if((((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(backgroundCandidate,kFALSE))){
                      hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
-                     Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),zbin,mbin};
+                     Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
                      sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
+                     if(backgroundCandidate->M()>0.1 && backgroundCandidate->M()<0.15)
+                        hESDBackAlpha[fiCut]->Fill(backgroundCandidate->GetAlpha());
                   }
                   delete backgroundCandidate;
                   backgroundCandidate = 0x0;
@@ -1024,8 +1273,10 @@ void AliAnalysisTaskGammaConvV1::CalculateBackground(){
 
                      if((((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(backgroundCandidate,kFALSE))){
                         hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate->M(),backgroundCandidate->Pt());
-                        Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),zbin,mbin};
+                        Double_t sparesFill[4] = {backgroundCandidate->M(),backgroundCandidate->Pt(),(Double_t)zbin,(Double_t)mbin};
                         sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,1);
+                        if(backgroundCandidate->M()>0.1 && backgroundCandidate->M()<0.15)
+                           hESDBackAlpha[fiCut]->Fill(backgroundCandidate->GetAlpha());
                      }
                      delete backgroundCandidate;
                      backgroundCandidate = 0x0;
@@ -1036,7 +1287,86 @@ void AliAnalysisTaskGammaConvV1::CalculateBackground(){
       }
    }
 }
+//________________________________________________________________________
+void AliAnalysisTaskGammaConvV1::CalculateBackgroundRP(){
+
+   Int_t zbin= fBGHandlerRP[fiCut]->GetZBinIndex(fInputEvent->GetPrimaryVertex()->GetZ());
+   Int_t mbin = 0;
+   if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
+      mbin = fBGHandlerRP[fiCut]->GetMultiplicityBinIndex(fNumberOfESDTracks);
+   } else {
+      mbin = fBGHandlerRP[fiCut]->GetMultiplicityBinIndex(fGoodGammas->GetEntries());
+   }
+
+
+   //Rotation Method
+   if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseRotationMethod()){
+      // Correct for the number of rotations
+      // BG is for rotation the same, except for factor NRotations
+      Double_t weight=1./Double_t(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->GetNumberOfBGEvents());
+
+      for(Int_t firstGammaIndex=0;firstGammaIndex<fGoodGammas->GetEntries();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));
+            if(!((AliConversionCuts*)fCutArray->At(fiCut))->PhotonIsSelected(gamma1,fInputEvent))continue;
+            for(Int_t nRandom=0;nRandom<((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->GetNumberOfBGEvents();nRandom++){
+
+               RotateParticle(gamma1);
+
+               AliAODConversionMother backgroundCandidate(gamma0,gamma1);
+
+               if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(&backgroundCandidate,kFALSE)){
+                  hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate.M(),backgroundCandidate.Pt());
+                  Double_t sparesFill[4] = {backgroundCandidate.M(),backgroundCandidate.Pt(),(Double_t)zbin,(Double_t)mbin};
+                  sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,weight);
+                  if(backgroundCandidate.M()>0.1 && backgroundCandidate.M()<0.15)
+                     hESDBackAlpha[fiCut]->Fill(backgroundCandidate.GetAlpha());
+               }
+            }
+         }
+      }
+   }
+   else{
+      // Do Event Mixing
+      for(Int_t nEventsInBG=0;nEventsInBG <fBGHandlerRP[fiCut]->GetNBGEvents(fGoodGammas,fInputEvent);nEventsInBG++){
+
+         AliGammaConversionPhotonVector *previousEventGammas = fBGHandlerRP[fiCut]->GetBGGoodGammas(fGoodGammas,fInputEvent,nEventsInBG);
+
+         if(previousEventGammas){
+            // test weighted background
+            Double_t weight=1.0;
+            // Correct for the number of eventmixing:
+            // N gammas -> (N-1) + (N-2) +(N-3) ...+ (N-(N-1))  using sum formula sum(i)=N*(N-1)/2  -> N*(N-1)/2
+            // real combinations (since you cannot combine a photon with its own)
+            // but BG leads to N_{a}*N_{b} combinations
+            weight*=0.5*(Double_t(fGoodGammas->GetEntries()-1))/Double_t(previousEventGammas->size());
+
+            for(Int_t iCurrent=0;iCurrent<fGoodGammas->GetEntries();iCurrent++){
+
+               AliAODConversionPhoton *gamma0 = (AliAODConversionPhoton*)(fGoodGammas->At(iCurrent));
+
+               for(UInt_t iPrevious=0;iPrevious<previousEventGammas->size();iPrevious++){
 
+                  AliAODConversionPhoton *gamma1 = (AliAODConversionPhoton*)(previousEventGammas->at(iPrevious));
+
+                  AliAODConversionMother backgroundCandidate(gamma0,gamma1);
+
+                  if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->MesonIsSelected(&backgroundCandidate,kFALSE)){
+                     hESDMotherBackInvMassPt[fiCut]->Fill(backgroundCandidate.M(),backgroundCandidate.Pt());
+                     Double_t sparesFill[4] = {backgroundCandidate.M(),backgroundCandidate.Pt(),(Double_t)zbin,(Double_t)mbin};
+                     sESDMotherBackInvMassPtZM[fiCut]->Fill(sparesFill,weight);
+                     if(backgroundCandidate.M()>0.1 && backgroundCandidate.M()<0.15)
+                        hESDBackAlpha[fiCut]->Fill(backgroundCandidate.GetAlpha());
+                  }
+               }
+            }
+         }
+      }
+   }
+}
 //________________________________________________________________________
 void AliAnalysisTaskGammaConvV1::RotateParticle(AliAODConversionPhoton *gamma){
    Int_t fNDegreesPMBackground= ((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->NDegreesRotation();
@@ -1048,9 +1378,9 @@ void AliAnalysisTaskGammaConvV1::RotateParticle(AliAODConversionPhoton *gamma){
 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 dx = vertex->fX - fInputEvent->GetPrimaryVertex()->GetX();
+   Double_t dy = vertex->fY - fInputEvent->GetPrimaryVertex()->GetY();
+   Double_t dz = vertex->fZ - fInputEvent->GetPrimaryVertex()->GetZ();
 
    Double_t movedPlace[3] = {particle->GetConversionX() - dx,particle->GetConversionY() - dy,particle->GetConversionZ() - dz};
    particle->SetConversionPoint(movedPlace);
@@ -1060,10 +1390,10 @@ void AliAnalysisTaskGammaConvV1::UpdateEventByEventData(){
    //see header file for documentation
    if(fGoodGammas->GetEntries() >0 ){
       if(((AliConversionMesonCuts*)fMesonCutArray->At(fiCut))->UseTrackMultiplicity()){
-         fBGHandler[fiCut]->AddEvent(fGoodGammas,fESDEvent->GetPrimaryVertex()->GetX(),fESDEvent->GetPrimaryVertex()->GetY(),fESDEvent->GetPrimaryVertex()->GetZ(),fNumberOfESDTracks);
+         fBGHandler[fiCut]->AddEvent(fGoodGammas,fInputEvent->GetPrimaryVertex()->GetX(),fInputEvent->GetPrimaryVertex()->GetY(),fInputEvent->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());
+         fBGHandler[fiCut]->AddEvent(fGoodGammas,fInputEvent->GetPrimaryVertex()->GetX(),fInputEvent->GetPrimaryVertex()->GetY(),fInputEvent->GetPrimaryVertex()->GetZ(),fGoodGammas->GetEntries());
       }
    }
 }
@@ -1080,9 +1410,13 @@ void AliAnalysisTaskGammaConvV1::CountESDTracks(){
    EsdTrackCuts->SetPtRange(0.15);
 
    fNumberOfESDTracks = 0;
-   for(Int_t iTracks = 0; iTracks < fESDEvent->GetNumberOfTracks(); iTracks++){
-      AliESDtrack* curTrack = fESDEvent->GetTrack(iTracks);
+
+   for(Int_t iTracks = 0; iTracks < fInputEvent->GetNumberOfTracks(); iTracks++){
+      AliESDtrack* curTrack = (AliESDtrack*) fInputEvent->GetTrack(iTracks);
       if(!curTrack) continue;
+      // if(fMCEvent && ((AliConversionCuts*)fCutArray->At(fiCut))->GetSignalRejection() != 0){
+      //    if(!((AliConversionCuts*)fCutArray->At(fiCut))->IsParticleFromBGEvent(abs(curTrack->GetLabel()), fMCStack)) continue;
+      // }
       if(EsdTrackCuts->AcceptTrack(curTrack) ) fNumberOfESDTracks++;
    }
    delete EsdTrackCuts;
@@ -1093,9 +1427,30 @@ void AliAnalysisTaskGammaConvV1::CountESDTracks(){
 //________________________________________________________________________
 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))->GetSignalRejection() == 2 && fMCEvent){
+         fHeaderNameList[iCut] = new TList();
+         TString HeaderNames = "Header:";
+         for(Int_t i = 0;i<(((AliConversionCuts*)fCutArray->At(iCut))->GetAcceptedHeader())->GetEntries();i++){
+            HeaderNames = HeaderNames+"_"+ ((TObjString*)((TList*) ( (AliConversionCuts*)fCutArray->At(iCut))
+                                                          ->GetAcceptedHeader())->At(i))->GetString();
+         }
+         fHeaderNameList[iCut]->SetName(HeaderNames);
+         fHeaderNameList[iCut]->SetOwner(kTRUE);
+         fCutFolder[iCut]->Add(fHeaderNameList[iCut]);
+      }
+      else if(((AliConversionCuts*)fCutArray->At(iCut))->GetSignalRejection() == 0 &&
+              (((AliConversionCuts*)fCutArray->At(iCut))->GetFoundHeader()) && fMCEvent){
+         fHeaderNameList[iCut] = new TList();
+         TString HeaderNames = (((AliConversionCuts*)fCutArray->At(iCut))->GetFoundHeader())[0];
+         fHeaderNameList[iCut]->SetName(HeaderNames);
+         fHeaderNameList[iCut]->SetOwner(kTRUE);
+         fCutFolder[iCut]->Add(fHeaderNameList[iCut]);
+      }
+
       if(((AliConversionCuts*)fCutArray->At(iCut))->GetCutHistograms()){
          fCutFolder[iCut]->Add(((AliConversionCuts*)fCutArray->At(iCut))->GetCutHistograms());
       }
index a4af0c5..80983f3 100644 (file)
@@ -6,9 +6,10 @@
 #include "AliV0ReaderV1.h"
 #include "AliKFConversionPhoton.h"
 #include "AliGammaConversionAODBGHandler.h"
+#include "AliConversionAODBGHandlerRP.h"
 #include "AliConversionMesonCuts.h"
 #include "TH3.h"
-
+#include "TH3F.h"
 
 class AliAnalysisTaskGammaConvV1 : public AliAnalysisTaskSE {
  public:
@@ -27,6 +28,7 @@ class AliAnalysisTaskGammaConvV1 : public AliAnalysisTaskSE {
    void ProcessPhotonCandidates();
    void CalculatePi0Candidates();
    void CalculateBackground();
+   void CalculateBackgroundRP();
    void ProcessMCParticles();
    void ProcessTruePhotonCandidates( AliAODConversionPhoton* TruePhotonCandidate);
    void ProcessTrueMesonCandidates( AliAODConversionMother *Pi0Candidate, AliAODConversionPhoton *TrueGammaCandidate0, AliAODConversionPhoton *TrueGammaCandidate1);
@@ -49,7 +51,8 @@ class AliAnalysisTaskGammaConvV1 : public AliAnalysisTaskSE {
  protected:
    AliV0ReaderV1 *fV0Reader;
    AliGammaConversionAODBGHandler **fBGHandler;
-   AliESDEvent *fESDEvent;
+   AliConversionAODBGHandlerRP    **fBGHandlerRP;
+   AliVEvent *fInputEvent;
    AliMCEvent *fMCEvent;
    AliStack *fMCStack;
    TList **fCutFolder;
@@ -64,9 +67,10 @@ class AliAnalysisTaskGammaConvV1 : public AliAnalysisTaskSE {
    TList *fGoodGammas;
    TList *fCutArray;
    AliConversionCuts *fConversionCuts;
-       TList *fMesonCutArray;
-       AliConversionMesonCuts *fMesonCuts;
+   TList *fMesonCutArray;
+   AliConversionMesonCuts *fMesonCuts;
    TH1F **hESDConvGammaPt;
+   TH1F **hESDConvGammaR;
    TH2F **hESDMotherInvMassPt;
    THnSparseF **sESDMotherInvMassPtZM;
    TH2F **hESDMotherBackInvMassPt;
@@ -79,49 +83,59 @@ class AliAnalysisTaskGammaConvV1 : public AliAnalysisTaskSE {
    TH1F **hMCDecayGammaOmegaPt;
    TH1F **hMCDecayGammaEtapPt;
    TH1F **hMCDecayGammaPhiPt;
+   TH1F **hMCDecayGammaSigmaPt;
    TH1F **hMCConvGammaPt;
    TH1F **hMCConvGammaR;
    TH1F **hMCConvGammaEta;
+   TH1F **hMCConvGammaRSPt;
+   TH1F **hMCConvGammaRSR;
+   TH1F **hMCConvGammaRSEta;
    TH1F **hMCPi0Pt;
    TH1F **hMCEtaPt;
    TH1F **hMCPi0InAccPt;
    TH1F **hMCEtaInAccPt;
    TH2F **hESDTrueMotherInvMassPt;
+   TH2F **hESDTruePi0FromEtaInvMassPt;
    TH2F **hESDTruePrimaryMotherInvMassMCPt;
    TH2F **hESDTruePrimaryPi0ESDPtMCPt;
    TH2F **hESDTrueSecondaryMotherInvMassPt;
    TH2F **hESDTrueSecondaryMotherFromK0sInvMassPt;
+   TH1F **hESDTrueK0sWithPi0DaughterMCPt;
+   TH2F **hESDTrueSecondaryMotherFromEtaInvMassPt;
+   TH1F **hESDTrueEtaWithPi0DaughterMCPt;
    TH2F **hESDTrueBckGGInvMassPt;
    TH2F **hESDTrueBckContInvMassPt;
    TH2F **hESDTrueMotherDalitzInvMassPt;
    TH1F **hESDTrueConvGammaPt;
-   TH1F **hESDTrueTwoElecCombPt;
-   TH1F **hESDTrueTwoPionCombPt;
-   TH1F **hESDTrueElecPionCombPt;
-   TH1F **hESDTrueCombPt;
+   TH2F **hESDCombinatorialPt;
    TH1F **hESDTruePrimaryConvGammaPt;
    TH1F **hESDTruePrimaryConvGammaR;
    TH1F **hESDTruePrimaryConvGammaEta;
    TH2F **hESDTruePrimaryConvGammaESDPtMCPt;
+   TH2F **hESDTruePrimaryConvGammaRSESDPtMCPt;
    TH1F **hESDTrueSecondaryConvGammaPt;
-   TH1F **hESDTrueSecondaryConvGammaFromK0sPt;
+   TH1F **hESDTrueSecondaryConvGammaR;
    TH1F **hESDTrueSecondaryConvGammaFromXFromK0sPt;
+   TH1F **hESDPi0Alpha;
+   TH1F **hESDBackAlpha;
+   TH1F **hESDTruePi0Alpha;
    TH1I **hNEvents;
    TH1I **hNGoodESDTracks;
    TH1I **hNV0Tracks;
 
    TRandom3 fRandom;
-   Double_t *fUnsmearedPx;
-   Double_t *fUnsmearedPy;
-   Double_t *fUnsmearedPz;
-   Double_t *fUnsmearedE;
+   Int_t fnGoodGammas;
+   Double_t *fUnsmearedPx; //[fnGoodGammas]
+   Double_t *fUnsmearedPy; //[fnGoodGammas]
+   Double_t *fUnsmearedPz; //[fnGoodGammas]
+   Double_t *fUnsmearedE;  //[fnGoodGammas]
    Int_t fnCuts;
    Int_t fiCut;
    Int_t fNumberOfESDTracks;
-   Int_t fNumberOfHijingPythiaParticles;
    Bool_t fMoveParticleAccordingToVertex;
    Bool_t fIsHeavyIon;
    Bool_t fDoMesonAnalysis;
+   Bool_t fIsFromBGEvent;
 
    ClassDef(AliAnalysisTaskGammaConvV1, 2);
 };
index 81412fb..29adf76 100644 (file)
@@ -656,18 +656,18 @@ Bool_t AliAnalysisTaskGammaConversion::DoEventSelection() {
                for(Int_t iC = 0; iC < 32; ++iC) {
                        if (fV0Reader->GetESDEvent()->GetVZEROData()->BBTriggerV0C(iC)) hitsC++;
                }
-    if (fSelectV0AND==2 ){
-                       if (hitsA<2 || hitsC<2) {
-                               eventQuality=5;
-                               fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
-                               if(fDoMCTruth){
-                                       if(!fV0Reader->GetIsHeavyIon()){
-                                               CheckMesonProcessTypeEventQuality(eventQuality);
-                                       }
-                               }
-
-                               return kFALSE;
-                       }
+                if (fSelectV0AND==2 ){
+                   if (hitsA<2 || hitsC<2) {
+                      eventQuality=5;
+                      fHistograms->FillHistogram("ESD_EventQuality",eventQuality);
+                      if(fDoMCTruth){
+                         if(!fV0Reader->GetIsHeavyIon()){
+                            CheckMesonProcessTypeEventQuality(eventQuality);
+                         }
+                      }
+                      
+                      return kFALSE;
+                   }
                }
                if (fSelectV0AND==3 ){
                        if (hitsA>=2 && hitsC>=2) {
index 6032504..deba93d 100644 (file)
@@ -92,12 +92,16 @@ void AliAnalysisTaskMaterial::UserExec(Option_t *){
    fV0Reader=(AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask("V0ReaderV1");
 
    Int_t eventQuality = ((AliConversionCuts*)fV0Reader->GetConversionCuts())->GetEventQuality();
-   if(eventQuality != 0){// Event Not Accepted
+       if(eventQuality != 0){// Event Not Accepted
       return;
    }
    fESDEvent = (AliESDEvent*) InputEvent();
    if(fIsHeavyIon && !fConversionCuts->IsCentralitySelected(fESDEvent)) return;
-       Int_t nESDtracks = CountESDTracks(); // Estimate Event Multiplicity
+       Int_t nESDtracksEta09 = CountESDTracks09(); // Estimate Event Multiplicity
+       Int_t nESDtracksEta0914 = CountESDTracks0914(); // Estimate Event Multiplicity
+       //      Int_t nESDtracksEta14 = CountESDTracks14(); // Estimate Event Multiplicity
+       Int_t nESDtracksEta14; // Estimate Event Multiplicity
+  nESDtracksEta14= nESDtracksEta09 + nESDtracksEta0914;
        Int_t nContrVtx;
        if(fESDEvent){
                if(fESDEvent->GetPrimaryVertexTracks()->GetNContributors()>0) {
@@ -111,13 +115,15 @@ void AliAnalysisTaskMaterial::UserExec(Option_t *){
                        }
                }
    }
-       Int_t primVtxZ = fESDEvent->GetPrimaryVertex()->GetZ();
+       Float_t primVtxZ = fESDEvent->GetPrimaryVertex()->GetZ();
        
        if (fStreamMaterial){
                (*fStreamMaterial)<<"Event"
                                                << "primVtxZ=" << primVtxZ
                                                << "nContrVtx=" << nContrVtx
-                                               << "nGoodTracks=" << nESDtracks
+                                               << "nGoodTracksEta09=" << nESDtracksEta09
+                                               << "nGoodTracksEta0914=" << nESDtracksEta0914
+                                               << "nGoodTracksEta14=" << nESDtracksEta14
                                                << "\n";
        }
        
@@ -132,6 +138,55 @@ void AliAnalysisTaskMaterial::UserExec(Option_t *){
    PostData(1, fOutputList);
 }
 
+///________________________________________________________________________
+void AliAnalysisTaskMaterial::FillMCTree(Int_t stackPos){
+       AliStack *MCStack = fMCEvent->Stack();
+       TParticle* candidate = (TParticle *)MCStack->Particle(stackPos);
+       if(fConversionCuts->PhotonIsSelectedMC(candidate,MCStack,kFALSE)){
+               Float_t gammaPt = candidate->Pt();
+               Float_t gammaTheta = candidate->Theta();
+               if (fStreamMaterial){
+                       (*fStreamMaterial)<<"AllGamma"
+                                                       << "pt=" << gammaPt
+//                                                     << "p=" << gammaP
+                                                       << "theta=" << gammaTheta
+                                                       << "\n";
+               }       
+       }
+       if(fConversionCuts->PhotonIsSelectedMC(candidate,MCStack,kTRUE)){
+               Float_t gammaPt = candidate->Pt();
+               Float_t gammaTheta = candidate->Theta();
+               TParticle* daughter1 = (TParticle *)MCStack->Particle(candidate->GetFirstDaughter()); 
+               TParticle* daughter2 = (TParticle *)MCStack->Particle(candidate->GetLastDaughter()); 
+               TVectorF coord(5);      
+               coord(0) = daughter1->Vx();
+               coord(1) = daughter1->Vy();
+               coord(2) = daughter1->Vz();
+               coord(3) = daughter1->R();
+               coord(4) = candidate->Phi();
+               TVectorF daughterProp(4);       
+               if (daughter1-> GetPdgCode() < 0){
+                       daughterProp(0) = daughter2->Pt();
+                       daughterProp(1) = daughter2->Theta();
+                       daughterProp(2) = daughter1->Pt();
+                       daughterProp(3) = daughter1->Theta();
+               } else {
+                       daughterProp(0) = daughter1->Pt();
+                       daughterProp(1) = daughter1->Theta();
+                       daughterProp(2) = daughter2->Pt();
+                       daughterProp(3) = daughter2->Theta();
+               }
+               if (fStreamMaterial){
+                       (*fStreamMaterial)<<"ConvGammaMC"
+                                                       << "pt=" << gammaPt
+//                                                     << "p=" << gammaP
+                                                       << "theta=" << gammaTheta
+                                                       << "coord.=" << &coord
+                                                       << "daughterProp.=" << &daughterProp
+                                                       << "\n";
+               }
+       } // Converted MC Gamma         
+}
 
 ///________________________________________________________________________
 void AliAnalysisTaskMaterial::ProcessMCPhotons(){
@@ -140,42 +195,14 @@ void AliAnalysisTaskMaterial::ProcessMCPhotons(){
        for(Int_t i = 0; i < ffMCStack->GetNprimary(); i++) {
                TParticle* particle = (TParticle *)ffMCStack->Particle(i);
                if (!particle) continue;                
-               if(fConversionCuts->PhotonIsSelectedMC(particle,ffMCStack,kFALSE)){
-                       Float_t gammaPt = particle->Pt();
-                       Float_t gammaP = particle->P();
-                       Float_t gammaEta = particle->Eta();
-                       if (fStreamMaterial){
-                               (*fStreamMaterial)<<"AllGamma"
-                                                               << "pt=" << gammaPt
-                                                               << "p=" << gammaP
-                                                               << "eta=" << gammaEta
-                                                               << "\n";
-                       }       
-               }
-               if(fConversionCuts->PhotonIsSelectedMC(particle,ffMCStack,kTRUE)){
-                       Float_t gammaPt = particle->Pt();
-                       Float_t gammaP = particle->P();
-                       Float_t gammaEta = particle->Eta();
-                       TParticle* daughter = (TParticle *)ffMCStack->Particle(particle->GetFirstDaughter());
-                       Float_t gammaX = daughter->Vx();
-                       Float_t gammaY =  daughter->Vy();
-                       Float_t gammaZ = daughter->Vz();
-                       Float_t gammaR = daughter->R();
-                       Float_t gammaPhi = particle->Phi();
-                       
-                       if (fStreamMaterial){
-                               (*fStreamMaterial)<<"ConvGammaMC"
-                                                               << "pt=" << gammaPt
-                                                               << "p=" << gammaP
-                                                               << "eta=" << gammaEta
-                                                               << "X=" << gammaX
-                                                               << "Y=" << gammaY
-                                                               << "Z=" << gammaZ
-                                                               << "R=" << gammaR
-                                                               << "Phi=" << gammaPhi
-                                                               << "\n";
+               if (particle->GetPdgCode() == 111 && particle->GetFirstDaughter() >= ffMCStack->GetNprimary()){
+//                     cout << "Undecayed pi0 found with mother: " << particle->GetMother(0) << endl;
+                       for (Int_t j = 0; j < 2 ; j++){
+                               FillMCTree(particle->GetDaughter(j));
                        }
-               } // Converted MC Gamma
+               } else {
+                       FillMCTree(i);
+               }       
        }       
 }
 
@@ -188,14 +215,30 @@ void AliAnalysisTaskMaterial::ProcessPhotons(){
       if(!fConversionCuts->PhotonIsSelected(gamma,fESDEvent)) continue;
 //             cout << "i=  " <<firstGammaIndex << " of "<< fConversionGammas->GetEntriesFast() << endl;
       Float_t gammaPt = gamma->GetPhotonPt();
-               Float_t gammaP = gamma->GetPhotonP();
+//             Float_t gammaP = gamma->GetPhotonP();
+               Float_t gammaTheta = gamma->GetPhotonTheta();
                Float_t gammaEta = gamma->GetPhotonEta();
                Float_t gammaChi2NDF = gamma->GetChi2perNDF();
-               Float_t gammaX = gamma->GetConversionX();
-               Float_t gammaY = gamma->GetConversionY();
-               Float_t gammaZ = gamma->GetConversionZ();
+//             Float_t gammaX = gamma->GetConversionX();
+//             Float_t gammaY = gamma->GetConversionY();
+               Float_t gammaZ = gamma->GetConversionZ();
       Float_t gammaR = gamma->GetConversionRadius();
-               Float_t gammaPhi = gamma->GetPhotonPhi();
+               Float_t gammaPhi = gamma->GetPhotonPhi();
+               
+               TVectorF coord(5);      
+               coord(0) = gamma->GetConversionX();
+               coord(1) = gamma->GetConversionY();
+               coord(2) = gamma->GetConversionZ();
+               coord(3) = gamma->GetConversionRadius();
+               coord(4) = gamma->GetPhotonPhi();
+               TVectorF daughterProp(4);       
+               AliESDtrack * negTrack = fConversionCuts->GetESDTrack(fESDEvent, gamma->GetTrackLabelNegative());
+      AliESDtrack * posTrack = fConversionCuts->GetESDTrack(fESDEvent, gamma->GetTrackLabelPositive());
+               daughterProp(0) = posTrack->Pt();
+      daughterProp(1) = posTrack->Theta();
+      daughterProp(2) = negTrack->Pt();
+      daughterProp(3) = negTrack->Theta();
+                               
                UInt_t kind = 9;
                if(fMCEvent){
 //                     cout << "generating MC stack"<< endl;
@@ -247,12 +290,13 @@ void AliAnalysisTaskMaterial::ProcessPhotons(){
                                        kind = 2; // combinatorics from hadronic decays
                                else if ( !(pdgCodeNeg==pdgCodePos)){
                                        TParticle *truePhotonCanditate = gamma->GetMCParticle(fMCStack);
+                                       Int_t motherLabelPhoton = truePhotonCanditate->GetMother(0);
                                        if(pdgCode == 111) 
                                                kind = 3; // pi0 Dalitz
                                        else if (pdgCode == 221) 
                                                kind = 4; // eta Dalitz
                                        else if (!(negDaughter->GetUniqueID() != 5 || posDaughter->GetUniqueID() !=5)){
-                                               if(pdgCode == 22 && negDaughter->GetMother(0) <= fMCStack->GetNprimary()){
+                                               if(pdgCode == 22 && motherLabelPhoton < fMCStack->GetNprimary()){
                                                        kind = 0; // primary photons
                                                } else if (pdgCode == 22){
                                                        kind = 5; //secondary photons
@@ -287,29 +331,21 @@ void AliAnalysisTaskMaterial::ProcessPhotons(){
                        if (fStreamMaterial){
                                (*fStreamMaterial)<<"ConvPointRec"
                                                                << "pt=" << gammaPt
-                                                               << "p=" << gammaP
-                                                               << "eta=" << gammaEta
+                                                               << "theta=" << gammaTheta
                                                                << "chi2ndf=" << gammaChi2NDF
                                                                << "kind=" << kind
-                                                               << "X=" << gammaX
-                                                               << "Y=" << gammaY
-                                                               << "Z=" << gammaZ
-                                                               << "R=" << gammaR
-                                                               << "Phi=" << gammaPhi
+                                                               << "coord.=" << &coord
+                                                               << "daughterProp.=" << &daughterProp
                                                                << "\n";
                        }               
                } else {
                                if (fStreamMaterial){
                                (*fStreamMaterial)<<"ConvPointRec"
                                                                << "pt=" << gammaPt
-                                                               << "p=" << gammaP
-                                                               << "eta=" << gammaEta
+                                                               << "theta=" << gammaTheta
                                                                << "chi2ndf=" << gammaChi2NDF
-                                                               << "X=" << gammaX
-                                                               << "Y=" << gammaY
-                                                               << "Z=" << gammaZ
-                                                               << "R=" << gammaR
-                                                               << "Phi=" << gammaPhi
+                                                               << "coord.=" << &coord
+                                                               << "daughterProp.=" << &daughterProp
                                                                << "\n";
                        }
                }
@@ -317,14 +353,66 @@ void AliAnalysisTaskMaterial::ProcessPhotons(){
 }
 
 //________________________________________________________________________
-Int_t AliAnalysisTaskMaterial::CountESDTracks(){
+Int_t AliAnalysisTaskMaterial::CountESDTracks09(){
+
+   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.9, 0.9);
+   EsdTrackCuts->SetPtRange(0.15);
+
+   Int_t 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 fNumberOfESDTracks;
+}
+
+Int_t AliAnalysisTaskMaterial::CountESDTracks0914(){
+
+   AliESDtrackCuts *EsdTrackCuts = new AliESDtrackCuts("AliESDtrackCuts");
+   // Using standard function for setting Cuts ; We use TPCOnlyTracks for outer eta region
+   Bool_t selectPrimaries=kTRUE;
+        //   EsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(selectPrimaries);
+   EsdTrackCuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();
+        EsdTrackCuts->SetMaxDCAToVertexXY(5);
+        //      EsdTrackCuts->SetMaxDCAToVertexXYPtDep("sqrt(0.15^2+(0.4/pt)^2");
+   EsdTrackCuts->SetEtaRange(0.9, 1.4);
+   EsdTrackCuts->SetPtRange(0.15);
+
+   Int_t fNumberOfESDTracks = 0;
+   for(Int_t iTracks = 0; iTracks < fESDEvent->GetNumberOfTracks(); iTracks++){
+      AliESDtrack* curTrack = fESDEvent->GetTrack(iTracks);
+      if(!curTrack) continue;
+      if(EsdTrackCuts->AcceptTrack(curTrack) ) fNumberOfESDTracks++;
+   }
+   EsdTrackCuts->SetEtaRange(-1.4, -0.9);
+   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 fNumberOfESDTracks;
+}
+
+Int_t AliAnalysisTaskMaterial::CountESDTracks14(){
 
    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->SetEtaRange(-1.4, 1.4);
    EsdTrackCuts->SetPtRange(0.15);
 
    Int_t fNumberOfESDTracks = 0;
index d5f121d..9ada50c 100644 (file)
@@ -39,7 +39,10 @@ private:
 
     void ProcessPhotons();
         void ProcessMCPhotons();
-        Int_t CountESDTracks();
+        void FillMCTree(Int_t stackPos);
+        Int_t CountESDTracks14();
+        Int_t CountESDTracks0914();
+        Int_t CountESDTracks09();
         
     AliV0ReaderV1 *fV0Reader;
     TClonesArray *fConversionGammas; //Reconstructed Photons;
index c0c4db5..1e55a6f 100644 (file)
@@ -14,6 +14,8 @@
 #include "TFile.h"
 #include "AliOADBContainer.h"
 
+#include "AliEPSelectionTask.h"
+
 // Author Daniel Lohner (Daniel.Lohner@cern.ch)
 
 using namespace std;
@@ -22,7 +24,7 @@ ClassImp(AliAnalysisTaskPi0v2)
 
 
 //________________________________________________________________________
-    AliAnalysisTaskPi0v2::AliAnalysisTaskPi0v2(const char *name) : AliAnalysisTaskSE(name),
+    AliAnalysisTaskPi0v2::AliAnalysisTaskPi0v2(const char *name,Int_t harmonic) : AliAnalysisTaskSE(name),
     fV0Reader(NULL),
     fConversionSelection(NULL),
     fConversionGammas(NULL),
@@ -32,17 +34,21 @@ ClassImp(AliAnalysisTaskPi0v2)
     fCentralityBin(0),
     fNBinsPhi(6),
     fEP(NULL),
+    fUseTPCOnlyTracks(kTRUE),
     fEtaMax(0.75),
     fEtaGap(1),
     fRPTPCEtaA(0),
     fRPTPCEtaC(0),
     fRPV0A(0),
     fRPV0C(0),
+    fRPTPC(0),
+    fRPTPCEtaABF(0),
+    fRPTPCEtaCBF(0),
+    fRPV0ABF(0),
+    fRPV0CBF(0),
+    fRPTPCBF(0),
     fNCuts(0),
-    fCutList(NULL),
     fConversionCuts(NULL),
-    fMesonCutList(NULL),
-    fMesonCuts(NULL),
     fRandomizer(NULL),
     fOutputList(NULL),
     fMesonPDGCode(kPi0),
@@ -52,7 +58,14 @@ ClassImp(AliAnalysisTaskPi0v2)
     fRunIndex(0),
     fNEPMethods(knEPMethod),
     fFillQA(kTRUE),
-   
+    fHarmonic(harmonic),
+    fPsiMax(2*TMath::Pi()/Double_t(harmonic)),
+    fPeriod("LHC10h"),
+    fIsAOD(kFALSE),
+    fSparseDist(NULL),
+    fHruns(NULL),
+    fDoEPFlattening(kTRUE),
+
     hNEvents(NULL),
     hRPTPC(NULL),
     hRPV0A(NULL),
@@ -69,21 +82,12 @@ ClassImp(AliAnalysisTaskPi0v2)
     hRPTPCEtaC(NULL),
     hRPTPCEtaAC(NULL),
     hCos2TPCEta(NULL),
-    hCos2TPCWeightedPhoton(NULL),
-    hCos2TPCEtaWeightedPhoton(NULL),
-    hCos2V0ATPCWeightedPhoton(NULL),
-    hCos2V0CTPCWeightedPhoton(NULL),
-    hCos2V0ACWeightedPhoton(NULL),
-    hCos2TPCWeightedCharged(NULL),
-    hCos2TPCEtaWeightedCharged(NULL),
-    hCos2V0ATPCWeightedCharged(NULL),
-    hCos2V0CTPCWeightedCharged(NULL),
-    hCos2V0ACWeightedCharged(NULL),
-    hCos2TPCWeightedV0Mult(NULL),
-    hCos2TPCEtaWeightedV0Mult(NULL),
-    hCos2V0ATPCWeightedV0Mult(NULL),
-    hCos2V0CTPCWeightedV0Mult(NULL),
-    hCos2V0ACWeightedV0Mult(NULL),
+    hCos2V0ATPCEtaA(NULL),
+    hCos2V0ATPCEtaC(NULL),
+    hCos2V0CTPCEtaA(NULL),
+    hCos2V0CTPCEtaC(NULL),
+    hCos2SumWeights(NULL),
+    hEtaTPCEP(NULL),
     hGammaMultCent(NULL),
     hGammaPhi(NULL),
     hMultChargedvsNGamma(NULL),
@@ -105,16 +109,22 @@ ClassImp(AliAnalysisTaskPi0v2)
     fMultV0(0x0),
     fV0Cpol(0.),
     fV0Apol(0.),
-    hEPVertex(NULL)
-
+    //hEPVertex(NULL)
+    hEPQA(NULL)
 {
     fInvMassRange=new Double_t[2];
     fInvMassRange[0]=0.05;
     fInvMassRange[1]=0.3;
 
+    for(Int_t ii=0;ii<knEPMethod;ii++)fEPSelectionMask[ii]=1;
+
     fRandomizer=new TRandom3();
     fRandomizer->SetSeed(0);
 
+    for(Int_t i = 0; i < 4; ++i) {
+       fPhiDist[i] = 0;
+    }
+
     // Define input and output slots here
     DefineInput(0, TChain::Class());
     DefineOutput(1, TList::Class());
@@ -135,19 +145,21 @@ AliAnalysisTaskPi0v2::~AliAnalysisTaskPi0v2(){
        delete fInvMassRange;
         fInvMassRange=NULL;
     }
-    if(fCutList){
-       delete fCutList;
-       fCutList=NULL;
-    }
-    if(fMesonCutList){
-        delete fMesonCutList;
-        fMesonCutList=NULL;
-    }
 
     if(fConversionSelection){
        delete fConversionSelection;
        fConversionSelection=NULL;
     }
+
+    if (fPeriod.CompareTo("LHC11h")==0){
+       for(Int_t i = 0; i < 4; i++) {
+           if(fPhiDist[i]){
+               delete fPhiDist[i];
+               fPhiDist[i] = 0;
+           }
+       }
+       if(fHruns) delete fHruns;
+    }
 }
 
 //________________________________________________________________________
@@ -186,40 +198,32 @@ void AliAnalysisTaskPi0v2::UserCreateOutputObjects()
     Double_t kGCfirstXBinSpectra = fInvMassRange[0];
     Double_t kGClastXBinSpectra = fInvMassRange[1];
 
-    Int_t nbinspi0[knbinsPi0]={kGCnYBinsSpectra,kGCnXBinsSpectra,6,fNCentralityBins,fNEPMethods};
+    Int_t nbinspi0[knbinsPi0]={kGCnYBinsSpectra,kGCnXBinsSpectra,fNBinsPhi,fNCentralityBins,fNEPMethods};
     Double_t minpi0[knbinsPi0]={kGCfirstYBinSpectra,kGCfirstXBinSpectra,0,-0.5,-0.5};
-    Double_t maxpi0[knbinsPi0]={kGClastYBinSpectra,kGClastXBinSpectra,TMath::Pi()/2,fNCentralityBins-0.5,fNEPMethods-0.5};
+    Double_t maxpi0[knbinsPi0]={kGClastYBinSpectra,kGClastXBinSpectra,fPsiMax/2.,fNCentralityBins-0.5,fNEPMethods-0.5};
     const char *binpi0[knbinsPi0]={"pt","mass","dPhi","centr","EPm"};
 
-    Int_t nbinsg[knbinsGamma]={kGCnYBinsSpectra,6,fNCentralityBins,fNEPMethods};
+    Int_t nbinsg[knbinsGamma]={kGCnYBinsSpectra,fNBinsPhi,fNCentralityBins,fNEPMethods};
     Double_t ming[knbinsGamma]={kGCfirstYBinSpectra,0,-0.5,-0.5};
-    Double_t maxg[knbinsGamma]={kGClastYBinSpectra,TMath::Pi()/2,fNCentralityBins-0.5,fNEPMethods-0.5};
+    Double_t maxg[knbinsGamma]={kGClastYBinSpectra,fPsiMax/2.,fNCentralityBins-0.5,fNEPMethods-0.5};
     const char *bingamma[knbinsGamma]={"pt","dPhi","centr","EPm"};
 
     // Define Binning
 
     if(!IsMC){
 
-       hPi0=new THnSparseF*[fNCuts];
-       hPi0BG=new THnSparseF*[fNCuts];
-       hGamma=new THnSparseF*[fNCuts];
+       hPi0=new THnSparseF*[fNCuts+1];
+       hPi0BG=new THnSparseF*[fNCuts+1];
+       hGamma=new THnSparseF*[fNCuts+1];
 
        // Photon Cuts
        for(Int_t iCut=0;iCut<fNCuts;iCut++){
-           AliConversionCuts *fPhotonv2Cuts=(AliConversionCuts*)fCutList->At(iCut);
 
            TList *fCutOutputList=new TList();
-           fCutOutputList->SetName(fPhotonv2Cuts->GetCutNumber().Data());
+           fCutOutputList->SetName(fConversionSelection[iCut]->GetCutString().Data());
            fCutOutputList->SetOwner(kTRUE);
            fOutputList->Add(fCutOutputList);
 
-           /*fPhotonv2Cuts->SetFillCutHistograms("",kFALSE);
-            TList *fCutQAList=fPhotonv2Cuts->GetCutHistograms();
-            if(fCutQAList){
-            fCutQAList->SetOwner(kTRUE);
-            fCutOutputList->Add(fCutQAList);
-            } */
-
            hPi0[iCut]=new THnSparseF("Pi0_Sparse","Pi0_Sparse",knbinsPi0,nbinspi0,minpi0,maxpi0);
            for(Int_t i=0;i<knbinsPi0;i++) hPi0[iCut]->GetAxis(i)->SetName(binpi0[i]);
            hPi0[iCut]->Sumw2();
@@ -236,8 +240,35 @@ void AliAnalysisTaskPi0v2::UserCreateOutputObjects()
            for(Int_t i=0;i<knbinsGamma;i++) hGamma[iCut]->GetAxis(i)->SetName(bingamma[i]);
            hGamma[iCut]->Sumw2();
            fCutOutputList->Add(hGamma[iCut]);
+       }
+
+       // no EP Flattening
+       Int_t iCut=0;
+
+       TList *fCutOutputList=new TList();
+       fCutOutputList->SetName(Form("%s_BF",fConversionSelection[iCut]->GetCutString().Data()));
+       fCutOutputList->SetOwner(kTRUE);
+       fOutputList->Add(fCutOutputList);
+
+       iCut=fNCuts;
+
+       hPi0[iCut]=new THnSparseF("Pi0_Sparse","Pi0_Sparse",knbinsPi0,nbinspi0,minpi0,maxpi0);
+       for(Int_t i=0;i<knbinsPi0;i++) hPi0[iCut]->GetAxis(i)->SetName(binpi0[i]);
+       hPi0[iCut]->Sumw2();
+       fCutOutputList->Add(hPi0[iCut]);
+
+       hPi0BG[iCut]=new THnSparseF("Pi0BG_Sparse","Pi0BG_Sparse",knbinsPi0,nbinspi0,minpi0,maxpi0);
+       for(Int_t i=0;i<knbinsPi0;i++) hPi0BG[iCut]->GetAxis(i)->SetName(binpi0[i]);
+       hPi0BG[iCut]->Sumw2();
+       fCutOutputList->Add(hPi0BG[iCut]);
+
+       // Gamma
+
+       hGamma[iCut]=new THnSparseF("Gamma_Sparse","Gamma_Sparse",knbinsGamma,nbinsg,ming,maxg);
+       for(Int_t i=0;i<knbinsGamma;i++) hGamma[iCut]->GetAxis(i)->SetName(bingamma[i]);
+       hGamma[iCut]->Sumw2();
+       fCutOutputList->Add(hGamma[iCut]);
 
-        }
     }
 
     if(IsHeavyIon&&!IsMC){
@@ -248,109 +279,94 @@ void AliAnalysisTaskPi0v2::UserCreateOutputObjects()
        fRPList->SetOwner(kTRUE);
        fOutputList->Add(fRPList);
 
-       hRPTPC=new TH2F("TPCAC" ,"TPC_AC" , fNCentralityBins,fCentralityBins, 180, 0, TMath::Pi());
+       hRPTPC=new TH2F("TPCAC" ,"TPC_AC" , fNCentralityBins,fCentralityBins, 180, 0, fPsiMax);
        hRPTPC->Sumw2();
        fRPList->Add(hRPTPC);
-       hRPTPCEtaA=new TH2F("TPCEtaA" ,"TPC_EtaA" , fNCentralityBins,fCentralityBins, 180, 0, TMath::Pi());
+       hRPTPCEtaA=new TH2F("TPCEtaA" ,"TPC_EtaA" , fNCentralityBins,fCentralityBins, 180, 0, fPsiMax);
        hRPTPCEtaA->Sumw2();
        fRPList->Add(hRPTPCEtaA);
-       hRPTPCEtaC=new TH2F("TPCEtaC" ,"TPC_EtaC" , fNCentralityBins,fCentralityBins, 180, 0, TMath::Pi());
+       hRPTPCEtaC=new TH2F("TPCEtaC" ,"TPC_EtaC" , fNCentralityBins,fCentralityBins, 180, 0, fPsiMax);
        hRPTPCEtaC->Sumw2();
        fRPList->Add(hRPTPCEtaC);
-       hRPV0A=new TH2F("V0A" ,"VZERO_A" , fNCentralityBins,fCentralityBins, 180, 0, TMath::Pi());
+       hRPV0A=new TH2F("V0A" ,"VZERO_A" , fNCentralityBins,fCentralityBins, 180, 0, fPsiMax);
        hRPV0A->Sumw2();
        fRPList->Add(hRPV0A);
-       hRPV0C=new TH2F("V0C" ,"VZERO_C" , fNCentralityBins,fCentralityBins, 180, 0, TMath::Pi());
+       hRPV0C=new TH2F("V0C" ,"VZERO_C" , fNCentralityBins,fCentralityBins, 180, 0, fPsiMax);
        hRPV0C->Sumw2();
        fRPList->Add(hRPV0C);
 
-       hRPTPCAC=new TH2F("TPCA_TPCC" ,"TPCA_TPCC" , 180, 0, TMath::Pi(), 180, 0, TMath::Pi());
+       hRPTPCAC=new TH2F("TPCA_TPCC" ,"TPCA_TPCC" , 180, 0, fPsiMax, 180, 0, fPsiMax);
        hRPTPCAC->Sumw2();
        fRPList->Add(hRPTPCAC);
-       hRPV0ATPC=new TH2F("V0A_TPC" ,"V0A_TPC" , 180, 0, TMath::Pi(), 180, 0, TMath::Pi());
+       hRPV0ATPC=new TH2F("V0A_TPC" ,"V0A_TPC" , 180, 0, fPsiMax, 180, 0, fPsiMax);
        hRPV0ATPC->Sumw2();
        fRPList->Add(hRPV0ATPC);
-       hRPV0CTPC=new TH2F("V0C_TPC" ,"V0C_TPC" , 180, 0, TMath::Pi(), 180, 0, TMath::Pi());
+       hRPV0CTPC=new TH2F("V0C_TPC" ,"V0C_TPC" , 180, 0, fPsiMax, 180, 0, fPsiMax);
        hRPV0CTPC->Sumw2();
        fRPList->Add(hRPV0CTPC);
-       hRPV0AC=new TH2F("V0A_V0C" ,"V0A_V0C" , 180, 0, TMath::Pi(), 180, 0, TMath::Pi());
+       hRPV0AC=new TH2F("V0A_V0C" ,"V0A_V0C" , 180, 0, fPsiMax, 180, 0, fPsiMax);
        hRPV0AC->Sumw2();
        fRPList->Add(hRPV0AC);
-       hRPTPCEtaAC=new TH2F("TPCEtaA_TPCEtaC" ,"TPCEtaA_TPCEtaC" , 180, 0, TMath::Pi(), 180, 0, TMath::Pi());
+       hRPTPCEtaAC=new TH2F("TPCEtaA_TPCEtaC" ,"TPCEtaA_TPCEtaC" , 180, 0, fPsiMax, 180, 0, fPsiMax);
        hRPTPCEtaAC->Sumw2();
        fRPList->Add(hRPTPCEtaAC);
 
-       hCos2TPC=new TH2F("Cos2_TPCAC" ,"Cos2_TPCAC" ,fNCentralityBins,fCentralityBins,100,-1,1);
+        Int_t nsystep=4;// 3 different weights + unflattened EP
+
+       hCos2TPC=new TH2F("Cos2_TPCAC" ,"Cos2_TPCAC" ,fNCentralityBins,fCentralityBins,nsystep+1,-0.5,nsystep+0.5);
        hCos2TPC->Sumw2();
        fRPList->Add(hCos2TPC);
-       hCos2TPCEta=new TH2F("Cos2_TPCEtaAC" ,"Cos2_TPCEtaAC" ,fNCentralityBins,fCentralityBins,100,-1,1);
+       hCos2TPCEta=new TH2F("Cos2_TPCEtaAC" ,"Cos2_TPCEtaAC" ,fNCentralityBins,fCentralityBins,nsystep+1,-0.5,nsystep+0.5);
        hCos2TPCEta->Sumw2();
        fRPList->Add(hCos2TPCEta);
-       hCos2V0ATPC=new TH2F("Cos2_V0ATPC" ,"Cos2_V0ATPC" ,fNCentralityBins,fCentralityBins,100,-1,1);
+       hCos2V0ATPC=new TH2F("Cos2_V0ATPC" ,"Cos2_V0ATPC" ,fNCentralityBins,fCentralityBins,nsystep+1,-0.5,nsystep+0.5);
        hCos2V0ATPC->Sumw2();
        fRPList->Add(hCos2V0ATPC);
-       hCos2V0CTPC=new TH2F("Cos2_V0CTPC" ,"Cos2_V0CTPC" ,fNCentralityBins,fCentralityBins,100,-1,1);
+       hCos2V0CTPC=new TH2F("Cos2_V0CTPC" ,"Cos2_V0CTPC" ,fNCentralityBins,fCentralityBins,nsystep+1,-0.5,nsystep+0.5);
        hCos2V0CTPC->Sumw2();
        fRPList->Add(hCos2V0CTPC);
-       hCos2V0AC=new TH2F("Cos2_V0AC" ,"Cos2_V0AC" ,fNCentralityBins,fCentralityBins,100,-1,1);
+       hCos2V0AC=new TH2F("Cos2_V0AC" ,"Cos2_V0AC" ,fNCentralityBins,fCentralityBins,nsystep+1,-0.5,nsystep+0.5);
        hCos2V0AC->Sumw2();
        fRPList->Add(hCos2V0AC);
+        hCos2V0ATPCEtaA=new TH2F("Cos2_V0ATPCEtaA" ,"Cos2_V0ATPCEtaA" ,fNCentralityBins,fCentralityBins,nsystep+1,-0.5,nsystep+0.5);
+       hCos2V0ATPCEtaA->Sumw2();
+       fRPList->Add(hCos2V0ATPCEtaA);
+       hCos2V0ATPCEtaC=new TH2F("Cos2_V0ATPCEtaC" ,"Cos2_V0ATPCEtaC" ,fNCentralityBins,fCentralityBins,nsystep+1,-0.5,nsystep+0.5);
+       hCos2V0ATPCEtaC->Sumw2();
+       fRPList->Add(hCos2V0ATPCEtaC);
+        hCos2V0CTPCEtaA=new TH2F("Cos2_V0CTPCEtaA" ,"Cos2_V0CTPCEtaA" ,fNCentralityBins,fCentralityBins,nsystep+1,-0.5,nsystep+0.5);
+       hCos2V0CTPCEtaA->Sumw2();
+       fRPList->Add(hCos2V0CTPCEtaA);
+       hCos2V0CTPCEtaC=new TH2F("Cos2_V0CTPCEtaC" ,"Cos2_V0CTPCEtaC" ,fNCentralityBins,fCentralityBins,nsystep+1,-0.5,nsystep+0.5);
+       hCos2V0CTPCEtaC->Sumw2();
+       fRPList->Add(hCos2V0CTPCEtaC);
+       hCos2SumWeights=new TH2F("Cos2_SumWeights" ,"Cos2_SumWeights" ,fNCentralityBins,fCentralityBins,nsystep+1,-0.5,nsystep+0.5);
+       hCos2SumWeights->Sumw2();
+       fRPList->Add(hCos2SumWeights);
+
+       hEtaTPCEP=new TH2F("Eta_TPCEP" ,"Eta_TPCEP" ,fNCentralityBins,fCentralityBins,100,-1,1);
+       hEtaTPCEP->Sumw2();
+       fRPList->Add(hEtaTPCEP);
+
+
+       /*const Int_t nepbins=4;
+        Int_t nbinsep[nepbins]={30,30,40,180};
+        Double_t minep[nepbins]={-0.015,0.17,-10,0};
+        Double_t maxep[nepbins]={0.015,0.20,10,fPsiMax};
+
+        hEPVertex=new THnSparseF("EP_Vertex","EP_Vertex",nepbins,nbinsep,minep,maxep);
+        fRPList->Add(hEPVertex);
+        */
+
+       const Int_t nepbins=4;
+        Int_t nbinsep[nepbins]={fNCentralityBins,180,140,5};
+       Double_t minep[nepbins]={-0.5,0,0.5,-0.5};
+       Double_t maxep[nepbins]={fNCentralityBins-0.5,fPsiMax,140.5,4.5};
+
+       hEPQA=new THnSparseF("EP_QA","EP_QA",nepbins,nbinsep,minep,maxep);
+       fRPList->Add(hEPQA);
+       
 
-       hCos2TPCWeightedPhoton=new TH2F("Cos2_TPCAC_WeightedPhoton" ,"Cos2_TPCAC_WeightedPhoton" ,fNCentralityBins,fCentralityBins,100,-1,1);
-       hCos2TPCWeightedPhoton->Sumw2();
-       fRPList->Add(hCos2TPCWeightedPhoton);
-       hCos2TPCEtaWeightedPhoton=new TH2F("Cos2_TPCEtaAC_WeightedPhoton" ,"Cos2_TPCEtaAC_WeightedPhoton" ,fNCentralityBins,fCentralityBins,100,-1,1);
-       hCos2TPCEtaWeightedPhoton->Sumw2();
-       fRPList->Add(hCos2TPCEtaWeightedPhoton);
-       hCos2V0ATPCWeightedPhoton=new TH2F("Cos2_V0ATPC_WeightedPhoton" ,"Cos2_V0ATPC_WeightedPhoton" ,fNCentralityBins,fCentralityBins,100,-1,1);
-       hCos2V0ATPCWeightedPhoton->Sumw2();
-       fRPList->Add(hCos2V0ATPCWeightedPhoton);
-       hCos2V0CTPCWeightedPhoton=new TH2F("Cos2_V0CTPC_WeightedPhoton" ,"Cos2_V0CTPC_WeightedPhoton" ,fNCentralityBins,fCentralityBins,100,-1,1);
-       hCos2V0CTPCWeightedPhoton->Sumw2();
-       fRPList->Add(hCos2V0CTPCWeightedPhoton);
-       hCos2V0ACWeightedPhoton=new TH2F("Cos2_V0AC_WeightedPhoton" ,"Cos2_V0AC_WeightedPhoton" ,fNCentralityBins,fCentralityBins,100,-1,1);
-       hCos2V0ACWeightedPhoton->Sumw2();
-       fRPList->Add(hCos2V0ACWeightedPhoton);
-
-       hCos2TPCWeightedCharged=new TH2F("Cos2_TPCAC_WeightedCharged" ,"Cos2_TPCAC_WeightedCharged" ,fNCentralityBins,fCentralityBins,100,-1,1);
-       hCos2TPCWeightedCharged->Sumw2();
-       fRPList->Add(hCos2TPCWeightedCharged);
-       hCos2TPCEtaWeightedCharged=new TH2F("Cos2_TPCEtaAC_WeightedCharged" ,"Cos2_TPCEtaAC_WeightedCharged" ,fNCentralityBins,fCentralityBins,100,-1,1);
-       hCos2TPCEtaWeightedCharged->Sumw2();
-       fRPList->Add(hCos2TPCEtaWeightedCharged);
-       hCos2V0ATPCWeightedCharged=new TH2F("Cos2_V0ATPC_WeightedCharged" ,"Cos2_V0ATPC_WeightedCharged" ,fNCentralityBins,fCentralityBins,100,-1,1);
-       hCos2V0ATPCWeightedCharged->Sumw2();
-       fRPList->Add(hCos2V0ATPCWeightedCharged);
-       hCos2V0CTPCWeightedCharged=new TH2F("Cos2_V0CTPC_WeightedCharged" ,"Cos2_V0CTPC_WeightedCharged" ,fNCentralityBins,fCentralityBins,100,-1,1);
-       hCos2V0CTPCWeightedCharged->Sumw2();
-       fRPList->Add(hCos2V0CTPCWeightedCharged);
-       hCos2V0ACWeightedCharged=new TH2F("Cos2_V0AC_WeightedCharged" ,"Cos2_V0AC_WeightedCharged" ,fNCentralityBins,fCentralityBins,100,-1,1);
-       hCos2V0ACWeightedCharged->Sumw2();
-       fRPList->Add(hCos2V0ACWeightedCharged);
-
-       hCos2TPCWeightedV0Mult=new TH2F("Cos2_TPCAC_WeightedV0Mult" ,"Cos2_TPCAC_WeightedV0Mult" ,fNCentralityBins,fCentralityBins,100,-1,1);
-       hCos2TPCWeightedV0Mult->Sumw2();
-       fRPList->Add(hCos2TPCWeightedV0Mult);
-       hCos2TPCEtaWeightedV0Mult=new TH2F("Cos2_TPCEtaAC_WeightedV0Mult" ,"Cos2_TPCEtaAC_WeightedV0Mult" ,fNCentralityBins,fCentralityBins,100,-1,1);
-       hCos2TPCEtaWeightedV0Mult->Sumw2();
-       fRPList->Add(hCos2TPCEtaWeightedV0Mult);
-       hCos2V0ATPCWeightedV0Mult=new TH2F("Cos2_V0ATPC_WeightedV0Mult" ,"Cos2_V0ATPC_WeightedV0Mult" ,fNCentralityBins,fCentralityBins,100,-1,1);
-       hCos2V0ATPCWeightedV0Mult->Sumw2();
-       fRPList->Add(hCos2V0ATPCWeightedV0Mult);
-       hCos2V0CTPCWeightedV0Mult=new TH2F("Cos2_V0CTPC_WeightedV0Mult" ,"Cos2_V0CTPC_WeightedV0Mult" ,fNCentralityBins,fCentralityBins,100,-1,1);
-       hCos2V0CTPCWeightedV0Mult->Sumw2();
-       fRPList->Add(hCos2V0CTPCWeightedV0Mult);
-       hCos2V0ACWeightedV0Mult=new TH2F("Cos2_V0AC_WeightedV0Mult" ,"Cos2_V0AC_WeightedV0Mult" ,fNCentralityBins,fCentralityBins,100,-1,1);
-       hCos2V0ACWeightedV0Mult->Sumw2();
-       fRPList->Add(hCos2V0ACWeightedV0Mult);
-
-        const Int_t nepbins=4;
-       Int_t nbinsep[nepbins]={30,30,40,180};
-       Double_t minep[nepbins]={-0.015,0.17,-10,0};
-       Double_t maxep[nepbins]={0.015,0.20,10,TMath::Pi()};
-
-       hEPVertex=new THnSparseF("EP_Vertex","EP_Vertex",nepbins,nbinsep,minep,maxep);
-       fRPList->Add(hEPVertex);
 
        
     }
@@ -433,9 +449,9 @@ void AliAnalysisTaskPi0v2::UserCreateOutputObjects()
        }
 
        const Int_t knbinsCharged=3;
-       Int_t nbinscharged[knbinsCharged]={6,fNCentralityBins,fNEPMethods};
+       Int_t nbinscharged[knbinsCharged]={fNBinsPhi,fNCentralityBins,fNEPMethods};
        Double_t mincharged[knbinsCharged]={0,-0.5,-0.5};
-       Double_t maxcharged[knbinsCharged]={TMath::Pi()/2,fNCentralityBins-0.5,fNEPMethods-0.5};
+       Double_t maxcharged[knbinsCharged]={fPsiMax/2,fNCentralityBins-0.5,fNEPMethods-0.5};
        hCharged=new THnSparseF("Charged","Charged",knbinsCharged,nbinscharged,mincharged,maxcharged);
        hCharged->GetAxis(0)->SetName("dPhi");
        hCharged->GetAxis(1)->SetName("centr");
@@ -466,52 +482,56 @@ void AliAnalysisTaskPi0v2::UserCreateOutputObjects()
 }
 
 //________________________________________________________________________
-void AliAnalysisTaskPi0v2::InitConversionSelection(){
-
-    fConversionSelection=new AliConversionSelection*[fNCuts];
-    for(Int_t iCut=0;iCut<fNCuts;iCut++){
-       AliConversionCuts *fPhotonv2Cuts=(AliConversionCuts*)fCutList->At(iCut);
-       if(iCut==0)fEtaMax=fPhotonv2Cuts->GetEtaCut();
-        AliConversionMesonCuts *fMesonv2Cuts=(AliConversionMesonCuts*)fMesonCutList->At(iCut);
-       fConversionSelection[iCut]=new AliConversionSelection(fPhotonv2Cuts,fMesonv2Cuts);
-       fConversionSelection[iCut]->SetInvMassRange(fInvMassRange);
-    }
-}
-
-//________________________________________________________________________
 Bool_t AliAnalysisTaskPi0v2::InitEvent(){
 
     if(!fV0Reader){AliError("Error: No V0 Reader and Pi0 Reconstructor");return kFALSE;}
     if(!fV0Reader->IsEventSelected())return kFALSE;
     fConversionGammas=fV0Reader->GetReconstructedGammas();
 
+    fIsAOD=(fInputEvent->IsA()==AliAODEvent::Class());
+
     if(!fConversionSelection){
-       InitConversionSelection();
+       AliError("No Cut Selection");
+       return kFALSE;
     }
 
     if(!SetCentrality()){return kFALSE;}
 
-    if(fConversionCuts->IsHeavyIon()){
+    if(fConversionCuts->IsHeavyIon()&&!fMCEvent){
 
        if(fRunNumber!=fInputEvent->GetRunNumber()){
            fRunNumber=fInputEvent->GetRunNumber();
+           if (fRunNumber >= 136851 && fRunNumber <= 139515){fPeriod = "LHC10h";}
+           if (fRunNumber >= 166529 && fRunNumber <= 170593){fPeriod = "LHC11h";}
            fRunIndex=GetRunIndex(fRunNumber);
-           OpenInfoCalibration(fRunNumber); // Load Calibration of V0 Event Plane
+           OpenInfoCalibration(fRunNumber); // Load Calibration of V0 and TPC Event Plane
        }
        if(fRunIndex<0)return kFALSE;
 
-       fEP=fInputEvent->GetEventplane();
+       // TPC Event Plane
+       if(!GetTPCEventPlane())return kFALSE;
+       //fEP=fInputEvent->GetEventplane();
        if(!fEP)return kFALSE;
+       fRPTPCBF=GetCorrectedTPCEPAngle(NULL,NULL,kFALSE);
+       fRPTPC=GetEventPlaneAngle(kTPC);
 
-       fRPTPCEtaA=GetTPCSubEPEta(fEtaGap/2,1);
-       fRPTPCEtaC=GetTPCSubEPEta(-1,-fEtaGap/2);
+       // TPC Eta Sub Events
+       fRPTPCEtaABF=GetTPCSubEPEta(kEPTPCEtaA);
+       fRPTPCEtaA=ApplyFlattening(fRPTPCEtaABF,kEPTPCEtaA);
+
+       fRPTPCEtaCBF=GetTPCSubEPEta(kEPTPCEtaC);
+       fRPTPCEtaC=ApplyFlattening(fRPTPCEtaCBF,kEPTPCEtaC);
 
        // GetV0 Event Plane
-       GetV0EP(fInputEvent);
+       GetV0EP(fInputEvent,fRPV0ABF,fRPV0CBF);
+       fRPV0A=ApplyFlattening(fRPV0ABF,kEPV0A);
+       fRPV0C=ApplyFlattening(fRPV0CBF,kEPV0C);
+
     }
     return kTRUE;
 }
 
+
 //________________________________________________________________________
 void AliAnalysisTaskPi0v2::UserExec(Option_t *) 
 {
@@ -528,11 +548,16 @@ void AliAnalysisTaskPi0v2::UserExec(Option_t *)
                // Process EP methods
                for(Int_t iEP=0;iEP<fNEPMethods;iEP++){
 
+                   if(!fEPSelectionMask[iEP])continue; // dont fill THnSparse if not needed-> Save Memory
+
                    ProcessPi0s(iCut,EEventPlaneMethod(iEP));
 
                    ProcessGammas(iCut,EEventPlaneMethod(iEP));
                }
            }
+
+           // QA
+           if(fFillQA&&iCut==0)ProcessQA();
        }
     }
 
@@ -542,11 +567,7 @@ void AliAnalysisTaskPi0v2::UserExec(Option_t *)
     // EventPlaneResolution
     ProcessEventPlane();
 
-    // QA
-    if(fFillQA)ProcessQA();
-
     PostData(1, fOutputList);
-
 }
 
 //________________________________________________________________________
@@ -554,11 +575,9 @@ void AliAnalysisTaskPi0v2::ProcessPi0s(Int_t iCut,EEventPlaneMethod iEP){
 
     if(!fConversionSelection[iCut])return;
 
-    Int_t photonMultiplicity=fConversionSelection[iCut]->GetMultiplicity(fInputEvent);
-    if(photonMultiplicity==0)return;
+    if(fConversionSelection[iCut]->GetNumberOfPhotons()==0)return;
 
     // Process Pi0s
-    Float_t weight=1/Float_t(photonMultiplicity);
 
     for(Int_t ii=0;ii<fConversionSelection[iCut]->GetNumberOfPi0s();ii++){
 
@@ -573,7 +592,13 @@ void AliAnalysisTaskPi0v2::ProcessPi0s(Int_t iCut,EEventPlaneMethod iEP){
        val[kPi0Cent]=fCentralityBin;
        val[kPi0EPM]=Int_t(iEP);
 
-       hPi0[iCut]->Fill(val,weight);
+       hPi0[iCut]->Fill(val);
+
+       if(iCut==0){
+           // no flattening
+           val[kPi0dPhi]=GetPi0PhiwrtRP(pi0cand,iEP,kFALSE);
+           hPi0[fNCuts]->Fill(val);
+       }
     }
 
     // Pi0 BG
@@ -590,19 +615,23 @@ void AliAnalysisTaskPi0v2::ProcessPi0s(Int_t iCut,EEventPlaneMethod iEP){
        val[kPi0Cent]=fCentralityBin;
        val[kPi0EPM]=Int_t(iEP);
 
-       hPi0BG[iCut]->Fill(val,pi0cand->GetWeight()*weight);
+       hPi0BG[iCut]->Fill(val,pi0cand->GetWeight());
+
+       if(iCut==0){
+           // no flattening
+           val[kPi0dPhi]=GetPi0PhiwrtRP(pi0cand,iEP,kFALSE);
+           hPi0BG[fNCuts]->Fill(val);
+       }
     }
 }
 
 //________________________________________________________________________
 void AliAnalysisTaskPi0v2::ProcessGammas(Int_t iCut,EEventPlaneMethod iEP){
 
-    if(!fConversionSelection[iCut])return;
-
-    Int_t photonMultiplicity=fConversionSelection[iCut]->GetMultiplicity(fInputEvent);
-    if(photonMultiplicity==0)return;
-
-    Float_t weight=1/Float_t(photonMultiplicity);
+    if(!fConversionSelection[iCut]){
+       AliWarning("Conversion Selection does not exist");
+       return;
+    }
 
     for(Int_t ii=0;ii<fConversionSelection[iCut]->GetNumberOfPhotons();ii++){
 
@@ -614,7 +643,13 @@ void AliAnalysisTaskPi0v2::ProcessGammas(Int_t iCut,EEventPlaneMethod iEP){
        val[kGammaCent]=fCentralityBin;
        val[kGammaEPM]=Int_t(iEP);
 
-       hGamma[iCut]->Fill(val,weight);
+       hGamma[iCut]->Fill(val);
+
+       if(iCut==0){
+            // no flattening
+           val[kGammadPhi]=GetPhotonPhiwrtRP(gamma,iEP,kFALSE);
+           hGamma[fNCuts]->Fill(val);
+       }
 
        if(iCut==0&&fFillQA){
            hGammadNdPhi->Fill(val);
@@ -632,6 +667,12 @@ void AliAnalysisTaskPi0v2::ProcessGammas(Int_t iCut,EEventPlaneMethod iEP){
 //________________________________________________________________________
 void AliAnalysisTaskPi0v2::ProcessQA(){
 
+    if(!fConversionSelection[0]){
+       AliWarning("Conversion Selection does not exist");
+       return;
+    }
+
+
     AliStack *fMCStack=NULL;
     if(fMCEvent)fMCStack=fMCEvent->Stack();
 
@@ -647,9 +688,6 @@ void AliAnalysisTaskPi0v2::ProcessQA(){
 
     // Efficiency Purity
 
-    Int_t photonMultiplicity=fConversionSelection[0]->GetMultiplicity(fInputEvent);
-    Float_t weight=1/Float_t(photonMultiplicity);
-
     Double_t valdPhi[knbinsGammaMult];
     Double_t val[knbinsGammaMult];
 
@@ -670,8 +708,8 @@ void AliAnalysisTaskPi0v2::ProcessQA(){
            valdPhi[1]=dNdPhi[GetPhotonPhiBin(gamma,iEP)];
            valdPhi[2]=fCentralityBin;
        
-           hGammaMult[iEP]->Fill(val,weight);
-           hGammaMultdPhi[iEP]->Fill(valdPhi,weight);
+           hGammaMult[iEP]->Fill(val);
+           hGammaMultdPhi[iEP]->Fill(valdPhi);
 
            // Gamma Phi
            hGammaPhi[fCentralityBin]->Fill(gamma->Pt(),gamma->Phi());
@@ -679,8 +717,8 @@ void AliAnalysisTaskPi0v2::ProcessQA(){
 
            if(fMCStack){
                if(gamma->IsTruePhoton(fMCStack)){
-                   hGammaMultRECOTRUE->Fill(val,weight);
-                   hGammaMultdPhiRECOTRUE->Fill(valdPhi,weight);
+                   hGammaMultRECOTRUE->Fill(val);
+                   hGammaMultdPhiRECOTRUE->Fill(valdPhi);
                }
            }
        }
@@ -701,8 +739,8 @@ void AliAnalysisTaskPi0v2::ProcessQA(){
                        valdPhi[1]=dNdPhi[GetPhiBin(GetMCPhotonPhiwrtRP(particle,EEventPlaneMethod(iEP)))];
                        valdPhi[2]=fCentralityBin;
        
-                       hGammaMultTRUE->Fill(val,weight);
-                       hGammaMultdPhiTRUE->Fill(valdPhi,weight);
+                       hGammaMultTRUE->Fill(val);
+                       hGammaMultdPhiTRUE->Fill(valdPhi);
                    }
                }
            }
@@ -750,7 +788,7 @@ void AliAnalysisTaskPi0v2::GetChargeddNdPhi(Int_t *dNdPhi,Int_t &ntot,Int_t iEP)
 
 //________________________________________________________________________
 Int_t AliAnalysisTaskPi0v2::GetPhiBin(Double_t phiwrt){
-    Double_t binrange=TMath::Pi()/(2*Double_t(fNBinsPhi));
+    Double_t binrange=TMath::Pi()/(Double_t(fHarmonic*fNBinsPhi));
     for(Int_t iPhi=0;iPhi<fNBinsPhi;iPhi++){
        if(phiwrt>=(binrange*iPhi)&&phiwrt<(binrange*(iPhi+1)))return iPhi;
     }
@@ -764,37 +802,43 @@ Int_t AliAnalysisTaskPi0v2::GetPhotonPhiBin(AliAODConversionPhoton *gamma,Int_t
 }
 
 //________________________________________________________________________
-Double_t AliAnalysisTaskPi0v2::GetPi0PhiwrtRP(AliAODConversionMother *pi0,EEventPlaneMethod iEP){
+Double_t AliAnalysisTaskPi0v2::GetPi0PhiwrtRP(AliAODConversionMother *pi0,EEventPlaneMethod iEP,Bool_t bDoFlattening){
 
     AliAODConversionPhoton *gamma0=dynamic_cast<AliAODConversionPhoton*>(fConversionGammas->At(pi0->GetLabel1()));
     AliAODConversionPhoton *gamma1=dynamic_cast<AliAODConversionPhoton*>(fConversionGammas->At(pi0->GetLabel2()));
 
-    Double_t EPAngle=GetEventPlaneAngle(iEP,pi0->Eta(),gamma0,gamma1);
+    Double_t EPAngle=GetEventPlaneAngle(iEP,pi0->Eta(),gamma0,gamma1,bDoFlattening);
 
-    return TMath::ACos(TMath::Abs(TMath::Cos(pi0->Phi()-EPAngle)));
+    return GetPhiwrtRP(pi0->Phi()-EPAngle);
 }
 
 //________________________________________________________________________
-Double_t AliAnalysisTaskPi0v2::GetPhotonPhiwrtRP(AliAODConversionPhoton *gamma,EEventPlaneMethod iEP){
+Double_t AliAnalysisTaskPi0v2::GetPhotonPhiwrtRP(AliAODConversionPhoton *gamma,EEventPlaneMethod iEP,Bool_t bDoFlattening){
 
-    Double_t EPAngle=GetEventPlaneAngle(iEP,gamma->Eta(),gamma,NULL);
+    Double_t EPAngle=GetEventPlaneAngle(iEP,gamma->Eta(),gamma,NULL,bDoFlattening);
 
-    return TMath::ACos(TMath::Abs(TMath::Cos(gamma->Phi()-EPAngle)));
+    return GetPhiwrtRP(gamma->Phi()-EPAngle);
 }
 
 //________________________________________________________________________
-Double_t AliAnalysisTaskPi0v2::GetMCPhotonPhiwrtRP(TParticle *gamma,EEventPlaneMethod iEP){
+Double_t AliAnalysisTaskPi0v2::GetMCPhotonPhiwrtRP(TParticle *gamma,EEventPlaneMethod iEP,Bool_t bDoFlattening){
 
-    Double_t EPAngle=GetEventPlaneAngle(iEP,gamma->Eta(),NULL,NULL);
+    Double_t EPAngle=GetEventPlaneAngle(iEP,gamma->Eta(),NULL,NULL,bDoFlattening);
 
-    return TMath::ACos(TMath::Abs(TMath::Cos(gamma->Phi()-EPAngle)));
+    return GetPhiwrtRP(gamma->Phi()-EPAngle);
 }
 //________________________________________________________________________
-Double_t AliAnalysisTaskPi0v2::GetChargedPhiwrtRP(AliVTrack *track,EEventPlaneMethod iEP){
+Double_t AliAnalysisTaskPi0v2::GetChargedPhiwrtRP(AliVTrack *track,EEventPlaneMethod iEP,Bool_t bDoFlattening){
 
-    Double_t EPAngle=GetEventPlaneAngle(iEP,track->Eta(),NULL,NULL);
+    Double_t EPAngle=GetEventPlaneAngle(iEP,track->Eta(),NULL,NULL,bDoFlattening);
 
-    return TMath::ACos(TMath::Abs(TMath::Cos(track->Phi()-EPAngle)));
+    return GetPhiwrtRP(track->Phi()-EPAngle);
+}
+//________________________________________________________________________
+Double_t AliAnalysisTaskPi0v2::GetPhiwrtRP(Double_t dPhi){
+    Double_t newdPhi=TMath::Abs(dPhi); // Cos is symmetric
+    while(newdPhi>fPsiMax/2)newdPhi=TMath::Abs(newdPhi-fPsiMax);
+    return newdPhi;
 }
 
 //________________________________________________________________________
@@ -808,68 +852,116 @@ void AliAnalysisTaskPi0v2::ProcessEventPlane()
 {
     if(!fMCEvent&&fConversionCuts->IsHeavyIon()){
 
-        Double_t val[4];
+       /*  Double_t val[4];
        val[0]=fInputEvent->GetPrimaryVertex()->GetX();
-         val[1]=fInputEvent->GetPrimaryVertex()->GetY();
-         val[2]=fInputEvent->GetPrimaryVertex()->GetZ();
-        val[3]=GetEventPlaneAngle(kTPC);
-         hEPVertex->Fill(val);
+       val[1]=fInputEvent->GetPrimaryVertex()->GetY();
+       val[2]=fInputEvent->GetPrimaryVertex()->GetZ();
+       val[3]=GetEventPlaneAngle(kTPC);
+       hEPVertex->Fill(val);   */
+
+       // Run by run monitoring (before flattening)
+
+       Double_t val[4];
+        val[0]=fCentralityBin;
+       val[2]=fRunIndex;
+
+       val[1]=fRPTPCBF;
+       val[3]=kEPTPC;
+       hEPQA->Fill(val);
+
+       val[1]=fRPTPCEtaABF;
+       val[3]=kEPTPCEtaA;
+        hEPQA->Fill(val);
+       val[1]=fRPTPCEtaCBF;
+       val[3]=kEPTPCEtaC;
+       hEPQA->Fill(val);
+
+        val[1]=fRPV0ABF;
+       val[3]=kEPV0A;
+        hEPQA->Fill(val);
+        val[1]=fRPV0CBF;
+       val[3]=kEPV0C;
+        hEPQA->Fill(val);
+
+       // After Flattening
 
        // TPC EP
-       Double_t PsiRP1=fEP->GetQsub1()->Phi()/2;
-       Double_t PsiRP2=fEP->GetQsub2()->Phi()/2;
-       Double_t EPTPC=GetEventPlaneAngle(kTPC);
+        Double_t PsiRP1BF=fEP->GetQsub1()->Phi()/Double_t(fHarmonic);
+       Double_t PsiRP2BF=fEP->GetQsub2()->Phi()/Double_t(fHarmonic);
+       Double_t PsiRP1=ApplyFlattening(PsiRP1BF,kEPTPC);
+       Double_t PsiRP2=ApplyFlattening(PsiRP2BF,kEPTPC);
 
-       hRPTPC->Fill(fCentrality,EPTPC);
+       hRPTPC->Fill(fCentrality,fRPTPC);
        hRPTPCAC->Fill(PsiRP1,PsiRP2);
-       hCos2TPC->Fill(fCentrality,TMath::Cos(2*(PsiRP1-PsiRP2)));
-
+       
        // TPC Eta Gap
        hRPTPCEtaA->Fill(fCentrality,fRPTPCEtaA);
         hRPTPCEtaC->Fill(fCentrality,fRPTPCEtaC);
        hRPTPCEtaAC->Fill(fRPTPCEtaA,fRPTPCEtaC);
-       hCos2TPCEta->Fill(fCentrality,TMath::Cos(2.*(fRPTPCEtaA-fRPTPCEtaC)));
-
+     
        // V0
-       hCos2V0ATPC->Fill(fCentrality,TMath::Cos(2*(EPTPC-fRPV0A)));
-       hCos2V0CTPC->Fill(fCentrality,TMath::Cos(2*(EPTPC-fRPV0C)));
-       hCos2V0AC->Fill(fCentrality,TMath::Cos(2*(fRPV0C-fRPV0A)));
-
+      
        hRPV0A->Fill(fCentrality,fRPV0A);
        hRPV0C->Fill(fCentrality,fRPV0C);
 
-       hRPV0ATPC->Fill(fRPV0A,EPTPC);
-       hRPV0CTPC->Fill(fRPV0C,EPTPC);
+       hRPV0ATPC->Fill(fRPV0A,fRPTPC);
+       hRPV0CTPC->Fill(fRPV0C,fRPTPC);
        hRPV0AC->Fill(fRPV0A,fRPV0C);
 
-        // Weight with Photon Mult
-       Float_t weightphoton=Float_t(fConversionSelection[0]->GetNumberOfPhotons());
-
-       hCos2TPCWeightedPhoton->Fill(fCentrality,TMath::Cos(2*(PsiRP1-PsiRP2)),weightphoton);
-       hCos2TPCEtaWeightedPhoton->Fill(fCentrality,TMath::Cos(2.*(fRPTPCEtaA-fRPTPCEtaC)),weightphoton);
-       hCos2V0ATPCWeightedPhoton->Fill(fCentrality,TMath::Cos(2*(EPTPC-fRPV0A)),weightphoton);
-       hCos2V0CTPCWeightedPhoton->Fill(fCentrality,TMath::Cos(2*(EPTPC-fRPV0C)),weightphoton);
-       hCos2V0ACWeightedPhoton->Fill(fCentrality,TMath::Cos(2*(fRPV0C-fRPV0A)),weightphoton);
-
-       // Weight with charged Track Mult
-
-       Float_t weightcharged=Float_t(fConversionSelection[0]->GetNumberOfChargedTracks(fInputEvent));
-
-        hCos2TPCWeightedCharged->Fill(fCentrality,TMath::Cos(2*(PsiRP1-PsiRP2)),weightcharged);
-       hCos2TPCEtaWeightedCharged->Fill(fCentrality,TMath::Cos(2.*(fRPTPCEtaA-fRPTPCEtaC)),weightcharged);
-       hCos2V0ATPCWeightedCharged->Fill(fCentrality,TMath::Cos(2*(EPTPC-fRPV0A)),weightcharged);
-       hCos2V0CTPCWeightedCharged->Fill(fCentrality,TMath::Cos(2*(EPTPC-fRPV0C)),weightcharged);
-       hCos2V0ACWeightedCharged->Fill(fCentrality,TMath::Cos(2*(fRPV0C-fRPV0A)),weightcharged);
-
-       // Weight with V0 mult
-
-       Float_t weightv0Mult=Float_t(fConversionSelection[0]->GetVZEROMult(fInputEvent));
+       Double_t cos2V0ATPC=TMath::Cos(Double_t(fHarmonic)*(fRPTPC-fRPV0A));
+        Double_t cos2V0CTPC=TMath::Cos(Double_t(fHarmonic)*(fRPTPC-fRPV0C));
+       Double_t cos2V0AV0C=TMath::Cos(Double_t(fHarmonic)*(fRPV0C-fRPV0A));
+       Double_t cos2TPCEta=TMath::Cos(Double_t(fHarmonic)*(fRPTPCEtaA-fRPTPCEtaC));
+        Double_t cos2TPC=TMath::Cos(Double_t(fHarmonic)*(PsiRP1-PsiRP2));
+       Double_t cos2V0ATPCEtaA=TMath::Cos(Double_t(fHarmonic)*(fRPV0A-fRPTPCEtaA));
+       Double_t cos2V0CTPCEtaA=TMath::Cos(Double_t(fHarmonic)*(fRPV0C-fRPTPCEtaA));
+        Double_t cos2V0ATPCEtaC=TMath::Cos(Double_t(fHarmonic)*(fRPV0A-fRPTPCEtaC));
+        Double_t cos2V0CTPCEtaC=TMath::Cos(Double_t(fHarmonic)*(fRPV0C-fRPTPCEtaC));
+
+        const Int_t nfill=4;
+       Double_t weight[nfill];
+       weight[0]=1.;// Fill unweighted
+       weight[1]=Float_t(fConversionSelection[0]->GetNumberOfPhotons());// Weight with Photon Mult
+       weight[2]=Float_t(fConversionSelection[0]->GetNumberOfChargedTracks(fInputEvent)); // Weight with charged Track Mult
+       weight[3]=Float_t(fConversionSelection[0]->GetVZEROMult(fInputEvent)); // Weight with V0 mult
+
+       for(Int_t i=0;i<nfill;i++){
+
+           hCos2V0ATPC->Fill(fCentrality,i,cos2V0ATPC*weight[i]);
+           hCos2V0CTPC->Fill(fCentrality,i,cos2V0CTPC*weight[i]);
+           hCos2V0AC->Fill(fCentrality,i,cos2V0AV0C*weight[i]);
+           hCos2TPCEta->Fill(fCentrality,i,cos2TPCEta*weight[i]);
+           hCos2TPC->Fill(fCentrality,i,cos2TPC*weight[i]);
+           hCos2V0ATPCEtaA->Fill(fCentrality,i,cos2V0ATPCEtaA*weight[i]);
+           hCos2V0ATPCEtaC->Fill(fCentrality,i,cos2V0ATPCEtaC*weight[i]);
+           hCos2V0CTPCEtaA->Fill(fCentrality,i,cos2V0CTPCEtaA*weight[i]);
+           hCos2V0CTPCEtaC->Fill(fCentrality,i,cos2V0CTPCEtaC*weight[i]);
+
+           hCos2SumWeights->Fill(fCentrality,i,weight[i]);
+       }
 
-        hCos2TPCWeightedV0Mult->Fill(fCentrality,TMath::Cos(2*(PsiRP1-PsiRP2)),weightv0Mult);
-       hCos2TPCEtaWeightedV0Mult->Fill(fCentrality,TMath::Cos(2.*(fRPTPCEtaA-fRPTPCEtaC)),weightv0Mult);
-       hCos2V0ATPCWeightedV0Mult->Fill(fCentrality,TMath::Cos(2*(EPTPC-fRPV0A)),weightv0Mult);
-       hCos2V0CTPCWeightedV0Mult->Fill(fCentrality,TMath::Cos(2*(EPTPC-fRPV0C)),weightv0Mult);
-       hCos2V0ACWeightedV0Mult->Fill(fCentrality,TMath::Cos(2*(fRPV0C-fRPV0A)),weightv0Mult);
+        // Fill Resolution before EP Flattening
+       Double_t cos2V0ATPCBF=TMath::Cos(Double_t(fHarmonic)*(fRPTPCBF-fRPV0ABF));
+        Double_t cos2V0CTPCBF=TMath::Cos(Double_t(fHarmonic)*(fRPTPCBF-fRPV0CBF));
+       Double_t cos2V0AV0CBF=TMath::Cos(Double_t(fHarmonic)*(fRPV0CBF-fRPV0ABF));
+       Double_t cos2TPCEtaBF=TMath::Cos(Double_t(fHarmonic)*(fRPTPCEtaABF-fRPTPCEtaCBF));
+       Double_t cos2TPCBF=TMath::Cos(Double_t(fHarmonic)*(PsiRP1BF-PsiRP2BF));
+       Double_t cos2V0ATPCEtaABF=TMath::Cos(Double_t(fHarmonic)*(fRPV0ABF-fRPTPCEtaABF));
+       Double_t cos2V0CTPCEtaABF=TMath::Cos(Double_t(fHarmonic)*(fRPV0CBF-fRPTPCEtaABF));
+       Double_t cos2V0ATPCEtaCBF=TMath::Cos(Double_t(fHarmonic)*(fRPV0ABF-fRPTPCEtaCBF));
+       Double_t cos2V0CTPCEtaCBF=TMath::Cos(Double_t(fHarmonic)*(fRPV0CBF-fRPTPCEtaCBF));
+
+       hCos2V0ATPC->Fill(fCentrality,nfill,cos2V0ATPCBF);
+       hCos2V0CTPC->Fill(fCentrality,nfill,cos2V0CTPCBF);
+       hCos2V0AC->Fill(fCentrality,nfill,cos2V0AV0CBF);
+       hCos2TPCEta->Fill(fCentrality,nfill,cos2TPCEtaBF);
+       hCos2TPC->Fill(fCentrality,nfill,cos2TPCBF);
+       hCos2V0ATPCEtaA->Fill(fCentrality,nfill,cos2V0ATPCEtaABF);
+       hCos2V0ATPCEtaC->Fill(fCentrality,nfill,cos2V0ATPCEtaCBF);
+       hCos2V0CTPCEtaA->Fill(fCentrality,nfill,cos2V0CTPCEtaABF);
+       hCos2V0CTPCEtaC->Fill(fCentrality,nfill,cos2V0CTPCEtaCBF);
+
+       hCos2SumWeights->Fill(fCentrality,nfill);
 
     }
 }
@@ -879,60 +971,116 @@ TVector2 AliAnalysisTaskPi0v2::GetEPContribution(AliAODConversionPhoton *gamma){
     TVector2 q;
     for(Int_t ii=0;ii<2;ii++){
        AliVTrack *fCurrentTrack=AliConversionCuts::GetTrack(fInputEvent,gamma->GetTrackLabel(ii));
-       TVector2 qtrack(fEP->GetQContributionX(fCurrentTrack),fEP->GetQContributionY(fCurrentTrack));
+       TVector2 qtrack=GetContributionEP(fCurrentTrack);
        q+=qtrack;
     }
     return q;
 }
 
 //________________________________________________________________________
-Double_t AliAnalysisTaskPi0v2::GetCorrectedTPCEPAngle(AliAODConversionPhoton *gamma0,AliAODConversionPhoton *gamma1){
+Double_t AliAnalysisTaskPi0v2::GetCorrectedTPCEPAngle(AliAODConversionPhoton *gamma0,AliAODConversionPhoton *gamma1,Bool_t bDoFlattening){
     // Correct Event Plane for Dilepton Tracks
     TVector2 q0(*fEP->GetQVector());
     if(gamma0)q0-=GetEPContribution(gamma0);
     if(gamma1)q0-=GetEPContribution(gamma1);
-    Double_t EPangle=q0.Phi()/2;
-    //EPangle=ApplyFlatteningTPC(EPangle,fCentrality);
+    Double_t EPangle=GetPsiInRange(q0.Phi()/Double_t(fHarmonic));
+    if(bDoFlattening)EPangle=ApplyFlattening(EPangle,kEPTPC);
 
     return EPangle;
 }
 
 //________________________________________________________________________
-Double_t AliAnalysisTaskPi0v2::GetTPCSubEPEta(Double_t etamin,Double_t etamax){
+Double_t AliAnalysisTaskPi0v2::GetTPCSubEPEta(EEventPlane ep){
+
+    Double_t etamin,etamax;
+    switch(ep){
+    case kEPTPCEtaA:
+       etamin=fEtaGap/2;
+       etamax=1;
+       break;
+    case kEPTPCEtaC:
+       etamin=-1;
+       etamax=-fEtaGap/2;
+        break;
+    default:
+       return 0;
+    }
+
     TVector2 q;
     for(Int_t ii=0;ii<fInputEvent->GetNumberOfTracks();ii++){
        AliVTrack *fCurrentTrack=dynamic_cast<AliVTrack*>(fInputEvent->GetTrack(ii));
        if(!fCurrentTrack)continue;
        if(fCurrentTrack->Eta()>=etamin&&fCurrentTrack->Eta()<=etamax){
-           TVector2 qtrack(fEP->GetQContributionX(fCurrentTrack),fEP->GetQContributionY(fCurrentTrack));
+           TVector2 qtrack=GetContributionEP(fCurrentTrack);
            q+=qtrack;
        }
     }
-    return q.Phi()/2;
+
+    Double_t phi=GetPsiInRange(q.Phi()/Double_t(fHarmonic));
+
+    return phi;
 }
 
 //________________________________________________________________________
-Double_t AliAnalysisTaskPi0v2::GetEventPlaneAngle(EEventPlaneMethod EPmethod,Double_t eta,AliAODConversionPhoton *gamma0,AliAODConversionPhoton *gamma1)
+TVector2 AliAnalysisTaskPi0v2::GetContributionEP(AliVTrack *track){
+
+    TVector2 q(0,0);
+
+    TArrayF *fQContributionX=fEP->GetQContributionXArray();
+    TArrayF *fQContributionY=fEP->GetQContributionYArray();
+
+    Int_t trackID=track->GetID();
+
+    if(fIsAOD){
+       if((trackID>-1)&&fUseTPCOnlyTracks)return q;
+       if((trackID<0)&&!fUseTPCOnlyTracks)return q;
+       if (fUseTPCOnlyTracks) trackID = trackID*(-1) - 1;
+    }
+
+    q.Set(fQContributionX->GetAt(trackID),fQContributionY->GetAt(trackID));
+
+    return q;
+}
+
+//________________________________________________________________________
+Double_t AliAnalysisTaskPi0v2::GetPsiInRange(Double_t phi){
+
+    Double_t newphi=phi;
+    while(newphi<0)newphi+=fPsiMax;
+    while(newphi>fPsiMax)newphi-=fPsiMax;
+    return newphi;
+}
+
+//________________________________________________________________________
+Double_t AliAnalysisTaskPi0v2::GetEventPlaneAngle(EEventPlaneMethod EPmethod,Double_t eta,AliAODConversionPhoton *gamma0,AliAODConversionPhoton *gamma1,Bool_t bDoFlattening)
 {
     // If arguments are not null, the contribution of these photons is subtracted from the TPC EP
 
     if(fConversionCuts->IsHeavyIon()){
-       
+
        // For MC select random EP angle in order to avoid correlations due to azimuth dependent efficiencies (ITS holes)
        if(fMCEvent){
-           return fRandomizer->Uniform(2*TMath::Pi());
+           return fRandomizer->Uniform(0,fPsiMax);
        }
-
        switch(EPmethod){
        case kTPC:
-           return GetCorrectedTPCEPAngle(gamma0,gamma1);
+           return GetCorrectedTPCEPAngle(gamma0,gamma1,bDoFlattening);
        case kTPCEtaGap:
-           if(eta<0)return fRPTPCEtaA; // Use opposite EP
-           else return fRPTPCEtaC;
+           // Use opposite EP
+           if(bDoFlattening){
+               if(eta<0)return fRPTPCEtaA; 
+               else return fRPTPCEtaC;
+           }
+           else{
+               if(eta<0)return fRPTPCEtaABF;
+               else return fRPTPCEtaCBF;
+           }
        case kV0A:
-           return fRPV0A;
+           if(bDoFlattening)return fRPV0A;
+           else return fRPV0ABF;
        case kV0C:
-           return fRPV0C;
+           if(bDoFlattening)return fRPV0C;
+           else return fRPV0CBF;
        default:
            return 0;
        }
@@ -984,29 +1132,16 @@ void AliAnalysisTaskPi0v2::SetCentralityBins(Double_t *bins,Int_t nbins)
 }
 
 //________________________________________________________________________
-void AliAnalysisTaskPi0v2::SetCuts(TString *cutarray,Int_t ncuts){
-
-    if(fCutList){
-       delete fCutList;
-        fCutList=NULL;
-    }
+void AliAnalysisTaskPi0v2::SetCuts(AliConversionSelection **conversionselection,Int_t ncuts){
 
+    fConversionSelection=conversionselection;
     fNCuts=ncuts;
-
-    fCutList = new TList();
-    fCutList->SetOwner(kTRUE);
-    AliConversionCuts **analysisCuts = new AliConversionCuts*[fNCuts];
-    for(Int_t i = 0; i<fNCuts; i++){
-       analysisCuts[i] = new AliConversionCuts();
-       analysisCuts[i]->InitializeCutsFromCutString(cutarray[i].Data());
-       fCutList->Add(analysisCuts[i]);
-    }
 }
 
 //___________________________________________________________________________
 Int_t AliAnalysisTaskPi0v2::GetRunIndex(Int_t run){
 
-  switch(run){
+   switch(run){
   case  139517 : return 137;
   case  139514 : return 136;
   case  139513 : return 135; 
@@ -1054,7 +1189,7 @@ Int_t AliAnalysisTaskPi0v2::GetRunIndex(Int_t run){
   case  138973 : return 93; 
   case  138972 : return 92; 
   case  138965 : return 91; 
-  case  138924 : return 90; 
+  case  138924 : return 90;
   case  138872 : return 89; 
   case  138871 : return 88; 
   case  138870 : return 87; 
@@ -1076,8 +1211,8 @@ Int_t AliAnalysisTaskPi0v2::GetRunIndex(Int_t run){
   case  138621 : return 71; 
   case  138583 : return 70; 
   case  138582 : return 69; 
-  case  138579 : return 68; 
-  case  138578 : return 67; 
+ // case  138579 : return 68;
+ // case  138578 : return 67;
   case  138534 : return 66; 
   case  138469 : return 65; 
   case  138442 : return 64; 
@@ -1149,7 +1284,7 @@ Int_t AliAnalysisTaskPi0v2::GetRunIndex(Int_t run){
 }
 
 //____________________________________________________________________________
-void AliAnalysisTaskPi0v2::GetV0EP(AliVEvent * event){
+void AliAnalysisTaskPi0v2::GetV0EP(AliVEvent * event,Double_t &rpv0a,Double_t &rpv0c){
 
     // Corrected VZERO EP (from AliAnalysisTaskPi0Flow)
 
@@ -1163,12 +1298,14 @@ void AliAnalysisTaskPi0v2::GetV0EP(AliVEvent * event){
     for (Int_t iv0 = 0; iv0 < 64; iv0++) {
        Double_t phiV0 = TMath::PiOver4()*(0.5 + iv0 % 8);
        Float_t multv0 = esdV0->GetMultiplicity(iv0);
+       Double_t lqx=TMath::Cos(fHarmonic*phiV0) * multv0*fV0Cpol/fMultV0->GetBinContent(iv0+1);
+       Double_t lqy=TMath::Sin(fHarmonic*phiV0) * multv0*fV0Cpol/fMultV0->GetBinContent(iv0+1);
        if (iv0 < 32){ // V0C
-           Qxc2 += TMath::Cos(2*phiV0) * multv0*fV0Cpol/fMultV0->GetBinContent(iv0+1);
-           Qyc2 += TMath::Sin(2*phiV0) * multv0*fV0Cpol/fMultV0->GetBinContent(iv0+1);
+           Qxc2 += lqx;
+           Qyc2 += lqy;
        } else {       // V0A
-           Qxa2 += TMath::Cos(2*phiV0) * multv0*fV0Apol/fMultV0->GetBinContent(iv0+1);
-           Qya2 += TMath::Sin(2*phiV0) * multv0*fV0Apol/fMultV0->GetBinContent(iv0+1);
+           Qxa2 += lqx;
+           Qya2 += lqy;
        }
     }
 
@@ -1199,27 +1336,24 @@ void AliAnalysisTaskPi0v2::GetV0EP(AliVEvent * event){
     Double_t QyaCor2 = (Qya2 - Qyamean2)/Qyarms2;
     Double_t QxcCor2 = (Qxc2 - Qxcmean2)/Qxcrms2;
     Double_t QycCor2 = (Qyc2 - Qycmean2)/Qycrms2;
+    rpv0a = TMath::ATan2(QyaCor2, QxaCor2)/Double_t(fHarmonic);
+    rpv0c = TMath::ATan2(QycCor2, QxcCor2)/Double_t(fHarmonic);
 
-    fRPV0A = TMath::ATan2(QyaCor2, QxaCor2)/2.;
-    fRPV0C = TMath::ATan2(QycCor2, QxcCor2)/2.;
+    //rpv0a = TMath::ATan2(Qya2, Qxa2)/Double_t(fHarmonic);
+    //rpv0c = TMath::ATan2(Qyc2, Qxc2)/Double_t(fHarmonic);
 
-    while(fRPV0A<0)fRPV0A+=TMath::Pi() ;
-    while(fRPV0A>TMath::Pi())fRPV0A-=TMath::Pi() ;
-    fRPV0A=ApplyFlatteningV0A(fRPV0A,fCentrality) ;
-    while(fRPV0A<0)fRPV0A+=TMath::Pi() ;
-    while(fRPV0A>TMath::Pi())fRPV0A-=TMath::Pi() ;
+   // cout<<"Compare v"<<fHarmonic<<" "<<rpv0a<<" "<<fInputEvent->GetEventplane()->GetEventplane("V0A",fInputEvent,fHarmonic)<<endl;
 
-    while(fRPV0C<0)fRPV0C+=TMath::Pi() ;
-    while(fRPV0C>TMath::Pi())fRPV0C-=TMath::Pi() ;
-    fRPV0C=ApplyFlatteningV0C(fRPV0C,fCentrality) ;
-    while(fRPV0C<0)fRPV0C+=TMath::Pi() ;
-    while(fRPV0C>TMath::Pi())fRPV0C-=TMath::Pi() ;
+    rpv0a=GetPsiInRange(rpv0a);
+    rpv0c=GetPsiInRange(rpv0c);
 
 }
 
-
 //_____________________________________________________________________________
 void AliAnalysisTaskPi0v2::OpenInfoCalibration(Int_t run){
+
+    // VZERO Phi Weights and Recentering
+
     TString oadbfilename = "$ALICE_ROOT/OADB/PWGCF/VZERO/VZEROcalibEP.root";
     TFile *foadb = TFile::Open(oadbfilename.Data());
 
@@ -1242,1158 +1376,515 @@ void AliAnalysisTaskPi0v2::OpenInfoCalibration(Int_t run){
     fMultV0 = ((TH2F *) cont->GetObject(run))->ProfileX();
 
     TF1 *fpol0 = new TF1("fpol0","pol0"); 
-    fMultV0->Fit(fpol0,"","",0,31);
+    fMultV0->Fit(fpol0,"0","",0,31);
     fV0Cpol = fpol0->GetParameter(0);
-    fMultV0->Fit(fpol0,"","",32,64);
+    fMultV0->Fit(fpol0,"0","",32,64);
     fV0Apol = fpol0->GetParameter(0);
 
     for(Int_t iside=0;iside<2;iside++){
        for(Int_t icoord=0;icoord<2;icoord++){
            for(Int_t i=0;i  < nCentrBinV0;i++){
                char namecont[100];
-               if(iside==0 && icoord==0)
-                   snprintf(namecont,100,"hQxc2_%i",i);
+
+               if(iside==0 && icoord==0)
+                   snprintf(namecont,100,"hQxc%i_%i",fHarmonic,i);
                else if(iside==1 && icoord==0)
-                   snprintf(namecont,100,"hQxa2_%i",i);
+                   snprintf(namecont,100,"hQxa%i_%i",fHarmonic,i);
                else if(iside==0 && icoord==1)
-                   snprintf(namecont,100,"hQyc2_%i",i);
+                   snprintf(namecont,100,"hQyc%i_%i",fHarmonic,i);
                else if(iside==1 && icoord==1)
-                   snprintf(namecont,100,"hQya2_%i",i);
+                   snprintf(namecont,100,"hQya%i_%i",fHarmonic,i);
 
                cont = (AliOADBContainer*) foadb->Get(namecont);
                if(!cont){
                    printf("OADB object %s is not available in the file\n",namecont);
-                   return;     
+                   return;
                }
-               
+
                if(!(cont->GetObject(run))){
                    printf("OADB object %s is not available for run %i (used run 137366)\n",namecont,run);
                    run = 137366;
                }
                fMeanQ[i][iside][icoord] = ((TH1F *) cont->GetObject(run))->GetMean();
                fWidthQ[i][iside][icoord] = ((TH1F *) cont->GetObject(run))->GetRMS();
+           }
+       }
+    }
 
-               //for v3
-               if(iside==0 && icoord==0)
-                   snprintf(namecont,100,"hQxc3_%i",i);
-               else if(iside==1 && icoord==0)
-                   snprintf(namecont,100,"hQxa3_%i",i);
-               else if(iside==0 && icoord==1)
-                   snprintf(namecont,100,"hQyc3_%i",i);
-               else if(iside==1 && icoord==1)
-                   snprintf(namecont,100,"hQya3_%i",i);
+    // TPC Event Plane Weights
+    AliOADBContainer *fEPContainer=NULL;
 
-               cont = (AliOADBContainer*) foadb->Get(namecont);
-               if(!cont){
-                   printf("OADB object %s is not available in the file\n",namecont);
-                   return;     
-               }
-               
-               if(!(cont->GetObject(run))){
-                   printf("OADB object %s is not available for run %i (used run 137366)\n",namecont,run);
-                   run = 137366;
+    if (run >= 136851 && run <= 139515){
+       // LHC10h
+
+       if(fIsAOD){
+           oadbfilename = (Form("%s/COMMON/EVENTPLANE/data/epphidist.aod.root", AliAnalysisManager::GetOADBPath()));
+       }
+       else{
+           oadbfilename = (Form("%s/COMMON/EVENTPLANE/data/epphidist.root", AliAnalysisManager::GetOADBPath()));
+       }
+
+       TFile foadb(oadbfilename);
+       if(!foadb.IsOpen()) AliFatal(Form("Cannot open OADB file %s", oadbfilename.Data()));
+
+       AliInfo("Using Standard OADB");
+       fEPContainer = (AliOADBContainer*) foadb.Get("epphidist");
+       if (!fEPContainer) AliFatal("Cannot fetch OADB container for EP selection");
+       foadb.Close();
+
+       fPhiDist[0] = (TH1F*) fEPContainer->GetObject(fRunNumber, "Default");
+
+       Bool_t emptybins;
+
+       int iter = 0;
+       while (iter<3){
+           emptybins = kFALSE;
+
+           for (int i=1; i<fPhiDist[0]->GetNbinsX(); i++){
+               if (!((fPhiDist[0]->GetBinContent(i))>0)) {
+                   emptybins = kTRUE;
                }
-               //              fMeanQv3[i][iside][icoord] = ((TH1F *) cont->GetObject(run))->GetMean();
-               //              fWidthQv3[i][iside][icoord] = ((TH1F *) cont->GetObject(run))->GetRMS();
+           }
+           if (emptybins) {
+               cout << "empty bins - rebinning!" << endl;
+               fPhiDist[0]->Rebin();
+               iter++;
+           }
+           else iter = 3;
+       }
 
+       if (emptybins) {
+           AliError("After Maximum of rebinning still empty Phi-bins!!!");
+       }
+    }
+
+    if (run >= 166529 && run <= 170593){
+        // LHC11h
+
+       oadbfilename = (Form("%s/COMMON/EVENTPLANE/data/epphidist2011.root", AliAnalysisManager::GetOADBPath()));
+       TFile *foadb = TFile::Open(oadbfilename);
+       if(!foadb->IsOpen()) AliFatal(Form("Cannot open OADB file %s", oadbfilename.Data()));
+
+       AliInfo("Using Standard OADB");
+       fSparseDist = (THnSparse*) foadb->Get("Default");
+       if (!fSparseDist) AliFatal("Cannot fetch OADB container for EP selection");
+       foadb->Close();
+       if(!fHruns){
+         fHruns = (TH1F*)fSparseDist->Projection(0); //projection on run axis;
+           fHruns->SetName("runsHisto");
+       }
+
+       Int_t runbin=fHruns->FindBin(fRunNumber);
+       if (fHruns->GetBinContent(runbin) > 1){
+           fSparseDist->GetAxis(0)->SetRange(runbin,runbin);
+       }
+       else if(fHruns->GetBinContent(runbin) < 2){
+           fSparseDist->GetAxis(0)->SetRange(1,2901); // not calibrated run, use integrated phi-weights
+           AliInfo("Using integrated Phi-weights for this run");
+       }
+       for (Int_t i = 0; i<4 ;i++)
+       {
+           if(fPhiDist[i]){
+               delete fPhiDist[i];
+               fPhiDist[i] = 0x0;
            }
+           if(i == 0){
+               fSparseDist->GetAxis(1)->SetRange(1,1);  // neg charge
+               fSparseDist->GetAxis(2)->SetRange(1,1);} // neg eta
+           if(i == 1){
+               fSparseDist->GetAxis(1)->SetRange(2,2);  // pos charge
+               fSparseDist->GetAxis(2)->SetRange(1,1);} // neg eta
+           if(i == 2){
+               fSparseDist->GetAxis(1)->SetRange(1,1);  // neg charge
+               fSparseDist->GetAxis(2)->SetRange(2,2);} // pos eta
+           if(i == 3){
+               fSparseDist->GetAxis(1)->SetRange(2,2);  // pos charge
+               fSparseDist->GetAxis(2)->SetRange(2,2);} // pos eta
+           fPhiDist[i] = (TH1F*)fSparseDist->Projection(3); // Projection on Phi
+           fPhiDist[i]->SetName(Form("phidist%d%d",i,fRunNumber));
+           fSparseDist->GetAxis(1)->SetRange(1,2); // reset axes
+           fSparseDist->GetAxis(2)->SetRange(1,2);
        }
+       fSparseDist->GetAxis(0)->SetRange(1,2901);// reset run axis
     }
+
+    if (!fPhiDist[0]) AliFatal(Form("Cannot find OADB phi distribution for run %d", run));
+
+}
+
+//_________________________________________________________________________
+Int_t AliAnalysisTaskPi0v2::GetAODEPTrackFilterBit(){
+
+    if(fUseTPCOnlyTracks){
+       return 128;// TPC only with vertex constraint
+    }
+    return 1;// Use Global Tracks
+}
+
+//_________________________________________________________________________
+TObjArray* AliAnalysisTaskPi0v2::GetEventPlaneTracks(Int_t &maxID)
+{
+    TObjArray *tracklist=NULL;
+
+    AliESDtrackCuts *fEPESDtrackCuts=AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();
+    fEPESDtrackCuts->SetPtRange(0.15,20.);
+    fEPESDtrackCuts->SetEtaRange(-0.8,0.8);
+
+    Int_t fAODfilterbit=GetAODEPTrackFilterBit();
+
+    if(fInputEvent->IsA()==AliESDEvent::Class()){
+       maxID=fInputEvent->GetNumberOfTracks();
+       tracklist=fEPESDtrackCuts->GetAcceptedTracks((AliESDEvent*)fInputEvent,fUseTPCOnlyTracks);
+    }
+    if(fInputEvent->IsA()==AliAODEvent::Class()){
+
+        // From AliEPSelectionTask
+       tracklist = new TObjArray();
+
+       AliAODTrack *tr = 0;
+       Int_t maxid1 = 0;
+       Int_t maxidtemp = -1;
+       Float_t ptlow = 0;
+       Float_t ptup = 0;
+       Float_t etalow = 0;
+       Float_t etaup = 0;
+       fEPESDtrackCuts->GetPtRange(ptlow,ptup);
+       fEPESDtrackCuts->GetEtaRange(etalow,etaup);
+       Int_t ntpc = fEPESDtrackCuts->GetMinNClusterTPC();
+
+       for (Int_t i = 0; i < fInputEvent->GetNumberOfTracks() ; i++){
+           tr = (AliAODTrack*)fInputEvent->GetTrack(i);
+           maxidtemp = tr->GetID();
+           if(maxidtemp < 0 && fAODfilterbit != 128) continue;// id<0 means filter bit 128
+           if(maxidtemp > -1 && fAODfilterbit == 128) continue;// id>01 means filter bit 1
+           if (fAODfilterbit == 128) maxidtemp = maxidtemp*(-1) - 1;
+           if (maxidtemp > maxid1) maxid1 = maxidtemp;
+           if(tr->TestFilterBit(fAODfilterbit) && tr->Pt() < ptup && tr->Pt() > ptlow && tr->Eta() < etaup && tr->Eta() > etalow && tr->GetTPCNcls() > ntpc){
+               tracklist->Add(tr);
+           }
+       }
+       maxID = maxid1;
+    }
+    delete fEPESDtrackCuts;
+    if(!tracklist)AliError("No tracklist");
+    return tracklist;
 }
 
 //____________________________________________________________________________
-Double_t  AliAnalysisTaskPi0v2::ApplyFlatteningV0A(Double_t phi, Double_t c){
-  //LHC10h
+Bool_t AliAnalysisTaskPi0v2::GetTPCEventPlane(){
+
+    if(fEP){
+       delete fEP;
+       fEP=NULL;
+    }
+    fEP=new AliEventplane();
+
+    float mQx=0, mQy=0;
+    float mQx1=0, mQy1=0, mQx2=0, mQy2=0;
+    AliVTrack* track;
+    Double_t weight;
+    Int_t idtemp = -1;
+    int trackcounter1=0, trackcounter2=0;
+
+    Int_t maxID=0;
+
+    TObjArray *tracklist=GetEventPlaneTracks(maxID);
+
+    fEP->GetQContributionXArray()->Set(maxID);
+    fEP->GetQContributionYArray()->Set(maxID);
+    fEP->GetQContributionXArraysub1()->Set(maxID);
+    fEP->GetQContributionYArraysub1()->Set(maxID);
+    fEP->GetQContributionXArraysub2()->Set(maxID);
+    fEP->GetQContributionYArraysub2()->Set(maxID);
+
+    int nt = tracklist->GetEntries();
+    for (int i=0; i<nt; i++){
+       weight = 1;
+       track = dynamic_cast<AliVTrack*> (tracklist->At(i));
+       if (track) {
+           // Fill Eta Distribution
+           hEtaTPCEP->Fill(fCentrality,track->Eta());
+
+           weight=GetWeight(track);
+           idtemp = track->GetID();
+           // TPC only tracks have negative id ((-1)*IDESD - 1) in AOD
+           if (fIsAOD && (fUseTPCOnlyTracks)) idtemp = idtemp*(-1) - 1;
+
+           Double_t qx=weight*cos(Double_t(fHarmonic)*track->Phi());
+           Double_t qy=weight*sin(Double_t(fHarmonic)*track->Phi());
+           fEP->GetQContributionXArray()->AddAt(qx,idtemp);
+           fEP->GetQContributionYArray()->AddAt(qy,idtemp);
+
+           mQx += (qx);
+           mQy += (qy);
+
+           // This loop splits the track set into 2 random subsets
+           if( trackcounter1 < int(nt/2.) && trackcounter2 < int(nt/2.)){
+               float random = fRandomizer->Rndm();
+               if(random < .5){
+                   mQx1 += (qx);
+                   mQy1 += (qy);
+                   fEP->GetQContributionXArraysub1()->AddAt(qx,idtemp);
+                   fEP->GetQContributionYArraysub1()->AddAt(qy,idtemp);
+                   trackcounter1++;
+                   }
+               else {
+                   mQx2 += (qx);
+                   mQy2 += (qy);
+                   fEP->GetQContributionXArraysub2()->AddAt(qx,idtemp);
+                   fEP->GetQContributionYArraysub2()->AddAt(qy,idtemp);
+                   trackcounter2++;
+               }
+           }
+           else{
+               if( trackcounter1 >= int(nt/2.)){
+                   mQx2 += (qx);
+                   mQy2 += (qy);
+                   fEP->GetQContributionXArraysub2()->AddAt(qx,idtemp);
+                   fEP->GetQContributionYArraysub2()->AddAt(qy,idtemp);
+                   trackcounter2++;
+               }
+               else {
+                   mQx1 += (qx);
+                   mQy1 += (qy);
+                   fEP->GetQContributionXArraysub1()->AddAt(qx,idtemp);
+                   fEP->GetQContributionYArraysub1()->AddAt(qy,idtemp);
+                   trackcounter1++;
+               }
+           }
+       }
+    }
 
-  Double_t v2c =0.;
-  Double_t v2s =0; 
+    tracklist->Clear();
+    delete tracklist;
+    tracklist = NULL;
 
-  if(fRunIndex==1){
-      v2c=0.00271301 + (0.00340046)*c + (-0.000376369)*c*c + (8.56362e-06)*c*c*c + (-5.70955e-08)*c*c*c*c ;
-      v2s=0.024278 + (0.000586593)*c + (-1.07748e-06)*c*c + (-5.01567e-07)*c*c*c + (3.65956e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==2){
-      v2c=0.111374 + (-0.0111331)*c + (0.000212342)*c*c + (-9.6774e-07)*c*c*c + (-2.54199e-09)*c*c*c*c ;
-      v2s=-0.0252636 + (0.0152193)*c + (-0.000830793)*c*c + (1.5099e-05)*c*c*c + (-9.04687e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==4){
-      v2c=-0.0323376 + (0.0058672)*c + (-0.000257135)*c*c + (3.54353e-06)*c*c*c + (-1.50431e-08)*c*c*c*c ;
-      v2s=0.0596758 + (-0.00520203)*c + (0.000178495)*c*c + (-2.94143e-06)*c*c*c + (1.55424e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==5){
-      v2c=-0.0415369 + (0.0098273)*c + (-0.000486907)*c*c + (8.00188e-06)*c*c*c + (-4.29107e-08)*c*c*c*c ;
-      v2s=-0.0146049 + (0.00693627)*c + (-0.000348663)*c*c + (5.79331e-06)*c*c*c + (-3.33179e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==6){
-      v2c=0.251902 + (-0.0415419)*c + (0.0018553)*c*c + (-3.15181e-05)*c*c*c + (1.80073e-07)*c*c*c*c ;
-      v2s=0.0771839 + (-0.00962468)*c + (0.000394453)*c*c + (-7.22485e-06)*c*c*c + (4.53562e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==7){
-      v2c=0.157038 + (-0.0204377)*c + (0.000847477)*c*c + (-1.4232e-05)*c*c*c + (8.04965e-08)*c*c*c*c ;
-      v2s=0.0256337 + (-0.00242333)*c + (0.000140455)*c*c + (-3.5149e-06)*c*c*c + (2.44854e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==8){
-      v2c=-0.0916108 + (0.0146996)*c + (-0.000624971)*c*c + (9.63331e-06)*c*c*c + (-4.8574e-08)*c*c*c*c ;
-      v2s=0.0332113 + (-0.00332475)*c + (0.000151857)*c*c + (-2.86187e-06)*c*c*c + (1.54796e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==9){
-      v2c=0.00925348 + (1.58854e-05)*c + (-3.85178e-05)*c*c + (6.75167e-07)*c*c*c + (-3.1502e-09)*c*c*c*c ;
-      v2s=0.0249253 + (-0.00300902)*c + (0.000152653)*c*c + (-3.20923e-06)*c*c*c + (2.08818e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==10){
-      v2c=0.040903 + (0.00142711)*c + (-0.000264675)*c*c + (6.50624e-06)*c*c*c + (-4.46628e-08)*c*c*c*c ;
-      v2s=0.0914196 + (-0.00957901)*c + (0.000408998)*c*c + (-7.49412e-06)*c*c*c + (4.63915e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==11){
-      v2c=-0.0130133 + (0.00296474)*c + (-0.000183518)*c*c + (3.65755e-06)*c*c*c + (-2.24484e-08)*c*c*c*c ;
-      v2s=-0.00449031 + (0.00365474)*c + (-0.000226455)*c*c + (4.49792e-06)*c*c*c + (-2.96018e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==12){
-      v2c=-0.021987 + (0.00506675)*c + (-0.000301768)*c*c + (5.66088e-06)*c*c*c + (-3.21447e-08)*c*c*c*c ;
-      v2s=0.0830858 + (-0.00871637)*c + (0.000299212)*c*c + (-4.10705e-06)*c*c*c + (1.76888e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==13){
-      v2c=0.0502952 + (-0.00152478)*c + (-0.000106289)*c*c + (3.39398e-06)*c*c*c + (-2.45015e-08)*c*c*c*c ;
-      v2s=0.0639936 + (-0.00775191)*c + (0.000347449)*c*c + (-6.46454e-06)*c*c*c + (4.00439e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==14){
-      v2c=-0.116922 + (0.0122105)*c + (-0.000373923)*c*c + (4.08464e-06)*c*c*c + (-1.05659e-08)*c*c*c*c ;
-      v2s=0.128821 + (-0.0204399)*c + (0.000831009)*c*c + (-1.33147e-05)*c*c*c + (7.24876e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==15){
-      v2c=0.0853741 + (-0.00924528)*c + (0.00034257)*c*c + (-5.69551e-06)*c*c*c + (3.44998e-08)*c*c*c*c ;
-      v2s=0.0205492 + (-0.00052015)*c + (-5.42051e-05)*c*c + (1.82754e-06)*c*c*c + (-1.58393e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==16){
-      v2c=-0.0233639 + (0.00703612)*c + (-0.000403314)*c*c + (7.45693e-06)*c*c*c + (-4.4522e-08)*c*c*c*c ;
-      v2s=-0.0712605 + (0.0124469)*c + (-0.000543644)*c*c + (8.22618e-06)*c*c*c + (-4.1073e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==17){
-      v2c=0.0113215 + (-0.0019788)*c + (9.81834e-05)*c*c + (-1.30009e-06)*c*c*c + (5.03998e-09)*c*c*c*c ;
-      v2s=0.0459851 + (-0.00170929)*c + (-5.96459e-05)*c*c + (2.90146e-06)*c*c*c + (-2.85325e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==18){
-      v2c=-0.0924521 + (0.0162203)*c + (-0.000702717)*c*c + (1.0269e-05)*c*c*c + (-4.632e-08)*c*c*c*c ;
-      v2s=-0.0456605 + (0.00706138)*c + (-0.000243957)*c*c + (2.7335e-06)*c*c*c + (-8.83296e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==19){
-      v2c=0.00150974 + (0.0113356)*c + (-0.000923111)*c*c + (2.0452e-05)*c*c*c + (-1.36949e-07)*c*c*c*c ;
-      v2s=0.0673845 + (-0.0187379)*c + (0.00112044)*c*c + (-2.19997e-05)*c*c*c + (1.33115e-07)*c*c*c*c ;
-  }
-  if(fRunIndex==20){
-      v2c=0.0223891 + (-0.000921021)*c + (-3.56276e-05)*c*c + (9.95622e-07)*c*c*c + (-5.54486e-09)*c*c*c*c ;
-      v2s=0.0657305 + (-0.00354234)*c + (2.90428e-05)*c*c + (5.82994e-07)*c*c*c + (-7.53656e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==21){
-      v2c=0.00969434 + (-0.00195313)*c + (3.56409e-05)*c*c + (2.15514e-07)*c*c*c + (-5.5161e-09)*c*c*c*c ;
-      v2s=0.000236584 + (0.00458234)*c + (-0.000306408)*c*c + (6.04476e-06)*c*c*c + (-3.79354e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==22){
-      v2c=0.0973536 + (-0.00907174)*c + (0.000239041)*c*c + (-2.64399e-06)*c*c*c + (1.12038e-08)*c*c*c*c ;
-      v2s=0.0506578 + (-0.00256521)*c + (1.53982e-05)*c*c + (4.18193e-07)*c*c*c + (-4.99622e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==23){
-      v2c=0.120714 + (-0.0190965)*c + (0.000887955)*c*c + (-1.57144e-05)*c*c*c + (9.22823e-08)*c*c*c*c ;
-      v2s=-0.00178837 + (0.00377706)*c + (-0.000358619)*c*c + (9.54949e-06)*c*c*c + (-7.39141e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==24){
-      v2c=0.0593053 + (-0.00687397)*c + (0.000200607)*c*c + (-2.34483e-06)*c*c*c + (9.60642e-09)*c*c*c*c ;
-      v2s=0.0235174 + (0.00219788)*c + (-0.000225065)*c*c + (4.9594e-06)*c*c*c + (-3.2695e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==25){
-      v2c=0.0551353 + (-0.00340874)*c + (2.26718e-05)*c*c + (4.1675e-07)*c*c*c + (-3.37457e-09)*c*c*c*c ;
-      v2s=0.0110038 + (-0.000180543)*c + (3.28645e-05)*c*c + (-1.08119e-06)*c*c*c + (6.7157e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==26){
-      v2c=-0.0138673 + (0.00475006)*c + (-0.00030584)*c*c + (6.0294e-06)*c*c*c + (-3.69906e-08)*c*c*c*c ;
-      v2s=0.0395065 + (-0.00331262)*c + (9.40592e-05)*c*c + (-1.1541e-06)*c*c*c + (4.38329e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==27){
-      v2c=0.0547504 + (-0.00669067)*c + (0.000269785)*c*c + (-4.75217e-06)*c*c*c + (2.96254e-08)*c*c*c*c ;
-      v2s=0.101508 + (-0.0107211)*c + (0.000385539)*c*c + (-6.28713e-06)*c*c*c + (3.75932e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==28){
-      v2c=-0.102173 + (0.0158262)*c + (-0.000706394)*c*c + (1.14263e-05)*c*c*c + (-6.14646e-08)*c*c*c*c ;
-      v2s=0.02013 + (9.82197e-05)*c + (-1.71572e-05)*c*c + (-7.69646e-08)*c*c*c + (1.45113e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==29){
-      v2c=0.100539 + (-0.0115012)*c + (0.000295367)*c*c + (-2.57489e-06)*c*c*c + (5.41526e-09)*c*c*c*c ;
-      v2s=0.138027 + (-0.00342397)*c + (-0.000392569)*c*c + (1.34626e-05)*c*c*c + (-1.06683e-07)*c*c*c*c ;
-  }
-  if(fRunIndex==30){
-      v2c=0.0695326 + (-0.00752755)*c + (0.000237872)*c*c + (-3.31513e-06)*c*c*c + (1.69653e-08)*c*c*c*c ;
-      v2s=0.0290133 + (-0.00073999)*c + (-3.35653e-05)*c*c + (7.61029e-07)*c*c*c + (-2.95792e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==31){
-      v2c=-0.103171 + (0.0134058)*c + (-0.000631602)*c*c + (1.10298e-05)*c*c*c + (-6.41177e-08)*c*c*c*c ;
-      v2s=-0.137648 + (0.0111259)*c + (-0.000400035)*c*c + (5.90535e-06)*c*c*c + (-3.24676e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==32){
-      v2c=0.0522957 + (-0.00718492)*c + (0.000288586)*c*c + (-5.14534e-06)*c*c*c + (3.31303e-08)*c*c*c*c ;
-      v2s=0.0731685 + (-0.00469449)*c + (9.57641e-05)*c*c + (-1.11891e-06)*c*c*c + (6.13984e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==33){
-      v2c=0.0882828 + (-0.00916109)*c + (0.00027821)*c*c + (-3.61312e-06)*c*c*c + (1.76418e-08)*c*c*c*c ;
-      v2s=0.123302 + (-0.0156303)*c + (0.000623468)*c*c + (-9.83474e-06)*c*c*c + (5.24687e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==34){
-      v2c=0.0848636 + (-0.0142808)*c + (0.000723319)*c*c + (-1.32627e-05)*c*c*c + (7.77064e-08)*c*c*c*c ;
-      v2s=-0.138483 + (0.0268553)*c + (-0.0013585)*c*c + (2.56034e-05)*c*c*c + (-1.63065e-07)*c*c*c*c ;
-  }
-  if(fRunIndex==35){
-      v2c=-0.0134575 + (0.00267433)*c + (-0.000168784)*c*c + (3.24012e-06)*c*c*c + (-1.92766e-08)*c*c*c*c ;
-      v2s=0.0596795 + (-0.00350808)*c + (2.97282e-05)*c*c + (3.52115e-07)*c*c*c + (-4.17462e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==36){
-      v2c=0.0784813 + (-0.00718389)*c + (0.000145303)*c*c + (-1.40121e-06)*c*c*c + (7.52775e-09)*c*c*c*c ;
-      v2s=-0.0439181 + (0.0101363)*c + (-0.000494075)*c*c + (8.43356e-06)*c*c*c + (-4.68549e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==37){
-      v2c=-0.0118549 + (0.00328751)*c + (-0.000207156)*c*c + (3.92678e-06)*c*c*c + (-2.30059e-08)*c*c*c*c ;
-      v2s=0.0344878 + (-0.000363669)*c + (-7.62481e-05)*c*c + (1.67135e-06)*c*c*c + (-9.64004e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==38){
-      v2c=-0.0254171 + (0.00297494)*c + (-0.000122361)*c*c + (1.78861e-06)*c*c*c + (-7.87609e-09)*c*c*c*c ;
-      v2s=-0.0321399 + (0.00705636)*c + (-0.000325906)*c*c + (5.17669e-06)*c*c*c + (-2.86143e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==39){
-      v2c=-0.0368721 + (0.00253133)*c + (-0.000136793)*c*c + (2.51874e-06)*c*c*c + (-1.46055e-08)*c*c*c*c ;
-      v2s=-0.0757763 + (0.005728)*c + (-0.000217489)*c*c + (3.11936e-06)*c*c*c + (-1.56919e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==40){
-      v2c=0.0166884 + (0.000509256)*c + (-0.000117911)*c*c + (2.65839e-06)*c*c*c + (-1.60875e-08)*c*c*c*c ;
-      v2s=0.0336629 + (-0.00123023)*c + (-4.90123e-05)*c*c + (2.17862e-06)*c*c*c + (-1.98445e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==41){
-      v2c=-0.00887514 + (0.00491344)*c + (-0.000325782)*c*c + (6.54782e-06)*c*c*c + (-4.14143e-08)*c*c*c*c ;
-      v2s=0.0720999 + (-0.00650524)*c + (0.000214752)*c*c + (-3.19681e-06)*c*c*c + (1.64573e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==42){
-      v2c=-0.0495903 + (0.00428229)*c + (-0.000181618)*c*c + (2.3913e-06)*c*c*c + (-8.55469e-09)*c*c*c*c ;
-      v2s=0.0127982 + (-0.00690065)*c + (0.000342707)*c*c + (-6.40515e-06)*c*c*c + (3.83973e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==43){
-      v2c=0.0196783 + (-0.000221524)*c + (-7.09556e-05)*c*c + (1.76517e-06)*c*c*c + (-1.19612e-08)*c*c*c*c ;
-      v2s=0.0350359 + (-0.0020458)*c + (5.18727e-05)*c*c + (-6.58401e-07)*c*c*c + (1.10936e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==44){
-      v2c=-0.0196041 + (0.00257682)*c + (-0.000174854)*c*c + (3.2168e-06)*c*c*c + (-1.85569e-08)*c*c*c*c ;
-      v2s=-0.0870278 + (0.00634528)*c + (-0.000273588)*c*c + (4.77944e-06)*c*c*c + (-2.98422e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==45){
-      v2c=-0.0105827 + (0.00271714)*c + (-0.000152357)*c*c + (2.71899e-06)*c*c*c + (-1.5435e-08)*c*c*c*c ;
-      v2s=0.135579 + (-0.0135952)*c + (0.000424184)*c*c + (-5.12316e-06)*c*c*c + (1.84497e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==46){
-      v2c=-0.017755 + (0.00411137)*c + (-0.000231724)*c*c + (4.17641e-06)*c*c*c + (-2.39164e-08)*c*c*c*c ;
-      v2s=-0.0198628 + (0.0010032)*c + (-4.9708e-05)*c*c + (7.12455e-07)*c*c*c + (-4.22231e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==47){
-      v2c=-0.0111387 + (0.00258591)*c + (-0.000194287)*c*c + (3.84062e-06)*c*c*c + (-2.37192e-08)*c*c*c*c ;
-      v2s=-0.0478616 + (0.00365349)*c + (-0.000152037)*c*c + (2.24323e-06)*c*c*c + (-1.23308e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==48){
-      v2c=0.070344 + (-0.0137332)*c + (0.000638536)*c*c + (-1.188e-05)*c*c*c + (7.4801e-08)*c*c*c*c ;
-      v2s=-0.00208823 + (-0.00314157)*c + (9.9553e-05)*c*c + (-8.73891e-07)*c*c*c + (-1.72944e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==51){
-      v2c=0.017789 + (-0.00598224)*c + (0.000328477)*c*c + (-6.80787e-06)*c*c*c + (4.46905e-08)*c*c*c*c ;
-      v2s=-0.0894734 + (0.007351)*c + (-0.000291085)*c*c + (4.38654e-06)*c*c*c + (-2.32261e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==52){
-      v2c=0.0555614 + (-0.00430576)*c + (0.00011519)*c*c + (-1.81584e-06)*c*c*c + (1.19214e-08)*c*c*c*c ;
-      v2s=0.0901479 + (-0.0091505)*c + (0.000343757)*c*c + (-5.71204e-06)*c*c*c + (3.31217e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==53){
-      v2c=0.0181761 + (-0.00186378)*c + (4.60531e-05)*c*c + (-7.59581e-07)*c*c*c + (5.52465e-09)*c*c*c*c ;
-      v2s=0.0456713 + (-0.00526813)*c + (0.000232978)*c*c + (-3.98724e-06)*c*c*c + (2.10384e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==54){
-      v2c=0.0456225 + (-0.00611173)*c + (0.000228414)*c*c + (-3.70527e-06)*c*c*c + (2.10774e-08)*c*c*c*c ;
-      v2s=-0.00553874 + (0.00501799)*c + (-0.000331323)*c*c + (6.96978e-06)*c*c*c + (-4.72472e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==55){
-      v2c=-0.0578879 + (0.00664986)*c + (-0.000335443)*c*c + (6.0086e-06)*c*c*c + (-3.54293e-08)*c*c*c*c ;
-      v2s=-0.0675269 + (0.00407581)*c + (-0.000148063)*c*c + (1.922e-06)*c*c*c + (-8.8635e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==56){
-      v2c=-0.000898903 + (0.00199222)*c + (-0.000207257)*c*c + (4.46148e-06)*c*c*c + (-2.71361e-08)*c*c*c*c ;
-      v2s=-0.103794 + (0.0198667)*c + (-0.000879042)*c*c + (1.43177e-05)*c*c*c + (-8.09672e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==57){
-      v2c=0.00953087 + (0.000947327)*c + (-3.45822e-05)*c*c + (-4.22294e-07)*c*c*c + (9.08727e-09)*c*c*c*c ;
-      v2s=0.0662314 + (-0.0076136)*c + (0.000288482)*c*c + (-4.82931e-06)*c*c*c + (2.67751e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==58){
-      v2c=0.00682728 + (-0.000293407)*c + (-2.88037e-05)*c*c + (6.63629e-07)*c*c*c + (-3.93121e-09)*c*c*c*c ;
-      v2s=0.0085365 + (0.00138919)*c + (-8.15068e-05)*c*c + (1.26437e-06)*c*c*c + (-7.50322e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==59){
-      v2c=-0.0185226 + (0.00377881)*c + (-0.000226383)*c*c + (4.22897e-06)*c*c*c + (-2.51383e-08)*c*c*c*c ;
-      v2s=-0.222605 + (0.0100699)*c + (-0.00029256)*c*c + (3.3855e-06)*c*c*c + (-1.33648e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==60){
-      v2c=-0.00111322 + (0.00291259)*c + (-0.000215769)*c*c + (4.13355e-06)*c*c*c + (-2.36883e-08)*c*c*c*c ;
-      v2s=0.033686 + (-0.00124534)*c + (1.52616e-05)*c*c + (-2.99302e-07)*c*c*c + (1.05198e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==61){
-      v2c=0.00041873 + (-0.000231092)*c + (1.19226e-05)*c*c + (-6.29604e-07)*c*c*c + (7.26582e-09)*c*c*c*c ;
-      v2s=0.00435438 + (0.0025265)*c + (-0.000153028)*c*c + (2.71169e-06)*c*c*c + (-1.67127e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==62){
-      v2c=-0.0573899 + (0.00972389)*c + (-0.000495772)*c*c + (9.0103e-06)*c*c*c + (-5.45756e-08)*c*c*c*c ;
-      v2s=0.00702691 + (0.00698504)*c + (-0.000541929)*c*c + (1.19971e-05)*c*c*c + (-8.26942e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==63){
-      v2c=0.047222 + (-0.00604037)*c + (0.0002092)*c*c + (-3.07144e-06)*c*c*c + (1.68579e-08)*c*c*c*c ;
-      v2s=0.0568815 + (-0.00607571)*c + (0.000244243)*c*c + (-4.22237e-06)*c*c*c + (2.38928e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==64){
-      v2c=0.0464686 + (-0.00463482)*c + (0.000146379)*c*c + (-2.23008e-06)*c*c*c + (1.29549e-08)*c*c*c*c ;
-      v2s=-0.00571995 + (0.00273485)*c + (-0.000131945)*c*c + (2.08986e-06)*c*c*c + (-1.26717e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==65){
-      v2c=0.0544794 + (-0.00616918)*c + (0.000173808)*c*c + (-2.01338e-06)*c*c*c + (8.78123e-09)*c*c*c*c ;
-      v2s=0.0557002 + (-0.00701287)*c + (0.000340418)*c*c + (-6.12754e-06)*c*c*c + (3.3384e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==66){
-      v2c=0.0111176 + (0.000262254)*c + (-7.20349e-05)*c*c + (1.38755e-06)*c*c*c + (-6.65016e-09)*c*c*c*c ;
-      v2s=0.0644184 + (-0.00518515)*c + (0.000174227)*c*c + (-2.7347e-06)*c*c*c + (1.29547e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==67){
-      v2c=-0.0481037 + (0.00823686)*c + (-0.000418053)*c*c + (7.40186e-06)*c*c*c + (-4.19609e-08)*c*c*c*c ;
-      v2s=0.0560171 + (-0.002556)*c + (2.54529e-05)*c*c + (-5.22269e-09)*c*c*c + (-2.19983e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==68){
-      v2c=-0.0139809 + (0.00274305)*c + (-0.00017744)*c*c + (3.20286e-06)*c*c*c + (-1.74137e-08)*c*c*c*c ;
-      v2s=-0.218673 + (0.00764806)*c + (-0.000222739)*c*c + (3.14656e-06)*c*c*c + (-1.73548e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==69){
-      v2c=0.0736938 + (-0.0122004)*c + (0.000498227)*c*c + (-8.08779e-06)*c*c*c + (4.52749e-08)*c*c*c*c ;
-      v2s=-0.236254 + (0.00979816)*c + (-0.000280698)*c*c + (3.4103e-06)*c*c*c + (-1.47299e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==70){
-      v2c=-0.0366545 + (0.00399604)*c + (-0.000196876)*c*c + (3.49686e-06)*c*c*c + (-2.01142e-08)*c*c*c*c ;
-      v2s=0.0220911 + (-0.000529459)*c + (9.10408e-06)*c*c + (-3.57334e-07)*c*c*c + (1.87909e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==71){
-      v2c=-0.039698 + (0.00654615)*c + (-0.000323865)*c*c + (5.50998e-06)*c*c*c + (-3.00866e-08)*c*c*c*c ;
-      v2s=0.0650078 + (-0.00502636)*c + (0.000128459)*c*c + (-1.3877e-06)*c*c*c + (3.21917e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==72){
-      v2c=0.0594227 + (-0.00872513)*c + (0.000368684)*c*c + (-6.34986e-06)*c*c*c + (3.79523e-08)*c*c*c*c ;
-      v2s=0.050348 + (-0.00512087)*c + (0.000228643)*c*c + (-4.40797e-06)*c*c*c + (2.62482e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==73){
-      v2c=0.131281 + (-0.0162697)*c + (0.000584063)*c*c + (-8.64349e-06)*c*c*c + (4.61009e-08)*c*c*c*c ;
-      v2s=0.0271721 + (-0.000487039)*c + (1.60624e-05)*c*c + (-5.38029e-07)*c*c*c + (2.08589e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==74){
-      v2c=-0.0128651 + (0.00946426)*c + (-0.00055547)*c*c + (9.37245e-06)*c*c*c + (-4.78224e-08)*c*c*c*c ;
-      v2s=0.0903476 + (-0.0164972)*c + (0.000927481)*c*c + (-1.88459e-05)*c*c*c + (1.20249e-07)*c*c*c*c ;
-  }
-  if(fRunIndex==75){
-      v2c=0.0204147 + (-0.00139139)*c + (-2.47732e-05)*c*c + (1.1214e-06)*c*c*c + (-7.22533e-09)*c*c*c*c ;
-      v2s=0.0214247 + (-0.000147929)*c + (-7.58241e-06)*c*c + (-7.05565e-08)*c*c*c + (-4.86528e-10)*c*c*c*c ;
-  }
-  if(fRunIndex==76){
-      v2c=0.0469095 + (-0.00541793)*c + (0.000133238)*c*c + (-1.14334e-06)*c*c*c + (3.4826e-09)*c*c*c*c ;
-      v2s=0.0304763 + (-0.00213957)*c + (8.27588e-05)*c*c + (-1.34495e-06)*c*c*c + (4.81134e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==77){
-      v2c=0.113822 + (-0.0154286)*c + (0.000574533)*c*c + (-8.67874e-06)*c*c*c + (4.76727e-08)*c*c*c*c ;
-      v2s=0.010623 + (0.00513467)*c + (-0.000372733)*c*c + (7.40692e-06)*c*c*c + (-4.64093e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==78){
-      v2c=0.020658 + (-0.00274725)*c + (5.8872e-05)*c*c + (-3.43999e-07)*c*c*c + (-1.04273e-10)*c*c*c*c ;
-      v2s=0.00219379 + (0.000972033)*c + (-1.41816e-05)*c*c + (-4.41149e-07)*c*c*c + (3.81037e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==79){
-      v2c=0.227324 + (-0.0264915)*c + (0.000915298)*c*c + (-1.3343e-05)*c*c*c + (7.1044e-08)*c*c*c*c ;
-      v2s=0.0474072 + (-0.00939515)*c + (0.000730108)*c*c + (-1.80811e-05)*c*c*c + (1.3003e-07)*c*c*c*c ;
-  }
-  if(fRunIndex==81){
-      v2c=-0.0368028 + (0.00368927)*c + (-0.000228321)*c*c + (4.48174e-06)*c*c*c + (-2.75298e-08)*c*c*c*c ;
-      v2s=-0.238807 + (0.0108667)*c + (-0.000350649)*c*c + (4.95568e-06)*c*c*c + (-2.53022e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==82){
-      v2c=-0.0214072 + (0.00119258)*c + (-7.80215e-05)*c*c + (1.37682e-06)*c*c*c + (-7.31103e-09)*c*c*c*c ;
-      v2s=-0.233825 + (0.00735109)*c + (-0.000142737)*c*c + (9.15013e-07)*c*c*c + (-1.98463e-10)*c*c*c*c ;
-  }
-  if(fRunIndex==83){
-      v2c=-0.0716708 + (0.00855289)*c + (-0.00037249)*c*c + (6.41638e-06)*c*c*c + (-3.66318e-08)*c*c*c*c ;
-      v2s=-0.329702 + (0.033231)*c + (-0.00131012)*c*c + (2.1101e-05)*c*c*c + (-1.18905e-07)*c*c*c*c ;
-  }
-  if(fRunIndex==84){
-      v2c=-0.0259022 + (0.00711773)*c + (-0.000434778)*c*c + (8.94774e-06)*c*c*c + (-5.84408e-08)*c*c*c*c ;
-      v2s=-0.0936287 + (-0.00455282)*c + (0.000390982)*c*c + (-7.95224e-06)*c*c*c + (4.95612e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==85){
-      v2c=0.0263223 + (-0.00475593)*c + (9.63236e-05)*c*c + (-4.95311e-07)*c*c*c + (-5.47428e-10)*c*c*c*c ;
-      v2s=-0.220593 + (0.00823892)*c + (-0.000248477)*c*c + (3.28082e-06)*c*c*c + (-1.45098e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==86){
-      v2c=-0.0157962 + (0.00408922)*c + (-0.000282087)*c*c + (5.81961e-06)*c*c*c + (-3.6481e-08)*c*c*c*c ;
-      v2s=0.0340979 + (-0.00139471)*c + (6.48561e-06)*c*c + (3.02184e-08)*c*c*c + (-1.05879e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==87){
-      v2c=0.0577366 + (-0.00471394)*c + (0.000107329)*c*c + (-7.28927e-07)*c*c*c + (-1.51199e-09)*c*c*c*c ;
-      v2s=0.0350171 + (-0.00402687)*c + (0.00016046)*c*c + (-2.39625e-06)*c*c*c + (9.98146e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==88){
-      v2c=-0.00547971 + (0.00161905)*c + (-0.00013831)*c*c + (2.94662e-06)*c*c*c + (-1.92504e-08)*c*c*c*c ;
-      v2s=-0.0722251 + (0.0127634)*c + (-0.000612284)*c*c + (1.07553e-05)*c*c*c + (-6.34054e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==89){
-      v2c=0.165574 + (-0.0241913)*c + (0.00101221)*c*c + (-1.62279e-05)*c*c*c + (8.77252e-08)*c*c*c*c ;
-      v2s=0.0692954 + (-0.0147219)*c + (0.00068782)*c*c + (-1.11091e-05)*c*c*c + (5.37295e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==91){
-      v2c=-0.0334666 + (0.00583866)*c + (-0.000329883)*c*c + (6.08932e-06)*c*c*c + (-3.59853e-08)*c*c*c*c ;
-      v2s=-0.229775 + (0.010061)*c + (-0.00028144)*c*c + (3.3231e-06)*c*c*c + (-1.40799e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==95){
-      v2c=-0.0993203 + (0.0150547)*c + (-0.000713531)*c*c + (1.22733e-05)*c*c*c + (-6.98669e-08)*c*c*c*c ;
-      v2s=-0.217746 + (0.0068375)*c + (-0.000171962)*c*c + (2.05506e-06)*c*c*c + (-8.78703e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==96){
-      v2c=-0.0398801 + (0.00406028)*c + (-0.000214066)*c*c + (3.69056e-06)*c*c*c + (-1.99339e-08)*c*c*c*c ;
-      v2s=-0.240195 + (0.00782806)*c + (-0.000131365)*c*c + (3.18193e-07)*c*c*c + (4.88009e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==97){
-      v2c=-0.0325538 + (0.00250986)*c + (-0.000136762)*c*c + (2.35572e-06)*c*c*c + (-1.23413e-08)*c*c*c*c ;
-      v2s=-0.240415 + (0.010435)*c + (-0.000291848)*c*c + (3.35357e-06)*c*c*c + (-1.35833e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==98){
-      v2c=-0.00692338 + (0.00379335)*c + (-0.000332833)*c*c + (7.35052e-06)*c*c*c + (-4.89956e-08)*c*c*c*c ;
-      v2s=-0.263042 + (0.0134291)*c + (-0.000465334)*c*c + (7.09595e-06)*c*c*c + (-3.90332e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==101){
-      v2c=-0.049409 + (0.0073433)*c + (-0.000376933)*c*c + (7.39945e-06)*c*c*c + (-4.967e-08)*c*c*c*c ;
-      v2s=0.00564511 + (-0.00101958)*c + (0.000121077)*c*c + (-3.44889e-06)*c*c*c + (2.42733e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==102){
-      v2c=-0.0393185 + (0.00610331)*c + (-0.000286099)*c*c + (4.61693e-06)*c*c*c + (-2.44104e-08)*c*c*c*c ;
-      v2s=-0.00898987 + (0.00463766)*c + (-0.000269122)*c*c + (5.46456e-06)*c*c*c + (-3.85677e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==103){
-      v2c=-0.0171815 + (0.00271616)*c + (-9.49063e-05)*c*c + (5.68888e-07)*c*c*c + (2.77777e-09)*c*c*c*c ;
-      v2s=-0.0348362 + (0.00661647)*c + (-0.000196625)*c*c + (1.60914e-06)*c*c*c + (-4.34769e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==104){
-      v2c=0.0453893 + (-0.00220981)*c + (-6.34642e-05)*c*c + (2.5268e-06)*c*c*c + (-1.81319e-08)*c*c*c*c ;
-      v2s=0.0131555 + (0.00115036)*c + (-5.70975e-05)*c*c + (5.20224e-07)*c*c*c + (-3.11332e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==105){
-      v2c=0.0052505 + (0.000251094)*c + (-3.95143e-05)*c*c + (5.6354e-07)*c*c*c + (-1.86603e-09)*c*c*c*c ;
-      v2s=0.079882 + (-0.00841369)*c + (0.000342924)*c*c + (-5.64554e-06)*c*c*c + (2.89511e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==106){
-      v2c=0.0561693 + (-0.00693389)*c + (0.000243013)*c*c + (-3.7816e-06)*c*c*c + (2.21666e-08)*c*c*c*c ;
-      v2s=0.115847 + (-0.0145063)*c + (0.000597908)*c*c + (-9.37418e-06)*c*c*c + (4.57406e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==107){
-      v2c=-0.160892 + (0.0259075)*c + (-0.00120084)*c*c + (1.99814e-05)*c*c*c + (-1.09708e-07)*c*c*c*c ;
-      v2s=0.0922001 + (-0.00861465)*c + (0.000196846)*c*c + (-5.34939e-07)*c*c*c + (-1.20442e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==108){
-      v2c=0.0325605 + (-0.00795036)*c + (0.000436987)*c*c + (-9.37794e-06)*c*c*c + (6.59912e-08)*c*c*c*c ;
-      v2s=0.0894763 + (-0.00694006)*c + (0.000214928)*c*c + (-3.05745e-06)*c*c*c + (1.33679e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==109){
-      v2c=-8.30505e-05 + (0.00304264)*c + (-0.000228365)*c*c + (4.43511e-06)*c*c*c + (-2.5788e-08)*c*c*c*c ;
-      v2s=0.0276356 + (-0.000486726)*c + (-1.12152e-05)*c*c + (1.56258e-07)*c*c*c + (-2.17826e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==112){
-      v2c=0.0273919 + (-0.00243837)*c + (2.41667e-05)*c*c + (3.06367e-07)*c*c*c + (-3.9028e-09)*c*c*c*c ;
-      v2s=0.0119428 + (0.00161447)*c + (-0.00010526)*c*c + (1.76239e-06)*c*c*c + (-1.12844e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==114){
-      v2c=0.114287 + (-0.016125)*c + (0.000673002)*c*c + (-1.11635e-05)*c*c*c + (6.39533e-08)*c*c*c*c ;
-      v2s=0.0353709 + (-0.00169691)*c + (-3.93183e-05)*c*c + (2.08815e-06)*c*c*c + (-2.03159e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==115){
-      v2c=-0.0109276 + (0.00378322)*c + (-0.000252651)*c*c + (4.599e-06)*c*c*c + (-2.36568e-08)*c*c*c*c ;
-      v2s=0.0185448 + (0.00102852)*c + (-6.04966e-05)*c*c + (5.89933e-07)*c*c*c + (-2.5921e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==116){
-      v2c=-0.117563 + (0.00405449)*c + (-0.000112806)*c*c + (4.01903e-06)*c*c*c + (-4.25358e-08)*c*c*c*c ;
-      v2s=0.0280797 + (-0.00528592)*c + (0.000375784)*c*c + (-9.96825e-06)*c*c*c + (7.72147e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==117){
-      v2c=0.0301869 + (-0.000751512)*c + (-9.43748e-05)*c*c + (2.60697e-06)*c*c*c + (-1.73948e-08)*c*c*c*c ;
-      v2s=0.0594442 + (-0.00499442)*c + (0.000170617)*c*c + (-2.80903e-06)*c*c*c + (1.51075e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==118){
-      v2c=0.0118942 + (-0.000669595)*c + (-3.6634e-05)*c*c + (1.40794e-06)*c*c*c + (-1.15253e-08)*c*c*c*c ;
-      v2s=-0.0174395 + (0.00460355)*c + (-0.00023192)*c*c + (3.83941e-06)*c*c*c + (-2.30761e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==119){
-      v2c=0.018229 + (-0.00144698)*c + (-1.07295e-06)*c*c + (6.22528e-07)*c*c*c + (-4.90504e-09)*c*c*c*c ;
-      v2s=0.0122761 + (0.000985351)*c + (-6.02936e-05)*c*c + (9.41867e-07)*c*c*c + (-6.59756e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==120){
-      v2c=-0.0968065 + (0.0131861)*c + (-0.000585224)*c*c + (9.82175e-06)*c*c*c + (-5.51313e-08)*c*c*c*c ;
-      v2s=0.0719334 + (-0.00752912)*c + (0.000362464)*c*c + (-6.65114e-06)*c*c*c + (3.70295e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==121){
-      v2c=0.0296329 + (-0.00448004)*c + (0.00010239)*c*c + (-2.40647e-07)*c*c*c + (-5.4555e-09)*c*c*c*c ;
-      v2s=0.0774925 + (-0.00635491)*c + (0.0001939)*c*c + (-3.04755e-06)*c*c*c + (1.66055e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==122){
-      v2c=0.00956939 + (0.000460793)*c + (-0.000105912)*c*c + (2.38286e-06)*c*c*c + (-1.446e-08)*c*c*c*c ;
-      v2s=0.0152677 + (0.00345263)*c + (-0.000262399)*c*c + (5.5895e-06)*c*c*c + (-3.84974e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==123){
-      v2c=0.0495618 + (-0.00059293)*c + (-0.00025227)*c*c + (6.61088e-06)*c*c*c + (-4.24063e-08)*c*c*c*c ;
-      v2s=0.0862227 + (-0.0190161)*c + (0.0010647)*c*c + (-1.94957e-05)*c*c*c + (1.08665e-07)*c*c*c*c ;
-  }
-  if(fRunIndex==124){
-      v2c=-0.0408078 + (0.00565108)*c + (-0.00027528)*c*c + (5.2165e-06)*c*c*c + (-3.3244e-08)*c*c*c*c ;
-      v2s=0.00169862 + (0.00371982)*c + (-0.000169757)*c*c + (2.07347e-06)*c*c*c + (-8.30142e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==125){
-      v2c=0.0285065 + (-0.00348583)*c + (0.000106189)*c*c + (-1.56726e-06)*c*c*c + (9.40552e-09)*c*c*c*c ;
-      v2s=0.0363645 + (-0.00252206)*c + (0.000122553)*c*c + (-2.74066e-06)*c*c*c + (1.66856e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==126){
-      v2c=-0.00864424 + (0.00157555)*c + (-0.000127367)*c*c + (2.47447e-06)*c*c*c + (-1.42302e-08)*c*c*c*c ;
-      v2s=-0.213003 + (0.00643156)*c + (-0.000121219)*c*c + (6.06838e-07)*c*c*c + (1.48381e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==127){
-      v2c=-0.0336884 + (0.00299236)*c + (-0.000147557)*c*c + (2.47908e-06)*c*c*c + (-1.33495e-08)*c*c*c*c ;
-      v2s=-0.271925 + (0.0158755)*c + (-0.000583802)*c*c + (9.14376e-06)*c*c*c + (-5.05302e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==128){
-      v2c=-0.0639711 + (0.00822881)*c + (-0.000428416)*c*c + (7.98075e-06)*c*c*c + (-4.81995e-08)*c*c*c*c ;
-      v2s=-0.22634 + (0.00908632)*c + (-0.00029)*c*c + (4.14095e-06)*c*c*c + (-2.15823e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==129){
-      v2c=0.0652753 + (-0.00529737)*c + (0.000133883)*c*c + (-1.63339e-06)*c*c*c + (7.88294e-09)*c*c*c*c ;
-      v2s=0.00357003 + (0.00503303)*c + (-0.000316531)*c*c + (6.45793e-06)*c*c*c + (-4.44467e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==131){
-      v2c=0.117255 + (-0.0149009)*c + (0.000560178)*c*c + (-8.75754e-06)*c*c*c + (4.85024e-08)*c*c*c*c ;
-      v2s=-0.00180786 + (0.00224258)*c + (-9.84056e-05)*c*c + (1.39525e-06)*c*c*c + (-7.63512e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==132){
-      v2c=0.0100287 + (-0.00051338)*c + (-2.7702e-05)*c*c + (5.0205e-07)*c*c*c + (-1.12682e-09)*c*c*c*c ;
-      v2s=0.00556895 + (0.00211082)*c + (-0.000125448)*c*c + (2.30409e-06)*c*c*c + (-1.63703e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==133){
-      v2c=-0.00755913 + (0.00327793)*c + (-0.00024545)*c*c + (5.03417e-06)*c*c*c + (-3.11617e-08)*c*c*c*c ;
-      v2s=0.0398477 + (-0.000728372)*c + (-2.63935e-05)*c*c + (7.85276e-07)*c*c*c + (-7.72703e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==134){
-      v2c=0.00344056 + (0.000171769)*c + (-8.00887e-05)*c*c + (1.76696e-06)*c*c*c + (-1.08652e-08)*c*c*c*c ;
-      v2s=-0.200474 + (0.00736532)*c + (-0.000221809)*c*c + (2.91763e-06)*c*c*c + (-1.40827e-08)*c*c*c*c ;
-  }
-  if(fRunIndex==135){
-      v2c=-0.0251554 + (0.00227996)*c + (-0.000133757)*c*c + (2.50604e-06)*c*c*c + (-1.48528e-08)*c*c*c*c ;
-      v2s=-0.229223 + (0.0091122)*c + (-0.000245035)*c*c + (2.64826e-06)*c*c*c + (-9.57268e-09)*c*c*c*c ;
-  }
-  if(fRunIndex==136){
-      v2c=-0.0308547 + (0.00209237)*c + (-0.000183034)*c*c + (4.54164e-06)*c*c*c + (-3.26557e-08)*c*c*c*c ;
-      v2s=-0.241702 + (0.00988355)*c + (-0.000263014)*c*c + (2.73376e-06)*c*c*c + (-9.79971e-09)*c*c*c*c ;
-  }
+    TVector2 *mQ=new TVector2();
+    mQ->Set(mQx,mQy);
+    Double_t EPAngle=mQ->Phi()/Double_t(fHarmonic);
+   
+    TVector2 *fQsub1=new TVector2();
+    TVector2 *fQsub2=new TVector2();
+    fQsub1->Set(mQx1,mQy1);
+    fQsub2->Set(mQx2,mQy2);
 
-/*  
-  
-  if(fRunIndex>=1 && fRunIndex<=45){ // 137161 -137848 //period 1
-//    v2c = 1.133676e-02-1.759454e-04*x-6.217033e-05*x*x+1.532507e-06*x*x*x-9.665265e-09*x*x*x*x;
-//    v2s = 2.173690e-02-8.410340e-04*x-1.391841e-05*x*x+5.003301e-07*x*x*x-4.175974e-09*x*x*x*x;
-    v2c=2.295070e-02-1.050171e-03*x-3.432843e-05*x*x+1.156549e-06*x*x*x-7.781377e-09*x*x*x*x ;
-    v2s=3.994886e-02-1.961957e-03*x+1.641958e-05*x*x+1.234025e-07*x*x*x-2.175698e-09*x*x*x*x ;
-  }
-  if(fRunIndex>=46 && fRunIndex<=58){ //138125-138275//period 2
-    v2c =-1.394612e-03+1.333726e-03*x-1.115323e-04*x*x+2.103762e-06*x*x*x-1.186760e-08*x*x*x*x ;
-    v2s =-7.788201e-03+7.178984e-04*x-4.553597e-05*x*x+6.941817e-07*x*x*x-4.465249e-09*x*x*x*x ;
-  }
-  if(fRunIndex>=59 && fRunIndex<=78){ //138359-138730//period 3
-    v2c = 1.448809e-02+-7.894029e-04*x-2.693871e-05*x*x+7.944017e-07*x*x*x-4.272135e-09*x*x*x*x ;
-    v2s = 3.442216e-03+-5.574560e-05*x-1.758343e-05*x*x+2.386547e-07*x*x*x-2.404210e-09*x*x*x*x ;
-  }
-  if(fRunIndex>=79){//period 4
-    v2c =-1.553536e-03+7.761106e-04*x-9.529723e-05*x*x+2.026750e-06*x*x*x-1.217009e-08*x*x*x*x ;
-    v2s =-7.787317e-02+3.843455e-03*x-1.221144e-04*x*x+1.478448e-06*x*x*x-7.442702e-09*x*x*x*x ;
-  }
-*/  
-  
-  return phi+v2c*TMath::Sin(2.*phi)-v2s*TMath::Cos(2.*phi) ;
+    fEP->SetQVector(mQ);
+    fEP->SetEventplaneQ(EPAngle);
+    fEP->SetQsub(fQsub1,fQsub2);
+    fEP->SetQsubRes(fQsub1->Phi()/Double_t(fHarmonic) - fQsub2->Phi()/Double_t(fHarmonic));
 
+    return kTRUE;
 }
+
+
 //____________________________________________________________________________
-Double_t  AliAnalysisTaskPi0v2::ApplyFlatteningV0C(Double_t phi, Double_t c){
-  //LHC10h
+Double_t AliAnalysisTaskPi0v2::ApplyFlattening(Double_t phi,EEventPlane ep){
 
-    Double_t v2c =0.;
-    Double_t v2s =0;
+    Double_t c2=0;
+    Double_t s2=0;
+    Double_t c4=0;
+    Double_t s4=0;
 
-    if(fRunIndex==1){
-       v2c=-0.038901 + (0.00539521)*c + (-0.000213271)*c*c + (3.01147e-06)*c*c*c + (-1.35977e-08)*c*c*c*c ;
-       v2s=0.0693294 + (-0.00851319)*c + (0.000337408)*c*c + (-5.33097e-06)*c*c*c + (2.90883e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==2){
-       v2c=-0.0943695 + (0.0137829)*c + (-0.000569334)*c*c + (8.95522e-06)*c*c*c + (-4.78396e-08)*c*c*c*c ;
-       v2s=0.00971525 + (-0.00181026)*c + (6.15798e-05)*c*c + (-8.51046e-07)*c*c*c + (4.57403e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==4){
-       v2c=-0.00585475 + (0.000307793)*c + (1.89109e-06)*c*c + (-3.14804e-07)*c*c*c + (3.54341e-09)*c*c*c*c ;
-       v2s=0.00374568 + (-0.00123435)*c + (8.01941e-05)*c*c + (-1.70807e-06)*c*c*c + (1.14576e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==5){
-       v2c=-0.0301267 + (0.00206698)*c + (-4.82282e-05)*c*c + (4.39355e-07)*c*c*c + (-1.3747e-09)*c*c*c*c ;
-       v2s=-0.0441947 + (0.00501774)*c + (-0.000181736)*c*c + (2.69235e-06)*c*c*c + (-1.37411e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==6){
-       v2c=0.190652 + (-0.0254912)*c + (0.00105707)*c*c + (-1.63872e-05)*c*c*c + (8.51113e-08)*c*c*c*c ;
-       v2s=0.0803124 + (-0.0119724)*c + (0.000575997)*c*c + (-1.07892e-05)*c*c*c + (6.67214e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==7){
-       v2c=0.00875044 + (-0.00343147)*c + (0.0002198)*c*c + (-4.76292e-06)*c*c*c + (3.24844e-08)*c*c*c*c ;
-       v2s=-0.081288 + (0.0146429)*c + (-0.000728327)*c*c + (1.32462e-05)*c*c*c + (-7.95362e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==8){
-       v2c=0.0381367 + (-0.0082048)*c + (0.000410914)*c*c + (-7.28851e-06)*c*c*c + (4.22008e-08)*c*c*c*c ;
-       v2s=-0.023338 + (0.003381)*c + (-0.000167791)*c*c + (3.13998e-06)*c*c*c + (-1.97233e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==9){
-       v2c=-0.00734261 + (0.00121272)*c + (-5.31181e-05)*c*c + (7.88974e-07)*c*c*c + (-3.86356e-09)*c*c*c*c ;
-       v2s=-0.0228333 + (0.00266052)*c + (-0.000112824)*c*c + (1.89515e-06)*c*c*c + (-1.07446e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==10){
-       v2c=-0.0456385 + (0.0102956)*c + (-0.000529689)*c*c + (9.62809e-06)*c*c*c + (-5.7301e-08)*c*c*c*c ;
-       v2s=0.0142197 + (-0.0031677)*c + (0.000190389)*c*c + (-4.10911e-06)*c*c*c + (2.81791e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==11){
-       v2c=-0.00999249 + (0.00123939)*c + (-4.23895e-05)*c*c + (6.55415e-07)*c*c*c + (-3.98256e-09)*c*c*c*c ;
-       v2s=-0.00809817 + (0.00199727)*c + (-0.000116718)*c*c + (2.33449e-06)*c*c*c + (-1.46407e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==12){
-       v2c=0.0183566 + (-0.0020805)*c + (6.79726e-05)*c*c + (-7.96708e-07)*c*c*c + (3.1214e-09)*c*c*c*c ;
-       v2s=-0.00714715 + (0.000721418)*c + (-3.50355e-05)*c*c + (9.09996e-07)*c*c*c + (-7.92198e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==13){
-       v2c=0.0056915 + (0.000167211)*c + (-4.68018e-05)*c*c + (1.21891e-06)*c*c*c + (-8.70124e-09)*c*c*c*c ;
-       v2s=0.00986223 + (-0.00247957)*c + (0.000133539)*c*c + (-2.51362e-06)*c*c*c + (1.5397e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==14){
-       v2c=0.0479623 + (-0.00948196)*c + (0.000551795)*c*c + (-1.05692e-05)*c*c*c + (6.38754e-08)*c*c*c*c ;
-       v2s=-0.00438456 + (-0.00152976)*c + (2.00645e-05)*c*c + (9.91017e-07)*c*c*c + (-1.35776e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==15){
-       v2c=-0.00384088 + (0.00121719)*c + (-6.88665e-05)*c*c + (1.26138e-06)*c*c*c + (-7.13987e-09)*c*c*c*c ;
-       v2s=0.0273017 + (-0.00314818)*c + (7.85031e-05)*c*c + (-9.07336e-08)*c*c*c + (-6.42421e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==16){
-       v2c=-0.0313175 + (0.00368025)*c + (-0.000126895)*c*c + (1.7443e-06)*c*c*c + (-9.12442e-09)*c*c*c*c ;
-       v2s=-0.0812178 + (0.0117402)*c + (-0.000506287)*c*c + (8.36766e-06)*c*c*c + (-4.69866e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==17){
-       v2c=0.062893 + (-0.0128204)*c + (0.000591931)*c*c + (-1.00835e-05)*c*c*c + (5.72782e-08)*c*c*c*c ;
-       v2s=-0.143105 + (0.0183921)*c + (-0.000787289)*c*c + (1.33237e-05)*c*c*c + (-7.71707e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==18){
-       v2c=-0.0029353 + (-0.0016097)*c + (0.000199618)*c*c + (-5.42008e-06)*c*c*c + (4.08897e-08)*c*c*c*c ;
-       v2s=0.0482015 + (-0.00115233)*c + (3.96019e-05)*c*c + (-7.7193e-07)*c*c*c + (3.90004e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==19){
-       v2c=-0.0397728 + (0.0129154)*c + (-0.000703903)*c*c + (1.30972e-05)*c*c*c + (-7.93547e-08)*c*c*c*c ;
-       v2s=0.181945 + (-0.0289807)*c + (0.00133685)*c*c + (-2.30866e-05)*c*c*c + (1.32746e-07)*c*c*c*c ;
-    }
-    if(fRunIndex==20){
-       v2c=-0.00927858 + (0.0021033)*c + (-0.000113971)*c*c + (2.17508e-06)*c*c*c + (-1.36812e-08)*c*c*c*c ;
-       v2s=0.0201645 + (-0.00331311)*c + (0.000164916)*c*c + (-3.08376e-06)*c*c*c + (1.92565e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==21){
-       v2c=-0.0254895 + (0.00388685)*c + (-0.000171429)*c*c + (2.87209e-06)*c*c*c + (-1.60625e-08)*c*c*c*c ;
-       v2s=0.00237609 + (0.000664255)*c + (-4.93436e-05)*c*c + (8.86415e-07)*c*c*c + (-4.51913e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==22){
-       v2c=0.0308671 + (-0.00365824)*c + (0.000148483)*c*c + (-2.52946e-06)*c*c*c + (1.49859e-08)*c*c*c*c ;
-       v2s=-0.00805023 + (0.00154452)*c + (-6.89678e-05)*c*c + (1.14317e-06)*c*c*c + (-5.98991e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==23){
-       v2c=0.122018 + (-0.0233973)*c + (0.00116385)*c*c + (-2.11232e-05)*c*c*c + (1.25836e-07)*c*c*c*c ;
-       v2s=-0.0511879 + (0.00708815)*c + (-0.000227282)*c*c + (2.27542e-06)*c*c*c + (-4.83128e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==24){
-       v2c=0.00888562 + (-0.000839847)*c + (2.52839e-05)*c*c + (-2.28921e-07)*c*c*c + (1.01057e-11)*c*c*c*c ;
-       v2s=0.00814357 + (-0.000788997)*c + (2.43948e-05)*c*c + (-2.99558e-07)*c*c*c + (1.21675e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==25){
-       v2c=0.00360833 + (0.000379977)*c + (-3.68193e-05)*c*c + (5.86861e-07)*c*c*c + (-2.01826e-09)*c*c*c*c ;
-       v2s=-0.00642047 + (0.00060076)*c + (-2.42907e-05)*c*c + (4.12933e-07)*c*c*c + (-2.3557e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==26){
-       v2c=-0.0131971 + (0.00189761)*c + (-7.7551e-05)*c*c + (1.25884e-06)*c*c*c + (-7.38989e-09)*c*c*c*c ;
-       v2s=0.00679891 + (-0.000614692)*c + (1.04559e-06)*c*c + (4.34463e-07)*c*c*c + (-4.75821e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==27){
-       v2c=-0.00887089 + (0.00126865)*c + (-7.15766e-05)*c*c + (1.43811e-06)*c*c*c + (-9.408e-09)*c*c*c*c ;
-       v2s=-0.0302105 + (0.00349565)*c + (-0.000126108)*c*c + (1.835e-06)*c*c*c + (-9.27845e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==28){
-       v2c=-0.0187616 + (0.0021974)*c + (-5.11412e-05)*c*c + (2.94628e-07)*c*c*c + (7.4194e-10)*c*c*c*c ;
-       v2s=-0.0119204 + (-0.00156879)*c + (0.000132746)*c*c + (-2.67371e-06)*c*c*c + (1.61097e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==29){
-       v2c=-0.121018 + (0.0228924)*c + (-0.00127093)*c*c + (2.48724e-05)*c*c*c + (-1.56121e-07)*c*c*c*c ;
-       v2s=-0.0687197 + (0.015702)*c + (-0.000764074)*c*c + (1.38991e-05)*c*c*c + (-8.48812e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==30){
-       v2c=0.01582 + (-0.0012293)*c + (1.62768e-05)*c*c + (2.36172e-07)*c*c*c + (-3.67153e-09)*c*c*c*c ;
-       v2s=-0.00875651 + (0.00135376)*c + (-5.16763e-05)*c*c + (6.17614e-07)*c*c*c + (-1.64099e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==31){
-       v2c=-0.044721 + (0.00756113)*c + (-0.000365759)*c*c + (6.15804e-06)*c*c*c + (-3.40075e-08)*c*c*c*c ;
-       v2s=-0.0500828 + (-0.000695112)*c + (0.000130909)*c*c + (-3.38476e-06)*c*c*c + (2.41179e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==32){
-       v2c=0.0306236 + (-0.00443307)*c + (0.000196517)*c*c + (-3.48059e-06)*c*c*c + (2.10266e-08)*c*c*c*c ;
-       v2s=0.00819214 + (-0.000560558)*c + (-5.03783e-06)*c*c + (4.37862e-07)*c*c*c + (-3.93834e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==33){
-       v2c=0.0120077 + (-0.00139976)*c + (5.85677e-05)*c*c + (-9.06209e-07)*c*c*c + (4.61403e-09)*c*c*c*c ;
-       v2s=-0.0197677 + (0.00253589)*c + (-0.000101374)*c*c + (1.59347e-06)*c*c*c + (-8.65961e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==34){
-       v2c=0.0759546 + (-0.0131538)*c + (0.000577001)*c*c + (-9.39636e-06)*c*c*c + (5.16814e-08)*c*c*c*c ;
-       v2s=-0.0727864 + (0.00956655)*c + (-0.000406191)*c*c + (7.50453e-06)*c*c*c + (-4.93819e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==35){
-       v2c=-0.00622564 + (0.00107647)*c + (-6.25644e-05)*c*c + (1.28553e-06)*c*c*c + (-8.46286e-09)*c*c*c*c ;
-       v2s=0.0051704 + (-0.00165348)*c + (8.69531e-05)*c*c + (-1.69895e-06)*c*c*c + (1.09762e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==36){
-       v2c=0.0117872 + (-0.000807391)*c + (-1.70999e-05)*c*c + (1.19089e-06)*c*c*c + (-1.13278e-08)*c*c*c*c ;
-       v2s=-0.000162495 + (1.04465e-05)*c + (-1.07156e-05)*c*c + (2.54308e-07)*c*c*c + (-7.04948e-10)*c*c*c*c ;
-    }
-    if(fRunIndex==37){
-       v2c=-0.0119236 + (0.00290105)*c + (-0.000162086)*c*c + (3.22645e-06)*c*c*c + (-2.07075e-08)*c*c*c*c ;
-       v2s=-0.0178535 + (0.00283024)*c + (-0.00012812)*c*c + (2.02404e-06)*c*c*c + (-1.0248e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==38){
-       v2c=0.023002 + (-0.00433112)*c + (0.000229879)*c*c + (-4.52792e-06)*c*c*c + (2.92715e-08)*c*c*c*c ;
-       v2s=-0.0217933 + (0.00235291)*c + (-0.000108054)*c*c + (2.08937e-06)*c*c*c + (-1.3524e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==39){
-       v2c=0.00795585 + (-0.000372683)*c + (1.85243e-05)*c*c + (-4.28133e-07)*c*c*c + (3.02452e-09)*c*c*c*c ;
-       v2s=-0.0849826 + (0.00529466)*c + (-0.000163148)*c*c + (2.1186e-06)*c*c*c + (-9.48208e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==40){
-       v2c=0.00653019 + (-0.00127651)*c + (7.59264e-05)*c*c + (-1.6363e-06)*c*c*c + (1.11375e-08)*c*c*c*c ;
-       v2s=-0.0107686 + (0.000982587)*c + (-2.97061e-05)*c*c + (4.04795e-07)*c*c*c + (-1.91289e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==41){
-       v2c=0.012007 + (-0.00102703)*c + (3.48714e-05)*c*c + (-5.13011e-07)*c*c*c + (2.57827e-09)*c*c*c*c ;
-       v2s=-0.00713083 + (0.00101952)*c + (-4.7675e-05)*c*c + (9.12723e-07)*c*c*c + (-5.99694e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==42){
-       v2c=-0.0486696 + (0.00723345)*c + (-0.000324232)*c*c + (5.25317e-06)*c*c*c + (-2.78981e-08)*c*c*c*c ;
-       v2s=-0.0485877 + (-0.00064506)*c + (9.15858e-05)*c*c + (-1.97486e-06)*c*c*c + (1.28831e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==43){
-       v2c=0.0003541 + (-0.000236832)*c + (1.82448e-05)*c*c + (-4.20764e-07)*c*c*c + (2.96882e-09)*c*c*c*c ;
-       v2s=0.00107616 + (-0.000462058)*c + (2.46761e-05)*c*c + (-4.33199e-07)*c*c*c + (2.47324e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==44){
-       v2c=-0.0778259 + (0.0128797)*c + (-0.000514371)*c*c + (7.70095e-06)*c*c*c + (-3.89026e-08)*c*c*c*c ;
-       v2s=-0.106839 + (0.00670369)*c + (-0.000184721)*c*c + (1.64581e-06)*c*c*c + (-1.47049e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==45){
-       v2c=0.0513049 + (-0.00715356)*c + (0.000289106)*c*c + (-4.46938e-06)*c*c*c + (2.36599e-08)*c*c*c*c ;
-       v2s=-0.0252464 + (0.00170124)*c + (-3.04376e-05)*c*c + (9.4935e-08)*c*c*c + (9.41807e-10)*c*c*c*c ;
-    }
-    if(fRunIndex==46){
-       v2c=0.0317697 + (-0.00121243)*c + (5.94543e-05)*c*c + (-1.26341e-06)*c*c*c + (8.49329e-09)*c*c*c*c ;
-       v2s=-0.092276 + (0.00299941)*c + (-5.24713e-05)*c*c + (3.07331e-07)*c*c*c + (7.44139e-10)*c*c*c*c ;
-    }
-    if(fRunIndex==47){
-       v2c=0.0429796 + (-0.000861588)*c + (6.82123e-07)*c*c + (1.96388e-07)*c*c*c + (-1.56984e-09)*c*c*c*c ;
-       v2s=-0.133047 + (0.00853153)*c + (-0.000287983)*c*c + (4.1155e-06)*c*c*c + (-2.00239e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==48){
-       v2c=0.0480979 + (-0.000354969)*c + (-6.45176e-05)*c*c + (2.34807e-06)*c*c*c + (-1.9069e-08)*c*c*c*c ;
-       v2s=-0.138315 + (0.0126874)*c + (-0.000672052)*c*c + (1.34449e-05)*c*c*c + (-8.64756e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==51){
-       v2c=-0.0114422 + (0.00506157)*c + (-0.000227041)*c*c + (3.97457e-06)*c*c*c + (-2.35322e-08)*c*c*c*c ;
-       v2s=-0.208135 + (0.0160488)*c + (-0.000536132)*c*c + (7.2714e-06)*c*c*c + (-3.28328e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==52){
-       v2c=0.00113321 + (0.000922798)*c + (-6.5971e-05)*c*c + (1.40416e-06)*c*c*c + (-9.29905e-09)*c*c*c*c ;
-       v2s=0.0550392 + (-0.00725661)*c + (0.000298984)*c*c + (-4.85473e-06)*c*c*c + (2.72063e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==53){
-       v2c=-0.003508 + (6.54451e-06)*c + (1.28603e-05)*c*c + (-3.83674e-07)*c*c*c + (3.1053e-09)*c*c*c*c ;
-       v2s=0.00714978 + (-0.00198147)*c + (0.000113909)*c*c + (-2.1949e-06)*c*c*c + (1.34933e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==54){
-       v2c=-0.0024598 + (5.87979e-05)*c + (9.36516e-06)*c*c + (-2.66045e-07)*c*c*c + (1.80016e-09)*c*c*c*c ;
-       v2s=-0.00651135 + (0.00109883)*c + (-4.41501e-05)*c*c + (6.19398e-07)*c*c*c + (-2.61977e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==55){
-       v2c=0.0472936 + (-0.00156718)*c + (3.03713e-05)*c*c + (-1.97139e-07)*c*c*c + (-3.55205e-10)*c*c*c*c ;
-       v2s=-0.155014 + (0.00717506)*c + (-0.000168137)*c*c + (1.55419e-06)*c*c*c + (-3.64579e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==56){
-       v2c=0.011328 + (0.000924574)*c + (-6.803e-05)*c*c + (9.76956e-07)*c*c*c + (-2.90494e-09)*c*c*c*c ;
-       v2s=-0.0412661 + (0.0107218)*c + (-0.000533108)*c*c + (9.75563e-06)*c*c*c + (-5.95608e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==57){
-       v2c=0.00900452 + (0.000588343)*c + (-3.02208e-05)*c*c + (2.13239e-07)*c*c*c + (9.25727e-10)*c*c*c*c ;
-       v2s=0.13086 + (-0.0204768)*c + (0.000928956)*c*c + (-1.63917e-05)*c*c*c + (9.8273e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==58){
-       v2c=-0.0143951 + (0.00247373)*c + (-0.000107909)*c*c + (1.69603e-06)*c*c*c + (-9.05555e-09)*c*c*c*c ;
-       v2s=-0.0209397 + (0.00180446)*c + (-5.97034e-05)*c*c + (8.17388e-07)*c*c*c + (-3.77989e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==59){
-       v2c=-0.0619279 + (0.00393575)*c + (-0.00011867)*c*c + (1.45001e-06)*c*c*c + (-5.98792e-09)*c*c*c*c ;
-       v2s=-0.248103 + (0.0158553)*c + (-0.000529631)*c*c + (7.46158e-06)*c*c*c + (-3.60091e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==60){
-       v2c=-0.00886115 + (0.00152741)*c + (-6.94062e-05)*c*c + (1.11727e-06)*c*c*c + (-5.81351e-09)*c*c*c*c ;
-       v2s=-0.000911417 + (0.000122344)*c + (-1.24605e-06)*c*c + (-6.29249e-08)*c*c*c + (8.81971e-10)*c*c*c*c ;
-    }
-    if(fRunIndex==61){
-       v2c=-0.00510166 + (0.00040596)*c + (-4.37341e-06)*c*c + (-1.15302e-07)*c*c*c + (1.53428e-09)*c*c*c*c ;
-       v2s=-0.0170123 + (0.00220818)*c + (-9.50905e-05)*c*c + (1.59566e-06)*c*c*c + (-8.92053e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==62){
-       v2c=-0.00332885 + (-0.000430498)*c + (5.60341e-05)*c*c + (-1.47922e-06)*c*c*c + (1.09723e-08)*c*c*c*c ;
-       v2s=-0.0519534 + (0.00892818)*c + (-0.000434243)*c*c + (7.8407e-06)*c*c*c + (-4.69363e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==63){
-       v2c=-0.00176529 + (0.00123097)*c + (-6.59677e-05)*c*c + (1.24591e-06)*c*c*c + (-7.90285e-09)*c*c*c*c ;
-       v2s=-0.0181792 + (0.00222004)*c + (-7.96902e-05)*c*c + (1.13047e-06)*c*c*c + (-5.72272e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==64){
-       v2c=0.00546184 + (-0.000449463)*c + (1.50833e-05)*c*c + (-1.72501e-07)*c*c*c + (3.58774e-10)*c*c*c*c ;
-       v2s=0.013284 + (-0.00260671)*c + (0.000134403)*c*c + (-2.461e-06)*c*c*c + (1.47694e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==65){
-       v2c=0.0108447 + (-0.0017699)*c + (4.62716e-05)*c*c + (-3.4647e-07)*c*c*c + (5.24536e-10)*c*c*c*c ;
-       v2s=0.0302247 + (-0.00605136)*c + (0.000290676)*c*c + (-4.87706e-06)*c*c*c + (2.65104e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==66){
-       v2c=-0.0100092 + (0.00144457)*c + (-6.512e-05)*c*c + (1.05356e-06)*c*c*c + (-5.52231e-09)*c*c*c*c ;
-       v2s=-0.00380228 + (0.000610003)*c + (-3.47943e-05)*c*c + (7.21188e-07)*c*c*c + (-4.76727e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==67){
-       v2c=-0.0229901 + (0.00400737)*c + (-0.000206024)*c*c + (3.93038e-06)*c*c*c + (-2.46388e-08)*c*c*c*c ;
-       v2s=-0.00286041 + (0.000648607)*c + (-2.37397e-05)*c*c + (2.0372e-07)*c*c*c + (2.97679e-10)*c*c*c*c ;
-    }
-    if(fRunIndex==68){
-       v2c=-0.0603647 + (0.0045685)*c + (-0.000171555)*c*c + (2.66377e-06)*c*c*c + (-1.45892e-08)*c*c*c*c ;
-       v2s=-0.21447 + (0.00909524)*c + (-0.000265298)*c*c + (3.73262e-06)*c*c*c + (-1.84484e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==69){
-       v2c=-0.0207879 + (0.000139613)*c + (1.27802e-05)*c*c + (-6.40328e-07)*c*c*c + (6.35949e-09)*c*c*c*c ;
-       v2s=-0.266459 + (0.0156802)*c + (-0.000481647)*c*c + (6.4597e-06)*c*c*c + (-3.047e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==70){
-       v2c=-0.0324843 + (0.00376852)*c + (-0.000136873)*c*c + (2.01389e-06)*c*c*c + (-1.03877e-08)*c*c*c*c ;
-       v2s=-0.0178378 + (0.00145491)*c + (-3.55421e-05)*c*c + (2.25993e-07)*c*c*c + (7.06258e-10)*c*c*c*c ;
-    }
-    if(fRunIndex==71){
-       v2c=-0.0138645 + (0.00167315)*c + (-6.68544e-05)*c*c + (1.07133e-06)*c*c*c + (-5.92659e-09)*c*c*c*c ;
-       v2s=0.0359716 + (-0.00461076)*c + (0.000192868)*c*c + (-3.21409e-06)*c*c*c + (1.84468e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==72){
-       v2c=0.0111712 + (-0.00175546)*c + (6.87862e-05)*c*c + (-8.99029e-07)*c*c*c + (3.44492e-09)*c*c*c*c ;
-       v2s=-0.00352823 + (0.000480673)*c + (-2.66091e-05)*c*c + (5.54922e-07)*c*c*c + (-3.84534e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==73){
-       v2c=-0.000939145 + (-0.000235945)*c + (2.51908e-05)*c*c + (-6.52435e-07)*c*c*c + (4.8218e-09)*c*c*c*c ;
-       v2s=0.00666852 + (-0.000373105)*c + (-1.22838e-05)*c*c + (7.3621e-07)*c*c*c + (-7.2867e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==74){
-       v2c=0.0474235 + (-0.00890967)*c + (0.000427741)*c*c + (-7.38723e-06)*c*c*c + (4.17242e-08)*c*c*c*c ;
-       v2s=0.0142517 + (-0.00326338)*c + (0.000142729)*c*c + (-2.27831e-06)*c*c*c + (1.14084e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==75){
-       v2c=0.0237808 + (-0.00310491)*c + (0.000134288)*c*c + (-2.27429e-06)*c*c*c + (1.32749e-08)*c*c*c*c ;
-       v2s=-0.0258905 + (0.00417719)*c + (-0.000193901)*c*c + (3.41383e-06)*c*c*c + (-2.01695e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==76){
-       v2c=0.0149865 + (-0.00140739)*c + (4.24537e-05)*c*c + (-4.06273e-07)*c*c*c + (5.44496e-10)*c*c*c*c ;
-       v2s=0.00820134 + (-0.000519432)*c + (6.82211e-06)*c*c + (1.06291e-07)*c*c*c + (-1.65344e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==77){
-       v2c=0.048123 + (-0.00608197)*c + (0.000246409)*c*c + (-4.05028e-06)*c*c*c + (2.33536e-08)*c*c*c*c ;
-       v2s=-0.0214729 + (0.0029389)*c + (-0.000133826)*c*c + (2.29845e-06)*c*c*c + (-1.29253e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==78){
-       v2c=-0.0172924 + (0.00202216)*c + (-6.478e-05)*c*c + (8.08739e-07)*c*c*c + (-3.73211e-09)*c*c*c*c ;
-       v2s=-0.0355638 + (0.00121518)*c + (3.97839e-05)*c*c + (-1.62346e-06)*c*c*c + (1.27105e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==79){
-       v2c=0.040762 + (-0.00311921)*c + (6.66868e-05)*c*c + (-1.18554e-06)*c*c*c + (1.07519e-08)*c*c*c*c ;
-       v2s=-0.00558438 + (-0.00154821)*c + (0.000165732)*c*c + (-4.56377e-06)*c*c*c + (3.56988e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==81){
-       v2c=-0.0247995 + (0.00179444)*c + (-0.000102085)*c*c + (2.31093e-06)*c*c*c + (-1.61924e-08)*c*c*c*c ;
-       v2s=-0.249009 + (0.0133297)*c + (-0.000415717)*c*c + (5.84494e-06)*c*c*c + (-2.88179e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==82){
-       v2c=-0.0249921 + (0.00199208)*c + (-7.86121e-05)*c*c + (1.40547e-06)*c*c*c + (-9.39651e-09)*c*c*c*c ;
-       v2s=-0.254469 + (0.0150694)*c + (-0.000499848)*c*c + (7.08318e-06)*c*c*c + (-3.40806e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==83){
-       v2c=-0.0721 + (0.00951559)*c + (-0.000431762)*c*c + (8.4632e-06)*c*c*c + (-5.79485e-08)*c*c*c*c ;
-       v2s=-0.00864625 + (-0.00706196)*c + (0.000313773)*c*c + (-5.10066e-06)*c*c*c + (2.9662e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==84){
-       v2c=-0.0198112 + (-0.0062788)*c + (0.000353589)*c*c + (-5.70525e-06)*c*c*c + (2.82617e-08)*c*c*c*c ;
-       v2s=-0.0704647 + (0.0031015)*c + (-0.000244985)*c*c + (6.17258e-06)*c*c*c + (-4.43331e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==85){
-       v2c=-0.0161955 + (-0.0017361)*c + (0.000130612)*c*c + (-2.9548e-06)*c*c*c + (2.05684e-08)*c*c*c*c ;
-       v2s=-0.204119 + (0.00714989)*c + (-0.000162549)*c*c + (1.87459e-06)*c*c*c + (-7.79143e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==86){
-       v2c=0.00995155 + (-0.00196822)*c + (0.00010617)*c*c + (-2.01071e-06)*c*c*c + (1.22728e-08)*c*c*c*c ;
-       v2s=0.0148901 + (-0.002581)*c + (0.000132002)*c*c + (-2.44601e-06)*c*c*c + (1.48144e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==87){
-       v2c=-0.00411031 + (0.000510639)*c + (-2.27814e-05)*c*c + (6.41192e-07)*c*c*c + (-5.85467e-09)*c*c*c*c ;
-       v2s=0.0121118 + (-0.00281)*c + (0.000143754)*c*c + (-2.62557e-06)*c*c*c + (1.61207e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==88){
-       v2c=-0.00570308 + (-0.000945116)*c + (7.42606e-05)*c*c + (-1.51212e-06)*c*c*c + (9.57993e-09)*c*c*c*c ;
-       v2s=-0.0282666 + (0.00398475)*c + (-0.000165678)*c*c + (2.68542e-06)*c*c*c + (-1.4688e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==89){
-       v2c=0.0845785 + (-0.012611)*c + (0.000561197)*c*c + (-9.39333e-06)*c*c*c + (5.16139e-08)*c*c*c*c ;
-       v2s=0.149689 + (-0.0193648)*c + (0.000771629)*c*c + (-1.21901e-05)*c*c*c + (6.6443e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==91){
-       v2c=-0.0289605 + (0.00127922)*c + (-4.47445e-06)*c*c + (-4.00293e-07)*c*c*c + (3.82966e-09)*c*c*c*c ;
-       v2s=-0.241098 + (0.00906132)*c + (-0.000159552)*c*c + (6.47243e-07)*c*c*c + (4.61048e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==95){
-       v2c=0.0144072 + (-0.000966056)*c + (6.47254e-05)*c*c + (-1.84164e-06)*c*c*c + (1.51588e-08)*c*c*c*c ;
-       v2s=-0.306678 + (0.0184746)*c + (-0.000540218)*c*c + (6.36681e-06)*c*c*c + (-2.37512e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==96){
-       v2c=0.00506182 + (-0.000632672)*c + (1.89752e-05)*c*c + (-2.14999e-07)*c*c*c + (3.12179e-10)*c*c*c*c ;
-       v2s=-0.218693 + (0.00676786)*c + (-0.000115485)*c*c + (5.56737e-07)*c*c*c + (2.68891e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==97){
-       v2c=-0.0225062 + (0.00204445)*c + (-6.76028e-05)*c*c + (8.92976e-07)*c*c*c + (-4.00576e-09)*c*c*c*c ;
-       v2s=-0.260286 + (0.0139325)*c + (-0.000425631)*c*c + (5.64038e-06)*c*c*c + (-2.51554e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==98){
-       v2c=-0.0261849 + (0.0063862)*c + (-0.000293076)*c*c + (4.37234e-06)*c*c*c + (-2.04899e-08)*c*c*c*c ;
-       v2s=-0.17744 + (0.00236157)*c + (9.2782e-06)*c*c + (-5.63126e-07)*c*c*c + (4.9714e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==101){
-       v2c=0.101445 + (-0.015664)*c + (0.000747255)*c*c + (-1.36979e-05)*c*c*c + (8.36903e-08)*c*c*c*c ;
-       v2s=0.0152975 + (-0.00329946)*c + (0.00018627)*c*c + (-3.88572e-06)*c*c*c + (2.64895e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==102){
-       v2c=-0.0344927 + (0.00470964)*c + (-0.000188941)*c*c + (3.0206e-06)*c*c*c + (-1.69735e-08)*c*c*c*c ;
-       v2s=0.0142624 + (-0.00240623)*c + (9.16657e-05)*c*c + (-1.14663e-06)*c*c*c + (4.14195e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==103){
-       v2c=-0.0238316 + (0.00322675)*c + (-0.000123462)*c*c + (1.76428e-06)*c*c*c + (-8.66176e-09)*c*c*c*c ;
-       v2s=0.0227184 + (-0.00299954)*c + (0.00014422)*c*c + (-2.81018e-06)*c*c*c + (1.82546e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==104){
-       v2c=0.0118014 + (-0.000998833)*c + (3.77271e-05)*c*c + (-6.19183e-07)*c*c*c + (3.49065e-09)*c*c*c*c ;
-       v2s=0.000977264 + (0.00012542)*c + (1.40219e-08)*c*c + (-2.24472e-09)*c*c*c + (-3.39763e-10)*c*c*c*c ;
-    }
-    if(fRunIndex==105){
-       v2c=0.0312332 + (-0.00348485)*c + (0.000108654)*c*c + (-1.28443e-06)*c*c*c + (4.80188e-09)*c*c*c*c ;
-       v2s=-0.0344234 + (0.00443313)*c + (-0.000173309)*c*c + (2.7124e-06)*c*c*c + (-1.42518e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==106){
-       v2c=0.0369386 + (-0.00434063)*c + (0.00018894)*c*c + (-3.45688e-06)*c*c*c + (2.16617e-08)*c*c*c*c ;
-       v2s=-0.00675251 + (0.000691284)*c + (-1.08033e-06)*c*c + (-5.57352e-07)*c*c*c + (6.28148e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==107){
-       v2c=-0.0441483 + (0.00803486)*c + (-0.00034871)*c*c + (4.76349e-06)*c*c*c + (-1.81393e-08)*c*c*c*c ;
-       v2s=-0.141046 + (0.0165183)*c + (-0.000592546)*c*c + (8.956e-06)*c*c*c + (-4.86662e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==108){
-       v2c=-0.0531169 + (0.00637348)*c + (-0.000218334)*c*c + (2.66873e-06)*c*c*c + (-9.86859e-09)*c*c*c*c ;
-       v2s=-0.00809622 + (-0.000552159)*c + (6.27984e-05)*c*c + (-1.33136e-06)*c*c*c + (7.45069e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==109){
-       v2c=-0.00189593 + (0.00153994)*c + (-9.92105e-05)*c*c + (1.98756e-06)*c*c*c + (-1.24677e-08)*c*c*c*c ;
-       v2s=0.0252107 + (-0.00330651)*c + (0.000128362)*c*c + (-1.89951e-06)*c*c*c + (9.45477e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==112){
-       v2c=-0.00939028 + (0.00128226)*c + (-5.24125e-05)*c*c + (8.50382e-07)*c*c*c + (-4.65785e-09)*c*c*c*c ;
-       v2s=0.00201633 + (-0.00116151)*c + (7.59727e-05)*c*c + (-1.59962e-06)*c*c*c + (1.04645e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==114){
-       v2c=-0.00783351 + (0.00122277)*c + (-3.37736e-05)*c*c + (3.12136e-07)*c*c*c + (-9.19359e-10)*c*c*c*c ;
-       v2s=0.0103833 + (-0.00215968)*c + (9.96942e-05)*c*c + (-1.71974e-06)*c*c*c + (1.01511e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==115){
-       v2c=0.00588164 + (-0.00083683)*c + (5.13684e-05)*c*c + (-1.14177e-06)*c*c*c + (8.11899e-09)*c*c*c*c ;
-       v2s=0.0037561 + (-0.000786163)*c + (3.88084e-05)*c*c + (-7.73678e-07)*c*c*c + (5.27396e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==116){
-       v2c=0.0610685 + (-0.00392239)*c + (6.23272e-05)*c*c + (9.84282e-07)*c*c*c + (-1.75418e-08)*c*c*c*c ;
-       v2s=-0.106295 + (0.0124333)*c + (-0.000510299)*c*c + (8.51235e-06)*c*c*c + (-4.9787e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==117){
-       v2c=-0.0132264 + (0.0024143)*c + (-0.000106307)*c*c + (1.74632e-06)*c*c*c + (-9.79752e-09)*c*c*c*c ;
-       v2s=-0.00788943 + (0.000443907)*c + (-1.83984e-05)*c*c + (3.81018e-07)*c*c*c + (-2.52604e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==118){
-       v2c=-0.045835 + (0.00849686)*c + (-0.000408675)*c*c + (7.3031e-06)*c*c*c + (-4.34655e-08)*c*c*c*c ;
-       v2s=-0.0455199 + (0.00718851)*c + (-0.000340502)*c*c + (6.00457e-06)*c*c*c + (-3.51883e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==119){
-       v2c=-0.00627236 + (0.00146712)*c + (-9.05375e-05)*c*c + (1.96962e-06)*c*c*c + (-1.35867e-08)*c*c*c*c ;
-       v2s=-0.00544096 + (0.000598445)*c + (-7.61032e-06)*c*c + (-2.09579e-07)*c*c*c + (3.00091e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==120){
-       v2c=-0.0376823 + (0.00376965)*c + (-8.01573e-05)*c*c + (-2.80792e-09)*c*c*c + (6.79508e-09)*c*c*c*c ;
-       v2s=-0.0675803 + (0.00849852)*c + (-0.000298266)*c*c + (3.93178e-06)*c*c*c + (-1.68582e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==121){
-       v2c=0.0285153 + (-0.00340253)*c + (0.000130854)*c*c + (-2.02449e-06)*c*c*c + (1.09594e-08)*c*c*c*c ;
-       v2s=0.0224991 + (-0.00524188)*c + (0.000269226)*c*c + (-4.93926e-06)*c*c*c + (2.97604e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==122){
-       v2c=0.00379321 + (0.000532446)*c + (-6.16649e-05)*c*c + (1.67786e-06)*c*c*c + (-1.29277e-08)*c*c*c*c ;
-       v2s=-0.011158 + (0.00256124)*c + (-0.000150921)*c*c + (3.22488e-06)*c*c*c + (-2.16809e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==123){
-       v2c=-0.0607006 + (0.00831906)*c + (-0.000398705)*c*c + (6.66385e-06)*c*c*c + (-3.5222e-08)*c*c*c*c ;
-       v2s=0.0389204 + (-0.00798361)*c + (0.000297135)*c*c + (-3.79751e-06)*c*c*c + (1.47914e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==124){
-       v2c=-0.0288952 + (0.00325728)*c + (-0.000104126)*c*c + (1.29062e-06)*c*c*c + (-6.03539e-09)*c*c*c*c ;
-       v2s=0.0318884 + (-0.00301585)*c + (0.000131913)*c*c + (-2.5702e-06)*c*c*c + (1.71313e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==125){
-       v2c=-0.00413859 + (0.00024613)*c + (5.33902e-06)*c*c + (-3.86963e-07)*c*c*c + (3.89277e-09)*c*c*c*c ;
-       v2s=-0.0492298 + (0.00624793)*c + (-0.000243844)*c*c + (3.69001e-06)*c*c*c + (-1.9156e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==126){
-       v2c=-0.018816 + (0.00134076)*c + (-4.50486e-05)*c*c + (5.84259e-07)*c*c*c + (-2.34235e-09)*c*c*c*c ;
-       v2s=-0.295912 + (0.0159608)*c + (-0.000497569)*c*c + (6.92442e-06)*c*c*c + (-3.35159e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==127){
-       v2c=-0.039222 + (0.00400933)*c + (-0.0001341)*c*c + (1.65214e-06)*c*c*c + (-6.33829e-09)*c*c*c*c ;
-       v2s=-0.290884 + (0.0147027)*c + (-0.000429021)*c*c + (5.64116e-06)*c*c*c + (-2.58784e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==128){
-       v2c=0.0168685 + (-0.00285775)*c + (0.000141099)*c*c + (-2.48846e-06)*c*c*c + (1.41845e-08)*c*c*c*c ;
-       v2s=-0.278776 + (0.0113771)*c + (-0.000279052)*c*c + (3.16144e-06)*c*c*c + (-1.18545e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==129){
-       v2c=0.0490322 + (-0.00736827)*c + (0.000304529)*c*c + (-4.89472e-06)*c*c*c + (2.60746e-08)*c*c*c*c ;
-       v2s=-0.0961198 + (0.0179264)*c + (-0.000914589)*c*c + (1.70145e-05)*c*c*c + (-1.03423e-07)*c*c*c*c ;
-    }
-    if(fRunIndex==131){
-       v2c=0.075924 + (-0.0108106)*c + (0.000493471)*c*c + (-8.39074e-06)*c*c*c + (4.67109e-08)*c*c*c*c ;
-       v2s=0.0700446 + (-0.0105027)*c + (0.00048267)*c*c + (-8.4422e-06)*c*c*c + (4.91292e-08)*c*c*c*c ;
-    }
-    if(fRunIndex==132){
-       v2c=0.00752887 + (-0.00142672)*c + (7.37857e-05)*c*c + (-1.36894e-06)*c*c*c + (8.28054e-09)*c*c*c*c ;
-       v2s=-0.0121719 + (0.00188256)*c + (-8.67104e-05)*c*c + (1.50514e-06)*c*c*c + (-8.79759e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==133){
-       v2c=0.00242068 + (-0.000274576)*c + (1.06631e-05)*c*c + (-1.45829e-07)*c*c*c + (7.18001e-10)*c*c*c*c ;
-       v2s=0.0113182 + (-0.000529549)*c + (-7.75839e-06)*c*c + (4.86382e-07)*c*c*c + (-3.98634e-09)*c*c*c*c ;
-    }
-    if(fRunIndex==134){
-       v2c=-0.0438721 + (0.00906564)*c + (-0.000407471)*c*c + (6.6254e-06)*c*c*c + (-3.61035e-08)*c*c*c*c ;
-       v2s=-0.276264 + (0.0107322)*c + (-0.000281971)*c*c + (3.27634e-06)*c*c*c + (-1.17426e-08)*c*c*c*c ;
+    // GetCorrection Parameter
+    if(fHarmonic==2){
+     
+       if(ep==kEPTPC){
+
+           Double_t cc2[5]={0.00904396,0.00472483,0.00306154,0.00218462,0.00167447};
+           Double_t cs2[5]={0.00885519,0.00516223,0.00411065,0.00380145,0.00324424};
+           Double_t cc4[5]={-0.00110933,-0.00110521,-0.00124342,0.00104131,0.000651779};
+           Double_t cs4[5]={0.00163869,-0.00053565,0.000878745,-0.000563657,-0.000604021};
+
+           c2=cc2[fCentralityBin];
+           s2=cs2[fCentralityBin];
+           c4=cc4[fCentralityBin];
+           s4=cs4[fCentralityBin];
+       }
+
+       if(ep==kEPTPCEtaA){
+
+           Double_t cc2[5]={0.00529447,0.00278029,0.00315325,0.00173634,0.000763168};
+           Double_t cs2[5]={0.00314285,0.00170173,0.00263333,0.0018509,0.00223784};
+           Double_t cc4[5]={-0.000737254,-0.00037845,-0.000492715,0.000775897,0.000768656};
+           Double_t cs4[5]={0.000347583,3.79872e-05,0.000387037,-0.000186129,0.000432698};
+
+           c2=cc2[fCentralityBin];
+           s2=cs2[fCentralityBin];
+           c4=cc4[fCentralityBin];
+           s4=cs4[fCentralityBin];
+       }
+
+       if(ep==kEPTPCEtaC){
+
+           Double_t cc2[5]={-0.00562282,-0.00456735,-0.00306068,-0.0027173,-0.00172432};
+           Double_t cs2[5]={0.0101804,0.00430782,0.00394715,0.00350156,0.00302749};
+           Double_t cc4[5]={0.00150831,-0.00159271,-0.000964157,0.000525894,9.93172e-05};
+           Double_t cs4[5]={0.00119279,-4.74629e-05,0.000118845,0.000278554,3.20868e-05};
+
+           c2=cc2[fCentralityBin];
+           s2=cs2[fCentralityBin];
+           c4=cc4[fCentralityBin];
+           s4=cs4[fCentralityBin];
+       }
+
+       if(ep==kEPV0A){
+
+           Double_t cc2[5]={0.046427,0.0105401,-0.000152992,-0.00578274,-0.0108038};
+           Double_t cs2[5]={0.00551503,0.0158159,0.00965148,0.00135414,-0.00548846};
+           Double_t cc4[5]={0.00362833,0.00170777,0.000152998,0.00223823,0.00215164};
+           Double_t cs4[5]={0.00349056,0.00142802,0.00123298,0.00207995,0.00145625};
+
+           c2=cc2[fCentralityBin];
+           s2=cs2[fCentralityBin];
+           c4=cc4[fCentralityBin];
+           s4=cs4[fCentralityBin];
+       }
+
+       if(ep==kEPV0C){
+
+           Double_t cc2[5]={-0.00473277,-0.000371313,0.000857122,-1.54263e-05,-0.000686139};
+           Double_t cs2[5]={0.00408304,-0.00208615,-0.00149018,-0.000853616,-2.78855e-05};
+           Double_t cc4[5]={-0.00451741,-0.00399036,-0.00318784,-0.00186472,-0.00106299};
+           Double_t cs4[5]={0.00188045,-0.00713956,-0.00484254,-0.00448149,-0.00482164};
+
+           c2=cc2[fCentralityBin];
+           s2=cs2[fCentralityBin];
+           c4=cc4[fCentralityBin];
+           s4=cs4[fCentralityBin];
+       }
     }
-    if(fRunIndex==135){
-       v2c=0.0224469 + (-0.00324762)*c + (0.000165861)*c*c + (-3.16496e-06)*c*c*c + (2.011e-08)*c*c*c*c ;
-       v2s=-0.308891 + (0.0136721)*c + (-0.00032343)*c*c + (2.93575e-06)*c*c*c + (-5.7637e-09)*c*c*c*c ;
+
+    if(fHarmonic==3){
+
+       if(ep==kEPTPC){
+
+           Double_t cc2[5]={0.0116542,0.0103631,0.00897965,0.00707409,0.00605151};
+           Double_t cs2[5]={-0.0171191,-0.013024,-0.0114752,-0.0086613,-0.00706863};
+           Double_t cc4[5]={-0.000602948,0.00144836,-0.000193641,0.000108773,-0.000518333};
+           Double_t cs4[5]={-0.00164769,0.00134327,-0.00106369,7.96546e-06,-0.000261517};
+
+           c2=cc2[fCentralityBin];
+           s2=cs2[fCentralityBin];
+           c4=cc4[fCentralityBin];
+           s4=cs4[fCentralityBin];
+       }
+
+       if(ep==kEPTPCEtaA){
+
+           Double_t cc2[5]={0.000386277,0.000119225,0.00111969,0.000534801,0.000642703};
+           Double_t cs2[5]={-0.00581604,-0.00607255,-0.00443819,-0.00268834,-0.00299961};
+           Double_t cc4[5]={0.00051635,0.00036326,-0.000221272,4.66775e-05,-3.05784e-06};
+           Double_t cs4[5]={1.43285e-05,0.000514099,0.000619339,0.00106466,0.000344196};
+
+           c2=cc2[fCentralityBin];
+           s2=cs2[fCentralityBin];
+           c4=cc4[fCentralityBin];
+           s4=cs4[fCentralityBin];
+       }
+
+       if(ep==kEPTPCEtaC){
+
+           Double_t cc2[5]={0.0116475,0.0102385,0.00801121,0.00552336,0.00423273};
+           Double_t cs2[5]={-0.0112722,-0.00796059,-0.00683678,-0.00531097,-0.00430716};
+           Double_t cc4[5]={-0.000609051,1.36573e-08,-0.000464961,-0.000387943,-2.28363e-05};
+           Double_t cs4[5]={0.00125449,0.00168484,-0.000390491,-0.000219447,8.11997e-07};
+
+           c2=cc2[fCentralityBin];
+           s2=cs2[fCentralityBin];
+           c4=cc4[fCentralityBin];
+           s4=cs4[fCentralityBin];
+       }
+
+       if(ep==kEPV0A){
+
+            Double_t cc2[5]={-0.0057427,-0.00482728,-0.00565919,-0.000717094,-0.00933233};
+           Double_t cs2[5]={0.0306554,-0.0144675,-0.0159243,-0.0120465,-0.00814124};
+           Double_t cc4[5]={-0.002868,0.00159533,0.00754171,0.00683898,0.00689441};
+           Double_t cs4[5]={0.00083196,0.00198133,4.68307e-05,-0.00018187,-0.0014258};
+
+           c2=cc2[fCentralityBin];
+           s2=cs2[fCentralityBin];
+           c4=cc4[fCentralityBin];
+           s4=cs4[fCentralityBin];
+       }
+
+       if(ep==kEPV0C){
+
+           Double_t cc2[5]={-0.00259141,-0.00115826,-0.000738658,-4.96667e-05,-0.000346694};
+           Double_t cs2[5]={-0.0111001,0.00258109,0.00110959,-0.000147296,-0.000199817};
+           Double_t cc4[5]={0.000968742,0.00157903,0.000206157,0.000444206,-0.00046573};
+           Double_t cs4[5]={-0.00307319,-0.0047952,-0.00412117,-0.00320344,-0.00386629};
+
+           c2=cc2[fCentralityBin];
+           s2=cs2[fCentralityBin];
+           c4=cc4[fCentralityBin];
+           s4=cs4[fCentralityBin];
+       }
     }
-    if(fRunIndex==136){
-       v2c=0.0279685 + (-0.00441)*c + (0.000294342)*c*c + (-6.56635e-06)*c*c*c + (4.53669e-08)*c*c*c*c ;
-       v2s=-0.273287 + (0.00917778)*c + (-0.000144155)*c*c + (1.59881e-07)*c*c*c + (8.63874e-09)*c*c*c*c ;
+
+    // Do correction
+    Double_t newphi=phi;
+    newphi+=1/Double_t(fHarmonic)*(2*c2*sin(Double_t(fHarmonic)*phi)-2*s2*cos(Double_t(fHarmonic)*phi)+c4*sin(2*Double_t(fHarmonic)*phi)-s4*cos(2*Double_t(fHarmonic)*phi));
+    newphi=GetPsiInRange(newphi);
+
+    return newphi;
+}
+
+//________________________________________________________________________
+Double_t AliAnalysisTaskPi0v2::GetWeight(TObject* track1)
+{
+    Double_t ptweight=1;
+    AliVTrack* track = dynamic_cast<AliVTrack*>(track1);
+    if (track) {
+       if (track->Pt()<2) ptweight=track->Pt();
+       else ptweight=2;
     }
+    return ptweight*GetPhiWeight(track);
+}
 
-    /*
-     if(fRunIndex>=1 && fRunIndex<=45){ // 137161 -137848 //period 1
-     //    v2c =-3.523975e-03+8.132703e-04*x+-4.107765e-05*x*x+7.308763e-07*x*x*x+-4.285144e-09*x*x*x*x;
-     //    v2s =-1.555676e-02+1.075371e-03*x+-3.597818e-05*x*x+4.927188e-07*x*x*x+-2.217080e-09*x*x*x*x;
-     v2c=-2.007559e-05+3.143290e-04*x-2.065995e-05*x*x+4.071671e-07*x*x*x-2.562114e-09*x*x*x*x ;
-     v2s=-4.920033e-03+6.807606e-04*x-3.065278e-05*x*x+5.132261e-07*x*x*x-2.767644e-09*x*x*x*x ;
+//________________________________________________________________________
+Double_t AliAnalysisTaskPi0v2::GetPhiWeight(TObject* track1)
+{
+  Double_t phiweight=1;
+  AliVTrack* track = dynamic_cast<AliVTrack*>(track1);
 
+  TH1F *phiDist = 0x0;
+  if(track) phiDist = SelectPhiDist(track);
+
+  if (phiDist && track) {
+      Double_t nParticles = phiDist->Integral();
+      Double_t nPhibins = phiDist->GetNbinsX();
+
+      Double_t Phi = track->Phi();
+
+      while (Phi<0) Phi += TMath::TwoPi();
+      while (Phi>TMath::TwoPi()) Phi -= TMath::TwoPi();
+
+      Double_t PhiDistValue = phiDist->GetBinContent(1+TMath::FloorNint((track->Phi())*nPhibins/TMath::TwoPi()));
+
+      if (PhiDistValue > 0) phiweight = nParticles/nPhibins/PhiDistValue;
   }
-  if(fRunIndex>=46 && fRunIndex<=58){ //138125-138275//period 2
-    v2c = 1.591471e-02+2.772445e-04*x-2.229627e-05*x*x+3.803341e-07*x*x*x-2.056551e-09*x*x*x*x;
-    v2s =-5.800393e-02+2.007102e-03*x-3.292094e-05*x*x+7.266378e-08*x*x*x+1.828472e-09*x*x*x*x ;
-  }
-  if(fRunIndex>=59 && fRunIndex<=78){ //138359-138730//period 3
-    v2c =-8.010228e-03+8.947184e-04*x-4.192609e-05*x*x+7.388210e-07*x*x*x-4.280541e-09*x*x*x*x ;
-    v2s =-3.203888e-02+2.122650e-03*x-7.549389e-05*x*x+1.161380e-06*x*x*x-6.156621e-09*x*x*x*x ;
-  }
-  if(fRunIndex>=79){//period 4
-    v2c =-1.025964e-02+1.128454e-03*x-4.603917e-05*x*x+7.386637e-07*x*x*x-4.035342e-09*x*x*x*x ;
-    v2s =-9.746961e-02+4.672675e-03*x-1.311440e-04*x*x+1.650922e-06*x*x*x-7.083187e-09*x*x*x*x ;
-  }
-*/  
-    return phi+v2c*TMath::Sin(2.*phi)-v2s*TMath::Cos(2.*phi) ;
+  return phiweight;
 }
-//____________________________________________________________________________
-Double_t  AliAnalysisTaskPi0v2::ApplyFlatteningTPC(Double_t phi, Double_t c){
-  
-  if(fRunIndex==39){ //137748
-    Double_t v2c= 0.0222974-0.00132297*c+0.000204021*c*c-4.49827e-06*c*c*c+2.76986e-08*c*c*c*c ; 
-    Double_t v2s=0.00615401-7.76462e-05*c ;   
-    return phi+v2c*TMath::Sin(2.*phi)-v2s*TMath::Cos(2.*phi) ;
-  }
-  
-  
-  //Periods 1,2,3
-  //fRunIndex - run index
-  if(fRunIndex>=1 && fRunIndex<79){
-    Double_t v2c=4.40516e-04+TMath::Exp(-4.71923-7.62089e-02*c) ;
-    Double_t v2s=1.79859e-03+TMath::Exp(-4.99649-7.87523e-02*c) ;
-   
-    return phi+v2c*TMath::Sin(2.*phi)-v2s*TMath::Cos(2.*phi) ;
-  }
-  
-  //period4
-   //138826, 138828, 138830
-  if(fRunIndex==83 ||fRunIndex==84 ||fRunIndex==85 ){
-     Double_t v2c = -1.4e-03 ;
-     Double_t v2s =  -5.60117e-02-TMath::Exp( -1.62827e+00-9.96071e-02*c);
-    return phi + v2c*TMath::Sin(2.*phi) - v2s*TMath::Cos(2.*phi) ;
-  }
-  //Runs 138871,138872
-  if(fRunIndex==87 ||fRunIndex==88 ){   
-    Double_t v2c=-0.00518371 ;
-    Double_t v2s= 0.00633324 ;
-    return phi + v2c*TMath::Sin(2.*phi) - v2s*TMath::Cos(2.*phi) ;
-  }   
-  //run 139029
-  if(fRunIndex==102 ){   
-     Double_t v2c = -0.00354633 ;
-     Double_t v2s =  0.00418512 ;
-     return phi+v2c*TMath::Sin(2.*phi)-v2s*TMath::Cos(2.*phi) ;
-  }  
-  //run 139110  
-/*
-  if(fRunIndex==110 ){   
-    Double_t v2c=4.78327e-04+TMath::Exp(-3.21625    -6.74306e-02*c) ;
-    Double_t v2s=3.50176e-02+TMath::Exp(-9.73541e-01-9.19214e-02*c) ;
-    return phi + v2c*TMath::Sin(2.*phi) - v2s*TMath::Cos(2.*phi) ;
-  }
-*/
-  if(fRunIndex>=79 && fRunIndex<=139){
-    Double_t v2c= 4.78327e-04 + TMath::Exp(-6.70587-2.33120e-02*c) ;
-    Double_t v2s=-2.57731e-03 + TMath::Exp(-2.75493-1.05166e-01*c) ;
-   
-    return phi + v2c*TMath::Sin(2.*phi) - v2s*TMath::Cos(2.*phi) ;
-  }
-  return phi ;  
-  
-}  
+
+//_________________________________________________________________________
+TH1F* AliAnalysisTaskPi0v2::SelectPhiDist(AliVTrack *track)
+{ 
+  if (fPeriod.CompareTo("LHC10h")==0) return fPhiDist[0];
+  else if(fPeriod.CompareTo("LHC11h")==0)
+    {
+     if (track->Charge() < 0)
+       {
+        if(track->Eta() < 0.)       return fPhiDist[0];
+        else if (track->Eta() > 0.) return fPhiDist[2];
+       }
+      else if (track->Charge() > 0)
+       {
+        if(track->Eta() < 0.)       return fPhiDist[1];
+        else if (track->Eta() > 0.) return fPhiDist[3];
+       }
+       
+    }
+  return 0;
+}
+
index 981bb59..1293701 100644 (file)
@@ -27,6 +27,15 @@ public:
        knEPMethod=4
     };
 
+    enum EEventPlane{
+       kEPTPC=0,
+       kEPTPCEtaA,
+       kEPTPCEtaC,
+       kEPV0A,
+       kEPV0C,
+        knEP
+    };
+
     enum EPDGCode{
        kPi0=111,
        kEta=221
@@ -34,7 +43,7 @@ public:
 
     static const Int_t knBinsPhi=6;
 
-    AliAnalysisTaskPi0v2(const char *name);
+    AliAnalysisTaskPi0v2(const char *name,Int_t harmonic=2);
     virtual ~AliAnalysisTaskPi0v2();
 
     virtual void   UserCreateOutputObjects();
@@ -51,14 +60,12 @@ public:
     void SetEtaGap(Double_t gapsize){fEtaGap=gapsize;};
 
     void SetMesonCuts(const TString cut);
-    void SetCuts(TString *cutarray,Int_t ncuts);
-    void SetMesonCutList(Int_t nCuts, TList *cutArray){
-      fMesonCutList = cutArray;
-    }
-
+    void SetCuts(AliConversionSelection **conversionselection,Int_t numberOfCuts);
 
     void SetFillQA(Bool_t fill){fFillQA=fill;}
 
+    void SetEPSelectionMask(Int_t mask[knEPMethod]){for(Int_t ii=0;ii<knEPMethod;ii++)fEPSelectionMask[ii]=mask[ii];};
+
 private:
     Bool_t InitEvent();
 
@@ -66,34 +73,38 @@ private:
     void ProcessPi0s(Int_t iCut,EEventPlaneMethod iEP);
     void ProcessQA();
 
-    void InitConversionSelection();
-    Double_t GetPhiwrtRP(Double_t phi);
-    Double_t GetPhotonPhiwrtRP(AliAODConversionPhoton *gamma,EEventPlaneMethod iEP);
-    Double_t GetPi0PhiwrtRP(AliAODConversionMother *pi0,EEventPlaneMethod iEP);
-    Double_t GetChargedPhiwrtRP(AliVTrack *charged,EEventPlaneMethod iEP);
+    Double_t GetPhiwrtRP(Double_t dPhi);
+    Double_t GetPhotonPhiwrtRP(AliAODConversionPhoton *gamma,EEventPlaneMethod iEP,Bool_t bDoFlattening=kTRUE);
+    Double_t GetPi0PhiwrtRP(AliAODConversionMother *pi0,EEventPlaneMethod iEP,Bool_t bDoFlattening=kTRUE);
+    Double_t GetChargedPhiwrtRP(AliVTrack *charged,EEventPlaneMethod iEP,Bool_t bDoFlattening=kTRUE);
     void GetPhotondNdPhi(Int_t *dNdPhi,Int_t iEP,Int_t iCut=0);
     void GetChargeddNdPhi(Int_t *dNdPhi,Int_t &ntot,Int_t iEP);
     Int_t GetPhiBin(Double_t phiwrt);
     Int_t GetPhotonPhiBin(AliAODConversionPhoton *gamma,Int_t iEP);
-    Double_t GetMCPhotonPhiwrtRP(TParticle *gamma,EEventPlaneMethod iEP);
+    Double_t GetMCPhotonPhiwrtRP(TParticle *gamma,EEventPlaneMethod iEP,Bool_t bDoFlattening=kTRUE);
     TVector2 GetEPContribution(AliAODConversionPhoton *gamma);
-    Double_t GetEventPlaneAngle(EEventPlaneMethod EPmethod,Double_t eta=0,AliAODConversionPhoton *gamma0=NULL,AliAODConversionPhoton *gamma1=NULL);
-    Double_t GetTPCSubEPEta(Double_t etamin,Double_t etamax);
-    Double_t GetCorrectedTPCEPAngle(AliAODConversionPhoton *gamma0=NULL,AliAODConversionPhoton *gamma1=NULL);
+    Double_t GetEventPlaneAngle(EEventPlaneMethod EPmethod,Double_t eta=0,AliAODConversionPhoton *gamma0=NULL,AliAODConversionPhoton *gamma1=NULL,Bool_t bDoFlattening=kTRUE);
+    Double_t GetTPCSubEPEta(EEventPlane ep);
+    Double_t GetCorrectedTPCEPAngle(AliAODConversionPhoton *gamma0=NULL,AliAODConversionPhoton *gamma1=NULL,Bool_t bDoFlattening=kTRUE);
     Bool_t SetCentrality();
     void ProcessEventPlane();
     Int_t GetRadialBin(Double_t radius);
     Int_t GetRunIndex(Int_t run);
+    Double_t ApplyFlattening(Double_t phi,EEventPlane ep);
+    Bool_t GetTPCEventPlane();
 
-    // For V0 EP
-    void GetV0EP(AliVEvent * event);
+    void GetV0EP(AliVEvent * event,Double_t &rpv0a,Double_t &rpv0c);
     void OpenInfoCalibration(Int_t run);
+    Double_t GetWeight(TObject* track1);
+    Double_t GetPhiWeight(TObject* track1);
+    TH1F* SelectPhiDist(AliVTrack *track);
 
-    Double_t ApplyFlatteningTPC(Double_t phi, Double_t c);
-    Double_t ApplyFlatteningV0A(Double_t phi, Double_t c);
-    Double_t ApplyFlatteningV0C(Double_t phi, Double_t c);
-
+    Double_t GetPsiInRange(Double_t phi);
 
+    TObjArray* GetEventPlaneTracks(Int_t &maxID);
+    TVector2 GetContributionEP(AliVTrack *track);
+    Int_t GetAODEPTrackFilterBit();
+   
     // Constants
 
     enum Ebinsgamma{
@@ -130,18 +141,21 @@ private:
     Int_t fCentralityBin; // Event Centrality Bin
     Int_t fNBinsPhi; // Number of Phi wrt RP bins
     AliEventplane *fEP; // Event Plane Pointer
-    Bool_t fWeightMultiplicity; // Use Multiplicity Weight
+    Bool_t fUseTPCOnlyTracks; // Use TPC Only Tracks for EP
     Double_t fEtaMax; // Eta Max for analysis;
     Double_t fEtaGap; // Eta Gap
     Double_t fRPTPCEtaA; // TPCEtaA event plane
     Double_t fRPTPCEtaC; // TPCEtaC event plane
     Double_t fRPV0A; // V0A event plane
     Double_t fRPV0C; // V0C event plane
+    Double_t fRPTPC; // TPC event plane
+    Double_t fRPTPCEtaABF; // TPCEtaA event plane before flattening
+    Double_t fRPTPCEtaCBF; // TPCEtaC event plane before flattening
+    Double_t fRPV0ABF;// V0A event plane before flattening
+    Double_t fRPV0CBF;// V0C event plane before flattening
+    Double_t fRPTPCBF;// TPC event plane before flattening
     Int_t fNCuts; // NUmber of Photon Cuts for v2 analysis
-    TList *fCutList; // Cuts for Photon v2 analysis
     AliConversionCuts *fConversionCuts; // Cuts used by the V0Reader
-   TList *fMesonCutList; // Cuts for Photon v2 analysis
-    AliConversionMesonCuts *fMesonCuts; // Cuts used by the V0Reader
     TRandom3 *fRandomizer; // Randomizer for Event Plane Randomisation
     TList *fOutputList; // List for Output (Histograms etc.)
     EPDGCode fMesonPDGCode; // PDG Code of the processed Meson (for MC truth)
@@ -151,7 +165,15 @@ private:
     Int_t fRunIndex; // current internal run index
     Int_t fNEPMethods; // number of EP methods
     Bool_t fFillQA; // Fill QA Histograms
-
+    Int_t fHarmonic; // Harmonic to be analyzed (v2,v3,..)
+    Double_t fPsiMax; //Range for Psi
+    TString  fPeriod; //"LHC11h","LHC10h"
+    Bool_t fIsAOD; // Is AOD? else ESD
+    TH1F*       fPhiDist[4];                   // array of Phi distributions used to calculate phi weights
+    THnSparse *fSparseDist;               //! THn for eta-charge phi-weighting
+    TH1F *fHruns;                         // information about runwise statistics of phi-weights
+    Bool_t fDoEPFlattening; // Do flattening
+    Int_t fEPSelectionMask[knEPMethod]; // Which EP methods shall be applied
     // Histograms
 
     TH1F *hNEvents;
@@ -172,25 +194,12 @@ private:
     TH2F *hRPTPCEtaC;
     TH2F *hRPTPCEtaAC;
     TH2F *hCos2TPCEta;
-
-    TH2F *hCos2TPCWeightedPhoton;
-    TH2F *hCos2TPCEtaWeightedPhoton;
-    TH2F *hCos2V0ATPCWeightedPhoton;
-    TH2F *hCos2V0CTPCWeightedPhoton;
-    TH2F *hCos2V0ACWeightedPhoton;
-
-    TH2F *hCos2TPCWeightedCharged;
-    TH2F *hCos2TPCEtaWeightedCharged;
-    TH2F *hCos2V0ATPCWeightedCharged;
-    TH2F *hCos2V0CTPCWeightedCharged;
-    TH2F *hCos2V0ACWeightedCharged;
-
-    TH2F *hCos2TPCWeightedV0Mult;
-    TH2F *hCos2TPCEtaWeightedV0Mult;
-    TH2F *hCos2V0ATPCWeightedV0Mult;
-    TH2F *hCos2V0CTPCWeightedV0Mult;
-    TH2F *hCos2V0ACWeightedV0Mult;
-
+    TH2F *hCos2V0ATPCEtaA;
+    TH2F *hCos2V0ATPCEtaC;
+    TH2F *hCos2V0CTPCEtaA;
+    TH2F *hCos2V0CTPCEtaC;
+    TH2F *hCos2SumWeights;
+    TH2F *hEtaTPCEP;
 
     // Gamma
     TH2F *hGammaMultCent;
@@ -225,7 +234,8 @@ private:
     Float_t fWidthQ[nCentrBinV0][2][2];   // ...
 
     //Event Plane
-    THnSparse *hEPVertex;
+    //THnSparse *hEPVertex;
+    THnSparse *hEPQA;
 
     AliAnalysisTaskPi0v2(const AliAnalysisTaskPi0v2&); // not implemented
     AliAnalysisTaskPi0v2& operator=(const AliAnalysisTaskPi0v2&); // not implemented
index c04270a..633b7e4 100644 (file)
@@ -207,6 +207,28 @@ Bool_t AliConversionAODBGHandlerRP::FindBins(TObjArray * const eventGammas,AliVE
     //cout<<Form("Requested BG pool does not exist:  z %i m %i",zbin,mbin)<<endl;
     return kFALSE;
 }
+//-------------------------------------------------------------
+Bool_t AliConversionAODBGHandlerRP::FindBins(TList * const eventGammas,AliVEvent *fInputEvent,Int_t &zbin,Int_t &mbin){
+    Double_t vertexz=fInputEvent->GetPrimaryVertex()->GetZ();
+    zbin = GetZBinIndex(vertexz);
+
+    Int_t multiplicity=0;
+    if(fUseChargedTrackMult){
+       multiplicity=fInputEvent->GetNumberOfTracks();
+    }
+    else{
+       multiplicity=eventGammas->GetEntries();
+    }
+    mbin = GetMultiplicityBinIndex(multiplicity);
+
+    if(zbin<fNBinsZ&&mbin<fNBinsMultiplicity){
+       if(zbin>=0&&mbin>=0){
+           return kTRUE;
+       }
+    }
+    //cout<<Form("Requested BG pool does not exist:  z %i m %i",zbin,mbin)<<endl;
+    return kFALSE;
+}
 
 
 //-------------------------------------------------------------
@@ -247,6 +269,43 @@ void AliConversionAODBGHandlerRP::AddEvent(TObjArray * const eventGammas,AliVEve
        fBGEventCounter[z][m]++;
     }
 }
+//-------------------------------------------------------------
+void AliConversionAODBGHandlerRP::AddEvent(TList * const eventGammas,AliVEvent *fInputEvent){
+    if(eventGammas->GetEntries()==0)return;
+
+    Int_t z;
+    Int_t m;
+    if(FindBins(eventGammas,fInputEvent,z,m)){
+  
+   
+       // If Event Stack is full, replace the first entry (First in first out)
+       if(fBGEventCounter[z][m] >= fNEvents){
+           fBGEventCounter[z][m]=0;
+       }
+
+       // Update number of Events stored
+       if(fNBGEvents[z][m] < fNEvents){
+           fNBGEvents[z][m]++;
+       }
+
+       Int_t eventCounter=fBGEventCounter[z][m];
+
+       //clear the vector for old gammas
+       for(UInt_t d=0;d<fBGPool[z][m][eventCounter].size();d++){
+           delete (AliAODConversionPhoton*)(fBGPool[z][m][eventCounter][d]);
+       }
+
+       fBGPool[z][m][eventCounter].clear();
+
+       // add the gammas to the vector
+
+       for(Int_t i=0; i< eventGammas->GetEntries();i++){
+           fBGPool[z][m][eventCounter].push_back(new AliAODConversionPhoton(*(AliAODConversionPhoton*)(eventGammas->At(i))));
+       }
+
+       fBGEventCounter[z][m]++;
+    }
+}
 
 //-------------------------------------------------------------
 AliGammaConversionPhotonVector* AliConversionAODBGHandlerRP::GetBGGoodGammas(TObjArray * const eventGammas,AliVEvent *fInputEvent,Int_t event){
@@ -257,6 +316,15 @@ AliGammaConversionPhotonVector* AliConversionAODBGHandlerRP::GetBGGoodGammas(TOb
     }
     return NULL;
 }
+//-------------------------------------------------------------
+AliGammaConversionPhotonVector* AliConversionAODBGHandlerRP::GetBGGoodGammas(TList * const eventGammas,AliVEvent *fInputEvent,Int_t event){
+    Int_t zbin;
+    Int_t mbin;
+    if(FindBins(eventGammas,fInputEvent,zbin,mbin)){
+       return &(fBGPool[zbin][mbin][event]);
+    }
+    return NULL;
+}
 
 //-------------------------------------------------------------
 Int_t AliConversionAODBGHandlerRP::GetNBGEvents(TObjArray * const eventGammas,AliVEvent *fInputEvent){
@@ -267,4 +335,13 @@ Int_t AliConversionAODBGHandlerRP::GetNBGEvents(TObjArray * const eventGammas,Al
     }
     return 0;
 }
+//-------------------------------------------------------------
+Int_t AliConversionAODBGHandlerRP::GetNBGEvents(TList * const eventGammas,AliVEvent *fInputEvent){
+   Int_t zbin;
+   Int_t mbin;
+   if(FindBins(eventGammas,fInputEvent,zbin,mbin)){
+      return fNBGEvents[zbin][mbin];
+   }
+   return 0;
+}
 
index 920fef3..dd1723d 100644 (file)
@@ -5,6 +5,7 @@
 #include "TObject.h"
 #include "AliAODConversionPhoton.h"
 #include "TObjArray.h"
+#include "TList.h"
 using namespace std;
 
 typedef vector<AliAODConversionPhoton*> AliGammaConversionPhotonVector;   // Vector containing photons
@@ -25,12 +26,16 @@ public:
     Int_t GetMultiplicityBinIndex(Int_t mult) const;
     void Initialize();
     Bool_t FindBins(TObjArray * const eventGammas,AliVEvent *fInputEvent,Int_t &zbin,Int_t &mbin);
+    Bool_t FindBins(TList * const eventGammas,AliVEvent *fInputEvent,Int_t &zbin,Int_t &mbin);
 
  
     AliGammaConversionPhotonVector* GetBGGoodGammas(TObjArray * const eventGammas,AliVEvent *fInputEvent,Int_t event);
+    AliGammaConversionPhotonVector* GetBGGoodGammas(TList * const eventGammas,AliVEvent *fInputEvent,Int_t event);
     void AddEvent(TObjArray * const eventGammas,AliVEvent *fInputEvent);
+    void AddEvent(TList * const eventGammas,AliVEvent *fInputEvent);
     Int_t GetNBGEvents()const {return fNEvents;} // Size of the Pool (20)
     Int_t GetNBGEvents(TObjArray * const eventGammas,AliVEvent *fInputEvent);
+    Int_t GetNBGEvents(TList * const eventGammas,AliVEvent *fInputEvent);
     Int_t GetNZBins()const{return fNBinsZ;};
     Int_t GetNMultiplicityBins()const{return fNBinsMultiplicity;};
 
index 495c141..40fe508 100644 (file)
@@ -14,7 +14,7 @@
  **************************************************************************/
 
 ////////////////////////////////////////////////
-//--------------------------------------------- 
+//---------------------------------------------
 // Class handling all kinds of selection cuts for
 // Gamma Conversion analysis
 //---------------------------------------------
@@ -41,6 +41,8 @@
 #include "TList.h"
 #include "AliLog.h"
 #include "AliGenCocktailEventHeader.h"
+#include "AliTriggerAnalysis.h"
+#include "AliV0ReaderV1.h"
 
 class iostream;
 
@@ -74,7 +76,7 @@ const char* AliConversionCuts::fgkCutNames[AliConversionCuts::kNCuts] = {
    "DoPhotonAsymmetryCut",
    "CosinePointingAngle",
    "SharedElectronCuts",
-   "RejectToCloseV0s",
+   "RejectToCloseV0s"
 };
 
 
@@ -82,7 +84,7 @@ const char* AliConversionCuts::fgkCutNames[AliConversionCuts::kNCuts] = {
 AliConversionCuts::AliConversionCuts(const char *name,const char *title) :
    AliAnalysisCuts(name,title),
    fHistograms(NULL),
-   fHeaderList(NULL),                                                     
+   fHeaderList(NULL),
    fPIDResponse(NULL),
    fEventQuality(-1),
    fMaxR(200),
@@ -102,13 +104,13 @@ AliConversionCuts::AliConversionCuts(const char *name,const char *title) :
    fPIDProbabilityCutNegativeParticle(0),
    fPIDProbabilityCutPositiveParticle(0),
    fDodEdxSigmaCut(kTRUE),
-   fDoTOFsigmaCut(kFALSE), 
+   fDoTOFsigmaCut(kFALSE),
    fPIDTRDEfficiency(1),
    fDoTRDPID(kFALSE),
    fPIDnSigmaAboveElectronLine(100),
    fPIDnSigmaBelowElectronLine(-100),
-   fTofPIDnSigmaAboveElectronLine(100), 
-   fTofPIDnSigmaBelowElectronLine(-100), 
+   fTofPIDnSigmaAboveElectronLine(100),
+   fTofPIDnSigmaBelowElectronLine(-100),
    fPIDnSigmaAbovePionLine(0),
    fPIDnSigmaAbovePionLineHighPt(-100),
    fPIDMinPnSigmaAbovePionLine(0),
@@ -119,14 +121,14 @@ AliConversionCuts::AliConversionCuts(const char *name,const char *title) :
    fPIDnSigmaAtLowPAroundKaonLine(0),
    fPIDnSigmaAtLowPAroundProtonLine(0),
    fPIDnSigmaAtLowPAroundPionLine(0),
-   fPIDMinPKaonRejectionLowP(0),
-   fPIDMinPProtonRejectionLowP(0),
+   fPIDMinPKaonRejectionLowP(1.5),
+   fPIDMinPProtonRejectionLowP(2),
    fPIDMinPPionRejectionLowP(0),
    fDoQtGammaSelection(kTRUE),
-   fDoHighPtQtGammaSelection(kFALSE), // RRnew
+   fDoHighPtQtGammaSelection(kFALSE),
    fQtMax(100),
-   fHighPtQtMax(0.), // RRnew
-   fPtBorderForQt(0), // RRnew
+   fHighPtQtMax(0.),
+   fPtBorderForQt(0),
    fXVertexCut(0.),
    fYVertexCut(0.),
    fZVertexCut(0.),
@@ -145,7 +147,7 @@ AliConversionCuts::AliConversionCuts(const char *name,const char *title) :
    fUseCorrectedTPCClsInfo(kFALSE),
    fUseTOFpid(kFALSE),
    fMultiplicityMethod(0),
-   fSelectV0AND(kFALSE),
+   fSpecialTrigger(0),
    fRemovePileUp(kFALSE),
    fOpeningAngle(0.005),
    fPsiPairCut(10000),
@@ -155,13 +157,15 @@ AliConversionCuts::AliConversionCuts(const char *name,const char *title) :
    fminV0Dist(200.),
    fDoSharedElecCut(kFALSE),
    fOfflineTriggerMask(0),
+   fHasV0AND(kTRUE),
+   fIsSDDFired(kTRUE),
    fRandom(0),
-   fSizeElectronArray(500),
+   fElectronArraySize(500),
    fElectronLabelArray(NULL),
-   fConversionPointXArray(0),
-   fConversionPointYArray(0),
-   fConversionPointZArray(0),
-   fnHeaders(100),
+   fConversionPointXArray(0.0),
+   fConversionPointYArray(0.0),
+   fConversionPointZArray(0.0),
+   fnHeaders(0),
    fNotRejectedStart(NULL),
    fNotRejectedEnd(NULL),
    fGeneratorNames(NULL),
@@ -169,8 +173,11 @@ AliConversionCuts::AliConversionCuts(const char *name,const char *title) :
    hdEdxCuts(NULL),
    hTPCdEdxbefore(NULL),
    hTPCdEdxafter(NULL),
+   hTPCdEdxSigbefore(NULL),
+   hTPCdEdxSigafter(NULL),
    hTOFbefore(NULL),
-   hTOFafter(NULL),
+   hTOFSigbefore(NULL),
+   hTOFSigafter(NULL),
    hTrackCuts(NULL),
    hPhotonCuts(NULL),
    hInvMassbefore(NULL),
@@ -188,7 +195,7 @@ AliConversionCuts::AliConversionCuts(const char *name,const char *title) :
    for(Int_t jj=0;jj<kNCuts;jj++){fCuts[jj]=0;}
    fCutString=new TObjString((GetCutNumber()).Data());
 
-   fElectronLabelArray = new Int_t[500];
+   fElectronLabelArray = new Int_t[fElectronArraySize];
 
 }
 
@@ -249,7 +256,7 @@ void AliConversionCuts::InitCutHistograms(TString name, Bool_t preCut){
    fHistograms->Add(hCutIndex);
 
    // Track Cuts
-   hTrackCuts=new TH1F(Form("TrackCuts %s",GetCutNumber().Data()),"TrackCuts",10,-0.5,9.5);
+   hTrackCuts=new TH1F(Form("TrackCuts %s",GetCutNumber().Data()),"TrackCuts",9,-0.5,8.5);
    hTrackCuts->GetXaxis()->SetBinLabel(1,"in");
    hTrackCuts->GetXaxis()->SetBinLabel(2,"likesign");
    hTrackCuts->GetXaxis()->SetBinLabel(3,"ntpccl");
@@ -275,12 +282,12 @@ void AliConversionCuts::InitCutHistograms(TString name, Bool_t preCut){
    fHistograms->Add(hPhotonCuts);
 
    if(preCut){
-      hInvMassbefore=new TH1F(Form("InvMass_before %s",GetCutNumber().Data()),"InvMass_before",100,0,0.3);
+      hInvMassbefore=new TH1F(Form("InvMass_before %s",GetCutNumber().Data()),"InvMass_before",1000,0,0.3);
       fHistograms->Add(hInvMassbefore);
-      hArmenterosbefore=new TH2F(Form("Armenteros_before %s",GetCutNumber().Data()),"Armenteros_before",200,-1,1,250,0,0.25);
+      hArmenterosbefore=new TH2F(Form("Armenteros_before %s",GetCutNumber().Data()),"Armenteros_before",200,-1,1,1000,0,1.);
       fHistograms->Add(hArmenterosbefore);
    }
-   hInvMassafter=new TH1F(Form("InvMass_after %s",GetCutNumber().Data()),"InvMass_after",100,0,0.3);
+   hInvMassafter=new TH1F(Form("InvMass_after %s",GetCutNumber().Data()),"InvMass_after",1000,0,0.3);
    fHistograms->Add(hInvMassafter);
    hArmenterosafter=new TH2F(Form("Armenteros_after %s",GetCutNumber().Data()),"Armenteros_after",200,-1,1,250,0,0.25);
    fHistograms->Add(hArmenterosafter);
@@ -309,25 +316,37 @@ void AliConversionCuts::InitCutHistograms(TString name, Bool_t preCut){
    hdEdxCuts->GetXaxis()->SetBinLabel(9,"TRDelectron");
    hdEdxCuts->GetXaxis()->SetBinLabel(10,"out");
    fHistograms->Add(hdEdxCuts);
-    
+
    TAxis *AxisBeforedEdx = NULL;
+   TAxis *AxisBeforedEdxSig = NULL;
    TAxis *AxisBeforeTOF = NULL;
+   TAxis *AxisBeforeTOFSig = NULL;
    if(preCut){
-      hTPCdEdxbefore=new TH2F(Form("Gamma_dEdx_before %s",GetCutNumber().Data()),"dEdx Gamma before" ,150,0.05,20,400,-10,10);
+      hTPCdEdxbefore=new TH2F(Form("Gamma_dEdx_before %s",GetCutNumber().Data()),"dEdx Gamma before" ,150,0.03,20,800,0,200);
       fHistograms->Add(hTPCdEdxbefore);
-      AxisBeforedEdx = hTPCdEdxbefore->GetXaxis(); 
+      AxisBeforedEdx = hTPCdEdxbefore->GetXaxis();
+      hTPCdEdxSigbefore=new TH2F(Form("Gamma_dEdxSig_before %s",GetCutNumber().Data()),"dEdx Sigma Gamma before" ,150,0.03,20,400,-10,10);
+      fHistograms->Add(hTPCdEdxSigbefore);
+      AxisBeforedEdxSig = hTPCdEdxSigbefore->GetXaxis();
 
-      hTOFbefore=new TH2F(Form("Gamma_TOF_before %s",GetCutNumber().Data()),"TOF Gamma before" ,150,0.05,20,400,-6,10);
+      hTOFbefore=new TH2F(Form("Gamma_TOF_before %s",GetCutNumber().Data()),"TOF Gamma before" ,150,0.03,20,11000,-1000,10000);
       fHistograms->Add(hTOFbefore);
-      AxisBeforeTOF = hTOFbefore->GetXaxis(); 
+      AxisBeforeTOF = hTOFbefore->GetXaxis();
+      hTOFSigbefore=new TH2F(Form("Gamma_TOFSig_before %s",GetCutNumber().Data()),"TOF Sigma Gamma before" ,150,0.03,20,400,-6,10);
+      fHistograms->Add(hTOFSigbefore);
+      AxisBeforeTOFSig = hTOFSigbefore->GetXaxis();
+
    }
-   hTPCdEdxafter=new TH2F(Form("Gamma_dEdx_after %s",GetCutNumber().Data()),"dEdx Gamma after" ,150,0.05,20,400, -10,10);
+   hTPCdEdxSigafter=new TH2F(Form("Gamma_dEdxSig_after %s",GetCutNumber().Data()),"dEdx Sigma Gamma after" ,150,0.03,20,400, -10,10);
+   fHistograms->Add(hTPCdEdxSigafter);
+
+   hTPCdEdxafter=new TH2F(Form("Gamma_dEdx_after %s",GetCutNumber().Data()),"dEdx Gamma after" ,150,0.03,20,800,0,200);
    fHistograms->Add(hTPCdEdxafter);
 
-   hTOFafter=new TH2F(Form("Gamma_TOF_after %s",GetCutNumber().Data()),"TOF Gamma after" ,150,0.05,20,400,-6,10);
-   fHistograms->Add(hTOFafter);
+   hTOFSigafter=new TH2F(Form("Gamma_TOFSig_after %s",GetCutNumber().Data()),"TOF Sigma Gamma after" ,150,0.03,20,400,-6,10);
+   fHistograms->Add(hTOFSigafter);
 
-   TAxis *AxisAfter = hTPCdEdxafter->GetXaxis(); 
+   TAxis *AxisAfter = hTPCdEdxSigafter->GetXaxis();
    Int_t bins = AxisAfter->GetNbins();
    Double_t from = AxisAfter->GetXmin();
    Double_t to = AxisAfter->GetXmax();
@@ -336,38 +355,69 @@ void AliConversionCuts::InitCutHistograms(TString name, Bool_t preCut){
    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 = hTOFSigafter->GetXaxis();
+   AxisAfter->Set(bins, newBins);
+   AxisAfter = hTPCdEdxafter->GetXaxis();
    AxisAfter->Set(bins, newBins);
    if(preCut){
       AxisBeforedEdx->Set(bins, newBins);
       AxisBeforeTOF->Set(bins, newBins);
+      AxisBeforedEdxSig->Set(bins, newBins);
+      AxisBeforeTOFSig->Set(bins, newBins);
    }
    delete [] newBins;
-        
+
    // Event Cuts and Info
    if(preCut){
-      hV0EventCuts=new TH1F(Form("ESD_EventCuts %s",GetCutNumber().Data()),"Event Cuts",10,-0.5,9.5);
+      hV0EventCuts=new TH1F(Form("ESD_EventCuts %s",GetCutNumber().Data()),"Event Cuts",7,-0.5,6.5);
       hV0EventCuts->GetXaxis()->SetBinLabel(1,"in");
       hV0EventCuts->GetXaxis()->SetBinLabel(2,"OfflineTrigger");
-      hV0EventCuts->GetXaxis()->SetBinLabel(3,"VertexZ");
-      hV0EventCuts->GetXaxis()->SetBinLabel(4,"nvtxcontr");
+      hV0EventCuts->GetXaxis()->SetBinLabel(3,"nvtxcontr");
+      hV0EventCuts->GetXaxis()->SetBinLabel(4,"VertexZ");
       hV0EventCuts->GetXaxis()->SetBinLabel(5,"pileup");
       hV0EventCuts->GetXaxis()->SetBinLabel(6,"centrsel");
       hV0EventCuts->GetXaxis()->SetBinLabel(7,"out");
       fHistograms->Add(hV0EventCuts);
-       
+
       hCentrality=new TH1F(Form("Centrality %s",GetCutNumber().Data()),"Centrality",100,0,100);
       fHistograms->Add(hCentrality);
       hVertexZ=new TH1F(Form("VertexZ %s",GetCutNumber().Data()),"VertexZ",1000,-50,50);
       fHistograms->Add(hVertexZ);
-       
-      hTriggerClass= new TH1F(Form("OfflineTrigger %s",GetCutNumber().Data()),"OfflineTrigger",4,-0.5,5.5);
-      hTriggerClass->GetXaxis()->SetBinLabel(1,"kAny");
-      hTriggerClass->GetXaxis()->SetBinLabel(2,"kMB");
-      hTriggerClass->GetXaxis()->SetBinLabel(3,"kCentral");
-      hTriggerClass->GetXaxis()->SetBinLabel(4,"kSemiCentral");
-      hTriggerClass->GetXaxis()->SetBinLabel(4,"kCINT5");
-      hTriggerClass->GetXaxis()->SetBinLabel(5,"kINT7");
+
+      hTriggerClass= new TH1F(Form("OfflineTrigger %s",GetCutNumber().Data()),"OfflineTrigger",33,-0.5,32.5);
+      hTriggerClass->GetXaxis()->SetBinLabel( 1,"kMB");
+      hTriggerClass->GetXaxis()->SetBinLabel( 2,"kINT7");
+      hTriggerClass->GetXaxis()->SetBinLabel( 3,"kMUON");
+      hTriggerClass->GetXaxis()->SetBinLabel( 4,"kHighMult");
+      hTriggerClass->GetXaxis()->SetBinLabel( 5,"kKEMC1");
+      hTriggerClass->GetXaxis()->SetBinLabel( 6,"kCINT5");
+      hTriggerClass->GetXaxis()->SetBinLabel( 7,"kCMUS5/kMUSPB");
+      hTriggerClass->GetXaxis()->SetBinLabel( 8,"kMUSH7/kMUSHPB");
+      hTriggerClass->GetXaxis()->SetBinLabel( 9,"kMUL7/kMuonLikePB");
+      hTriggerClass->GetXaxis()->SetBinLabel(10,"kMUU7/kMuonUnlikePB");
+      hTriggerClass->GetXaxis()->SetBinLabel(11,"kEMC7/kEMC8");
+      hTriggerClass->GetXaxis()->SetBinLabel(12,"kMUS7");
+      hTriggerClass->GetXaxis()->SetBinLabel(13,"kPHI1");
+      hTriggerClass->GetXaxis()->SetBinLabel(14,"kPHI7/kPHI8/kPHOSPb");
+      hTriggerClass->GetXaxis()->SetBinLabel(15,"kEMCEJE");
+      hTriggerClass->GetXaxis()->SetBinLabel(16,"kEMCEGA");
+      hTriggerClass->GetXaxis()->SetBinLabel(17,"kCentral");
+      hTriggerClass->GetXaxis()->SetBinLabel(18,"kSemiCentral");
+      hTriggerClass->GetXaxis()->SetBinLabel(19,"kDG5");
+      hTriggerClass->GetXaxis()->SetBinLabel(20,"kZED");
+      hTriggerClass->GetXaxis()->SetBinLabel(21,"kSPI7/kSPI");
+      hTriggerClass->GetXaxis()->SetBinLabel(22,"kINT8");
+      hTriggerClass->GetXaxis()->SetBinLabel(23,"kMuonSingleLowPt8");
+      hTriggerClass->GetXaxis()->SetBinLabel(24,"kMuonSingleHighPt8");
+      hTriggerClass->GetXaxis()->SetBinLabel(25,"kMuonLikeLowPt8");
+      hTriggerClass->GetXaxis()->SetBinLabel(26,"kMuonUnlikeLowPt8");
+      hTriggerClass->GetXaxis()->SetBinLabel(27,"kMuonUnlikeLowPt0");
+      hTriggerClass->GetXaxis()->SetBinLabel(28,"kUserDefined");
+      hTriggerClass->GetXaxis()->SetBinLabel(29,"kFastOnly");
+      hTriggerClass->GetXaxis()->SetBinLabel(30,"kAnyINT");
+      hTriggerClass->GetXaxis()->SetBinLabel(31,"kAny");
+      hTriggerClass->GetXaxis()->SetBinLabel(32,"V0AND");
+      hTriggerClass->GetXaxis()->SetBinLabel(33,"NOT kFastOnly");
       fHistograms->Add(hTriggerClass);
    }
 }
@@ -377,13 +427,13 @@ Bool_t AliConversionCuts::InitPIDResponse(){
    // Set Pointer to AliPIDResponse
 
    AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
-   if(man) { 
+   if(man) {
       AliInputEventHandler* inputHandler = (AliInputEventHandler*) (man->GetInputEventHandler());
       fPIDResponse = (AliPIDResponse*)inputHandler->GetPIDResponse();
       if(fPIDResponse)return kTRUE;
-    
+
    }
-  
+
 
    return kFALSE;
 }
@@ -394,7 +444,7 @@ Bool_t AliConversionCuts::EventIsSelected(AliVEvent *fInputEvent, AliVEvent *fMC
    Int_t cutindex=0;
    if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
    cutindex++;
-    
+
    // Check for MC event
    if(fMCEvent){
       // Check if MC event is correctly loaded
@@ -416,28 +466,33 @@ Bool_t AliConversionCuts::EventIsSelected(AliVEvent *fInputEvent, AliVEvent *fMC
          return kFALSE;
       }
    }
-    
-   // Event Trigger
 
+   // Event Trigger
    if(!IsTriggerSelected()){
       if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
       fEventQuality = 3;
       return kFALSE;
    }
    cutindex++;
+   
+   if(fInputEvent->IsA()==AliESDEvent::Class()){
+      AliTriggerAnalysis fTriggerAnalysis;// = new AliTriggerAnalysis;
+      fHasV0AND = fTriggerAnalysis.IsOfflineTriggerFired((AliESDEvent*)fInputEvent, AliTriggerAnalysis::kV0AND);
+      if(fHasV0AND&&hTriggerClass)hTriggerClass->Fill(31);
+   }
 
-   // Z Vertex Position Cut
-   if(!VertexZCut(fInputEvent)){
+   // Number of Contributors Cut
+   if(GetNumberOfContributorsVtx(fInputEvent)<=0) {
       if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
-      fEventQuality = 4;
+      fEventQuality = 5;
       return kFALSE;
    }
    cutindex++;
 
-   // Number of Contributors Cut
-   if(GetNumberOfContributorsVtx(fInputEvent)<=0) {
+   // Z Vertex Position Cut
+   if(!VertexZCut(fInputEvent)){
       if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
-      fEventQuality = 5;
+      fEventQuality = 4;
       return kFALSE;
    }
    cutindex++;
@@ -454,7 +509,7 @@ Bool_t AliConversionCuts::EventIsSelected(AliVEvent *fInputEvent, AliVEvent *fMC
    cutindex++;
 
    // Centrality Selection
-   if(!IsCentralitySelected(fInputEvent)){
+   if(!IsCentralitySelected(fInputEvent,fMCEvent)){
       if(hV0EventCuts)hV0EventCuts->Fill(cutindex);
       fEventQuality = 1;
       return kFALSE;
@@ -477,9 +532,9 @@ Bool_t AliConversionCuts::PhotonIsSelectedMC(TParticle *particle,AliStack *fMCSt
    if(!fMCStack)return kFALSE;
 
    if (particle->GetPdgCode() == 22){
-              
-      if(particle->R() > fMaxR)        return kFALSE;
-      if(TMath::Abs(particle->Eta())> fEtaCut || TMath::Abs(particle->Eta())< fEtaCutMin)      return kFALSE;
+
+      if(particle->R() > fMaxR) return kFALSE;
+      if(abs(particle->Eta())> fEtaCut || abs(particle->Eta())< fEtaCutMin) return kFALSE;
 
       if(particle->GetMother(0) >-1 && fMCStack->Particle(particle->GetMother(0))->GetPdgCode() == 22){
          return kFALSE; // no photon as mothers!
@@ -511,39 +566,39 @@ Bool_t AliConversionCuts::PhotonIsSelectedMC(TParticle *particle,AliStack *fMCSt
       if(ePos == NULL || eNeg == NULL){ // means we do not have two daughters from pair production
          return kFALSE;
       }
-        
+
       if(ePos->Pt()<fSinglePtCut || eNeg->Pt()<fSinglePtCut){
          return kFALSE; // no reconstruction below the Pt cut
       }
-       
-      if( TMath::Abs(ePos->Eta())> fEtaCut || TMath::Abs(ePos->Eta())< fEtaCutMin || 
-          TMath::Abs(eNeg->Eta())> fEtaCut || TMath::Abs(eNeg->Eta())< fEtaCutMin ) {
+
+      if( abs(ePos->Eta())> fEtaCut || abs(ePos->Eta())< fEtaCutMin ||
+          abs(eNeg->Eta())> fEtaCut || abs(eNeg->Eta())< fEtaCutMin ) {
          return kFALSE;
       }
-       
+
       if(ePos->R()>fMaxR){
          return kFALSE; // cuts on distance from collision point
       }
 
-      if(TMath::Abs(ePos->Vz()) > fMaxZ){
+      if(abs(ePos->Vz()) > fMaxZ){
          return kFALSE;         // outside material
       }
-      if(TMath::Abs(eNeg->Vz()) > fMaxZ){
+      if(abs(eNeg->Vz()) > fMaxZ){
          return kFALSE;         // outside material
       }
 
-      if( ePos->R() <= ((TMath::Abs(ePos->Vz()) * fLineCutZRSlope) - fLineCutZValue)){
+      if( ePos->R() <= ((abs(ePos->Vz()) * fLineCutZRSlope) - fLineCutZValue)){
          return kFALSE;  // line cut to exclude regions where we do not reconstruct
-      } else if ( fEtaCutMin != -0.1 &&   ePos->R() >= ((TMath::Abs(ePos->Vz()) * fLineCutZRSlopeMin) - fLineCutZValueMin)){
+      } else if ( fEtaCutMin != -0.1 &&   ePos->R() >= ((abs(ePos->Vz()) * fLineCutZRSlopeMin) - fLineCutZValueMin)){
          return kFALSE;
       }
-       
-      if( eNeg->R() <= ((TMath::Abs(eNeg->Vz()) * fLineCutZRSlope) - fLineCutZValue)){
+
+      if( eNeg->R() <= ((abs(eNeg->Vz()) * fLineCutZRSlope) - fLineCutZValue)){
          return kFALSE; // line cut to exclude regions where we do not reconstruct
-      } else if ( fEtaCutMin != -0.1 &&   eNeg->R() >= ((TMath::Abs(eNeg->Vz()) * fLineCutZRSlopeMin) - fLineCutZValueMin)){
+      } else if ( fEtaCutMin != -0.1 &&   eNeg->R() >= ((abs(eNeg->Vz()) * fLineCutZRSlopeMin) - fLineCutZValueMin)){
          return kFALSE;
       }
-       
+
       return kTRUE;
       //if(AcceptanceCut(particle,ePos,eNeg))return kTRUE;
    }
@@ -561,6 +616,7 @@ Bool_t AliConversionCuts::PhotonCuts(AliConversionPhotonBase *photon,AliVEvent *
 
    // Fill Histos before Cuts
    if(hInvMassbefore)hInvMassbefore->Fill(photon->GetMass());
+
    if(hArmenterosbefore)hArmenterosbefore->Fill(photon->GetArmenterosAlpha(),photon->GetArmenterosQt());
 
    // Gamma selection based on QT from Armenteros
@@ -655,14 +711,14 @@ Bool_t AliConversionCuts::CorrectedTPCClusterCut(AliConversionPhotonBase *photon
 
    Double_t posclsToF = 0.;
    if (!fUseCorrectedTPCClsInfo ){
-      if(posTrack->GetTPCNclsF()!=0    ){
+      if(posTrack->GetTPCNclsF()!=0){
          posclsToF = (Double_t)posTrack->GetNcls(1)/(Double_t)posTrack->GetTPCNclsF();
       }
    }else{
       posclsToF = posTrack->GetTPCClusterInfo(2,0,GetFirstTPCRow(photon->GetConversionRadius()));
    }
 
-   if( negclsToF < fMinClsTPCToF ||    posclsToF < fMinClsTPCToF ){
+   if( negclsToF < fMinClsTPCToF || posclsToF < fMinClsTPCToF ){
       return kFALSE;
    }
 
@@ -752,24 +808,24 @@ Bool_t AliConversionCuts::AcceptanceCuts(AliConversionPhotonBase *photon) {
    }
    cutIndex++;
 
-   if(photon->GetConversionRadius() <= ((TMath::Abs(photon->GetConversionZ())*fLineCutZRSlope)-fLineCutZValue)){
+   if(photon->GetConversionRadius() <= ((abs(photon->GetConversionZ())*fLineCutZRSlope)-fLineCutZValue)){
       if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
       return kFALSE;
    }
-   else if (fUseEtaMinCut &&  photon->GetConversionRadius() >= ((TMath::Abs(photon->GetConversionZ())*fLineCutZRSlopeMin)-fLineCutZValueMin )){
+   else if (fUseEtaMinCut &&  photon->GetConversionRadius() >= ((abs(photon->GetConversionZ())*fLineCutZRSlopeMin)-fLineCutZValueMin )){
       if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
       return kFALSE;
    }
    cutIndex++;
 
-   if(TMath::Abs(photon->GetConversionZ()) > fMaxZ ){ // cuts out regions where we do not reconstruct
+   if(abs(photon->GetConversionZ()) > fMaxZ ){ // cuts out regions where we do not reconstruct
       if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
       return kFALSE;
    }
    cutIndex++;
 
 
-   if(TMath::Abs(photon->GetPhotonEta())> fEtaCut || TMath::Abs(photon->GetPhotonEta())< fEtaCutMin){
+   if(abs(photon->GetPhotonEta())> fEtaCut || abs(photon->GetPhotonEta())< fEtaCutMin){
       if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
       return kFALSE;
    }
@@ -783,7 +839,7 @@ Bool_t AliConversionCuts::AcceptanceCuts(AliConversionPhotonBase *photon) {
    cutIndex++;
 
    if(hAcceptanceCuts)hAcceptanceCuts->Fill(cutIndex);
+
    return kTRUE;
 }
 
@@ -852,8 +908,8 @@ Bool_t AliConversionCuts::TracksAreSelected(AliVTrack * negTrack, AliVTrack * po
 
    // Acceptance
 
-   if(TMath::Abs(negTrack->Eta()) > fEtaCut || TMath::Abs(negTrack->Eta()) < fEtaCutMin ||
-      TMath::Abs(posTrack->Eta())> fEtaCut || TMath::Abs(posTrack->Eta())< fEtaCutMin) {
+   if(abs(negTrack->Eta()) > fEtaCut || abs(negTrack->Eta()) < fEtaCutMin ||
+      abs(posTrack->Eta())> fEtaCut || abs(posTrack->Eta())< fEtaCutMin) {
       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
       return kFALSE;
    }
@@ -871,9 +927,9 @@ Bool_t AliConversionCuts::TracksAreSelected(AliVTrack * negTrack, AliVTrack * po
 
    if(negTrack->IsA()==AliAODTrack::Class()) {
       passCuts = passCuts * SpecificTrackCuts(static_cast<AliAODTrack*>(negTrack), static_cast<AliAODTrack*>(posTrack),cutIndex);
-   } else { 
+   } else {
       passCuts = passCuts * SpecificTrackCuts(static_cast<AliESDtrack*>(negTrack), static_cast<AliESDtrack*>(posTrack),cutIndex);
-   }   
+   }
 
    if(!passCuts){
       if(hTrackCuts)hTrackCuts->Fill(cutIndex);
@@ -884,7 +940,7 @@ Bool_t AliConversionCuts::TracksAreSelected(AliVTrack * negTrack, AliVTrack * po
    if(hTrackCuts)hTrackCuts->Fill(cutIndex);
 
    return kTRUE;
-                   
+
 }
 
 ///________________________________________________________________________
@@ -896,9 +952,10 @@ Bool_t AliConversionCuts::dEdxCuts(AliVTrack *fCurrentTrack){
 
    Int_t cutIndex=0;
    if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
-   if(hTPCdEdxbefore)hTPCdEdxbefore->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTPC(fCurrentTrack, AliPID::kElectron));
+   if(hTPCdEdxSigbefore)hTPCdEdxSigbefore->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTPC(fCurrentTrack, AliPID::kElectron));
+   if(hTPCdEdxbefore)hTPCdEdxbefore->Fill(fCurrentTrack->P(),fCurrentTrack->GetTPCsignal());
    cutIndex++;
-    
+
 
    if(fDodEdxSigmaCut == kTRUE){
       // TPC Electron Line
@@ -921,11 +978,11 @@ Bool_t AliConversionCuts::dEdxCuts(AliVTrack *fCurrentTrack){
          }
       }
       cutIndex++;
-   
+
       // High Pt Pion rej
       if( fCurrentTrack->P()>fPIDMaxPnSigmaAbovePionLine ){
          if(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)>fPIDnSigmaBelowElectronLine &&
-            fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)<fPIDnSigmaAboveElectronLine&&
+            fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kElectron)<fPIDnSigmaAboveElectronLine &&
             fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kPion)<fPIDnSigmaAbovePionLineHighPt){
 
             if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
@@ -938,7 +995,7 @@ Bool_t AliConversionCuts::dEdxCuts(AliVTrack *fCurrentTrack){
 
    if(fDoKaonRejectionLowP == kTRUE){
       if(fCurrentTrack->P()<fPIDMinPKaonRejectionLowP ){
-         if( TMath::Abs(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kKaon))<fPIDnSigmaAtLowPAroundKaonLine){
+         if( abs(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kKaon))<fPIDnSigmaAtLowPAroundKaonLine){
 
             if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
             return kFALSE;
@@ -946,10 +1003,10 @@ Bool_t AliConversionCuts::dEdxCuts(AliVTrack *fCurrentTrack){
       }
    }
    cutIndex++;
-   
+
    if(fDoProtonRejectionLowP == kTRUE){
       if( fCurrentTrack->P()<fPIDMinPProtonRejectionLowP ){
-         if( TMath::Abs(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kProton))<fPIDnSigmaAtLowPAroundProtonLine){
+         if( abs(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kProton))<fPIDnSigmaAtLowPAroundProtonLine){
 
             if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
             return kFALSE;
@@ -957,10 +1014,10 @@ Bool_t AliConversionCuts::dEdxCuts(AliVTrack *fCurrentTrack){
       }
    }
    cutIndex++;
-   
+
    if(fDoPionRejectionLowP == kTRUE){
       if( fCurrentTrack->P()<fPIDMinPPionRejectionLowP ){
-         if( TMath::Abs(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kPion))<fPIDnSigmaAtLowPAroundPionLine){
+         if( abs(fPIDResponse->NumberOfSigmasTPC(fCurrentTrack,AliPID::kPion))<fPIDnSigmaAtLowPAroundPionLine){
 
             if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
             return kFALSE;
@@ -968,9 +1025,31 @@ Bool_t AliConversionCuts::dEdxCuts(AliVTrack *fCurrentTrack){
       }
    }
    cutIndex++;
+
+
+   // cout<<"Start"<<endl;
+   // AliPIDResponse::EDetPidStatus status=fPIDResponse->CheckPIDStatus(AliPIDResponse::kTOF,fCurrentTrack);
+   
+   // if( ( (status & AliVTrack::kTOFout) == AliVTrack::kTOFout ) && ( (status & AliVTrack::kTIME) == AliVTrack::kTIME ))
+   //    {cout<<"TOF DA"<<endl;}
+   // if(status == AliPIDResponse::kDetPidOk){      
+   //    Float_t probMis = fPIDResponse->GetTOFMismatchProbability(fCurrentTrack);
+   //    cout<<"--> "<<probMis<<endl;
+   //    if(probMis > 0.01){
+         
+   //    }
+   // }
    
    if((fCurrentTrack->GetStatus() & AliESDtrack::kTOFpid) && !(fCurrentTrack->GetStatus() & AliESDtrack::kTOFmismatch)){
-      if(hTOFbefore) hTOFbefore->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTOF(fCurrentTrack, AliPID::kElectron));
+      if(hTOFbefore){
+         Double_t t0 = fPIDResponse->GetTOFResponse().GetStartTime(fCurrentTrack->P());
+         Double_t times[5];
+         fCurrentTrack->GetIntegratedTimes(times);
+         Double_t TOFsignal =  fCurrentTrack->GetTOFsignal();
+         Double_t dT = TOFsignal - t0 - times[0];
+         hTOFbefore->Fill(fCurrentTrack->P(),dT);
+      }
+      if(hTOFSigbefore) hTOFSigbefore->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTOF(fCurrentTrack, AliPID::kElectron));
       if(fUseTOFpid){
          if(fPIDResponse->NumberOfSigmasTOF(fCurrentTrack, AliPID::kElectron)>fTofPIDnSigmaAboveElectronLine ||
             fPIDResponse->NumberOfSigmasTOF(fCurrentTrack, AliPID::kElectron)<fTofPIDnSigmaBelowElectronLine ){
@@ -978,14 +1057,13 @@ Bool_t AliConversionCuts::dEdxCuts(AliVTrack *fCurrentTrack){
             return kFALSE;
          }
       }
-      if(hTOFafter)hTOFafter->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTOF(fCurrentTrack, AliPID::kElectron));
+      if(hTOFSigafter)hTOFSigafter->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTOF(fCurrentTrack, AliPID::kElectron));
    }
    cutIndex++;
-   
+
    // Apply TRD PID
    if(fDoTRDPID){
       if(!fPIDResponse->IdentifiedAsElectronTRD(fCurrentTrack,fPIDTRDEfficiency)){
-
          if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
          return kFALSE;
       }
@@ -993,8 +1071,8 @@ Bool_t AliConversionCuts::dEdxCuts(AliVTrack *fCurrentTrack){
    cutIndex++;
 
    if(hdEdxCuts)hdEdxCuts->Fill(cutIndex);
-   if(hTPCdEdxafter)hTPCdEdxafter->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTPC(fCurrentTrack, AliPID::kElectron));
-
+   if(hTPCdEdxSigafter)hTPCdEdxSigafter->Fill(fCurrentTrack->P(),fPIDResponse->NumberOfSigmasTPC(fCurrentTrack, AliPID::kElectron));
+   if(hTPCdEdxafter)hTPCdEdxafter->Fill(fCurrentTrack->P(),fCurrentTrack->GetTPCsignal());
    return kTRUE;
 }
 
@@ -1032,23 +1110,39 @@ AliVTrack *AliConversionCuts::GetTrack(AliVEvent * event, Int_t label){
       if(label > event->GetNumberOfTracks() ) return NULL;
       AliESDtrack * track = esdEvent->GetTrack(label);
       return track;
-       
-   } else { 
+
+   } else {
       for(Int_t ii=0; ii<event->GetNumberOfTracks(); ii++) {
          AliVTrack * track = dynamic_cast<AliVTrack*>(event->GetTrack(ii));
-         
-         if(track) { 
+
+         if(track) {
             if(track->GetID() == label) {
                return track;
             }
          }
       }
    }
-  
+
    //AliDebug(5,(Form("track not found %d %d",label,event->GetNumberOfTracks()));
    return NULL;
 }
 
+///________________________________________________________________________
+AliESDtrack *AliConversionCuts::GetESDTrack(AliESDEvent * 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)
+
+   if(event) {
+      if(label > event->GetNumberOfTracks() ) return NULL;
+      AliESDtrack * track = event->GetTrack(label);
+      return track;
+   }
+   //AliDebug(5,(Form("track not found %d %d",label,event->GetNumberOfTracks()));
+   return NULL;
+}
+
+
 
 ///________________________________________________________________________
 Bool_t AliConversionCuts::PIDProbabilityCut(AliConversionPhotonBase *photon, AliVEvent * event){
@@ -1057,17 +1151,17 @@ Bool_t AliConversionCuts::PIDProbabilityCut(AliConversionPhotonBase *photon, Ali
    AliESDEvent * esdEvent = dynamic_cast<AliESDEvent*>(event);
 
    if(esdEvent){
-       
+
       Bool_t iResult=kFALSE;
-       
+
       Double_t *posProbArray = new Double_t[AliPID::kSPECIES];
       Double_t *negProbArray = new Double_t[AliPID::kSPECIES];
-       
+
       AliESDtrack* negTrack    = esdEvent->GetTrack(photon->GetTrackLabelNegative());
       AliESDtrack* posTrack    = esdEvent->GetTrack(photon->GetTrackLabelPositive());
-       
+
       if(negProbArray && posProbArray){
-         
+
          negTrack->GetTPCpid(negProbArray);
          posTrack->GetTPCpid(posProbArray);
 
@@ -1075,7 +1169,7 @@ Bool_t AliConversionCuts::PIDProbabilityCut(AliConversionPhotonBase *photon, Ali
             iResult=kTRUE;
          }
       }
-       
+
       delete [] posProbArray;
       delete [] negProbArray;
       return iResult;
@@ -1087,7 +1181,7 @@ Bool_t AliConversionCuts::PIDProbabilityCut(AliConversionPhotonBase *photon, Ali
 
 
 
-  
+
 }
 
 
@@ -1107,14 +1201,14 @@ Bool_t AliConversionCuts::AcceptanceCut(TParticle *particle, TParticle * ePos,TP
       return kFALSE;
    }
 
-   if( ePos->R() <= ((TMath::Abs(ePos->Vz())*fLineCutZRSlope)-fLineCutZValue)){
+   if( ePos->R() <= ((abs(ePos->Vz())*fLineCutZRSlope)-fLineCutZValue)){
       return kFALSE;
    }
-   else if (fUseEtaMinCut &&  ePos->R() >= ((TMath::Abs(ePos->Vz())*fLineCutZRSlopeMin)-fLineCutZValueMin )){
+   else if (fUseEtaMinCut &&  ePos->R() >= ((abs(ePos->Vz())*fLineCutZRSlopeMin)-fLineCutZValueMin )){
       return kFALSE;
    }
 
-   if(TMath::Abs(eNeg->Vz()) > fMaxZ ){ // cuts out regions where we do not reconstruct
+   if(abs(eNeg->Vz()) > fMaxZ ){ // cuts out regions where we do not reconstruct
       return kFALSE;
    }
 
@@ -1122,19 +1216,19 @@ Bool_t AliConversionCuts::AcceptanceCut(TParticle *particle, TParticle * ePos,TP
       return kFALSE;
    }
 
-   if(TMath::Abs(ePos->Vz()) > fMaxZ ){ // cuts out regions where we do not reconstruct
+   if(abs(ePos->Vz()) > fMaxZ ){ // cuts out regions where we do not reconstruct
       return kFALSE;
    }
 
-   if(TMath::Abs(particle->Eta())> fEtaCut || TMath::Abs(particle->Eta())< fEtaCutMin){
+   if(abs(particle->Eta())> fEtaCut || abs(particle->Eta())< fEtaCutMin){
       return kFALSE;
    }
 
-   if(TMath::Abs(ePos->Eta())> fEtaCut || TMath::Abs(ePos->Eta())< fEtaCutMin){
+   if(abs(ePos->Eta())> fEtaCut || abs(ePos->Eta())< fEtaCutMin){
       return kFALSE;
    }
 
-   if(TMath::Abs(eNeg->Eta())> fEtaCut || TMath::Abs(eNeg->Eta())< fEtaCutMin){
+   if(abs(eNeg->Eta())> fEtaCut || abs(eNeg->Eta())< fEtaCutMin){
       return kFALSE;
    }
 
@@ -1149,7 +1243,7 @@ Bool_t AliConversionCuts::AcceptanceCut(TParticle *particle, TParticle * ePos,TP
    return kTRUE;
 }
 ///________________________________________________________________________
-Bool_t AliConversionCuts::UpdateCutString(cutIds cutID, Int_t value) {
+Bool_t AliConversionCuts::UpdateCutString() {
    ///Update the cut string (if it has been created yet)
 
    if(fCutString && fCutString->GetString().Length() == kNCuts) {
@@ -1173,7 +1267,7 @@ Bool_t AliConversionCuts::InitializeCutsFromCutString(const TString analysisCutS
       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++){
@@ -1198,160 +1292,159 @@ Bool_t AliConversionCuts::InitializeCutsFromCutString(const TString analysisCutS
 Bool_t AliConversionCuts::SetCut(cutIds cutID, const Int_t value) {
    ///Set individual cut ID
 
-
    switch (cutID) {
+
    case kv0FinderType:
       if( SetV0Finder(value)) {
          fCuts[kv0FinderType] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
    case kededxSigmaCut:
       if( SetTPCdEdxCutElectronLine(value)) {
          fCuts[kededxSigmaCut] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
    case kpidedxSigmaCut:
       if( SetTPCdEdxCutPionLine(value)) {
          fCuts[kpidedxSigmaCut] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
    case kpiMomdedxSigmaCut:
       if( SetMinMomPiondEdxCut(value)) {
          fCuts[kpiMomdedxSigmaCut] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
    case kchi2GammaCut:
       if( SetChi2GammaCut(value)) {
          fCuts[kchi2GammaCut] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
    case ksinglePtCut:
       if( SetSinglePtCut(value)) {
          fCuts[ksinglePtCut] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
    case kclsTPCCut:
       if( SetTPCClusterCut(value)) {
          fCuts[kclsTPCCut] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
    case ketaCut:
       if( SetEtaCut(value)) {
          fCuts[ketaCut] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
    case kLowPRejectionSigmaCut:
       if( SetLowPRejectionCuts(value)) {
          fCuts[kLowPRejectionSigmaCut] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
    case kQtMaxCut:
       if( SetQtMaxCut(value)) {
          fCuts[kQtMaxCut] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
    case kpiMaxMomdedxSigmaCut:
       if( SetMaxMomPiondEdxCut(value)) {
          fCuts[kpiMaxMomdedxSigmaCut] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
    case kRCut:
       if( SetRCut(value)) {
          fCuts[kRCut] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
    case kremovePileUp:
       if( SetRemovePileUp(value)) {
          fCuts[kremovePileUp] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
    case kselectV0AND:
-      if( SetSelectV0AND(value)) {
+      if( SetSelectSpecialTrigger(value)) {
          fCuts[kselectV0AND] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
    case kmultiplicityMethod:
       if( SetMultiplicityMethod(value)) {
          fCuts[kmultiplicityMethod] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
    case kisHeavyIon:
       if( SetIsHeavyIon(value)) {
          fCuts[kisHeavyIon] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
    case kCentralityMin:
       if( SetCentralityMin(value)) {
          fCuts[kCentralityMin] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
    case kCentralityMax:
       if( SetCentralityMax(value)) {
          fCuts[kCentralityMax] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
    case kTOFelectronPID:
       if( SetTOFElectronPIDCut(value)) {
          fCuts[kTOFelectronPID] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
    case kdoPhotonAsymmetryCut:
       if( SetPhotonAsymmetryCut(value)) {
          fCuts[kdoPhotonAsymmetryCut] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
    case kPsiPair:
       if( SetPsiPairCut(value)) {
          fCuts[kPsiPair] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
    case kCosPAngle:
       if( SetCosPAngleCut(value)) {
          fCuts[kCosPAngle] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
@@ -1359,26 +1452,24 @@ Bool_t AliConversionCuts::SetCut(cutIds cutID, const Int_t value) {
    case kElecShare:
       if( SetSharedElectronCut(value)) {
          fCuts[kElecShare] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
-
    case kToCloseV0s:
       if( SetToCloseV0sCut(value)) {
          fCuts[kToCloseV0s] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
    case kExtraSignals:
       if( SetRejectExtraSignalsCut(value)) {
          fCuts[kExtraSignals] = value;
-         UpdateCutString(cutID, value);
+         UpdateCutString();
          return kTRUE;
       } else return kFALSE;
 
-
    case kNCuts:
       AliError("Cut id out of range");
       return kFALSE;
@@ -1387,41 +1478,110 @@ Bool_t AliConversionCuts::SetCut(cutIds cutID, const Int_t value) {
    AliError("Cut id %d not recognized");
    return kFALSE;
 
+
 }
 ///________________________________________________________________________
-Bool_t AliConversionCuts::SetRemovePileUp(Int_t removePileUp)
-{// Set Cut
-   switch(removePileUp){
+void AliConversionCuts::PrintCuts() {
+   // Print out current Cut Selection
+   for(Int_t ic = 0; ic < kNCuts; ic++) {
+      printf("%-30s : %d \n", fgkCutNames[ic], fCuts[ic]);
+   }
+}
+///________________________________________________________________________
+Bool_t AliConversionCuts::SetIsHeavyIon(Int_t isHeavyIon)
+{   // Set Cut
+   switch(isHeavyIon){
    case 0:
-      fRemovePileUp=kFALSE;
+      fIsHeavyIon=0;
       break;
    case 1:
-      fRemovePileUp=kTRUE;
+      fIsHeavyIon=1;
+      fDetectorCentrality=0;
+      break;
+   case 2:
+      fIsHeavyIon=1;
+      fDetectorCentrality=1;
+      break;
+   case 3: //allows to select centrality 0-45% in steps of 5% for V0 Multiplicity
+      fIsHeavyIon=1;
+      fDetectorCentrality=0;
+      fModCentralityClass=1;
+      break;
+   case 4: //allows to select centrality 45-90% in steps of 5% for V0 Multiplicity
+      fIsHeavyIon=1;
+      fDetectorCentrality=0;
+      fModCentralityClass=2;
+      break;
+   case 5: //strict cut on v0 tracks for MC
+      fIsHeavyIon=1;
+      fDetectorCentrality=0;
+      fModCentralityClass=3;
+      break;
+   case 6: //allows to select centrality 0-45% in steps of 5% for V0 Multiplicity
+      //strict cut on v0 tracks for MC
+      fIsHeavyIon=1;
+      fDetectorCentrality=0;
+      fModCentralityClass=4;
+      break;
+   case 7: //allows to select centrality 45-90% in steps of 5% for V0 Multiplicity
+      //strict cut on v0 tracks for MC
+      fIsHeavyIon=1;
+      fDetectorCentrality=0;
+      fModCentralityClass=5;
       break;
    default:
-      AliError("RemovePileUpCut not defined");
+      AliError(Form("SetHeavyIon not defined %d",isHeavyIon));
       return kFALSE;
    }
    return kTRUE;
 }
+//___________________________________________________________________
+Bool_t AliConversionCuts::SetCentralityMin(Int_t minCentrality)
+{
+   // Set Cut
+   if(minCentrality<0||minCentrality>9){
+      AliError(Form("minCentrality not defined %d",minCentrality));
+      return kFALSE;
+   }
 
+   fCentralityMin=minCentrality;
+   return kTRUE;
+}
+//___________________________________________________________________
+Bool_t AliConversionCuts::SetCentralityMax(Int_t maxCentrality)
+{
+   // Set Cut
+   if(maxCentrality<0||maxCentrality>9){
+      AliError(Form("maxCentrality not defined %d",maxCentrality));
+      return kFALSE;
+   }
+   fCentralityMax=maxCentrality;
+   return kTRUE;
+}
 ///________________________________________________________________________
-Bool_t AliConversionCuts::SetSelectV0AND(Int_t selectV0AND)
+Int_t AliConversionCuts::SetSelectSpecialTrigger(Int_t selectSpecialTrigger)
 {// Set Cut
-   switch(selectV0AND){
+
+   switch(selectSpecialTrigger){
    case 0:
-      fSelectV0AND=kFALSE;
+      fSpecialTrigger=0; // dont care
       break;
    case 1:
-      fSelectV0AND=kTRUE;
+      fSpecialTrigger=1; // V0AND
+      break;
+   case 2:
+      fSpecialTrigger=2; // with SDD requested
+      break;
+   case 3:
+      fSpecialTrigger=3; // V0AND plus with SDD requested
       break;
+
    default:
-      AliError("Warning: V0ANDCut not defined");
+      AliError("Warning: Special Trigger Not known");
       return kFALSE;
    }
    return kTRUE;
 }
-
 ///________________________________________________________________________
 Bool_t AliConversionCuts::SetMultiplicityMethod(Int_t multiplicityMethod)
 {
@@ -1435,17 +1595,135 @@ Bool_t AliConversionCuts::SetMultiplicityMethod(Int_t multiplicityMethod)
 
    return kTRUE;
 }
-
-
 ///________________________________________________________________________
-void AliConversionCuts::PrintCuts() {
-   // Print out current Cut Selection
-   for(Int_t ic = 0; ic < kNCuts; ic++) {
-      printf("%-30s : %d \n", fgkCutNames[ic], fCuts[ic]);
+Bool_t AliConversionCuts::SetRemovePileUp(Int_t removePileUp)
+{// Set Cut
+   switch(removePileUp){
+   case 0:
+      fRemovePileUp=kFALSE;
+      break;
+   case 1:
+      fRemovePileUp=kTRUE;
+      break;
+   default:
+      AliError("RemovePileUpCut not defined");
+      return kFALSE;
    }
+   return kTRUE;
+}
+///________________________________________________________________________
+Bool_t AliConversionCuts::SetRejectExtraSignalsCut(Int_t extraSignal) {
 
+   switch(extraSignal){
+   case 0:
+      fRejectExtraSignals = 0;
+      break; // No Rejection
+   case 1:
+      fRejectExtraSignals = 1;
+      break; // MinBias Header
+   case 2:
+      fRejectExtraSignals = 2;
+      break; // User String Array
+   case 3:
+      fRejectExtraSignals = 3;
+      break; // Rejection for Gamma Correction only
+   default:
+      AliError(Form("Extra Signal Rejection not defined %d",extraSignal));
+      return kFALSE;
+   }
+   return kTRUE;
+}
+///________________________________________________________________________
+Bool_t AliConversionCuts::SetV0Finder(Int_t v0FinderType)
+{   // Set Cut
+   switch (v0FinderType){
+   case 0:  // on fly V0 finder
+      fUseOnFlyV0Finder=kTRUE;
+      break;
+   case 1:  // offline V0 finder
+      fUseOnFlyV0Finder=kFALSE;
+      break;
+   default:
+      AliError(Form(" v0FinderType not defined %d",v0FinderType));
+      return kFALSE;
+   }
+   return kTRUE;
 }
+///________________________________________________________________________
+Bool_t AliConversionCuts::SetEtaCut(Int_t etaCut)
+{   // Set Cut
 
+   //Set Standard LineCutZValues
+   fLineCutZValueMin = -2;
+   fLineCutZValue = 7.;
+
+   switch(etaCut){
+   case 0: // 0.9
+      fEtaCut          = 0.9;
+      fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
+      fEtaCutMin               = -0.1;
+      fLineCutZRSlopeMin = 0.;
+      break;
+   case 1:     // 1.2
+      fEtaCut          = 1.2;
+      fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
+      fEtaCutMin               = -0.1;
+      fLineCutZRSlopeMin = 0.;
+      break;
+   case 2:     // 1.4
+      fEtaCut          = 1.4;
+      fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
+      fEtaCutMin               = -0.1;
+      fLineCutZRSlopeMin = 0.;
+      break;
+   case 3: // 0.8
+      fEtaCut          = 0.8;
+      fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
+      fEtaCutMin               = -0.1;
+      fLineCutZRSlopeMin = 0.;
+      break;
+   case 4: // 1.
+      fEtaCut          = 1.0;
+      fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
+      fEtaCutMin               = -0.1;
+      fLineCutZRSlopeMin = 0.;
+      break;
+   case 5: // 0.9 - 1.4
+      fEtaCut          = 1.4;
+      fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
+      fEtaCutMin               = 0.9;
+      fLineCutZRSlopeMin = tan(2*atan(exp(-fEtaCutMin)));
+      break;
+   case 6: // 5.
+      fEtaCut          = 5.;
+      fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
+      fEtaCutMin               = -0.1;
+      fLineCutZRSlopeMin = 0.;
+      break;
+   case 7: // 0.1 - 0.8
+      fEtaCut          = 0.8;
+      fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
+      fEtaCutMin               = 0.1;
+      fLineCutZRSlopeMin = tan(2*atan(exp(-fEtaCutMin)));
+      break;
+   case 8: // 0.1 - 0.8
+      fEtaCut          = 0.9;
+      fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
+      fEtaCutMin               = 0.1;
+      fLineCutZRSlopeMin = tan(2*atan(exp(-fEtaCutMin)));
+      break;
+   case 9: // 10
+      fEtaCut          = 10;
+      fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
+      fEtaCutMin               = -0.1;
+      fLineCutZRSlopeMin = 0.;
+      break;
+   default:
+      AliError(Form(" EtaCut not defined %d",etaCut));
+      return kFALSE;
+   }
+   return kTRUE;
+}
 ///________________________________________________________________________
 Bool_t AliConversionCuts::SetRCut(Int_t RCut){
    // Set Cut
@@ -1473,7 +1751,7 @@ Bool_t AliConversionCuts::SetRCut(Int_t RCut){
       // High purity cuts for PbPb (remove first layers of material)
    case 5:
       fMaxR = 180.;
-      fMinR = 10.;  
+      fMinR = 10.;
       break;
    case 6:
       fMaxR = 180.;
@@ -1488,8 +1766,8 @@ Bool_t AliConversionCuts::SetRCut(Int_t RCut){
       fMinR = 35.;
       break;
    case 9:
-      fMaxR = 180.;
-      fMinR = 60.;
+      fMaxR = 35.;
+      fMinR = 5.;
       break;
 
    default:
@@ -1498,7 +1776,86 @@ Bool_t AliConversionCuts::SetRCut(Int_t RCut){
    }
    return kTRUE;
 }
-
+///________________________________________________________________________
+Bool_t AliConversionCuts::SetSinglePtCut(Int_t singlePtCut)
+{   // Set Cut
+   switch(singlePtCut){
+   case 0: // 0.050 GeV
+      fSinglePtCut = 0.050;
+      break;
+   case 1:  // 0.100 GeV
+      fSinglePtCut = 0.100;
+      break;
+   case 2:  // 0.150 GeV
+      fSinglePtCut = 0.150;
+      break;
+   case 3:  // 0.200 GeV
+      fSinglePtCut = 0.200;
+      break;
+   case 4:  // 0.075 GeV
+      fSinglePtCut = 0.075;
+      break;
+   case 5:  // 0.125 GeV
+      fSinglePtCut = 0.125;
+      break;
+   case 6:  // 0.04 GeV
+      fSinglePtCut = 0.040;
+      break;
+   case 7:  // 0.0 GeV
+      fSinglePtCut = 0.0;
+      break;
+   default:
+      AliError(Form("singlePtCut not defined %d",singlePtCut));
+      return kFALSE;
+   }
+   return kTRUE;
+}
+///________________________________________________________________________
+Bool_t AliConversionCuts::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:  // 60% of findable clusters
+      fMinClsTPCToF= 0.6;
+      fUseCorrectedTPCClsInfo=0;
+      break;
+   case 5:  // 0% of findable clusters
+      fMinClsTPCToF= 0.0;
+      fUseCorrectedTPCClsInfo=1;
+      break;
+   case 6:  // 70% of findable clusters
+      fMinClsTPCToF= 0.7;
+      fUseCorrectedTPCClsInfo=1;
+      break;
+   case 7:  // 0% of findable clusters
+      fMinClsTPCToF= 0.35;
+      fUseCorrectedTPCClsInfo=0;
+      break;
+   case 8:
+      fMinClsTPCToF= 0.35;
+      fUseCorrectedTPCClsInfo=1;
+      break;
+   case 9:
+      fMinClsTPCToF= 0.6;
+      fUseCorrectedTPCClsInfo=1;
+      break;
+   default:
+      AliError(Form("Warning: clsTPCCut not defined %d",clsTPCCut));
+      return kFALSE;
+   }
+   return kTRUE;
+}
 ///________________________________________________________________________
 Bool_t AliConversionCuts::SetTPCdEdxCutElectronLine(Int_t ededxSigmaCut)
 {   // Set Cut
@@ -1538,11 +1895,10 @@ Bool_t AliConversionCuts::SetTPCdEdxCutElectronLine(Int_t ededxSigmaCut)
    default:
       AliError("TPCdEdxCutElectronLine not defined");
       return kFALSE;
-        
+
    }
    return kTRUE;
 }
-
 ///________________________________________________________________________
 Bool_t AliConversionCuts::SetTPCdEdxCutPionLine(Int_t pidedxSigmaCut)
 {   // Set Cut
@@ -1561,11 +1917,11 @@ Bool_t AliConversionCuts::SetTPCdEdxCutPionLine(Int_t pidedxSigmaCut)
       fPIDnSigmaAbovePionLineHighPt=-10;
       break;
    case 3:  // 1
-      fPIDnSigmaAbovePionLine=-1;
+      fPIDnSigmaAbovePionLine=2.5;
       fPIDnSigmaAbovePionLineHighPt=-10;
       break;
    case 4:  // 1
-      fPIDnSigmaAbovePionLine=2.5;
+      fPIDnSigmaAbovePionLine=0.5;
       fPIDnSigmaAbovePionLineHighPt=-10;
       break;
    case 5:  // 1
@@ -1594,7 +1950,6 @@ Bool_t AliConversionCuts::SetTPCdEdxCutPionLine(Int_t pidedxSigmaCut)
    }
    return kTRUE;
 }
-
 ///________________________________________________________________________
 Bool_t AliConversionCuts::SetMinMomPiondEdxCut(Int_t piMomdedxSigmaCut)
 {   // Set Cut
@@ -1623,218 +1978,15 @@ Bool_t AliConversionCuts::SetMinMomPiondEdxCut(Int_t piMomdedxSigmaCut)
    case 7:  // 0.4 GeV
       fPIDMinPnSigmaAbovePionLine=0.4;
       break;
-   default:
-      AliError(Form("piMomdedxSigmaCut not defined %d",piMomdedxSigmaCut));
-      return kFALSE;
-   }
-   return kTRUE;
-}
-
-///________________________________________________________________________
-Bool_t AliConversionCuts::SetChi2GammaCut(Int_t chi2GammaCut)
-{   // Set Cut
-
-   switch(chi2GammaCut){
-   case 0: // 100
-      fChi2CutConversion = 100.;
-      break;
-   case 1:  // 50
-      fChi2CutConversion = 50.;
-      break;
-   case 2:  // 30
-      fChi2CutConversion = 30.;
-      break;
-   case 3:
-      fChi2CutConversion = 200.;
-      break;
-   case 4:
-      fChi2CutConversion = 500.;
-      break;
-   case 5:
-      fChi2CutConversion = 100000.;
-      break;
-   case 6:
-      fChi2CutConversion = 5.;
-      break;
-   case 7:
-      fChi2CutConversion = 10.;
-      break;
-   case 8:
-      fChi2CutConversion = 20.;
-      break;
-   case 9:
-      fChi2CutConversion = 15.;
-      break;
-   default:
-      AliError(Form("Warning: Chi2GammaCut not defined %d",chi2GammaCut));
-      return kFALSE;
-   }
-   return kTRUE;
-}
-
-///________________________________________________________________________
-Bool_t AliConversionCuts::SetV0Finder(Int_t v0FinderType)
-{   // Set Cut
-   switch (v0FinderType){
-   case 0:  // on fly V0 finder
-      fUseOnFlyV0Finder=kTRUE;
-      break;
-   case 1:  // offline V0 finder
-      fUseOnFlyV0Finder=kFALSE;
-      break;
-   default:
-      AliError(Form(" v0FinderType not defined %d",v0FinderType));
-      return kFALSE;
-   }
-   return kTRUE;
-}
-
-
-///________________________________________________________________________
-Bool_t AliConversionCuts::SetSinglePtCut(Int_t singlePtCut)
-{   // Set Cut
-   switch(singlePtCut){
-   case 0: // 0.050 GeV
-      fSinglePtCut = 0.050;
-      break;
-   case 1:  // 0.100 GeV
-      fSinglePtCut = 0.100;
-      break;
-   case 2:  // 0.150 GeV
-      fSinglePtCut = 0.150;
-      break;
-   case 3:  // 0.200 GeV
-      fSinglePtCut = 0.200;
-      break;
-   case 4:  // 0.075 GeV
-      fSinglePtCut = 0.075;
-      break;
-   case 5:  // 0.125 GeV
-      fSinglePtCut = 0.125;
+   case 8:  // 0.2 GeV
+      fPIDMinPnSigmaAbovePionLine=0.2;
       break;
    default:
-      AliError(Form("singlePtCut not defined %d",singlePtCut));
-      return kFALSE;
-   }
-   return kTRUE;
-}
-///________________________________________________________________________
-Bool_t AliConversionCuts::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:  // 60% of findable clusters
-      fMinClsTPCToF= 0.6;
-      fUseCorrectedTPCClsInfo=0;
-      break;
-   case 5:  // 0% of findable clusters
-      fMinClsTPCToF= 0.0;
-      fUseCorrectedTPCClsInfo=1;
-      break;
-   case 6:  // 0% of findable clusters
-      fMinClsTPCToF= 0.7;
-      fUseCorrectedTPCClsInfo=1;
-      break;
-   case 7:  // 0% of findable clusters
-      fMinClsTPCToF= 0.35;
-      fUseCorrectedTPCClsInfo=0;
-      break;
-   case 8:
-      fMinClsTPCToF= 0.35;
-      fUseCorrectedTPCClsInfo=1;
-      break;
-   case 9:
-      fMinClsTPCToF= 0.6;
-      fUseCorrectedTPCClsInfo=1;
-      break;
-   default:
-      AliError(Form("Warning: clsTPCCut not defined %d",clsTPCCut));
-      return kFALSE;
-   }
-   return kTRUE;
-}
-
-///________________________________________________________________________
-Bool_t AliConversionCuts::SetEtaCut(Int_t etaCut)
-{   // Set Cut
-
-   //Set Standard LineCutZValues
-   fLineCutZValueMin = -2;
-   fLineCutZValue = 7.;
-   
-   switch(etaCut){
-   case 0: // 0.9
-      fEtaCut          = 0.9;
-      fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
-      fEtaCutMin               = -0.1;
-      fLineCutZRSlopeMin = 0.;
-      break;
-   case 1:     // 1.2
-      fEtaCut          = 1.2;
-      fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
-      fEtaCutMin               = -0.1;
-      fLineCutZRSlopeMin = 0.;
-      break;
-   case 2:     // 1.4
-      fEtaCut          = 1.4;
-      fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
-      fEtaCutMin               = -0.1;
-      fLineCutZRSlopeMin = tan(2*atan(exp(-fEtaCut)));
-      break;
-   case 3: // 0.8
-      fEtaCut          = 0.8;
-      fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
-      fEtaCutMin               = -0.1;
-      fLineCutZRSlopeMin = 0.;
-      break;
-   case 4: // 0.75
-      fEtaCut          = 0.75;
-      fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
-      fEtaCutMin               = -0.1;
-      fLineCutZRSlopeMin = 0.;
-      break;
-   case 5: // 0.9 - 1.4
-      fEtaCut          = 1.4;
-      fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
-      fEtaCutMin               = 0.9;
-      fLineCutZRSlopeMin = tan(2*atan(exp(-fEtaCutMin)));
-      break;
-   case 6: // 0.9 - 1.2
-      fEtaCut          = 1.2;
-      fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
-      fEtaCutMin               = 0.9;
-      fLineCutZRSlopeMin = tan(2*atan(exp(-fEtaCutMin)));
-      break;
-   case 7: // 0.1 - 0.8
-      fEtaCut          = 0.8;
-      fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
-      fEtaCutMin               = 0.1;
-      fLineCutZRSlopeMin = tan(2*atan(exp(-fEtaCutMin)));
-      break;
-   case 8: // 0.1 - 0.8
-      fEtaCut          = 0.9;
-      fLineCutZRSlope = tan(2*atan(exp(-fEtaCut)));
-      fEtaCutMin               = 0.1;
-      fLineCutZRSlopeMin = tan(2*atan(exp(-fEtaCutMin)));
-      break;
-   default:
-      AliError(Form(" EtaCut not defined %d",etaCut));
+      AliError(Form("piMomdedxSigmaCut not defined %d",piMomdedxSigmaCut));
       return kFALSE;
    }
    return kTRUE;
 }
-
 ///________________________________________________________________________
 Bool_t AliConversionCuts::SetMaxMomPiondEdxCut(Int_t piMaxMomdedxSigmaCut)
 {   // Set Cut
@@ -1854,46 +2006,15 @@ Bool_t AliConversionCuts::SetMaxMomPiondEdxCut(Int_t piMaxMomdedxSigmaCut)
    case 4:  // 3. GeV
       fPIDMaxPnSigmaAbovePionLine=3.;
       break;
-   default:
-      AliError(Form("piMaxMomdedxSigmaCut not defined %d",piMaxMomdedxSigmaCut));
-      return kFALSE;
-   }
-   return kTRUE;
-}
-
-///________________________________________________________________________
-Bool_t AliConversionCuts::SetIsHeavyIon(Int_t isHeavyIon)
-{   // Set Cut
-   switch(isHeavyIon){
-   case 0:
-      fIsHeavyIon=0;
-      break;
-   case 1:
-      fIsHeavyIon=1;
-      fDetectorCentrality=0;
-      break;
-   case 2:
-      fIsHeavyIon=1;
-      fDetectorCentrality=1;
-      break;
-   case 3: //allows to select centrality 0-45% in steps of 5% for V0 Multiplicity
-      fIsHeavyIon=1;
-      fDetectorCentrality=0;     
-      fModCentralityClass=1;
-      break;
-   case 4: //allows to select centrality 45-90% in steps of 5% for V0 Multiplicity
-      fIsHeavyIon=1;
-      fDetectorCentrality=0;
-      fModCentralityClass=2;
+   case 5:  // 7. GeV
+      fPIDMaxPnSigmaAbovePionLine=7.;
       break;
    default:
-      AliError(Form("SetHeavyIon not defined %d",isHeavyIon));
+      AliError(Form("piMaxMomdedxSigmaCut not defined %d",piMaxMomdedxSigmaCut));
       return kFALSE;
    }
    return kTRUE;
 }
-
-
 ///________________________________________________________________________
 Bool_t AliConversionCuts::SetLowPRejectionCuts(Int_t LowPRejectionSigmaCut)
 {   // Set Cut
@@ -1902,36 +2023,73 @@ Bool_t AliConversionCuts::SetLowPRejectionCuts(Int_t LowPRejectionSigmaCut)
       fPIDnSigmaAtLowPAroundKaonLine=0;
       fPIDnSigmaAtLowPAroundProtonLine=0;
       fPIDnSigmaAtLowPAroundPionLine=0;
+      fDoKaonRejectionLowP = kFALSE;
+      fDoProtonRejectionLowP = kFALSE;
+      fDoPionRejectionLowP = kFALSE;
+      fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
       break;
    case 1:  //
       fPIDnSigmaAtLowPAroundKaonLine=0.5;
       fPIDnSigmaAtLowPAroundProtonLine=0.5;
       fPIDnSigmaAtLowPAroundPionLine=0.5;
+      fDoKaonRejectionLowP = kTRUE;
+      fDoProtonRejectionLowP = kTRUE;
+      fDoPionRejectionLowP = kTRUE;
+      fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
       break;
    case 2:  //
       fPIDnSigmaAtLowPAroundKaonLine=1;
       fPIDnSigmaAtLowPAroundProtonLine=1;
       fPIDnSigmaAtLowPAroundPionLine=1;
+      fDoKaonRejectionLowP = kTRUE;
+      fDoProtonRejectionLowP = kTRUE;
+      fDoPionRejectionLowP = kTRUE;
+      fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
       break;
    case 3:  //
       fPIDnSigmaAtLowPAroundKaonLine=2.;
       fPIDnSigmaAtLowPAroundProtonLine=2.;
       fPIDnSigmaAtLowPAroundPionLine=2.;
+      fDoKaonRejectionLowP = kTRUE;
+      fDoProtonRejectionLowP = kTRUE;
+      fDoPionRejectionLowP = kTRUE;
+      fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
       break;
    case 4:  //
       fPIDnSigmaAtLowPAroundKaonLine=0.;
       fPIDnSigmaAtLowPAroundProtonLine=0.;
       fPIDnSigmaAtLowPAroundPionLine=1;
+      fDoKaonRejectionLowP = kFALSE;
+      fDoProtonRejectionLowP = kFALSE;
+      fDoPionRejectionLowP = kTRUE;
+      fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
       break;
    case 5:  //
       fPIDnSigmaAtLowPAroundKaonLine=0.;
       fPIDnSigmaAtLowPAroundProtonLine=0.;
       fPIDnSigmaAtLowPAroundPionLine=1.5;
+      fDoKaonRejectionLowP = kFALSE;
+      fDoProtonRejectionLowP = kFALSE;
+      fDoPionRejectionLowP = kTRUE;
+      fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
       break;
    case 6:  //
       fPIDnSigmaAtLowPAroundKaonLine=0.;
       fPIDnSigmaAtLowPAroundProtonLine=0.;
       fPIDnSigmaAtLowPAroundPionLine=2.;
+      fDoKaonRejectionLowP = kFALSE;
+      fDoProtonRejectionLowP = kFALSE;
+      fDoPionRejectionLowP = kTRUE;
+      fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
+      break;
+   case 7:  //
+      fPIDnSigmaAtLowPAroundKaonLine=0.;
+      fPIDnSigmaAtLowPAroundProtonLine=0.;
+      fPIDnSigmaAtLowPAroundPionLine=0.5;
+      fDoKaonRejectionLowP = kFALSE;
+      fDoProtonRejectionLowP = kFALSE;
+      fDoPionRejectionLowP = kTRUE;
+      fPIDMinPPionRejectionLowP = fPIDMinPnSigmaAbovePionLine;
       break;
    default:
       AliError(Form("LowPRejectionSigmaCut not defined %d",LowPRejectionSigmaCut));
@@ -1939,11 +2097,10 @@ Bool_t AliConversionCuts::SetLowPRejectionCuts(Int_t LowPRejectionSigmaCut)
    }
    return kTRUE;
 }
-
 ///________________________________________________________________________
 Bool_t AliConversionCuts::SetTOFElectronPIDCut(Int_t TOFelectronPID){
    // Set Cut
-   switch(TOFelectronPID){ 
+   switch(TOFelectronPID){
    case 0: // no cut
       fUseTOFpid = kFALSE;
       fTofPIDnSigmaBelowElectronLine=-100;
@@ -1969,37 +2126,15 @@ Bool_t AliConversionCuts::SetTOFElectronPIDCut(Int_t TOFelectronPID){
       fTofPIDnSigmaBelowElectronLine=-2;
       fTofPIDnSigmaAboveElectronLine=3;
       break;
-   default:
-      AliError(Form("TOFElectronCut not defined %d",TOFelectronPID));
-      return kFALSE;
-   } 
-   return kTRUE;
-}
-
-///________________________________________________________________________
-Bool_t AliConversionCuts::SetTRDElectronCut(Int_t TRDElectronCut)
-{   // Set Cut
-   switch(TRDElectronCut){
-   case 0:
-      fDoTRDPID=kFALSE;
-      break;
-   case 1:
-      fDoTRDPID=kTRUE;
-      fPIDTRDEfficiency=0.1;
-      break;
-   case 8:
-      fDoTRDPID=kTRUE;
-      fPIDTRDEfficiency=0.8;
-      break;
-   case 9:
-      fDoTRDPID=kTRUE;
-      fPIDTRDEfficiency=0.9;
+   case 5: // -3,3
+      fUseTOFpid = kTRUE;
+      fTofPIDnSigmaBelowElectronLine=-3;
+      fTofPIDnSigmaAboveElectronLine=3;
       break;
    default:
-      AliError(Form("TRDElectronCut not defined %d",TRDElectronCut));
+      AliError(Form("TOFElectronCut not defined %d",TOFelectronPID));
       return kFALSE;
    }
-
    return kTRUE;
 }
 ///________________________________________________________________________
@@ -2008,52 +2143,52 @@ Bool_t AliConversionCuts::SetQtMaxCut(Int_t QtMaxCut)
    switch(QtMaxCut){
    case 0: //
       fQtMax=1.;
-      fDoQtGammaSelection=kFALSE;      //No Qt selection (true by default)
-      fDoHighPtQtGammaSelection=kFALSE; // RRnew
-      fHighPtQtMax=100.;               // RRnew
-      fPtBorderForQt=100.;             // RRnew
+      fDoQtGammaSelection=kFALSE;
+      fDoHighPtQtGammaSelection=kFALSE;
+      fHighPtQtMax=100.;
+      fPtBorderForQt=100.;
       break;
    case 1:
       fQtMax=0.1;
-      fDoHighPtQtGammaSelection=kFALSE; // RRnew
-      fHighPtQtMax=100.;               // RRnew
-      fPtBorderForQt=100.;             // RRnew
+      fDoHighPtQtGammaSelection=kFALSE;
+      fHighPtQtMax=100.;
+      fPtBorderForQt=100.;
       break;
    case 2:
       fQtMax=0.07;
-      fDoHighPtQtGammaSelection=kFALSE; // RRnew
-      fHighPtQtMax=100.;               // RRnew
-      fPtBorderForQt=100.;             // RRnew
+      fDoHighPtQtGammaSelection=kFALSE;
+      fHighPtQtMax=100.;
+      fPtBorderForQt=100.;
       break;
    case 3:
       fQtMax=0.05;
-      fDoHighPtQtGammaSelection=kFALSE; // RRnew
-      fHighPtQtMax=100.;               // RRnew
-      fPtBorderForQt=100.;             // RRnew
+      fDoHighPtQtGammaSelection=kFALSE;
+      fHighPtQtMax=100.;
+      fPtBorderForQt=100.;
       break;
    case 4:
       fQtMax=0.03;
-      fDoHighPtQtGammaSelection=kFALSE; // RRnew
-      fHighPtQtMax=100.;               // RRnew
-      fPtBorderForQt=100.;             // RRnew
+      fDoHighPtQtGammaSelection=kFALSE;
+      fHighPtQtMax=100.;
+      fPtBorderForQt=100.;
       break;
-   case 5: // RR try to improve (get rid of) low InvMass peak in PbPb
+   case 5:
       fQtMax=0.02;
-      fDoHighPtQtGammaSelection=kFALSE; // RRnew
-      fHighPtQtMax=100.;               // RRnew
-      fPtBorderForQt=100.;             // RRnew
-      break; // end RR ///////////////////////////////////////////////
-   case 6:  // RRnew start: pT dependent qT cut
+      fDoHighPtQtGammaSelection=kFALSE;
+      fHighPtQtMax=100.;
+      fPtBorderForQt=100.;
+      break;
+   case 6:
       fQtMax=0.02;
       fDoHighPtQtGammaSelection=kTRUE;
       fHighPtQtMax=0.06;
       fPtBorderForQt=2.5;
-      break; // RRnew end ////////////////////////////////////////////
+      break;
    case 7:
       fQtMax=0.15;
-      fDoHighPtQtGammaSelection=kFALSE; // RRnew
-      fHighPtQtMax=100.;               // RRnew
-      fPtBorderForQt=100.;             // RRnew
+      fDoHighPtQtGammaSelection=kFALSE;
+      fHighPtQtMax=100.;
+      fPtBorderForQt=100.;
       break;
    default:
       AliError(Form("Warning: QtMaxCut not defined %d",QtMaxCut));
@@ -2061,91 +2196,88 @@ Bool_t AliConversionCuts::SetQtMaxCut(Int_t QtMaxCut)
    }
    return kTRUE;
 }
+///________________________________________________________________________
+Bool_t AliConversionCuts::SetChi2GammaCut(Int_t chi2GammaCut)
+{   // Set Cut
 
-//-------------------------------------------------------------
-Double_t AliConversionCuts::GetCentrality(AliVEvent *event)
-{   // Get Event Centrality
-
-   AliESDEvent *esdEvent=dynamic_cast<AliESDEvent*>(event);
-   if(esdEvent){
-      AliCentrality *fESDCentrality=(AliCentrality*)esdEvent->GetCentrality();
-
-      if(fDetectorCentrality==0){
-         return fESDCentrality->GetCentralityPercentile("V0M"); // default
-      }
-      if(fDetectorCentrality==1){
-         return fESDCentrality->GetCentralityPercentile("CL1");
-      }
-   }
-
-   AliAODEvent *aodEvent=dynamic_cast<AliAODEvent*>(event);
-   if(aodEvent){
-      if(aodEvent->GetHeader()){return aodEvent->GetHeader()->GetCentrality();}
-   }
-
-   return -1;
-}
-
-//-------------------------------------------------------------
-Bool_t AliConversionCuts::IsCentralitySelected(AliVEvent *event)
-{   // Centrality Selection
-   if(!fIsHeavyIon)return kTRUE;
-    
-   if(fCentralityMin == 0 && fCentralityMax == 0) return kTRUE;//0-100%
-   if(fCentralityMin >= fCentralityMax) return kTRUE;//0-100%
-   
-   Double_t centrality=GetCentrality(event);
-   if(centrality<0)return kFALSE;
-       
-   Int_t centralityC=0;
-   if (fModCentralityClass == 0){
-      centralityC= Int_t(centrality/10);
-      if(centralityC >= fCentralityMin && centralityC < fCentralityMax)
-         return kTRUE;
-      else 
-         return kFALSE;
-   }   else if (fModCentralityClass ==1){
-      centralityC= Int_t(centrality);
-      if(centralityC >= fCentralityMin*5 && centralityC < fCentralityMax*5){
-         return kTRUE;
-      } else { 
-         return kFALSE;
-      }
-   } else if (fModCentralityClass ==2){
-      centralityC= Int_t(centrality+1);
-      if(centralityC >= (fCentralityMin*5+45) && centralityC < (fCentralityMax*5+45))
-         return kTRUE;
-      else 
-         return kFALSE;
-   }
-   return kFALSE;
-}
-
-//-------------------------------------------------------------
-Bool_t AliConversionCuts::SetCentralityMin(Int_t minCentrality)
-{
-   // Set Cut
-   if(minCentrality<0||minCentrality>9){
-      AliError(Form("minCentrality not defined %d",minCentrality));
+   switch(chi2GammaCut){
+   case 0: // 100
+      fChi2CutConversion = 100.;
+      break;
+   case 1:  // 50
+      fChi2CutConversion = 50.;
+      break;
+   case 2:  // 30
+      fChi2CutConversion = 30.;
+      break;
+   case 3:
+      fChi2CutConversion = 200.;
+      break;
+   case 4:
+      fChi2CutConversion = 500.;
+      break;
+   case 5:
+      fChi2CutConversion = 100000.;
+      break;
+   case 6:
+      fChi2CutConversion = 5.;
+      break;
+   case 7:
+      fChi2CutConversion = 10.;
+      break;
+   case 8:
+      fChi2CutConversion = 20.;
+      break;
+   case 9:
+      fChi2CutConversion = 15.;
+      break;
+   default:
+      AliError(Form("Warning: Chi2GammaCut not defined %d",chi2GammaCut));
       return kFALSE;
    }
-
-   fCentralityMin=minCentrality;
    return kTRUE;
 }
-//-------------------------------------------------------------
-Bool_t AliConversionCuts::SetCentralityMax(Int_t maxCentrality)
-{
-   // Set Cut
-   if(maxCentrality<0||maxCentrality>9){
-      AliError(Form("maxCentrality not defined %d",maxCentrality));
+///________________________________________________________________________
+Bool_t AliConversionCuts::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;
+   case 9:
+      fPsiPairCut = 0.5; //
+      break;
+   default:
+      AliError(Form("PsiPairCut not defined %d",psiCut));
       return kFALSE;
    }
 
-   fCentralityMax=maxCentrality;
    return kTRUE;
 }
-
 ///________________________________________________________________________
 Bool_t AliConversionCuts::SetPhotonAsymmetryCut(Int_t doPhotonAsymmetryCut){
    // Set Cut
@@ -2172,85 +2304,41 @@ Bool_t AliConversionCuts::SetPhotonAsymmetryCut(Int_t doPhotonAsymmetryCut){
    fCuts[kdoPhotonAsymmetryCut]=doPhotonAsymmetryCut;
    return kTRUE;
 }
-
-
 ///________________________________________________________________________
-Bool_t AliConversionCuts::SetPsiPairCut(Int_t psiCut) {
-  
+Bool_t AliConversionCuts::SetCosPAngleCut(Int_t cosCut) {
 
-   switch(psiCut) {
+   switch(cosCut){
    case 0:
-      fPsiPairCut = 10000; // 
+      fCosPAngleCut = TMath::Pi(); // -1
       break;
    case 1:
-      fPsiPairCut = 0.1; // 
+      fCosPAngleCut = 0.1; // 0.99500
       break;
    case 2:
-      fPsiPairCut = 0.05; // Standard
+      fCosPAngleCut = 0.05; // 0.99875
       break;
    case 3:
-      fPsiPairCut = 0.035; // 
+      fCosPAngleCut = 0.025; // 0.99969
       break;
    case 4:
-      fPsiPairCut = 0.15; // 
+      fCosPAngleCut = 0.01; // 0.99995
       break;
    case 5:
-      fPsiPairCut = 0.2; // 
+      fCosPAngleCut = 0.2; // 0.98007
       break;
    case 6:
-      fPsiPairCut = 0.03; // 
+      fCosPAngleCut = 0.5; // 0.87758
       break;
    case 7:
-      fPsiPairCut = 0.025; // 
-      break;
-   case 8:
-      fPsiPairCut = 0.01; // 
-      break;
-   default:
-      AliError(Form("PsiPairCut not defined %d",psiCut));
-      return kFALSE;
-   }
-
-   return kTRUE;
-}
-
-///________________________________________________________________________
-Bool_t AliConversionCuts::SetCosPAngleCut(Int_t cosCut) {
-
-   switch(cosCut){
-   case 0:
-      fCosPAngleCut = TMath::Pi(); //
-      break;
-   case 1:
-      fCosPAngleCut = 0.1; //
-      break;
-   case 2:
-      fCosPAngleCut = 0.05; //
-      break;
-   case 3:
-      fCosPAngleCut = 0.025; // Standard
-      break;
-   case 4:
-      fCosPAngleCut = 0.01; //
+      fCosPAngleCut = 0.075; // 0.73169
       break;
    default:
       AliError(Form("Cosine Pointing Angle cut not defined %d",cosCut));
       return kFALSE;
    }
-       
-   return kTRUE;
-}
 
-
-///________________________________________________________________________
-Bool_t AliConversionCuts::VertexZCut(AliVEvent *event){
-   // Cut on z position of primary vertex
-   Double_t fVertexZ=event->GetPrimaryVertex()->GetZ();
-
-   if(TMath::Abs(fVertexZ)>fMaxVertexZ)return kFALSE;
    return kTRUE;
 }
-
 ///________________________________________________________________________
 Bool_t AliConversionCuts::SetSharedElectronCut(Int_t sharedElec) {
 
@@ -2265,10 +2353,9 @@ Bool_t AliConversionCuts::SetSharedElectronCut(Int_t sharedElec) {
       AliError(Form("Shared Electron Cut not defined %d",sharedElec));
       return kFALSE;
    }
-       
+
    return kTRUE;
 }
-
 ///________________________________________________________________________
 Bool_t AliConversionCuts::SetToCloseV0sCut(Int_t toClose) {
 
@@ -2296,44 +2383,162 @@ Bool_t AliConversionCuts::SetToCloseV0sCut(Int_t toClose) {
    return kTRUE;
 }
 ///________________________________________________________________________
-Bool_t AliConversionCuts::SetRejectExtraSignalsCut(Int_t extraSignal) {
-
-   switch(extraSignal){
+Bool_t AliConversionCuts::SetTRDElectronCut(Int_t TRDElectronCut)
+{   // Set Cut
+   switch(TRDElectronCut){
    case 0:
-      fRejectExtraSignals = 0;
-      break; // No Rejection
+      fDoTRDPID=kFALSE;
+      break;
    case 1:
-      fRejectExtraSignals = 1;
-      break; // MinBias Header
-   case 2:
-      fRejectExtraSignals = 2;
-      break; // User String Array
+      fDoTRDPID=kTRUE;
+      fPIDTRDEfficiency=0.1;
+      break;
+   case 8:
+      fDoTRDPID=kTRUE;
+      fPIDTRDEfficiency=0.8;
+      break;
+   case 9:
+      fDoTRDPID=kTRUE;
+      fPIDTRDEfficiency=0.9;
+      break;
    default:
-      AliError(Form("Extra Signal Rejection not defined %d",extraSignal));
+      AliError(Form("TRDElectronCut not defined %d",TRDElectronCut));
       return kFALSE;
    }
+
    return kTRUE;
 }
+//-------------------------------------------------------------
+Double_t AliConversionCuts::GetCentrality(AliVEvent *event)
+{   // Get Event Centrality
+
+   AliESDEvent *esdEvent=dynamic_cast<AliESDEvent*>(event);
+   if(esdEvent){
+      AliCentrality *fESDCentrality=(AliCentrality*)esdEvent->GetCentrality();
+
+      if(fDetectorCentrality==0){
+         return fESDCentrality->GetCentralityPercentile("V0M"); // default
+      }
+      if(fDetectorCentrality==1){
+         return fESDCentrality->GetCentralityPercentile("CL1");
+      }
+   }
+
+   AliAODEvent *aodEvent=dynamic_cast<AliAODEvent*>(event);
+   if(aodEvent){
+      if(aodEvent->GetHeader()){return aodEvent->GetHeader()->GetCentrality();}
+   }
+
+   return -1;
+}
+//-------------------------------------------------------------
+Bool_t AliConversionCuts::IsCentralitySelected(AliVEvent *event, AliVEvent *fMCEvent)
+{   // Centrality Selection
+   if(!fIsHeavyIon)return kTRUE;
+
+   if(fCentralityMin == 0 && fCentralityMax == 0) return kTRUE;//0-100%
+   if(fCentralityMin >= fCentralityMax) return kTRUE;//0-100%
+
+   Double_t centrality=GetCentrality(event);
+   if(centrality<0)return kFALSE;
+
+   Int_t centralityC=0;
+   if (fModCentralityClass == 0){
+      centralityC= Int_t(centrality/10);
+      if(centralityC >= fCentralityMin && centralityC < fCentralityMax)
+         return kTRUE;
+      else return kFALSE;
+   }
+   else if (fModCentralityClass ==1){
+      centralityC= Int_t(centrality);
+      if(centralityC >= fCentralityMin*5 && centralityC < fCentralityMax*5){
+         return kTRUE;
+      } else return kFALSE;
+   }
+   else if (fModCentralityClass ==2){
+      centralityC= Int_t(centrality);
+      if(centralityC >= ((fCentralityMin*5)+45) && centralityC < ((fCentralityMax*5)+45))
+         return kTRUE;
+      else return kFALSE;
+   }
+
+   // Use strict V0 amplitude cut for MC centrality
+   Float_t nv0amplitude = event->GetVZEROData()->GetMTotV0A()+event->GetVZEROData()->GetMTotV0C();
+   Float_t V0Amplitude10[10] = {9999999.0,13670,9345,6209,3944,2352,1272,611,255, 83};
+   //                                    0    10   20   30   40   50   60  70  80  90%
+   Float_t V0Amplitude5a[10] = {9999999.0,16612,13670,11290,9345,7650,6209,4984,3944,3074};
+   //                                    0     5    10    15   20   25   30   35   40   45%
+   Float_t V0Amplitude5b[10] = {3074,2352,1725,1272,899,611,402,255,152,83};
+   //                             45   50   55   60  65  70  75  80  85 90%
+
+   if (fModCentralityClass == 3){
+      if(fMCEvent){
+         if(nv0amplitude > V0Amplitude10[fCentralityMax] && nv0amplitude <= V0Amplitude10[fCentralityMin])
+            return kTRUE;
+         else return kFALSE;
+      }
+      else{
+         centralityC= Int_t(centrality/10);
+         if(centralityC >= fCentralityMin && centralityC < fCentralityMax)
+            return kTRUE;
+         else return kFALSE;
+      }
+   }
+   else if (fModCentralityClass ==4){
+      if(fMCEvent){
+         if(nv0amplitude > V0Amplitude5a[fCentralityMax] && nv0amplitude <= V0Amplitude5a[fCentralityMin])
+            return kTRUE;
+         else return kFALSE;
+      }
+      else{
+         centralityC= Int_t(centrality);
+         if(centralityC >= fCentralityMin*5 && centralityC < fCentralityMax*5){
+            return kTRUE;
+         } else return kFALSE;
+      }
+   }
+   else if (fModCentralityClass ==5){
+      if(fMCEvent){
+         if(nv0amplitude > V0Amplitude5b[fCentralityMax] && nv0amplitude <= V0Amplitude5b[fCentralityMin])
+            return kTRUE;
+         else return kFALSE;
+      }
+      else{
+         centralityC= Int_t(centrality);
+         if(centralityC >= ((fCentralityMin*5)+45) && centralityC < ((fCentralityMax*5)+45))
+            return kTRUE;
+         else return kFALSE;
+      }
+   }
+
+   return kFALSE;
+}
+///________________________________________________________________________
+Bool_t AliConversionCuts::VertexZCut(AliVEvent *event){
+   // Cut on z position of primary vertex
+   Double_t fVertexZ=event->GetPrimaryVertex()->GetZ();
 
+   if(abs(fVertexZ)>fMaxVertexZ)return kFALSE;
+   return kTRUE;
+}
 ///________________________________________________________________________
 
 Int_t AliConversionCuts::GetNumberOfContributorsVtx(AliVEvent *event){
    // returns number of contributors to the vertex
-    
+
    AliESDEvent *fESDEvent=dynamic_cast<AliESDEvent*>(event);
    if(fESDEvent){
-      if(fESDEvent->GetPrimaryVertexTracks()->GetNContributors()>0) {
-         return fESDEvent->GetPrimaryVertexTracks()->GetNContributors();
+      if (fESDEvent->GetPrimaryVertex() != NULL){
+         if(fESDEvent->GetPrimaryVertex()->GetNContributors()>0) {
+            return fESDEvent->GetPrimaryVertex()->GetNContributors();
+         }
       }
-     
-      if(fESDEvent->GetPrimaryVertexTracks()->GetNContributors()<1) {
-         //            return 0;
-         //-AM test pi0s without SPD only vertex
+      
+      if(fESDEvent->GetPrimaryVertexSPD() !=NULL){
          if(fESDEvent->GetPrimaryVertexSPD()->GetNContributors()>0) {
             return fESDEvent->GetPrimaryVertexSPD()->GetNContributors();
-
-         }
-         if(fESDEvent->GetPrimaryVertexSPD()->GetNContributors()<1) {
+         }  else {
+            AliWarning(Form("Number of contributors from bad vertex type:: %s",fESDEvent->GetPrimaryVertex()->GetName()));
             return 0;
          }
       }
@@ -2341,21 +2546,21 @@ Int_t AliConversionCuts::GetNumberOfContributorsVtx(AliVEvent *event){
 
    AliAODEvent *fAODEvent=dynamic_cast<AliAODEvent*>(event);
    if(fAODEvent){
-      if(fAODEvent->GetPrimaryVertex()->GetNContributors()>0) {
-         return fAODEvent->GetPrimaryVertex()->GetNContributors();
-      }
-      if(fAODEvent->GetPrimaryVertex()->GetNContributors()<1) {
+      if (fAODEvent->GetPrimaryVertex() != NULL){
+         if(fAODEvent->GetPrimaryVertex()->GetNContributors()>0) {
+            return fAODEvent->GetPrimaryVertex()->GetNContributors();
+         }
+      } 
+      if(fAODEvent->GetPrimaryVertexSPD() !=NULL){
          if(fAODEvent->GetPrimaryVertexSPD()->GetNContributors()>0) {
             return fAODEvent->GetPrimaryVertexSPD()->GetNContributors();
-         }
-         if(fAODEvent->GetPrimaryVertexSPD()->GetNContributors()<1) {
+         } else {
             AliWarning(Form("Number of contributors from bad vertex type:: %s",fAODEvent->GetPrimaryVertex()->GetName()));
             return 0;
          }
       }
    }
-
-
+   
    return 0;
 }
 
@@ -2363,6 +2568,7 @@ Int_t AliConversionCuts::GetNumberOfContributorsVtx(AliVEvent *event){
 
 Bool_t AliConversionCuts::IsTriggerSelected()
 {
+
    AliInputEventHandler *fInputHandler=(AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
 
    UInt_t isSelected = AliVEvent::kAny;
@@ -2372,20 +2578,56 @@ Bool_t AliConversionCuts::IsTriggerSelected()
       if (fOfflineTriggerMask)
          isSelected = fOfflineTriggerMask & fInputHandler->IsEventSelected();
    }
-   
-   if(!isSelected)return kFALSE;
+   fIsSDDFired = !(fInputHandler->IsEventSelected() & AliVEvent::kFastOnly);
 
    // Fill Histogram
    if(hTriggerClass){
-      if (fInputHandler->IsEventSelected() & AliVEvent::kAny)hTriggerClass->Fill(0);
-      if (fInputHandler->IsEventSelected() & AliVEvent::kMB)hTriggerClass->Fill(1);
-      if (fInputHandler->IsEventSelected() & AliVEvent::kCentral)hTriggerClass->Fill(2);
-      if (fInputHandler->IsEventSelected() & AliVEvent::kSemiCentral)hTriggerClass->Fill(3);
-      if (fInputHandler->IsEventSelected() & AliVEvent::kCINT5)hTriggerClass->Fill(4);
+      if (!fIsSDDFired) hTriggerClass->Fill(32);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kMB)hTriggerClass->Fill(0);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kINT7)hTriggerClass->Fill(1);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kMUON)hTriggerClass->Fill(2);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kHighMult)hTriggerClass->Fill(3);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kEMC1)hTriggerClass->Fill(4);
       if (fInputHandler->IsEventSelected() & AliVEvent::kCINT5)hTriggerClass->Fill(5);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kCMUS5)hTriggerClass->Fill(6);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kMUSPB)hTriggerClass->Fill(6);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kCMUS5)hTriggerClass->Fill(6);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kMUSPB)hTriggerClass->Fill(6);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kMUSH7)hTriggerClass->Fill(7);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kMUSHPB)hTriggerClass->Fill(7);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kMUL7)hTriggerClass->Fill(8);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kMuonLikePB)hTriggerClass->Fill(8);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kMUU7)hTriggerClass->Fill(9);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikePB)hTriggerClass->Fill(9);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kEMC7)hTriggerClass->Fill(10);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kEMC8)hTriggerClass->Fill(10);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kMUS7)hTriggerClass->Fill(11);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kPHI1)hTriggerClass->Fill(12);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kPHI7)hTriggerClass->Fill(13);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kPHI8)hTriggerClass->Fill(13);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kPHOSPb)hTriggerClass->Fill(13);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kEMCEJE)hTriggerClass->Fill(14);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kEMCEGA)hTriggerClass->Fill(15);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kCentral)hTriggerClass->Fill(16);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kSemiCentral)hTriggerClass->Fill(17);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kDG5)hTriggerClass->Fill(18);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kZED)hTriggerClass->Fill(19);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kSPI7)hTriggerClass->Fill(20);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kSPI)hTriggerClass->Fill(20);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kINT8)hTriggerClass->Fill(21);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kMuonSingleLowPt8)hTriggerClass->Fill(22);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kMuonSingleHighPt8)hTriggerClass->Fill(23);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kMuonLikeLowPt8)hTriggerClass->Fill(24);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikeLowPt8)hTriggerClass->Fill(25);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kMuonUnlikeLowPt0)hTriggerClass->Fill(26);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kUserDefined)hTriggerClass->Fill(27);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kFastOnly)hTriggerClass->Fill(28);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kAnyINT)hTriggerClass->Fill(29);
+      if (fInputHandler->IsEventSelected() & AliVEvent::kAny)hTriggerClass->Fill(30);
    }
 
-    
+   if(!isSelected)return kFALSE;
+      
    return kTRUE;
 
 }