]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
TPC cluster finder speeded up, can process unsorted data (Kenneth); not yet enabled...
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 20 Jul 2007 11:24:05 +0000 (11:24 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 20 Jul 2007 11:24:05 +0000 (11:24 +0000)
13 files changed:
HLT/TPCLib/AliHLTTPCClusterFinder.cxx
HLT/TPCLib/AliHLTTPCClusterFinder.h
HLT/TPCLib/AliHLTTPCClusterFinderComponent.cxx
HLT/TPCLib/AliHLTTPCClusterFinderComponent.h
HLT/TPCLib/AliHLTTPCClusters.cxx [new file with mode: 0644]
HLT/TPCLib/AliHLTTPCClusters.h [new file with mode: 0644]
HLT/TPCLib/AliHLTTPCDigitReader.cxx
HLT/TPCLib/AliHLTTPCDigitReader.h
HLT/TPCLib/AliHLTTPCPad.cxx
HLT/TPCLib/AliHLTTPCPad.h
HLT/TPCLib/AliHLTTPCPadArray.cxx [new file with mode: 0644]
HLT/TPCLib/AliHLTTPCPadArray.h [new file with mode: 0644]
HLT/libAliHLTTPC.pkg

index e849656604b17a11ddeac4f639833836a3b3e7bd..505b54eb2e440400fd455903094d368d7f19cf36 100644 (file)
@@ -5,10 +5,9 @@
  * This file is property of and copyright by the ALICE HLT Project        * 
  * ALICE Experiment at CERN, All rights reserved.                         *
  *                                                                        *
- * Primary Authors: Anders Vestbo <mailto:vestbo@fi.uib.no>,             *
- *          Constantin Loizides <mailto:loizides@ikf.uni-frankfurt.de>    *
- *          Jochen Thaeder <mailto:thaeder@kip.uni-heidelberg.de>         *
- *          for The ALICE Off-line Project.                               *
+ * Primary Authors: Anders Vestbo, Constantin Loizides, Jochen Thaeder    *
+ *                  Kenneth Aamodt <kenneth.aamodt@student.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   *
@@ -20,9 +19,8 @@
  **************************************************************************/
 
 /** @file   AliHLTTPCClusterFinder.cxx
-    @author Anders Vestbo <mailto:vestbo@fi.uib.no>,                
-           Constantin Loizides <mailto:loizides@ikf.uni-frankfurt.de>
-           Jochen Thaeder <mailto:thaeder@kip.uni-heidelberg.de>     
+    @author Anders Vestbo, Constantin Loizides, Jochen Thaeder
+           Kenneth Aamodt kenneth.aamodt@student.uib.no
     @date   
     @brief  Cluster Finder for the TPC
 */
@@ -36,6 +34,7 @@
 #include "AliHLTTPCSpacePointData.h"
 #include "AliHLTTPCMemHandler.h"
 #include "AliHLTTPCPad.h"
+#include "AliHLTTPCPadArray.h"
 
 #if __GNUC__ >= 3
 using namespace std;
@@ -45,7 +44,15 @@ using namespace std;
 //
 // The current cluster finder for HLT
 // (Based on STAR L3)
-// 
+//
+//Basically we have two versions for the cluster finder now.
+//The default version, reads the data pad by pad, and find the
+//clusters as it reads the data. The other version has now been
+//developed to cope with unsorted data. New methods for the unsorted
+//version can  be found at the end of the default one i the source file.
+//Currently the new version is only build to manage zero-suppressed data.
+//More functionality will be added later.
+//
 // The cluster finder is initialized with the Init function, 
 // providing the slice and patch information to work on. 
 //
@@ -133,7 +140,8 @@ AliHLTTPCClusterFinder::AliHLTTPCClusterFinder()
   fMaxNClusters(0),
   fXYErr(0.2),
   fZErr(0.3),
-  fOccupancyLimit(1.0)
+  fOccupancyLimit(1.0),
+  fPadArray(NULL)
 {
   //constructor
 }
@@ -161,7 +169,8 @@ AliHLTTPCClusterFinder::AliHLTTPCClusterFinder(const AliHLTTPCClusterFinder& src
   fMaxNClusters(src.fMaxNClusters),
   fXYErr(src.fXYErr),
   fZErr(src.fZErr),
-  fOccupancyLimit(src.fOccupancyLimit)
+  fOccupancyLimit(src.fOccupancyLimit),
+  fPadArray(NULL)
 {
 }
 
@@ -712,3 +721,136 @@ void AliHLTTPCClusterFinder::GetTrackID(Int_t pad,Int_t time,Int_t *trackID)
   }
 }
 #endif
