]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDseedV1.cxx
Update of the class ESDMuonFilter. New marcros for creating AOD with muon information...
[u/mrichter/AliRoot.git] / TRD / AliTRDseedV1.cxx
CommitLineData
e4f2f73d 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$ */
17
18////////////////////////////////////////////////////////////////////////////
19// //
20// The TRD track seed //
21// //
22// Authors: //
23// Alex Bercuci <A.Bercuci@gsi.de> //
24// Markus Fasel <M.Fasel@gsi.de> //
25// //
26////////////////////////////////////////////////////////////////////////////
27
28#include "TMath.h"
29#include "TLinearFitter.h"
eb38ed55 30#include "TClonesArray.h" // tmp
31#include <TTreeStream.h>
e4f2f73d 32
33#include "AliLog.h"
34#include "AliMathBase.h"
35
36#include "AliTRDseedV1.h"
37#include "AliTRDcluster.h"
0906e73e 38#include "AliTRDtrack.h"
e4f2f73d 39#include "AliTRDcalibDB.h"
eb38ed55 40#include "AliTRDchamberTimeBin.h"
41#include "AliTRDtrackingChamber.h"
42#include "AliTRDtrackerV1.h"
43#include "AliTRDReconstructor.h"
e4f2f73d 44#include "AliTRDrecoParam.h"
0906e73e 45#include "AliTRDgeometry.h"
46#include "Cal/AliTRDCalPID.h"
e4f2f73d 47
e4f2f73d 48ClassImp(AliTRDseedV1)
49
50//____________________________________________________________________
eb38ed55 51AliTRDseedV1::AliTRDseedV1(Int_t plane)
e4f2f73d 52 :AliTRDseed()
eb38ed55 53 ,fPlane(plane)
0906e73e 54 ,fMom(0.)
bcb6fb78 55 ,fSnp(0.)
56 ,fTgl(0.)
57 ,fdX(0.)
e4f2f73d 58{
59 //
60 // Constructor
61 //
0906e73e 62 for(int islice=0; islice < knSlices; islice++) fdEdx[islice] = 0.;
0906e73e 63 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) fProb[ispec] = -1.;
e4f2f73d 64}
65
66//____________________________________________________________________
0906e73e 67AliTRDseedV1::AliTRDseedV1(const AliTRDseedV1 &ref)
e4f2f73d 68 :AliTRDseed((AliTRDseed&)ref)
0906e73e 69 ,fPlane(ref.fPlane)
0906e73e 70 ,fMom(ref.fMom)
bcb6fb78 71 ,fSnp(ref.fSnp)
72 ,fTgl(ref.fTgl)
73 ,fdX(ref.fdX)
e4f2f73d 74{
75 //
76 // Copy Constructor performing a deep copy
77 //
78
79 //AliInfo("");
0906e73e 80 for(int islice=0; islice < knSlices; islice++) fdEdx[islice] = ref.fdEdx[islice];
0906e73e 81 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) fProb[ispec] = ref.fProb[ispec];
fbb2ea06 82}
d9950a5a 83
0906e73e 84
e4f2f73d 85//____________________________________________________________________
86AliTRDseedV1& AliTRDseedV1::operator=(const AliTRDseedV1 &ref)
87{
88 //
89 // Assignment Operator using the copy function
90 //
91
92 //AliInfo("");
93 if(this != &ref){
94 ref.Copy(*this);
95 }
96 return *this;
97
98}
99
100//____________________________________________________________________
101AliTRDseedV1::~AliTRDseedV1()
102{
103 //
104 // Destructor. The RecoParam object belongs to the underlying tracker.
105 //
106
107 //AliInfo(Form("fOwner[%s]", fOwner?"YES":"NO"));
108
47d5d320 109 if(IsOwner())
0906e73e 110 for(int itb=0; itb<knTimebins; itb++){
111 if(!fClusters[itb]) continue;
112 //AliInfo(Form("deleting c %p @ %d", fClusters[itb], itb));
113 delete fClusters[itb];
114 fClusters[itb] = 0x0;
115 }
e4f2f73d 116}
117
118//____________________________________________________________________
119void AliTRDseedV1::Copy(TObject &ref) const
120{
121 //
122 // Copy function
123 //
124
125 //AliInfo("");
126 AliTRDseedV1 &target = (AliTRDseedV1 &)ref;
127
0906e73e 128 target.fPlane = fPlane;
129 target.fMom = fMom;
bcb6fb78 130 target.fSnp = fSnp;
131 target.fTgl = fTgl;
132 target.fdX = fdX;
0906e73e 133
134 for(int islice=0; islice < knSlices; islice++) target.fdEdx[islice] = fdEdx[islice];
0906e73e 135 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) target.fProb[ispec] = fProb[ispec];
136
e4f2f73d 137 AliTRDseed::Copy(target);
138}
139
0906e73e 140
141//____________________________________________________________
51863bc0 142Bool_t AliTRDseedV1::Init(AliTRDtrack *track)
0906e73e 143{
144// Initialize this tracklet using the track information
145//
146// Parameters:
147// track - the TRD track used to initialize the tracklet
148//
149// Detailed description
150// The function sets the starting point and direction of the
151// tracklet according to the information from the TRD track.
152//
153// Caution
154// The TRD track has to be propagated to the beginning of the
155// chamber where the tracklet will be constructed
156//
157
158 Double_t y, z;
51863bc0 159 if(!track->GetProlongation(fX0, y, z)) return kFALSE;
0906e73e 160 fYref[0] = y;
33f721e9 161 fYref[1] = track->GetSnp()/(1. - track->GetSnp()*track->GetSnp());
0906e73e 162 fZref[0] = z;
33f721e9 163 fZref[1] = track->GetTgl();
0906e73e 164
165 //printf("Tracklet ref x[%7.3f] y[%7.3f] z[%7.3f], snp[%f] tgl[%f]\n", fX0, fYref[0], fZref[0], track->GetSnp(), track->GetTgl());
51863bc0 166 return kTRUE;
0906e73e 167}
168
bcb6fb78 169
170//____________________________________________________________________
171void AliTRDseedV1::CookdEdx(Int_t nslices)
172{
173// Calculates average dE/dx for all slices and store them in the internal array fdEdx.
174//
175// Parameters:
176// nslices : number of slices for which dE/dx should be calculated
177// Output:
178// store results in the internal array fdEdx. This can be accessed with the method
179// AliTRDseedV1::GetdEdx()
180//
181// Detailed description
182// Calculates average dE/dx for all slices. Depending on the PID methode
183// the number of slices can be 3 (LQ) or 8(NN).
184// The calculation of dQ/dl are done using the tracklet fit results (see AliTRDseedV1::GetdQdl(Int_t)) i.e.
185//
186// dQ/dl = qc/(dx * sqrt(1 + dy/dx^2 + dz/dx^2))
187//
188// The following effects are included in the calculation:
189// 1. calibration values for t0 and vdrift (using x coordinate to calculate slice)
190// 2. cluster sharing (optional see AliTRDrecoParam::SetClusterSharing())
191// 3. cluster size
192//
193
194 Int_t nclusters[knSlices];
195 for(int i=0; i<knSlices; i++){
196 fdEdx[i] = 0.;
197 nclusters[i] = 0;
198 }
199 Float_t clength = (/*.5 * */AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());
200
201 AliTRDcluster *cluster = 0x0;
2985ffcb 202 for(int ic=0; ic<AliTRDtrackerV1::GetNTimeBins(); ic++){
bcb6fb78 203 if(!(cluster = fClusters[ic])) continue;
204 Float_t x = cluster->GetX();
205
206 // Filter clusters for dE/dx calculation
207
208 // 1.consider calibration effects for slice determination
209 Int_t slice;
210 if(cluster->IsInChamber()) slice = Int_t(TMath::Abs(fX0 - x) * nslices / clength);
211 else slice = x < fX0 ? 0 : nslices-1;
212
213 // 2. take sharing into account
214 Float_t w = cluster->IsShared() ? .5 : 1.;
215
216 // 3. take into account large clusters TODO
217 //w *= c->GetNPads() > 3 ? .8 : 1.;
218
219 //CHECK !!!
220 fdEdx[slice] += w * GetdQdl(ic); //fdQdl[ic];
221 nclusters[slice]++;
222 } // End of loop over clusters
223
b83573da 224 if(AliTRDReconstructor::RecoParam()->GetPIDMethod() == 0){
225 // calculate mean charge per slice (only LQ PID)
226 for(int is=0; is<nslices; is++){
227 if(nclusters[is]) fdEdx[is] /= nclusters[is];
228 }
229 }
bcb6fb78 230}
231
b83573da 232
bcb6fb78 233//____________________________________________________________________
234Float_t AliTRDseedV1::GetdQdl(Int_t ic) const
235{
10f75631 236 return fClusters[ic] ? TMath::Abs(fClusters[ic]->GetQ()) /fdX / TMath::Sqrt(1. + fYfit[1]*fYfit[1] + fZref[1]*fZref[1]) : 0.;
bcb6fb78 237}
238
0906e73e 239//____________________________________________________________________
240Double_t* AliTRDseedV1::GetProbability()
241{
242// Fill probability array for tracklet from the DB.
243//
244// Parameters
245//
246// Output
247// returns pointer to the probability array and 0x0 if missing DB access
248//
249// Detailed description
250
251
252 // retrive calibration db
253 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
254 if (!calibration) {
255 AliError("No access to calibration data");
256 return 0x0;
257 }
258
259 // Retrieve the CDB container class with the parametric detector response
eb38ed55 260 const AliTRDCalPID *pd = calibration->GetPIDObject(AliTRDReconstructor::RecoParam()->GetPIDMethod());
0906e73e 261 if (!pd) {
262 AliError("No access to AliTRDCalPID object");
263 return 0x0;
264 }
10f75631 265 //AliInfo(Form("Method[%d] : %s", AliTRDReconstructor::RecoParam()->GetPIDMethod(), pd->IsA()->GetName()));
266
0906e73e 267 // calculate tracklet length TO DO
268 Float_t length = (AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());
269 /// TMath::Sqrt((1.0 - fSnp[iPlane]*fSnp[iPlane]) / (1.0 + fTgl[iPlane]*fTgl[iPlane]));
270
271 //calculate dE/dx
eb38ed55 272 CookdEdx(AliTRDReconstructor::RecoParam()->GetNdEdxSlices());
0906e73e 273
274 // Sets the a priori probabilities
275 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) {
276 fProb[ispec] = pd->GetProbability(ispec, fMom, &fdEdx[0], length, fPlane);
277 }
278
279 return &fProb[0];
280}
281
e4f2f73d 282//____________________________________________________________________
283Float_t AliTRDseedV1::GetQuality(Bool_t kZcorr) const
284{
285 //
286 // Returns a quality measurement of the current seed
287 //
288
289 Float_t zcorr = kZcorr ? fTilt * (fZProb - fZref[0]) : 0.;
eb38ed55 290 return
291 .5 * TMath::Abs(18.0 - fN2)
e4f2f73d 292 + 10.* TMath::Abs(fYfit[1] - fYref[1])
eb38ed55 293 + 5. * TMath::Abs(fYfit[0] - fYref[0] + zcorr)
e4f2f73d 294 + 2. * TMath::Abs(fMeanz - fZref[0]) / fPadLength;
295}
296
0906e73e 297//____________________________________________________________________
298void AliTRDseedV1::GetCovAt(Double_t /*x*/, Double_t *cov) const
299{
300// Computes covariance in the y-z plane at radial point x
301
eb38ed55 302 Int_t ic = 0; while (!fClusters[ic]) ic++;
303 AliTRDcalibDB *fCalib = AliTRDcalibDB::Instance();
304 Double_t exB = fCalib->GetOmegaTau(fCalib->GetVdriftAverage(fClusters[ic]->GetDetector()), -AliTracker::GetBz()*0.1);
305
306 Double_t sy2 = fSigmaY2*fSigmaY2 + .2*(fYfit[1]-exB)*(fYfit[1]-exB);
0906e73e 307 Double_t sz2 = fPadLength/12.;
308
eb38ed55 309
0906e73e 310 //printf("Yfit[1] %f sy20 %f SigmaY2 %f\n", fYfit[1], sy20, fSigmaY2);
311
312 cov[0] = sy2;
313 cov[1] = fTilt*(sy2-sz2);
314 cov[2] = sz2;
315}
316
0906e73e 317
318//____________________________________________________________________
319void AliTRDseedV1::SetOwner(Bool_t own)
320{
321 //AliInfo(Form("own [%s] fOwner[%s]", own?"YES":"NO", fOwner?"YES":"NO"));
322
323 if(own){
324 for(int ic=0; ic<knTimebins; ic++){
325 if(!fClusters[ic]) continue;
326 fClusters[ic] = new AliTRDcluster(*fClusters[ic]);
327 }
47d5d320 328 SetBit(1);
0906e73e 329 } else {
47d5d320 330 if(IsOwner()){
0906e73e 331 for(int ic=0; ic<knTimebins; ic++){
332 if(!fClusters[ic]) continue;
333 delete fClusters[ic];
334 //fClusters[ic] = tracker->GetClusters(index) TODO
335 }
336 }
47d5d320 337 SetBit(1, kFALSE);
0906e73e 338 }
339}
340
e4f2f73d 341//____________________________________________________________________
eb38ed55 342Bool_t AliTRDseedV1::AttachClustersIter(AliTRDtrackingChamber *chamber, Float_t quality, Bool_t kZcorr, AliTRDcluster *c)
e4f2f73d 343{
344 //
345 // Iterative process to register clusters to the seed.
346 // In iteration 0 we try only one pad-row and if quality not
347 // sufficient we try 2 pad-rows (about 5% of tracks cross 2 pad-rows)
348 //
eb38ed55 349 // debug level 7
350 //
e4f2f73d 351
eb38ed55 352 if(!AliTRDReconstructor::RecoParam()){
e4f2f73d 353 AliError("Seed can not be used without a valid RecoParam.");
354 return kFALSE;
355 }
0906e73e 356
eb38ed55 357 AliTRDchamberTimeBin *layer = 0x0;
358 if(AliTRDReconstructor::StreamLevel()>=7 && c){
359 TClonesArray clusters("AliTRDcluster", 24);
360 clusters.SetOwner(kTRUE);
361 AliTRDcluster *cc = 0x0;
362 Int_t det=-1, ncl, ncls = 0;
2985ffcb 363 for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
eb38ed55 364 if(!(layer = chamber->GetTB(iTime))) continue;
365 if(!(ncl = Int_t(*layer))) continue;
366 for(int ic=0; ic<ncl; ic++){
367 cc = (*layer)[ic];
368 det = cc->GetDetector();
369 new(clusters[ncls++]) AliTRDcluster(*cc);
370 }
371 }
372 AliInfo(Form("N clusters[%d] = %d", fPlane, ncls));
373
374 Int_t ref = c ? 1 : 0;
375 TTreeSRedirector &cstreamer = *AliTRDtrackerV1::DebugStreamer();
376 cstreamer << "AttachClustersIter"
377 << "det=" << det
378 << "ref=" << ref
379 << "clusters.=" << &clusters
380 << "tracklet.=" << this
381 << "cl.=" << c
382 << "\n";
383 }
0906e73e 384
e4f2f73d 385 Float_t tquality;
eb38ed55 386 Double_t kroady = AliTRDReconstructor::RecoParam()->GetRoad1y();
e4f2f73d 387 Double_t kroadz = fPadLength * .5 + 1.;
388
389 // initialize configuration parameters
390 Float_t zcorr = kZcorr ? fTilt * (fZProb - fZref[0]) : 0.;
391 Int_t niter = kZcorr ? 1 : 2;
392
393 Double_t yexp, zexp;
394 Int_t ncl = 0;
395 // start seed update
396 for (Int_t iter = 0; iter < niter; iter++) {
e4f2f73d 397 ncl = 0;
2985ffcb 398 for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
eb38ed55 399 if(!(layer = chamber->GetTB(iTime))) continue;
400 if(!Int_t(*layer)) continue;
401
e4f2f73d 402 // define searching configuration
eb38ed55 403 Double_t dxlayer = layer->GetX() - fX0;
e4f2f73d 404 if(c){
405 zexp = c->GetZ();
406 //Try 2 pad-rows in second iteration
407 if (iter > 0) {
408 zexp = fZref[0] + fZref[1] * dxlayer - zcorr;
409 if (zexp > c->GetZ()) zexp = c->GetZ() + fPadLength*0.5;
410 if (zexp < c->GetZ()) zexp = c->GetZ() - fPadLength*0.5;
411 }
eb38ed55 412 } else zexp = fZref[0] + (kZcorr ? fZref[1] * dxlayer : 0.);
e4f2f73d 413 yexp = fYref[0] + fYref[1] * dxlayer - zcorr;
bcb6fb78 414
415 // Get and register cluster
eb38ed55 416 Int_t index = layer->SearchNearestCluster(yexp, zexp, kroady, kroadz);
e4f2f73d 417 if (index < 0) continue;
eb38ed55 418 AliTRDcluster *cl = (*layer)[index];
e4f2f73d 419
eb38ed55 420 fIndexes[iTime] = layer->GetGlobalIndex(index);
e4f2f73d 421 fClusters[iTime] = cl;
e4f2f73d 422 fY[iTime] = cl->GetY();
423 fZ[iTime] = cl->GetZ();
e4f2f73d 424 ncl++;
425 }
eb38ed55 426 if(AliTRDReconstructor::StreamLevel()>=7) AliInfo(Form("iter = %d ncl [%d] = %d", iter, fPlane, ncl));
bcb6fb78 427
eb38ed55 428 if(ncl>1){
bcb6fb78 429 // calculate length of the time bin (calibration aware)
430 Int_t irp = 0; Float_t x[2]; Int_t tb[2];
2985ffcb 431 for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
bcb6fb78 432 if(!fClusters[iTime]) continue;
433 x[irp] = fClusters[iTime]->GetX();
434 tb[irp] = iTime;
435 irp++;
436 if(irp==2) break;
437 }
438 fdX = (x[1] - x[0]) / (tb[0] - tb[1]);
439
440 // update X0 from the clusters (calibration/alignment aware)
2985ffcb 441 for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
eb38ed55 442 if(!(layer = chamber->GetTB(iTime))) continue;
443 if(!layer->IsT0()) continue;
bcb6fb78 444 if(fClusters[iTime]){
445 fX0 = fClusters[iTime]->GetX();
446 break;
447 } else { // we have to infere the position of the anode wire from the other clusters
2985ffcb 448 for (Int_t jTime = iTime+1; jTime < AliTRDtrackerV1::GetNTimeBins(); jTime++) {
bcb6fb78 449 if(!fClusters[jTime]) continue;
450 fX0 = fClusters[jTime]->GetX() + fdX * (jTime - iTime);
451 }
452 break;
453 }
454 }
455
456 // update YZ reference point
457 // TODO
458
459 // update x reference positions (calibration/alignment aware)
2985ffcb 460 for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
bcb6fb78 461 if(!fClusters[iTime]) continue;
462 fX[iTime] = fClusters[iTime]->GetX() - fX0;
463 }
464
465 AliTRDseed::Update();
466 }
eb38ed55 467 if(AliTRDReconstructor::StreamLevel()>=7) AliInfo(Form("iter = %d nclFit [%d] = %d", iter, fPlane, fN2));
bcb6fb78 468
e4f2f73d 469 if(IsOK()){
470 tquality = GetQuality(kZcorr);
471 if(tquality < quality) break;
472 else quality = tquality;
473 }
474 kroadz *= 2.;
475 } // Loop: iter
476 if (!IsOK()) return kFALSE;
477
478 CookLabels();
479 UpdateUsed();
480 return kTRUE;
481}
482
483//____________________________________________________________________
eb38ed55 484Bool_t AliTRDseedV1::AttachClusters(AliTRDtrackingChamber *chamber
0906e73e 485 ,Bool_t kZcorr)
e4f2f73d 486{
487 //
488 // Projective algorithm to attach clusters to seeding tracklets
489 //
490 // Parameters
491 //
492 // Output
493 //
494 // Detailed description
495 // 1. Collapse x coordinate for the full detector plane
496 // 2. truncated mean on y (r-phi) direction
497 // 3. purge clusters
498 // 4. truncated mean on z direction
499 // 5. purge clusters
500 // 6. fit tracklet
501 //
502
eb38ed55 503 if(!AliTRDReconstructor::RecoParam()){
e4f2f73d 504 AliError("Seed can not be used without a valid RecoParam.");
505 return kFALSE;
506 }
507
0906e73e 508 const Int_t kClusterCandidates = 2 * knTimebins;
e4f2f73d 509
510 //define roads
eb38ed55 511 Double_t kroady = AliTRDReconstructor::RecoParam()->GetRoad1y();
e4f2f73d 512 Double_t kroadz = fPadLength * 1.5 + 1.;
513 // correction to y for the tilting angle
514 Float_t zcorr = kZcorr ? fTilt * (fZProb - fZref[0]) : 0.;
515
516 // working variables
517 AliTRDcluster *clusters[kClusterCandidates];
0906e73e 518 Double_t cond[4], yexp[knTimebins], zexp[knTimebins],
e4f2f73d 519 yres[kClusterCandidates], zres[kClusterCandidates];
0906e73e 520 Int_t ncl, *index = 0x0, tboundary[knTimebins];
e4f2f73d 521
522 // Do cluster projection
eb38ed55 523 AliTRDchamberTimeBin *layer = 0x0;
e4f2f73d 524 Int_t nYclusters = 0; Bool_t kEXIT = kFALSE;
2985ffcb 525 for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
eb38ed55 526 if(!(layer = chamber->GetTB(iTime))) continue;
527 if(!Int_t(*layer)) continue;
528
529 fX[iTime] = layer->GetX() - fX0;
e4f2f73d 530 zexp[iTime] = fZref[0] + fZref[1] * fX[iTime];
531 yexp[iTime] = fYref[0] + fYref[1] * fX[iTime] - zcorr;
532
533 // build condition and process clusters
534 cond[0] = yexp[iTime] - kroady; cond[1] = yexp[iTime] + kroady;
535 cond[2] = zexp[iTime] - kroadz; cond[3] = zexp[iTime] + kroadz;
eb38ed55 536 layer->GetClusters(cond, index, ncl);
e4f2f73d 537 for(Int_t ic = 0; ic<ncl; ic++){
eb38ed55 538 AliTRDcluster *c = layer->GetCluster(index[ic]);
e4f2f73d 539 clusters[nYclusters] = c;
540 yres[nYclusters++] = c->GetY() - yexp[iTime];
541 if(nYclusters >= kClusterCandidates) {
542 AliWarning(Form("Cluster candidates reached limit %d. Some may be lost.", kClusterCandidates));
543 kEXIT = kTRUE;
544 break;
545 }
546 }
547 tboundary[iTime] = nYclusters;
548 if(kEXIT) break;
549 }
550
551 // Evaluate truncated mean on the y direction
552 Double_t mean, sigma;
553 AliMathBase::EvaluateUni(nYclusters, yres, mean, sigma, Int_t(nYclusters*.8)-2);
eb38ed55 554 // purge cluster candidates
e4f2f73d 555 Int_t nZclusters = 0;
556 for(Int_t ic = 0; ic<nYclusters; ic++){
557 if(yres[ic] - mean > 4. * sigma){
558 clusters[ic] = 0x0;
559 continue;
560 }
561 zres[nZclusters++] = clusters[ic]->GetZ() - zexp[clusters[ic]->GetLocalTimeBin()];
562 }
563
564 // Evaluate truncated mean on the z direction
565 AliMathBase::EvaluateUni(nZclusters, zres, mean, sigma, Int_t(nZclusters*.8)-2);
eb38ed55 566 // purge cluster candidates
e4f2f73d 567 for(Int_t ic = 0; ic<nZclusters; ic++){
568 if(zres[ic] - mean > 4. * sigma){
569 clusters[ic] = 0x0;
570 continue;
571 }
572 }
573
574
575 // Select only one cluster/TimeBin
576 Int_t lastCluster = 0;
577 fN2 = 0;
2985ffcb 578 for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
e4f2f73d 579 ncl = tboundary[iTime] - lastCluster;
580 if(!ncl) continue;
eb38ed55 581 Int_t iptr = lastCluster;
582 if(ncl > 1){
583 Float_t dold = 9999.;
e4f2f73d 584 for(int ic=lastCluster; ic<tboundary[iTime]; ic++){
585 if(!clusters[ic]) continue;
586 Float_t y = yexp[iTime] - clusters[ic]->GetY();
587 Float_t z = zexp[iTime] - clusters[ic]->GetZ();
588 Float_t d = y * y + z * z;
589 if(d > dold) continue;
590 dold = d;
591 iptr = ic;
592 }
e4f2f73d 593 }
eb38ed55 594 fIndexes[iTime] = chamber->GetTB(iTime)->GetGlobalIndex(iptr);
595 fClusters[iTime] = clusters[iptr];
596 fY[iTime] = clusters[iptr]->GetY();
597 fZ[iTime] = clusters[iptr]->GetZ();
0906e73e 598 lastCluster = tboundary[iTime];
e4f2f73d 599 fN2++;
600 }
601
602 // number of minimum numbers of clusters expected for the tracklet
2985ffcb 603 Int_t kClmin = Int_t(AliTRDReconstructor::RecoParam()->GetFindableClusters()*AliTRDtrackerV1::GetNTimeBins());
e4f2f73d 604 if (fN2 < kClmin){
605 AliWarning(Form("Not enough clusters to fit the tracklet %d [%d].", fN2, kClmin));
606 fN2 = 0;
607 return kFALSE;
608 }
0906e73e 609
610 // update used clusters
611 fNUsed = 0;
2985ffcb 612 for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
0906e73e 613 if(!fClusters[iTime]) continue;
614 if((fClusters[iTime]->IsUsed())) fNUsed++;
615 }
616
617 if (fN2-fNUsed < kClmin){
618 AliWarning(Form("Too many clusters already in use %d (from %d).", fNUsed, fN2));
619 fN2 = 0;
620 return kFALSE;
621 }
e4f2f73d 622
e4f2f73d 623 return kTRUE;
624}
625
626//____________________________________________________________________
0906e73e 627Bool_t AliTRDseedV1::Fit()
e4f2f73d 628{
629 //
630 // Linear fit of the tracklet
631 //
632 // Parameters :
633 //
634 // Output :
635 // True if successful
636 //
637 // Detailed description
638 // 2. Check if tracklet crosses pad row boundary
639 // 1. Calculate residuals in the y (r-phi) direction
640 // 3. Do a Least Square Fit to the data
641 //
642
47d5d320 643 const Int_t kClmin = 8;
644 const Int_t kNtb = AliTRDtrackerV1::GetNTimeBins();
8acca6a3 645 AliTRDtrackerV1::AliTRDLeastSquare fitterY, fitterZ;
47d5d320 646
647 // convertion factor from square to gauss distribution for sigma
648 Double_t convert = 1./TMath::Sqrt(12.);
649
650 // book cluster information
8acca6a3 651 Double_t xc[knTimebins+1], yc[knTimebins], zc[knTimebins+1], sy[knTimebins], sz[knTimebins+1];
47d5d320 652 Int_t zRow[knTimebins];
653 AliTRDcluster *c = 0x0;
654 Int_t nc = 0;
655 for (Int_t ic=0; ic<kNtb; ic++) {
656 zRow[ic] = -1;
657 xc[ic] = -1.;
658 yc[ic] = 999.;
659 zc[ic] = 999.;
660 sy[ic] = 0.;
661 sz[ic] = 0.;
662 if(!(c = fClusters[ic])) continue;
663 if(!c->IsInChamber()) continue;
664 Float_t w = 1.;
665 if(c->GetNPads()>4) w = .5;
666 if(c->GetNPads()>5) w = .2;
667 zRow[nc] = c->GetPadRow();
668 xc[nc] = fX0 - c->GetX();
669 yc[nc] = c->GetY();
670 zc[nc] = c->GetZ();
671 sy[ic] = w; // all clusters have the same sigma
672 sz[ic] = fPadLength*convert;
8acca6a3 673 fitterZ.AddPoint(&xc[ic], zc[ic], sz[ic]);
47d5d320 674 nc++;
675 }
676 // to few clusters
677 if (nc < kClmin) return kFALSE;
678
e4f2f73d 679
47d5d320 680 Int_t zN[2*35];
681 Int_t nz = AliTRDtrackerV1::Freq(nc, zRow, zN, kFALSE);
682 // more than one pad row crossing
683 if(nz>2) return kFALSE;
e4f2f73d 684
47d5d320 685 // estimate reference parameter at average x
686 Double_t y0 = fYref[0];
687 Double_t dydx = fYref[1];
688 Double_t dzdx = fZref[1];
689 zc[nc] = fZref[0];
690
691 // determine z offset of the fit
692 Int_t nchanges = 0, nCross = 0;
693 if(nz==2){ // tracklet is crossing pad row
694 // Find the break time allowing one chage on pad-rows
695 // with maximal number of accepted clusters
696 Int_t padRef = zRow[0];
697 for (Int_t ic=1; ic<nc; ic++) {
698 if(zRow[ic] == padRef) continue;
699
700 // debug
701 if(zRow[ic-1] == zRow[ic]){
702 printf("ERROR in pad row change!!!\n");
703 }
704
705 // evaluate parameters of the crossing point
706 Float_t sx = (xc[ic-1] - xc[ic])*convert;
707 xc[nc] = .5 * (xc[ic-1] + xc[ic]);
708 zc[nc] = .5 * (zc[ic-1] + zc[ic]);
709 sz[nc] = TMath::Max(dzdx * sx, .01);
710 dzdx = zc[ic-1] > zc[ic] ? 1. : -1.;
711 padRef = zRow[ic];
712 nCross = ic;
713 nchanges++;
714 }
e4f2f73d 715 }
716
47d5d320 717 // condition on nCross and reset nchanges TODO
718
47d5d320 719 if(nchanges==1){
720 if(dzdx * fZref[1] < 0.){
721 AliInfo("tracklet direction does not correspond to the track direction. TODO.");
722 }
723 SetBit(2, kTRUE); // mark pad row crossing
724 fCross[0] = xc[nc]; fCross[2] = zc[nc]; fCross[3] = sz[nc];
8acca6a3 725 fitterZ.AddPoint(&xc[nc], zc[nc], sz[nc]);
726 fitterZ.Eval();
727 dzdx = fZref[1]; // we don't trust Parameter[1] ??;
728 zc[nc] = fitterZ.GetFunctionParameter(0);
47d5d320 729 } else if(nchanges > 1){ // debug
730 AliInfo("ERROR in n changes!!!");
e4f2f73d 731 return kFALSE;
732 }
47d5d320 733
734
735 // estimate deviation from reference direction
736 dzdx *= fTilt;
737 for (Int_t ic=0; ic<nc; ic++) {
738 yc[ic] -= y0 + xc[ic]*(dydx + dzdx) + fTilt * (zc[ic] - zc[nc]);
8acca6a3 739 fitterY.AddPoint(&xc[ic], yc[ic], sy[ic]);
e4f2f73d 740 }
8acca6a3 741 fitterY.Eval();
742 fYfit[0] = y0+fitterY.GetFunctionParameter(0);
743 fYfit[1] = dydx+fitterY.GetFunctionParameter(1);
47d5d320 744 if(nchanges) fCross[1] = fYfit[0] + fCross[0] * fYfit[1];
e4f2f73d 745
47d5d320 746// printf("\nnz = %d\n", nz);
747// for(int ic=0; ic<35; ic++) printf("%d row[%d]\n", ic, zRow[ic]);
748//
749// for(int ic=0; ic<nz; ic++) printf("%d n[%d]\n", ic, zN[ic]);
e4f2f73d 750
751 return kTRUE;
752}
753
47d5d320 754//___________________________________________________________________
755void AliTRDseedV1::Draw(Option_t*)
756{
757}
e4f2f73d 758
759//___________________________________________________________________
47d5d320 760void AliTRDseedV1::Print(Option_t*) const
e4f2f73d 761{
762 //
763 // Printing the seedstatus
764 //
765
e4f2f73d 766 printf("Seed status :\n");
767 printf(" fTilt = %f\n", fTilt);
768 printf(" fPadLength = %f\n", fPadLength);
769 printf(" fX0 = %f\n", fX0);
2985ffcb 770 for(int ic=0; ic<AliTRDtrackerV1::GetNTimeBins(); ic++) {
e4f2f73d 771 const Char_t *isUsable = fUsable[ic]?"Yes":"No";
0906e73e 772 printf(" %d X[%f] Y[%f] Z[%f] Indexes[%d] clusters[%p] usable[%s]\n"
e4f2f73d 773 , ic
774 , fX[ic]
775 , fY[ic]
776 , fZ[ic]
777 , fIndexes[ic]
0906e73e 778 , ((void*) fClusters[ic])
e4f2f73d 779 , isUsable);
780 }
781
782 printf(" fYref[0] =%f fYref[1] =%f\n", fYref[0], fYref[1]);
783 printf(" fZref[0] =%f fZref[1] =%f\n", fZref[0], fZref[1]);
784 printf(" fYfit[0] =%f fYfit[1] =%f\n", fYfit[0], fYfit[1]);
785 printf(" fYfitR[0]=%f fYfitR[1]=%f\n", fYfitR[0], fYfitR[1]);
786 printf(" fZfit[0] =%f fZfit[1] =%f\n", fZfit[0], fZfit[1]);
787 printf(" fZfitR[0]=%f fZfitR[1]=%f\n", fZfitR[0], fZfitR[1]);
788 printf(" fSigmaY =%f\n", fSigmaY);
789 printf(" fSigmaY2=%f\n", fSigmaY2);
790 printf(" fMeanz =%f\n", fMeanz);
791 printf(" fZProb =%f\n", fZProb);
792 printf(" fLabels[0]=%d fLabels[1]=%d\n", fLabels[0], fLabels[1]);
793 printf(" fN =%d\n", fN);
794 printf(" fN2 =%d (>8 isOK)\n",fN2);
795 printf(" fNUsed =%d\n", fNUsed);
796 printf(" fFreq =%d\n", fFreq);
797 printf(" fNChange=%d\n", fNChange);
798 printf(" fMPads =%f\n", fMPads);
799
800 printf(" fC =%f\n", fC);
801 printf(" fCC =%f\n",fCC);
802 printf(" fChi2 =%f\n", fChi2);
803 printf(" fChi2Z =%f\n", fChi2Z);
e4f2f73d 804}
47d5d320 805