1 //Author: Anders Strand Vestbo
2 //Last Modified: 17.08.2001
5 #include "AliL3Logging.h"
6 #include "AliL3ClustFinderNew.h"
7 #include "AliL3DigitData.h"
8 #include "AliL3Transform.h"
9 #include "AliL3SpacePointData.h"
11 ClassImp(AliL3ClustFinderNew)
13 AliL3ClustFinderNew::AliL3ClustFinderNew()
21 AliL3ClustFinderNew::AliL3ClustFinderNew(AliL3Transform *transform)
23 fTransform = transform;
30 AliL3ClustFinderNew::~AliL3ClustFinderNew()
36 void AliL3ClustFinderNew::InitSlice(Int_t slice,Int_t patch,Int_t firstrow, Int_t lastrow,Int_t nmaxpoints)
39 fMaxNClusters = nmaxpoints;
40 fCurrentSlice = slice;
41 fCurrentPatch = patch;
48 void AliL3ClustFinderNew::InitSlice(Int_t slice,Int_t patch,Int_t nmaxpoints)
51 fMaxNClusters = nmaxpoints;
52 fCurrentSlice = slice;
53 fCurrentPatch = patch;
56 void AliL3ClustFinderNew::SetOutputArray(AliL3SpacePointData *pt)
63 void AliL3ClustFinderNew::Read(UInt_t ndigits,AliL3DigitRowData *ptr)
65 fNDigitRowData = ndigits;
70 void AliL3ClustFinderNew::ProcessDigits()
72 //Loop over rows, and call processrow
75 AliL3DigitRowData *tempPt = (AliL3DigitRowData*)fDigitRowData;
77 for(Int_t i=fFirstRow; i<=fLastRow; i++)
81 Byte_t *tmp = (Byte_t*)tempPt;
82 Int_t size = sizeof(AliL3DigitRowData) + tempPt->fNDigit*sizeof(AliL3DigitData);
84 tempPt = (AliL3DigitRowData*)tmp;
90 void AliL3ClustFinderNew::ProcessRow(AliL3DigitRowData *tempPt)
93 UInt_t last_pad = 123456789;
95 ClusterData *pad1[2500]; //2 lists for internal memory=2pads
96 ClusterData *pad2[2500]; //2 lists for internal memory=2pads
97 ClusterData clusterlist[5000]; //Clusterlist
99 ClusterData **currentPt; //List of pointers to the current pad
100 ClusterData **previousPt; //List of pointers to the previous pad
103 UInt_t n_previous=0,n_current=0,n_total=0;
105 //Loop over sequences of this row:
106 for(UInt_t bin=0; bin<tempPt->fNDigit; bin++)
109 AliL3DigitData *data = tempPt->fDigitData;
110 if(data[bin].fPad != last_pad)
115 if(currentPt == pad2)
126 n_previous = n_current;
128 if(bin[data].fPad != last_pad+1)
130 //this happens if there is a pad with no signal.
131 n_previous = n_current = 0;
133 last_pad = data[bin].fPad;
136 Bool_t new_cluster = kTRUE;
138 UInt_t seq_charge=0,seq_average=0;
140 UInt_t last_charge=0,last_was_falling=0;
144 redo: //This is a goto.
152 last_was_falling = 0;
156 while(1) //Loop over current sequence
158 //Get the current ADC-value
159 UInt_t charge = data[bin].fCharge;
163 //Check if the last pixel in the sequence is smaller than this
164 if(charge > last_charge)
172 else last_was_falling = 1; //last pixel was larger than this
173 last_charge = charge;
176 //Sum the total charge of this sequence
177 seq_charge += charge;
178 seq_average += data[bin].fTime*charge;
180 //Check where to stop:
181 if(data[bin+1].fPad != data[bin].fPad) //new pad
183 if(data[bin+1].fTime != data[bin].fTime+1) //end of sequence
187 }//end loop over sequence
189 //Calculate mean of sequence:
192 seq_mean = seq_average/seq_charge;
195 printf("\nCF: Should not happen\n");
200 //Calculate mean in pad direction:
201 Int_t pad_mean = seq_charge*data[bin].fPad;
203 //Compare with results on previous pad:
204 for(UInt_t p=0; p<n_previous; p++)
206 Int_t difference = seq_mean - previousPt[p]->fMean;
207 if(difference < -fMatch)
210 if(difference <= fMatch)//There is a match here!!
213 ClusterData *local = previousPt[p];
216 if(seq_charge > local->fLastCharge)
218 if(local->fChargeFalling)//The previous pad was falling
220 break;//create a new cluster
224 local->fChargeFalling = 1;
225 local->fLastCharge = seq_charge;
228 //Don't create a new cluster, because we found a match
229 new_cluster = kFALSE;
231 //Update cluster on current pad with the matching one:
232 //currentPt[n_current] = previousPt[p];
234 local->fTotalCharge += seq_charge;
235 local->fPad += pad_mean;
236 local->fTime += seq_average;
237 local->fMean = seq_mean;
238 local->fFlags++; //means we have more than one pad
240 currentPt[n_current] = local;
244 }//Checking for match at previous pad
245 }//Loop over results on previous pad.
249 //Start a new cluster. Add it to the clusterlist, and update
250 //the list of pointers to clusters in current pad.
251 //current pad will be previous pad on next pad.
253 //Add to the clusterlist:
254 ClusterData *tmp = &clusterlist[n_total];
255 tmp->fTotalCharge = seq_charge;
256 tmp->fPad = pad_mean;
257 tmp->fTime = seq_average;
258 tmp->fMean = seq_mean;
259 tmp->fFlags = 0; //flags for 1 pad clusters
262 tmp->fChargeFalling = 0;
263 tmp->fLastCharge = seq_charge;
266 //Update list of pointers to previous pad:
267 currentPt[n_current] = &clusterlist[n_total];
272 if(new_bin >= 0) goto redo;
274 }//Loop over digits on this padrow
276 WriteClusters(n_total,clusterlist);
281 void AliL3ClustFinderNew::WriteClusters(Int_t n_clusters,ClusterData *list)
283 Int_t thisrow,thissector;
284 UInt_t counter = fNClusters;
286 for(int j=0; j<n_clusters; j++)
288 if(!list[j].fFlags) continue; //discard 1 pad clusters
289 if(list[j].fTotalCharge < fThreshold) continue; //noise cluster
292 Float_t fpad=(Float_t)list[j].fPad/(Float_t)list[j].fTotalCharge;
293 Float_t ftime=(Float_t)list[j].fTime/(Float_t)list[j].fTotalCharge;
294 //printf("padrow %d number of pads %d totalcharge %d\n",fCurrentRow,list[j].fFlags,list[j].fTotalCharge);
295 fTransform->Slice2Sector(fCurrentSlice,fCurrentRow,thissector,thisrow);
296 fTransform->Raw2Local(xyz,thissector,thisrow,fpad,ftime);
297 if(xyz[0]==0) LOG(AliL3Log::kError,"AliL3ClustFinder","Cluster Finder")
298 <<AliL3Log::kDec<<"Zero cluster"<<ENDLOG;
299 if(fNClusters >= fMaxNClusters)
301 LOG(AliL3Log::kError,"AliL3ClustFinder::WriteClusters","Cluster Finder")
302 <<AliL3Log::kDec<<"Too many clusters"<<ENDLOG;
305 fSpacePointData[counter].fX = xyz[0];
306 fSpacePointData[counter].fY = xyz[1];
307 fSpacePointData[counter].fZ = xyz[2];
308 fSpacePointData[counter].fPadRow = fCurrentRow;
309 fSpacePointData[counter].fXYErr = fXYErr;
310 fSpacePointData[counter].fZErr = fZErr;
311 fSpacePointData[counter].fID = counter
312 +((fCurrentSlice&0x7f)<<25)+((fCurrentPatch&0x7)<<22);//uli