adding new library libAliHLTGlobal for global HLT components; adding global track...
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 2 Jan 2009 14:43:49 +0000 (14:43 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 2 Jan 2009 14:43:49 +0000 (14:43 +0000)
15 files changed:
HLT/AliHLTGlobalLinkDef.h [new file with mode: 0644]
HLT/CMakeLists.txt
HLT/CMake_libAliHLTGlobal.txt [new file with mode: 0644]
HLT/Makefile.am
HLT/configure.ac
HLT/doc/Makefile.am
HLT/global/AliHLTGlobalAgent.cxx [new file with mode: 0644]
HLT/global/AliHLTGlobalAgent.h [new file with mode: 0644]
HLT/global/AliHLTGlobalTrackMerger.cxx [new file with mode: 0644]
HLT/global/AliHLTGlobalTrackMerger.h [new file with mode: 0644]
HLT/global/AliHLTGlobalTrackMergerComponent.cxx [new file with mode: 0644]
HLT/global/AliHLTGlobalTrackMergerComponent.h [new file with mode: 0644]
HLT/global/Makefile.am [new file with mode: 0644]
HLT/global/macros/rec-hlt-global-merger.C [new file with mode: 0644]
HLT/libAliHLTGlobal.pkg [new file with mode: 0644]

diff --git a/HLT/AliHLTGlobalLinkDef.h b/HLT/AliHLTGlobalLinkDef.h
new file mode 100644 (file)
index 0000000..9b35b44
--- /dev/null
@@ -0,0 +1,12 @@
+
+#ifdef __CINT__
+
+#pragma link off all globals;
+#pragma link off all classes;
+#pragma link off all functions;
+
+#pragma link C++ class  AliHLTGlobalTrackMerger+;
+#pragma link C++ class  AliHLTGlobalTrackMergerComponent+;
+#pragma link C++ class  AliHLTGlobalAgent+;
+
+#endif
index 64e8aec..fd03ac7 100644 (file)
@@ -39,6 +39,7 @@ ${CMAKE_SOURCE_DIR}/RAW
 ${CMAKE_SOURCE_DIR}/STEER
 ${CMAKE_SOURCE_DIR}/TPC
 ${CMAKE_SOURCE_DIR}/TRD
+${CMAKE_SOURCE_DIR}/global
 ${ROOT_INCLUDE_DIR}
 )
 
@@ -74,6 +75,8 @@ Include(CMake_libHLTrec.txt)
 
 Include(CMake_libHLTbase.txt)
 
+Include(CMake_libAliHLTGlobal.txt)
+
 Include(CMake_libAliHLTTPC.txt)
 
 Include(CMake_libAliHLTTRD.txt)
diff --git a/HLT/CMake_libAliHLTGlobal.txt b/HLT/CMake_libAliHLTGlobal.txt
new file mode 100644 (file)
index 0000000..8e66cf6
--- /dev/null
@@ -0,0 +1,14 @@
+# -*- mode: cmake -*-
+
+set(SRCS
+global/AliHLTGlobalTrackMergerComponent.cxx
+global/AliHLTGlobalTrackMerger.cxx
+global/AliHLTGlobalAgent.cxx
+)
+
+# fill list of header files from list of source files
+# by exchanging the file extension
+String(REPLACE ".cxx" ".h" HDRS "${SRCS}")
+
+
+AddLibrary(AliHLTGlobal "${SRCS}" "${HDRS}")
index 870f4b5..1448b4e 100644 (file)
@@ -53,6 +53,11 @@ if EN_HLT_EMCAL
 EMCAL_DIR=EMCAL
 endif
 
+if EN_HLT_GLOBAL
+GLOBAL_DIR=global
+endif
+
+
 SUBDIRS                = BASE \
                          $(ALIROOT_DEP) \
                          $(RCU_DIR) \
@@ -66,6 +71,7 @@ SUBDIRS               = BASE \
                           $(TRIGGER_DIR) \
                           $(ITS_DIR) \
                           $(EMCAL_DIR) \
+                          $(GLOBAL_DIR) \
                          doc
 
 EXTRA_DIST             = libHLTbase.pkg \
@@ -87,6 +93,7 @@ EXTRA_DIST            = libHLTbase.pkg \
                          libAliHLTRCU.pkg \
                          libAliHLTITS.pkg \
                          libAliHLTEMCAL.pkg \
+                         libAliHLTGlobal.pkg \
                          exa/sample-component1.C \
                          exa/monitoring.C \
                          hlt.conf \
index 0ed6611..ddaba1a 100644 (file)
@@ -892,6 +892,50 @@ AC_MSG_RESULT([$enable_module])
 AC_SUBST([ALITRIGGER_LIBS])
 
 dnl ------------------------------------------------------------------
+AH_TEMPLATE([HLT_GLOBAL],[hlt global library])
+
+ALIGLOBAL_LIBS=
+CHECK_HLTMODULE([global],
+               [], [$ALIROOT_CPPFLAGS],
+               [], [-L$ROOTLIBDIR], [$ROOTLIBS $ADD_ROOTLIBS],
+               [], [-L$ROOTLIBDIR $ALIROOT_LDFLAGS], 
+               [$ROOTLIBS $ADD_ROOTLIBS $ALIROOT_LIBS])
+
+if test "x$enable_module" = "xmissheader"; then
+  enable_module="no...header.missing"
+  enable_global=$enable_module
+elif test "x$enable_module" = "xforce"; then
+  enable_global="yes"
+else
+  enable_global=$enable_module
+  if test "x$enable_global" = "xyes" ; then
+    AC_LANG_PUSH(C++)
+    save_CPPFLAGS="$CPPFLAGS"
+    CPPFLAGS="$save_CPPFLAGS $ALIROOT_CPPFLAGS"
+    AC_MSG_CHECKING([for required functions in AliESDtrack])
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <AliESDtrack.h>], 
+                                       [AliESDtrack t;
+                                      t.SetGlobalChi2(0)])],
+                                       [], 
+                                      [enable_global="no...requires.AliRoot>v4-17-Release"])
+    AC_MSG_RESULT([$enable_global])       
+    AC_LANG_POP(C++)
+    CPPFLAGS="$save_CPPFLAGS"
+  fi
+fi
+
+if test "x$enable_global" = "xyes" ; then 
+  AC_DEFINE(HLT_GLOBAL)
+  ALIGLOBAL_LIBS=$ALIHLTMODULE_LIBS
+else
+  enable_module=$enable_global
+fi
+AM_CONDITIONAL(EN_HLT_GLOBAL, test x$enable_global = xyes)
+AC_MSG_CHECKING([whether to compile Global library])
+AC_MSG_RESULT([$enable_module])
+AC_SUBST([ALIGLOBAL_LIBS])
+
+dnl ------------------------------------------------------------------
 AH_TEMPLATE([HLT_ITS],[hlt its library])
 
 ALIITS_LIBS=
@@ -1197,6 +1241,11 @@ if test "x$enable_trigger" = "xyes"; then
                    trigger/test/Makefile])
 fi
 
+AC_MSG_NOTICE([compile global library: $enable_global])
+if test "x$enable_global" = "xyes"; then 
+  AC_CONFIG_FILES([global/Makefile])
+fi
+
 AC_MSG_NOTICE([compile comp library: $enable_comp])
 if test "x$enable_comp" = "xyes"; then 
   AC_CONFIG_FILES([comp/Makefile])
index 892aa0d..dba3d09 100644 (file)
@@ -53,6 +53,10 @@ if EN_HLT_TRIGGER
 MODULES                        += trigger
 endif
 
+if EN_HLT_GLOBAL
+MODULES                        += global
+endif
+
 # if EN_HLT_ITS
 # MODULES                      += ITS
 # endif
