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 AliDebug(2,Form("Track finder for Zchannel: %i", zch));
199 if (!RunTrackFinder(zch, ListOfTracks)) {
200 AliError(Form("Track Finder in z-channel %i failed", zch));
205 // ----- Track Merging -----
206 if (!RunTrackMerging(ListOfTracks)) {
207 AliError("Track merging failed");
211 // ----- track reconstruction -----
212 if (!RunTrackReconstruction(ListOfTracks)) {
213 AliError("Track reconstruction failed");
218 TIter next(ListOfTracks);
219 while (AliTRDtrackGTU *trk = (AliTRDtrackGTU*) next()) {
220 AliESDTrdTrack *trdtrack = trk->CreateTrdTrack();
221 esd->AddTrdTrack(trdtrack);
229 Bool_t AliTRDgtuTMU::RunInputUnit(Int_t layer)
231 // precalculations for the tracking and reconstruction
233 Int_t iTrkl0 = 0; // A-side tracklet
234 Int_t iTrkl1 = 0; // B-side tracklet
236 while ((iTrkl0 < fTracklets[2*layer + 0]->GetEntriesFast()) || (iTrkl1 < fTracklets[2*layer + 1]->GetEntriesFast())) {
237 if (iTrkl1 >= fTracklets[2*layer + 1]->GetEntriesFast()) {
238 fTrackletsPostInput[layer]->AddLast(fTracklets[2*layer + 0]->At(iTrkl0));
242 if (iTrkl0 >= fTracklets[2*layer + 0]->GetEntriesFast()) {
243 fTrackletsPostInput[layer]->AddLast(fTracklets[2*layer + 1]->At(iTrkl1));
247 if (((AliTRDtrackletGTU*) fTracklets[2*layer + 1]->At(iTrkl1))->GetZbin() <
248 ((AliTRDtrackletGTU*) fTracklets[2*layer + 0]->At(iTrkl0))->GetZbin()) {
249 fTrackletsPostInput[layer]->AddLast(fTracklets[2*layer + 1]->At(iTrkl1));
254 fTrackletsPostInput[layer]->AddLast(fTracklets[2*layer + 0]->At(iTrkl0));
261 TIter next(fTrackletsPostInput[layer]);
263 while ( AliTRDtrackletGTU *trk = (AliTRDtrackletGTU*) next() ) {
264 trk->SetIndex(fTrackletsPostInput[layer]->IndexOf(trk));
266 Int_t alpha = (trk->GetYbin() >> fGtuParam->GetBitExcessY()) * fGtuParam->GetCiAlpha(layer);
267 alpha = ( 2 * trk->GetdY() - (alpha >> fGtuParam->GetBitExcessAlpha()) + 1 ) >> 1;
268 trk->SetAlpha(alpha);
270 Int_t yproj = trk->GetdY() * (fGtuParam->GetCiYProj(layer)); //??? sign?
271 yproj = ( ( ( (yproj >> fGtuParam->GetBitExcessYProj()) + trk->GetYbin() ) >> 2) + 1) >> 1;
272 trk->SetYProj(yproj);
274 trk->SetYPrime(trk->GetYbin() + fGtuParam->GetYt(fStack, layer, trk->GetZbin()));
276 AliDebug(10, Form("0x%08x: idx: %3i, z: %2i, y: %5i, dy: %3i, y': %5i, y_proj: %5i, alpha: %3i, pid: %3i",
277 trk->GetTrackletWord(), trk->GetIndex(), trk->GetZbin(), trk->GetYbin(), trk->GetdY(), trk->GetYPrime(),
278 trk->GetYProj(), trk->GetAlpha(), trk->GetPID() ));
283 Bool_t AliTRDgtuTMU::RunZChannelUnit(Int_t layer)
285 // run the z-channel unit
287 TIter next(fTrackletsPostInput[layer]);
289 while (AliTRDtrackletGTU *trk = (AliTRDtrackletGTU*) next()) {
290 for (Int_t zch = 0; zch < fGtuParam->GetNZChannels(); zch++) {
291 if (fGtuParam->IsInZChannel(fStack, layer, zch, trk->GetZbin()) ) {
292 trk->SetSubChannel(zch, fGtuParam->GetZSubchannel(fStack, layer, zch, trk->GetZbin()) );
294 TIter nexttrkl(&fZChannelTracklets[layer][zch], kIterBackward);
295 AliTRDtrackletGTU *t = 0x0;
296 while ((t = (AliTRDtrackletGTU*) nexttrkl.Next())) {
297 if (t->GetSubChannel(zch) < trk->GetSubChannel(zch) ||
298 ((t->GetSubChannel(zch) == trk->GetSubChannel(zch)) && (t->GetYProj() < trk->GetYProj())) ) {
303 fZChannelTracklets[layer][zch].AddAfter(t, trk);
305 fZChannelTracklets[layer][zch].AddFirst(trk);
308 AliDebug(10, Form("stack %d, layer %2d: 0x%08x Z(2..0)=%i/%i/%i",
309 fStack, layer, trk->GetTrackletWord(),
310 fGtuParam->IsInZChannel(fStack, layer, 2, trk->GetZbin()) ? trk->GetSubChannel(2) : -1,
311 fGtuParam->IsInZChannel(fStack, layer, 1, trk->GetZbin()) ? trk->GetSubChannel(1) : -1,
312 fGtuParam->IsInZChannel(fStack, layer, 0, trk->GetZbin()) ? trk->GetSubChannel(0) : -1
318 Bool_t AliTRDgtuTMU::RunTrackFinder(Int_t zch, TList* /* ListOfTracks */)
320 // run the track finding
322 Int_t *notr = new Int_t[fGtuParam->GetNLayers()];
323 Int_t *ptrA = new Int_t[fGtuParam->GetNLayers()];
324 Int_t *ptrB = new Int_t[fGtuParam->GetNLayers()];
326 Bool_t *bHitA = new Bool_t[fGtuParam->GetNLayers()];
327 Bool_t *bHitB = new Bool_t[fGtuParam->GetNLayers()];
328 Bool_t *bAligned = new Bool_t[fGtuParam->GetNLayers()];
329 Bool_t *bAlignedA = new Bool_t[fGtuParam->GetNLayers()];
330 Bool_t *bAlignedB = new Bool_t[fGtuParam->GetNLayers()];
331 Bool_t *bDone = new Bool_t[fGtuParam->GetNLayers()];
334 Int_t *inc = new Int_t[fGtuParam->GetNLayers()];
335 Int_t *incprime = new Int_t[fGtuParam->GetNLayers()];
337 // ----- signals within current layer -----
348 AliTRDtrackletGTU *trkRA = 0x0; // reference tracklet A
349 AliTRDtrackletGTU *trkRB = 0x0; // reference tracklet B
350 AliTRDtrackletGTU *trkA = 0x0; // tracklet A in current layer
351 AliTRDtrackletGTU *trkB = 0x0; // tracklet B in current layer
353 AliTRDtrackletGTU *trkEnd = new AliTRDtrackletGTU();
354 for (Int_t i = 0; i < fGtuParam->GetNZChannels(); i++)
355 trkEnd->SetSubChannel(i, 7);
360 for (Int_t refLayerIdx = 0; refLayerIdx < fGtuParam->GetNRefLayers(); refLayerIdx++) {
361 Int_t reflayer = fGtuParam->GetRefLayer(refLayerIdx);
362 AliDebug(5,Form("~~~~~ Reflayer: %i", reflayer));
364 ready = kFALSE; // ready if all channels done
366 // for (Int_t iLayer = 0; iLayer < fGtuParam->GetNLayers(); iLayer++) {
367 // for (Int_t iTrkl = 0; iTrkl < fZChannelTracklets[iLayer][zch].GetEntries(); iTrkl++) {
368 // printf("%4i/%4i(%i,%i) ",
369 // ((AliTRDtrackletGTU*) fZChannelTracklets[iLayer][zch].At(iTrkl))->GetYProj(),
370 // ((AliTRDtrackletGTU*) fZChannelTracklets[iLayer][zch].At(iTrkl))->GetAlpha(),
371 // ((AliTRDtrackletGTU*) fZChannelTracklets[iLayer][zch].At(iTrkl))->GetIndex(),
372 // ((AliTRDtrackletGTU*) fZChannelTracklets[iLayer][zch].At(iTrkl))->GetSubChannel(zch)
378 for (Int_t layer = 0; layer < fGtuParam->GetNLayers(); layer++) {
379 notr[layer] = fZChannelTracklets[layer][zch].GetEntries();
380 ptrA[layer] = 0; // notr[layer] > 0 ? 0 : -1;
381 ptrB[layer] = 1; // notr[layer] > 1 ? 1 : -1;
383 // not necessary here
384 // bDone[layer] = (ptrB[layer] >= notr[layer] - 1); // trkB is last one
385 // bDone[layer] = (notr[layer] <= 0);
386 // ready = ready && bDone[layer];
389 AliDebug(5,Form("in layer: %i (zchannel = %i) there are: %i tracklets", layer, zch, notr[layer]));
392 if (ptrA[reflayer] < 0 && ptrB[reflayer] < 0)
396 // ----- reference tracklets -----
399 if (0 <= ptrA[reflayer] && ptrA[reflayer] < notr[reflayer])
400 trkRA = (AliTRDtrackletGTU*) fZChannelTracklets[reflayer][zch].At(ptrA[reflayer]);
402 AliDebug(10,Form("No valid tracklet in the reference at ptr: %i! Nothing done!", ptrA[reflayer]));
406 if (0 <= ptrB[reflayer] && ptrB[reflayer] < notr[reflayer])
407 trkRB = (AliTRDtrackletGTU*) fZChannelTracklets[reflayer][zch].At(ptrB[reflayer]);
409 AliDebug(10,Form("ptrRA: %i, ptrRB: %i", ptrA[reflayer], ptrB[reflayer]));
410 yPlus = trkRA->GetYProj() + fGtuParam->GetDeltaY();
411 yMinus = trkRA->GetYProj() - fGtuParam->GetDeltaY();
412 alphaPlus = trkRA->GetAlpha() + fGtuParam->GetDeltaAlpha();
413 alphaMinus = trkRA->GetAlpha() - fGtuParam->GetDeltaAlpha();
415 ybPlus = trkRB->GetYProj() + fGtuParam->GetDeltaY();
416 ybMinus = trkRB->GetYProj() - fGtuParam->GetDeltaY();
418 else { // irrelevant (should be, is it?)
419 ybPlus = trkRA->GetYProj() + fGtuParam->GetDeltaY();
420 ybMinus = trkRA->GetYProj() - fGtuParam->GetDeltaY();
427 for (Int_t layer = 0; layer < fGtuParam->GetNLayers(); layer++) {
428 bHitA[layer] = bHitB[layer] = bAligned[layer] = kFALSE;
429 inc[layer] = incprime[layer] = 0;
431 if (layer == reflayer) {
432 bHitA[layer] = kTRUE;
433 bAligned[layer] = kTRUE;
440 if (0 <= ptrA[layer] && ptrA[layer] < notr[layer])
441 trkA = (AliTRDtrackletGTU*) fZChannelTracklets[layer][zch].At(ptrA[layer]);
442 if (0 <= ptrB[layer] && ptrB[layer] < notr[layer])
443 trkB = (AliTRDtrackletGTU*) fZChannelTracklets[layer][zch].At(ptrB[layer]);
445 bAlignedA[layer] = kFALSE;
446 bAlignedB[layer] = kFALSE;
449 bHitA[layer] = ( !(trkA->GetSubChannel(zch) < trkRA->GetSubChannel(zch) || (trkA->GetSubChannel(zch) == trkRA->GetSubChannel(zch) && trkA->GetYProj() < yMinus) ) &&
450 !(trkA->GetSubChannel(zch) > trkRA->GetSubChannel(zch) || (trkA->GetSubChannel(zch) == trkRA->GetSubChannel(zch) && trkA->GetYProj() > yPlus) ) &&
451 !(trkA->GetAlpha() < alphaMinus) &&
452 !(trkA->GetAlpha() > alphaPlus) );
453 bAlignedA[layer] = !(trkA->GetSubChannel(zch) < trkRA->GetSubChannel(zch) || (trkA->GetSubChannel(zch) == trkRA->GetSubChannel(zch) && trkA->GetYProj() < yMinus) );
457 bAlignedA[layer] = kTRUE;
461 bHitB[layer] = ( !(trkB->GetSubChannel(zch) < trkRA->GetSubChannel(zch) || (trkB->GetSubChannel(zch) == trkRA->GetSubChannel(zch) && trkB->GetYProj() < yMinus) ) &&
462 !(trkB->GetSubChannel(zch) > trkRA->GetSubChannel(zch) || (trkB->GetSubChannel(zch) == trkRA->GetSubChannel(zch) && trkB->GetYProj() > yPlus) ) &&
463 !(trkB->GetAlpha() < alphaMinus) &&
464 !(trkB->GetAlpha() > alphaPlus) );
465 bAlignedB[layer] = (trkB->GetSubChannel(zch) > trkRA->GetSubChannel(zch) || (trkB->GetSubChannel(zch) == trkRA->GetSubChannel(zch) && trkB->GetYProj() > yPlus) );
469 bAlignedB[layer] = kTRUE;
472 bAligned[layer] = bAlignedA[layer] || bAlignedB[layer]; //???
473 // bAligned[layer] = bAlignedA[layer]; //???
475 if (bAligned[layer] && (bHitA[layer] || bHitB[layer]) )
477 else if (!bAligned[layer] )
481 if ((trkA->GetSubChannel(zch) > trkRB->GetSubChannel(zch)) || (trkA->GetSubChannel(zch) == trkRB->GetSubChannel(zch) && trkA->GetYProj() > ybPlus) )
488 // pre-calculation for the layer shifting (alignment w. r. t. trkRB)
491 if ((trkA->GetSubChannel(zch) < trkRB->GetSubChannel(zch)) || (trkA->GetSubChannel(zch) == trkRB->GetSubChannel(zch) && trkA->GetYProj() < ybMinus )) // could trkA be aligned for trkRB
501 if ((trkB->GetSubChannel(zch) < trkRB->GetSubChannel(zch)) || (trkB->GetSubChannel(zch) == trkRB->GetSubChannel(zch) && trkB->GetYProj() < ybMinus )) // could trkB be aligned for trkRB
508 } // end of loop over layers
510 AliDebug(5,Form("logic calculation finished, Nhits: %i", nHits));
513 // ----- track registration -----
514 AliDebug(1,"***** TMU: Track found *****");
515 AliTRDtrackGTU *track = new AliTRDtrackGTU();
516 track->SetSector(fSector);
517 track->SetStack(fStack);
518 for (Int_t layer = 0; layer < fGtuParam->GetNLayers(); layer++ ) {
519 if (bHitA[layer] || layer == reflayer)
520 track->AddTracklet((AliTRDtrackletGTU* ) fZChannelTracklets[layer][zch].At(ptrA[layer]), layer );
521 else if (bHitB[layer])
522 track->AddTracklet((AliTRDtrackletGTU* ) fZChannelTracklets[layer][zch].At(ptrB[layer]), layer );
525 Bool_t registerTrack = kTRUE;
526 for (Int_t layerIdx = refLayerIdx-1; layerIdx >= 0; layerIdx--) {
527 if (track->IsTrackletInLayer(fGtuParam->GetRefLayer(layerIdx))) {
528 if ((track->GetTracklet(fGtuParam->GetRefLayer(layerIdx)))->GetSubChannel(zch) > 0) {
529 AliDebug(1,"Not registered");
530 registerTrack = kFALSE;
535 track->SetZChannel(zch);
536 track->SetRefLayerIdx(refLayerIdx);
537 fTracks[zch][refLayerIdx].Add(track);
541 if ( (nUnc != 0) && (nUnc + nHits >= 4) ) // could this position of the reference layer give some track //??? special check in case of hit?
543 else if (nWayBeyond > 2) // no track possible for both reference tracklets
548 if (inc[reflayer] != 0) // reflayer is shifted
549 for (Int_t layer = 0; layer < fGtuParam->GetNLayers(); layer++) {
550 if (layer == reflayer)
552 inc[layer] = incprime[layer];
554 else { // reflayer is not shifted
555 for (Int_t layer = 0; layer < fGtuParam->GetNLayers(); layer++) {
556 if (layer == reflayer || notr[layer] == 0)
561 if (0 <= ptrA[layer] && ptrA[layer] < notr[layer])
562 trkA = (AliTRDtrackletGTU*) fZChannelTracklets[layer][zch].At(ptrA[layer]);
564 if (0 <= ptrB[layer] && ptrB[layer] < notr[layer])
565 trkB = (AliTRDtrackletGTU*) fZChannelTracklets[layer][zch].At(ptrB[layer]);
568 if ( !(trkA->GetSubChannel(zch) < trkRA->GetSubChannel(zch) || (trkA->GetSubChannel(zch) == trkRA->GetSubChannel(zch) && trkA->GetYProj() < yMinus) ) &&
569 !(trkA->GetSubChannel(zch) > trkRA->GetSubChannel(zch) || (trkA->GetSubChannel(zch) == trkRA->GetSubChannel(zch) && trkA->GetYProj() > yPlus ) ) ) // trkA could hit trkRA
570 // if ( !(trkA->GetSubChannel(zch) < trkRA->GetSubChannel(zch) || (trkA->GetSubChannel(zch) == trkRA->GetSubChannel(zch) && trkA->GetYProj() < yMinus) ) )
573 if ( trkB->GetSubChannel(zch) < trkRA->GetSubChannel(zch) || (trkB->GetSubChannel(zch) == trkRA->GetSubChannel(zch) && trkB->GetYProj() < yMinus) )
575 else if ( !(trkB->GetSubChannel(zch) > trkRA->GetSubChannel(zch) || (trkB->GetSubChannel(zch) == trkRA->GetSubChannel(zch) && trkB->GetYProj() > yPlus) ) )
578 inc[layer] = incprime[layer];
581 inc[layer] = incprime[layer];
587 for (Int_t layer = 0; layer < fGtuParam->GetNLayers(); layer++) {
589 bDone[layer] = ptrB[layer] < 0 || ptrB[layer] >= notr[layer];
590 ready = ready && bDone[layer];
592 if (inc[layer] != 0 && ptrA[layer] >= notr[layer])
593 AliError(Form("Invalid increment: %i at ptrA: %i, notr: %i", inc[layer], ptrA[layer], notr[layer]));
595 // AliInfo(Form("Shifting layer: %i, notr: %i, ptrA: %i, ptrB: %i, inc: %i", layer, notr[layer], ptrA[layer], ptrB[layer], inc[layer]));
596 AliDebug(10,Form(" -- Layer: %i %2i(%2i)%s%s %2i(%2i)%s%s +%i %s (no: %i)",
599 (0 <= ptrA[layer] && ptrA[layer] < notr[layer]) ? ((AliTRDtrackletGTU*) fZChannelTracklets[layer][zch].At(ptrA[layer]))->GetIndex() : -1,
600 bHitA[layer] ? "*" : " ", bAlignedA[layer] ? "+" : " ",
602 (0 <= ptrB[layer] && ptrB[layer] < notr[layer]) ? ((AliTRDtrackletGTU*) fZChannelTracklets[layer][zch].At(ptrB[layer]))->GetIndex() : -1,
603 bHitB[layer] ? "*" : " ", bAlignedB[layer] ? "+" : " ",
604 inc[layer], bDone[layer] ? "done" : " ", notr[layer]));
605 ptrA[layer] += inc[layer];
606 ptrB[layer] += inc[layer];
610 } // end of loop over reflayer
627 Bool_t AliTRDgtuTMU::RunTrackMerging(TList* ListOfTracks)
629 TList **tracksRefMerged = new TList*[fGtuParam->GetNZChannels()];
630 TList **tracksRefUnique = new TList*[fGtuParam->GetNZChannels()];
632 for (Int_t zch = 0; zch < fGtuParam->GetNZChannels(); zch++) {
633 tracksRefMerged[zch] = new TList;
634 tracksRefUnique[zch] = new TList;
637 TList *tracksZMergedStage0 = new TList;
638 TList *tracksZUniqueStage0 = new TList;
640 TList **tracksZSplitted = new TList*[2];
641 for (Int_t i = 0; i < 2; i++)
642 tracksZSplitted[i] = new TList;
644 TList *tracksZMergedStage1 = new TList;
646 AliTRDtrackGTU **trkInRefLayer = new AliTRDtrackGTU*[fGtuParam->GetNRefLayers()];
648 Bool_t done = kFALSE;
650 AliTRDtrackGTU *trkStage0 = 0x0;
652 for (Int_t zch = 0; zch < fGtuParam->GetNZChannels(); zch++) {
653 // ----- Merging and Unification in Reflayers (seed_merger) -----
657 for (Int_t refLayerIdx = 0; refLayerIdx < fGtuParam->GetNRefLayers(); refLayerIdx++) {
658 trkInRefLayer[refLayerIdx] = (AliTRDtrackGTU*) fTracks[zch][refLayerIdx].First();
659 if (trkInRefLayer[refLayerIdx] == 0) {
662 else if (trkStage0 == 0x0 ) {
663 trkStage0 = trkInRefLayer[refLayerIdx];
664 minIdx = refLayerIdx;
667 else if (trkInRefLayer[refLayerIdx]->GetZSubChannel() < trkStage0->GetZSubChannel() ||
668 (trkInRefLayer[refLayerIdx]->GetZSubChannel() == trkStage0->GetZSubChannel() && trkInRefLayer[refLayerIdx]->GetYapprox() < trkStage0->GetYapprox()) ) {
669 minIdx = refLayerIdx;
670 trkStage0 = trkInRefLayer[refLayerIdx];
676 tracksRefMerged[zch]->Add(trkStage0);
677 fTracks[zch][minIdx].RemoveFirst();
678 } while (trkStage0 != 0);
680 Uniquifier(tracksRefMerged[zch], tracksRefUnique[zch]);
682 AliDebug(2, Form("zchannel %i", zch));
683 TIter trackRefMerged(tracksRefMerged[zch]);
684 while (AliTRDtrackGTU *trk = (AliTRDtrackGTU*) trackRefMerged())
685 AliDebug(2, Form("track ref layer %i : %i %i %i %i %i %i, y=%i, z_idx=%i",
686 trk->GetRefLayerIdx(),
687 trk->GetTrackletIndex(5),
688 trk->GetTrackletIndex(4),
689 trk->GetTrackletIndex(3),
690 trk->GetTrackletIndex(2),
691 trk->GetTrackletIndex(1),
692 trk->GetTrackletIndex(0),
693 trk->GetYapprox() >> 3,
694 trk->GetZSubChannel()));
695 AliDebug(2, "uniquified:");
696 TIter trackRefUnique(tracksRefUnique[zch]);
697 while (AliTRDtrackGTU *trk = (AliTRDtrackGTU*) trackRefUnique())
698 AliDebug(2, Form("track ref layer %i : %i %i %i %i %i %i, y=%i, z_idx=%i",
699 trk->GetRefLayerIdx(),
700 trk->GetTrackletIndex(5),
701 trk->GetTrackletIndex(4),
702 trk->GetTrackletIndex(3),
703 trk->GetTrackletIndex(2),
704 trk->GetTrackletIndex(1),
705 trk->GetTrackletIndex(0),
706 trk->GetYapprox() >> 3,
707 trk->GetZSubChannel()));
710 // ----- Merging in zchannels - 1st stage -----
715 for (Int_t zch = fGtuParam->GetNZChannels() - 1; zch > -1; zch--) {
716 AliTRDtrackGTU *trk = (AliTRDtrackGTU*) tracksRefUnique[zch]->First();
720 else if (trkStage0 == 0x0 ) {
725 else if ( ((trk->GetZChannel() + 3 * trk->GetZSubChannel()) / 2 - 1) < ((trkStage0->GetZChannel() + 3 * trkStage0->GetZSubChannel()) / 2 -1 ) ) {
734 tracksZMergedStage0->Add(trkStage0);
735 tracksRefUnique[minIdx]->RemoveFirst();
736 } while (trkStage0 != 0);
738 Uniquifier(tracksZMergedStage0, tracksZUniqueStage0);
740 // ----- Splitting in z -----
742 TIter next(tracksZUniqueStage0);
743 while (AliTRDtrackGTU *trk = (AliTRDtrackGTU*) next()) {
744 tracksZSplitted[(trk->GetZChannel() + 3 * (trk->GetZSubChannel() - 1)) % 2]->Add(trk);
747 // ----- Merging in zchanels - 2nd stage -----
752 for (Int_t i = 1; i >= 0; i--) {
753 AliTRDtrackGTU *trk = (AliTRDtrackGTU*) tracksZSplitted[i]->First();
757 else if (trkStage0 == 0x0 ) {
762 else if ( ((trk->GetZChannel() + 3 * (trk->GetZSubChannel() - 1)) / 2) < ((trkStage0->GetZChannel() + 3 * (trkStage0->GetZSubChannel() - 1)) / 2) ) {
771 tracksZMergedStage1->Add(trkStage0);
772 tracksZSplitted[minIdx]->RemoveFirst();
773 } while (trkStage0 != 0);
775 Uniquifier(tracksZMergedStage1, ListOfTracks);
778 for (Int_t zch = 0; zch < fGtuParam->GetNZChannels(); zch++) {
779 delete tracksRefMerged[zch];
780 delete tracksRefUnique[zch];
782 delete [] tracksRefMerged;
783 delete [] tracksRefUnique;
786 delete tracksZMergedStage0;
787 delete tracksZUniqueStage0;
789 for (Int_t i = 0; i < 2; i++)
790 delete tracksZSplitted[i];
791 delete [] tracksZSplitted;
793 delete tracksZMergedStage1;
795 delete [] trkInRefLayer;
800 Bool_t AliTRDgtuTMU::RunTrackReconstruction(TList* ListOfTracks)
802 // run the track reconstruction for all tracks in the list
804 TIter next(ListOfTracks);
805 while (AliTRDtrackGTU *track = (AliTRDtrackGTU*) next()) {
806 CalculateTrackParams(track);
808 AliDebug(1, Form("track with pid = %i", track->GetPID()));
813 Bool_t AliTRDgtuTMU::CalculatePID(AliTRDtrackGTU *track)
815 // calculate PID for the given track
817 AliError("No track to calculate!");
821 if (AliTRDgtuParam::GetUseGTUconst()) {
822 // averaging as in GTU
825 // selection of coefficient for averaging
826 switch(track->GetTrackletMask()){
829 coeff=0x5558; // approx. 1/6
839 coeff=0x6666; // approx. 1/5
844 coeff=0x8000; // = 0.25
846 coeff &= 0x1ffff; // 17-bit constant
849 for (Int_t iLayer = 0; iLayer < fGtuParam->GetNLayers(); iLayer++) {
850 if ((track->GetTrackletMask() >> iLayer) & 1) {
851 sum += track->GetTracklet(iLayer)->GetPID();
855 ULong64_t sumExt = (sum << 1) & 0xfff; // 11 bit -> 12 bit vector
856 ULong64_t prod = (sumExt * coeff) & 0xfffffffffull; // 18x18 signed -> 36
857 ULong64_t prodFinal = ((prod >> 18) + ((prod >> 17) & 1)) & 0xff; // rounding term is equivalent to adding 5 to sum_ext
859 track->SetPID(prodFinal & 0xff);
866 Int_t nTracklets = 0;
868 for (Int_t layer = 0; layer < fGtuParam->GetNLayers(); layer++) {
869 if (!track->IsTrackletInLayer(layer)) {
872 AliTRDtrackletGTU *trk = track->GetTracklet(layer);
873 pidSum += trk->GetPID();
876 track->SetPID(pidSum/nTracklets);
882 Bool_t AliTRDgtuTMU::CalculateTrackParams(AliTRDtrackGTU *track)
884 // calculate the track parameters
887 AliError("No track to calculate!");
897 AliDebug(5,Form("There are %i tracklets in this track.", track->GetNTracklets()));
899 for (Int_t layer = 0; layer < fGtuParam->GetNLayers(); layer++) {
900 if (!track->IsTrackletInLayer(layer)) {
903 AliTRDtrackletGTU *trk = track->GetTracklet(layer);
905 AliError(Form("Could not get tracklet in layer %i\n", layer));
908 AliDebug(10,Form("trk yprime: %i", trk->GetYPrime()));
909 a += (((Int_t) (2048 * fGtuParam->GetAki(track->GetTrackletMask(), layer))) * trk->GetYPrime() + 1) >> 8;
910 b += fGtuParam->GetBki(track->GetTrackletMask(), layer) * trk->GetYPrime() * fGtuParam->GetBinWidthY();
911 c += fGtuParam->GetCki(track->GetTrackletMask(), layer) * trk->GetYPrime() * fGtuParam->GetBinWidthY();
917 fGtuParam->GetIntersectionPoints(track->GetTrackletMask(), x1, x2);
918 AliDebug(10,Form("Intersection points: %f, %f", x1, x2));
919 AliDebug(10,Form("Sum: a = %5i, b = %9.2f, c = %9.2f\n", a, b, c));
920 track->SetFitParams(a, b, c);
922 Int_t pt = fGtuParam->GetPt(track->GetTrackletMask(), a, b, x1, x2);
924 AliDebug(5,Form("Track parameters: a = %i, b = %f, c = %f, x1 = %f, x2 = %f, pt = %f (trkl mask: %i)", a, b, c, x1, x2, track->GetPt(), track->GetTrackletMask()));
928 Bool_t AliTRDgtuTMU::WriteTrackletsToTree(TTree *trklTree)
931 AliError("No tree given");
934 AliTRDtrackletGTU *trkl = 0x0;
935 TBranch *branch = trklTree->GetBranch("gtutracklets");
937 branch = trklTree->Branch("gtutracklets", "AliTRDtrackletGTU", &trkl, 32000, 99);
940 AliDebug(5,Form("---------- Writing tracklets to tree (not yet) ----------"));
941 for (Int_t layer = 0; layer < fGtuParam->GetNLayers(); layer++) {
942 TIter next(fTrackletsPostInput[layer]);
943 while ((trkl = (AliTRDtrackletGTU*) next())) {
944 AliDebug(10,Form("InputUnit : GetIndex(): %3i, GetZbin(): %2i, GetY() : %5i, GetdY() : %3i, GetYPrime() : %5i, GetYProj() : %5i, GetAlpha() : %3i, Zidx(2..0): %i %i %i", trkl->GetIndex(), trkl->GetZbin(), trkl->GetYbin(), trkl->GetdY(), trkl->GetYPrime(), trkl->GetYProj(), trkl->GetAlpha(), trkl->GetSubChannel(2), trkl->GetSubChannel(1), trkl->GetSubChannel(0) ));
945 branch->SetAddress(&trkl);
952 Bool_t AliTRDgtuTMU::Uniquifier(TList *inlist, TList *outlist)
954 // remove multiple occurences of the same track
957 AliTRDtrackGTU *trkStage0 = 0x0;
958 AliTRDtrackGTU *trkStage1 = 0x0;
961 trkStage0 = (AliTRDtrackGTU*) next();
963 Bool_t tracksEqual = kFALSE;
964 if (trkStage0 != 0 && trkStage1 != 0) {
965 for (Int_t layer = 0; layer < fGtuParam->GetNLayers(); layer++) {
966 if (trkStage0->GetTrackletIndex(layer) != -1 && trkStage0->GetTrackletIndex(layer) == trkStage1->GetTrackletIndex(layer)) {
974 if (trkStage0->GetNTracklets() >= trkStage1->GetNTracklets())
975 trkStage1 = trkStage0;
978 if (trkStage1 != 0x0)
979 outlist->Add(trkStage1);
980 trkStage1 = trkStage0;
983 } while (trkStage1 != 0x0);