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