diff --git a/HLT/global/AliHLTGlobalAgent.cxx b/HLT/global/AliHLTGlobalAgent.cxx
new file mode 100644 (file)
index 0000000..7acfe7f
--- /dev/null
@@ -0,0 +1,98 @@
+// $Id$
+
+//**************************************************************************
+//* This file is property of and copyright by the ALICE HLT Project        * 
+//* ALICE Experiment at CERN, All rights reserved.                         *
+//*                                                                        *
+//* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
+//*                  for The ALICE HLT Project.                            *
+//*                                                                        *
+//* 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.                  *
+//**************************************************************************
+
+/** @file   AliHLTGlobalAgent.cxx
+    @author Matthias Richter
+    @date   
+    @brief  Agent of the libAliHLTGlobal library
+*/
+
+#include <cassert>
+#include "AliHLTGlobalAgent.h"
+
+// header files of library components
+#include "AliHLTGlobalTrackMergerComponent.h"
+
+/** global instance for agent registration */
+AliHLTGlobalAgent gAliHLTGlobalAgent;
+
+/** ROOT macro for the implementation of ROOT specific class methods */
+ClassImp(AliHLTGlobalAgent)
+
+AliHLTGlobalAgent::AliHLTGlobalAgent()
+  :
+  AliHLTModuleAgent("Global")
+{
+  // see header file for class documentation
+  // or
+  // refer to README to build package
+  // or
+  // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+}
+
+AliHLTGlobalAgent::~AliHLTGlobalAgent()
+{
+  // see header file for class documentation
+}
+
+int AliHLTGlobalAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
+{
+  // see header file for class documentation
+  assert(pHandler);
+  if (!pHandler) return -EINVAL;
+  pHandler->AddComponent(new AliHLTGlobalTrackMergerComponent);
+  return 0;
+}
+
+int AliHLTGlobalAgent::GetHandlerDescription(AliHLTComponentDataType dt,
+                                          AliHLTUInt32_t /*spec*/,
+                                         AliHLTOUTHandlerDesc& desc) const
+{
+  // see header file for class documentation
+
+  // handler for the HLT readou list and global data data blocks {'HLTRDLST':'HLT '}
+  if (dt==AliHLTComponentDataTypeInitializer("HLTRDLST", kAliHLTDataOriginOut) ||
+      dt==AliHLTComponentDataTypeInitializer("HLTTRGDT", kAliHLTDataOriginOut)) {
+      desc=AliHLTOUTHandlerDesc(kProprietary, dt, GetModuleId());
+      return 1;
+  }
+
+  return 0;
+}
+
+AliHLTOUTHandler* AliHLTGlobalAgent::GetOutputHandler(AliHLTComponentDataType dt,
+                                                  AliHLTUInt32_t /*spec*/)
+{
+  // see header file for class documentation
+
+  // handler for the HLT readou list and global data data blocks {'HLTRDLST':'HLT '}
+  if (dt==AliHLTComponentDataTypeInitializer("HLTRDLST", kAliHLTDataOriginOut) ||
+      dt==AliHLTComponentDataTypeInitializer("HLTTRGDT", kAliHLTDataOriginOut)) {
+    return NULL;
+  }
+
+  return NULL;
+}
+
+int AliHLTGlobalAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
+{
+  // see header file for class documentation
+  if (pInstance==NULL) return -EINVAL;
+
+  return 0;
+}
diff --git a/HLT/global/AliHLTGlobalAgent.h b/HLT/global/AliHLTGlobalAgent.h
new file mode 100644 (file)
index 0000000..b585967
--- /dev/null
@@ -0,0 +1,56 @@
+// $Id$
+
+#ifndef ALIHLTGLOBALAGENT_H
+#define ALIHLTGLOBALAGENT_H
+//* This file is property of and copyright by the ALICE HLT Project        * 
+//* ALICE Experiment at CERN, All rights reserved.                         *
+//* See cxx source for full Copyright notice                               */
+
+/** @file   AliHLTGlobalAgent.h
+    @author Matthias Richter
+    @date   
+    @brief  Agent of the libAliHLTGlobal library
+*/
+
+#include "AliHLTModuleAgent.h"
+
+class AliHLTOUTHandler;
+
+/**
+ * @class AliHLTGlobalAgent
+ * This is the agent for the AliHLTGlobal library.
+ *
+ * @ingroup alihlt_system
+ */
+class AliHLTGlobalAgent : public AliHLTModuleAgent {
+ public:
+  /**
+   * standard constructor. The agent is automatically registered in the
+   * global agent manager
+   */
+  AliHLTGlobalAgent();
+  /** destructor */
+  virtual ~AliHLTGlobalAgent();
+
+  int RegisterComponents(AliHLTComponentHandler* pHandler) const;
+
+  int GetHandlerDescription(AliHLTComponentDataType dt,
+                           AliHLTUInt32_t spec,
+                           AliHLTOUTHandlerDesc& desc) const;
+
+  AliHLTOUTHandler* GetOutputHandler(AliHLTComponentDataType dt, AliHLTUInt32_t spec);
+
+  int DeleteOutputHandler(AliHLTOUTHandler* pInstance);
+
+ protected:
+
+ private:
+  /** copy constructor prohibited */
+  AliHLTGlobalAgent(const AliHLTGlobalAgent&);
+  /** assignment operator prohibited */
+  AliHLTGlobalAgent& operator=(const AliHLTGlobalAgent&);
+
+  ClassDef(AliHLTGlobalAgent, 0);
+};
+
+#endif
diff --git a/HLT/global/AliHLTGlobalTrackMerger.cxx b/HLT/global/AliHLTGlobalTrackMerger.cxx
new file mode 100644 (file)
index 0000000..c120108
--- /dev/null
@@ -0,0 +1,530 @@
+//$Id$
+
+/**************************************************************************
+ * This file is property of and copyright by the ALICE HLT Project        * 
+ * ALICE Experiment at CERN, All rights reserved.                         *
+ *                                                                        *
+ * Primary Authors: Jacek Otwinowski (Jacek.Otwinowski@gsi.de)            *
+ *                  for The ALICE HLT Project.                            *
+ *                                                                        *
+ * 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.                  *
+ **************************************************************************/
+
+/** @file   AliHLTGlobalTrackMerger.cxx
+    @author Jacek Otwinowski
+    @date   
+    @brief  The HLT global merger base class
+*/
+
+#include "AliHLTTPCTransform.h"
+#include "AliHLTTPCTrack.h"
+#include "AliHLTTPCTrackSegmentData.h"
+#include "AliHLTTPCTransform.h"
+#include "AliHLTTPCTrackArray.h"
+
+#include "AliTRDtrackV1.h"
+#include "AliESDEvent.h"
+#include "AliESDVertex.h"
+#include "AliTracker.h"
+
+#include <TClonesArray.h>
+
+#include "AliHLTGlobalTrackMerger.h"
+
+#if __GNUC__>= 3
+using namespace std;
+#endif
+
+ClassImp(AliHLTGlobalTrackMerger)
+
+AliHLTGlobalTrackMerger::AliHLTGlobalTrackMerger()
+  :
+  fMaxY(0.0),
+  fMaxZ(0.0),
+  fMaxSnp(0.0),
+  fMaxTgl(0.0),
+  fMaxSigned1Pt(0.0),
+  fVertex(0)
+{
+  //Default constructor
+
+  // standard vertex settings at the moment
+  // V(0.,0.,0.), sigmaVx=sigmaVy=5.e-3 [cm], sigmaVz=5.3 [cm]    
+  fVertex = new AliESDVertex;
+}
+
+//_____________________________________________________________________________
+AliHLTGlobalTrackMerger::~AliHLTGlobalTrackMerger()
+{
+  //Destructor
+  if(fVertex) delete fVertex; fVertex =0;
+}
+
+//_____________________________________________________________________________
+Bool_t AliHLTGlobalTrackMerger::LoadTracks(TClonesArray *aTRDTracks, AliESDEvent *esdEvent)
+{
+  // load TRD tracks
+  if(!aTRDTracks) return kFALSE;
+
+  Int_t entries = aTRDTracks->GetEntriesFast();
+  for(Int_t i=0; i<entries; ++i) {
+    AliTRDtrackV1 *track = (AliTRDtrackV1*)aTRDTracks->At(i);
+    if(!track) continue;
+
+    FillTRDESD(track,AliESDtrack::kTRDin,esdEvent); 
+  }
+
+return kTRUE;
+}
+
+//_____________________________________________________________________________
+Bool_t AliHLTGlobalTrackMerger::LoadTracks(AliHLTTPCTrackArray *aTPCTracks, AliESDEvent *esdEvent)
+{
+  // load TPC tracks
+  if(!aTPCTracks) return kFALSE;
+
+  for (int i=0; i<aTPCTracks->GetNTracks();++i) {
+    AliHLTTPCTrack* track=(*aTPCTracks)[i];
+    if(!track) continue;
+
+    // convert to the AliKalmanTrack 
+    Int_t local=track->Convert2AliKalmanTrack();
+    if(local<0) continue;
+
+    FillTPCESD(track,AliESDtrack::kTPCin,esdEvent); 
+  }
+
+return kTRUE;
+}
+
+//_____________________________________________________________________________
+void AliHLTGlobalTrackMerger::FillTPCESD(AliHLTTPCTrack *tpcTrack, ULong_t flags, AliESDEvent* esdEvent)
+{
+  // create AliESDtracks from AliHLTTPCTracks 
+  // and add them to AliESDEvent
+
+  if(!tpcTrack) return;
+  if(!esdEvent) return;
+
+  AliESDtrack iotrack;
+  iotrack.UpdateTrackParams(tpcTrack,flags);
+
+  Float_t points[4]={tpcTrack->GetFirstPointX(),tpcTrack->GetFirstPointY(),tpcTrack->GetLastPointX(),tpcTrack->GetLastPointY()};
+  if(tpcTrack->GetSector() == -1){ // Set first and last points for global tracks
+    Double_t s = TMath::Sin( tpcTrack->GetAlpha() );
+    Double_t c = TMath::Cos( tpcTrack->GetAlpha() );
+    points[0] =  tpcTrack->GetFirstPointX()*c + tpcTrack->GetFirstPointY()*s;
+    points[1] = -tpcTrack->GetFirstPointX()*s + tpcTrack->GetFirstPointY()*c;
+    points[2] =  tpcTrack->GetLastPointX() *c + tpcTrack->GetLastPointY() *s;
+    points[3] = -tpcTrack->GetLastPointX() *s + tpcTrack->GetLastPointY() *c;
+  }
+  iotrack.SetTPCPoints(points);
+
+  esdEvent->AddTrack(&iotrack);
+}
+//_____________________________________________________________________________
+void AliHLTGlobalTrackMerger::FillTRDESD(AliTRDtrackV1* trdTrack, ULong_t flags, AliESDEvent* esdEvent)
+{
+  // create AliESDtracks from AliTRDtrackV1
+  // and add them to AliESDEvent
+
+  if(!trdTrack) return;
+  if(!esdEvent) return;
+
+  AliESDtrack iotrack;
+  iotrack.UpdateTrackParams(trdTrack,flags);
+  esdEvent->AddTrack(&iotrack);
+}
+
+//_____________________________________________________________________________
+Bool_t AliHLTGlobalTrackMerger::Merge(AliESDEvent* esdEvent)
+{
+  // merge TPC and TRD tracks
+  // 1. propagate TPC track to the radius between TPC and TRD
+  // 2. propagate TRD track to the same radius between TPC and TRD
+  // 3. matches TPC and TRD tracks at the radius
+  // 4. propagate matched TPC and TRD track to the merging radius (first measured TPC point - x coordinate)
+  // 5. merge TPC and TRD track parameters at the merging radius 
+  // 6. create AliESDtrack from merged tracks
+  // 7. add AliESDtrack to AliESDEvent
+
+  if(!esdEvent) return kFALSE;
+
+  const Double_t kMaxStep     = 10.0;    // [cm] track propagation step
+  const Double_t kMatchRadius = 285.0;   // [cm] matching at radius between TPC and TRD
+  Double_t kMergeRadius = 0.0;
+  Bool_t isOk = kFALSE;
+  Bool_t isMatched = kFALSE;
+
+  Int_t nTracks = esdEvent->GetNumberOfTracks(); 
+  //HLTDebug("nTracks %d",nTracks);
+  HLTWarning("nTracks %d",nTracks);
+
+  for(Int_t iTrack = 0; iTrack<nTracks; ++iTrack) 
+  {
+    AliESDtrack *track = esdEvent->GetTrack(iTrack); 
+    if(!track) continue;
+
+    // TPC tracks
+    if((track->GetStatus()&AliESDtrack::kTPCin)==0) continue;
+    AliESDtrack *tpcTrack = track;
+
+    kMergeRadius = tpcTrack->GetTPCPoints(0); // [cm] merging at first measured TPC point
+
+    //HLTWarning("-------------------------------------------------------------------------------------");
+    //HLTWarning("-------------------------------------------------------------------------------------");
+
+    //HLTWarning("1-----tpc before matching: alpha %f, x %f, y, %f, z %f, snp %f, tgl %f, 1pt %f",tpcTrack->GetAlpha(),tpcTrack->GetX(),tpcTrack->GetY(),tpcTrack->GetZ(),tpcTrack->GetSnp(),tpcTrack->GetTgl(),tpcTrack->GetSigned1Pt());
+
+    // propagate tracks to the matching radius 
+    isOk = AliTracker::PropagateTrackTo(tpcTrack,kMatchRadius,tpcTrack->GetMass(),kMaxStep,kFALSE);
+    if(!isOk) continue;
+
+    //HLTWarning("2-----tpc before matching: alpha %f, x %f, y, %f, z %f, snp %f, tgl %f, 1pt %f",tpcTrack->GetAlpha(),tpcTrack->GetX(),tpcTrack->GetY(),tpcTrack->GetZ(),tpcTrack->GetSnp(),tpcTrack->GetTgl(),tpcTrack->GetSigned1Pt());
+
+    for(Int_t jTrack = 0; jTrack<nTracks; ++jTrack) 
+    {
+      AliESDtrack *track = esdEvent->GetTrack(jTrack); 
+      if(!track) continue;
+
+      // TRD tracks
+      if((track->GetStatus()&AliESDtrack::kTRDin)==0) continue;
+      AliESDtrack *trdTrack = track;
+
+      //HLTWarning("1-----trd before matching: alpha %f, x %f, y, %f, z %f, snp %f, tgl %f, 1pt %f",trdTrack->GetAlpha(),trdTrack->GetX(),trdTrack->GetY(),trdTrack->GetZ(),trdTrack->GetSnp(),trdTrack->GetTgl(),trdTrack->GetSigned1Pt());
+
+      isOk = AliTracker::PropagateTrackTo(trdTrack,kMatchRadius,trdTrack->GetMass(),kMaxStep,kFALSE);
+      if(!isOk) continue;
+
+      //HLTWarning("2-----trd before matching: alpha %f, x %f, y, %f, z %f, snp %f, tgl %f, 1pt %f",trdTrack->GetAlpha(),trdTrack->GetX(),trdTrack->GetY(),trdTrack->GetZ(),trdTrack->GetSnp(),trdTrack->GetTgl(),trdTrack->GetSigned1Pt());
+
+      // match TPC and TRD tracks
+      isMatched = MatchTracks(tpcTrack,trdTrack);
+      if(!isMatched) continue;
+
+      //HLTWarning("2-----tpc after matching: alpha %f, x %f, y, %f, z %f, snp %f, tgl %f, 1pt %f",tpcTrack->GetAlpha(),tpcTrack->GetX(),tpcTrack->GetY(),tpcTrack->GetZ(),tpcTrack->GetSnp(),tpcTrack->GetTgl(),tpcTrack->GetSigned1Pt());
+
+      //HLTWarning("2-----trd after matching: alpha %f, x %f, y, %f, z %f, snp %f, tgl %f, 1pt %f",trdTrack->GetAlpha(),trdTrack->GetX(),trdTrack->GetY(),trdTrack->GetZ(),trdTrack->GetSnp(),trdTrack->GetTgl(),trdTrack->GetSigned1Pt());
+
+      // propagate tracks to the merging radius 
+      isOk = AliTracker::PropagateTrackTo(tpcTrack,kMergeRadius,tpcTrack->GetMass(),kMaxStep,kFALSE);
+      if(!isOk) continue;
+
+      isOk = AliTracker::PropagateTrackTo(trdTrack,kMergeRadius,trdTrack->GetMass(),kMaxStep,kFALSE);
+      if(!isOk) continue;
+
+      //HLTWarning("3-----tpc before merging: alpha %f, x %f, y, %f, z %f, snp %f, tgl %f, 1pt %f",tpcTrack->GetAlpha(),tpcTrack->GetX(),tpcTrack->GetY(),tpcTrack->GetZ(),tpcTrack->GetSnp(),tpcTrack->GetTgl(),tpcTrack->GetSigned1Pt());
+
+      //HLTWarning("3-----trd before merging: alpha %f, x %f, y, %f, z %f, snp %f, tgl %f, 1pt %f",trdTrack->GetAlpha(),trdTrack->GetX(),trdTrack->GetY(),trdTrack->GetZ(),trdTrack->GetSnp(),trdTrack->GetTgl(),trdTrack->GetSigned1Pt());
+
+      // merge TPC and TRD tracks
+      // create AliESDtrack and add it to AliESDevent
+      Bool_t isMerged = MergeTracks(tpcTrack,trdTrack,esdEvent);
+      if(!isMerged) HLTWarning("No merged tracks");
+
+    }
+  }
+
+return kTRUE;
+}
+
+//_____________________________________________________________________________
+Bool_t AliHLTGlobalTrackMerger::MergeTracks(AliESDtrack *tpcTrack, AliESDtrack* trdTrack, AliESDEvent *esdEvent)
+{
+  // merge TPC and TRD track parameters
+  // create new AliESDtrack with TPC+TRD merged track parameters
+  // add AliESDtrack to AliESDEvent
+
+  if(!tpcTrack) return kFALSE;
+  if(!trdTrack) return kFALSE;
+
+  /*
+  Double_t tpcParam[5] = {tpcTrack->GetY(),tpcTrack->GetZ(),tpcTrack->GetSnp(),tpcTrack->GetTgl(),tpcTrack->GetSigned1Pt()};
+  Double_t trdParam[5] = {trdTrack->GetY(),trdTrack->GetZ(),trdTrack->GetSnp(),trdTrack->GetTgl(),trdTrack->GetSigned1Pt()};
+
+  const Double_t* tpcCv = tpcTrack->GetCovariance();
+  const Double_t* trdCv = trdTrack->GetCovariance();
+
+  Double_t tpcCovar[15] = {tpcCv[0],tpcCv[1],tpcCv[2],tpcCv[3],tpcCv[4],tpcCv[5],tpcCv[6],tpcCv[7],tpcCv[8],tpcCv[9],tpcCv[10],tpcCv[11],tpcCv[12],tpcCv[13], tpcCv[14] } ;
+
+  Double_t trdCovar[15] = {trdCv[0],trdCv[1],trdCv[2],trdCv[3],trdCv[4],trdCv[5],trdCv[6],trdCv[7],trdCv[8],trdCv[9],trdCv[10],trdCv[11],trdCv[12],trdCv[13], trdCv[14] } ;
+
+
+  Bool_t isNotOK = SmoothTracks(tpcParam, tpcCovar, tpcTrack->GetChi2(), 5,
+                                trdParam, trdCovar, trdTrack->GetChi2(), 5,
+                                trackParam, trackCovar, trackChi2, trackNDF,5);
+  */
+
+  Double_t trackParam[5], trackCovar[15]; 
+  Double_t trackChi2;
+  Int_t trackNDF;
+
+  // calculate merged track parameters
+  Bool_t isNotOK = SmoothTracks(tpcTrack->GetParameter(), tpcTrack->GetCovariance(), tpcTrack->GetTPCchi2(), 5,
+                                trdTrack->GetParameter(), trdTrack->GetCovariance(), trdTrack->GetTRDchi2(), 5,
+                                trackParam, trackCovar, trackChi2, trackNDF,5);
+
+  if(isNotOK) 
+      return kFALSE;
+
+  //
+  // create AliESDtrack
+  // merged TPC+TRD information
+  // 
+
+  AliESDtrack track;
+  //track.UpdateTrackParams(tpcTrack, AliESDtrack::kTPCrefit);
+  track.SetStatus(AliESDtrack::kGlobalMerge);
+  track.SetLabel(tpcTrack->GetLabel());
+  track.Set(tpcTrack->GetX(),tpcTrack->GetAlpha(),trackParam,trackCovar);
+  track.SetGlobalChi2(trackChi2);
+
+  //track.SetTPCLabel(tpcTrack->GetLabel());
+  Double32_t tpcPID[AliPID::kSPECIES];
+  tpcTrack->GetTPCpid(tpcPID);
+  track.SetTPCpid(tpcPID);
+  //fTPCncls=t->GetNumberOfClusters();  // no cluster on HLT
+  //fTPCchi2=t->GetChi2();
+
+  //track.SetTRDLabel(trdTrack->GetLabel());
+  Double32_t trdPID[AliPID::kSPECIES];
+  trdTrack->GetTRDpid(trdPID);
+  track.SetTRDpid(trdPID);
+  //fTRDchi2  = t->GetChi2();
+  //fTRDncls  = t->GetNumberOfClusters();
+  //for (Int_t i=0;i<6;i++) index[i]=t->GetTrackletIndex(i);
+
+  // add track to AliESDEvent
+  esdEvent->AddTrack(&track);
+
+return kTRUE;
+}
+
+//_____________________________________________________________________________
+void AliHLTGlobalTrackMerger::SetParameter(Double_t maxy, Double_t maxz, Double_t maxsnp, Double_t maxtgl, Double_t signed1Pt)
+{ 
+  //set parameters for merger
+  fMaxY = maxy;
+  fMaxZ = maxz;
+  fMaxSnp = maxsnp;
+  fMaxTgl = maxtgl;
+  fMaxSigned1Pt = signed1Pt;
+}
+
+//_____________________________________________________________________________
+Bool_t AliHLTGlobalTrackMerger::MatchTracks(AliESDtrack *trackTPC, AliESDtrack *trackTRD)
+{ 
+  // match TPC and TRD tracks 
+  // return kTRUE in case of matching
+  if(!trackTPC) return kFALSE;
+  if(!trackTRD) return kFALSE;
+
+  if (TMath::Abs(trackTPC->GetY()-trackTRD->GetY()) > fMaxY) return kFALSE;
+  if (TMath::Abs(trackTPC->GetZ()-trackTRD->GetZ()) > fMaxZ) return kFALSE;
+  if (TMath::Abs(trackTPC->GetSnp()-trackTRD->GetSnp()) > fMaxSnp) return kFALSE;
+  if (TMath::Abs(trackTPC->GetTgl()-trackTRD->GetTgl()) > fMaxTgl) return kFALSE;
+  if (TMath::Abs(trackTPC->GetSigned1Pt()-trackTRD->GetSigned1Pt()) > fMaxSigned1Pt) return kFALSE;
+
+return kTRUE;
+}
+
+//_____________________________________________________________________________
+Bool_t AliHLTGlobalTrackMerger::SmoothTracks( const Double_t T1[], const Double_t C1[], Double_t Chi21, Int_t NDF1,
+                                   const  Double_t T2[], const Double_t C2[], Double_t Chi22, Int_t NDF2,
+                                    Double_t T [], Double_t C [], Double_t &Chi2, Int_t &NDF,
+                                    Int_t N  )
+{
+  //* Smooth two tracks with parameter vectors of size N
+  //*
+  //* Input:
+  //*
+  //* T1[N], T2[N] - tracks
+  //* C1[N*(N+1)/2], C2[N*(N+1)/2] - covariance matrices in low-diagonal form:
+  //* C = { c00, 
+  //*       c10, c11, 
+  //*       c20, c21, c22, 
+  //*       ...             };
+  //* Chi2{1,2}, NDF{1,2} - \Chi^2 and "Number of Degrees of Freedom" values for both tracks
+  //* Output: 
+  //*
+  //* T[N], C[N] ( can be aqual to {T1,C1}, or {T2,C2} )
+  //* Chi2, NDF
+  //*
+  //* returns error flag (0 means OK, 1 not OK )
+    
+  Int_t M = N*(N+1)/2;
+  
+  Double_t A[M];
+  Double_t K[N*N];
+  
+  for(Int_t k=0; k<M; k++) A[k] = C1[k] + C2[k]; 
+  Bool_t err = InvertS(A,N);
+  if( err ) return 1;
+
+  Chi2 = Chi21 + Chi22;
+  NDF = NDF1 + NDF2;
+  
+  MultSSQ( C1, A, K, N);       
+  Double_t r[N];
+  for( Int_t k=0; k<N;k++) r[k] = T1[k] - T2[k]; 
+  for( Int_t k=0; k<N;k++ )
+    for( Int_t l=0;l<N;l++) T[k] = T1[k] - K[k*N+l]*r[l];
+
+  for( Int_t ind=0,i=0; i<N; i++ ){
+    for( Int_t j=0; j<i; j++ ) Chi2+= 2*r[i]*r[j]*A[ind++];
+    Chi2+= r[i]*r[i]*A[ind++];
+  }
+  NDF+=N;
+
+  for( Int_t l=0; l<N; l++ ) K[ (N+1)*l ] -= 1;
+  
+  for( Int_t ind = 0, l=0; l<N; ++l ){
+    for( Int_t j=0; j<=l; ++j, ind++ ){
+      A[ind] = 0;
+      for( Int_t k=0; k<N; ++k ) A[ind] -= K[l*N+k] * C1[IndexS(j,k)];
+    }
+  }
+  for( Int_t l=0; l<N; l++ ) C[l] = A[l];
+  return 0;
+}
+
+//_____________________________________________________________________________
+void AliHLTGlobalTrackMerger::MultSSQ( const Double_t *A, const Double_t *B, Double_t *C, Int_t N )
+{
+  for( Int_t ind=0, i=0; i<N; ++i ){
+    for( Int_t j=0; j<N; ++j, ++ind ){
+      C[ind] = 0;
+      for( Int_t k=0; k<N; ++k ) C[ind] += A[IndexS(i,k)] * B[IndexS(k,j)];
+    }
+  }
+}
+
+//_____________________________________________________________________________
+Bool_t AliHLTGlobalTrackMerger::InvertS( Double_t A[], Int_t N )
+{
+  //* input: simmetric > 0 NxN matrix A = {a11,a21,a22,a31..a33,..}  
+  //* output: inverse A, in case of problems fill zero and return 1
+  //*  
+  //* A->low triangular Anew : A = Anew x Anew^T
+  //* method:
+  //* for(j=1,N) for(i=j,N) Aij=(Aii-sum_{k=1}^{j-1}Aik*Ajk )/Ajj
+  //*   
+
+  Bool_t ret = 0;
+  
+  const Double_t ZERO = 1.E-20;
+    
+  {
+    Double_t *j1 = A, *jj = A;
+    for( Int_t j=1; j<=N; j1+=j++, jj+=j ){
+      Double_t *ik = j1, x = 0;
+      while( ik!=jj ){
+       x -= (*ik) * (*ik);
+       ik++;
+      }
+      x += *ik;
+      if( x > ZERO ){
+       x = sqrt(x);
+       *ik = x;
+       ik++;
+       x = 1 / x;
+       for( Int_t step=1; step<=N-j; ik+=++step ){ // ik==Ai1
+         Double_t sum = 0;
+         for( Double_t *jk=j1; jk!=jj; sum += *(jk++) * *(ik++) );
+         *ik = (*ik - sum) * x; // ik == Aij
+       }
+      }else{
+       Double_t *ji=jj;
+       for( Int_t i=j; i<N; i++ ) *(ji+=i) = 0.;
+       ret = 1;
+      }   
+    }
+  }
+  
+  //* A -> Ainv
+  //* method : 
+  //* for(i=1,N){ 
+  //*   Aii = 1/Aii; 
+  //*   for(j=1,i-1) Aij=-(sum_{k=j}^{i-1} Aik * Akj) / Aii ;
+  //* }
+  
+  {
+    Double_t *ii=A,*ij=A;
+    for( Int_t i = 1; i<=N; ij=ii+1, ii+=++i ){
+      if( *ii > ZERO ){
+       Double_t x = -(*ii = 1./ *ii);
+       { 
+         Double_t *jj = A;
+         for( Int_t j=1; j<i; jj+=++j, ij++ ){
+           Double_t *ik = ij, *kj = jj, sum = 0.;
+           for( Int_t k=j; ik!=ii; kj+=k++, ik++ ){
+             sum += *ik * *kj;
+           }
+           *kj = sum * x;
+         }
+       }
+      }else{      
+       for( Double_t *ik = ij; ik!=ii+1; ik++ ){
+         *ik = 0.;
+       }
+       ret = 1;
+      }
+    }
+  }
+  
+  //* A -> A^T x A
+  //* method: 
+  //* Aij = sum_{k=i}^N Aki * Akj
+  
+  {
+    Double_t *ii=A, *ij=A;
+    for( Int_t i=1; i<=N; ii+=++i ){
+      do{ 
+       Double_t *ki = ii, *kj = ij, sum = 0.;
+       for( Int_t k=i; k<=N; ki+=k, kj+=k++ ) sum += (*ki) * (*kj);
+       *ij = sum;
+      }while( (ij++)!=ii );
+    }    
+  }
+  return ret;    
+}
+
+//_____________________________________________________________________________
+void  AliHLTGlobalTrackMerger::PropagateTracksToDCA(AliESDEvent *esdEvent)
+{
+  // try to propagate all tracks to DCA to primary vertex
+  if(!esdEvent) return;
+
+  const Double_t kBz = esdEvent->GetMagneticField();
+  const Double_t kSmallRadius  = 2.8; // [cm] something less than the beam pipe radius
+  const Double_t kMaxStep  = 10.0;    // [cm] track propagation step
+  Bool_t isOK = kFALSE;
+
+  Int_t nTracks = esdEvent->GetNumberOfTracks(); 
+  for(Int_t iTrack = 0; iTrack<nTracks; ++iTrack) {
+    AliESDtrack *track = esdEvent->GetTrack(iTrack); 
+    if(!track) continue;
+
+    //HLTWarning("1-------: alpha %f, x %f, y, %f, z %f, snp %f, tgl %f, 1pt %f",track->GetAlpha(),track->GetX(),track->GetY(),track->GetZ(),track->GetSnp(),track->GetTgl(),track->GetSigned1Pt());
+
+    // propagate to small radius (material budget included)
+    isOK = AliTracker::PropagateTrackTo(track,kSmallRadius,track->GetMass(),kMaxStep,kFALSE);
+
+    //HLTWarning("2-------: alpha %f, x %f, y, %f, z %f, snp %f, tgl %f, 1pt %f",track->GetAlpha(),track->GetX(),track->GetY(),track->GetZ(),track->GetSnp(),track->GetTgl(),track->GetSigned1Pt());
+     
+    // relate tracks to DCA to primary vertex
+    if(isOK) 
+    {
+      track->RelateToVertex(fVertex, kBz, kVeryBig);
+     // HLTWarning("3-------: alpha %f, x %f, y, %f, z %f, snp %f, tgl %f, 1pt %f",track->GetAlpha(),track->GetX(),track->GetY(),track->GetZ(),track->GetSnp(),track->GetTgl(),track->GetSigned1Pt());
+    }
+  }
+}
diff --git a/HLT/global/AliHLTGlobalTrackMerger.h b/HLT/global/AliHLTGlobalTrackMerger.h
new file mode 100644 (file)
index 0000000..5a941b5
--- /dev/null
@@ -0,0 +1,102 @@
+// $Id$
+#ifndef ALIHLTGLOBALTRACKMERGER_H
+#define ALIHLTGLOBALTRACKMERGER_H
+//* This file is property of and copyright by the ALICE HLT Project        * 
+//* ALICE Experiment at CERN, All rights reserved.                         *
+//* See cxx source for full Copyright notice                               *
+
+/** @file   AliHLTGlobalTrackMerger.h
+    @author Jacek Otwinowski (Jacek.Otwinowski@gsi.de)
+    @date   
+    @brief  The HLT TPC merger base class
+*/
+
+
+class AliHLTTPCTrack;
+class AliHLTTPCTrackSegmentData;
+class AliHLTTPCVertex;
+class AliHLTTPCTrackArray;
+class AliTRDtrackV1;
+class AliESDEvent;
+class AliESDVertex;
+class AliExternalTrackParam;
+
+class TClonesArray;
+
+#include "AliHLTLogging.h"
+#include "AliESDtrack.h"
+
+/** 
+ * @class AliHLTGlobalTrackMerger
+ * Global track merger for the barrel section.
+ *
+ * @ingroup alihlt_global
+ * @author Jacek.Otwinowski@gsi.de
+ */
+class AliHLTGlobalTrackMerger : public AliHLTLogging {
+public:
+  AliHLTGlobalTrackMerger();
+  /** destructor */
+  virtual ~AliHLTGlobalTrackMerger();
+
+  // load tracks
+  Bool_t LoadTracks(TClonesArray *aTRDTracks,AliESDEvent *esdEvent=0);
+  Bool_t LoadTracks(AliHLTTPCTrackArray *aTPCTracks,AliESDEvent *esdEvent=0);
+
+  // set matching parameters
+  void SetParameter(Double_t maxy=1., Double_t maxz=1., Double_t maxsnp=0.05, Double_t maxtgl=0.1, Double_t signed1Pt=0.001);
+
+  // match tracks
+  Bool_t MatchTracks(AliESDtrack *extTPC=0, AliESDtrack *extTPC=0);
+
+  // merge tracks
+  Bool_t Merge(AliESDEvent *esdEvent=0);
+  Bool_t MergeTracks(AliESDtrack *extTPC=0, AliESDtrack *extTRD=0, AliESDEvent *esdEvent=0);
+
+  // create AliESDtrack objects
+  void FillTPCESD(AliHLTTPCTrack* tpcTrack=0, ULong_t flags=AliESDtrack::kTPCin, AliESDEvent* esdEvent=0); 
+  void FillTRDESD(AliTRDtrackV1*  trdTrack=0, ULong_t flags=AliESDtrack::kTRDin, AliESDEvent* esdEvent=0);
+
+  // propagate tracks to DCA to primary vertex
+  void PropagateTracksToDCA(AliESDEvent *esdEvent=0);
+
+  // Smooth track parameters 
+  // (origin Sergey Gorbunov)
+  /*
+  Bool_t SmoothTracks( Double_t T1[], Double_t C1[], Double_t Chi21, Int_t NDF1,
+                      Double_t T2[], Double_t C2[], Double_t Chi22, Int_t NDF2,
+                      Double_t T [], Double_t C [], Double_t &Chi2, Int_t &NDF,
+                      Int_t N );
+  */
+  Bool_t SmoothTracks( const Double_t T1[], const Double_t C1[], Double_t Chi21, Int_t NDF1,
+                      const Double_t T2[], const Double_t C2[], Double_t Chi22, Int_t NDF2,
+                      Double_t T [], Double_t C [], Double_t &Chi2, Int_t &NDF,
+                      Int_t N );
+  Int_t IndexS(Int_t i, Int_t j) {
+     return ( j<=i ) ? i*(i+1)/2+j :j*(j+1)/2+i;
+  }
+  void MultSSQ( const Double_t *A, const Double_t *B, Double_t *C, Int_t N );
+  Bool_t InvertS( Double_t A[], Int_t N );  
+
+private:
+
+  // TRD-TPC matching parameters
+  Double_t fMaxY;    //! max Y track (cm)
+  Double_t fMaxZ;    //! max Z track (cm)
+  Double_t fMaxSnp;  //! max local sine of the track momentum azimuthal angle
+  Double_t fMaxTgl;  //! max tangent of the track momentum dip angle
+  Double_t fMaxSigned1Pt; //! max 1/pt (1/(GeV/c)) 
+
+  // primary vertex
+  AliESDVertex *fVertex; //! event vertex (needed to propagate all tracks to DCA) 
+  
+  /** copy constructor prohibited */
+  AliHLTGlobalTrackMerger(const AliHLTGlobalTrackMerger&);
+  /** assignment operator prohibited */
+  AliHLTGlobalTrackMerger& operator=(const AliHLTGlobalTrackMerger&);
+
+  ClassDef(AliHLTGlobalTrackMerger,1) //Merging base class
+};
+
+#endif
diff --git a/HLT/global/AliHLTGlobalTrackMergerComponent.cxx b/HLT/global/AliHLTGlobalTrackMergerComponent.cxx
new file mode 100644 (file)
index 0000000..e240111
--- /dev/null
@@ -0,0 +1,271 @@
+// $Id$
+
+//**************************************************************************
+//* This file is property of and copyright by the ALICE HLT Project        * 
+//* ALICE Experiment at CERN, All rights reserved.                         *
+//*                                                                        *
+//* Primary Authors: Jacek Otwinowski <Jacek.Otwinowski@gsi.de>            *
+//*                  for The ALICE HLT Project.                            *
+//*                                                                        *
+//* 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.                  *
+//**************************************************************************
+
+/** @file   AliHLTGlobalTrackMergerComponent.cxx
+    @author Jacek Otwinowski
+    @date   
+    @brief  HLT global track merger component.
+*/
+
+using namespace std;
+#include <climits>
+#include <cassert>
+#include "AliHLTTPCTransform.h"
+#include "AliHLTTPCGlobalMerger.h"
+#include "AliHLTTPCVertex.h"
+#include "AliHLTTPCVertexData.h"
+#include "AliHLTTPCTrack.h"
+
+//#include "AliHLTTPCSpacePointData.h"
+//#include "AliHLTTPCClusterDataFormat.h"
+#include "AliHLTTPCTrackletDataFormat.h"
+#include "AliHLTTPCTrackSegmentData.h"
+#include "AliHLTTPCTrackArray.h"
+#include "AliHLTTPCDefinitions.h"
+#include "AliHLTTRDDefinitions.h"
+#include <cstdlib>
+#include <cerrno>
+
+#include "AliESDEvent.h"
+#include "AliTracker.h"
+#include "AliTRDtrackV1.h"
+#include "AliHLTGlobalTrackMerger.h"
+
+#include "AliHLTGlobalTrackMergerComponent.h"
+
+/** ROOT macro for the implementation of ROOT specific class methods */
+ClassImp(AliHLTGlobalTrackMergerComponent);
+
+//_____________________________________________________________________________
+AliHLTGlobalTrackMergerComponent::AliHLTGlobalTrackMergerComponent() : AliHLTProcessor(), 
+  fGlobalTrackMerger(0), 
+  fESD(0)
+{
+}
+
+//_____________________________________________________________________________
+AliHLTGlobalTrackMergerComponent::~AliHLTGlobalTrackMergerComponent()
+{
+  // see header file for class documentation
+}
+
+//_____________________________________________________________________________
+const char* AliHLTGlobalTrackMergerComponent::GetComponentID()
+{
+  // see header file for class documentation
+  return "GlobalTrackMerger";
+}
+
+//_____________________________________________________________________________
+void AliHLTGlobalTrackMergerComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
+{
+  // see header file for class documentation
+  list.clear();
+  list.push_back( AliHLTTPCDefinitions::fgkTracksDataType );
+  list.push_back( AliHLTTRDDefinitions::fgkTRDSATracksDataType );
+}
+
+//_____________________________________________________________________________
+AliHLTComponentDataType AliHLTGlobalTrackMergerComponent::GetOutputDataType()
+{
+  // see header file for class documentation
+  return kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC;
+}
+
+//_____________________________________________________________________________
+void AliHLTGlobalTrackMergerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
+{
+  // see header file for class documentation
+  // XXX TODO: Find more realistic values.
+  constBase = 20000;
+  inputMultiplier = 1.0;
+}
+
+//_____________________________________________________________________________
+AliHLTComponent* AliHLTGlobalTrackMergerComponent::Spawn()
+{
+  // see header file for class documentation
+  return new AliHLTGlobalTrackMergerComponent;
+}
+
+//_____________________________________________________________________________
+void AliHLTGlobalTrackMergerComponent::SetMergerParameters(Double_t maxy,Double_t maxz,Double_t maxkappa,Double_t maxpsi,Double_t maxtgl)
+{
+  // see header file for class documentation
+  fGlobalTrackMerger->SetParameter( maxy, maxz, maxkappa, maxpsi, maxtgl );
+}
+
+//_____________________________________________________________________________
+int AliHLTGlobalTrackMergerComponent::DoInit( int /*argc*/, const char** /*argv*/ )
+{
+  // see header file for class documentation
+  int iResult = 0;
+  
+  // Init merger
+  fGlobalTrackMerger = new AliHLTGlobalTrackMerger();
+  
+  // output of the component
+  fESD = new AliESDEvent();
+  if (fESD) {
+     fESD->CreateStdContent();
+  }
+
+  if (!fGlobalTrackMerger || !fESD ) {
+     HLTError("failed creating internal objects");
+     iResult=-ENOMEM;
+     return iResult;
+  }
+
+  SetMergerParameters();
+
+  return iResult;
+}
+
+//_____________________________________________________________________________
+int AliHLTGlobalTrackMergerComponent::DoDeinit()
+{
+  // see header file for class documentation
+  if(fGlobalTrackMerger) delete fGlobalTrackMerger; fGlobalTrackMerger =0;
+  if(fESD) delete fESD; fESD = 0;
+  return 0;
+}
+
+//_____________________________________________________________________________
+int AliHLTGlobalTrackMergerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
+                                             AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* /*outputPtr*/, 
+                                             AliHLTUInt32_t& /*size*/, AliHLTComponentBlockDataList& /*outputBlocks*/ )
+{
+  //
+  // global track merger function
+  // takes TRD and TPC tracks and merges them
+  //
+  HLTInfo("DoEvent processing data");
+
+  // see header file for class documentation
+  int iResult=0;
+
+  if(!fGlobalTrackMerger || !fESD) {
+    HLTError("component not initialized");
+    iResult=-ENOMEM;
+    return iResult;
+  }
+
+  if(!blocks) {
+    HLTError("no blocks");
+    iResult=-EINVAL;
+    return iResult;
+  }
+
+  const AliHLTComponentBlockData* iter=0;
+  AliHLTTPCTrackletData* inPtr=0;
+  Bool_t bIsTRDTrackDataBlock=kFALSE;
+  Bool_t bIsTPCTrackDataBlock=kFALSE;
+  TClonesArray *aTRDTracks=0;
+  Int_t minSlice = INT_MAX, maxSlice = 0;
+  Int_t slice;
+
+  unsigned long ndx;
+  for ( ndx = 0; ndx < evtData.fBlockCnt && iResult>=0; ndx++ )
+  {
+      iter = blocks+ndx;
+      bIsTRDTrackDataBlock=kFALSE;
+      bIsTPCTrackDataBlock=kFALSE;
+
+      // check if TPC or TRD tracks
+      if(!(bIsTRDTrackDataBlock=(iter->fDataType==AliHLTTRDDefinitions::fgkTRDSATracksDataType)) &&
+         !(bIsTPCTrackDataBlock=(iter->fDataType==AliHLTTPCDefinitions::fgkTracksDataType))) {
+       continue;
+      }
+
+      // collect TRD tracks from all SM
+      // one TClonesArray of tracks per SM
+      if(bIsTRDTrackDataBlock) 
+      {
+        for (TObject *pObj = (TObject *)GetFirstInputObject(AliHLTTRDDefinitions::fgkTRDSATracksDataType,"TClonesArray",0);
+         pObj !=0 && iResult>=0;
+         pObj = (TObject *)GetNextInputObject(0)) {
+          aTRDTracks = dynamic_cast<TClonesArray*>(pObj);
+          if (!aTRDTracks) continue;
+
+          HLTDebug("reading block %d, trdTracks %d", ndx, aTRDTracks->GetEntriesFast());
+
+         // load TRD tracks by global track merger 
+         if (fGlobalTrackMerger->LoadTracks(aTRDTracks,fESD) == kFALSE) {
+             HLTError("Cannot load TRD tracks");
+             iResult=-ENOMEM;
+             return iResult;
+         }
+       }
+       aTRDTracks->Delete();
+      } 
+      
+      // collect TPC tracks from whole TPC
+      if (bIsTPCTrackDataBlock) 
+      {
+        slice=AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
+       if(slice<minSlice) minSlice = slice;
+       if(slice>maxSlice) maxSlice = slice;
+       
+        //minslice=AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
+        //maxslice=AliHLTTPCDefinitions::GetMaxSliceNr(iter->fSpecification);
+
+        AliHLTTPCTrackArray tracks;
+        inPtr=(AliHLTTPCTrackletData*)iter->fPtr;
+
+        HLTDebug("reading block %d (slice %d): %d tracklets", ndx, slice, inPtr->fTrackletCnt);
+
+        // read TPC track segments from memory
+        if((iResult=tracks.FillTracksChecked(inPtr->fTracklets, inPtr->fTrackletCnt, iter->fSize, -1/*global track*/, 0/*don't rotate*/))>=0) {
+
+          // load TPC tracks by  global track merger
+          if (fGlobalTrackMerger->LoadTracks(&tracks,fESD) == kFALSE) {
+             HLTError("Cannot load TPC tracks");
+             iResult=-ENOMEM;
+             return iResult;
+         }
+       }
+     }
+   }
+
+   // set magnetic field 
+   fESD->SetMagneticField(AliTracker::GetBz());
+
+   // merge tracks
+   Bool_t isMerged = fGlobalTrackMerger->Merge(fESD);
+   if(!isMerged) {
+     HLTWarning("No merged tracks");
+   }
+
+   // try to propagate all tracks to DCA to primary vertex
+   fGlobalTrackMerger->PropagateTracksToDCA(fESD);
+
+   // calculate specification
+   // AliHLTUInt32_t iSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( minSlice, maxSlice, 0, 5 );
+   // HLTInfo("minSlice %d, maxSlice %d", minSlice, maxSlice);
+
+   // send output data
+   //PushBack(fESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC, iSpecification);
+   PushBack(fESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC);
+
+   // reset fESD
+   fESD->Reset();
+  
+return iResult;
+}
+
+       
diff --git a/HLT/global/AliHLTGlobalTrackMergerComponent.h b/HLT/global/AliHLTGlobalTrackMergerComponent.h
new file mode 100644 (file)
index 0000000..6376151
--- /dev/null
@@ -0,0 +1,90 @@
+// $Id$
+#ifndef ALIHLTGLOBALTRACKMERGERCOMPONENT_H
+#define ALIHLTGLOBALTRACKMERGERCOMPONENT_H
+//* This file is property of and copyright by the ALICE HLT Project        * 
+//* ALICE Experiment at CERN, All rights reserved.                         *
+//* See cxx source for full Copyright notice                               *
+
+/** @file   AliHLTGlobalTrackMergerComponent.h
+    @author Jacek Otwinowski
+    @date   
+    @brief  HLT global track merger component.
+*/
+
+#include "AliHLTProcessor.h"
+
+class AliESDEvent;
+class AliHLTGlobalTrackMerger;
+
+/**
+ * @class AliHLTGlobalTrackMergerComponent
+ * The global track merger component
+ *
+ * @ingroup alihlt_global_components
+ * @author Jacek.Otwinowski@gsi.de
+ */
+class AliHLTGlobalTrackMergerComponent : public AliHLTProcessor
+    {
+    public:
+      /** standard constructor */
+      AliHLTGlobalTrackMergerComponent();
+      /** standard destructor */
+      virtual ~AliHLTGlobalTrackMergerComponent();
+
+       // Public functions to implement AliHLTComponent's interface.
+       // These functions are required for the registration process
+
+      /** @see component interface AliHLTComponent::GetComponentID */
+       const char* GetComponentID();
+      
+      /** @see component interface AliHLTComponent::GetInputDataTypes */
+       void GetInputDataTypes(AliHLTComponentDataTypeList& list);
+
+      /** @see component interface AliHLTComponent::GetOutputDataType */
+       AliHLTComponentDataType GetOutputDataType();
+
+      /** @see component interface AliHLTComponent::GetOutputDataSize */
+       virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier );
+
+      /** @see component interface AliHLTComponent::Spawn */
+       AliHLTComponent* Spawn();
+
+    protected:
+       
+       /**
+       * Set the parameters
+       */
+       void SetMergerParameters(Double_t maxy=2.0,Double_t maxz=3.0,
+                                Double_t maxsnp=0.1,Double_t maxtgl=0.05, Double_t signed1Pt=0.003);
+
+       // Protected functions to implement AliHLTComponent's interface.
+       // These functions provide initialization as well as the actual processing
+       // capabilities of the component. 
+
+
+      /** @see component interface AliHLTComponent::DoInit */
+       int DoInit( int argc, const char** argv );
+
+      /** @see component interface AliHLTComponent::DoDeinit */
+       int DoDeinit();
+
+      /** @see component interface @ref AliHLTProcessor::DoEvent */
+       int DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
+                    AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, 
+                    AliHLTUInt32_t& size, AliHLTComponentBlockDataList& outputBlocks );
+
+       using AliHLTProcessor::DoEvent;
+       
+    private:
+      /** copy constructor prohibited */
+      AliHLTGlobalTrackMergerComponent(const AliHLTGlobalTrackMergerComponent&);
+      /** assignment operator prohibited */
+      AliHLTGlobalTrackMergerComponent& operator=(const AliHLTGlobalTrackMergerComponent&);
+
+      AliHLTGlobalTrackMerger *fGlobalTrackMerger;  //! global track merger
+      AliESDEvent *fESD;                            //! AliESDEvent output from merger
+
+      ClassDef(AliHLTGlobalTrackMergerComponent, 0)
+
+    };
+#endif
diff --git a/HLT/global/Makefile.am b/HLT/global/Makefile.am
new file mode 100644 (file)
index 0000000..722be46
--- /dev/null
@@ -0,0 +1,66 @@
+# $Id$
+# Makefile template for the Alice HLT global library
+
+MODULE                                 = AliHLTGlobal
+
+EXTRA_DIST                     =
+
+# library definition
+lib_LTLIBRARIES                        = libAliHLTGlobal.la
+
+# version info for the library
+LIBRARY_VERSION                        = '0:0:0'
+
+# MODDIR is set by the AliRoot build system and denotes the topdir
+# of the module, we must set it since the package definition libAliHLTGlobal.pkg
+# includes another common configuration file
+MODDIR                         = $(top_srcdir)
+PKGDEF                         = $(MODDIR)/libAliHLTGlobal.pkg
+include $(top_srcdir)/libAliHLTGlobal.pkg
+
+# compiler flags
+AM_CPPFLAGS                    = -DMODULE=$(MODULE) \
+                                 $(PACKCXXFLAGS) \
+                                 $(foreach i, $(EINCLUDE),  \
+                                       $(shell echo $(i) | sed -e "/HLT\//!d" -e "s|HLT/|-I$(top_srcdir)/|")) \
+                                 $(foreach i, $(EINCLUDE),  \
+                                       $(shell echo $(i) | sed -e "/HLT\//d" -e "s|^|-I$(ALICE_ROOT)/|"))
+# library sources
+libAliHLTGlobal_la_SOURCES     = $(MODULE_SRCS)
+
+# library headers
+pkginclude_HEADERS             = $(MODULE_HDRS)
+
+# additional link def file
+EXTRA_DIST                     +=$(MODULE_DHDR)
+
+libAliHLTGlobal_la_LIBADD      =
+# version info for the library
+libAliHLTGlobal_la_LDFLAGS     = -L@ROOTLIBDIR@ \
+                                 @ROOTLIBS@ \
+                                 @HLTBASE_LDFLAGS@ \
+                                 @ALIROOT_LDFLAGS@ \
+                                 @ALIROOT_LIBS@ \
+                                 @ALIGLOBAL_LIBS@ \
+                                 -version-info  $(LIBRARY_VERSION)
+
+# automatic generation of data and time of library build
+COMPILE_INFO                   =  AliHLTGlobalCompileInfo.cxx
+
+# set the file name for the generated root dictionary
+DICTCPP                                =  AliHLTGlobal-DICT.cxx
+nodist_libAliHLTGlobal_la_SOURCES  =  $(COMPILE_INFO) \
+                                  $(DICTCPP)
+
+CLEANFILES                     = $(COMPILE_INFO)
+
+include $(top_srcdir)/make.dict
+
+SUBDIRS                        = . 
+
+$(COMPILE_INFO): $(libAliHLTGlobal_la_SOURCES) $(pkginclude_HEADERS) $(noinst_HEADERS) Makefile.am
+       @echo '//automatically generated compilation info' > $@
+       @echo '//!!! DO NOT EDIT THIS FILE !!!' >> $@
+       @echo '//add changes in Makefile.am' >> $@
+       @echo 'extern "C" void CompileInfo(const char*& date, const char*& time)' >> $@
+       @echo '{date=__DATE__; time=__TIME__; return;}' >> $@
diff --git a/HLT/global/macros/rec-hlt-global-merger.C b/HLT/global/macros/rec-hlt-global-merger.C
new file mode 100644 (file)
index 0000000..a1dc659
--- /dev/null
@@ -0,0 +1,197 @@
+// $Id$
+/*
+ * Example macro to run the HLT global track merger embedded
+ * into AliRoot reconstruction. The reconstruction is done from the raw data.
+ *
+ * Usage:
+ * <pre>
+ *   aliroot -b -q rec-hlt-global-merger.C | tee rec-hlt-global-merger.log
+ * </pre>
+ *
+ * The chain to be run is defined by the macro given to the parameter
+ * 'config='
+ *
+ * The macro asumes raw data to be available in the rawx folders, either
+ * simulated or real data. A different input can be specified as parameter
+ * <pre>
+ *   aliroot -b -q rec-hlt-global-merger.C'("input.root")'
+ * </pre>
+ *
+ * By the second parameter the digit reader can be chosen, default is
+ * AliHLTTPCDigitReaderPacked (=false). Set to true to use
+ * AliHLTTPCDigitReaderDecoder
+ *
+ * In the first section, an analysis chain is defined. The scale of the
+ * chain can be defined by choosing the range of sectors and partitions.
+ *
+ * The reconstruction is steered by the AliReconstruction object in the
+ * usual way.
+ *
+ * @ingroup alihlt_global
+ * @author 
+ */
+void rec_hlt_global_merger(const char* input="./", bool bUseClusterFinderDecoder=true)
+{
+  if (!input) {
+    cerr << "please specify input or run without arguments" << endl;
+    return;
+  }
+
+  gSystem->Exec("rm galice.root");
+
+  ///////////////////////////////////////////////////////////////////////////////////////////////////
+  //
+  // init the HLT system in order to define the analysis chain below
+  //
+  gSystem->Load("libHLTrec.so");
+  AliHLTSystem* gHLT=AliHLTReconstructorBase::GetInstance();
+  //gHLT->SetGlobalLoggingLevel(0x0); 
+  /*  enum AliHLTComponentLogSeverity {       
+      kHLTLogNone      = 0,
+      kHLTLogBenchmark = 0x1,
+      kHLTLogDebug     = 0x2,
+      kHLTLogInfo      = 0x4,
+      kHLTLogWarning   = 0x8,
+      kHLTLogError     = 0x10,
+      kHLTLogFatal     = 0x20,      
+      few important messages not to be filtered out.
+      redirected to kHLTLogInfo in AliRoot
+      kHLTLogImportant = 0x40,
+      special value to enable all messages 
+      kHLTLogAll       = 0x7f,
+      the default logging filter 
+      kHLTLogDefault   = 0x79
+      useful           = 0x45
+  */
+
+  //gHLT->LoadComponentLibraries("libAliHLTUtil.so libAliHLTRCU.so libAliHLTTRD.so libAliHLTTPC.so libAliHLTGlobal.so");
+
+  ///////////////////////////////////////////////////////////////////////////////////////////////////
+  //
+  // define the analysis chain to be run
+  //
+
+  //  Global merger
+  TString globalmergerInput;
+
+  // TPC
+  int iMinSlice=0;
+  //int iMaxSlice=35;
+  int iMaxSlice=17;
+  int iMinPart=0;
+  int iMaxPart=5;
+
+  TString writerInput;
+  TString mergerInput;
+  for (int slice=iMinSlice; slice<=iMaxSlice; slice++) {
+    TString trackerInput;
+    for (int part=iMinPart; part<=iMaxPart; part++) {
+      TString arg, publisher, cf;
+
+      // raw data publisher components
+      int ddlno=768;
+      if (part>1) ddlno+=72+4*slice+(part-2);
+      else ddlno+=2*slice+part;
+      arg.Form("-minid %d -datatype 'DDL_RAW ' 'TPC '  -dataspec 0x%02x%02x%02x%02x -verbose", ddlno, slice, slice, part, part);
+      publisher.Form("DP_%02d_%d", slice, part);
+      AliHLTConfiguration pubconf(publisher.Data(), "AliRawReaderPublisher", NULL , arg.Data());
+
+      // cluster finder components
+      cf.Form("CF_%02d_%d",slice,part);
+      if (bUseClusterFinderDecoder) {
+       AliHLTConfiguration cfconf(cf.Data(), "TPCClusterFinderDecoder", publisher.Data(), "-timebins 446");
+      } else {
+       AliHLTConfiguration cfconf(cf.Data(), "TPCClusterFinderPacked", publisher.Data(), "-timebins 446 -sorted");
+      }
+      if (trackerInput.Length()>0) trackerInput+=" ";
+      trackerInput+=cf;
+      if (writerInput.Length()>0) writerInput+=" ";
+      writerInput+=cf;
+    }
+    TString tracker;
+    // tracker finder components
+    tracker.Form("TR_%02d",slice);
+    AliHLTConfiguration trackerconf(tracker.Data(), "TPCCATracker", trackerInput.Data(), "-solenoidBz 5");
+    if (writerInput.Length()>0) writerInput+=" ";
+    writerInput+=tracker;
+    if (mergerInput.Length()>0) mergerInput+=" ";
+    mergerInput+=tracker;
+  }
+  // TPC GlobalMerger component
+  AliHLTConfiguration mergerconf("globalmerger","TPCGlobalMerger",mergerInput.Data(),"");
+
+  //
+  // TRD
+  //
+  int iMinSlice=0;
+  //int iMaxSlice=17;
+  int iMaxSlice=8;
+
+  TString writerInput1;
+  TString mergerInput1;
+  for (int slice=iMinSlice; slice<=iMaxSlice; slice++) {
+    //TString trackerInput1;
+    TString arg1, publisher1, cf1;
+
+    // raw data publisher components
+    int ddlno=1024;
+    ddlno += slice;
+
+    arg1.Form("-minid %d -datatype 'DDL_RAW ' 'TRD ' -verbose", ddlno);
+    publisher1.Form("DP1_%02d", slice);
+    AliHLTConfiguration pubconf(publisher1.Data(), "AliRawReaderPublisher", NULL , arg1.Data());
+
+    //arg1.Form("-datatype 'DDL_RAW ' 'TRD ' -datafile raw0/TRD_%d.ddl", ddlno);
+    //publisher1.Form("DP1_%02d",slice);
+    //AliHLTConfiguration pubconf(publisher1.Data(), "FilePublisher", NULL , arg.Data());
+    //cout << arg.Data() << endl; 
+
+    // cluster finder components
+    cf1.Form("CF1_%02d",slice);
+    AliHLTConfiguration cfconf(cf1.Data(), "TRDClusterizer", publisher1.Data(), "output_percentage 1000 -geometry geometry.root -lowflux -simulation");
+
+    // tracker finder components
+    TString tracker1;
+    tracker1.Form("TR1_%02d",slice);
+    AliHLTConfiguration trackerconf(tracker1.Data(), "TRDTrackerV1", cf1.Data(), "output_percentage 300 -NTimeBins 24 -magnetic_field_ON -lowflux -geometry geometry.root");
+
+    if (writerInput1.Length()>0) writerInput1+=" ";
+    writerInput1+=tracker1;
+
+    if (mergerInput1.Length()>0) mergerInput1+=" ";
+    mergerInput1 += tracker1;
+  }
+
+  if (globalmergerInput.Length()>0) globalmergerInput+=" ";
+  globalmergerInput += "globalmerger";
+
+  if (globalmergerInput.Length()>0) globalmergerInput+=" ";
+  globalmergerInput += mergerInput1;
+
+  //TString datatype = "sim";
+  //AliHLTConfiguration HWriterTR( "HWriterTR", "FileWriter", writerInput.Data(), "-directory . -datafile tr_" + datatype + ".out");
+  
+  //GlobalTrackMerger component
+  AliHLTConfiguration gtrackmergerconf("gtrackmerger","GlobalTrackMerger",globalmergerInput.Data(),"");
+
+  // the root file writer configuration
+  AliHLTConfiguration sink("sink1", "EsdCollector" , "gtrackmerger" , "-directory hlt-global-track");
+
+  ///////////////////////////////////////////////////////////////////////////////////////////////////
+  //
+  // Init and run the reconstruction
+  // All but HLT reconstructio is switched off
+  //
+  AliReconstruction rec;
+  rec.SetInput(input);
+  rec.SetRunVertexFinder(kFALSE);
+  rec.SetRunLocalReconstruction("HLT");
+  rec.SetRunTracking("");
+  rec.SetLoadAlignFromCDB(0);
+  rec.SetRunQA(":");
+  AliMagFMaps* field = new AliMagFMaps("Maps","Maps", 2, 1., 10., AliMagFMaps::k5kG);
+  AliTracker::SetFieldMap(field,kTRUE);
+  rec.SetFillESD("HLT");
+  rec.SetOption("HLT", "libAliHLTUtil.so libAliHLTRCU.so libAliHLTTRD.so libAliHLTTPC.so libAliHLTGlobal.so chains=sink1");
+  rec.Run();
+}
diff --git a/HLT/libAliHLTGlobal.pkg b/HLT/libAliHLTGlobal.pkg
new file mode 100644 (file)
index 0000000..0c6e0ef
--- /dev/null
@@ -0,0 +1,51 @@
+#-*- Mode: Makefile -*-
+# $Id$
+
+CLASS_HDRS:=   AliHLTGlobalTrackMerger.h \
+               AliHLTGlobalTrackMergerComponent.h \
+               AliHLTGlobalAgent.h
+
+#              
+MODULE_SRCS=   $(CLASS_HDRS:.h=.cxx)
+
+MODULE_HDRS:=  $(CLASS_HDRS)
+
+MODULE_DHDR:= 
+
+EINCLUDE       := HLT/global \
+                  HLT/TPCLib \
+                  HLT/TPCLib/tracking \
+                  HLT/TPCLib/comp \
+                  HLT/TPCLib/tracking-ca \
+                  HLT/TPCLib/offline \
+                  HLT/BASE \
+                  HLT/BASE/util \
+                  HLT/RCU \
+                  HLT/TRD \
+                  TPC \
+                  RAW \
+                  TRD \
+                  STEER
+
+LIBRARY_DEP := -lHLTbase -lAliHLTRCU -lAliHLTUtil -lAliHLTTRD \
+               -lCDB -lESD -lSTEER -lSTEERBase -lTPCrec -lTPCcalib -lTPCbase \
+               -lRAWDatarec -lRAWDatabase -lTRDbase \
+               -L$(shell root-config --libdir) -lEG
+
+###############################################################################
+#
+# do not change anything below this line
+#
+include $(MODDIR)/hlt.conf
+
+SRCS:=$(patsubst %,global/%,$(MODULE_SRCS))
+CINTHDRS:=$(patsubst %,global/%,$(CLASS_HDRS))
+HDRS:=$(patsubst %,global/%,$(MODULE_HDRS))
+DHDR:=$(patsubst %,global/%,$(MODULE_DHDR))
+CINTAUTOLINK:= $(shell test "x$(MODULE_DHDR)" = "x" && echo 1)
+
+EDEFINE      := ${HLTDEFS}
+PACKCXXFLAGS := ${HLTCXXFLAGS}
+PACKCFLAGS   := ${HLTCLFAGS}
+PACKDCXXFLAGS:= ${HLTDCXXFLAGS}
+PACKSOFLAGS  := $(HLTSOFLAGS)