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 for the slow simulator.
23 ///////////////////////////////////////////////////////////////////////////////
31 #include "AliRunLoader.h"
32 #include "AliLoader.h"
33 #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():AliTRDclusterizer()
54 // AliTRDclusterizerV1 default constructor
61 //_____________________________________________________________________________
62 AliTRDclusterizerV1::AliTRDclusterizerV1(const Text_t* name, const Text_t* title)
63 :AliTRDclusterizer(name,title)
66 // AliTRDclusterizerV1 default constructor
69 fDigitsManager = new AliTRDdigitsManager();
70 fDigitsManager->CreateArrays();
74 //_____________________________________________________________________________
75 AliTRDclusterizerV1::AliTRDclusterizerV1(const AliTRDclusterizerV1 &c)
79 // AliTRDclusterizerV1 copy constructor
82 ((AliTRDclusterizerV1 &) c).Copy(*this);
86 //_____________________________________________________________________________
87 AliTRDclusterizerV1::~AliTRDclusterizerV1()
90 // AliTRDclusterizerV1 destructor
94 delete fDigitsManager;
95 fDigitsManager = NULL;
100 //_____________________________________________________________________________
101 AliTRDclusterizerV1 &AliTRDclusterizerV1::operator=(const AliTRDclusterizerV1 &c)
104 // Assignment operator
107 if (this != &c) ((AliTRDclusterizerV1 &) c).Copy(*this);
112 //_____________________________________________________________________________
113 void AliTRDclusterizerV1::Copy(TObject &c) const
119 ((AliTRDclusterizerV1 &) c).fDigitsManager = 0;
121 AliTRDclusterizer::Copy(c);
125 //_____________________________________________________________________________
126 Bool_t AliTRDclusterizerV1::ReadDigits()
129 // Reads the digits arrays from the input aliroot file
133 printf("<AliTRDclusterizerV1::ReadDigits> ");
134 printf("No input file open\n");
137 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
138 if (!loader->TreeD()) loader->LoadDigits();
140 // Read in the digit arrays
141 return (fDigitsManager->ReadDigits(loader->TreeD()));
145 //_____________________________________________________________________________
146 Bool_t AliTRDclusterizerV1::ReadDigits(AliRawReader* rawReader)
149 // Reads the digits arrays from the ddl file
154 fDigitsManager = raw.Raw2Digits(rawReader);
160 //_____________________________________________________________________________
161 Bool_t AliTRDclusterizerV1::MakeClusters()
164 // Generates the cluster.
167 Int_t row, col, time;
170 if (fTRD->IsVersion() != 1) {
171 printf("<AliTRDclusterizerV1::MakeCluster> ");
172 printf("TRD must be version 1 (slow simulator).\n");
178 AliTRDgeometry *geo = AliTRDgeometry::GetGeometry(fRunLoader);
179 AliTRDcalibDB* calibration = AliTRDcalibDB::Instance();
182 printf("<AliTRDclusterizerV1::MakeCluster> ");
183 printf("ERROR getting instance of AliTRDcalibDB");
187 AliTRDSimParam* simParam = AliTRDSimParam::Instance();
190 printf("<AliTRDclusterizerV1::MakeCluster> ");
191 printf("ERROR getting instance of AliTRDSimParam");
195 AliTRDRecParam* recParam = AliTRDRecParam::Instance();
198 printf("<AliTRDclusterizerV1::MakeCluster> ");
199 printf("ERROR getting instance of AliTRDRecParam");
203 AliTRDCommonParam* commonParam = AliTRDCommonParam::Instance();
206 printf("<AliTRDclusterizerV1::MakeDigits> ");
207 printf("Could not get common params\n");
211 Float_t ADCthreshold = simParam->GetADCthreshold();
214 //printf("<AliTRDclusterizerV1::MakeCluster> ");
215 //printf("OmegaTau = %f \n",omegaTau);
216 printf("<AliTRDclusterizerV1::MakeCluster> ");
217 printf("Start creating clusters.\n");
220 AliTRDdataArrayI *digitsIn;
221 AliTRDdataArrayI *track0;
222 AliTRDdataArrayI *track1;
223 AliTRDdataArrayI *track2;
225 // Threshold value for the maximum
226 Float_t maxThresh = recParam->GetClusMaxThresh();
227 // Threshold value for the digit signal
228 Float_t sigThresh = recParam->GetClusSigThresh();
229 // Iteration limit for unfolding procedure
230 const Float_t kEpsilon = 0.01;
232 const Int_t kNclus = 3;
233 const Int_t kNsig = 5;
234 const Int_t kNtrack = 3 * kNclus;
238 Double_t ratioLeft = 1.0;
239 Double_t ratioRight = 1.0;
242 Double_t padSignal[kNsig];
243 Double_t clusterSignal[kNclus];
244 Double_t clusterPads[kNclus];
245 Int_t clusterTracks[kNtrack];
248 Int_t chamEnd = AliTRDgeometry::Ncham();
250 Int_t planEnd = AliTRDgeometry::Nplan();
252 Int_t sectEnd = AliTRDgeometry::Nsect();
254 Int_t nTimeTotal = calibration->GetNumberOfTimeBins();
257 printf("<AliTRDclusterizerV1::MakeCluster> ");
258 printf("Number of Time Bins = %d.\n",nTimeTotal);
261 // Start clustering in every chamber
262 for (Int_t icham = chamBeg; icham < chamEnd; icham++) {
263 for (Int_t iplan = planBeg; iplan < planEnd; iplan++) {
264 for (Int_t isect = sectBeg; isect < sectEnd; isect++) {
266 Int_t idet = geo->GetDetector(iplan,icham,isect);
268 Int_t nRowMax = commonParam->GetRowMax(iplan,icham,isect);
269 Int_t nColMax = commonParam->GetColMax(iplan);
272 Int_t nClusters2pad = 0;
273 Int_t nClusters3pad = 0;
274 Int_t nClusters4pad = 0;
275 Int_t nClusters5pad = 0;
276 Int_t nClustersLarge = 0;
279 printf("<AliTRDclusterizerV1::MakeCluster> ");
280 printf("Analyzing chamber %d, plane %d, sector %d.\n"
284 AliTRDpadPlane *padPlane = commonParam->GetPadPlane(iplan,icham);
287 digitsIn = fDigitsManager->GetDigits(idet);
289 AliTRDdataArrayF *digitsOut = new AliTRDdataArrayF(digitsIn->GetNrow(), digitsIn->GetNcol(), digitsIn->GetNtime());
291 Transform(digitsIn, digitsOut, idet, nRowMax, nColMax, nTimeTotal, ADCthreshold);
293 track0 = fDigitsManager->GetDictionary(idet,0);
295 track1 = fDigitsManager->GetDictionary(idet,1);
297 track2 = fDigitsManager->GetDictionary(idet,2);
300 // Loop through the chamber and find the maxima
301 for ( row = 0; row < nRowMax; row++) {
302 for ( col = 2; col < nColMax; col++) {
303 //for ( col = 4; col < nColMax-2; col++) {
304 for (time = 0; time < nTimeTotal; time++) {
306 Float_t signalL = TMath::Abs(digitsOut->GetDataUnchecked(row,col ,time));
307 Float_t signalM = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time));
308 Float_t signalR = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
310 // // Lonok for the maximum
311 // if (signalM >= maxThresh) {
312 // if (((signalL >= sigThresh) &&
313 // (signalL < signalM)) ||
314 // ((signalR >= sigThresh) &&
315 // (signalR < signalM))) {
316 // // Maximum found, mark the position by a negative signal
317 // digitsOut->SetDataUnchecked(row,col-1,time,-signalM);
320 // Look for the maximum
321 if (signalM >= maxThresh) {
322 if ( (TMath::Abs(signalL)<=signalM) && (TMath::Abs(signalR)<=signalM) &&
323 (TMath::Abs(signalL)+TMath::Abs(signalR))>sigThresh ) {
324 // Maximum found, mark the position by a negative signal
325 digitsOut->SetDataUnchecked(row,col-1,time,-signalM);
332 // Now check the maxima and calculate the cluster position
333 for ( row = 0; row < nRowMax ; row++) {
334 for (time = 0; time < nTimeTotal; time++) {
335 for ( col = 1; col < nColMax-1; col++) {
338 if (digitsOut->GetDataUnchecked(row,col,time) < 0) {
341 for (iPad = 0; iPad < kNclus; iPad++) {
342 Int_t iPadCol = col - 1 + iPad;
343 clusterSignal[iPad] = TMath::Abs(digitsOut->GetDataUnchecked(row
346 clusterTracks[3*iPad ] = track0->GetDataUnchecked(row,iPadCol,time) - 1;
347 clusterTracks[3*iPad+1] = track1->GetDataUnchecked(row,iPadCol,time) - 1;
348 clusterTracks[3*iPad+2] = track2->GetDataUnchecked(row,iPadCol,time) - 1;
351 // Count the number of pads in the cluster
354 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col-ii ,time))
358 if (col-ii < 0) break;
361 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col+ii+1,time))
365 if (col+ii+1 >= nColMax) break;
392 // Look for 5 pad cluster with minimum in the middle
393 Bool_t fivePadCluster = kFALSE;
394 if (col < nColMax-3) {
395 if (digitsOut->GetDataUnchecked(row,col+2,time) < 0) {
396 fivePadCluster = kTRUE;
398 if ((fivePadCluster) && (col < nColMax-5)) {
399 if (digitsOut->GetDataUnchecked(row,col+4,time) >= sigThresh) {
400 fivePadCluster = kFALSE;
403 if ((fivePadCluster) && (col > 1)) {
404 if (digitsOut->GetDataUnchecked(row,col-2,time) >= sigThresh) {
405 fivePadCluster = kFALSE;
411 // Modify the signal of the overlapping pad for the left part
412 // of the cluster which remains from a previous unfolding
414 clusterSignal[0] *= ratioLeft;
419 // Unfold the 5 pad cluster
420 if (fivePadCluster) {
421 for (iPad = 0; iPad < kNsig; iPad++) {
422 padSignal[iPad] = TMath::Abs(digitsOut->GetDataUnchecked(row
426 // Unfold the two maxima and set the signal on
427 // the overlapping pad to the ratio
428 ratioRight = Unfold(kEpsilon,iplan,padSignal);
429 ratioLeft = 1.0 - ratioRight;
430 clusterSignal[2] *= ratioRight;
435 Double_t clusterCharge = clusterSignal[0]
439 // The position of the cluster
440 clusterPads[0] = row + 0.5;
441 // Take the shift of the additional time bins into account
442 clusterPads[2] = time + 0.5;
445 if (recParam->LUTOn()) {
446 // Calculate the position of the cluster by using the
447 // lookup table method
448 clusterPads[1] = recParam->LUTposition(iplan,clusterSignal[0]
453 // Calculate the position of the cluster by using the
454 // center of gravity method
455 for (Int_t i=0;i<5;i++) padSignal[i]=0;
456 padSignal[2] = TMath::Abs(digitsOut->GetDataUnchecked(row,col,time)); // central pad
457 padSignal[1] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time)); // left pad
458 padSignal[3] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+1,time)); // right pad
459 if (col>2 &&TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time)<padSignal[1])){
460 padSignal[0] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
462 if (col<nColMax-3 &&TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time)<padSignal[3])){
463 padSignal[4] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time));
465 clusterPads[1] = GetCOG(padSignal);
469 Double_t q0 = clusterSignal[0];
470 Double_t q1 = clusterSignal[1];
471 Double_t q2 = clusterSignal[2];
472 Double_t clusterSigmaY2 = (q1*(q0+q2)+4*q0*q2) /
473 (clusterCharge*clusterCharge);
477 // Calculate the position and the error
480 Int_t clusterTimeBin = TMath::Nint(time - calibration->GetT0(idet, col, row));
482 Double_t colSize = padPlane->GetColSize(col);
483 Double_t rowSize = padPlane->GetRowSize(row);
484 Double_t clusterPos[3];
485 clusterPos[0] = padPlane->GetColPos(col) - (clusterPads[1]+0.5)*colSize; // MI change
486 clusterPos[1] = padPlane->GetRowPos(row) - 0.5*rowSize; //MI change
487 clusterPos[2] = CalcXposFromTimebin(clusterPads[2], idet, col, row);
488 Double_t clusterSig[2];
489 clusterSig[0] = (clusterSigmaY2 + 1./12.) * colSize*colSize;
490 clusterSig[1] = rowSize * rowSize / 12.;
493 // Add the cluster to the output array
494 AliTRDcluster * cluster = AddCluster(clusterPos
500 ,iType,clusterPads[1]);
503 Short_t signals[7]={0,0,0,0,0,0,0};
504 for (Int_t jPad = col-3;jPad<=col+3;jPad++){
505 if (jPad<0 ||jPad>=nColMax-1) continue;
506 signals[jPad-col+3] = TMath::Nint(TMath::Abs(digitsOut->GetDataUnchecked(row,jPad,time)));
508 cluster->SetSignals(signals);
516 // Compress the arrays
517 track0->Compress(1,0);
518 track1->Compress(1,0);
519 track2->Compress(1,0);
521 // Write the cluster and reset the array
529 printf("<AliTRDclusterizerV1::MakeCluster> ");
539 //_____________________________________________________________________________
540 Double_t AliTRDclusterizerV1::GetCOG(Double_t signal[5])
544 // used for clusters with more than 3 pads - where LUT not applicable
545 Double_t sum = signal[0]+signal[1]+signal[2]+signal[3]+signal[4];
546 Double_t res = (0.0*(-signal[0]+signal[4])+(-signal[1]+signal[3]))/sum;
550 //_____________________________________________________________________________
551 Double_t AliTRDclusterizerV1::Unfold(Double_t eps, Int_t plane, Double_t* padSignal)
554 // Method to unfold neighbouring maxima.
555 // The charge ratio on the overlapping pad is calculated
556 // until there is no more change within the range given by eps.
557 // The resulting ratio is then returned to the calling method.
560 AliTRDcalibDB* calibration = AliTRDcalibDB::Instance();
563 printf("<AliTRDclusterizerMI::Unfold> ");
564 printf("ERROR getting instance of AliTRDcalibDB");
569 Int_t itStep = 0; // Count iteration steps
571 Double_t ratio = 0.5; // Start value for ratio
572 Double_t prevRatio = 0; // Store previous ratio
574 Double_t newLeftSignal[3] = {0}; // Array to store left cluster signal
575 Double_t newRightSignal[3] = {0}; // Array to store right cluster signal
576 Double_t newSignal[3] = {0};
578 // Start the iteration
579 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
584 // Cluster position according to charge ratio
585 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
586 / (padSignal[0] + padSignal[1] + ratio*padSignal[2]);
587 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
588 / ((1-ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
590 // Set cluster charge ratio
591 irc = calibration->PadResponse(1.0,maxLeft ,plane,newSignal);
592 Double_t ampLeft = padSignal[1] / newSignal[1];
593 irc = calibration->PadResponse(1.0,maxRight,plane,newSignal);
594 Double_t ampRight = padSignal[3] / newSignal[1];
596 // Apply pad response to parameters
597 irc = calibration->PadResponse(ampLeft ,maxLeft ,plane,newLeftSignal );
598 irc = calibration->PadResponse(ampRight,maxRight,plane,newRightSignal);
600 // Calculate new overlapping ratio
601 ratio = TMath::Min((Double_t)1.0,newLeftSignal[2] /
602 (newLeftSignal[2] + newRightSignal[0]));
610 //_____________________________________________________________________________
611 void AliTRDclusterizerV1::Transform(AliTRDdataArrayI* digitsIn,
612 AliTRDdataArrayF* digitsOut,
613 Int_t idet, Int_t nRowMax,
614 Int_t nColMax, Int_t nTimeTotal,
615 Float_t ADCthreshold)
620 // Apply tail cancellation: Transform digitsIn to digitsOut
624 AliTRDRecParam* recParam = AliTRDRecParam::Instance();
627 printf("<AliTRDclusterizerV1::Transform> ");
628 printf("ERROR getting instance of AliTRDRecParam");
631 AliTRDcalibDB* calibration = AliTRDcalibDB::Instance();
633 Double_t *inADC = new Double_t[nTimeTotal]; // adc data before tail cancellation
634 Double_t *outADC = new Double_t[nTimeTotal]; // adc data after tail cancellation
637 printf("<AliTRDclusterizerV1::Transform> ");
638 printf("Tail cancellation (nExp = %d) for detector %d.\n",
639 recParam->GetTCnexp(),idet);
642 for (Int_t iRow = 0; iRow < nRowMax; iRow++ ) {
643 for (Int_t iCol = 0; iCol < nColMax; iCol++ ) {
644 for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
648 Double_t gain = calibration->GetGainFactor(idet, iCol, iRow);
650 AliError("Not a valid gain\n");
652 inADC[iTime] = digitsIn->GetDataUnchecked(iRow, iCol, iTime);
654 inADC[iTime] /= gain;
655 outADC[iTime] = inADC[iTime];
658 // Apply the tail cancelation via the digital filter
659 if (recParam->TCOn())
661 DeConvExp(inADC,outADC,nTimeTotal,recParam->GetTCnexp());
664 for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
665 // Store the amplitude of the digit if above threshold
666 if (outADC[iTime] > ADCthreshold) {
669 printf(" iRow = %d, iCol = %d, iTime = %d, adc = %f\n"
670 ,iRow,iCol,iTime,outADC[iTime]);
672 digitsOut->SetDataUnchecked(iRow,iCol,iTime,outADC[iTime]);
689 //_____________________________________________________________________________
690 void AliTRDclusterizerV1::DeConvExp(Double_t *source, Double_t *target,
694 // Tail Cancellation by Deconvolution for PASA v4 TRF
698 Double_t coefficients[2];
700 // initialize (coefficient = alpha, rates = lambda)
707 if (nexp == 1) { // 1 Exponentials
713 if (nexp == 2) { // 2 Exponentials
720 coefficients[0] = C1;
721 coefficients[1] = C2;
725 rates[0] = TMath::Exp(-Dt/(R1));
726 rates[1] = TMath::Exp(-Dt/(R2));
729 Double_t reminder[2];
730 Double_t correction, result;
732 /* attention: computation order is important */
735 for ( k=0; k<nexp; k++ ) reminder[k]=0.0;
737 for ( i=0; i<n; i++ ) {
738 result = ( source[i] - correction ); // no rescaling
741 for ( k=0; k<nexp; k++ ) reminder[k] = rates[k] *
742 ( reminder[k] + coefficients[k] * result);
744 for ( k=0; k<nexp; k++ ) correction += reminder[k];