o add Reduced Event
authorwiechula <wiechula@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 21 Jun 2012 16:25:26 +0000 (16:25 +0000)
committerwiechula <wiechula@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 21 Jun 2012 16:25:26 +0000 (16:25 +0000)
PWGDQ/CMakelibPWGDQdielectron.pkg
PWGDQ/PWGDQdielectronLinkDef.h
PWGDQ/dielectron/AliAnalysisTaskReducedTree.cxx [new file with mode: 0644]
PWGDQ/dielectron/AliAnalysisTaskReducedTree.h [new file with mode: 0644]
PWGDQ/dielectron/AliDielectron.cxx
PWGDQ/dielectron/AliDielectron.h
PWGDQ/dielectron/AliReducedEvent.cxx [new file with mode: 0644]
PWGDQ/dielectron/AliReducedEvent.h [new file with mode: 0644]
PWGDQ/dielectron/macrosJPSI/AddTask_ReducedTree.C [new file with mode: 0644]

index c64b543..c8f04e2 100644 (file)
@@ -61,6 +61,9 @@ set ( SRCS
       dielectron/AliDielectronSignalMC.cxx
       dielectron/AliDielectronEvent.cxx
       dielectron/AliDielectronMixingHandler.cxx
+      dielectron/AliReducedEvent.cxx
+      dielectron/AliAnalysisTaskReducedTree.cxx
+
 )
 
 string(REPLACE ".cxx" ".h" HDRS "${SRCS}")
index e30d4bc..6c74f06 100644 (file)
 #pragma link C++ class AliDielectronSignalMC+;
 #pragma link C++ class AliDielectronEvent+;
 #pragma link C++ class AliDielectronMixingHandler+;
+#pragma link C++ class AliReducedEvent+;
+#pragma link C++ class AliReducedEventFriend+;                                                                                                                                  
+#pragma link C++ class AliReducedTrack+;
+#pragma link C++ class AliReducedPair+;
+#pragma link C++ class AliReducedCaloCluster+;
+#pragma link C++ class AliAnalysisTaskReducedTree+;
 
 #endif
