]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
new classes for track segments
authorschutz <schutz@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 8 Jan 2003 17:28:53 +0000 (17:28 +0000)
committerschutz <schutz@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 8 Jan 2003 17:28:53 +0000 (17:28 +0000)
EMCAL/AliEMCALTrackSegment.cxx [new file with mode: 0644]
EMCAL/AliEMCALTrackSegment.h [new file with mode: 0644]
EMCAL/AliEMCALTrackSegmentMaker.cxx [new file with mode: 0644]
EMCAL/AliEMCALTrackSegmentMaker.h [new file with mode: 0644]
EMCAL/AliEMCALTrackSegmentMakerv1.cxx [new file with mode: 0644]
EMCAL/AliEMCALTrackSegmentMakerv1.h [new file with mode: 0644]

diff --git a/EMCAL/AliEMCALTrackSegment.cxx b/EMCAL/AliEMCALTrackSegment.cxx
new file mode 100644 (file)
index 0000000..ec28bec
--- /dev/null
@@ -0,0 +1,118 @@
+/**************************************************************************
+ * 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$ */
+//_________________________________________________________________________
+//  Track segment in EMCAL
+//  Can be : 1 EmcRecPoint
+//           1 EmcRecPoint + 1 PPSD
+//           1 EmcRecPoint + 1 PPSD + 1 PPSD     
+//                  
+//*-- Author:  Dmitri Peressounko (RRC KI & SUBATECH)
+//             Adapted from PHOS by Y. Schutz (SUBATECH)
+
+// --- ROOT system ---
+
+// --- Standard library ---
+
+// --- AliRoot header files ---
+
+#include "AliEMCALTrackSegment.h" 
+
+ClassImp(AliEMCALTrackSegment)
+
+//____________________________________________________________________________
+AliEMCALTrackSegment::AliEMCALTrackSegment( AliEMCALTowerRecPoint * ec, AliEMCALTowerRecPoint * pre, AliEMCALTowerRecPoint * hc)
+{
+  // ctor
+
+  if( pre )   
+    fPRERecPoint =  pre->GetIndexInList() ;
+  else 
+    fPRERecPoint = -1 ;
+
+  if( ec )   
+    fECRecPoint =  ec->GetIndexInList() ;
+  else 
+    fECRecPoint = -1 ;
+
+  if( hc )   
+    fHCRecPoint =  hc->GetIndexInList() ;
+  else 
+    fHCRecPoint = -1 ;
+
+  fIndexInList = -1 ;
+}
+
+//____________________________________________________________________________
+AliEMCALTrackSegment::AliEMCALTrackSegment( const AliEMCALTrackSegment & ts) 
+{
+  // Copy ctor
+
+  ( (AliEMCALTrackSegment &)ts ).Copy(*this) ; 
+}
+
+
+//____________________________________________________________________________
+void AliEMCALTrackSegment::Copy(TObject & obj) 
+{
+  // Copy of a track segment into another track segment
+
+   TObject::Copy(obj) ;
+   ( (AliEMCALTrackSegment &)obj ).fPRERecPoint = fPRERecPoint ; 
+   ( (AliEMCALTrackSegment &)obj ).fECRecPoint  = fECRecPoint ; 
+   ( (AliEMCALTrackSegment &)obj ).fHCRecPoint  = fHCRecPoint ; 
+   ( (AliEMCALTrackSegment &)obj ).fIndexInList = fIndexInList ; 
+}
+
+//____________________________________________________________________________
+void AliEMCALTrackSegment::Print(Option_t * opt) const
+{
+  // Print all information on this track Segment
+  
+  
+  Info("Print", "TrackSegment information:") ; 
+  printf("--------AliEMCALTrackSegment-------- \n");
+  printf("Stored at position %d\n", fIndexInList) ;
+  if (fPRERecPoint) 
+    printf("PRE RecPoint #     %d\n", fPRERecPoint) ;
+  if (fECRecPoint) 
+    printf("EC RecPoint  #     %d\n", fECRecPoint) ;
+  if (fHCRecPoint) 
+    printf("HC RecPoint  #     %d\n", fHCRecPoint) ;
+
+  printf("------------------------------------ \n") ; 
+  
+}
+
+//____________________________________________________________________________
+void AliEMCALTrackSegment::SetPRERecPoint(AliEMCALRecPoint * pre) 
+{
+  // gives an id from its position in the list
+  if( pre )  
+    fPRERecPoint = pre->GetIndexInList() ;
+ else 
+    fPRERecPoint = -1 ;
+}
+
+//____________________________________________________________________________
+void AliEMCALTrackSegment::SetHCRecPoint(AliEMCALRecPoint * hc) 
+{
+  // gives an id from its position in the list
+  if( hc )  
+    fHCRecPoint = hc->GetIndexInList() ;
+ else 
+    fHCRecPoint = -1 ;
+}
diff --git a/EMCAL/AliEMCALTrackSegment.h b/EMCAL/AliEMCALTrackSegment.h
new file mode 100644 (file)
index 0000000..ab574f3
--- /dev/null
@@ -0,0 +1,58 @@
+#ifndef ALIEMCALTRACKSEGMENT_H
+#define ALIEMCALTRACKSEGMENT_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+//_________________________________________________________________________
+//  Track segment in EMCAL
+//  Can be any combination of : 1 PRERecPoint, ECRecPoint and HCRecPoint     
+//                  
+//*-- Author:  Dmitri Peressounko (RRC KI & SUBATECH)
+//             Adapted from PHOS by Y. Schutz (SUBATECH)
+// --- ROOT system ---
+
+#include "TObject.h"
+
+// --- Standard library ---
+
+// --- AliRoot header files ---
+
+#include "AliEMCALTowerRecPoint.h"
+
+class AliEMCALTrackSegment : public TObject  {
+
+public:
+
+  AliEMCALTrackSegment() {} 
+  AliEMCALTrackSegment(AliEMCALTowerRecPoint * ec, AliEMCALTowerRecPoint * pre, AliEMCALTowerRecPoint * hc) ; 
+  AliEMCALTrackSegment(const AliEMCALTrackSegment & ts) ;  // ctor                   
+  virtual ~AliEMCALTrackSegment() {  } 
+
+  void Copy(TObject & obj) ;  
+
+  Int_t   GetIndexInList() const {  return fIndexInList ; } 
+  Int_t   GetPREIndex()    const {  return fPRERecPoint ; }
+  Int_t   GetECIndex()     const {  return fECRecPoint; }
+  Int_t   GetHCIndex()     const {  return fHCRecPoint; }
+
+  virtual void  Print(Option_t * option) const;
+  void SetIndexInList(Int_t val){ fIndexInList = val ;     } 
+  void SetPRERecPoint(AliEMCALRecPoint * pre ) ; 
+  void SetHCRecPoint(AliEMCALRecPoint * hc ) ; 
+
+  typedef TClonesArray TrackSegmentsList ; 
+ private:
+  
+  Int_t fPRERecPoint ; // The PRE reconstructed point index in array stored in TreeR/EMCALPRERP
+  Int_t fECRecPoint ;  // The EC reconstructed point index in array stored in TreeR/EMCALECRP
+  Int_t fHCRecPoint ;  // The HC reconstructed point index in array stored in TreeR/EMCALHCRP
+  Int_t fIndexInList ; // The index of this TrackSegment in the list stored in TreeR (to be set by analysis)
+  
+  ClassDef(AliEMCALTrackSegment,1)  // Track segment in EMCAL
+
+};
+
+#endif // ALIEMCALTRACKSEGMENT_H
diff --git a/EMCAL/AliEMCALTrackSegmentMaker.cxx b/EMCAL/AliEMCALTrackSegmentMaker.cxx
new file mode 100644 (file)
index 0000000..ef75264
--- /dev/null
@@ -0,0 +1,63 @@
+/**************************************************************************
+ * 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$ */
+//_________________________________________________________________________
+// Algorithm Base class to construct EMCAL track segments
+// Associates EMC and PPSD clusters
+// Unfolds the EMC cluster   
+//*-- 
+//*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH)
+//             Adapted from PHOS by Y. Schutz (SUBATECH)
+
+
+// --- ROOT system ---
+#include "TGeometry.h"
+#include "TFile.h"
+#include "TTree.h"
+
+// --- Standard library ---
+#include <stdlib.h>   
+
+// --- AliRoot header files ---
+#include "AliRun.h" 
+#include "AliEMCALTrackSegmentMaker.h"
+#include "AliHeader.h" 
+
+ClassImp( AliEMCALTrackSegmentMaker) 
+
+
+//____________________________________________________________________________
+  AliEMCALTrackSegmentMaker:: AliEMCALTrackSegmentMaker() : TTask("","")
+{
+  // ctor
+  fSplitFile= 0 ; 
+
+}
+
+//____________________________________________________________________________
+AliEMCALTrackSegmentMaker::AliEMCALTrackSegmentMaker(const char * headerFile, const char * name, const Bool_t toSplit): TTask(name, headerFile)
+{
+  // ctor
+  fSplitFile= 0 ; 
+  fToSplit  = toSplit ;
+}
+
+//____________________________________________________________________________
+AliEMCALTrackSegmentMaker::~AliEMCALTrackSegmentMaker()
+{
+   
+      fSplitFile = 0 ;
+}
+
diff --git a/EMCAL/AliEMCALTrackSegmentMaker.h b/EMCAL/AliEMCALTrackSegmentMaker.h
new file mode 100644 (file)
index 0000000..77ee96c
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef ALIEMCALTRACKSEGMENTMAKER_H
+#define ALIEMCALTRACKSEGMENTMAKER_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+//_________________________________________________________________________
+// Algorithm Base class to construct EMCAL track segments
+// Associates EMC and PPSD clusters
+// Unfolds the EMC cluster   
+//                  
+//*-- Author: Dmitri Peressounko (RRC Kurchatov Institute  & SUBATECH)
+//             Adapted from PHOS by Y. Schutz (SUBATECH)
+
+// --- ROOT system ---
+#include "TTask.h"
+class TFile ;
+
+// --- Standard library ---
+
+// --- AliRoot header files ---
+
+
+class AliEMCALClusterizer ;
+class AliEMCALGeometry ;
+
+class  AliEMCALTrackSegmentMaker : public TTask {
+
+public:
+
+  AliEMCALTrackSegmentMaker() ;                     
+  AliEMCALTrackSegmentMaker(const char* headerFile, const char* name, const Bool_t toSplit) ;                     
+  
+  virtual ~ AliEMCALTrackSegmentMaker() ;
+
+  virtual void    Exec(Option_t * option){Warning("Exec", "Not Defined" ) ; } 
+  virtual const Int_t GetTrackSegmentsInRun()  const {Warning("GetTrackSegmentsInRun", "Not Defined" ) ; return 0 ; } 
+
+  virtual void    Print(Option_t * option)const {Warning("Print", "Not Defined" ) ; }  
+  virtual const char * Version() const {Warning("Version", "Not Defined" ) ; return 0 ; }   
+  virtual void WriteTrackSegments(Int_t event){Warning("WriteTrackSegments", "Not Defined" ) ; } 
+  
+protected:
+  
+  TFile * fSplitFile ;             //! file in which TrackSegments will eventually be stored
+  Bool_t  fToSplit ;               //! Do we work in the split mode
+
+  ClassDef( AliEMCALTrackSegmentMaker,1)    // Algorithm class to make EMCAL track segments (Base Class)
+
+};
+
+#endif // ALIEMCALTRACKSEGMENTMAKER_H
diff --git a/EMCAL/AliEMCALTrackSegmentMakerv1.cxx b/EMCAL/AliEMCALTrackSegmentMakerv1.cxx
new file mode 100644 (file)
index 0000000..78fcc3b
--- /dev/null
@@ -0,0 +1,520 @@
+/**************************************************************************
+ * 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$ */
+//_________________________________________________________________________
+// Implementation version 1 of algorithm class to construct EMCAL track segments
+// Track segment for EMCAL is list of 
+//        ECAL RecPoint + (possibly) PRE RecPoint + (possibly) HCAL RecPoint
+// To find TrackSegments we do the following: 
+//  for each ECAL RecPoint we look for PRE and HC RecPoints with same direction  within fSame. 
+//  If there is such a PRE or ECAL RecPoint, 
+//   we make a "Link": indexes of ECAL and PRE, HCAL  RecPoints and their scalar product. 
+//  Then we sort "Links", starting from the 
+//   least "Link" pointing to the unassigned RecPoints assigning them to a new TrackSegment. 
+//  If there is no PRE, HCAL RecPoint we make a TrackSegment 
+//   consisting from ECAL alone. There is no TrackSegments without ECAL RecPoint.
+//// In principle this class should be called from AliEMCALReconstructioner, but 
+// one can use it as well in standalone mode.
+//                 
+//*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH) & Yves Schutz (SUBATECH) 
+//
+
+// --- ROOT system ---
+#include "TROOT.h"
+#include "TFile.h"
+#include "TFolder.h"
+#include "TTree.h"
+#include "TSystem.h"
+#include "TBenchmark.h"
+
+// --- Standard library ---
+
+// --- AliRoot header files ---
+
+#include "AliEMCALTrackSegmentMakerv1.h"
+#include "AliEMCALClusterizerv1.h"
+#include "AliEMCALTrackSegment.h"
+#include "AliEMCALLink.h"
+#include "AliEMCALGetter.h"
+#include "AliEMCAL.h"
+#include "AliRun.h"
+
+ClassImp( AliEMCALTrackSegmentMakerv1) 
+
+
+//____________________________________________________________________________
+  AliEMCALTrackSegmentMakerv1::AliEMCALTrackSegmentMakerv1() : AliEMCALTrackSegmentMaker()
+{
+  // default ctor (to be used mainly by Streamer)
+
+  InitParameters() ; 
+
+  fTrackSegmentsInRun       = 0 ; 
+
+  fDefaultInit = kTRUE ; 
+}
+
+//____________________________________________________________________________
+ AliEMCALTrackSegmentMakerv1::AliEMCALTrackSegmentMakerv1(const char * headerFile, const char * name, const Bool_t toSplit) : AliEMCALTrackSegmentMaker(headerFile, name, toSplit)
+{
+  // ctor
+
+  InitParameters() ; 
+
+  fTrackSegmentsInRun       = 0 ; 
+
+  Init() ;
+
+  fDefaultInit = kFALSE ; 
+
+}
+
+//____________________________________________________________________________
+ AliEMCALTrackSegmentMakerv1::~AliEMCALTrackSegmentMakerv1()
+{ 
+  // dtor
+  // fDefaultInit = kTRUE if TrackSegmentMaker created by default ctor (to get just the parameters)
+  
+  if (!fDefaultInit) {
+    delete fPRELinkArray  ;
+    delete fHCLinkArray  ;
+    fSplitFile = 0 ; 
+  }
+}
+
+
+//____________________________________________________________________________
+const TString AliEMCALTrackSegmentMakerv1::BranchName() const 
+{  
+  TString branchName(GetName() ) ;
+  branchName.Remove(branchName.Index(Version())-1) ;
+  return branchName ;
+}
+
+//____________________________________________________________________________
+Float_t  AliEMCALTrackSegmentMakerv1::HowClose(AliEMCALTowerRecPoint * ec, AliEMCALTowerRecPoint * rp, Bool_t &toofar)const
+{
+  // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
+  // Clusters are sorted in "rows" and "columns" of width 1 cm
+
+  Float_t r = -1. ;
+  Float_t delta = 10. ;  // large enough to be ineffective ??! 
+
+  TVector3 vecEC = ec->XYZInAlice() ;
+  TVector3 vecRP = rp->XYZInAlice() ;
+  
+  Float_t pro = TMath::Abs(1 - (vecEC * vecRP / ( vecEC.Mag() * vecRP.Mag() ))) ; 
+
+  if(pro <= delta) { 
+    r = pro ;
+    toofar = kFALSE ;
+  } 
+  else 
+    toofar = kTRUE ;
+
+  if (gDebug == 2 ) 
+    Info("HowClose", "ec = %d, rp = %d pro = %f, toofar=%d", ec->GetIndexInList(), rp->GetIndexInList(), pro, toofar ) ; 
+  return r ;
+}
+
+//____________________________________________________________________________
+void  AliEMCALTrackSegmentMakerv1::Init()
+{
+  // Make all memory allocations that are not possible in default constructor
+  
+  if ( strcmp(GetTitle(), "") == 0 )
+    SetTitle("galice.root") ;
+    
+  TString branchname = GetName() ;
+  branchname.Remove(branchname.Index(Version())-1) ;
+  AliEMCALGetter * gime = AliEMCALGetter::GetInstance(GetTitle(),branchname.Data(), fToSplit ) ; 
+  if ( gime == 0 ) {
+    Error("Init", "Could not obtain the Getter object !") ; 
+    return ;
+  } 
+  
+  fSplitFile = 0 ;
+  if(fToSplit){
+    //First - extract full path if necessary
+    TString fileName(GetTitle()) ;
+    Ssiz_t islash = fileName.Last('/') ;
+    if(islash<fileName.Length())
+      fileName.Remove(islash+1,fileName.Length()) ;
+    else
+      fileName="" ;
+    fileName+="EMCAL.RecData." ;
+    if((strcmp(branchname.Data(),"Default")!=0)&&(strcmp(branchname.Data(),"")!=0)){
+      fileName+=branchname ;
+      fileName+="." ;
+    }
+    fileName+="root" ;
+    fSplitFile = static_cast<TFile*>(gROOT->GetFile(fileName.Data()));   
+    if(!fSplitFile)
+      fSplitFile =  TFile::Open(fileName.Data(),"update") ;
+  }
+  
+  fPRELinkArray = new TClonesArray("AliEMCALLink", 1000); 
+  fHCLinkArray  = new TClonesArray("AliEMCALLink", 1000); 
+
+
+  gime->PostTrackSegmentMaker(this) ;
+  gime->PostTrackSegments(BranchName()) ; 
+
+}
+
+//____________________________________________________________________________
+void  AliEMCALTrackSegmentMakerv1::InitParameters()
+{
+  fClose     = 10e-3 ;   
+  fPRELinkArray = 0 ;
+  fHCLinkArray  = 0 ;
+  TString tsmName( GetName()) ; 
+  if (tsmName.IsNull() ) 
+    tsmName = "Default" ; 
+  tsmName.Append(":") ; 
+  tsmName.Append(Version()) ; 
+  SetName(tsmName) ;
+}
+
+
+//____________________________________________________________________________
+void  AliEMCALTrackSegmentMakerv1::MakeLinks()const
+{ 
+  // Finds distances (links) between all PRE, EC and HC clusters, 
+  // which are not further apart from each other than fDangle 
+  // and sort them in accordance with this distance
+  
+  AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ; 
+  TObjArray * aECRecPoints  = gime->ECALRecPoints() ; 
+  TObjArray * aPRERecPoints = gime->PRERecPoints() ; 
+  TObjArray * aHCRecPoints  = gime->HCALRecPoints() ; 
+
+  fPRELinkArray->Clear() ;    
+  fHCLinkArray->Clear() ;    
+
+  AliEMCALTowerRecPoint * pre ;
+  AliEMCALTowerRecPoint * ec ;
+  AliEMCALTowerRecPoint * hc ;
+
+  Int_t iPRELink  = 0 ;
+  Int_t iHCLink   = 0 ;
+    
+  Int_t iECRP;
+  for(iECRP = 0; iECRP < aECRecPoints->GetEntriesFast(); iECRP++ ) {
+    ec = dynamic_cast<AliEMCALTowerRecPoint *>(aECRecPoints->At(iECRP)) ;
+    Bool_t toofar = kTRUE ;        
+    Int_t iPRERP = 0 ;    
+    for(iPRERP = 0; iPRERP < aPRERecPoints->GetEntriesFast(); iPRERP++ ) { 
+      pre = dynamic_cast<AliEMCALTowerRecPoint *>(aPRERecPoints->At(iPRERP)) ;
+      Float_t prod = HowClose(ec, pre, toofar) ;    
+      if(toofar)
+       break ;  
+      if(prod < fClose) { 
+       new ((*fPRELinkArray)[iPRELink++])  AliEMCALLink(prod, iECRP, iPRERP, 0) ;
+      }      
+    }
+    toofar = kTRUE ; 
+    Int_t iHCRP = 0 ;    
+    for(iHCRP = 0; iHCRP < aHCRecPoints->GetEntriesFast(); iHCRP++ ) { 
+      hc = dynamic_cast<AliEMCALTowerRecPoint *>(aHCRecPoints->At(iHCRP)) ;
+      Float_t prod = HowClose(ec, hc, toofar) ;    
+      if(toofar)
+       break ;  
+      if(prod < fClose) { 
+       new ((*fHCLinkArray)[iHCLink++])  AliEMCALLink(prod, iECRP, iHCRP, 1) ;
+      }      
+    }
+  } 
+  
+  fPRELinkArray->Sort() ;  //first links with largest scalar product
+  fHCLinkArray->Sort() ;  //first links with largest scalar product
+}
+
+//____________________________________________________________________________
+void  AliEMCALTrackSegmentMakerv1::MakePairs()
+{ 
+  // Using the previously made list of "links", we found the best link - i.e. 
+  // link with the largest scalar product (closest to one) to still 
+  // unassigned RecParticles. We assign these RecPoints to TrackSegment and 
+  // remove them from the list of "unassigned". 
+  
+  AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ; 
+  TObjArray * aECALRecPoints = gime->ECALRecPoints() ; 
+  TObjArray * aPRERecPoints = gime->PRERecPoints() ; 
+  TObjArray * aHCALRecPoints = gime->HCALRecPoints() ; 
+  TClonesArray * trackSegments = gime->TrackSegments(BranchName()) ;   
+    
+  //Make arrays to mark clusters already chosen
+  Int_t * ecalExist = 0;
+  Int_t nECAL = aECALRecPoints->GetEntriesFast() ;  
+  if (nECAL) 
+    ecalExist = new Int_t[nECAL] ;
+  
+  Int_t index;
+  for(index = 0; index < nECAL; index ++)
+    ecalExist[index] = 1 ;
+  
+  Bool_t * preExist = 0;
+  Int_t nPRE = aPRERecPoints->GetEntriesFast() ;  
+  if(nPRE)
+    preExist = new Bool_t[nPRE] ;
+  for(index = 0; index < nPRE; index ++)
+    preExist[index] = kTRUE ;
+  
+  Bool_t * hcalExist = 0;
+  Int_t nHCAL = aHCALRecPoints->GetEntriesFast() ;  
+  if(nHCAL)
+    hcalExist = new Bool_t[nHCAL] ;
+  for(index = 0; index < nHCAL; index ++)
+    hcalExist[index] = kTRUE ;
+  
+  AliEMCALTowerRecPoint * null = 0 ; 
+ // Finds the smallest links and makes pairs of PRE and ECAL clusters with largest scalar product 
+  TIter nextPRE(fPRELinkArray) ;
+  AliEMCALLink * linkPRE ;
+  
+  while ( (linkPRE =  static_cast<AliEMCALLink *>(nextPRE()) ) ){  
+
+    if(ecalExist[linkPRE->GetECAL()] != -1){ //without PRE yet 
+
+      if(preExist[linkPRE->GetOther()]){ // PRE still exist
+       
+       new ((* trackSegments)[fNTrackSegments]) 
+         AliEMCALTrackSegment(dynamic_cast<AliEMCALTowerRecPoint *>(aECALRecPoints->At(linkPRE->GetECAL())) , 
+                              dynamic_cast<AliEMCALTowerRecPoint *>(aPRERecPoints->At(linkPRE->GetOther())), null) ;
+       (dynamic_cast<AliEMCALTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
+       fNTrackSegments++ ;
+       if (gDebug == 2 ) 
+         Info("MakePairs", "ECAL section with PRE section") ;  
+       ecalExist[linkPRE->GetECAL()] = -1 ; //Mark ecal  that pre was found 
+       //mark PRE recpoint as already used 
+       preExist[linkPRE->GetOther()] = kFALSE ;
+      } //if PRE still exist
+    } 
+  }
+
+  // Finds the smallest links and makes pairs of HCAL and ECAL clusters with largest scalar product 
+  TIter nextHCAL(fHCLinkArray) ;
+  AliEMCALLink * linkHCAL ;
+  
+  while ( (linkHCAL =  static_cast<AliEMCALLink *>(nextHCAL()) ) ){  
+
+    if(ecalExist[linkHCAL->GetECAL()] != -2){ //without HCAL yet 
+
+      if(hcalExist[linkHCAL->GetOther()]){ // HCAL still exist
+       // search among the already existing track segments
+       Int_t ii ; 
+       Bool_t found = kFALSE ; 
+       AliEMCALTrackSegment * ts = 0 ; 
+       for ( ii = 0 ; ii < fNTrackSegments ; ii++ ) {
+         ts = dynamic_cast<AliEMCALTrackSegment *>(trackSegments->At(ii)) ;
+         if ( ts->GetECIndex() == linkHCAL->GetECAL() ) {
+           found = kTRUE ; 
+           break ; 
+         }
+       }
+       if (found){
+         ts->SetHCRecPoint( dynamic_cast<AliEMCALTowerRecPoint *>(aHCALRecPoints->At(linkHCAL->GetOther())) ) ;
+         if (gDebug == 2 ) 
+           Info("MakePairs", "ECAL section with PRE and HCAL sections") ;
+       }       
+       if (!found) {
+         new ((* trackSegments)[fNTrackSegments]) 
+           AliEMCALTrackSegment(dynamic_cast<AliEMCALTowerRecPoint *>(aECALRecPoints->At(linkHCAL->GetECAL())), null,
+                                dynamic_cast<AliEMCALTowerRecPoint *>(aHCALRecPoints->At(linkHCAL->GetOther()))) ; 
+       (dynamic_cast<AliEMCALTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
+       fNTrackSegments++ ;
+       if (gDebug == 2 ) 
+         Info("MakePairs", "ECAL section with HCAL section") ;         
+       }
+       ecalExist[linkHCAL->GetECAL()] = -2 ; //Mark ecal  that hcal was found 
+       //mark HCAL recpoint as already used 
+       hcalExist[linkHCAL->GetOther()] = kFALSE ;
+      } //if HCAL still exist
+    } 
+  }
+  
+
+  //look through ECAL recPoints left without PRE/HCAL
+  if(ecalExist){ //if there is ecal rec point
+    Int_t iECALRP ;
+    for(iECALRP = 0; iECALRP < nECAL  ; iECALRP++ ){
+      if(ecalExist[iECALRP] > 0 ){
+       new ((*trackSegments)[fNTrackSegments])  
+         AliEMCALTrackSegment(dynamic_cast<AliEMCALTowerRecPoint *>(aECALRecPoints->At(iECALRP)), null, null) ;
+       (dynamic_cast<AliEMCALTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
+       fNTrackSegments++;    
+       if( gDebug == 2 ) 
+         Info("MakePairs", "ECAL section alone") ; 
+     } 
+    }
+  }
+  delete [] ecalExist ; 
+  delete [] preExist ; 
+  delete [] hcalExist ; 
+}
+
+//____________________________________________________________________________
+void  AliEMCALTrackSegmentMakerv1::Exec(Option_t * option)
+{
+  // STEERing method
+
+  if( strcmp(GetName(), "")== 0 ) 
+    Init() ;
+
+  if(strstr(option,"tim"))
+    gBenchmark->Start("EMCALTSMaker");
+  if(strstr(option,"print")) {
+    Print("") ; 
+    return ; 
+  }
+
+  AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ; 
+  if(gime->BranchExists("TrackSegments") )
+    return ;
+
+  Int_t nevents = gime->MaxEvent() ;       //(Int_t) gAlice->TreeE()->GetEntries() ;
+  Int_t ievent ;
+
+  for(ievent = 0; ievent < nevents; ievent++){
+
+    gime->Event(ievent,"R") ;
+    //Make some initializations 
+    fNTrackSegments = 0 ;
+    gime->TrackSegments(BranchName())->Clear() ; 
+    
+    MakeLinks() ;
+    
+    MakePairs() ;
+
+    WriteTrackSegments(ievent) ;
+    
+    if(strstr(option,"deb"))
+      PrintTrackSegments(option) ;
+    
+    //increment the total number of track segments per run 
+    fTrackSegmentsInRun += gime->TrackSegments(BranchName())->GetEntriesFast() ; 
+    
+  }
+  
+  if(strstr(option,"tim")){
+    gBenchmark->Stop("EMCALTSMaker");
+    Info("Exec", "took %f seconds for making TS %f seconds per event", 
+        gBenchmark->GetCpuTime("EMCALTSMaker"), gBenchmark->GetCpuTime("EMCALTSMaker")/nevents) ;
+  }
+  
+}
+
+//____________________________________________________________________________
+void AliEMCALTrackSegmentMakerv1::Print(Option_t * option)const
+{
+  //  Print TrackSegmentMaker parameters
+
+  Info("Print", "TrackSegmentMakerv1 parameters:") ; 
+  if( strcmp(GetName(), "") != 0 ) { 
+    printf("Making Track segments with parameters:\n") ; 
+    printf("    Allowed spred on the scalar product of two recpoints with same direction: %f\n", fClose) ;
+    printf("============================================\n") ;
+  }
+  else
+    printf("AliEMCALTrackSegmentMakerv1 not initialized ") ;
+}
+
+//____________________________________________________________________________
+void AliEMCALTrackSegmentMakerv1::WriteTrackSegments(Int_t event)
+{
+  // Writes found TrackSegments to TreeR. Creates branches 
+  // "EMCALTS" and "AliEMCALTrackSegmentMaker" with the same title.
+  // In the former branch found TrackSegments are stored, while 
+  // in the latter all parameters, with which TS were made. 
+  // ROOT does not allow overwriting existing branches, therefore
+  // first we check, if branches with the same title already exist.
+  // If yes - exits without writing.
+  
+  AliEMCALGetter *gime = AliEMCALGetter::GetInstance() ; 
+
+  TClonesArray * trackSegments = gime->TrackSegments() ; 
+  trackSegments->Expand(trackSegments->GetEntriesFast()) ;
+  TTree * treeR ;
+  
+  if(fToSplit){
+    if(!fSplitFile)
+      return ;
+    fSplitFile->cd() ;
+    char name[10] ;
+    sprintf(name,"%s%d", "TreeR",event) ;
+    treeR = dynamic_cast<TTree*>(fSplitFile->Get(name)); 
+  }
+  else{
+    treeR = gAlice->TreeR();
+  }
+  
+  if(!treeR){
+    gAlice->MakeTree("R", fSplitFile);
+    treeR = gAlice->TreeR() ;
+  }
+  
+  //First TS
+  Int_t bufferSize = 32000 ;    
+  TBranch * tsBranch = treeR->Branch("EMCALTS",&trackSegments,bufferSize);
+  tsBranch->SetTitle(BranchName());
+
+  //Second -TSMaker
+  Int_t splitlevel = 0 ;
+  AliEMCALTrackSegmentMakerv1 * ts = this ;
+  TBranch * tsMakerBranch = treeR->Branch("AliEMCALTrackSegmentMaker","AliEMCALTrackSegmentMakerv1",
+                                         &ts,bufferSize,splitlevel);
+  tsMakerBranch->SetTitle(BranchName());
+
+  tsBranch->Fill() ;  
+  tsMakerBranch->Fill() ;
+
+  treeR->AutoSave() ; //Write(0,kOverwrite) ;  
+  if(gAlice->TreeR()!=treeR)
+    treeR->Delete();
+}
+
+
+//____________________________________________________________________________
+void AliEMCALTrackSegmentMakerv1::PrintTrackSegments(Option_t * option)
+{
+  // option deb - prints # of found TrackSegments
+  // option deb all - prints as well indexed of found RecParticles assigned to the TS
+  TString taskName(GetName()) ; 
+  taskName.Remove(taskName.Index(Version())-1) ;
+  
+  TClonesArray * trackSegments = AliEMCALGetter::GetInstance()->TrackSegments(taskName) ; 
+
+
+  Info("PrintTrackSegments", "Results from TrackSegmentMaker:") ; 
+  printf("nevent: %d\n", gAlice->GetEvNumber()) ; 
+  printf("        Found %d TrackSegments\n", trackSegments->GetEntriesFast() ); 
+
+  if(strstr(option,"all")) {  // printing found TS
+    printf("TrackSegment#  ECAL RP#  PRE RP#   HCAL RP#  \n") ; 
+    Int_t index;
+    for (index = 0 ; index < fNTrackSegments ; index++) {
+      AliEMCALTrackSegment * ts = (AliEMCALTrackSegment * )trackSegments->At(index) ; 
+      printf("   %d           %d        %d         %d \n", 
+            ts->GetIndexInList(), ts->GetECIndex(), ts->GetPREIndex(), ts->GetHCIndex() ); 
+    }  
+  }
+}
diff --git a/EMCAL/AliEMCALTrackSegmentMakerv1.h b/EMCAL/AliEMCALTrackSegmentMakerv1.h
new file mode 100644 (file)
index 0000000..2be5609
--- /dev/null
@@ -0,0 +1,75 @@
+#ifndef ALIEMCALTRACKSEGMENTMAKERV1_H
+#define ALIEMCALTRACKSEGMENTMAKERV1_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+//_________________________________________________________________________
+// Implementation version 1 of algorithm class to construct EMCAL track segments
+// Associates EMC and PPSD clusters
+// Unfolds the EMC cluster   
+//                  
+//*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH) & Yves Schutz (SUBATECH) 
+
+// --- ROOT system ---
+
+// --- Standard library ---
+
+// --- AliRoot header files ---
+#include "AliEMCALTrackSegmentMaker.h"
+
+class AliEMCALTowerRecPoint ;
+
+class  AliEMCALTrackSegmentMakerv1 : public AliEMCALTrackSegmentMaker {
+
+public:
+
+  AliEMCALTrackSegmentMakerv1() ;                     
+  AliEMCALTrackSegmentMakerv1(const char* headerFile, const char* name = "Default", const Bool_t toSplit = kFALSE) ;                     
+  AliEMCALTrackSegmentMakerv1(const AliEMCALTrackSegmentMakerv1 & tsm) {
+    // cpy ctor: no implementation yet
+    // requested by the Coding Convention
+    Fatal("cpy ctor", "not implemented") ;
+}
+   
+  virtual ~ AliEMCALTrackSegmentMakerv1() ; // dtor
+  
+  virtual const Int_t GetTrackSegmentsInRun()const {return fTrackSegmentsInRun ;}  
+
+  virtual void   Exec(Option_t * option) ;
+  Float_t HowClose(AliEMCALTowerRecPoint * ec, AliEMCALTowerRecPoint * rp, Bool_t &toofar) const ;
+          void   MakeLinks() const;      //Evaluates distances(links) between PRE/EC/HC recpoints
+          void   MakePairs() ;           //Finds pairs(triplets) with smallest link
+  virtual void   Print(Option_t * option) const ;
+  virtual const char * Version() const { return "tsm-v1" ; }  
+
+  AliEMCALTrackSegmentMakerv1 & operator = (const AliEMCALTrackSegmentMakerv1 & )  {
+    // assignement operator requested by coding convention but not needed
+    Fatal("operator =", "not implemented") ;
+    return *this ; 
+  }
+
+
+private:
+
+  const TString BranchName() const ; 
+  void    Init() ;
+  void    InitParameters() ;
+  void    PrintTrackSegments(Option_t *option) ;
+  virtual void   WriteTrackSegments(Int_t event) ;
+
+private:  
+
+  Float_t fClose ;               // Spread within which 2 recpoints are declared to have the same direction 
+  Bool_t  fDefaultInit ;         //! Says if the task was created by defaut ctor (only parameters are initialized)
+  Int_t fNTrackSegments ;        // number of track segments found 
+  TClonesArray * fPRELinkArray  ;//! Contains the links ECAL-PRE
+  TClonesArray * fHCLinkArray  ; //! Contains the links ECAL-HCAL
+  Int_t fTrackSegmentsInRun ;    //! Total number of track segments in one run
+
+  ClassDef( AliEMCALTrackSegmentMakerv1,2)  // Implementation version 1 of algorithm class to make EMCAL track segments 
+
+};
+
+#endif // AliEMCALTRACKSEGMENTMAKERV1_H