]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/global/AliHLTGlobalEsdConverterComponent.cxx
fix AliHLTGlobalEsdConverterComponent
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalEsdConverterComponent.cxx
index b142deb8ef059228679843bab643edccdc5e74e1..1658cddc1bfb935a684820182c34a4ea004494e2 100644 (file)
 #include "AliHLTExternalTrackParam.h"
 #include "AliHLTTrackMCLabel.h"
 #include "AliHLTCTPData.h"
+#include "AliHLTTPCDefinitions.h"
+#include "AliHLTTPCSpacePointData.h"
+#include "AliHLTTPCClusterDataFormat.h"
+#include "AliTPCclusterMI.h"
+#include "AliTPCseed.h"
+#include "AliITStrackV2.h"
+#include "AliESDfriend.h"
+#include "AliESDfriendTrack.h"
+#include "AliHLTTPCTransform.h"
+#include "AliHLTErrorGuard.h"
 #include "AliESDEvent.h"
 #include "AliESDtrack.h"
 #include "AliESDMuonTrack.h"
+#include "AliESDMuonCluster.h"
 #include "AliCDBEntry.h"
 #include "AliCDBManager.h"
 #include "AliPID.h"
 #include "TTree.h"
 #include "TList.h"
 #include "TClonesArray.h"
+#include "TTimeStamp.h"
+#include "THnSparse.h"
 #include "AliHLTESDCaloClusterMaker.h"
 #include "AliHLTCaloClusterDataStruct.h"
 #include "AliHLTCaloClusterReader.h"
 #include "AliESDCaloCluster.h"
+#include "AliESDVZERO.h"
 #include "AliHLTGlobalVertexerComponent.h"
+#include "AliHLTVertexFinderBase.h"
+#include "AliSysInfo.h"
+#include "AliHLTSAPTrackerData.h"
+#include "AliFlatESDVertex.h"
 
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTGlobalEsdConverterComponent)
@@ -57,7 +75,9 @@ AliHLTGlobalEsdConverterComponent::AliHLTGlobalEsdConverterComponent()
   , fWriteTree(0)
   , fVerbosity(0)
   , fESD(NULL)
+  , fESDfriend(NULL)
   , fSolenoidBz(-5.00668)
+  , fMakeFriends(0)
   , fBenchmark("EsdConverter")
 {
   // see header file for class documentation
@@ -65,13 +85,20 @@ AliHLTGlobalEsdConverterComponent::AliHLTGlobalEsdConverterComponent()
   // refer to README to build package
   // or
   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+  for( int i=0; i<fkNPartition; i++ ){
+       fPartitionClusters[i]  = 0;    
+       fNPartitionClusters[i] = 0;    
+  }  
 }
 
 AliHLTGlobalEsdConverterComponent::~AliHLTGlobalEsdConverterComponent()
 {
   // see header file for class documentation
   if (fESD) delete fESD;
-  fESD=NULL;
+  if (fESDfriend) delete fESDfriend;
+  for( int i=0; i<fkNPartition; i++ ){
+    delete[] fPartitionClusters[i];
+  }
 }
 
 int AliHLTGlobalEsdConverterComponent::Configure(const char* arguments)
