]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Update of the TOF code, see the presentation at
authorhristov <Peter.Hristov@cern.ch>
Thu, 16 Jan 2014 15:34:27 +0000 (16:34 +0100)
committerhristov <Peter.Hristov@cern.ch>
Thu, 16 Jan 2014 15:34:27 +0000 (16:34 +0100)
https://indico.cern.ch/conferenceDisplay.py?confId=291297

25 files changed:
ANALYSIS/ESDfilter/AliAnalysisTaskESDfilter.cxx
STEER/CMakelibESD.pkg
STEER/CMakelibSTEERBase.pkg
STEER/ESD/AliESDEvent.cxx
STEER/ESD/AliESDEvent.h
STEER/ESD/AliESDTOFcluster.cxx [new file with mode: 0644]
STEER/ESD/AliESDTOFcluster.h [new file with mode: 0644]
STEER/ESD/AliESDpid.cxx
STEER/ESD/AliESDtrack.cxx
STEER/ESD/AliESDtrack.h
STEER/ESD/AliKalmanTrack.cxx
STEER/ESD/AliKalmanTrack.h
STEER/ESDLinkDef.h
STEER/STEERBase/AliVTOFcluster.cxx [new file with mode: 0644]
STEER/STEERBase/AliVTOFcluster.h [new file with mode: 0644]
STEER/STEERBaseLinkDef.h
TOF/AliTOFReconstructor.cxx
TOF/AliTOFtrack.cxx
TOF/AliTOFtracker.cxx
TOF/AliTOFtracker.h
TOF/AliTOFtrackerV1.cxx
TOF/AliTOFtrackerV2.cxx [new file with mode: 0644]
TOF/AliTOFtrackerV2.h [new file with mode: 0644]
TOF/CMakelibTOFrec.pkg
TOF/TOFrecLinkDef.h

index 3ccdef218a0cd6c74a7228e907974e9ce12edc93..a1ea831db0d48189a94d3a7d3bfe90b139d01505 100644 (file)
@@ -2556,7 +2556,7 @@ void AliAnalysisTaskESDfilter::SetDetectorRawSignals(AliAODPid *aodpid, AliESDtr
  aodpid->SetTRDChi2(track->GetTRDchi2());
 
  //TOF PID  
- Double_t times[AliPID::kSPECIES]; track->GetIntegratedTimes(times);
+ Double_t times[AliPID::kSPECIESC]; track->GetIntegratedTimes(times);
  aodpid->SetIntegratedTimes(times);
 
    //  Float_t tzeroTrack = fESDpid->GetTOFResponse().GetStartTime(track->P());
index 30fc5dfc18166f45aa2a30672e0e54710c8260c3..2263b92d3518ba42266c88e518169e511a845d83 100644 (file)
@@ -69,6 +69,7 @@ set ( SRCS
     ESD/AliESDCosmicTrack.cxx
     ESD/AliV0vertexer.cxx 
     ESD/AliCascadeVertexer.cxx 
+    ESD/AliESDTOFcluster.cxx
     )
 
 string( REPLACE ".cxx" ".h" HDRS "${SRCS}")
index c40a639f0dbe05d20e959058bcdaaff4fe172692..b4610ed49242baab797aef00c3dafb0c1a70225c 100644 (file)
@@ -92,6 +92,7 @@ set ( SRCS
     STEERBase/AliVTrdTracklet.cxx
     STEERBase/AliGenEventHeaderTunedPbPb.cxx
     STEERBase/AliDummyHandler.cxx
+    STEERBase/AliVTOFcluster.cxx
   )
 
 string(REPLACE ".cxx" ".h" HDRS  "${SRCS}")
index 7a36370614eb6bf394c06542ba47ac9134ea94b1..4e873f35f4ae915d5610c4af65e092c87228c461 100644 (file)
@@ -171,7 +171,9 @@ AliESDEvent::AliESDEvent():
   fEventplane(0),
   fDetectorStatus(0xFFFFFFFF),
   fDAQDetectorPattern(0xFFFF),
-  fDAQAttributes(0xFFFF)
+  fDAQAttributes(0xFFFF),
+  fNTOFclusters(0),
+  fTOFcluster(new TObjArray(1))
   #ifdef MFT_UPGRADE
 //  , fESDMFT(0)
   #endif
@@ -223,7 +225,10 @@ AliESDEvent::AliESDEvent(const AliESDEvent& esd):
   fEventplane(new AliEventplane(*esd.fEventplane)),
   fDetectorStatus(esd.fDetectorStatus),
   fDAQDetectorPattern(esd.fDAQDetectorPattern),
-  fDAQAttributes(esd.fDAQAttributes)
+  fDAQAttributes(esd.fDAQAttributes),
+  fNTOFclusters(esd.fNTOFclusters),
+  //  fTOFcluster(esd.fTOFcluster)
+  fTOFcluster(new TObjArray(*(esd.fTOFcluster)))
   #ifdef MFT_UPGRADE
 //  , fESDMFT(new AliESDMFT(*esd.fESDMFT))
   #endif
@@ -269,14 +274,13 @@ AliESDEvent::AliESDEvent(const AliESDEvent& esd):
 //  AddObject(fESDMFT);
   #endif
   GetStdContent();
-
 }
 
 //______________________________________________________________________________
 AliESDEvent & AliESDEvent::operator=(const AliESDEvent& source) {
 
   // Assignment operator
-
+  printf("operator = ESD\n");
   if(&source == this) return *this;
   AliVEvent::operator=(source);
 
@@ -370,6 +374,10 @@ AliESDEvent & AliESDEvent::operator=(const AliESDEvent& source) {
   fDetectorStatus = source.fDetectorStatus;
   fDAQDetectorPattern = source.fDAQDetectorPattern;
   fDAQAttributes = source.fDAQAttributes;
+  fNTOFclusters = source.fNTOFclusters;
+
+  *fTOFcluster = *source.fTOFcluster;
+  //  fTOFcluster = new TObjArray(*(source.fTOFcluster));
 
   return *this;
 }
@@ -393,6 +401,11 @@ AliESDEvent::~AliESDEvent()
   if (fCentrality) delete fCentrality;
   if (fEventplane) delete fEventplane;
   
+
+  if(fTOFcluster){
+    fTOFcluster->Clear();
+    delete fTOFcluster;
+  }
 }
 
 void AliESDEvent::Copy(TObject &obj) const {
@@ -1640,9 +1653,12 @@ void AliESDEvent::WriteToTree(TTree* tree) const {
       tree->Bronch(branchname, obj->ClassName(), fESDObjects->GetObjectRef(obj),kBufsize, splitLevel);
     }
   }
+
   tree->Branch("fDetectorStatus",(void*)&fDetectorStatus,"fDetectorStatus/l");
   tree->Branch("fDAQDetectorPattern",(void*)&fDAQDetectorPattern,"fDAQDetectorPattern/i");
   tree->Branch("fDAQAttributes",(void*)&fDAQAttributes,"fDAQAttributes/i");
+  tree->Branch("fNTOFclusters",(void *) &fNTOFclusters,"fNTOFclusters/i");
+  tree->Branch("fTOFcluster","TObjArray",(void *) &fTOFcluster);
 }
 
 
