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 **************************************************************************/
16 /* $Id: AliTRDtrackingChamber.cxx 23810 2008-02-08 09:00:27Z hristov $ */
18 ////////////////////////////////////////////////////////////////////////////
20 // Tracking in one chamber //
23 // Alex Bercuci <A.Bercuci@gsi.de> //
24 // Markus Fasel <M.Fasel@gsi.de> //
26 ////////////////////////////////////////////////////////////////////////////
28 #include "AliTRDtrackingChamber.h"
31 #include "TMatrixTBase.h"
32 #include <TTreeStream.h>
34 #include "AliTRDReconstructor.h"
35 #include "AliTRDrecoParam.h"
36 #include "AliTRDtrackerV1.h"
37 #include "AliTRDgeometry.h"
38 #include "AliTRDpadPlane.h"
39 #include "AliTRDcalibDB.h"
40 #include "Cal/AliTRDCalDet.h"
41 #include "Cal/AliTRDCalROC.h"
43 ClassImp(AliTRDtrackingChamber)
45 //_______________________________________________________
46 AliTRDtrackingChamber::AliTRDtrackingChamber(Int_t det)
52 //_______________________________________________________
53 void AliTRDtrackingChamber::Clear(const Option_t *opt)
55 for(Int_t itb=0; itb<kNTimeBins; itb++) fTB[itb].Clear(opt);
58 //_______________________________________________________
59 void AliTRDtrackingChamber::InsertCluster(AliTRDcluster *c, Int_t index)
61 fTB[c->GetPadTime()].InsertCluster(c, index);
64 //_______________________________________________________
65 Bool_t AliTRDtrackingChamber::Build(AliTRDgeometry *geo, const AliTRDCalDet *cal, Bool_t hlt)
67 // Init chamber and all time bins (AliTRDchamberTimeBin)
68 // Calculates radial position of the chamber based on
69 // radial positions of the time bins (calibration/alignment aware)
71 Int_t stack = geo->GetStack(fDetector);
72 Int_t layer = geo->GetLayer(fDetector);
73 AliTRDpadPlane *pp = geo->GetPadPlane(layer, stack);
74 Double_t zl = pp->GetRow0ROC() - pp->GetRowEndROC();
75 Double_t z0 = geo->GetRow0(layer, stack, 0) - zl;
76 Int_t nrows = pp->GetNrows();
78 Int_t index[50], jtb = 0;
79 for(Int_t itb=0; itb<kNTimeBins; itb++){
80 if(!fTB[itb]) continue;
81 fTB[itb].SetRange(z0, zl);
82 fTB[itb].SetNRows(nrows);
83 fTB[itb].BuildIndices();
86 if(jtb<2) return kFALSE;
89 // ESTIMATE POSITION OF PAD PLANE FOR THIS CHAMBER
90 Double_t x0 = fTB[index[0]].GetX();
91 Double_t x1 = fTB[index[1]].GetX();
92 Double_t dx = (x0 - x1)/(index[1] - index[0]);
94 Int_t t0 = (Int_t)cal->GetValue(fDetector);
97 AliTRDCalROC *roc = AliTRDcalibDB::Instance()->GetT0ROC(fDetector);
98 for(Int_t k = 0; k<roc->GetNchannels(); k++) mean += roc->GetValue(k);
99 mean /= roc->GetNchannels();
100 t0 = (Int_t)(cal->GetValue(fDetector) + mean);
103 fX0 = x0 + dx*(index[0] - t0);
107 //_______________________________________________________
108 Int_t AliTRDtrackingChamber::GetNClusters() const
110 // Returns number of clusters in chamber
113 for(Int_t itb=0; itb<kNTimeBins; itb++){
114 n += Int_t(fTB[itb]);
119 //_______________________________________________________
120 Double_t AliTRDtrackingChamber::GetQuality()
123 // Calculate chamber quality for seeding.
127 // layers : Array of propagation layers for this plane.
130 // plane quality factor for seeding
132 // Detailed description
134 // The quality of the plane for seeding is higher if:
135 // 1. the average timebin population is closer to an integer number
136 // 2. the distribution of clusters/timebin is closer to a uniform distribution.
137 // - the slope of the first derivative of a parabolic fit is small or
138 // - the slope of a linear fit is small
144 for(int itb=0; itb<kNTimeBins; itb++){
145 if(!(nClLayer = fTB[itb].GetNClusters())) continue;
147 for(Int_t incl = 0; incl < nClLayer; incl++){
148 if((fTB[itb].GetCluster(incl))->IsUsed()) nused++;
152 // calculate the deviation of the mean number of clusters from the
153 // closest integer values
154 Float_t nclMed = float(ncl-nused)/AliTRDtrackerV1::GetNTimeBins();
155 Int_t ncli = Int_t(nclMed);
156 Float_t nclDev = TMath::Abs(nclMed - TMath::Max(ncli, 1));
157 nclDev -= (nclDev>.5) && ncli ? 1. : 0.;
158 return TMath::Exp(-5.*TMath::Abs(nclDev));
160 // // get slope of the derivative
161 // if(!fitter.Eval()) return quality;
162 // fitter.PrintResults(3);
163 // Double_t a = fitter.GetParameter(1);
165 // printf("ncl_dev(%f) a(%f)\n", ncl_dev, a);
166 // return quality*TMath::Exp(-a);
171 //_______________________________________________________
172 Bool_t AliTRDtrackingChamber::GetSeedingLayer(AliTRDchamberTimeBin *&fakeLayer, AliTRDgeometry *geo, const AliTRDReconstructor *rec)
175 // Creates a seeding layer
179 const Int_t kMaxRows = 16;
180 const Int_t kMaxCols = 144;
181 const Int_t kMaxPads = 2304;
182 Int_t timeBinMin = rec->GetRecoParam()->GetNumberOfPresamples();
183 Int_t timeBinMax = rec->GetRecoParam()->GetNumberOfPostsamples();
185 // Get the geometrical data of the chamber
186 Int_t layer = geo->GetLayer(fDetector);
187 Int_t stack = geo->GetStack(fDetector);
188 Int_t sector= geo->GetSector(fDetector);
189 AliTRDpadPlane *pp = geo->GetPadPlane(layer, stack);
190 Int_t nCols = pp->GetNcols();
191 Float_t ymin = TMath::Min(pp->GetCol0(), pp->GetColEnd());
192 Float_t ymax = TMath::Max(pp->GetCol0(), pp->GetColEnd());
193 Float_t zmin = TMath::Min(pp->GetRow0(), pp->GetRowEnd());
194 Float_t zmax = TMath::Max(pp->GetRow0(), pp->GetRowEnd());
195 Float_t z0 = -1., zl = -1.;
196 Int_t nRows = pp->GetNrows();
197 Float_t binlength = (ymax - ymin)/nCols;
198 //AliInfo(Form("ymin(%f) ymax(%f) zmin(%f) zmax(%f) nRows(%d) binlength(%f)", ymin, ymax, zmin, zmax, nRows, binlength));
200 // Fill the histogram
202 Int_t *histogram[kMaxRows]; // 2D-Histogram
203 Int_t hvals[kMaxPads + 1]; memset(hvals, 0, sizeof(Int_t)*kMaxPads); // one entry in addition for termination flag
204 Float_t *sigmas[kMaxRows];
205 Float_t svals[kMaxPads]; memset(svals, 0, sizeof(Float_t)*kMaxPads);
206 AliTRDcluster *c = 0x0;
207 for(Int_t irs = 0; irs < kMaxRows; irs++){
208 histogram[irs] = &hvals[irs*kMaxCols];
209 sigmas[irs] = &svals[irs*kMaxCols];
211 for(Int_t iTime = timeBinMin; iTime < kNTimeBins-timeBinMax; iTime++){
212 if(!(nClusters = fTB[iTime].GetNClusters())) continue;
213 z0 = fTB[iTime].GetZ0();
214 zl = fTB[iTime].GetDZ0();
215 for(Int_t incl = 0; incl < nClusters; incl++){
216 c = fTB[iTime].GetCluster(incl);
217 histogram[c->GetPadRow()][c->GetPadCol()]++;
218 sigmas[c->GetPadRow()][c->GetPadCol()] += c->GetSigmaZ2();
222 // Now I have everything in the histogram, do the selection
223 //Int_t nPads = nCols * nRows;
224 // This is what we are interested in: The center of gravity of the best candidates
225 Float_t cogyvals[kMaxPads]; memset(cogyvals, 0, sizeof(Float_t)*kMaxPads);
226 Float_t cogzvals[kMaxPads]; memset(cogzvals, 0, sizeof(Float_t)*kMaxPads);
227 Float_t *cogy[kMaxRows];
228 Float_t *cogz[kMaxRows];
230 // Lookup-Table storing coordinates according to the bins
231 Float_t yLengths[kMaxCols];
232 Float_t zLengths[kMaxRows];
233 for(Int_t icnt = 0; icnt < nCols; icnt++){
234 yLengths[icnt] = pp->GetColPos(nCols - 1 - icnt) + binlength/2;
236 for(Int_t icnt = 0; icnt < nRows; icnt++){
237 zLengths[icnt] = pp->GetRowPos(icnt) - pp->GetRowSize(icnt)/2;
240 // A bitfield is used to mask the pads as usable
241 Short_t mask[kMaxCols]; memset(mask, 0 ,sizeof(Short_t) * kMaxCols);//bool mvals[kMaxPads];
242 for(UChar_t icount = 0; icount < nRows; icount++){
243 cogy[icount] = &cogyvals[icount*kMaxCols];
244 cogz[icount] = &cogzvals[icount*kMaxCols];
246 // In this array the array position of the best candidates will be stored
247 Int_t cand[AliTRDtrackerV1::kMaxTracksStack];
248 Float_t sigcands[AliTRDtrackerV1::kMaxTracksStack];
251 Int_t indices[kMaxPads]; memset(indices, -1, sizeof(Int_t)*kMaxPads);
252 Int_t nCandidates = 0;
254 // histogram filled -> Select best bins
255 Int_t nPads = nCols * nRows;
256 // take out all the bins which have less than 3 entries (faster sorting)
257 Int_t content[kMaxPads], dictionary[kMaxPads], nCont = 0, padnumber = 0;
258 Int_t *iter = &hvals[0], *citer = &content[0], *diter = &dictionary[0]; // iterators for preselection
259 const Int_t threshold = 2;
260 hvals[nPads] = -1; // termination for iterator
262 if(*iter > threshold){
264 *(diter++) = padnumber;
268 }while(*(++iter) != -1);
269 TMath::Sort(nCont, content, indices);
271 Int_t col, row, lower, lower1, upper, upper1;
272 for(Int_t ib = 0; ib < nCont; ib++){
273 if(nCandidates >= AliTRDtrackerV1::kMaxTracksStack){
274 printf("Number of seed candidates %d exceeded maximum allowed per stack %d", nCandidates, AliTRDtrackerV1::kMaxTracksStack);
278 row = dictionary[indices[ib]]/nCols;
279 col = dictionary[indices[ib]]%nCols;
280 // here will be the threshold condition:
281 if((mask[col] & (1 << row)) != 0) continue; // Pad is masked: continue
282 // if(histogram[row][col] < TMath::Max(threshold, 1)){ // of course at least one cluster is needed
283 // break; // number of clusters below threshold: break;
285 // passing: Mark the neighbors
286 lower = TMath::Max(col - 1, 0); upper = TMath::Min(col + 2, nCols);
287 lower1 = TMath::Max(row - 1, 0); upper1 = TMath::Min(row + 2, nCols);
288 for(Int_t ic = lower; ic < upper; ++ic)
289 for(Int_t ir = lower1; ir < upper1; ++ir){
290 if(ic == col && ir == row) continue;
291 mask[ic] |= (1 << ir);
293 // Storing the position in an array
294 // testing for neigboring
297 lower = TMath::Max(col - 1, 0);
298 upper = TMath::Min(col + 2, nCols);
299 for(Int_t inb = lower; inb < upper; ++inb){
300 cogv += yLengths[inb] * histogram[row][inb];
301 norm += histogram[row][inb];
303 cogy[row][col] = cogv / norm;
305 lower = TMath::Max(row - 1, 0);
306 upper = TMath::Min(row + 2, nRows);
307 for(Int_t inb = lower; inb < upper; ++inb){
308 cogv += zLengths[inb] * histogram[inb][col];
309 norm += histogram[inb][col];
311 cogz[row][col] = Float_t(cogv) / norm;
313 cand[nCandidates] = row*nCols + col; // store the position of a passig candidate into an Array
314 sigcands[nCandidates] = sigmas[row][col] / histogram[row][col]; // never be a floating point exeption
318 if(!nCandidates) return kFALSE;
320 Float_t pos[3], sig[2];
321 Short_t signal[7]; memset(&signal[0], 0, 7*sizeof(Short_t));
323 new(fakeLayer) AliTRDchamberTimeBin(layer, stack, sector, z0, zl);
324 fakeLayer->SetReconstructor(rec);
325 AliTRDcluster *cluster = 0x0;
327 UInt_t fakeIndex = 0;
328 for(Int_t ican = 0; ican < nCandidates; ican++){
329 row = cand[ican] / nCols;
330 col = cand[ican] % nCols;
332 Int_t n = 0; Double_t x = 0., y = 0., z = 0.;
333 for(int itb=0; itb<kNTimeBins; itb++){
334 if(!(nClusters = fTB[itb].GetNClusters())) continue;
335 for(Int_t incl = 0; incl < nClusters; incl++){
336 c = fTB[itb].GetCluster(incl);
337 if(c->GetPadRow() != row) continue;
338 if(TMath::Abs(c->GetPadCol() - col) > 2) continue;
349 sig[1] = sigcands[ican];
350 cluster = new AliTRDcluster(fDetector, 0., pos, sig, 0x0, 3, signal, col, row, 0, 0, 0., 0);
351 fakeLayer->InsertCluster(cluster, fakeIndex++);
354 fakeLayer->SetNRows(nRows);
355 fakeLayer->SetOwner();
356 fakeLayer->BuildIndices();
357 //fakeLayer->PrintClusters();
359 if(rec->GetStreamLevel(AliTRDReconstructor::kTracker) >= 3){
360 //TMatrixD hist(nRows, nCols);
361 //for(Int_t i = 0; i < nRows; i++)
362 // for(Int_t j = 0; j < nCols; j++)
363 // hist(i,j) = histogram[i][j];
364 TTreeSRedirector &cstreamer = *AliTRDtrackerV1::DebugStreamer();
365 cstreamer << "GetSeedingLayer"
371 << "L.=" << fakeLayer
372 //<< "Histogram.=" << &hist