+
+//----------------------------------Methods for the new unsorted way of reading the data --------------------------------
+
+void AliHLTTPCClusterFinder::SetPadArray(AliHLTTPCPadArray * padArray)
+{
+ // see header file for function documentation
+ 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);
+
+ if(fSignalThreshold>0){
+ fPadArray->SetSignalThreshold(fSignalThreshold);
+ }
+ if(fNSigmaThreshold>0){
+ fPadArray->SetNSigmaThreshold(fNSigmaThreshold);
+ }
+ fPadArray->ReadData();
+}
+
+void AliHLTTPCClusterFinder::FindClusters()
+{
+ // see header file for function documentation
+ fPadArray->FindClusterCandidates();
+ fPadArray->FindClusters(fMatch);
+
+ AliClusterData * clusterlist = new AliClusterData[fPadArray->fClusters.size()]; //Clusterlist
+ for(unsigned int i=0;i<fPadArray->fClusters.size();i++){
+ clusterlist[i].fTotalCharge = fPadArray->fClusters[i].fTotalCharge;
+ clusterlist[i].fPad = fPadArray->fClusters[i].fPad;
+ clusterlist[i].fPad2 = fPadArray->fClusters[i].fPad2;
+ clusterlist[i].fTime = fPadArray->fClusters[i].fTime;
+ clusterlist[i].fTime2 = fPadArray->fClusters[i].fTime2;
+ clusterlist[i].fMean = fPadArray->fClusters[i].fMean;
+ clusterlist[i].fFlags = fPadArray->fClusters[i].fFlags;
+ clusterlist[i].fChargeFalling = fPadArray->fClusters[i].fChargeFalling;
+ clusterlist[i].fLastCharge = fPadArray->fClusters[i].fLastCharge;
+ clusterlist[i].fLastMergedPad = fPadArray->fClusters[i].fLastMergedPad;
+ clusterlist[i].fRow = fPadArray->fClusters[i].fRowNumber;
+ }
+ WriteClusters(fPadArray->fClusters.size(),clusterlist);
+ delete [] clusterlist;
+ fPadArray->DataToDefault();
+}
+
+Int_t AliHLTTPCClusterFinder::GetActivePads(AliHLTTPCPadArray::AliHLTTPCActivePads* activePads,Int_t maxActivePads)
+{
+ // see header file for function documentation
+ Int_t iResult=0;
+ if (fPadArray) {
+ iResult=fPadArray->GetActivePads((AliHLTTPCPadArray::AliHLTTPCActivePads*)activePads , maxActivePads);
+ } else if ((iResult=fActivePads.size())>0) {
+ if (iResult>maxActivePads) {
+ HLTWarning("target array (%d) not big enough to receive %d active pad descriptors", maxActivePads, iResult);
+ iResult=maxActivePads;
+ }
+ memcpy(activePads, &fActivePads[0], iResult*sizeof(AliHLTTPCPadArray::AliHLTTPCActivePads));
+ }
+
+ return iResult;
+}
+
+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++;
+ }
+}