@@ -87,7 +114,7 @@ int AliHLTGlobalEsdConverterComponent::Configure(const char* arguments)
   TObjArray* pTokens=allArgs.Tokenize(" ");
   if (pTokens) {
     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
-      argument=((TObjString*)pTokens->At(i))->GetString();     
+      argument=((TObjString*)pTokens->At(i))->String();        
       if (argument.IsNull()) continue;
       
       if (argument.CompareTo("-solenoidBz")==0) {
@@ -126,8 +153,8 @@ int AliHLTGlobalEsdConverterComponent::Reconfigure(const char* cdbEntry, const c
     if (pEntry) {
       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
       if (pString) {
-       HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
-       iResult=Configure(pString->GetString().Data());
+       HLTInfo("received configuration object string: \'%s\'", pString->String().Data());
+       iResult=Configure(pString->String().Data());
       } else {
        HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
       }
@@ -150,12 +177,28 @@ void AliHLTGlobalEsdConverterComponent::GetInputDataTypes(AliHLTComponentDataTyp
   list.push_back(kAliHLTDataTypeESDObject);
   list.push_back(kAliHLTDataTypeTObject);
   list.push_back(kAliHLTDataTypeGlobalVertexer);
+  list.push_back(kAliHLTDataTypeV0Finder); // array of track ids for V0s
+  list.push_back(kAliHLTDataTypeKFVertex); // KFVertex object from vertexer
+  list.push_back(kAliHLTDataTypePrimaryFinder); // array of track ids for prim vertex
+  list.push_back(kAliHLTDataTypeESDContent);
+  list.push_back( AliHLTTPCDefinitions::fgkClustersDataType   );
+  list.push_back(kAliHLTDataTypeFlatESDVertex); // VertexTracks resonctructed using SAP ITS tracks
+  list.push_back(kAliHLTDataTypeITSSAPData);    // SAP ITS tracks
 }
 
 AliHLTComponentDataType AliHLTGlobalEsdConverterComponent::GetOutputDataType()
 {
   // see header file for class documentation
-  return kAliHLTDataTypeESDObject|kAliHLTDataOriginOut;
+  return kAliHLTMultipleDataType;
+}
+
+int AliHLTGlobalEsdConverterComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList){ 
+// see header file for class documentation
+
+  tgtList.clear();
+  tgtList.push_back( kAliHLTDataTypeESDObject|kAliHLTDataOriginOut );
+  tgtList.push_back( kAliHLTDataTypeESDfriendObject|kAliHLTDataOriginOut );
+  return tgtList.size();
 }
 
 void AliHLTGlobalEsdConverterComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
@@ -176,7 +219,7 @@ int AliHLTGlobalEsdConverterComponent::DoInit(int argc, const char** argv)
   TString skipObjects=
     // "AliESDRun,"
     // "AliESDHeader,"
-    "AliESDZDC,"
+    // "AliESDZDC,"
     "AliESDFMD,"
     // "AliESDVZERO,"
     // "AliESDTZERO,"
@@ -203,7 +246,7 @@ int AliHLTGlobalEsdConverterComponent::DoInit(int argc, const char** argv)
   TObjArray* pTokens=allArgs.Tokenize(" ");
   if (pTokens) {
     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
-      argument=((TObjString*)pTokens->At(i))->GetString();     
+      argument=((TObjString*)pTokens->At(i))->String();        
       if (argument.IsNull()) continue;
 
       // -notree
@@ -215,7 +258,7 @@ int AliHLTGlobalEsdConverterComponent::DoInit(int argc, const char** argv)
        fWriteTree=1;
       } else if (argument.CompareTo("-solenoidBz")==0) {
        if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
-       HLTInfo("Magnetic Field set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
+       HLTInfo("Magnetic Field set to: %s", ((TObjString*)pTokens->At(i))->String().Data());
        HLTWarning("argument '-solenoidBz' is deprecated, solenoid field initiaized from CDB settings");
        continue;
       } else if (argument.Contains("-skipobject=")) {
@@ -235,6 +278,11 @@ int AliHLTGlobalEsdConverterComponent::DoInit(int argc, const char** argv)
 
   fSolenoidBz=GetBz();
 
+  if(fESD) delete fESD;
+  fESD = NULL;
+  if(fESDfriend) delete fESDfriend;
+  fESDfriend=NULL;
+
   if (iResult>=0) {
     fESD = new AliESDEvent;
     if (fESD) {
@@ -248,7 +296,7 @@ int AliHLTGlobalEsdConverterComponent::DoInit(int argc, const char** argv)
          TIter next(pTokens);
          TObject* pObject=NULL;
          while ((pObject=next())!=NULL) {
-           id=((TObjString*)pObject)->GetString().Data();
+           id=((TObjString*)pObject)->String().Data();
            TObject* pObj=fESD->GetList()->FindObject(id);
            if (pObj) {
              HLTDebug("removing object %s", id);
@@ -268,6 +316,10 @@ int AliHLTGlobalEsdConverterComponent::DoInit(int argc, const char** argv)
 
     SetupCTPData();
   }
+  
+  if( iResult>=0 && fMakeFriends ){
+    fESDfriend = new AliESDfriend();
+  }
 
   fBenchmark.SetTimer(0,"total");
 
@@ -277,24 +329,33 @@ int AliHLTGlobalEsdConverterComponent::DoInit(int argc, const char** argv)
 int AliHLTGlobalEsdConverterComponent::DoDeinit()
 {
   // see header file for class documentation
-  if (fESD) delete fESD;
+  if(fESD) delete fESD;
   fESD=NULL;
-
+  if(fESDfriend) delete fESDfriend;
+  fESDfriend = NULL;
   return 0;
 }
 
-int AliHLTGlobalEsdConverterComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/
+int AliHLTGlobalEsdConverterComponent::DoEvent(const AliHLTComponentEventData& evtData
                                               AliHLTComponentTriggerData& trigData)
 {
   // see header file for class documentation
   int iResult=0;
+
   if (!fESD) return -ENODEV;
 
-  if (IsDataEvent()) fBenchmark.StartNewEvent();
+  if (!IsDataEvent()) return iResult;
+  fBenchmark.StartNewEvent();
   fBenchmark.Start(0);
 
+  for(Int_t i=0; i<fkNPartition; i++){
+    delete[] fPartitionClusters[i];    
+    fPartitionClusters[i]  = 0;
+    fNPartitionClusters[i] = 0;    
+  }  
+  
   AliESDEvent* pESD = fESD;
-
+  
   pESD->Reset(); 
   pESD->SetMagneticField(fSolenoidBz);
   pESD->SetRunNumber(GetRunNo());
@@ -305,12 +366,18 @@ int AliHLTGlobalEsdConverterComponent::DoEvent(const AliHLTComponentEventData& /
 
   const AliHLTCTPData* pCTPData=CTPData();
   if (pCTPData) {
-    AliHLTUInt64_t mask=pCTPData->ActiveTriggers(trigData);
+    AliHLTTriggerMask_t mask=pCTPData->ActiveTriggers(trigData);
     for (int index=0; index<gkNCTPTriggerClasses; index++) {
-      if ((mask&((AliHLTUInt64_t)0x1<<index)) == 0) continue;
+      if ((mask&(AliHLTTriggerMask_t(0x1)<<index)) == 0) continue;
       pESD->SetTriggerClass(pCTPData->Name(index), index);
     }
-    pESD->SetTriggerMask(mask);
+    //first 50 triggers
+    AliHLTTriggerMask_t mask50;
+    mask50.set(); // set all bits
+    mask50 >>= 50; // shift 50 right
+    pESD->SetTriggerMask((mask&mask50).to_ulong());
+    //next 50
+    pESD->SetTriggerMaskNext50((mask>>50).to_ulong());
   }
 
   TTree* pTree = NULL;
@@ -321,7 +388,9 @@ int AliHLTGlobalEsdConverterComponent::DoEvent(const AliHLTComponentEventData& /
     pTree->SetDirectory(0);
   }
 
-  if ((iResult=ProcessBlocks(pTree, pESD))>=0) {
+  if( fESDfriend ) fESDfriend->Reset();
+
+  if ((iResult=ProcessBlocks(pTree, pESD, fESDfriend))>=0) {
     // TODO: set the specification correctly
     if (pTree) {
       // the esd structure is written to the user info and is
@@ -333,6 +402,10 @@ int AliHLTGlobalEsdConverterComponent::DoEvent(const AliHLTComponentEventData& /
       iResult=PushBack(pESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginOut, 0);
     }
     fBenchmark.AddOutput(GetLastObjectSize());
+    if( iResult>=0 && fMakeFriends ){
+      iResult=PushBack(fESDfriend, kAliHLTDataTypeESDfriendObject|kAliHLTDataOriginOut, 0);
+      fBenchmark.AddOutput(GetLastObjectSize());
+     }
   }
   if (pTree) {
     // clear user info list to prevent objects from being deleted
@@ -341,18 +414,40 @@ int AliHLTGlobalEsdConverterComponent::DoEvent(const AliHLTComponentEventData& /
   }
 
   fBenchmark.Stop(0);
-  HLTInfo( fBenchmark.GetStatistics() );
+  HLTBenchmark( fBenchmark.GetStatistics() );
+  
+  for(Int_t i=0; i<fkNPartition; i++){
+    delete[] fPartitionClusters[i];    
+    fPartitionClusters[i]  = 0;
+    fNPartitionClusters[i] = 0;    
+  }
+
+  if( fESDfriend ) fESDfriend->Reset();
+  if( fESD ) fESD->Reset();
 
   return iResult;
 }
 
-int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD)
+int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD, AliESDfriend *pESDfriend )
 {
   // see header file for class documentation
 
   int iResult=0;
   int iAddedDataBlocks=0;
 
+  // check if there is an ESD block in the input and copy its content first to the
+  // ESD
+  const TObject* pEsdObj = GetFirstInputObject(kAliHLTDataTypeESDObject, "AliESDEvent");
+  AliESDEvent* pInputESD=NULL;
+  if (pEsdObj) pInputESD=dynamic_cast<AliESDEvent*>(const_cast<TObject*>(pEsdObj));
+  if (pInputESD) {
+    pInputESD->GetStdContent();
+    *pESD=*pInputESD;
+  }
+  if (GetNextInputObject()!=NULL) {
+    HLTWarning("handling of multiple ESD input objects not implemented, skipping input");
+  }
+
   // Barrel tracking
   // tracks are based on the TPC tracks, and only updated from the ITS information
   // Sequence:
@@ -373,6 +468,101 @@ int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent*
   //    TODO 2010-07-12 find out if the kITSrefit has to be set as well
   // 4) extract TRD tracks and add to ESD
   //    TODO 2010-07-12 at the moment there is no matching or merging of TPC and TRD tracks
+  // 5) Add Trigger Detectors 
+  //    VZERO, ZDC
+
+  // read the clusters
+  // ---------- Access to clusters --------------------//
+  /*
+  const AliHLTComponentBlockData* pBl0=GetFirstInputBlock();
+  int cnt = 0;
+  while (pBl0) {
+    char tp[9],org[5];
+    strncpy(tp,pBl0->fDataType.fID,8);
+    tp[8] = '0';
+    strncpy(org,pBl0->fDataType.fOrigin,4);
+    org[4] = '0';
+    //
+    printf(">>> Bl%3d %8s|%4s of size %d\n",cnt++,tp,org,pBl0->fSize);
+    pBl0 = GetNextInputBlock();
+  };
+  */
+  for(Int_t i=0; i<fkNPartition; i++){
+    delete[] fPartitionClusters[i];    
+    fPartitionClusters[i]  = 0;
+    fNPartitionClusters[i] = 0;    
+  }
+
+  if( pESDfriend ){
+
+    int nInputClusters = 0;
+    
+    for(const AliHLTComponentBlockData *iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkClustersDataType); iter != NULL; iter = GetNextInputBlock()){
+      
+      if(iter->fDataType != AliHLTTPCDefinitions::fgkClustersDataType) continue;    
+      Int_t slice     = AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
+      Int_t partition = AliHLTTPCDefinitions::GetMinPatchNr(iter->fSpecification);    
+      Int_t slicepartition = slice*6+partition;      
+      if(slicepartition<0 || slicepartition > fkNPartition){
+       HLTWarning("Wrong header of TPC cluster data, slice %d, partition %d", slice, partition );
+       continue;
+      }
+      
+      AliHLTTPCClusterData *inPtrSP = ( AliHLTTPCClusterData* )( iter->fPtr );
+      nInputClusters += inPtrSP->fSpacePointCnt;
+      
+      delete[] fPartitionClusters[slicepartition];
+      fPartitionClusters[slicepartition]  = new AliTPCclusterMI[inPtrSP->fSpacePointCnt];
+      fNPartitionClusters[slicepartition] = inPtrSP->fSpacePointCnt;
+    
+      // create  offline clusters out of the HLT clusters
+
+      for ( unsigned int i = 0; i < inPtrSP->fSpacePointCnt; i++ ) {
+       AliHLTTPCSpacePointData *chlt = &( inPtrSP->fSpacePoints[i] );
+       AliTPCclusterMI *c = fPartitionClusters[slicepartition]+i;
+       c->SetX(chlt->fX);
+       c->SetY(chlt->fY);
+       c->SetZ(chlt->fZ);
+       c->SetSigmaY2(chlt->fSigmaY2);
+       c->SetSigmaYZ( 0 );
+       c->SetSigmaZ2(chlt->fSigmaZ2);
+       c->SetQ( chlt->fCharge );
+       c->SetMax( chlt->fQMax );
+       Int_t sector, row;
+       Float_t padtime[3] = {0,chlt->fY,chlt->fZ};
+       AliHLTTPCTransform::Slice2Sector(slice,chlt->fPadRow, sector, row);
+       AliHLTTPCTransform::Local2Raw( padtime, sector, row);
+       c->SetDetector( sector );
+       c->SetRow( row );
+       c->SetPad( (Int_t) padtime[1] );
+       c->SetTimeBin( (Int_t) padtime[2] );
+      }
+    } // end of loop over blocks of clusters    
+    
+    
+        // fill event info
+    {
+      for( Int_t iSlice=0; iSlice<36; iSlice++ ){
+       int iSector = iSlice;
+       int nclu = 0;
+       for( Int_t iPartition=0; iPartition<3; iPartition++){       
+         int slicepartition = iSlice*6+iPartition;
+         nclu+= fNPartitionClusters[slicepartition];
+       }
+       pESDfriend->SetNclustersTPC( iSector, nclu );
+       iSector = 36+iSlice;
+       nclu = 0;
+       for( Int_t iPartition=3; iPartition<6; iPartition++){       
+         int slicepartition = iSlice*6+iPartition;
+         nclu+= fNPartitionClusters[slicepartition];
+       }
+       pESDfriend->SetNclustersTPC( iSector, nclu );
+      }
+    }
+    
+    
+    
+  }
 
   // 1) first read MC information (if present)
   std::map<int,int> mcLabelsTPC;
@@ -421,26 +611,28 @@ int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent*
   AliHLTFloat32_t *dEdxTPC = 0; 
   Int_t ndEdxTPC = 0;
   for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypedEdx|kAliHLTDataOriginTPC);
-       pBlock!=NULL; pBlock=GetNextInputBlock()) {
+       pBlock!=NULL; pBlock=NULL/*GetNextInputBlock() there is only one block*/) {
     fBenchmark.AddInput(pBlock->fSize);
     dEdxTPC = reinterpret_cast<AliHLTFloat32_t*>( pBlock->fPtr );
-    ndEdxTPC = pBlock->fSize / sizeof(AliHLTFloat32_t);
-    break;
+    ndEdxTPC = pBlock->fSize / (3*sizeof(AliHLTFloat32_t));
   }
 
   // 2) convert the TPC tracks to ESD tracks
   for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC);
        pBlock!=NULL; pBlock=GetNextInputBlock()) {
+    if (pInputESD && pInputESD->GetNumberOfTracks()>0) {
+      HLTWarning("Tracks array already filled from the input esd block, additional filling from TPC tracks block might cause inconsistent content");
+    }
     fBenchmark.AddInput(pBlock->fSize);
     vector<AliHLTGlobalBarrelTrack> tracks;
     if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>=0) {
       for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
           element!=tracks.end(); element++) {
        Float_t points[4] = {
-         element->GetX(),
-         element->GetY(),
-         element->GetLastPointX(),
-         element->GetLastPointY()
+         static_cast<Float_t>(element->GetX()),
+         static_cast<Float_t>(element->GetY()),
+         static_cast<Float_t>(element->GetLastPointX()),
+         static_cast<Float_t>(element->GetLastPointY())
        };
 
        Int_t mcLabel = -1;
@@ -472,9 +664,15 @@ int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent*
        // HLT does not provide such standalone tracking
        {
          AliHLTGlobalBarrelTrack outPar(*element);       
-         outPar.AliExternalTrackParam::PropagateTo( element->GetLastPointX(), fSolenoidBz );
+         //outPar.AliExternalTrackParam::PropagateTo( element->GetLastPointX(), fSolenoidBz );
+         const Int_t N=10; // number of steps.
+         const Float_t xRange = element->GetLastPointX() - element->GetX();
+         const Float_t xStep = xRange / N ;
+         for(int i = 1; i <= N; ++i) {
+           if(!outPar.AliExternalTrackParam::PropagateTo(element->GetX() + xStep * i, fSolenoidBz)) break;
+         }
          outPar.SetLabel(element->GetLabel());
-         //iotrack.UpdateTrackParams(&outPar,AliESDtrack::kTPCout);
+         iotrack.UpdateTrackParams(&outPar,AliESDtrack::kTPCout);
        }
        // 2.2 TPC tracking estimates parameters at first cluster
        iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCin);
@@ -486,11 +684,12 @@ int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent*
        iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCrefit);
        iotrack.SetTPCPoints(points);
        if( element->TrackID()<ndEdxTPC ){
-         iotrack.SetTPCsignal( dEdxTPC[element->TrackID()], 0, 0 ); 
+         AliHLTFloat32_t *val = &(dEdxTPC[3*element->TrackID()]);
+         iotrack.SetTPCsignal( val[0], val[1], (UChar_t) val[2] ); 
          //AliTPCseed s;
          //s.Set( element->GetX(), element->GetAlpha(),
          //element->GetParameter(), element->GetCovariance() );
-         //s.SetdEdx( dEdxTPC[element->TrackID()] );
+         //s.SetdEdx( val[0] );
          //s.CookPID();
          //iotrack.SetTPCpid(s.TPCrPIDs() );
        } else {
@@ -499,7 +698,70 @@ int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent*
        iotrack.SetLabel(mcLabel);
        pESD->AddTrack(&iotrack);
        if (fVerbosity>0) element->Print();
+
+       if( pESDfriend ){ // create friend track
+
+         AliHLTGlobalBarrelTrack gb(*element);
+         AliTPCseed tTPC;
+         tTPC.Set( gb.GetX(), gb.GetAlpha(), gb.GetParameter(), gb.GetCovariance() );    
+         tTPC.SetLabel(mcLabel);
+         
+         // set the clusters 
+         UInt_t nClusters = element->GetNumberOfPoints();
+         const UInt_t*clusterIDs = element->GetPoints();
+
+         tTPC.SetNumberOfClusters(nClusters);
+
+         for(UInt_t ic=0; ic<nClusters; ic++){  
+
+           UInt_t id      = clusterIDs[ic];         
+           int iSlice = AliHLTTPCSpacePointData::GetSlice(id);
+           int iPartition = AliHLTTPCSpacePointData::GetPatch(id);
+           int iCluster = AliHLTTPCSpacePointData::GetNumber(id);
+           
+           if(iSlice<0 || iSlice>36 || iPartition<0 || iPartition>5){
+             HLTError("Corrupted TPC cluster Id: slice %d, partition %d, cluster %d", iSlice, iPartition, iCluster);
+             continue;
+           }
+           
+           AliTPCclusterMI *patchClusters = fPartitionClusters[iSlice*6 + iPartition];
+           if(!patchClusters){
+             HLTError("Clusters are missed for slice %d, partition %d", iSlice, iPartition );
+             continue;
+           }
+           
+           if(iCluster >= fNPartitionClusters[iSlice*6 + iPartition]){
+             HLTError("TPC slice %d, partition %d: ClusterID==%d >= N Cluaters==%d ", iSlice, iPartition,iCluster, fNPartitionClusters[iSlice*6 + iPartition] );
+             continue;
+           }
+       
+           AliTPCclusterMI *c = &(patchClusters[iCluster]);            
+           int sec = c->GetDetector();
+           int row = c->GetRow();
+           if(sec >= 36) row = row + AliHLTTPCTransform::GetNRowLow();
+         
+           tTPC.SetClusterPointer(row, c);     
+       
+           AliTPCTrackerPoint &point = *( tTPC.GetTrackPoint( row ) );
+           //tTPC.Propagate( TMath::DegToRad()*(sec%18*20.+10.), c->GetX(), fSolenoidBz );
+           Double_t angle2 = tTPC.GetSnp()*tTPC.GetSnp();
+           angle2 = (angle2<1) ?TMath::Sqrt(angle2/(1-angle2)) :10.; 
+           point.SetAngleY( angle2 );
+           point.SetAngleZ( tTPC.GetTgl() );
+         } // end of associated cluster loop
+         
+         // Cook dEdx
+         
+         //AliTPCseed *seed = &(tTPC);      
+         //fSeedArray->AddAt( seed, TMath::Abs(seed->GetLabel()) );
+         //fdEdx->Fill( seed->P()*seed->Charge(), seed->CookdEdx(0.02, 0.6) );
+
+         AliESDfriendTrack friendTrack;
+         friendTrack.AddCalibObject(&tTPC);
+         pESDfriend->AddTrack(&friendTrack);
+       }
       }
+
       HLTInfo("converted %d track(s) to AliESDtrack and added to ESD", tracks.size());
       iAddedDataBlocks++;
     } else if (iResult<0) {
@@ -519,6 +781,53 @@ int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent*
     pESD->SetPrimaryVertexSPD( vtx );
   }
 
+  // Get ITS Standalone primaries (SAP) vertexTracks
+  {
+    const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeFlatESDVertex|kAliHLTDataOriginITS);
+    if (pBlock) {
+      fBenchmark.AddInput(pBlock->fSize);
+      AliFlatESDVertex *vtxFlat =  reinterpret_cast<AliFlatESDVertex*>( pBlock->fPtr );
+      if (vtxFlat->GetNContributors()>0) {
+       AliESDVertex vtx;
+       vtxFlat->GetESDVertex(vtx);
+       vtx.SetTitle("vertexITSSAP");
+       pESD->SetPrimaryVertexSPD( &vtx );
+      }
+    }
+  }
+
+  // Get ITS Standalone primary (SAP) Tracks
+  {
+    const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeITSSAPData|kAliHLTDataOriginITS);
+    if (pBlock) {
+      fBenchmark.AddInput(pBlock->fSize);
+      const AliHLTITSSAPTrackerDataContainer *dataSAP = reinterpret_cast<const AliHLTITSSAPTrackerDataContainer*>(pBlock->fPtr);
+      AliITStrackV2 trcV2;
+      int ntrITSSAP = dataSAP->fCount;
+      for (int itr=0;itr<ntrITSSAP;itr++) {
+       const AliHLTITSSAPTrackerData& trcFlatSAP = dataSAP->fTracks[itr];
+       AliESDtrack inpESDtrc;
+       inpESDtrc.SetID(pESD->GetNumberOfTracks());
+       trcFlatSAP.paramInw.GetExternalTrackParam(trcV2); // track at the vertex
+       trcV2.SetLabel(trcFlatSAP.label);
+       trcV2.SetNumberOfClusters(trcFlatSAP.ncl);
+       trcV2.SetChi2(trcFlatSAP.chi2);
+       inpESDtrc.UpdateTrackParams(&trcV2,AliESDtrack::kITSrefit);
+       inpESDtrc.SetStatus( (AliESDtrack::kITSin|AliESDtrack::kITSout|AliESDtrack::kITSpureSA) );
+       pESD->AddTrack(&inpESDtrc);
+       //
+       if( pESDfriend ) {
+         AliESDfriendTrack friendTrack;
+         trcFlatSAP.paramOut.GetExternalTrackParam(trcV2); // track at the vertex
+         friendTrack.SetITSOut(trcV2);
+         pESDfriend->AddTrack(&friendTrack);
+       }
+      }
+    }
+  }
+
+
+
   // 3.1. now update ESD tracks with the ITSOut info
   // updating track parameters with flag kITSout will overwrite parameter set above with flag kTPCout
   // TODO 2010-07-12 there are some issues with this updating sequence, for the moment update with
@@ -584,13 +893,42 @@ int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent*
   }
 
   // update with  vertices and vertex-fitted tracks
-
+  // output of the GlobalVertexerComponent
   for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeGlobalVertexer);
        pBlock!=NULL; pBlock=GetNextInputBlock()) {
     fBenchmark.AddInput(pBlock->fSize);   
     AliHLTGlobalVertexerComponent::FillESD( pESD, reinterpret_cast<AliHLTGlobalVertexerComponent::AliHLTGlobalVertexerData* >(pBlock->fPtr) );
   }
 
