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 #include "Cal/AliTRDCalROC.h"
49 #include "Cal/AliTRDCalDet.h"
51 ClassImp(AliTRDclusterizerV1)
53 //_____________________________________________________________________________
54 AliTRDclusterizerV1::AliTRDclusterizerV1()
59 // AliTRDclusterizerV1 default constructor
64 //_____________________________________________________________________________
65 AliTRDclusterizerV1::AliTRDclusterizerV1(const Text_t *name, const Text_t *title)
66 :AliTRDclusterizer(name,title)
67 ,fDigitsManager(new AliTRDdigitsManager())
70 // AliTRDclusterizerV1 constructor
73 fDigitsManager->CreateArrays();
77 //_____________________________________________________________________________
78 AliTRDclusterizerV1::AliTRDclusterizerV1(const AliTRDclusterizerV1 &c)
83 // AliTRDclusterizerV1 copy constructor
88 //_____________________________________________________________________________
89 AliTRDclusterizerV1::~AliTRDclusterizerV1()
92 // AliTRDclusterizerV1 destructor
96 delete fDigitsManager;
97 fDigitsManager = NULL;
102 //_____________________________________________________________________________
103 AliTRDclusterizerV1 &AliTRDclusterizerV1::operator=(const AliTRDclusterizerV1 &c)
106 // Assignment operator
109 if (this != &c) ((AliTRDclusterizerV1 &) c).Copy(*this);
114 //_____________________________________________________________________________
115 void AliTRDclusterizerV1::Copy(TObject &c) const
121 ((AliTRDclusterizerV1 &) c).fDigitsManager = 0;
123 AliTRDclusterizer::Copy(c);
127 //_____________________________________________________________________________
128 Bool_t AliTRDclusterizerV1::ReadDigits()
131 // Reads the digits arrays from the input aliroot file
135 AliError("No run loader available");
139 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
140 if (!loader->TreeD()) {
141 loader->LoadDigits();
144 // Read in the digit arrays
145 return (fDigitsManager->ReadDigits(loader->TreeD()));
149 //_____________________________________________________________________________
150 Bool_t AliTRDclusterizerV1::ReadDigits(AliRawReader *rawReader)
153 // Reads the digits arrays from the ddl file
157 fDigitsManager = raw.Raw2Digits(rawReader);
163 //_____________________________________________________________________________
164 Bool_t AliTRDclusterizerV1::MakeClusters()
167 // Generates the cluster.
178 AliTRDdataArrayI *digitsIn;
179 AliTRDdataArrayI *tracksIn;
182 AliTRDgeometry *geo = AliTRDgeometry::GetGeometry(fRunLoader);
184 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
186 AliFatal("No AliTRDcalibDB instance available\n");
190 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
192 AliError("No AliTRDSimParam instance available\n");
196 AliTRDRecParam *recParam = AliTRDRecParam::Instance();
198 AliError("No AliTRDRecParam instance available\n");
202 AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance();
204 AliError("Could not get common parameters\n");
209 Float_t ADCthreshold = simParam->GetADCthreshold();
210 // Threshold value for the maximum
211 Float_t maxThresh = recParam->GetClusMaxThresh();
212 // Threshold value for the digit signal
213 Float_t sigThresh = recParam->GetClusSigThresh();
215 // Detector wise calibration object for t0
216 const AliTRDCalDet *calT0Det = calibration->GetT0Det();
218 // Iteration limit for unfolding procedure
219 const Float_t kEpsilon = 0.01;
220 const Int_t kNclus = 3;
221 const Int_t kNsig = 5;
222 const Int_t kNdict = AliTRDdigitsManager::kNDict;
223 const Int_t kNtrack = kNdict * kNclus;
227 Double_t ratioLeft = 1.0;
228 Double_t ratioRight = 1.0;
230 Int_t iClusterROC = 0;
232 Double_t padSignal[kNsig];
233 Double_t clusterSignal[kNclus];
234 Double_t clusterPads[kNclus];
237 Int_t chamEnd = AliTRDgeometry::Ncham();
239 Int_t planEnd = AliTRDgeometry::Nplan();
241 Int_t sectEnd = AliTRDgeometry::Nsect();
242 Int_t nTimeTotal = calibration->GetNumberOfTimeBins();
244 Int_t dummy[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
246 AliDebug(1,Form("Number of Time Bins = %d.\n",nTimeTotal));
248 // Start clustering in every chamber
249 for (icham = chamBeg; icham < chamEnd; icham++) {
250 for (iplan = planBeg; iplan < planEnd; iplan++) {
251 for (isect = sectBeg; isect < sectEnd; isect++) {
253 Int_t idet = geo->GetDetector(iplan,icham,isect);
256 digitsIn = fDigitsManager->GetDigits(idet);
257 // This is to take care of switched off super modules
258 if (digitsIn->GetNtime() == 0) {
262 AliTRDdataArrayI *tracksTmp = fDigitsManager->GetDictionary(idet,0);
265 Int_t nRowMax = commonParam->GetRowMax(iplan,icham,isect);
266 Int_t nColMax = commonParam->GetColMax(iplan);
268 AliTRDpadPlane *padPlane = commonParam->GetPadPlane(iplan,icham);
270 // Calibration object with pad wise values for t0
271 AliTRDCalROC *calT0ROC = calibration->GetT0ROC(idet);
272 // Calibration value for chamber wise t0
273 Float_t calT0DetValue = calT0Det->GetValue(idet);
276 Int_t nClusters2pad = 0;
277 Int_t nClusters3pad = 0;
278 Int_t nClusters4pad = 0;
279 Int_t nClusters5pad = 0;
280 Int_t nClustersLarge = 0;
282 // Apply the gain and the tail cancelation via digital filter
283 AliTRDdataArrayF *digitsOut = new AliTRDdataArrayF(digitsIn->GetNrow()
285 ,digitsIn->GetNtime());
286 Transform(digitsIn,digitsOut,idet,nRowMax,nColMax,nTimeTotal,ADCthreshold);
288 // Input digits are not needed any more
289 digitsIn->Compress(1,0);
291 // Loop through the chamber and find the maxima
292 for ( row = 0; row < nRowMax; row++) {
293 for ( col = 2; col < nColMax; col++) {
294 for (time = 0; time < nTimeTotal; time++) {
296 Float_t signalL = TMath::Abs(digitsOut->GetDataUnchecked(row,col ,time));
297 Float_t signalM = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time));
298 Float_t signalR = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
300 // Look for the maximum
301 if (signalM >= maxThresh) {
302 if ((TMath::Abs(signalL) <= signalM) &&
303 (TMath::Abs(signalR) < signalM)) {
304 if ((TMath::Abs(signalL) >= sigThresh) ||
305 (TMath::Abs(signalR) >= sigThresh)) {
306 // Maximum found, mark the position by a negative signal
307 digitsOut->SetDataUnchecked(row,col-1,time,-signalM);
315 tracksTmp->Compress(1,0);
317 // The index to the first cluster of a given ROC
318 Int_t firstClusterROC = -1;
319 // The number of cluster in a given ROC
320 Int_t nClusterROC = 0;
322 // Now check the maxima and calculate the cluster position
323 for ( row = 0; row < nRowMax ; row++) {
324 for (time = 0; time < nTimeTotal; time++) {
325 for ( col = 1; col < nColMax-1; col++) {
328 if (digitsOut->GetDataUnchecked(row,col,time) < 0.0) {
330 for (iPad = 0; iPad < kNclus; iPad++) {
331 Int_t iPadCol = col - 1 + iPad;
332 clusterSignal[iPad] =
333 TMath::Abs(digitsOut->GetDataUnchecked(row,iPadCol,time));
336 // Count the number of pads in the cluster
341 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col-ii ,time)) >= sigThresh) {
344 if (col-ii < 0) break;
348 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col+ii+1,time)) >= sigThresh) {
351 if (col+ii+1 >= nColMax) break;
377 // Look for 5 pad cluster with minimum in the middle
378 Bool_t fivePadCluster = kFALSE;
379 if (col < (nColMax - 3)) {
380 if (digitsOut->GetDataUnchecked(row,col+2,time) < 0) {
381 fivePadCluster = kTRUE;
383 if ((fivePadCluster) && (col < (nColMax - 5))) {
384 if (digitsOut->GetDataUnchecked(row,col+4,time) >= sigThresh) {
385 fivePadCluster = kFALSE;
388 if ((fivePadCluster) && (col > 1)) {
389 if (digitsOut->GetDataUnchecked(row,col-2,time) >= sigThresh) {
390 fivePadCluster = kFALSE;
396 // Modify the signal of the overlapping pad for the left part
397 // of the cluster which remains from a previous unfolding
399 clusterSignal[0] *= ratioLeft;
404 // Unfold the 5 pad cluster
405 if (fivePadCluster) {
406 for (iPad = 0; iPad < kNsig; iPad++) {
407 padSignal[iPad] = TMath::Abs(digitsOut->GetDataUnchecked(row
411 // Unfold the two maxima and set the signal on
412 // the overlapping pad to the ratio
413 ratioRight = Unfold(kEpsilon,iplan,padSignal);
414 ratioLeft = 1.0 - ratioRight;
415 clusterSignal[2] *= ratioRight;
420 Double_t clusterCharge = clusterSignal[0]
424 // The position of the cluster
425 clusterPads[0] = row + 0.5;
426 // Take the shift of the additional time bins into account
427 clusterPads[2] = time + 0.5;
429 if (recParam->LUTOn()) {
430 // Calculate the position of the cluster by using the
431 // lookup table method
432 clusterPads[1] = recParam->LUTposition(iplan,clusterSignal[0]
437 // Calculate the position of the cluster by using the
438 // center of gravity method
439 for (Int_t i = 0; i < kNsig; i++) {
442 padSignal[2] = TMath::Abs(digitsOut->GetDataUnchecked(row,col ,time)); // Central pad
443 padSignal[1] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time)); // Left pad
444 padSignal[3] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+1,time)); // Right pad
446 (TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time)) < padSignal[1])) {
447 padSignal[0] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
449 if ((col < nColMax - 3) &&
450 (TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time)) < padSignal[3])) {
451 padSignal[4] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time));
453 clusterPads[1] = GetCOG(padSignal);
456 Double_t q0 = clusterSignal[0];
457 Double_t q1 = clusterSignal[1];
458 Double_t q2 = clusterSignal[2];
459 Double_t clusterSigmaY2 = (q1 * (q0 + q2) + 4.0 * q0 * q2)
460 / (clusterCharge*clusterCharge);
463 // Calculate the position and the error
466 // Correct for t0 (sum of chamber and pad wise values !!!)
467 Float_t calT0ROCValue = calT0ROC->GetValue(col,row);
468 Int_t clusterTimeBin = TMath::Nint(time - (calT0DetValue + calT0ROCValue));
469 Double_t colSize = padPlane->GetColSize(col);
470 Double_t rowSize = padPlane->GetRowSize(row);
472 Double_t clusterPos[3];
473 clusterPos[0] = padPlane->GetColPos(col) - (clusterPads[1] + 0.5) * colSize;
474 clusterPos[1] = padPlane->GetRowPos(row) - 0.5 * rowSize;
475 clusterPos[2] = CalcXposFromTimebin(clusterPads[2],idet,col,row);
477 printf("------------> idet=%d, row=%d, col=%d, time=%d\n",idet,row,col,time);
478 printf(" pos = %f, %f, %f\n",clusterPos[0],clusterPos[1],clusterPos[2]);
480 Double_t clusterSig[2];
481 clusterSig[0] = (clusterSigmaY2 + 1.0/12.0) * colSize*colSize;
482 clusterSig[1] = rowSize * rowSize / 12.0;
484 // Add the cluster to the output array
485 // The track indices will be stored later
486 AliTRDcluster *cluster = AddCluster(clusterPos
495 // Store the amplitudes of the pads in the cluster for later analysis
496 Short_t signals[7] = { 0, 0, 0, 0, 0, 0, 0 };
497 for (Int_t jPad = col-3; jPad <= col+3; jPad++) {
499 (jPad >= nColMax-1)) {
502 signals[jPad-col+3] = TMath::Nint(TMath::Abs(digitsOut->GetDataUnchecked(row,jPad,time)));
504 cluster->SetSignals(signals);
506 // Temporarily store the row, column and time bin of the center pad
507 // Used to later on assign the track indices
508 cluster->SetLabel( row,0);
509 cluster->SetLabel( col,1);
510 cluster->SetLabel(time,2);
512 // Store the index of the first cluster in the current ROC
513 if (firstClusterROC < 0) {
514 firstClusterROC = RecPoints()->GetEntriesFast() - 1;
516 // Count the number of cluster in the current ROC
519 } // if: Maximum found ?
521 } // loop: pad columns
528 // Add the track indices to the found clusters
531 // Temporary array to collect the track indices
532 Int_t *idxTracks = new Int_t[kNtrack*nClusterROC];
534 // Loop through the dictionary arrays one-by-one
535 // to keep memory consumption low
536 for (Int_t iDict = 0; iDict < kNdict; iDict++) {
538 tracksIn = fDigitsManager->GetDictionary(idet,iDict);
541 // Loop though the clusters found in this ROC
542 for (iClusterROC = 0; iClusterROC < nClusterROC; iClusterROC++) {
544 AliTRDcluster *cluster = (AliTRDcluster *)
545 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
546 row = cluster->GetLabel(0);
547 col = cluster->GetLabel(1);
548 time = cluster->GetLabel(2);
550 for (iPad = 0; iPad < kNclus; iPad++) {
551 Int_t iPadCol = col - 1 + iPad;
552 Int_t index = tracksIn->GetDataUnchecked(row,iPadCol,time) - 1;
553 idxTracks[3*iPad+iDict + iClusterROC*kNtrack] = index;
558 // Compress the arrays
559 tracksIn->Compress(1,0);
563 // Copy the track indices into the cluster
564 // Loop though the clusters found in this ROC
565 for (iClusterROC = 0; iClusterROC < nClusterROC; iClusterROC++) {
567 AliTRDcluster *cluster = (AliTRDcluster *)
568 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
569 cluster->SetLabel(-9999,0);
570 cluster->SetLabel(-9999,1);
571 cluster->SetLabel(-9999,2);
573 cluster->AddTrackIndex(&idxTracks[iClusterROC*kNtrack]);
579 // Write the cluster and reset the array
591 //_____________________________________________________________________________
592 Double_t AliTRDclusterizerV1::GetCOG(Double_t signal[5])
596 // Used for clusters with more than 3 pads - where LUT not applicable
599 Double_t sum = signal[0]
605 Double_t res = (0.0 * (-signal[0] + signal[4])
606 + (-signal[1] + signal[3])) / sum;
612 //_____________________________________________________________________________
613 Double_t AliTRDclusterizerV1::Unfold(Double_t eps, Int_t plane, Double_t *padSignal)
616 // Method to unfold neighbouring maxima.
617 // The charge ratio on the overlapping pad is calculated
618 // until there is no more change within the range given by eps.
619 // The resulting ratio is then returned to the calling method.
622 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
624 AliError("No AliTRDcalibDB instance available\n");
629 Int_t itStep = 0; // Count iteration steps
631 Double_t ratio = 0.5; // Start value for ratio
632 Double_t prevRatio = 0.0; // Store previous ratio
634 Double_t newLeftSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store left cluster signal
635 Double_t newRightSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store right cluster signal
636 Double_t newSignal[3] = { 0.0, 0.0, 0.0 };
638 // Start the iteration
639 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
644 // Cluster position according to charge ratio
645 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
646 / (padSignal[0] + padSignal[1] + ratio*padSignal[2]);
647 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
648 / ((1.0 - ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
650 // Set cluster charge ratio
651 irc = calibration->PadResponse(1.0,maxLeft ,plane,newSignal);
652 Double_t ampLeft = padSignal[1] / newSignal[1];
653 irc = calibration->PadResponse(1.0,maxRight,plane,newSignal);
654 Double_t ampRight = padSignal[3] / newSignal[1];
656 // Apply pad response to parameters
657 irc = calibration->PadResponse(ampLeft ,maxLeft ,plane,newLeftSignal );
658 irc = calibration->PadResponse(ampRight,maxRight,plane,newRightSignal);
660 // Calculate new overlapping ratio
661 ratio = TMath::Min((Double_t)1.0,newLeftSignal[2] /
662 (newLeftSignal[2] + newRightSignal[0]));
670 //_____________________________________________________________________________
671 void AliTRDclusterizerV1::Transform(AliTRDdataArrayI *digitsIn
672 , AliTRDdataArrayF *digitsOut
673 , Int_t idet, Int_t nRowMax
674 , Int_t nColMax, Int_t nTimeTotal
675 , Float_t ADCthreshold)
679 // Apply tail cancelation: Transform digitsIn to digitsOut
686 AliTRDRecParam *recParam = AliTRDRecParam::Instance();
688 AliError("No AliTRDRecParam instance available\n");
691 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
693 AliError("No AliTRDcalibDB instance available\n");
697 Double_t *inADC = new Double_t[nTimeTotal]; // ADC data before tail cancellation
698 Double_t *outADC = new Double_t[nTimeTotal]; // ADC data after tail cancellation
700 AliDebug(1,Form("Tail cancellation (nExp = %d) for detector %d.\n"
701 ,recParam->GetTCnexp(),idet));
703 // Calibration object with chamber wise values for the gain factor
704 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
705 // Calibration object with pad wise values for the gain factor
706 AliTRDCalROC *calGainFactorROC = calibration->GetGainFactorROC(idet);
707 // Calibration value for chamber wise gain factors
708 Float_t calGainFactorDetValue = calGainFactorDet->GetValue(idet);
710 for (iRow = 0; iRow < nRowMax; iRow++ ) {
711 for (iCol = 0; iCol < nColMax; iCol++ ) {
713 Float_t calGainFactorROCValue = calGainFactorROC->GetValue(iCol,iRow);
714 Double_t gain = calGainFactorDetValue
715 * calGainFactorROCValue;
717 for (iTime = 0; iTime < nTimeTotal; iTime++) {
722 inADC[iTime] = digitsIn->GetDataUnchecked(iRow,iCol,iTime);
723 inADC[iTime] /= gain;
724 outADC[iTime] = inADC[iTime];
728 // Apply the tail cancelation via the digital filter
729 if (recParam->TCOn()) {
730 DeConvExp(inADC,outADC,nTimeTotal,recParam->GetTCnexp());
733 for (iTime = 0; iTime < nTimeTotal; iTime++) {
735 // Store the amplitude of the digit if above threshold
736 if (outADC[iTime] > ADCthreshold) {
737 digitsOut->SetDataUnchecked(iRow,iCol,iTime,outADC[iTime]);
752 //_____________________________________________________________________________
753 void AliTRDclusterizerV1::DeConvExp(Double_t *source, Double_t *target
754 , Int_t n, Int_t nexp)
757 // Tail cancellation by deconvolution for PASA v4 TRF
761 Double_t coefficients[2];
763 // Initialization (coefficient = alpha, rates = lambda)
769 if (nexp == 1) { // 1 Exponentials
775 if (nexp == 2) { // 2 Exponentials
782 coefficients[0] = C1;
783 coefficients[1] = C2;
787 rates[0] = TMath::Exp(-Dt/(R1));
788 rates[1] = TMath::Exp(-Dt/(R2));
793 Double_t reminder[2];
797 // Attention: computation order is important
799 for (k = 0; k < nexp; k++) {
802 for (i = 0; i < n; i++) {
803 result = (source[i] - correction); // No rescaling
806 for (k = 0; k < nexp; k++) {
807 reminder[k] = rates[k] * (reminder[k] + coefficients[k] * result);
810 for (k = 0; k < nexp; k++) {
811 correction += reminder[k];