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 Revision 1.1 2000/02/28 18:58:54 cblume
23 ///////////////////////////////////////////////////////////////////////////////
25 // TRD cluster finder for the slow simulator.
27 ///////////////////////////////////////////////////////////////////////////////
31 #include "AliTRDclusterizerV1.h"
32 #include "AliTRDmatrix.h"
33 #include "AliTRDgeometry.h"
34 #include "AliTRDdigitizer.h"
35 #include "AliTRDrecPoint.h"
36 #include "AliTRDdataArray.h"
38 ClassImp(AliTRDclusterizerV1)
40 //_____________________________________________________________________________
41 AliTRDclusterizerV1::AliTRDclusterizerV1():AliTRDclusterizer()
44 // AliTRDclusterizerV1 default constructor
51 //_____________________________________________________________________________
52 AliTRDclusterizerV1::AliTRDclusterizerV1(const Text_t* name, const Text_t* title)
53 :AliTRDclusterizer(name,title)
56 // AliTRDclusterizerV1 default constructor
65 //_____________________________________________________________________________
66 AliTRDclusterizerV1::~AliTRDclusterizerV1()
70 fDigitsArray->Delete();
76 //_____________________________________________________________________________
77 void AliTRDclusterizerV1::Init()
80 // Initializes the cluster finder
83 // The default parameter for the clustering
90 //_____________________________________________________________________________
91 Bool_t AliTRDclusterizerV1::ReadDigits()
94 // Reads the digits arrays from the input aliroot file
98 printf("AliTRDclusterizerV1::ReadDigits -- ");
99 printf("No input file open\n");
103 // Create a new segment array for the digits
104 fDigitsArray = new AliTRDsegmentArray(kNsect*kNplan*kNcham);
106 // Read in the digit arrays
107 return (fDigitsArray->LoadArray("TRDdigits"));
111 //_____________________________________________________________________________
112 Bool_t AliTRDclusterizerV1::MakeCluster()
115 // Generates the cluster.
118 Int_t row, col, time;
120 // Get the pointer to the detector class and check for version 1
121 AliTRD *TRD = (AliTRD*) gAlice->GetDetector("TRD");
122 if (TRD->IsVersion() != 1) {
123 printf("AliTRDclusterizerV1::MakeCluster -- ");
124 printf("TRD must be version 1 (slow simulator).\n");
129 AliTRDgeometry *Geo = TRD->GetGeometry();
131 printf("AliTRDclusterizerV1::MakeCluster -- ");
132 printf("Start creating clusters.\n");
134 AliTRDdataArray *Digits;
137 Float_t maxThresh = fClusMaxThresh; // threshold value for maximum
138 Float_t signalThresh = fClusSigThresh; // threshold value for digit signal
139 Int_t clusteringMethod = fClusMethod; // clustering method option (for testing)
141 // Iteration limit for unfolding procedure
142 const Float_t epsilon = 0.01;
144 const Int_t nClus = 3;
145 const Int_t nSig = 5;
148 Int_t chamEnd = kNcham;
149 if (TRD->GetSensChamber() >= 0) {
150 chamBeg = TRD->GetSensChamber();
151 chamEnd = chamEnd + 1;
154 Int_t planEnd = kNplan;
155 if (TRD->GetSensPlane() >= 0) {
156 planBeg = TRD->GetSensPlane();
157 planEnd = planBeg + 1;
160 Int_t sectEnd = kNsect;
161 if (TRD->GetSensSector() >= 0) {
162 sectBeg = TRD->GetSensSector();
163 sectEnd = sectBeg + 1;
166 // *** Start clustering *** in every chamber
167 for (Int_t icham = chamBeg; icham < chamEnd; icham++) {
168 for (Int_t iplan = planBeg; iplan < planEnd; iplan++) {
169 for (Int_t isect = sectBeg; isect < sectEnd; isect++) {
171 Int_t idet = Geo->GetDetector(iplan,icham,isect);
174 printf("AliTRDclusterizerV1::MakeCluster -- ");
175 printf("Analyzing chamber %d, plane %d, sector %d.\n"
178 Int_t nRowMax = Geo->GetRowMax(iplan,icham,isect);
179 Int_t nColMax = Geo->GetColMax(iplan);
180 Int_t nTimeMax = Geo->GetTimeMax();
182 // Create a detector matrix to keep maxima
183 AliTRDmatrix *digitMatrix = new AliTRDmatrix(nRowMax,nColMax,nTimeMax
185 // Create a matrix to contain maximum flags
186 AliTRDmatrix *maximaMatrix = new AliTRDmatrix(nRowMax,nColMax,nTimeMax
189 // Read in the digits
190 Digits = (AliTRDdataArray *) fDigitsArray->At(idet);
192 // Loop through the detector pixel
193 for (time = 0; time < nTimeMax; time++) {
194 for ( col = 0; col < nColMax; col++) {
195 for ( row = 0; row < nRowMax; row++) {
197 Int_t signal = Digits->GetData(row,col,time);
198 Int_t index = Digits->GetIndex(row,col,time);
200 // Fill the detector matrix
201 if (signal > signalThresh) {
202 // Store the signal amplitude
203 digitMatrix->SetSignal(row,col,time,signal);
204 // Store the digits number
205 digitMatrix->AddTrack(row,col,time,index);
212 // Loop chamber and find maxima in digitMatrix
213 for ( row = 0; row < nRowMax; row++) {
214 for ( col = 1; col < nColMax; col++) {
215 for (time = 0; time < nTimeMax; time++) {
217 if (digitMatrix->GetSignal(row,col,time)
218 < digitMatrix->GetSignal(row,col - 1,time)) {
221 if (digitMatrix->GetSignal(row,col - 2,time)
222 < digitMatrix->GetSignal(row,col - 1,time)) {
223 // yes, so set maximum flag
224 maximaMatrix->SetSignal(row,col - 1,time,1);
226 else maximaMatrix->SetSignal(row,col - 1,time,0);
234 // now check maxima and calculate cluster position
235 for ( row = 0; row < nRowMax; row++) {
236 for ( col = 1; col < nColMax; col++) {
237 for (time = 0; time < nTimeMax; time++) {
239 if ((maximaMatrix->GetSignal(row,col,time) > 0)
240 && (digitMatrix->GetSignal(row,col,time) > maxThresh)) {
242 // Ratio resulting from unfolding
244 // Signals on max and neighbouring pads
245 Float_t padSignal[nSig] = {0};
246 // Signals from cluster
247 Float_t clusterSignal[nClus] = {0};
249 Float_t clusterPads[nClus] = {0};
250 // Cluster digit info
251 Int_t clusterDigit[nClus] = {0};
253 for (Int_t iPad = 0; iPad < nClus; iPad++) {
254 clusterSignal[iPad] = digitMatrix->GetSignal(row,col-1+iPad,time);
255 clusterDigit[iPad] = digitMatrix->GetTrack(row,col-1+iPad,time,0);
258 // neighbouring maximum on right side?
259 if (col < nColMax - 2) {
260 if (maximaMatrix->GetSignal(row,col + 2,time) > 0) {
262 for (Int_t iPad = 0; iPad < 5; iPad++) {
263 padSignal[iPad] = digitMatrix->GetSignal(row,col-1+iPad,time);
267 ratio = Unfold(epsilon, padSignal);
269 // set signal on overlapping pad to ratio
270 clusterSignal[2] *= ratio;
275 // Calculate the position of the cluster
276 switch (clusteringMethod) {
278 // method 1: simply center of mass
279 clusterPads[0] = row + 0.5;
280 clusterPads[1] = col - 0.5 + (clusterSignal[2] - clusterSignal[0]) /
281 (clusterSignal[0] + clusterSignal[1] + clusterSignal[2]);
282 clusterPads[2] = time + 0.5;
287 // method 2: integral gauss fit on 3 pads
288 TH1F *hPadCharges = new TH1F("hPadCharges", "Charges on center 3 pads"
290 for (Int_t iCol = -1; iCol <= 3; iCol++) {
291 if (clusterSignal[iCol] < 1) clusterSignal[iCol] = 1;
292 hPadCharges->Fill(iCol, clusterSignal[iCol]);
294 hPadCharges->Fit("gaus", "IQ", "SAME", -0.5, 2.5);
295 TF1 *fPadChargeFit = hPadCharges->GetFunction("gaus");
296 Double_t colMean = fPadChargeFit->GetParameter(1);
298 clusterPads[0] = row + 0.5;
299 clusterPads[1] = col - 1.5 + colMean;
300 clusterPads[2] = time + 0.5;
308 Float_t clusterCharge = clusterSignal[0]
312 // Add the cluster to the output array
313 TRD->AddRecPoint(clusterPads,clusterDigit,idet,clusterCharge);
320 printf("AliTRDclusterizerV1::MakeCluster -- ");
321 printf("Number of clusters found: %d\n",nClusters);
330 printf("AliTRDclusterizerV1::MakeCluster -- ");
331 printf("Total number of points found: %d\n"
332 ,TRD->RecPoints()->GetEntries());
334 // Get the pointer to the cluster branch
335 TTree *ClusterTree = gAlice->TreeR();
337 // Fill the cluster-branch
338 printf("AliTRDclusterizerV1::MakeCluster -- ");
339 printf("Fill the cluster tree.\n");
341 printf("AliTRDclusterizerV1::MakeCluster -- ");
348 //_____________________________________________________________________________
349 Float_t AliTRDclusterizerV1::Unfold(Float_t eps, Float_t* padSignal)
352 // Method to unfold neighbouring maxima.
353 // The charge ratio on the overlapping pad is calculated
354 // until there is no more change within the range given by eps.
355 // The resulting ratio is then returned to the calling method.
358 Int_t itStep = 0; // count iteration steps
360 Float_t ratio = 0.5; // start value for ratio
361 Float_t prevRatio = 0; // store previous ratio
363 Float_t newLeftSignal[3] = {0}; // array to store left cluster signal
364 Float_t newRightSignal[3] = {0}; // array to store right cluster signal
367 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
372 // cluster position according to charge ratio
373 Float_t maxLeft = (ratio*padSignal[2] - padSignal[0]) /
374 (padSignal[0] + padSignal[1] + ratio*padSignal[2]);
375 Float_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2]) /
376 ((1-ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
378 // set cluster charge ratio
379 Float_t ampLeft = padSignal[1];
380 Float_t ampRight = padSignal[3];
382 // apply pad response to parameters
383 newLeftSignal[0] = ampLeft*PadResponse(-1 - maxLeft);
384 newLeftSignal[1] = ampLeft*PadResponse( 0 - maxLeft);
385 newLeftSignal[2] = ampLeft*PadResponse( 1 - maxLeft);
387 newRightSignal[0] = ampRight*PadResponse(-1 - maxRight);
388 newRightSignal[1] = ampRight*PadResponse( 0 - maxRight);
389 newRightSignal[2] = ampRight*PadResponse( 1 - maxRight);
391 // calculate new overlapping ratio
392 ratio = newLeftSignal[2]/(newLeftSignal[2] + newRightSignal[0]);
400 //_____________________________________________________________________________
401 Float_t AliTRDclusterizerV1::PadResponse(Float_t x)
404 // The pad response for the chevron pads.
405 // We use a simple Gaussian approximation which should be good
406 // enough for our purpose.
409 // The parameters for the response function
410 const Float_t aa = 0.8872;
411 const Float_t bb = -0.00573;
412 const Float_t cc = 0.454;
413 const Float_t cc2 = cc*cc;
415 Float_t pr = aa * (bb + TMath::Exp(-x*x / (2. * cc2)));