diff --git a/PWGDQ/dielectron/AliAnalysisTaskReducedTree.cxx b/PWGDQ/dielectron/AliAnalysisTaskReducedTree.cxx
new file mode 100644 (file)
index 0000000..a9f756f
--- /dev/null
@@ -0,0 +1,703 @@
+/*************************************************************************
+* Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
+*                                                                        *
+* Author: The ALICE Off-line Project.                                    *
+* Contributors are mentioned in the code where appropriate.              *
+*                                                                        *
+* Permission to use, copy, modify and distribute this software and its   *
+* documentation strictly for non-commercial purposes is hereby granted   *
+* without fee, provided that the above copyright notice appears in all   *
+* copies and that both the copyright notice and this permission notice   *
+* appear in the supporting documentation. The authors make no claims     *
+* about the suitability of this software for any purpose. It is          *
+* provided "as is" without express or implied warranty.                  *
+**************************************************************************/
+
+///////////////////////////////////////////////////////////////////////////
+//                                                                       //
+//    Analysis task for creating a reduced data tree                     //
+//                                                                       //
+///////////////////////////////////////////////////////////////////////////
+
+
+#include <TChain.h>
+#include <TH1D.h>
+#include <TFile.h>
+
+#include <AliCFContainer.h>
+#include <AliInputEventHandler.h>
+#include <AliESDInputHandler.h>
+#include <AliAODInputHandler.h>
+#include <AliAnalysisManager.h>
+#include <AliVEvent.h>
+#include <AliESDEvent.h>
+#include <AliAODEvent.h>
+#include <AliAODTrack.h>
+#include <AliTriggerAnalysis.h>
+#include <AliESDtrackCuts.h>
+#include <AliVZDC.h>
+#include <AliESDv0.h>
+#include <AliESDv0Cuts.h>
+#include <AliVCluster.h>
+#include "AliDielectron.h"
+#include "AliDielectronHistos.h"
+#include "AliDielectronMC.h"
+#include "AliDielectronVarManager.h"
+#include "AliFlowTrackCuts.h"
+#include "AliFlowBayesianPID.h"
+
+#include "AliReducedEvent.h"
+#include "AliAnalysisTaskReducedTree.h"
+
+ClassImp(AliAnalysisTaskReducedTree)
+
+
+//_________________________________________________________________________________
+AliAnalysisTaskReducedTree::AliAnalysisTaskReducedTree() :
+  AliAnalysisTaskSE(),
+  fListDielectron(),
+  fListHistos(),
+  fSelectPhysics(kFALSE),
+  fTriggerMask(AliVEvent::kAny),
+  fRejectPileup(kFALSE),
+  fFillTrackInfo(kTRUE),
+  fFillDielectronInfo(kTRUE),
+  fFillV0Info(kTRUE),
+  fFillCaloClusterInfo(kTRUE),
+  fFillFriendInfo(kTRUE),
+  fEventFilter(0x0),
+  fTrackFilter(0x0),
+  fFlowTrackFilter(0x0),
+  fK0sCuts(0x0),
+  fLambdaCuts(0x0),
+  fK0sPionCuts(0x0),
+  fLambdaProtonCuts(0x0),
+  fLambdaPionCuts(0x0),
+  fK0sMassRange(),
+  fLambdaMassRange(),
+  fV0Histos(0x0),
+  fTreeFile(0x0),
+  fTree(0x0),
+  fFriendTreeFile(0x0),
+  fFriendTree(0x0),
+  fReducedEvent(0x0),
+  fReducedEventFriend(0x0)
+{
+  //
+  // Constructor
+  //
+}
+
+//_________________________________________________________________________________
+AliAnalysisTaskReducedTree::AliAnalysisTaskReducedTree(const char *name) :
+  AliAnalysisTaskSE(name),
+  fListDielectron(),
+  fListHistos(),
+  fSelectPhysics(kFALSE),
+  fTriggerMask(AliVEvent::kAny),
+  fRejectPileup(kFALSE),
+  fFillTrackInfo(kTRUE),
+  fFillDielectronInfo(kTRUE),
+  fFillV0Info(kTRUE),
+  fFillCaloClusterInfo(kTRUE),
+  fFillFriendInfo(kTRUE),
+  fEventFilter(0x0),
+  fTrackFilter(0x0),
+  fFlowTrackFilter(0x0),
+  fK0sCuts(0x0),
+  fLambdaCuts(0x0),
+  fK0sPionCuts(0x0),
+  fLambdaProtonCuts(0x0),
+  fLambdaPionCuts(0x0),
+  fK0sMassRange(),
+  fLambdaMassRange(),
+  fV0Histos(0x0),
+  fTreeFile(0x0),
+  fTree(0x0),
+  fFriendTreeFile(0x0),
+  fFriendTree(0x0),
+  fReducedEvent(0x0),
+  fReducedEventFriend(0x0)
+{
+  //
+  // Constructor
+  //
+  fK0sMassRange[0] = 0.4; fK0sMassRange[1] = 0.6;
+  fLambdaMassRange[0] = 1.08; fLambdaMassRange[1] = 1.15;
+  
+  DefineInput(0,TChain::Class());
+  DefineOutput(1, TList::Class());   // QA histograms
+  DefineOutput(2, TTree::Class());   // reduced information tree
+  if(fFillFriendInfo) DefineOutput(3, TTree::Class());   // reduced information tree with friends
+  //DefineOutput(2, TTree::Class());   // reduced information tree with friends
+  
+  fListHistos.SetName("QAhistograms");
+  fListDielectron.SetOwner();
+  fListHistos.SetOwner(kFALSE);
+}
+
+
+//_________________________________________________________________________________
+void AliAnalysisTaskReducedTree::UserCreateOutputObjects()
+{
+  //
+  // Add all histogram manager histogram lists to the output TList
+  //
+
+  if (!fListHistos.IsEmpty() || fTree || fFriendTree) return; //already initialised
+
+  TIter nextDie(&fListDielectron);
+  AliDielectron *die=0;
+  while ( (die=static_cast<AliDielectron*>(nextDie())) ){
+    die->Init();
+    if (die->GetHistogramList()) fListHistos.Add(const_cast<THashList*>(die->GetHistogramList()));
+  }  
+  if(fV0Histos) fListHistos.Add(const_cast<THashList*>(fV0Histos->GetHistogramList()));
+
+  if(fFillFriendInfo) {
+    fFriendTree = new TTree("DstFriendTree","Reduced ESD information");
+    fReducedEventFriend = new AliReducedEventFriend();
+    fFriendTree->Branch("Event",&fReducedEventFriend,16000,99);
+  }
+  
+  //fTreeFile = new TFile("dstTree.root", "RECREATE");
+  fTree = new TTree("DstTree","Reduced ESD information");
+  fReducedEvent = new AliReducedEvent("DstEvent");
+  fTree->Branch("Event",&fReducedEvent,16000,99);
+    
+  PostData(1, &fListHistos);
+  PostData(2, fTree);
+  if(fFillFriendInfo) PostData(3, fFriendTree);
+  //PostData(2, fFriendTree);
+}
+
+//_________________________________________________________________________________
+void AliAnalysisTaskReducedTree::UserExec(Option_t *option)
+{
+  //
+  // Main loop. Called for every event
+  //  
+  option = option;
+  AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
+  Bool_t isESD=man->GetInputEventHandler()->IsA()==AliESDInputHandler::Class();
+  Bool_t isAOD=man->GetInputEventHandler()->IsA()==AliAODInputHandler::Class();
+  
+  AliInputEventHandler* inputHandler = (AliInputEventHandler*) (man->GetInputEventHandler());
+  if (!inputHandler) return;
+  
+  if ( inputHandler->GetPIDResponse() ){
+    AliDielectronVarManager::SetPIDResponse( inputHandler->GetPIDResponse() );
+  } else {
+    AliFatal("This task needs the PID response attached to the input event handler!");
+  }
+  
+  // Was event selected ?
+  UInt_t isSelected = AliVEvent::kAny;
+  if(fSelectPhysics && inputHandler){
+    if((isESD && inputHandler->GetEventSelection()) || isAOD){
+      isSelected = inputHandler->IsEventSelected();
+      isSelected&=fTriggerMask;
+    }
+  }
+
+  if(isSelected==0) {
+    return;
+  }
+
+  // fill event histograms before event filter
+  Double_t values[AliDielectronVarManager::kNMaxValues]={0};
+  AliDielectronVarManager::Fill(InputEvent(),values);
+  
+  TIter nextDie(&fListDielectron);
+  AliDielectron *die=0;
+  while ( (die=static_cast<AliDielectron*>(nextDie())) ){
+    AliDielectronHistos *h=die->GetHistoManager();
+    if (h){
+      if (h->GetHistogramList()->FindObject("Event_noCuts"))
+        h->FillClass("Event_noCuts",AliDielectronVarManager::kNMaxValues,values);
+    }
+  }
+  nextDie.Reset();
+
+  //event filter
+  if (fEventFilter) {
+    if (!fEventFilter->IsSelected(InputEvent())) return;
+  }
+  
+  //pileup
+  if (fRejectPileup){
+    if (InputEvent()->IsPileupFromSPD(3,0.8,3.,2.,5.)) return;
+  }
+
+  //bz for AliKF
+  Double_t bz = InputEvent()->GetMagneticField();
+  AliKFParticle::SetField( bz );
+
+  //Process event in all AliDielectron instances
+  fReducedEvent->ClearEvent();
+  if(fFillFriendInfo) fReducedEventFriend->ClearEvent();
+  FillEventInfo();
+  if(fFillV0Info) FillV0PairInfo();
+  
+  Short_t idie=0;
+  if(fFillDielectronInfo) {
+    while((die=static_cast<AliDielectron*>(nextDie()))){
+      die->Process(InputEvent());
+      FillDielectronPairInfo(die, idie);
+      ++idie;
+    }
+  }
+  nextDie.Reset();
+  
+  if(fFillTrackInfo) FillTrackInfo();
+  if(fFillFriendInfo) FillFriendEventInfo();              // Q-vector calculation
+  
+  fTree->Fill();
+  if(fFillFriendInfo) fFriendTree->Fill();
+      
+  // if there are candidate pairs, add the information to the reduced tree
+  PostData(1, &fListHistos);
+  PostData(2, fTree);
+  if(fFillFriendInfo) PostData(3, fFriendTree);
+  //PostData(2, fFriendTree);
+}
+
+
+//_________________________________________________________________________________
+void AliAnalysisTaskReducedTree::FillEventInfo() 
+{
+  //
+  // fill reduced event information
+  //
+  AliVEvent* event = InputEvent();
+  // Was event selected ?
+  AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
+  Bool_t isESD = (event->IsA()==AliESDEvent::Class());
+  Bool_t isAOD = (event->IsA()==AliAODEvent::Class());
+  
+  AliInputEventHandler* inputHandler = (AliInputEventHandler*) (man->GetInputEventHandler());
+  UInt_t isSelected = AliVEvent::kAny;
+  if(inputHandler){
+    if((isESD && inputHandler->GetEventSelection()) || isAOD){
+      isSelected = inputHandler->IsEventSelected();
+      isSelected&=fTriggerMask;
+    }
+  }
+
+  Double_t values[AliDielectronVarManager::kNMaxValues];
+  AliDielectronVarManager::Fill(event, values);
+  
+  fReducedEvent->fRunNo       = event->GetRunNumber();
+  fReducedEvent->fBC          = event->GetBunchCrossNumber();
+  fReducedEvent->fTriggerMask = event->GetTriggerMask();
+  fReducedEvent->fIsPhysicsSelection = (isSelected!=0 ? kTRUE : kFALSE);
+  AliVVertex* eventVtx = 0x0;
+  if(isESD) eventVtx = const_cast<AliESDVertex*>((static_cast<AliESDEvent*>(event))->GetPrimaryVertexTracks());
+  if(isAOD) eventVtx = const_cast<AliAODVertex*>((static_cast<AliAODEvent*>(event))->GetPrimaryVertex());
+  if(eventVtx) {
+    fReducedEvent->fVtx[0] = (isESD ? ((AliESDVertex*)eventVtx)->GetXv() : ((AliAODVertex*)eventVtx)->GetX());
+    fReducedEvent->fVtx[1] = (isESD ? ((AliESDVertex*)eventVtx)->GetYv() : ((AliAODVertex*)eventVtx)->GetY());
+    fReducedEvent->fVtx[2] = (isESD ? ((AliESDVertex*)eventVtx)->GetZv() : ((AliAODVertex*)eventVtx)->GetZ());
+    fReducedEvent->fNVtxContributors = eventVtx->GetNContributors();
+  }
+  if(isESD) {
+    eventVtx = const_cast<AliESDVertex*>((static_cast<AliESDEvent*>(event))->GetPrimaryVertexTPC());
+    if(eventVtx) {
+      fReducedEvent->fVtxTPC[0] = ((AliESDVertex*)eventVtx)->GetXv();
+      fReducedEvent->fVtxTPC[1] = ((AliESDVertex*)eventVtx)->GetYv();
+      fReducedEvent->fVtxTPC[2] = ((AliESDVertex*)eventVtx)->GetZv();
+      fReducedEvent->fNVtxTPCContributors = eventVtx->GetNContributors();
+    }
+  }
+  
+  AliCentrality *centrality = event->GetCentrality();
+  if(centrality) {
+    fReducedEvent->fCentrality[0] = centrality->GetCentralityPercentile("V0M");
+    fReducedEvent->fCentrality[1] = centrality->GetCentralityPercentile("CL1");
+    fReducedEvent->fCentrality[2] = centrality->GetCentralityPercentile("TRK");
+    fReducedEvent->fCentrality[3] = centrality->GetCentralityPercentile("ZEMvsZDC");    
+    fReducedEvent->fCentQuality   = centrality->GetQuality();
+  }
+  
+  fReducedEvent->fNtracks[0] = event->GetNumberOfTracks();
+  fReducedEvent->fSPDntracklets = values[AliDielectronVarManager::kNaccTrckltsEsd10Corr];
+
+  AliVVZERO* vzero = event->GetVZEROData();
+  for(Int_t i=0;i<64;++i) 
+    fReducedEvent->fVZEROMult[i] = vzero->GetMultiplicity(i);  
+
+  AliESDZDC* zdc = (isESD ? (static_cast<AliESDEvent*>(event))->GetESDZDC() : 0x0);
+  if(zdc) {
+    for(Int_t i=0; i<4; ++i)  fReducedEvent->fZDCnEnergy[i]   = zdc->GetZN1TowerEnergy()[i];
+    for(Int_t i=4; i<8; ++i)  fReducedEvent->fZDCnEnergy[i]   = zdc->GetZN2TowerEnergy()[i-5];
+  }
+  
+  // EMCAL/PHOS clusters
+  if(fFillCaloClusterInfo) FillCaloClusters();
+  
+  // TODO FMD multiplicities
+  
+}
+
+
+//_________________________________________________________________________________
+void AliAnalysisTaskReducedTree::FillCaloClusters() {
+  //
+  // Fill info about the calorimeter clusters
+  //
+  AliVEvent* event = InputEvent();
+  Int_t nclusters = event->GetNumberOfCaloClusters();
+
+  fReducedEvent->fNCaloClusters = 0;
+  for(Int_t iclus=0; iclus<nclusters; ++iclus) {
+    AliVCluster* cluster = event->GetCaloCluster(iclus);
+    
+    TClonesArray& clusters = *(fReducedEvent->fCaloClusters);
+    AliReducedCaloCluster *reducedCluster=new(clusters[fReducedEvent->fNCaloClusters]) AliReducedCaloCluster();
+    
+    reducedCluster->fType    = (cluster->IsEMCAL() ? AliReducedCaloCluster::kEMCAL : AliReducedCaloCluster::kPHOS);
+    reducedCluster->fEnergy  = cluster->E();
+    reducedCluster->fTrackDx = cluster->GetTrackDx();
+    reducedCluster->fTrackDz = cluster->GetTrackDz();
+    fReducedEvent->fNCaloClusters += 1;
+  }  // end loop over clusters
+}
+
+
+//_________________________________________________________________________________
+void AliAnalysisTaskReducedTree::FillFriendEventInfo() {
+  //
+  // Fill event info into the friend tree
+  //
+  // Add here calculated Q-vector components from all detectors
+  for(Int_t idet=0; idet<AliReducedEventFriend::kNdetectors; ++idet) {
+    fReducedEvent->GetQvector(fReducedEventFriend->fQvector[idet], idet);
+    for(Int_t ih=0; ih<fgkNMaxHarmonics; ++ih)
+      fReducedEventFriend->fEventPlaneStatus[idet][ih] = AliReducedEventFriend::kRaw;
+  }
+}
+
+
+//_________________________________________________________________________________
+void AliAnalysisTaskReducedTree::FillTrackInfo() 
+{
+  //
+  // fill reduced track information
+  //
+  AliVEvent* event = InputEvent();
+  Bool_t isESD = (event->IsA()==AliESDEvent::Class());
+  Bool_t isAOD = (event->IsA()==AliAODEvent::Class());
+
+  Int_t ntracks=event->GetNumberOfTracks();
+  for(Int_t itrack=0; itrack<ntracks; ++itrack){
+    AliVParticle *particle=event->GetTrack(itrack);
+    //apply track cuts
+    if(fTrackFilter && !fTrackFilter->IsSelected(particle)) continue;
+    
+    TClonesArray& tracks = *(fReducedEvent->fTracks);
+    AliReducedTrack *reducedParticle=new(tracks[fReducedEvent->fNtracks[1]]) AliReducedTrack();
+        
+    Double_t values[AliDielectronVarManager::kNMaxValues];
+    AliDielectronVarManager::Fill(particle, values);
+    reducedParticle->fStatus        = (ULong_t)values[AliDielectronVarManager::kTrackStatus];
+    reducedParticle->fGlobalPhi     = values[AliDielectronVarManager::kPhi];
+    reducedParticle->fGlobalPt      = values[AliDielectronVarManager::kPt]*values[AliDielectronVarManager::kCharge];
+    reducedParticle->fGlobalEta     = values[AliDielectronVarManager::kEta];    
+    reducedParticle->fMomentumInner = values[AliDielectronVarManager::kPIn];
+    reducedParticle->fDCA[0]        = values[AliDielectronVarManager::kImpactParXY];
+    reducedParticle->fDCA[1]        = values[AliDielectronVarManager::kImpactParZ];
+    
+    reducedParticle->fITSclusterMap = values[AliDielectronVarManager::kITSclusterMap];
+    reducedParticle->fITSsignal     = values[AliDielectronVarManager::kITSsignal];
+    
+    reducedParticle->fTPCNcls      = (UChar_t)values[AliDielectronVarManager::kNclsTPC];
+    reducedParticle->fTPCNclsF     = (UChar_t)values[AliDielectronVarManager::kNFclsTPC];
+    reducedParticle->fTPCNclsIter1 = (UChar_t)values[AliDielectronVarManager::kNclsTPCiter1];
+    reducedParticle->fTPCsignal    = values[AliDielectronVarManager::kTPCsignal];
+    reducedParticle->fTPCnSig[0]   = values[AliDielectronVarManager::kTPCnSigmaEle];
+    reducedParticle->fTPCnSig[1]   = values[AliDielectronVarManager::kTPCnSigmaPio];
+    reducedParticle->fTPCnSig[2]   = values[AliDielectronVarManager::kTPCnSigmaKao];
+    reducedParticle->fTPCnSig[3]   = values[AliDielectronVarManager::kTPCnSigmaPro];
+    
+    reducedParticle->fTOFbeta      = values[AliDielectronVarManager::kTOFbeta];
+    reducedParticle->fTOFnSig[0]   = values[AliDielectronVarManager::kTOFnSigmaEle];
+    reducedParticle->fTOFnSig[1]   = values[AliDielectronVarManager::kTOFnSigmaPio];
+    reducedParticle->fTOFnSig[2]   = values[AliDielectronVarManager::kTOFnSigmaKao];
+    reducedParticle->fTOFnSig[3]   = values[AliDielectronVarManager::kTOFnSigmaPro];
+
+    reducedParticle->fTRDpid[0]    = values[AliDielectronVarManager::kTRDprobEle];
+    reducedParticle->fTRDpid[1]    = values[AliDielectronVarManager::kTRDprobPio];
+    
+    if(fFlowTrackFilter) {
+      // switch on the first bit if this particle should be used for the event plane
+      if(fFlowTrackFilter->IsSelected(particle)) reducedParticle->fFlags |= (1<<0);
+    }
+    
+    if(isESD){
+      AliESDtrack *track=static_cast<AliESDtrack*>(particle);
+      reducedParticle->fTrackId          = (UShort_t)track->GetID();
+      reducedParticle->fTPCCrossedRows   = (UChar_t)track->GetTPCCrossedRows();
+      reducedParticle->fTPCClusterMap    = EncodeTPCClusterMap(track);
+      const AliExternalTrackParam* tpcInner = track->GetTPCInnerParam();
+      reducedParticle->fTPCPhi        = (tpcInner ? tpcInner->Phi() : 0.0);
+      reducedParticle->fTPCPt         = (tpcInner ? tpcInner->Pt() : 0.0);
+      reducedParticle->fTPCEta        = (tpcInner ? tpcInner->Eta() : 0.0);
+      reducedParticle->fTRDntracklets[0] = track->GetTRDntracklets();
+      reducedParticle->fTRDntracklets[1] = track->GetTRDntrackletsPID();
+      if(track->IsEMCAL()) reducedParticle->fCaloClusterId = track->GetEMCALcluster();
+      if(track->IsPHOS()) reducedParticle->fCaloClusterId = track->GetPHOScluster();
+    }
+    if(isAOD) {
+      AliAODTrack *track=static_cast<AliAODTrack*>(particle);
+      reducedParticle->fTrackId = track->GetID(); 
+      if(track->IsEMCAL()) reducedParticle->fCaloClusterId = track->GetEMCALcluster();
+      if(track->IsPHOS()) reducedParticle->fCaloClusterId = track->GetPHOScluster();
+    }
+
+    fReducedEvent->fNtracks[1] += 1;
+  }
+}
+
+
+//_________________________________________________________________________________
+void AliAnalysisTaskReducedTree::FillDielectronPairInfo(AliDielectron* die, Short_t iDie) 
+{
+  //
+  // fill reduced pair information
+  //
+  Bool_t hasMC=AliDielectronMC::Instance()->HasMC();
+
+  for(Int_t iType=0; iType<3; ++iType) {
+    
+    const TObjArray* array = die->GetPairArray(iType);
+    if(!array || array->GetEntriesFast()==0) continue;
+    
+    for(Int_t iCandidate=0; iCandidate<array->GetEntriesFast(); ++iCandidate) {
+      AliDielectronPair* pair = (AliDielectronPair*)array->At(iCandidate);
+      Double_t values[AliDielectronVarManager::kNMaxValues];
+      AliDielectronVarManager::Fill(pair, values);
+      
+      TClonesArray& tracks = *(fReducedEvent->fCandidates);
+      AliReducedPair *reducedParticle= 
+         new (tracks[fReducedEvent->fNV0candidates[1]+fReducedEvent->fNDielectronCandidates]) AliReducedPair();
+      // !!! hardcoded flag for dielectron id 
+      reducedParticle->fCandidateId  = (iDie==0 ? AliReducedPair::kJpsiToEE : AliReducedPair::kPhiToKK);
+      reducedParticle->fPairType     = values[AliDielectronVarManager::kPairType];
+      reducedParticle->fLegIds[0]    = (UShort_t)(static_cast<AliVTrack*>(pair->GetFirstDaughter()))->GetID();
+      reducedParticle->fLegIds[1]    = (UShort_t)(static_cast<AliVTrack*>(pair->GetSecondDaughter()))->GetID();
+      reducedParticle->fMass[0]      = values[AliDielectronVarManager::kM];
+      reducedParticle->fMass[1]      = -999.;
+      reducedParticle->fMass[2]      = -999.;
+      reducedParticle->fPhi          = values[AliDielectronVarManager::kPhi];  // in the [-pi,pi] interval
+      if(reducedParticle->fPhi<0.0) reducedParticle->fPhi = 2.0*TMath::Pi() + reducedParticle->fPhi;  // converted to [0,2pi]
+      reducedParticle->fPt           = values[AliDielectronVarManager::kPt];
+      reducedParticle->fEta          = values[AliDielectronVarManager::kEta];
+      reducedParticle->fLxy          = values[AliDielectronVarManager::kPseudoProperTime];
+      reducedParticle->fLxyErr       = values[AliDielectronVarManager::kPseudoProperTimeErr];
+      reducedParticle->fOpeningAngle = values[AliDielectronVarManager::kOpeningAngle];     
+     
+      reducedParticle->fMCid         = 0;
+      if(hasMC) {
+       AliDielectronMC::Instance()->ConnectMCEvent();
+       const TObjArray* mcSignals = die->GetMCSignals();
+       for(Int_t iSig=0; iSig<mcSignals->GetEntries(); ++iSig) {
+         if(iSig>31) break;
+         AliDielectronMC *mc=AliDielectronMC::Instance();
+         if(mc->IsMCTruth(pair, (AliDielectronSignalMC*)mcSignals->At(iSig))) {
+           reducedParticle->fMCid = reducedParticle->fMCid | (1<<iSig);
+         }
+       }
+      }   // end if has MC
+      fReducedEvent->fNDielectronCandidates += 1;
+    }    // end loop over candidates
+  }    // end loop over pair type
+}
+
+
+//_________________________________________________________________________________
+void AliAnalysisTaskReducedTree::FillV0PairInfo() 
+{
+  //
+  // fill reduced pair information
+  //
+  AliESDEvent* esd = (AliESDEvent*)InputEvent();
+  const AliESDVertex *primaryVertex = esd->GetPrimaryVertex();
+  AliKFVertex primaryVertexKF(*primaryVertex);
+  
+  fReducedEvent->fNV0candidates[0] = InputEvent()->GetNumberOfV0s();
+  
+  Double_t valuesPos[AliDielectronVarManager::kNMaxValues];
+  Double_t valuesNeg[AliDielectronVarManager::kNMaxValues];
+   
+  for(Int_t iV0=0; iV0<InputEvent()->GetNumberOfV0s(); ++iV0) {   // loop over V0s
+    AliESDv0 *v0 = esd->GetV0(iV0);
+       
+    AliESDtrack* legPos = esd->GetTrack(v0->GetPindex());
+    AliESDtrack* legNeg = esd->GetTrack(v0->GetNindex());
+    if(legPos->GetSign() == legNeg->GetSign()) {
+      continue;
+    }
+
+    Bool_t v0ChargesAreCorrect = (legPos->GetSign()==+1 ? kTRUE : kFALSE);
+    legPos = (!v0ChargesAreCorrect ? esd->GetTrack(v0->GetNindex()) : legPos);
+    legNeg = (!v0ChargesAreCorrect ? esd->GetTrack(v0->GetPindex()) : legNeg); 
+    
+    // apply the K0s filter
+    Bool_t goodK0s = kTRUE;
+    if(fK0sPionCuts && (!fK0sPionCuts->IsSelected(legPos) || !fK0sPionCuts->IsSelected(legNeg))) goodK0s = kFALSE;
+    if(fK0sCuts) {
+      TList k0sList;
+      k0sList.Add(v0);
+      k0sList.Add(legPos); k0sList.Add(legNeg);
+      k0sList.Add(const_cast<AliESDVertex*>(primaryVertex));
+      if(!fK0sCuts->IsSelected(&k0sList)) goodK0s = kFALSE;
+    }
+    
+    // apply the lambda filter
+    Bool_t goodLambda = kTRUE;
+    if(fLambdaProtonCuts && !fLambdaProtonCuts->IsSelected(legPos)) goodLambda = kFALSE;
+    if(fLambdaPionCuts && !fLambdaPionCuts->IsSelected(legNeg)) goodLambda = kFALSE;
+    Bool_t goodALambda = kTRUE;
+    if(fLambdaProtonCuts && !fLambdaProtonCuts->IsSelected(legNeg)) goodALambda = kFALSE;
+    if(fLambdaPionCuts && !fLambdaPionCuts->IsSelected(legPos)) goodALambda = kFALSE;
+    if(fLambdaCuts) {
+      TList lambdaList;
+      lambdaList.Add(v0);
+      lambdaList.Add(legPos); lambdaList.Add(legNeg);
+      lambdaList.Add(const_cast<AliESDVertex*>(primaryVertex));
+      if(!fLambdaCuts->IsSelected(&lambdaList)) {goodLambda = kFALSE; goodALambda = kFALSE;}
+    }
+    
+    if(!(goodK0s || goodLambda || goodALambda)) continue;
+    
+    // Fill the V0 information into the tree for 3 hypothesis: K0s, Lambda, Anti-Lambda
+    AliReducedPair* k0sReducedPair     = FillV0PairInfo(v0, AliReducedPair::kK0sToPiPi,     legPos, legNeg, &primaryVertexKF, v0ChargesAreCorrect);
+    AliReducedPair* lambdaReducedPair  = FillV0PairInfo(v0, AliReducedPair::kLambda0ToPPi,  legPos, legNeg, &primaryVertexKF, v0ChargesAreCorrect);
+    AliReducedPair* alambdaReducedPair = FillV0PairInfo(v0, AliReducedPair::kALambda0ToPPi, legPos, legNeg, &primaryVertexKF, v0ChargesAreCorrect);
+
+    if(goodK0s && k0sReducedPair->fMass[0]>fK0sMassRange[0] && k0sReducedPair->fMass[0]<fK0sMassRange[1]) {
+      TClonesArray& tracks = *(fReducedEvent->fCandidates);
+      AliReducedPair *goodK0sPair = new (tracks[fReducedEvent->fNV0candidates[1]]) AliReducedPair(*k0sReducedPair);
+      goodK0sPair->fMass[0] = k0sReducedPair->fMass[0];
+      goodK0sPair->fMass[1] = lambdaReducedPair->fMass[0];
+      goodK0sPair->fMass[2] = alambdaReducedPair->fMass[0];
+      fReducedEvent->fNV0candidates[1] += 1;
+    } else {goodK0s=kFALSE;}
+    if(goodLambda && lambdaReducedPair->fMass[0]>fLambdaMassRange[0] && lambdaReducedPair->fMass[0]<fLambdaMassRange[1]) {
+      TClonesArray& tracks = *(fReducedEvent->fCandidates);
+      AliReducedPair *goodLambdaPair = new (tracks[fReducedEvent->fNV0candidates[1]]) AliReducedPair(*lambdaReducedPair);
+      fReducedEvent->fNV0candidates[1] += 1;
+      goodLambdaPair->fMass[0] = k0sReducedPair->fMass[0];
+      goodLambdaPair->fMass[1] = lambdaReducedPair->fMass[0];
+      goodLambdaPair->fMass[2] = alambdaReducedPair->fMass[0];
+    } else {goodLambda=kFALSE;}
+    if(goodALambda && alambdaReducedPair->fMass[0]>fLambdaMassRange[0] && alambdaReducedPair->fMass[0]<fLambdaMassRange[1]) {
+      TClonesArray& tracks = *(fReducedEvent->fCandidates);
+      AliReducedPair *goodALambdaPair = new (tracks[fReducedEvent->fNV0candidates[1]]) AliReducedPair(*alambdaReducedPair);
+      fReducedEvent->fNV0candidates[1] += 1;  
+      goodALambdaPair->fMass[0] = k0sReducedPair->fMass[0];
+      goodALambdaPair->fMass[1] = lambdaReducedPair->fMass[0];
+      goodALambdaPair->fMass[2] = alambdaReducedPair->fMass[0];
+    } else {goodALambda = kFALSE;}
+    delete k0sReducedPair;
+    delete lambdaReducedPair;
+    delete alambdaReducedPair;
+
+    if(!(goodK0s || goodLambda || goodALambda)) continue;
+    
+    //  Fill histograms and the CF container
+    AliDielectronVarManager::Fill(legPos, valuesPos);
+    AliDielectronVarManager::Fill(legNeg, valuesNeg);
+    
+    if(fV0Histos && fV0Histos->GetHistogramList()->FindObject("V0Track_Pos"))
+      fV0Histos->FillClass("V0Track_Pos", AliDielectronVarManager::kNMaxValues, valuesPos);
+    if(fV0Histos && fV0Histos->GetHistogramList()->FindObject("V0Track_Neg"))
+      fV0Histos->FillClass("V0Track_Neg", AliDielectronVarManager::kNMaxValues, valuesNeg);    
+  }   // end loop over V0s
+}
+
+
+//_________________________________________________________________________________
+AliReducedPair* AliAnalysisTaskReducedTree::FillV0PairInfo(AliESDv0* v0, Int_t id, 
+                                                   AliESDtrack* legPos, AliESDtrack* legNeg,
+                                                   AliKFVertex* vtxKF, Bool_t chargesAreCorrect) {
+  //
+  // Create a reduced V0 object and fill it
+  //
+  AliReducedPair* reducedPair=new AliReducedPair();  
+  reducedPair->fCandidateId = id;
+  reducedPair->fPairType    = v0->GetOnFlyStatus();    // on the fly status
+  //reducedPair->fOnTheFly    = v0->GetOnFlyStatus();
+  reducedPair->fLegIds[0]   = legPos->GetID();
+  reducedPair->fLegIds[1]   = legNeg->GetID();
+  if(!reducedPair->fPairType) {    // offline
+    UInt_t pidPos = AliPID::kPion;
+    if(id==AliReducedPair::kLambda0ToPPi) pidPos = AliPID::kProton;
+    UInt_t pidNeg = AliPID::kPion;
+    if(id==AliReducedPair::kALambda0ToPPi) pidNeg = AliPID::kProton;
+    reducedPair->fMass[0]      = v0->GetEffMass(pidPos, pidNeg);
+    reducedPair->fPhi          = v0->Phi();
+    if(reducedPair->fPhi<0.0) reducedPair->fPhi = 2.0*TMath::Pi() + reducedPair->fPhi;  // converted to [0,2pi]
+    reducedPair->fPt           = v0->Pt();
+    reducedPair->fEta          = v0->Eta();
+    reducedPair->fLxy          = 0.0;           //TODO
+    reducedPair->fOpeningAngle = 0.0;
+  }
+  else {
+    const AliExternalTrackParam *negHelix=v0->GetParamN();
+    const AliExternalTrackParam *posHelix=v0->GetParamP();
+    if(!chargesAreCorrect) {
+      negHelix = v0->GetParamP();
+      posHelix = v0->GetParamN();
+    }
+    AliKFParticle negKF(*(negHelix),(id==AliReducedPair::kALambda0ToPPi ? -2212 : -211));
+    AliKFParticle posKF(*(posHelix),(id==AliReducedPair::kLambda0ToPPi ? +2212 : +211));
+    AliKFParticle v0Refit;
+    v0Refit += negKF;
+    v0Refit += posKF;
+    Double_t massFit=0.0, massErrFit=0.0;
+    v0Refit.GetMass(massFit,massErrFit);
+    reducedPair->fMass[0] = massFit;
+    reducedPair->fPhi          = v0Refit.GetPhi();
+    if(reducedPair->fPhi<0.0) reducedPair->fPhi = 2.0*TMath::Pi() + reducedPair->fPhi;  // converted to [0,2pi]
+    reducedPair->fPt           = v0Refit.GetPt();
+    reducedPair->fEta          = v0Refit.GetEta();
+    reducedPair->fLxy          = v0Refit.GetPseudoProperDecayTime(*vtxKF, massFit);
+    reducedPair->fOpeningAngle = negKF.GetAngle(posKF);
+  }
+  return reducedPair;
+}
+
+
+//_________________________________________________________________________________
+UChar_t AliAnalysisTaskReducedTree::EncodeTPCClusterMap(AliESDtrack* track) {
+  //
+  // Encode the TPC cluster map into an UChar_t
+  // Divide the 159 bits from the bit map into 8 groups of adiacent clusters
+  // For each group enable its corresponding bit if in that group there are more clusters compared to
+  // a threshold.
+  //
+  const UChar_t threshold=5;
+  TBits tpcClusterMap = track->GetTPCClusterMap();
+  UChar_t map=0;
+  UChar_t n=0;
+  UChar_t j=0;
+  for(UChar_t i=0; i<8; ++i) {
+    n=0;
+    for(j=i*20; j<(i+1)*20 && j<159; ++j) n+=tpcClusterMap.TestBitNumber(j);
+    if(n>=threshold) map |= (1<<i);
+  }
+  return map;
+}
+
+
+//_________________________________________________________________________________
+void AliAnalysisTaskReducedTree::FinishTaskOutput()
+{
+  //
+  // Finish Task 
+  //
+  //fTreeFile->Write();
+  //fTreeFile->Close();
+}
diff --git a/PWGDQ/dielectron/AliAnalysisTaskReducedTree.h b/PWGDQ/dielectron/AliAnalysisTaskReducedTree.h
new file mode 100644 (file)
index 0000000..9206f1b
--- /dev/null
@@ -0,0 +1,115 @@
+// Analysis task for creating a reduced tree containing event, track and resonance candidate information 
+// Author: Ionut-Cristian Arsene (i.c.arsene@gsi.de,i.c.arsene@cern.ch)                                 
+// 2012/06/21
+
+#ifndef ALIANALYSISTASKREDUCEDTREE_H
+#define ALIANALYSISTASKREDUCEDTREE_H 
+
+#include "TList.h"
+
+#include "AliAnalysisTaskSE.h"
+
+class AliAnalysisCuts;
+class TTree;
+class TFile;
+class AliESDv0Cuts;
+class AliKFVertex;
+class AliReducedEvent;
+class AliReducedEventFriend;
+class AliReducedPair;
+class AliDielectron;
+
+//_________________________________________________________________________
+class AliAnalysisTaskReducedTree : public AliAnalysisTaskSE {
+  
+public:
+  AliAnalysisTaskReducedTree();
+  AliAnalysisTaskReducedTree(const char *name);
+  virtual ~AliAnalysisTaskReducedTree(){  }
+
+  virtual void UserExec(Option_t *option);
+  virtual void UserCreateOutputObjects();
+  virtual void FinishTaskOutput();
+  
+  void UsePhysicsSelection(Bool_t phy=kTRUE) {fSelectPhysics=phy;}
+  void SetTriggerMask(UInt_t mask) {fTriggerMask=mask;}
+  UInt_t GetTriggerMask() const { return fTriggerMask; }
+  void SetRejectPileup(Bool_t pileup=kTRUE)     { fRejectPileup=pileup;     }
+  
+  // Cuts for selection of event to be written to tree
+  void SetEventFilter(AliAnalysisCuts * const filter) {fEventFilter=filter;}
+  // Cuts for selecting tracks included in the tree
+  void SetTrackFilter(AliAnalysisCuts * const filter) {fTrackFilter=filter;}
+  // Cuts for selecting tracks to be used for Q vector calculation
+  void SetFlowTrackFilter(AliAnalysisCuts * const filter) {fFlowTrackFilter = filter;}
+  
+  // Cuts for selecting V0s
+  void SetK0sPionCuts(AliAnalysisCuts * const filter) {fK0sPionCuts=filter;}
+  void SetLambdaProtonCuts(AliAnalysisCuts * const filter) {fLambdaProtonCuts=filter;}
+  void SetLambdaPionCuts(AliAnalysisCuts * const filter) {fLambdaPionCuts=filter;}
+  void SetK0sCuts(AliESDv0Cuts* const cuts) {fK0sCuts = cuts;}
+  void SetLambdaCuts(AliESDv0Cuts* const cuts) {fLambdaCuts = cuts;}
+  void SetK0sMassRange(Double_t min=0.4, Double_t max=0.6) {fK0sMassRange[0]=min; fK0sMassRange[1]=max;}
+  void SetLambdaMassRange(Double_t min=1.08, Double_t max=1.15) {fLambdaMassRange[0]=min; fLambdaMassRange[1]=max;}
+  void SetV0Histograms(AliDielectronHistos * const histos) {fV0Histos=histos;}
+  
+  // Toggle on/off information branches
+  void SetFillTrackInfo(Bool_t flag=kTRUE)       {fFillTrackInfo = flag;}
+  void SetFillDielectronInfo(Bool_t flag=kTRUE)  {fFillDielectronInfo = flag;}
+  void SetFillV0Info(Bool_t flag=kTRUE)          {fFillV0Info = flag;}
+  void SetFillCaloClusterInfo(Bool_t flag=kTRUE) {fFillCaloClusterInfo = flag;}
+  void SetFillFriendInfo(Bool_t flag=kTRUE)      {fFillFriendInfo = flag;}
+  
+  // Add dielectron objects to the list. These contain cuts and histogram definitions
+  void AddDielectron(AliDielectron * const die) { fListDielectron.Add(die); }
+ private:
+
+  TList fListDielectron;             // List of dielectron framework instances
+  TList fListHistos;                 //! List of histogram managers in the dielectron framework classes
+  
+  Bool_t fSelectPhysics;             // Whether to use physics selection
+  UInt_t fTriggerMask;               // Event trigger mask
+  Bool_t fRejectPileup;              // pileup rejection wanted
+
+  Bool_t fFillTrackInfo;             // fill track information
+  Bool_t fFillDielectronInfo;        // fill dielectrons
+  Bool_t fFillV0Info;                // fill the V0 information
+  Bool_t fFillCaloClusterInfo;       // fill the calorimeter clusters
+  Bool_t fFillFriendInfo;            // fill friend tree information
+
+  AliAnalysisCuts *fEventFilter;     // event filter
+  AliAnalysisCuts *fTrackFilter;     // filter for the hadrons to be correlated with the dielectrons
+  AliAnalysisCuts *fFlowTrackFilter; // filter for the barrel tracks to be used for the Q-vector
+  
+  AliESDv0Cuts *fK0sCuts;            // v0 standard filter for K0s->pi+pi-
+  AliESDv0Cuts *fLambdaCuts;         // v0 standard filter for Lambda0->p + pi
+  AliAnalysisCuts *fK0sPionCuts;     // filter for pions from K0s
+  AliAnalysisCuts *fLambdaProtonCuts;// filter for protons from Lambda
+  AliAnalysisCuts *fLambdaPionCuts;  // filter for pions from Lambda
+  Double_t fK0sMassRange[2];           // mass range for allowed K0s pairs
+  Double_t fLambdaMassRange[2];        // mass range for allowed Lambda pairs
+  AliDielectronHistos* fV0Histos;    // histogram manager for V0s
+
+  TFile *fTreeFile;                  // output file containing the tree
+  TTree *fTree;                      //! Reduced event tree
+  TTree *fFriendTreeFile;            // output file containing the friend tree
+  TTree *fFriendTree;                //! Reduced event tree with friend info (event plane, etc.)
+  AliReducedEvent *fReducedEvent;    // reduced event wise information
+  AliReducedEventFriend *fReducedEventFriend;    // friend reduced event wise information
+  
+  void FillEventInfo();                     // fill reduced event information
+  void FillFriendEventInfo();               // fill reduced event friend information
+  void FillTrackInfo();                     // fill reduced track information
+  void FillDielectronPairInfo(AliDielectron* die, Short_t iDie);  // fill dielectron reduced pair information
+  void FillV0PairInfo();                    // fill V0 reduced pair information
+  AliReducedPair* FillV0PairInfo(AliESDv0* v0, Int_t id, AliESDtrack* legPos, AliESDtrack* legNeg, AliKFVertex* vtxKF, Bool_t chargesAreCorrect);
+  UChar_t EncodeTPCClusterMap(AliESDtrack* track);
+  void FillCaloClusters();
+  
+  AliAnalysisTaskReducedTree(const AliAnalysisTaskReducedTree &c);
+  AliAnalysisTaskReducedTree& operator= (const AliAnalysisTaskReducedTree &c);
+
+  ClassDef(AliAnalysisTaskReducedTree, 1); //Analysis Task for creating a reduced event information tree 
+};
+#endif
index 2993050..7b1a2b5 100644 (file)
@@ -47,8 +47,6 @@ The names are available via the function PairClassName(Int_t i)
 #include <TMath.h>
 #include <TObject.h>
 