+  // update with  vertices and vertex-fitted tracks
+  // output of PrimaryVertexer and V0Finder components
+  
+  TObject* pBase = (TObject*)GetFirstInputObject(kAliHLTDataTypeKFVertex | kAliHLTDataOriginOut);
+  if (pBase) {
+    AliKFVertex* kfVertex = dynamic_cast<AliKFVertex *>(pBase);
+    if (kfVertex) {
+      const AliHLTComponentBlockData* pP = GetFirstInputBlock(kAliHLTDataTypePrimaryFinder | kAliHLTDataOriginOut);
+      if (pP && pP->fSize && pP->fPtr) {
+       const AliHLTComponentBlockData* pV0 = GetFirstInputBlock(kAliHLTDataTypeV0Finder | kAliHLTDataOriginOut);
+       if (pV0 && pV0->fPtr && pInputESD && pInputESD->GetNumberOfV0s()>0) {
+         const int* v0s = static_cast<const int*>(pV0->fPtr);
+         HLTWarning("V0 array already filled from the input esd block, additional filling from V0 block of %d entries might cause inconsistent content", v0s[0]);
+       }
+       AliHLTVertexFinderBase::FillESD(pESD, kfVertex, pP->fPtr, pV0?pV0->fPtr:NULL);
+      } else
+       HLTWarning("Problem with primary finder's data block");
+    } else {
+      HLTWarning("primary vertex block of wrong type, expecting AliKFVertex instead of %s", pBase->GetName());
+    }
+  } else {
+    // throw an error if there is a V0 data block which can not be handled without
+    // the AliKFVertex object
+    if (GetFirstInputBlock(kAliHLTDataTypeV0Finder | kAliHLTDataOriginOut)!=NULL) {
+      ALIHLTERRORGUARD(1, "missing AliKFVertex object ignoring V0 data block of type %s",
+                      DataType2Text(kAliHLTDataTypeV0Finder|kAliHLTDataOriginOut).c_str());
+    }
+  }
+
   // Fill DCA parameters for TPC tracks
   // TODO 2010-07-12 this propagates also the TPC inner param to beamline
   // sounds not very reasonable
