]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDmodule.cxx
Introduce protection against switched off supermodules
[u/mrichter/AliRoot.git] / TRD / AliTRDmodule.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 6-chambers stack                                                     //
20 //                                                                           //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include <TObject.h>
25
26 #include "AliLog.h"
27
28 #include "AliTRDgeometry.h"
29 #include "AliTRDmodule.h"
30 #include "AliTRDltuTracklet.h"
31 #include "AliTRDgtuTrack.h"
32 #include "AliTRDtrigParam.h"
33 #include "AliTRDzmaps.h"
34
35 ClassImp(AliTRDmodule)
36
37 //_____________________________________________________________________________
38 AliTRDmodule::AliTRDmodule()
39   :TObject() 
40   ,fXprojPlane(0)
41   ,fField(0)
42   ,fTracklets(NULL)
43   ,fTracks(NULL)
44   ,fDeltaY(0)
45   ,fDeltaS(0)
46   ,fLTUtrk(0)
47   ,fGTUtrk(0)
48 {
49   //
50   // AliTRDmodule default constructor
51   //
52
53 }
54
55 //_____________________________________________________________________________
56 AliTRDmodule::AliTRDmodule(AliTRDtrigParam *trigp) 
57   :TObject()
58   ,fXprojPlane(trigp->GetXprojPlane())
59   ,fField(trigp->GetField())
60   ,fTracklets(new TObjArray(400))
61   ,fTracks(new TObjArray(400))
62   ,fDeltaY(trigp->GetDeltaY())
63   ,fDeltaS(trigp->GetDeltaS())
64   ,fLTUtrk(0)
65   ,fGTUtrk(0)
66 {
67   //
68   // AliTRDmodule constructor
69   //
70
71   for (Int_t iPlan = 0; iPlan < AliTRDgeometry::Nplan(); iPlan++) {
72     for (Int_t i = 0; i < kNsubZchan; i++) {
73       fZnchan[iPlan][i] = 0;
74       for (Int_t j = 0; j < kNmaxZchan; j++) {
75         fZtrkid[iPlan][j][i] = -1;
76       }
77     }
78   }
79
80 }
81
82 //_____________________________________________________________________________
83 AliTRDmodule::AliTRDmodule(const AliTRDmodule &m)
84   :TObject(m)
85   ,fXprojPlane(m.fXprojPlane)
86   ,fField(m.fField)
87   ,fTracklets(NULL)
88   ,fTracks(NULL)
89   ,fDeltaY(m.fDeltaY)
90   ,fDeltaS(m.fDeltaS)
91   ,fLTUtrk(NULL)
92   ,fGTUtrk(NULL)
93 {
94   //
95   // AliTRDmodule copy constructor
96   //
97
98   for (Int_t iPlan = 0; iPlan < AliTRDgeometry::Nplan(); iPlan++) {
99     for (Int_t i = 0; i < kNsubZchan; i++) {
100       ((AliTRDmodule &) m).fZnchan[iPlan][i] = 0;
101       for (Int_t j = 0; j < kNmaxZchan; j++) {
102         ((AliTRDmodule &) m).fZtrkid[iPlan][j][i] = -1;
103       }
104     }
105   }
106
107 }
108
109 //_____________________________________________________________________________
110 AliTRDmodule::~AliTRDmodule()
111 {
112   //
113   // Destructor
114   //
115
116 }
117
118 //_____________________________________________________________________________
119 AliTRDmodule &AliTRDmodule::operator=(const AliTRDmodule &m)
120 {
121   //
122   // Assignment operator
123   //
124
125   if (this != &m) ((AliTRDmodule &) m).Copy(*this); 
126   return *this;
127
128 }
129
130 //_____________________________________________________________________________
131 void AliTRDmodule::Copy(TObject &m) const
132 {
133   //
134   // copy function
135   //
136
137   ((AliTRDmodule &) m).fXprojPlane = fXprojPlane;
138   ((AliTRDmodule &) m).fField      = fField;
139   ((AliTRDmodule &) m).fTracklets  = NULL;
140   ((AliTRDmodule &) m).fTracks     = NULL;
141   ((AliTRDmodule &) m).fDeltaY     = fDeltaY;
142   ((AliTRDmodule &) m).fDeltaS     = fDeltaS;
143   ((AliTRDmodule &) m).fLTUtrk     = NULL;
144   ((AliTRDmodule &) m).fGTUtrk     = NULL;
145
146   for (Int_t iPlan = 0; iPlan < AliTRDgeometry::Nplan(); iPlan++) {
147     for (Int_t i = 0; i < kNsubZchan; i++) {
148       ((AliTRDmodule &) m).fZnchan[iPlan][i] = 0;
149       for (Int_t j = 0; j < kNmaxZchan; j++) {
150         ((AliTRDmodule &) m).fZtrkid[iPlan][j][i] = -1;
151       }
152     }
153   }
154
155 }
156
157 //_____________________________________________________________________________
158 void AliTRDmodule::Reset() 
159 {
160   //
161   // Reset the tracks and tracklets in the module
162   //
163
164   ResetTracklets();
165   ResetTracks();
166
167   fLTUtrk    = 0;
168   fGTUtrk    = 0;
169   fTracklets = new TObjArray(400);
170   fTracks    = new TObjArray(400);
171
172 }
173
174 //_____________________________________________________________________________
175 void AliTRDmodule::ResetTracks() 
176 {
177   // 
178   // Reset the tracks in the module
179   //
180
181   if (fTracks) {
182
183     AliTRDgtuTrack *trk;
184     for (Int_t i = 0; i < GetNtracks(); i++) {
185       
186       trk = GetTrack(i);
187       trk->Reset();
188       
189     }
190
191     fTracks->Delete();
192
193   }
194
195 }
196
197 //_____________________________________________________________________________
198 AliTRDgtuTrack* AliTRDmodule::GetTrack(Int_t pos) const
199 {
200   //
201   // Return track at position "pos"
202   //
203
204   if (fTracks == 0) {
205     return 0;
206   }
207
208   void *trk = fTracks->UncheckedAt(pos);
209   if (trk == 0) {
210     return 0;
211   }
212
213   return (AliTRDgtuTrack *) trk;
214
215 }
216
217 //_____________________________________________________________________________
218 void AliTRDmodule::RemoveTrack(Int_t pos)
219 {
220   //
221   // Remove the track at position "pos"
222   //
223
224   if (fTracks == 0) {
225     return;
226   }
227
228   fTracks->RemoveAt(pos);
229   fTracks->Compress();
230
231 }
232
233 //_____________________________________________________________________________
234 void AliTRDmodule::AddTracklet(Int_t det, Int_t row, Float_t rowz, Float_t slope 
235                              , Float_t offset, Float_t time, Int_t ncl
236                              , Int_t label, Float_t q) 
237 {
238   // 
239   // Add a tracklet to this track
240   //
241   
242   fLTUtrk = new AliTRDltuTracklet(det,row,rowz,slope,offset,time,ncl,label,q);
243   Tracklets()->Add(fLTUtrk);
244
245 }
246
247 //_____________________________________________________________________________
248 AliTRDltuTracklet* AliTRDmodule::GetTracklet(Int_t pos) const
249 {
250   //
251   // Get the tracklet at position "pos"
252   //
253
254   if (fTracklets == 0) {
255     return 0;
256   }
257
258   void *trk = fTracklets->UncheckedAt(pos);
259   if (trk == 0) {
260     return 0;
261   }
262
263   return (AliTRDltuTracklet *) trk;
264
265 }
266
267 //_____________________________________________________________________________
268 void AliTRDmodule::RemoveTracklet(Int_t pos)
269 {
270   //
271   // Remove the tracklet at position "pos"
272   //
273
274   if (fTracklets == 0) {
275     return;
276   }
277
278   fTracklets->RemoveAt(pos);
279   fTracklets->Compress();
280
281 }
282
283 //_____________________________________________________________________________
284 void AliTRDmodule::RemoveMultipleTracklets()
285 {
286   //
287   // Remove multiple found tracklets
288   //
289
290   Float_t offDiffMin = 0.5;  // [cm]
291
292   AliTRDltuTracklet *trk;
293   Int_t   det1, det2, row1, row2, ncl1, ncl2, label1, label2;
294   Float_t off1, off2;
295   Int_t   itrk = 0;
296   while (itrk < (GetNtracklets() - 1)) {
297
298     trk    = GetTracklet(itrk);
299     det1   = trk->GetDetector();
300     row1   = trk->GetRow();
301     off1   = trk->GetOffset();
302     ncl1   = trk->GetNclusters();
303     label1 = trk->GetLabel();
304
305     trk    = GetTracklet(itrk+1);
306     det2   = trk->GetDetector();
307     row2   = trk->GetRow();
308     off2   = trk->GetOffset();
309     ncl2   = trk->GetNclusters();
310     label2 = trk->GetLabel();
311
312     if ((det1 == det2) && (row1 == row2)) {
313       if ((off2 - off1) < offDiffMin) {
314         if (ncl1 < ncl2) {
315           RemoveTracklet(itrk  );
316         }    
317         else {
318           RemoveTracklet(itrk+1);
319         }
320       }
321     }
322
323     itrk++;
324
325   }
326
327 }
328
329 //_____________________________________________________________________________
330 void AliTRDmodule::SortZ(Int_t cha)
331 {
332   //
333   // Match tracklets in the x-z plane (pad row sorting)
334   //
335
336   InitZLUT();
337
338   AliTRDltuTracklet *trk;
339   Int_t row, pla, det;
340
341   for (Int_t iTrk = 0; iTrk < GetNtracklets(); iTrk++) {
342
343     trk = GetTracklet(iTrk);
344     row = trk->GetRow();
345     det = trk->GetDetector();
346     pla = trk->GetPlane(det);
347
348     for (Int_t iZchan = 0; iZchan < kNsubZchan; iZchan++) {
349       if (fZChannelMap[cha][iZchan][pla][row] == 1) {
350         fZtrkid[pla][fZnchan[pla][iZchan]][iZchan] = iTrk;
351         fZnchan[pla][iZchan]++;
352       }
353     }
354
355   }
356
357 }
358
359 //_____________________________________________________________________________
360 void AliTRDmodule::InitZLUT()
361 {
362   //
363   // Initialize the pad row sorting look-up-table
364   //
365
366   for (Int_t iPlan = 0; iPlan < AliTRDgeometry::Nplan(); iPlan++) {
367     for (Int_t i = 0; i < kNsubZchan; i++) {
368       fZnchan[iPlan][i] = 0;
369       for (Int_t j = 0; j < kNmaxZchan; j++) {
370         fZtrkid[iPlan][j][i] = -1;
371       }
372     }
373   }
374
375 }
376
377 //_____________________________________________________________________________
378 void AliTRDmodule::FindTracks() 
379 {
380   //
381   // Find tracks from tracklets
382   //
383
384   for (Int_t iZchan = 0; iZchan < kNsubZchan; iZchan++) {
385     FindTracksCombi(iZchan);
386   }
387
388 }
389
390 //_____________________________________________________________________________
391 void AliTRDmodule::FindTracksCombi(Int_t zchan) 
392 {
393   //
394   // Find tracks by pure combinatorics...
395   //
396   
397   static Int_t trkTrack[12];
398   
399   Int_t   nTracklets, nPlanes;
400   Int_t   ntrk1, trkId1, ntrk2, trkId2;
401   Float_t y1, y1min, y1max, s1, z1, s1min, s1max, y2, s2, z2;
402   AliTRDltuTracklet *trk1;
403   AliTRDltuTracklet *trk2;
404   AliTRDltuTracklet *trk ;
405
406   Bool_t isPlane[kNplan];
407
408   for (Int_t iPlan1 = 0; iPlan1 < kNplan; iPlan1++) {
409
410     ntrk1 = fZnchan[iPlan1][zchan];
411
412     for (Int_t iTrk1 = 0; iTrk1 < ntrk1; iTrk1++) {
413
414       for (Int_t iPlan = 0; iPlan < kNplan; iPlan++) {
415         isPlane[iPlan] = kFALSE;
416       }
417
418       trkId1 = fZtrkid[iPlan1][iTrk1][zchan];
419
420       nTracklets = 0;
421       for (Int_t iList = 0; iList < kNmaxTrk; iList++) {
422         trkTrack[iList] = -1;
423       }
424       trkTrack[nTracklets++] = trkId1;
425
426       isPlane[iPlan1] = kTRUE;
427
428       trk1  = GetTracklet(trkId1);
429       y1    = trk1->GetYproj(fXprojPlane);
430       y1min = y1 - fDeltaY;
431       y1max = y1 + fDeltaY;
432       s1    = trk1->GetSlope();
433       s1min = s1 - fDeltaS;
434       s1max = s1 + fDeltaS;
435       z1    = trk1->GetZproj(fXprojPlane);      
436
437       for (Int_t iPlan2 = 0; iPlan2 < kNplan; iPlan2++) {
438
439         if (iPlan2 == iPlan1) continue;
440
441         ntrk2 = fZnchan[iPlan2][zchan];
442
443         for (Int_t iTrk2 = 0; iTrk2 < ntrk2; iTrk2++) {
444
445           trkId2 = fZtrkid[iPlan2][iTrk2][zchan];
446
447           if (trkId2 == trkId1) continue;
448
449           trk2 = GetTracklet(trkId2);
450           y2   = trk2->GetYproj(fXprojPlane);
451           s2   = trk2->GetSlope();
452           z2   = trk2->GetZproj(fXprojPlane);
453
454           if ((y1min < y2 && y2 < y1max) && 
455               (s1min < s2 && s2 < s1max)) {
456
457             if (nTracklets >= kNmaxTrk) {
458               AliWarning("Too many tracklets for this track.");
459             }    
460             else {
461               trkTrack[nTracklets++] = trkId2;
462               isPlane[iPlan2] = kTRUE;
463             }
464
465           }
466
467         }  // end trk 2
468
469       }  // end plan 2
470
471       nPlanes = 0;
472       for (Int_t iPlan = 0; iPlan < kNplan; iPlan++) {
473         nPlanes += (Int_t) isPlane[iPlan];
474       }
475       
476       if (nPlanes >= 4) {
477
478         Int_t cha1, cha2, npoints1, npoints2;
479         for (Int_t iList = 0; iList < (nTracklets - 1); iList++) {
480
481           if (trkTrack[iList] == -1 || trkTrack[iList+1] == -1) continue;
482           trk1 = GetTracklet(trkTrack[iList  ]);
483           trk2 = GetTracklet(trkTrack[iList+1]);
484
485           cha1 = trk1->GetDetector();
486           cha2 = trk2->GetDetector();
487           if (cha1 != cha2) continue;
488
489           npoints1 = trk1->GetNclusters();
490           npoints2 = trk2->GetNclusters();
491
492           if (npoints1 == npoints2) {
493             trkTrack[iList] = -1;
494           } 
495           else {
496             if (npoints1 > npoints2) trkTrack[iList+1] = -1;
497             if (npoints1 < npoints2) trkTrack[iList  ] = -1;
498           }
499
500         }
501
502         fGTUtrk = new AliTRDgtuTrack();
503         for (Int_t iList = 0; iList < nTracklets; iList++) {
504           if (trkTrack[iList] == -1) continue;
505           trk = GetTracklet(trkTrack[iList]);
506           fGTUtrk->AddTracklet(trk);
507         }
508         fGTUtrk->Track(fXprojPlane,fField);
509         AddTrack();
510
511       }
512            
513     }  // end trk 1
514
515   }  // end plan 1
516
517 }
518
519 //_____________________________________________________________________________
520 void AliTRDmodule::AddTrack() 
521 {
522   //
523   // Add a found track to the module
524   //
525   
526   Tracks()->Add(fGTUtrk);
527
528 }
529
530 //_____________________________________________________________________________
531 void AliTRDmodule::RemoveMultipleTracks()
532 {
533   //
534   // Remove multiple found tracks
535   //
536
537   AliTRDgtuTrack *trk1;
538   AliTRDgtuTrack *trk2;
539
540   Float_t yproj1, yproj2, alpha1, alpha2;
541   Int_t   ntrk1, ntrk2;
542   Int_t   iTrack = 0;
543
544   while (iTrack < (GetNtracks()-1)) {
545
546     trk1   = GetTrack(iTrack  );
547     trk2   = GetTrack(iTrack+1);
548
549     ntrk1  = trk1->GetNtracklets();
550     yproj1 = trk1->GetYproj();
551     alpha1 = trk1->GetSlope();
552     ntrk2  = trk2->GetNtracklets();
553     yproj2 = trk2->GetYproj();
554     alpha2 = trk2->GetSlope();
555
556     if ((TMath::Abs(yproj1-yproj2) < fDeltaY) && 
557         (TMath::Abs(alpha1-alpha2) < fDeltaS)) {
558       if (ntrk1 < ntrk2) {
559         RemoveTrack(iTrack  );
560       } 
561       else {
562         RemoveTrack(iTrack+1);
563       }
564     } 
565     else {
566       iTrack++;
567     }
568     
569   }
570
571 }
572
573 //_____________________________________________________________________________
574 TObjArray* AliTRDmodule::Tracklets() 
575
576   //
577   // Returns the list of tracklets
578   //
579
580   if (!fTracklets) {
581     fTracklets = new TObjArray(400); 
582   }
583
584   return fTracklets; 
585
586 }
587
588 //_____________________________________________________________________________
589 void AliTRDmodule::ResetTracklets() 
590 {
591   //
592   // Resets the list of tracklets
593   //
594  
595   if (fTracklets) {
596     fTracklets->Delete();
597   } 
598
599 }
600
601 //_____________________________________________________________________________
602 void AliTRDmodule::SortTracklets()  
603 {
604   //
605   // Sorts the list of tracklets
606   //
607
608   if (fTracklets) {
609     fTracklets->Sort();
610   }
611  
612 }
613
614 //_____________________________________________________________________________
615 Int_t AliTRDmodule::GetNtracklets() const 
616 {
617   //
618   // Returns the number of tracklets
619   //
620
621   if (fTracklets) {
622     return fTracklets->GetEntriesFast();
623   }
624
625   return 0;
626
627 }
628
629 //_____________________________________________________________________________
630 TObjArray* AliTRDmodule::Tracks() 
631 {
632   //
633   // Returns the list of tracks
634   //
635  
636   if (!fTracks) {
637     fTracks = new TObjArray(400);
638   }
639  
640   return fTracks; 
641
642 }
643
644 //_____________________________________________________________________________
645 void AliTRDmodule::SortTracks()  
646
647   //
648   // Sort the list of tracks
649   //
650
651   if (fTracks) {
652     fTracks->Sort();
653   } 
654
655 }
656
657 //_____________________________________________________________________________
658 Int_t AliTRDmodule::GetNtracks() const 
659 {
660   //
661   // Returns the number of tracks
662   //
663
664   if (fTracks) {
665     return fTracks->GetEntriesFast();
666   }
667
668   return 0;
669
670 }