]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDseedV1.cxx
misc small mods
[u/mrichter/AliRoot.git] / TRD / AliTRDseedV1.cxx
CommitLineData
e4f2f73d 1/**************************************************************************
29b87567 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**************************************************************************/
e4f2f73d 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
03cef9b2 36#include "AliTRDpadPlane.h"
e4f2f73d 37#include "AliTRDcluster.h"
f3d3af1b 38#include "AliTRDseedV1.h"
39#include "AliTRDtrackV1.h"
e4f2f73d 40#include "AliTRDcalibDB.h"
eb38ed55 41#include "AliTRDchamberTimeBin.h"
42#include "AliTRDtrackingChamber.h"
43#include "AliTRDtrackerV1.h"
44#include "AliTRDReconstructor.h"
e4f2f73d 45#include "AliTRDrecoParam.h"
0906e73e 46#include "Cal/AliTRDCalPID.h"
e4f2f73d 47
e4f2f73d 48ClassImp(AliTRDseedV1)
49
50//____________________________________________________________________
ae4e8b84 51AliTRDseedV1::AliTRDseedV1(Int_t det)
e4f2f73d 52 :AliTRDseed()
3a039a31 53 ,fReconstructor(0x0)
ae4e8b84 54 ,fClusterIter(0x0)
55 ,fClusterIdx(0)
56 ,fDet(det)
0906e73e 57 ,fMom(0.)
bcb6fb78 58 ,fSnp(0.)
59 ,fTgl(0.)
60 ,fdX(0.)
6e4d4425 61 ,fXref(0.)
e4f2f73d 62{
63 //
64 // Constructor
65 //
29b87567 66 //printf("AliTRDseedV1::AliTRDseedV1()\n");
e44586fb 67
29b87567 68 for(int islice=0; islice < knSlices; islice++) fdEdx[islice] = 0.;
69 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) fProb[ispec] = -1.;
6e4d4425 70 fRefCov[0] = 1.; fRefCov[1] = 0.; fRefCov[2] = 1.;
e4f2f73d 71}
72
73//____________________________________________________________________
0906e73e 74AliTRDseedV1::AliTRDseedV1(const AliTRDseedV1 &ref)
e4f2f73d 75 :AliTRDseed((AliTRDseed&)ref)
43d6ad34 76 ,fReconstructor(ref.fReconstructor)
ae4e8b84 77 ,fClusterIter(0x0)
78 ,fClusterIdx(0)
79 ,fDet(ref.fDet)
0906e73e 80 ,fMom(ref.fMom)
bcb6fb78 81 ,fSnp(ref.fSnp)
82 ,fTgl(ref.fTgl)
83 ,fdX(ref.fdX)
6e4d4425 84 ,fXref(ref.fXref)
e4f2f73d 85{
86 //
87 // Copy Constructor performing a deep copy
88 //
89
29b87567 90 //printf("AliTRDseedV1::AliTRDseedV1(const AliTRDseedV1 &)\n");
91 SetBit(kOwner, kFALSE);
92 for(int islice=0; islice < knSlices; islice++) fdEdx[islice] = ref.fdEdx[islice];
93 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) fProb[ispec] = ref.fProb[ispec];
6e4d4425 94 memcpy(fRefCov, ref.fRefCov, 3*sizeof(Double_t));
fbb2ea06 95}
d9950a5a 96
0906e73e 97
e4f2f73d 98//____________________________________________________________________
99AliTRDseedV1& AliTRDseedV1::operator=(const AliTRDseedV1 &ref)
100{
101 //
102 // Assignment Operator using the copy function
103 //
104
29b87567 105 if(this != &ref){
106 ref.Copy(*this);
107 }
221ab7e0 108 SetBit(kOwner, kFALSE);
109
29b87567 110 return *this;
e4f2f73d 111
112}
113
114//____________________________________________________________________
115AliTRDseedV1::~AliTRDseedV1()
116{
117 //
118 // Destructor. The RecoParam object belongs to the underlying tracker.
119 //
120
29b87567 121 //printf("I-AliTRDseedV1::~AliTRDseedV1() : Owner[%s]\n", IsOwner()?"YES":"NO");
e4f2f73d 122
29b87567 123 if(IsOwner())
124 for(int itb=0; itb<knTimebins; itb++){
125 if(!fClusters[itb]) continue;
126 //AliInfo(Form("deleting c %p @ %d", fClusters[itb], itb));
127 delete fClusters[itb];
128 fClusters[itb] = 0x0;
129 }
e4f2f73d 130}
131
132//____________________________________________________________________
133void AliTRDseedV1::Copy(TObject &ref) const
134{
135 //
136 // Copy function
137 //
138
29b87567 139 //AliInfo("");
140 AliTRDseedV1 &target = (AliTRDseedV1 &)ref;
141
ae4e8b84 142 target.fClusterIter = 0x0;
143 target.fClusterIdx = 0;
144 target.fDet = fDet;
29b87567 145 target.fMom = fMom;
146 target.fSnp = fSnp;
147 target.fTgl = fTgl;
148 target.fdX = fdX;
6e4d4425 149 target.fXref = fXref;
29b87567 150 target.fReconstructor = fReconstructor;
151
152 for(int islice=0; islice < knSlices; islice++) target.fdEdx[islice] = fdEdx[islice];
153 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) target.fProb[ispec] = fProb[ispec];
6e4d4425 154 memcpy(target.fRefCov, fRefCov, 3*sizeof(Double_t));
29b87567 155
156 AliTRDseed::Copy(target);
e4f2f73d 157}
158
0906e73e 159
160//____________________________________________________________
f3d3af1b 161Bool_t AliTRDseedV1::Init(AliTRDtrackV1 *track)
0906e73e 162{
163// Initialize this tracklet using the track information
164//
165// Parameters:
166// track - the TRD track used to initialize the tracklet
167//
168// Detailed description
169// The function sets the starting point and direction of the
170// tracklet according to the information from the TRD track.
171//
172// Caution
173// The TRD track has to be propagated to the beginning of the
174// chamber where the tracklet will be constructed
175//
176
29b87567 177 Double_t y, z;
178 if(!track->GetProlongation(fX0, y, z)) return kFALSE;
179 fYref[0] = y;
180 fYref[1] = track->GetSnp()/(1. - track->GetSnp()*track->GetSnp());
181 fZref[0] = z;
182 fZref[1] = track->GetTgl();
6e4d4425 183
184 const Double_t *cov = track->GetCovariance();
185 fRefCov[0] = cov[0]; // Var(y)
186 fRefCov[1] = cov[1]; // Cov(yz)
187 fRefCov[2] = cov[5]; // Var(z)
0906e73e 188
29b87567 189 //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());
190 return kTRUE;
0906e73e 191}
192
bcb6fb78 193
194//____________________________________________________________________
195void AliTRDseedV1::CookdEdx(Int_t nslices)
196{
197// Calculates average dE/dx for all slices and store them in the internal array fdEdx.
198//
199// Parameters:
200// nslices : number of slices for which dE/dx should be calculated
201// Output:
202// store results in the internal array fdEdx. This can be accessed with the method
203// AliTRDseedV1::GetdEdx()
204//
205// Detailed description
206// Calculates average dE/dx for all slices. Depending on the PID methode
207// the number of slices can be 3 (LQ) or 8(NN).
208// The calculation of dQ/dl are done using the tracklet fit results (see AliTRDseedV1::GetdQdl(Int_t)) i.e.
209//
210// dQ/dl = qc/(dx * sqrt(1 + dy/dx^2 + dz/dx^2))
211//
212// The following effects are included in the calculation:
213// 1. calibration values for t0 and vdrift (using x coordinate to calculate slice)
214// 2. cluster sharing (optional see AliTRDrecoParam::SetClusterSharing())
215// 3. cluster size
216//
217
29b87567 218 Int_t nclusters[knSlices];
219 for(int i=0; i<knSlices; i++){
220 fdEdx[i] = 0.;
221 nclusters[i] = 0;
222 }
223 Float_t clength = (/*.5 * */AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());
224
225 AliTRDcluster *cluster = 0x0;
226 for(int ic=0; ic<AliTRDtrackerV1::GetNTimeBins(); ic++){
227 if(!(cluster = fClusters[ic])) continue;
228 Float_t x = cluster->GetX();
229
230 // Filter clusters for dE/dx calculation
231
232 // 1.consider calibration effects for slice determination
233 Int_t slice;
234 if(cluster->IsInChamber()) slice = Int_t(TMath::Abs(fX0 - x) * nslices / clength);
235 else slice = x < fX0 ? 0 : nslices-1;
236
237 // 2. take sharing into account
238 Float_t w = cluster->IsShared() ? .5 : 1.;
239
240 // 3. take into account large clusters TODO
241 //w *= c->GetNPads() > 3 ? .8 : 1.;
242
243 //CHECK !!!
244 fdEdx[slice] += w * GetdQdl(ic); //fdQdl[ic];
245 nclusters[slice]++;
246 } // End of loop over clusters
247
cd40b287 248 //if(fReconstructor->GetPIDMethod() == AliTRDReconstructor::kLQPID){
249 if(nslices == AliTRDReconstructor::kLQslices){
29b87567 250 // calculate mean charge per slice (only LQ PID)
251 for(int is=0; is<nslices; is++){
252 if(nclusters[is]) fdEdx[is] /= nclusters[is];
253 }
254 }
bcb6fb78 255}
256
b83573da 257
bcb6fb78 258//____________________________________________________________________
259Float_t AliTRDseedV1::GetdQdl(Int_t ic) const
260{
29b87567 261 return fClusters[ic] ? TMath::Abs(fClusters[ic]->GetQ()) /fdX / TMath::Sqrt(1. + fYfit[1]*fYfit[1] + fZref[1]*fZref[1]) : 0.;
bcb6fb78 262}
263
0906e73e 264//____________________________________________________________________
265Double_t* AliTRDseedV1::GetProbability()
266{
267// Fill probability array for tracklet from the DB.
268//
269// Parameters
270//
271// Output
272// returns pointer to the probability array and 0x0 if missing DB access
273//
274// Detailed description
275
29b87567 276
277 // retrive calibration db
0906e73e 278 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
279 if (!calibration) {
280 AliError("No access to calibration data");
281 return 0x0;
282 }
283
3a039a31 284 if (!fReconstructor) {
285 AliError("Reconstructor not set.");
4ba1d6ae 286 return 0x0;
287 }
288
0906e73e 289 // Retrieve the CDB container class with the parametric detector response
3a039a31 290 const AliTRDCalPID *pd = calibration->GetPIDObject(fReconstructor->GetPIDMethod());
0906e73e 291 if (!pd) {
292 AliError("No access to AliTRDCalPID object");
293 return 0x0;
294 }
29b87567 295 //AliInfo(Form("Method[%d] : %s", fReconstructor->GetRecoParam() ->GetPIDMethod(), pd->IsA()->GetName()));
10f75631 296
29b87567 297 // calculate tracklet length TO DO
0906e73e 298 Float_t length = (AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());
299 /// TMath::Sqrt((1.0 - fSnp[iPlane]*fSnp[iPlane]) / (1.0 + fTgl[iPlane]*fTgl[iPlane]));
300
301 //calculate dE/dx
3a039a31 302 CookdEdx(fReconstructor->GetNdEdxSlices());
0906e73e 303
304 // Sets the a priori probabilities
305 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) {
ae4e8b84 306 fProb[ispec] = pd->GetProbability(ispec, fMom, &fdEdx[0], length, GetPlane());
0906e73e 307 }
308
29b87567 309 return &fProb[0];
0906e73e 310}
311
e4f2f73d 312//____________________________________________________________________
313Float_t AliTRDseedV1::GetQuality(Bool_t kZcorr) const
314{
315 //
316 // Returns a quality measurement of the current seed
317 //
318
29b87567 319 Float_t zcorr = kZcorr ? fTilt * (fZProb - fZref[0]) : 0.;
320 return
321 .5 * TMath::Abs(18.0 - fN2)
322 + 10.* TMath::Abs(fYfit[1] - fYref[1])
323 + 5. * TMath::Abs(fYfit[0] - fYref[0] + zcorr)
324 + 2. * TMath::Abs(fMeanz - fZref[0]) / fPadLength;
e4f2f73d 325}
326
0906e73e 327//____________________________________________________________________
328void AliTRDseedV1::GetCovAt(Double_t /*x*/, Double_t *cov) const
329{
330// Computes covariance in the y-z plane at radial point x
331
29b87567 332 Int_t ic = 0; while (!fClusters[ic]) ic++;
eb38ed55 333 AliTRDcalibDB *fCalib = AliTRDcalibDB::Instance();
29b87567 334 Double_t exB = fCalib->GetOmegaTau(fCalib->GetVdriftAverage(fClusters[ic]->GetDetector()), -AliTracker::GetBz()*0.1);
eb38ed55 335
29b87567 336 Double_t sy2 = fSigmaY2*fSigmaY2 + .2*(fYfit[1]-exB)*(fYfit[1]-exB);
337 Double_t sz2 = fPadLength/12.;
0906e73e 338
eb38ed55 339
29b87567 340 //printf("Yfit[1] %f sy20 %f SigmaY2 %f\n", fYfit[1], sy20, fSigmaY2);
0906e73e 341
29b87567 342 cov[0] = sy2;
343 cov[1] = fTilt*(sy2-sz2);
344 cov[2] = sz2;
3a039a31 345
346 // insert systematic uncertainties calibration and misalignment
347 Double_t sys[15];
348 fReconstructor->GetRecoParam()->GetSysCovMatrix(sys);
349 cov[0] += (sys[0]*sys[0]);
350 cov[2] += (sys[1]*sys[1]);
0906e73e 351}
352
0906e73e 353
354//____________________________________________________________________
29b87567 355void AliTRDseedV1::SetOwner()
0906e73e 356{
29b87567 357 //AliInfo(Form("own [%s] fOwner[%s]", own?"YES":"NO", fOwner?"YES":"NO"));
358
359 if(TestBit(kOwner)) return;
360 for(int ic=0; ic<knTimebins; ic++){
361 if(!fClusters[ic]) continue;
362 fClusters[ic] = new AliTRDcluster(*fClusters[ic]);
363 }
364 SetBit(kOwner);
0906e73e 365}
366
e4f2f73d 367//____________________________________________________________________
eb38ed55 368Bool_t AliTRDseedV1::AttachClustersIter(AliTRDtrackingChamber *chamber, Float_t quality, Bool_t kZcorr, AliTRDcluster *c)
e4f2f73d 369{
370 //
371 // Iterative process to register clusters to the seed.
372 // In iteration 0 we try only one pad-row and if quality not
373 // sufficient we try 2 pad-rows (about 5% of tracks cross 2 pad-rows)
374 //
29b87567 375 // debug level 7
376 //
377
378 if(!fReconstructor->GetRecoParam() ){
379 AliError("Seed can not be used without a valid RecoParam.");
380 return kFALSE;
381 }
382
383 AliTRDchamberTimeBin *layer = 0x0;
a8276d32 384 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker)>=7){
e8037fda 385 AliTRDtrackingChamber ch(*chamber);
386 ch.SetOwner();
29f95561 387 TTreeSRedirector &cstreamer = *fReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
388 cstreamer << "AttachClustersIter"
e8037fda 389 << "chamber.=" << &ch
29b87567 390 << "tracklet.=" << this
29b87567 391 << "\n";
392 }
393
35c24814 394 Float_t tquality;
29b87567 395 Double_t kroady = fReconstructor->GetRecoParam() ->GetRoad1y();
396 Double_t kroadz = fPadLength * .5 + 1.;
35c24814 397
398 // initialize configuration parameters
399 Float_t zcorr = kZcorr ? fTilt * (fZProb - fZref[0]) : 0.;
400 Int_t niter = kZcorr ? 1 : 2;
401
29b87567 402 Double_t yexp, zexp;
403 Int_t ncl = 0;
35c24814 404 // start seed update
405 for (Int_t iter = 0; iter < niter; iter++) {
29b87567 406 ncl = 0;
407 for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
408 if(!(layer = chamber->GetTB(iTime))) continue;
409 if(!Int_t(*layer)) continue;
410
411 // define searching configuration
412 Double_t dxlayer = layer->GetX() - fX0;
413 if(c){
414 zexp = c->GetZ();
415 //Try 2 pad-rows in second iteration
416 if (iter > 0) {
417 zexp = fZref[0] + fZref[1] * dxlayer - zcorr;
418 if (zexp > c->GetZ()) zexp = c->GetZ() + fPadLength*0.5;
419 if (zexp < c->GetZ()) zexp = c->GetZ() - fPadLength*0.5;
420 }
421 } else zexp = fZref[0] + (kZcorr ? fZref[1] * dxlayer : 0.);
35c24814 422 yexp = fYref[0] + fYref[1] * dxlayer - zcorr;
29b87567 423
424 // Get and register cluster
425 Int_t index = layer->SearchNearestCluster(yexp, zexp, kroady, kroadz);
426 if (index < 0) continue;
427 AliTRDcluster *cl = (*layer)[index];
35c24814 428
29b87567 429 fIndexes[iTime] = layer->GetGlobalIndex(index);
430 fClusters[iTime] = cl;
431 fY[iTime] = cl->GetY();
432 fZ[iTime] = cl->GetZ();
433 ncl++;
434 }
35c24814 435 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker)>=7) AliInfo(Form("iter = %d ncl [%d] = %d", iter, fDet, ncl));
29b87567 436
437 if(ncl>1){
438 // calculate length of the time bin (calibration aware)
439 Int_t irp = 0; Float_t x[2]; Int_t tb[2];
440 for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
441 if(!fClusters[iTime]) continue;
442 x[irp] = fClusters[iTime]->GetX();
443 tb[irp] = iTime;
444 irp++;
445 if(irp==2) break;
446 }
447 fdX = (x[1] - x[0]) / (tb[0] - tb[1]);
448
449 // update X0 from the clusters (calibration/alignment aware)
450 for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
451 if(!(layer = chamber->GetTB(iTime))) continue;
452 if(!layer->IsT0()) continue;
453 if(fClusters[iTime]){
454 fX0 = fClusters[iTime]->GetX();
455 break;
456 } else { // we have to infere the position of the anode wire from the other clusters
457 for (Int_t jTime = iTime+1; jTime < AliTRDtrackerV1::GetNTimeBins(); jTime++) {
458 if(!fClusters[jTime]) continue;
459 fX0 = fClusters[jTime]->GetX() + fdX * (jTime - iTime);
f660dce9 460 break;
29b87567 461 }
29b87567 462 }
463 }
464
465 // update YZ reference point
466 // TODO
467
468 // update x reference positions (calibration/alignment aware)
469 for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
470 if(!fClusters[iTime]) continue;
0849f128 471 fX[iTime] = fX0 - fClusters[iTime]->GetX();
29b87567 472 }
473
474 AliTRDseed::Update();
475 }
35c24814 476 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker)>=7) AliInfo(Form("iter = %d nclFit [%d] = %d", iter, fDet, fN2));
29b87567 477
478 if(IsOK()){
479 tquality = GetQuality(kZcorr);
480 if(tquality < quality) break;
481 else quality = tquality;
482 }
483 kroadz *= 2.;
484 } // Loop: iter
485 if (!IsOK()) return kFALSE;
486
804bb02e 487 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker)>=1) CookLabels();
29b87567 488 UpdateUsed();
489 return kTRUE;
e4f2f73d 490}
491
492//____________________________________________________________________
eb38ed55 493Bool_t AliTRDseedV1::AttachClusters(AliTRDtrackingChamber *chamber
29b87567 494 ,Bool_t kZcorr)
e4f2f73d 495{
496 //
497 // Projective algorithm to attach clusters to seeding tracklets
498 //
499 // Parameters
500 //
501 // Output
502 //
503 // Detailed description
504 // 1. Collapse x coordinate for the full detector plane
505 // 2. truncated mean on y (r-phi) direction
506 // 3. purge clusters
507 // 4. truncated mean on z direction
508 // 5. purge clusters
509 // 6. fit tracklet
510 //
511
29b87567 512 if(!fReconstructor->GetRecoParam() ){
513 AliError("Seed can not be used without a valid RecoParam.");
514 return kFALSE;
515 }
516
517 const Int_t kClusterCandidates = 2 * knTimebins;
518
519 //define roads
520 Double_t kroady = fReconstructor->GetRecoParam() ->GetRoad1y();
521 Double_t kroadz = fPadLength * 1.5 + 1.;
522 // correction to y for the tilting angle
523 Float_t zcorr = kZcorr ? fTilt * (fZProb - fZref[0]) : 0.;
524
525 // working variables
526 AliTRDcluster *clusters[kClusterCandidates];
527 Double_t cond[4], yexp[knTimebins], zexp[knTimebins],
528 yres[kClusterCandidates], zres[kClusterCandidates];
529 Int_t ncl, *index = 0x0, tboundary[knTimebins];
530
531 // Do cluster projection
532 AliTRDchamberTimeBin *layer = 0x0;
533 Int_t nYclusters = 0; Bool_t kEXIT = kFALSE;
534 for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
535 if(!(layer = chamber->GetTB(iTime))) continue;
536 if(!Int_t(*layer)) continue;
537
538 fX[iTime] = layer->GetX() - fX0;
539 zexp[iTime] = fZref[0] + fZref[1] * fX[iTime];
540 yexp[iTime] = fYref[0] + fYref[1] * fX[iTime] - zcorr;
541
542 // build condition and process clusters
543 cond[0] = yexp[iTime] - kroady; cond[1] = yexp[iTime] + kroady;
544 cond[2] = zexp[iTime] - kroadz; cond[3] = zexp[iTime] + kroadz;
545 layer->GetClusters(cond, index, ncl);
546 for(Int_t ic = 0; ic<ncl; ic++){
547 AliTRDcluster *c = layer->GetCluster(index[ic]);
548 clusters[nYclusters] = c;
549 yres[nYclusters++] = c->GetY() - yexp[iTime];
550 if(nYclusters >= kClusterCandidates) {
551 AliWarning(Form("Cluster candidates reached limit %d. Some may be lost.", kClusterCandidates));
552 kEXIT = kTRUE;
553 break;
554 }
555 }
556 tboundary[iTime] = nYclusters;
557 if(kEXIT) break;
558 }
559
560 // Evaluate truncated mean on the y direction
561 Double_t mean, sigma;
562 AliMathBase::EvaluateUni(nYclusters, yres, mean, sigma, Int_t(nYclusters*.8)-2);
563 // purge cluster candidates
564 Int_t nZclusters = 0;
565 for(Int_t ic = 0; ic<nYclusters; ic++){
566 if(yres[ic] - mean > 4. * sigma){
567 clusters[ic] = 0x0;
568 continue;
569 }
570 zres[nZclusters++] = clusters[ic]->GetZ() - zexp[clusters[ic]->GetLocalTimeBin()];
571 }
572
573 // Evaluate truncated mean on the z direction
574 AliMathBase::EvaluateUni(nZclusters, zres, mean, sigma, Int_t(nZclusters*.8)-2);
575 // purge cluster candidates
576 for(Int_t ic = 0; ic<nZclusters; ic++){
577 if(zres[ic] - mean > 4. * sigma){
578 clusters[ic] = 0x0;
579 continue;
580 }
581 }
582
583
584 // Select only one cluster/TimeBin
585 Int_t lastCluster = 0;
586 fN2 = 0;
587 for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
588 ncl = tboundary[iTime] - lastCluster;
589 if(!ncl) continue;
590 Int_t iptr = lastCluster;
591 if(ncl > 1){
592 Float_t dold = 9999.;
593 for(int ic=lastCluster; ic<tboundary[iTime]; ic++){
594 if(!clusters[ic]) continue;
595 Float_t y = yexp[iTime] - clusters[ic]->GetY();
596 Float_t z = zexp[iTime] - clusters[ic]->GetZ();
597 Float_t d = y * y + z * z;
598 if(d > dold) continue;
599 dold = d;
600 iptr = ic;
601 }
602 }
603 fIndexes[iTime] = chamber->GetTB(iTime)->GetGlobalIndex(iptr);
604 fClusters[iTime] = clusters[iptr];
605 fY[iTime] = clusters[iptr]->GetY();
606 fZ[iTime] = clusters[iptr]->GetZ();
607 lastCluster = tboundary[iTime];
608 fN2++;
609 }
610
611 // number of minimum numbers of clusters expected for the tracklet
612 Int_t kClmin = Int_t(fReconstructor->GetRecoParam() ->GetFindableClusters()*AliTRDtrackerV1::GetNTimeBins());
e4f2f73d 613 if (fN2 < kClmin){
29b87567 614 AliWarning(Form("Not enough clusters to fit the tracklet %d [%d].", fN2, kClmin));
e4f2f73d 615 fN2 = 0;
616 return kFALSE;
617 }
0906e73e 618
29b87567 619 // update used clusters
620 fNUsed = 0;
621 for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) {
622 if(!fClusters[iTime]) continue;
623 if((fClusters[iTime]->IsUsed())) fNUsed++;
624 }
0906e73e 625
626 if (fN2-fNUsed < kClmin){
29b87567 627 AliWarning(Form("Too many clusters already in use %d (from %d).", fNUsed, fN2));
0906e73e 628 fN2 = 0;
629 return kFALSE;
630 }
29b87567 631
632 return kTRUE;
e4f2f73d 633}
634
03cef9b2 635//____________________________________________________________
636void AliTRDseedV1::Bootstrap(const AliTRDReconstructor *rec)
637{
638// Fill in all derived information. It has to be called after recovery from file or HLT.
639// The primitive data are
640// - list of clusters
641// - detector (as the detector will be removed from clusters)
642// - position of anode wire (fX0) - temporary
643// - track reference position and direction
644// - momentum of the track
645// - time bin length [cm]
646//
647// A.Bercuci <A.Bercuci@gsi.de> Oct 30th 2008
648//
649 fReconstructor = rec;
650 AliTRDgeometry g;
651 AliTRDpadPlane *pp = g.GetPadPlane(fDet);
652 fTilt = TMath::Tan(TMath::DegToRad()*pp->GetTiltingAngle());
653 fPadLength = pp->GetLengthIPad();
654 fSnp = fYref[1]/TMath::Sqrt(1+fYref[1]*fYref[1]);
655 fTgl = fZref[1];
656 fN = 0; fN2 = 0; fMPads = 0.;
657 AliTRDcluster **cit = &fClusters[0];
658 for(Int_t ic = knTimebins; ic--; cit++){
659 if(!(*cit)) return;
660 fN++; fN2++;
661 fX[ic] = (*cit)->GetX() - fX0;
662 fY[ic] = (*cit)->GetY();
663 fZ[ic] = (*cit)->GetZ();
664 }
665 Update(); // Fit();
666 CookLabels();
667 GetProbability();
668}
669
670
e4f2f73d 671//____________________________________________________________________
d2b9977a 672Bool_t AliTRDseedV1::Fit(Bool_t tilt)
e4f2f73d 673{
674 //
675 // Linear fit of the tracklet
676 //
677 // Parameters :
678 //
679 // Output :
680 // True if successful
681 //
682 // Detailed description
683 // 2. Check if tracklet crosses pad row boundary
684 // 1. Calculate residuals in the y (r-phi) direction
685 // 3. Do a Least Square Fit to the data
686 //
687
29b87567 688 const Int_t kClmin = 8;
9462866a 689 // drift velocity correction TODO to be moved to the clusterizer
690 const Float_t cx[] = {
6910.044168, 0.130812, -0.017411, -0.099284, -0.120416, -0.095457,
692-0.050021, -0.016758, 0.003570, 0.018618, 0.026380, 0.033786, 0.034889, 0.035264,
6930.035284, 0.036028, 0.035250, 0.034368, 0.032823, 0.031937, 0.032064, 0.022542,
694-0.025167, -0.120645, 0.};
695
696 // cluster error parametrization parameters
697 // 1. total charge
698 const Float_t sq0inv = 0.019962; // [1/q0]
699 const Float_t sqb = 1.0281564; //[cm]
700 // 2. sy parallel to the track
701 const Float_t sy0 = 2.60967e-01; // [mm] !!
702 const Float_t sya =-7.68941e+00; //
703 const Float_t syb =-3.41160e-01; //
704 // 3. sx parallel to the track
705 const Float_t sxgc = 5.49018e-01;
706 const Float_t sxgm = 7.82999e-01;
707 const Float_t sxgs = 2.74451e-01;
708 const Float_t sxe0 = 2.53596e-01;
709 const Float_t sxe1 =-2.40078e-02;
710 // 4. sx perpendicular to the track
711// const Float_t sxd0 = 0.190676;
712// const Float_t sxd1 =-3.9269;
713// const Float_t sxd2 =14.7851;
714
2f7d6ac8 715 // get track direction
716 Double_t y0 = fYref[0];
717 Double_t dydx = fYref[1];
718 Double_t z0 = fZref[0];
719 Double_t dzdx = fZref[1];
720 Double_t yt, zt;
ae4e8b84 721
29b87567 722 const Int_t kNtb = AliTRDtrackerV1::GetNTimeBins();
24d8660e 723 AliTRDtrackerV1::AliTRDLeastSquare fitterZ;
724 TLinearFitter fitterY(1, "pol1");
29b87567 725 // convertion factor from square to gauss distribution for sigma
726 Double_t convert = 1./TMath::Sqrt(12.);
ae4e8b84 727
29b87567 728 // book cluster information
9462866a 729 Double_t q, xc[knTimebins], yc[knTimebins], zc[knTimebins], sy[knTimebins], sz[knTimebins];
29b87567 730 Int_t zRow[knTimebins];
9462866a 731
732 // TODO move as data member of the tracklet
733 // TODO calculate for the exact position of the tracklet (det, col, row)
734 Double_t exb = -.16;
2f7d6ac8 735
736 fN = 0;
9eb2d46c 737 AliTRDcluster *c=0x0, **jc = &fClusters[0];
9eb2d46c 738 for (Int_t ic=0; ic<kNtb; ic++, ++jc) {
29b87567 739 zRow[ic] = -1;
740 xc[ic] = -1.;
741 yc[ic] = 999.;
742 zc[ic] = 999.;
743 sy[ic] = 0.;
744 sz[ic] = 0.;
9eb2d46c 745 if(!(c = (*jc))) continue;
29b87567 746 if(!c->IsInChamber()) continue;
9462866a 747
29b87567 748 Float_t w = 1.;
749 if(c->GetNPads()>4) w = .5;
750 if(c->GetNPads()>5) w = .2;
2f7d6ac8 751 zRow[fN] = c->GetPadRow();
9462866a 752 xc[fN] = fX0 - c->GetX() + cx[c->GetLocalTimeBin()];
2f7d6ac8 753 yc[fN] = c->GetY();
754 zc[fN] = c->GetZ();
755
756 // extrapolated y value for the track
757 yt = y0 - xc[fN]*dydx;
758 // extrapolated z value for the track
759 zt = z0 - xc[fN]*dzdx;
760 // tilt correction
761 if(tilt) yc[fN] -= fTilt*(zc[fN] - zt);
762
763 // elaborate cluster error
9462866a 764 q = TMath::Abs(c->GetQ());
765 Double_t tgg = (dydx-exb)/(1.+dydx*exb);
766 // error of drift length parallel to the track
767 Double_t sx = sxgc*TMath::Gaus(xc[fN], sxgm, sxgs) + sxe0*TMath::Exp(sxe1*xc[fN]); // [cm]
768 // error of drift length perpendicular to the track
769 //sx += sxd0 + sxd1*d + sxd2*d*d;
770 // global radial error due to misalignment/miscalibration
771 Double_t sx0 = 0.; // [cm]
772 sy[fN] = sy0 + TMath::Exp(sya*(xc[fN]+syb)) + sqb*(1./q - sq0inv);
773 sy[fN] *= sy[fN];
774 // add error on x
775 sy[fN] += tgg*tgg*(sx*sx+sx0*sx0);
776 // add error from ExB
777 sy[fN] += exb*exb*sx*sx;
778 sy[fN] = TMath::Sqrt(sy[fN]);
24d8660e 779 fitterY.AddPoint(&xc[fN], yc[fN]/*-yt*/, sy[fN]);
2f7d6ac8 780
781 sz[fN] = fPadLength*convert;
782 fitterZ.AddPoint(&xc[fN], zc[fN], sz[fN]);
783 fN++;
29b87567 784 }
47d5d320 785 // to few clusters
2f7d6ac8 786 if (fN < kClmin) return kFALSE;
787
788 // fit XY plane
789 fitterY.Eval();
24d8660e 790 fYfit[0] = /*y0+*/fitterY.GetParameter(0);
791 fYfit[1] = /*dydx-*/-fitterY.GetParameter(1);
2f7d6ac8 792
793 // check par row crossing
794 Int_t zN[2*AliTRDseed::knTimebins];
795 Int_t nz = AliTRDtrackerV1::Freq(fN, zRow, zN, kFALSE);
29b87567 796 // more than one pad row crossing
797 if(nz>2) return kFALSE;
9eb2d46c 798
29b87567 799
800 // determine z offset of the fit
2f7d6ac8 801 Float_t zslope = 0.;
29b87567 802 Int_t nchanges = 0, nCross = 0;
803 if(nz==2){ // tracklet is crossing pad row
804 // Find the break time allowing one chage on pad-rows
805 // with maximal number of accepted clusters
806 Int_t padRef = zRow[0];
2f7d6ac8 807 for (Int_t ic=1; ic<fN; ic++) {
29b87567 808 if(zRow[ic] == padRef) continue;
809
810 // debug
811 if(zRow[ic-1] == zRow[ic]){
812 printf("ERROR in pad row change!!!\n");
813 }
814
815 // evaluate parameters of the crossing point
816 Float_t sx = (xc[ic-1] - xc[ic])*convert;
2f7d6ac8 817 fCross[0] = .5 * (xc[ic-1] + xc[ic]);
818 fCross[2] = .5 * (zc[ic-1] + zc[ic]);
819 fCross[3] = TMath::Max(dzdx * sx, .01);
820 zslope = zc[ic-1] > zc[ic] ? 1. : -1.;
821 padRef = zRow[ic];
822 nCross = ic;
29b87567 823 nchanges++;
824 }
825 }
826
827 // condition on nCross and reset nchanges TODO
828
829 if(nchanges==1){
2f7d6ac8 830 if(dzdx * zslope < 0.){
29b87567 831 AliInfo("tracklet direction does not correspond to the track direction. TODO.");
832 }
833 SetBit(kRowCross, kTRUE); // mark pad row crossing
2f7d6ac8 834 fitterZ.AddPoint(&fCross[0], fCross[2], fCross[3]);
29b87567 835 fitterZ.Eval();
2f7d6ac8 836 //zc[nc] = fitterZ.GetFunctionParameter(0);
837 fCross[1] = fYfit[0] - fCross[0] * fYfit[1];
838 fCross[0] = fX0 - fCross[0];
29b87567 839 } else if(nchanges > 1){ // debug
2389e96f 840 AliError("N pad row crossing > 1.");
29b87567 841 return kFALSE;
842 }
843
2389e96f 844 UpdateUsed();
845
29b87567 846 return kTRUE;
e4f2f73d 847}
848
e4f2f73d 849
850//___________________________________________________________________
203967fc 851void AliTRDseedV1::Print(Option_t *o) const
e4f2f73d 852{
853 //
854 // Printing the seedstatus
855 //
856
203967fc 857 AliInfo(Form("Det[%3d] Tilt[%+6.2f] Pad[%5.2f]", fDet, fTilt, fPadLength));
858 AliInfo(Form("Nattach[%2d] Nfit[%2d] Nuse[%2d] pads[%f]", fN, fN2, fNUsed, fMPads));
859 AliInfo(Form("x[%7.2f] y[%7.2f] z[%7.2f] dydx[%5.2f] dzdx[%5.2f]", fX0, fYfit[0], fZfit[0], fYfit[1], fZfit[1]));
860 AliInfo(Form("Ref y[%7.2f] z[%7.2f] dydx[%5.2f] dzdx[%5.2f]", fYref[0], fZref[0], fYref[1], fZref[1]))
861
862
863 if(strcmp(o, "a")!=0) return;
864
4dc4dc2e 865 AliTRDcluster* const* jc = &fClusters[0];
866 for(int ic=0; ic<AliTRDtrackerV1::GetNTimeBins(); ic++, jc++) {
867 if(!(*jc)) continue;
203967fc 868 (*jc)->Print(o);
4dc4dc2e 869 }
e4f2f73d 870
203967fc 871/* printf(" fSigmaY =%f\n", fSigmaY);
29b87567 872 printf(" fSigmaY2=%f\n", fSigmaY2);
873 printf(" fMeanz =%f\n", fMeanz);
874 printf(" fZProb =%f\n", fZProb);
203967fc 875 printf(" fLabels[0]=%d fLabels[1]=%d\n", fLabels[0], fLabels[1]);*/
29b87567 876
203967fc 877/* printf(" fC =%f\n", fC);
29b87567 878 printf(" fCC =%f\n",fCC);
879 printf(" fChi2 =%f\n", fChi2);
203967fc 880 printf(" fChi2Z =%f\n", fChi2Z);*/
e4f2f73d 881}
47d5d320 882
203967fc 883
884//___________________________________________________________________
885Bool_t AliTRDseedV1::IsEqual(const TObject *o) const
886{
887 // Checks if current instance of the class has the same essential members
888 // as the given one
889
890 if(!o) return kFALSE;
891 const AliTRDseedV1 *inTracklet = dynamic_cast<const AliTRDseedV1*>(o);
892 if(!inTracklet) return kFALSE;
893
894 for (Int_t i = 0; i < 2; i++){
895 if ( fYref[i] != inTracklet->GetYref(i) ) return kFALSE;
896 if ( fZref[i] != inTracklet->GetZref(i) ) return kFALSE;
897 }
898
899 if ( fSigmaY != inTracklet->GetSigmaY() ) return kFALSE;
900 if ( fSigmaY2 != inTracklet->GetSigmaY2() ) return kFALSE;
901 if ( fTilt != inTracklet->GetTilt() ) return kFALSE;
902 if ( fPadLength != inTracklet->GetPadLength() ) return kFALSE;
903
904 for (Int_t i = 0; i < knTimebins; i++){
905 if ( fX[i] != inTracklet->GetX(i) ) return kFALSE;
906 if ( fY[i] != inTracklet->GetY(i) ) return kFALSE;
907 if ( fZ[i] != inTracklet->GetZ(i) ) return kFALSE;
908 if ( fIndexes[i] != inTracklet->GetIndexes(i) ) return kFALSE;
909 if ( fUsable[i] != inTracklet->IsUsable(i) ) return kFALSE;
910 }
911
912 for (Int_t i=0; i < 2; i++){
913 if ( fYfit[i] != inTracklet->GetYfit(i) ) return kFALSE;
914 if ( fZfit[i] != inTracklet->GetZfit(i) ) return kFALSE;
915 if ( fYfitR[i] != inTracklet->GetYfitR(i) ) return kFALSE;
916 if ( fZfitR[i] != inTracklet->GetZfitR(i) ) return kFALSE;
917 if ( fLabels[i] != inTracklet->GetLabels(i) ) return kFALSE;
918 }
919
920 if ( fMeanz != inTracklet->GetMeanz() ) return kFALSE;
921 if ( fZProb != inTracklet->GetZProb() ) return kFALSE;
922 if ( fN2 != inTracklet->GetN2() ) return kFALSE;
923 if ( fNUsed != inTracklet->GetNUsed() ) return kFALSE;
924 if ( fFreq != inTracklet->GetFreq() ) return kFALSE;
925 if ( fNChange != inTracklet->GetNChange() ) return kFALSE;
926 if ( fNChange != inTracklet->GetNChange() ) return kFALSE;
927
928 if ( fC != inTracklet->GetC() ) return kFALSE;
929 if ( fCC != inTracklet->GetCC() ) return kFALSE;
930 if ( fChi2 != inTracklet->GetChi2() ) return kFALSE;
931 // if ( fChi2Z != inTracklet->GetChi2Z() ) return kFALSE;
932
933 if ( fDet != inTracklet->GetDetector() ) return kFALSE;
934 if ( fMom != inTracklet->GetMomentum() ) return kFALSE;
935 if ( fdX != inTracklet->GetdX() ) return kFALSE;
936
937 for (Int_t iCluster = 0; iCluster < knTimebins; iCluster++){
938 AliTRDcluster *curCluster = fClusters[iCluster];
939 AliTRDcluster *inCluster = inTracklet->GetClusters(iCluster);
940 if (curCluster && inCluster){
941 if (! curCluster->IsEqual(inCluster) ) {
942 curCluster->Print();
943 inCluster->Print();
944 return kFALSE;
945 }
946 } else {
947 // if one cluster exists, and corresponding
948 // in other tracklet doesn't - return kFALSE
949 if(curCluster || inCluster) return kFALSE;
950 }
951 }
952 return kTRUE;
953}