-#include <AliESDEvent.h>
-#include <AliESDtrack.h>
 #include <AliKFParticle.h>
 
 #include <AliEventplane.h>
@@ -577,13 +575,6 @@ void AliDielectron::FillTrackArrays(AliVEvent * const ev, Int_t eventNr)
   for (Int_t itrack=0; itrack<ntracks; ++itrack){
     //get particle
     AliVParticle *particle=ev->GetTrack(itrack);
-    //TODO: temporary solution, perhaps think about a better implementation
-    //      This is needed to use AliESDpidCuts, which relies on the ESD event
-    //      is set as a AliESDtrack attribute... somehow ugly!
-    if (ev->IsA()==AliESDEvent::Class()){
-      AliESDtrack *track=static_cast<AliESDtrack*>(particle);
-      track->SetESDEvent(static_cast<AliESDEvent*>(ev)); //only in trunk...
-    }
 
     //apply track cuts
     if (fTrackFilter.IsSelected(particle)!=selectedMask) continue;
index 39b4ae1..7e23a20 100644 (file)
@@ -46,7 +46,6 @@ public:
       kEv1PEv2M, kEv1MEv2M, kEv2PM,
       kEv2MM, kEv1PMRot };
   enum ELegType  { kEv1P, kEv1M, kEv2P, kEv2M };
-  enum EFilterBit  { kNone=0, kTPCqual=1, kTPCqualSPDany=4, kTPCqualSPDanyPIDele=8 };
   
   AliDielectron();
   AliDielectron(const char* name, const char* title);
