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