3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
4 //*-- Copyright © ASV
8 #include "AliL3Logging.h"
9 #include "AliL3ClustFinderNew.h"
10 #include "AliL3DigitData.h"
11 #include "AliL3Transform.h"
12 #include "AliL3SpacePointData.h"
13 #include "AliL3MemHandler.h"
15 //_____________________________________________________________
16 // AliL3ClustFinderNew
18 // The current cluster finder for HLT
21 ClassImp(AliL3ClustFinderNew)
23 AliL3ClustFinderNew::AliL3ClustFinderNew()
31 AliL3ClustFinderNew::~AliL3ClustFinderNew()
37 void AliL3ClustFinderNew::InitSlice(Int_t slice,Int_t patch,Int_t firstrow, Int_t lastrow,Int_t nmaxpoints)
40 fMaxNClusters = nmaxpoints;
41 fCurrentSlice = slice;
42 fCurrentPatch = patch;
49 void AliL3ClustFinderNew::InitSlice(Int_t slice,Int_t patch,Int_t nmaxpoints)
52 fMaxNClusters = nmaxpoints;
53 fCurrentSlice = slice;
54 fCurrentPatch = patch;
57 void AliL3ClustFinderNew::SetOutputArray(AliL3SpacePointData *pt)
64 void AliL3ClustFinderNew::Read(UInt_t ndigits,AliL3DigitRowData *ptr)
66 fNDigitRowData = ndigits;
71 void AliL3ClustFinderNew::ProcessDigits()
73 //Loop over rows, and call processrow
76 AliL3DigitRowData *tempPt = (AliL3DigitRowData*)fDigitRowData;
78 for(Int_t i=fFirstRow; i<=fLastRow; i++)
82 Byte_t *tmp = (Byte_t*)tempPt;
83 Int_t size = sizeof(AliL3DigitRowData) + tempPt->fNDigit*sizeof(AliL3DigitData);
85 tempPt = (AliL3DigitRowData*)tmp;
87 LOG(AliL3Log::kInformational,"AliL3ClustFinderNew::WriteClusters","Space points")
88 <<"Cluster finder found "<<fNClusters<<" clusters in slice "<<fCurrentSlice
89 <<" patch "<<fCurrentPatch<<ENDLOG;
92 void AliL3ClustFinderNew::ProcessRow(AliL3DigitRowData *tempPt)
95 UInt_t last_pad = 123456789;
97 ClusterData *pad1[2500]; //2 lists for internal memory=2pads
98 ClusterData *pad2[2500]; //2 lists for internal memory=2pads
99 ClusterData clusterlist[5000]; //Clusterlist
101 ClusterData **currentPt; //List of pointers to the current pad
102 ClusterData **previousPt; //List of pointers to the previous pad
105 UInt_t n_previous=0,n_current=0,n_total=0;
107 //Loop over sequences of this row:
108 for(UInt_t bin=0; bin<tempPt->fNDigit; bin++)
111 AliL3DigitData *data = tempPt->fDigitData;
112 if(data[bin].fPad != last_pad)
117 if(currentPt == pad2)
128 n_previous = n_current;
130 if(bin[data].fPad != last_pad+1)
132 //this happens if there is a pad with no signal.
133 n_previous = n_current = 0;
135 last_pad = data[bin].fPad;
138 Bool_t new_cluster = kTRUE;
140 UInt_t seq_charge=0,seq_average=0;
142 UInt_t last_charge=0,last_was_falling=0;
146 redo: //This is a goto.
154 last_was_falling = 0;
158 while(1) //Loop over current sequence
160 if(data[bin].fTime >= AliL3Transform::GetNTimeBins())
162 LOG(AliL3Log::kFatal,"AliL3ClustFinderNew::ProcessRow","Digits")
163 <<"Timebin out of range "<<(Int_t)data[bin].fTime<<ENDLOG;
167 //Get the current ADC-value
168 UInt_t charge = data[bin].fCharge;
172 //Check if the last pixel in the sequence is smaller than this
173 if(charge > last_charge)
181 else last_was_falling = 1; //last pixel was larger than this
182 last_charge = charge;
185 //Sum the total charge of this sequence
186 seq_charge += charge;
187 seq_average += data[bin].fTime*charge;
189 //Check where to stop:
190 if(data[bin+1].fPad != data[bin].fPad) //new pad
192 if(data[bin+1].fTime != data[bin].fTime+1) //end of sequence
196 }//end loop over sequence
198 //Calculate mean of sequence:
201 seq_mean = seq_average/seq_charge;
204 LOG(AliL3Log::kFatal,"AliL3ClustFinderNew::ProcessRow","Data")
205 <<"Error in data given to the cluster finder"<<ENDLOG;
210 //Calculate mean in pad direction:
211 Int_t pad_mean = seq_charge*data[bin].fPad;
213 //Compare with results on previous pad:
214 for(UInt_t p=0; p<n_previous; p++)
216 Int_t difference = seq_mean - previousPt[p]->fMean;
217 if(difference < -fMatch)
220 if(difference <= fMatch)//There is a match here!!
223 ClusterData *local = previousPt[p];
226 if(seq_charge > local->fLastCharge)
228 if(local->fChargeFalling)//The previous pad was falling
230 break;//create a new cluster
234 local->fChargeFalling = 1;
235 local->fLastCharge = seq_charge;
238 //Don't create a new cluster, because we found a match
239 new_cluster = kFALSE;
241 //Update cluster on current pad with the matching one:
242 //currentPt[n_current] = previousPt[p];
244 local->fTotalCharge += seq_charge;
245 local->fPad += pad_mean;
246 local->fTime += seq_average;
247 local->fMean = seq_mean;
248 local->fFlags++; //means we have more than one pad
250 currentPt[n_current] = local;
254 }//Checking for match at previous pad
255 }//Loop over results on previous pad.
259 //Start a new cluster. Add it to the clusterlist, and update
260 //the list of pointers to clusters in current pad.
261 //current pad will be previous pad on next pad.
263 //Add to the clusterlist:
264 ClusterData *tmp = &clusterlist[n_total];
265 tmp->fTotalCharge = seq_charge;
266 tmp->fPad = pad_mean;
267 tmp->fTime = seq_average;
268 tmp->fMean = seq_mean;
269 tmp->fFlags = 0; //flags for 1 pad clusters
272 tmp->fChargeFalling = 0;
273 tmp->fLastCharge = seq_charge;
276 //Update list of pointers to previous pad:
277 currentPt[n_current] = &clusterlist[n_total];
282 if(new_bin >= 0) goto redo;
284 }//Loop over digits on this padrow
286 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;
303 //cout<<"WriteCluster: padrow "<<fCurrentRow<<" pad "<<fpad<<" time "<<ftime<<" charge "<<list[j].fTotalCharge<<endl;
305 AliL3Transform::Slice2Sector(fCurrentSlice,fCurrentRow,thissector,thisrow);
306 AliL3Transform::Raw2Local(xyz,thissector,thisrow,fpad,ftime);
307 if(xyz[0]==0) LOG(AliL3Log::kError,"AliL3ClustFinder","Cluster Finder")
308 <<AliL3Log::kDec<<"Zero cluster"<<ENDLOG;
309 if(fNClusters >= fMaxNClusters)
311 LOG(AliL3Log::kError,"AliL3ClustFinder::WriteClusters","Cluster Finder")
312 <<AliL3Log::kDec<<"Too many clusters"<<ENDLOG;
315 fSpacePointData[counter].fCharge = list[j].fTotalCharge;
316 fSpacePointData[counter].fX = xyz[0];
317 fSpacePointData[counter].fY = xyz[1];
318 fSpacePointData[counter].fZ = xyz[2];
319 fSpacePointData[counter].fPadRow = fCurrentRow;
320 fSpacePointData[counter].fXYErr = fXYErr;
321 fSpacePointData[counter].fZErr = fZErr;
322 fSpacePointData[counter].fID = counter
323 +((fCurrentSlice&0x7f)<<25)+((fCurrentPatch&0x7)<<22);//Uli
326 GetTrackID((Int_t)rint(fpad),(Int_t)rint(ftime),trackID);
327 //cout<<"padrow "<<fCurrentRow<<" pad "<<(Int_t)rint(fpad)<<" time "<<(Int_t)rint(ftime)<<" Trackid "<<trackID[0]<<endl;
328 fSpacePointData[counter].fTrackID[0] = trackID[0];
329 fSpacePointData[counter].fTrackID[1] = trackID[1];
330 fSpacePointData[counter].fTrackID[2] = trackID[2];
338 void AliL3ClustFinderNew::GetTrackID(Int_t pad,Int_t time,Int_t *trackID)
340 AliL3DigitRowData *rowPt = (AliL3DigitRowData*)fDigitRowData;
342 trackID[0]=trackID[1]=trackID[2]=-2;
343 //cout<<"Looking for pad "<<pad<<" time "<<time<<endl;
344 for(Int_t i=fFirstRow; i<=fLastRow; i++)
346 if(rowPt->fRow < (UInt_t)fCurrentRow)
348 AliL3MemHandler::UpdateRowPointer(rowPt);
351 AliL3DigitData *digPt = (AliL3DigitData*)rowPt->fDigitData;
352 for(UInt_t j=0; j<rowPt->fNDigit; j++)
354 Int_t cpad = digPt[j].fPad;
355 Int_t ctime = digPt[j].fTime;
356 if(cpad != pad) continue;
357 if(ctime != time) continue;
358 //if(cpad != pad && ctime != ctime) continue;
359 //cout<<"Reading row "<<fCurrentRow<<" pad "<<cpad<<" time "<<ctime<<" trackID "<<digPt[j].fTrackID[0]<<endl;
360 trackID[0] = digPt[j].fTrackID[0];
361 trackID[1] = digPt[j].fTrackID[1];
362 trackID[2] = digPt[j].fTrackID[2];
364 //cout<<"Reading trackID "<<trackID[0]<<endl;