]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDtrigger.cxx
First round of effc++ changes
[u/mrichter/AliRoot.git] / TRD / AliTRDtrigger.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 ///////////////////////////////////////////////////////////////////////////////
17 //                                                                           //
18 //                                                                           //
19 //  TRD trigger class                                                        //
20 //                                                                           //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include <TTree.h>
25 #include <TBranch.h>
26 #include <TMatrixD.h>
27
28 #include "AliLog.h"
29 #include "AliRun.h"
30 #include "AliLoader.h"
31
32 #include "AliTRDdigitsManager.h"
33 #include "AliTRDgeometry.h"
34 #include "AliTRDdataArrayI.h"
35 #include "AliTRDcalibDB.h"
36 #include "AliTRDCommonParam.h"
37 #include "Cal/AliTRDCalPIDLQ.h"
38 #include "AliTRDrawData.h"
39
40 #include "AliTRDtrigger.h"
41 #include "AliTRDmodule.h"
42 #include "AliTRDmcmTracklet.h"
43 #include "AliTRDtrigParam.h"
44 #include "AliTRDmcm.h"
45 #include "AliTRDzmaps.h"
46
47 //#include "AliHeader.h"
48
49 ClassImp(AliTRDtrigger)
50
51 //_____________________________________________________________________________
52 AliTRDtrigger::AliTRDtrigger():
53   TNamed(),
54   fTracks("AliTRDgtuTrack",0)
55 {
56   //
57   // AliTRDtrigger default constructor
58   //
59
60   fDigitsManager = NULL;
61   fTrackletTree = NULL;
62   fTracklets     = NULL;
63
64   fNROB = 0;
65   fTrigParam = NULL;
66   fMCM = NULL;
67   fTrk = NULL;
68   fTrkTest = NULL;
69   fGTUtrk = NULL;
70
71   fNtracklets = 0;
72
73   fDigits = NULL;
74   fTrack0 = NULL;
75   fTrack1 = NULL;
76   fTrack2 = NULL;
77
78   fModule = NULL;
79
80   fNPrimary = 0;
81
82   fField  = 0.0;
83   fGeo    = NULL;
84   fCalib  = NULL;
85   fCParam = NULL;
86
87 }
88
89 //_____________________________________________________________________________
90 AliTRDtrigger::AliTRDtrigger(const Text_t *name, const Text_t *title):
91   TNamed(name,title),
92   fTracks("AliTRDgtuTrack",1000)
93 {
94   //
95   // AliTRDtrigger constructor
96   //
97
98   fDigitsManager = new AliTRDdigitsManager();
99   fTrackletTree = NULL;
100   fTracklets = new TObjArray(400);
101
102   fNROB = 0;
103   fTrigParam = NULL;
104   fMCM = NULL;
105   fTrk = NULL;
106   fTrkTest = NULL;
107   fGTUtrk = NULL;
108
109   fNtracklets = 0;
110
111   fDigits = NULL;
112   fTrack0 = NULL;
113   fTrack1 = NULL;
114   fTrack2 = NULL;
115
116   fModule = NULL;
117
118   fNPrimary = 0;
119
120   fField  = 0.0;
121   fGeo    = NULL;
122   fCalib  = NULL;
123   fCParam = NULL;
124
125 }
126
127 //_____________________________________________________________________________
128 AliTRDtrigger::AliTRDtrigger(const AliTRDtrigger &p):TNamed(p)
129 {
130   //
131   // AliTRDtrigger copy constructor
132   //
133
134   ((AliTRDtrigger &) p).Copy(*this);
135
136 }
137
138 ///_____________________________________________________________________________
139 AliTRDtrigger::~AliTRDtrigger()
140 {
141   //
142   // AliTRDtrigger destructor
143   //
144
145   if (fTracklets) {
146     fTracklets->Delete();
147     delete fTracklets;
148   }
149
150   fTracks.Delete();
151
152 }
153
154 //_____________________________________________________________________________
155 AliTRDtrigger &AliTRDtrigger::operator=(const AliTRDtrigger &p)
156 {
157   //
158   // Assignment operator
159   //
160
161   if (this != &p) ((AliTRDtrigger &) p).Copy(*this);
162   return *this;
163
164 }
165
166 //_____________________________________________________________________________
167 void AliTRDtrigger::Copy(TObject &) const
168 {
169   //
170   // Copy function
171   //
172
173   AliFatal("Not implemented");
174
175 }
176
177 //_____________________________________________________________________________
178 void AliTRDtrigger::Init()
179 {
180
181   fModule = new AliTRDmodule(fTrigParam); 
182   /*
183   AliHeader *header = fRunLoader->GetHeader();
184   fNPrimary = header->GetNprimary();
185   */
186   fTracks.Clear();
187
188   fField = fTrigParam->GetField();
189   fGeo = (AliTRDgeometry*)AliTRDgeometry::GetGeometry(fRunLoader);
190
191   fCalib = AliTRDcalibDB::Instance();
192   if (!fCalib)
193   {
194     Error("Init","No instance of AliTRDcalibDB.");
195     return;  
196   }
197
198   fCParam = AliTRDCommonParam::Instance();
199   if (!fCParam)
200   {
201     Error("Init","No common params.");
202     return;
203   }
204
205 }
206
207 //_____________________________________________________________________________
208 Bool_t AliTRDtrigger::Open(const Char_t *name, Int_t nEvent)
209 {
210   //
211   // Opens the AliROOT file.
212   //
213
214   TString evfoldname = AliConfig::GetDefaultEventFolderName();
215   fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
216
217   if (!fRunLoader)
218     fRunLoader = AliRunLoader::Open(name);
219
220   if (!fRunLoader) {
221     Error("Open","Can not open session for file %s.",name);
222     return kFALSE;
223   }
224
225   // Open input
226
227   if (fRunLoader->GetAliRun() == 0x0) fRunLoader->LoadgAlice();
228   gAlice = fRunLoader->GetAliRun();
229
230   if (!(gAlice)) {
231     fRunLoader->LoadgAlice();
232     gAlice = fRunLoader->GetAliRun();
233     if (!(gAlice)) {
234       Error("Open","Could not find AliRun object.");
235       return kFALSE;
236     }
237   }
238
239   // Import the Trees for the event nEvent in the file
240   fRunLoader->GetEvent(nEvent);
241
242   // Open output
243
244   TObjArray *ioArray = 0;
245
246   AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
247   loader->MakeTree("T");
248   fTrackletTree = loader->TreeT();
249   fTrackletTree->Branch("TRDmcmTracklet","TObjArray",&ioArray,32000,0);
250   /*
251   fRunLoader->LoadHeader();
252   */
253   Init();
254
255   return kTRUE;
256
257 }
258
259
260 //_____________________________________________________________________________
261 Bool_t AliTRDtrigger::ReadDigits() 
262 {
263   //
264   // Reads the digits arrays from the input aliroot file
265   //
266
267   if (!fRunLoader) {
268     Error("ReadDigits","Can not find the Run Loader");
269     return kFALSE;
270   }
271
272   AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
273   if (!loader->TreeD()) loader->LoadDigits();
274
275   if (!loader->TreeD()) return kFALSE;
276
277   return (fDigitsManager->ReadDigits(loader->TreeD()));
278
279 }
280
281 //_____________________________________________________________________________
282 Bool_t AliTRDtrigger::ReadDigits(AliRawReader* rawReader)
283 {
284   //
285   // Reads the digits arrays from the ddl file
286   //
287
288   AliTRDrawData *raw = new AliTRDrawData();
289
290   fDigitsManager = raw->Raw2Digits(rawReader);
291
292   return kTRUE;
293
294 }
295
296 //_____________________________________________________________________________
297 Bool_t AliTRDtrigger::ReadTracklets(AliRunLoader *rl) 
298 {
299   //
300   // Reads the tracklets find the tracks
301   //
302
303   Int_t idet;
304
305   AliLoader *loader = rl->GetLoader("TRDLoader");
306   loader->LoadTracks();
307   fTrackletTree = loader->TreeT();
308
309   TBranch *branch = fTrackletTree->GetBranch("TRDmcmTracklet");
310   if (!branch) {
311     Error("ReadTracklets","Can't get the branch !");
312     return kFALSE;
313   }
314   TObjArray *tracklets = new TObjArray(400);
315   branch->SetAddress(&tracklets);
316
317   Int_t nEntries = (Int_t) fTrackletTree->GetEntries();
318   Int_t iEntry, itrk;
319   Int_t iStack, iStackPrev = -1;
320   
321   for (iEntry = 0; iEntry < nEntries; iEntry++) {    
322     fTrackletTree->GetEvent(iEntry);
323     
324     for (itrk = 0; itrk < tracklets->GetEntriesFast(); itrk++){
325
326       fTrk = (AliTRDmcmTracklet*)tracklets->UncheckedAt(itrk);
327       
328       idet = fTrk->GetDetector();
329
330       iStack = idet / (AliTRDgeometry::Nplan());
331       if (iStackPrev != iStack) {
332         if (iStackPrev == -1) {
333           iStackPrev = iStack;
334         } else {
335           MakeTracks(idet-AliTRDgeometry::Nplan());
336           ResetTracklets();
337           iStackPrev = iStack;
338         }
339       }
340       
341       Tracklets()->Add(fTrk);
342
343       if (iEntry == (nEntries-1) && itrk == (tracklets->GetEntriesFast()-1)) {
344         idet++;
345         MakeTracks(idet-AliTRDgeometry::Nplan());
346         ResetTracklets();
347       }
348
349     }
350
351   }
352
353   loader->UnloadTracks();
354
355   return kTRUE;
356
357 }
358
359 //_____________________________________________________________________________
360 Bool_t AliTRDtrigger::MakeTracklets(Bool_t makeTracks)
361 {
362   //
363   // Create tracklets from digits
364   //
365
366   Int_t    chamBeg = 0;
367   Int_t    chamEnd = AliTRDgeometry::Ncham();
368   Int_t    planBeg = 0;
369   Int_t    planEnd = AliTRDgeometry::Nplan();
370   Int_t    sectBeg = 0;
371   Int_t    sectEnd = AliTRDgeometry::Nsect();
372
373   fTrkTest = new AliTRDmcmTracklet(0,0,0);
374
375   fMCM = new AliTRDmcm(fTrigParam,0);
376
377   Int_t time, col, row, col1, col2;
378   Float_t amp;
379   Int_t idet, iStack, iStackPrev;
380   idet       = -1;
381   iStack     = -1;
382   iStackPrev = -1;
383   for (Int_t isect = sectBeg; isect < sectEnd; isect++) {
384
385     for (Int_t icham = chamBeg; icham < chamEnd; icham++) {
386
387       // number of ROBs in the chamber
388       if( icham == 2 ) {
389         fNROB = 6;
390       } else {
391         fNROB = 8;
392       }
393
394       for (Int_t iplan = planBeg; iplan < planEnd; iplan++) {
395
396         idet = fGeo->GetDetector(iplan,icham,isect);
397         ResetTracklets();
398         
399         if (makeTracks) {
400           iStack = idet / (AliTRDgeometry::Nplan());
401           if (iStackPrev != iStack) {
402             if (iStackPrev == -1) {
403               iStackPrev = iStack;
404             } else {
405               MakeTracks(idet-AliTRDgeometry::Nplan());
406               ResetTracklets();
407               iStackPrev = iStack;
408             }
409           }
410         }
411
412         Int_t    nRowMax     = fCParam->GetRowMax(iplan,icham,isect);
413         Int_t    nColMax     = fCParam->GetColMax(iplan);
414         Int_t    nTimeTotal  = fCalib->GetNumberOfTimeBins();
415
416         // Get the digits
417         fDigits = fDigitsManager->GetDigits(idet);
418         if (!fDigits) return kFALSE;
419         fDigits->Expand();
420         fTrack0 = fDigitsManager->GetDictionary(idet,0);
421         if (!fTrack0) return kFALSE;
422         fTrack0->Expand();
423         fTrack1 = fDigitsManager->GetDictionary(idet,1);
424         if (!fTrack1) return kFALSE;
425         fTrack1->Expand();
426         fTrack2 = fDigitsManager->GetDictionary(idet,2); 
427         if (!fTrack2) return kFALSE;
428         fTrack2->Expand();
429
430         for (Int_t iRob = 0; iRob < fNROB; iRob++) {
431
432           for (Int_t iMcm = 0; iMcm < kNMCM; iMcm++) {
433
434             fMCM->Reset();
435
436             fMCM->SetRobId(iRob);
437             fMCM->SetChaId(idet);
438
439             SetMCMcoordinates(iMcm);
440
441             row = fMCM->GetRow();
442
443             if (row < 0 || row >= nRowMax) {
444               Error("MakeTracklets","MCM row number out of range.");
445               continue;
446             }
447
448             fMCM->GetColRange(col1,col2);
449             
450             for (time = 0; time < nTimeTotal; time++) {
451               for (col = col1; col < col2; col++) {
452                 if (col >= 0 && col < nColMax) {
453                   amp = TMath::Abs(fDigits->GetDataUnchecked(row,col,time));
454                 } else {
455                   amp = 0.0;
456                 }
457                 fMCM->SetADC(col-col1,time,amp);
458
459               }
460             }
461
462             if (fTrigParam->GetTailCancelation()) {
463               fMCM->Filter(fTrigParam->GetNexponential(),fTrigParam->GetFilterType());
464             }
465             
466             if (fMCM->Run()) {
467
468               for (Int_t iSeed = 0; iSeed < kMaxTrackletsPerMCM; iSeed++) {
469                 
470                 if (fMCM->GetSeedCol()[iSeed] < 0) continue;
471
472                 if ( fTrigParam->GetDebugLevel() > 1 ) 
473                   printf("Add tracklet %d in col %02d \n",fNtracklets,fMCM->GetSeedCol()[iSeed]);
474
475                 if ( fTrigParam->GetDebugLevel() == -1 ) {
476                   printf("Add tracklet %d in col %02d \n",fNtracklets,fMCM->GetSeedCol()[iSeed]);
477                   for (time = 0; time < nTimeTotal; time++) {
478                     for (col = 0; col < kMcmCol; col++) {                   
479                       printf("%03.0f  ",fMCM->GetADC(col,time));
480                     }
481                     printf("\n");
482                   }
483                 }
484
485                 if (TestTracklet(idet,row,iSeed,0)) {
486                   AddTracklet(idet,row,iSeed,fNtracklets++);
487                 }
488
489               }
490
491             }
492
493           }
494
495       
496         }
497
498         // Compress the arrays
499         fDigits->Compress(1,0);
500         fTrack0->Compress(1,0);
501         fTrack1->Compress(1,0);
502         fTrack2->Compress(1,0);
503
504         WriteTracklets(idet);
505
506      }
507     }
508   }
509
510   if (makeTracks) {
511     idet++;
512     MakeTracks(idet-AliTRDgeometry::Nplan());
513     ResetTracklets();
514   }
515
516   return kTRUE;
517
518 }
519
520 //_____________________________________________________________________________
521 void AliTRDtrigger::SetMCMcoordinates(Int_t imcm)
522 {
523   //
524   // Configure MCM position in the pad plane
525   //
526
527   Int_t robid = fMCM->GetRobId();
528
529   // setting the Row and Col range
530
531   const Int_t kNcolRob = 2;  // number of ROBs per chamber in column direction
532   const Int_t kNmcmRob = 4;  // number of MCMs per ROB in column/row direction
533
534   Int_t mcmid = imcm%(kNmcmRob*kNmcmRob);
535
536   if (robid%kNcolRob == 0) {
537
538     if ( mcmid%kNmcmRob == 0 ) {
539       fMCM->SetColRange(18*0-1,18*1-1+2+1);
540     }
541     if ( mcmid%kNmcmRob == 1 ) {
542       fMCM->SetColRange(18*1-1,18*2-1+2+1);
543     }
544     if ( mcmid%kNmcmRob == 2 ) {
545       fMCM->SetColRange(18*2-1,18*3-1+2+1);
546     }
547     if ( mcmid%kNmcmRob == 3 ) {
548       fMCM->SetColRange(18*3-1,18*4-1+2+1);
549     }
550
551   } else {
552
553     if ( mcmid%kNmcmRob == 0 ) {
554       fMCM->SetColRange(18*4-1,18*5-1+2+1);
555     }
556     if ( mcmid%kNmcmRob == 1 ) {
557       fMCM->SetColRange(18*5-1,18*6-1+2+1);
558     }
559     if ( mcmid%kNmcmRob == 2 ) {
560       fMCM->SetColRange(18*6-1,18*7-1+2+1);
561     }
562     if ( mcmid%kNmcmRob == 3 ) {
563       fMCM->SetColRange(18*7-1,18*8-1+2+1);
564     }
565
566   } 
567
568   fMCM->SetRow(kNmcmRob*(robid/kNcolRob)+mcmid/kNmcmRob);
569
570 }
571
572 //_____________________________________________________________________________
573 Bool_t AliTRDtrigger::TestTracklet(Int_t det, Int_t row, Int_t seed, Int_t n)
574 {
575   //
576   // Check first the tracklet pt
577   //
578
579   Int_t nTimeTotal  = fCalib->GetNumberOfTimeBins();
580
581   fTrkTest->Reset();
582
583   fTrkTest->SetDetector(det);
584   fTrkTest->SetRow(row);
585   fTrkTest->SetN(n);
586
587   Int_t iCol, iCol1, iCol2, track[3];
588   iCol = fMCM->GetSeedCol()[seed];  // 0....20 (MCM)
589   fMCM->GetColRange(iCol1,iCol2);   // range in the pad plane
590             
591   Float_t amp[3];
592   for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
593
594     amp[0] = fMCM->GetADC(iCol-1,iTime);
595     amp[1] = fMCM->GetADC(iCol  ,iTime);
596     amp[2] = fMCM->GetADC(iCol+1,iTime);
597
598     // extract track contribution only from the central pad
599     track[0] = fTrack0->GetDataUnchecked(row,iCol+iCol1,iTime);
600     track[1] = fTrack1->GetDataUnchecked(row,iCol+iCol1,iTime);
601     track[2] = fTrack2->GetDataUnchecked(row,iCol+iCol1,iTime);
602
603     if (fMCM->IsCluster(iCol,iTime)) {
604
605       fTrkTest->AddCluster(iCol+iCol1,iTime,amp,track);
606
607     } else if ((iCol+1+1) < kMcmCol) {
608
609       amp[0] = fMCM->GetADC(iCol-1+1,iTime);
610       amp[1] = fMCM->GetADC(iCol  +1,iTime);
611       amp[2] = fMCM->GetADC(iCol+1+1,iTime);
612
613       if (fMCM->IsCluster(iCol+1,iTime)) {
614
615         // extract track contribution only from the central pad
616         track[0] = fTrack0->GetDataUnchecked(row,iCol+1+iCol1,iTime);
617         track[1] = fTrack1->GetDataUnchecked(row,iCol+1+iCol1,iTime);
618         track[2] = fTrack2->GetDataUnchecked(row,iCol+1+iCol1,iTime);
619
620         fTrkTest->AddCluster(iCol+1+iCol1,iTime,amp,track);
621
622       }
623
624     } else {
625     }
626
627   }
628
629   fTrkTest->CookLabel(0.8);  
630   /*
631   if (fTrkTest->GetLabel() >= fNPrimary) {
632     Info("AddTracklet","Only primaries are stored!");
633     return;
634   }
635   */
636   // LTU Pt cut
637     
638   fTrkTest->MakeTrackletGraph(fGeo,fField);
639   fTrkTest->MakeClusAmpGraph();
640   if (TMath::Abs(fTrkTest->GetPt()) < fTrigParam->GetLtuPtCut()) {
641     return kFALSE;
642   }
643   
644   return kTRUE;  
645
646 }
647
648 //_____________________________________________________________________________
649 void AliTRDtrigger::AddTracklet(Int_t det, Int_t row, Int_t seed, Int_t n)
650 {
651   //
652   // Add a found tracklet
653   //
654
655   Int_t nTimeTotal  = fCalib->GetNumberOfTimeBins();
656
657   fTrk = new AliTRDmcmTracklet(det,row,n);
658
659   Int_t iCol, iCol1, iCol2, track[3];
660   iCol = fMCM->GetSeedCol()[seed];  // 0....20 (MCM)
661   fMCM->GetColRange(iCol1,iCol2);   // range in the pad plane
662             
663   Float_t amp[3];
664   for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
665
666     amp[0] = fMCM->GetADC(iCol-1,iTime);
667     amp[1] = fMCM->GetADC(iCol  ,iTime);
668     amp[2] = fMCM->GetADC(iCol+1,iTime);
669
670     // extract track contribution only from the central pad
671     track[0] = fTrack0->GetDataUnchecked(row,iCol+iCol1,iTime);
672     track[1] = fTrack1->GetDataUnchecked(row,iCol+iCol1,iTime);
673     track[2] = fTrack2->GetDataUnchecked(row,iCol+iCol1,iTime);
674
675     if (fMCM->IsCluster(iCol,iTime)) {
676
677       fTrk->AddCluster(iCol+iCol1,iTime,amp,track);
678
679     } else if ((iCol+1+1) < kMcmCol) {
680
681       amp[0] = fMCM->GetADC(iCol-1+1,iTime);
682       amp[1] = fMCM->GetADC(iCol  +1,iTime);
683       amp[2] = fMCM->GetADC(iCol+1+1,iTime);
684
685       if (fMCM->IsCluster(iCol+1,iTime)) {
686
687         // extract track contribution only from the central pad
688         track[0] = fTrack0->GetDataUnchecked(row,iCol+1+iCol1,iTime);
689         track[1] = fTrack1->GetDataUnchecked(row,iCol+1+iCol1,iTime);
690         track[2] = fTrack2->GetDataUnchecked(row,iCol+1+iCol1,iTime);
691
692         fTrk->AddCluster(iCol+1+iCol1,iTime,amp,track);
693
694       }
695
696     } else {
697     }
698
699   }
700
701   fTrk->CookLabel(0.8);  
702   /*
703   if (fTrk->GetLabel() >= fNPrimary) {
704     Info("AddTracklet","Only primaries are stored!");
705     return;
706   }
707   */
708   // LTU Pt cut
709   fTrk->MakeTrackletGraph(fGeo,fField);
710   fTrk->MakeClusAmpGraph();
711   if (TMath::Abs(fTrk->GetPt()) < fTrigParam->GetLtuPtCut()) {
712     return;
713   }
714       
715   Tracklets()->Add(fTrk);
716
717 }
718
719 //_____________________________________________________________________________
720 Bool_t AliTRDtrigger::WriteTracklets(Int_t det) 
721 {
722   //
723   // Fills TRDmcmTracklet branch in the tree with the Tracklets 
724   // found in detector = det. For det=-1 writes the tree. 
725   //
726
727   if ((det < -1) || (det >= AliTRDgeometry::Ndet())) {
728     Error("WriteTracklets","Unexpected detector index %d.",det);
729     return kFALSE;
730   }
731
732   TBranch *branch = fTrackletTree->GetBranch("TRDmcmTracklet");
733   if (!branch) {
734     TObjArray *ioArray = 0;
735     branch = fTrackletTree->Branch("TRDmcmTracklet","TObjArray",&ioArray,32000,0);
736   }
737
738   if ((det >= 0) && (det < AliTRDgeometry::Ndet())) {
739
740     Int_t nTracklets = Tracklets()->GetEntriesFast();
741     TObjArray *detTracklets = new TObjArray(400);
742
743     for (Int_t i = 0; i < nTracklets; i++) {
744       AliTRDmcmTracklet *trk = (AliTRDmcmTracklet *) Tracklets()->UncheckedAt(i);
745       
746       if (det == trk->GetDetector()) {
747         detTracklets->AddLast(trk);
748       }
749       else {
750       }
751     }
752
753     branch->SetAddress(&detTracklets);
754     fTrackletTree->Fill();
755
756     delete detTracklets;
757
758     return kTRUE;
759
760   }
761
762   if (det == -1) {
763
764     Info("WriteTracklets","Writing the Tracklet tree %s for event %d."
765          ,fTrackletTree->GetName(),fRunLoader->GetEventNumber());
766
767     AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
768     loader->WriteTracks("OVERWRITE");
769     
770     return kTRUE;  
771
772   }
773
774   return kFALSE;
775
776 }
777
778 //_____________________________________________________________________________
779 void AliTRDtrigger::MakeTracks(Int_t det)
780 {
781   //
782   // Create GTU tracks per module (stack of 6 chambers)
783   //
784   
785   fModule->Reset();
786
787   Int_t nRowMax, iplan, icham, isect, row;
788
789   if ((det < 0) || (det >= AliTRDgeometry::Ndet())) {
790     Error("MakeTracks","Unexpected detector index %d.",det);
791     return;
792   }
793   
794   Int_t nTracklets = Tracklets()->GetEntriesFast();
795   
796   AliTRDmcmTracklet *trk;
797   for (Int_t i = 0; i < nTracklets; i++) {
798     
799     trk = (AliTRDmcmTracklet *) Tracklets()->UncheckedAt(i);
800     
801     iplan = fGeo->GetPlane(trk->GetDetector());
802     icham = fGeo->GetChamber(trk->GetDetector());
803     isect = fGeo->GetSector(trk->GetDetector());
804
805     nRowMax = fCParam->GetRowMax(iplan,icham,isect);
806     row = trk->GetRow();
807
808     fModule->AddTracklet(trk->GetDetector(),
809                          row,
810                          trk->GetRowz(),
811                          trk->GetSlope(),
812                          trk->GetOffset(),
813                          trk->GetTime0(),
814                          trk->GetNclusters(),
815                          trk->GetLabel(),
816                          trk->GetdQdl());
817     
818   }
819
820   fModule->SortTracklets();
821   fModule->RemoveMultipleTracklets();
822   fModule->SortZ((Int_t)fGeo->GetChamber(det));
823   fModule->FindTracks();
824   fModule->SortTracks();
825   fModule->RemoveMultipleTracks();
826
827   Int_t nModTracks = fModule->GetNtracks();
828   AliTRDgtuTrack *gtutrk;
829   for (Int_t i = 0; i < nModTracks; i++) {
830     gtutrk = (AliTRDgtuTrack*)fModule->GetTrack(i);
831     if (TMath::Abs(gtutrk->GetPt()) < fTrigParam->GetGtuPtCut()) continue;
832     gtutrk->CookLabel();
833     gtutrk->MakePID();
834     AddTrack(gtutrk,det);
835   }
836   
837 }
838
839