2 /**************************************************************************
3 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
19 ///////////////////////////////////////////////////////////////////////////////
21 // TRD cluster finder //
23 ///////////////////////////////////////////////////////////////////////////////
30 #include "AliRunLoader.h"
31 #include "AliLoader.h"
32 #include "AliRawReader.h"
35 #include "AliTRDclusterizerV1.h"
36 #include "AliTRDgeometry.h"
37 #include "AliTRDdataArrayF.h"
38 #include "AliTRDdataArrayI.h"
39 #include "AliTRDdigitsManager.h"
40 #include "AliTRDpadPlane.h"
41 #include "AliTRDrawData.h"
42 #include "AliTRDcalibDB.h"
43 #include "AliTRDSimParam.h"
44 #include "AliTRDRecParam.h"
45 #include "AliTRDCommonParam.h"
46 #include "AliTRDcluster.h"
48 ClassImp(AliTRDclusterizerV1)
50 //_____________________________________________________________________________
51 AliTRDclusterizerV1::AliTRDclusterizerV1()
56 // AliTRDclusterizerV1 default constructor
61 //_____________________________________________________________________________
62 AliTRDclusterizerV1::AliTRDclusterizerV1(const Text_t *name, const Text_t *title)
63 :AliTRDclusterizer(name,title)
64 ,fDigitsManager(new AliTRDdigitsManager())
67 // AliTRDclusterizerV1 constructor
70 fDigitsManager->CreateArrays();
74 //_____________________________________________________________________________
75 AliTRDclusterizerV1::AliTRDclusterizerV1(const AliTRDclusterizerV1 &c)
80 // AliTRDclusterizerV1 copy constructor
85 //_____________________________________________________________________________
86 AliTRDclusterizerV1::~AliTRDclusterizerV1()
89 // AliTRDclusterizerV1 destructor
93 delete fDigitsManager;
94 fDigitsManager = NULL;
99 //_____________________________________________________________________________
100 AliTRDclusterizerV1 &AliTRDclusterizerV1::operator=(const AliTRDclusterizerV1 &c)
103 // Assignment operator
106 if (this != &c) ((AliTRDclusterizerV1 &) c).Copy(*this);
111 //_____________________________________________________________________________
112 void AliTRDclusterizerV1::Copy(TObject &c) const
118 ((AliTRDclusterizerV1 &) c).fDigitsManager = 0;
120 AliTRDclusterizer::Copy(c);
124 //_____________________________________________________________________________
125 Bool_t AliTRDclusterizerV1::ReadDigits()
128 // Reads the digits arrays from the input aliroot file
132 AliError("No run loader available");
136 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
137 if (!loader->TreeD()) {
138 loader->LoadDigits();
141 // Read in the digit arrays
142 return (fDigitsManager->ReadDigits(loader->TreeD()));
146 //_____________________________________________________________________________
147 Bool_t AliTRDclusterizerV1::ReadDigits(AliRawReader *rawReader)
150 // Reads the digits arrays from the ddl file
154 fDigitsManager = raw.Raw2Digits(rawReader);
160 //_____________________________________________________________________________
161 Bool_t AliTRDclusterizerV1::MakeClusters()
164 // Generates the cluster.
175 AliTRDdataArrayI *digitsIn;
176 AliTRDdataArrayI *tracksIn;
179 AliTRDgeometry *geo = AliTRDgeometry::GetGeometry(fRunLoader);
181 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
183 AliError("No AliTRDcalibDB instance available\n");
187 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
189 AliError("No AliTRDSimParam instance available\n");
193 AliTRDRecParam *recParam = AliTRDRecParam::Instance();
195 AliError("No AliTRDRecParam instance available\n");
199 AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance();
201 AliError("Could not get common parameters\n");
206 Float_t ADCthreshold = simParam->GetADCthreshold();
207 // Threshold value for the maximum
208 Float_t maxThresh = recParam->GetClusMaxThresh();
209 // Threshold value for the digit signal
210 Float_t sigThresh = recParam->GetClusSigThresh();
212 // Iteration limit for unfolding procedure
213 const Float_t kEpsilon = 0.01;
214 const Int_t kNclus = 3;
215 const Int_t kNsig = 5;
216 const Int_t kNdict = AliTRDdigitsManager::kNDict;
217 const Int_t kNtrack = kNdict * kNclus;
221 Double_t ratioLeft = 1.0;
222 Double_t ratioRight = 1.0;
224 Int_t iClusterROC = 0;
226 Double_t padSignal[kNsig];
227 Double_t clusterSignal[kNclus];
228 Double_t clusterPads[kNclus];
231 Int_t chamEnd = AliTRDgeometry::Ncham();
233 Int_t planEnd = AliTRDgeometry::Nplan();
235 Int_t sectEnd = AliTRDgeometry::Nsect();
236 Int_t nTimeTotal = calibration->GetNumberOfTimeBins();
238 Int_t dummy[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
240 AliDebug(1,Form("Number of Time Bins = %d.\n",nTimeTotal));
242 // Start clustering in every chamber
243 for (icham = chamBeg; icham < chamEnd; icham++) {
244 for (iplan = planBeg; iplan < planEnd; iplan++) {
245 for (isect = sectBeg; isect < sectEnd; isect++) {
247 Int_t idet = geo->GetDetector(iplan,icham,isect);
250 digitsIn = fDigitsManager->GetDigits(idet);
251 // This is to take care of switched off super modules
252 if (digitsIn->GetNtime() == 0) {
256 AliTRDdataArrayI *tracksTmp = fDigitsManager->GetDictionary(idet,0);
259 Int_t nRowMax = commonParam->GetRowMax(iplan,icham,isect);
260 Int_t nColMax = commonParam->GetColMax(iplan);
262 AliTRDpadPlane *padPlane = commonParam->GetPadPlane(iplan,icham);
265 Int_t nClusters2pad = 0;
266 Int_t nClusters3pad = 0;
267 Int_t nClusters4pad = 0;
268 Int_t nClusters5pad = 0;
269 Int_t nClustersLarge = 0;
271 // Apply the gain and the tail cancelation via digital filter
272 AliTRDdataArrayF *digitsOut = new AliTRDdataArrayF(digitsIn->GetNrow()
274 ,digitsIn->GetNtime());
275 Transform(digitsIn,digitsOut,idet,nRowMax,nColMax,nTimeTotal,ADCthreshold);
277 // Input digits are not needed any more
278 digitsIn->Compress(1,0);
280 // Loop through the chamber and find the maxima
281 for ( row = 0; row < nRowMax; row++) {
282 for ( col = 2; col < nColMax; col++) {
283 for (time = 0; time < nTimeTotal; time++) {
285 Float_t signalL = TMath::Abs(digitsOut->GetDataUnchecked(row,col ,time));
286 Float_t signalM = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time));
287 Float_t signalR = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
289 // Look for the maximum
290 if (signalM >= maxThresh) {
291 if ((TMath::Abs(signalL) <= signalM) &&
292 (TMath::Abs(signalR) < signalM)) {
293 if ((TMath::Abs(signalL) >= sigThresh) ||
294 (TMath::Abs(signalR) >= sigThresh)) {
295 // Maximum found, mark the position by a negative signal
296 digitsOut->SetDataUnchecked(row,col-1,time,-signalM);
304 tracksTmp->Compress(1,0);
306 // The index to the first cluster of a given ROC
307 Int_t firstClusterROC = -1;
308 // The number of cluster in a given ROC
309 Int_t nClusterROC = 0;
311 // Now check the maxima and calculate the cluster position
312 for ( row = 0; row < nRowMax ; row++) {
313 for (time = 0; time < nTimeTotal; time++) {
314 for ( col = 1; col < nColMax-1; col++) {
317 if (digitsOut->GetDataUnchecked(row,col,time) < 0.0) {
319 for (iPad = 0; iPad < kNclus; iPad++) {
320 Int_t iPadCol = col - 1 + iPad;
321 clusterSignal[iPad] =
322 TMath::Abs(digitsOut->GetDataUnchecked(row,iPadCol,time));
325 // Count the number of pads in the cluster
330 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col-ii ,time)) >= sigThresh) {
333 if (col-ii < 0) break;
337 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col+ii+1,time)) >= sigThresh) {
340 if (col+ii+1 >= nColMax) break;
366 // Look for 5 pad cluster with minimum in the middle
367 Bool_t fivePadCluster = kFALSE;
368 if (col < (nColMax - 3)) {
369 if (digitsOut->GetDataUnchecked(row,col+2,time) < 0) {
370 fivePadCluster = kTRUE;
372 if ((fivePadCluster) && (col < (nColMax - 5))) {
373 if (digitsOut->GetDataUnchecked(row,col+4,time) >= sigThresh) {
374 fivePadCluster = kFALSE;
377 if ((fivePadCluster) && (col > 1)) {
378 if (digitsOut->GetDataUnchecked(row,col-2,time) >= sigThresh) {
379 fivePadCluster = kFALSE;
385 // Modify the signal of the overlapping pad for the left part
386 // of the cluster which remains from a previous unfolding
388 clusterSignal[0] *= ratioLeft;
393 // Unfold the 5 pad cluster
394 if (fivePadCluster) {
395 for (iPad = 0; iPad < kNsig; iPad++) {
396 padSignal[iPad] = TMath::Abs(digitsOut->GetDataUnchecked(row
400 // Unfold the two maxima and set the signal on
401 // the overlapping pad to the ratio
402 ratioRight = Unfold(kEpsilon,iplan,padSignal);
403 ratioLeft = 1.0 - ratioRight;
404 clusterSignal[2] *= ratioRight;
409 Double_t clusterCharge = clusterSignal[0]
413 // The position of the cluster
414 clusterPads[0] = row + 0.5;
415 // Take the shift of the additional time bins into account
416 clusterPads[2] = time + 0.5;
418 if (recParam->LUTOn()) {
419 // Calculate the position of the cluster by using the
420 // lookup table method
421 clusterPads[1] = recParam->LUTposition(iplan,clusterSignal[0]
426 // Calculate the position of the cluster by using the
427 // center of gravity method
428 for (Int_t i = 0; i < kNsig; i++) {
431 padSignal[2] = TMath::Abs(digitsOut->GetDataUnchecked(row,col ,time)); // Central pad
432 padSignal[1] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time)); // Left pad
433 padSignal[3] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+1,time)); // Right pad
435 (TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time)) < padSignal[1])) {
436 padSignal[0] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
438 if ((col < nColMax - 3) &&
439 (TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time)) < padSignal[3])) {
440 padSignal[4] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time));
442 clusterPads[1] = GetCOG(padSignal);
445 Double_t q0 = clusterSignal[0];
446 Double_t q1 = clusterSignal[1];
447 Double_t q2 = clusterSignal[2];
448 Double_t clusterSigmaY2 = (q1 * (q0 + q2) + 4.0 * q0 * q2)
449 / (clusterCharge*clusterCharge);
452 // Calculate the position and the error
456 Int_t clusterTimeBin = TMath::Nint(time - calibration->GetT0(idet,col,row));
457 Double_t colSize = padPlane->GetColSize(col);
458 Double_t rowSize = padPlane->GetRowSize(row);
460 Double_t clusterPos[3];
461 clusterPos[0] = padPlane->GetColPos(col) - (clusterPads[1] + 0.5) * colSize;
462 clusterPos[1] = padPlane->GetRowPos(row) - 0.5 * rowSize;
463 clusterPos[2] = CalcXposFromTimebin(clusterPads[2],idet,col,row);
464 Double_t clusterSig[2];
465 clusterSig[0] = (clusterSigmaY2 + 1.0/12.0) * colSize*colSize;
466 clusterSig[1] = rowSize * rowSize / 12.0;
468 // Add the cluster to the output array
469 // The track indices will be stored later
470 AliTRDcluster *cluster = AddCluster(clusterPos
479 // Store the amplitudes of the pads in the cluster for later analysis
480 Short_t signals[7] = { 0, 0, 0, 0, 0, 0, 0 };
481 for (Int_t jPad = col-3; jPad <= col+3; jPad++) {
483 (jPad >= nColMax-1)) {
486 signals[jPad-col+3] = TMath::Nint(TMath::Abs(digitsOut->GetDataUnchecked(row,jPad,time)));
488 cluster->SetSignals(signals);
490 // Temporarily store the row, column and time bin of the center pad
491 // Used to later on assign the track indices
492 cluster->SetLabel( row,0);
493 cluster->SetLabel( col,1);
494 cluster->SetLabel(time,2);
496 // Store the index of the first cluster in the current ROC
497 if (firstClusterROC < 0) {
498 firstClusterROC = RecPoints()->GetEntriesFast() - 1;
500 // Count the number of cluster in the current ROC
503 } // if: Maximum found ?
505 } // loop: pad columns
512 // Add the track indices to the found clusters
515 // Temporary array to collect the track indices
516 Int_t *idxTracks = new Int_t[kNtrack*nClusterROC];
518 // Loop through the dictionary arrays one-by-one
519 // to keep memory consumption low
520 for (Int_t iDict = 0; iDict < kNdict; iDict++) {
522 tracksIn = fDigitsManager->GetDictionary(idet,iDict);
525 // Loop though the clusters found in this ROC
526 for (iClusterROC = 0; iClusterROC < nClusterROC; iClusterROC++) {
528 AliTRDcluster *cluster = (AliTRDcluster *)
529 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
530 row = cluster->GetLabel(0);
531 col = cluster->GetLabel(1);
532 time = cluster->GetLabel(2);
534 for (iPad = 0; iPad < kNclus; iPad++) {
535 Int_t iPadCol = col - 1 + iPad;
536 Int_t index = tracksIn->GetDataUnchecked(row,iPadCol,time) - 1;
537 idxTracks[3*iPad+iDict + iClusterROC*kNtrack] = index;
542 // Compress the arrays
543 tracksIn->Compress(1,0);
547 // Copy the track indices into the cluster
548 // Loop though the clusters found in this ROC
549 for (iClusterROC = 0; iClusterROC < nClusterROC; iClusterROC++) {
551 AliTRDcluster *cluster = (AliTRDcluster *)
552 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
553 cluster->SetLabel(-9999,0);
554 cluster->SetLabel(-9999,1);
555 cluster->SetLabel(-9999,2);
557 cluster->AddTrackIndex(&idxTracks[iClusterROC*kNtrack]);
563 // Write the cluster and reset the array
575 //_____________________________________________________________________________
576 Double_t AliTRDclusterizerV1::GetCOG(Double_t signal[5])
580 // Used for clusters with more than 3 pads - where LUT not applicable
583 Double_t sum = signal[0]
589 Double_t res = (0.0 * (-signal[0] + signal[4])
590 + (-signal[1] + signal[3])) / sum;
596 //_____________________________________________________________________________
597 Double_t AliTRDclusterizerV1::Unfold(Double_t eps, Int_t plane, Double_t *padSignal)
600 // Method to unfold neighbouring maxima.
601 // The charge ratio on the overlapping pad is calculated
602 // until there is no more change within the range given by eps.
603 // The resulting ratio is then returned to the calling method.
606 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
608 AliError("No AliTRDcalibDB instance available\n");
613 Int_t itStep = 0; // Count iteration steps
615 Double_t ratio = 0.5; // Start value for ratio
616 Double_t prevRatio = 0.0; // Store previous ratio
618 Double_t newLeftSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store left cluster signal
619 Double_t newRightSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store right cluster signal
620 Double_t newSignal[3] = { 0.0, 0.0, 0.0 };
622 // Start the iteration
623 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
628 // Cluster position according to charge ratio
629 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
630 / (padSignal[0] + padSignal[1] + ratio*padSignal[2]);
631 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
632 / ((1.0 - ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
634 // Set cluster charge ratio
635 irc = calibration->PadResponse(1.0,maxLeft ,plane,newSignal);
636 Double_t ampLeft = padSignal[1] / newSignal[1];
637 irc = calibration->PadResponse(1.0,maxRight,plane,newSignal);
638 Double_t ampRight = padSignal[3] / newSignal[1];
640 // Apply pad response to parameters
641 irc = calibration->PadResponse(ampLeft ,maxLeft ,plane,newLeftSignal );
642 irc = calibration->PadResponse(ampRight,maxRight,plane,newRightSignal);
644 // Calculate new overlapping ratio
645 ratio = TMath::Min((Double_t)1.0,newLeftSignal[2] /
646 (newLeftSignal[2] + newRightSignal[0]));
654 //_____________________________________________________________________________
655 void AliTRDclusterizerV1::Transform(AliTRDdataArrayI *digitsIn
656 , AliTRDdataArrayF *digitsOut
657 , Int_t idet, Int_t nRowMax
658 , Int_t nColMax, Int_t nTimeTotal
659 , Float_t ADCthreshold)
663 // Apply tail cancelation: Transform digitsIn to digitsOut
670 AliTRDRecParam *recParam = AliTRDRecParam::Instance();
672 AliError("No AliTRDRecParam instance available\n");
675 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
677 AliError("No AliTRDcalibDB instance available\n");
681 Double_t *inADC = new Double_t[nTimeTotal]; // ADC data before tail cancellation
682 Double_t *outADC = new Double_t[nTimeTotal]; // ADC data after tail cancellation
684 AliDebug(1,Form("Tail cancellation (nExp = %d) for detector %d.\n"
685 ,recParam->GetTCnexp(),idet));
687 for (iRow = 0; iRow < nRowMax; iRow++ ) {
688 for (iCol = 0; iCol < nColMax; iCol++ ) {
690 for (iTime = 0; iTime < nTimeTotal; iTime++) {
695 Double_t gain = calibration->GetGainFactor(idet,iCol,iRow);
697 AliError("Not a valid gain\n");
699 inADC[iTime] = digitsIn->GetDataUnchecked(iRow,iCol,iTime);
700 inADC[iTime] /= gain;
701 outADC[iTime] = inADC[iTime];
705 // Apply the tail cancelation via the digital filter
706 if (recParam->TCOn()) {
707 DeConvExp(inADC,outADC,nTimeTotal,recParam->GetTCnexp());
710 for (iTime = 0; iTime < nTimeTotal; iTime++) {
712 // Store the amplitude of the digit if above threshold
713 if (outADC[iTime] > ADCthreshold) {
714 digitsOut->SetDataUnchecked(iRow,iCol,iTime,outADC[iTime]);
729 //_____________________________________________________________________________
730 void AliTRDclusterizerV1::DeConvExp(Double_t *source, Double_t *target
731 , Int_t n, Int_t nexp)
734 // Tail cancellation by deconvolution for PASA v4 TRF
738 Double_t coefficients[2];
740 // Initialization (coefficient = alpha, rates = lambda)
746 if (nexp == 1) { // 1 Exponentials
752 if (nexp == 2) { // 2 Exponentials
759 coefficients[0] = C1;
760 coefficients[1] = C2;
764 rates[0] = TMath::Exp(-Dt/(R1));
765 rates[1] = TMath::Exp(-Dt/(R2));
770 Double_t reminder[2];
774 // Attention: computation order is important
776 for (k = 0; k < nexp; k++) {
779 for (i = 0; i < n; i++) {
780 result = (source[i] - correction); // No rescaling
783 for (k = 0; k < nexp; k++) {
784 reminder[k] = rates[k] * (reminder[k] + coefficients[k] * result);
787 for (k = 0; k < nexp; k++) {
788 correction += reminder[k];