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;
194 //AliTRDgeometry *geo = AliTRDgeometry::GetGeometry(fRunLoader);
196 // AliWarning("Creating default TRD geometry!");
197 // geo = new AliTRDgeometry();
201 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
203 AliFatal("No AliTRDcalibDB instance available\n");
207 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
209 AliError("No AliTRDSimParam instance available\n");
213 AliTRDRecParam *recParam = AliTRDRecParam::Instance();
215 AliError("No AliTRDRecParam instance available\n");
220 Float_t ADCthreshold = simParam->GetADCthreshold();
221 // Threshold value for the maximum
222 Float_t maxThresh = recParam->GetClusMaxThresh();
223 // Threshold value for the digit signal
224 Float_t sigThresh = recParam->GetClusSigThresh();
226 // Detector wise calibration object for t0
227 const AliTRDCalDet *calT0Det = calibration->GetT0Det();
228 // Detector wise calibration object for the gain factors
229 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
231 // Iteration limit for unfolding procedure
232 const Float_t kEpsilon = 0.01;
233 const Int_t kNclus = 3;
234 const Int_t kNsig = 5;
235 const Int_t kNdict = AliTRDdigitsManager::kNDict;
236 const Int_t kNtrack = kNdict * kNclus;
240 Double_t ratioLeft = 1.0;
241 Double_t ratioRight = 1.0;
243 Int_t iClusterROC = 0;
245 Double_t padSignal[kNsig];
246 Double_t clusterSignal[kNclus];
247 Double_t clusterPads[kNclus];
250 Int_t chamEnd = AliTRDgeometry::Ncham();
252 Int_t planEnd = AliTRDgeometry::Nplan();
254 Int_t sectEnd = AliTRDgeometry::Nsect();
255 Int_t nTimeTotal = calibration->GetNumberOfTimeBins();
257 Int_t dummy[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
259 AliDebug(1,Form("Number of Time Bins = %d.\n",nTimeTotal));
261 // Start clustering in every chamber
262 for (icham = chamBeg; icham < chamEnd; icham++) {
263 for (iplan = planBeg; iplan < planEnd; iplan++) {
264 for (isect = sectBeg; isect < sectEnd; isect++) {
266 Int_t idet = geo.GetDetector(iplan,icham,isect);
267 Int_t ilayer = AliGeomManager::kTRD1 + iplan;
268 Int_t imodule = icham + chamEnd * isect;
269 UShort_t volid = AliGeomManager::LayerToVolUID(ilayer,imodule);
272 digitsIn = fDigitsManager->GetDigits(idet);
273 // This is to take care of switched off super modules
274 if (digitsIn->GetNtime() == 0) {
278 AliTRDdataArrayI *tracksTmp = fDigitsManager->GetDictionary(idet,0);
281 Int_t nRowMax = geo.GetRowMax(iplan,icham,isect);
282 Int_t nColMax = geo.GetColMax(iplan);
284 AliTRDpadPlane *padPlane = geo.GetPadPlane(iplan,icham);
286 // Calibration object with pad wise values for t0
287 AliTRDCalROC *calT0ROC = calibration->GetT0ROC(idet);
288 // Calibration object with pad wise values for the gain factors
289 AliTRDCalROC *calGainFactorROC = calibration->GetGainFactorROC(idet);
290 // Calibration value for chamber wise t0
291 Float_t calT0DetValue = calT0Det->GetValue(idet);
292 // Calibration value for chamber wise gain factor
293 Float_t calGainFactorDetValue = calGainFactorDet->GetValue(idet);
296 Int_t nClusters2pad = 0;
297 Int_t nClusters3pad = 0;
298 Int_t nClusters4pad = 0;
299 Int_t nClusters5pad = 0;
300 Int_t nClustersLarge = 0;
302 // Apply the gain and the tail cancelation via digital filter
303 AliTRDdataArrayF *digitsOut = new AliTRDdataArrayF(digitsIn->GetNrow()
305 ,digitsIn->GetNtime());
308 ,nRowMax,nColMax,nTimeTotal
311 ,calGainFactorDetValue);
313 // Input digits are not needed any more
314 digitsIn->Compress(1,0);
316 // Loop through the chamber and find the maxima
317 for ( row = 0; row < nRowMax; row++) {
318 for ( col = 2; col < nColMax; col++) {
319 for (time = 0; time < nTimeTotal; time++) {
321 Float_t signalM = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time));
323 // Look for the maximum
324 if (signalM >= maxThresh) {
326 Float_t signalL = TMath::Abs(digitsOut->GetDataUnchecked(row,col ,time));
327 Float_t signalR = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
329 if ((TMath::Abs(signalL) <= signalM) &&
330 (TMath::Abs(signalR) < signalM)) {
331 if ((TMath::Abs(signalL) >= sigThresh) ||
332 (TMath::Abs(signalR) >= sigThresh)) {
333 // Maximum found, mark the position by a negative signal
334 digitsOut->SetDataUnchecked(row,col-1,time,-signalM);
343 tracksTmp->Compress(1,0);
345 // The index to the first cluster of a given ROC
346 Int_t firstClusterROC = -1;
347 // The number of cluster in a given ROC
348 Int_t nClusterROC = 0;
350 // Now check the maxima and calculate the cluster position
351 for ( row = 0; row < nRowMax ; row++) {
352 for (time = 0; time < nTimeTotal; time++) {
353 for ( col = 1; col < nColMax-1; col++) {
356 if (digitsOut->GetDataUnchecked(row,col,time) < 0.0) {
358 for (iPad = 0; iPad < kNclus; iPad++) {
359 Int_t iPadCol = col - 1 + iPad;
360 clusterSignal[iPad] =
361 TMath::Abs(digitsOut->GetDataUnchecked(row,iPadCol,time));
364 // Count the number of pads in the cluster
369 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col-ii ,time)) >= sigThresh) {
372 if (col-ii < 0) break;
376 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col+ii+1,time)) >= sigThresh) {
379 if (col+ii+1 >= nColMax) break;
405 // Look for 5 pad cluster with minimum in the middle
406 Bool_t fivePadCluster = kFALSE;
407 if (col < (nColMax - 3)) {
408 if (digitsOut->GetDataUnchecked(row,col+2,time) < 0) {
409 fivePadCluster = kTRUE;
411 if ((fivePadCluster) && (col < (nColMax - 5))) {
412 if (digitsOut->GetDataUnchecked(row,col+4,time) >= sigThresh) {
413 fivePadCluster = kFALSE;
416 if ((fivePadCluster) && (col > 1)) {
417 if (digitsOut->GetDataUnchecked(row,col-2,time) >= sigThresh) {
418 fivePadCluster = kFALSE;
424 // Modify the signal of the overlapping pad for the left part
425 // of the cluster which remains from a previous unfolding
427 clusterSignal[0] *= ratioLeft;
432 // Unfold the 5 pad cluster
433 if (fivePadCluster) {
434 for (iPad = 0; iPad < kNsig; iPad++) {
435 padSignal[iPad] = TMath::Abs(digitsOut->GetDataUnchecked(row
439 // Unfold the two maxima and set the signal on
440 // the overlapping pad to the ratio
441 ratioRight = Unfold(kEpsilon,iplan,padSignal);
442 ratioLeft = 1.0 - ratioRight;
443 clusterSignal[2] *= ratioRight;
448 Double_t clusterCharge = clusterSignal[0]
452 // The position of the cluster
453 clusterPads[0] = row + 0.5;
454 // Take the shift of the additional time bins into account
455 clusterPads[2] = time + 0.5;
457 if (recParam->LUTOn()) {
458 // Calculate the position of the cluster by using the
459 // lookup table method
460 clusterPads[1] = recParam->LUTposition(iplan,clusterSignal[0]
465 // Calculate the position of the cluster by using the
466 // center of gravity method
467 for (Int_t i = 0; i < kNsig; i++) {
470 padSignal[2] = TMath::Abs(digitsOut->GetDataUnchecked(row,col ,time)); // Central pad
471 padSignal[1] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time)); // Left pad
472 padSignal[3] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+1,time)); // Right pad
474 (TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time)) < padSignal[1])) {
475 padSignal[0] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
477 if ((col < nColMax - 3) &&
478 (TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time)) < padSignal[3])) {
479 padSignal[4] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time));
481 clusterPads[1] = GetCOG(padSignal);
484 Double_t q0 = clusterSignal[0];
485 Double_t q1 = clusterSignal[1];
486 Double_t q2 = clusterSignal[2];
487 Double_t clusterSigmaY2 = (q1 * (q0 + q2) + 4.0 * q0 * q2)
488 / (clusterCharge*clusterCharge);
491 // Calculate the position and the error
494 // Correct for t0 (sum of chamber and pad wise values !!!)
495 Float_t calT0ROCValue = calT0ROC->GetValue(col,row);
496 Int_t clusterTimeBin = TMath::Nint(time - (calT0DetValue + calT0ROCValue));
497 Double_t colSize = padPlane->GetColSize(col);
498 Double_t rowSize = padPlane->GetRowSize(row);
500 Double_t clusterPos[3];
501 clusterPos[0] = padPlane->GetColPos(col) - (clusterPads[1] + 0.5) * colSize;
502 clusterPos[1] = padPlane->GetRowPos(row) - 0.5 * rowSize;
503 clusterPos[2] = CalcXposFromTimebin(clusterPads[2],idet,col,row);
504 Double_t clusterSig[2];
505 clusterSig[0] = (clusterSigmaY2 + 1.0/12.0) * colSize*colSize;
506 clusterSig[1] = rowSize * rowSize / 12.0;
508 // Add the cluster to the output array
509 // The track indices will be stored later
510 AliTRDcluster *cluster = AddCluster(clusterPos
521 // Store the amplitudes of the pads in the cluster for later analysis
522 Short_t signals[7] = { 0, 0, 0, 0, 0, 0, 0 };
523 for (Int_t jPad = col-3; jPad <= col+3; jPad++) {
525 (jPad >= nColMax-1)) {
528 signals[jPad-col+3] = TMath::Nint(TMath::Abs(digitsOut->GetDataUnchecked(row,jPad,time)));
530 cluster->SetSignals(signals);
532 // Temporarily store the row, column and time bin of the center pad
533 // Used to later on assign the track indices
534 cluster->SetLabel( row,0);
535 cluster->SetLabel( col,1);
536 cluster->SetLabel(time,2);
538 // Store the index of the first cluster in the current ROC
539 if (firstClusterROC < 0) {
540 firstClusterROC = RecPoints()->GetEntriesFast() - 1;
542 // Count the number of cluster in the current ROC
545 } // if: Maximum found ?
547 } // loop: pad columns
554 // Add the track indices to the found clusters
557 // Temporary array to collect the track indices
558 Int_t *idxTracks = new Int_t[kNtrack*nClusterROC];
560 // Loop through the dictionary arrays one-by-one
561 // to keep memory consumption low
562 for (Int_t iDict = 0; iDict < kNdict; iDict++) {
564 tracksIn = fDigitsManager->GetDictionary(idet,iDict);
567 // Loop though the clusters found in this ROC
568 for (iClusterROC = 0; iClusterROC < nClusterROC; iClusterROC++) {
570 AliTRDcluster *cluster = (AliTRDcluster *)
571 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
572 row = cluster->GetLabel(0);
573 col = cluster->GetLabel(1);
574 time = cluster->GetLabel(2);
576 for (iPad = 0; iPad < kNclus; iPad++) {
577 Int_t iPadCol = col - 1 + iPad;
578 Int_t index = tracksIn->GetDataUnchecked(row,iPadCol,time) - 1;
579 idxTracks[3*iPad+iDict + iClusterROC*kNtrack] = index;
584 // Compress the arrays
585 tracksIn->Compress(1,0);
589 // Copy the track indices into the cluster
590 // Loop though the clusters found in this ROC
591 for (iClusterROC = 0; iClusterROC < nClusterROC; iClusterROC++) {
593 AliTRDcluster *cluster = (AliTRDcluster *)
594 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
595 cluster->SetLabel(-9999,0);
596 cluster->SetLabel(-9999,1);
597 cluster->SetLabel(-9999,2);
599 cluster->AddTrackIndex(&idxTracks[iClusterROC*kNtrack]);
605 // Write the cluster and reset the array
617 //_____________________________________________________________________________
618 Double_t AliTRDclusterizerV1::GetCOG(Double_t signal[5])
622 // Used for clusters with more than 3 pads - where LUT not applicable
625 Double_t sum = signal[0]
631 Double_t res = (0.0 * (-signal[0] + signal[4])
632 + (-signal[1] + signal[3])) / sum;
638 //_____________________________________________________________________________
639 Double_t AliTRDclusterizerV1::Unfold(Double_t eps, Int_t plane, Double_t *padSignal)
642 // Method to unfold neighbouring maxima.
643 // The charge ratio on the overlapping pad is calculated
644 // until there is no more change within the range given by eps.
645 // The resulting ratio is then returned to the calling method.
648 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
650 AliError("No AliTRDcalibDB instance available\n");
655 Int_t itStep = 0; // Count iteration steps
657 Double_t ratio = 0.5; // Start value for ratio
658 Double_t prevRatio = 0.0; // Store previous ratio
660 Double_t newLeftSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store left cluster signal
661 Double_t newRightSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store right cluster signal
662 Double_t newSignal[3] = { 0.0, 0.0, 0.0 };
664 // Start the iteration
665 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
670 // Cluster position according to charge ratio
671 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
672 / (padSignal[0] + padSignal[1] + ratio*padSignal[2]);
673 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
674 / ((1.0 - ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
676 // Set cluster charge ratio
677 irc = calibration->PadResponse(1.0,maxLeft ,plane,newSignal);
678 Double_t ampLeft = padSignal[1] / newSignal[1];
679 irc = calibration->PadResponse(1.0,maxRight,plane,newSignal);
680 Double_t ampRight = padSignal[3] / newSignal[1];
682 // Apply pad response to parameters
683 irc = calibration->PadResponse(ampLeft ,maxLeft ,plane,newLeftSignal );
684 irc = calibration->PadResponse(ampRight,maxRight,plane,newRightSignal);
686 // Calculate new overlapping ratio
687 ratio = TMath::Min((Double_t)1.0,newLeftSignal[2] /
688 (newLeftSignal[2] + newRightSignal[0]));
696 //_____________________________________________________________________________
697 void AliTRDclusterizerV1::Transform(AliTRDdataArrayI *digitsIn
698 , AliTRDdataArrayF *digitsOut
699 , Int_t nRowMax, Int_t nColMax, Int_t nTimeTotal
700 , Float_t ADCthreshold
701 , AliTRDCalROC *calGainFactorROC
702 , Float_t calGainFactorDetValue)
706 // Apply tail cancelation: Transform digitsIn to digitsOut
713 AliTRDRecParam *recParam = AliTRDRecParam::Instance();
715 AliError("No AliTRDRecParam instance available\n");
719 Double_t *inADC = new Double_t[nTimeTotal]; // ADC data before tail cancellation
720 Double_t *outADC = new Double_t[nTimeTotal]; // ADC data after tail cancellation
722 for (iRow = 0; iRow < nRowMax; iRow++ ) {
723 for (iCol = 0; iCol < nColMax; iCol++ ) {
725 Float_t calGainFactorROCValue = calGainFactorROC->GetValue(iCol,iRow);
726 Double_t gain = calGainFactorDetValue
727 * calGainFactorROCValue;
729 for (iTime = 0; iTime < nTimeTotal; iTime++) {
734 inADC[iTime] = digitsIn->GetDataUnchecked(iRow,iCol,iTime);
735 inADC[iTime] /= gain;
736 outADC[iTime] = inADC[iTime];
740 // Apply the tail cancelation via the digital filter
741 if (recParam->TCOn()) {
742 DeConvExp(inADC,outADC,nTimeTotal,recParam->GetTCnexp());
745 for (iTime = 0; iTime < nTimeTotal; iTime++) {
747 // Store the amplitude of the digit if above threshold
748 if (outADC[iTime] > ADCthreshold) {
749 digitsOut->SetDataUnchecked(iRow,iCol,iTime,outADC[iTime]);
764 //_____________________________________________________________________________
765 void AliTRDclusterizerV1::DeConvExp(Double_t *source, Double_t *target
766 , Int_t n, Int_t nexp)
769 // Tail cancellation by deconvolution for PASA v4 TRF
773 Double_t coefficients[2];
775 // Initialization (coefficient = alpha, rates = lambda)
781 if (nexp == 1) { // 1 Exponentials
787 if (nexp == 2) { // 2 Exponentials
794 coefficients[0] = C1;
795 coefficients[1] = C2;
799 rates[0] = TMath::Exp(-Dt/(R1));
800 rates[1] = TMath::Exp(-Dt/(R2));
805 Double_t reminder[2];
809 // Attention: computation order is important
811 for (k = 0; k < nexp; k++) {
814 for (i = 0; i < n; i++) {
815 result = (source[i] - correction); // No rescaling
818 for (k = 0; k < nexp; k++) {
819 reminder[k] = rates[k] * (reminder[k] + coefficients[k] * result);
822 for (k = 0; k < nexp; k++) {
823 correction += reminder[k];