@@ -642,6 +980,7 @@ int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent*
        
        AliESDtrack iotrack;
        iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTRDout);
+       iotrack.SetStatus(AliESDtrack::kTRDin);
        iotrack.SetTRDpid(TRDpid);
        
        pESD->AddTrack(&iotrack);
@@ -672,7 +1011,50 @@ int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent*
       iAddedDataBlocks++;
     }
   
-  // Add tracks from MUON.
+  // 5) Add Trigger Detectors 
+  //    VZERO, ZDC
+
+  // FIXME: the size of all input blocks can be added in one loop
+  for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeESDContent|kAliHLTDataOriginVZERO);
+       pBlock!=NULL; pBlock=GetNextInputBlock()) {
+    fBenchmark.AddInput(pBlock->fSize);
+  }
+
+  for ( const TObject *pObject = GetFirstInputObject(kAliHLTDataTypeESDContent|kAliHLTDataOriginVZERO); 
+       pObject != NULL; pObject = GetNextInputObject() ) {
+    AliESDVZERO *esdVZERO = dynamic_cast<AliESDVZERO*>(const_cast<TObject*>( pObject ) );
+    if (esdVZERO) {
+      pESD->SetVZEROData( esdVZERO );
+      break;
+    } else {
+      ALIHLTERRORGUARD(1, "input object of data type %s is not of class AliESDVZERO",
+                      DataType2Text(kAliHLTDataTypeESDContent|kAliHLTDataOriginVZERO).c_str());
+    }
+  }
+
+  // FIXME: the size of all input blocks can be added in one loop
+  for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeESDContent|kAliHLTDataOriginZDC);
+       pBlock!=NULL; pBlock=GetNextInputBlock()) {
+    fBenchmark.AddInput(pBlock->fSize);
+  }
+  for ( const TObject *pObject = GetFirstInputObject(kAliHLTDataTypeESDContent|kAliHLTDataOriginZDC); 
+       pObject != NULL; pObject = GetNextInputObject() ) {
+    AliESDZDC *esdZDC = dynamic_cast<AliESDZDC*>(const_cast<TObject*>( pObject ) );
+    if (esdZDC) {
+#ifndef HAVE_NOT_ALIZDCRECONSTRUCTOR_r43770
+      pESD->SetZDCData( esdZDC );
+#else
+      ALIHLTERRORGUARD(1, "Processing of ZDC data requires AliRoot r43770m skipping data block of type %s",
+                      DataType2Text(kAliHLTDataTypeESDContent|kAliHLTDataOriginZDC).c_str());
+#endif
+      break;
+    } else {
+      ALIHLTERRORGUARD(1, "input object of data type %s is not of class AliESDZDC",
+                      DataType2Text(kAliHLTDataTypeESDContent|kAliHLTDataOriginZDC).c_str());
+    }
+  }
+
+  // Add tracks and clusters from MUON.
   for( const AliHLTComponentBlockData *i= GetFirstInputBlock(kAliHLTAnyDataType | kAliHLTDataOriginMUON); i!=NULL; i=GetNextInputBlock() ){
     fBenchmark.AddInput(i->fSize);
   }
