New event mixing task for HF vertexing (Rossella)
authordainese <dainese@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 3 Nov 2009 01:15:38 +0000 (01:15 +0000)
committerdainese <dainese@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 3 Nov 2009 01:15:38 +0000 (01:15 +0000)
PWG3/CMake_libPWG3vertexingHF.txt
PWG3/PWG3vertexingHFLinkDef.h
PWG3/libPWG3vertexingHF.pkg
PWG3/vertexingHF/AddTaskHFMixing.C [new file with mode: 0644]
PWG3/vertexingHF/AliAnalysisTaskMEVertexingHF.cxx [new file with mode: 0644]
PWG3/vertexingHF/AliAnalysisTaskMEVertexingHF.h [new file with mode: 0644]
PWG3/vertexingHF/AliAnalysisTaskMEVertexingHFTest.C [new file with mode: 0644]
PWG3/vertexingHF/AliAnalysisVertexingHF.cxx
PWG3/vertexingHF/AliAnalysisVertexingHF.h

index feba3d9..234a1fe 100644 (file)
@@ -7,6 +7,7 @@ set(SRCS
        vertexingHF/AliAODRecoCascadeHF.cxx 
        vertexingHF/AliAnalysisVertexingHF.cxx 
        vertexingHF/AliAnalysisTaskSEVertexingHF.cxx 
+       vertexingHF/AliAnalysisTaskMEVertexingHF.cxx 
        vertexingHF/AliAnalysisTaskSESelectHF.cxx
        vertexingHF/AliAnalysisTaskSECompareHF.cxx
        vertexingHF/AliAnalysisTaskSEDplus.cxx
index fcca932..e2ad0bc 100644 (file)
@@ -12,6 +12,7 @@
 #pragma link C++ class AliAODRecoCascadeHF+;
 #pragma link C++ class AliAnalysisVertexingHF+;
 #pragma link C++ class AliAnalysisTaskSEVertexingHF+;
+#pragma link C++ class AliAnalysisTaskMEVertexingHF+;
 #pragma link C++ class AliAnalysisTaskSESelectHF+;
 #pragma link C++ class AliAnalysisTaskSECompareHF+;
 #pragma link C++ class AliAnalysisTaskSEDplus+;
index 6949dba..20ef7cb 100644 (file)
@@ -6,6 +6,7 @@ SRCS:=   vertexingHF/AliAODRecoDecayHF.cxx \
        vertexingHF/AliAODRecoCascadeHF.cxx \
        vertexingHF/AliAnalysisVertexingHF.cxx \
        vertexingHF/AliAnalysisTaskSEVertexingHF.cxx \
+       vertexingHF/AliAnalysisTaskMEVertexingHF.cxx \
        vertexingHF/AliAnalysisTaskSESelectHF.cxx \
        vertexingHF/AliAnalysisTaskSECompareHF.cxx \
        vertexingHF/AliAnalysisTaskSEDplus.cxx \
diff --git a/PWG3/vertexingHF/AddTaskHFMixing.C b/PWG3/vertexingHF/AddTaskHFMixing.C
new file mode 100644 (file)
index 0000000..0184707
--- /dev/null
@@ -0,0 +1,38 @@
+AliAnalysisTaskMEVertexingHF *AddTaskHFMixing() {
+  //
+  // Creates a task for event mixing and adds it to the analysis manager.
+  // r.romita@gsi.de
+  //
+
+  // Get the pointer to the existing analysis manager via the static access method.
+  //==============================================================================
+  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+  if (!mgr) {
+    ::Error("AddTaskHFMixing", "No analysis manager to connect to.");
+    return NULL;
+  }   
+   
+  // This task requires  AOD input handler and an AOD output handler.
+  // Check this using the analysis manager.
+  //===============================================================================
+
+  // Check if AOD output handler exist.
+  AliAODHandler *aodh = (AliAODHandler*)mgr->GetOutputEventHandler();
+  if (!aodh) {
+    ::Error("AddTaskMixing", "HF vertexing task needs the manager to have an AOD output handler.");
+    return NULL;
+  }   
+  
+  // Create the task, add it to the manager and configure it.
+  //===========================================================================
+  AliAnalysisTaskMEVertexingHF *hfTask = new AliAnalysisTaskMEVertexingHF("mixing vertexing HF");
+  mgr->AddTask(hfTask);
+
+  //
+  // Create containers for input/output
+  AliAnalysisDataContainer *cinput1 = mgr->CreateContainer("cchain",TChain::Class(), AliAnalysisManager::kInputContainer);
+  mgr->ConnectInput(hfTask,0,mgr->GetCommonInputContainer());
+  mgr->ConnectOutput(hfTask,0,mgr->GetCommonOutputContainer());
+
+  return hfTask;
+}
diff --git a/PWG3/vertexingHF/AliAnalysisTaskMEVertexingHF.cxx b/PWG3/vertexingHF/AliAnalysisTaskMEVertexingHF.cxx
new file mode 100644 (file)
index 0000000..273287f
--- /dev/null
@@ -0,0 +1,213 @@
+/**************************************************************************
+ * 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.                  *
+ **************************************************************************/
+//*************************************************************************
+// Class AliAnalysisTaskMEVertexingHF
+// AliAnalysisTaskME for event mixing, building the background for 
+// heavy-flavour decay candidates
+// Author: R.Romita, r.romita@gsi.de
+//*************************************************************************
+
+
+
+#include "TH1F.h"
+#include "TObjArray.h"
+#include "TList.h"
+#include "TROOT.h"
+#include "TSystem.h"
+#include "TCanvas.h"
+
+#include "AliVEvent.h"
+#include "AliVVertex.h"
+#include "AliAODEvent.h"
+#include "AliESDEvent.h"
+#include "AliAnalysisVertexingHF.h"
+#include "AliMixedEvent.h"
+#include "AliAnalysisTaskMEVertexingHF.h"
+#include "AliAnalysisManager.h"
+#include "AliMultiEventInputHandler.h"
+
+ClassImp(AliAnalysisTaskMEVertexingHF)
+
+//________________________________________________________________________
+AliAnalysisTaskMEVertexingHF::AliAnalysisTaskMEVertexingHF(const char *name) : 
+AliAnalysisTaskME(name), 
+fvHF(0), 
+fMixedEvent(),
+fVerticesHFTClArr(0),
+fD0toKpiTClArr(0), 
+fJPSItoEleTClArr(0),
+fCharm3ProngTClArr(0),
+fCharm4ProngTClArr(0),
+fDstarTClArr(0),
+fLikeSign2ProngTClArr(0),
+fLikeSign3ProngTClArr(0)
+{
+  // Constructor
+}
+//________________________________________________________________________
+void AliAnalysisTaskMEVertexingHF::Init()
+{
+ // Initialization
+ // Instanciates vHF and loads its parameters
+ // Some parameters are changed
+  if(gROOT->LoadMacro("ConfigVertexingHF.C")) {
+    printf("AnalysisTaskMEVertexingHF::Init() \n Using $ALICE_ROOT/PWG3/vertexingHF/ConfigVertexingHF.C\n");
+    gROOT->LoadMacro("$ALICE_ROOT/PWG3/vertexingHF/ConfigVertexingHF.C");
+  }
+  fvHF = (AliAnalysisVertexingHF*)gROOT->ProcessLine("ConfigVertexingHF()");
+  fvHF->SetMixEventOn();
+  fvHF->SetInputAOD();
+  fvHF->PrintStatus();
+  if(fvHF->GetLikeSign()) {
+    printf("WARNING: fLikeSign will be switched off!");
+    fvHF->SetLikeSignOff();
+  }
+  if(fvHF->GetRecoPrimVtxSkippingTrks() || fvHF->GetRmTrksFromPrimVtx()){
+    fvHF->UnsetRecoPrimVtxSkippingTrks();
+    printf("WARNING: if on, fRecoPrimVtxSkippingTrks and fRmTrksFromPrimVtx  will be switched off!\n");
+  }
+  
+  AliAnalysisManager::GetAnalysisManager()->RegisterExtraFile("AliAOD.VertexingHF.root");
+
+  return;
+}
+//________________________________________________________________________
+void AliAnalysisTaskMEVertexingHF::UserCreateOutputObjects()
+{  
+// Create the output container
+
+
+  if (!AODEvent()) {
+    Fatal("UserCreateOutputObjects", "This task needs an AOD handler");
+    return;
+  }
+  
+  if(!fvHF) {
+    printf("AnalysisTaskMEVertexingHF::UserCreateOutPutData() \n ERROR! no fvHF!\n");
+    return;
+  }
+  fVerticesHFTClArr = new TClonesArray("AliAODVertex", 0);
+  fVerticesHFTClArr->SetName("VerticesHF");
+  AddAODBranch("TClonesArray", &fVerticesHFTClArr);
+  if(fvHF->GetD0toKpi()) {
+    fD0toKpiTClArr = new TClonesArray("AliAODRecoDecayHF2Prong", 0);
+    fD0toKpiTClArr->SetName("D0toKpi");
+    AddAODBranch("TClonesArray", &fD0toKpiTClArr);
+  }
+  if(fvHF->GetJPSItoEle()) {
+    fJPSItoEleTClArr = new TClonesArray("AliAODRecoDecayHF2Prong", 0);
+    fJPSItoEleTClArr->SetName("JPSItoEle");
+    AddAODBranch("TClonesArray", &fJPSItoEleTClArr);
+  }
+  if(fvHF->Get3Prong()) {
+    fCharm3ProngTClArr = new TClonesArray("AliAODRecoDecayHF3Prong", 0);
+    fCharm3ProngTClArr->SetName("Charm3Prong");
+    AddAODBranch("TClonesArray", &fCharm3ProngTClArr);
+  }
+  if(fvHF->Get4Prong()) {
+    fCharm4ProngTClArr = new TClonesArray("AliAODRecoDecayHF4Prong", 0);
+    fCharm4ProngTClArr->SetName("Charm4Prong");
+    AddAODBranch("TClonesArray", &fCharm4ProngTClArr);
+  }
+  
+  if(fvHF->GetDstar()) {
+    fDstarTClArr = new TClonesArray("AliAODRecoCascadeHF", 0);
+    fDstarTClArr->SetName("Dstar");
+    AddAODBranch("TClonesArray", &fDstarTClArr);
+  }
+  
+  if(fvHF->GetLikeSign()) {
+    fLikeSign2ProngTClArr = new TClonesArray("AliAODRecoDecayHF2Prong", 0);
+    fLikeSign2ProngTClArr->SetName("LikeSign2Prong");
+    AddAODBranch("TClonesArray", &fLikeSign2ProngTClArr);
+  }
+  if(fvHF->GetLikeSign() && fvHF->Get3Prong()) {
+    fLikeSign3ProngTClArr = new TClonesArray("AliAODRecoDecayHF3Prong", 0);
+    fLikeSign3ProngTClArr->SetName("LikeSign3Prong");
+    AddAODBranch("TClonesArray", &fLikeSign3ProngTClArr);
+  }
+
+  return;
+}
+
+//________________________________________________________________________
+void AliAnalysisTaskMEVertexingHF::UserExec(Option_t *) 
+{
+  // Execute analysis for current event:
+  // first build the mixed event, compute the new primary vtx 
+  // then heavy flavor vertexing 
+
+  Int_t nev = fInputHandler->GetBufferSize();
+  fMixedEvent = new AliMixedEvent();
+  fMixedEvent->Reset();
+  TString primTitle;
+  TString primTitleFirst;
+  
+
+  TObjArray *vertices=new TObjArray(nev);
+  for (Int_t iev = 0; iev < nev; iev++) {
+    AliAODEvent *evt = (AliAODEvent*)GetEvent(iev);
+    if(!evt) {delete vertices;return;}
+    AliAODVertex *evtVtx=(AliAODVertex*)evt->GetPrimaryVertex();
+    if(!evtVtx) {delete vertices;return;}
+    primTitle = evtVtx->GetTitle();
+    Int_t nContrib=evtVtx->GetNContributors();
+    if(!primTitle.Contains("VertexerTracks") || nContrib<=0) {
+      delete vertices;
+      return;
+    }
+
+    AliAODVertex *vtxCopy=new AliAODVertex(*evtVtx);
+    primTitleFirst=evtVtx->GetTitle();
+        
+
+    fMixedEvent->AddEvent(evt);
+
+    vertices->AddLast(vtxCopy);
+  }
+
+
+  fMixedEvent->Init();
+  Double_t vtxPos[3]={0.,0.,0.},vtxSigma[3]={0.,0.,0.};
+  Int_t nContributors[1]={0};
+  Double_t chi2=0;
+  Bool_t primaryOk=fMixedEvent->ComputeVtx(vertices,vtxPos,vtxSigma,nContributors);
+  if(!primaryOk) {delete vertices;return;}
+  Int_t contribCopy=nContributors[0];
+  AliVVertex* newVertex=new AliESDVertex(vtxPos,vtxSigma,chi2,contribCopy);
+  newVertex->SetTitle(primTitleFirst.Data());
+  fMixedEvent->SetPrimaryVertex(newVertex);
+
+  delete vertices;
+
+  fvHF->FindCandidates(fMixedEvent,
+                      fVerticesHFTClArr,
+                      fD0toKpiTClArr,
+                      fJPSItoEleTClArr,
+                      fCharm3ProngTClArr,
+                      fCharm4ProngTClArr,
+                      fDstarTClArr,
+                      fLikeSign2ProngTClArr,
+                      fLikeSign3ProngTClArr);
+
+  return;
+}      
+
+//________________________________________________________________________
+void AliAnalysisTaskMEVertexingHF::Terminate(Option_t *) 
+{
+  // Terminate analysis
+}
diff --git a/PWG3/vertexingHF/AliAnalysisTaskMEVertexingHF.h b/PWG3/vertexingHF/AliAnalysisTaskMEVertexingHF.h
new file mode 100644 (file)
index 0000000..4513241
--- /dev/null
@@ -0,0 +1,55 @@
+#ifndef AliAnalysisTaskMEVertexingHF_cxx\r
+#define AliAnalysisTaskMEVertexingHF_cxx\r
+\r
+/* Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *\r
+ *  * See cxx source for full Copyright notice                               */\r
+\r
+//*************************************************************************\r
+// Class AliAnalysisTaskMEVertexingHF\r
+// AliAnalysisTaskME for event mixing, building the background for \r
+// heavy-flavour decay candidates\r
+// Author: R.Romita, r.romita@gsi.de\r
+//*************************************************************************\r
+\r
+\r
+class TH1F;\r
+class TList;\r
+class AliESDEvent;\r
+\r
+#include "AliAnalysisTaskME.h"\r
+#include "AliAnalysisVertexingHF.h"\r
+#include "AliMixedEvent.h"\r
+#include <TClonesArray.h>\r
+\r
+\r
+class AliAnalysisTaskMEVertexingHF : public AliAnalysisTaskME {\r
+ public:\r
+  AliAnalysisTaskMEVertexingHF(const char *name = "AliAnalysisTaskMEVertexingHF");\r
+  virtual ~AliAnalysisTaskMEVertexingHF() {}\r
+  \r
+  virtual void   Init();\r
+  virtual void   LocalInit() {Init();}\r
+  virtual void   UserCreateOutputObjects();\r
+  virtual void   UserExec(Option_t *option);\r
+  virtual void   Terminate(Option_t *);\r
+  \r
+ private:\r
+  AliAnalysisVertexingHF *fvHF;      // Vertexer heavy flavour\r
+  AliMixedEvent *fMixedEvent;        // Mixed event\r
+  TClonesArray  *fVerticesHFTClArr;  //Array of heavy-flavour vertices\r
+  TClonesArray  *fD0toKpiTClArr;     //Array of D0->Kpi\r
+  TClonesArray  *fJPSItoEleTClArr;   //Array of Jpsi->ee\r
+  TClonesArray  *fCharm3ProngTClArr; //Array of D+,Ds,Lc\r
+  TClonesArray  *fCharm4ProngTClArr; // Array of D0->Kpipipi\r
+  TClonesArray  *fDstarTClArr;          // Array of D*->D0pi\r
+  TClonesArray  *fLikeSign2ProngTClArr; // Array of LikeSign2Prong\r
+  TClonesArray  *fLikeSign3ProngTClArr; // Array of LikeSign3Prong\r
+\r
+\r
+  AliAnalysisTaskMEVertexingHF(const AliAnalysisTaskMEVertexingHF&); // not implemented\r
+  AliAnalysisTaskMEVertexingHF& operator=(const AliAnalysisTaskMEVertexingHF&); // not implemented\r
+  \r
+  ClassDef(AliAnalysisTaskMEVertexingHF,1); // event mixing for heavy-flavour vertexing\r
+};\r
+\r
+#endif\r
diff --git a/PWG3/vertexingHF/AliAnalysisTaskMEVertexingHFTest.C b/PWG3/vertexingHF/AliAnalysisTaskMEVertexingHFTest.C
new file mode 100644 (file)
index 0000000..3e1f83c
--- /dev/null
@@ -0,0 +1,65 @@
+void AliAnalysisTaskMEVertexingHFTest()\r
+{\r
+  //\r
+  // Test macro for the AliAnalysisTaskME for heavy-flavour event mixing\r
+  // r.romita@gsi.de\r
+  //\r
+\r
+  Bool_t useParFiles=kFALSE;\r
+  \r
+  gROOT->LoadMacro("$ALICE_ROOT/PWG3/vertexingHF/LoadLibraries.C");\r
+  LoadLibraries(useParFiles);\r
+\r
+  // Local files \r
+  \r
+\r
+  TChain* chain = new TChain("aodTree");\r
+  Char_t fileName[100];\r
+  sprintf(fileName,"AliAODs.root");\r
+  chain->Add(fileName);\r
+  \r
+  // Create the analysis manager\r
+  AliAnalysisManager *mgr  = new AliAnalysisManager("My Manager","My Manager");\r
+  \r
+  // Input Handler\r
+  AliMultiEventInputHandler *inputHandler = new AliMultiEventInputHandler(4,1);\r
+  AliEventPoolOTF* pool = new AliEventPoolOTF("event pool", "AOD");\r
+  // apply selections\r
+  pool->SetMultiplicityBin(0, 100, 2);\r
+  pool->SetZVertexBinning(-20., 20., 2);\r
+  pool->Init();\r
+  //set tag directory\r
+  Char_t tagDir[100];\r
+  sprintf(tagDir,".");\r
+  pool->SetTagDirectory(tagDir);\r
+  mgr->SetInputEventHandler(inputHandler);\r
+  mgr->SetEventPool(pool);\r
+  inputHandler->SetEventPool(pool);\r
+  \r
+  // Output \r
+  AliAODHandler *aodHandler = new AliAODHandler();\r
+  aodHandler->SetOutputFileName("AliAOD.VertexingHF.root");\r
+  aodHandler->SetCreateNonStandardAOD();\r
+  mgr->SetOutputEventHandler(aodHandler);\r
+  \r
+  gROOT->LoadMacro("AddTaskMixing.C");\r
+  AliAnalysisTaskMEVertexingHF *hfTask = AddTaskHFMixing();\r
+  \r
+  \r
+  //\r
+  // Run the analysis\r
+  //    \r
+  printf("CHAIN HAS %d ENTRIES\n",(Int_t)chain->GetEntries());\r
+  if(!mgr->InitAnalysis()) return;\r
+\r
+  mgr->PrintStatus();\r
+\r
+  TStopwatch watch;\r
+  watch.Start();\r
+  mgr->StartAnalysis("mix",chain, 1000);\r
+  watch.Stop();\r
+  watch.Print();\r
+  delete mgr;\r
+\r
+  return;\r
+}\r
index 7129007..f8a84de 100644 (file)
@@ -20,7 +20,7 @@
 // class AliAnalysisTaskSEVertexingHF. 
 // An example of usage in the macro AliAnalysisTaskSEVertexingHFTest.C.
 //
-//  Contact: andrea.dainese@lnl.infn.it
+//  Contact: andrea.dainese@pd.infn.it
 //  Contributors: E.Bruna, G.E.Bruno, A.Dainese, C.Di Gliglio,
 //                F.Prino, R.Romita, X.M.Zhang
 //----------------------------------------------------------------------------
@@ -48,6 +48,7 @@
 #include "AliAODRecoCascadeHF.h"
 #include "AliAnalysisFilter.h"
 #include "AliAnalysisVertexingHF.h"
+#include "AliMixedEvent.h"
 
 ClassImp(AliAnalysisVertexingHF)
 
@@ -67,6 +68,7 @@ f3Prong(kTRUE),
 f4Prong(kTRUE),
 fDstar(kTRUE),
 fLikeSign(kFALSE),
+fMixEvent(kFALSE),
 fTrackFilter(0x0),
 fTrackFilterSoftPi(0x0),
 fFindVertexForDstar(kTRUE)
@@ -98,6 +100,7 @@ f3Prong(source.f3Prong),
 f4Prong(source.f4Prong),
 fDstar(source.fDstar),
 fLikeSign(source.fLikeSign),
+fMixEvent(source.fMixEvent),
 fTrackFilter(source.fTrackFilter),
 fTrackFilterSoftPi(source.fTrackFilterSoftPi),
 fFindVertexForDstar(source.fFindVertexForDstar)
@@ -133,6 +136,7 @@ AliAnalysisVertexingHF &AliAnalysisVertexingHF::operator=(const AliAnalysisVerte
   f4Prong = source.f4Prong;
   fDstar = source.fDstar;
   fLikeSign = source.fLikeSign;
+  fMixEvent = source.fMixEvent;
   fTrackFilter = source.fTrackFilter;
   fTrackFilterSoftPi = source.fTrackFilterSoftPi;
   fFindVertexForDstar = source.fFindVertexForDstar;
@@ -170,9 +174,10 @@ void AliAnalysisVertexingHF::FindCandidates(AliVEvent *event,
   // Input:  ESD or AOD
   // Output: AOD (additional branches added)
 
-
-  TString evtype = event->IsA()->GetName();
-  fInputAOD = ((evtype=="AliAODEvent") ? kTRUE : kFALSE);
+  if(!fMixEvent){
+    TString evtype = event->IsA()->GetName();
+    fInputAOD = ((evtype=="AliAODEvent") ? kTRUE : kFALSE);
+  } // if we do mixing AliVEvent is a AliMixedEvent
 
   if(fInputAOD) {
     AliDebug(2,"Creating HF candidates from AOD");
@@ -293,12 +298,14 @@ void AliAnalysisVertexingHF::FindCandidates(AliVEvent *event,
     AliDebug(1," No primary vertex from tracks");
     return;
   }
-  TString primTitle = primary->GetTitle();
+
+  TString primTitle=primary->GetTitle();
   if(!primTitle.Contains("VertexerTracks") ||
      primary->GetNContributors()<=0) {
     AliDebug(1," No primary vertex from tracks");
     return;
   }
+  
 
   // call function that applies sigle-track selection,
   // for displaced tracks and soft pions (both charges) for D*,
@@ -306,7 +313,8 @@ void AliAnalysisVertexingHF::FindCandidates(AliVEvent *event,
   TObjArray seleTrksArray(trkEntries);
   UChar_t  *seleFlags = new UChar_t[trkEntries]; // bit 0: displaced, bit 1: softpi
   Int_t     nSeleTrks=0;
-  SelectTracksAndCopyVertex(event,seleTrksArray,nSeleTrks,seleFlags);
+  Int_t *evtNumber    = new Int_t[trkEntries];
+  SelectTracksAndCopyVertex(event,seleTrksArray,nSeleTrks,seleFlags,evtNumber);
     
   AliDebug(1,Form(" Selected tracks: %d",nSeleTrks));
     
@@ -348,6 +356,10 @@ void AliAnalysisVertexingHF::FindCandidates(AliVEvent *event,
 
       if(!TESTBIT(seleFlags[iTrkN1],kBitDispl)) continue;
 
+      if(fMixEvent) {
+       if(evtNumber[iTrkP1]==evtNumber[iTrkN1]) continue;
+      }
+
       if(postrack1->Charge()==negtrack1->Charge()) { // like-sign 
        isLikeSign2Prong=kTRUE;
        if(!fLikeSign)    continue;
@@ -355,12 +367,15 @@ void AliAnalysisVertexingHF::FindCandidates(AliVEvent *event,
       } else { // unlike-sign
        isLikeSign2Prong=kFALSE;
        if(postrack1->Charge()<0 || negtrack1->Charge()>0) continue;  // this is needed to avoid double-counting of unlike-sign
+       if(fMixEvent) {
+         if(evtNumber[iTrkP1]==evtNumber[iTrkN1]) continue;
+       }
+       
       }
 
       // back to primary vertex
       postrack1->PropagateToDCA(fV1,fBzkG,kVeryBig);
       negtrack1->PropagateToDCA(fV1,fBzkG,kVeryBig);
-      //printf("********** %d %d\n",postrack1->GetID(),negtrack1->GetID());
 
       // DCA between the two tracks
       dcap1n1 = postrack1->GetDCA(negtrack1,fBzkG,xdummy,ydummy);
@@ -426,6 +441,12 @@ void AliAnalysisVertexingHF::FindCandidates(AliVEvent *event,
 
            if(!TESTBIT(seleFlags[iTrkSoftPi],kBitSoftPi)) continue;
 
+           if(fMixEvent) {
+             if(evtNumber[iTrkP1]==evtNumber[iTrkSoftPi] || 
+                evtNumber[iTrkN1]==evtNumber[iTrkSoftPi] || 
+                evtNumber[iTrkP1]==evtNumber[iTrkN1]) continue;
+           }
+
            if(iTrkSoftPi%1==0) AliDebug(1,Form("    1st loop on pi_s: track number %d of %d",iTrkSoftPi,nSeleTrks));  
 
            trackD0->PropagateToDCA(fV1,fBzkG,kVeryBig);
@@ -520,6 +541,12 @@ void AliAnalysisVertexingHF::FindCandidates(AliVEvent *event,
 
        if(!TESTBIT(seleFlags[iTrkP2],kBitDispl)) continue;
 
+       if(fMixEvent) {
+         if(evtNumber[iTrkP1]==evtNumber[iTrkP2] || 
+            evtNumber[iTrkN1]==evtNumber[iTrkP2] ||
+            evtNumber[iTrkP1]==evtNumber[iTrkN1]) continue;
+       }
+
        if(isLikeSign2Prong) { // like-sign pair -> have to build only like-sign triplet 
          if(postrack1->Charge()>0) { // ok: like-sign triplet (+++)
            isLikeSign3Prong=kTRUE;
@@ -528,6 +555,11 @@ void AliAnalysisVertexingHF::FindCandidates(AliVEvent *event,
          }
        } else { // normal triplet (+-+)
          isLikeSign3Prong=kFALSE; 
+         if(fMixEvent) {
+           if(evtNumber[iTrkP1]==evtNumber[iTrkP2] || 
+              evtNumber[iTrkN1]==evtNumber[iTrkP2] ||
+              evtNumber[iTrkP1]==evtNumber[iTrkN1]) continue;
+         }
        }
 
        // back to primary vertex
@@ -614,6 +646,14 @@ void AliAnalysisVertexingHF::FindCandidates(AliVEvent *event,
            if(negtrack2->Charge()>0) continue;
 
            if(!TESTBIT(seleFlags[iTrkN2],kBitDispl)) continue;
+           if(fMixEvent){ 
+             if(evtNumber[iTrkP1]==evtNumber[iTrkN2] || 
+                evtNumber[iTrkN1]==evtNumber[iTrkN2] || 
+                evtNumber[iTrkP2]==evtNumber[iTrkN2] ||
+                evtNumber[iTrkP1]==evtNumber[iTrkN1] ||
+                evtNumber[iTrkP1]==evtNumber[iTrkP2] ||
+                evtNumber[iTrkN1]==evtNumber[iTrkP2]) continue;
+           }
 
            // back to primary vertex
            postrack1->PropagateToDCA(fV1,fBzkG,kVeryBig);
@@ -675,6 +715,12 @@ void AliAnalysisVertexingHF::FindCandidates(AliVEvent *event,
 
        if(!TESTBIT(seleFlags[iTrkN2],kBitDispl)) continue;
 
+       if(fMixEvent) {
+         if(evtNumber[iTrkP1]==evtNumber[iTrkN2] || 
+            evtNumber[iTrkN1]==evtNumber[iTrkN2] ||
+            evtNumber[iTrkP1]==evtNumber[iTrkN1]) continue;
+       }
+
        if(isLikeSign2Prong) { // like-sign pair -> have to build only like-sign triplet 
          if(postrack1->Charge()<0) { // ok: like-sign triplet (---)
            isLikeSign3Prong=kTRUE;
@@ -682,7 +728,7 @@ void AliAnalysisVertexingHF::FindCandidates(AliVEvent *event,
            continue;
          }
        } else { // normal triplet (-+-)
-         isLikeSign3Prong=kFALSE; 
+         isLikeSign3Prong=kFALSE;
        }
 
        // back to primary vertex
@@ -785,6 +831,7 @@ void AliAnalysisVertexingHF::FindCandidates(AliVEvent *event,
   threeTrackArray->Delete(); delete threeTrackArray;
   fourTrackArray->Delete();  delete fourTrackArray;
   delete [] seleFlags; seleFlags=NULL;
+  if(evtNumber) {delete [] evtNumber; evtNumber=NULL;}
 
   if(fInputAOD) {
     seleTrksArray.Delete(); 
@@ -862,7 +909,7 @@ AliAODRecoCascadeHF* AliAnalysisVertexingHF::MakeCascade(
   tmpCascade->GetSecondaryVtx()->RemoveDaughters();
   tmpCascade->UnsetOwnPrimaryVtx(); 
   delete tmpCascade; tmpCascade=NULL;
-  if(!fRecoPrimVtxSkippingTrks && !fRmTrksFromPrimVtx) {
+  if(!fRecoPrimVtxSkippingTrks && !fRmTrksFromPrimVtx && !fMixEvent) {
     rd2Prong->UnsetOwnPrimaryVtx();
   }
   if(primVertexAOD) {delete primVertexAOD; primVertexAOD=NULL;}
@@ -884,7 +931,6 @@ AliAODRecoDecayHF2Prong *AliAnalysisVertexingHF::Make2Prong(
   okD0=kFALSE; okJPSI=kFALSE; okD0fromDstar=kFALSE;
 
   Double_t px[2],py[2],pz[2],d0[2],d0err[2];
-
   AliESDtrack *postrack = (AliESDtrack*)twoTrackArray->UncheckedAt(0);
   AliESDtrack *negtrack = (AliESDtrack*)twoTrackArray->UncheckedAt(1);
 
@@ -908,11 +954,11 @@ AliAODRecoDecayHF2Prong *AliAnalysisVertexingHF::Make2Prong(
     AliDebug(2," candidate didn't pass mass cut");
     return 0x0;    
   }
-  
   // primary vertex to be used by this candidate
   AliAODVertex *primVertexAOD  = PrimaryVertex(twoTrackArray,event);
   if(!primVertexAOD) return 0x0;
 
+
   Double_t d0z0[2],covd0z0[3];
   postrack->PropagateToDCA(primVertexAOD,fBzkG,kVeryBig,d0z0,covd0z0);
   d0[0] = d0z0[0];
@@ -942,7 +988,7 @@ AliAODRecoDecayHF2Prong *AliAnalysisVertexingHF::Make2Prong(
   //if(fDebug && fDstar) printf("   %d\n",(Int_t)okD0fromDstar);
 
   // remove the primary vertex (was used only for selection)
-  if(!fRecoPrimVtxSkippingTrks && !fRmTrksFromPrimVtx) {
+  if(!fRecoPrimVtxSkippingTrks && !fRmTrksFromPrimVtx && !fMixEvent) {
     the2Prong->UnsetOwnPrimaryVtx();
   }
   
@@ -1041,7 +1087,7 @@ AliAODRecoDecayHF3Prong* AliAnalysisVertexingHF::Make3Prong(
   }
   //if(fDebug) printf("ok3Prong: %d\n",(Int_t)ok3Prong);
 
-  if(!fRecoPrimVtxSkippingTrks && !fRmTrksFromPrimVtx) {
+  if(!fRecoPrimVtxSkippingTrks && !fRmTrksFromPrimVtx && !fMixEvent) {
     the3Prong->UnsetOwnPrimaryVtx();
   }
 
@@ -1149,7 +1195,7 @@ AliAODRecoDecayHF4Prong* AliAnalysisVertexingHF::Make4Prong(
   Int_t checkD0,checkD0bar;
   ok4Prong=the4Prong->SelectD0(fD0to4ProngsCuts,checkD0,checkD0bar);
 
-  if(!fRecoPrimVtxSkippingTrks && !fRmTrksFromPrimVtx) {
+  if(!fRecoPrimVtxSkippingTrks && !fRmTrksFromPrimVtx && !fMixEvent) {
     the4Prong->UnsetOwnPrimaryVtx();
   }
 
@@ -1538,7 +1584,7 @@ Bool_t AliAnalysisVertexingHF::SelectInvMass(Int_t decay,
 //-----------------------------------------------------------------------------
 void AliAnalysisVertexingHF::SelectTracksAndCopyVertex(AliVEvent *event,
                                   TObjArray &seleTrksArray,Int_t &nSeleTrks,
-                                                      UChar_t *seleFlags)
+                                  UChar_t *seleFlags,Int_t *evtNumber)
 {
   // Apply single-track preselection.
   // Fill a TObjArray with selected tracks (for displaced vertices or
@@ -1573,7 +1619,8 @@ void AliAnalysisVertexingHF::SelectTracksAndCopyVertex(AliVEvent *event,
  
   // transfer ITS tracks from event to arrays
   for(Int_t i=0; i<entries; i++) {
-    AliVTrack *track = (AliVTrack*)event->GetTrack(i);
+    AliVTrack *track;
+    track = (AliVTrack*)event->GetTrack(i);
 
     // TEMPORARY: check that the cov matrix is there
     Double_t covtest[21];
@@ -1598,6 +1645,25 @@ void AliAnalysisVertexingHF::SelectTracksAndCopyVertex(AliVEvent *event,
 
     // single track selection
     okDisplaced=kFALSE; okSoftPi=kFALSE;
+    if(fMixEvent){
+      evtNumber[i]=((AliMixedEvent*)event)->EventIndex(i);
+      const AliVVertex* eventVtx=((AliMixedEvent*)event)->GetEventVertex(i);
+      Double_t vtxPos[3],primPos[3],primCov[6],trasl[3];
+      eventVtx->GetXYZ(vtxPos);
+      vprimary->GetXYZ(primPos);
+      eventVtx->GetCovarianceMatrix(primCov);
+      for(Int_t ind=0;ind<3;ind++){
+       trasl[ind]=vtxPos[ind]-primPos[ind];
+      }
+      
+      Bool_t isTransl=esdt->Translate(trasl,primCov);
+      if(!isTransl) {
+       delete esdt;
+       esdt = NULL;
+       continue;
+      }
+    }
+
     if(SingleTrkCuts(esdt,okDisplaced,okSoftPi)) {
       seleTrksArray.AddLast(esdt);
       seleFlags[nSeleTrks]=0;
index 8cc88fa..ba4c5ad 100644 (file)
@@ -8,7 +8,7 @@
 //            Reconstruction of heavy-flavour decay candidates
 //      
 //  Origin: E.Bruna, G.E.Bruno, A.Dainese, F.Prino, R.Romita, X.M.Zhang
-//  Contact: andrea.dainese@lnl.infn.it
+//  Contact: andrea.dainese@pd.infn.it
 //-------------------------------------------------------------------------
 
 #include <TNamed.h>
@@ -57,15 +57,24 @@ class AliAnalysisVertexingHF : public TNamed {
   void SetDstarOff() { fDstar=kFALSE; }
   void SetLikeSignOn() { fLikeSign=kTRUE; }
   void SetLikeSignOff() { fLikeSign=kFALSE; }
+  void SetMixEventOn() { fMixEvent=kTRUE; }
+  void SetMixEventOff() { fMixEvent=kFALSE; }
+  void SetInputAOD() { fInputAOD=kTRUE; }
   Bool_t GetD0toKpi() { return fD0toKpi; }
   Bool_t GetJPSItoEle() { return fJPSItoEle; }
   Bool_t Get3Prong() { return f3Prong; }
   Bool_t Get4Prong() { return f4Prong; }
   Bool_t GetDstar()  { return fDstar; }
   Bool_t GetLikeSign() { return fLikeSign; }
+  Bool_t GetMixEvent() { return fMixEvent; }
+  Bool_t GetInputAOD() { return fInputAOD; }
+  Bool_t GetRecoPrimVtxSkippingTrks() {return fRecoPrimVtxSkippingTrks;}
+  Bool_t GetRmTrksFromPrimVtx(){return fRmTrksFromPrimVtx;}
   void SetFindVertexForDstar(Bool_t vtx=kTRUE) { fFindVertexForDstar=vtx; }
   void SetRecoPrimVtxSkippingTrks() 
     { fRecoPrimVtxSkippingTrks=kTRUE; fRmTrksFromPrimVtx=kFALSE;}
+  void UnsetRecoPrimVtxSkippingTrks()
+    { fRecoPrimVtxSkippingTrks=kFALSE; fRmTrksFromPrimVtx=kFALSE;}
   void SetRmTrksFromPrimVtx() 
     {fRmTrksFromPrimVtx=kTRUE; fRecoPrimVtxSkippingTrks=kFALSE; }
   void SetTrackFilter(AliAnalysisFilter* trackF) { fTrackFilter = trackF; }
@@ -154,6 +163,7 @@ class AliAnalysisVertexingHF : public TNamed {
   Bool_t f4Prong;    // D0->Kpipipi
   Bool_t fDstar;     // D*->D0pi
   Bool_t fLikeSign;  // Like-sign pairs
+  Bool_t fMixEvent; // event mixing
 
   // single-track cuts
   AliAnalysisFilter *fTrackFilter; //  Track Filter for displaced vertices
@@ -288,11 +298,11 @@ class AliAnalysisVertexingHF : public TNamed {
                       Double_t *px,Double_t *py,Double_t *pz) const;
   void   SelectTracksAndCopyVertex(AliVEvent *event,
                                   TObjArray &seleTrksArray,Int_t &nSeleTrks,
-                                  UChar_t *seleFlags);
+                                  UChar_t *seleFlags,Int_t *evtNumber);
   void   SetPrimaryVertex(AliESDVertex *v1) { fV1 = v1; }
   Bool_t SingleTrkCuts(AliESDtrack *trk,Bool_t &okDisplaced,Bool_t &okSoftPi) const;
   //
-  ClassDef(AliAnalysisVertexingHF,11);  // Reconstruction of HF decay candidates
+  ClassDef(AliAnalysisVertexingHF,12);  // Reconstruction of HF decay candidates
 };