correcting the drift time transformation; optional output of cluster id array in...
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 29 Sep 2011 04:37:03 +0000 (04:37 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 29 Sep 2011 04:37:03 +0000 (04:37 +0000)
HLT/TPCLib/AliHLTTPCTrackGeometry.cxx
HLT/TPCLib/AliHLTTPCTrackGeometry.h
HLT/TPCLib/comp/AliHLTTPCDataCompressionComponent.cxx
HLT/TPCLib/comp/AliHLTTPCDataCompressionComponent.h

index 646455b..df6536e 100644 (file)
@@ -32,6 +32,7 @@
 #include "AliHLTComponent.h"
 #include "AliHLTGlobalBarrelTrack.h"
 #include "AliHLTDataDeflater.h"
+#include "AliHLTErrorGuard.h"
 #include "TMath.h"
 #include "TH2F.h"
 #include <memory>
@@ -42,6 +43,10 @@ ClassImp(AliHLTTPCTrackGeometry)
 AliHLTTPCTrackGeometry::AliHLTTPCTrackGeometry()
   : AliHLTTrackGeometry()
   , fRawTrackPoints()
+  , fDriftTimeFactorA(0.)
+  , fDriftTimeOffsetA(0.)
+  , fDriftTimeFactorC(0.)
+  , fDriftTimeOffsetC(0.)
 {
   /// standard constructor
 }
@@ -49,6 +54,10 @@ AliHLTTPCTrackGeometry::AliHLTTPCTrackGeometry()
 AliHLTTPCTrackGeometry::AliHLTTPCTrackGeometry(const AliHLTTPCTrackGeometry& src)
   : AliHLTTrackGeometry(src)
   , fRawTrackPoints(src.fRawTrackPoints)
+  , fDriftTimeFactorA(0.)
+  , fDriftTimeOffsetA(0.)
+  , fDriftTimeFactorC(0.)
+  , fDriftTimeOffsetC(0.)
 {
   /// copy constructor
 }
@@ -160,7 +169,18 @@ int AliHLTTPCTrackGeometry::CalculateTrackPoints(AliHLTGlobalBarrelTrack& track,
     if (AddTrackPoint(AliHLTTrackPoint(id, y, z), AliHLTTPCSpacePointData::GetID(slice, partition, 0))>=0) {
       Float_t rpt[3]={0.,y,z}; // row pad time
       AliHLTTPCTransform::LocHLT2Raw(rpt, slice, padrow);
-      fRawTrackPoints.push_back(AliHLTTrackPoint(id, rpt[1], rpt[2]));
+      float m=fDriftTimeFactorA;
+      float n=fDriftTimeOffsetA;
+      if (slice>=18) {
+       m=fDriftTimeFactorC;
+       n=fDriftTimeOffsetC;
+      }
+      if (TMath::Abs(m)>0.) {
+       rpt[2]=(z-n)/m;
+       fRawTrackPoints.push_back(AliHLTTrackPoint(id, rpt[1], rpt[2]));
+      } else {
+       ALIHLTERRORGUARD(1, "drift time correction not initialized, can not add track points in raw coordinates");
+      }
     }
   }
   return 0;
@@ -384,6 +404,7 @@ int AliHLTTPCTrackGeometry::Write(const AliHLTGlobalBarrelTrack& track,
                                  AliHLTDataDeflater* pDeflater,
                                  AliHLTUInt8_t* outputPtr,
                                  AliHLTUInt32_t size,
+                                 vector<AliHLTUInt32_t>* writtenClusterIds,
                                  const char* option) const
 {
   // write track block to buffer
@@ -401,7 +422,7 @@ int AliHLTTPCTrackGeometry::Write(const AliHLTGlobalBarrelTrack& track,
 
   pDeflater->Clear();
   pDeflater->InitBitDataOutput(reinterpret_cast<AliHLTUInt8_t*>(outputPtr+sizeof(AliHLTTPCTrackBlock)), size-sizeof(AliHLTTPCTrackBlock));
-  int result=WriteAssociatedClusters(pSpacePoints, pDeflater, option);
+  int result=WriteAssociatedClusters(pSpacePoints, pDeflater, writtenClusterIds, option);
   if (result<0) return result;
   pTrackBlock->fSize+=result;
   return pTrackBlock->fSize;
@@ -409,6 +430,7 @@ int AliHLTTPCTrackGeometry::Write(const AliHLTGlobalBarrelTrack& track,
 
 int AliHLTTPCTrackGeometry::WriteAssociatedClusters(AliHLTSpacePointContainer* pSpacePoints,
                                                    AliHLTDataDeflater* pDeflater,
+                                                   vector<AliHLTUInt32_t>* writtenClusterIds,
                                                    const char* /*option*/) const
 {
   // write associated clusters to buffer via deflater
@@ -457,6 +479,9 @@ int AliHLTTPCTrackGeometry::WriteAssociatedClusters(AliHLTSpacePointContainer* p
              HLTError("can not find spacepoint 0x%08x", clid->fId);
              continue;
            }
+           if (writtenClusterIds) {
+             writtenClusterIds->push_back(clid->fId);
+           }
 
            float deltapad =clid->fdU;
            float deltatime =clid->fdV;
index 699eaa8..ceec5ff 100644 (file)
@@ -13,6 +13,7 @@
 ///
 
 #include "AliHLTTrackGeometry.h"
+#include <vector>
 
 class AliHLTGlobalBarrelTrack;
 class AliHLTDataDeflater;
@@ -73,12 +74,18 @@ class AliHLTTPCTrackGeometry : public AliHLTTrackGeometry
            AliHLTDataDeflater* pDeflater,
            AliHLTUInt8_t* outputPtr,
            AliHLTUInt32_t size,
+           vector<AliHLTUInt32_t>* writtenClusterIds=NULL,
            const char* option="") const;
 
   virtual int WriteAssociatedClusters(AliHLTSpacePointContainer* pSpacePoints,
                                      AliHLTDataDeflater* pDeflater,
+                                     vector<AliHLTUInt32_t>* writtenClusterIds=NULL,
                                      const char* option="") const;
 
+  int InitDriftTimeTransformation(float mA, float nA, float mC, float nC) {
+    fDriftTimeFactorA=mA; fDriftTimeOffsetA=nA; fDriftTimeFactorC=mC; fDriftTimeOffsetC=nC; return 0;
+  }
+
   struct AliHLTTPCTrackBlock {
     AliHLTUInt16_t   fSize; //! size in byte of the complete track block
     AliHLTUInt8_t    fSlice; //! slice number -> rotation angle of local coordinates
@@ -110,6 +117,11 @@ class AliHLTTPCTrackGeometry : public AliHLTTrackGeometry
 
   vector<AliHLTTrackPoint> fRawTrackPoints; // list of points in raw coordinates
 
+  float fDriftTimeFactorA; //! drift time A side
+  float fDriftTimeOffsetA; //! drift time A side
+  float fDriftTimeFactorC; //! drift time C side
+  float fDriftTimeOffsetC; //! drift time C side
+
   ClassDef(AliHLTTPCTrackGeometry, 0)
 };
 #endif
index f4f5ee2..be88a9c 100644 (file)
@@ -32,6 +32,7 @@
 #include "AliHLTDataDeflaterHuffman.h"
 #include "AliHLTTPCTransform.h"
 #include "AliHLTTPCClusterMCData.h"
+#include "AliHLTTPCClusterTransformation.h"
 #include "AliRawDataHeader.h"
 #include "AliCDBManager.h"
 #include "AliCDBPath.h"
@@ -48,6 +49,7 @@ AliHLTTPCDataCompressionComponent::AliHLTTPCDataCompressionComponent()
   : AliHLTProcessor()
   , fMode(0)
   , fDeflaterMode(0)
+  , fVerificationMode(0)
   , fMaxDeltaPad(AliHLTTPCDefinitions::GetMaxClusterDeltaPad())
   , fMaxDeltaTime(AliHLTTPCDefinitions::GetMaxClusterDeltaTime())
   , fRawInputClusters(NULL)
@@ -64,6 +66,11 @@ AliHLTTPCDataCompressionComponent::AliHLTTPCDataCompressionComponent()
   , fHistogramFile()
   , fTrainingTableOutput()
   , fpBenchmark(NULL)
+  , fpWrittenAssociatedClusterIds(NULL)
+  , fDriftTimeFactorA(1.)
+  , fDriftTimeOffsetA(0.)
+  , fDriftTimeFactorC(1.)
+  , fDriftTimeOffsetC(0.)
   , fVerbosity(0)
 {
 }
@@ -71,6 +78,7 @@ AliHLTTPCDataCompressionComponent::AliHLTTPCDataCompressionComponent()
 AliHLTTPCDataCompressionComponent::~AliHLTTPCDataCompressionComponent()
 {
   /// destructor
+  if (fpWrittenAssociatedClusterIds) delete fpWrittenAssociatedClusterIds;
 }
 
 
@@ -100,7 +108,11 @@ int AliHLTTPCDataCompressionComponent::GetOutputDataTypes(AliHLTComponentDataTyp
 {
   /// inherited from AliHLTComponent: multiple output data types of the component.
   tgtList.clear();
-  tgtList.push_back(AliHLTTPCDefinitions::fgkRawClustersDataType);
+  tgtList.push_back(AliHLTTPCDefinitions::RawClustersDataType());
+  tgtList.push_back(AliHLTTPCDefinitions::RemainingClustersCompressedDataType());
+  tgtList.push_back(AliHLTTPCDefinitions::RemainingClusterIdsDataType());
+  tgtList.push_back(AliHLTTPCDefinitions::ClusterTracksCompressedDataType());
+  tgtList.push_back(AliHLTTPCDefinitions::ClusterIdTracksDataType());
   return tgtList.size();
 }
 
@@ -108,7 +120,9 @@ void AliHLTTPCDataCompressionComponent::GetOutputDataSize( unsigned long& constB
 {
   /// inherited from AliHLTComponent: output data size estimator
   constBase=0;
-  inputMultiplier=1.3;
+  inputMultiplier=1.;  // there should not be more data than input
+  inputMultiplier+=.3; // slightly more data when using the old HWCF data with 20 Byte and raw clusters 22 Byte
+  if (fpWrittenAssociatedClusterIds) inputMultiplier+=.3; // space for optional cluster id array
 }
 
 AliHLTComponent* AliHLTTPCDataCompressionComponent::Spawn()
@@ -143,6 +157,9 @@ int AliHLTTPCDataCompressionComponent::DoEvent( const AliHLTComponentEventData&
   // Process an event
   // Loop over all input blocks in the event
   bool bHaveMC=(GetFirstInputBlock(AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo | kAliHLTDataOriginTPC))!=NULL;
+  if ((bHaveMC || fVerificationMode>0) && fpWrittenAssociatedClusterIds==NULL) {
+    fpWrittenAssociatedClusterIds=new vector<AliHLTUInt32_t>;
+  }
 
   const AliHLTComponentBlockData* pDesc=NULL;
 
@@ -233,8 +250,9 @@ int AliHLTTPCDataCompressionComponent::DoEvent( const AliHLTComponentEventData&
       }
     }
 
-    AliHLTTrackGeometry* trackpoints=new AliHLTTPCTrackGeometry;
+    AliHLTTPCTrackGeometry* trackpoints=new AliHLTTPCTrackGeometry;
     if (!trackpoints) continue;
+    trackpoints->InitDriftTimeTransformation(fDriftTimeFactorA, fDriftTimeOffsetA, fDriftTimeFactorC, fDriftTimeOffsetC);
     trackpoints->SetTrackId(trackID);
     trackpoints->CalculateTrackPoints(*track);
     trackpoints->RegisterTrackPoints(fTrackGrid);
@@ -322,8 +340,12 @@ int AliHLTTPCDataCompressionComponent::DoEvent( const AliHLTComponentEventData&
     // FIXME: decoder index instead of data specification to be used
     // use an external access grid to reduce allocated memory
     // set to NULL after writing the clusters
+    const char* writeoptions="";
+    if (fpWrittenAssociatedClusterIds) {
+      writeoptions="write-cluster-ids";
+    }
     fRawInputClusters->SetSpacePointPropertyGrid(pDesc->fSpecification, fSpacePointGrid);
-    iResult=fRawInputClusters->Write(outputPtr+size, capacity-size, outputBlocks, fpDataDeflater);
+    iResult=fRawInputClusters->Write(outputPtr+size, capacity-size, outputBlocks, fpDataDeflater, writeoptions);
     fRawInputClusters->SetSpacePointPropertyGrid(pDesc->fSpecification, NULL);
     if (iResult>=0) {
       size+=iResult;
@@ -370,6 +392,7 @@ int AliHLTTPCDataCompressionComponent::DoEvent( const AliHLTComponentEventData&
 
   // output of track model clusters
   if (iResult>=0) {
+    if (fpWrittenAssociatedClusterIds) fpWrittenAssociatedClusterIds->clear();
     iResult=WriteTrackClusters(inputTrackArray, fRawInputClusters, fpDataDeflater, outputPtr+size, capacity-size);
     if (iResult>=0) {
       AliHLTComponent_BlockData bd;
@@ -382,6 +405,19 @@ int AliHLTTPCDataCompressionComponent::DoEvent( const AliHLTComponentEventData&
       size += bd.fSize;
       outputDataSize+=bd.fSize;
       HLTBenchmark("track data block of %d tracks: size %d", inputTrackArray.size(), bd.fSize);
+
+      if (fpWrittenAssociatedClusterIds && fpWrittenAssociatedClusterIds->size()>0) {
+       AliHLTComponent::FillBlockData(bd);
+       bd.fOffset        = size;
+       bd.fSize        = fpWrittenAssociatedClusterIds->size()*sizeof(vector<AliHLTUInt32_t>::value_type);
+       memcpy(outputPtr+bd.fOffset, &(*fpWrittenAssociatedClusterIds)[0], bd.fSize);
+       bd.fDataType    = AliHLTTPCDefinitions::ClusterIdTracksDataType();
+       bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification(minSlice, maxSlice, minPatch, maxPatch);
+       outputBlocks.push_back(bd);    
+       size += bd.fSize;
+       
+       fpWrittenAssociatedClusterIds->clear();
+      }
     }
   }
 
@@ -604,7 +640,7 @@ int AliHLTTPCDataCompressionComponent::WriteTrackClusters(const vector<AliHLTGlo
       return -EBADF;
     }
 
-    int result=pTrackPoints->Write(*track, pSpacePoints, pDeflater, outputPtr+size, capacity-size);
+    int result=pTrackPoints->Write(*track, pSpacePoints, pDeflater, outputPtr+size, capacity-size, fpWrittenAssociatedClusterIds);
     if (result<0) return result;
     size+=result;
 
@@ -732,6 +768,8 @@ int AliHLTTPCDataCompressionComponent::DoInit( int argc, const char** argv )
     fHistoTrackClusterRatio=histoTrackClusterRatio.release();
   }
 
+  if (iResult>=0 && (iResult=InitDriftTimeTransformation())<0) return iResult;
+
   return iResult;
 }
 
@@ -831,6 +869,11 @@ int AliHLTTPCDataCompressionComponent::DoDeinit()
   fHistoTrackClusterRatio=NULL;
 
   if (fpDataDeflater) {
+    if (!fHistogramFile.IsNull()) {
+      TString filename=fHistogramFile;
+      filename.ReplaceAll(".root", "-deflater.root");
+      fpDataDeflater->SaveAs(filename);
+    }
     if (fDeflaterMode==3) {
       if (fTrainingTableOutput.IsNull()) {
        fTrainingTableOutput=GetComponentID();
@@ -988,3 +1031,61 @@ int AliHLTTPCDataCompressionComponent::ForwardMCLabels(const AliHLTComponentBloc
 
   return bd.fSize;
 }
+
+int AliHLTTPCDataCompressionComponent::InitDriftTimeTransformation()
+{
+  /// calculate correction factor and offset for a linear approximation of the
+  /// drift time transformation, separately for A and C side
+  int iResult=0;
+  AliHLTTPCClusterTransformation transform;
+  if ((iResult=transform.Init( GetBz(), GetTimeStamp()))<0) {
+    HLTError("failed to init AliHLTTPCClusterTransformation: %d", iResult);
+    return iResult;
+  }
+
+  if ((iResult=CalculateDriftTimeTransformation(transform, 0, 0, fDriftTimeFactorA, fDriftTimeOffsetA))<0) return iResult;
+  if (fVerbosity>0) HLTInfo("drift time transformation A side: m=%f n=%f", fDriftTimeFactorA, fDriftTimeOffsetA);
+  if ((iResult=CalculateDriftTimeTransformation(transform, 18, 0, fDriftTimeFactorC, fDriftTimeOffsetC))<0) return iResult;
+  if (fVerbosity>0) HLTInfo("drift time transformation C side: m=%f n=%f", fDriftTimeFactorC, fDriftTimeOffsetC);
+
+  return 0;
+}
+
+int AliHLTTPCDataCompressionComponent::CalculateDriftTimeTransformation(AliHLTTPCClusterTransformation& transform,
+                                                                       int slice, int padrow,
+                                                                       float& m, float& n) const
+{
+  /// calculate correction factor and offset for a linear approximation of the
+  /// drift time transformation by just probing the range of timebins with
+  /// AliHLTTPCClusterTransformation
+  const int nofSteps=100;
+  vector<float> zvalues;
+
+  int nofTimebins=AliHLTTPCTransform::GetNTimeBins();
+  int stepWidth=nofTimebins/nofSteps;
+  int time=0;
+  int count=0;
+  float meanT=0.;
+  float meanZ=0.;
+  for (time=0; time<nofTimebins; time+=stepWidth, count++) {
+    Float_t xyz[3];
+    transform.Transform(slice, padrow, 0, time, xyz);
+    zvalues.push_back(xyz[2]);
+    meanT+=time;
+    meanZ+=xyz[2];
+  }
+  meanT/=count;
+  meanZ/=count;
+  float sumTZ=.0;
+  float sumT2=.0;
+  time=0;
+  for (vector<float>::const_iterator z=zvalues.begin();
+       z!=zvalues.end(); z++, time+=stepWidth) {
+    sumTZ+=(time-meanT)*((*z)-meanZ);
+    sumT2+=(time-meanT)*(time-meanT);
+  }
+  m=sumTZ/sumT2;
+  n=meanZ-m*meanT;
+
+  return 0;
+}
index 40fb1ed..17bfce0 100644 (file)
 #include "TString.h"
 #include "AliHLTTrackGeometry.h"
 #include "AliHLTSpacePointContainer.h"
+#include <vector>
 
 class AliHLTGlobalBarrelTrack;
 class AliHLTComponentBenchmark;
 class AliHLTSpacePointContainer;
 class AliHLTDataDeflater;
+class AliHLTTPCClusterTransformation;
 class TH1F;
 
 /**
@@ -142,10 +144,19 @@ private:
 
   int InitDeflater(int mode);
 
+  /// calculate correction factor and offset for a linear approximation of the
+  /// drift time transformation, separately for A and C side
+  int InitDriftTimeTransformation();
+  /// calculate correction factor and offset for a linear approximation of the
+  /// drift time transformation by just probing the range of timebins
+  int CalculateDriftTimeTransformation(AliHLTTPCClusterTransformation& transform, int slice, int padrow,
+                                      float& m, float& n) const;
+
   AliHLTComponentBenchmark* GetBenchmarkInstance() const {return fpBenchmark;}
 
   int fMode; //! mode
   int fDeflaterMode; //! deflater mode
+  int fVerificationMode; //! mode for verification and unit tests
 
   float fMaxDeltaPad; //! maximum deviation in pad
   float fMaxDeltaTime; //! maximum deviation in time
@@ -177,6 +188,14 @@ private:
   /// benchmark
   AliHLTComponentBenchmark* fpBenchmark; //! benchmark instance
 
+  /// temporary array of ids of associated cluster ids
+  vector<AliHLTUInt32_t>* fpWrittenAssociatedClusterIds; //!
+
+  float fDriftTimeFactorA; //! drift time A side
+  float fDriftTimeOffsetA; //! drift time A side
+  float fDriftTimeFactorC; //! drift time C side
+  float fDriftTimeOffsetC; //! drift time C side
+
   /// verbosity
   int fVerbosity; // verbosity for debug printout