3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
4 //*-- Copyright © ASV
7 #include "AliL3Logging.h"
8 #include "AliL3ClustFinderNew.h"
9 #include "AliL3DigitData.h"
10 #include "AliL3Transform.h"
11 #include "AliL3SpacePointData.h"
13 //_____________________________________________________________
14 // AliL3ClustFinderNew
16 // The current cluster finder for HLT
19 ClassImp(AliL3ClustFinderNew)
21 AliL3ClustFinderNew::AliL3ClustFinderNew()
29 AliL3ClustFinderNew::AliL3ClustFinderNew(AliL3Transform *transform)
31 fTransform = transform;
38 AliL3ClustFinderNew::~AliL3ClustFinderNew()
44 void AliL3ClustFinderNew::InitSlice(Int_t slice,Int_t patch,Int_t firstrow, Int_t lastrow,Int_t nmaxpoints)
47 fMaxNClusters = nmaxpoints;
48 fCurrentSlice = slice;
49 fCurrentPatch = patch;
56 void AliL3ClustFinderNew::InitSlice(Int_t slice,Int_t patch,Int_t nmaxpoints)
59 fMaxNClusters = nmaxpoints;
60 fCurrentSlice = slice;
61 fCurrentPatch = patch;
64 void AliL3ClustFinderNew::SetOutputArray(AliL3SpacePointData *pt)
71 void AliL3ClustFinderNew::Read(UInt_t ndigits,AliL3DigitRowData *ptr)
73 fNDigitRowData = ndigits;
78 void AliL3ClustFinderNew::ProcessDigits()
80 //Loop over rows, and call processrow
83 AliL3DigitRowData *tempPt = (AliL3DigitRowData*)fDigitRowData;
85 for(Int_t i=fFirstRow; i<=fLastRow; i++)
89 Byte_t *tmp = (Byte_t*)tempPt;
90 Int_t size = sizeof(AliL3DigitRowData) + tempPt->fNDigit*sizeof(AliL3DigitData);
92 tempPt = (AliL3DigitRowData*)tmp;
98 void AliL3ClustFinderNew::ProcessRow(AliL3DigitRowData *tempPt)
101 UInt_t last_pad = 123456789;
103 ClusterData *pad1[2500]; //2 lists for internal memory=2pads
104 ClusterData *pad2[2500]; //2 lists for internal memory=2pads
105 ClusterData clusterlist[5000]; //Clusterlist
107 ClusterData **currentPt; //List of pointers to the current pad
108 ClusterData **previousPt; //List of pointers to the previous pad
111 UInt_t n_previous=0,n_current=0,n_total=0;
113 //Loop over sequences of this row:
114 for(UInt_t bin=0; bin<tempPt->fNDigit; bin++)
117 AliL3DigitData *data = tempPt->fDigitData;
118 if(data[bin].fPad != last_pad)
123 if(currentPt == pad2)
134 n_previous = n_current;
136 if(bin[data].fPad != last_pad+1)
138 //this happens if there is a pad with no signal.
139 n_previous = n_current = 0;
141 last_pad = data[bin].fPad;
144 Bool_t new_cluster = kTRUE;
146 UInt_t seq_charge=0,seq_average=0;
148 UInt_t last_charge=0,last_was_falling=0;
152 redo: //This is a goto.
160 last_was_falling = 0;
164 while(1) //Loop over current sequence
166 //Get the current ADC-value
167 UInt_t charge = data[bin].fCharge;
171 //Check if the last pixel in the sequence is smaller than this
172 if(charge > last_charge)
180 else last_was_falling = 1; //last pixel was larger than this
181 last_charge = charge;
184 //Sum the total charge of this sequence
185 seq_charge += charge;
186 seq_average += data[bin].fTime*charge;
188 //Check where to stop:
189 if(data[bin+1].fPad != data[bin].fPad) //new pad
191 if(data[bin+1].fTime != data[bin].fTime+1) //end of sequence
195 }//end loop over sequence
197 //Calculate mean of sequence:
200 seq_mean = seq_average/seq_charge;
203 printf("\nCF: Should not happen\n");
208 //Calculate mean in pad direction:
209 Int_t pad_mean = seq_charge*data[bin].fPad;
211 //Compare with results on previous pad:
212 for(UInt_t p=0; p<n_previous; p++)
214 Int_t difference = seq_mean - previousPt[p]->fMean;
215 if(difference < -fMatch)
218 if(difference <= fMatch)//There is a match here!!
221 ClusterData *local = previousPt[p];
224 if(seq_charge > local->fLastCharge)
226 if(local->fChargeFalling)//The previous pad was falling
228 break;//create a new cluster
232 local->fChargeFalling = 1;
233 local->fLastCharge = seq_charge;
236 //Don't create a new cluster, because we found a match
237 new_cluster = kFALSE;
239 //Update cluster on current pad with the matching one:
240 //currentPt[n_current] = previousPt[p];
242 local->fTotalCharge += seq_charge;
243 local->fPad += pad_mean;
244 local->fTime += seq_average;
245 local->fMean = seq_mean;
246 local->fFlags++; //means we have more than one pad
248 currentPt[n_current] = local;
252 }//Checking for match at previous pad
253 }//Loop over results on previous pad.
257 //Start a new cluster. Add it to the clusterlist, and update
258 //the list of pointers to clusters in current pad.
259 //current pad will be previous pad on next pad.
261 //Add to the clusterlist:
262 ClusterData *tmp = &clusterlist[n_total];
263 tmp->fTotalCharge = seq_charge;
264 tmp->fPad = pad_mean;
265 tmp->fTime = seq_average;
266 tmp->fMean = seq_mean;
267 tmp->fFlags = 0; //flags for 1 pad clusters
270 tmp->fChargeFalling = 0;
271 tmp->fLastCharge = seq_charge;
274 //Update list of pointers to previous pad:
275 currentPt[n_current] = &clusterlist[n_total];
280 if(new_bin >= 0) goto redo;
282 }//Loop over digits on this padrow
284 WriteClusters(n_total,clusterlist);
289 void AliL3ClustFinderNew::WriteClusters(Int_t n_clusters,ClusterData *list)
291 Int_t thisrow,thissector;
292 UInt_t counter = fNClusters;
294 for(int j=0; j<n_clusters; j++)
296 if(!list[j].fFlags) continue; //discard 1 pad clusters
297 if(list[j].fTotalCharge < fThreshold) continue; //noise cluster
300 Float_t fpad=(Float_t)list[j].fPad/(Float_t)list[j].fTotalCharge;
301 Float_t ftime=(Float_t)list[j].fTime/(Float_t)list[j].fTotalCharge;
302 //printf("padrow %d number of pads %d totalcharge %d\n",fCurrentRow,list[j].fFlags,list[j].fTotalCharge);
303 fTransform->Slice2Sector(fCurrentSlice,fCurrentRow,thissector,thisrow);
304 fTransform->Raw2Local(xyz,thissector,thisrow,fpad,ftime);
305 if(xyz[0]==0) LOG(AliL3Log::kError,"AliL3ClustFinder","Cluster Finder")
306 <<AliL3Log::kDec<<"Zero cluster"<<ENDLOG;
307 if(fNClusters >= fMaxNClusters)
309 LOG(AliL3Log::kError,"AliL3ClustFinder::WriteClusters","Cluster Finder")
310 <<AliL3Log::kDec<<"Too many clusters"<<ENDLOG;
313 fSpacePointData[counter].fX = xyz[0];
314 fSpacePointData[counter].fY = xyz[1];
315 fSpacePointData[counter].fZ = xyz[2];
316 fSpacePointData[counter].fPadRow = fCurrentRow;
317 fSpacePointData[counter].fXYErr = fXYErr;
318 fSpacePointData[counter].fZErr = fZErr;
319 fSpacePointData[counter].fID = counter
320 +((fCurrentSlice&0x7f)<<25)+((fCurrentPatch&0x7)<<22);//uli