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: AliTRDgtuTMU.cxx 28397 2008-09-02 09:33:00Z cblume $ */
18 ////////////////////////////////////////////////////////////////////////////
20 // Track Matching Unit (TMU) simulation //
22 // Author: J. Klein (Jochen.Klein@cern.ch) //
24 ////////////////////////////////////////////////////////////////////////////
31 #include "AliESDEvent.h"
32 #include "AliESDTrdTrack.h"
35 #include "AliTRDgeometry.h"
36 #include "AliTRDpadPlane.h"
38 #include "AliTRDgtuParam.h"
39 #include "AliTRDgtuTMU.h"
40 #include "AliTRDtrackGTU.h"
42 ClassImp(AliTRDgtuTMU)
44 AliTRDgtuTMU::AliTRDgtuTMU(Int_t stack, Int_t sector) :
47 fTrackletsPostInput(0x0),
48 fZChannelTracklets(0x0),
54 // constructor which initializes the position information of the TMU
56 fGtuParam = AliTRDgtuParam::Instance();
58 // store tracklets per link
59 fTracklets = new TObjArray*[fGtuParam->GetNLinks()];
60 for (Int_t iLink = 0; iLink < fGtuParam->GetNLinks(); iLink++) {
61 fTracklets[iLink] = new TObjArray();
64 // tracklets after input units per layer
65 fTrackletsPostInput = new TObjArray*[fGtuParam->GetNLayers()];
66 fZChannelTracklets = new TList*[fGtuParam->GetNLayers()];
67 for (Int_t layer = 0; layer < fGtuParam->GetNLayers(); layer++) {
68 fZChannelTracklets[layer] = new TList[fGtuParam->GetNZChannels()];
69 fTrackletsPostInput[layer] = new TObjArray();
72 fTracks = new TList*[fGtuParam->GetNZChannels()];
73 for (Int_t zch = 0; zch < fGtuParam->GetNZChannels(); zch++) {
74 fTracks[zch] = new TList[fGtuParam->GetNRefLayers()];
83 AliTRDgtuTMU::~AliTRDgtuTMU()
87 for (Int_t zch = 0; zch < fGtuParam->GetNZChannels(); zch++) {
88 delete [] fTracks[zch];
91 for (Int_t layer = 0; layer < fGtuParam->GetNLayers(); layer++) {
92 delete [] fZChannelTracklets[layer];
93 // delete [] fTrackletsPostInput[layer];
95 delete [] fZChannelTracklets;
96 // delete [] fTrackletsPostInput;
98 for (Int_t iLink = 0; iLink < fGtuParam->GetNLinks(); iLink++) {
99 delete fTracklets[iLink];
101 delete [] fTracklets;
104 Bool_t AliTRDgtuTMU::SetSector(Int_t sector)
108 if (sector > -1 && sector < fGtuParam->GetGeo()->Nsector() ) {
113 AliError(Form("Invalid sector given: %i", sector));
117 Bool_t AliTRDgtuTMU::SetStack(Int_t stack)
119 // Set the stack (necessary for tracking)
121 if (stack > -1 && stack < fGtuParam->GetGeo()->Nstack() ) {
126 AliError(Form("Invalid stack given: %i", stack));
130 Bool_t AliTRDgtuTMU::Reset()
134 for (Int_t zch = 0; zch < fGtuParam->GetNZChannels(); zch++) {
135 for (Int_t reflayeridx = 0; reflayeridx < fGtuParam->GetNRefLayers(); reflayeridx++) {
136 fTracks[zch][reflayeridx].Clear();
140 // delete all added tracklets
141 for (Int_t iLink = 0; iLink < fGtuParam->GetNLinks(); iLink++) {
142 fTracklets[iLink]->Clear();
144 for (Int_t layer = 0; layer < fGtuParam->GetNLinks()/2; layer++) {
145 fTrackletsPostInput[layer]->Clear();
146 for (Int_t zch = 0; zch < fGtuParam->GetNZChannels(); zch++)
147 fZChannelTracklets[layer][zch].Clear();
156 Bool_t AliTRDgtuTMU::AddTracklet(AliTRDtrackletGTU *tracklet, Int_t link)
158 // add a tracklet on the given link
160 fTracklets[link]->Add(tracklet);
165 Bool_t AliTRDgtuTMU::RunTMU(TList *ListOfTracks, AliESDEvent *esd)
167 // performs the analysis as in a TMU module of the GTU, i. e.
169 // calculation of track parameteres (pt, deflection, ???)
171 if (fStack < 0 || fSector < 0) {
172 AliError("No valid stack/sector set for this TMU! No tracking!");
176 // ----- Input units -----
177 AliDebug(1,"--------- Running Input units ----------");
178 for (Int_t layer = 0; layer < fGtuParam->GetNLayers(); layer++) {
179 if (!RunInputUnit(layer)) {
180 AliError(Form("Input unit in layer %i failed", layer));
185 // ----- Z-channel units -----
186 AliDebug(1,"--------- Running Z-channel units ----------");
187 for (Int_t layer = 0; layer < fGtuParam->GetNLayers(); layer++) {
188 fZChannelTracklets[layer] = new TList[fGtuParam->GetNZChannels()];
189 if (!RunZChannelUnit(layer)) {
190 AliError(Form("Z-Channel unit in layer %i failed", layer));
195 // ----- track finding -----
196 AliDebug(1,"--------- Running tracking units ----------");
197 for (Int_t zch = 0; zch < fGtuParam->GetNZChannels(); zch++) {
198 if (!RunTrackFinder(zch, ListOfTracks)) {
199 AliError(Form("Track Finder in z-channel %i failed", zch));
204 // ----- Track Merging -----
205 if (!RunTrackMerging(ListOfTracks)) {
206 AliError("Track merging failed");
210 // ----- track reconstruction -----
211 if (!RunTrackReconstruction(ListOfTracks)) {
212 AliError("Track reconstruction failed");
216 // ----- label calculation and ESD storage -----
217 TIter next(ListOfTracks);
218 while (AliTRDtrackGTU *trk = (AliTRDtrackGTU*) next()) {
221 AliESDTrdTrack *trdtrack = trk->CreateTrdTrack();
222 esd->AddTrdTrack(trdtrack);
230 Bool_t AliTRDgtuTMU::RunInputUnit(Int_t layer)
232 // precalculations for the tracking and reconstruction
234 Int_t iTrkl0 = 0; // A-side tracklet
235 Int_t iTrkl1 = 0; // B-side tracklet
237 while ((iTrkl0 < fTracklets[2*layer + 0]->GetEntriesFast()) || (iTrkl1 < fTracklets[2*layer + 1]->GetEntriesFast())) {
238 if (iTrkl1 >= fTracklets[2*layer + 1]->GetEntriesFast()) {
239 fTrackletsPostInput[layer]->AddLast(fTracklets[2*layer + 0]->At(iTrkl0));
243 if (iTrkl0 >= fTracklets[2*layer + 0]->GetEntriesFast()) {
244 fTrackletsPostInput[layer]->AddLast(fTracklets[2*layer + 1]->At(iTrkl1));
248 if (((AliTRDtrackletGTU*) fTracklets[2*layer + 1]->At(iTrkl1))->GetZbin() <
249 ((AliTRDtrackletGTU*) fTracklets[2*layer + 0]->At(iTrkl0))->GetZbin()) {
250 fTrackletsPostInput[layer]->AddLast(fTracklets[2*layer + 1]->At(iTrkl1));
255 fTrackletsPostInput[layer]->AddLast(fTracklets[2*layer + 0]->At(iTrkl0));
262 TIter next(fTrackletsPostInput[layer]);
264 while ( AliTRDtrackletGTU *trk = (AliTRDtrackletGTU*) next() ) {
265 trk->SetIndex(fTrackletsPostInput[layer]->IndexOf(trk));
267 Int_t alpha = (trk->GetYbin() >> fGtuParam->GetBitExcessY()) * fGtuParam->GetCiAlpha(layer);
268 alpha = ( 2 * trk->GetdY() - (alpha >> fGtuParam->GetBitExcessAlpha()) + 1 ) >> 1;
269 // wrapping projected alpha as in hardware
270 if ((alpha < -64) || (alpha > 63))
271 AliError(Form("alpha out of range: %i", alpha));
272 alpha = alpha & 0x7f;
274 trk->SetAlpha(0xffffffc0 | alpha);
276 trk->SetAlpha(alpha);
278 Int_t yproj = trk->GetdY() * (fGtuParam->GetCiYProj(layer));
279 yproj = ( ( ( (yproj >> fGtuParam->GetBitExcessYProj()) + trk->GetYbin() ) >> 2) + 1) >> 1;
280 trk->SetYProj(yproj);
282 trk->SetYPrime(trk->GetYbin() + fGtuParam->GetYt(fStack, layer, trk->GetZbin()));
284 AliDebug(10, Form("0x%08x: idx: %3i, z: %2i, y: %5i, dy: %3i, y': %5i, y_proj: %5i, alpha: %3i, pid: %3i, c: %5i, yt: %5i",
285 trk->GetTrackletWord(), trk->GetIndex(), trk->GetZbin(), trk->GetYbin(), trk->GetdY(), trk->GetYPrime(),
286 trk->GetYProj(), trk->GetAlpha(), trk->GetPID(),
287 fGtuParam->GetCiYProj(layer), fGtuParam->GetYt(fStack, layer, trk->GetZbin()) ));
292 Bool_t AliTRDgtuTMU::RunZChannelUnit(Int_t layer)
294 // run the z-channel unit
296 TIter next(fTrackletsPostInput[layer]);
298 while (AliTRDtrackletGTU *trk = (AliTRDtrackletGTU*) next()) {
299 for (Int_t zch = 0; zch < fGtuParam->GetNZChannels(); zch++) {
300 if (fGtuParam->IsInZChannel(fStack, layer, zch, trk->GetZbin()) ) {
301 trk->SetSubChannel(zch, fGtuParam->GetZSubchannel(fStack, layer, zch, trk->GetZbin()) );
303 TIter nexttrkl(&fZChannelTracklets[layer][zch], kIterBackward);
304 AliTRDtrackletGTU *t = 0x0;
305 while ((t = (AliTRDtrackletGTU*) nexttrkl.Next())) {
306 if (t->GetSubChannel(zch) < trk->GetSubChannel(zch) ||
307 ((t->GetSubChannel(zch) == trk->GetSubChannel(zch)) && (t->GetYProj() < trk->GetYProj())) ) {
312 fZChannelTracklets[layer][zch].AddAfter(t, trk);
314 fZChannelTracklets[layer][zch].AddFirst(trk);
317 AliDebug(10, Form("stack %d, layer %2d: 0x%08x Z(2..0)=%i/%i/%i",
318 fStack, layer, trk->GetTrackletWord(),
319 fGtuParam->IsInZChannel(fStack, layer, 2, trk->GetZbin()) ? trk->GetSubChannel(2) : -1,
320 fGtuParam->IsInZChannel(fStack, layer, 1, trk->GetZbin()) ? trk->GetSubChannel(1) : -1,
321 fGtuParam->IsInZChannel(fStack, layer, 0, trk->GetZbin()) ? trk->GetSubChannel(0) : -1
327 Bool_t AliTRDgtuTMU::RunTrackFinder(Int_t zch, TList* /* ListOfTracks */)
329 // run the track finding
331 Int_t *notr = new Int_t[fGtuParam->GetNLayers()];
332 Int_t *ptrA = new Int_t[fGtuParam->GetNLayers()];
333 Int_t *ptrB = new Int_t[fGtuParam->GetNLayers()];
335 Bool_t *bHitA = new Bool_t[fGtuParam->GetNLayers()];
336 Bool_t *bHitB = new Bool_t[fGtuParam->GetNLayers()];
337 Bool_t *bAligned = new Bool_t[fGtuParam->GetNLayers()];
338 Bool_t *bAlignedA = new Bool_t[fGtuParam->GetNLayers()];
339 Bool_t *bAlignedB = new Bool_t[fGtuParam->GetNLayers()];
340 Bool_t *bDone = new Bool_t[fGtuParam->GetNLayers()];
343 Int_t *inc = new Int_t[fGtuParam->GetNLayers()];
344 Int_t *incprime = new Int_t[fGtuParam->GetNLayers()];
346 // ----- signals within current layer -----
357 AliTRDtrackletGTU *trkRA = 0x0; // reference tracklet A
358 AliTRDtrackletGTU *trkRB = 0x0; // reference tracklet B
359 AliTRDtrackletGTU *trkA = 0x0; // tracklet A in current layer
360 AliTRDtrackletGTU *trkB = 0x0; // tracklet B in current layer
362 AliTRDtrackletGTU *trkEnd = new AliTRDtrackletGTU();
363 for (Int_t i = 0; i < fGtuParam->GetNZChannels(); i++)
364 trkEnd->SetSubChannel(i, 7);
369 for (Int_t refLayerIdx = 0; refLayerIdx < fGtuParam->GetNRefLayers(); refLayerIdx++) {
370 Int_t reflayer = fGtuParam->GetRefLayer(refLayerIdx);
371 AliDebug(5,Form("Tracking for z-channel: %i, reflayer: %i", zch, reflayer));
373 ready = kFALSE; // ready if all channels done
375 // for (Int_t iLayer = 0; iLayer < fGtuParam->GetNLayers(); iLayer++) {
376 // for (Int_t iTrkl = 0; iTrkl < fZChannelTracklets[iLayer][zch].GetEntries(); iTrkl++) {
377 // printf("%4i/%4i(%i,%i) ",
378 // ((AliTRDtrackletGTU*) fZChannelTracklets[iLayer][zch].At(iTrkl))->GetYProj(),
379 // ((AliTRDtrackletGTU*) fZChannelTracklets[iLayer][zch].At(iTrkl))->GetAlpha(),
380 // ((AliTRDtrackletGTU*) fZChannelTracklets[iLayer][zch].At(iTrkl))->GetIndex(),
381 // ((AliTRDtrackletGTU*) fZChannelTracklets[iLayer][zch].At(iTrkl))->GetSubChannel(zch)
387 for (Int_t layer = 0; layer < fGtuParam->GetNLayers(); layer++) {
388 notr[layer] = fZChannelTracklets[layer][zch].GetEntries();
389 ptrA[layer] = 0; // notr[layer] > 0 ? 0 : -1;
390 ptrB[layer] = 1; // notr[layer] > 1 ? 1 : -1;
392 // not necessary here
393 // bDone[layer] = (ptrB[layer] >= notr[layer] - 1); // trkB is last one
394 // bDone[layer] = (notr[layer] <= 0);
395 // ready = ready && bDone[layer];
398 AliDebug(5,Form("in layer: %i (zchannel = %i) there are: %i tracklets", layer, zch, notr[layer]));
401 if (ptrA[reflayer] < 0 && ptrB[reflayer] < 0)
405 // ----- reference tracklets -----
408 if (0 <= ptrA[reflayer] && ptrA[reflayer] < notr[reflayer])
409 trkRA = (AliTRDtrackletGTU*) fZChannelTracklets[reflayer][zch].At(ptrA[reflayer]);
411 AliDebug(10,Form("No valid tracklet in the reference at ptr: %i! Nothing done!", ptrA[reflayer]));
415 if (0 <= ptrB[reflayer] && ptrB[reflayer] < notr[reflayer])
416 trkRB = (AliTRDtrackletGTU*) fZChannelTracklets[reflayer][zch].At(ptrB[reflayer]);
418 yPlus = trkRA->GetYProj() + fGtuParam->GetDeltaY();
419 yMinus = trkRA->GetYProj() - fGtuParam->GetDeltaY();
420 alphaPlus = trkRA->GetAlpha() + fGtuParam->GetDeltaAlpha();
421 alphaMinus = trkRA->GetAlpha() - fGtuParam->GetDeltaAlpha();
423 ybPlus = trkRB->GetYProj() + fGtuParam->GetDeltaY();
424 ybMinus = trkRB->GetYProj() - fGtuParam->GetDeltaY();
426 else { // irrelevant (should be, is it?)
427 ybPlus = trkRA->GetYProj() + fGtuParam->GetDeltaY();
428 ybMinus = trkRA->GetYProj() - fGtuParam->GetDeltaY();
435 for (Int_t layer = 0; layer < fGtuParam->GetNLayers(); layer++) {
436 bHitA[layer] = bHitB[layer] = bAligned[layer] = kFALSE;
437 inc[layer] = incprime[layer] = 0;
439 if (layer == reflayer) {
440 bHitA[layer] = kTRUE;
441 bAligned[layer] = kTRUE;
448 if (0 <= ptrA[layer] && ptrA[layer] < notr[layer])
449 trkA = (AliTRDtrackletGTU*) fZChannelTracklets[layer][zch].At(ptrA[layer]);
450 if (0 <= ptrB[layer] && ptrB[layer] < notr[layer])
451 trkB = (AliTRDtrackletGTU*) fZChannelTracklets[layer][zch].At(ptrB[layer]);
453 bAlignedA[layer] = kFALSE;
454 bAlignedB[layer] = kFALSE;
457 bHitA[layer] = ( !(trkA->GetSubChannel(zch) < trkRA->GetSubChannel(zch) || (trkA->GetSubChannel(zch) == trkRA->GetSubChannel(zch) && trkA->GetYProj() < yMinus) ) &&
458 !(trkA->GetSubChannel(zch) > trkRA->GetSubChannel(zch) || (trkA->GetSubChannel(zch) == trkRA->GetSubChannel(zch) && trkA->GetYProj() > yPlus) ) &&
459 !(trkA->GetAlpha() < alphaMinus) &&
460 !(trkA->GetAlpha() > alphaPlus) );
461 bAlignedA[layer] = !(trkA->GetSubChannel(zch) < trkRA->GetSubChannel(zch) || (trkA->GetSubChannel(zch) == trkRA->GetSubChannel(zch) && trkA->GetYProj() < yMinus) );
465 bAlignedA[layer] = kTRUE;
469 bHitB[layer] = ( !(trkB->GetSubChannel(zch) < trkRA->GetSubChannel(zch) || (trkB->GetSubChannel(zch) == trkRA->GetSubChannel(zch) && trkB->GetYProj() < yMinus) ) &&
470 !(trkB->GetSubChannel(zch) > trkRA->GetSubChannel(zch) || (trkB->GetSubChannel(zch) == trkRA->GetSubChannel(zch) && trkB->GetYProj() > yPlus) ) &&
471 !(trkB->GetAlpha() < alphaMinus) &&
472 !(trkB->GetAlpha() > alphaPlus) );
473 bAlignedB[layer] = (trkB->GetSubChannel(zch) > trkRA->GetSubChannel(zch) || (trkB->GetSubChannel(zch) == trkRA->GetSubChannel(zch) && trkB->GetYProj() > yPlus) );
477 bAlignedB[layer] = kTRUE;
480 bAligned[layer] = bAlignedA[layer] || bAlignedB[layer]; //???
481 // bAligned[layer] = bAlignedA[layer]; //???
483 if (bAligned[layer] && (bHitA[layer] || bHitB[layer]) )
485 else if (!bAligned[layer] )
489 if ((trkA->GetSubChannel(zch) > trkRB->GetSubChannel(zch)) || (trkA->GetSubChannel(zch) == trkRB->GetSubChannel(zch) && trkA->GetYProj() > ybPlus) )
496 // pre-calculation for the layer shifting (alignment w. r. t. trkRB)
499 if ((trkA->GetSubChannel(zch) < trkRB->GetSubChannel(zch)) || (trkA->GetSubChannel(zch) == trkRB->GetSubChannel(zch) && trkA->GetYProj() < ybMinus )) // could trkA be aligned for trkRB
509 if ((trkB->GetSubChannel(zch) < trkRB->GetSubChannel(zch)) || (trkB->GetSubChannel(zch) == trkRB->GetSubChannel(zch) && trkB->GetYProj() < ybMinus )) // could trkB be aligned for trkRB
516 } // end of loop over layers
518 AliDebug(5,Form("logic calculation finished, Nhits: %i %s",
519 nHits, (nHits >= 4) ? "-> track found" : ""));
522 // ----- track registration -----
523 AliTRDtrackGTU *track = new AliTRDtrackGTU();
524 track->SetSector(fSector);
525 track->SetStack(fStack);
526 for (Int_t layer = 0; layer < fGtuParam->GetNLayers(); layer++ ) {
527 if (bHitA[layer] || layer == reflayer)
528 track->AddTracklet((AliTRDtrackletGTU* ) fZChannelTracklets[layer][zch].At(ptrA[layer]), layer );
529 else if (bHitB[layer])
530 track->AddTracklet((AliTRDtrackletGTU* ) fZChannelTracklets[layer][zch].At(ptrB[layer]), layer );
533 Bool_t registerTrack = kTRUE;
534 for (Int_t layerIdx = refLayerIdx-1; layerIdx >= 0; layerIdx--) {
535 if (track->IsTrackletInLayer(fGtuParam->GetRefLayer(layerIdx))) {
536 if ((track->GetTracklet(fGtuParam->GetRefLayer(layerIdx)))->GetSubChannel(zch) > 0) {
537 AliDebug(1,"Not registered");
538 registerTrack = kFALSE;
543 track->SetZChannel(zch);
544 track->SetRefLayerIdx(refLayerIdx);
545 fTracks[zch][refLayerIdx].Add(track);
549 if ( (nUnc != 0) && (nUnc + nHits >= 4) ) // could this position of the reference layer give some track //??? special check in case of hit?
551 else if (nWayBeyond > 2) // no track possible for both reference tracklets
556 if (inc[reflayer] != 0) // reflayer is shifted
557 for (Int_t layer = 0; layer < fGtuParam->GetNLayers(); layer++) {
558 if (layer == reflayer)
560 inc[layer] = incprime[layer];
562 else { // reflayer is not shifted
563 for (Int_t layer = 0; layer < fGtuParam->GetNLayers(); layer++) {
564 if (layer == reflayer || notr[layer] == 0)
569 if (0 <= ptrA[layer] && ptrA[layer] < notr[layer])
570 trkA = (AliTRDtrackletGTU*) fZChannelTracklets[layer][zch].At(ptrA[layer]);
572 if (0 <= ptrB[layer] && ptrB[layer] < notr[layer])
573 trkB = (AliTRDtrackletGTU*) fZChannelTracklets[layer][zch].At(ptrB[layer]);
576 if ( !(trkA->GetSubChannel(zch) < trkRA->GetSubChannel(zch) || (trkA->GetSubChannel(zch) == trkRA->GetSubChannel(zch) && trkA->GetYProj() < yMinus) ) &&
577 !(trkA->GetSubChannel(zch) > trkRA->GetSubChannel(zch) || (trkA->GetSubChannel(zch) == trkRA->GetSubChannel(zch) && trkA->GetYProj() > yPlus ) ) ) // trkA could hit trkRA
578 // if ( !(trkA->GetSubChannel(zch) < trkRA->GetSubChannel(zch) || (trkA->GetSubChannel(zch) == trkRA->GetSubChannel(zch) && trkA->GetYProj() < yMinus) ) )
581 if ( trkB->GetSubChannel(zch) < trkRA->GetSubChannel(zch) || (trkB->GetSubChannel(zch) == trkRA->GetSubChannel(zch) && trkB->GetYProj() < yMinus) )
583 else if ( !(trkB->GetSubChannel(zch) > trkRA->GetSubChannel(zch) || (trkB->GetSubChannel(zch) == trkRA->GetSubChannel(zch) && trkB->GetYProj() > yPlus) ) )
586 inc[layer] = incprime[layer];
589 inc[layer] = incprime[layer];
595 for (Int_t layer = fGtuParam->GetNLayers()-1; layer >= 0; layer--) {
597 bDone[layer] = ptrB[layer] < 0 || ptrB[layer] >= notr[layer];
598 ready = ready && bDone[layer];
600 if (inc[layer] != 0 && ptrA[layer] >= notr[layer])
601 AliError(Form("Invalid increment: %i at ptrA: %i, notr: %i", inc[layer], ptrA[layer], notr[layer]));
603 // AliInfo(Form("Shifting layer: %i, notr: %i, ptrA: %i, ptrB: %i, inc: %i", layer, notr[layer], ptrA[layer], ptrB[layer], inc[layer]));
604 AliDebug(10,Form(" Layer: %i %2i(%2i, %2i, %4i, %3i)%s%s %2i(%2i, %2i, %4i, %3i)%s%s +%i %s (no: %i)",
607 (0 <= ptrA[layer] && ptrA[layer] < notr[layer]) ? ((AliTRDtrackletGTU*) fZChannelTracklets[layer][zch].At(ptrA[layer]))->GetIndex() : -1,
608 (0 <= ptrA[layer] && ptrA[layer] < notr[layer]) ? ((AliTRDtrackletGTU*) fZChannelTracklets[layer][zch].At(ptrA[layer]))->GetSubChannel(zch) : -1,
609 (0 <= ptrA[layer] && ptrA[layer] < notr[layer]) ? ((AliTRDtrackletGTU*) fZChannelTracklets[layer][zch].At(ptrA[layer]))->GetYProj() : -1,
610 (0 <= ptrA[layer] && ptrA[layer] < notr[layer]) ? ((AliTRDtrackletGTU*) fZChannelTracklets[layer][zch].At(ptrA[layer]))->GetAlpha() : -1,
611 bHitA[layer] ? "*" : " ", bAlignedA[layer] ? "+" : " ",
613 (0 <= ptrB[layer] && ptrB[layer] < notr[layer]) ? ((AliTRDtrackletGTU*) fZChannelTracklets[layer][zch].At(ptrB[layer]))->GetIndex() : -1,
614 (0 <= ptrB[layer] && ptrB[layer] < notr[layer]) ? ((AliTRDtrackletGTU*) fZChannelTracklets[layer][zch].At(ptrB[layer]))->GetSubChannel(zch) : -1,
615 (0 <= ptrB[layer] && ptrB[layer] < notr[layer]) ? ((AliTRDtrackletGTU*) fZChannelTracklets[layer][zch].At(ptrB[layer]))->GetYProj() : -1,
616 (0 <= ptrB[layer] && ptrB[layer] < notr[layer]) ? ((AliTRDtrackletGTU*) fZChannelTracklets[layer][zch].At(ptrB[layer]))->GetAlpha() : -1,
617 bHitB[layer] ? "*" : " ", bAlignedB[layer] ? "+" : " ",
618 inc[layer], bDone[layer] ? "done" : " ", notr[layer]));
619 ptrA[layer] += inc[layer];
620 ptrB[layer] += inc[layer];
624 } // end of loop over reflayer
641 Bool_t AliTRDgtuTMU::RunTrackMerging(TList* ListOfTracks)
643 TList **tracksRefMerged = new TList*[fGtuParam->GetNZChannels()];
644 TList **tracksRefUnique = new TList*[fGtuParam->GetNZChannels()];
646 for (Int_t zch = 0; zch < fGtuParam->GetNZChannels(); zch++) {
647 tracksRefMerged[zch] = new TList;
648 tracksRefUnique[zch] = new TList;
651 TList *tracksZMergedStage0 = new TList;
652 TList *tracksZUniqueStage0 = new TList;
654 TList **tracksZSplitted = new TList*[2];
655 for (Int_t i = 0; i < 2; i++)
656 tracksZSplitted[i] = new TList;
658 TList *tracksZMergedStage1 = new TList;
660 AliTRDtrackGTU **trkInRefLayer = new AliTRDtrackGTU*[fGtuParam->GetNRefLayers()];
662 // Bool_t done = kFALSE;
664 AliTRDtrackGTU *trkStage0 = 0x0;
666 for (Int_t zch = 0; zch < fGtuParam->GetNZChannels(); zch++) {
667 // ----- Merging and Unification in Reflayers (seed_merger) -----
671 for (Int_t refLayerIdx = 0; refLayerIdx < fGtuParam->GetNRefLayers(); refLayerIdx++) {
672 trkInRefLayer[refLayerIdx] = (AliTRDtrackGTU*) fTracks[zch][refLayerIdx].First();
673 if (trkInRefLayer[refLayerIdx] == 0) {
676 else if (trkStage0 == 0x0 ) {
677 trkStage0 = trkInRefLayer[refLayerIdx];
678 minIdx = refLayerIdx;
681 else if ( (trkInRefLayer[refLayerIdx]->GetZSubChannel() < trkStage0->GetZSubChannel()) ||
682 ((trkInRefLayer[refLayerIdx]->GetZSubChannel() == trkStage0->GetZSubChannel()) &&
683 ((trkInRefLayer[refLayerIdx]->GetYapprox() >> 3) < (trkStage0->GetYapprox() >> 3)) ) ) {
684 minIdx = refLayerIdx;
685 trkStage0 = trkInRefLayer[refLayerIdx];
691 tracksRefMerged[zch]->Add(trkStage0);
692 fTracks[zch][minIdx].RemoveFirst();
693 } while (trkStage0 != 0);
695 Uniquifier(tracksRefMerged[zch], tracksRefUnique[zch]);
697 AliDebug(2, Form("zchannel %i", zch));
698 TIter trackRefMerged(tracksRefMerged[zch]);
699 while (AliTRDtrackGTU *trk = (AliTRDtrackGTU*) trackRefMerged())
700 AliDebug(2, Form("track ref layer %i : %i %i %i %i %i %i, y=%i, z_idx=%i",
701 AliTRDgtuParam::GetRefLayer(trk->GetRefLayerIdx()),
702 trk->GetTrackletIndex(5),
703 trk->GetTrackletIndex(4),
704 trk->GetTrackletIndex(3),
705 trk->GetTrackletIndex(2),
706 trk->GetTrackletIndex(1),
707 trk->GetTrackletIndex(0),
708 trk->GetYapprox() >> 3,
709 trk->GetZSubChannel()));
710 AliDebug(2, "uniquified:");
711 TIter trackRefUnique(tracksRefUnique[zch]);
712 while (AliTRDtrackGTU *trk = (AliTRDtrackGTU*) trackRefUnique())
713 AliDebug(2, Form("track ref layer %i : %i %i %i %i %i %i, y=%i, z_idx=%i",
714 AliTRDgtuParam::GetRefLayer(trk->GetRefLayerIdx()),
715 trk->GetTrackletIndex(5),
716 trk->GetTrackletIndex(4),
717 trk->GetTrackletIndex(3),
718 trk->GetTrackletIndex(2),
719 trk->GetTrackletIndex(1),
720 trk->GetTrackletIndex(0),
721 trk->GetYapprox() >> 3,
722 trk->GetZSubChannel()));
725 // ----- Merging in zchannels - 1st stage -----
727 if (AliTRDgtuParam::GetUseGTUmerge()) {
730 Bool_t lowerThan[3] = { kFALSE, kFALSE, kFALSE };
731 AliTRDtrackGTU *trk[3] = { 0x0, 0x0, 0x0 };
732 for (Int_t iChannel = 0; iChannel < fGtuParam->GetNZChannels(); ++iChannel)
733 trk[iChannel] = (AliTRDtrackGTU*) tracksRefUnique[iChannel]->First();
735 for (Int_t iChannel = 0; iChannel < fGtuParam->GetNZChannels(); ++iChannel) {
736 AliTRDtrackGTU *trk1 = trk[iChannel];
737 AliTRDtrackGTU *trk2 = trk[(iChannel + 1) % 3];
739 Int_t sortnum1 = (trk1->GetZChannel() + 3 * trk1->GetZSubChannel()) / 2 - 1;
740 Int_t sortnum2 = (trk2->GetZChannel() + 3 * trk2->GetZSubChannel()) / 2 - 1;
741 AliDebug(5, Form("comparing tracks %i - %i: %i - %i",
742 trk1->GetZChannel(), trk2->GetZChannel(),
743 sortnum1, sortnum2));
744 if ( (sortnum1 < sortnum2) ||
745 ((sortnum1 == sortnum2) &&
746 ((trk1->GetYapprox() >> 3) < (trk2->GetYapprox() >> 3)) ) ) {
747 lowerThan[iChannel] = kTRUE;
752 notEmpty = (trk[2] ? (1 << 2) : 0) |
753 (trk[1] ? (1 << 1) : 0) |
754 (trk[0] ? (1 << 0) : 0);
811 tracksZMergedStage0->Add(trk[pop]);
812 tracksRefUnique[pop]->RemoveFirst();
817 // there is still a difference between this implementation and
818 // the hardware algorithm, only for expert use
823 // compare tracks from all adjacent zchannels
824 // (including comparison of channels 2 and 0)
825 for (Int_t i = fGtuParam->GetNZChannels() - 1; i > -1; i--) {
827 AliTRDtrackGTU *trk = (AliTRDtrackGTU*) tracksRefUnique[zch]->First();
831 else if (trkStage0 == 0x0 ) {
837 Int_t sortnum1 = (trk->GetZChannel() + 3 * trk->GetZSubChannel()) / 2 - 1;
838 Int_t sortnum2 = (trkStage0->GetZChannel() + 3 * trkStage0->GetZSubChannel()) / 2 - 1;
839 AliDebug(5, Form("comparing tracks %i - %i: %i - %i",
840 trk->GetZChannel(), trkStage0->GetZChannel(),
841 sortnum1, sortnum2));
842 if ( (sortnum1 < sortnum2) ||
843 ((sortnum1 == sortnum2) &&
844 ((trk->GetYapprox() >> 3) < (trkStage0->GetYapprox() >> 3)) ) ) {
854 tracksZMergedStage0->Add(trkStage0);
855 tracksRefUnique[minIdx]->RemoveFirst();
856 } while (trkStage0 != 0);
859 Uniquifier(tracksZMergedStage0, tracksZUniqueStage0);
861 AliDebug(2, "stage 0:");
862 TIter trackZMergedStage0(tracksZMergedStage0);
863 while (AliTRDtrackGTU *trk = (AliTRDtrackGTU*) trackZMergedStage0())
864 AliDebug(2, Form("track ref layer %i : %i %i %i %i %i %i, y=%i, zch=%i idx=%i",
865 AliTRDgtuParam::GetRefLayer(trk->GetRefLayerIdx()),
866 trk->GetTrackletIndex(5),
867 trk->GetTrackletIndex(4),
868 trk->GetTrackletIndex(3),
869 trk->GetTrackletIndex(2),
870 trk->GetTrackletIndex(1),
871 trk->GetTrackletIndex(0),
872 trk->GetYapprox() >> 3,
874 trk->GetZSubChannel()));
876 AliDebug(2, "uniquified:");
877 TIter trackZUniqueStage0(tracksZUniqueStage0);
878 while (AliTRDtrackGTU *trk = (AliTRDtrackGTU*) trackZUniqueStage0())
879 AliDebug(2, Form("track ref layer %i : %i %i %i %i %i %i, y=%i, zch=%i idx=%i",
880 AliTRDgtuParam::GetRefLayer(trk->GetRefLayerIdx()),
881 trk->GetTrackletIndex(5),
882 trk->GetTrackletIndex(4),
883 trk->GetTrackletIndex(3),
884 trk->GetTrackletIndex(2),
885 trk->GetTrackletIndex(1),
886 trk->GetTrackletIndex(0),
887 trk->GetYapprox() >> 3,
889 trk->GetZSubChannel()));
891 // ----- Splitting in z -----
893 TIter next(tracksZUniqueStage0);
894 while (AliTRDtrackGTU *trk = (AliTRDtrackGTU*) next()) {
895 tracksZSplitted[(trk->GetZChannel() + 3 * (trk->GetZSubChannel() - 1)) % 2]->Add(trk);
898 for (Int_t i = 0; i < 2; i++) {
899 AliDebug(2, Form("split %i:", i));
900 TIter trackZSplit(tracksZSplitted[i]);
901 while (AliTRDtrackGTU *trk = (AliTRDtrackGTU*) trackZSplit())
902 AliDebug(2, Form("track ref layer %i : %i %i %i %i %i %i, y=%i, zch=%i idx=%i",
903 AliTRDgtuParam::GetRefLayer(trk->GetRefLayerIdx()),
904 trk->GetTrackletIndex(5),
905 trk->GetTrackletIndex(4),
906 trk->GetTrackletIndex(3),
907 trk->GetTrackletIndex(2),
908 trk->GetTrackletIndex(1),
909 trk->GetTrackletIndex(0),
910 trk->GetYapprox() >> 3,
912 trk->GetZSubChannel()));
915 // ----- Merging in zchanels - 2nd stage -----
920 for (Int_t i = 1; i >= 0; i--) {
921 AliTRDtrackGTU *trk = (AliTRDtrackGTU*) tracksZSplitted[i]->First();
925 else if (trkStage0 == 0x0 ) {
930 else if ( (((trk->GetZChannel() + 3 * (trk->GetZSubChannel() - 1)) / 2) < ((trkStage0->GetZChannel() + 3 * (trkStage0->GetZSubChannel() - 1)) / 2)) ||
931 ((((trk->GetZChannel() + 3 * (trk->GetZSubChannel() - 1)) / 2) == ((trkStage0->GetZChannel() + 3 * (trkStage0->GetZSubChannel() - 1)) / 2)) &&
932 ((trk->GetYapprox() >> 3) < (trkStage0->GetYapprox() >> 3)) ) ) {
941 tracksZMergedStage1->Add(trkStage0);
942 tracksZSplitted[minIdx]->RemoveFirst();
943 } while (trkStage0 != 0);
945 Uniquifier(tracksZMergedStage1, ListOfTracks);
947 AliDebug(2, "merged:");
948 TIter trackZMergedStage1(tracksZMergedStage1);
949 while (AliTRDtrackGTU *trk = (AliTRDtrackGTU*) trackZMergedStage1())
950 AliDebug(2, Form("track ref layer %i : %i %i %i %i %i %i, y=%i, zch=%i idx=%i",
951 AliTRDgtuParam::GetRefLayer(trk->GetRefLayerIdx()),
952 trk->GetTrackletIndex(5),
953 trk->GetTrackletIndex(4),
954 trk->GetTrackletIndex(3),
955 trk->GetTrackletIndex(2),
956 trk->GetTrackletIndex(1),
957 trk->GetTrackletIndex(0),
958 trk->GetYapprox() >> 3,
960 trk->GetZSubChannel()));
962 AliDebug(2, "uniquified:");
963 TIter track(ListOfTracks);
964 while (AliTRDtrackGTU *trk = (AliTRDtrackGTU*) track())
965 AliDebug(2, Form("track ref layer %i : %i %i %i %i %i %i, y=%i, zch=%i idx=%i",
966 AliTRDgtuParam::GetRefLayer(trk->GetRefLayerIdx()),
967 trk->GetTrackletIndex(5),
968 trk->GetTrackletIndex(4),
969 trk->GetTrackletIndex(3),
970 trk->GetTrackletIndex(2),
971 trk->GetTrackletIndex(1),
972 trk->GetTrackletIndex(0),
973 trk->GetYapprox() >> 3,
975 trk->GetZSubChannel()));
978 for (Int_t zch = 0; zch < fGtuParam->GetNZChannels(); zch++) {
979 delete tracksRefMerged[zch];
980 delete tracksRefUnique[zch];
982 delete [] tracksRefMerged;
983 delete [] tracksRefUnique;
986 delete tracksZMergedStage0;
987 delete tracksZUniqueStage0;
989 for (Int_t i = 0; i < 2; i++)
990 delete tracksZSplitted[i];
991 delete [] tracksZSplitted;
993 delete tracksZMergedStage1;
995 delete [] trkInRefLayer;
1000 Bool_t AliTRDgtuTMU::RunTrackReconstruction(TList* ListOfTracks)
1002 // run the track reconstruction for all tracks in the list
1004 TIter next(ListOfTracks);
1005 while (AliTRDtrackGTU *track = (AliTRDtrackGTU*) next()) {
1006 CalculateTrackParams(track);
1007 CalculatePID(track);
1008 AliDebug(1, Form("track with pid = %i", track->GetPID()));
1013 Bool_t AliTRDgtuTMU::CalculatePID(AliTRDtrackGTU *track)
1015 // calculate PID for the given track
1017 AliError("No track to calculate!");
1021 if (AliTRDgtuParam::GetUseGTUconst()) {
1022 // averaging as in GTU
1023 AliDebug(1, "using GTU constants for PID calculation");
1026 // selection of coefficient for averaging
1027 switch(track->GetTrackletMask()){
1030 coeff=0x5558; // approx. 1/6
1040 coeff=0x6666; // approx. 1/5
1045 coeff=0x8000; // = 0.25
1047 coeff &= 0x1ffff; // 17-bit constant
1051 for (Int_t iLayer = 0; iLayer < fGtuParam->GetNLayers(); iLayer++) {
1052 if ((track->GetTrackletMask() >> iLayer) & 1) {
1053 sum += track->GetTracklet(iLayer)->GetPID();
1058 Float_t av = 1./i * sum;
1060 ULong64_t prod = (sum * coeff) & 0xfffffffffull;
1061 ULong64_t prodFinal = ((prod >> 17) + ((prod >> 16) & 1)) & 0xff;
1063 if (TMath::Abs((prodFinal & 0xff) - av) > 0.5)
1064 AliError(Form("problem with PID averaging (hw <-> ar): %3lli <-> %4.1f", prodFinal & 0xff, av));
1065 track->SetPID(prodFinal & 0xff);
1072 Int_t nTracklets = 0;
1074 for (Int_t layer = 0; layer < fGtuParam->GetNLayers(); layer++) {
1075 if (!track->IsTrackletInLayer(layer)) {
1078 AliTRDtrackletGTU *trk = track->GetTracklet(layer);
1079 pidSum += trk->GetPID();
1084 track->SetPID(pidSum/nTracklets);
1086 AliError("Track without contributing tracklets, no PID assigned");
1092 Bool_t AliTRDgtuTMU::CalculateTrackParams(AliTRDtrackGTU *track)
1094 // calculate the track parameters
1097 AliError("No track to calculate!");
1107 AliDebug(5,Form("There are %i tracklets in this track.", track->GetNTracklets()));
1109 for (Int_t layer = 0; layer < fGtuParam->GetNLayers(); layer++) {
1110 if (!track->IsTrackletInLayer(layer)) {
1113 AliTRDtrackletGTU *trk = track->GetTracklet(layer);
1115 AliError(Form("Could not get tracklet in layer %i\n", layer));
1118 AliDebug(10,Form(" layer %i trk yprime: %6i, aki: %6i", layer, trk->GetYPrime(),
1119 fGtuParam->GetAki(track->GetTrackletMask(), layer)));
1120 a += (((fGtuParam->GetAki(track->GetTrackletMask(), layer) * trk->GetYPrime()) >> 7) + 1) >> 1;
1121 b += fGtuParam->GetBki(track->GetTrackletMask(), layer) * trk->GetYPrime() * fGtuParam->GetBinWidthY();
1122 c += fGtuParam->GetCki(track->GetTrackletMask(), layer) * trk->GetYPrime() * fGtuParam->GetBinWidthY();
1128 track->SetFitParams(a << 2, b, c);
1130 fGtuParam->GetIntersectionPoints(track->GetTrackletMask(), x1, x2);
1132 AliDebug(5,Form(" Track parameters: a16 = %i, a18 = %i, b = %f, c = %f, x1 = %f, x2 = %f, pt = %f (trkl mask: %i)",
1133 a, a << 2, b, c, x1, x2, track->GetPt(), track->GetTrackletMask()));
1139 Bool_t AliTRDgtuTMU::Uniquifier(const TList *inlist, TList *outlist)
1141 // remove multiple occurences of the same track
1144 AliTRDtrackGTU *trkStage0 = 0x0;
1145 AliTRDtrackGTU *trkStage1 = 0x0;
1148 trkStage0 = (AliTRDtrackGTU*) next();
1150 Bool_t tracksEqual = kFALSE;
1151 if (trkStage0 != 0 && trkStage1 != 0) {
1152 for (Int_t layer = 0; layer < fGtuParam->GetNLayers(); layer++) {
1153 if (trkStage0->GetTrackletIndex(layer) != -1 && trkStage0->GetTrackletIndex(layer) == trkStage1->GetTrackletIndex(layer)) {
1154 tracksEqual = kTRUE;
1161 if (trkStage0->GetNTracklets() >= trkStage1->GetNTracklets())
1162 trkStage1 = trkStage0;
1165 if (trkStage1 != 0x0)
1166 outlist->Add(trkStage1);
1167 trkStage1 = trkStage0;
1170 } while (trkStage1 != 0x0);