@@ -1745,6 +1761,8 @@ void AliESDEvent::ReadFromTree(TTree *tree, Option_t* opt){
       tree->SetBranchAddress("fDetectorStatus",&fDetectorStatus); //PH probably redundant
       tree->SetBranchAddress("fDAQDetectorPattern",&fDAQDetectorPattern);
       tree->SetBranchAddress("fDAQAttributes",&fDAQAttributes);
+      if(tree->GetBranch("fNTOFclusters")) tree->SetBranchAddress("fNTOFclusters",(UInt_t *) &fNTOFclusters);
+      if(tree->GetBranch("fTOFcluster")) tree->SetBranchAddress("fTOFcluster",&fTOFcluster);
       GetStdContent(); 
       fOldMuonStructure = fESDObjects->TestBit(BIT(23));
       fConnected = true;
@@ -1811,6 +1829,9 @@ void AliESDEvent::ReadFromTree(TTree *tree, Option_t* opt){
     tree->SetBranchAddress("fDetectorStatus",&fDetectorStatus);
     tree->SetBranchAddress("fDAQDetectorPattern",&fDAQDetectorPattern);
     tree->SetBranchAddress("fDAQAttributes",&fDAQAttributes);
+    if(tree->GetBranch("fNTOFclusters")) tree->SetBranchAddress("fNTOFclusters",(UInt_t *) &fNTOFclusters);
+    if(tree->GetBranch("fTOFcluster")) tree->SetBranchAddress("fTOFcluster",&fTOFcluster);
+
     GetStdContent();
     // when reading back we are not owner of the list 
     // must not delete it
@@ -1849,6 +1870,9 @@ void AliESDEvent::ReadFromTree(TTree *tree, Option_t* opt){
     tree->SetBranchAddress("fDetectorStatus",&fDetectorStatus);
     tree->SetBranchAddress("fDAQDetectorPattern",&fDAQDetectorPattern);
     tree->SetBranchAddress("fDAQAttributes",&fDAQAttributes);
+    if(tree->GetBranch("fNTOFclusters")) tree->SetBranchAddress("fNTOFclusters",(UInt_t *) &fNTOFclusters);
+    if(tree->GetBranch("fTOFcluster")) tree->SetBranchAddress("fTOFcluster",&fTOFcluster);
+
     GetStdContent();
     // when reading back we are not owner of the list 
     // must not delete it
@@ -2172,3 +2196,46 @@ Float_t AliESDEvent::GetVZEROEqMultiplicity(Int_t i) const
 
   return (fESDVZERO->GetMultiplicity(i)/factor);
 }
+
+void AliESDEvent::SetTOFcluster(Int_t ntofclusters,AliESDTOFcluster *cluster,Int_t *mapping){
+  fNTOFclusters = 0;
+
+  fTOFcluster->Clear();
+  fTOFcluster->Expand(1);      
+      
+  for(Int_t i=0;i < ntofclusters;i++){
+
+    if(cluster[i].GetNMatchableTracks() || !mapping){
+      fTOFcluster->Expand(fNTOFclusters+1);      
+      fTOFcluster->AddAt(&cluster[i],fNTOFclusters);
+      if(mapping)
+       mapping[i] = fNTOFclusters;
+      fNTOFclusters++;
+    }
+  }
+  if(mapping)
+    printf("TOF cluster before of matching = %i , after = %i\n",ntofclusters,fNTOFclusters);
+   
+
+}
+void AliESDEvent::SetTOFcluster(Int_t ntofclusters,AliESDTOFcluster *cluster[],Int_t *mapping){
+  fNTOFclusters = 0;
+
+  fTOFcluster->Clear();
+  fTOFcluster->Expand(1);      
+      
+  for(Int_t i=0;i < ntofclusters;i++){
+
+    if(cluster[i]->GetNMatchableTracks() || !mapping){
+      fTOFcluster->Expand(fNTOFclusters+1);      
+      fTOFcluster->AddAt(cluster[i],fNTOFclusters);
+      if(mapping)
+       mapping[i] = fNTOFclusters;
+      fNTOFclusters++;
+    }
+  }
+  if(mapping)
+    printf("TOF cluster before of matching = %i , after = %i\n",ntofclusters,fNTOFclusters);
+   
+
+}
index e74bacba09d7d57823d62148ebe0512a43a62f5c..f1f7c75fe1459c1c7c2478a03d3a63fedc4bccc7 100644 (file)
@@ -19,6 +19,7 @@
 #include <TObject.h>
 #include <TTree.h>
 #include <TArrayF.h>
+#include <TObjArray.h>
 
 
 #include "AliVEvent.h"
@@ -42,6 +43,8 @@
 
 #include "AliESDVZERO.h"
 #include "AliESDTrdTrack.h"
+#include "AliESDTOFcluster.h"
+
 #ifdef MFT_UPGRADE
 //#include "AliESDMFT.h"
 #endif
@@ -302,7 +305,10 @@ public:
   AliTOFHeader *GetTOFHeader() const {return fTOFHeader;}
   Float_t GetEventTimeSpread() const {if (fTOFHeader) return fTOFHeader->GetT0spread(); else return 0.;}
   Float_t GetTOFTimeResolution() const {if (fTOFHeader) return fTOFHeader->GetTOFResolution(); else return 0.;}
-
+  TObjArray *GetTOFcluster() const {return fTOFcluster;}
+  void SetTOFcluster(Int_t ntofclusters,AliESDTOFcluster *cluster,Int_t *mapping=NULL);
+  void SetTOFcluster(Int_t ntofclusters,AliESDTOFcluster *cluster[],Int_t *mapping=NULL);
+  Int_t GetNTOFclusters() const {return fNTOFclusters;}
 
   void SetMultiplicity(const AliMultiplicity *mul);
 
@@ -581,7 +587,10 @@ protected:
   UInt_t fDAQDetectorPattern; // Detector pattern from DAQ: bit 0 is SPD, bit 4 is TPC, etc. See event.h
   UInt_t fDAQAttributes; // Third word of attributes from DAQ: bit 7 corresponds to HLT decision 
 
-  ClassDef(AliESDEvent,19)  //ESDEvent class 
+  Int_t fNTOFclusters;     //! N TOF clusters matchable
+  TObjArray *fTOFcluster; //! TOF clusters
+
+  ClassDef(AliESDEvent,20)  //ESDEvent class 
 };
 #endif 
 
diff --git a/STEER/ESD/AliESDTOFcluster.cxx b/STEER/ESD/AliESDTOFcluster.cxx
new file mode 100644 (file)
index 0000000..c4e96eb
--- /dev/null
@@ -0,0 +1,444 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, 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.                  * 
+ **************************************************************************/
+
+/* $Id:  $ */
+
+//_________________________________________________________________________//
+//_________________________________________________________________________//
+
+#include "AliESDTOFcluster.h"
+
+ClassImp(AliESDTOFcluster)
+
+AliESDTOFcluster::AliESDTOFcluster() :
+  AliVTOFcluster(),
+  fNTOFhits(1),
+  fClusterIndex(new TArrayI(1)),
+  fTOFchannel(new TArrayI(1)),
+  fTime(new TArrayF(1)),
+  fTimeRaw(new TArrayF(1)),
+  fTOT(new TArrayF(1)),
+  fTOFlabel(new TArrayI(3)),
+  fDeltaBC(new TArrayI(1)),
+  fL0L1Latency(new TArrayI(1)),
+  fStatus(0),
+  fZ(0),
+  fPhi(0),
+  fR(0),
+  fNmatchableTracks(0),
+  fTrackIndex(new TArrayI(1)),
+  fDx(new TArrayF(1)),
+  fDy(new TArrayF(1)),
+  fDz(new TArrayF(1)),
+  fTrackLength(new TArrayF(1)),
+  fIntegratedTimes(new TArrayD(9))
+{
+  //
+  // default ctor
+  //
+}
+
+AliESDTOFcluster::AliESDTOFcluster(Int_t clusterIndex,Int_t tofChannel,Float_t tofTime,Float_t timeRaw,Float_t tofTot,Int_t label[3],Int_t deltaBC,Int_t l0l1Latency,
+                                  Bool_t status,Float_t zClu,Float_t phiClu,Float_t rClu,
+                                  Int_t trackIndex,Float_t dX,Float_t dY,Float_t dZ,Float_t length,Double_t expTimes[9]) :
+  AliVTOFcluster(),
+  fNTOFhits(1),
+  fClusterIndex(new TArrayI(1)),
+  fTOFchannel(new TArrayI(1)),
+  fTime(new TArrayF(1)),
+  fTimeRaw(new TArrayF(1)),
+  fTOT(new TArrayF(1)),
+  fTOFlabel(new TArrayI(3)),
+  fDeltaBC(new TArrayI(1)),
+  fL0L1Latency(new TArrayI(1)),
+  fStatus(status),
+  fZ(zClu),
+  fPhi(phiClu),
+  fR(rClu),
+  fNmatchableTracks(1),
+  fTrackIndex(new TArrayI(1)),
+  fDx(new TArrayF(1)),
+  fDy(new TArrayF(1)),
+  fDz(new TArrayF(1)),
+  fTrackLength(new TArrayF(1)),
+  fIntegratedTimes(new TArrayD(9))
+{
+  //
+  // Constructor of AliESDTOFcluster object
+  //
+  fClusterIndex->AddAt(clusterIndex,0);
+  fTOFchannel->AddAt(tofChannel,0);
+  fTime->AddAt(tofTime,0);
+  fTimeRaw->AddAt(timeRaw,0);
+  fTOT->AddAt(tofTot,0);
+  fTOFlabel->AddAt(label[0],0);
+  fTOFlabel->AddAt(label[1],1);
+  fTOFlabel->AddAt(label[2],2);
+  fDeltaBC->AddAt(deltaBC,0);
+  fL0L1Latency->AddAt(l0l1Latency,0);
+  fTrackIndex->AddAt(trackIndex,0);
+  fDx->AddAt(dX,0);
+  fDy->AddAt(dY,0);
+  fDz->AddAt(dZ,0);
+  fTrackLength->AddAt(length,0);
+  for (Int_t ii=0; ii<9; ii++) fIntegratedTimes->AddAt(expTimes[ii],ii);
+
+}
+
+AliESDTOFcluster::AliESDTOFcluster(Int_t clusterIndex,Int_t tofChannel,Float_t tofTime,Float_t timeRaw,Float_t tofTot,Int_t label[3],Int_t deltaBC,Int_t l0l1Latency,
+                                  Bool_t status,Float_t zClu,Float_t phiClu,Float_t rClu) :
+  AliVTOFcluster(),
+  fNTOFhits(1),
+  fClusterIndex(new TArrayI(1)),
+  fTOFchannel(new TArrayI(1)),
+  fTime(new TArrayF(1)),
+  fTimeRaw(new TArrayF(1)),
+  fTOT(new TArrayF(1)),
+  fTOFlabel(new TArrayI(3)),
+  fDeltaBC(new TArrayI(1)),
+  fL0L1Latency(new TArrayI(1)),
+  fStatus(status),
+  fZ(zClu),
+  fPhi(phiClu),
+  fR(rClu),
+  fNmatchableTracks(0),
+  fTrackIndex(new TArrayI(1)),
+  fDx(new TArrayF(1)),
+  fDy(new TArrayF(1)),
+  fDz(new TArrayF(1)),
+  fTrackLength(new TArrayF(1)),
+  fIntegratedTimes(new TArrayD(9))
+{
+  //
+  // Constructor of AliESDTOFcluster object
+  //
+  fClusterIndex->AddAt(clusterIndex,0);
+  fTOFchannel->AddAt(tofChannel,0);
+  fTime->AddAt(tofTime,0);
+  fTimeRaw->AddAt(timeRaw,0);
+  fTOT->AddAt(tofTot,0);
+  fTOFlabel->AddAt(label[0],0);
+  fTOFlabel->AddAt(label[1],1);
+  fTOFlabel->AddAt(label[2],2);
+  fDeltaBC->AddAt(deltaBC,0);
+  fL0L1Latency->AddAt(l0l1Latency,0);
+}
+
+AliESDTOFcluster::AliESDTOFcluster(const AliESDTOFcluster & source) :
+  AliVTOFcluster(source),
+  fNTOFhits(source.fNTOFhits),
+  fClusterIndex(new TArrayI(source.fNTOFhits)),
+  fTOFchannel(new TArrayI(source.fNTOFhits)),
+  fTime(new TArrayF(source.fNTOFhits)),
+  fTimeRaw(new TArrayF(source.fNTOFhits)),
+  fTOT(new TArrayF(source.fNTOFhits)),
+  fTOFlabel(new TArrayI(3*source.fNTOFhits)),
+  fDeltaBC(new TArrayI(source.fNTOFhits)),
+  fL0L1Latency(new TArrayI(source.fNTOFhits)),
+  fStatus(source.fStatus),
+  fZ(source.fZ),
+  fPhi(source.fPhi),
+  fR(source.fR),
+  fNmatchableTracks(source.fNmatchableTracks),
+  fTrackIndex(NULL),
+  fDx(NULL),
+  fDy(NULL),
+  fDz(NULL),
+  fTrackLength(NULL),
+  fIntegratedTimes(NULL)
+{
+  // 
+  // copy ctor for AliESDTOFcluster object
+  //
+
+  printf("Copy constructor (matchable tracks = %i)\n",fNmatchableTracks);
+
+  for(Int_t i=0;i < source.fNTOFhits;i++){
+    fClusterIndex->AddAt((*source.fClusterIndex)[i],i);
+    fTOFchannel->AddAt((*source.fTOFchannel)[i],i);
+    fTime->AddAt((*source.fTime)[i],i);
+    fTimeRaw->AddAt((*source.fTimeRaw)[i],i);
+    fTOT->AddAt((*source.fTOT)[i],i);
+    fTOFlabel->AddAt((*source.fTOFlabel)[0+3*i],0+3*i);
+    fTOFlabel->AddAt((*source.fTOFlabel)[1+3*i],1+3*i);
+    fTOFlabel->AddAt((*source.fTOFlabel)[2+3*i],2+3*i);
+    fDeltaBC->AddAt((*source.fDeltaBC)[i],i);
+    fL0L1Latency->AddAt((*source.fL0L1Latency)[i],i);
+  }
+
+  if (fNmatchableTracks>0) {
+    fTrackIndex = new TArrayI(fNmatchableTracks);
+    fDx = new TArrayF(fNmatchableTracks);
+    fDy = new TArrayF(fNmatchableTracks);
+    fDz = new TArrayF(fNmatchableTracks);
+    fTrackLength = new TArrayF(fNmatchableTracks);
+    fIntegratedTimes = new TArrayD(fNmatchableTracks*9);
+    for(Int_t i=0;i<fNmatchableTracks;i++) {
+      (*fTrackIndex)[i]=source.fTrackIndex->At(i);
+      (*fDx)[i]=source.fDx->At(i);
+      (*fDy)[i]=source.fDy->At(i);
+      (*fDz)[i]=source.fDz->At(i);
+      (*fTrackLength)[i]=source.fTrackLength->At(i);
+      for(Int_t j=0;j<9;j++)
+       (*fIntegratedTimes)[i*9+j]=source.fIntegratedTimes->At(i*9+j);
+    }
+  }
+  else{
+    fTrackIndex = new TArrayI(1);
+    fDx = new TArrayF(1);
+    fDy = new TArrayF(1);
+    fDz = new TArrayF(1);
+    fTrackLength = new TArrayF(1);
+    fIntegratedTimes = new TArrayD(9);
+  }
+
+  printf("END -> Copy constructor\n");
+
+}
+
+AliESDTOFcluster & AliESDTOFcluster::operator=(const AliESDTOFcluster & source)
+{
+  // 
+  // copy ctor for AliESDTOFcluster object
+  //
+  if (this == &source) return *this;
+  AliVTOFcluster::operator=(source);
+
+  fNTOFhits = source.fNTOFhits;
+
+  if(fClusterIndex) delete fClusterIndex;
+  if(fTOFchannel->GetArray()) delete fTOFchannel;
+  if(fTime) delete fTime;
+  if(fTimeRaw) delete fTimeRaw;
+  if(fTOT) delete fTOT;
+  if(fTOFlabel) delete fTOFlabel;
+  if(fDeltaBC) delete fDeltaBC;
+  if(fL0L1Latency) delete fL0L1Latency;
+
+  if(fNTOFhits){
+    fClusterIndex = new TArrayI(source.fNTOFhits);
+    fTOFchannel = new TArrayI(source.fNTOFhits);
+    fTime = new TArrayF(source.fNTOFhits);
+    fTimeRaw = new TArrayF(source.fNTOFhits);
+    fTOT = new TArrayF(source.fNTOFhits);
+    fTOFlabel = new TArrayI(3*source.fNTOFhits);
+    fDeltaBC = new TArrayI(source.fNTOFhits);
+    fL0L1Latency = new TArrayI(source.fNTOFhits);
+      
+    
+    for(Int_t i=0;i < source.fNTOFhits;i++){
+      fClusterIndex->AddAt(source.fClusterIndex->At(i),i);
+      fTOFchannel->AddAt(source.fTOFchannel->At(i),i);
+      fTime->AddAt(source.fTime->At(i),i);
+      fTimeRaw->AddAt(source.fTimeRaw->At(i),i);
+      fTOT->AddAt(source.fTOT->At(i),i);
+      fTOFlabel->AddAt(source.fTOFlabel->At(0+3*i),0+3*i);
+      fTOFlabel->AddAt(source.fTOFlabel->At(1+3*i),1+3*i);
+      fTOFlabel->AddAt(source.fTOFlabel->At(2+3*i),2+3*i);
+      fDeltaBC->AddAt(source.fDeltaBC->At(i),i);
+      fL0L1Latency->AddAt(source.fL0L1Latency->At(i),i);
+    }
+  }
+  else{
+    fClusterIndex = new TArrayI(1);
+    fTOFchannel = new TArrayI(1);
+    fTime = new TArrayF(1);
+    fTimeRaw = new TArrayF(1);
+    fTOT = new TArrayF(1);
+    fTOFlabel = new TArrayI(3);
+    fDeltaBC = new TArrayI(1);
+    fL0L1Latency = new TArrayI(1);    
+  }
+
+  fStatus=source.fStatus;
+  fZ=source.fZ;
+  fPhi=source.fPhi;
+  fR=source.fR;
+
+  if(fTrackIndex) delete fTrackIndex;
+  if(fDx) delete fDx;
+  if(fDy) delete fDy;
+  if(fDz) delete fDz;
+  if(fTrackLength) delete fTrackLength;
+  if(fIntegratedTimes) delete fIntegratedTimes;
+
+  fNmatchableTracks=source.fNmatchableTracks;
+
+  if (fNmatchableTracks>0) {
+    fTrackIndex = new TArrayI(fNmatchableTracks);
+    fDx = new TArrayF(fNmatchableTracks);
+    fDy = new TArrayF(fNmatchableTracks);
+    fDz = new TArrayF(fNmatchableTracks);
+    fTrackLength = new TArrayF(fNmatchableTracks);
+    fIntegratedTimes = new TArrayD(fNmatchableTracks*9);
+    for(Int_t i=0;i<fNmatchableTracks;i++) {
+      (*fTrackIndex)[i]=source.fTrackIndex->At(i);
+      (*fDx)[i]=source.fDx->At(i);
+      (*fDy)[i]=source.fDy->At(i);
+      (*fDz)[i]=source.fDz->At(i);
+      (*fTrackLength)[i]=source.fTrackLength->At(i);
+      for(Int_t j=0;j<9;j++)
+       (*fIntegratedTimes)[i*9+j]=source.fIntegratedTimes->At(i*9+j);
+    }
+  } else {
+    fTrackIndex= new TArrayI(1);
+    fDx = new TArrayF(1);
+    fDy = new TArrayF(1);
+    fDz = new TArrayF(1);
+    fTrackLength = new TArrayF(1);
+    fIntegratedTimes = new TArrayD(9);
+  }
+
+  return *this;
+}
+
+Int_t AliESDTOFcluster::Update(Int_t trackIndex,Float_t dX,Float_t dY,Float_t dZ,Float_t length,Double_t expTimes[9])
+{
+
+  if (fNmatchableTracks==0) {
+    fNmatchableTracks++;
+    fTrackIndex = new TArrayI(fNmatchableTracks);
+    fDx = new TArrayF(fNmatchableTracks);
+    fDy = new TArrayF(fNmatchableTracks);
+    fDz = new TArrayF(fNmatchableTracks);
+    fTrackLength = new TArrayF(fNmatchableTracks);
+    fIntegratedTimes = new TArrayD(fNmatchableTracks*9);
+    fTrackIndex->AddAt(trackIndex,fNmatchableTracks-1);
+    fDx->AddAt(dX,fNmatchableTracks-1);
+    fDy->AddAt(dY,fNmatchableTracks-1);
+    fDz->AddAt(dZ,fNmatchableTracks-1);
+    fTrackLength->AddAt(length,fNmatchableTracks-1);
+    for (Int_t ii=0; ii<9; ii++) fIntegratedTimes->AddAt(expTimes[ii],(fNmatchableTracks-1)*9+ii);
+
+  } else {
+    Bool_t updatedOneAlreadyStored = kFALSE;
+    for (Int_t ii=0; ii<fNmatchableTracks; ii++) {
+      if (trackIndex==fTrackIndex->At(ii)) {
+       // evitare di mettere piu' trackPoints della stessa traccia,
+       // scegliere solo quello piu' vicino al piano centrale del pad
+       updatedOneAlreadyStored=kTRUE;
+//     if (TMath::Abs(dX)<TMath::Abs(fDx->At(ii))) {
+//       fDx->AddAt(dX,ii);
+//       fDy->AddAt(dY,ii);
+//       fDz->AddAt(dZ,ii);
+//       fTrackLength->AddAt(length,ii);
+//       for (Int_t jj=0; jj<9; jj++) fIntegratedTimes->AddAt(expTimes[jj],ii*9+jj);
+//     }
+       return 1;
+      }
+    }
+    if (!updatedOneAlreadyStored) {
+      fNmatchableTracks++;
+      fTrackIndex->Set(fNmatchableTracks);
+      fDx->Set(fNmatchableTracks);
+      fDy->Set(fNmatchableTracks);
+      fDz->Set(fNmatchableTracks);
+      fTrackLength->Set(fNmatchableTracks);
+      fIntegratedTimes->Set(fNmatchableTracks*9);
+      fTrackIndex->AddAt(trackIndex,fNmatchableTracks-1);
+      fDx->AddAt(dX,fNmatchableTracks-1);
+      fDy->AddAt(dY,fNmatchableTracks-1);
+      fDz->AddAt(dZ,fNmatchableTracks-1);
+      fTrackLength->AddAt(length,fNmatchableTracks-1);
+      for (Int_t jj=0; jj<9; jj++) fIntegratedTimes->AddAt(expTimes[jj],(fNmatchableTracks-1)*9+jj);
+    }
+  }
+  return 0;
+}
+
+AliESDTOFcluster::~AliESDTOFcluster()
+{
+  //
+  // dtr
+  //
+  if(fClusterIndex) delete fClusterIndex;
+  if(fTOFchannel) delete fTOFchannel;
+  if(fTime) delete fTime;
+  if(fTimeRaw) delete fTimeRaw;
+  if(fTOT) delete fTOT;
+  if(fTOFlabel) delete fTOFlabel;
+  if(fDeltaBC) delete fDeltaBC;
+  if(fL0L1Latency) delete fL0L1Latency;
+
+  if (fTrackIndex) delete fTrackIndex;
+  if (fDx) delete fDx;
+  if (fDy) delete fDy;
+  if (fDz) delete fDz;
+  if (fTrackLength) delete fTrackLength;
+  if (fIntegratedTimes) delete fIntegratedTimes;
+
+}
+
+void AliESDTOFcluster::AddTOFhit(Int_t clusterIndex,Int_t tofChannel,Float_t tofTime,Float_t timeRaw,Float_t tofTot,Int_t label[3],Int_t deltaBC,Int_t l0l1Latency, Bool_t status,Float_t zClu,Float_t phiClu,Float_t rClu){
+
+  TArrayI *ClusterIndexOld = fClusterIndex;
+  TArrayI *TOFchannelOld = fTOFchannel;
+  TArrayF *TimeOld = fTime;
+  TArrayF *TimeRawOld = fTimeRaw;
+  TArrayF *TOTOld = fTOT;
+  TArrayI *TOFlabelOld = fTOFlabel;
+  TArrayI *DeltaBCOld = fDeltaBC;
+  TArrayI *L0L1LatencyOld = fL0L1Latency;
+  
+  fClusterIndex = new TArrayI(fNTOFhits+1);
+  fTOFchannel = new TArrayI(fNTOFhits+1);
+  fTime = new TArrayF(fNTOFhits+1);
+  fTimeRaw = new TArrayF(fNTOFhits+1);
+  fTOT = new TArrayF(fNTOFhits+1);
+  fTOFlabel = new TArrayI(3*fNTOFhits+3);
+  fDeltaBC = new TArrayI(fNTOFhits+1);
+  fL0L1Latency = new TArrayI(fNTOFhits+1);
+
+  for(Int_t i=0;i < fNTOFhits;i++){
+    fClusterIndex->AddAt(ClusterIndexOld->At(i),i);
+    fTOFchannel->AddAt(TOFchannelOld->At(i),i);
+    fTime->AddAt(TimeOld->At(i),i);
+    fTimeRaw->AddAt(TimeRawOld->At(i),i);
+    fTOT->AddAt(TOTOld->At(i),i);
+    fTOFlabel->AddAt(TOFlabelOld->At(0+3*i),0+3*i);
+    fTOFlabel->AddAt(TOFlabelOld->At(1+3*i),1+3*i);
+    fTOFlabel->AddAt(TOFlabelOld->At(2+3*i),2+3*i);
+    fDeltaBC->AddAt(DeltaBCOld->At(i),i);
+    fL0L1Latency->AddAt(L0L1LatencyOld->At(i),i);
+  }
+  
+  if(ClusterIndexOld) delete ClusterIndexOld;
+  if(TOFchannelOld) delete TOFchannelOld;
+  if(TimeOld) delete TimeOld;
+  if(TimeRawOld) delete TimeRawOld;
+  if(TOTOld) delete TOTOld;
+  if(TOFlabelOld) delete TOFlabelOld;
+  if(DeltaBCOld) delete DeltaBCOld;
+  if(L0L1LatencyOld) delete L0L1LatencyOld;
+
+  fClusterIndex->AddAt(clusterIndex,fNTOFhits);
+  fTOFchannel->AddAt(tofChannel,fNTOFhits);
+  fTime->AddAt(tofTime,fNTOFhits);
+  fTimeRaw->AddAt(timeRaw,0);
+  fTOT->AddAt(tofTot,fNTOFhits);
+  fTOFlabel->AddAt(label[0],3*fNTOFhits+0);
+  fTOFlabel->AddAt(label[1],3*fNTOFhits+1);
+  fTOFlabel->AddAt(label[2],3*fNTOFhits+2);
+  fDeltaBC->AddAt(deltaBC,fNTOFhits);
+  fL0L1Latency->AddAt(l0l1Latency,fNTOFhits);
+
+  if(status){
+    fZ = (fZ*fNTOFhits + zClu)/(fNTOFhits+1);
+    fPhi = (fPhi*fNTOFhits + phiClu)/(fNTOFhits+1);
+    fR = (fR*fNTOFhits + rClu)/(fNTOFhits+1);
+  }
+
+  fNTOFhits++;
+}
diff --git a/STEER/ESD/AliESDTOFcluster.h b/STEER/ESD/AliESDTOFcluster.h
new file mode 100644 (file)
index 0000000..1b89291
--- /dev/null
@@ -0,0 +1,99 @@
+#ifndef ALIESDTOFCLUSTER_H
+#define ALIESDTOFCLUSTER_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id: $ */
+
+//----------------------------------------------------------------------//
+//                                                                      //
+// AliESDTOFcluster Class                                                //
+//                                                                      //
+//----------------------------------------------------------------------//
+
+#include "TArrayI.h"
+#include "TArrayF.h"
+#include "TArrayD.h"
+#include "TMath.h"
+#include <AliVTOFcluster.h>
+
+class AliESDTOFcluster : public AliVTOFcluster {
+
+ public:
+  AliESDTOFcluster();
+  AliESDTOFcluster(Int_t clusterIndex,Int_t tofChannel,Float_t tofTime,Float_t timeRaw,Float_t tofTot,Int_t label[3],Int_t deltaBC,Int_t l0l1Latency,
+                  Bool_t status,Float_t zClu,Float_t phiClu,Float_t rClu,
+                  Int_t trackIndex,Float_t dX,Float_t dY,Float_t dZ,Float_t length,Double_t expTimes[9]);
+  AliESDTOFcluster(Int_t clusterIndex,Int_t tofChannel,Float_t tofTime,Float_t timeRaw,Float_t tofTot,Int_t label[3],Int_t deltaBC,Int_t l0l1Latency,
+                  Bool_t status,Float_t zClu,Float_t phiClu,Float_t rClu);
+  AliESDTOFcluster(const AliESDTOFcluster & source);
+  AliESDTOFcluster & operator=(const AliESDTOFcluster & source);
+  virtual ~AliESDTOFcluster();
+
+  Int_t Update(Int_t trackIndex,Float_t dX,Float_t dY,Float_t dZ,Float_t length,Double_t expTimes[9]);
+
+  Int_t GetClusterIndex() const {return (*fClusterIndex)[0];} // cluster index
+  Int_t GetClusterIndex(Int_t ihit) const {return (*fClusterIndex)[ihit];} // cluster index
+  Int_t GetTOFchannel() const {return (*fTOFchannel)[0];} // TOF channel
+  Int_t GetTOFchannel(Int_t ihit) const {return (*fTOFchannel)[ihit];} // TOF channel
+  Float_t GetTime() const {return (*fTime)[0];}; // TOF time
+  Float_t GetTime(Int_t ihit) const {return (*fTime)[ihit];}; // TOF time
+  Float_t GetTimeRaw() const {return (*fTimeRaw)[0];}; // TOF raw time
+  Float_t GetTimeRaw(Int_t ihit) const {return (*fTimeRaw)[ihit];}; // TOF raw time
+  Float_t GetTOT() const {return (*fTOT)[0];}; // TOF tot
+  Float_t GetTOT(Int_t ihit) const {return (*fTOT)[ihit];}; // TOF tot
+  Float_t GetTOFsignalToT() const {return (*fTOT)[0];}; // TOF tot
+  Float_t GetTOFsignalToT(Int_t ihit) const {return (*fTOT)[ihit];}; // TOF tot
+  Int_t GetLabel(Int_t i=0) const {return i<3 ? (*fTOFlabel)[i] : -999;};
+  Int_t GetLabel(Int_t i,Int_t ihit) const {return i<3 ? (*fTOFlabel)[i+3*ihit] : -999;};
+  Int_t GetDeltaBC() const { return (*fDeltaBC)[0];};
+  Int_t GetDeltaBC(Int_t ihit) const { return (*fDeltaBC)[ihit];};
+  Int_t GetL0L1Latency() const { return (*fL0L1Latency)[0];};
+  Int_t GetL0L1Latency(Int_t ihit) const { return (*fL0L1Latency)[ihit];};
+  Bool_t GetStatus() const {return fStatus;};
+  Float_t GetZ() const {return fZ;};
+  Float_t GetPhi() const {return fPhi;};
+  Float_t GetR() const {return fR;};
+  Int_t GetNMatchableTracks() const {return fNmatchableTracks;};
+  Int_t GetTrackIndex(Int_t i=0) const {return i<fNmatchableTracks ? fTrackIndex->At(i) : -999;};
+  Float_t GetDistanceInStripPlane(Int_t i=0)   const {return i<fNmatchableTracks ? TMath::Sqrt(fDx->At(i)*fDx->At(i)+fDz->At(i)*fDz->At(i)) : -999.;}; // distance
+  Float_t GetDx(Int_t i=0)  const {return i<fNmatchableTracks ? fDx->At(i) : -999.;} // distance, X component
+  Float_t GetDy(Int_t i=0)  const {return i<fNmatchableTracks ? fDy->At(i) : -999.;} // distance, Y component
+  Float_t GetDz(Int_t i=0)  const {return i<fNmatchableTracks ? fDz->At(i) : -999.;} // distance, Z component
+  Float_t GetLength(Int_t i=0) const {return i<fNmatchableTracks ? fTrackLength->At(i) : -999.;} // reconstructed track length at TOF
+  Double_t GetIntegratedTime(Int_t iPart=0,Int_t i=0) const {return (i<fNmatchableTracks && iPart<9) ? fIntegratedTimes->At(9*i+iPart) : -999.;} // reconstructed track length at TOF
+  void SetStatus(Int_t status) {fStatus=status;};
+
+  void AddTOFhit(Int_t clusterIndex,Int_t tofChannel,Float_t tofTime,Float_t timeRaw,Float_t tofTot,Int_t label[3],Int_t deltaBC,Int_t l0l1Latency, Bool_t status,Float_t zClu,Float_t phiClu,Float_t rClu);
+
+  Int_t GetNTOFhits() const {return fNTOFhits;}
+
+ protected:
+
+  Int_t fNTOFhits;        // number of TOF hit in the cluster
+  TArrayI *fClusterIndex; // TOF cluster index in the original tree
+  TArrayI *fTOFchannel; //  TOF channel
+  TArrayF *fTime; // measurement of TOF time
+  TArrayF *fTimeRaw; // 
+  TArrayF *fTOT; // measurement of time-over-threshould
+  TArrayI *fTOFlabel; // labels of tracks (3 at maximum) that contribute to the TOF hit
+  TArrayI *fDeltaBC; // 
+  TArrayI *fL0L1Latency; // 
+  Bool_t fStatus; // !
+  Float_t fZ; // !
+  Float_t fPhi; // !
+  Float_t fR; // !
+  Int_t fNmatchableTracks; // number of matchable tracks with the same TOF matchable hit
+  TArrayI *fTrackIndex; //  index of the track in the original tree
+  TArrayF *fDx; //  X component of track-cluster distance
+  TArrayF *fDy; // ! Y component of track-cluster distance
+  TArrayF *fDz; //  Z component of track-cluster distance
+  TArrayF *fTrackLength; // receonstructed track length
+  TArrayD *fIntegratedTimes; // integrated times
+
+  ClassDef(AliESDTOFcluster, 1) // TOF matchable cluster
+
+}; 
+
+#endif
index 9f9dd80d8588a81e4093f02f819e477fa32daabe..89f6d92f8d4a37ccb46380f7aade70028e24eeb5 100644 (file)
@@ -13,7 +13,7 @@
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/* $Id$ */
+/* $Id: AliESDpid.cxx 64123 2013-09-05 15:09:53Z morsch $ */
 
 //-----------------------------------------------------------------
 //           Implementation of the combined PID class
@@ -61,7 +61,7 @@ Int_t AliESDpid::MakePID(AliESDEvent *event, Bool_t TPConly, Float_t timeZeroTOF
     MakeTPCPID(track);
     if (!TPConly) {
       MakeITSPID(track);
-      MakeTOFPID(track, timeZeroTOF);
+      //MakeTOFPID(track, timeZeroTOF);
       //MakeHMPIDPID(track);
       //MakeTRDPID(track);
     }
index 3203ee576702330eb0d12738090f0ec4600a0c1c..0e228f7bb13a2fd3a18e29e6e9962fd24a5afbae 100644 (file)
 #include "AliTPCdEdxInfo.h"
 #include "AliDetectorPID.h"
 #include "TTreeStream.h"
+#include "TObjArray.h"
 
 ClassImp(AliESDtrack)
 
@@ -178,6 +179,7 @@ AliESDtrack::AliESDtrack() :
   fITSLabel(0),
   fTPCLabel(0),
   fTRDLabel(0),
+  fTOFLabel(NULL),
   fTOFCalChannel(-1),
   fTOFindex(-1),
   fHMPIDqn(0),
@@ -186,6 +188,7 @@ AliESDtrack::AliESDtrack() :
   fHMPIDtrkTheta(0),
   fHMPIDtrkPhi(0),
   fHMPIDsignal(0),
+  fTrackTime(0),
   fTrackLength(0),
   fdTPC(0),fzTPC(0),
   fCddTPC(0),fCdzTPC(0),fCzzTPC(0),
@@ -245,7 +248,9 @@ AliESDtrack::AliESDtrack() :
   fDetectorPID(0x0),
   fTrackPhiOnEMCal(-999),
   fTrackEtaOnEMCal(-999),
-  fTrackPtOnEMCal(-999)
+  fTrackPtOnEMCal(-999),
+  fNtofClusters(0),
+  fTOFcluster(NULL)
 {
   //
   // The default ESD constructor 
@@ -255,7 +260,6 @@ AliESDtrack::AliESDtrack() :
   Int_t i;
   for (i=kNITSchi2Std;i--;) fITSchi2Std[i] = 0;
   for (i=0; i<AliPID::kSPECIES; i++) {
-    fTrackTime[i]=0.;
     fR[i]=0.;
     fITSr[i]=0.;
     fTPCr[i]=0.;
@@ -271,7 +275,6 @@ AliESDtrack::AliESDtrack() :
   }
   for (i=0;i<4;i++) {fITSdEdxSamples[i]=0.;}
   for (i=0;i<4;i++) {fTPCPoints[i]=0;}
-  for (i=0;i<3;i++) {fTOFLabel[i]=-1;}
   for (i=0;i<10;i++) {fTOFInfo[i]=0;}
   for (i=0;i<12;i++) {fITSModule[i]=-1;}
 }
@@ -296,6 +299,7 @@ AliESDtrack::AliESDtrack(const AliESDtrack& track):
   fITSLabel(track.fITSLabel),
   fTPCLabel(track.fTPCLabel),
   fTRDLabel(track.fTRDLabel),
+  fTOFLabel(NULL),
   fTOFCalChannel(track.fTOFCalChannel),
   fTOFindex(track.fTOFindex),
   fHMPIDqn(track.fHMPIDqn),
@@ -304,6 +308,7 @@ AliESDtrack::AliESDtrack(const AliESDtrack& track):
   fHMPIDtrkTheta(track.fHMPIDtrkTheta),
   fHMPIDtrkPhi(track.fHMPIDtrkPhi),
   fHMPIDsignal(track.fHMPIDsignal),
+  fTrackTime(NULL),
   fTrackLength(track.fTrackLength),
   fdTPC(track.fdTPC),fzTPC(track.fzTPC),
   fCddTPC(track.fCddTPC),fCdzTPC(track.fCdzTPC),fCzzTPC(track.fCzzTPC),
@@ -363,13 +368,20 @@ AliESDtrack::AliESDtrack(const AliESDtrack& track):
   fDetectorPID(0x0),
   fTrackPhiOnEMCal(track.fTrackPhiOnEMCal),
   fTrackEtaOnEMCal(track.fTrackEtaOnEMCal),
-  fTrackPtOnEMCal(track.fTrackPtOnEMCal)
+  fTrackPtOnEMCal(track.fTrackPtOnEMCal),
+  fNtofClusters(track.fNtofClusters),
+  fTOFcluster(NULL)
 {
   //
   //copy constructor
   //
   for (Int_t i=kNITSchi2Std;i--;) fITSchi2Std[i] = track.fITSchi2Std[i];
-  for (Int_t i=0;i<AliPID::kSPECIES;i++) fTrackTime[i]=track.fTrackTime[i];
+
+  if(track.fTrackTime){
+    fTrackTime = new Double32_t[AliPID::kSPECIESC];
+    for (Int_t i=0;i<AliPID::kSPECIESC;i++) fTrackTime[i]=track.fTrackTime[i];
+  }
+
   for (Int_t i=0;i<AliPID::kSPECIES;i++)  fR[i]=track.fR[i];
   //
   for (Int_t i=0;i<AliPID::kSPECIES;i++) fITSr[i]=track.fITSr[i]; 
@@ -393,7 +405,11 @@ AliESDtrack::AliESDtrack(const AliESDtrack& track):
 
   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTRDr[i]=track.fTRDr[i]; 
   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTOFr[i]=track.fTOFr[i];
-  for (Int_t i=0;i<3;i++) fTOFLabel[i]=track.fTOFLabel[i];
+  if(track.fTOFLabel){
+    if(!fTOFLabel) fTOFLabel = new Int_t[3];
+    for (Int_t i=0;i<3;i++) fTOFLabel[i]=track.fTOFLabel[i];
+  }
+
   for (Int_t i=0;i<10;i++) fTOFInfo[i]=track.fTOFInfo[i];
   for (Int_t i=0;i<12;i++) fITSModule[i]=track.fITSModule[i];
   for (Int_t i=0;i<AliPID::kSPECIES;i++) fHMPIDr[i]=track.fHMPIDr[i];
@@ -407,6 +423,11 @@ AliESDtrack::AliESDtrack(const AliESDtrack& track):
 
   
   if (track.fFriendTrack) fFriendTrack=new AliESDfriendTrack(*(track.fFriendTrack));
+
+  if(fNtofClusters > 0){
+    fTOFcluster = new Int_t[fNtofClusters];
+        for(Int_t i=0;i < fNtofClusters;i++) fTOFcluster[i] = track.fTOFcluster[i];
+  }
 }
 
 //_______________________________________________________________________
@@ -427,6 +448,7 @@ AliESDtrack::AliESDtrack(const AliVTrack *track) :
   fITSLabel(0),
   fTPCLabel(0),
   fTRDLabel(0),
+  fTOFLabel(NULL),
   fTOFCalChannel(-1),
   fTOFindex(-1),
   fHMPIDqn(0),
@@ -435,6 +457,7 @@ AliESDtrack::AliESDtrack(const AliVTrack *track) :
   fHMPIDtrkTheta(0),
   fHMPIDtrkPhi(0),
   fHMPIDsignal(0),
+  fTrackTime(NULL),
   fTrackLength(0),
   fdTPC(0),fzTPC(0),
   fCddTPC(0),fCdzTPC(0),fCzzTPC(0),
@@ -494,7 +517,9 @@ AliESDtrack::AliESDtrack(const AliVTrack *track) :
   fDetectorPID(0x0),
   fTrackPhiOnEMCal(-999),
   fTrackEtaOnEMCal(-999),
-  fTrackPtOnEMCal(-999)
+  fTrackPtOnEMCal(-999),
+  fNtofClusters(0),
+  fTOFcluster(NULL)
 {
   //
   // ESD track from AliVTrack.
@@ -512,7 +537,6 @@ AliESDtrack::AliESDtrack(const AliVTrack *track) :
   Int_t i;
   for (i=kNITSchi2Std;i--;) fITSchi2Std[i] = 0;
   for (i=0; i<AliPID::kSPECIES; i++) {
-    fTrackTime[i]=0.;
     fR[i]=0.;
     fITSr[i]=0.;
     fTPCr[i]=0.;
@@ -528,7 +552,6 @@ AliESDtrack::AliESDtrack(const AliVTrack *track) :
   }
   for (i=0;i<4;i++) {fITSdEdxSamples[i]=0.;}
   for (i=0;i<4;i++) {fTPCPoints[i]=0;}
-  for (i=0;i<3;i++) {fTOFLabel[i]=-1;}
   for (i=0;i<10;i++) {fTOFInfo[i]=0;}
   for (i=0;i<12;i++) {fITSModule[i]=-1;}
 
@@ -589,7 +612,7 @@ AliESDtrack::AliESDtrack(const AliVTrack *track) :
   fTRDchi2 = track->GetTRDchi2();
   //
   SetTOFsignal(track->GetTOFsignal());
-  Double_t expt[AliPID::kSPECIES];
+  Double_t expt[AliPID::kSPECIESC];
   track->GetIntegratedTimes(expt);
   SetIntegratedTimes(expt);
   //
@@ -618,6 +641,7 @@ AliESDtrack::AliESDtrack(TParticle * part) :
   fITSLabel(0),
   fTPCLabel(0),
   fTRDLabel(0),
+  fTOFLabel(NULL),
   fTOFCalChannel(-1),
   fTOFindex(-1),
   fHMPIDqn(0),
@@ -626,6 +650,7 @@ AliESDtrack::AliESDtrack(TParticle * part) :
   fHMPIDtrkTheta(0),
   fHMPIDtrkPhi(0),
   fHMPIDsignal(0),
+  fTrackTime(NULL),
   fTrackLength(0),
   fdTPC(0),fzTPC(0),
   fCddTPC(0),fCdzTPC(0),fCzzTPC(0),
@@ -685,7 +710,9 @@ AliESDtrack::AliESDtrack(TParticle * part) :
   fDetectorPID(0x0),
   fTrackPhiOnEMCal(-999),
   fTrackEtaOnEMCal(-999),
-  fTrackPtOnEMCal(-999)
+  fTrackPtOnEMCal(-999),
+  fNtofClusters(0),
+  fTOFcluster(NULL)
 {
   //
   // ESD track from TParticle
@@ -695,7 +722,6 @@ AliESDtrack::AliESDtrack(TParticle * part) :
   Int_t i;
   for (i=kNITSchi2Std;i--;) fITSchi2Std[i] = 0;
   for (i=0; i<AliPID::kSPECIES; i++) {
-    fTrackTime[i]=0.;
     fR[i]=0.;
     fITSr[i]=0.;
     fTPCr[i]=0.;
@@ -711,7 +737,6 @@ AliESDtrack::AliESDtrack(TParticle * part) :
   }
   for (i=0;i<4;i++) {fITSdEdxSamples[i]=0.;}
   for (i=0;i<4;i++) {fTPCPoints[i]=0;}
-  for (i=0;i<3;i++) {fTOFLabel[i]=-1;}
   for (i=0;i<10;i++) {fTOFInfo[i]=0;}
   for (i=0;i<12;i++) {fITSModule[i]=-1;}
 
@@ -825,7 +850,15 @@ AliESDtrack::~AliESDtrack(){
   fCacheChi2TPCConstrainedVsGlobal = -10.;
   if(fCacheChi2TPCConstrainedVsGlobalVertex) fCacheChi2TPCConstrainedVsGlobalVertex = 0;
 
+  if(fTOFcluster)
+    delete[] fTOFcluster;
+  fTOFcluster = NULL;
+  fNtofClusters=0;
+
   delete fDetectorPID;
+
+  if(fTrackTime) delete[] fTrackTime; 
+  if(fTOFLabel) delete[] fTOFLabel;
 }
 
 AliESDtrack &AliESDtrack::operator=(const AliESDtrack &source){
@@ -921,8 +954,11 @@ AliESDtrack &AliESDtrack::operator=(const AliESDtrack &source){
   }
   fTPCLabel = source.fTPCLabel; 
   fTRDLabel = source.fTRDLabel;
-  for(int i = 0; i< 3;++i){
-    fTOFLabel[i] = source.fTOFLabel[i];    
+  if(source.fTOFLabel){
+    if(!fTOFLabel) fTOFLabel = new Int_t[3];
+    for(int i = 0; i< 3;++i){
+      fTOFLabel[i] = source.fTOFLabel[i];    
+    }
   }
   fTOFCalChannel = source.fTOFCalChannel;
   fTOFindex      = source.fTOFindex;
@@ -942,7 +978,6 @@ AliESDtrack &AliESDtrack::operator=(const AliESDtrack &source){
     fTRDr[i]  = source.fTRDr[i];
     fTOFr[i]  = source.fTOFr[i];
     fHMPIDr[i] = source.fHMPIDr[i];
-    fTrackTime[i] = source.fTrackTime[i];  
   }
 
   fHMPIDtrkTheta = source.fHMPIDtrkTheta;
@@ -950,6 +985,15 @@ AliESDtrack &AliESDtrack::operator=(const AliESDtrack &source){
   fHMPIDsignal   = source.fHMPIDsignal; 
 
   
+  if(fTrackTime){
+    delete[] fTrackTime;
+  }
+  if(source.fTrackTime){
+    fTrackTime = new Double32_t[AliPID::kSPECIESC];
+    for(Int_t i=0;i < AliPID::kSPECIESC;i++)
+      fTrackTime[i] = source.fTrackTime[i];  
+  }
+
   fTrackLength   = source. fTrackLength;
   fdTPC  = source.fdTPC; 
   fzTPC  = source.fzTPC; 
@@ -1045,6 +1089,15 @@ AliESDtrack &AliESDtrack::operator=(const AliESDtrack &source){
   fTrackEtaOnEMCal= source.fTrackEtaOnEMCal;
   fTrackPtOnEMCal= source.fTrackPtOnEMCal;
 
+  if(fTOFcluster){
+    delete[] fTOFcluster;
+  }
+  fNtofClusters = source.fNtofClusters;
+  if(fNtofClusters > 0){
+    fTOFcluster = new Int_t[fNtofClusters];
+        for(Int_t i=0;i < fNtofClusters;i++) fTOFcluster[i] = source.fTOFcluster[i];
+  }
+
   return *this;
 }
 
@@ -1178,7 +1231,8 @@ void AliESDtrack::MakeMiniESDtrack(){
   
   fTrackLength = 0;
 
-  for (Int_t i=0;i<AliPID::kSPECIES;i++) fTrackTime[i] = 0;
+  if(fTrackTime)
+    for (Int_t i=0;i<AliPID::kSPECIESC;i++) fTrackTime[i] = 0;
 
   // Reset track parameters constrained to the primary vertex
   delete fCp;fCp = 0;
@@ -1255,7 +1309,6 @@ void AliESDtrack::MakeMiniESDtrack(){
   fTOFdeltaBC = 999;
   fTOFl0l1 = 999;
   for (Int_t i=0;i<AliPID::kSPECIES;i++) fTOFr[i] = 0;
-  for (Int_t i=0;i<3;i++) fTOFLabel[i] = -1;
   for (Int_t i=0;i<10;i++) fTOFInfo[i] = 0;
 
   // Reset HMPID related track information
@@ -1327,9 +1380,12 @@ Int_t AliESDtrack::GetTOFBunchCrossing(Double_t b, Bool_t pidTPConly) const
   if (!IsOn(kTOFout) || !IsOn(kESDpid)) return bcid; // no info
   //
   double tdif = fTOFsignal;
+  Double_t times[AliPID::kSPECIESC];
+  GetIntegratedTimes(times);
   if (IsOn(kTIME)) { // integrated time info is there
     int pid = GetPID(pidTPConly);
-    tdif -= fTrackTime[pid];
+
+    tdif -= times[pid];
   }
   else { // assume integrated time info from TOF radius and momentum
     const double kRTOF = 385.;
@@ -1398,7 +1454,7 @@ Bool_t AliESDtrack::UpdateTrackParams(const AliKalmanTrack *t, ULong_t flags){
 
   if (t->IsStartedTimeIntegral()) {
     SetStatus(kTIME);
-    Double_t times[10];t->GetIntegratedTimes(times); SetIntegratedTimes(times);
+    Double_t times[AliPID::kSPECIESC];t->GetIntegratedTimes(times); SetIntegratedTimes(times);
     SetIntegratedLength(t->GetIntegratedLength());
   }
 
@@ -1736,14 +1792,54 @@ Int_t AliESDtrack::GetClusters(Int_t idet, Int_t *idx) const
 
 //_______________________________________________________________________
 void AliESDtrack::GetIntegratedTimes(Double_t *times) const {
+  Int_t index = -1;
+
+  if(fNtofClusters>0 && GetESDEvent()){
+    TObjArray *tofclArray = GetESDEvent()->GetTOFcluster();
+    AliESDTOFcluster *tofcl = (AliESDTOFcluster *) tofclArray->At(fTOFcluster[0]);
+
+    for(Int_t i=0;i < tofcl->GetNMatchableTracks();i++){
+      if(tofcl->GetTrackIndex(i) == GetID()) index = i;
+    }
+    if(fNtofClusters>0 && index > -1){
+      for (Int_t i=0; i<AliPID::kSPECIESC; i++) times[i]=tofcl->GetIntegratedTime(i,index);
+      return;
+    }
+  }
+  else if(fNtofClusters>0) 
+    AliInfo("No AliESDEvent available here!\n");
+
   // Returns the array with integrated times for each particle hypothesis
-  for (Int_t i=0; i<AliPID::kSPECIES; i++) times[i]=fTrackTime[i];
+  if(fTrackTime)
+    for (Int_t i=0; i<AliPID::kSPECIESC; i++) times[i]=fTrackTime[i];
+  else
+    for (Int_t i=0; i<AliPID::kSPECIESC; i++) times[i]=0.0;
+}
+//_______________________________________________________________________
+Double_t AliESDtrack::GetIntegratedLength() const{
+  Int_t index = -1;
+  if(fNtofClusters>0 && GetESDEvent()){
+    TObjArray *tofclArray = GetESDEvent()->GetTOFcluster();
+    AliESDTOFcluster *tofcl = (AliESDTOFcluster *) tofclArray->At(fTOFcluster[0]);
+
+    for(Int_t i=0;i < tofcl->GetNMatchableTracks();i++){
+      if(tofcl->GetTrackIndex(i) == GetID()) index = i;
+    }
+    
+    if(fNtofClusters>0 && index > -1)
+      return tofcl->GetLength(index);
+  }
+  else if(fNtofClusters>0) AliInfo("No AliESDEvent available here!\n");
+
+  return fTrackLength;
 }
 
 //_______________________________________________________________________
 void AliESDtrack::SetIntegratedTimes(const Double_t *times) {
   // Sets the array with integrated times for each particle hypotesis
-  for (Int_t i=0; i<AliPID::kSPECIES; i++) fTrackTime[i]=times[i];
+  if(!fTrackTime)
+    fTrackTime = new Double32_t[AliPID::kSPECIESC];
+  for (Int_t i=0; i<AliPID::kSPECIESC; i++) fTrackTime[i]=times[i];
 }
 
 //_______________________________________________________________________
@@ -2205,6 +2301,7 @@ void AliESDtrack::SetTOFpid(const Double_t *p) {
 //_______________________________________________________________________
 void AliESDtrack::SetTOFLabel(const Int_t *p) {  
   // Sets  (in TOF)
+  if(!fTOFLabel) fTOFLabel = new Int_t[3]; 
   for (Int_t i=0; i<3; i++) fTOFLabel[i]=p[i];
 }
 
@@ -2217,7 +2314,16 @@ void AliESDtrack::GetTOFpid(Double_t *p) const {
 //_______________________________________________________________________
 void AliESDtrack::GetTOFLabel(Int_t *p) const {
   // Gets (in TOF)
-  for (Int_t i=0; i<3; i++) p[i]=fTOFLabel[i];
+  if(fNtofClusters>0){
+    TObjArray *tofclArray = GetESDEvent()->GetTOFcluster();
+    AliESDTOFcluster *tofcl = (AliESDTOFcluster *) tofclArray->At(fTOFcluster[0]);
+
+    for (Int_t i=0; i<3; i++) p[i]=tofcl->GetLabel(i);
+  }
+  else{
+    if(fTOFLabel)
+      for (Int_t i=0; i<3; i++) p[i]=fTOFLabel[i];
+  }
 }
 
 //_______________________________________________________________________
@@ -2791,3 +2897,236 @@ Double_t AliESDtrack::GetLengthInActiveZone(const AliExternalTrackParam  *paramT
   }
   return length;
 }
+
+void    AliESDtrack::SetTOFclusterArray(Int_t ncluster,Int_t *TOFcluster){
+  AliInfo("Method has to be implemented!");
+//   fNtofClusters=ncluster;
+//   if(TOFcluster == fTOFcluster) return;
+//   if(fTOFcluster){ // reset previous content    
+//     delete[] fTOFcluster;
+//     fTOFcluster = NULL;
+//     fNtofClusters=0;
+//   }
+
+//   if(ncluster){ // set new content
+//     fTOFcluster = new Int_t[fNtofClusters];
+//     for(Int_t i=0;i < fNtofClusters;i++) fTOFcluster[i] = TOFcluster[i];
+//   }
+//   else
+//     fTOFcluster = 0;
+}
+
+void    AliESDtrack::AddTOFcluster(Int_t icl){
+  fNtofClusters++;
+  
+  Int_t *old = fTOFcluster;
+  fTOFcluster = new Int_t[fNtofClusters];
+
+  for(Int_t i=0;i < fNtofClusters-1;i++) fTOFcluster[i] = old[i];
+  fTOFcluster[fNtofClusters-1] = icl;
+
+  if(fNtofClusters-1){ // delete previous content    
+    delete old;
+    old = NULL;
+  }
+}
+
+Double_t AliESDtrack::GetTOFsignal() const {
+  if(fNtofClusters>0 && GetESDEvent()){
+    TObjArray *tofclArray = GetESDEvent()->GetTOFcluster();
+    AliESDTOFcluster *tofcl = (AliESDTOFcluster *) tofclArray->At(fTOFcluster[0]);
+
+    return tofcl->GetTime();
+  }
+  else if(fNtofClusters>0) AliInfo("No AliESDEvent available here!\n");
+
+  return fTOFsignal;
+}
+
+Double_t AliESDtrack::GetTOFsignalToT() const 
+{
+  if(fNtofClusters>0 && GetESDEvent()){
+    TObjArray *tofclArray = GetESDEvent()->GetTOFcluster();
+    AliESDTOFcluster *tofcl = (AliESDTOFcluster *) tofclArray->At(fTOFcluster[0]);
+
+    return tofcl->GetTOT();
+  }
+  else if(fNtofClusters>0) AliInfo("No AliESDEvent available here!\n");
+
+  return fTOFsignalToT;
+}
+
+Double_t AliESDtrack::GetTOFsignalRaw() const 
+{
+  if(fNtofClusters>0 && GetESDEvent()){
+    TObjArray *tofclArray = GetESDEvent()->GetTOFcluster();
+    AliESDTOFcluster *tofcl = (AliESDTOFcluster *) tofclArray->At(fTOFcluster[0]);
+
+    return tofcl->GetTimeRaw();
+  }
+  else if(fNtofClusters>0) AliInfo("No AliESDEvent available here!\n");
+
+  return fTOFsignalRaw;
+}
+
+Double_t AliESDtrack::GetTOFsignalDz() const 
+{
+
+  AliESDTOFcluster *tofcl;
+
+  Int_t index = -1;
+  if(fNtofClusters>0 && GetESDEvent()){
+    TObjArray *tofclArray = GetESDEvent()->GetTOFcluster();
+    tofcl = (AliESDTOFcluster *) tofclArray->At(fTOFcluster[0]);
+
+    for(Int_t i=0;i < tofcl->GetNMatchableTracks();i++){
+      if(tofcl->GetTrackIndex(i) == GetID()) index = i;
+    }
+  }
+  else if(fNtofClusters>0) AliInfo("No AliESDEvent available here!\n");
+
+  if(fNtofClusters>0 && index > -1){
+    return tofcl->GetDz(index);
+  }
+  return fTOFsignalDz;
+}
+
+Double_t AliESDtrack::GetTOFsignalDx() const 
+{
+  AliESDTOFcluster *tofcl;
+
+  Int_t index = -1;
+  if(fNtofClusters>0 && GetESDEvent()){
+    TObjArray *tofclArray = GetESDEvent()->GetTOFcluster();
+    tofcl = (AliESDTOFcluster *) tofclArray->At(fTOFcluster[0]);
+    for(Int_t i=0;i < tofcl->GetNMatchableTracks();i++){
+      if(tofcl->GetTrackIndex(i) == GetID()) index = i;
+    }
+  }
+  else if(fNtofClusters>0) AliInfo("No AliESDEvent available here!\n");
+  if(fNtofClusters>0 && index > -1){
+    return tofcl->GetDx(index);
+  }
+  return fTOFsignalDx;
+}
+
+Short_t  AliESDtrack::GetTOFDeltaBC() const 
+{
+  if(fNtofClusters>0 && GetESDEvent()){
+    TObjArray *tofclArray = GetESDEvent()->GetTOFcluster();
+    AliESDTOFcluster *tofcl = (AliESDTOFcluster *) tofclArray->At(fTOFcluster[0]);
+    return tofcl->GetDeltaBC();
+  }
+  else if(fNtofClusters>0) AliInfo("No AliESDEvent available here!\n");
+
+  return fTOFdeltaBC;
+}
+
+Short_t  AliESDtrack::GetTOFL0L1() const 
+{
+  if(fNtofClusters>0 && GetESDEvent()){
+    TObjArray *tofclArray = GetESDEvent()->GetTOFcluster();
+    AliESDTOFcluster *tofcl = (AliESDTOFcluster *) tofclArray->At(fTOFcluster[0]);
+
+    return tofcl->GetL0L1Latency();
+  }
+  else if(fNtofClusters>0) AliInfo("No AliESDEvent available here!\n");
+
+  return fTOFl0l1;
+}
+
+Int_t   AliESDtrack::GetTOFCalChannel() const 
+{
+  if(fNtofClusters>0 && GetESDEvent()){
+    TObjArray *tofclArray = GetESDEvent()->GetTOFcluster();
+    AliESDTOFcluster *tofcl = (AliESDTOFcluster *) tofclArray->At(fTOFcluster[0]);
+
+    tofcl->GetTOFchannel();
+  }
+  else if(fNtofClusters>0) AliInfo("No AliESDEvent available here!\n");
+
+  return fTOFCalChannel;
+}
+
+Int_t   AliESDtrack::GetTOFcluster() const 
+{
+  if(fNtofClusters>0 && GetESDEvent()){
+    TObjArray *tofclArray = GetESDEvent()->GetTOFcluster();
+    AliESDTOFcluster *tofcl = (AliESDTOFcluster *) tofclArray->At(fTOFcluster[0]);
+
+    tofcl->GetClusterIndex();
+  }
+  else if(fNtofClusters>0) AliInfo("No AliESDEvent available here!\n");
+
+  return fTOFindex;
+}
+
+Int_t   AliESDtrack::GetTOFclusterN() const
+{
+  return fNtofClusters;
+}
+
+Bool_t  AliESDtrack::IsTOFHitAlreadyMatched() const{
+  if(fNtofClusters>0 && GetESDEvent()){
+    TObjArray *tofclArray = GetESDEvent()->GetTOFcluster();
+    AliESDTOFcluster *tofcl = (AliESDTOFcluster *) tofclArray->At(fTOFcluster[0]);
+
+    if (tofcl->GetNMatchableTracks() > 1)
+      return kTRUE;
+  }
+  else if(fNtofClusters>0) AliInfo("No AliESDEvent available here!\n");
+
+  return kFALSE;
+}
+
+void AliESDtrack::ReMapTOFcluster(Int_t ncl,Int_t *mapping){
+  for(Int_t i=0;i<fNtofClusters;i++){
+    if(fTOFcluster[i]<ncl && fTOFcluster[i]>-1)
+      fTOFcluster[i] = mapping[fTOFcluster[i]];
+    else
+      AliInfo(Form("TOF cluster re-mapping in AliESDtrack: out of range (%i > %i)\n",fTOFcluster[i],ncl));
+  }
+}
+
+void AliESDtrack::SortTOFcluster(){
+  TObjArray *tofclArray = GetESDEvent()->GetTOFcluster();
+
+  for(Int_t i=0;i<fNtofClusters-1;i++){
+    for(Int_t j=i+1;j<fNtofClusters;j++){
+      AliESDTOFcluster *tofcl = (AliESDTOFcluster *) tofclArray->At(fTOFcluster[i]);
+      Int_t index1 = -1;
+      for(Int_t it=0;it < tofcl->GetNMatchableTracks();it++){
+         if(tofcl->GetTrackIndex(it) == GetID()) index1 = it;
+      }
+      Double_t timedist1 = 10000;
+      for(Int_t isp=0; isp< AliPID::kSPECIESC;isp++){
+       Double_t timec = TMath::Abs(tofcl->GetTime() - tofcl->GetIntegratedTime(isp));
+       if(timec < timedist1) timedist1 = timec;
+      }
+      timedist1 *= 0.03; // in cm
+      Double_t radius1 = tofcl->GetDx(index1)*tofcl->GetDx(index1) + tofcl->GetDz(index1)*tofcl->GetDz(index1) + timedist1*timedist1;
+
+      AliESDTOFcluster *tofcl2 = (AliESDTOFcluster *) tofclArray->At(fTOFcluster[j]);
+      Int_t index2 = -1;
+      for(Int_t it=0;it < tofcl2->GetNMatchableTracks();it++){
+         if(tofcl2->GetTrackIndex(it) == GetID()) index2 = it;
+      }
+      if(index1 == -1 || index2 == -1){
+      }
+      Double_t timedist2 = 10000;
+      for(Int_t isp=0; isp< AliPID::kSPECIESC;isp++){
+       Double_t timec = TMath::Abs(tofcl2->GetTime() - tofcl2->GetIntegratedTime(isp));
+       if(timec < timedist2) timedist2 = timec;
+      }
+      timedist2 *= 0.03; // in cm
+      Double_t radius2 = tofcl2->GetDx(index2)*tofcl2->GetDx(index2) + tofcl2->GetDz(index2)*tofcl2->GetDz(index2) + timedist2*timedist2;
+
+      if(radius2 < radius1){
+        Int_t change = fTOFcluster[i];
+        fTOFcluster[i] = fTOFcluster[j];
+        fTOFcluster[j] = change;
+      }
+    }
+  }
+}
index 69015a1119e328ccb45d8d9839ead4f798c813b8..97b86e4cb08079ffc1952ff93da497d51b4db7b9 100644 (file)
@@ -3,7 +3,7 @@
 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
  * See cxx source for full Copyright notice                               */
 
-/* $Id$ */
+/* $Id: AliESDtrack.h 64153 2013-09-09 09:33:47Z akalweit $ */
 
 //-------------------------------------------------------------------------
 //                          Class AliESDtrack
@@ -30,6 +30,7 @@
 #include <TBits.h>
 #include "AliExternalTrackParam.h"
 #include "AliVTrack.h"
+#include "AliESDTOFcluster.h"
 #include "AliPID.h"
 #include "AliESDfriendTrack.h"
 #include "AliTPCdEdxInfo.h"
@@ -83,8 +84,10 @@ public:
   void GetExternalParameters(Double_t &x, Double_t p[5]) const;
   void GetExternalCovariance(Double_t cov[15]) const;
 
-  Double_t GetIntegratedLength() const {return fTrackLength;}
+  Double_t GetIntegratedLength() const;
+  Double_t GetIntegratedLengthOld() const {return fTrackLength;}
   void GetIntegratedTimes(Double_t *times) const;
+  Double_t GetIntegratedTimesOld(Int_t i) const {if(fTrackTime) return fTrackTime[i]; else return 0;};
   Int_t    GetPID(Bool_t tpcOnly=kFALSE)  const;
   Int_t    GetTOFBunchCrossing(Double_t b=0, Bool_t pidTPConly=kTRUE) const;
   Double_t GetMass(Bool_t tpcOnly=kFALSE) const {return AliPID::ParticleMass(GetPID(tpcOnly));}
@@ -303,31 +306,40 @@ public:
     return fFriendTrack!=NULL?fFriendTrack->GetTRDtrack():NULL;
   }
 
+  void    SetTOFclusterArray(Int_t ncluster,Int_t *TOFcluster);
+  Int_t   *GetTOFclusterArray() const {return fTOFcluster;}
+  Int_t   GetNTOFclusters() const {return fNtofClusters;}
+  void    AddTOFcluster(Int_t icl);
+  void    SortTOFcluster();
+  void    ReMapTOFcluster(Int_t ncl,Int_t *mapping);
+
   void    SetTOFsignal(Double_t tof) {fTOFsignal=tof;}
-  Double_t GetTOFsignal() const {return fTOFsignal;}
+  Double_t GetTOFsignal() const;
   void    SetTOFsignalToT(Double_t ToT) {fTOFsignalToT=ToT;}
-  Double_t GetTOFsignalToT() const {return fTOFsignalToT;}
+  Double_t GetTOFsignalToT() const;
   void    SetTOFsignalRaw(Double_t tof) {fTOFsignalRaw=tof;}
-  Double_t GetTOFsignalRaw() const {return fTOFsignalRaw;}
+  Double_t GetTOFsignalRaw() const;
   void    SetTOFsignalDz(Double_t dz) {fTOFsignalDz=dz;}
-  Double_t GetTOFsignalDz() const {return fTOFsignalDz;}
+  Double_t GetTOFsignalDz() const;
   void    SetTOFsignalDx(Double_t dx) {fTOFsignalDx=dx;}
-  Double_t GetTOFsignalDx() const {return fTOFsignalDx;}
+  Double_t GetTOFsignalDx() const;
   void     SetTOFDeltaBC(Short_t deltaBC) {fTOFdeltaBC=deltaBC;};
-  Short_t  GetTOFDeltaBC() const {return fTOFdeltaBC;}
+  Short_t  GetTOFDeltaBC() const;
   void     SetTOFL0L1(Short_t l0l1) {fTOFl0l1=l0l1;};
-  Short_t  GetTOFL0L1() const {return fTOFl0l1;}
-  Double_t GetTOFchi2() const {return fTOFchi2;}
+  Short_t  GetTOFL0L1() const;
+  Double_t GetTOFchi2() const {return fTOFchi2;};
   void    SetTOFpid(const Double_t *p);
   void    SetTOFLabel(const Int_t *p);
   void    GetTOFpid(Double_t *p) const;
   void    GetTOFLabel(Int_t *p) const;
   void    GetTOFInfo(Float_t *info) const;
   void    SetTOFInfo(Float_t *info);
-  Int_t   GetTOFCalChannel() const {return fTOFCalChannel;}
-  Int_t   GetTOFcluster() const {return fTOFindex;}
+  Int_t   GetTOFCalChannel() const;
+  Int_t   GetTOFcluster() const;
   void    SetTOFcluster(Int_t index) {fTOFindex=index;}
   void    SetTOFCalChannel(Int_t index) {fTOFCalChannel=index;}
+  Int_t   GetTOFclusterN() const;
+  Bool_t  IsTOFHitAlreadyMatched() const;
   void    SetTOFsignalTunedOnData(Double_t signal){fTOFsignalTuned=signal;}
   Double_t GetTOFsignalTunedOnData() const {return fTOFsignalTuned;}
 
@@ -447,8 +459,8 @@ protected:
   Int_t     fITSModule[12];  // modules crossed by the track in the ITS 
   Int_t     fTPCLabel;       // label according TPC
   Int_t     fTRDLabel;       // label according TRD
-  Int_t     fTOFLabel[3];    // TOF label 
-  Int_t     fTOFCalChannel;  // Channel Index of the TOF Signal 
+  Int_t     *fTOFLabel;      //! TOF label 
+  Int_t     fTOFCalChannel;  //! Channel Index of the TOF Signal 
   Int_t     fTOFindex;       // index of the assigned TOF cluster
   Int_t     fHMPIDqn;         // 1000000*number of photon clusters + QDC
   Int_t     fHMPIDcluIdx;     // 1000000*chamber id + cluster idx of the assigned MIP cluster
@@ -470,8 +482,8 @@ protected:
   Double32_t fHMPIDtrkPhi;     //[-2*pi,2*pi,16] phi of the track extrapolated to the HMPID, LORS
   Double32_t fHMPIDsignal;  // HMPID PID signal (Theta ckov, rad)
 
-  Double32_t   fTrackTime[AliPID::kSPECIES]; // TOFs estimated by the tracking
-  Double32_t   fTrackLength;   // Track length
+  Double32_t   *fTrackTime; //! TOFs estimated by the tracking
+  Double32_t   fTrackLength;   //! Track length
 
   Double32_t   fdTPC;          // TPC-only impact parameter in XY plane
   Double32_t   fzTPC;          // TPC-only impact parameter in Z
@@ -506,15 +518,15 @@ protected:
   Double32_t fTRDQuality;     // trd quality factor for TOF
   Double32_t fTRDBudget;      // trd material budget
 
-  Double32_t fTOFsignal;      // detector's PID signal
+  Double32_t fTOFsignal;      //! detector's PID signal [ps]
   Double32_t fTOFsignalTuned; //! detector's PID signal tuned on data when using MC
-  Double32_t fTOFsignalToT;   // detector's ToT signal
-  Double32_t fTOFsignalRaw;   // detector's uncorrected time signal
-  Double32_t fTOFsignalDz;    // local z  of track's impact on the TOF pad 
-  Double32_t fTOFsignalDx;    // local x  of track's impact on the TOF pad 
+  Double32_t fTOFsignalToT;   //! detector's ToT signal [ns]
+  Double32_t fTOFsignalRaw;   //! detector's uncorrected time signal [ps]
+  Double32_t fTOFsignalDz;    //! local z  of track's impact on the TOF pad [cm]
+  Double32_t fTOFsignalDx;    //! local x  of track's impact on the TOF pad [cm]
   Double32_t fTOFInfo[10];    //! TOF informations
-  Short_t    fTOFdeltaBC;     // detector's Delta Bunch Crossing correction
-  Short_t    fTOFl0l1;        // detector's L0L1 latency correction
+  Short_t    fTOFdeltaBC;     //! detector's Delta Bunch Crossing correction
+  Short_t    fTOFl0l1;        //! detector's L0L1 latency correction
 
   Double32_t fCaloDx ;        // [0.,0.,8] distance to calorimeter cluster in calo plain (phi direction)
   Double32_t fCaloDz ;        // [0.,0.,8] distance to calorimeter cluster in calo plain (z direction)
@@ -557,11 +569,17 @@ protected:
   Double_t      fTrackEtaOnEMCal;   // eta of track after being propagated to the EMCal surface (default r = 440 cm)
   Double_t      fTrackPtOnEMCal;    // pt of track after being propagated to the EMCal surface (default r = 440 cm)
   
+
+  // new TOF data structure
+  Int_t fNtofClusters;              // number of matchable TOF clusters 
+  Int_t *fTOFcluster;               //[fNtofClusters]
+                                    // TOF clusters matchable with the track
+
  private:
   static bool fgkOnlineMode; //! indicate the online mode to skip some of the functionality
 
   AliESDtrack & operator=(const AliESDtrack & );
-  ClassDef(AliESDtrack,68)  //ESDtrack 
+  ClassDef(AliESDtrack,69)  //ESDtrack 
 };
 
 
index 69abf5a064723aa7cdbd2242846ba509444f2ccf..70aef794925c8c4aeac0bdc679e16708ac46f0df 100644 (file)
@@ -40,7 +40,7 @@ ClassImp(AliKalmanTrack)
   // Default constructor
   //
 
-  for(Int_t i=0; i<AliPID::kSPECIES; i++) fIntegratedTime[i] = 0;
+  for(Int_t i=0; i<AliPID::kSPECIESC; i++) fIntegratedTime[i] = 0;
 }
 
 AliKalmanTrack::AliKalmanTrack(const AliKalmanTrack &t):
@@ -57,7 +57,7 @@ AliKalmanTrack::AliKalmanTrack(const AliKalmanTrack &t):
   // Copy constructor
   //
   
-  for (Int_t i=0; i<AliPID::kSPECIES; i++)
+  for (Int_t i=0; i<AliPID::kSPECIESC; i++)
       fIntegratedTime[i] = t.fIntegratedTime[i];
 }
 
@@ -70,7 +70,7 @@ AliKalmanTrack& AliKalmanTrack::operator=(const AliKalmanTrack&o){
     fMass = o.fMass;
     fN = o.fN;
     fStartTimeIntegral = o.fStartTimeIntegral;
-    for(Int_t i = 0;i<AliPID::kSPECIES;++i)fIntegratedTime[i] = o.fIntegratedTime[i];
+    for(Int_t i = 0;i<AliPID::kSPECIESC;++i)fIntegratedTime[i] = o.fIntegratedTime[i];
     fIntegratedLength = o.fIntegratedLength;
   }
   return *this;
@@ -90,7 +90,7 @@ void AliKalmanTrack::StartTimeIntegral()
   //  AliWarning("Reseting Recorded Time.");
 
   fStartTimeIntegral = kTRUE;
-  for(Int_t i=0; i<AliPID::kSPECIES; i++) fIntegratedTime[i] = 0;  
+  for(Int_t i=0; i<AliPID::kSPECIESC; i++) fIntegratedTime[i] = 0;  
   fIntegratedLength = 0;
 }
 
@@ -134,10 +134,11 @@ void AliKalmanTrack:: AddTimeStep(Double_t length)
 
   //  if (length > 100) return;
 
-  for (Int_t i=0; i<AliPID::kSPECIES; i++) {
+  for (Int_t i=0; i<AliPID::kSPECIESC; i++) {
     
     Double_t mass = AliPID::ParticleMass(i);
-    Double_t correction = TMath::Sqrt( pt*pt * (1 + tgl*tgl) + mass * mass ) / p;
+    Double_t pCharge = p * AliPID::ParticleCharge(i);
+    Double_t correction = TMath::Sqrt( pCharge * pCharge + mass * mass ) / pCharge;
     Double_t time = length * correction / kcc;
 
     fIntegratedTime[i] += time;
@@ -163,7 +164,7 @@ Double_t AliKalmanTrack::GetIntegratedTime(Int_t pdg) const
     return 0.;
   }
 
-  for (Int_t i=0; i<AliPID::kSPECIES; i++)
+  for (Int_t i=0; i<AliPID::kSPECIESC; i++)
     if (AliPID::ParticleCode(i) == TMath::Abs(pdg)) return fIntegratedTime[i];
 
   AliWarning(Form("Particle type [%d] not found", pdg));
@@ -171,10 +172,10 @@ Double_t AliKalmanTrack::GetIntegratedTime(Int_t pdg) const
 }
 
 void AliKalmanTrack::GetIntegratedTimes(Double_t *times) const {
-  for (Int_t i=0; i<AliPID::kSPECIES; i++) times[i]=fIntegratedTime[i];
+  for (Int_t i=0; i<AliPID::kSPECIESC; i++) times[i]=fIntegratedTime[i];
 }
 
 void AliKalmanTrack::SetIntegratedTimes(const Double_t *times) {
-  for (Int_t i=0; i<AliPID::kSPECIES; i++) fIntegratedTime[i]=times[i];
+  for (Int_t i=0; i<AliPID::kSPECIESC; i++) fIntegratedTime[i]=times[i];
 }
 
index fe3e711e5b1022c2634c27c17997ae31bfe3bca7..07bd5dd05cd76a96403eb1eb8c7b5fc4ec16fe83 100644 (file)
@@ -91,10 +91,10 @@ protected:
 private:
   Bool_t  fStartTimeIntegral;       // indicator wether integrate time
   // variables for time integration (S.Radomski@gsi.de)
-  Double32_t fIntegratedTime[AliPID::kSPECIES];       // integrated time
+  Double32_t fIntegratedTime[AliPID::kSPECIESC];       // integrated time
   Double32_t fIntegratedLength;        // integrated length
   
-  ClassDef(AliKalmanTrack,7)    // Reconstructed track
+  ClassDef(AliKalmanTrack,8)    // Reconstructed track
 };
 
 #endif
index 2225be3cbe51788d56b2d7a6a31cea8cb2f0f217..ec3b9b97ff97a6594589b92d97e7202665804324 100644 (file)
 #pragma link C++ class  AliESDfriend+;                                                                                                           
 #pragma read sourceClass="AliESDtrack" targetClass="AliESDtrack" source="unsigned char fTRDpidQuality"  version="[-49]" target="fTRDntracklets" targetType="unsigned char" code="{newObj->SetTRDntracklets(onfile.fTRDpidQuality);}"
 // see http://root.cern.ch/svn/root/trunk/io/doc/DataModelEvolution.txt
+
+#pragma read sourceClass="AliESDtrack" targetClass="AliESDtrack" source="Int_t fTOFLabel[3]"  version="[-68]" target="fTOFLabel" targetType="Int_t*" code="{fTOFLabel = new Int_t[3];for(Int_t i=0;i < 3;i++) fTOFLabel[i]=onfile.fTOFLabel[i];}"
+#pragma read sourceClass="AliESDtrack" targetClass="AliESDtrack" source="Double32_t fTrackTime[5]"  version="[-68]" target="fTrackTime" targetType="Double32_t*" include="AliPID.h" code="{fTrackTime = new Double32_t[AliPID::kSPECIESC];for(Int_t isp=0;isp < 5;isp++) fTrackTime[isp]=onfile.fTrackTime[isp];}"
+#pragma read sourceClass="AliESDtrack" targetClass="AliESDtrack" source="Double32_t fTrackLength"  version="[-68]" target="fTrackLength" targetType="Double32_t" code="{fTrackLength=onfile.fTrackLength;}"
+
+
+#pragma read sourceClass="AliESDtrack" targetClass="AliESDtrack" source="Double32_t fTOFsignal"  version="[-68]" target="fTOFsignal" targetType="Double32_t" code="{fTOFsignal=onfile.fTOFsignal;}"
+#pragma read sourceClass="AliESDtrack" targetClass="AliESDtrack" source="Double32_t fTOFsignalToT"  version="[-68]" target="fTOFsignalToT" targetType="Double32_t" code="{fTOFsignalToT=onfile.fTOFsignalToT;}"
+#pragma read sourceClass="AliESDtrack" targetClass="AliESDtrack" source="Double32_t fTOFsignalRaw"  version="[-68]" target="fTOFsignalRaw" targetType="Double32_t" code="{fTOFsignalRaw=onfile.fTOFsignalRaw;}"
+#pragma read sourceClass="AliESDtrack" targetClass="AliESDtrack" source="Double32_t fTOFsignalDx"  version="[-68]" target="fTOFsignalDx" targetType="Double32_t" code="{fTOFsignalDx=onfile.fTOFsignalDx;}"
+#pragma read sourceClass="AliESDtrack" targetClass="AliESDtrack" source="Double32_t fTOFsignalDz"  version="[-68]" target="fTOFsignalDz" targetType="Double32_t" code="{fTOFsignalDz=onfile.fTOFsignalDz;}"
+#pragma read sourceClass="AliESDtrack" targetClass="AliESDtrack" source="Short_t fTOFdeltaBC"  version="[-68]" target="fTOFdeltaBC" targetType="Short_t" code="{fTOFdeltaBC=onfile.fTOFdeltaBC;}"
+#pragma read sourceClass="AliESDtrack" targetClass="AliESDtrack" source="Short_t fTOFl0l1"  version="[-68]" target="fTOFl0l1" targetType="Short_t" code="{fTOFl0l1=onfile.fTOFl0l1;}"
+
+
 #pragma link C++ class  AliESDtrack+;
 #pragma read sourceClass="AliESDfriendTrack" targetClass="AliESDfriendTrack" source="Int_t fITSindex" version="[-3]" \
         target="fnMaxITScluster, fITSindex" targetType="Int_t, Int_t*" code="{fnMaxITScluster = 12; fITSindex= new Int_t[fnMaxITScluster]; memcpy(fITSindex, &(onfile.fITSindex), fnMaxITScluster*sizeof(Int_t));}"
 #pragma link C++ class  AliV0vertexer+;
 #pragma link C++ class  AliCascadeVertexer+;
 
+#pragma link C++ class  AliESDTOFcluster+;
+
 #pragma link C++ function AliESDUtils::GetCorrV0(const AliESDEvent*,Float_t &);
 #pragma link C++ function AliESDUtils::GetCorrSPD2(Float_t,Float_t);
 #pragma link C++ function operator*(const AliFMDMap&,const AliFMDMap&);
diff --git a/STEER/STEERBase/AliVTOFcluster.cxx b/STEER/STEERBase/AliVTOFcluster.cxx
new file mode 100644 (file)
index 0000000..333482c
--- /dev/null
@@ -0,0 +1,42 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, 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.                  * 
+ **************************************************************************/
+
+/* $Id:  $ */
+
+//_________________________________________________________________________//
+//_________________________________________________________________________//
+
+#include "AliVTOFcluster.h"
+
+AliVTOFcluster::AliVTOFcluster(const AliVTOFcluster & source) :
+  TObject(source)
+{
+  // 
+  // copy ctor for AliVTOFcluster object
+  //
+}
+
+AliVTOFcluster & AliVTOFcluster::operator=(const AliVTOFcluster & source)
+{
+  // 
+  // copy ctor for AliVTOFcluster object
+  //
+  if (this != &source) {
+    TObject::operator=(source);
+  }
+  return *this;
+}
+
+ClassImp(AliVTOFcluster)
diff --git a/STEER/STEERBase/AliVTOFcluster.h b/STEER/STEERBase/AliVTOFcluster.h
new file mode 100644 (file)
index 0000000..8d353cc
--- /dev/null
@@ -0,0 +1,54 @@
+// -*- mode: C++ -*- 
+#ifndef ALIVTOFCLUSTER_H
+#define ALIVTOFCLUSTER_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id: $ */
+
+//----------------------------------------------------------------------//
+//                                                                      //
+// AliVTOFcluster Class                                                //
+//                                                                      //
+//----------------------------------------------------------------------//
+
+#include <TObject.h>
+#include <TArrayI.h>
+#include <TArrayF.h>
+
+class AliVTOFcluster : public TObject {
+
+ public:
+
+  AliVTOFcluster() { }
+  virtual ~AliVTOFcluster() { }
+  AliVTOFcluster(const AliVTOFcluster & source);
+  AliVTOFcluster & operator=(const AliVTOFcluster & source);
+
+  virtual Int_t GetClusterIndex() const {return 0;} // cluster index
+  virtual Int_t GetTOFchannel() const {return 0;}; // TOF channel
+  virtual Float_t GetTime() const {return 0;}; // TOF time
+  virtual Float_t GetTimeRaw() const {return 0;}; // TOF raw time
+  virtual Float_t GetTOT() const {return 0;}; // TOF ToT
+  virtual Int_t GetLabel(Int_t ) const {return 0;};
+  virtual Int_t GetDeltaBC() const {return 0;};
+  virtual Int_t GetL0L1Latency() const {return 0;};
+  virtual Bool_t GetStatus() const {return 0;};
+  virtual Float_t GetZ() const {return 0;};
+  virtual Float_t GetPhi() const {return 0;};
+  virtual Float_t GetR() const {return 0;};
+  virtual Int_t GetNMatchableTracks() const {return 0;};
+  virtual Int_t GetTrackIndex(Int_t ) const {return 0;};
+  virtual Float_t GetDistanceInStripPlane(Int_t )   const {return 0;};
+  virtual Float_t GetDx(Int_t )  const {return 0;};
+  virtual Float_t GetDy(Int_t )  const {return 0;};
+  virtual Float_t GetDz(Int_t )  const {return 0;};
+  virtual Float_t GetLength(Int_t ) const {return 0;};
+  virtual Double_t GetIntegratedTime(Int_t ,Int_t ) const {return 0;};
+
+  ClassDef(AliVTOFcluster, 1) // TOF matchable cluster
+
+}; 
+
+#endif
index 2759794d3094a8170843018669cafd597e250dac..baa945ef1d5695d8cda986973d8606c2c134eaf1 100644 (file)
@@ -2,7 +2,7 @@
 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
  * See cxx source for full Copyright notice                               */
 
-/* $Id$ */
+/* $Id: STEERBaseLinkDef.h 65235 2013-12-02 15:40:49Z jgrosseo $ */
 
 #pragma link off all globals;
 #pragma link off all classes;
 #pragma link C++ class AliVTrdTracklet+;
 #pragma link C++ class AliGenEventHeaderTunedPbPb+;
 
+#pragma link C++ class AliVTOFcluster+;
+
 #endif
 
index 753f20d6a1ed7ff20152a731a9d8dc62b9fa0924..adb9832697302533abeec640bd5448b47cb5a2f0 100644 (file)
@@ -13,7 +13,7 @@
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/* $Id$ */
+/* $Id: AliTOFReconstructor.cxx 59948 2012-12-12 11:05:59Z fnoferin $ */
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
@@ -37,6 +37,7 @@
 #include "AliTOFtrackerMI.h"
 #include "AliTOFtracker.h"
 #include "AliTOFtrackerV1.h"
+#include "AliTOFtrackerV2.h"
 #include "AliTOFT0maker.h"
 #include "AliTOFReconstructor.h"
 #include "AliTOFTriggerMask.h"
@@ -299,6 +300,9 @@ AliTracker* AliTOFReconstructor::CreateTracker() const
   else if (selectedTracker.Contains("TrackerV1")) {
     tracker =  new AliTOFtrackerV1();
   }
+  else if (selectedTracker.Contains("TrackerV2")) {
+    tracker =  new AliTOFtrackerV2();
+  }
   else {
     tracker = new AliTOFtracker();
   }
index a15ed715b9f8bdcb6b1effc1d0f8e1efad9f09d8..64bd058b1fc1bc305405a5577e6b749824070a08 100644 (file)
@@ -72,8 +72,13 @@ AliTOFtrack::AliTOFtrack(const AliESDtrack& t) :
 
   if ((t.GetStatus()&AliESDtrack::kTIME) == 0) return;
   StartTimeIntegral();
-  Double_t times[10]; t.GetIntegratedTimes(times); SetIntegratedTimes(times);
-  SetIntegratedLength(t.GetIntegratedLength());
+  Double_t times[10]; 
+  for(Int_t isp=0;isp<AliPID::kSPECIESC;isp++){
+    times[isp] = t.GetIntegratedTimesOld(isp); // in ps
+  }
+
+  SetIntegratedTimes(times);
+  SetIntegratedLength(t.GetIntegratedLengthOld());
 
 }              
 
index f776c71c38f1d5f56539b6f98262aee75a0f2a4b..aecefb87e88d548fbe47bcc858e13a2c6b33de38 100644 (file)
@@ -89,7 +89,8 @@ AliTOFtracker::AliTOFtracker():
   fTime(-1.),
   fExpTimePi(-1.),
   fExpTimeKa(-1.),
-  fExpTimePr(-1.)
+  fExpTimePr(-1.),
+  fNTOFmatched(0)
 {
   //AliTOFtracker main Ctor
 
@@ -143,6 +144,14 @@ AliTOFtracker::~AliTOFtracker() {
   for (Int_t ii=0; ii<kMaxCluster; ii++)
     if (fClusters[ii]) fClusters[ii]->Delete();
 
+  for(Int_t i=0; i< 20000;i++){
+    if(fClusterESD[i]){
+      delete fClusterESD[i];
+      fClusterESD[i] = NULL;
+    }
+  }
+
+
 }
 //_____________________________________________________________________________
 void AliTOFtracker::GetPidSettings(AliESDpid *esdPID) {
@@ -160,6 +169,14 @@ Int_t AliTOFtracker::PropagateBack(AliESDEvent * const event) {
   // Gets seeds from ESD event and Match with TOF Clusters
   //
 
+  if(fNTOFmatched==0)
+    event->SetTOFcluster(1,fClusterESD);
+
+  if (fN==0) {
+    AliInfo("No TOF recPoints to be matched with reconstructed tracks");
+    return 0;
+  }
+
   // initialize RecoParam for current event
   AliDebug(1,"Initializing params for TOF");
 
@@ -192,11 +209,26 @@ Int_t AliTOFtracker::PropagateBack(AliESDEvent * const event) {
   //Prepare ESD tracks candidates for TOF Matching
   CollectESD();
 
+  if (fNseeds==0 || fNseedsTOF==0) {
+    AliInfo("No seeds to try TOF match");
+    return 0 ;
+  }
+
   //First Step with Strict Matching Criterion
-  MatchTracks(kFALSE);
+  MatchTracks(0);
 
   //Second Step with Looser Matching Criterion
-  MatchTracks(kTRUE);
+  MatchTracks(1);
+
+  //Third Step without kTOFout flag (just to update clusters)
+  MatchTracks(2);
+
+  event->SetTOFcluster(fNTOFmatched,fClusterESD); 
+  if (fNTOFmatched==0) {
+    AliInfo("No TOF recPoints to be matched with reconstructed tracks");
+    return 0;
+  }
 
   AliInfo(Form("Number of matched tracks = %d (good = %d, bad = %d)",fnmatch,fngoodmatch,fnbadmatch));
 
@@ -252,10 +284,10 @@ Int_t AliTOFtracker::PropagateBack(AliESDEvent * const event) {
          AliTOFtrack *track = new AliTOFtrack(*seed);
          t->UpdateTrackParams(track,AliESDtrack::kTOFout); // to be checked - AdC
          delete track;
-         Double_t time[10]; t->GetIntegratedTimes(time);
+         Double_t time[AliPID::kSPECIESC]; t->GetIntegratedTimes(time);
        */
 
-       Double_t time[10]; seed->GetIntegratedTimes(time);
+       Double_t time[AliPID::kSPECIESC]; seed->GetIntegratedTimes(time);
        t->SetIntegratedTimes(time);
 
        Double_t length =  seed->GetIntegratedLength();
@@ -269,17 +301,17 @@ Int_t AliTOFtracker::PropagateBack(AliESDEvent * const event) {
        Double_t p2B = (Double_t)t->GetTgl();
        Double_t p3B = (Double_t)t->GetSigned1Pt();
        const Double_t *covB = (Double_t*)t->GetCovariance();
-       AliDebug(2,"Track params -now(before)-:");
-       AliDebug(2,Form("    X: %f(%f), Y: %f(%f), Z: %f(%f) --- alpha: %f(%f)",
+       AliDebug(3,"Track params -now(before)-:");
+       AliDebug(3,Form("    X: %f(%f), Y: %f(%f), Z: %f(%f) --- alpha: %f(%f)",
                        xB,xA,
                        yB,yA,
                        zB,zA,
                        alphaB,alphaA));
-       AliDebug(2,Form("    p1: %f(%f), p2: %f(%f), p3: %f(%f)",
+       AliDebug(3,Form("    p1: %f(%f), p2: %f(%f), p3: %f(%f)",
                        p1B,p1A,
                        p2B,p2A,
                        p3B,p3A));
-       AliDebug(2,Form("    cov1: %f(%f), cov2: %f(%f), cov3: %f(%f)"
+       AliDebug(3,Form("    cov1: %f(%f), cov2: %f(%f), cov3: %f(%f)"
                        " cov4: %f(%f), cov5: %f(%f), cov6: %f(%f)"
                        " cov7: %f(%f), cov8: %f(%f), cov9: %f(%f)"
                        " cov10: %f(%f), cov11: %f(%f), cov12: %f(%f)"
@@ -300,7 +332,7 @@ Int_t AliTOFtracker::PropagateBack(AliESDEvent * const event) {
                        covB[13],covA[13],
                        covB[14],covA[14]
                        ));
-       AliDebug(3,Form(" TOF params: %6d  %f %f %f %f %f %6d %3d %f  %f %f %f %f %f",
+       AliDebug(2,Form(" TOF params: %6d  %f %f %f %f %f %6d %3d  %f",
                        i,
                        t->GetTOFsignalRaw(),
                        t->GetTOFsignal(),
@@ -309,14 +341,24 @@ Int_t AliTOFtracker::PropagateBack(AliESDEvent * const event) {
                        t->GetTOFsignalDx(),
                        t->GetTOFCalChannel(),
                        t->GetTOFcluster(),
-                       t->GetIntegratedLength(),
-                       time[0], time[1], time[2], time[3], time[4]
-                       )
-                );
+                       t->GetIntegratedLength()));
+       AliDebug(2,Form(" %f %f %f %f %f %f %f %f %f",
+                       time[0], time[1], time[2], time[3], time[4], time[5], time[6], time[7], time[8]));
       }
     }
   }
 
+  if(fNTOFmatched){
+    Int_t *matchmap = new Int_t[fNTOFmatched];
+    event->SetTOFcluster(fNTOFmatched,fClusterESD,matchmap);
+    for (Int_t i=0; i<ntrk; i++) { // remapping after TOF matching selection
+      AliESDtrack *t=event->GetTrack(i);
+      t->ReMapTOFcluster(fNTOFmatched,matchmap);
+    }
+
+    delete[] matchmap;
+  }
+
   //Make TOF PID
   // Now done in AliESDpid
   // fPid->MakePID(event,timeZero);
@@ -421,7 +463,7 @@ void AliTOFtracker::CollectESD() {
 }
 
 //_________________________________________________________________________
-void AliTOFtracker::MatchTracks( Bool_t mLastStep){
+void AliTOFtracker::MatchTracks( Int_t mLastStep){
 
   // Parameters used/regulating the reconstruction
 
@@ -446,10 +488,14 @@ void AliTOFtracker::MatchTracks( Bool_t mLastStep){
     AliInfo(Form("Matching window=%f, since low multiplicity event (fNseedsTOF=%d)",
                 dCut, fNseedsTOF));
   }
+  if(mLastStep == 2)
+    dCut=10.;
+
+
   Double_t maxChi2=fkRecoParam->GetMaxChi2TRD();
   Bool_t timeWalkCorr    = fkRecoParam->GetTimeWalkCorr();
   if(!mLastStep){
-    AliDebug(1,"++++++++++++++TOF Reconstruction Parameters:++++++++++++ \n");
+    AliDebug(1,"++++++++++++++TOF Reconstruction Parameters:++++++++++++");
     AliDebug(1,Form("TOF sens radius: %f",sensRadius));
     AliDebug(1,Form("TOF step size: %f",stepSize));
     AliDebug(1,Form("TOF Window scale factor: %f",scaleFact));
@@ -466,6 +512,8 @@ void AliTOFtracker::MatchTracks( Bool_t mLastStep){
   Int_t nSteps=(Int_t)(detDepth/stepSize);
   AliDebug(1,Form(" Number of steps to be done %d",nSteps));
 
+  AliDebug(1,"++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
+
   //PH Arrays (moved outside of the loop)
   Float_t * trackPos[4];
   for (Int_t ii=0; ii<4; ii++) trackPos[ii] = new Float_t[nSteps];
@@ -485,7 +533,7 @@ void AliTOFtracker::MatchTracks( Bool_t mLastStep){
     AliTOFtrack *track =(AliTOFtrack*)fTracks->UncheckedAt(iseed);
     AliESDtrack *t =(AliESDtrack*)fSeeds->At(track->GetSeedIndex());
     //if ( t->GetTOFsignal()>0. ) continue;
-    if ( (t->GetStatus()&AliESDtrack::kTOFout)!=0 ) continue;
+    if ( ((t->GetStatus()&AliESDtrack::kTOFout)!=0 ) && mLastStep < 2) continue;
     AliTOFtrack *trackTOFin = new AliTOFtrack(*track);
 
     // Determine a window around the track
@@ -528,7 +576,7 @@ void AliTOFtracker::MatchTracks( Bool_t mLastStep){
 
       AliTOFcluster *c=fClusters[k];
       if (c->GetZ() > z+dz) break;
-      if (c->IsUsed()) continue;
+      if (c->IsUsed() && mLastStep < 2) continue;
       if (!c->GetStatus()) {
        AliDebug(1,"Cluster in channel declared bad!");
        continue; // skip bad channels as declared in OCDB
@@ -557,14 +605,15 @@ void AliTOFtracker::MatchTracks( Bool_t mLastStep){
       nc++;
     }
 
-    AliDebug(1,Form(" Number of matchable TOF clusters for the track number %d: %d",iseed,nc));
-
     if (nc == 0 ) {
+      AliDebug(1,Form("No available clusters for the track number %d",iseed));
       fnunmatch++;
       delete trackTOFin;
       continue;
     }
 
+    AliDebug(1,Form(" Number of available TOF clusters for the track number %d: %d",iseed,nc));
+
     //start fine propagation 
 
     Int_t nStepsDone = 0;
@@ -584,7 +633,7 @@ void AliTOFtracker::MatchTracks( Bool_t mLastStep){
       }
 
       nStepsDone++;
-      AliDebug(2,Form(" current step %d (%d) - nStepsDone=%d",istep,nSteps,nStepsDone));
+      AliDebug(3,Form(" current step %d (%d) - nStepsDone=%d",istep,nSteps,nStepsDone));
 
       // store the running point (Globalrf) - fine propagation     
 
@@ -623,7 +672,7 @@ void AliTOFtracker::MatchTracks( Bool_t mLastStep){
           Float_t yLoc = dist3d[1];
           Float_t rLoc = TMath::Sqrt(dist3d[0]*dist3d[0]+dist3d[2]*dist3d[2]);
          accept = (TMath::Abs(yLoc)<padDepth*0.5 && rLoc<dCut);
-         AliDebug(2," I am in the case mLastStep==kTRUE ");
+         AliDebug(3," I am in the case mLastStep==kTRUE ");
        }
        else {
          accept = isInside;
@@ -635,7 +684,7 @@ void AliTOFtracker::MatchTracks( Bool_t mLastStep){
                                                        dist3d[2],dist3d[0],dist3d[1],
                                                        AliTOFGeometry::RinTOF()+istep*stepSize,trackPos[3][istep]));
 
-         AliDebug(2,Form(" dist3dLoc[0] = %f, dist3dLoc[1] = %f, dist3dLoc[2] = %f ",dist3d[0],dist3d[1],dist3d[2]));
+         AliDebug(3,Form(" dist3dLoc[0] = %f, dist3dLoc[1] = %f, dist3dLoc[2] = %f ",dist3d[0],dist3d[1],dist3d[2]));
          nfound++;
          if(accept &&!mLastStep)break;
        }//end if accept
@@ -649,18 +698,25 @@ void AliTOFtracker::MatchTracks( Bool_t mLastStep){
     /*****************/
 #endif
 
-    AliDebug(1,Form(" Number of steps done for the track number %d: %d",iseed,nStepsDone));
-
     if ( nStepsDone == 0 ) {
+      AliDebug(1,Form(" No track points for the track number %d",iseed));
       fnunmatch++;
       delete trackTOFin;
       continue;
     }
 
+    AliDebug(2,Form(" Number of steps done for the track number %d: %d",iseed,nStepsDone));
+
     /*****************/
     /**** NEW CODE ***/
     /*****************/
 
+    Int_t *isClusterMatchable = NULL;
+    if(nc){
+      isClusterMatchable = new Int_t[nc];
+      for (Int_t i=0; i<nc; i++) isClusterMatchable[i] = kFALSE;               
+    }
+
     Int_t nfound = 0;
     Bool_t accept = kFALSE;
     Bool_t isInside = kFALSE;
@@ -686,10 +742,10 @@ void AliTOFtracker::MatchTracks( Bool_t mLastStep){
          * this will allow to only go on and add track points for
          * that cluster where the track got inside first */
         if (gotInsideCluster && trackInsideCluster != i) {
-         AliDebug(2,Form(" A - istep=%d ~ %d %d ~ nfound=%d",istep,trackInsideCluster,i,nfound));
+         AliDebug(3,Form(" A - istep=%d ~ %d %d ~ nfound=%d",istep,trackInsideCluster,i,nfound));
           continue;
        }
-       AliDebug(2,Form(" B - istep=%d ~ %d %d ~ nfound=%d",istep,trackInsideCluster,i,nfound));
+       AliDebug(3,Form(" B - istep=%d ~ %d %d ~ nfound=%d",istep,trackInsideCluster,i,nfound));
 
         /* check whether track is inside this cluster */
        for (Int_t hh=0; hh<3; hh++) dist3d[hh]=0.;
@@ -707,7 +763,7 @@ void AliTOFtracker::MatchTracks( Bool_t mLastStep){
           Float_t yLoc = dist3d[1];
           Float_t rLoc = TMath::Sqrt(dist3d[0]*dist3d[0]+dist3d[2]*dist3d[2]);
           accept = (TMath::Abs(yLoc)<padDepth*0.5 && rLoc<dCut);
-          AliDebug(2," I am in the case mLastStep==kTRUE ");
+          AliDebug(3," I am in the case mLastStep==kTRUE ");
         }
 
        //***** NEW *****
@@ -726,8 +782,29 @@ void AliTOFtracker::MatchTracks( Bool_t mLastStep){
           AliDebug(2,Form(" dist3dLoc[0] = %f, dist3dLoc[1] = %f, dist3dLoc[2] = %f ",dist3d[0],dist3d[1],dist3d[2]));
           nfound++;
 
-         AliDebug(2,Form(" C - istep=%d ~ %d %d ~ nfound=%d",istep,trackInsideCluster,i,nfound));
+         AliDebug(3,Form(" C - istep=%d ~ %d %d ~ nfound=%d",istep,trackInsideCluster,i,nfound));
         
+
+         if(clind[i] < 20000 && mLastStep==2 && !isClusterMatchable[i]){ // add TOF clusters to the track
+           isClusterMatchable[i] = kTRUE;
+
+           //Tracking info
+           Double_t mom=t->GetP();
+           AliDebug(3,Form(" Momentum for track %d -> %f", iseed,mom));
+           Double_t time[AliPID::kSPECIESC];
+           // read from old structure (the one used by TPC in reco)
+           for(Int_t isp=0;isp<AliPID::kSPECIESC;isp++){
+             time[isp] = t->GetIntegratedTimesOld(isp); // in ps
+             Double_t mass=AliPID::ParticleMass(isp);
+             Double_t momz = mom*AliPID::ParticleCharge(isp);
+             time[isp]+=(trackPos[3][istep]-trackPos[3][0])/kSpeedOfLight*TMath::Sqrt(momz*momz+mass*mass)/momz;
+             //time[isp]+=(trackPos[3][istep]-trackPos[3][0])/kSpeedOfLight*TMath::Sqrt(mom*mom+mass*mass)/mom;
+           }
+
+           if(!fClusterESD[clind[i]]->Update(t->GetID(),dist3d[1],dist3d[0],dist3d[2],trackPos[3][istep],time))//x,y,z -> tracking RF
+             t->AddTOFcluster(clind[i]);
+         }
+
           // ***** NEW *****
           /* do not break loop in any case
            * if the track got inside a cluster all other clusters
@@ -745,16 +822,17 @@ void AliTOFtracker::MatchTracks( Bool_t mLastStep){
       //      if(accept &&!mLastStep)break;
       
     } //end for on the steps     
-
-
-    AliDebug(1,Form(" Number of track points for the track number %d: %d",iseed,nfound));
+    if(nc) delete[] isClusterMatchable;
 
     if (nfound == 0 ) {
+      AliDebug(1,Form("No track points for the track number %d",iseed));
       fnunmatch++;
       delete trackTOFin;
       continue;
     }
     
+    AliDebug(1,Form(" Number of track points for the track number %d: %d",iseed,nfound));
+
     // now choose the cluster to be matched with the track.
 
     Int_t idclus=-1;
@@ -789,14 +867,14 @@ void AliTOFtracker::MatchTracks( Bool_t mLastStep){
         idclus = matchableTOFcluster->Index();
         recL = matchableTOFcluster->Length();// + corrLen*0.5;
 
-       AliDebug(1,Form(" %d(%d) --- %f (%f, %f, %f), step=%f -- idclus=%d --- seed=%d, trackId=%d, trackLab=%d", iclus,nfound,
+       AliDebug(2,Form(" %d(%d) --- %f (%f, %f, %f), step=%f -- idclus=%d --- seed=%d, trackId=%d, trackLab=%d", iclus,nfound,
                        mindist,mindistX,mindistY,mindistZ,stepSize,idclus,iseed,track->GetSeedIndex(),track->GetLabel()));
 
       }
     } // loop on found TOF track points
 
     if (TMath::Abs(mindistX)>stepSize && idclus!=-1) {
-      AliInfo(Form("--------Not matched --- but idclus=%d, trackId=%d, trackLab=%d",
+      AliInfo(Form(" %d - not matched --- but idclus=%d, trackId=%d, trackLab=%d",iseed,
                   idclus,track->GetSeedIndex(),track->GetLabel()));
       idclus=-1;
     }
@@ -808,13 +886,13 @@ void AliTOFtracker::MatchTracks( Bool_t mLastStep){
       continue;
     }
 
-    AliDebug(1,"--------Matched");
+    AliDebug(1,Form(" %d - matched",iseed));
 
     fnmatch++;
 
     AliTOFcluster *c=fClusters[idclus];
 
-    AliDebug(2, Form("%7d     %7d     %10d     %10d  %10d  %10d      %7d",
+    AliDebug(3, Form("%7d     %7d     %10d     %10d  %10d  %10d      %7d",
                     iseed,
                     fnmatch-1,
                     TMath::Abs(trackTOFin->GetLabel()),
@@ -868,7 +946,7 @@ void AliTOFtracker::MatchTracks( Bool_t mLastStep){
     Float_t info[10] = {mindist,mindistY,mindistZ,
                        0.,0.,0.,0.,0.,0.,0.};
     t->SetTOFInfo(info);
-    AliDebug(2,Form(" distance=%f; residual in the pad reference frame: dX=%f, dZ=%f", info[0],info[1],info[2]));
+    AliDebug(3,Form(" distance=%f; residual in the pad reference frame: dX=%f, dZ=%f", info[0],info[1],info[2]));
 
 
     Int_t ind[5];
@@ -885,25 +963,31 @@ void AliTOFtracker::MatchTracks( Bool_t mLastStep){
     tlab[0]=c->GetLabel(0);
     tlab[1]=c->GetLabel(1);
     tlab[2]=c->GetLabel(2);
-    AliDebug(2,Form(" tdc time of the matched track %6d = ",c->GetTDC()));    
+    AliDebug(3,Form(" tdc time of the matched track %6d = ",c->GetTDC()));    
     Double_t tof=AliTOFGeometry::TdcBinWidth()*c->GetTDC()+kTimeOffset; // in ps
-    AliDebug(2,Form(" tof time of the matched track: %f = ",tof));    
+    AliDebug(3,Form(" tof time of the matched track: %f = ",tof));    
     Double_t tofcorr=tof;
     if(timeWalkCorr)tofcorr=CorrectTimeWalk(mindistZ,tof);
-    AliDebug(2,Form(" tof time of the matched track, after TW corr: %f = ",tofcorr));    
+    AliDebug(3,Form(" tof time of the matched track, after TW corr: %f = ",tofcorr));    
     //Set TOF time signal and pointer to the matched cluster
     t->SetTOFsignal(tofcorr);
     t->SetTOFcluster(idclus); // pointing to the recPoints tree
 
-    AliDebug(2,Form(" Setting TOF raw time: %f, z distance: %f  corrected time: %f ",rawTime,mindistZ,tofcorr));
+    AliDebug(3,Form(" Setting TOF raw time: %f, z distance: %f  corrected time: %f ",rawTime,mindistZ,tofcorr));
 
     //Tracking info
-    Double_t time[AliPID::kSPECIES]; t->GetIntegratedTimes(time); // in ps
+    Double_t time[AliPID::kSPECIESC];
+    // read from old structure (the one used by TPC in reco)
+    for(Int_t isp=0;isp<AliPID::kSPECIESC;isp++){
+      time[isp] = t->GetIntegratedTimesOld(isp); // in ps
+    }
     Double_t mom=t->GetP();
-    AliDebug(2,Form(" Momentum for track %d -> %f", iseed,mom));
-    for (Int_t j=0;j<AliPID::kSPECIES;j++) {
+    AliDebug(3,Form(" Momentum for track %d -> %f", iseed,mom));
+    for (Int_t j=0;j<AliPID::kSPECIESC;j++) {
       Double_t mass=AliPID::ParticleMass(j);
-      time[j]+=(recL-trackPos[3][0])/kSpeedOfLight*TMath::Sqrt(mom*mom+mass*mass)/mom;
+      Double_t momz = mom*AliPID::ParticleCharge(j);
+      time[j]+=(recL-trackPos[3][0])/kSpeedOfLight*TMath::Sqrt(momz*momz+mass*mass)/momz;
+      //time[j]+=(recL-trackPos[3][0])/kSpeedOfLight*TMath::Sqrt(mom*mom+mass*mass)/mom;
     }
 
     AliTOFtrack *trackTOFout = new AliTOFtrack(*t); 
@@ -927,15 +1011,28 @@ void AliTOFtracker::MatchTracks( Bool_t mLastStep){
       }
     }
 
-    // Fill the track residual histograms.
-    FillResiduals(trackTOFout,c,kFALSE);
+    // Fill the track residual histograms and update track only if in the first two step (0 and 1)
+    if(mLastStep < 2){
+      FillResiduals(trackTOFout,c,kFALSE);
 
-    t->UpdateTrackParams(trackTOFout,AliESDtrack::kTOFout);
-    t->SetIntegratedLength(recL);
-    t->SetIntegratedTimes(time);
-    t->SetTOFLabel(tlab);
+      t->UpdateTrackParams(trackTOFout,AliESDtrack::kTOFout);
 
+// don't update old structure with TOF info
+//       t->SetIntegratedLength(recL);
+//       t->SetIntegratedTimes(time);
+//       t->SetTOFLabel(tlab);
  
+    // add tof cluster to the track also for step 2
+      if(idclus < 20000){
+       fClusterESD[idclus]->Update(t->GetID(),mindistY,mindist,mindistZ,recL,time);//x,y,z -> tracking RF
+       
+       t->AddTOFcluster(idclus);
+      }
+      else{
+       AliInfo("Too many TOF clusters matched with tracks (> 20000)");
+      }
+      
+    }
     // Fill Reco-QA histos for Reconstruction
     fHRecNClus->Fill(nc);
     fHRecDist->Fill(mindist);
@@ -964,6 +1061,7 @@ void AliTOFtracker::MatchTracks( Bool_t mLastStep){
     delete trackTOFout;
   }
 
+
   for (Int_t ii=0; ii<4; ii++) delete [] trackPos[ii];
   delete [] clind;
  
@@ -997,6 +1095,14 @@ Int_t AliTOFtracker::LoadClusters(TTree *cTree) {
 
   AliInfo(Form("Number of clusters: %d",nc));
 
+  fNTOFmatched = 0;
+  for(Int_t i=0; i< 20000;i++){
+    if(fClusterESD[i]){
+      delete fClusterESD[i];
+      fClusterESD[i] = NULL;
+    }
+  }
+
   for (Int_t i=0; i<nc; i++) {
     AliTOFcluster *c=(AliTOFcluster*)clusters->UncheckedAt(i);
 //PH    fClusters[i]=new AliTOFcluster(*c); fN++;
@@ -1012,6 +1118,16 @@ Int_t AliTOFtracker::LoadClusters(TTree *cTree) {
 
     Float_t time =(AliTOFGeometry::TdcBinWidth()*c->GetTDC())*1E-3; // in ns
     Float_t tot = (AliTOFGeometry::TdcBinWidth()*c->GetToT())*1E-3;//in ns
+
+    Int_t ind[5];
+    ind[0]=isector;
+    ind[1]=iplate;
+    ind[2]=istrip;
+    ind[3]=ipadX;
+    ind[4]=ipadZ;
+
+    Int_t calindex = AliTOFGeometry::GetIndex(ind);
+    Int_t tofLabels[3]={c->GetLabel(0),c->GetLabel(1),c->GetLabel(2)};
  
     Int_t stripOffset = 0;
     switch (iplate) {
@@ -1040,9 +1156,23 @@ Int_t AliTOFtracker::LoadClusters(TTree *cTree) {
     fHDigClusTime->Fill(time);
     fHDigClusToT->Fill(tot);
 
+    if(fNTOFmatched < 20000){
+      fClusterESD[fNTOFmatched] = new AliESDTOFcluster(i,calindex,
+                               AliTOFGeometry::TdcBinWidth()*c->GetTDC()/*ps*/,
+                               AliTOFGeometry::TdcBinWidth()*c->GetTDCRAW()/*ps*/,
+                               AliTOFGeometry::ToTBinWidth()*c->GetToT()*1E-3/*ns*/,
+                               tofLabels,
+                               c->GetDeltaBC(),c->GetL0L1Latency(),
+                               c->GetStatus(),c->GetZ(),c->GetPhi(),c->GetR());
+      fNTOFmatched++;
+    }
+
   }
 
 
+  if(fNTOFmatched == 0)
+    fClusterESD[0] = new AliESDTOFcluster();
+
   return 0;
 }
 //_________________________________________________________________________
index 2d1f3d7ea9a3667d448e35cf9a602d8fa5ccf703..75832ac2868ccee6db6b39de5c1fb4eaa2f91783 100644 (file)
@@ -21,7 +21,7 @@
 #include "AliTracker.h"
 
 #include "TObject.h"
-
+#include "AliESDTOFcluster.h"
 
 class TClonesArray;
 class TObjArray;
@@ -116,7 +116,7 @@ private:
  AliTOFtracker& operator=(const AliTOFtracker &source); // ass. op.
 
  Int_t FindClusterIndex(Double_t z) const; // Returns cluster index 
- void  MatchTracks(Bool_t mLastStep); // Matching Algorithm 
+ void  MatchTracks(Int_t mLastStep); // Matching Algorithm 
  void  CollectESD(); // Select starting Set for Matching 
  Float_t CorrectTimeWalk(Float_t dist,Float_t tof) const; // Time Walk correction
 
@@ -158,7 +158,10 @@ private:
  Float_t fExpTimeKa; // exp time, Kaons
  Float_t fExpTimePr; // exp time, Protons
 
- ClassDef(AliTOFtracker, 6) // TOF tracker 
+ Int_t fNTOFmatched;                   // number of matched TOF cluster
+ AliESDTOFcluster *fClusterESD[20000]; // pointers to the TOF clusters for ESD
+
+ ClassDef(AliTOFtracker, 7) // TOF tracker 
 };
 
 #endif
index 54bea69fa30acd570eb2b381e8aa7e0c1c5fe135..bd308f9f3c7a65ba0f5d643ed7c2d783c03b2538 100644 (file)
@@ -141,6 +141,11 @@ Int_t AliTOFtrackerV1::PropagateBack(AliESDEvent * const event) {
   // Gets seeds from ESD event and Match with TOF Clusters
   //
 
+  if (fN==0) {
+    AliInfo("No TOF recPoints to be matched with reconstructed tracks");
+    return 0;
+  }
+
   // initialize RecoParam for current event
   AliDebug(1,"Initializing params for TOF");
 
@@ -172,6 +177,11 @@ Int_t AliTOFtrackerV1::PropagateBack(AliESDEvent * const event) {
   //Prepare ESD tracks candidates for TOF Matching
   CollectESD();
 
+  if (fNseeds==0 || fNseedsTOF==0) {
+    AliInfo("No seeds to try TOF match");
+    return 0;
+  }
+
   //Matching Step
   MatchTracks();
 
@@ -230,10 +240,10 @@ Int_t AliTOFtrackerV1::PropagateBack(AliESDEvent * const event) {
          AliTOFtrack *track = new AliTOFtrack(*seed);
          t->UpdateTrackParams(track,AliESDtrack::kTOFout); // to be checked - AdC
          delete track;
-         Double_t time[10]; t->GetIntegratedTimes(time);
+         Double_t time[AliPID::kSPECIESC]; t->GetIntegratedTimes(time);
        */
 
-       Double_t time[10]; seed->GetIntegratedTimes(time);
+       Double_t time[AliPID::kSPECIESC]; seed->GetIntegratedTimes(time);
        t->SetIntegratedTimes(time);
 
        Double_t length =  seed->GetIntegratedLength();
@@ -247,17 +257,17 @@ Int_t AliTOFtrackerV1::PropagateBack(AliESDEvent * const event) {
        Double_t p2B = (Double_t)t->GetTgl();
        Double_t p3B = (Double_t)t->GetSigned1Pt();
        const Double_t *covB = (Double_t*)t->GetCovariance();
-       AliDebug(2,"Track params -now(before)-:");
-       AliDebug(2,Form("    X: %f(%f), Y: %f(%f), Z: %f(%f) --- alpha: %f(%f)",
+       AliDebug(3,"Track params -now(before)-:");
+       AliDebug(3,Form("    X: %f(%f), Y: %f(%f), Z: %f(%f) --- alpha: %f(%f)",
                        xB,xA,
                        yB,yA,
                        zB,zA,
                        alphaB,alphaA));
-       AliDebug(2,Form("    p1: %f(%f), p2: %f(%f), p3: %f(%f)",
+       AliDebug(3,Form("    p1: %f(%f), p2: %f(%f), p3: %f(%f)",
                        p1B,p1A,
                        p2B,p2A,
                        p3B,p3A));
-       AliDebug(2,Form("    cov1: %f(%f), cov2: %f(%f), cov3: %f(%f)"
+       AliDebug(3,Form("    cov1: %f(%f), cov2: %f(%f), cov3: %f(%f)"
                        " cov4: %f(%f), cov5: %f(%f), cov6: %f(%f)"
                        " cov7: %f(%f), cov8: %f(%f), cov9: %f(%f)"
                        " cov10: %f(%f), cov11: %f(%f), cov12: %f(%f)"
@@ -278,7 +288,7 @@ Int_t AliTOFtrackerV1::PropagateBack(AliESDEvent * const event) {
                        covB[13],covA[13],
                        covB[14],covA[14]
                        ));
-       AliDebug(3,Form(" %6d  %f %f %f %f %f %6d %3d %f  %f %f %f %f %f",
+       AliDebug(2,Form(" TOF params: %6d  %f %f %f %f %f  %6d %3d  %f",
                        i,
                        t->GetTOFsignalRaw(),
                        t->GetTOFsignal(),
@@ -287,10 +297,9 @@ Int_t AliTOFtrackerV1::PropagateBack(AliESDEvent * const event) {
                        t->GetTOFsignalDx(),
                        t->GetTOFCalChannel(),
                        t->GetTOFcluster(),
-                       t->GetIntegratedLength(),
-                       time[0], time[1], time[2], time[3], time[4]
-                       )
-                );
+                       t->GetIntegratedLength()));
+       AliDebug(2,Form(" %f %f %f %f %f %f %f %f %f",
+                       time[0], time[1], time[2], time[3], time[4], time[5], time[6], time[7], time[8]));
       }
     }
   }
@@ -410,14 +419,14 @@ void AliTOFtrackerV1::MatchTracks( ){
   Float_t dzMax=fkRecoParam->GetWindowSizeMaxZ();
   Double_t maxChi2=fkRecoParam->GetMaxChi2();
   Bool_t timeWalkCorr    = fkRecoParam->GetTimeWalkCorr();
-  AliDebug(1,"++++++++++++++TOF Reconstruction Parameters:++++++++++++ \n");
+  AliDebug(1,"++++++++++++++TOF Reconstruction Parameters:++++++++++++");
   AliDebug(1,Form("TOF sens radius: %f",sensRadius));
   AliDebug(1,Form("TOF Window scale factor: %f",scaleFact));
   AliDebug(1,Form("TOF Window max dy: %f",dyMax));
   AliDebug(1,Form("TOF Window max dz: %f",dzMax));
   AliDebug(1,Form("TOF Max Chi2: %f",maxChi2));
   AliDebug(1,Form("Time Walk Correction? : %d",timeWalkCorr));   
-
+  AliDebug(1,"++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
 
   //The matching loop
   for (Int_t iseed=0; iseed<fNseedsTOF; iseed++) {
@@ -518,14 +527,16 @@ void AliTOFtrackerV1::MatchTracks( ){
     }
     
     if (!bestCluster) {  // no matching , go to the next track 
+      AliDebug(1,Form("No track points for the track number %d",iseed));
       fnunmatch++;
       delete trackTOFin;
       continue;
     }
 
     fnmatch++;
+    AliDebug(1,Form(" Matched TOF cluster %d for the track number %d: %d",idclus,iseed));
 
-    AliDebug(2, Form("%7i     %7i     %10i     %10i  %10i  %10i      %7i",
+    AliDebug(3, Form("%7i     %7i     %10i     %10i  %10i  %10i      %7i",
                     iseed,
                     fnmatch-1,
                     TMath::Abs(trackTOFin->GetLabel()),
@@ -579,7 +590,7 @@ void AliTOFtrackerV1::MatchTracks( ){
     Double_t dzTW=trackTOFin->GetZ()-bestCluster->GetZ(); // in cm - in the ALICE RF -
     dzTW/=TMath::Cos(tiltangle); // from ALICE/tracking RF to pad RF (1)
     dzTW=-dzTW; // from ALICE/tracking RF to pad RF (2)
-    if (tiltangle!=0.) AliDebug(2,Form(" rho_track = %f --- rho_cluster = %f ",trackTOFin->GetX(),bestCluster->GetX()));
+    if (tiltangle!=0.) AliDebug(3,Form(" rho_track = %f --- rho_cluster = %f ",trackTOFin->GetX(),bestCluster->GetX()));
 
     //update the ESD track and delete the TOFtrack
     t->UpdateTrackParams(trackTOFin,AliESDtrack::kTOFout);
@@ -620,21 +631,21 @@ void AliTOFtrackerV1::MatchTracks( ){
     tlab[0]=bestCluster->GetLabel(0);
     tlab[1]=bestCluster->GetLabel(1);
     tlab[2]=bestCluster->GetLabel(2);
-    AliDebug(2,Form(" tdc time of the matched track %6d = ",bestCluster->GetTDC()));    
+    AliDebug(3,Form(" tdc time of the matched track %6d = ",bestCluster->GetTDC()));    
     Double_t tof=AliTOFGeometry::TdcBinWidth()*bestCluster->GetTDC()+kTimeOffset; // in ps
-    AliDebug(2,Form(" tof time of the matched track: %f = ",tof));
+    AliDebug(3,Form(" tof time of the matched track: %f = ",tof));
     Double_t tofcorr=tof;
     if(timeWalkCorr)tofcorr=CorrectTimeWalk(dzTW,tof);
-    AliDebug(2,Form(" tof time of the matched track, after TW corr: %f = ",tofcorr));    
+    AliDebug(3,Form(" tof time of the matched track, after TW corr: %f = ",tofcorr));    
     //Set TOF time signal and pointer to the matched cluster
     t->SetTOFsignal(tofcorr);
     t->SetTOFcluster(idclus); // pointing to the recPoints tree
     t->SetTOFLabel(tlab);
 
-    AliDebug(2,Form(" Setting TOF raw time: %f  z distance: %f  corrected time: %f",rawTime,dzTW,tofcorr));
+    AliDebug(3,Form(" Setting TOF raw time: %f  z distance: %f  corrected time: %f",rawTime,dzTW,tofcorr));
 
     Double_t mom=t->GetP();
-    AliDebug(2,Form(" Momentum for track %d -> %f", iseed,mom));
+    AliDebug(3,Form(" Momentum for track %d -> %f", iseed,mom));
     // Fill Reco-QA histos for Reconstruction
     fHRecNClus->Fill(nc);
     fHRecChi2->Fill(bestChi2);
diff --git a/TOF/AliTOFtrackerV2.cxx b/TOF/AliTOFtrackerV2.cxx
new file mode 100644 (file)
index 0000000..bcdaa09
--- /dev/null
@@ -0,0 +1,1060 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/**************************************************************************
+ * Copyright(c) 1998-1999, 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.                  *
+ **************************************************************************/
+
+//--------------------------------------------------------------------//
+//                                                                    //
+// AliTOFtrackerV2 Class                                              //
+// Task: Perform association of the ESD tracks to TOF Clusters        //
+// and Update ESD track with associated TOF Cluster parameters        //
+//                                                                    //
+// -- Authors : S. Arcelli, C. Zampolli (Bologna University and INFN) //
+// -- Contacts: Annalisa.De.Caro@cern.ch                              //
+// --         : Chiara.Zampolli@bo.infn.it                            //
+// --         : Silvia.Arcelli@bo.infn.it                             //
+//                                                                    //
+//--------------------------------------------------------------------//
+
+#include <Rtypes.h>
+#include <TROOT.h>
+
+#include <TClonesArray.h>
+#include <TObjArray.h>
+#include <TGeoManager.h>
+#include <TTree.h>
+
+#include "AliGeomManager.h"
+#include "AliESDtrack.h"
+#include "AliESDEvent.h"
+#include "AliESDpid.h"
+#include "AliESDTOFcluster.h"
+#include "AliLog.h"
+#include "AliTrackPointArray.h"
+#include "AliCDBManager.h"
+
+#include "AliTOFRecoParam.h"
+#include "AliTOFReconstructor.h"
+#include "AliTOFcluster.h"
+#include "AliTOFGeometry.h"
+#include "AliTOFtrackerV2.h"
+#include "AliTOFtrack.h"
+
+extern TGeoManager *gGeoManager;
+
+ClassImp(AliTOFtrackerV2)
+
+//_____________________________________________________________________________
+AliTOFtrackerV2::AliTOFtrackerV2():
+  fkRecoParam(0x0),
+  fGeom(0x0),
+  fN(0),
+  fNseeds(0),
+  fNseedsTOF(0),
+  fnunmatch(0),
+  fnmatch(0),
+  fTracks(new TClonesArray("AliTOFtrack")),
+  fSeeds(new TObjArray(100)),
+  fClusters(0x0)
+{
+  //AliTOFtrackerV2 main Ctor
+
+  // Getting the geometry
+  fGeom = new AliTOFGeometry();
+
+}
+//_____________________________________________________________________________
+AliTOFtrackerV2::~AliTOFtrackerV2() {
+  //
+  // Dtor
+  //
+
+  if(!(AliCDBManager::Instance()->GetCacheFlag())){
+    delete fkRecoParam;
+  }
+  delete fGeom; 
+  if (fTracks){
+    fTracks->Delete();
+    delete fTracks;
+    fTracks=0x0;
+  }
+  if (fSeeds){
+    fSeeds->Delete();
+    delete fSeeds;
+    fSeeds=0x0;
+  }
+
+  if(fClusters){
+    delete[] fClusters;
+    fClusters = NULL;
+  }
+
+}
+//_____________________________________________________________________________
+void AliTOFtrackerV2::GetPidSettings(AliESDpid *esdPID) {
+  // 
+  // Sets TOF resolution from RecoParams
+  //
+  if (fkRecoParam)
+    esdPID->GetTOFResponse().SetTimeResolution(fkRecoParam->GetTimeResolution());
+  else
+    AliWarning("fkRecoParam not yet set; cannot set PID settings");
+} 
+//_____________________________________________________________________________
+Int_t AliTOFtrackerV2::PropagateBack(AliESDEvent * const event) {
+  //
+  // Gets seeds from ESD event and Match with TOF Clusters
+  //
+
+  //Update the matched ESD tracks
+  // needed in case of call of TOF info before of the selection of matching and in case of no clusters available at all
+  if(fN==0)
+    event->SetTOFcluster(1,fClusters); 
+  else
+    event->SetTOFcluster(fN,fClusters);
+
+  if (fN==0) {
+    AliInfo("No TOF recPoints to be matched with reconstructed tracks");
+    return 0;
+  }
+
+  // initialize RecoParam for current event
+  AliDebug(1,"Initializing params for TOF");
+
+  fkRecoParam = AliTOFReconstructor::GetRecoParam();  // instantiate reco param from STEER...
+
+  if (fkRecoParam == 0x0) { 
+    AliFatal("No Reco Param found for TOF!!!");
+  }
+
+  //Initialise some counters
+
+  fNseeds=0;
+  fNseedsTOF=0;
+  fnunmatch=0;
+  fnmatch=0;
+
+  Int_t ntrk=event->GetNumberOfTracks();
+  fNseeds = ntrk;
+
+  //Load ESD tracks into a local Array of ESD Seeds
+  for (Int_t i=0; i<fNseeds; i++)
+    fSeeds->AddLast(event->GetTrack(i));
+
+  //Prepare ESD tracks candidates for TOF Matching
+  CollectESD();
+
+  if (fNseeds==0 || fNseedsTOF==0) {
+    AliInfo("No seeds to try TOF match");
+    return 0;
+  }
+
+  // clusterize before of matching
+  Clusterize();
+
+  //Second Step with Looser Matching Criterion
+  MatchTracks();
+
+  AliInfo(Form("Number of matched tracks = %d",fnmatch));
+
+  for (Int_t i=0; i<ntrk; i++) {
+    AliESDtrack *t=event->GetTrack(i);
+    //t->SetESDEvent(event);
+    AliESDtrack *seed =(AliESDtrack*)fSeeds->At(i);
+
+    if ( (seed->GetStatus()&AliESDtrack::kTOFin)!=0 ) {
+      t->SetStatus(AliESDtrack::kTOFin);
+      if ( (seed->GetStatus()&AliESDtrack::kTOFout)!=0 ) {
+       t->SetStatus(AliESDtrack::kTOFout);
+       //t->SetTOFclusterArray(seed->GetNTOFclusters(),seed->GetTOFclusterArray());
+       t->SortTOFcluster();
+
+       // Make attention, please:
+       //      AliESDtrack::fTOFInfo array does not be stored in the AliESDs.root file
+       //      it is there only for a check during the reconstruction step.
+       Float_t info[10]; seed->GetTOFInfo(info);
+       t->SetTOFInfo(info);
+       AliDebug(3,Form(" distance=%f; residual in the pad reference frame: dX=%f, dZ=%f", info[0],info[1],info[2]));
+
+       /*
+       Double_t alphaA = (Double_t)t->GetAlpha();
+       Double_t xA = (Double_t)t->GetX();
+       Double_t yA = (Double_t)t->GetY();
+       Double_t zA = (Double_t)t->GetZ();
+       Double_t p1A = (Double_t)t->GetSnp();
+       Double_t p2A = (Double_t)t->GetTgl();
+       Double_t p3A = (Double_t)t->GetSigned1Pt();
+       const Double_t *covA = (Double_t*)t->GetCovariance();
+
+       // Check done:
+       //       by calling the AliESDtrack::UpdateTrackParams,
+       //       the current track parameters are changed
+       //       and it could cause refit problems.
+       //       We need to update only the following track parameters:
+        //            the track length and expected times.
+       //       Removed AliESDtrack::UpdateTrackParams call
+       //       Called AliESDtrack::SetIntegratedTimes(...) and
+       //       AliESDtrack::SetIntegratedLength() routines.
+
+       AliTOFtrack *track = new AliTOFtrack(*seed);
+       t->UpdateTrackParams(track,AliESDtrack::kTOFout); // to be checked - AdC
+       delete track;
+       Double_t time[AliPID::kSPECIESC]; t->GetIntegratedTimes(time);
+       Double_t alphaB = (Double_t)t->GetAlpha();
+       Double_t xB = (Double_t)t->GetX();
+       Double_t yB = (Double_t)t->GetY();
+       Double_t zB = (Double_t)t->GetZ();
+       Double_t p1B = (Double_t)t->GetSnp();
+       Double_t p2B = (Double_t)t->GetTgl();
+       Double_t p3B = (Double_t)t->GetSigned1Pt();
+       const Double_t *covB = (Double_t*)t->GetCovariance();
+       AliDebug(2,"Track params -now(before)-:");
+       AliDebug(2,Form("    X: %f(%f), Y: %f(%f), Z: %f(%f) --- alpha: %f(%f)",
+                       xB,xA,
+                       yB,yA,
+                       zB,zA,
+                       alphaB,alphaA));
+       AliDebug(2,Form("    p1: %f(%f), p2: %f(%f), p3: %f(%f)",
+                       p1B,p1A,
+                       p2B,p2A,
+                       p3B,p3A));
+       AliDebug(2,Form("    cov1: %f(%f), cov2: %f(%f), cov3: %f(%f)"
+                       " cov4: %f(%f), cov5: %f(%f), cov6: %f(%f)"
+                       " cov7: %f(%f), cov8: %f(%f), cov9: %f(%f)"
+                       " cov10: %f(%f), cov11: %f(%f), cov12: %f(%f)"
+                       " cov13: %f(%f), cov14: %f(%f), cov15: %f(%f)",
+                       covB[0],covA[0],
+                       covB[1],covA[1],
+                       covB[2],covA[2],
+                       covB[3],covA[3],
+                       covB[4],covA[4],
+                       covB[5],covA[5],
+                       covB[6],covA[6],
+                       covB[7],covA[7],
+                       covB[8],covA[8],
+                       covB[9],covA[9],
+                       covB[10],covA[10],
+                       covB[11],covA[11],
+                       covB[12],covA[12],
+                       covB[13],covA[13],
+                       covB[14],covA[14]
+                       ));
+       */
+       Double_t time[AliPID::kSPECIESC]; t->GetIntegratedTimes(time);
+       AliDebug(2,Form(" TOF params: %6d  %f %f %f %f %f %6d %3d %f",
+                       i,
+                       t->GetTOFsignalRaw(),t->GetTOFsignal(),t->GetTOFsignalToT(),
+                       t->GetTOFsignalDz(),t->GetTOFsignalDx(),t->GetTOFCalChannel(),
+                       t->GetTOFcluster(),t->GetIntegratedLength()));
+       AliDebug(2,Form("  %f %f %f %f %f %f %f %f %f",
+                       time[0], time[1], time[2], time[3], time[4], time[5], time[6], time[7], time[8]));
+      }
+    }
+  }
+  
+  fSeeds->Clear();
+  fTracks->Clear();
+  
+  AliInfo(Form("Number of cluster to be checked = %d",fN));
+  if(fN){
+    Int_t *matchmap = new Int_t[fN];
+    event->SetTOFcluster(fN,fClusters,matchmap);
+    for (Int_t i=0; i<ntrk; i++) { // remapping after TOF matching selection
+      AliESDtrack *t=event->GetTrack(i);
+      t->ReMapTOFcluster(fN,matchmap);
+    }
+
+    delete[] matchmap;
+  }
+  
+  
+
+  return 0;
+  
+}
+//_________________________________________________________________________
+void AliTOFtrackerV2::CollectESD() {
+   //prepare the set of ESD tracks to be matched to clusters in TOF
+
+  Int_t seedsTOF1=0;
+  Int_t seedsTOF3=0;
+  Int_t seedsTOF2=0;
+  TClonesArray &aTOFTrack = *fTracks;
+  for (Int_t i=0; i<fNseeds; i++) {
+
+    AliESDtrack *t =(AliESDtrack*)fSeeds->At(i);
+    if ((t->GetStatus()&AliESDtrack::kTPCout)==0)continue;
+
+    AliTOFtrack *track = new AliTOFtrack(*t); // New
+    Float_t x = (Float_t)track->GetX(); //New
+
+    // TRD 'good' tracks
+    if ( ( (t->GetStatus()&AliESDtrack::kTRDout)!=0 ) ) {
+
+      AliDebug(1,Form(" Before propagation till inner TOF radius, ESDtrackLength=%f, TOFtrackLength=%f",t->GetIntegratedLength(),track->GetIntegratedLength()));
+
+      // TRD 'good' tracks, already propagated at 371 cm
+      if ( x >= AliTOFGeometry::Rmin() ) {
+
+       if ( track->PropagateToInnerTOF() ) {
+
+         AliDebug(1,Form(" TRD propagated track till rho = %fcm."
+                         " And then the track has been propagated till rho = %fcm.",
+                         x, (Float_t)track->GetX()));
+
+         track->SetSeedIndex(i);
+         t->UpdateTrackParams(track,AliESDtrack::kTOFin);
+         new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
+         fNseedsTOF++;
+         seedsTOF1++;
+
+         AliDebug(1,Form(" After propagation till inner TOF radius, ESDtrackLength=%f, TOFtrackLength=%f",t->GetIntegratedLength(),track->GetIntegratedLength()));
+       }
+       delete track;
+
+      }
+      else { // TRD 'good' tracks, propagated rho<371cm
+
+       if  ( track->PropagateToInnerTOF() ) {
+
+         AliDebug(1,Form(" TRD propagated track till rho = %fcm."
+                         " And then the track has been propagated till rho = %fcm.",
+                         x, (Float_t)track->GetX()));
+
+         track->SetSeedIndex(i);
+         t->UpdateTrackParams(track,AliESDtrack::kTOFin);
+         new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
+         fNseedsTOF++;
+         seedsTOF3++;
+
+         AliDebug(1,Form(" After propagation till inner TOF radius, ESDtrackLength=%f, TOFtrackLength=%f",t->GetIntegratedLength(),track->GetIntegratedLength()));
+       }
+       delete track;
+
+      }
+      //delete track;
+    }
+
+    else { // Propagate the rest of TPCbp
+
+      AliDebug(1,Form(" Before propagation till inner TOF radius, ESDtrackLength=%f, TOFtrackLength=%f",t->GetIntegratedLength(),track->GetIntegratedLength()));
+
+      if ( track->PropagateToInnerTOF() ) { 
+
+       AliDebug(1,Form(" TPC propagated track till rho = %fcm."
+                       " And then the track has been propagated till rho = %fcm.",
+                       x, (Float_t)track->GetX()));
+
+       track->SetSeedIndex(i);
+       t->UpdateTrackParams(track,AliESDtrack::kTOFin);
+       new(aTOFTrack[fNseedsTOF]) AliTOFtrack(*track);
+       fNseedsTOF++;
+       seedsTOF2++;
+
+       AliDebug(1,Form(" After propagation till inner TOF radius, ESDtrackLength=%f, TOFtrackLength=%f",t->GetIntegratedLength(),track->GetIntegratedLength()));
+      }
+      delete track;
+    }
+  }
+
+  AliInfo(Form("Number of TOF seeds = %d (kTRDout371 = %d, kTRDoutLess371 = %d, !kTRDout = %d)",fNseedsTOF,seedsTOF1,seedsTOF3,seedsTOF2));
+
+  // Sort according uncertainties on track position 
+  fTracks->Sort();
+
+}
+
+//_________________________________________________________________________
+void AliTOFtrackerV2::MatchTracks() {
+  //
+  //Match ESD tracks to clusters in TOF
+  //
+
+  // Parameters used/regulating the reconstruction
+  static Float_t detDepth=18.;
+  static Float_t padDepth=0.5;
+
+  const Float_t kSpeedOfLight= 2.99792458e-2; // speed of light [cm/ps]
+
+  Float_t dY=AliTOFGeometry::XPad(); 
+  Float_t dZ=AliTOFGeometry::ZPad(); 
+
+  Float_t sensRadius = fkRecoParam->GetSensRadius();
+  Float_t stepSize   = fkRecoParam->GetStepSize();
+  Float_t scaleFact  = fkRecoParam->GetWindowScaleFact();
+  Float_t dyMax=fkRecoParam->GetWindowSizeMaxY(); 
+  Float_t dzMax=fkRecoParam->GetWindowSizeMaxZ();
+  Float_t dCut=10.;//fkRecoParam->GetDistanceCut(); // This is to be loaded by OCDB. It should be 10cm always.
+  Double_t maxChi2=fkRecoParam->GetMaxChi2TRD();
+  Bool_t timeWalkCorr = fkRecoParam->GetTimeWalkCorr();
+  AliDebug(1,"++++++++++++++TOF Reconstruction Parameters:++++++++++++++");
+  AliDebug(1,Form("TOF sens radius: %f",sensRadius));
+  AliDebug(1,Form("TOF step size: %f",stepSize));
+  AliDebug(1,Form("TOF Window scale factor: %f",scaleFact));
+  AliDebug(1,Form("TOF Window max dy: %f",dyMax));
+  AliDebug(1,Form("TOF Window max dz: %f",dzMax));
+  AliDebug(1,Form("TOF distance Cut: %f",dCut));
+  AliDebug(1,Form("TOF Max Chi2: %f",maxChi2));
+  AliDebug(1,Form("Time Walk Correction? : %d",timeWalkCorr));   
+
+  //Match ESD tracks to clusters in TOF
+
+  // Get the number of propagation steps
+  Int_t nSteps=(Int_t)(detDepth/stepSize);
+  AliDebug(1,Form(" Number of steps to be done %d",nSteps));
+
+  AliDebug(1,"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
+
+  //PH Arrays (moved outside of the loop)
+  Float_t * trackPos[4];
+  for (Int_t ii=0; ii<4; ii++) trackPos[ii] = new Float_t[nSteps];
+  Int_t * clind = new Int_t[fN];
+  
+  // Some init
+  const Int_t kNclusterMax = 1000; // related to fN value
+  TGeoHMatrix global[kNclusterMax];
+
+  //The matching loop
+  for (Int_t iseed=0; iseed<fNseedsTOF; iseed++) {
+
+    for (Int_t ii=0; ii<fN; ii++) clind[ii]=-1;
+    for (Int_t ii=0; ii<kNclusterMax; ii++) global[ii] = 0x0;
+    for (Int_t ii=0; ii<4; ii++)
+      for (Int_t jj=0; jj<nSteps; jj++) trackPos[ii][jj]=0.;
+
+    AliTOFtrack *track =(AliTOFtrack*)fTracks->UncheckedAt(iseed);
+    AliESDtrack *t =(AliESDtrack*)fSeeds->At(track->GetSeedIndex());
+    AliTOFtrack *trackTOFin = new AliTOFtrack(*track);
+
+    Double_t timesOr[AliPID::kSPECIESC]; t->GetIntegratedTimes(timesOr); // in ps
+
+    // Determine a window around the track
+    Double_t x,par[5]; 
+    trackTOFin->GetExternalParameters(x,par);
+    Double_t cov[15]; 
+    trackTOFin->GetExternalCovariance(cov);
+
+    if (cov[0]<0. || cov[2]<0.) {
+      AliWarning(Form("Very strange track (%d)! At least one of its covariance matrix diagonal elements is negative!",iseed));
+      delete trackTOFin;
+      continue;
+    }
+
+    Double_t dphi=
+      scaleFact*
+      ((5*TMath::Sqrt(TMath::Abs(cov[0])) + 0.5*dY + 2.5*TMath::Abs(par[2]))/sensRadius); 
+    Double_t dz=
+       scaleFact*
+       (5*TMath::Sqrt(TMath::Abs(cov[2])) + 0.5*dZ + 2.5*TMath::Abs(par[3]));
+
+    Double_t phi=TMath::ATan2(par[0],x) + trackTOFin->GetAlpha();
+    if (phi<-TMath::Pi())phi+=2*TMath::Pi();
+    if (phi>=TMath::Pi())phi-=2*TMath::Pi();
+    Double_t z=par[1];   
+
+    //upper limit on window's size.
+    if (dz> dzMax) dz=dzMax;
+    if (dphi*sensRadius> dyMax) dphi=dyMax/sensRadius;
+
+
+    // find the clusters in the window of the track
+    Int_t nc=0;
+    for (Int_t k=FindClusterIndex(z-dz); k<fN; k++) {
+
+      if (nc>=kNclusterMax) {
+       AliWarning("No more matchable clusters can be stored! Please, increase the corresponding vectors size.");
+       break;
+      }
+
+      AliESDTOFcluster *c=&(fClusters[k]);
+      if (c->GetZ() > z+dz) break;
+      if (!c->GetStatus()) {
+       AliDebug(1,"Cluster in channel declared bad!");
+       continue; // skip bad channels as declared in OCDB
+      }
+
+      Double_t dph=TMath::Abs(c->GetPhi()-phi);
+      if (dph>TMath::Pi()) dph-=2.*TMath::Pi();
+      if (TMath::Abs(dph)>dphi) continue;
+
+      Double_t yc=(c->GetPhi() - trackTOFin->GetAlpha())*c->GetR();
+      Double_t p[2]={yc, c->GetZ()};
+      Double_t cov2[3]= {dY*dY/12., 0., dZ*dZ/12.};
+      if (trackTOFin->AliExternalTrackParam::GetPredictedChi2(p,cov2) > maxChi2)continue;
+
+      clind[nc] = k;      
+      Char_t path[200];
+      Int_t ind[5]; fGeom->GetVolumeIndices(c->GetTOFchannel(),ind);
+      fGeom->GetVolumePath(ind,path);
+      gGeoManager->cd(path);
+      global[nc] = *gGeoManager->GetCurrentMatrix();
+      nc++;
+    }
+
+    if (nc == 0 ) {
+      AliDebug(1,Form("No available clusters for the track number %d",iseed));
+      fnunmatch++;
+      delete trackTOFin;
+      continue;
+    }
+
+    AliDebug(1,Form(" Number of available TOF clusters for the track number %d: %d",iseed,nc));
+
+    //start fine propagation 
+
+    Double_t *times[AliPID::kSPECIESC];
+    for(Int_t isp=0;isp < AliPID::kSPECIESC;isp++){
+      times[isp] = new Double_t[nSteps];
+    }
+
+    Int_t nStepsDone = 0;
+    for( Int_t istep=0; istep<nSteps; istep++){ 
+      
+      // First of all, propagate the track...
+      Float_t xs = AliTOFGeometry::RinTOF()+istep*stepSize;
+      if (!(trackTOFin->PropagateTo(xs))) break;
+
+      //  ...and then, if necessary, rotate the track
+      Double_t ymax = xs*TMath::Tan(0.5*AliTOFGeometry::GetAlpha());
+      Double_t ysect = trackTOFin->GetY();
+      if (ysect > ymax) {
+       if (!(trackTOFin->Rotate(AliTOFGeometry::GetAlpha()))) break;
+      } else if (ysect <-ymax) {
+       if (!(trackTOFin->Rotate(-AliTOFGeometry::GetAlpha()))) break;
+      }
+
+      Double_t mom = trackTOFin->P();
+
+      if(istep == 0){
+       for(Int_t isp=0;isp<AliPID::kSPECIESC;isp++){
+         Double_t mass=AliPID::ParticleMass(isp);
+         Double_t momz = mom*AliPID::ParticleCharge(isp);
+         times[isp][nStepsDone] = stepSize/kSpeedOfLight*TMath::Sqrt(momz*momz+mass*mass)/momz;
+       }
+      }
+      else{
+       for(Int_t isp=0;isp<AliPID::kSPECIESC;isp++){
+         Double_t mass=AliPID::ParticleMass(isp);
+         Double_t momz = mom*AliPID::ParticleCharge(isp);
+         times[isp][nStepsDone] = times[isp][nStepsDone-1] + (trackTOFin->GetIntegratedLength()-trackPos[3][nStepsDone-1])/kSpeedOfLight*TMath::Sqrt(momz*momz+mass*mass)/momz;
+       }
+      }
+
+      // store the running point (Globalrf) - fine propagation     
+
+      Double_t r[3]; trackTOFin->GetXYZ(r);
+      trackPos[0][nStepsDone]= (Float_t) r[0];
+      trackPos[1][nStepsDone]= (Float_t) r[1];
+      trackPos[2][nStepsDone]= (Float_t) r[2];   
+      trackPos[3][nStepsDone]= trackTOFin->GetIntegratedLength();
+
+      nStepsDone++;
+      AliDebug(3,Form(" current step %d (%d) - nStepsDone=%d",istep,nSteps,nStepsDone));
+    }
+
+    if ( nStepsDone == 0 ) {
+      AliDebug(1,Form(" No track points for track number %d",iseed));
+      fnunmatch++;
+      delete trackTOFin;
+      continue;
+    }
+
+    AliDebug(3,Form(" Number of steps done for the track number %d: %d",iseed,nStepsDone));
+
+    Int_t *isClusterMatchable = NULL;
+    if(nc){
+      isClusterMatchable = new Int_t[nc];
+      for (Int_t i=0; i<nc; i++) isClusterMatchable[i] = kFALSE;               
+    }
+
+    Int_t nfound = 0;
+    Bool_t accept = kFALSE;
+    Bool_t isInside = kFALSE;
+    for (Int_t istep=0; istep<nStepsDone; istep++) {
+
+      Bool_t gotInsideCluster = kFALSE;
+      Int_t trackInsideCluster = -1;
+
+      Float_t ctrackPos[3];     
+      ctrackPos[0] = trackPos[0][istep];
+      ctrackPos[1] = trackPos[1][istep];
+      ctrackPos[2] = trackPos[2][istep];
+
+      //now see whether the track matches any of the TOF clusters            
+
+      Float_t dist3d[3]={0.,0.,0.};
+      accept = kFALSE;
+     
+      for (Int_t i=0; i<nc; i++) {
+
+        // ***** NEW *****
+        /* check whether track was inside another cluster
+         * and in case inhibit this cluster.
+         * this will allow to only go on and add track points for
+         * that cluster where the track got inside first */
+        if (gotInsideCluster && trackInsideCluster != i) {
+         AliDebug(3,Form(" A - istep=%d ~ %d %d ~ nfound=%d",istep,trackInsideCluster,i,nfound));
+          continue;
+       }
+       AliDebug(3,Form(" B - istep=%d ~ %d %d ~ nfound=%d",istep,trackInsideCluster,i,nfound));
+
+        /* check whether track is inside this cluster */
+       for (Int_t hh=0; hh<3; hh++) dist3d[hh]=0.;
+       isInside = fGeom->IsInsideThePad((TGeoHMatrix*)(&global[i]),ctrackPos,dist3d);
+
+        // ***** NEW *****
+        /* if track is inside this cluster set flags which will then
+         * inhibit to add track points for the other clusters */
+        if (isInside) {
+          gotInsideCluster = kTRUE;
+          trackInsideCluster = i;
+        }
+
+       Float_t yLoc = dist3d[1];
+       Float_t rLoc = TMath::Sqrt(dist3d[0]*dist3d[0]+dist3d[2]*dist3d[2]);
+       accept = (TMath::Abs(yLoc)<padDepth*0.5 && rLoc<dCut);
+
+       //***** NEW *****
+       /* add point everytime that:
+        * - the track is inside the cluster
+        * - the track got inside the cluster, even when it eventually exited the cluster
+        * - the tracks is within dCut from the cluster
+        */
+        if (accept || isInside || gotInsideCluster) {
+
+         Double_t timesCurrent[AliPID::kSPECIESC];
+         AliDebug(3,Form(" Momentum for track %d -> %f", iseed,t->P()));
+         for (Int_t j=0;j<AliPID::kSPECIESC;j++) {
+           timesCurrent[j] = timesOr[j] + times[j][istep];
+         }
+
+         if (TMath::Abs(dist3d[1])<stepSize && !isClusterMatchable[i]) {
+           isClusterMatchable[i] = kTRUE;
+           fClusters[clind[i]].Update(t->GetID(),dist3d[1],dist3d[0],dist3d[2],trackPos[3][istep],timesCurrent);//x,y,z -> tracking RF
+           t->AddTOFcluster(clind[i]);
+           t->SetStatus(AliESDtrack::kTOFout);
+         }
+          AliDebug(2,Form(" dist3dLoc[0] = %f, dist3dLoc[1] = %f, dist3dLoc[2] = %f ",dist3d[0],dist3d[1],dist3d[2]));
+
+          nfound++;
+
+         AliDebug(3,Form(" C - istep=%d ~ %d %d ~ nfound=%d",istep,trackInsideCluster,i,nfound));
+        
+          // ***** NEW *****
+        }//end if accept
+        
+      } //end for on the clusters
+    } //end for on the steps     
+    if(nc) delete[] isClusterMatchable;
+
+    for(Int_t isp=0;isp < AliPID::kSPECIESC;isp++){
+      delete[] times[isp];
+    }
+
+
+    if (nfound == 0 ) {
+      AliDebug(1,Form(" No matchable track points for the track number %d",iseed));
+      fnunmatch++;
+      delete trackTOFin;
+      continue;
+    }
+
+    AliDebug(1,Form(" Number of track points for the track number %d: %d",iseed,nfound));
+
+    Int_t nMatchedClusters = t->GetNTOFclusters();
+    if (nMatchedClusters==0) {
+      AliDebug(1,Form("Reconstructed track %d doesn't match any TOF cluster", iseed));
+      fnunmatch++;
+      delete trackTOFin;
+      continue;
+    }
+
+    AliDebug(1,Form(" %d - matched (%d)",track->GetSeedIndex()/*iseed*/,nMatchedClusters));
+
+    fnmatch++;
+
+    /*
+    AliTOFcluster cTOF = AliTOFcluster(volIdClus,
+    (Float_t)posClus[0],(Float_t)posClus[1],(Float_t)posClus[2],
+    (Float_t)covClus[0],(Float_t)covClus[1],(Float_t)covClus[2],
+    (Float_t)covClus[3],(Float_t)covClus[4],(Float_t)covClus[5],
+    tofLabels,volIndices,parClu,kTRUE,index[i]);
+
+    // Fill the track residual histograms.
+    FillResiduals(trackTOFin,c,kFALSE);
+    */
+
+    delete trackTOFin;
+
+  } // loop on fSeeds
+
+  for (Int_t ii=0; ii<4; ii++) delete [] trackPos[ii];
+  delete [] clind;
+}
+//_________________________________________________________________________
+Int_t AliTOFtrackerV2::LoadClusters(TTree *cTree) {
+  //--------------------------------------------------------------------
+  //This function loads the TOF clusters
+  //--------------------------------------------------------------------
+
+  TBranch *branch=cTree->GetBranch("TOF");
+  if (!branch) { 
+    AliError("can't get the branch with the TOF clusters !");
+    return 1;
+  }
+
+  static TClonesArray dummy("AliTOFcluster",10000);
+  dummy.Clear();
+  TClonesArray *clusters=&dummy;
+  branch->SetAddress(&clusters);
+
+  cTree->GetEvent(0);
+  fN=clusters->GetEntriesFast();
+  AliInfo(Form("Number of clusters: %d",fN));
+
+  if(fClusters){
+    delete[] fClusters;
+    fClusters = NULL;
+  }
+
+  if(fN)
+    fClusters = new AliESDTOFcluster[fN];
+  else{
+    fClusters = new AliESDTOFcluster[1];
+    fN = 1;
+    return 0;
+  }
+
+  for (Int_t i=0; i<fN; i++) {
+    AliTOFcluster *c=(AliTOFcluster*)clusters->UncheckedAt(i);
+    Int_t ind[5];
+    ind[0]=c->GetDetInd(0);
+    ind[1]=c->GetDetInd(1);
+    ind[2]=c->GetDetInd(2);
+    ind[3]=c->GetDetInd(3);
+    ind[4]=c->GetDetInd(4);
+    Int_t calindex = AliTOFGeometry::GetIndex(ind);
+    Int_t tofLabels[3]={c->GetLabel(0),c->GetLabel(1),c->GetLabel(2)};
+    AliESDTOFcluster esdTOFclus(i,calindex,
+                               AliTOFGeometry::TdcBinWidth()*c->GetTDC()/*ps*/,
+                               AliTOFGeometry::TdcBinWidth()*c->GetTDCRAW()/*ps*/,
+                               AliTOFGeometry::ToTBinWidth()*c->GetToT()*1E-3/*ns*/,
+                               tofLabels,
+                               c->GetDeltaBC(),c->GetL0L1Latency(),
+                               c->GetStatus(),c->GetZ(),c->GetPhi(),c->GetR());
+
+    fClusters[i] = esdTOFclus;
+
+  }
+
+  return 0;
+}
+//_________________________________________________________________________
+void AliTOFtrackerV2::UnloadClusters() {
+  //--------------------------------------------------------------------
+  //This function unloads TOF clusters
+  //--------------------------------------------------------------------
+
+  // don't delete TOF clusters here because they should be written
+}
+
+//_________________________________________________________________________
+Int_t AliTOFtrackerV2::FindClusterIndex(Double_t z) const {
+  //--------------------------------------------------------------------
+  // This function returns the index of the nearest cluster 
+  //--------------------------------------------------------------------
+  if (fN==0) return 0;
+  if (z <= fClusters[0].GetZ()) return 0;
+  if (z > fClusters[fN-1].GetZ()) return fN;
+  Int_t b=0, e=fN-1, m=(b+e)/2;
+  for (; b<e; m=(b+e)/2) {
+    if (z > fClusters[m].GetZ()) b=m+1;
+
+    else e=m; 
+  }
+  return m;
+}
+
+//_________________________________________________________________________
+Bool_t AliTOFtrackerV2::GetTrackPoint(Int_t index, AliTrackPoint& p) const
+{
+  // Get track space point with index i
+  // Coordinates are in the global system
+  AliESDTOFcluster *cl = &(fClusters[index]);
+  Float_t xyz[3];
+  xyz[0] = cl->GetR()*TMath::Cos(cl->GetPhi());
+  xyz[1] = cl->GetR()*TMath::Sin(cl->GetPhi());
+  xyz[2] = cl->GetZ();
+  Float_t phiangle = (Int_t(cl->GetPhi()*TMath::RadToDeg()/20.)+0.5)*20.*TMath::DegToRad();
+  Float_t sinphi = TMath::Sin(phiangle), cosphi = TMath::Cos(phiangle);
+  Int_t tofChannel=cl->GetTOFchannel();
+  Int_t ind[5]; fGeom->GetVolumeIndices(tofChannel,ind);
+  Float_t tiltangle = AliTOFGeometry::GetAngles(ind[1],ind[2])*TMath::DegToRad();
+  Float_t sinth = TMath::Sin(tiltangle), costh = TMath::Cos(tiltangle);
+  Float_t sigmay2 = AliTOFGeometry::XPad()*AliTOFGeometry::XPad()/12.;
+  Float_t sigmaz2 = AliTOFGeometry::ZPad()*AliTOFGeometry::ZPad()/12.;
+  Float_t cov[6];
+  cov[0] = sinphi*sinphi*sigmay2 + cosphi*cosphi*sinth*sinth*sigmaz2;
+  cov[1] = -sinphi*cosphi*sigmay2 + sinphi*cosphi*sinth*sinth*sigmaz2;
+  cov[2] = -cosphi*sinth*costh*sigmaz2;
+  cov[3] = cosphi*cosphi*sigmay2 + sinphi*sinphi*sinth*sinth*sigmaz2;
+  cov[4] = -sinphi*sinth*costh*sigmaz2;
+  cov[5] = costh*costh*sigmaz2;
+  p.SetXYZ(xyz[0],xyz[1],xyz[2],cov);
+
+  // Detector numbering scheme
+  Int_t nSector = AliTOFGeometry::NSectors();
+  Int_t nPlate  = AliTOFGeometry::NPlates();
+  Int_t nStripA = AliTOFGeometry::NStripA();
+  Int_t nStripB = AliTOFGeometry::NStripB();
+  Int_t nStripC = AliTOFGeometry::NStripC();
+
+  Int_t isector = ind[0];//cl->GetDetInd(0);
+  if (isector >= nSector)
+    AliError(Form("Wrong sector number in TOF (%d) !",isector));
+  Int_t iplate = ind[1];//cl->GetDetInd(1);
+  if (iplate >= nPlate)
+    AliError(Form("Wrong plate number in TOF (%d) !",iplate));
+  Int_t istrip = ind[2];//cl->GetDetInd(2);
+
+  Int_t stripOffset = 0;
+  switch (iplate) {
+  case 0:
+    stripOffset = 0;
+    break;
+  case 1:
+    stripOffset = nStripC;
+    break;
+  case 2:
+    stripOffset = nStripC+nStripB;
+    break;
+  case 3:
+    stripOffset = nStripC+nStripB+nStripA;
+    break;
+  case 4:
+    stripOffset = nStripC+nStripB+nStripA+nStripB;
+    break;
+  default:
+    AliError(Form("Wrong plate number in TOF (%d) !",iplate));
+    break;
+  };
+
+  Int_t idet = (2*(nStripC+nStripB)+nStripA)*isector +
+               stripOffset +
+               istrip;
+  UShort_t volid = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,idet);
+  p.SetVolumeID((UShort_t)volid);
+  return kTRUE;
+}
+//_________________________________________________________________________
+
+void AliTOFtrackerV2::FillClusterArray(TObjArray* arr) const
+{
+  //
+  // Returns the TOF cluster array
+  //
+
+  if (fN==0)
+    arr = 0x0;
+  else
+    for (Int_t i=0; i<fN; ++i) arr->Add(&(fClusters[i]));
+
+}
+//_________________________________________________________________________
+Float_t AliTOFtrackerV2::CorrectTimeWalk( Float_t dist, Float_t tof) const {
+
+  //dummy, for the moment
+  Float_t tofcorr=0.;
+  if(dist<AliTOFGeometry::ZPad()*0.5){
+    tofcorr=tof;
+    //place here the actual correction
+  }else{
+    tofcorr=tof; 
+  } 
+  return tofcorr;
+}
+//_________________________________________________________________________
+void AliTOFtrackerV2::Clusterize(){
+  Int_t detId[5];
+  for(Int_t i=0; i < fN-1;i++){
+    AliESDTOFcluster *c1=&(fClusters[i]);
+    if(!c1->GetStatus()) continue;
+
+    Int_t chan1 = c1->GetTOFchannel();
+    AliTOFGeometry::GetVolumeIndices(chan1, detId); // Get volume index from channel index
+
+    Int_t ieta = detId[2]/*strip*/*2 + detId[3]/*pad Z*/;
+    if(detId[1]/*module*/ == 0) ieta += 0;
+    else if(detId[1] == 1) ieta += 38;
+    else if(detId[1] == 2) ieta += 76;
+    else if(detId[1] == 3) ieta += 106;
+    else if(detId[1] == 4) ieta += 144;
+    Int_t iphi = detId[0]/*phi sector*/*48 + detId[4]/*pad x*/;
+    
+
+    for(Int_t j=i+1; j < fN;j++){
+      AliESDTOFcluster *c2=&(fClusters[j]);
+      if(!c2->GetStatus()) continue;
+
+      Int_t chan2 = c2->GetTOFchannel();
+
+      // check if the two TOF hits are in the same strip
+      if(chan1/96 != chan2/96) continue;
+
+      AliTOFGeometry::GetVolumeIndices(chan2, detId); // Get volume index from channel index
+      Int_t ieta2 = detId[2]/*strip*/*2 + detId[3]/*pad Z*/;
+      if(detId[1]/*module*/ == 0) ieta2 += 0;
+      else if(detId[1] == 1) ieta2 += 38;
+      else if(detId[1] == 2) ieta2 += 76;
+      else if(detId[1] == 3) ieta2 += 106;
+      else if(detId[1] == 4) ieta2 += 144;
+      Int_t iphi2 = detId[0]/*phi sector*/*48 + detId[4]/*pad x*/;
+      
+      // check if the fired pad are close in space
+      if(TMath::Abs(iphi-iphi2)>1 || TMath::Abs(ieta-ieta2)>1) continue;
+
+      // check if the TOF time are close enough to be merged
+      if(TMath::Abs(c1->GetTime() - c2->GetTime()) > 500/*in ps*/) continue;
+
+      // merge them
+      Int_t label[3] = {c2->GetLabel(0),c2->GetLabel(1),c2->GetLabel(2)};
+      fClusters[i].AddTOFhit(c2->GetClusterIndex(),chan2,c2->GetTime(),c2->GetTimeRaw(),c2->GetTOT(),label,
+                                       c2->GetDeltaBC(),c2->GetL0L1Latency(),1,c2->GetZ(),c2->GetPhi(),c2->GetR());
+      
+      c2->SetStatus(0); // only the merged one should be used
+      j = fN; // cluster "i" merged go to the next one ("i+1")
+    }
+  }
+
+  // second step of clusterization
+  for(Int_t i=0; i < fN-1;i++){
+    AliESDTOFcluster *c1=&(fClusters[i]);
+    if(!c1->GetStatus()) continue;
+
+    Int_t chan1 = c1->GetTOFchannel(0);
+    AliTOFGeometry::GetVolumeIndices(chan1, detId); // Get volume index from channel index
+
+    Int_t ieta = detId[2]/*strip*/*2 + detId[3]/*pad Z*/;
+    if(detId[1]/*module*/ == 0) ieta += 0;
+    else if(detId[1] == 1) ieta += 38;
+    else if(detId[1] == 2) ieta += 76;
+    else if(detId[1] == 3) ieta += 106;
+    else if(detId[1] == 4) ieta += 144;
+    Int_t iphi = detId[0]/*phi sector*/*48 + detId[4]/*pad x*/;
+
+    Int_t ieta2,iphi2,chan2=chan1;
+    if(c1->GetNTOFhits() > 1){
+      chan2 = c1->GetTOFchannel(1);
+      AliTOFGeometry::GetVolumeIndices(chan2, detId); // Get volume index from channel index
+
+      ieta2 = detId[2]/*strip*/*2 + detId[3]/*pad Z*/;
+      if(detId[1]/*module*/ == 0) ieta2 += 0;
+      else if(detId[1] == 1) ieta2 += 38;
+      else if(detId[1] == 2) ieta2 += 76;
+      else if(detId[1] == 3) ieta2 += 106;
+      else if(detId[1] == 4) ieta2 += 144;
+      iphi2 = detId[0]/*phi sector*/*48 + detId[4]/*pad x*/;
+    }
+    else{
+      iphi2=iphi;
+      ieta2=ieta;
+    }
+
+    for(Int_t j=i+1; j < i;j++){
+      AliESDTOFcluster *c2=&(fClusters[j]);
+      if(!c2->GetStatus()) continue;
+
+      Int_t chan3 = c2->GetTOFchannel();
+
+      // check if the two TOF hits are in the same strip
+      if(chan1/96 != chan3/96) continue;
+
+      AliTOFGeometry::GetVolumeIndices(chan3, detId); // Get volume index from channel index
+      Int_t ieta3 = detId[2]/*strip*/*2 + detId[3]/*pad Z*/;
+      if(detId[1]/*module*/ == 0) ieta3 += 0;
+      else if(detId[1] == 1) ieta3 += 38;
+      else if(detId[1] == 2) ieta3 += 76;
+      else if(detId[1] == 3) ieta3 += 106;
+      else if(detId[1] == 4) ieta3 += 144;
+      Int_t iphi3 = detId[0]/*phi sector*/*48 + detId[4]/*pad x*/;
+      
+      // check if the fired pad are close in space
+      if((TMath::Abs(iphi-iphi3)>1 && TMath::Abs(iphi2-iphi3)>1) || (TMath::Abs(ieta-ieta3)>1 && TMath::Abs(ieta2-ieta3)>1)) 
+continue;
+      
+      // check if the TOF time are close enough to be merged
+      if(TMath::Abs(c1->GetTime() - c2->GetTime()) > 500/*in ps*/) continue;
+      
+      // merge them
+      Int_t label[3] = {c2->GetLabel(0),c2->GetLabel(1),c2->GetLabel(2)};
+      fClusters[i].AddTOFhit(c2->GetClusterIndex(),chan2,c2->GetTime(),c2->GetTimeRaw(),c2->GetTOT(),label,
+                                       c2->GetDeltaBC(),c2->GetL0L1Latency(),1,c2->GetZ(),c2->GetPhi(),c2->GetR());
+
+      if(c2->GetNTOFhits() > 1){ // in case also the second cluster has two hits
+        Int_t label2[3] = {c2->GetLabel(0,1),c2->GetLabel(1,1),c2->GetLabel(2,1)};
+        fClusters[i].AddTOFhit(c2->GetClusterIndex(1),c2->GetTOFchannel(1),c2->GetTime(1),c2->GetTimeRaw(1),
+                                         c2->GetTOT(1),label2,c2->GetDeltaBC(2),c2->GetL0L1Latency(2),1,c2->GetZ(),
+                                         c2->GetPhi(),c2->GetR());
+      }
+
+      c1->SetStatus(0); // only the merged one should be used
+      j = fN; // cluster "i" merged go to the next one ("i+1")
+    }
+  }  
+}
+
diff --git a/TOF/AliTOFtrackerV2.h b/TOF/AliTOFtrackerV2.h
new file mode 100644 (file)
index 0000000..e8285b6
--- /dev/null
@@ -0,0 +1,81 @@
+#ifndef ALITOFTRACKERV2_H
+#define ALITOFTRACKERV2_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id:  $ */
+
+//------------------------------------------------------------------//
+//                                                                  //
+// AliTOFtrackerV2 Class                                            //
+// Task: Perform association of the ESD tracks to TOF Clusters      //
+// and Update ESD track with associated TOF Cluster parameters      //
+//                                                                  //
+// -- Authors : A. De Caro (Centro Studi e Ricerche E.Fermi)        //
+// -- Contacts: Annalisa.De.Caro@cern.ch                            //
+//                                                                  //
+//------------------------------------------------------------------//
+
+#include "AliTracker.h"
+#include "AliESDTOFcluster.h"
+
+class TClonesArray;
+class TObjArray;
+
+class AliESDEvent;
+class AliESDpid;
+
+class AliTOFRecoParam;
+class AliTOFGeometry;
+
+class AliTOFtrackerV2 : public AliTracker {
+
+ public:
+
+ AliTOFtrackerV2(); 
+
+ virtual ~AliTOFtrackerV2();
+ virtual void GetPidSettings(AliESDpid *esdPID);
+ virtual Int_t Clusters2Tracks(AliESDEvent* /*event*/) {return -1;};
+ virtual Int_t PropagateBack(AliESDEvent * const event);
+ virtual Int_t RefitInward(AliESDEvent* /*event*/) {return -1;};
+ virtual Int_t LoadClusters(TTree * cTree); // Load Clusters
+ virtual void  UnloadClusters();// UnLoad Clusters
+ virtual AliCluster *GetCluster(Int_t index) const
+   {if (index==-1 || index >= fN) return NULL;
+     return (AliCluster *) (&fClusters[index]);};
+ Bool_t GetTrackPoint(Int_t index, AliTrackPoint& p) const;
+ Int_t GetNumberOfMatchedTOFtracks() const {return fnmatch;}
+ void FillClusterArray(TObjArray* arr) const;
+ void Clusterize();
+
+private:
+
+ enum {kMaxCluster=77777}; //maximal number of the TOF clusters
+
+ AliTOFtrackerV2(const AliTOFtrackerV2 &t); //Copy Ctor 
+ AliTOFtrackerV2& operator=(const AliTOFtrackerV2 &source); // ass. op.
+
+ Int_t FindClusterIndex(Double_t z) const; // Returns cluster index 
+ void  MatchTracks(); // Matching Algorithm 
+ void  CollectESD(); // Select starting Set for Matching 
+ Float_t CorrectTimeWalk(Float_t dist,Float_t tof) const; // Time Walk correction
+
+ const AliTOFRecoParam* fkRecoParam;    // Pointer to TOF Recon. Pars
+ AliTOFGeometry*  fGeom;                // Pointer to TOF geometry
+ Int_t fN;              // Number of Clusters
+ Int_t fNseeds;         // Number of track seeds  
+ Int_t fNseedsTOF;      // TPC BP tracks
+ Int_t fnunmatch;       // Unmatched tracks
+ Int_t fnmatch;         // Total matched tracks
+
+ TClonesArray* fTracks; //! pointer to the TClonesArray with TOF tracks
+ TObjArray* fSeeds;  //! pointer to the TObjArray with ESD tracks
+ AliESDTOFcluster *fClusters; // pointers to the TOF clusters
+
+ ClassDef(AliTOFtrackerV2, 1) // TOF tracker 
+};
+
+#endif
index 2dd4622b109f7b018e87c65b39e61b41b20b4fb9..95c456abefae301d151b12f77f581b55a8b020fb 100644 (file)
@@ -34,6 +34,7 @@ set ( SRCS
     AliTOFtracker.cxx 
     AliTOFtrackerMI.cxx 
     AliTOFtrackerV1.cxx 
+    AliTOFtrackerV2.cxx 
     AliTOFReconstructor.cxx 
     AliTOFRecoParam.cxx 
     AliTOFT0maker.cxx 
index b27f44f2f79e6a3f17bc36ae57f4ba68638bca15..bedd8cddd0afd7bb4e17a89869480b76f1e3bc7c 100644 (file)
@@ -2,7 +2,7 @@
 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
  * See cxx source for full Copyright notice                               */
 
-/* $Id$ */
+/* $Id: TOFrecLinkDef.h 38239 2010-01-14 13:24:49Z rpreghen $ */
 
 #pragma link off all globals;
 #pragma link off all classes;
@@ -15,6 +15,7 @@
 #pragma link C++ class  AliTOFtracker+;
 #pragma link C++ class  AliTOFtrackerMI+;
 #pragma link C++ class  AliTOFtrackerV1+;
+#pragma link C++ class  AliTOFtrackerV2+;
 #pragma link C++ class  AliTOFReconstructor+;
 #pragma link C++ class  AliTOFRecoParam+;
 #pragma link C++ class  AliTOFQADataMakerRec+;