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 "AliTRDmatrix.h"
37 #include "AliTRDgeometry.h"
38 #include "AliTRDdataArrayF.h"
39 #include "AliTRDdataArrayI.h"
40 #include "AliTRDdigitsManager.h"
41 #include "AliTRDparameter.h"
42 #include "AliTRDpadPlane.h"
43 #include "AliTRDrawData.h"
44 #include "AliTRDcalibDB.h"
45 #include "AliTRDSimParam.h"
46 #include "AliTRDRecParam.h"
47 #include "AliTRDCommonParam.h"
48 #include "AliTRDcluster.h"
50 ClassImp(AliTRDclusterizerV1)
52 //_____________________________________________________________________________
53 AliTRDclusterizerV1::AliTRDclusterizerV1():AliTRDclusterizer()
56 // AliTRDclusterizerV1 default constructor
63 //_____________________________________________________________________________
64 AliTRDclusterizerV1::AliTRDclusterizerV1(const Text_t* name, const Text_t* title)
65 :AliTRDclusterizer(name,title)
68 // AliTRDclusterizerV1 default constructor
71 fDigitsManager = new AliTRDdigitsManager();
72 fDigitsManager->CreateArrays();
76 //_____________________________________________________________________________
77 AliTRDclusterizerV1::AliTRDclusterizerV1(const AliTRDclusterizerV1 &c)
81 // AliTRDclusterizerV1 copy constructor
84 ((AliTRDclusterizerV1 &) c).Copy(*this);
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 printf("<AliTRDclusterizerV1::ReadDigits> ");
136 printf("No input file open\n");
139 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
140 if (!loader->TreeD()) loader->LoadDigits();
142 // Read in the digit arrays
143 return (fDigitsManager->ReadDigits(loader->TreeD()));
147 //_____________________________________________________________________________
148 Bool_t AliTRDclusterizerV1::ReadDigits(AliRawReader* rawReader)
151 // Reads the digits arrays from the ddl file
154 AliTRDrawData *raw = new AliTRDrawData();
157 fDigitsManager = raw->Raw2Digits(rawReader);
163 //_____________________________________________________________________________
164 Bool_t AliTRDclusterizerV1::MakeClusters()
167 // Generates the cluster.
170 Int_t row, col, time;
173 if (fTRD->IsVersion() != 1) {
174 printf("<AliTRDclusterizerV1::MakeCluster> ");
175 printf("TRD must be version 1 (slow simulator).\n");
181 AliTRDgeometry *geo = AliTRDgeometry::GetGeometry(fRunLoader);
182 AliTRDcalibDB* calibration = AliTRDcalibDB::Instance();
185 printf("<AliTRDclusterizerV1::MakeCluster> ");
186 printf("ERROR getting instance of AliTRDcalibDB");
190 AliTRDSimParam* simParam = AliTRDSimParam::Instance();
193 printf("<AliTRDclusterizerV1::MakeCluster> ");
194 printf("ERROR getting instance of AliTRDSimParam");
198 AliTRDRecParam* recParam = AliTRDRecParam::Instance();
201 printf("<AliTRDclusterizerV1::MakeCluster> ");
202 printf("ERROR getting instance of AliTRDRecParam");
206 AliTRDCommonParam* commonParam = AliTRDCommonParam::Instance();
209 printf("<AliTRDclusterizerV1::MakeDigits> ");
210 printf("Could not get common params\n");
215 //printf("<AliTRDclusterizerV1::MakeCluster> ");
216 //printf("OmegaTau = %f \n",omegaTau);
217 printf("<AliTRDclusterizerV1::MakeCluster> ");
218 printf("Start creating clusters.\n");
221 AliTRDdataArrayI *digitsIn;
222 AliTRDdataArrayI *digitsOut; // Should actually be Float_t here (C.L.)!!
223 AliTRDdataArrayI *track0;
224 AliTRDdataArrayI *track1;
225 AliTRDdataArrayI *track2;
227 // Threshold value for the maximum
228 Int_t maxThresh = recParam->GetClusMaxThresh();
229 // Threshold value for the digit signal
230 Int_t sigThresh = recParam->GetClusSigThresh();
231 // Iteration limit for unfolding procedure
232 const Float_t kEpsilon = 0.01;
234 const Int_t kNclus = 3;
235 const Int_t kNsig = 5;
236 const Int_t kNtrack = 3 * kNclus;
240 Double_t ratioLeft = 1.0;
241 Double_t ratioRight = 1.0;
244 Double_t padSignal[kNsig];
245 Double_t clusterSignal[kNclus];
246 Double_t clusterPads[kNclus];
247 Int_t clusterDigit[kNclus];
248 Int_t clusterTracks[kNtrack];
251 Int_t chamEnd = AliTRDgeometry::Ncham();
253 Int_t planEnd = AliTRDgeometry::Nplan();
255 Int_t sectEnd = AliTRDgeometry::Nsect();
257 Int_t nTimeTotal = calibration->GetNumberOfTimeBins();
260 printf("<AliTRDclusterizerV1::MakeCluster> ");
261 printf("Number of Time Bins = %d.\n",nTimeTotal);
265 // Start clustering in every chamber
266 for (Int_t icham = chamBeg; icham < chamEnd; icham++) {
267 for (Int_t iplan = planBeg; iplan < planEnd; iplan++) {
268 for (Int_t isect = sectBeg; isect < sectEnd; isect++) {
270 Int_t idet = geo->GetDetector(iplan,icham,isect);
272 Int_t nRowMax = commonParam->GetRowMax(iplan,icham,isect);
273 Int_t nColMax = commonParam->GetColMax(iplan);
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;
283 printf("<AliTRDclusterizerV1::MakeCluster> ");
284 printf("Analyzing chamber %d, plane %d, sector %d.\n"
288 AliTRDpadPlane *padPlane = commonParam->GetPadPlane(iplan,icham);
291 digitsIn = digitsOut = fDigitsManager->GetDigits(idet);
295 Transform(digitsIn, digitsOut, idet, nRowMax, nColMax, nTimeTotal);
297 track0 = fDigitsManager->GetDictionary(idet,0);
299 track1 = fDigitsManager->GetDictionary(idet,1);
301 track2 = fDigitsManager->GetDictionary(idet,2);
304 // Loop through the chamber and find the maxima
305 for ( row = 0; row < nRowMax; row++) {
306 for ( col = 2; col < nColMax; col++) {
307 //for ( col = 4; col < nColMax-2; col++) {
308 for (time = 0; time < nTimeTotal; time++) {
310 Int_t signalL = TMath::Abs(digitsOut->GetDataUnchecked(row,col ,time));
311 Int_t signalM = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time));
312 Int_t signalR = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
314 // // Look for the maximum
315 // if (signalM >= maxThresh) {
316 // if (((signalL >= sigThresh) &&
317 // (signalL < signalM)) ||
318 // ((signalR >= sigThresh) &&
319 // (signalR < signalM))) {
320 // // Maximum found, mark the position by a negative signal
321 // digitsOut->SetDataUnchecked(row,col-1,time,-signalM);
324 // Look for the maximum
325 if (signalM >= maxThresh) {
326 if ( (TMath::Abs(signalL)<=signalM) && (TMath::Abs(signalR)<=signalM) &&
327 (TMath::Abs(signalL)+TMath::Abs(signalR))>sigThresh ) {
328 // Maximum found, mark the position by a negative signal
329 digitsOut->SetDataUnchecked(row,col-1,time,-signalM);
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) {
345 for (iPad = 0; iPad < kNclus; iPad++) {
346 Int_t iPadCol = col - 1 + iPad;
347 clusterSignal[iPad] = TMath::Abs(digitsOut->GetDataUnchecked(row
350 clusterDigit[iPad] = digitsOut->GetIndexUnchecked(row,iPadCol,time);
351 clusterTracks[3*iPad ] = track0->GetDataUnchecked(row,iPadCol,time) - 1;
352 clusterTracks[3*iPad+1] = track1->GetDataUnchecked(row,iPadCol,time) - 1;
353 clusterTracks[3*iPad+2] = track2->GetDataUnchecked(row,iPadCol,time) - 1;
356 // Count the number of pads in the cluster
359 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col-ii ,time))
363 if (col-ii < 0) break;
366 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col+ii+1,time))
370 if (col+ii+1 >= nColMax) break;
397 // Look for 5 pad cluster with minimum in the middle
398 Bool_t fivePadCluster = kFALSE;
399 if (col < nColMax-3) {
400 if (digitsOut->GetDataUnchecked(row,col+2,time) < 0) {
401 fivePadCluster = kTRUE;
403 if ((fivePadCluster) && (col < nColMax-5)) {
404 if (digitsOut->GetDataUnchecked(row,col+4,time) >= sigThresh) {
405 fivePadCluster = kFALSE;
408 if ((fivePadCluster) && (col > 1)) {
409 if (digitsOut->GetDataUnchecked(row,col-2,time) >= sigThresh) {
410 fivePadCluster = kFALSE;
416 // Modify the signal of the overlapping pad for the left part
417 // of the cluster which remains from a previous unfolding
419 clusterSignal[0] *= ratioLeft;
424 // Unfold the 5 pad cluster
425 if (fivePadCluster) {
426 for (iPad = 0; iPad < kNsig; iPad++) {
427 padSignal[iPad] = TMath::Abs(digitsOut->GetDataUnchecked(row
431 // Unfold the two maxima and set the signal on
432 // the overlapping pad to the ratio
433 ratioRight = Unfold(kEpsilon,iplan,padSignal);
434 ratioLeft = 1.0 - ratioRight;
435 clusterSignal[2] *= ratioRight;
441 Double_t clusterCharge = clusterSignal[0]
445 // The position of the cluster
446 clusterPads[0] = row + 0.5;
447 // Take the shift of the additional time bins into account
448 clusterPads[2] = time + 0.5;
451 if (recParam->LUTOn()) {
452 // Calculate the position of the cluster by using the
453 // lookup table method
454 clusterPads[1] = recParam->LUTposition(iplan,clusterSignal[0]
459 // Calculate the position of the cluster by using the
460 // center of gravity method
461 for (Int_t i=0;i<5;i++) padSignal[i]=0;
462 padSignal[2] = TMath::Abs(digitsOut->GetDataUnchecked(row,col,time)); // central pad
463 padSignal[1] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time)); // left pad
464 padSignal[3] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+1,time)); // right pad
465 if (col>2 &&TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time)<padSignal[1])){
466 padSignal[0] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
468 if (col<nColMax-3 &&TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time)<padSignal[3])){
469 padSignal[4] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time));
471 clusterPads[1] = GetCOG(padSignal);
475 Double_t q0 = clusterSignal[0];
476 Double_t q1 = clusterSignal[1];
477 Double_t q2 = clusterSignal[2];
478 Double_t clusterSigmaY2 = (q1*(q0+q2)+4*q0*q2) /
479 (clusterCharge*clusterCharge);
483 // Calculate the position and the error
486 Int_t clusterTimeBin = TMath::Nint(time - calibration->GetT0(idet, col, row));
488 Double_t colSize = padPlane->GetColSize(col);
489 Double_t rowSize = padPlane->GetRowSize(row);
490 Double_t clusterPos[3];
491 clusterPos[0] = padPlane->GetColPos(col) - (clusterPads[1]+0.5)*colSize; // MI change
492 clusterPos[1] = padPlane->GetRowPos(row) - 0.5*rowSize; //MI change
493 clusterPos[2] = CalcXposFromTimebin(clusterPads[2], idet, col, row);
494 Double_t clusterSig[2];
495 clusterSig[0] = (clusterSigmaY2 + 1./12.) * colSize*colSize;
496 clusterSig[1] = rowSize * rowSize / 12.;
499 // Add the cluster to the output array
500 AliTRDcluster * cluster = AddCluster(clusterPos
506 ,iType,clusterPads[1]);
509 Short_t signals[7]={0,0,0,0,0,0,0};
510 for (Int_t jPad = col-3;jPad<=col+3;jPad++){
511 if (jPad<0 ||jPad>=nColMax-1) continue;
512 signals[jPad-col+3] = TMath::Abs(digitsOut->GetDataUnchecked(row,jPad,time));
514 cluster->SetSignals(signals);
520 // Compress the arrays
521 digitsOut->Compress(1,0);
522 track0->Compress(1,0);
523 track1->Compress(1,0);
524 track2->Compress(1,0);
526 // Write the cluster and reset the array
534 printf("<AliTRDclusterizerV1::MakeCluster> ");
544 Double_t AliTRDclusterizerV1::GetCOG(Double_t signal[5])
548 // used for clusters with more than 3 pads - where LUT not applicable
549 Double_t sum = signal[0]+signal[1]+signal[2]+signal[3]+signal[4];
550 Double_t res = (0.0*(-signal[0]+signal[4])+(-signal[1]+signal[3]))/sum;
556 //_____________________________________________________________________________
557 Double_t AliTRDclusterizerV1::Unfold(Double_t eps, Int_t plane, Double_t* padSignal)
560 // Method to unfold neighbouring maxima.
561 // The charge ratio on the overlapping pad is calculated
562 // until there is no more change within the range given by eps.
563 // The resulting ratio is then returned to the calling method.
566 AliTRDcalibDB* calibration = AliTRDcalibDB::Instance();
569 printf("<AliTRDclusterizerMI::Unfold> ");
570 printf("ERROR getting instance of AliTRDcalibDB");
575 Int_t itStep = 0; // Count iteration steps
577 Double_t ratio = 0.5; // Start value for ratio
578 Double_t prevRatio = 0; // Store previous ratio
580 Double_t newLeftSignal[3] = {0}; // Array to store left cluster signal
581 Double_t newRightSignal[3] = {0}; // Array to store right cluster signal
582 Double_t newSignal[3] = {0};
584 // Start the iteration
585 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
590 // Cluster position according to charge ratio
591 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
592 / (padSignal[0] + padSignal[1] + ratio*padSignal[2]);
593 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
594 / ((1-ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
596 // Set cluster charge ratio
597 irc = calibration->PadResponse(1.0,maxLeft ,plane,newSignal);
598 Double_t ampLeft = padSignal[1] / newSignal[1];
599 irc = calibration->PadResponse(1.0,maxRight,plane,newSignal);
600 Double_t ampRight = padSignal[3] / newSignal[1];
602 // Apply pad response to parameters
603 irc = calibration->PadResponse(ampLeft ,maxLeft ,plane,newLeftSignal );
604 irc = calibration->PadResponse(ampRight,maxRight,plane,newRightSignal);
606 // Calculate new overlapping ratio
607 ratio = TMath::Min((Double_t)1.0,newLeftSignal[2] /
608 (newLeftSignal[2] + newRightSignal[0]));
616 //_____________________________________________________________________________
617 void AliTRDclusterizerV1::Transform(AliTRDdataArrayI* digitsIn,
618 AliTRDdataArrayI* digitsOut,
619 Int_t idet, Int_t nRowMax,
620 Int_t nColMax, Int_t nTimeTotal)
625 // Apply tail cancellation: Transform digitsIn to digitsOut
629 AliTRDSimParam* simParam = AliTRDSimParam::Instance();
632 printf("<AliTRDclusterizerV1::Transform> ");
633 printf("ERROR getting instance of AliTRDSimParam");
636 AliTRDcalibDB* calibration = AliTRDcalibDB::Instance();
638 Double_t *inADC = new Double_t[nTimeTotal]; // adc data before tail cancellation
639 Double_t *outADC = new Double_t[nTimeTotal]; // adc data after tail cancellation
642 printf("<AliTRDclusterizerV1::Transform> ");
643 printf("Tail cancellation (nExp = %d) for detector %d.\n",
644 simParam->GetTCnexp(),idet);
647 for (Int_t iRow = 0; iRow < nRowMax; iRow++ ) {
648 for (Int_t iCol = 0; iCol < nColMax; iCol++ ) {
649 for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
653 Double_t gain = calibration->GetGainFactor(idet, iCol, iRow);
655 AliError("Not a valid gain\n");
657 inADC[iTime] = digitsIn->GetDataUnchecked(iRow, iCol, iTime);
658 inADC[iTime] /= gain;
659 outADC[iTime] = inADC[iTime];
663 // Apply the tail cancelation via the digital filter
664 if (simParam->TCOn())
666 DeConvExp(inADC,outADC,nTimeTotal,simParam->GetTCnexp());
669 for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
670 // Store the amplitude of the digit if above threshold
671 if (outADC[iTime] > simParam->GetADCthreshold()) {
674 printf(" iRow = %d, iCol = %d, iTime = %d, adc = %f\n"
675 ,iRow,iCol,iTime,outADC[iTime]);
677 digitsOut->SetDataUnchecked(iRow,iCol,iTime,(Int_t)outADC[iTime]);
694 //_____________________________________________________________________________
695 void AliTRDclusterizerV1::DeConvExp(Double_t *source, Double_t *target,
699 // Tail Cancellation by Deconvolution for PASA v4 TRF
703 Double_t coefficients[2];
705 // initialize (coefficient = alpha, rates = lambda)
712 if (nexp == 1) { // 1 Exponentials
718 if (nexp == 2) { // 2 Exponentials
725 coefficients[0] = C1;
726 coefficients[1] = C2;
730 rates[0] = TMath::Exp(-Dt/(R1));
731 rates[1] = TMath::Exp(-Dt/(R2));
734 Double_t reminder[2];
735 Double_t correction, result;
737 /* attention: computation order is important */
740 for ( k=0; k<nexp; k++ ) reminder[k]=0.0;
742 for ( i=0; i<n; i++ ) {
743 result = ( source[i] - correction ); // no rescaling
746 for ( k=0; k<nexp; k++ ) reminder[k] = rates[k] *
747 ( reminder[k] + coefficients[k] * result);
749 for ( k=0; k<nexp; k++ ) correction += reminder[k];