1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // TRD cluster finder for the slow simulator.
22 ///////////////////////////////////////////////////////////////////////////////
30 #include "AliRunLoader.h"
31 #include "AliLoader.h"
32 #include "AliRawReader.h"
34 #include "AliTRDclusterizerV1.h"
35 #include "AliTRDmatrix.h"
36 #include "AliTRDgeometry.h"
37 #include "AliTRDdataArrayF.h"
38 #include "AliTRDdataArrayI.h"
39 #include "AliTRDdigitsManager.h"
40 #include "AliTRDparameter.h"
41 #include "AliTRDpadPlane.h"
42 #include "AliTRDrawData.h"
43 #include "AliTRDcalibDB.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
152 AliTRDrawData *raw = new AliTRDrawData();
155 fDigitsManager = raw->Raw2Digits(rawReader);
161 //_____________________________________________________________________________
162 Bool_t AliTRDclusterizerV1::MakeClusters()
165 // Generates the cluster.
168 Int_t row, col, time;
171 if (fTRD->IsVersion() != 1) {
172 printf("<AliTRDclusterizerV1::MakeCluster> ");
173 printf("TRD must be version 1 (slow simulator).\n");
179 AliTRDgeometry *geo = AliTRDgeometry::GetGeometry(fRunLoader);
181 // Create a default parameter class if none is defined
183 fPar = new AliTRDparameter("TRDparameter","Standard TRD parameter");
184 printf("<AliTRDclusterizerV1::MakeCluster> ");
185 printf("Create the default parameter object.\n");
189 AliTRDcalibDB* calibration = AliTRDcalibDB::Instance();
192 printf("<AliTRDclusterizerMI::MakeCluster> ");
193 printf("ERROR getting instance of AliTRDcalibDB");
197 AliTRDRecParam* recParam = AliTRDRecParam::Instance();
200 printf("<AliTRDclusterizerMI::MakeCluster> ");
201 printf("ERROR getting instance of AliTRDRecParam");
205 AliTRDCommonParam* commonParam = AliTRDCommonParam::Instance();
208 printf("<AliTRDdigitizer::MakeDigits> ");
209 printf("Could not get common params\n");
213 //Float_t timeBinSize = fPar->GetDriftVelocity()
214 // / fPar->GetSamplingFrequency();
215 // Half of ampl.region
216 // const Float_t kAmWidth = AliTRDgeometry::AmThick()/2.;
218 //Float_t omegaTau = fPar->GetOmegaTau();
220 //printf("<AliTRDclusterizerV1::MakeCluster> ");
221 //printf("OmegaTau = %f \n",omegaTau);
222 printf("<AliTRDclusterizerV1::MakeCluster> ");
223 printf("Start creating clusters.\n");
226 AliTRDdataArrayI *digits;
227 AliTRDdataArrayI *track0;
228 AliTRDdataArrayI *track1;
229 AliTRDdataArrayI *track2;
231 // Threshold value for the maximum
232 Int_t maxThresh = recParam->GetClusMaxThresh();
233 // Threshold value for the digit signal
234 Int_t sigThresh = recParam->GetClusSigThresh();
235 // Iteration limit for unfolding procedure
236 const Float_t kEpsilon = 0.01;
238 const Int_t kNclus = 3;
239 const Int_t kNsig = 5;
240 const Int_t kNtrack = 3 * kNclus;
244 Double_t ratioLeft = 1.0;
245 Double_t ratioRight = 1.0;
248 Double_t padSignal[kNsig];
249 Double_t clusterSignal[kNclus];
250 Double_t clusterPads[kNclus];
251 Int_t clusterDigit[kNclus];
252 Int_t clusterTracks[kNtrack];
255 Int_t chamEnd = AliTRDgeometry::Ncham();
257 Int_t planEnd = AliTRDgeometry::Nplan();
259 Int_t sectEnd = AliTRDgeometry::Nsect();
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);
269 Int_t nClusters2pad = 0;
270 Int_t nClusters3pad = 0;
271 Int_t nClusters4pad = 0;
272 Int_t nClusters5pad = 0;
273 Int_t nClustersLarge = 0;
276 printf("<AliTRDclusterizerV1::MakeCluster> ");
277 printf("Analyzing chamber %d, plane %d, sector %d.\n"
281 Int_t nRowMax = commonParam->GetRowMax(iplan,icham,isect);
282 Int_t nColMax = commonParam->GetColMax(iplan);
283 Int_t nTimeTotal = calibration->GetNumberOfTimeBins();
284 Int_t nTimeBefore = fPar->GetTimeBefore();
286 AliTRDpadPlane *padPlane = commonParam->GetPadPlane(iplan,icham);
289 digits = fDigitsManager->GetDigits(idet);
291 track0 = fDigitsManager->GetDictionary(idet,0);
293 track1 = fDigitsManager->GetDictionary(idet,1);
295 track2 = fDigitsManager->GetDictionary(idet,2);
298 // Loop through the chamber and find the maxima
299 for ( row = 0; row < nRowMax; row++) {
300 for ( col = 2; col < nColMax; col++) {
301 //for ( col = 4; col < nColMax-2; col++) {
302 for (time = 0; time < nTimeTotal; time++) {
304 Int_t signalL = TMath::Abs(digits->GetDataUnchecked(row,col ,time));
305 Int_t signalM = TMath::Abs(digits->GetDataUnchecked(row,col-1,time));
306 Int_t signalR = TMath::Abs(digits->GetDataUnchecked(row,col-2,time));
308 // // Look for the maximum
309 // if (signalM >= maxThresh) {
310 // if (((signalL >= sigThresh) &&
311 // (signalL < signalM)) ||
312 // ((signalR >= sigThresh) &&
313 // (signalR < signalM))) {
314 // // Maximum found, mark the position by a negative signal
315 // digits->SetDataUnchecked(row,col-1,time,-signalM);
318 // Look for the maximum
319 if (signalM >= maxThresh) {
320 if ( (TMath::Abs(signalL)<=signalM) && (TMath::Abs(signalR)<=signalM) &&
321 (TMath::Abs(signalL)+TMath::Abs(signalR))>sigThresh ) {
322 // Maximum found, mark the position by a negative signal
323 digits->SetDataUnchecked(row,col-1,time,-signalM);
331 // Now check the maxima and calculate the cluster position
332 for ( row = 0; row < nRowMax ; row++) {
333 for (time = 0; time < nTimeTotal; time++) {
334 for ( col = 1; col < nColMax-1; col++) {
337 if (digits->GetDataUnchecked(row,col,time) < 0) {
340 for (iPad = 0; iPad < kNclus; iPad++) {
341 Int_t iPadCol = col - 1 + iPad;
342 clusterSignal[iPad] = TMath::Abs(digits->GetDataUnchecked(row
345 clusterDigit[iPad] = digits->GetIndexUnchecked(row,iPadCol,time);
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(digits->GetDataUnchecked(row,col-ii ,time))
358 if (col-ii < 0) break;
361 while (TMath::Abs(digits->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 (digits->GetDataUnchecked(row,col+2,time) < 0) {
396 fivePadCluster = kTRUE;
398 if ((fivePadCluster) && (col < nColMax-5)) {
399 if (digits->GetDataUnchecked(row,col+4,time) >= sigThresh) {
400 fivePadCluster = kFALSE;
403 if ((fivePadCluster) && (col > 1)) {
404 if (digits->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(digits->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;
436 Double_t clusterCharge = clusterSignal[0]
440 // The position of the cluster
441 clusterPads[0] = row + 0.5;
442 // Take the shift of the additional time bins into account
443 clusterPads[2] = time - nTimeBefore + 0.5;
446 clusterPads[2] -= calibration->GetT0(idet, col, row);
448 if (recParam->LUTOn()) {
449 // Calculate the position of the cluster by using the
450 // lookup table method
452 recParam->LUTposition(iplan,clusterSignal[0]
457 // Calculate the position of the cluster by using the
458 // center of gravity method
459 for (Int_t i=0;i<5;i++) padSignal[i]=0;
460 padSignal[2] = TMath::Abs(digits->GetDataUnchecked(row,col,time)); // central pad
461 padSignal[1] = TMath::Abs(digits->GetDataUnchecked(row,col-1,time)); // left pad
462 padSignal[3] = TMath::Abs(digits->GetDataUnchecked(row,col+1,time)); // right pad
463 if (col>2 &&TMath::Abs(digits->GetDataUnchecked(row,col-2,time)<padSignal[1])){
464 padSignal[0] = TMath::Abs(digits->GetDataUnchecked(row,col-2,time));
466 if (col<nColMax-3 &&TMath::Abs(digits->GetDataUnchecked(row,col+2,time)<padSignal[3])){
467 padSignal[4] = TMath::Abs(digits->GetDataUnchecked(row,col+2,time));
469 clusterPads[1] = GetCOG(padSignal);
470 //Double_t check = fPar->LUTposition(iplan,clusterSignal[0]
472 // ,clusterSignal[2]);
473 // Float_t diff = clusterPads[1] - check;
477 Double_t q0 = clusterSignal[0];
478 Double_t q1 = clusterSignal[1];
479 Double_t q2 = clusterSignal[2];
480 Double_t clusterSigmaY2 = (q1*(q0+q2)+4*q0*q2) /
481 (clusterCharge*clusterCharge);
483 Float_t vdrift = calibration->GetVdrift(idet, col, row);
485 // Calculate the position and the error
486 Double_t colSize = padPlane->GetColSize(col);
487 Double_t rowSize = padPlane->GetRowSize(row);
488 Double_t clusterPos[3];
489 clusterPos[0] = padPlane->GetColPos(col) + (clusterPads[1]-0.5)*colSize; // MI change
490 clusterPos[1] = padPlane->GetRowPos(row) -0.5*rowSize; //MI change
491 clusterPos[2] = CalcXposFromTimebin(clusterPads[2], vdrift);
492 Double_t clusterSig[2];
493 clusterSig[0] = (clusterSigmaY2 + 1./12.) * colSize*colSize;
494 clusterSig[1] = rowSize * rowSize / 12.;
497 // Add the cluster to the output array
498 AliTRDcluster * cluster = AddCluster(clusterPos
499 ,(Int_t) clusterPads[2]
504 ,iType,clusterPads[1]);
507 Short_t signals[7]={0,0,0,0,0,0,0};
508 for (Int_t jPad = col-3;jPad<=col+3;jPad++){
509 if (jPad<0 ||jPad>=nColMax-1) continue;
510 signals[jPad-col+3] = TMath::Abs(digits->GetDataUnchecked(row,jPad,time));
512 cluster->SetSignals(signals);
518 // Compress the arrays
519 digits->Compress(1,0);
520 track0->Compress(1,0);
521 track1->Compress(1,0);
522 track2->Compress(1,0);
524 // Write the cluster and reset the array
532 printf("<AliTRDclusterizerV1::MakeCluster> ");
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;
552 //_____________________________________________________________________________
553 Double_t AliTRDclusterizerV1::Unfold(Double_t eps, Int_t plane, Double_t* padSignal)
556 // Method to unfold neighbouring maxima.
557 // The charge ratio on the overlapping pad is calculated
558 // until there is no more change within the range given by eps.
559 // The resulting ratio is then returned to the calling method.
562 AliTRDCommonParam* commonParam = AliTRDCommonParam::Instance();
565 printf("<AliTRDdigitizer::MakeDigits> ");
566 printf("Could not get common params\n");
571 Int_t itStep = 0; // Count iteration steps
573 Double_t ratio = 0.5; // Start value for ratio
574 Double_t prevRatio = 0; // Store previous ratio
576 Double_t newLeftSignal[3] = {0}; // Array to store left cluster signal
577 Double_t newRightSignal[3] = {0}; // Array to store right cluster signal
578 Double_t newSignal[3] = {0};
580 // Start the iteration
581 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
586 // Cluster position according to charge ratio
587 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
588 / (padSignal[0] + padSignal[1] + ratio*padSignal[2]);
589 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
590 / ((1-ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
592 // Set cluster charge ratio
593 irc = commonParam->PadResponse(1.0,maxLeft ,plane,newSignal);
594 Double_t ampLeft = padSignal[1] / newSignal[1];
595 irc = commonParam->PadResponse(1.0,maxRight,plane,newSignal);
596 Double_t ampRight = padSignal[3] / newSignal[1];
598 // Apply pad response to parameters
599 irc = commonParam->PadResponse(ampLeft ,maxLeft ,plane,newLeftSignal );
600 irc = commonParam->PadResponse(ampRight,maxRight,plane,newRightSignal);
602 // Calculate new overlapping ratio
603 ratio = TMath::Min((Double_t)1.0,newLeftSignal[2] /
604 (newLeftSignal[2] + newRightSignal[0]));