+
+//----------------------------------Methods for the new unsorted way of reading the data --------------------------------
+
+void AliHLTTPCClusterFinder::SetPadArray(AliHLTTPCPadArray * padArray){
+  fPadArray=padArray;
+}
+
+void AliHLTTPCClusterFinder::ReadDataUnsorted(void* ptr,unsigned long size){
+  //set input pointer
+  fPtr = (UChar_t*)ptr;
+  fSize = size;
+
+  fDigitReader->InitBlock(fPtr,fSize,fFirstRow,fLastRow,fCurrentPatch,fCurrentSlice);
+
+  fPadArray->SetDigitReader(fDigitReader);
+  fPadArray->ReadData();
+}
+void AliHLTTPCClusterFinder::FindClusters(){
+  fPadArray->FindClusterCandidates();
+  fPadArray->FindClusters(fMatch);
+  AliHLTTPCClusters clusterlist[fPadArray->fClusters.size()]; //Clusterlist
+  for(int i=0;i<fPadArray->fClusters.size();i++){
+    clusterlist[i] = fPadArray->fClusters[i];
+  }
+  WriteClusters(fPadArray->fClusters.size(),clusterlist);
+}
+void AliHLTTPCClusterFinder::WriteClusters(Int_t nclusters,AliHLTTPCClusters *list)//This is used when using the AliHLTTPCClusters class for cluster data
+{
+  //write cluster to output pointer
+  Int_t thisrow,thissector;
+  UInt_t counter = fNClusters;
+  
+  for(int j=0; j<nclusters; j++)
+    {
+      if(!list[j].fFlags) continue; //discard single pad clusters
+      if(list[j].fTotalCharge < fThreshold) continue; //noise cluster
+
+      Float_t xyz[3];      
+      Float_t fpad =(Float_t)list[j].fPad / list[j].fTotalCharge;
+      Float_t fpad2=fXYErr*fXYErr; //fixed given error
+      Float_t ftime =(Float_t)list[j].fTime / list[j].fTotalCharge;
+      Float_t ftime2=fZErr*fZErr;  //fixed given error
+
+      if(fCalcerr) { //calc the errors, otherwice take the fixed error 
+       Int_t patch = AliHLTTPCTransform::GetPatch(fCurrentRow);
+       UInt_t q2=list[j].fTotalCharge*list[j].fTotalCharge;
+       Float_t sy2=list[j].fPad2 * list[j].fTotalCharge - list[j].fPad * list[j].fPad;
+       sy2/=q2;
+       if(sy2 < 0) {
+           LOG(AliHLTTPCLog::kError,"AliHLTTPCClusterFinder::WriteClusters","Cluster width")
+             <<"SigmaY2 negative "<<sy2<<" on row "<<fCurrentRow<<" "<<fpad<<" "<<ftime<<ENDLOG;
+           continue;
+       } else {
+         if(!fRawSP){
+           fpad2 = (sy2 + 1./12)*AliHLTTPCTransform::GetPadPitchWidth(patch)*AliHLTTPCTransform::GetPadPitchWidth(patch);
+           if(sy2 != 0){
+             fpad2*=0.108; //constants are from offline studies
+             if(patch<2)
+               fpad2*=2.07;
+           }
+         } else fpad2=sy2; //take the width not the error
+       }
+       Float_t sz2=list[j].fTime2*list[j].fTotalCharge - list[j].fTime*list[j].fTime;
+       sz2/=q2;
+       if(sz2 < 0){
+         LOG(AliHLTTPCLog::kError,"AliHLTTPCClusterFinder::WriteClusters","Cluster width")
+           <<"SigmaZ2 negative "<<sz2<<" on row "<<fCurrentRow<<" "<<fpad<<" "<<ftime<<ENDLOG;
+         continue;
+       } else {
+         if(!fRawSP){
+           ftime2 = (sz2 + 1./12)*AliHLTTPCTransform::GetZWidth()*AliHLTTPCTransform::GetZWidth();
+           if(sz2 != 0) {
+             ftime2 *= 0.169; //constants are from offline studies
+             if(patch<2)
+               ftime2 *= 1.77;
+           }
+         } else ftime2=sz2; //take the width, not the error
+       }
+      }
+      if(fStdout==kTRUE)
+       cout<<"WriteCluster: padrow "<<fCurrentRow<<" pad "<<fpad << " +- "<<fpad2<<" time "<<ftime<<" +- "<<ftime2<<" charge "<<list[j].fTotalCharge<<endl;
+      
+      if(!fRawSP){
+       AliHLTTPCTransform::Slice2Sector(fCurrentSlice,fCurrentRow,thissector,thisrow);
+       AliHLTTPCTransform::Raw2Local(xyz,thissector,thisrow,fpad,ftime);
+       
+       if(xyz[0]==0) LOG(AliHLTTPCLog::kError,"AliHLTTPCClustFinder","Cluster Finder")
+         <<AliHLTTPCLog::kDec<<"Zero cluster"<<ENDLOG;
+       if(fNClusters >= fMaxNClusters)
+         {
+           LOG(AliHLTTPCLog::kError,"AliHLTTPCClustFinder::WriteClusters","Cluster Finder")
+             <<AliHLTTPCLog::kDec<<"Too many clusters "<<fNClusters<<ENDLOG;
+           return;
+         }  
+       
+       fSpacePointData[counter].fX = xyz[0];
+       fSpacePointData[counter].fY = xyz[1];
+       fSpacePointData[counter].fZ = xyz[2];
+       
+      } else {
+       fSpacePointData[counter].fX = fCurrentRow;
+       fSpacePointData[counter].fY = fpad;
+       fSpacePointData[counter].fZ = ftime;
+      }
+      
+      fSpacePointData[counter].fCharge = list[j].fTotalCharge;
+      fSpacePointData[counter].fPadRow = fCurrentRow;
+      fSpacePointData[counter].fSigmaY2 = fpad2;
+      fSpacePointData[counter].fSigmaZ2  = ftime2;
+
+      fSpacePointData[counter].fUsed = kFALSE;         // only used / set in AliHLTTPCDisplay
+      fSpacePointData[counter].fTrackN = -1;           // only used / set in AliHLTTPCDisplay
+
+      Int_t patch=fCurrentPatch;
+      if(patch==-1) patch=0; //never store negative patch number
+      fSpacePointData[counter].fID = counter
+       +((fCurrentSlice&0x7f)<<25)+((patch&0x7)<<22);//Uli
+
+#ifdef do_mc
+      Int_t trackID[3];
+      GetTrackID((Int_t)rint(fpad),(Int_t)rint(ftime),trackID);
+
+      fSpacePointData[counter].fTrackID[0] = trackID[0];
+      fSpacePointData[counter].fTrackID[1] = trackID[1];
+      fSpacePointData[counter].fTrackID[2] = trackID[2];
+
+      //cout<<"padrow "<<fCurrentRow<<" pad "<<(Int_t)rint(fpad)<<" time "<<(Int_t)rint(ftime)<<" Trackid "<<trackID[0]<<endl;
+#endif
+      
+      fNClusters++;
+      counter++;
+    }
+}
index 99857dee8bd4219e5d46d89dffc24276d4b2fe10..d1557cdddba02b3aefe47c04a7f18ea7dfed8efd 100644 (file)
@@ -1,11 +1,27 @@
 // @(#) $Id$
 // Original: AliHLTClustFinderNew.h,v 1.13 2004/06/18 10:55:26 loizides 
 
-#ifndef AliHLTTPC_ClusterFinder
-#define AliHLTTPC_ClusterFinder
+#ifndef AliHLTTPC_CLUSTERFINDER
+#define AliHLTTPC_CLUSTERFINDER
+/* 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                               */
 
-#include "AliHLTLogging.h"
+/** @file   AliHLTTPCClusterFinder.h
+    @author Anders Vestbo, Constantin Loizides, Jochen Thaeder
+           Kenneth Aamodt kenneth.aamodt@student.uib.no
+    @date   
+    @brief  Cluster Finder for the TPC
+*/
+
+// see below for class documentation
+// or
+// refer to README to build package
+// or
+// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
 
+#include "AliHLTLogging.h"
+#include "AliHLTTPCPadArray.h"
 class AliHLTTPCSpacePointData;
 class AliHLTTPCDigitReader;
 
