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 ///////////////////////////////////////////////////////////////////////////////
20 // TRD cluster finder for the slow simulator.
22 ///////////////////////////////////////////////////////////////////////////////
30 #include "AliRunLoader.h"
31 #include "AliLoader.h"
33 #include "AliTRDclusterizerV1.h"
34 #include "AliTRDmatrix.h"
35 #include "AliTRDgeometry.h"
36 #include "AliTRDdataArrayF.h"
37 #include "AliTRDdataArrayI.h"
38 #include "AliTRDdigitsManager.h"
39 #include "AliTRDparameter.h"
41 ClassImp(AliTRDclusterizerV1)
43 //_____________________________________________________________________________
44 AliTRDclusterizerV1::AliTRDclusterizerV1():AliTRDclusterizer()
47 // AliTRDclusterizerV1 default constructor
54 //_____________________________________________________________________________
55 AliTRDclusterizerV1::AliTRDclusterizerV1(const Text_t* name, const Text_t* title)
56 :AliTRDclusterizer(name,title)
59 // AliTRDclusterizerV1 default constructor
62 fDigitsManager = new AliTRDdigitsManager();
63 fDigitsManager->CreateArrays();
67 //_____________________________________________________________________________
68 AliTRDclusterizerV1::AliTRDclusterizerV1(const AliTRDclusterizerV1 &c)
72 // AliTRDclusterizerV1 copy constructor
75 ((AliTRDclusterizerV1 &) c).Copy(*this);
79 //_____________________________________________________________________________
80 AliTRDclusterizerV1::~AliTRDclusterizerV1()
83 // AliTRDclusterizerV1 destructor
87 delete fDigitsManager;
88 fDigitsManager = NULL;
93 //_____________________________________________________________________________
94 AliTRDclusterizerV1 &AliTRDclusterizerV1::operator=(const AliTRDclusterizerV1 &c)
97 // Assignment operator
100 if (this != &c) ((AliTRDclusterizerV1 &) c).Copy(*this);
105 //_____________________________________________________________________________
106 void AliTRDclusterizerV1::Copy(TObject &c)
112 ((AliTRDclusterizerV1 &) c).fDigitsManager = 0;
114 AliTRDclusterizer::Copy(c);
118 //_____________________________________________________________________________
119 Bool_t AliTRDclusterizerV1::ReadDigits()
122 // Reads the digits arrays from the input aliroot file
126 printf("<AliTRDclusterizerV1::ReadDigits> ");
127 printf("No input file open\n");
130 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
131 if (!loader->TreeD()) loader->LoadDigits();
133 // Read in the digit arrays
134 return (fDigitsManager->ReadDigits(loader->TreeD()));
138 //_____________________________________________________________________________
139 Bool_t AliTRDclusterizerV1::MakeClusters()
142 // Generates the cluster.
145 Int_t row, col, time;
148 if (fTRD->IsVersion() != 1) {
149 printf("<AliTRDclusterizerV1::MakeCluster> ");
150 printf("TRD must be version 1 (slow simulator).\n");
156 AliTRDgeometry *geo = AliTRDgeometry::GetGeometry(fRunLoader);
158 // Create a default parameter class if none is defined
160 fPar = new AliTRDparameter("TRDparameter","Standard TRD parameter");
161 printf("<AliTRDclusterizerV1::MakeCluster> ");
162 printf("Create the default parameter object.\n");
165 Float_t timeBinSize = fPar->GetTimeBinSize();
166 // Half of ampl.region
167 const Float_t kAmWidth = AliTRDgeometry::AmThick()/2.;
169 Float_t omegaTau = fPar->GetOmegaTau();
171 printf("<AliTRDclusterizerV1::MakeCluster> ");
172 printf("OmegaTau = %f \n",omegaTau);
173 printf("<AliTRDclusterizerV1::MakeCluster> ");
174 printf("Start creating clusters.\n");
177 AliTRDdataArrayI *digits;
178 AliTRDdataArrayI *track0;
179 AliTRDdataArrayI *track1;
180 AliTRDdataArrayI *track2;
182 // Threshold value for the maximum
183 Int_t maxThresh = fPar->GetClusMaxThresh();
184 // Threshold value for the digit signal
185 Int_t sigThresh = fPar->GetClusSigThresh();
187 // Iteration limit for unfolding procedure
188 const Float_t kEpsilon = 0.01;
190 const Int_t kNclus = 3;
191 const Int_t kNsig = 5;
192 const Int_t kNtrack = 3 * kNclus;
197 Float_t ratioLeft = 1.0;
198 Float_t ratioRight = 1.0;
200 Float_t padSignal[kNsig];
201 Float_t clusterSignal[kNclus];
202 Float_t clusterPads[kNclus];
203 Int_t clusterDigit[kNclus];
204 Int_t clusterTracks[kNtrack];
207 Int_t chamEnd = AliTRDgeometry::Ncham();
209 Int_t planEnd = AliTRDgeometry::Nplan();
211 Int_t sectEnd = AliTRDgeometry::Nsect();
213 // Start clustering in every chamber
214 for (Int_t icham = chamBeg; icham < chamEnd; icham++) {
215 for (Int_t iplan = planBeg; iplan < planEnd; iplan++) {
216 for (Int_t isect = sectBeg; isect < sectEnd; isect++) {
218 Int_t idet = geo->GetDetector(iplan,icham,isect);
221 Int_t nClusters2pad = 0;
222 Int_t nClusters3pad = 0;
223 Int_t nClusters4pad = 0;
224 Int_t nClusters5pad = 0;
225 Int_t nClustersLarge = 0;
228 printf("<AliTRDclusterizerV1::MakeCluster> ");
229 printf("Analyzing chamber %d, plane %d, sector %d.\n"
233 Int_t nRowMax = fPar->GetRowMax(iplan,icham,isect);
234 Int_t nColMax = fPar->GetColMax(iplan);
235 Int_t nTimeBefore = fPar->GetTimeBefore();
236 Int_t nTimeTotal = fPar->GetTimeTotal();
238 Float_t row0 = fPar->GetRow0(iplan,icham,isect);
239 Float_t col0 = fPar->GetCol0(iplan);
240 Float_t rowSize = fPar->GetRowPadSize(iplan,icham,isect);
241 Float_t colSize = fPar->GetColPadSize(iplan);
244 digits = fDigitsManager->GetDigits(idet);
246 track0 = fDigitsManager->GetDictionary(idet,0);
248 track1 = fDigitsManager->GetDictionary(idet,1);
250 track2 = fDigitsManager->GetDictionary(idet,2);
253 // Loop through the chamber and find the maxima
254 for ( row = 0; row < nRowMax; row++) {
255 // for ( col = 2; col < nColMax; col++) {
256 for ( col = 4; col < nColMax-2; col++) {
257 for (time = 0; time < nTimeTotal; time++) {
259 Int_t signalL = TMath::Abs(digits->GetDataUnchecked(row,col ,time));
260 Int_t signalM = TMath::Abs(digits->GetDataUnchecked(row,col-1,time));
261 Int_t signalR = TMath::Abs(digits->GetDataUnchecked(row,col-2,time));
263 // Look for the maximum
264 if (signalM >= maxThresh) {
265 if (((signalL >= sigThresh) &&
266 (signalL < signalM)) ||
267 ((signalR >= sigThresh) &&
268 (signalR < signalM))) {
269 // Maximum found, mark the position by a negative signal
270 digits->SetDataUnchecked(row,col-1,time,-signalM);
278 // Now check the maxima and calculate the cluster position
279 for ( row = 0; row < nRowMax ; row++) {
280 for (time = 0; time < nTimeTotal; time++) {
281 for ( col = 1; col < nColMax-1; col++) {
284 if (digits->GetDataUnchecked(row,col,time) < 0) {
287 for (iPad = 0; iPad < kNclus; iPad++) {
288 Int_t iPadCol = col - 1 + iPad;
289 clusterSignal[iPad] = TMath::Abs(digits->GetDataUnchecked(row
292 clusterDigit[iPad] = digits->GetIndexUnchecked(row,iPadCol,time);
293 clusterTracks[3*iPad ] = track0->GetDataUnchecked(row,iPadCol,time) - 1;
294 clusterTracks[3*iPad+1] = track1->GetDataUnchecked(row,iPadCol,time) - 1;
295 clusterTracks[3*iPad+2] = track2->GetDataUnchecked(row,iPadCol,time) - 1;
298 // Count the number of pads in the cluster
301 while (TMath::Abs(digits->GetDataUnchecked(row,col-ii ,time))
305 if (col-ii < 0) break;
308 while (TMath::Abs(digits->GetDataUnchecked(row,col+ii+1,time))
312 if (col+ii+1 >= nColMax) break;
339 // Don't analyze large clusters
340 //if (iType == 4) continue;
342 // Look for 5 pad cluster with minimum in the middle
343 Bool_t fivePadCluster = kFALSE;
344 if (col < nColMax-3) {
345 if (digits->GetDataUnchecked(row,col+2,time) < 0) {
346 fivePadCluster = kTRUE;
348 if ((fivePadCluster) && (col < nColMax-5)) {
349 if (digits->GetDataUnchecked(row,col+4,time) >= sigThresh) {
350 fivePadCluster = kFALSE;
353 if ((fivePadCluster) && (col > 1)) {
354 if (digits->GetDataUnchecked(row,col-2,time) >= sigThresh) {
355 fivePadCluster = kFALSE;
361 // Modify the signal of the overlapping pad for the left part
362 // of the cluster which remains from a previous unfolding
364 clusterSignal[0] *= ratioLeft;
369 // Unfold the 5 pad cluster
370 if (fivePadCluster) {
371 for (iPad = 0; iPad < kNsig; iPad++) {
372 padSignal[iPad] = TMath::Abs(digits->GetDataUnchecked(row
376 // Unfold the two maxima and set the signal on
377 // the overlapping pad to the ratio
378 ratioRight = Unfold(kEpsilon,iplan,padSignal);
379 ratioLeft = 1.0 - ratioRight;
380 clusterSignal[2] *= ratioRight;
385 Float_t clusterCharge = clusterSignal[0]
389 // The position of the cluster
390 clusterPads[0] = row + 0.5;
391 // Take the shift of the additional time bins into account
392 clusterPads[2] = time - nTimeBefore + 0.5;
396 // Calculate the position of the cluster by using the
397 // lookup table method
398 clusterPads[1] = col + 0.5
399 + fPar->LUTposition(iplan,clusterSignal[0]
406 // Calculate the position of the cluster by using the
407 // center of gravity method
408 clusterPads[1] = col + 0.5
409 + (clusterSignal[2] - clusterSignal[0])
414 Float_t q0 = clusterSignal[0];
415 Float_t q1 = clusterSignal[1];
416 Float_t q2 = clusterSignal[2];
417 Float_t clusterSigmaY2 = (q1*(q0+q2)+4*q0*q2) /
418 (clusterCharge*clusterCharge);
420 // Correct for ExB displacement
422 Int_t local_time_bin = (Int_t) clusterPads[2];
423 Float_t driftLength = local_time_bin * timeBinSize + kAmWidth;
424 Float_t colSize = fPar->GetColPadSize(iplan);
425 Float_t deltaY = omegaTau*driftLength/colSize;
426 clusterPads[1] = clusterPads[1] - deltaY;
430 printf("-----------------------------------------------------------\n");
431 printf("Create cluster no. %d\n",nClusters);
432 printf("Position: row = %f, col = %f, time = %f\n",clusterPads[0]
435 printf("Indices: %d, %d, %d\n",clusterDigit[0]
438 printf("Total charge = %f\n",clusterCharge);
439 printf("Tracks: pad0 %d, %d, %d\n",clusterTracks[0]
442 printf(" pad1 %d, %d, %d\n",clusterTracks[3]
445 printf(" pad2 %d, %d, %d\n",clusterTracks[6]
448 printf("Type = %d, Number of pads = %d\n",iType,nPadCount);
451 // Calculate the position and the error
452 Float_t clusterPos[3];
453 clusterPos[0] = clusterPads[1] * colSize + col0;
454 clusterPos[1] = clusterPads[0] * rowSize + row0;
455 clusterPos[2] = clusterPads[2];
456 Float_t clusterSig[2];
457 clusterSig[0] = (clusterSigmaY2 + 1./12.) * colSize*colSize;
458 clusterSig[1] = rowSize * rowSize / 12.;
460 // Add the cluster to the output array
461 AddCluster(clusterPos
473 // Compress the arrays
474 digits->Compress(1,0);
475 track0->Compress(1,0);
476 track1->Compress(1,0);
477 track2->Compress(1,0);
479 // Write the cluster and reset the array
484 printf("<AliTRDclusterizerV1::MakeCluster> ");
485 printf("Found %d clusters in total.\n"
487 printf(" 2pad: %d\n",nClusters2pad);
488 printf(" 3pad: %d\n",nClusters3pad);
489 printf(" 4pad: %d\n",nClusters4pad);
490 printf(" 5pad: %d\n",nClusters5pad);
491 printf(" Large: %d\n",nClustersLarge);
499 printf("<AliTRDclusterizerV1::MakeCluster> ");
507 //_____________________________________________________________________________
508 Float_t AliTRDclusterizerV1::Unfold(Float_t eps, Int_t plane, Float_t* padSignal)
511 // Method to unfold neighbouring maxima.
512 // The charge ratio on the overlapping pad is calculated
513 // until there is no more change within the range given by eps.
514 // The resulting ratio is then returned to the calling method.
518 Int_t itStep = 0; // Count iteration steps
520 Float_t ratio = 0.5; // Start value for ratio
521 Float_t prevRatio = 0; // Store previous ratio
523 Float_t newLeftSignal[3] = {0}; // Array to store left cluster signal
524 Float_t newRightSignal[3] = {0}; // Array to store right cluster signal
525 Float_t newSignal[3] = {0};
527 // Start the iteration
528 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
533 // Cluster position according to charge ratio
534 Float_t maxLeft = (ratio*padSignal[2] - padSignal[0])
535 / (padSignal[0] + padSignal[1] + ratio*padSignal[2]);
536 Float_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
537 / ((1-ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
539 // Set cluster charge ratio
540 irc = fPar->PadResponse(1.0,maxLeft ,plane,newSignal);
541 Float_t ampLeft = padSignal[1] / newSignal[1];
542 irc = fPar->PadResponse(1.0,maxRight,plane,newSignal);
543 Float_t ampRight = padSignal[3] / newSignal[1];
545 // Apply pad response to parameters
546 irc = fPar->PadResponse(ampLeft ,maxLeft ,plane,newLeftSignal );
547 irc = fPar->PadResponse(ampRight,maxRight,plane,newRightSignal);
549 // Calculate new overlapping ratio
550 ratio = TMath::Min((Float_t)1.0,newLeftSignal[2] /
551 (newLeftSignal[2] + newRightSignal[0]));