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 if(data[bin].fTime >= fTransform->GetNTimeBins())
168 LOG(AliL3Log::kFatal,"AliL3ClustFinderNew::ProcessRow","Digits")
169 <<"Timebin out of range "<<(Int_t)data[bin].fTime<<ENDLOG;
173 //Get the current ADC-value
174 UInt_t charge = data[bin].fCharge;
178 //Check if the last pixel in the sequence is smaller than this
179 if(charge > last_charge)
187 else last_was_falling = 1; //last pixel was larger than this
188 last_charge = charge;
191 //Sum the total charge of this sequence
192 seq_charge += charge;
193 seq_average += data[bin].fTime*charge;
195 //Check where to stop:
196 if(data[bin+1].fPad != data[bin].fPad) //new pad
198 if(data[bin+1].fTime != data[bin].fTime+1) //end of sequence
202 }//end loop over sequence
204 //Calculate mean of sequence:
207 seq_mean = seq_average/seq_charge;
210 LOG(AliL3Log::kFatal,"AliL3ClustFinderNew::ProcessRow","Data")
211 <<"Error in data given to the cluster finder"<<ENDLOG;
216 //Calculate mean in pad direction:
217 Int_t pad_mean = seq_charge*data[bin].fPad;
219 //Compare with results on previous pad:
220 for(UInt_t p=0; p<n_previous; p++)
222 Int_t difference = seq_mean - previousPt[p]->fMean;
223 if(difference < -fMatch)
226 if(difference <= fMatch)//There is a match here!!
229 ClusterData *local = previousPt[p];
232 if(seq_charge > local->fLastCharge)
234 if(local->fChargeFalling)//The previous pad was falling
236 break;//create a new cluster
240 local->fChargeFalling = 1;
241 local->fLastCharge = seq_charge;
244 //Don't create a new cluster, because we found a match
245 new_cluster = kFALSE;
247 //Update cluster on current pad with the matching one:
248 //currentPt[n_current] = previousPt[p];
250 local->fTotalCharge += seq_charge;
251 local->fPad += pad_mean;
252 local->fTime += seq_average;
253 local->fMean = seq_mean;
254 local->fFlags++; //means we have more than one pad
256 currentPt[n_current] = local;
260 }//Checking for match at previous pad
261 }//Loop over results on previous pad.
265 //Start a new cluster. Add it to the clusterlist, and update
266 //the list of pointers to clusters in current pad.
267 //current pad will be previous pad on next pad.
269 //Add to the clusterlist:
270 ClusterData *tmp = &clusterlist[n_total];
271 tmp->fTotalCharge = seq_charge;
272 tmp->fPad = pad_mean;
273 tmp->fTime = seq_average;
274 tmp->fMean = seq_mean;
275 tmp->fFlags = 0; //flags for 1 pad clusters
278 tmp->fChargeFalling = 0;
279 tmp->fLastCharge = seq_charge;
282 //Update list of pointers to previous pad:
283 currentPt[n_current] = &clusterlist[n_total];
288 if(new_bin >= 0) goto redo;
290 }//Loop over digits on this padrow
292 WriteClusters(n_total,clusterlist);
297 void AliL3ClustFinderNew::WriteClusters(Int_t n_clusters,ClusterData *list)
299 Int_t thisrow,thissector;
300 UInt_t counter = fNClusters;
302 for(int j=0; j<n_clusters; j++)
304 if(!list[j].fFlags) continue; //discard 1 pad clusters
305 if(list[j].fTotalCharge < fThreshold) continue; //noise cluster
308 Float_t fpad=(Float_t)list[j].fPad/(Float_t)list[j].fTotalCharge;
309 Float_t ftime=(Float_t)list[j].fTime/(Float_t)list[j].fTotalCharge;
310 //printf("padrow %d number of pads %d totalcharge %d\n",fCurrentRow,list[j].fFlags,list[j].fTotalCharge);
311 fTransform->Slice2Sector(fCurrentSlice,fCurrentRow,thissector,thisrow);
312 fTransform->Raw2Local(xyz,thissector,thisrow,fpad,ftime);
313 if(xyz[0]==0) LOG(AliL3Log::kError,"AliL3ClustFinder","Cluster Finder")
314 <<AliL3Log::kDec<<"Zero cluster"<<ENDLOG;
315 if(fNClusters >= fMaxNClusters)
317 LOG(AliL3Log::kError,"AliL3ClustFinder::WriteClusters","Cluster Finder")
318 <<AliL3Log::kDec<<"Too many clusters"<<ENDLOG;
321 fSpacePointData[counter].fCharge = list[j].fTotalCharge;
322 fSpacePointData[counter].fX = xyz[0];
323 fSpacePointData[counter].fY = xyz[1];
324 fSpacePointData[counter].fZ = xyz[2];
325 fSpacePointData[counter].fPadRow = fCurrentRow;
326 fSpacePointData[counter].fXYErr = fXYErr;
327 fSpacePointData[counter].fZErr = fZErr;
328 fSpacePointData[counter].fID = counter
329 +((fCurrentSlice&0x7f)<<25)+((fCurrentPatch&0x7)<<22);//uli