@@ -56,6 +72,8 @@ class AliHLTTPCClusterFinder : public AliHLTLogging {
   
   Float_t fOccupancyLimit; // Occupancy Limit
 
+  AliHLTTPCPadArray * fPadArray; //! transient
+
 
 #ifdef do_mc
   void GetTrackID(Int_t pad,Int_t time,Int_t *trackID);
@@ -92,7 +110,13 @@ class AliHLTTPCClusterFinder : public AliHLTLogging {
   void SetRawSP(Bool_t f=kFALSE) {fRawSP=f;}
   void SetReader(AliHLTTPCDigitReader* f){fDigitReader = f;}
   Int_t GetNumberOfClusters() const {return fNClusters;}
+
+  //----------------------------------Methods for the new unsorted way of reading data ----------
+  void SetPadArray(AliHLTTPCPadArray *padArray);
+  void ReadDataUnsorted(void* ptr,unsigned long size);
+  void FindClusters();
+  void WriteClusters(Int_t nclusters,AliHLTTPCClusters *list);
   
-  ClassDef(AliHLTTPCClusterFinder,0) //Fast cluster finder
+  ClassDef(AliHLTTPCClusterFinder,1) //Fast cluster finder
 };
 #endif
index 6d9ffb2bff15f11af01fd87cb46f872971b62b43..e0bc9cee7198f95e06cead22e5be97b77a4c6206 100644 (file)
@@ -37,9 +37,12 @@ using namespace std;
 #include "AliHLTTPCRawDataFormat.h"
 #include "AliHLTTPCClusterDataFormat.h"
 #include "AliHLTTPCTransform.h"
+#include "AliHLTTPCClusters.h"
 #include <stdlib.h>
 #include <errno.h>
 #include "TString.h"
+#include "TStopwatch.h"
+#include <sys/time.h>
 
 // this is a global object used for automatic component registration, do not use this
 // use fPackedSwitch = true for packed inputtype "gkDDLPackedRawDataType"
@@ -56,7 +59,10 @@ AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(bool packed)
   fClusterDeconv(true),
   fXYClusterError(-1),
   fZClusterError(-1),
-  fPackedSwitch(packed)
+  fPackedSwitch(packed),
+  fPatch(0),
+  fUnsorted(0),
+  fPadArray(NULL)
 {
   // see header file for class documentation
   // or
@@ -72,7 +78,10 @@ AliHLTTPCClusterFinderComponent::AliHLTTPCClusterFinderComponent(const AliHLTTPC
   fClusterDeconv(true),
   fXYClusterError(-1),
   fZClusterError(-1),
-  fPackedSwitch(0)
+  fPackedSwitch(0),
+  fPatch(0),
+  fUnsorted(0),
+  fPadArray(NULL)
 {
   // see header file for class documentation
   HLTFatal("copy constructor untested");
@@ -229,6 +238,28 @@ int AliHLTTPCClusterFinderComponent::DoInit( int argc, const char** argv )
       continue;
     }
       
+    // -- checking for unsorted clusterfinding
+    if ( !strcmp( argv[i], "unsorted" ) ) {
+      fUnsorted = strtoul( argv[i+1], &cpErr ,0);
+      if ( *cpErr ){
+       HLTError("Cannot convert unsorted specifier '%s'. Should  be 0(off) or 1(on), must be integer", argv[i+1]);
+       return EINVAL;
+      }
+      i+=2;
+      continue;
+    }
+      
+    // -- checking for unsorted clusterfinding
+    if ( !strcmp( argv[i], "patch" ) ) {
+      fPatch = strtoul( argv[i+1], &cpErr ,0);
+      if ( *cpErr ){
+       HLTError("Cannot convert patch specifier '%s'. Should  be between 0 and 5, must be integer", argv[i+1]);
+       return EINVAL;
+      }
+      i+=2;
+      continue;
+    }
+
     Logging(kHLTLogError, "HLT::TPCClusterFinder::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
     return EINVAL;
 
@@ -246,6 +277,9 @@ int AliHLTTPCClusterFinderComponent::DoInit( int argc, const char** argv )
       else if(oldRCUFormat!=0){
        HLTWarning("Wrong oldrcuformat specifier %d; oldrcuformat set to default(kFALSE)",oldRCUFormat);
       }
+      if(fUnsorted){
+       fReader->SetUnsorted(kTRUE);
+      }
       fClusterFinder->SetReader(fReader);
 #else // ! defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
       HLTFatal("DigitReaderPacked not available - check your build");
@@ -287,6 +321,11 @@ int AliHLTTPCClusterFinderComponent::DoInit( int argc, const char** argv )
     fClusterFinder->SetCalcErr( false );
   fClusterFinder->SetSignalThreshold(sigthresh);
     
+  if(fUnsorted&&fPatch>-1&&fPatch<6){
+    fPadArray = new AliHLTTPCPadArray(fPatch);
+    fPadArray->InitializeVector();
+  }
+
   return 0;
 }
 
@@ -370,12 +409,46 @@ int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponentEventData& ev
        
       outPtr = (AliHLTTPCClusterData*)outBPtr;
 
+#ifndef KENNETH
       maxPoints = (size-tSize-sizeof(AliHLTTPCClusterData))/sizeof(AliHLTTPCSpacePointData);
+#else
+      maxPoints = (size-tSize-sizeof(AliHLTTPCClusters))/sizeof(AliHLTTPCSpacePointData);
+#endif 
 
       fClusterFinder->InitSlice( slice, patch, row[0], row[1], maxPoints );
       fClusterFinder->SetOutputArray( outPtr->fSpacePoints );
-      fClusterFinder->Read(iter->fPtr, iter->fSize );
-      fClusterFinder->ProcessDigits();
+       
+      if(fUnsorted){
+
+
+       fClusterFinder->SetPadArray(fPadArray);
+         
+       double totalT=0;
+       struct timeval startT, endT;
+       gettimeofday( &startT, NULL );
+
+       fClusterFinder->ReadDataUnsorted(iter->fPtr, iter->fSize );
+
+       gettimeofday( &endT, NULL );
+       unsigned long long dt;
+       dt = endT.tv_sec-startT.tv_sec;
+       dt *= 1000000ULL;
+       dt += endT.tv_usec-startT.tv_usec;
+       double dtd = ((double)dt);
+       totalT += dtd;
+       //        dtd = dtd / (double)eventIterations;
+       //        if ( iterations<=1 )
+       cout<<endl;
+       printf( "Time needed to read data: %f microsec. / %f millisec. / %f s\n", 
+               dtd, dtd/1000.0, dtd/1000000.0 );
+         
+       cout<<endl;
+       fClusterFinder->FindClusters();
+      }
+      else{
+       fClusterFinder->Read(iter->fPtr, iter->fSize );
+       fClusterFinder->ProcessDigits();
+      }
       realPoints = fClusterFinder->GetNumberOfClusters();
        
       Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Spacepoints", 
@@ -383,7 +456,11 @@ int AliHLTTPCClusterFinderComponent::DoEvent( const AliHLTComponentEventData& ev
        
       outPtr->fSpacePointCnt = realPoints;
       nSize = sizeof(AliHLTTPCSpacePointData)*realPoints;
+#ifndef KENNETH
       mysize += nSize+sizeof(AliHLTTPCClusterData);
+#else
+      mysize += nSize+sizeof(AliHLTTPCClusters);
+#endif 
        
       Logging( kHLTLogDebug, "HLT::TPCClusterFinder::DoEvent", "Input Spacepoints", 
               "Number of spacepoints: %lu Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
index 03c8fa9adc289ea730a3e3494e9aef3b57190e11..4c38d4f91df000bf48cd35fb85eedee325c9d180 100644 (file)
@@ -3,7 +3,8 @@
 #ifndef ALIHLTTPCCLUSTERFINDERCOMPONENT_H
 #define ALIHLTTPCCLUSTERFINDERCOMPONENT_H
 
-/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+/* 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   AliHLTTPCClusterFinderComponent.h
@@ -19,6 +20,7 @@
 #include "AliHLTTPCDigitReaderRaw.h"
 
 class AliHLTTPCClusterFinder;
+class AliHLTTPCPadArray;
 
 /**
  * @class AliHLTTPCClusterFinderComponent
@@ -31,11 +33,14 @@ class AliHLTTPCClusterFinder;
  * instantiate different digit readers depending on the arguments.
  * 
  * The component has the following component arguments:
- * - rawreadermode   the mode for the @ref AliHLTTPCDigitReaderRaw
+ * - rawreadermode   the mode for the @ref AliHLTTPCDigitReaderRaw, use -2 if using unsorted
  * - adc-threshold   ADC count threshold for zero suppression, if <0 the base line
  *                   calculation and subtraction is switched off
  * - pp-run          set parameters specific to a pp run; currently this switches
- *                   cluster deconvolution off for pp runs
+ *                   cluster deconvolution off for pp runs (not true for unsorted reading)
+ * - unsorted        if 1 the data will be read unsorted in to a PadArray object. This should
+ *                   only be done on patch level since it use a lot of memory
+ * - patch           specify on which patch to resd the data unsorted
  *
  * @ingroup alihlt_tpc
  */
@@ -96,7 +101,25 @@ class AliHLTTPCClusterFinderComponent : public AliHLTProcessor
        */
       Int_t fPackedSwitch;                                                           // see above
       
-      ClassDef(AliHLTTPCClusterFinderComponent, 0)
+      /*
+       * Reads the data the new unsorted way if true
+       *
+       */
+      Int_t fUnsorted;                                                               //!transient
+
+      /*
+       * Patch number to be read, currently given as component argument,
+       * will be changed later.
+       */
+      Int_t fPatch;                                                                  //!transient
+
+      /*
+       * Pointer to a PadArray object containing a double array of all the pads in
+       * the current patch.
+       */
+      AliHLTTPCPadArray * fPadArray;                                                 //!transient
+
+      ClassDef(AliHLTTPCClusterFinderComponent, 1)
 
     };
 #endif
diff --git a/HLT/TPCLib/AliHLTTPCClusters.cxx b/HLT/TPCLib/AliHLTTPCClusters.cxx
new file mode 100644 (file)
index 0000000..b71673a
--- /dev/null
@@ -0,0 +1,68 @@
+#if __GNUC__>= 3
+using namespace std;
+#endif
+
+#include <cerrno>
+#include "AliHLTTPCPadArray.h"
+#include "AliHLTTPCPad.h"
+#include "AliHLTStdIncludes.h"
+#include "AliHLTTPCTransform.h"
+#include "AliTPCRawStream.h"
+#include "AliRawReaderMemory.h"
+#include "AliHLTTPCDigitReader.h"
+#include <vector>
+#include "AliHLTTPCClusters.h"
+/** ROOT macro for the implementation of ROOT specific class methods */
+//ClassImp(AliHLTTPCClusters)
+
+AliHLTTPCClusters::AliHLTTPCClusters()
+  :
+  fTotalCharge(0),
+  fPad(0),
+  fTime(0),
+  fPad2(0),
+  fTime2(0),
+  fMean(0),
+  fFlags(1),
+  fChargeFalling(0),
+  fLastCharge(0),
+  fLastMergedPad(0),
+  fFirstPad(0),
+  fLastPad(0),
+  fRowNumber(0)
+{
+
+}
+AliHLTTPCClusters::AliHLTTPCClusters(const AliHLTTPCClusters& src)
+  :
+  fTotalCharge(src.fTotalCharge),
+  fPad(src.fPad),
+  fTime(src.fTime),
+  fPad2(src.fPad2),
+  fTime2(src.fTime2),
+  fMean(src.fMean),
+  fFlags(src.fFlags),
+  fChargeFalling(src.fChargeFalling),
+  fLastCharge(src.fLastCharge),
+  fLastMergedPad(src.fLastMergedPad),
+  fFirstPad(src.fFirstPad),
+  fLastPad(src.fLastPad),
+  fRowNumber(src.fRowNumber)
+{
+  //HLTInfo("Copy constructor called");
+}
+AliHLTTPCClusters& AliHLTTPCClusters::operator=(const AliHLTTPCClusters& src){
+  fTotalCharge=src.fTotalCharge;
+  fPad = src.fPad;
+  fTime = src.fTime;
+  fPad2 = src.fPad2;
+  fTime2 = src.fTime2;
+  fMean = src.fMean;
+  fFlags = src.fFlags;
+  fChargeFalling = src.fChargeFalling;
+  fLastCharge = src.fLastCharge;
+  fLastMergedPad = src.fLastMergedPad;
+  fFirstPad = src.fFirstPad;
+  fRowNumber= src.fRowNumber;
+  return (*this);
+}
diff --git a/HLT/TPCLib/AliHLTTPCClusters.h b/HLT/TPCLib/AliHLTTPCClusters.h
new file mode 100644 (file)
index 0000000..1d56597
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef ALIHLTTPCCLUSTERS
+#define ALIHLTTPCCLUSTERS
+
+#include "AliHLTLogging.h"
+
+class AliHLTTPCClusters : public AliHLTLogging {
+
+ public:
+  AliHLTTPCClusters();
+  AliHLTTPCClusters(const AliHLTTPCClusters& src);
+  AliHLTTPCClusters& operator=(const AliHLTTPCClusters&);
+
+  UInt_t fTotalCharge;   //tot charge of cluster
+  UInt_t fPad;           //pad value
+  UInt_t fTime;          //time value
+  ULong64_t fPad2;       //for error in XY direction
+  ULong64_t fTime2;      //for error in Z  direction
+  UInt_t fMean;          //mean in time
+  UInt_t fFlags;         //different flags
+  UInt_t fChargeFalling; //for deconvolution
+  UInt_t fLastCharge;    //for deconvolution
+  UInt_t fLastMergedPad; //dont merge twice per pad
+  UInt_t fRowNumber;
+  Int_t fFirstPad;
+  UInt_t fLastPad;
+  ClassDef(AliHLTTPCClusters,0) //Fast cluster finder
+    };
+#endif
index 667b3e23a21eabc5c0f0ab505e009d71d13f29a5..c0f640c50ecf85871a15b384320b7503d787a2e8 100644 (file)
@@ -59,3 +59,5 @@ int AliHLTTPCDigitReader::InitBlock(void* ptr,unsigned long size,Int_t firstrow,
 void AliHLTTPCDigitReader::SetOldRCUFormat(Bool_t /*oldrcuformat*/)
 {
 }
+void AliHLTTPCDigitReader::SetUnsorted(Bool_t /*unsorted*/){
+}
index 86fd9cb4626a8b1192aa89e327a94d9261c94fe5..e569f1df2ce86cd11d3d08d3f5b09796a24c6a7f 100644 (file)
@@ -4,7 +4,8 @@
 #ifndef ALIHLTTPCDIGITREADER_H
 #define ALIHLTTPCDIGITREADER_H
 
-/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+/* 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   AliHLTTPCDigitReader.h
@@ -91,6 +92,11 @@ public:
    */
   virtual void SetOldRCUFormat(Bool_t oldrcuformat);
 
+  /**
+   * Method to set read unsorted flag.
+   */
+  virtual void SetUnsorted(Bool_t unsorted);
+
 protected:
        
 private:
index 6bdd2f6054f5ffcfb3b788ec06422cdc2b55f434..0d49c603c7c03a43957d2300b85f273ca711efe7 100644 (file)
@@ -5,6 +5,7 @@
  * ALICE Experiment at CERN, All rights reserved.                         *
  *                                                                        *
  * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
+ *                  Kenneth Aamodt   <Kenneth.aamodt@ift.uib.no>          *
  *                  for The ALICE HLT Project.                            *
  *                                                                        *
  * Permission to use, copy, modify and distribute this software and its   *
@@ -17,7 +18,7 @@
  **************************************************************************/
 
 /** @file   AliHLTTPCPad.cxx
-    @author Matthias Richter
+    @author Matthias Richter, Kenneth Aamodt
     @date   
     @brief  Container Class for TPC Pads.
 */
@@ -30,6 +31,13 @@ using namespace std;
 #include "AliHLTTPCPad.h"
 #include "AliHLTStdIncludes.h"
 
+
+//added by kenneth
+#include "AliHLTTPCTransform.h"
+#include "AliHLTTPCClusters.h"
+#include <sys/time.h>
+//------------------------------
+
 /** margin for the base line be re-avaluated */
 #define ALIHLTPAD_BASELINE_MARGIN (2*fAverage)
 
@@ -53,13 +61,25 @@ AliHLTTPCPad::AliHLTTPCPad()
   fFirstBLBin(0),
   fNofBins(0),
   fReadPos(0),
-  fpRawData(NULL)
+  fpRawData(NULL),
+  fClusterCandidates(),
+  fUsedClusterCandidates(0),
+  fDataSignals(NULL),
+  fSignalPositionArray(NULL),
+  fSizeOfSignalPositionArray(0)
 {
   // see header file for class documentation
   // or
   // refer to README to build package
   // or
   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+  //  HLTInfo("Entering default constructor");
+  fDataSignals= new AliHLTTPCSignal_t[AliHLTTPCTransform::GetNTimeBins()];
+  memset( fDataSignals, 0xFF, sizeof(Int_t)*(AliHLTTPCTransform::GetNTimeBins()));
+
+  fSignalPositionArray= new AliHLTTPCSignal_t[AliHLTTPCTransform::GetNTimeBins()];
+  memset( fSignalPositionArray, 0xFF, sizeof(Int_t)*(AliHLTTPCTransform::GetNTimeBins()));
+  fSizeOfSignalPositionArray=0;
 }
 
 AliHLTTPCPad::AliHLTTPCPad(Int_t offset, Int_t nofBins)
@@ -79,7 +99,12 @@ AliHLTTPCPad::AliHLTTPCPad(Int_t offset, Int_t nofBins)
   fFirstBLBin(offset),
   fNofBins(nofBins),
   fReadPos(0),
-  fpRawData(NULL)
+  fpRawData(NULL),
+  fClusterCandidates(),
+  fUsedClusterCandidates(0),
+  fDataSignals(NULL),
+  fSignalPositionArray(NULL),
+  fSizeOfSignalPositionArray(0)
 {
   // see header file for class documentation
 }
@@ -101,7 +126,12 @@ AliHLTTPCPad::AliHLTTPCPad(const AliHLTTPCPad& srcPad)
   fFirstBLBin(0),
   fNofBins(0),
   fReadPos(0),
-  fpRawData(NULL)
+  fpRawData(NULL),
+  fClusterCandidates(),
+  fUsedClusterCandidates(0),
+  fDataSignals(NULL),
+  fSignalPositionArray(NULL),
+  fSizeOfSignalPositionArray(0)
 {
   // see header file for class documentation
   HLTFatal("copy constructor not implemented");
@@ -121,6 +151,17 @@ AliHLTTPCPad::~AliHLTTPCPad()
     HLTWarning("event data acquisition not stopped");
     StopEvent();
   }
+  if (fDataSignals) {
+    AliHLTTPCSignal_t* pData=fDataSignals;
+    fDataSignals=NULL;
+   delete [] pData;
+  }
+  if (fSignalPositionArray) {
+    AliHLTTPCSignal_t* pData=fSignalPositionArray;
+    fSignalPositionArray=NULL;
+    //   delete [] pData;
+  }
+
 }
 
 Int_t AliHLTTPCPad::SetID(Int_t rowno, Int_t padno)
@@ -423,3 +464,142 @@ Float_t AliHLTTPCPad::GetAveragedOccupancy() const
   // history is not yet implemented
   return GetOccupancy();
 }
+void AliHLTTPCPad::PrintRawData(){
+  for(Int_t bin=0;bin<AliHLTTPCTransform::GetNTimeBins();bin++){
+    if(GetDataSignal(bin)>0)
+      cout<<fRowNo<<"\t"<<fPadNo<<"\t"<<bin<<"\t"<<GetDataSignal(bin)<<endl;;
+  }
+  cout<<"bins: "<<AliHLTTPCTransform::GetNTimeBins()<<endl;
+}
+
+void AliHLTTPCPad::SetDataToDefault(){
+  if(fpRawData){
+    memset( fDataSignals, 0xFF, sizeof(Int_t)*(AliHLTTPCTransform::GetNTimeBins()));
+    memset( fSignalPositionArray, 0xFF, sizeof(Int_t)*(AliHLTTPCTransform::GetNTimeBins()));
+    fSizeOfSignalPositionArray=0;
+  }
+}
+void AliHLTTPCPad::SetDataSignal(Int_t bin,Int_t signal){
+  fDataSignals[bin]=signal;
+  fSignalPositionArray[fSizeOfSignalPositionArray]=bin;
+  fSizeOfSignalPositionArray++;
+}
+Int_t AliHLTTPCPad::GetDataSignal(Int_t bin){
+  return fDataSignals[bin];
+}
+void AliHLTTPCPad::FindClusterCandidates(){
+  UInt_t seqcharge=0;
+  UInt_t seqaverage=0;
+  UInt_t seqerror=0;
+  vector<Int_t> tmpPos;
+  vector<Int_t> tmpSig;
+  UInt_t isFalling=0;
+
+  for(Int_t pos=fSizeOfSignalPositionArray-2;pos>=0;pos--){
+
+    if(fSignalPositionArray[pos]==fSignalPositionArray[pos+1]+1){
+      seqcharge+=fDataSignals[fSignalPositionArray[pos+1]];    
+      seqaverage += fSignalPositionArray[pos+1]*fDataSignals[fSignalPositionArray[pos+1]];
+      seqerror += fSignalPositionArray[pos+1]*fSignalPositionArray[pos+1]*fDataSignals[fSignalPositionArray[pos+1]];
+         
+      tmpPos.push_back(fSignalPositionArray[pos+1]);
+      tmpSig.push_back(fDataSignals[fSignalPositionArray[pos+1]]);
+
+      if(fDataSignals[fSignalPositionArray[pos+1]]>fDataSignals[fSignalPositionArray[pos]]){
+       isFalling=1;
+      }
+      if(fDataSignals[fSignalPositionArray[pos+1]]<fDataSignals[fSignalPositionArray[pos]]&&isFalling){
+       Int_t seqmean=0;
+       seqmean = seqaverage/seqcharge;
+       
+       //Calculate mean in pad direction:
+       Int_t padmean = seqcharge*fPadNo;
+       Int_t paderror = fPadNo*padmean;
+       AliHLTTPCClusters candidate;
+       candidate.fTotalCharge   = seqcharge;
+       candidate.fPad       = padmean;
+       candidate.fPad2      = paderror;
+       candidate.fTime      = seqaverage;
+       candidate.fTime2     = seqerror;
+       candidate.fMean          = seqmean;
+       candidate.fLastMergedPad = fPadNo;
+       fClusterCandidates.push_back(candidate);
+       fUsedClusterCandidates.push_back(0);
+       isFalling=0;
+       seqcharge=0;
+       seqaverage=0;
+       seqerror=0;
+
+       tmpPos.clear();
+       tmpSig.clear();
+
+       continue;
+      }
+        
+      if(pos<1){
+       seqcharge+=fDataSignals[fSignalPositionArray[0]];       
+       seqaverage += fSignalPositionArray[0]*fDataSignals[fSignalPositionArray[0]];
+       seqerror += fSignalPositionArray[0]*fSignalPositionArray[0]*fDataSignals[fSignalPositionArray[0]];
+       tmpPos.push_back(fSignalPositionArray[0]);
+       tmpSig.push_back(fDataSignals[fSignalPositionArray[0]]);
+         
+       //Calculate mean of sequence:
+       Int_t seqmean=0;
+       seqmean = seqaverage/seqcharge;
+         
+       //Calculate mean in pad direction:
+       Int_t padmean = seqcharge*fPadNo;
+       Int_t paderror = fPadNo*padmean;
+       AliHLTTPCClusters candidate;
+       candidate.fTotalCharge   = seqcharge;
+       candidate.fPad       = padmean;
+       candidate.fPad2      = paderror;
+       candidate.fTime      = seqaverage;
+       candidate.fTime2     = seqerror;
+       candidate.fMean          = seqmean;
+       candidate.fLastMergedPad = fPadNo;
+       fClusterCandidates.push_back(candidate);
+       fUsedClusterCandidates.push_back(0);
+       isFalling=0;
+       seqcharge=0;
+       seqaverage=0;
+       seqerror=0;
+
+       tmpPos.clear();
+       tmpSig.clear();
+      }
+    }
+    else if(seqcharge>0){
+      seqcharge+=fDataSignals[fSignalPositionArray[pos+1]];    
+      seqaverage += fSignalPositionArray[pos+1]*fDataSignals[fSignalPositionArray[pos+1]];
+       seqerror += fSignalPositionArray[pos+1]*fSignalPositionArray[pos+1]*fDataSignals[fSignalPositionArray[pos+1]];
+       tmpPos.push_back(fSignalPositionArray[pos+1]);
+       tmpSig.push_back(fDataSignals[fSignalPositionArray[pos+1]]);
+
+       //Calculate mean of sequence:
+       Int_t seqmean=0;
+       seqmean = seqaverage/seqcharge;
+       
+       //Calculate mean in pad direction:
+       Int_t padmean = seqcharge*fPadNo;
+       Int_t paderror = fPadNo*padmean;
+       AliHLTTPCClusters candidate;
+       candidate.fTotalCharge   = seqcharge;
+       candidate.fPad       = padmean;
+       candidate.fPad2      = paderror;
+       candidate.fTime      = seqaverage;
+       candidate.fTime2     = seqerror;
+       candidate.fMean          = seqmean;
+       candidate.fLastMergedPad = fPadNo;
+       fClusterCandidates.push_back(candidate);
+       fUsedClusterCandidates.push_back(0);
+       isFalling=0;
+       seqcharge=0;
+       seqaverage=0;
+       seqerror=0;
+
+       tmpPos.clear();
+       tmpSig.clear();
+    }
+  }
+}
index a1ecf2f1d5d9ae5c03c501f7729d5e40ce90712c..82b264edfdbeec0fa2a9292870f7aeddc540c548 100644 (file)
@@ -3,7 +3,8 @@
 
 #ifndef ALIHLTPAD_H
 #define ALIHLTPAD_H
-/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+/* 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   AliHLTTPCPad.h
@@ -13,6 +14,8 @@
 */
 
 #include "AliHLTLogging.h"
+#include "AliHLTTPCClusters.h"
+#include <vector>
 
 typedef Int_t AliHLTTPCSignal_t;
 
@@ -29,7 +32,7 @@ typedef Int_t AliHLTTPCSignal_t;
  * @ingroup alihlt_tpc
  */
 class AliHLTTPCPad : public AliHLTLogging {
- public:
+public:
   /** standard constructor */
   AliHLTTPCPad();
 
@@ -48,6 +51,24 @@ class AliHLTTPCPad : public AliHLTLogging {
   /** standard destructor */
   virtual ~AliHLTTPCPad();
 
+  
+  struct AliClusterData
+  {
+    UInt_t fTotalCharge;   //tot charge of cluster
+    UInt_t fPad;       //pad value
+    UInt_t fTime;      //time value
+    ULong64_t fPad2;   //for error in XY direction
+    ULong64_t fTime2;  //for error in Z  direction
+    UInt_t fMean;          //mean in time
+    UInt_t fFlags;         //different flags
+    UInt_t fChargeFalling; //for deconvolution
+    UInt_t fLastCharge;    //for deconvolution
+    UInt_t fLastMergedPad; //dont merge twice per pad
+  }; 
+
+  typedef struct AliClusterData AliClusterData; //!
+
+
   /**
    * Set the address the pad.
    * The address consists of row and pad number.
@@ -223,7 +244,41 @@ class AliHLTTPCPad : public AliHLTLogging {
    * Get the size (number of time bins) of the pad
    * @return number of bins 
    */
-   Int_t GetSize() const {return fNofBins;}
+  Int_t GetSize() const {return fNofBins;}
+  
+  /**
+   * Set the data array to -1
+   */
+  void SetDataToDefault();
+  /**
+   * Stores the signal in the data array, stores the timebin number of the signal,
+   * and increments a counter.
+   */
+  void SetDataSignal(Int_t bin,Int_t signal);
+
+  /**
+   * Returns the signal in the specified bin
+   */
+  Int_t GetDataSignal(Int_t bin);
+  /**
+   * Finds the cluster candidate. If atleast two signals in the data array are neighbours
+   * they are stored in a cluster candidate vector.
+   */
+  void FindClusterCandidates();
+  /**
+   * Prints the raw data og this pad.
+   */
+  void PrintRawData();
+  /**
+   * Vector of cluster candidates
+   */
+  vector<AliHLTTPCClusters> fClusterCandidates;
+
+  /**
+   * Vector of used clustercandidates, used so one do not use candidates multiple times
+   */
+  vector<Int_t> fUsedClusterCandidates;
 
  private:
   /**
@@ -270,6 +325,17 @@ class AliHLTTPCPad : public AliHLTLogging {
   /** The raw data history */
   AliHLTTPCSignal_t* fpRawData;                                    //! transient
 
+  /**
+   * Array containing the data
+   */
+  AliHLTTPCSignal_t* fDataSignals;
+
+  /**
+   * Array containing info on which bins have signals
+   */
+  Int_t *fSignalPositionArray;
+  Int_t fSizeOfSignalPositionArray;
+
   ClassDef(AliHLTTPCPad, 0)
 };
 #endif
diff --git a/HLT/TPCLib/AliHLTTPCPadArray.cxx b/HLT/TPCLib/AliHLTTPCPadArray.cxx
new file mode 100644 (file)
index 0000000..84d2c2e
--- /dev/null
@@ -0,0 +1,366 @@
+// @(#) $Id$
+
+/**************************************************************************
+ * This file is property of and copyright by the ALICE HLT Project        * 
+ * ALICE Experiment at CERN, All rights reserved.                         *
+ *                                                                        *
+ * Authors: Kenneth Aamodt <Kenneth.Aamodt@student.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   AliHLTTPCPadArray.cxx
+    @author Kenneth Aamodt
+    @date   
+    @brief  Class containing TPC Pad objects.
+*/
+
+#if __GNUC__>= 3
+using namespace std;
+#endif
+
+#include <cerrno>
+#include "AliHLTTPCPadArray.h"
+#include "AliHLTTPCPad.h"
+#include "AliHLTStdIncludes.h"
+#include "AliHLTTPCTransform.h"
+#include "AliHLTTPCDigitReader.h"
+#include "AliHLTTPCClusters.h"
+#include <vector>
+#include <sys/time.h>
+
+/** ROOT macro for the implementation of ROOT specific class methods */
+ClassImp(AliHLTTPCPadArray)
+
+AliHLTTPCPadArray::AliHLTTPCPadArray()
+  :
+  fPatch(-1),
+  fFirstRow(-1),
+  fLastRow(-1),
+  fThreshold(10)
+{
+  // see header file for class documentation
+  // or
+  // refer to README to build package
+  // or
+  // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+}
+
+AliHLTTPCPadArray::AliHLTTPCPadArray(Int_t patch)
+  :
+  fPatch(patch),
+  fFirstRow(-1),
+  fLastRow(-1),
+  fThreshold(10)
+{
+  // see header file for class documentation
+}
+
+AliHLTTPCPadArray::AliHLTTPCPadArray(const AliHLTTPCPadArray& srcPadArray)
+  :
+  fPatch(srcPadArray.fPatch),
+  fFirstRow(srcPadArray.fFirstRow),
+  fLastRow(srcPadArray.fLastRow)
+{
+  // see header file for class documentation
+  HLTFatal("copy constructor not implemented");
+}
+
+AliHLTTPCPadArray& AliHLTTPCPadArray::operator=(const AliHLTTPCPadArray&)
+{
+  // see header file for class documentation
+  HLTFatal("assignment operator not implemented");
+  return (*this);
+}
+
+AliHLTTPCPadArray::~AliHLTTPCPadArray()
+{
+  // see header file for class documentation
+}
+
+Int_t AliHLTTPCPadArray::InitializeVector(){
+  // see header file for class documentation
+
+  if(fPatch>5||fPatch<0){
+    HLTFatal("Patch is not set");
+    return 0;
+  }
+
+  fFirstRow = AliHLTTPCTransform::GetFirstRow(fPatch);
+  fLastRow = AliHLTTPCTransform::GetLastRow(fPatch);
+
+  fNumberOfRows=fLastRow-fFirstRow+1;
+  fNumberOfPadsInRow= new Int_t[fNumberOfRows];
+
+  memset( fNumberOfPadsInRow, 0, sizeof(Int_t)*(fNumberOfRows));
+
+  for(Int_t i=0;i<fNumberOfRows;i++){
+    fNumberOfPadsInRow[i]=AliHLTTPCTransform::GetNPads(i+fFirstRow);
+    fPadVector tmpRow;
+    for(Int_t j=0;j<fNumberOfPadsInRow[i];j++){
+      AliHLTTPCPad *tmpPad = new AliHLTTPCPad();
+      tmpPad->SetID(i,j);
+      tmpRow.push_back(tmpPad);
+    }
+    fRowPadVector.push_back(tmpRow);
+  }
+}
+
+Int_t AliHLTTPCPadArray::DeInitializeVector(){
+  for(Int_t i=0;i<fNumberOfRows;i++){
+    for(Int_t j=0;j<fNumberOfPadsInRow[i];j++){
+      delete fRowPadVector[i][j];
+    }
+    fRowPadVector[i].clear();
+  }
+  fRowPadVector.clear();
+  return 1;
+} 
+void AliHLTTPCPadArray::SetPatch(Int_t patch){
+  fPatch=patch;
+}
+
+void AliHLTTPCPadArray::SetDigitReader(AliHLTTPCDigitReader* digitReader){
+  fDigitReader=digitReader;
+}
+Int_t AliHLTTPCPadArray::ReadData(){
+
+  switch (fPatch){
+  case 0:
+    while(fDigitReader->Next()){
+      fRowPadVector[fDigitReader->GetRow()-fFirstRow][fDigitReader->GetPad()]->SetDataSignal(fDigitReader->GetTime(),fDigitReader->GetSignal());
+    }
+    
+  case 1:
+    while(fDigitReader->Next()){
+      fRowPadVector[fDigitReader->GetRow()-fFirstRow][fDigitReader->GetPad()]->SetDataSignal(fDigitReader->GetTime(),fDigitReader->GetSignal());      
+    }
+  case 2:
+    while(fDigitReader->Next()){
+      fRowPadVector[fDigitReader->GetRow()][fDigitReader->GetPad()]->SetDataSignal(fDigitReader->GetTime(),fDigitReader->GetSignal());
+    }
+  case 3:
+    while(fDigitReader->Next()){
+      fRowPadVector[fDigitReader->GetRow()-27][fDigitReader->GetPad()]->SetDataSignal(fDigitReader->GetTime(),fDigitReader->GetSignal());
+    }
+  case 4:
+    while(fDigitReader->Next()){
+      fRowPadVector[fDigitReader->GetRow()-54][fDigitReader->GetPad()]->SetDataSignal(fDigitReader->GetTime(),fDigitReader->GetSignal());
+    }
+  case 5:
+    while(fDigitReader->Next()){
+      fRowPadVector[fDigitReader->GetRow()-76][fDigitReader->GetPad()]->SetDataSignal(fDigitReader->GetTime(),fDigitReader->GetSignal());
+    }
+  }
+}
+void AliHLTTPCPadArray::FindClusters(Int_t match){
+  //see header file for documentation
+  Int_t nClusters=0;
+  Int_t totalChargeOfPreviousCandidate=0;
+  Int_t clusterChargeIsFalling=0;
+  for(Int_t row=0;row<fNumberOfRows;row++){
+    for(Int_t pad=0;pad<fNumberOfPadsInRow[row]-1;pad++){
+      AliHLTTPCPad *tmp1=fRowPadVector[row][pad];
+      AliHLTTPCPad *tmp2=fRowPadVector[row][pad+1];
+      for(Int_t c1=0;c1<tmp1->fClusterCandidates.size();c1++){
+
+       if(tmp1->fUsedClusterCandidates[c1]){
+         continue;
+       }
+
+       for(Int_t c2=0;c2<tmp2->fClusterCandidates.size();c2++){
+
+         if(tmp2->fUsedClusterCandidates[c2]){
+           continue;
+         }
+
+         Int_t diff= tmp1->fClusterCandidates[c1].fMean - tmp2->fClusterCandidates[c2].fMean;
+
+         if(diff < -match){
+           break;
+         }
+         if(diff <= match){
+
+           if((Int_t)(tmp1->fClusterCandidates[c1].fTotalCharge - tmp2->fClusterCandidates[c2].fTotalCharge)>0){
+             clusterChargeIsFalling=1;
+           }
+
+           tmp1->fUsedClusterCandidates[c1]=1;
+           tmp2->fUsedClusterCandidates[c2]=1;
+
+           AliHLTTPCClusters tmpCluster;
+           tmpCluster.fTotalCharge = tmp1->fClusterCandidates[c1].fTotalCharge;
+           tmpCluster.fPad     = tmp1->fClusterCandidates[c1].fPad;
+           tmpCluster.fPad2    = tmp1->fClusterCandidates[c1].fPad2;
+           tmpCluster.fTime    = tmp1->fClusterCandidates[c1].fTime;
+           tmpCluster.fTime2   = tmp1->fClusterCandidates[c1].fTime2;
+           tmpCluster.fRowNumber = row;
+
+           tmpCluster.fTotalCharge += tmp2->fClusterCandidates[c2].fTotalCharge;
+           tmpCluster.fPad     += tmp2->fClusterCandidates[c2].fPad;
+           tmpCluster.fPad2    += tmp2->fClusterCandidates[c2].fPad2;
+           tmpCluster.fTime    += tmp2->fClusterCandidates[c2].fTime;
+           tmpCluster.fTime2   += tmp2->fClusterCandidates[c2].fTime2;
+           tmpCluster.fMean         = tmp2->fClusterCandidates[c2].fMean;
+           totalChargeOfPreviousCandidate = tmp2->fClusterCandidates[c2].fTotalCharge;
+
+           int rowNumber=row;
+           int lastPad=pad+1;
+           nClusters++;
+           Int_t doBreak=0;
+           for(Int_t morePads=pad+2;morePads<fNumberOfPadsInRow[row];morePads++){
+             AliHLTTPCPad *tmpx=fRowPadVector[row][morePads];
+             if(morePads>lastPad+1){
+               break;
+             }
+             for(Int_t cx=0;cx<tmpx->fClusterCandidates.size();cx++){
+               if(tmpx->fUsedClusterCandidates[cx]){
+                 continue;
+               }
+               Int_t diffx=tmpCluster.fMean - tmpx->fClusterCandidates[cx].fMean;
+               if(diffx<-match){
+                 doBreak=1;
+                 break;
+               }
+               if(diffx <= match){
+                 if((Int_t)(totalChargeOfPreviousCandidate - tmpx->fClusterCandidates[cx].fTotalCharge)>0){
+                   clusterChargeIsFalling=1;
+                 }
+
+                 if(clusterChargeIsFalling&&(Int_t)(totalChargeOfPreviousCandidate - tmpx->fClusterCandidates[cx].fTotalCharge)<=0){
+                   //Means we have a deconvoluted cluster.
+                   totalChargeOfPreviousCandidate=0;
+                   doBreak=1;
+                   break;
+                 }
+                 
+                 tmpx->fUsedClusterCandidates[cx]=1;
+                 tmpCluster.fTotalCharge += tmpx->fClusterCandidates[cx].fTotalCharge;
+                 tmpCluster.fPad     += tmpx->fClusterCandidates[cx].fPad;
+                 tmpCluster.fPad2    += tmpx->fClusterCandidates[cx].fPad2;
+                 tmpCluster.fTime    += tmpx->fClusterCandidates[cx].fTime;
+                 tmpCluster.fTime2   += tmpx->fClusterCandidates[cx].fTime2;
+                 tmpCluster.fMean         = tmpx->fClusterCandidates[cx].fMean;
+                 lastPad=morePads;
+
+                 totalChargeOfPreviousCandidate=tmpx->fClusterCandidates[cx].fTotalCharge;
+               }
+             }
+             if(doBreak){
+               break;
+             }
+           }
+           
+           if(tmpCluster.fTotalCharge<fThreshold){
+             nClusters--;
+           }
+           else{
+             //Code to look for tails, TODO insert flag.
+             UInt_t meanTime=tmpCluster.fMean;
+             if(pad>0){
+               AliHLTTPCPad *tmpBefore=fRowPadVector[row][pad-1];
+               //checking the fMean -1 timebin for single timebin value in the pad before the cluster
+               if(meanTime>0){
+                 Int_t charge =tmpBefore->GetDataSignal(meanTime-1); 
+                 if(charge){
+                   tmpCluster.fTotalCharge+= charge;
+                   tmpCluster.fPad        += charge*(pad-1);
+                   tmpCluster.fPad2       += charge*(pad-1)*(pad-1); 
+                   tmpCluster.fTime       += meanTime*charge;
+                   tmpCluster.fTime2      += meanTime*charge*charge;
+                 } 
+               }
+               //checking the fMean timebin for single timebin value in the pad before the cluster
+               Int_t charge2 =tmpBefore->GetDataSignal(meanTime); 
+               if(charge2){
+                 tmpCluster.fTotalCharge+= charge2;
+                 tmpCluster.fPad        += charge2*(pad);
+                 tmpCluster.fPad2       += charge2*(pad)*(pad); 
+                 tmpCluster.fTime       += meanTime*charge2;
+                 tmpCluster.fTime2      += meanTime*charge2*charge2;
+               } 
+               //checking the fMean +1 timebin for single timebin value in the pad before the cluster
+               if(meanTime<AliHLTTPCTransform::GetNTimeBins()){
+                 Int_t charge3 =tmpBefore->GetDataSignal(meanTime+1); 
+                 if(charge3){
+                   tmpCluster.fTotalCharge+= charge3;
+                   tmpCluster.fPad        += charge3*(pad+1);
+                   tmpCluster.fPad2       += charge3*(pad+1)*(pad+1); 
+                   tmpCluster.fTime       += meanTime*charge3;
+                   tmpCluster.fTime2      += meanTime*charge3*charge3;
+                 } 
+               }
+             }
+             
+             if(lastPad<fNumberOfPadsInRow[row]-2){
+               AliHLTTPCPad *tmpAfter=fRowPadVector[row][lastPad+1];
+               //checking the fMean +1 timebin for single timebin value in the pad after the cluster
+               if(meanTime>0){
+                 Int_t charge4 =tmpAfter->GetDataSignal(meanTime-1); 
+                 if(charge4){
+                   tmpCluster.fTotalCharge+= charge4;
+                   tmpCluster.fPad        += charge4*(pad-1);
+                   tmpCluster.fPad2       += charge4*(pad-1)*(pad-1); 
+                   tmpCluster.fTime       += meanTime*charge4;
+                   tmpCluster.fTime2      += meanTime*charge4*charge4;
+                 } 
+               }
+
+             
+               //checking the fMean +1 timebin for single timebin value in the pad after the cluster
+               Int_t charge5 =tmpAfter->GetDataSignal(meanTime); 
+               if(charge5){
+                 tmpCluster.fTotalCharge+= charge5;
+                 tmpCluster.fPad        += charge5*(pad);
+                 tmpCluster.fPad2       += charge5*(pad)*(pad); 
+                 tmpCluster.fTime       += meanTime*charge5;
+                 tmpCluster.fTime2      += meanTime*charge5*charge5;
+               } 
+               //checking the fMean +1 timebin for single timebin value in the pad after the cluster
+               if(meanTime<AliHLTTPCTransform::GetNTimeBins()){
+                 Int_t charge6 =tmpAfter->GetDataSignal(meanTime+1); 
+                 if(charge6){
+                   tmpCluster.fTotalCharge+= charge6;
+                   tmpCluster.fPad        += charge6*(pad+1);
+                   tmpCluster.fPad2       += charge6*(pad+1)*(pad+1); 
+                   tmpCluster.fTime       += meanTime*charge6;
+                   tmpCluster.fTime2      += meanTime*charge6*charge6;
+                 } 
+               }
+             }
+             tmpCluster.fTime= tmpCluster.fTime/tmpCluster.fTotalCharge;
+             totalChargeOfPreviousCandidate=0;
+             clusterChargeIsFalling=0;
+             tmpCluster.fRowNumber=row;
+             tmpCluster.fFirstPad=pad;
+
+             fClusters.push_back(tmpCluster);
+           }
+         }
+       }
+      }
+    }
+  }
+
+  HLTInfo("Found %d clusters.",nClusters);
+  // PrintClusters();
+}
+void AliHLTTPCPadArray::PrintClusters(){
+  for(int i=0;i<fClusters.size();i++){
+    cout<<"Cluster number: "<<i<<endl;
+    cout<<"Row: "<<fClusters[i].fRowNumber<<" Pad: "<<fClusters[i].fFirstPad<<endl;
+    cout<<"Total Charge: "<<fClusters[i].fTotalCharge<<endl;
+    cout<<"PadError:     "<<fClusters[i].fPad2<<endl;
+    cout<<"TimeMean:     "<<fClusters[i].fTime<<endl;
+    cout<<"TimeError:    "<<fClusters[i].fTime2<<endl;
+    cout<<endl;
+    cout<<endl;
+  }
+}
diff --git a/HLT/TPCLib/AliHLTTPCPadArray.h b/HLT/TPCLib/AliHLTTPCPadArray.h
new file mode 100644 (file)
index 0000000..843471e
--- /dev/null
@@ -0,0 +1,142 @@
+// -*- Mode: C++ -*-
+// @(#) $Id$
+
+#ifndef ALIHLTPADARRAY_H
+#define ALIHLTPADARRAY_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   AliHLTTPCPadArray.h
+    @author Kenneth Aamodt
+    @date   
+    @brief  Class containing arrays of TPC Pads.
+*/
+
+#include "AliHLTLogging.h"
+#include "AliHLTTPCTransform.h"
+#include "AliHLTTPCPad.h"
+#include "AliHLTTPCClusters.h"
+#include <vector>
+
+typedef Int_t AliHLTTPCSignal_t;
+class AliHLTTPCDigitReader;
+
+/**
+ * @class AliHLTTPCPadArray
+ * TODO
+ */
+
+class AliHLTTPCPadArray : public AliHLTLogging {
+
+public:
+
+  /** standard constructor */
+  AliHLTTPCPadArray();
+
+  /** 
+   * Constructor
+   * @param offset   The number of bins to ignore at the beginning
+   *                 of the channels
+   * @param nofBins  The total number of bins for one channel
+   */
+  AliHLTTPCPadArray(Int_t patch);
+
+  /** not a valid copy constructor, defined according to effective C++ style */
+  AliHLTTPCPadArray(const AliHLTTPCPadArray&);
+  /** not a valid assignment op, but defined according to effective C++ style */
+  AliHLTTPCPadArray& operator=(const AliHLTTPCPadArray&);
+  /** standard destructor */
+  virtual ~AliHLTTPCPadArray();
+
+  /**
+   * Initialize the pad vector for the patch set.
+   */
+  Int_t InitializeVector();
+
+  /**
+   * Deinitialize the pad vector for the patch set.
+   */
+  Int_t DeInitializeVector();
+  
+  /**
+   * Loop over all pads setting their data array to -1.
+   */
+  void DataToDefault(){
+    for(Int_t i=0;i<fNumberOfRows;i++){
+      for(Int_t j=0;j<fNumberOfPadsInRow[i];j++){
+       fRowPadVector[i][j]->SetDataToDefault();
+      }
+    }
+  }
+  
+  /**
+   * Set the patch number.
+   */
+  void SetPatch(Int_t patch);
+
+  /**
+   * Set the digit reader.
+   */
+  void SetDigitReader(AliHLTTPCDigitReader* digitReader);
+
+  /**
+   * Reads the data, and set it in the Pad objects.
+   */
+  Int_t ReadData();
+
+  /**
+   * Retuns number of pads in this row.
+   */
+  Int_t GetNumberOfPads(Int_t row){return fNumberOfPadsInRow[row];}
+
+  /**
+   * Loop over all pads, checking for clustercandidates.
+   */
+  void FindClusterCandidates(){
+    for(Int_t row=0;row<fNumberOfRows;row++){
+      for(Int_t pad=0;pad<fNumberOfPadsInRow[row];pad++){
+       fRowPadVector[row][pad]->FindClusterCandidates();
+      }
+    }
+  }
+  
+  /**
+   *
+   * Loop over all pads looking for clusters, if cluster candidates on two neighbouring
+   * pads have a mean time difference of <match it is said to be a cluster.
+   *
+   */
+  void FindClusters(Int_t match);
+
+  /**
+   * Print the values of the cluster, used for debugging purposes.
+   */
+  void PrintClusters();
+
+  typedef vector<AliHLTTPCPad*> fPadVector;
+
+  vector<fPadVector> fRowPadVector;                                //! transient
+
+  vector<AliHLTTPCClusters> fClusters;                             //! transient
+
+private:
+
+  /** The patch number */
+  Int_t fPatch;
+
+  Int_t fFirstRow;                                                 //! transient
+
+  Int_t fLastRow;                                                  //! transient
+
+  Int_t fThreshold;                                                //! transient
+
+  Int_t* fNumberOfPadsInRow;                                       //! transient
+
+  Int_t fNumberOfRows;                                             //! transient
+
+  AliHLTTPCDigitReader* fDigitReader;                              //! transient
+
+  ClassDef(AliHLTTPCPadArray, 0);
+};
+#endif
index 076a0e4bb0908d51c40d9ba017f2a5e144879c9c..80e799f5b6440a45180782efec328030b0eab6a8 100644 (file)
@@ -31,6 +31,7 @@ MODULE_SRCS=  AliHLTTPCLog.cxx \
                tracking/AliHLTTPCHistogram.cxx \
                tracking/AliHLTTPCHistogram1D.cxx \
                tracking/AliHLTTPCHistogramAdaptive.cxx \
+               AliHLTTPCClusters.cxx \
                AliHLTTPCConfMapFit.cxx \
                AliHLTTPCConfMapTrack.cxx \
                AliHLTTPCConfMapPoint.cxx \
@@ -42,6 +43,7 @@ MODULE_SRCS=  AliHLTTPCLog.cxx \
                AliHLTTPCInterMerger.cxx \
                AliHLTTPCCATracker.cxx \
                AliHLTTPCPad.cxx \
+               AliHLTTPCPadArray.cxx \
                AliHLTTPCDefinitions.cxx \
                AliHLTTPCRawDataUnpackerComponent.cxx \
                AliHLTTPCClusterFinderComponent.cxx \
@@ -82,6 +84,7 @@ CLASS_HDRS:=          AliHLTTPCTransform.h \
                tracking/AliHLTTPCHistogram.h \
                tracking/AliHLTTPCHistogram1D.h \
                tracking/AliHLTTPCHistogramAdaptive.h \
+               AliHLTTPCClusters.h \
                AliHLTTPCConfMapFit.h \
                AliHLTTPCConfMapTrack.h \
                AliHLTTPCConfMapPoint.h \
@@ -93,6 +96,7 @@ CLASS_HDRS:=          AliHLTTPCTransform.h \
                AliHLTTPCInterMerger.h \
                AliHLTTPCCATracker.h \
                AliHLTTPCPad.h \
+               AliHLTTPCPadArray.h \
                AliHLTTPCSpacePointData.h \
                AliHLTTPCDefinitions.h \
                AliHLTTPCRawDataUnpackerComponent.h \