1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 Revision 1.4 2000/06/07 16:27:01 cblume
19 Try to remove compiler warnings on Sun and HP
21 Revision 1.3 2000/05/08 16:17:27 cblume
24 Revision 1.1.4.1 2000/05/08 15:09:01 cblume
25 Introduce AliTRDdigitsManager
27 Revision 1.1 2000/02/28 18:58:54 cblume
32 ///////////////////////////////////////////////////////////////////////////////
34 // TRD cluster finder for the slow simulator.
36 ///////////////////////////////////////////////////////////////////////////////
40 #include "AliTRDclusterizerV1.h"
41 #include "AliTRDmatrix.h"
42 #include "AliTRDgeometry.h"
43 #include "AliTRDdigitizer.h"
44 #include "AliTRDrecPoint.h"
45 #include "AliTRDdataArrayF.h"
47 ClassImp(AliTRDclusterizerV1)
49 //_____________________________________________________________________________
50 AliTRDclusterizerV1::AliTRDclusterizerV1():AliTRDclusterizer()
53 // AliTRDclusterizerV1 default constructor
56 fDigitsManager = NULL;
60 //_____________________________________________________________________________
61 AliTRDclusterizerV1::AliTRDclusterizerV1(const Text_t* name, const Text_t* title)
62 :AliTRDclusterizer(name,title)
65 // AliTRDclusterizerV1 default constructor
68 fDigitsManager = new AliTRDdigitsManager();
74 //_____________________________________________________________________________
75 AliTRDclusterizerV1::AliTRDclusterizerV1(AliTRDclusterizerV1 &c)
78 // AliTRDclusterizerV1 copy constructor
85 //_____________________________________________________________________________
86 AliTRDclusterizerV1::~AliTRDclusterizerV1()
89 // AliTRDclusterizerV1 destructor
93 delete fDigitsManager;
98 //_____________________________________________________________________________
99 void AliTRDclusterizerV1::Copy(AliTRDclusterizerV1 &c)
105 c.fClusMaxThresh = fClusMaxThresh;
106 c.fClusSigThresh = fClusSigThresh;
107 c.fClusMethod = fClusMethod;
108 c.fDigitsManager = NULL;
110 AliTRDclusterizer::Copy(c);
114 //_____________________________________________________________________________
115 void AliTRDclusterizerV1::Init()
118 // Initializes the cluster finder
121 // The default parameter for the clustering
122 fClusMaxThresh = 5.0;
123 fClusSigThresh = 2.0;
128 //_____________________________________________________________________________
129 Bool_t AliTRDclusterizerV1::ReadDigits()
132 // Reads the digits arrays from the input aliroot file
136 printf("AliTRDclusterizerV1::ReadDigits -- ");
137 printf("No input file open\n");
141 // Read in the digit arrays
142 return (fDigitsManager->ReadDigits());
146 //_____________________________________________________________________________
147 Bool_t AliTRDclusterizerV1::MakeCluster()
150 // Generates the cluster.
153 Int_t row, col, time;
155 // Get the pointer to the detector class and check for version 1
156 AliTRD *trd = (AliTRD*) gAlice->GetDetector("TRD");
157 if (trd->IsVersion() != 1) {
158 printf("AliTRDclusterizerV1::MakeCluster -- ");
159 printf("TRD must be version 1 (slow simulator).\n");
164 AliTRDgeometry *geo = trd->GetGeometry();
166 printf("AliTRDclusterizerV1::MakeCluster -- ");
167 printf("Start creating clusters.\n");
169 AliTRDdataArrayI *digits;
172 Float_t maxThresh = fClusMaxThresh; // threshold value for maximum
173 Float_t signalThresh = fClusSigThresh; // threshold value for digit signal
174 Int_t clusteringMethod = fClusMethod; // clustering method option (for testing)
176 // Iteration limit for unfolding procedure
177 const Float_t kEpsilon = 0.01;
179 const Int_t kNclus = 3;
180 const Int_t kNsig = 5;
183 Int_t chamEnd = kNcham;
184 if (trd->GetSensChamber() >= 0) {
185 chamBeg = trd->GetSensChamber();
186 chamEnd = chamBeg + 1;
189 Int_t planEnd = kNplan;
190 if (trd->GetSensPlane() >= 0) {
191 planBeg = trd->GetSensPlane();
192 planEnd = planBeg + 1;
195 Int_t sectEnd = kNsect;
197 // *** Start clustering *** in every chamber
198 for (Int_t icham = chamBeg; icham < chamEnd; icham++) {
199 for (Int_t iplan = planBeg; iplan < planEnd; iplan++) {
200 for (Int_t isect = sectBeg; isect < sectEnd; isect++) {
202 if (trd->GetSensSector() >= 0) {
203 Int_t sens1 = trd->GetSensSector();
204 Int_t sens2 = sens1 + trd->GetSensSectorRange();
205 sens2 -= ((Int_t) (sens2 / kNsect)) * kNsect;
207 if ((isect < sens1) || (isect >= sens2)) continue;
209 if ((isect < sens1) && (isect >= sens2)) continue;
212 Int_t idet = geo->GetDetector(iplan,icham,isect);
215 printf("AliTRDclusterizerV1::MakeCluster -- ");
216 printf("Analyzing chamber %d, plane %d, sector %d.\n"
219 Int_t nRowMax = geo->GetRowMax(iplan,icham,isect);
220 Int_t nColMax = geo->GetColMax(iplan);
221 Int_t nTimeMax = geo->GetTimeMax();
223 // Create a detector matrix to keep maxima
224 AliTRDmatrix *digitMatrix = new AliTRDmatrix(nRowMax,nColMax,nTimeMax
226 // Create a matrix to contain maximum flags
227 AliTRDmatrix *maximaMatrix = new AliTRDmatrix(nRowMax,nColMax,nTimeMax
230 // Read in the digits
231 digits = fDigitsManager->GetDigits(idet);
233 // Loop through the detector pixel
234 for (time = 0; time < nTimeMax; time++) {
235 for ( col = 0; col < nColMax; col++) {
236 for ( row = 0; row < nRowMax; row++) {
238 Int_t signal = digits->GetData(row,col,time);
239 Int_t index = digits->GetIndex(row,col,time);
241 // Fill the detector matrix
242 if (signal > signalThresh) {
243 // Store the signal amplitude
244 digitMatrix->SetSignal(row,col,time,signal);
245 // Store the digits number
246 digitMatrix->AddTrack(row,col,time,index);
253 // Loop chamber and find maxima in digitMatrix
254 for ( row = 0; row < nRowMax; row++) {
255 for ( col = 1; col < nColMax; col++) {
256 for (time = 0; time < nTimeMax; time++) {
258 if (digitMatrix->GetSignal(row,col,time)
259 < digitMatrix->GetSignal(row,col - 1,time)) {
262 if (digitMatrix->GetSignal(row,col - 2,time)
263 < digitMatrix->GetSignal(row,col - 1,time)) {
264 // yes, so set maximum flag
265 maximaMatrix->SetSignal(row,col - 1,time,1);
267 else maximaMatrix->SetSignal(row,col - 1,time,0);
275 // now check maxima and calculate cluster position
276 for ( row = 0; row < nRowMax; row++) {
277 for ( col = 1; col < nColMax; col++) {
278 for (time = 0; time < nTimeMax; time++) {
280 if ((maximaMatrix->GetSignal(row,col,time) > 0)
281 && (digitMatrix->GetSignal(row,col,time) > maxThresh)) {
283 // Ratio resulting from unfolding
285 // Signals on max and neighbouring pads
286 Float_t padSignal[kNsig] = {0};
287 // Signals from cluster
288 Float_t clusterSignal[kNclus] = {0};
290 Float_t clusterPads[kNclus] = {0};
291 // Cluster digit info
292 Int_t clusterDigit[kNclus] = {0};
295 for (iPad = 0; iPad < kNclus; iPad++) {
296 clusterSignal[iPad] = digitMatrix->GetSignal(row,col-1+iPad,time);
297 clusterDigit[iPad] = digitMatrix->GetTrack(row,col-1+iPad,time,0);
300 // neighbouring maximum on right side?
301 if (col < nColMax - 2) {
302 if (maximaMatrix->GetSignal(row,col + 2,time) > 0) {
304 for (iPad = 0; iPad < 5; iPad++) {
305 padSignal[iPad] = digitMatrix->GetSignal(row,col-1+iPad,time);
309 ratio = Unfold(kEpsilon, padSignal);
311 // set signal on overlapping pad to ratio
312 clusterSignal[2] *= ratio;
317 // Calculate the position of the cluster
318 switch (clusteringMethod) {
320 // method 1: simply center of mass
321 clusterPads[0] = row + 0.5;
322 clusterPads[1] = col - 0.5 + (clusterSignal[2] - clusterSignal[0]) /
323 (clusterSignal[0] + clusterSignal[1] + clusterSignal[2]);
324 clusterPads[2] = time + 0.5;
329 // method 2: integral gauss fit on 3 pads
330 TH1F *hPadCharges = new TH1F("hPadCharges", "Charges on center 3 pads"
332 for (Int_t iCol = -1; iCol <= 3; iCol++) {
333 if (clusterSignal[iCol] < 1) clusterSignal[iCol] = 1;
334 hPadCharges->Fill(iCol, clusterSignal[iCol]);
336 hPadCharges->Fit("gaus", "IQ", "SAME", -0.5, 2.5);
337 TF1 *fPadChargeFit = hPadCharges->GetFunction("gaus");
338 Double_t colMean = fPadChargeFit->GetParameter(1);
340 clusterPads[0] = row + 0.5;
341 clusterPads[1] = col - 1.5 + colMean;
342 clusterPads[2] = time + 0.5;
350 Float_t clusterCharge = clusterSignal[0]
354 // Add the cluster to the output array
355 trd->AddRecPoint(clusterPads,clusterDigit,idet,clusterCharge);
362 printf("AliTRDclusterizerV1::MakeCluster -- ");
363 printf("Number of clusters found: %d\n",nClusters);
372 printf("AliTRDclusterizerV1::MakeCluster -- ");
373 printf("Total number of points found: %d\n"
374 ,trd->RecPoints()->GetEntries());
376 // Get the pointer to the cluster branch
377 TTree *clusterTree = gAlice->TreeR();
379 // Fill the cluster-branch
380 printf("AliTRDclusterizerV1::MakeCluster -- ");
381 printf("Fill the cluster tree.\n");
383 printf("AliTRDclusterizerV1::MakeCluster -- ");
390 //_____________________________________________________________________________
391 Float_t AliTRDclusterizerV1::Unfold(Float_t eps, Float_t* padSignal)
394 // Method to unfold neighbouring maxima.
395 // The charge ratio on the overlapping pad is calculated
396 // until there is no more change within the range given by eps.
397 // The resulting ratio is then returned to the calling method.
400 Int_t itStep = 0; // count iteration steps
402 Float_t ratio = 0.5; // start value for ratio
403 Float_t prevRatio = 0; // store previous ratio
405 Float_t newLeftSignal[3] = {0}; // array to store left cluster signal
406 Float_t newRightSignal[3] = {0}; // array to store right cluster signal
409 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
414 // cluster position according to charge ratio
415 Float_t maxLeft = (ratio*padSignal[2] - padSignal[0]) /
416 (padSignal[0] + padSignal[1] + ratio*padSignal[2]);
417 Float_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2]) /
418 ((1-ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
420 // set cluster charge ratio
421 Float_t ampLeft = padSignal[1];
422 Float_t ampRight = padSignal[3];
424 // apply pad response to parameters
425 newLeftSignal[0] = ampLeft*PadResponse(-1 - maxLeft);
426 newLeftSignal[1] = ampLeft*PadResponse( 0 - maxLeft);
427 newLeftSignal[2] = ampLeft*PadResponse( 1 - maxLeft);
429 newRightSignal[0] = ampRight*PadResponse(-1 - maxRight);
430 newRightSignal[1] = ampRight*PadResponse( 0 - maxRight);
431 newRightSignal[2] = ampRight*PadResponse( 1 - maxRight);
433 // calculate new overlapping ratio
434 ratio = newLeftSignal[2]/(newLeftSignal[2] + newRightSignal[0]);
442 //_____________________________________________________________________________
443 Float_t AliTRDclusterizerV1::PadResponse(Float_t x)
446 // The pad response for the chevron pads.
447 // We use a simple Gaussian approximation which should be good
448 // enough for our purpose.
451 // The parameters for the response function
452 const Float_t kA = 0.8872;
453 const Float_t kB = -0.00573;
454 const Float_t kC = 0.454;
455 const Float_t kC2 = kC*kC;
457 Float_t pr = kA * (kB + TMath::Exp(-x*x / (2. * kC2)));