@@ -683,6 +1065,7 @@ int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent*
       )
   {
     const TClonesArray* tracklist = NULL;
+    const TClonesArray* clusterlist = NULL;
     if (obj->IsA() == AliESDEvent::Class())
     {
       const AliESDEvent* event = static_cast<const AliESDEvent*>(obj);
@@ -690,37 +1073,70 @@ int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent*
       if (event->GetList() == NULL) continue;
       tracklist = dynamic_cast<const TClonesArray*>(event->GetList()->FindObject("MuonTracks"));
       if (tracklist == NULL) continue;
+      clusterlist = dynamic_cast<const TClonesArray*>(event->GetList()->FindObject("MuonClusters"));
+      if (clusterlist == NULL) continue;
     }
     else if (obj->IsA() == TClonesArray::Class())
     {
-      tracklist = static_cast<const TClonesArray*>(obj);
-      HLTDebug("Received a MUON TClonesArray of tracks with specification: 0x%X", GetSpecification(obj));
+      if (!strcmp(obj->GetName(), "MuonTracks")) {
+       tracklist = static_cast<const TClonesArray*>(obj);
+       HLTDebug("Received a MUON TClonesArray of tracks with specification: 0x%X", GetSpecification(obj));
+      } else {
+       clusterlist = static_cast<const TClonesArray*>(obj);
+       HLTDebug("Received a MUON TClonesArray of clusters with specification: 0x%X", GetSpecification(obj));
+      }
     }
     else
     {
       // Cannot handle this object type.
       continue;
     }
-    HLTDebug("Received %d MUON tracks.", tracklist->GetEntriesFast());
-    if (tracklist->GetEntriesFast() > 0)
-    {
-      const AliESDMuonTrack* track = dynamic_cast<const AliESDMuonTrack*>(tracklist->UncheckedAt(0));
-      if (track == NULL)
+    // copy tracks
+    if (tracklist) {
+      HLTDebug("Received %d MUON tracks.", tracklist->GetEntriesFast());
+      if (tracklist->GetEntriesFast() > 0)
       {
-        HLTError(Form("%s from MUON does not contain AliESDMuonTrack objects.", obj->ClassName()));
-        continue;
+       const AliESDMuonTrack* track = dynamic_cast<const AliESDMuonTrack*>(tracklist->UncheckedAt(0));
+       if (track == NULL)
+       {
+         HLTError(Form("%s from MUON does not contain AliESDMuonTrack objects.", obj->ClassName()));
+         continue;
+       }
+      }
+      for (Int_t i = 0; i < tracklist->GetEntriesFast(); ++i)
+      {
+       AliESDMuonTrack* track = pESD->NewMuonTrack();
+       *track = *(static_cast<const AliESDMuonTrack*>(tracklist->UncheckedAt(i)));
       }
     }
-    for (Int_t i = 0; i < tracklist->GetEntriesFast(); ++i)
-    {
-      const AliESDMuonTrack* track = static_cast<const AliESDMuonTrack*>(tracklist->UncheckedAt(i));
-      pESD->AddMuonTrack(track);
+    // copy clusters
+    if (clusterlist) {
+      HLTDebug("Received %d MUON clusters.", clusterlist->GetEntriesFast());
+      if (clusterlist->GetEntriesFast() > 0)
+      {
+       const AliESDMuonCluster* cluster = dynamic_cast<const AliESDMuonCluster*>(clusterlist->UncheckedAt(0));
+       if (cluster == NULL)
+       {
+         HLTError(Form("%s from MUON does not contain AliESDMuonCluster objects.", obj->ClassName()));
+         continue;
+       }
+      }
+      for (Int_t i = 0; i < clusterlist->GetEntriesFast(); ++i)
+      {
+       AliESDMuonCluster* cluster = pESD->NewMuonCluster();
+       *cluster = *(static_cast<const AliESDMuonCluster*>(clusterlist->UncheckedAt(i)));
+      }
     }
   }
+
+  if( fMakeFriends && pESDfriend ){ // create friend track
+    pESD->SetESDfriend( pESDfriend );
+ }
   
   if (iAddedDataBlocks>0 && pTree) {
     pTree->Fill();
-  }
+  }  
   
   if (iResult>=0) iResult=iAddedDataBlocks;
   return iResult;