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"
34 #include "AliAlignObj.h"
36 #include "AliTRDclusterizerV1.h"
37 #include "AliTRDgeometry.h"
38 #include "AliTRDdataArrayF.h"
39 #include "AliTRDdataArrayI.h"
40 #include "AliTRDdigitsManager.h"
41 #include "AliTRDpadPlane.h"
42 #include "AliTRDrawData.h"
43 #include "AliTRDcalibDB.h"
44 #include "AliTRDSimParam.h"
45 #include "AliTRDRecParam.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(TTree *digitsTree)
153 // Reads the digits arrays from the input tree
156 // Read in the digit arrays
157 return (fDigitsManager->ReadDigits(digitsTree));
161 //_____________________________________________________________________________
162 Bool_t AliTRDclusterizerV1::ReadDigits(AliRawReader *rawReader)
165 // Reads the digits arrays from the ddl file
169 fDigitsManager = raw.Raw2Digits(rawReader);
175 //_____________________________________________________________________________
176 Bool_t AliTRDclusterizerV1::MakeClusters()
179 // Generates the cluster.
190 AliTRDdataArrayI *digitsIn;
191 AliTRDdataArrayI *tracksIn;
195 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
197 AliFatal("No AliTRDcalibDB instance available\n");
201 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
203 AliError("No AliTRDSimParam instance available\n");
207 AliTRDRecParam *recParam = AliTRDRecParam::Instance();
209 AliError("No AliTRDRecParam instance available\n");
214 Float_t ADCthreshold = simParam->GetADCthreshold();
215 // Threshold value for the maximum
216 Float_t maxThresh = recParam->GetClusMaxThresh();
217 // Threshold value for the digit signal
218 Float_t sigThresh = recParam->GetClusSigThresh();
220 // Detector wise calibration object for t0
221 const AliTRDCalDet *calT0Det = calibration->GetT0Det();
222 // Detector wise calibration object for the gain factors
223 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
225 // Iteration limit for unfolding procedure
226 const Float_t kEpsilon = 0.01;
227 const Int_t kNclus = 3;
228 const Int_t kNsig = 5;
229 const Int_t kNdict = AliTRDdigitsManager::kNDict;
230 const Int_t kNtrack = kNdict * kNclus;
233 Double_t ratioLeft = 1.0;
234 Double_t ratioRight = 1.0;
236 Int_t iClusterROC = 0;
238 Double_t padSignal[kNsig];
239 Double_t clusterSignal[kNclus];
240 Double_t clusterPads[kNclus];
243 Int_t chamEnd = AliTRDgeometry::Ncham();
245 Int_t planEnd = AliTRDgeometry::Nplan();
247 Int_t sectEnd = AliTRDgeometry::Nsect();
248 Int_t nTimeTotal = calibration->GetNumberOfTimeBins();
250 AliDebug(1,Form("Number of Time Bins = %d.\n",nTimeTotal));
252 // Start clustering in every chamber
253 for (icham = chamBeg; icham < chamEnd; icham++) {
254 for (iplan = planBeg; iplan < planEnd; iplan++) {
255 for (isect = sectBeg; isect < sectEnd; isect++) {
257 Int_t idet = geo.GetDetector(iplan,icham,isect);
258 Int_t ilayer = AliGeomManager::kTRD1 + iplan;
259 Int_t imodule = icham + chamEnd * isect;
260 UShort_t volid = AliGeomManager::LayerToVolUID(ilayer,imodule);
263 digitsIn = fDigitsManager->GetDigits(idet);
264 // This is to take care of switched off super modules
265 if (digitsIn->GetNtime() == 0) {
269 AliTRDdataArrayI *tracksTmp = fDigitsManager->GetDictionary(idet,0);
272 Int_t nRowMax = geo.GetRowMax(iplan,icham,isect);
273 Int_t nColMax = geo.GetColMax(iplan);
275 AliTRDpadPlane *padPlane = geo.GetPadPlane(iplan,icham);
277 // Calibration object with pad wise values for t0
278 AliTRDCalROC *calT0ROC = calibration->GetT0ROC(idet);
279 // Calibration object with pad wise values for the gain factors
280 AliTRDCalROC *calGainFactorROC = calibration->GetGainFactorROC(idet);
281 // Calibration value for chamber wise t0
282 Float_t calT0DetValue = calT0Det->GetValue(idet);
283 // Calibration value for chamber wise gain factor
284 Float_t calGainFactorDetValue = calGainFactorDet->GetValue(idet);
288 // Apply the gain and the tail cancelation via digital filter
289 AliTRDdataArrayF *digitsOut = new AliTRDdataArrayF(digitsIn->GetNrow()
291 ,digitsIn->GetNtime());
294 ,nRowMax,nColMax,nTimeTotal
297 ,calGainFactorDetValue);
299 // Input digits are not needed any more
300 digitsIn->Compress(1,0);
302 // Loop through the chamber and find the maxima
303 for ( row = 0; row < nRowMax; row++) {
304 for ( col = 2; col < nColMax; col++) {
305 for (time = 0; time < nTimeTotal; time++) {
307 Float_t signalM = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time));
309 // Look for the maximum
310 if (signalM >= maxThresh) {
312 Float_t signalL = TMath::Abs(digitsOut->GetDataUnchecked(row,col ,time));
313 Float_t signalR = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
315 if ((TMath::Abs(signalL) <= signalM) &&
316 (TMath::Abs(signalR) < signalM)) {
317 if ((TMath::Abs(signalL) >= sigThresh) ||
318 (TMath::Abs(signalR) >= sigThresh)) {
319 // Maximum found, mark the position by a negative signal
320 digitsOut->SetDataUnchecked(row,col-1,time,-signalM);
329 tracksTmp->Compress(1,0);
331 // The index to the first cluster of a given ROC
332 Int_t firstClusterROC = -1;
333 // The number of cluster in a given ROC
334 Int_t nClusterROC = 0;
336 // Now check the maxima and calculate the cluster position
337 for ( row = 0; row < nRowMax ; row++) {
338 for (time = 0; time < nTimeTotal; time++) {
339 for ( col = 1; col < nColMax-1; col++) {
342 if (digitsOut->GetDataUnchecked(row,col,time) < 0.0) {
344 for (iPad = 0; iPad < kNclus; iPad++) {
345 Int_t iPadCol = col - 1 + iPad;
346 clusterSignal[iPad] =
347 TMath::Abs(digitsOut->GetDataUnchecked(row,iPadCol,time));
350 // Count the number of pads in the cluster
355 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col-ii ,time)) >= sigThresh) {
358 if (col-ii < 0) break;
362 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col+ii+1,time)) >= sigThresh) {
365 if (col+ii+1 >= nColMax) break;
369 // Look for 5 pad cluster with minimum in the middle
370 Bool_t fivePadCluster = kFALSE;
371 if (col < (nColMax - 3)) {
372 if (digitsOut->GetDataUnchecked(row,col+2,time) < 0) {
373 fivePadCluster = kTRUE;
375 if ((fivePadCluster) && (col < (nColMax - 5))) {
376 if (digitsOut->GetDataUnchecked(row,col+4,time) >= sigThresh) {
377 fivePadCluster = kFALSE;
380 if ((fivePadCluster) && (col > 1)) {
381 if (digitsOut->GetDataUnchecked(row,col-2,time) >= sigThresh) {
382 fivePadCluster = kFALSE;
388 // Modify the signal of the overlapping pad for the left part
389 // of the cluster which remains from a previous unfolding
391 clusterSignal[0] *= ratioLeft;
395 // Unfold the 5 pad cluster
396 if (fivePadCluster) {
397 for (iPad = 0; iPad < kNsig; iPad++) {
398 padSignal[iPad] = TMath::Abs(digitsOut->GetDataUnchecked(row
402 // Unfold the two maxima and set the signal on
403 // the overlapping pad to the ratio
404 ratioRight = Unfold(kEpsilon,iplan,padSignal);
405 ratioLeft = 1.0 - ratioRight;
406 clusterSignal[2] *= ratioRight;
410 Double_t clusterCharge = clusterSignal[0]
414 // The position of the cluster
415 clusterPads[0] = row + 0.5;
416 // Take the shift of the additional time bins into account
417 clusterPads[2] = time + 0.5;
419 if (recParam->LUTOn()) {
420 // Calculate the position of the cluster by using the
421 // lookup table method
422 clusterPads[1] = recParam->LUTposition(iplan,clusterSignal[0]
427 // Calculate the position of the cluster by using the
428 // center of gravity method
429 for (Int_t i = 0; i < kNsig; i++) {
432 padSignal[2] = TMath::Abs(digitsOut->GetDataUnchecked(row,col ,time)); // Central pad
433 padSignal[1] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time)); // Left pad
434 padSignal[3] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+1,time)); // Right pad
436 (TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time)) < padSignal[1])) {
437 padSignal[0] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
439 if ((col < nColMax - 3) &&
440 (TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time)) < padSignal[3])) {
441 padSignal[4] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time));
443 clusterPads[1] = GetCOG(padSignal);
446 Double_t q0 = clusterSignal[0];
447 Double_t q1 = clusterSignal[1];
448 Double_t q2 = clusterSignal[2];
449 Double_t clusterSigmaY2 = (q1 * (q0 + q2) + 4.0 * q0 * q2)
450 / (clusterCharge*clusterCharge);
453 // Calculate the position and the error
456 // Correct for t0 (sum of chamber and pad wise values !!!)
457 Float_t calT0ROCValue = calT0ROC->GetValue(col,row);
458 Char_t clusterTimeBin = ((Char_t) TMath::Nint(time - (calT0DetValue + calT0ROCValue)));
459 Double_t colSize = padPlane->GetColSize(col);
460 Double_t rowSize = padPlane->GetRowSize(row);
462 Float_t clusterPos[3];
463 clusterPos[0] = padPlane->GetColPos(col) - (clusterPads[1] + 0.5) * colSize;
464 clusterPos[1] = padPlane->GetRowPos(row) - 0.5 * rowSize;
465 clusterPos[2] = CalcXposFromTimebin(clusterPads[2],idet,col,row);
466 Float_t clusterSig[2];
467 clusterSig[0] = (clusterSigmaY2 + 1.0/12.0) * colSize*colSize;
468 clusterSig[1] = rowSize * rowSize / 12.0;
470 // Store the amplitudes of the pads in the cluster for later analysis
471 Short_t signals[7] = { 0, 0, 0, 0, 0, 0, 0 };
472 for (Int_t jPad = col-3; jPad <= col+3; jPad++) {
474 (jPad >= nColMax-1)) {
477 signals[jPad-col+3] = TMath::Nint(TMath::Abs(digitsOut->GetDataUnchecked(row,jPad,time)));
480 // Add the cluster to the output array
481 // The track indices will be stored later
482 AliTRDcluster *cluster = new AliTRDcluster(idet
487 ,((Char_t) nPadCount)
493 // Temporarily store the row, column and time bin of the center pad
494 // Used to later on assign the track indices
495 cluster->SetLabel( row,0);
496 cluster->SetLabel( col,1);
497 cluster->SetLabel(time,2);
498 RecPoints()->Add(cluster);
500 // Store the index of the first cluster in the current ROC
501 if (firstClusterROC < 0) {
502 firstClusterROC = RecPoints()->GetEntriesFast() - 1;
504 // Count the number of cluster in the current ROC
507 } // if: Maximum found ?
509 } // loop: pad columns
516 // Add the track indices to the found clusters
519 // Temporary array to collect the track indices
520 Int_t *idxTracks = new Int_t[kNtrack*nClusterROC];
522 // Loop through the dictionary arrays one-by-one
523 // to keep memory consumption low
524 for (Int_t iDict = 0; iDict < kNdict; iDict++) {
526 tracksIn = fDigitsManager->GetDictionary(idet,iDict);
529 // Loop though the clusters found in this ROC
530 for (iClusterROC = 0; iClusterROC < nClusterROC; iClusterROC++) {
532 AliTRDcluster *cluster = (AliTRDcluster *)
533 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
534 row = cluster->GetLabel(0);
535 col = cluster->GetLabel(1);
536 time = cluster->GetLabel(2);
538 for (iPad = 0; iPad < kNclus; iPad++) {
539 Int_t iPadCol = col - 1 + iPad;
540 Int_t index = tracksIn->GetDataUnchecked(row,iPadCol,time) - 1;
541 idxTracks[3*iPad+iDict + iClusterROC*kNtrack] = index;
546 // Compress the arrays
547 tracksIn->Compress(1,0);
551 // Copy the track indices into the cluster
552 // Loop though the clusters found in this ROC
553 for (iClusterROC = 0; iClusterROC < nClusterROC; iClusterROC++) {
555 AliTRDcluster *cluster = (AliTRDcluster *)
556 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
557 cluster->SetLabel(-9999,0);
558 cluster->SetLabel(-9999,1);
559 cluster->SetLabel(-9999,2);
561 cluster->AddTrackIndex(&idxTracks[iClusterROC*kNtrack]);
567 // Write the cluster and reset the array
579 //_____________________________________________________________________________
580 Double_t AliTRDclusterizerV1::GetCOG(Double_t signal[5])
584 // Used for clusters with more than 3 pads - where LUT not applicable
587 Double_t sum = signal[0]
593 Double_t res = (0.0 * (-signal[0] + signal[4])
594 + (-signal[1] + signal[3])) / sum;
600 //_____________________________________________________________________________
601 Double_t AliTRDclusterizerV1::Unfold(Double_t eps, Int_t plane, Double_t *padSignal)
604 // Method to unfold neighbouring maxima.
605 // The charge ratio on the overlapping pad is calculated
606 // until there is no more change within the range given by eps.
607 // The resulting ratio is then returned to the calling method.
610 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
612 AliError("No AliTRDcalibDB instance available\n");
617 Int_t itStep = 0; // Count iteration steps
619 Double_t ratio = 0.5; // Start value for ratio
620 Double_t prevRatio = 0.0; // Store previous ratio
622 Double_t newLeftSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store left cluster signal
623 Double_t newRightSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store right cluster signal
624 Double_t newSignal[3] = { 0.0, 0.0, 0.0 };
626 // Start the iteration
627 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
632 // Cluster position according to charge ratio
633 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
634 / (padSignal[0] + padSignal[1] + ratio*padSignal[2]);
635 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
636 / ((1.0 - ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
638 // Set cluster charge ratio
639 irc = calibration->PadResponse(1.0,maxLeft ,plane,newSignal);
640 Double_t ampLeft = padSignal[1] / newSignal[1];
641 irc = calibration->PadResponse(1.0,maxRight,plane,newSignal);
642 Double_t ampRight = padSignal[3] / newSignal[1];
644 // Apply pad response to parameters
645 irc = calibration->PadResponse(ampLeft ,maxLeft ,plane,newLeftSignal );
646 irc = calibration->PadResponse(ampRight,maxRight,plane,newRightSignal);
648 // Calculate new overlapping ratio
649 ratio = TMath::Min((Double_t)1.0,newLeftSignal[2] /
650 (newLeftSignal[2] + newRightSignal[0]));
658 //_____________________________________________________________________________
659 void AliTRDclusterizerV1::Transform(AliTRDdataArrayI *digitsIn
660 , AliTRDdataArrayF *digitsOut
661 , Int_t nRowMax, Int_t nColMax, Int_t nTimeTotal
662 , Float_t ADCthreshold
663 , AliTRDCalROC *calGainFactorROC
664 , Float_t calGainFactorDetValue)
668 // Apply tail cancelation: Transform digitsIn to digitsOut
675 AliTRDRecParam *recParam = AliTRDRecParam::Instance();
677 AliError("No AliTRDRecParam 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 for (iRow = 0; iRow < nRowMax; iRow++ ) {
685 for (iCol = 0; iCol < nColMax; iCol++ ) {
687 Float_t calGainFactorROCValue = calGainFactorROC->GetValue(iCol,iRow);
688 Double_t gain = calGainFactorDetValue
689 * calGainFactorROCValue;
691 for (iTime = 0; iTime < nTimeTotal; iTime++) {
696 inADC[iTime] = digitsIn->GetDataUnchecked(iRow,iCol,iTime);
697 inADC[iTime] /= gain;
698 outADC[iTime] = inADC[iTime];
702 // Apply the tail cancelation via the digital filter
703 if (recParam->TCOn()) {
704 DeConvExp(inADC,outADC,nTimeTotal,recParam->GetTCnexp());
707 for (iTime = 0; iTime < nTimeTotal; iTime++) {
709 // Store the amplitude of the digit if above threshold
710 if (outADC[iTime] > ADCthreshold) {
711 digitsOut->SetDataUnchecked(iRow,iCol,iTime,outADC[iTime]);
726 //_____________________________________________________________________________
727 void AliTRDclusterizerV1::DeConvExp(Double_t *source, Double_t *target
728 , Int_t n, Int_t nexp)
731 // Tail cancellation by deconvolution for PASA v4 TRF
735 Double_t coefficients[2];
737 // Initialization (coefficient = alpha, rates = lambda)
743 if (nexp == 1) { // 1 Exponentials
749 if (nexp == 2) { // 2 Exponentials
756 coefficients[0] = C1;
757 coefficients[1] = C2;
761 rates[0] = TMath::Exp(-Dt/(R1));
762 rates[1] = TMath::Exp(-Dt/(R2));
767 Double_t reminder[2];
771 // Attention: computation order is important
773 for (k = 0; k < nexp; k++) {
776 for (i = 0; i < n; i++) {
777 result = (source[i] - correction); // No rescaling
780 for (k = 0; k < nexp; k++) {
781 reminder[k] = rates[k] * (reminder[k] + coefficients[k] * result);
784 for (k = 0; k < nexp; k++) {
785 correction += reminder[k];