diff --git a/PWGDQ/dielectron/AliReducedEvent.cxx b/PWGDQ/dielectron/AliReducedEvent.cxx
new file mode 100644 (file)
index 0000000..9cc55ca
--- /dev/null
@@ -0,0 +1,619 @@
+/*
+***********************************************************
+  Implementation of reduced ESD information classes for
+  quick analysis.
+  Contact: i.c.arsene@gsi.de, i.c.arsene@cern.ch
+  2012/06/21
+  *********************************************************
+*/
+
+#ifndef ALIREDUCEDEVENT_H
+#include "AliReducedEvent.h"
+#endif
+
+#include <TMath.h>
+#include <TClonesArray.h>
+
+ClassImp(AliReducedTrack)
+ClassImp(AliReducedPair)
+ClassImp(AliReducedEvent)
+ClassImp(AliReducedEventFriend)
+ClassImp(AliReducedCaloCluster)
+
+TClonesArray* AliReducedEvent::fgTracks = 0;
+TClonesArray* AliReducedEvent::fgCandidates = 0;
+TClonesArray* AliReducedEvent::fgCaloClusters = 0;
+
+//_______________________________________________________________________________
+AliReducedTrack::AliReducedTrack() :
+  fTrackId(-1),
+  fStatus(0),
+  fGlobalPhi(0.0),
+  fGlobalPt(0.0),
+  fGlobalEta(0.0),
+  fTPCPhi(0.0),
+  fTPCPt(0.0),
+  fTPCEta(0.0),
+  fMomentumInner(0.0),
+  fDCA(),
+  fITSclusterMap(0),
+  fITSsignal(0.0),
+  fTPCNcls(0),
+  fTPCCrossedRows(0),
+  fTPCNclsF(0),
+  fTPCNclsIter1(0),
+  fTPCClusterMap(0),
+  fTPCsignal(0),
+  fTPCnSig(),
+  fTOFbeta(0.0),
+  fTOFnSig(),
+  fTRDntracklets(),
+  fTRDpid(),
+  fCaloClusterId(-999),
+  fBayesPID(),
+  fFlags(0)
+{
+  //
+  // Constructor
+  //
+  fDCA[0] = 0.0; fDCA[1]=0.0;
+  for(Int_t i=0; i<4; ++i) {fTPCnSig[i]=-999.; fTOFnSig[i]=-999.;} 
+  for(Int_t i=0; i<3; ++i) {fBayesPID[i]=-999.;}
+  fTRDpid[0]=-999.; fTRDpid[1]=-999.;
+}
+
+
+//_______________________________________________________________________________
+AliReducedTrack::~AliReducedTrack()
+{
+  //
+  // De-Constructor
+  //
+}
+
+
+//_______________________________________________________________________________
+AliReducedPair::AliReducedPair() :
+  fCandidateId(-1),
+  fPairType(-1), 
+  fLegIds(),
+  fMass(),
+  fPhi(0.0),
+  fPt(0.0),
+  fEta(0.0),
+  fLxy(0.0),
+  fLxyErr(0.0),
+  fOpeningAngle(-1.0),
+  //fOnTheFly(kFALSE),
+  fMCid(0)
+{
+  //
+  // Constructor
+  //
+  fLegIds[0] = -1; fLegIds[1] = -1;
+  fMass[0]=-999.; fMass[1]=-999.; fMass[2]=-999.;
+}
+
+
+//_______________________________________________________________________________
+AliReducedPair::AliReducedPair(const AliReducedPair &c) :
+  TObject(c),
+  fCandidateId(c.CandidateId()),
+  fPairType(c.PairType()),
+  fLegIds(),
+  fMass(),
+  fPhi(c.Phi()),
+  fPt(c.Pt()),
+  fEta(c.Eta()),
+  fLxy(c.Lxy()),
+  fLxyErr(c.LxyErr()),
+  fOpeningAngle(c.OpeningAngle()),
+  //fOnTheFly(c.IsOnTheFly()),
+  fMCid(c.MCid())
+{
+  //
+  // copy constructor
+  //
+  fLegIds[0] = c.LegId(0);
+  fLegIds[1] = c.LegId(1);
+  fMass[0] = c.Mass(0); fMass[1] = c.Mass(1); fMass[2] = c.Mass(2);
+}
+
+
+//_______________________________________________________________________________
+AliReducedPair::~AliReducedPair() {
+  //
+  // destructor
+  //
+}
+
+//____________________________________________________________________________
+AliReducedEvent::AliReducedEvent() :
+  TObject(),
+  fRunNo(0),
+  fBC(0),
+  fTriggerMask(0),
+  fIsPhysicsSelection(kTRUE),
+  fVtx(),
+  fNVtxContributors(0),
+  fVtxTPC(),
+  fNVtxTPCContributors(0),
+  fCentrality(),
+  fCentQuality(0),
+  fNV0candidates(),
+  fNDielectronCandidates(0),
+  fNtracks(),
+  fSPDntracklets(0),
+  fVZEROMult(),
+  fZDCnEnergy(),
+  fTracks(0x0),
+  fCandidates(0x0),
+  fNCaloClusters(0),
+  fCaloClusters(0x0)
+//fFMDMult()
+{
+  //
+  // Constructor
+  //
+  for(Int_t i=0; i<3; ++i) {fVtx[i]=-999.; fVtxTPC[i]=-999.;}
+  for(Int_t i=0; i<4; ++i) fCentrality[i]=-1.;
+  fNV0candidates[0]=0; fNV0candidates[1]=0;
+  fNtracks[0]=0; fNtracks[1]=0;
+  for(Int_t i=0; i<64; ++i) fVZEROMult[i] = 0.0;
+  for(Int_t i=0; i<8; ++i) fZDCnEnergy[i]=0.0;
+}
+
+
+//____________________________________________________________________________
+AliReducedEvent::AliReducedEvent(const Char_t* /*name*/) :
+  TObject(),
+  fRunNo(0),
+  fBC(0),
+  fTriggerMask(0),
+  fIsPhysicsSelection(kTRUE),
+  fVtx(),
+  fNVtxContributors(0),
+  fVtxTPC(),
+  fNVtxTPCContributors(0),
+  fCentrality(),
+  fCentQuality(0),
+  fNV0candidates(),
+  fNDielectronCandidates(0),
+  fNtracks(),
+  fSPDntracklets(0),
+  fVZEROMult(),
+  fZDCnEnergy(),
+  fTracks(0x0),
+  fCandidates(0x0),
+  fNCaloClusters(0),
+  fCaloClusters(0x0)
+//fFMDMult()
+{
+  //
+  // Constructor
+  //
+  for(Int_t i=0; i<3; ++i) {fVtx[i]=-999.; fVtxTPC[i]=-999.;}
+  for(Int_t i=0; i<4; ++i) fCentrality[i]=-1.;
+  fNV0candidates[0]=0; fNV0candidates[1]=0;
+  fNtracks[0]=0; fNtracks[1]=0;
+  for(Int_t i=0; i<64; ++i) fVZEROMult[i] = 0.0;
+  for(Int_t i=0; i<8; ++i) fZDCnEnergy[i]=0.0;
+  
+  if(!fgTracks) fgTracks = new TClonesArray("AliReducedTrack", 100000);
+  fTracks = fgTracks;
+  if(!fgCandidates) fgCandidates = new TClonesArray("AliReducedPair", 100000);
+  fCandidates = fgCandidates;
+  if(!fgCaloClusters) fgCaloClusters = new TClonesArray("AliReducedCaloCluster", 50000);
+  fCaloClusters = fgCaloClusters;
+}
+
+
+//____________________________________________________________________________
+AliReducedEvent::~AliReducedEvent()
+{
+  //
+  // De-Constructor
+  //
+  ClearEvent();
+}
+
+
+//____________________________________________________________________________
+Float_t AliReducedEvent::MultVZEROA() const
+{
+  //
+  // Total VZERO multiplicity in A side
+  //
+  Float_t mult=0.0;
+  for(Int_t i=32;i<64;++i)
+    mult += fVZEROMult[i];
+  return mult;
+}
+
+
+//____________________________________________________________________________
+Float_t AliReducedEvent::MultVZEROC() const
+{
+  //
+  // Total VZERO multiplicity in C side
+  //
+  Float_t mult=0.0;
+  for(Int_t i=0;i<32;++i)
+    mult += fVZEROMult[i];
+  return mult;
+}
+
+
+//____________________________________________________________________________
+Float_t AliReducedEvent::MultVZERO() const
+{
+  //
+  // Total VZERO multiplicity
+  //
+  return MultVZEROA()+MultVZEROC();
+}
+
+
+//____________________________________________________________________________
+Float_t AliReducedEvent::MultRingVZEROA(Int_t ring) const 
+{
+  //
+  //  VZERO multiplicity in a given ring on A side
+  //
+  if(ring<0 || ring>3) return -1.0;
+
+  Float_t mult=0.0;
+  for(Int_t i=32+8*ring; i<32+8*(ring+1); ++i)
+    mult += fVZEROMult[i];
+  return mult;
+}
+
+
+//____________________________________________________________________________
+Float_t AliReducedEvent::MultRingVZEROC(Int_t ring) const 
+{
+  //
+  //  VZERO multiplicity in a given ring on C side
+  //
+  if(ring<0 || ring>3) return -1.0;
+
+  Float_t mult=0.0;
+  for(Int_t i=8*ring; i<8*(ring+1); ++i)
+    mult += fVZEROMult[i];
+  return mult;
+}
+
+//_____________________________________________________________________________
+void AliReducedEvent::ClearEvent() {
+  //
+  // clear the event
+  //
+  fTracks->Clear("C");
+  fCandidates->Clear("C");
+  fCaloClusters->Clear("C");
+  fRunNo = 0;
+  fBC = 0;
+  fTriggerMask = 0;
+  fIsPhysicsSelection = kTRUE;
+  fCentQuality = 0;
+  fNV0candidates[0] = 0; fNV0candidates[1] = 0;
+  fNDielectronCandidates = 0;
+  fNtracks[0] = 0; fNtracks[1] = 0;
+  for(Int_t i=0; i<3; ++i) {fVtx[i]=-999.; fVtxTPC[i]=-999.; fCentrality[i]=-1.;}
+  for(Int_t i=0; i<64; ++i) fVZEROMult[i] = 0.0;
+  for(Int_t i=0; i<8; ++i) fZDCnEnergy[i]=0.0;
+}
+
+
+//_______________________________________________________________________________
+AliReducedEventFriend::AliReducedEventFriend() :
+ fQvector(),
+ fEventPlaneStatus()
+{
+  //
+  // default constructor
+  //
+  for(Int_t idet=0; idet<kNdetectors; ++idet) {
+    for(Int_t ih=0; ih<fgkNMaxHarmonics; ++ih) {
+      fEventPlaneStatus[idet][ih] = 0;
+      for(Int_t ic=0; ic<2; ++ic)
+       fQvector[idet][ih][ic] = 0.0;
+    }
+  }
+}
+
+
+//____________________________________________________________________________
+AliReducedEventFriend::~AliReducedEventFriend()
+{
+  //
+  // De-Constructor
+  //
+  ClearEvent();
+}
+
+
+//_____________________________________________________________________________
+void AliReducedEventFriend::ClearEvent() {
+  //
+  // clear the event
+  //
+  for(Int_t idet=0; idet<kNdetectors; ++idet) {
+    for(Int_t ih=0; ih<fgkNMaxHarmonics; ++ih) {
+      fEventPlaneStatus[idet][ih] = 0;
+      for(Int_t ic=0; ic<2; ++ic)
+       fQvector[idet][ih][ic] = 0.0;
+    }
+  }
+}
+
+
+//____________________________________________________________________________
+void AliReducedEventFriend::CopyEvent(const AliReducedEventFriend* event) {
+  //
+  // copy information from another event to this one
+  //
+  for(Int_t idet=0; idet<kNdetectors; ++idet) {
+    for(Int_t ih=0; ih<fgkNMaxHarmonics; ++ih) {
+      fQvector[idet][ih][0] = event->Qx(idet, ih+1);
+      fQvector[idet][ih][1] = event->Qy(idet, ih+1);
+      fEventPlaneStatus[idet][ih] = event->GetEventPlaneStatus(idet, ih+1);
+    }
+  }
+}
+
+
+//_____________________________________________________________________________
+AliReducedCaloCluster::AliReducedCaloCluster() :
+ fType(kUndefined),
+ fEnergy(-999.),
+ fTrackDx(-999.),
+ fTrackDz(-999.)
+{
+  //
+  // default constructor
+  //
+}
+
+
+//_____________________________________________________________________________
+AliReducedCaloCluster::~AliReducedCaloCluster()
+{
+  //
+  // destructor
+  //
+}
+
+
+//_______________________________________________________________________________
+void AliReducedEvent::GetQvector(Double_t Qvec[][2], Int_t det,
+                                           Float_t etaMin/*=-0.8*/, Float_t etaMax/*=+0.8*/,
+                                           Bool_t (*IsTrackSelected)(AliReducedTrack*)/*=NULL*/) {
+  //
+  // Get the event plane for a specified detector
+  //
+  if(det==AliReducedEventFriend::kTPC || 
+     det==AliReducedEventFriend::kTPCptWeights ||
+     det==AliReducedEventFriend::kTPCpos ||
+     det==AliReducedEventFriend::kTPCneg) {
+    GetTPCQvector(Qvec, det, etaMin, etaMax, IsTrackSelected);
+    return;
+  }
+  if(det==AliReducedEventFriend::kVZEROA ||
+     det==AliReducedEventFriend::kVZEROC) {
+    GetVZEROQvector(Qvec, det);   
+    return;
+  }
+  if(det==AliReducedEventFriend::kZDCA ||
+     det==AliReducedEventFriend::kZDCC) {
+    GetZDCQvector(Qvec, det);
+    return;
+  }
+  if(det==AliReducedEventFriend::kFMD) {
+    //TODO implementation
+    return;
+  }
+  return;
+}
+
+
+//_________________________________________________________________
+Int_t AliReducedEvent::GetTPCQvector(Double_t Qvec[][2], Int_t det, 
+                                               Float_t etaMin/*=-0.8*/, Float_t etaMax/*=+0.8*/,
+                                               Bool_t (*IsTrackSelected)(AliReducedTrack*)/*=NULL*/) {
+  //
+  // Construct the event plane using tracks in the barrel
+  //
+  if(!(det==AliReducedEventFriend::kTPC ||
+       det==AliReducedEventFriend::kTPCpos ||
+       det==AliReducedEventFriend::kTPCneg))
+    return 0;
+  Int_t nUsedTracks = 0;
+  Short_t charge = 0;
+  AliReducedTrack* track=0x0;
+  Double_t weight=0.0; Double_t absWeight = 0.0; Double_t x=0.0; Double_t y=0.0; 
+  TIter nextTrack(fTracks);
+  while((track=static_cast<AliReducedTrack*>(nextTrack()))) {
+    if(track->Eta()<etaMin) continue;
+    if(track->Eta()>etaMax) continue;
+    charge = track->Charge();
+    if(det==AliReducedEventFriend::kTPCpos && charge<0) continue;
+    if(det==AliReducedEventFriend::kTPCneg && charge>0) continue;
+    
+    if(IsTrackSelected && !IsTrackSelected(track)) continue;
+    absWeight = 1.0;
+    if(det==AliReducedEventFriend::kTPCptWeights) {
+      absWeight = track->Pt();
+      if(absWeight>2.0) absWeight = 2.0;    // pt is the weight used for the event plane
+    }
+    weight = absWeight;
+    if(track->Eta()<0.0) weight *= -1.0;
+    
+    ++nUsedTracks;
+    x = TMath::Cos(track->Phi());
+    y = TMath::Sin(track->Phi());
+    //  1st harmonic  
+    Qvec[0][0] += weight*x;
+    Qvec[0][1] += weight*y;
+    //  2nd harmonic
+    Qvec[1][0] += absWeight*(2.0*TMath::Power(x,2.0)-1);
+    Qvec[1][1] += absWeight*(2.0*x*y);
+    //  3rd harmonic
+    Qvec[2][0] += weight*(4.0*TMath::Power(x,3.0)-3.0*x);
+    Qvec[2][1] += weight*(3.0*y-4.0*TMath::Power(y,3.0));
+    //  4th harmonic
+    Qvec[3][0] += absWeight*(1.0-8.0*TMath::Power(x*y,2.0));
+    Qvec[3][1] += absWeight*(4.0*x*y-8.0*x*TMath::Power(y,3.0));
+    //  5th harmonic
+    Qvec[4][0] += weight*(16.0*TMath::Power(x,5.0)-20.0*TMath::Power(x, 3.0)+5.0*x);
+    Qvec[4][1] += weight*(16.0*TMath::Power(y,5.0)-20.0*TMath::Power(y, 3.0)+5.0*y);
+    //  6th harmonic
+    Qvec[5][0] += absWeight*(32.0*TMath::Power(x,6.0)-48.0*TMath::Power(x, 4.0)+18.0*TMath::Power(x, 2.0)-1.0);
+    Qvec[5][1] += absWeight*(x*y*(32.0*TMath::Power(y,4.0)-32.0*TMath::Power(y, 2.0)+6.0)); 
+  }
+  return nUsedTracks;
+}
+
+
+//____________________________________________________________________________
+void AliReducedEvent::SubtractParticleFromQvector(
+       AliReducedTrack* particle, Double_t Qvec[][2], Int_t det, 
+       Float_t etaMin/*=-0.8*/, Float_t etaMax/*=+0.8*/,
+       Bool_t (*IsTrackSelected)(AliReducedTrack*)/*=NULL*/) {
+  //
+  // subtract a particle from the event Q-vector
+  //
+  Float_t eta = particle->Eta();
+  if(eta<etaMin) return;
+  if(eta>etaMax) return;
+
+  Float_t charge = particle->Charge();
+  if(det==AliReducedEventFriend::kTPCpos && charge<0) return;
+  if(det==AliReducedEventFriend::kTPCneg && charge>0) return;
+  
+  if(IsTrackSelected && !IsTrackSelected(particle)) return;
+  
+  Double_t weight=0.0; Double_t absWeight = 0.0;
+  if(det==AliReducedEventFriend::kTPCptWeights) {
+    absWeight = particle->Pt();
+    if(absWeight>2.0) absWeight = 2.0;
+  }
+  weight = absWeight;
+  if(eta<0.0) weight *= -1.0;
+    
+  Float_t x = TMath::Cos(particle->Phi());
+  Float_t y = TMath::Sin(particle->Phi());
+  
+  //  1st harmonic  
+  Qvec[0][0] -= weight*x;
+  Qvec[0][1] -= weight*y;
+  //  2nd harmonic
+  Qvec[1][0] -= absWeight*(2.0*TMath::Power(x,2.0)-1);
+  Qvec[1][1] -= absWeight*(2.0*x*y);
+  //  3rd harmonic
+  Qvec[2][0] -= weight*(4.0*TMath::Power(x,3.0)-3.0*x);
+  Qvec[2][1] -= weight*(3.0*y-4.0*TMath::Power(y,3.0));
+  //  4th harmonic
+  Qvec[3][0] -= absWeight*(1.0-8.0*TMath::Power(x*y,2.0));
+  Qvec[3][1] -= absWeight*(4.0*x*y-8.0*x*TMath::Power(y,3.0));
+  //  5th harmonic
+  Qvec[4][0] -= weight*(16.0*TMath::Power(x,5.0)-20.0*TMath::Power(x, 3.0)+5.0*x);
+  Qvec[4][1] -= weight*(16.0*TMath::Power(y,5.0)-20.0*TMath::Power(y, 3.0)+5.0*y);
+  //  6th harmonic
+  Qvec[5][0] -= absWeight*(32.0*TMath::Power(x,6.0)-48.0*TMath::Power(x, 4.0)+18.0*TMath::Power(x, 2.0)-1.0);
+  Qvec[5][1] -= absWeight*(x*y*(32.0*TMath::Power(y,4.0)-32.0*TMath::Power(y, 2.0)+6.0)); 
+  
+  return;
+}
+
+
+//_________________________________________________________________
+void AliReducedEvent::GetVZEROQvector(Double_t Qvec[][2], Int_t det) {
+  //
+  // Get the reaction plane from the VZERO detector for a given harmonic
+  //
+  GetVZEROQvector(Qvec, det, fVZEROMult);
+}
+
+
+//_________________________________________________________________
+void AliReducedEvent::GetVZEROQvector(Double_t Qvec[][2], Int_t det, Float_t* vzeroMult) {
+  //
+  // Get the reaction plane from the VZERO detector for a given harmonic
+  //
+  //  Q{x,y} = SUM_i mult(i) * {cos(n*phi_i), sin(n*phi_i)} 
+  //  phi_i - phi angle of the VZERO sector i
+  //          Each sector covers 45 degrees(8 sectors per ring). Middle of sector 0 is at 45/2
+  //        channel 0: 22.5
+  //                1: 22.5+45
+  //                2: 22.5+45*2
+  //               ...
+  //        at the next ring continues the same
+  //        channel 8: 22.5
+  //        channel 9: 22.5 + 45
+  //       
+  if(!(det==AliReducedEventFriend::kVZEROA ||
+       det==AliReducedEventFriend::kVZEROC))
+    return; 
+  
+  const Double_t kX[8] = {0.92388, 0.38268, -0.38268, -0.92388, -0.92388, -0.38268, 0.38268, 0.92388};    // cosines of the angles of the VZERO sectors (8 per ring)
+  const Double_t kY[8] = {0.38268, 0.92388, 0.92388, 0.38268, -0.38268, -0.92388, -0.92388, -0.38268};    // sines     -- " --
+  Int_t phi;
+  
+  for(Int_t iChannel=0; iChannel<64; ++iChannel) {
+    if(iChannel<32 && det==AliReducedEventFriend::kVZEROA) continue;
+    if(iChannel>=32 && det==AliReducedEventFriend::kVZEROC) continue;
+    phi=iChannel%8;
+    //  1st harmonic  
+    Qvec[0][0] += vzeroMult[iChannel]*kX[phi];
+    Qvec[0][1] += vzeroMult[iChannel]*kY[phi];
+    //  2nd harmonic
+    Qvec[1][0] += vzeroMult[iChannel]*(2.0*TMath::Power(kX[phi],2.0)-1);
+    Qvec[1][1] += vzeroMult[iChannel]*(2.0*kX[phi]*kY[phi]);
+    //  3rd harmonic
+    Qvec[2][0] += vzeroMult[iChannel]*(4.0*TMath::Power(kX[phi],3.0)-3.0*kX[phi]);
+    Qvec[2][1] += vzeroMult[iChannel]*(3.0*kY[phi]-4.0*TMath::Power(kY[phi],3.0));
+    //  4th harmonic
+    Qvec[3][0] += vzeroMult[iChannel]*(1.0-8.0*TMath::Power(kX[phi]*kY[phi],2.0));
+    Qvec[3][1] += vzeroMult[iChannel]*(4.0*kX[phi]*kY[phi]-8.0*kX[phi]*TMath::Power(kY[phi],3.0));
+    //  5th harmonic
+    Qvec[4][0] += vzeroMult[iChannel]*(16.0*TMath::Power(kX[phi],5.0)-20.0*TMath::Power(kX[phi], 3.0)+5.0*kX[phi]);
+    Qvec[4][1] += vzeroMult[iChannel]*(16.0*TMath::Power(kY[phi],5.0)-20.0*TMath::Power(kY[phi], 3.0)+5.0*kY[phi]);
+    //  6th harmonic
+    Qvec[5][0] += vzeroMult[iChannel]*(32.0*TMath::Power(kX[phi],6.0)-48.0*TMath::Power(kX[phi], 4.0)+18.0*TMath::Power(kX[phi], 2.0)-1.0);
+    Qvec[5][1] += vzeroMult[iChannel]*(kX[phi]*kY[phi]*(32.0*TMath::Power(kY[phi],4.0)-32.0*TMath::Power(kY[phi], 2.0)+6.0));
+  }    // end loop over channels 
+}
+
+
+//_________________________________________________________________
+void AliReducedEvent::GetZDCQvector(Double_t Qvec[][2], Int_t det) const {
+  //
+  // Construct the event plane using the ZDC
+  // ZDC has 2 side (A and C) with 4 calorimeters on each side  
+  // The XY position of each calorimeter is specified by the 
+  // zdcNTowerCenters_x and zdcNTowerCenters_y arrays
+  if(!(det==AliReducedEventFriend::kZDCA || 
+       det==AliReducedEventFriend::kZDCC)) return;       // bad detector option
+  const Float_t zdcTowerCenter = 1.75;
+  const Float_t zdcNTowerCentersX[4] = {-zdcTowerCenter,  zdcTowerCenter, -zdcTowerCenter, zdcTowerCenter};
+  const Float_t zdcNTowerCentersY[4] = {-zdcTowerCenter, -zdcTowerCenter,  zdcTowerCenter, zdcTowerCenter};
+
+  Qvec[0][0] = 0.0; Qvec[0][1] = 0.0;   // first harmonic Q-vector
+  Float_t zdcNCentroidSum = 0;
+  Float_t zdcNalpha = 0.5;
+    
+  for(Int_t i=0; i<4; ++i) {
+    if(fZDCnEnergy[i+(det==AliReducedEventFriend::kZDCA ? 4 : 0)]>0.0) {
+      Float_t zdcNenergyAlpha = TMath::Power(fZDCnEnergy[i+(det==AliReducedEventFriend::kZDCA ? 4 : 0)], zdcNalpha);
+      Qvec[0][0] += zdcNTowerCentersX[i-1]*zdcNenergyAlpha;
+      Qvec[0][1] += zdcNTowerCentersY[i-1]*zdcNenergyAlpha;
+      zdcNCentroidSum += zdcNenergyAlpha;
+    }
+  }   // end loop over channels
+  
+  if(zdcNCentroidSum>0.0) {
+    Qvec[0][0] /= zdcNCentroidSum;
+    Qvec[0][1] /= zdcNCentroidSum;
+  }
+}
diff --git a/PWGDQ/dielectron/AliReducedEvent.h b/PWGDQ/dielectron/AliReducedEvent.h
new file mode 100644 (file)
index 0000000..8eacd6b
--- /dev/null
@@ -0,0 +1,468 @@
+// Classes used for creating a reduced information tree
+// Author: Ionut-Cristian Arsene (i.c.arsene@gsi.de)
+// 
+//  Basic structure:
+//  1. Event wise information
+//  2. List of tracks in the event
+//  3. List of resonance candidates
+
+#ifndef ALIREDUCEDEVENT_H
+#define ALIREDUCEDEVENT_H
+
+#include <TClonesArray.h>
+#include <TBits.h>
+#include <TMath.h>
+
+
+const Int_t fgkNMaxHarmonics = 10;
+/*class AliCorrelationReducedTrack;
+class AliCorrelationReducedPair;
+class AliReducedEventFriend;
+class AliReducedEvent;
+class AliCorrelationReducedCaloCluster;*/
+
+//_____________________________________________________________________
+class AliReducedTrack : public TObject {
+
+  friend class AliAnalysisTaskReducedTree;  // friend analysis task which fills the object
+
+ public:
+  AliReducedTrack();
+  ~AliReducedTrack();
+
+  // getters
+  UShort_t TrackId()                     const {return fTrackId;}
+  ULong_t  Status()                      const {return fStatus;}
+  Bool_t   CheckTrackStatus(UInt_t flag) const {return (flag<8*sizeof(ULong_t) ? (fStatus&(1<<flag)) : kFALSE);}
+  Int_t    Charge()                      const {return (fGlobalPt>0.0 ? +1 : -1);}
+  Float_t  Px()                          const {return TMath::Abs(fGlobalPt)*TMath::Cos(fGlobalPhi);}
+  Float_t  Py()                          const {return TMath::Abs(fGlobalPt)*TMath::Sin(fGlobalPhi);}
+  Float_t  Pz()                          const {return TMath::Abs(fGlobalPt)*TMath::SinH(fGlobalEta);}
+  Float_t  P()                           const {return TMath::Abs(fGlobalPt)*TMath::CosH(fGlobalEta);};
+  Float_t  Phi()                         const {return fGlobalPhi;}
+  Float_t  Pt()                          const {return TMath::Abs(fGlobalPt);}
+  Float_t  Eta()                         const {return fGlobalEta;}
+  Float_t  Theta()                       const {return TMath::ACos(TMath::TanH(fGlobalEta));}
+  Float_t  PxTPC()                       const {return fTPCPt*TMath::Cos(fTPCPhi);}
+  Float_t  PyTPC()                       const {return fTPCPt*TMath::Sin(fTPCPhi);}
+  Float_t  PzTPC()                       const {return fTPCPt*TMath::SinH(fTPCEta);}
+  Float_t  PTPC()                        const {return fTPCPt*TMath::CosH(fTPCEta);};
+  Float_t  PhiTPC()                      const {return fTPCPhi;}
+  Float_t  PtTPC()                       const {return fTPCPt;}
+  Float_t  EtaTPC()                      const {return fTPCEta;}
+  Float_t  ThetaTPC()                    const {return TMath::ACos(TMath::TanH(fTPCEta));}
+  Float_t  Pin()                         const {return fMomentumInner;}
+  Float_t  DCAxy()                       const {return fDCA[0];}
+  Float_t  DCAz()                        const {return fDCA[1];}
+  
+  UShort_t ITSncls()                const;
+  UChar_t  ITSclusterMap()          const {return fITSclusterMap;}
+  Bool_t   ITSLayerHit(Int_t layer) const {return (layer>=0 && layer<6 ? (fITSclusterMap&(1<<layer)) : kFALSE);};
+  Float_t  ITSsignal()              const {return fITSsignal;}
+  
+  UChar_t TPCncls()                        const {return fTPCNcls;}
+  UChar_t TPCFindableNcls()                const {return fTPCNclsF;}
+  UChar_t TPCCrossedRows()                 const {return fTPCCrossedRows;}
+  UChar_t TPCnclsIter1()                   const {return fTPCNclsIter1;}
+  UChar_t TPCClusterMap()                  const {return fTPCClusterMap;}
+  Int_t   TPCClusterMapBitsFired()         const;
+  Bool_t  TPCClusterMapBitFired(Int_t bit) const {return (bit>=0 && bit<8 ? (fTPCClusterMap&(1<<bit)) : kFALSE);};
+  Float_t TPCsignal()                      const {return fTPCsignal;}
+  Float_t TPCnSig(Int_t specie)            const {return (specie>=0 && specie<=3 ? fTPCnSig[specie] : -999.);}
+  
+  Float_t  TOFbeta()             const {return fTOFbeta;}    
+  Float_t  TOFnSig(Int_t specie) const {return (specie>=0 && specie<=3 ? fTOFnSig[specie] : -999.);}
+  
+  Int_t    TRDntracklets(Int_t type)  const {return (type==0 || type==1 ? fTRDntracklets[type] : -1);}
+  Float_t  TRDpid(Int_t specie)       const {return (specie>=0 && specie<=1 ? fTRDpid[specie] : -999.);}
+  
+  Int_t    CaloClusterId() const {return fCaloClusterId;}
+  //Float_t  CaloEnergy(AliReducedEvent* event) const {if(fCaloClusterId>0) return event->GetCaloCluster(fCaloClusterId)->Energy();}
+  //Float_t  CaloDx(AliReducedEvent* event) const {if(fCaloClusterId>0) return event->GetCaloCluster(fCaloClusterId)->Dx();}
+  //Float_t  CaloDz(AliReducedEvent* event) const {if(fCaloClusterId>0) return event->GetCaloCluster(fCaloClusterId)->Dz();}
+  
+  Float_t  BayesPID(Int_t specie) const {return (specie>=0 && specie<=2 ? fBayesPID[specie] : -999.);}
+  Bool_t   UsedForQvector()       const {return fFlags&(1<<0);}
+  
+ private:
+  UShort_t fTrackId;            // track id 
+  ULong_t fStatus;              // tracking status
+  Float_t fGlobalPhi;           // phi at the vertex from global track, in the [0,2pi) interval
+  Float_t fGlobalPt;            // pt*charge at the vertex from global track
+  Float_t fGlobalEta;           // eta at the vertex from global track
+  Float_t fTPCPhi;              // phi at the vertex from TPC alone tracking , in the [0,2pi) interval
+  Float_t fTPCPt;               // pt at the vertex from TPC alone tracking  
+  Float_t fTPCEta;              // eta at the vertex from TPC alone tracking 
+  Float_t fMomentumInner;       // inner param momentum (only the magnitude)
+  Float_t fDCA[2];              // DCA xy,z
+  
+  // ITS
+  UChar_t  fITSclusterMap;      // ITS cluster map
+  Float_t  fITSsignal;          // ITS signal
+  
+  // TPC
+  UChar_t fTPCNcls;            // TPC ncls                          
+  UChar_t fTPCCrossedRows;     // TPC crossed rows                  
+  UChar_t fTPCNclsF;           // TPC findable ncls                 
+  UChar_t fTPCNclsIter1;       // TPC no clusters after first iteration
+  UChar_t fTPCClusterMap;      // TPC cluster distribution map
+  Float_t fTPCsignal;          // TPC de/dx
+  Float_t fTPCnSig[4];         // 0-electron; 1-pion; 2-kaon; 3-proton
+    
+  // TOF
+  Float_t fTOFbeta;             // TOF pid info
+  Float_t fTOFnSig[4];          // TOF n-sigma deviation from expected signal
+  
+  // TRD
+  UChar_t fTRDntracklets[2];       // 0 - AliESDtrack::GetTRDntracklets(); 1 - AliESDtrack::GetTRDntrackletsPID()   TODO: use only 1 char
+  Float_t fTRDpid[2];              // TRD pid probabilities, [0]-electron, [1]-pion
+  
+  // EMCAL/PHOS
+  Int_t  fCaloClusterId;          // ID for the calorimeter cluster (if any)
+  
+  // Bayesian PID
+  Float_t fBayesPID[3];            // Combined Bayesian PID   pi/K/p
+  
+  UShort_t fFlags;                // BIT0 toggled if track used for TPC event plane   TODO combine with other posible flags, use for MC pid?
+  // TODO flag for which TPC part used for pid  --> Char_t  used in 2011 data
+  
+  AliReducedTrack(const AliReducedTrack &c);
+  AliReducedTrack& operator= (const AliReducedTrack &c);
+
+  ClassDef(AliReducedTrack, 2);
+};
+
+
+//_____________________________________________________________________
+class AliReducedPair : public TObject {
+
+  friend class AliAnalysisTaskReducedTree;  // friend analysis task which fills the object
+
+ public:
+  enum CandidateType {
+    kK0sToPiPi=0,
+    kPhiToKK,
+    kLambda0ToPPi,
+    kALambda0ToPPi,
+    kJpsiToEE,
+    kUpsilon,
+    kNMaxCandidateTypes
+  };
+  AliReducedPair();
+  AliReducedPair(const AliReducedPair &c);
+  ~AliReducedPair();
+
+  // getters
+  Char_t   CandidateId()         const {return fCandidateId;}
+  Char_t   PairType()            const {return fPairType;}
+  Int_t    LegId(Int_t leg)      const {return (leg==0 || leg==1 ? fLegIds[leg] : -1);}
+  Float_t  Mass(Int_t idx=0)     const {return (idx>=0 && idx<3 ? fMass[idx] : -999.);}
+  Float_t  Px()                  const {return fPt*TMath::Cos(fPhi);}
+  Float_t  Py()                  const {return fPt*TMath::Sin(fPhi);}
+  Float_t  Pz()                  const {return fPt*TMath::SinH(fEta);}
+  Float_t  P()                   const {return fPt*TMath::CosH(fEta);}
+  Float_t  Phi()                 const {return fPhi;}
+  Float_t  Pt()                  const {return fPt;}
+  Float_t  Eta()                 const {return fEta;}
+  Float_t  Energy()              const;
+  Float_t  Rapidity()            const;
+  Float_t  Theta()               const {return TMath::ACos(TMath::TanH(fEta));}
+  Float_t  Lxy()                 const {return fLxy;}
+  Float_t  LxyErr()              const {return fLxyErr;}
+  Float_t  OpeningAngle()        const {return fOpeningAngle;}
+  Bool_t   IsOnTheFly()          const {return fPairType;}
+  UInt_t   MCid()                const {return fMCid;}
+  Bool_t   CheckMC(const Int_t flag) const {return (flag<32 ? (fMCid&(1<<flag)) : kFALSE);}
+  
+ private:
+  Char_t  fCandidateId;         // candidate type (K0s, Lambda, J/psi, phi, etc)
+  Char_t  fPairType;            // 0 ++; 1 +-; 2 -- for dielectron pairs; 0- offline, 1- on the fly for V0 candidates
+  UShort_t fLegIds[2];          // leg ids 
+  Float_t fMass[3];             // invariant mass for pairs (2 extra mass values for other V0 pid assumptions)
+                                // idx=0 -> K0s assumption; idx=1 -> Lambda; idx=2 -> anti-Lambda
+  Float_t fPhi;                 // pair phi in the [0,2*pi) interval
+  Float_t fPt;                  // pair pt
+  Float_t fEta;                 // pair eta 
+  Float_t fLxy;                 // pseudo-proper decay length
+  Float_t fLxyErr;              // error on Lxy
+  Float_t fOpeningAngle;        // opening angle                TODO remove   ???
+  UInt_t  fMCid;                // Bit map with Monte Carlo info about the pair
+
+  AliReducedPair& operator= (const AliReducedPair &c);
+
+  ClassDef(AliReducedPair, 1);
+};
+
+
+//_________________________________________________________________________
+class AliReducedEventFriend : public TObject {
+  
+  friend class AliAnalysisTaskReducedTree;    // friend analysis task which fills the object
+  
+ public: 
+  enum EventPlaneStatus {
+    kRaw=0,
+    kCalibrated,
+    kRecentered,
+    kShifted,
+    kNMaxFlowFlags
+  };
+  enum EventPlaneDetector {
+    kTPC=0,       
+    kTPCptWeights,
+    kTPCpos,
+    kTPCneg,
+    kVZEROA,
+    kVZEROC,
+    kFMD,
+    kZDCA,
+    kZDCC,
+    kNdetectors
+  };
+  
+  AliReducedEventFriend();
+  ~AliReducedEventFriend();
+  
+  Double_t Qx(Int_t det, Int_t harmonic)  const {return (det>=0 && det<kNdetectors && harmonic>0 && harmonic<=fgkNMaxHarmonics ? fQvector[det][harmonic-1][0] : -999.);}
+  Double_t Qy(Int_t det, Int_t harmonic)  const {return (det>=0 && det<kNdetectors && harmonic>0 && harmonic<=fgkNMaxHarmonics ? fQvector[det][harmonic-1][1] : -999.);}
+  Double_t EventPlane(Int_t det, Int_t h) const;
+  UChar_t GetEventPlaneStatus(Int_t det, Int_t h) const {return (det>=0 && det<kNdetectors && h>0 && h<=fgkNMaxHarmonics ? fEventPlaneStatus[det][h] : -999.);} 
+  Bool_t  CheckEventPlaneStatus(Int_t det, Int_t h, EventPlaneStatus flag) const;
+  void    CopyEvent(const AliReducedEventFriend* event);
+
+  void SetQx(Int_t det, Int_t harmonic, Float_t qx) { if(det>=0 && det<kNdetectors && harmonic>0 && harmonic<=fgkNMaxHarmonics) fQvector[det][harmonic-1][0]=qx;}
+  void SetQy(Int_t det, Int_t harmonic, Float_t qy) { if(det>=0 && det<kNdetectors && harmonic>0 && harmonic<=fgkNMaxHarmonics) fQvector[det][harmonic-1][1]=qy;}
+  void SetEventPlaneStatus(Int_t det, Int_t harmonic, EventPlaneStatus status) { 
+    if(det>=0 && det<kNdetectors && harmonic>0 && harmonic<=fgkNMaxHarmonics) 
+      fEventPlaneStatus[det][harmonic-1] |= (1<<status);
+  }
+  
+ private:
+  // Q-vectors for the first 10 harmonics from TPC, VZERO, FMD and ZDC detectors
+  Double_t fQvector[kNdetectors][fgkNMaxHarmonics][2];     // Q vector components for all detectors and 6 harmonics
+  UChar_t fEventPlaneStatus[kNdetectors][fgkNMaxHarmonics];  // Bit maps for the event plane status (1 char per detector and per harmonic)
+   
+  void ClearEvent();
+  AliReducedEventFriend(const AliReducedEventFriend &c);
+  AliReducedEventFriend& operator= (const AliReducedEventFriend &c);
+
+  ClassDef(AliReducedEventFriend, 1);
+};
+
+
+//_________________________________________________________________________
+class AliReducedCaloCluster : public TObject {
+  
+  friend class AliAnalysisTaskReducedTree;         // friend analysis task which fills the object
+  
+ public:
+  enum ClusterType {
+    kUndefined=0, kEMCAL, kPHOS  
+  };
+   
+  AliReducedCaloCluster();
+  ~AliReducedCaloCluster();
+  
+  Bool_t  IsEMCAL() const {return (fType==kEMCAL ? kTRUE : kFALSE);}
+  Bool_t  IsPHOS()  const {return (fType==kPHOS ? kTRUE : kFALSE);}
+  Float_t Energy()  const {return fEnergy;}
+  Float_t Dx()      const {return fTrackDx;}
+  Float_t Dz()      const {return fTrackDz;}
+  
+ private:
+  Char_t  fType;         // cluster type (EMCAL/PHOS)
+  Float_t fEnergy;       // cluster energy
+  Float_t fTrackDx;      // distance to closest track in phi
+  Float_t fTrackDz;      // distance to closest track in z
+  
+  AliReducedCaloCluster(const AliReducedCaloCluster &c);
+  AliReducedCaloCluster& operator= (const AliReducedCaloCluster &c);
+
+  ClassDef(AliReducedCaloCluster, 1);
+};
+
+
+//_________________________________________________________________________
+class AliReducedEvent : public TObject {
+
+  friend class AliAnalysisTaskReducedTree;     // friend analysis task which fills the object
+
+ public:
+  AliReducedEvent();
+  AliReducedEvent(const Char_t* name);
+  ~AliReducedEvent();
+
+  // getters
+  Int_t     RunNo()                           const {return fRunNo;}
+  UShort_t  BC()                              const {return fBC;}
+  ULong64_t TriggerMask()                     const {return fTriggerMask;}
+  Bool_t    IsPhysicsSelection()              const {return fIsPhysicsSelection;}
+  Float_t   Vertex(Int_t axis)                const {return (axis>=0 && axis<=2 ? fVtx[axis] : 0);}
+  Int_t     VertexNContributors()             const {return fNVtxContributors;}
+  Float_t   VertexTPC(Int_t axis)             const {return (axis>=0 && axis<=2 ? fVtxTPC[axis] : 0);}
+  Int_t     VertexTPCContributors()           const {return fNVtxTPCContributors;}
+  Float_t   CentralityVZERO()                 const {return fCentrality[0];}
+  Float_t   CentralitySPD()                   const {return fCentrality[1];}
+  Float_t   CentralityTPC()                   const {return fCentrality[2];}
+  Float_t   CentralityZEMvsZDC()              const {return fCentrality[3];}
+  Int_t     CentralityQuality()               const {return fCentQuality;}
+  Int_t     NV0CandidatesTotal()              const {return fNV0candidates[0];}
+  Int_t     NV0Candidates()                   const {return fNV0candidates[1];}
+  Int_t     NDielectrons()                    const {return fNDielectronCandidates;}
+  Int_t     NTracksTotal()                    const {return fNtracks[0];}
+  Int_t     NTracks()                         const {return fNtracks[1];}
+  Int_t     SPDntracklets()                   const {return fSPDntracklets;}
+  
+  Float_t   MultChannelVZERO(Int_t channel)   const {return (channel>=0 && channel<=63 ? fVZEROMult[channel] : -999.);}
+  Float_t   MultVZEROA()                      const;
+  Float_t   MultVZEROC()                      const;
+  Float_t   MultVZERO()                       const;
+  Float_t   MultRingVZEROA(Int_t ring)        const;
+  Float_t   MultRingVZEROC(Int_t ring)        const;
+  
+  Float_t   EnergyZDC(Int_t channel)   const {return (channel>=0 && channel<8 ? fZDCnEnergy[channel] : -999.);}
+  Float_t   EnergyZDCnA(Int_t channel) const {return (channel>=0 && channel<4 ? fZDCnEnergy[channel+4] : -999.);}
+  Float_t   EnergyZDCnC(Int_t channel) const {return (channel>=0 && channel<4 ? fZDCnEnergy[channel] : -999.);}
+  
+  AliReducedTrack* GetTrack(Int_t i)         const 
+    {return (i<fNtracks[1] ? (AliReducedTrack*)fTracks->At(i) : 0x0);}
+  AliReducedPair* GetV0Pair(Int_t i)         const 
+    {return (i>=0 && i<fNV0candidates[1] ? (AliReducedPair*)fCandidates->At(i) : 0x0);}
+  AliReducedPair* GetDielectronPair(Int_t i) const 
+    {return (i>=0 && i<fNDielectronCandidates ? (AliReducedPair*)fCandidates->At(i+fNV0candidates[1]) : 0x0);}
+  TClonesArray* GetPairs()                              const {return fCandidates;}
+  TClonesArray* GetTracks()                             const {return fTracks;}
+
+  Int_t GetNCaloClusters() const {return fNCaloClusters;}
+  AliReducedCaloCluster* GetCaloCluster(Int_t i) const 
+    {return (i>=0 && i<fNCaloClusters ? (AliReducedCaloCluster*)fCaloClusters->At(i) : 0x0);}
+  
+  void  GetQvector(Double_t Qvec[][2], Int_t det, Float_t etaMin=-0.8, Float_t etaMax=+0.8, Bool_t (*IsTrackSelected)(AliReducedTrack*)=NULL);
+  Int_t GetTPCQvector(Double_t Qvec[][2], Int_t det, Float_t etaMin=-0.8, Float_t etaMax=+0.8, Bool_t (*IsTrackSelected)(AliReducedTrack*)=NULL);
+  void  GetVZEROQvector(Double_t Qvec[][2], Int_t det) ;
+  void  GetVZEROQvector(Double_t Qvec[][2], Int_t det, Float_t* vzeroMult);
+  void  GetZDCQvector(Double_t Qvec[][2], Int_t det) const;
+  void  SubtractParticleFromQvector(AliReducedTrack* particle, Double_t Qvec[][2], Int_t det, 
+                                   Float_t etaMin=-0.8, Float_t etaMax=+0.8, Bool_t (*IsTrackSelected)(AliReducedTrack*)=NULL);
+
+ private:
+  Int_t     fRunNo;                 // run number
+  UShort_t  fBC;                    // bunch crossing
+  ULong64_t fTriggerMask;           // trigger mask
+  Bool_t    fIsPhysicsSelection;    // PhysicsSelection passed event
+  Float_t   fVtx[3];                // global event vertex vector in cm
+  Int_t     fNVtxContributors;      // global event vertex contributors
+  Float_t   fVtxTPC[3];             // TPC only event vertex           
+  Int_t     fNVtxTPCContributors;   // TPC only event vertex contributors
+  Float_t   fCentrality[4];         // centrality; 0-VZERO, 1-SPD, 2-TPC, 3-ZEMvsZDC 
+  Int_t     fCentQuality;           // quality flag for the centrality 
+  Int_t     fNV0candidates[2];      // number of V0 candidates, [0]-total, [1]-selected for the tree
+  Int_t     fNDielectronCandidates; // number of pairs selected as dielectrons
+  Int_t     fNtracks[2];            // number of tracks, [0]-total, [1]-selected for the tree
+  Int_t     fSPDntracklets;         // number of SPD tracklets in |eta|<1.0 
+
+  Float_t   fVZEROMult[64];         // VZERO multiplicity in all 64 channels
+  Float_t   fZDCnEnergy[8];         // neutron ZDC energy in all 8 channels
+    
+  TClonesArray* fTracks;            //->   array containing global tracks
+  static TClonesArray* fgTracks;    //       global tracks
+  
+  TClonesArray* fCandidates;        //->   array containing pair candidates
+  static TClonesArray* fgCandidates;  // pair candidates
+  
+  Int_t     fNCaloClusters;         // number of calorimeter clusters  
+  TClonesArray* fCaloClusters;        //->   array containing calorimeter clusters
+  static TClonesArray* fgCaloClusters;     // calorimeter clusters
+  
+  void ClearEvent();
+  AliReducedEvent(const AliReducedEvent &c);
+  AliReducedEvent& operator= (const AliReducedEvent &c);
+
+  ClassDef(AliReducedEvent, 2);
+};
+
+//_______________________________________________________________________________
+inline UShort_t AliReducedTrack::ITSncls() const
+{
+  //
+  // ITS number of clusters from the cluster map
+  //
+  UShort_t ncls=0;
+  for(Int_t i=0; i<6; ++i) ncls += (ITSLayerHit(i) ? 1 : 0);
+  return ncls;
+}
+
+
+//_______________________________________________________________________________
+inline Int_t AliReducedTrack::TPCClusterMapBitsFired()  const
+{
+  //
+  // Count the number of bits fired in the TPC cluster map
+  //
+  Int_t nbits=0;
+  for(Int_t i=0; i<8; ++i) nbits += (TPCClusterMapBitFired(i) ? 1 : 0);
+  return nbits;
+}
+
+
+//_______________________________________________________________________________
+inline Float_t AliReducedPair::Energy() const 
+{
+  //
+  // Return the energy
+  //
+  Float_t mass=fMass[0];
+  switch (fCandidateId) {
+    case kK0sToPiPi:
+      mass = fMass[0];
+      break;
+    case kLambda0ToPPi:
+      mass = fMass[1];
+      break;
+    case kALambda0ToPPi:
+      mass = fMass[2];
+      break;
+    default:
+      mass = fMass[0];
+      break;    
+  }
+  Float_t p = P();
+  return TMath::Sqrt(mass*mass+p*p);
+}
+
+
+//_______________________________________________________________________________
+inline Float_t AliReducedPair::Rapidity() const
+{
+  //
+  // return rapidity
+  //
+  Float_t e = Energy();
+  Float_t pz = Pz();
+  if(e-TMath::Abs(pz)>1.0e-10)
+    return 0.5*TMath::Log((e+pz)/(e-pz));
+  else 
+    return -999.;
+}
+
+
+//_______________________________________________________________________________
+inline Double_t AliReducedEventFriend::EventPlane(Int_t det, Int_t harmonic) const
+{
+  //
+  // Event plane from detector "det" and harmonic "harmonic"
+  //
+  if(det<0 || det>=kNdetectors || harmonic<1 || harmonic>fgkNMaxHarmonics) return -999.;
+  return TMath::ATan2(fQvector[det][harmonic-1][1], fQvector[det][harmonic-1][0])/Double_t(harmonic);
+}
+
+//_______________________________________________________________________________
+inline Bool_t AliReducedEventFriend::CheckEventPlaneStatus(Int_t det, Int_t h, EventPlaneStatus flag) const {
+  //
+  // Check the status of the event plane for a given detector and harmonic
+  //
+  if(det<0 || det>=kNdetectors || h<1 || h>fgkNMaxHarmonics) return kFALSE;
+  return (flag<kNMaxFlowFlags ? (fEventPlaneStatus[det][h]&(1<<flag)) : kFALSE);
+}
+
+#endif
diff --git a/PWGDQ/dielectron/macrosJPSI/AddTask_ReducedTree.C b/PWGDQ/dielectron/macrosJPSI/AddTask_ReducedTree.C
new file mode 100644 (file)
index 0000000..12729c8
--- /dev/null
@@ -0,0 +1,1012 @@
+//__________________________________________________________________________________________
+AliAnalysisTask *AddTask_ReducedTree(){
+  //get the current analysis manager
+  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+  if (!mgr) {
+    Error("AddTask_iarsene_dst", "No analysis manager found.");
+    return 0;
+  }
+
+  //Do we have an MC handler?
+  Bool_t hasMC=(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler()!=0x0);
+  
+  //gROOT->LoadMacro("AliReducedEvent.cxx+g");
+  //gROOT->LoadMacro("AliAnalysisTaskReducedTree.cxx+g");
+  
+  //create task and add it to the manager
+  AliAnalysisTaskReducedTree *task=new AliAnalysisTaskReducedTree("DSTTreeMaker");
+  task->SetTriggerMask(AliVEvent::kMB+AliVEvent::kCentral+AliVEvent::kSemiCentral);
+  //if(trainConfig=="pp") task->SetRejectPileup();
+  if(!hasMC) task->UsePhysicsSelection(kFALSE);
+  mgr->AddTask(task);
+  
+  task->SetFillV0Info(kFALSE);
+  task->SetFillCaloClusterInfo(kFALSE);
+  //task->SetFillFriendInfo(kFALSE);
+  
+  task->SetEventFilter(CreateEventFilter());
+  task->SetTrackFilter(CreateGlobalTrackFilter());
+  task->SetFlowTrackFilter(CreateFlowTrackFilter());
+  task->SetK0sPionCuts(CreateK0sPionCuts());
+  task->SetLambdaProtonCuts(CreateLambdaProtonCuts());
+  task->SetLambdaPionCuts(CreateLambdaPionCuts());
+  task->SetK0sCuts(CreateK0sCuts());
+  task->SetK0sMassRange(0.44,0.55);
+  task->SetLambdaMassRange(1.090,1.14);
+  task->SetLambdaCuts(CreateLambdaCuts());
+  //task->SetV0Histograms(CreateV0Histograms());
+  
+  task->AddDielectron(ConfigDielectron(0));   // J/psi -> e+e-
+  //task->AddDielectron(ConfigDielectron(1));   // phi -> K+K-
+  
+  //create output container
+  AliAnalysisDataContainer *coutput1 =
+    mgr->CreateContainer("diele_defaultTree",
+                         TChain::Class(),
+                         AliAnalysisManager::kExchangeContainer,
+                         "diele_default");
+  
+  AliAnalysisDataContainer *cOutputHist1 =
+    mgr->CreateContainer("qaHistos",
+                         TList::Class(),
+                         AliAnalysisManager::kOutputContainer,
+                         "dst_qaHistos.root");
+
+  AliAnalysisDataContainer *cOutputHist2 =
+    mgr->CreateContainer("dstTree",
+                         TTree::Class(),
+                         AliAnalysisManager::kOutputContainer,
+                         "dstTree.root");
+  
+  AliAnalysisDataContainer *cOutputHist3 =
+    mgr->CreateContainer("friendTree",
+                         TTree::Class(),
+                         AliAnalysisManager::kOutputContainer,
+                         "dstTree_friend.root");
+  /*  cout << "output containers: " << endl
+       << cOutputHist1 << endl
+       << cOutputHist2 << endl
+       << cOutputHist3 << endl;*/
+
+  mgr->ConnectInput(task,  0, mgr->GetCommonInputContainer());
+  mgr->ConnectOutput(task, 0, coutput1 );
+  mgr->ConnectOutput(task, 1, cOutputHist1);
+  mgr->ConnectOutput(task, 2, cOutputHist2);
+  mgr->ConnectOutput(task, 3, cOutputHist3);
+  //mgr->ConnectOutput(task, 2, cOutputHist3);
+  
+  return task;
+}
+
+
+//_______________________________________________________________________________________________
+AliAnalysisCuts* CreateEventFilter() {
+  //
+  // Event wise cuts
+  //
+  AliDielectronEventCuts *eventCuts=new AliDielectronEventCuts("eventCuts","Vertex Track && |vtxZ|<10 && ncontrib>0");
+  eventCuts->SetRequireVertex();
+  eventCuts->SetMinVtxContributors(1);
+  eventCuts->SetVertexZ(-10.,10.);
+  return eventCuts;
+}
+
+
+//_______________________________________________________________________________________________
+AliAnalysisCuts* CreateGlobalTrackFilter() {
+  //
+  // Cuts for tracks to be written in the dst
+  //
+  AliDielectronCutGroup* cuts = new AliDielectronCutGroup("cuts","cuts",AliDielectronCutGroup::kCompAND);
+  // general ESD cuts ---------------------------------
+  AliESDtrackCuts *esdTrackCuts = new AliESDtrackCuts;
+  // basic track quality cuts  (basicQ)
+  esdTrackCuts->SetMaxDCAToVertexZ(10.0);
+  esdTrackCuts->SetMaxDCAToVertexXY(3.0);
+  esdTrackCuts->SetEtaRange( -0.9 , 0.9 );
+  //esdTrackCuts->SetAcceptKinkDaughters(kFALSE);
+  //esdTrackCuts->SetRequireITSRefit(kTRUE);
+  esdTrackCuts->SetRequireTPCRefit(kTRUE);
+  esdTrackCuts->SetPRange(0.8,1e30);
+  //esdTrackCuts->SetMinNClustersTPC(60);
+  //esdTrackCuts->SetMaxChi2PerClusterTPC(4);
+  //  esdTrackCuts->SetClusterRequirementITS(AliESDtrackCuts::kSPD,AliESDtrackCuts::kAny);
+  //  esdTrackCuts->SetClusterRequirementITS(AliESDtrackCuts::kSPD,AliESDtrackCuts::kFirst);
+  cuts->AddCut(esdTrackCuts);
+  
+  return cuts;
+}
+
+
+//_______________________________________________________________________________________________
+AliAnalysisCuts* CreateFlowTrackFilter() {
+  //
+  // Cuts for tracks to be used for the event plane q-vector
+  // These cuts are applied aditionally to the global track cuts
+  //
+  AliESDtrackCuts *esdTrackCuts = new AliESDtrackCuts;
+  esdTrackCuts->SetPtRange(0.2,2.0);
+  esdTrackCuts->SetEtaRange(-0.8, 0.8);
+  esdTrackCuts->SetMinNClustersTPC(70);
+  return esdTrackCuts;
+}
+
+
+//_______________________________________________________________________________________________
+AliAnalysisCuts* CreateK0sPionCuts() {
+  //
+  // Cuts on the K0s pions (tracking cuts, pid cuts, ...) 
+  //
+  AliESDtrackCuts *pionCuts = new AliESDtrackCuts;
+  pionCuts->SetPtRange(0.15,100.0);
+  return pionCuts;
+}
+
+
+//_______________________________________________________________________________________________
+AliAnalysisCuts* CreateLambdaPionCuts() {
+  //
+  // Cuts on the Lambda pions (tracking cuts, pid cuts, ...) 
+  //
+  AliESDtrackCuts *pionCuts = new AliESDtrackCuts;
+  pionCuts->SetPtRange(0.15,100.0);
+  return pionCuts;
+}
+
+
+//_______________________________________________________________________________________________
+AliAnalysisCuts* CreateLambdaProtonCuts() {
+  //
+  // Cuts on the Lambda protons (tracking cuts, pid cuts, ...) 
+  //
+  AliESDtrackCuts *protonCuts = new AliESDtrackCuts;
+  protonCuts->SetPtRange(0.15,100.0);
+  return protonCuts;
+}
+
+
+//______________________________________________________________________________________
+AliESDv0Cuts* CreateK0sCuts() {
+  //
+  // Cuts on the V0s with K0s hypothesis
+  //
+  
+  AliESDv0Cuts *cuts=new AliESDv0Cuts();
+  //cuts->SetMinDcaPosToVertex(-1);
+  //cuts->SetMinDcaNegToVertex(-1);
+  //cuts->SetMaxChi2(10);
+  //cuts->SetMaxDcaV0Daughters(0.3);
+  //cuts->SetMinRadius(3.0);
+  //cuts->SetMaxRadius(90.0);
+  //cuts->SetMinCosinePointingAngle(0.9);
+  //cuts->SetRequireOnFlyStatus(kTRUE);
+  //cuts->SetMaxDcaV0ToVertex(0.5);
+  //cuts->SetPRange(0.,1.0e10);
+  //cuts->SetPtRange(0.,1.0e10);
+  return cuts;
+}
+
+
+//______________________________________________________________________________________
+AliESDv0Cuts* CreateLambdaCuts() {
+  //
+  // Cuts on the V0s with Lambda hypothesis
+  //
+  
+  AliESDv0Cuts *cuts=new AliESDv0Cuts();
+  //cuts->SetMinDcaPosToVertex(-1);
+  //cuts->SetMinDcaNegToVertex(-1);
+  //cuts->SetMaxChi2(10);
+  //cuts->SetMaxDcaV0Daughters(0.3);
+  //cuts->SetMinRadius(3.0);
+  //cuts->SetMaxRadius(90.0);
+  //cuts->SetMinCosinePointingAngle(0.9);
+  //cuts->SetRequireOnFlyStatus(kTRUE);
+  //cuts->SetMaxDcaV0ToVertex(0.5);
+  //cuts->SetPRange(0.,1.0e10);
+  //cuts->SetPtRange(0.,1.0e10);
+  return cuts;
+}
+
+
+//______________________________________________________________________________________
+AliDielectronHistos* CreateV0Histograms()
+{
+  //
+  // Initialise the histograms
+  //
+  
+  //Setup histogram Manager
+  AliDielectronHistos *histos=new AliDielectronHistos("V0Histograms","");
+        
+  //add histograms to Track classes ---------------------------------------------------------------------------
+  histos->SetReservedWords("V0Track");
+  
+  //Track classes
+  histos->AddClass("V0Track_Pos"); histos->AddClass("V0Track_Neg"); 
+  
+  // kinematic acceptance histograms
+  histos->UserHistogram("V0Track","Pt","Pt;Pt (GeV/c);#tracks",400,0,20.,AliDielectronVarManager::kPt);
+  histos->UserHistogram("V0Track","Eta_P","Eta_P;#eta;P (GeV/c)",40, -1.0, +1.0, 200,0,10., AliDielectronVarManager::kEta, AliDielectronVarManager::kP);
+  histos->UserHistogram("V0Track","Eta_TRDPhi","Eta Phi Map; Eta; Phi;#tracks",
+                        40,-1,1,200,-3.15,3.15,AliDielectronVarManager::kEta,AliDielectronVarManager::kTRDphi);  
+
+  // DCA diagnostic histograms
+  histos->UserHistogram("V0Track","dXY","dXY;dXY (cm);#tracks",500,-1.,1.,AliDielectronVarManager::kImpactParXY);
+  histos->UserHistogram("V0Track","dZ","dZ;dZ (cm);#tracks",600,-3.,3.,AliDielectronVarManager::kImpactParZ);
+  histos->UserHistogram("V0Track","dZ_dXY","dZ_dXY;dZ (cm);dXY (cm)",600,-3.,3.,500,-1.,1.,AliDielectronVarManager::kImpactParZ, AliDielectronVarManager::kImpactParXY);
+  histos->UserHistogram("V0Track","P_dXY","P_dXY;P (GeV/c);dXY (cm)",200,0.,10.,500,-1.,1.,AliDielectronVarManager::kP, AliDielectronVarManager::kImpactParXY);
+  histos->UserHistogram("V0Track","P_dZ","P_dZ;P (GeV/c);dZ (cm)",200,0.,10.,600,-3.,3.,AliDielectronVarManager::kP, AliDielectronVarManager::kImpactParZ);
+
+  // ITS
+  histos->UserHistogram("V0Track","ITSsignal","ITS signal;ITS dE/dx",1000,0.0,1000.0, AliDielectronVarManager::kITSsignal);  
+  histos->UserHistogram("V0Track","ITSsignal_P","ITS signal vs P;P (GeV/c); ITS dE/dx",300, 0.0, 3.0, 200,0.0,1000.0, AliDielectronVarManager::kP, AliDielectronVarManager::kITSsignal);
+  
+  // TPC
+  histos->UserHistogram("V0Track","TPCchi2","#chi^{2}/cluster;#chi^{2}/cluster;#tracks",200,0.0,5.0, AliDielectronVarManager::kTPCchi2Cl);
+  histos->UserHistogram("V0Track","Pt_TPCchi2","#chi^{2}/cluster vs pt;p_{T} (GeV/c);#chi^{2}/cluster",400,0.,20., 200,0.0,5.0,
+                       AliDielectronVarManager::kPt,AliDielectronVarManager::kTPCchi2Cl);
+  histos->UserHistogram("V0Track","TPCnCls","Number of Clusters TPC;TPC number clusters;#tracks",160,-0.5,159.5, AliDielectronVarManager::kNclsTPC);
+  histos->UserHistogram("V0Track","Phi_TPCnCls","Number of Clusters TPC vs #phi;#phi (rad.);TPC number clusters",200,0,6.285, 160,-0.5,159.5,
+                       AliDielectronVarManager::kPhi,AliDielectronVarManager::kNclsTPC);
+  histos->UserHistogram("V0Track","Pin_TPCnCls","Number of Clusters TPC vs TPC inner param P;p (GeV/c);TPC number clusters",400,0,20., 160,-0.5,159.5,
+                       AliDielectronVarManager::kPIn, AliDielectronVarManager::kNclsTPC);
+  histos->UserHistogram("V0Track","TPCnCls_dEdx","Number of Clusters TPC vs dE/dx; TPC number clusters; dE/dx (arb.units)", 160,-0.5,159.5, 200,0,200.,
+                       AliDielectronVarManager::kNclsTPC, AliDielectronVarManager::kTPCsignal);
+  histos->UserHistogram("V0Track","dEdx_P","dEdx;P [GeV];TPC signal (arb units);#tracks",
+                        400,0.2,20.,200,0.,200.,AliDielectronVarManager::kPIn,AliDielectronVarManager::kTPCsignal);
+  histos->UserHistogram("V0Track","dEdx_Eta","dEdx;#eta;TPC signal (arb units);#tracks",
+                        110,-1.1,1.1,200,0.,200.,AliDielectronVarManager::kEta,AliDielectronVarManager::kTPCsignal);
+  histos->UserHistogram("V0Track","TPCnSigmaEle_P","TPC number of sigmas Electrons;P [GeV];TPC number of sigmas Electrons;#tracks",
+                        400,0.2,20.,200,-5.,5.,AliDielectronVarManager::kPIn,AliDielectronVarManager::kTPCnSigmaEle);
+  histos->UserHistogram("V0Track","TPCnSigmaEle_Eta","TPC number of sigmas Electrons;#eta;TPC number of sigmas Electrons;#tracks",
+                        110,-1.1,1.1,200,-5.,5.,AliDielectronVarManager::kEta,AliDielectronVarManager::kTPCnSigmaEle);  
+  histos->UserHistogram("V0Track","TPCnSigmaPio_P","TPC number of sigmas Pions;P [GeV];TPC number of sigmas Pions;#tracks",
+                       400,0.2,20.,200,-5.,5.,AliDielectronVarManager::kPIn,AliDielectronVarManager::kTPCnSigmaPio);
+  histos->UserHistogram("V0Track","TPCnSigmaPio_Eta","TPC number of sigmas Pions;#eta;TPC number of sigmas Pions;#tracks",
+                        110,-1.1,1.1,200,-5.,5.,AliDielectronVarManager::kEta,AliDielectronVarManager::kTPCnSigmaPio);  
+  histos->UserHistogram("V0Track","TPCnSigmaKao_P","TPC number of sigmas Kaons;P [GeV];TPC number of sigmas Kaons;#tracks",
+                       400,0.2,20.,200,-5.,5.,AliDielectronVarManager::kPIn,AliDielectronVarManager::kTPCnSigmaKao);
+  histos->UserHistogram("V0Track","TPCnSigmaKao_Eta","TPC number of sigmas Kaons;#eta;TPC number of sigmas Kaons;#tracks",
+                        110,-1.1,1.1,200,-5.,5.,AliDielectronVarManager::kEta,AliDielectronVarManager::kTPCnSigmaKao);  
+  histos->UserHistogram("V0Track","TPCnSigmaPro_P","TPC number of sigmas Protons;P [GeV];TPC number of sigmas Protons;#tracks",
+                       400,0.2,20.,200,-5.,5.,AliDielectronVarManager::kPIn,AliDielectronVarManager::kTPCnSigmaPro);
+  histos->UserHistogram("V0Track","TPCnSigmaPro_Eta","TPC number of sigmas Protons;#eta;TPC number of sigmas Protons;#tracks",
+                        110,-1.1,1.1,200,-5.,5.,AliDielectronVarManager::kEta,AliDielectronVarManager::kTPCnSigmaPro);  
+  histos->UserHistogram("V0Track","POut","Track POut;P (GeV/c)",100,0.0,10.0, AliDielectronVarManager::kPOut);
+
+  // TOF
+  histos->UserHistogram("V0Track","Pin_TOFsignal","TOF signal vs TPC inner param P; P [GeV]; TOF signal",
+                       120,0.0,6.,1200,0.,120000.,AliDielectronVarManager::kPIn,AliDielectronVarManager::kTOFsignal);
+  histos->UserHistogram("V0Track","Pin_TOFbeta","TOF #beta vs TPC inner param P; P [GeV]; TOF #beta",
+                       120,0.0,6.,120,0.,1.2,AliDielectronVarManager::kPIn,AliDielectronVarManager::kTOFbeta);
+  histos->UserHistogram("V0Track","TOFnSigmaPio_Pin","TOF number of sigmas Pions;P [GeV];TOF number of sigmas Pions;#tracks",
+                       400,0.2,20.,200,-10.,10.,AliDielectronVarManager::kPIn,AliDielectronVarManager::kTOFnSigmaPio);
+  histos->UserHistogram("V0Track","TOFnSigmaPio_eta","TOF number of sigmas Pions vs #eta;#eta;TOF number of sigmas Pions;#tracks",
+                       100,-1.2,1.2,200,-10.,10.,AliDielectronVarManager::kEta,AliDielectronVarManager::kTOFnSigmaPio);
+  histos->UserHistogram("V0Track","TOFnSigmaKao_Pin","TOF number of sigmas Kaons;P [GeV];TOF number of sigmas Kaons;#tracks",
+                       400,0.2,20.,200,-10.,10.,AliDielectronVarManager::kPIn,AliDielectronVarManager::kTOFnSigmaKao);
+  histos->UserHistogram("V0Track","TOFnSigmaKao_eta","TOF number of sigmas Kaons vs #eta;#eta;TOF number of sigmas Kaons;#tracks",
+                       100,-1.2,1.2,200,-10.,10.,AliDielectronVarManager::kEta,AliDielectronVarManager::kTOFnSigmaKao);
+  histos->UserHistogram("V0Track","TOFnSigmaPro_Pin","TOF number of sigmas Protons;P [GeV];TOF number of sigmas Protons;#tracks",
+                       400,0.2,20.,200,-10.,10.,AliDielectronVarManager::kPIn,AliDielectronVarManager::kTOFnSigmaPro);
+  histos->UserHistogram("V0Track","TOFnSigmaPro_eta","TOF number of sigmas Protons vs #eta;#eta;TOF number of sigmas Protons;#tracks",
+                       100,-1.2,1.2,200,-10.,10.,AliDielectronVarManager::kEta,AliDielectronVarManager::kTOFnSigmaPro);
+  return histos;
+}
+
+
+//____________________________________________________________________________________________
+AliDielectron* ConfigDielectron(Int_t cutDefinition)
+{
+  //
+  // Setup the instance of an AliDielectron
+  //
+  const Char_t* dieleNames[2] = {"JpsiToEE", "PhiToKK"};
+      
+  AliDielectron *die =
+    new AliDielectron(dieleNames[cutDefinition],
+                      Form("Track cuts: %s", dieleNames));
+  die->SetDontClearArrays(kTRUE);
+  //die->SetEstimatorFilename("$TRAIN_ROOT/util/dielectron/dielectron/estimators.root");
+  if(cutDefinition==0) {       // J/psi -> e+e-
+    die->SetLegPdg(11,11);
+    die->SetMotherPdg(443);
+  }
+  if(cutDefinition==1) {       // phi -> K+K-
+    die->SetLegPdg(321,321);
+    die->SetMotherPdg(333);
+  }
+  
+  // cut setup
+  SetupDielectronTrackCuts(die,cutDefinition);
+  SetupDielectronPairCuts(die,cutDefinition);
+
+  // Set MC signals
+  //SetDielectronMCSignals(die);
+  
+  //
+  // histogram setup
+  // only if an AliDielectronHistos object is attached to the
+  // dielectron framework histograms will be filled
+  //
+  InitDielectronHistograms(die,cutDefinition);
+  //setup eta correction
+  //SetEtaCorrection();
+
+  return die;
+}
+
+//______________________________________________________________________________________
+void SetupDielectronTrackCuts(AliDielectron *die, Int_t cutDefinition)
+{
+  //
+  // Setup the track cuts
+  //
+
+  AliDielectronCutGroup* cuts = new AliDielectronCutGroup("cuts","cuts",AliDielectronCutGroup::kCompAND);
+  die->GetTrackFilter().AddCuts(cuts);
+  //ESD quality cuts  
+  AliESDtrackCuts *esdTrackCuts = new AliESDtrackCuts;
+  // basic track quality cuts  (basicQ)
+  esdTrackCuts->SetMaxDCAToVertexZ(3.0);
+  esdTrackCuts->SetMaxDCAToVertexXY(1.0);
+  if(cutDefinition==1) {
+    esdTrackCuts->SetMaxDCAToVertexZ(0.3);
+    esdTrackCuts->SetMaxDCAToVertexXY(0.3);
+  }
+  if(cutDefinition==1) esdTrackCuts->SetEtaRange(-1.0,1.0);
+  if(cutDefinition==0) esdTrackCuts->SetEtaRange(-0.9,0.9);
+  esdTrackCuts->SetAcceptKinkDaughters(kFALSE);
+  //esdTrackCuts->SetRequireITSRefit(kTRUE);
+  if(cutDefinition==0) esdTrackCuts->SetRequireTPCRefit(kTRUE);
+  if(cutDefinition==0) esdTrackCuts->SetPRange(.9,1e30);   // for J/psi
+  if(cutDefinition==1) esdTrackCuts->SetPRange(.1,1e30);   // for phi
+  //if(cutDefinition==0) esdTrackCuts->SetMinNClustersTPC(60);
+  //if(cutDefinition==0) esdTrackCuts->SetMaxChi2PerClusterTPC(4);
+  //esdTrackCuts->SetClusterRequirementITS(AliESDtrackCuts::kSPD,AliESDtrackCuts::kAny);
+  cuts->AddCut(esdTrackCuts);
+    
+  Bool_t hasMC=(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler()!=0x0);
+
+  AliDielectronPID *pid = new AliDielectronPID("PID","PID cut");
+  if(cutDefinition==0) {   // J/psi->ee, phi->ee
+    pid->AddCut(AliDielectronPID::kTPC,AliPID::kElectron,-4.5, 4.5, 0.0, 0.0,  kFALSE, AliDielectronPID::kRequire); // TPC 3-sigma inclusion for electron
+    pid->AddCut(AliDielectronPID::kTPC,AliPID::kProton,  -100.0, 2.0, 0.0, 10.0, kTRUE,  AliDielectronPID::kRequire); // TPC 3.0-sigma exclusion for proton
+//    pid->AddCut(AliDielectronPID::kTPC,AliPID::kKaon,    -3.0, 3.0, 0.0, 10.0, kTRUE,  AliDielectronPID::kRequire); // TPC 3.0-sigma exclusion for kaon
+//    pid->AddCut(AliDielectronPID::kTPC,AliPID::kPion,    -3.0, 3.0, 0.0, 10.0, kTRUE,  AliDielectronPID::kRequire); // TPC 3.0-sigma exclusion for pion
+  }
+  if(cutDefinition==1) {     // phi -> KK
+    pid->AddCut(AliDielectronPID::kTOF,AliPID::kKaon,   -3.5, 3.5, 0.6, 100.0, kFALSE, AliDielectronPID::kRequire, AliDielectronVarManager::kPIn);  // TOF 3-sigma inclusion for kaon
+    pid->AddCut(AliDielectronPID::kTPC,AliPID::kKaon,   -3.0, 3.5, 0.3, 100.0, kFALSE, AliDielectronPID::kRequire, AliDielectronVarManager::kPIn);  // TPC 3-sigma inclusion for kaon
+    /*    pid->AddCut(AliDielectronPID::kTPC,AliPID::kProton, -2.0, 2.0, 0.0, 0.0, kTRUE,  AliDielectronPID::kRequire);  // TPC 2.0-sigma exclusion for  proton
+    pid->AddCut(AliDielectronPID::kTPC,AliPID::kPion,   -2.0, 2.0, 0.0, 0.0, kTRUE,  AliDielectronPID::kRequire);  // TPC 2.0-sigma exclusion for  pion
+    pid->AddCut(AliDielectronPID::kTOF,AliPID::kProton, -2.0, 2.0, 0.6, 3.0, kTRUE,  AliDielectronPID::kIfAvailable);  // TOF 2.0-sigma exclusion for  proton
+    pid->AddCut(AliDielectronPID::kTOF,AliPID::kPion,   -2.0, 2.0, 0.6, 3.0, kTRUE,  AliDielectronPID::kIfAvailable);  // TOF 2.0-sigma exclusion for  pion
+*/
+  }
+    
+  // ++++++++++++++++++++++++++++++++++++++++
+  // shifts for the nSigma electrons
+  TGraph* nSigmaCorrection = new TGraph();
+  // b period (LHC10f7a)
+  nSigmaCorrection->SetPoint(0, 114000., -0.23-(0.0));
+  nSigmaCorrection->SetPoint(1, 117222., -0.23-(0.0));
+  // c period (LHC10f7a)
+  nSigmaCorrection->SetPoint(2, 119000., -0.23-(0.0));
+  nSigmaCorrection->SetPoint(3, 120829., -0.23-(0.0));
+  // d period (LHC10f7a)
+  nSigmaCorrection->SetPoint(4, 121000., -0.353-(-0.111));
+  nSigmaCorrection->SetPoint(5, 127000., -0.353-(-0.111));
+  // e period (LHC10f7a)
+  nSigmaCorrection->SetPoint(6, 127500., -0.351-(-0.116));
+  nSigmaCorrection->SetPoint(7, 130900., -0.351-(-0.116));
+  // LHC11a period (LHC11b10b)
+  nSigmaCorrection->SetPoint(8, 146680., -0.70-(+0.381));   //
+  nSigmaCorrection->SetPoint(9, 146870., -0.70-(+0.381));   //
+  if(hasMC)
+    pid->SetCorrGraph(nSigmaCorrection);
+  
+  cuts->AddCut(pid);
+}
+
+//______________________________________________________________________________________
+void SetupDielectronPairCuts(AliDielectron *die, Int_t cutDefinition)
+{
+  //
+  // Setup the pair cuts
+  //
+  
+  //Invariant mass selection
+  AliDielectronVarCuts *cuts=new AliDielectronVarCuts("|y|<0.9","|Y|<.9");
+  if(cutDefinition==0) cuts->AddCut(AliDielectronVarManager::kY,-0.9,0.9);
+  if(cutDefinition==1) cuts->AddCut(AliDielectronVarManager::kY,-1.0,1.0);
+  if(cutDefinition==1) cuts->AddCut(AliDielectronVarManager::kM, 0.95,1.1);
+  die->GetPairFilter().AddCuts(cuts);
+
+  // Configure prefilter to remove conversions
+  AliDielectronVarCuts *gammaCut=new AliDielectronVarCuts("gammaCut","gammaCut");
+  gammaCut->AddCut(AliDielectronVarManager::kM,0.,.05);
+  if(cutDefinition==0) {
+    die->GetPairPreFilter().AddCuts(gammaCut);
+    die->SetPreFilterUnlikeOnly();
+  }  
+}
+
+//______________________________________________________________________________________
+void InitDielectronHistograms(AliDielectron *die, Int_t cutDefinition)
+{
+  //
+  // Initialise the histograms
+  //
+  
+  //Setup histogram Manager
+  AliDielectronHistos *histos=new AliDielectronHistos(die->GetName(),die->GetTitle());
+  
+  //Initialise histogram classes
+  histos->SetReservedWords("Track;Pair");
+  
+  //Track classes
+  //to fill also track info from 2nd event loop until 2
+  for (Int_t i=0; i<2; ++i){
+    histos->AddClass(Form("Track_%s",AliDielectron::TrackClassName(i)));
+  }
+  
+  //Pair classes
+  // to fill also mixed event histograms loop until 10
+  for (Int_t i=0; i<3; ++i){
+    histos->AddClass(Form("Pair_%s",AliDielectron::PairClassName(i)));
+  }
+  
+  //legs from pair
+  for (Int_t i=0; i<3; ++i){
+    histos->AddClass(Form("Track_Legs_%s",AliDielectron::PairClassName(i)));
+  }
+    
+  //add histograms to event class
+  if (cutDefinition==0) {
+    histos->AddClass("Event");
+    histos->UserHistogram("Event","VtxZ","Vertex Z;Z[cm]",500,-25.,25.,AliDielectronVarManager::kZvPrim);
+    histos->UserHistogram("Event","NTrk","NTrk",500,-0.5,499.5,AliDielectronVarManager::kNTrk);
+    histos->UserHistogram("Event","VtxZ_NaccTrcklts","VtxZ_NaccTrcklts;VtxZ;NaccTrcklts", 
+                         240,-12.,12.,200,-0.5,199.5,AliDielectronVarManager::kZvPrim, AliDielectronVarManager::kNaccTrcklts);
+    histos->UserHistogram("Event","MultV0A","VZERO mult",2000,0.,2000.,AliDielectronVarManager::kMultV0A);
+    histos->UserHistogram("Event","MultV0C","VZERO mult",2000,0.,2000.,AliDielectronVarManager::kMultV0C);
+    histos->UserHistogram("Event","MultV0","VZERO mult",2000,0.,2000.,AliDielectronVarManager::kMultV0);
+    histos->UserHistogram("Event","AdcV0A","VZERO adc",10000,0.,100000.,AliDielectronVarManager::kAdcV0A);
+    histos->UserHistogram("Event","AdcV0C","VZERO adc",10000,0.,100000.,AliDielectronVarManager::kAdcV0C);
+    histos->UserHistogram("Event","AdcV0","VZERO adc",10000,0.,100000.,AliDielectronVarManager::kAdcV0);
+    histos->UserHistogram("Event","MultV0A_MultV0C","MultV0A_MultV0C;MultV0A;MultV0C", 
+                         2000,0.0,2000.,2000,0.0,2000,AliDielectronVarManager::kMultV0A, AliDielectronVarManager::kMultV0C);
+    histos->UserHistogram("Event","AdcV0A_AdcV0C","AdcV0A_AdcV0C;AdcV0A;AdcV0C", 
+                         1000,0.0,20000.,1000,0.0,20000,AliDielectronVarManager::kAdcV0A, AliDielectronVarManager::kAdcV0C);
+    histos->UserHistogram("Event","MultV0A_AdcV0A","MultV0A_AdcV0A;MultV0A;AdcV0A", 
+                         2000,0.0,2000.,2000,0.0,20000,AliDielectronVarManager::kMultV0A, AliDielectronVarManager::kAdcV0A);
+    histos->UserHistogram("Event","MultV0C_AdcV0C","MultV0C_AdcV0C;MultV0C;AdcV0C", 
+                         2000,0.0,2000.,2000,0.0,20000,AliDielectronVarManager::kMultV0C, AliDielectronVarManager::kAdcV0C);
+  }
+    
+  //add histograms to Track classes ---------------------------------------------------------------------------
+  // kinematic acceptance histograms
+  histos->UserHistogram("Track","Pt","Pt;Pt (GeV/c);#tracks",400,0,20.,AliDielectronVarManager::kPt);
+  histos->UserHistogram("Track","Eta_P","Eta_P;#eta;P (GeV/c)",40, -1.0, +1.0, 200,0,10., AliDielectronVarManager::kEta, AliDielectronVarManager::kP);
+  histos->UserHistogram("Track","Eta_Phi","Eta Phi Map; Eta; Phi;#tracks",
+                        40,-1,1,200,0,6.285,AliDielectronVarManager::kEta,AliDielectronVarManager::kPhi);  
+
+  // DCA diagnostic histograms
+  histos->UserHistogram("Track","dXY","dXY;dXY (cm);#tracks",500,-1.,1.,AliDielectronVarManager::kImpactParXY);
+  histos->UserHistogram("Track","dZ","dZ;dZ (cm);#tracks",600,-3.,3.,AliDielectronVarManager::kImpactParZ);
+  histos->UserHistogram("Track","dZ_dXY","dZ_dXY;dZ (cm);dXY (cm)",600,-3.,3.,500,-1.,1.,AliDielectronVarManager::kImpactParZ, AliDielectronVarManager::kImpactParXY);
+  histos->UserHistogram("Track","P_dXY","P_dXY;P (GeV/c);dXY (cm)",200,0.,10.,500,-1.,1.,AliDielectronVarManager::kP, AliDielectronVarManager::kImpactParXY);
+  histos->UserHistogram("Track","P_dZ","P_dZ;P (GeV/c);dZ (cm)",200,0.,10.,600,-3.,3.,AliDielectronVarManager::kP, AliDielectronVarManager::kImpactParZ);
+
+    // ITS
+  histos->UserHistogram("Track","ITSsignal","ITS signal;ITS dE/dx",1000,0.0,1000.0, AliDielectronVarManager::kITSsignal);  
+  histos->UserHistogram("Track","ITSsignal_P","ITS signal vs P;P (GeV/c); ITS dE/dx",300, 0.0, 3.0, 400,0.0,1000.0, AliDielectronVarManager::kP, AliDielectronVarManager::kITSsignal);
+  
+  // TPC
+  histos->UserHistogram("Track","TPCchi2","#chi^{2}/cluster;#chi^{2}/cluster;#tracks",200,0.0,5.0, AliDielectronVarManager::kTPCchi2Cl);
+  histos->UserHistogram("Track","Pt_TPCchi2","#chi^{2}/cluster vs pt;p_{T} (GeV/c);#chi^{2}/cluster",400,0.,20., 200,0.0,5.0,
+                       AliDielectronVarManager::kPt,AliDielectronVarManager::kTPCchi2Cl);
+  histos->UserHistogram("Track","TPCnCls","Number of Clusters TPC;TPC number clusters;#tracks",160,-0.5,159.5, AliDielectronVarManager::kNclsTPC);
+  histos->UserHistogram("Track","Phi_TPCnCls","Number of Clusters TPC vs #phi;#phi (rad.);TPC number clusters",200,0,6.285, 160,-0.5,159.5,
+                       AliDielectronVarManager::kPhi,AliDielectronVarManager::kNclsTPC);
+  histos->UserHistogram("Track","Pin_TPCnCls","Number of Clusters TPC vs TPC inner param P;p (GeV/c);TPC number clusters",400,0,20., 160,-0.5,159.5,
+                       AliDielectronVarManager::kPIn, AliDielectronVarManager::kNclsTPC);
+  histos->UserHistogram("Track","TPCnCls_dEdx","Number of Clusters TPC vs dE/dx; TPC number clusters; dE/dx (arb.units)", 160,-0.5,159.5, 200,0,200.,
+                       AliDielectronVarManager::kNclsTPC, AliDielectronVarManager::kTPCsignal);
+  histos->UserHistogram("Track","dEdx_P","dEdx;P [GeV];TPC signal (arb units);#tracks",
+                        400,0.2,20.,200,0.,200.,AliDielectronVarManager::kPIn,AliDielectronVarManager::kTPCsignal);
+  histos->UserHistogram("Track","TPCnSigmaEle_P","TPC number of sigmas Electrons;P [GeV];TPC number of sigmas Electrons;#tracks",
+                        400,0.2,20.,200,-5.,5.,AliDielectronVarManager::kPIn,AliDielectronVarManager::kTPCnSigmaEle);
+  histos->UserHistogram("Track","TPCnSigmaPio_P","TPC number of sigmas Pions;P [GeV];TPC number of sigmas Pions;#tracks",
+                       400,0.2,20.,200,-5.,5.,AliDielectronVarManager::kPIn,AliDielectronVarManager::kTPCnSigmaPio);
+  histos->UserHistogram("Track","TPCnSigmaKao_P","TPC number of sigmas Kaons;P [GeV];TPC number of sigmas Kaons;#tracks",
+                       400,0.2,20.,200,-5.,5.,AliDielectronVarManager::kPIn,AliDielectronVarManager::kTPCnSigmaKao);
+  histos->UserHistogram("Track","TPCnSigmaPro_P","TPC number of sigmas Protons;P [GeV];TPC number of sigmas Protons;#tracks",
+                       400,0.2,20.,200,-5.,5.,AliDielectronVarManager::kPIn,AliDielectronVarManager::kTPCnSigmaPro);
+  histos->UserHistogram("Track","dEdx_Eta","dEdx;#eta;TPC signal (arb units);#tracks",
+                        100,-1.0,1.0,200,0.,200.,AliDielectronVarManager::kEta,AliDielectronVarManager::kTPCsignal);
+  histos->UserHistogram("Track","TPCnSigmaEle_Eta","TPC number of sigmas Electrons;#eta;TPC number of sigmas Electrons;#tracks",
+                        100,-1.0,1.0,200,-5.,5.,AliDielectronVarManager::kEta,AliDielectronVarManager::kTPCnSigmaEle);
+  histos->UserHistogram("Track","TPCnSigmaPio_Eta","TPC number of sigmas Pions;#eta;TPC number of sigmas Pions;#tracks",
+                       100,-1.0,1.0,200,-5.,5.,AliDielectronVarManager::kEta,AliDielectronVarManager::kTPCnSigmaPio);
+  histos->UserHistogram("Track","TPCnSigmaKao_Eta","TPC number of sigmas Kaons;#eta;TPC number of sigmas Kaons;#tracks",
+                       100,-1.0,1.0,200,-5.,5.,AliDielectronVarManager::kEta,AliDielectronVarManager::kTPCnSigmaKao);
+  histos->UserHistogram("Track","TPCnSigmaPro_Eta","TPC number of sigmas Protons;#eta;TPC number of sigmas Protons;#tracks",
+                       100,-1.0,1.0,200,-5.,5.,AliDielectronVarManager::kEta,AliDielectronVarManager::kTPCnSigmaPro);
+
+  // TOF
+  histos->UserHistogram("Track","Pin_TOFsignal","TOF signal vs TPC inner param P; P [GeV]; TOF signal",
+                       120,0.0,6.,1200,0.,120000.,AliDielectronVarManager::kPIn,AliDielectronVarManager::kTOFsignal);
+  histos->UserHistogram("Track","Pin_TOFbeta","TOF #beta vs TPC inner param P; P [GeV]; TOF #beta",
+                       120,0.0,6.,120,0.,1.2,AliDielectronVarManager::kPIn,AliDielectronVarManager::kTOFbeta);
+  histos->UserHistogram("Track","TOFnSigmaPio_Pin","TOF number of sigmas Pions;P [GeV];TOF number of sigmas Pions;#tracks",
+                       400,0.2,20.,200,-10.,10.,AliDielectronVarManager::kPIn,AliDielectronVarManager::kTOFnSigmaPio);
+  histos->UserHistogram("Track","TOFnSigmaPio_eta","TOF number of sigmas Pions vs #eta;#eta;TOF number of sigmas Pions;#tracks",
+                       100,-1.2,1.2,200,-10.,10.,AliDielectronVarManager::kEta,AliDielectronVarManager::kTOFnSigmaPio);
+  histos->UserHistogram("Track","TOFnSigmaKao_Pin","TOF number of sigmas Kaons;P [GeV];TOF number of sigmas Kaons;#tracks",
+                       400,0.2,20.,200,-10.,10.,AliDielectronVarManager::kPIn,AliDielectronVarManager::kTOFnSigmaKao);
+  histos->UserHistogram("Track","TOFnSigmaKao_eta","TOF number of sigmas Kaons vs #eta;#eta;TOF number of sigmas Kaons;#tracks",
+                       100,-1.2,1.2,200,-10.,10.,AliDielectronVarManager::kEta,AliDielectronVarManager::kTOFnSigmaKao);
+  histos->UserHistogram("Track","TOFnSigmaPro_Pin","TOF number of sigmas Protons;P [GeV];TOF number of sigmas Protons;#tracks",
+                       400,0.2,20.,200,-10.,10.,AliDielectronVarManager::kPIn,AliDielectronVarManager::kTOFnSigmaPro);
+  histos->UserHistogram("Track","TOFnSigmaPro_eta","TOF number of sigmas Protons vs #eta;#eta;TOF number of sigmas Protons;#tracks",
+                       100,-1.2,1.2,200,-10.,10.,AliDielectronVarManager::kEta,AliDielectronVarManager::kTOFnSigmaPro);
+
+  //add histograms to Pair classes
+  Int_t nMassBins = 10000;
+  Double_t massRange[2] = {-0.005, 100.005};
+  if(cutDefinition==1) {   // Phi -> K+K-
+    nMassBins = 4000;
+    massRange[0] = 0.8; massRange[1] = 1.2;
+  }
+  histos->UserHistogram("Pair","InvMass","Inv.Mass;Inv. Mass [GeV];#pairs",
+                       nMassBins, massRange[0], massRange[1], AliDielectronVarManager::kM);
+  histos->UserHistogram("Pair","InvMass_Pt","Inv.Mass vs pt;Inv. Mass [GeV]; pt (GeV/c);#pairs",
+                       nMassBins/10, massRange[0], massRange[1], 100, 0.0, 50.0, AliDielectronVarManager::kM, AliDielectronVarManager::kPt);
+  histos->UserHistogram("Pair","InvMass_Cent","Inv.Mass vs centrality;Inv. Mass [GeV]; centrality;#pairs",
+                       nMassBins/10, massRange[0], massRange[1], 20, 0.0, 100.0, AliDielectronVarManager::kM, AliDielectronVarManager::kCentrality);
+  histos->UserHistogram("Pair","InvMass_Rap","Inv.Mass vs rapidity;Inv. Mass [GeV]; rapidity;#pairs",
+                       nMassBins/10, massRange[0], massRange[1], 100, -1.0, 1.0, AliDielectronVarManager::kM, AliDielectronVarManager::kY);
+  histos->UserHistogram("Pair","InvMass_OpAngle","Inv.Mass vs opening angle;Inv. Mass [GeV]; op. angle (rad.);#pairs",
+                       nMassBins/10, massRange[0], massRange[1], 100, 0.0, 4.0, AliDielectronVarManager::kM, AliDielectronVarManager::kOpeningAngle);
+  histos->UserHistogram("Pair","InvMass_ThetaHE","Inv.Mass vs cos #theta^{*}_{HE};Inv. Mass [GeV]; cos #theta^{*}_{HE};#pairs",
+                       nMassBins/10, massRange[0], massRange[1], 100, -1.0, 1.0, AliDielectronVarManager::kM, AliDielectronVarManager::kThetaHE);
+  histos->UserHistogram("Pair","InvMass_ThetaCS","Inv.Mass vs cos #theta^{*}_{CS};Inv. Mass [GeV]; cos #theta^{*}_{CS};#pairs",
+                       nMassBins/10, massRange[0], massRange[1], 100, -1.0, 1.0, AliDielectronVarManager::kM, AliDielectronVarManager::kThetaCS);
+  histos->UserHistogram("Pair","Pt","Transverse momentum; P_{t} [GeV/c];#pairs",
+                       1000, 0.0, 50.0, AliDielectronVarManager::kPt);
+  histos->UserHistogram("Pair","Pt_Y","Transverse momentum vs rapidity; rapidity;  P_{t} [GeV/c];#pairs",
+                       100, -1.0, 1.0, 200, 0.0, 50.0, AliDielectronVarManager::kY, AliDielectronVarManager::kPt);
+  histos->UserHistogram("Pair","Pt_ThetaCS","Transverse momentum vs cos #theta^{*}_{CS}; cos #theta^{*}_{CS};  P_{t} [GeV/c];#pairs",
+                       100, -1.0, 1.0, 200, 0.0, 50.0, AliDielectronVarManager::kThetaCS, AliDielectronVarManager::kPt);
+  histos->UserHistogram("Pair","Pt_ThetaHE","Transverse momentum vs cos #theta^{*}_{HE}; cos #theta^{*}_{HE};  P_{t} [GeV/c];#pairs",
+                       100, -1.0, 1.0, 200, 0.0, 50.0, AliDielectronVarManager::kThetaHE, AliDielectronVarManager::kPt);
+  histos->UserHistogram("Pair","Pt_Phi","Transverse momentum vs phi; #phi (rad.);  P_{t} [GeV/c];#pairs",
+                       200, -6.3, 6.3, 200, 0.0, 50.0, AliDielectronVarManager::kPhi, AliDielectronVarManager::kPt);
+  histos->UserHistogram("Pair","Phi","#phi; #phi (rad.);#pairs",
+                       1000, -6.3, 6.3, AliDielectronVarManager::kPhi);
+  histos->UserHistogram("Pair","Rapidity","Rapidity;Rapidity;#pairs",
+                        100,-1.,1.,AliDielectronVarManager::kY);
+  histos->UserHistogram("Pair","Rapidity_OpAngle","Rapidity vs opening angle;Rapidity; Op.Angle (rad.);#pairs",
+                        100,-1.,1.,200, 0.0, 4.0, AliDielectronVarManager::kY, AliDielectronVarManager::kOpeningAngle);
+  histos->UserHistogram("Pair","Rapidity_ThetaCS","Rapidity vs cos #theta^{*}_{CS};Rapidity; cos #theta^{*}_{CS};#pairs",
+                        100,-1.,1.,200, -1.0, 1.0, AliDielectronVarManager::kY, AliDielectronVarManager::kThetaCS);
+  histos->UserHistogram("Pair","Rapidity_ThetaHE","Rapidity vs cos #theta^{*}_{HE};Rapidity; cos #theta^{*}_{HE};#pairs",
+                        100,-1.,1.,200, -1.0, 1.0, AliDielectronVarManager::kY, AliDielectronVarManager::kThetaHE);
+  histos->UserHistogram("Pair","OpeningAngle","Opening angle;angle",
+                        100,0.,3.15,AliDielectronVarManager::kOpeningAngle);
+  histos->UserHistogram("Pair","Radius","Radius;R[cm]",
+                        1000,0.,300.,AliDielectronVarManager::kR);
+  histos->UserHistogram("Pair","ThetaHE","cos #theta^{*}_{HE}; cos #theta^{*}_{HE}",
+                        220,-1.1,1.1,AliDielectronVarManager::kThetaHE);
+  histos->UserHistogram("Pair","PhiHE","#varphi^{*}_{HE};#varphi^{*}_{HE} (rad.)",
+                        160,-3.2,3.2,AliDielectronVarManager::kPhiHE);
+  histos->UserHistogram("Pair","ThetaCS","cos #theta^{*}_{CS}; cos #theta^{*}_{CS}",
+                        220,-1.1,1.1,AliDielectronVarManager::kThetaCS);
+  histos->UserHistogram("Pair","PhiCS","#varphi^{*}_{CS};#varphi^{*}_{CS} (rad.)",
+                        160,-3.2,3.2,AliDielectronVarManager::kPhiCS);
+  histos->UserHistogram("Pair","Lxy","Pseudo-proper time;Lxy (cm.)",
+                        1000,0.0,2.0,AliDielectronVarManager::kPseudoProperTime);
+  histos->UserHistogram("Pair","Chi2NDF","Pair #chi^{2}/NDF; #chi^{2}/NDF",
+                        1000,0.0,10.0,AliDielectronVarManager::kChi2NDF);
+  
+  
+  die->SetHistogramManager(histos);
+}
+
+
+//_____________________________________________________________________________________________
+void SetDielectronMCSignals(AliDielectron *die)
+{
+  // J/psi sources (direct + feed down from charm higher states)
+  // 0
+  AliDielectronSignalMC* promptJpsi = new AliDielectronSignalMC("promptJpsi","Prompt J/psi");   // prompt J/psi (not from beauty decays)
+  promptJpsi->SetLegPDGs(11,-11);
+  promptJpsi->SetMotherPDGs(443,443);
+  promptJpsi->SetGrandMotherPDGs(503,503,kTRUE,kTRUE);   // not from beauty hadrons
+  promptJpsi->SetMothersRelation(AliDielectronSignalMC::kSame);
+  promptJpsi->SetFillPureMCStep(kTRUE);
+  promptJpsi->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  promptJpsi->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  promptJpsi->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  promptJpsi->SetCheckBothChargesGrandMothers(kTRUE,kTRUE);
+  die->AddSignalMC(promptJpsi);
+
+  // 1
+  AliDielectronSignalMC* beautyJpsi = new AliDielectronSignalMC("beautyJpsi","beauty hadron -> J/psi");  // J/psi->e+e- from beauty hadron decays
+  beautyJpsi->SetLegPDGs(11,-11);
+  beautyJpsi->SetMotherPDGs(443,443);
+  beautyJpsi->SetMothersRelation(AliDielectronSignalMC::kSame);
+  beautyJpsi->SetGrandMotherPDGs(503,503);
+  beautyJpsi->SetFillPureMCStep(kTRUE);
+  beautyJpsi->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  beautyJpsi->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  beautyJpsi->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  beautyJpsi->SetCheckBothChargesGrandMothers(kTRUE,kTRUE);
+  die->AddSignalMC(beautyJpsi);
+
+  // 2
+  AliDielectronSignalMC* beautyMesonJpsi = new AliDielectronSignalMC("beautyMesonJpsi","beauty meson -> J/psi");  // J/psi->e+e- from beauty meson decays
+  beautyMesonJpsi->SetLegPDGs(11,-11);
+  beautyMesonJpsi->SetMotherPDGs(443,443);
+  beautyMesonJpsi->SetMothersRelation(AliDielectronSignalMC::kSame);
+  beautyMesonJpsi->SetGrandMotherPDGs(500,500);
+  beautyMesonJpsi->SetFillPureMCStep(kTRUE);
+  beautyMesonJpsi->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  beautyMesonJpsi->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  beautyMesonJpsi->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  beautyMesonJpsi->SetCheckBothChargesGrandMothers(kTRUE,kTRUE);
+  die->AddSignalMC(beautyMesonJpsi);
+  
+  // 3
+  AliDielectronSignalMC* openBeautyMesonJpsi = new AliDielectronSignalMC("openBeautyMesonJpsi","open beauty meson -> J/psi");  // J/psi->e+e- from open beauty meson decays
+  openBeautyMesonJpsi->SetLegPDGs(11,-11);
+  openBeautyMesonJpsi->SetMotherPDGs(443,443);
+  openBeautyMesonJpsi->SetMothersRelation(AliDielectronSignalMC::kSame);
+  openBeautyMesonJpsi->SetGrandMotherPDGs(501,501);
+  openBeautyMesonJpsi->SetFillPureMCStep(kTRUE);
+  openBeautyMesonJpsi->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  openBeautyMesonJpsi->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  openBeautyMesonJpsi->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  openBeautyMesonJpsi->SetCheckBothChargesGrandMothers(kTRUE,kTRUE);
+  die->AddSignalMC(openBeautyMesonJpsi);
+
+  // 4
+  AliDielectronSignalMC* chic0Jpsi = new AliDielectronSignalMC("chic0Jpsi","chic0 -> J/psi + X");  // J/psi->e+e- from chic0 decays
+  chic0Jpsi->SetLegPDGs(11,-11);
+  chic0Jpsi->SetMotherPDGs(443,443);
+  chic0Jpsi->SetMothersRelation(AliDielectronSignalMC::kSame);
+  chic0Jpsi->SetGrandMotherPDGs(10441,10441);
+  chic0Jpsi->SetFillPureMCStep(kTRUE);
+  chic0Jpsi->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  chic0Jpsi->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  chic0Jpsi->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  chic0Jpsi->SetCheckBothChargesGrandMothers(kTRUE,kTRUE);
+  die->AddSignalMC(chic0Jpsi);
+  
+  // 5
+  AliDielectronSignalMC* chic1Jpsi = new AliDielectronSignalMC("chic1Jpsi","chic1 -> J/psi + X");  // J/psi->e+e- from chic1 decays
+  chic1Jpsi->SetLegPDGs(11,-11);
+  chic1Jpsi->SetMotherPDGs(443,443);
+  chic1Jpsi->SetMothersRelation(AliDielectronSignalMC::kSame);
+  chic1Jpsi->SetGrandMotherPDGs(20443,20443);
+  chic1Jpsi->SetFillPureMCStep(kTRUE);
+  chic1Jpsi->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  chic1Jpsi->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  chic1Jpsi->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  chic1Jpsi->SetCheckBothChargesGrandMothers(kTRUE,kTRUE);
+  die->AddSignalMC(chic1Jpsi);
+  
+  // 6
+  AliDielectronSignalMC* chic2Jpsi = new AliDielectronSignalMC("chic2Jpsi","chic2 -> J/psi + X");  // J/psi->e+e- from chic2 decays
+  chic2Jpsi->SetLegPDGs(11,-11);
+  chic2Jpsi->SetMotherPDGs(443,443);
+  chic2Jpsi->SetMothersRelation(AliDielectronSignalMC::kSame);
+  chic2Jpsi->SetGrandMotherPDGs(445,445);
+  chic2Jpsi->SetFillPureMCStep(kTRUE);
+  chic2Jpsi->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  chic2Jpsi->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  chic2Jpsi->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  chic2Jpsi->SetCheckBothChargesGrandMothers(kTRUE,kTRUE);
+  die->AddSignalMC(chic2Jpsi);
+  
+  // 7
+  AliDielectronSignalMC* psiPrimeJpsi = new AliDielectronSignalMC("psiPrimeJpsi","psi(2S) -> J/psi + X");  // J/psi->e+e- from psi(2S) decays
+  psiPrimeJpsi->SetLegPDGs(11,-11);
+  psiPrimeJpsi->SetMotherPDGs(443,443);
+  psiPrimeJpsi->SetMothersRelation(AliDielectronSignalMC::kSame);
+  psiPrimeJpsi->SetGrandMotherPDGs(445,445);
+  psiPrimeJpsi->SetFillPureMCStep(kTRUE);
+  psiPrimeJpsi->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  psiPrimeJpsi->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  psiPrimeJpsi->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  psiPrimeJpsi->SetCheckBothChargesGrandMothers(kTRUE,kTRUE);
+  die->AddSignalMC(psiPrimeJpsi);
+
+  // physical backgrounds (electrons pairs from other sources and their combinatorics)
+  // 8
+  AliDielectronSignalMC* diEleContinuum = new AliDielectronSignalMC("diEleContinuum","di-electron continuum");     // all di-electrons originating in the collision
+  diEleContinuum->SetLegPDGs(11,-11);
+  diEleContinuum->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  diEleContinuum->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  diEleContinuum->SetFillPureMCStep(kTRUE);
+  die->AddSignalMC(diEleContinuum);
+
+  // 9
+  AliDielectronSignalMC* diEleCharm = new AliDielectronSignalMC("diEleCharm","di-electrons from charm");  // dielectrons originating from charm hadrons (not neccessary from same mother)
+  diEleCharm->SetLegPDGs(11,-11);
+  diEleCharm->SetMotherPDGs(403,403);
+  diEleCharm->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  diEleCharm->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  diEleCharm->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  diEleCharm->SetFillPureMCStep(kTRUE);
+  die->AddSignalMC(diEleCharm);
+
+  // 10
+  AliDielectronSignalMC* diEleOpenCharm = new AliDielectronSignalMC("diEleOpenCharm","di-electrons from open charm");  // dielectrons originating from open charm hadrons
+  diEleOpenCharm->SetLegPDGs(11,-11);
+  diEleOpenCharm->SetMotherPDGs(402,402);
+  diEleOpenCharm->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  diEleOpenCharm->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  diEleOpenCharm->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  diEleOpenCharm->SetFillPureMCStep(kTRUE);
+  die->AddSignalMC(diEleOpenCharm);
+
+  // 11
+  AliDielectronSignalMC* diEleOpenCharmJpsi = new AliDielectronSignalMC("diEleOpenCharmJpsi","1 leg from open charm + 1 jpsi leg");  // 1 leg from open charm + 1 leg from jpsi
+  diEleOpenCharmJpsi->SetLegPDGs(11,-11);
+  diEleOpenCharmJpsi->SetMotherPDGs(402,443);
+  diEleOpenCharmJpsi->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  diEleOpenCharmJpsi->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  diEleOpenCharmJpsi->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  diEleOpenCharmJpsi->SetFillPureMCStep(kTRUE);
+  die->AddSignalMC(diEleOpenCharmJpsi);
+  
+  // 12
+  AliDielectronSignalMC* diEleBeauty = new AliDielectronSignalMC("diEleBeauty","di-electrons from beauty");  // dielectrons originating from beauty hadrons (not neccessary from same mother)
+  diEleBeauty->SetLegPDGs(11,-11);
+  diEleBeauty->SetMotherPDGs(503,503);
+  diEleBeauty->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  diEleBeauty->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  diEleBeauty->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  diEleBeauty->SetFillPureMCStep(kTRUE);
+  die->AddSignalMC(diEleBeauty);
+
+  // 13
+  AliDielectronSignalMC* diEleOpenBeauty = new AliDielectronSignalMC("diEleOpenBeauty","di-electrons from open beauty");  // dielectrons originating from open beauty hadrons
+  diEleOpenBeauty->SetLegPDGs(11,-11);
+  diEleOpenBeauty->SetMotherPDGs(502,502);
+  diEleOpenBeauty->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  diEleOpenBeauty->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  diEleOpenBeauty->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  diEleOpenBeauty->SetFillPureMCStep(kTRUE);
+  die->AddSignalMC(diEleOpenBeauty);
+
+  // 14
+  AliDielectronSignalMC* diEleBeautyJpsi = new AliDielectronSignalMC("diEleBeautyJpsi","1 leg from beauty + 1 jpsi leg");  // 1 leg from beauty + 1 leg from jpsi
+  diEleBeautyJpsi->SetLegPDGs(11,-11);
+  diEleBeautyJpsi->SetMotherPDGs(503,443);
+  diEleBeautyJpsi->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  diEleBeautyJpsi->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  diEleBeautyJpsi->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  diEleBeautyJpsi->SetFillPureMCStep(kTRUE);
+  die->AddSignalMC(diEleBeautyJpsi);
+
+  // 15
+  AliDielectronSignalMC* diEleBeautyOpenCharm = new AliDielectronSignalMC("diEleBeautyOpenCharm","1 leg from beauty + 1 leg from open charm");  // 1 leg from open charm + 1 leg from beauty
+  diEleBeautyOpenCharm->SetLegPDGs(11,-11);
+  diEleBeautyOpenCharm->SetMotherPDGs(503,403);
+  diEleBeautyOpenCharm->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  diEleBeautyOpenCharm->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  diEleBeautyOpenCharm->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  diEleBeautyOpenCharm->SetFillPureMCStep(kTRUE);
+  die->AddSignalMC(diEleBeautyOpenCharm);
+  
+  // 16
+  AliDielectronSignalMC* diEleStrange = new AliDielectronSignalMC("diEleStrange","di-electrons from strange particles");  // dielectrons originating from strange hadrons (not neccessary from same mother)
+  diEleStrange->SetLegPDGs(11,-11);
+  diEleStrange->SetMotherPDGs(300,300);
+  diEleStrange->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  diEleStrange->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  diEleStrange->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  diEleStrange->SetFillPureMCStep(kTRUE);
+  die->AddSignalMC(diEleStrange);
+  
+  // 17
+  AliDielectronSignalMC* diEleStrangeCharm = new AliDielectronSignalMC("diEleStrangeCharm","1 leg from strange + 1 leg from charm");  // 1 leg from strange + 1 leg from charm
+  diEleStrangeCharm->SetLegPDGs(11,-11);
+  diEleStrangeCharm->SetMotherPDGs(300,403);
+  diEleStrangeCharm->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  diEleStrangeCharm->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  diEleStrangeCharm->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  diEleStrangeCharm->SetFillPureMCStep(kTRUE);
+  die->AddSignalMC(diEleStrangeCharm);
+  
+  // 18
+  AliDielectronSignalMC* diEleStrangeBeauty = new AliDielectronSignalMC("diEleStrangeBeauty","1 leg from strange + 1 leg from beauty");  // 1 leg from strange + 1 leg from beauty
+  diEleStrangeBeauty->SetLegPDGs(11,-11);
+  diEleStrangeBeauty->SetMotherPDGs(300,503);
+  diEleStrangeBeauty->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  diEleStrangeBeauty->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  diEleStrangeBeauty->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  diEleStrangeBeauty->SetFillPureMCStep(kTRUE);
+  die->AddSignalMC(diEleStrangeBeauty);
+  
+  // 19
+  AliDielectronSignalMC* diEleLight1 = new AliDielectronSignalMC("diEleLight1","1 leg from light particles + 1 leg from everything");  // 1 leg from light hadrons (100+ PYTHIA codes) + 1 leg from everything
+  diEleLight1->SetLegPDGs(11,-11);
+  diEleLight1->SetMotherPDGs(100,0);
+  diEleLight1->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  diEleLight1->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  diEleLight1->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  diEleLight1->SetFillPureMCStep(kTRUE);
+  die->AddSignalMC(diEleLight1);
+  
+  // 20
+  AliDielectronSignalMC* diEleLight1Charm = new AliDielectronSignalMC("diEleLight1Charm","1 leg from light particles + 1 leg from charm");  // 1 leg from light hadrons (100+ PYTHIA codes) + 1 leg from charm
+  diEleLight1Charm->SetLegPDGs(11,-11);
+  diEleLight1Charm->SetMotherPDGs(100,403);
+  diEleLight1Charm->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  diEleLight1Charm->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  diEleLight1Charm->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  diEleLight1Charm->SetFillPureMCStep(kTRUE);
+  die->AddSignalMC(diEleLight1Charm);
+  
+  // 21
+  AliDielectronSignalMC* diEleLight1Beauty = new AliDielectronSignalMC("diEleLight1Beauty","1 leg from light particles + 1 leg from beauty");  // 1 leg from light hadrons (100+ PYTHIA codes) + 1 leg from beauty
+  diEleLight1Beauty->SetLegPDGs(11,-11);
+  diEleLight1Beauty->SetMotherPDGs(100,503);
+  diEleLight1Beauty->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  diEleLight1Beauty->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  diEleLight1Beauty->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  diEleLight1Beauty->SetFillPureMCStep(kTRUE);
+  die->AddSignalMC(diEleLight1Beauty);
+  
+  // 22
+  AliDielectronSignalMC* diEleLight2 = new AliDielectronSignalMC("diEleLight2","1 leg from light particles + 1 leg from everything");  // 1 leg from light hadrons (200+ PYTHIA codes) + 1 leg from everything
+  diEleLight2->SetLegPDGs(11,-11);
+  diEleLight2->SetMotherPDGs(200,0);
+  diEleLight2->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  diEleLight2->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  diEleLight2->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  diEleLight2->SetFillPureMCStep(kTRUE);
+  die->AddSignalMC(diEleLight2);
+  
+  // 23
+  AliDielectronSignalMC* diEleLight2Charm = new AliDielectronSignalMC("diEleLight2Charm","1 leg from light particles + 1 leg from charm");  // 1 leg from light hadrons (200+ PYTHIA codes) + 1 leg from charm
+  diEleLight2Charm->SetLegPDGs(11,-11);
+  diEleLight2Charm->SetMotherPDGs(100,403);
+  diEleLight2Charm->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  diEleLight2Charm->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  diEleLight2Charm->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  diEleLight2Charm->SetFillPureMCStep(kTRUE);
+  die->AddSignalMC(diEleLight2Charm);
+  
+  // 24
+  AliDielectronSignalMC* diEleLight2Beauty = new AliDielectronSignalMC("diEleLight2Beauty","1 leg from light particles + 1 leg from beauty");  // 1 leg from light hadrons (100+ PYTHIA codes) + 1 leg from beauty
+  diEleLight2Beauty->SetLegPDGs(11,-11);
+  diEleLight2Beauty->SetMotherPDGs(100,503);
+  diEleLight2Beauty->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kFinalState);
+  diEleLight2Beauty->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  diEleLight2Beauty->SetCheckBothChargesMothers(kTRUE,kTRUE);
+  diEleLight2Beauty->SetFillPureMCStep(kTRUE);
+  die->AddSignalMC(diEleLight2Beauty);
+  
+  // background from secondary electrons
+  // 25
+  AliDielectronSignalMC* secondaryElectrons = new AliDielectronSignalMC("secondaryElectrons","Secondary electrons");   // all di-electrons from secondary electrons (interaction with detector)
+  secondaryElectrons->SetLegPDGs(11,-11);
+  secondaryElectrons->SetLegSources(AliDielectronSignalMC::kSecondary, AliDielectronSignalMC::kSecondary);
+  secondaryElectrons->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  die->AddSignalMC(secondaryElectrons);
+
+  // 26
+  AliDielectronSignalMC* primarySecElePairs = new AliDielectronSignalMC("primarySecElePairs","Primary+Secondary electron pairs");  // primary-secondary pairs
+  primarySecElePairs->SetLegPDGs(11,-11);
+  primarySecElePairs->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  primarySecElePairs->SetLegSources(AliDielectronSignalMC::kFinalState, AliDielectronSignalMC::kSecondary);
+  die->AddSignalMC(primarySecElePairs);
+
+  // 27
+  AliDielectronSignalMC* conversionElePairs = new AliDielectronSignalMC("conversionElePairs","conversion electron pairs");      // pairs made from conversion (may be also from 2 different conversions)
+  conversionElePairs->SetLegPDGs(11,-11);
+  conversionElePairs->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  conversionElePairs->SetLegSources(AliDielectronSignalMC::kSecondary, AliDielectronSignalMC::kSecondary);
+  conversionElePairs->SetMotherPDGs(22,22);
+  die->AddSignalMC(conversionElePairs);
+
+  // misidentification
+  // 28
+  AliDielectronSignalMC* allEleMisIdPairs = new AliDielectronSignalMC("allEleMisIdPairs","all electron+misid. pairs");  // one true electron + a mis-id electron (all sources included)
+  allEleMisIdPairs->SetLegPDGs(11,11,kFALSE,kTRUE);
+  allEleMisIdPairs->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  die->AddSignalMC(allEleMisIdPairs);
+
+  // 29
+  AliDielectronSignalMC* allMisIdMisIdPairs = new AliDielectronSignalMC("allMisIdMisIdPairs","all misid.+misid. pairs");  // mis-id + mis-id
+  allMisIdMisIdPairs->SetLegPDGs(11,11,kTRUE,kTRUE);
+  allMisIdMisIdPairs->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  die->AddSignalMC(allMisIdMisIdPairs);
+
+  // 30
+  AliDielectronSignalMC* elePionPairs = new AliDielectronSignalMC("elePionPairs","electron+pion pairs");    // true electron + mis-id pion
+  elePionPairs->SetLegPDGs(11,211);
+  elePionPairs->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  die->AddSignalMC(elePionPairs);
+
+  // 31
+  AliDielectronSignalMC* eleProtonPairs = new AliDielectronSignalMC("eleProtonPairs","Electron+proton pairs");  // true electron + mis-id proton
+  eleProtonPairs->SetLegPDGs(11,2212);
+  eleProtonPairs->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  die->AddSignalMC(eleProtonPairs);
+  
+  // 32
+  AliDielectronSignalMC* eleKaonPairs = new AliDielectronSignalMC("eleKaonPairs","electron+kaon pairs");   // true electron + mis-id kaon
+  eleKaonPairs->SetLegPDGs(11,321);
+  eleKaonPairs->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  die->AddSignalMC(eleKaonPairs);
+
+  // 33
+  AliDielectronSignalMC* eleProtonPairs = new AliDielectronSignalMC("eleProtonPairs","Electron+proton pairs");  // true electron + mis-id proton
+  eleProtonPairs->SetLegPDGs(11,2212);
+  eleProtonPairs->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  die->AddSignalMC(eleProtonPairs);
+
+  // 34
+  AliDielectronSignalMC* piPiPairs = new AliDielectronSignalMC("piPiPairs","pion+pion pairs");    // mis-id pion + mis-id pion
+  piPiPairs->SetLegPDGs(211,211);
+  piPiPairs->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  die->AddSignalMC(piPiPairs);
+
+  // 35
+  AliDielectronSignalMC* piKaonPairs = new AliDielectronSignalMC("piKaonPairs","pion+kaon pairs");  // mis-id pion + mis-id kaon
+  piKaonPairs->SetLegPDGs(211,321);
+  piKaonPairs->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  die->AddSignalMC(piKaonPairs);
+
+  // 36
+  AliDielectronSignalMC* piProtonPairs = new AliDielectronSignalMC("piProtonPairs","pion+proton pairs");  // mis-id pion + mis-id proton
+  piProtonPairs->SetLegPDGs(211,2212);
+  piProtonPairs->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  die->AddSignalMC(piProtonPairs);
+
+  // 37
+  AliDielectronSignalMC* kaonKaonPairs = new AliDielectronSignalMC("kaonKaonPairs","kaon+kaon pairs");  // mis-id kaon + mis-id kaon
+  kaonKaonPairs->SetLegPDGs(321,321);
+  kaonKaonPairs->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  die->AddSignalMC(kaonKaonPairs);
+
+  // 38
+  AliDielectronSignalMC* muonAllPairs = new AliDielectronSignalMC("muonAllPairs","muon+everything pairs");        // mis-id muon + something else (electron, pion, kaon, proton)
+  muonAllPairs->SetLegPDGs(13,13,kFALSE,kTRUE);
+  muonAllPairs->SetCheckBothChargesLegs(kTRUE,kTRUE);
+  die->AddSignalMC(muonAllPairs);
+}
+
+//______________________________________________________________________________________
+void SetEtaCorrection()
+{
+//
+// Eta equalization for the TPC response
+//
+  if (AliDielectronPID::GetEtaCorrFunction()) return;
+
+  TString list=gSystem->Getenv("LIST");
+
+  TFile f("$TRAIN_ROOT/jpsi_JPSI/EtaCorrMaps.root");
+  if (!f.IsOpen()) return;
+  TList *keys=f.GetListOfKeys();
+
+  for (Int_t i=0; i<keys->GetEntries(); ++i){
+    TString kName=keys->At(i)->GetName();
+    TPRegexp reg(kName);
+    if (reg.MatchB(list)){
+      printf("Using Eta Correction Function: %s\n",kName.Data());
+      AliDielectronPID::SetEtaCorrFunction((TF1*)f.Get(kName.Data()));
+    }
+  }
+}