Put 0.1 as minimal value of the gas gain (Raphaelle)
[u/mrichter/AliRoot.git] / TRD / AliTRDtrackingChamber.cxx
CommitLineData
b0a48c4d 1/**************************************************************************
2* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3* *
4* Author: The ALICE Off-line Project. *
5* Contributors are mentioned in the code where appropriate. *
6* *
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**************************************************************************/
15
16/* $Id: AliTRDtrackingChamber.cxx 23810 2008-02-08 09:00:27Z hristov $ */
17
18////////////////////////////////////////////////////////////////////////////
19// //
20// Tracking in one chamber //
21// //
22// Authors: //
23// Alex Bercuci <A.Bercuci@gsi.de> //
24// Markus Fasel <M.Fasel@gsi.de> //
25// //
26////////////////////////////////////////////////////////////////////////////
27
28#include "AliTRDtrackingChamber.h"
29
30#include "TMath.h"
31#include "TMatrixTBase.h"
32#include <TTreeStream.h>
33
34#include "AliTRDReconstructor.h"
35#include "AliTRDrecoParam.h"
36#include "AliTRDtrackerV1.h"
37#include "AliTRDgeometry.h"
38#include "AliTRDpadPlane.h"
39#include "AliTRDcalibDB.h"
c79857d5 40#include "AliTRDCommonParam.h"
b0a48c4d 41#include "Cal/AliTRDCalDet.h"
42#include "Cal/AliTRDCalROC.h"
43
44ClassImp(AliTRDtrackingChamber)
45
46//_______________________________________________________
349f5eeb 47AliTRDtrackingChamber::AliTRDtrackingChamber()
a8276d32 48 :TObject()
349f5eeb 49 ,fDetector(-1)
b0a48c4d 50 ,fX0(0.)
5eb768d6 51 // ,fExB(0.)
52 // ,fVD(0.)
4eb02ab1 53 // ,fT0(0.)
5eb768d6 54 // ,fS2PRF(0.)
55 // ,fDiffL(0.)
56 // ,fDiffT(0.)
b0a48c4d 57{}
58
59//_______________________________________________________
60void AliTRDtrackingChamber::Clear(const Option_t *opt)
61{
fac58f00 62 for(Int_t itb=0; itb<AliTRDseedV1::kNtb; itb++) fTB[itb].Clear(opt);
b0a48c4d 63}
64
65//_______________________________________________________
5eb768d6 66Bool_t AliTRDtrackingChamber::Build(AliTRDgeometry *const geo, Bool_t hlt)
b0a48c4d 67{
68// Init chamber and all time bins (AliTRDchamberTimeBin)
69// Calculates radial position of the chamber based on
70// radial positions of the time bins (calibration/alignment aware)
71//
349f5eeb 72 if(fDetector < 0 || fDetector >= AliTRDgeometry::kNdet){
73 AliWarning(Form("Detector index not set correctly to %d", fDetector));
74 return kFALSE;
75 }
76
c79857d5 77 Int_t stack = AliTRDgeometry::GetStack(fDetector);
78 Int_t layer = AliTRDgeometry::GetLayer(fDetector);
b0a48c4d 79 AliTRDpadPlane *pp = geo->GetPadPlane(layer, stack);
80 Double_t zl = pp->GetRow0ROC() - pp->GetRowEndROC();
81 Double_t z0 = geo->GetRow0(layer, stack, 0) - zl;
82 Int_t nrows = pp->GetNrows();
83
84 Int_t index[50], jtb = 0;
fac58f00 85 for(Int_t itb=0; itb<AliTRDseedV1::kNtb; itb++){
b0a48c4d 86 if(!fTB[itb]) continue;
87 fTB[itb].SetRange(z0, zl);
88 fTB[itb].SetNRows(nrows);
89 fTB[itb].BuildIndices();
90 index[jtb++] = itb;
91 }
92 if(jtb<2) return kFALSE;
5eb768d6 93
94 AliTRDcalibDB *calib = AliTRDcalibDB::Instance();
4eb02ab1 95 Float_t t0;
5eb768d6 96 if(!hlt){
4eb02ab1 97 t0 = calib->GetT0Average(fDetector);
5eb768d6 98 }else{
4eb02ab1 99 t0 = calib->GetT0Det()->GetValue(fDetector);
5eb768d6 100 }
101 // fVD = calib->GetVdriftAverage(fDetector);
102 // fS2PRF = calib->GetPRFROC(fDetector)->GetMean(); fS2PRF *= fS2PRF;
103 // fExB = AliTRDCommonParam::Instance()->GetOmegaTau(fVD);
104 // AliTRDCommonParam::Instance()->GetDiffCoeff(fDiffL, fDiffT, fVD);
105
b0a48c4d 106 // ESTIMATE POSITION OF PAD PLANE FOR THIS CHAMBER
4eb02ab1 107 fTB[Int_t(t0)].SetT0();
b0a48c4d 108 Double_t x0 = fTB[index[0]].GetX();
109 Double_t x1 = fTB[index[1]].GetX();
110 Double_t dx = (x0 - x1)/(index[1] - index[0]);
b0a48c4d 111 fX0 = x0 + dx*(index[0] - t0);
112 return kTRUE;
113}
c79857d5 114
b0a48c4d 115//_______________________________________________________
116Int_t AliTRDtrackingChamber::GetNClusters() const
117{
ac1dec3b 118// Basic loop method
b0a48c4d 119// Returns number of clusters in chamber
120//
121 Int_t n = 0;
fac58f00 122 for(Int_t itb=0; itb<AliTRDseedV1::kNtb; itb++){
b0a48c4d 123 n += Int_t(fTB[itb]);
124 }
125 return n;
126}
127
128//_______________________________________________________
ac1dec3b 129void AliTRDtrackingChamber::Bootstrap(const AliTRDReconstructor *rec)
130{
131// Basic loop method
132// Bootstrap each time bin
133//
134 AliTRDchamberTimeBin *jtb = &fTB[0];
fac58f00 135 for(Int_t itb=0; itb<AliTRDseedV1::kNtb; itb++, ++jtb){
ac1dec3b 136 (*jtb).Bootstrap(rec, fDetector);
137 }
138}
139
140//_______________________________________________________
141void AliTRDtrackingChamber::SetOwner()
142{
143// Basic loop method
144// Set ownership in time bins
145//
146 AliTRDchamberTimeBin *jtb = &fTB[0];
fac58f00 147 for(Int_t itb=0; itb<AliTRDseedV1::kNtb; itb++, ++jtb){
ac1dec3b 148 if(!(Int_t(*jtb))) continue;
149 (*jtb).SetOwner();
150 }
151}
152
153//_______________________________________________________
b0a48c4d 154Double_t AliTRDtrackingChamber::GetQuality()
155{
156 //
157 // Calculate chamber quality for seeding.
158 //
159 //
160 // Parameters :
161 // layers : Array of propagation layers for this plane.
162 //
163 // Output :
164 // plane quality factor for seeding
165 //
166 // Detailed description
167 //
168 // The quality of the plane for seeding is higher if:
169 // 1. the average timebin population is closer to an integer number
170 // 2. the distribution of clusters/timebin is closer to a uniform distribution.
171 // - the slope of the first derivative of a parabolic fit is small or
172 // - the slope of a linear fit is small
173 //
174
175 Int_t ncl = 0;
176 Int_t nused = 0;
177 Int_t nClLayer;
fac58f00 178 for(int itb=0; itb<AliTRDseedV1::kNtb; itb++){
b0a48c4d 179 if(!(nClLayer = fTB[itb].GetNClusters())) continue;
180 ncl += nClLayer;
181 for(Int_t incl = 0; incl < nClLayer; incl++){
182 if((fTB[itb].GetCluster(incl))->IsUsed()) nused++;
183 }
184 }
185
186 // calculate the deviation of the mean number of clusters from the
187 // closest integer values
188 Float_t nclMed = float(ncl-nused)/AliTRDtrackerV1::GetNTimeBins();
189 Int_t ncli = Int_t(nclMed);
190 Float_t nclDev = TMath::Abs(nclMed - TMath::Max(ncli, 1));
191 nclDev -= (nclDev>.5) && ncli ? 1. : 0.;
192 return TMath::Exp(-5.*TMath::Abs(nclDev));
193
194// // get slope of the derivative
195// if(!fitter.Eval()) return quality;
196// fitter.PrintResults(3);
197// Double_t a = fitter.GetParameter(1);
198//
199// printf("ncl_dev(%f) a(%f)\n", ncl_dev, a);
200// return quality*TMath::Exp(-a);
201
202}
203
204
205//_______________________________________________________
4d6aee34 206Bool_t AliTRDtrackingChamber::GetSeedingLayer(AliTRDchamberTimeBin *&fakeLayer, AliTRDgeometry * const geo, const AliTRDReconstructor *rec)
b0a48c4d 207{
208 //
209 // Creates a seeding layer
210 //
211
212 // constants
213 const Int_t kMaxRows = 16;
214 const Int_t kMaxCols = 144;
215 const Int_t kMaxPads = 2304;
216 Int_t timeBinMin = rec->GetRecoParam()->GetNumberOfPresamples();
217 Int_t timeBinMax = rec->GetRecoParam()->GetNumberOfPostsamples();
218
219 // Get the geometrical data of the chamber
220 Int_t layer = geo->GetLayer(fDetector);
221 Int_t stack = geo->GetStack(fDetector);
222 Int_t sector= geo->GetSector(fDetector);
223 AliTRDpadPlane *pp = geo->GetPadPlane(layer, stack);
224 Int_t nCols = pp->GetNcols();
225 Float_t ymin = TMath::Min(pp->GetCol0(), pp->GetColEnd());
226 Float_t ymax = TMath::Max(pp->GetCol0(), pp->GetColEnd());
227 Float_t zmin = TMath::Min(pp->GetRow0(), pp->GetRowEnd());
228 Float_t zmax = TMath::Max(pp->GetRow0(), pp->GetRowEnd());
229 Float_t z0 = -1., zl = -1.;
230 Int_t nRows = pp->GetNrows();
231 Float_t binlength = (ymax - ymin)/nCols;
232 //AliInfo(Form("ymin(%f) ymax(%f) zmin(%f) zmax(%f) nRows(%d) binlength(%f)", ymin, ymax, zmin, zmax, nRows, binlength));
233
234 // Fill the histogram
235 Int_t nClusters;
236 Int_t *histogram[kMaxRows]; // 2D-Histogram
237 Int_t hvals[kMaxPads + 1]; memset(hvals, 0, sizeof(Int_t)*kMaxPads); // one entry in addition for termination flag
238 Float_t *sigmas[kMaxRows];
239 Float_t svals[kMaxPads]; memset(svals, 0, sizeof(Float_t)*kMaxPads);
4d6aee34 240 AliTRDcluster *c = NULL;
b0a48c4d 241 for(Int_t irs = 0; irs < kMaxRows; irs++){
242 histogram[irs] = &hvals[irs*kMaxCols];
243 sigmas[irs] = &svals[irs*kMaxCols];
244 }
fac58f00 245 for(Int_t iTime = timeBinMin; iTime < AliTRDseedV1::kNtb-timeBinMax; iTime++){
b0a48c4d 246 if(!(nClusters = fTB[iTime].GetNClusters())) continue;
247 z0 = fTB[iTime].GetZ0();
248 zl = fTB[iTime].GetDZ0();
249 for(Int_t incl = 0; incl < nClusters; incl++){
250 c = fTB[iTime].GetCluster(incl);
251 histogram[c->GetPadRow()][c->GetPadCol()]++;
252 sigmas[c->GetPadRow()][c->GetPadCol()] += c->GetSigmaZ2();
253 }
254 }
255
256// Now I have everything in the histogram, do the selection
257 //Int_t nPads = nCols * nRows;
258 // This is what we are interested in: The center of gravity of the best candidates
259 Float_t cogyvals[kMaxPads]; memset(cogyvals, 0, sizeof(Float_t)*kMaxPads);
260 Float_t cogzvals[kMaxPads]; memset(cogzvals, 0, sizeof(Float_t)*kMaxPads);
261 Float_t *cogy[kMaxRows];
262 Float_t *cogz[kMaxRows];
263
264 // Lookup-Table storing coordinates according to the bins
41f024fb 265 Float_t yLengths[kMaxCols]; memset(yLengths, 0, kMaxCols*sizeof(Float_t));
266 Float_t zLengths[kMaxRows]; memset(zLengths, 0, kMaxRows*sizeof(Float_t));
b0a48c4d 267 for(Int_t icnt = 0; icnt < nCols; icnt++){
268 yLengths[icnt] = pp->GetColPos(nCols - 1 - icnt) + binlength/2;
269 }
270 for(Int_t icnt = 0; icnt < nRows; icnt++){
271 zLengths[icnt] = pp->GetRowPos(icnt) - pp->GetRowSize(icnt)/2;
272 }
273
274 // A bitfield is used to mask the pads as usable
275 Short_t mask[kMaxCols]; memset(mask, 0 ,sizeof(Short_t) * kMaxCols);//bool mvals[kMaxPads];
276 for(UChar_t icount = 0; icount < nRows; icount++){
277 cogy[icount] = &cogyvals[icount*kMaxCols];
278 cogz[icount] = &cogzvals[icount*kMaxCols];
279 }
280 // In this array the array position of the best candidates will be stored
281 Int_t cand[AliTRDtrackerV1::kMaxTracksStack];
282 Float_t sigcands[AliTRDtrackerV1::kMaxTracksStack];
283
284 // helper variables
285 Int_t indices[kMaxPads]; memset(indices, -1, sizeof(Int_t)*kMaxPads);
286 Int_t nCandidates = 0;
287 Float_t norm, cogv;
288 // histogram filled -> Select best bins
289 Int_t nPads = nCols * nRows;
290 // take out all the bins which have less than 3 entries (faster sorting)
291 Int_t content[kMaxPads], dictionary[kMaxPads], nCont = 0, padnumber = 0;
292 Int_t *iter = &hvals[0], *citer = &content[0], *diter = &dictionary[0]; // iterators for preselection
293 const Int_t threshold = 2;
294 hvals[nPads] = -1; // termination for iterator
295 do{
296 if(*iter > threshold){
297 *(citer++) = *iter;
298 *(diter++) = padnumber;
299 nCont++;
300 }
301 padnumber++;
302 }while(*(++iter) != -1);
303 TMath::Sort(nCont, content, indices);
304
305 Int_t col, row, lower, lower1, upper, upper1;
306 for(Int_t ib = 0; ib < nCont; ib++){
307 if(nCandidates >= AliTRDtrackerV1::kMaxTracksStack){
0e0d327b 308 AliDebug(1, Form("Number of seed candidates %d exceeded maximum allowed per stack %d", nCandidates, AliTRDtrackerV1::kMaxTracksStack));
b0a48c4d 309 break;
310 }
311 // Positions
312 row = dictionary[indices[ib]]/nCols;
313 col = dictionary[indices[ib]]%nCols;
314 // here will be the threshold condition:
315 if((mask[col] & (1 << row)) != 0) continue; // Pad is masked: continue
316 // if(histogram[row][col] < TMath::Max(threshold, 1)){ // of course at least one cluster is needed
317 // break; // number of clusters below threshold: break;
318 // }
319 // passing: Mark the neighbors
320 lower = TMath::Max(col - 1, 0); upper = TMath::Min(col + 2, nCols);
321 lower1 = TMath::Max(row - 1, 0); upper1 = TMath::Min(row + 2, nCols);
322 for(Int_t ic = lower; ic < upper; ++ic)
323 for(Int_t ir = lower1; ir < upper1; ++ir){
324 if(ic == col && ir == row) continue;
325 mask[ic] |= (1 << ir);
326 }
327 // Storing the position in an array
328 // testing for neigboring
329 cogv = 0;
330 norm = 0;
331 lower = TMath::Max(col - 1, 0);
332 upper = TMath::Min(col + 2, nCols);
333 for(Int_t inb = lower; inb < upper; ++inb){
334 cogv += yLengths[inb] * histogram[row][inb];
335 norm += histogram[row][inb];
336 }
337 cogy[row][col] = cogv / norm;
338 cogv = 0; norm = 0;
339 lower = TMath::Max(row - 1, 0);
340 upper = TMath::Min(row + 2, nRows);
341 for(Int_t inb = lower; inb < upper; ++inb){
342 cogv += zLengths[inb] * histogram[inb][col];
343 norm += histogram[inb][col];
344 }
345 cogz[row][col] = Float_t(cogv) / norm;
346 // passed the filter
347 cand[nCandidates] = row*nCols + col; // store the position of a passig candidate into an Array
348 sigcands[nCandidates] = sigmas[row][col] / histogram[row][col]; // never be a floating point exeption
349 // Analysis output
350 nCandidates++;
351 }
352 if(!nCandidates) return kFALSE;
353
354 Float_t pos[3], sig[2];
355 Short_t signal[7]; memset(&signal[0], 0, 7*sizeof(Short_t));
356
357 new(fakeLayer) AliTRDchamberTimeBin(layer, stack, sector, z0, zl);
358 fakeLayer->SetReconstructor(rec);
ac1dec3b 359 fakeLayer->SetNRows(nRows);
360 fakeLayer->SetOwner(kFALSE);
b0a48c4d 361 if(nCandidates){
362 UInt_t fakeIndex = 0;
363 for(Int_t ican = 0; ican < nCandidates; ican++){
364 row = cand[ican] / nCols;
365 col = cand[ican] % nCols;
366 //temporary
367 Int_t n = 0; Double_t x = 0., y = 0., z = 0.;
fac58f00 368 for(int itb=0; itb<AliTRDseedV1::kNtb; itb++){
b0a48c4d 369 if(!(nClusters = fTB[itb].GetNClusters())) continue;
370 for(Int_t incl = 0; incl < nClusters; incl++){
371 c = fTB[itb].GetCluster(incl);
372 if(c->GetPadRow() != row) continue;
373 if(TMath::Abs(c->GetPadCol() - col) > 2) continue;
374 x += c->GetX();
375 y += c->GetY();
376 z += c->GetZ();
377 n++;
378 }
379 }
380 pos[0] = x/n;
381 pos[1] = y/n;
382 pos[2] = z/n;
383 sig[0] = .02;
384 sig[1] = sigcands[ican];
4d6aee34 385 fakeLayer->InsertCluster(new AliTRDcluster(fDetector, 0., pos, sig, NULL, 3, signal, col, row, 0, 0, 0., 0), fakeIndex++);
b0a48c4d 386 }
387 }
b0a48c4d 388 fakeLayer->BuildIndices();
ac1dec3b 389 //fakeLayer->Print();
b0a48c4d 390
a2fbb6ec 391 if(rec->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >= 3){
b0a48c4d 392 //TMatrixD hist(nRows, nCols);
393 //for(Int_t i = 0; i < nRows; i++)
394 // for(Int_t j = 0; j < nCols; j++)
395 // hist(i,j) = histogram[i][j];
a2fbb6ec 396 TTreeSRedirector &cstreamer = *rec->GetDebugStream(AliTRDrecoParam::kTracker);
b0a48c4d 397 cstreamer << "GetSeedingLayer"
398 << "layer=" << layer
399 << "ymin=" << ymin
400 << "ymax=" << ymax
401 << "zmin=" << zmin
402 << "zmax=" << zmax
403 << "L.=" << fakeLayer
404 //<< "Histogram.=" << &hist
405 << "\n";
406 }
407
408 return kTRUE;
409}
410
6c207d50 411
412//_______________________________________________________
413void AliTRDtrackingChamber::Print(Option_t *opt) const
414{
4d6aee34 415 // Print the chamber status
6c207d50 416 if(!GetNClusters()) return;
417 AliInfo(Form("fDetector = %d", fDetector));
418 AliInfo(Form("fX0 = %7.3f", fX0));
419 const AliTRDchamberTimeBin *itb = &fTB[0];
fac58f00 420 for(Int_t jtb=0; jtb<AliTRDseedV1::kNtb; jtb++, itb++) (*itb).Print(opt);
6c207d50 421}
fac58f00 422
423
424//_______________________________________________________
425void AliTRDtrackingChamber::Update()
426{
427// Steer purging of used and shared clusters
428
429 AliTRDchamberTimeBin *jtb = &fTB[0];
430 for(Int_t itb=AliTRDseedV1::kNtb; itb--; ++jtb){
431 if(!(Int_t(*jtb))) continue;
432 (*jtb).BuildIndices();
433 }
434}
435