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"
33 #include "AliTRDclusterizerV1.h"
34 #include "AliTRDmatrix.h"
35 #include "AliTRDgeometry.h"
36 #include "AliTRDdataArrayF.h"
37 #include "AliTRDdataArrayI.h"
38 #include "AliTRDdigitsManager.h"
39 #include "AliTRDparameter.h"
40 #include "AliTRDpadPlane.h"
42 ClassImp(AliTRDclusterizerV1)
44 //_____________________________________________________________________________
45 AliTRDclusterizerV1::AliTRDclusterizerV1():AliTRDclusterizer()
48 // AliTRDclusterizerV1 default constructor
55 //_____________________________________________________________________________
56 AliTRDclusterizerV1::AliTRDclusterizerV1(const Text_t* name, const Text_t* title)
57 :AliTRDclusterizer(name,title)
60 // AliTRDclusterizerV1 default constructor
63 fDigitsManager = new AliTRDdigitsManager();
64 fDigitsManager->CreateArrays();
68 //_____________________________________________________________________________
69 AliTRDclusterizerV1::AliTRDclusterizerV1(const AliTRDclusterizerV1 &c)
73 // AliTRDclusterizerV1 copy constructor
76 ((AliTRDclusterizerV1 &) c).Copy(*this);
80 //_____________________________________________________________________________
81 AliTRDclusterizerV1::~AliTRDclusterizerV1()
84 // AliTRDclusterizerV1 destructor
88 delete fDigitsManager;
89 fDigitsManager = NULL;
94 //_____________________________________________________________________________
95 AliTRDclusterizerV1 &AliTRDclusterizerV1::operator=(const AliTRDclusterizerV1 &c)
98 // Assignment operator
101 if (this != &c) ((AliTRDclusterizerV1 &) c).Copy(*this);
106 //_____________________________________________________________________________
107 void AliTRDclusterizerV1::Copy(TObject &c) const
113 ((AliTRDclusterizerV1 &) c).fDigitsManager = 0;
115 AliTRDclusterizer::Copy(c);
119 //_____________________________________________________________________________
120 Bool_t AliTRDclusterizerV1::ReadDigits()
123 // Reads the digits arrays from the input aliroot file
127 printf("<AliTRDclusterizerV1::ReadDigits> ");
128 printf("No input file open\n");
131 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
132 if (!loader->TreeD()) loader->LoadDigits();
134 // Read in the digit arrays
135 return (fDigitsManager->ReadDigits(loader->TreeD()));
139 //_____________________________________________________________________________
140 Bool_t AliTRDclusterizerV1::MakeClusters()
143 // Generates the cluster.
146 Int_t row, col, time;
149 if (fTRD->IsVersion() != 1) {
150 printf("<AliTRDclusterizerV1::MakeCluster> ");
151 printf("TRD must be version 1 (slow simulator).\n");
157 AliTRDgeometry *geo = AliTRDgeometry::GetGeometry(fRunLoader);
159 // Create a default parameter class if none is defined
161 fPar = new AliTRDparameter("TRDparameter","Standard TRD parameter");
162 printf("<AliTRDclusterizerV1::MakeCluster> ");
163 printf("Create the default parameter object.\n");
167 //Float_t timeBinSize = fPar->GetDriftVelocity()
168 // / fPar->GetSamplingFrequency();
169 // Half of ampl.region
170 // const Float_t kAmWidth = AliTRDgeometry::AmThick()/2.;
172 Float_t omegaTau = fPar->GetOmegaTau();
174 printf("<AliTRDclusterizerV1::MakeCluster> ");
175 printf("OmegaTau = %f \n",omegaTau);
176 printf("<AliTRDclusterizerV1::MakeCluster> ");
177 printf("Start creating clusters.\n");
180 AliTRDdataArrayI *digits;
181 AliTRDdataArrayI *track0;
182 AliTRDdataArrayI *track1;
183 AliTRDdataArrayI *track2;
185 // Threshold value for the maximum
186 Int_t maxThresh = fPar->GetClusMaxThresh();
187 // Threshold value for the digit signal
188 Int_t sigThresh = fPar->GetClusSigThresh();
189 // Iteration limit for unfolding procedure
190 const Float_t kEpsilon = 0.01;
192 const Int_t kNclus = 3;
193 const Int_t kNsig = 5;
194 const Int_t kNtrack = 3 * kNclus;
198 Double_t ratioLeft = 1.0;
199 Double_t ratioRight = 1.0;
202 Double_t padSignal[kNsig];
203 Double_t clusterSignal[kNclus];
204 Double_t clusterPads[kNclus];
205 Int_t clusterDigit[kNclus];
206 Int_t clusterTracks[kNtrack];
209 Int_t chamEnd = AliTRDgeometry::Ncham();
211 Int_t planEnd = AliTRDgeometry::Nplan();
213 Int_t sectEnd = AliTRDgeometry::Nsect();
215 // Start clustering in every chamber
216 for (Int_t icham = chamBeg; icham < chamEnd; icham++) {
217 for (Int_t iplan = planBeg; iplan < planEnd; iplan++) {
218 for (Int_t isect = sectBeg; isect < sectEnd; isect++) {
220 Int_t idet = geo->GetDetector(iplan,icham,isect);
223 Int_t nClusters2pad = 0;
224 Int_t nClusters3pad = 0;
225 Int_t nClusters4pad = 0;
226 Int_t nClusters5pad = 0;
227 Int_t nClustersLarge = 0;
230 printf("<AliTRDclusterizerV1::MakeCluster> ");
231 printf("Analyzing chamber %d, plane %d, sector %d.\n"
235 Int_t nRowMax = fPar->GetRowMax(iplan,icham,isect);
236 Int_t nColMax = fPar->GetColMax(iplan);
237 Int_t nTimeBefore = fPar->GetTimeBefore();
238 Int_t nTimeTotal = fPar->GetTimeTotal();
240 AliTRDpadPlane *padPlane = fPar->GetPadPlane(iplan,icham);
243 digits = fDigitsManager->GetDigits(idet);
245 track0 = fDigitsManager->GetDictionary(idet,0);
247 track1 = fDigitsManager->GetDictionary(idet,1);
249 track2 = fDigitsManager->GetDictionary(idet,2);
252 // Loop through the chamber and find the maxima
253 for ( row = 0; row < nRowMax; row++) {
254 // for ( col = 2; col < nColMax; col++) {
255 for ( col = 4; col < nColMax-2; col++) {
256 for (time = 0; time < nTimeTotal; time++) {
258 Int_t signalL = TMath::Abs(digits->GetDataUnchecked(row,col ,time));
259 Int_t signalM = TMath::Abs(digits->GetDataUnchecked(row,col-1,time));
260 Int_t signalR = TMath::Abs(digits->GetDataUnchecked(row,col-2,time));
262 // // Look for the maximum
263 // if (signalM >= maxThresh) {
264 // if (((signalL >= sigThresh) &&
265 // (signalL < signalM)) ||
266 // ((signalR >= sigThresh) &&
267 // (signalR < signalM))) {
268 // // Maximum found, mark the position by a negative signal
269 // digits->SetDataUnchecked(row,col-1,time,-signalM);
272 // Look for the maximum
273 if (signalM >= maxThresh) {
274 if ( (signalL<=signalM) && (signalR<=signalM) && (signalL+signalR)>sigThresh ) {
275 // Maximum found, mark the position by a negative signal
276 digits->SetDataUnchecked(row,col-1,time,-signalM);
284 // Now check the maxima and calculate the cluster position
285 for ( row = 0; row < nRowMax ; row++) {
286 for (time = 0; time < nTimeTotal; time++) {
287 for ( col = 1; col < nColMax-1; col++) {
290 if (digits->GetDataUnchecked(row,col,time) < 0) {
293 for (iPad = 0; iPad < kNclus; iPad++) {
294 Int_t iPadCol = col - 1 + iPad;
295 clusterSignal[iPad] = TMath::Abs(digits->GetDataUnchecked(row
298 clusterDigit[iPad] = digits->GetIndexUnchecked(row,iPadCol,time);
299 clusterTracks[3*iPad ] = track0->GetDataUnchecked(row,iPadCol,time) - 1;
300 clusterTracks[3*iPad+1] = track1->GetDataUnchecked(row,iPadCol,time) - 1;
301 clusterTracks[3*iPad+2] = track2->GetDataUnchecked(row,iPadCol,time) - 1;
304 // Count the number of pads in the cluster
307 while (TMath::Abs(digits->GetDataUnchecked(row,col-ii ,time))
311 if (col-ii < 0) break;
314 while (TMath::Abs(digits->GetDataUnchecked(row,col+ii+1,time))
318 if (col+ii+1 >= nColMax) break;
345 // Look for 5 pad cluster with minimum in the middle
346 Bool_t fivePadCluster = kFALSE;
347 if (col < nColMax-3) {
348 if (digits->GetDataUnchecked(row,col+2,time) < 0) {
349 fivePadCluster = kTRUE;
351 if ((fivePadCluster) && (col < nColMax-5)) {
352 if (digits->GetDataUnchecked(row,col+4,time) >= sigThresh) {
353 fivePadCluster = kFALSE;
356 if ((fivePadCluster) && (col > 1)) {
357 if (digits->GetDataUnchecked(row,col-2,time) >= sigThresh) {
358 fivePadCluster = kFALSE;
364 // Modify the signal of the overlapping pad for the left part
365 // of the cluster which remains from a previous unfolding
367 clusterSignal[0] *= ratioLeft;
372 // Unfold the 5 pad cluster
373 if (fivePadCluster) {
374 for (iPad = 0; iPad < kNsig; iPad++) {
375 padSignal[iPad] = TMath::Abs(digits->GetDataUnchecked(row
379 // Unfold the two maxima and set the signal on
380 // the overlapping pad to the ratio
381 ratioRight = Unfold(kEpsilon,iplan,padSignal);
382 ratioLeft = 1.0 - ratioRight;
383 clusterSignal[2] *= ratioRight;
389 Double_t clusterCharge = clusterSignal[0]
393 // The position of the cluster
394 clusterPads[0] = row + 0.5;
395 // Take the shift of the additional time bins into account
396 clusterPads[2] = time - nTimeBefore + 0.5;
399 // Calculate the position of the cluster by using the
400 // lookup table method
402 fPar->LUTposition(iplan,clusterSignal[0]
407 // Calculate the position of the cluster by using the
408 // center of gravity method
409 for (Int_t i=0;i<5;i++) padSignal[i]=0;
410 padSignal[2] = TMath::Abs(digits->GetDataUnchecked(row,col,time)); // central pad
411 padSignal[1] = TMath::Abs(digits->GetDataUnchecked(row,col-1,time)); // left pad
412 padSignal[3] = TMath::Abs(digits->GetDataUnchecked(row,col+1,time)); // right pad
413 if (col>2 &&TMath::Abs(digits->GetDataUnchecked(row,col-2,time)<padSignal[1])){
414 padSignal[0] = TMath::Abs(digits->GetDataUnchecked(row,col-2,time));
416 if (col<nColMax-3 &&TMath::Abs(digits->GetDataUnchecked(row,col+2,time)<padSignal[3])){
417 padSignal[4] = TMath::Abs(digits->GetDataUnchecked(row,col+2,time));
419 clusterPads[1] = GetCOG(padSignal);
420 Double_t check = fPar->LUTposition(iplan,clusterSignal[0]
423 // clusterPads[1] = check;
427 Double_t q0 = clusterSignal[0];
428 Double_t q1 = clusterSignal[1];
429 Double_t q2 = clusterSignal[2];
430 Double_t clusterSigmaY2 = (q1*(q0+q2)+4*q0*q2) /
431 (clusterCharge*clusterCharge);
433 // Calculate the position and the error
434 Double_t colSize = padPlane->GetColSize(col);
435 Double_t rowSize = padPlane->GetRowSize(row);
436 Double_t clusterPos[3];
437 clusterPos[0] = padPlane->GetColPos(col) + (clusterPads[1]-0.5)*colSize; // MI change
438 clusterPos[1] = padPlane->GetRowPos(row) -0.5*rowSize; //MI change
439 clusterPos[2] = clusterPads[2];
440 Double_t clusterSig[2];
441 clusterSig[0] = (clusterSigmaY2 + 1./12.) * colSize*colSize;
442 clusterSig[1] = rowSize * rowSize / 12.;
443 // Add the cluster to the output array
444 AddCluster(clusterPos
456 // Compress the arrays
457 digits->Compress(1,0);
458 track0->Compress(1,0);
459 track1->Compress(1,0);
460 track2->Compress(1,0);
462 // Write the cluster and reset the array
470 printf("<AliTRDclusterizerV1::MakeCluster> ");
478 Double_t AliTRDclusterizerV1::GetCOG(Double_t signal[5])
482 // used for clusters with more than 3 pads - where LUT not applicable
483 Double_t sum = signal[0]+signal[1]+signal[2]+signal[3]+signal[4];
484 Double_t res = (0.0*(-signal[0]+signal[4])+(-signal[1]+signal[3]))/sum;
490 //_____________________________________________________________________________
491 Double_t AliTRDclusterizerV1::Unfold(Double_t eps, Int_t plane, Double_t* padSignal)
494 // Method to unfold neighbouring maxima.
495 // The charge ratio on the overlapping pad is calculated
496 // until there is no more change within the range given by eps.
497 // The resulting ratio is then returned to the calling method.
501 Int_t itStep = 0; // Count iteration steps
503 Double_t ratio = 0.5; // Start value for ratio
504 Double_t prevRatio = 0; // Store previous ratio
506 Double_t newLeftSignal[3] = {0}; // Array to store left cluster signal
507 Double_t newRightSignal[3] = {0}; // Array to store right cluster signal
508 Double_t newSignal[3] = {0};
510 // Start the iteration
511 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
516 // Cluster position according to charge ratio
517 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
518 / (padSignal[0] + padSignal[1] + ratio*padSignal[2]);
519 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
520 / ((1-ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
522 // Set cluster charge ratio
523 irc = fPar->PadResponse(1.0,maxLeft ,plane,newSignal);
524 Double_t ampLeft = padSignal[1] / newSignal[1];
525 irc = fPar->PadResponse(1.0,maxRight,plane,newSignal);
526 Double_t ampRight = padSignal[3] / newSignal[1];
528 // Apply pad response to parameters
529 irc = fPar->PadResponse(ampLeft ,maxLeft ,plane,newLeftSignal );
530 irc = fPar->PadResponse(ampRight,maxRight,plane,newRightSignal);
532 // Calculate new overlapping ratio
533 ratio = TMath::Min((Double_t)1.0,newLeftSignal[2] /
534 (newLeftSignal[2] + newRightSignal[0]));