]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TRD/AliTRDtriggerHLT.cxx
initial HLT-TRD commit
[u/mrichter/AliRoot.git] / HLT / TRD / AliTRDtriggerHLT.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 "AliTRDmodule.h"
42 #include "AliTRDmcmTracklet.h"
43 #include "AliTRDgtuTrack.h"
44 #include "AliTRDtrigParam.h"
45 #include "AliTRDmcm.h"
46 #include "AliTRDzmaps.h"
47 #include "AliHLTTRDCalibra.h"
48 #include "Cal/AliTRDCalPIDLQ.h"
49
50 //#include "AliTRDtrigger.h"
51 #include "AliTRDtriggerHLT.h"
52
53 ClassImp(AliTRDtriggerHLT)
54
55 //_____________________________________________________________________________
56 AliTRDtriggerHLT::AliTRDtriggerHLT()
57   :AliTRDtrigger(),
58   fTreeCreatedHere(kFALSE)
59 {
60   //
61   // AliTRDtriggerHLT default constructor
62   //  
63 }
64
65 //_____________________________________________________________________________
66 AliTRDtriggerHLT::AliTRDtriggerHLT(const Text_t *name, const Text_t *title)
67   :AliTRDtrigger(name,title),
68   fTreeCreatedHere(kFALSE)   
69 {
70   //
71   // AliTRDtriggerHLT constructor
72   //
73 }
74
75 //_____________________________________________________________________________
76 AliTRDtriggerHLT::AliTRDtriggerHLT(const AliTRDtriggerHLT &p)
77   :AliTRDtrigger(p),
78   fTreeCreatedHere(kFALSE)   
79 {
80   //
81   // AliTRDtriggerHLT copy constructor
82   //
83 }
84
85 ///_____________________________________________________________________________
86 AliTRDtriggerHLT::~AliTRDtriggerHLT()
87 {
88   //
89   // AliTRDtrigger destructor
90   //
91
92   //   if (fTracklets) {
93   //     fTracklets->Delete();
94   //     delete fTracklets;
95   //   }
96   
97   //   if (fTracks) {
98   //     fTracks->Delete();
99   //     delete fTracks;
100   //   }
101
102   if (fGeo)
103     delete fGeo;
104 }
105
106 //_____________________________________________________________________________
107 AliTRDtriggerHLT &AliTRDtriggerHLT::operator=(const AliTRDtriggerHLT &p)
108 {
109   //
110   // Assignment operator
111   //
112
113   if (this != &p) ((AliTRDtriggerHLT &) p).Copy(*this);
114   return *this;
115
116 }
117
118 //_____________________________________________________________________________
119 void AliTRDtriggerHLT::Copy(TObject &) const
120 {
121   //
122   // Copy function
123   //
124
125   AliFatal("Not implemented");
126
127 }
128
129 //_____________________________________________________________________________
130 void AliTRDtriggerHLT::Init()
131 {
132   //
133   // Init: module, field, geometry, calibDB
134   //
135
136   fModule = new AliTRDmodule(fTrigParam); 
137   fTracks->Clear();
138   fField  = fTrigParam->GetField();
139
140   //AliInfo("Recreating default geometry!");
141   AliDebug(1, Form("Recreating default geometry!"));
142   //Modified by MP:
143   //fGeo    = (AliTRDgeometry*)AliTRDgeometry::GetGeometry(fRunLoader);
144   fGeo    = new AliTRDgeometry();
145
146   fCalib  = AliTRDcalibDB::Instance();
147   if (!fCalib) {
148     AliError("No instance of AliTRDcalibDB.");
149     return;  
150   }
151
152   fCParam = AliTRDCommonParam::Instance();
153   if (!fCParam) {
154     AliError("No common parameters.");
155     return;
156   }
157 }
158
159 //_____________________________________________________________________________
160 Bool_t AliTRDtriggerHLT::ReadDigits(AliRawReaderMemory* rawReader)
161 {
162   //
163   // Reads the digits arrays from the ddl file
164   //
165
166   AliTRDrawData raw;
167   fDigitsManager = raw.Raw2Digits((AliRawReader*)rawReader);
168   //AliInfo(Form("Digits manager at 0x%x", fDigitsManager));
169   AliDebug(1, Form("Digits manager at 0x%x", fDigitsManager));
170   if (fDigitsManager)
171     return kTRUE;
172   else
173     return kFALSE;
174 }
175
176 //_____________________________________________________________________________
177 Bool_t AliTRDtriggerHLT::MakeTracklets(Bool_t makeTracks)
178 {
179   //
180   // Create tracklets from digits
181   //
182
183   Int_t chamBeg = 0;
184   Int_t chamEnd = AliTRDgeometry::Ncham();
185   Int_t planBeg = 0;
186   Int_t planEnd = AliTRDgeometry::Nplan();
187   Int_t sectBeg = 0;
188   Int_t sectEnd = AliTRDgeometry::Nsect();
189
190   fTrkTest = new AliTRDmcmTracklet(0,0,0);
191   fMCM     = new AliTRDmcm(fTrigParam,0);
192
193   Int_t   time;
194   Int_t   col;
195   Int_t   row;
196   Int_t   col1;
197   Int_t   col2;
198   Int_t   idet       = -1;
199   Int_t   iStack     = -1;
200   Int_t   iStackPrev = -1;
201   Float_t amp;
202
203   for (Int_t isect = sectBeg; isect < sectEnd; isect++) {
204
205     for (Int_t icham = chamBeg; icham < chamEnd; icham++) {
206
207       // Number of ROBs in the chamber
208       if(icham == 2) {
209         fNROB = 6;
210       } 
211       else {
212         fNROB = 8;
213       }
214
215       for (Int_t iplan = planBeg; iplan < planEnd; iplan++) {
216
217         idet = fGeo->GetDetector(iplan,icham,isect);
218         ResetTracklets();
219         
220         if (makeTracks) {
221           iStack = idet / (AliTRDgeometry::Nplan());
222           if (iStackPrev != iStack) {
223             if (iStackPrev == -1) {
224               iStackPrev = iStack;
225             } 
226             else {
227               MakeTracks(idet-AliTRDgeometry::Nplan());
228               ResetTracklets();
229               iStackPrev = iStack;
230             }
231           }
232         }
233
234         Int_t nRowMax    = fCParam->GetRowMax(iplan,icham,isect);
235         Int_t nColMax    = fCParam->GetColMax(iplan);
236         Int_t nTimeTotal = fCalib->GetNumberOfTimeBins();
237
238         // Get the digits
239         fDigits = fDigitsManager->GetDigits(idet);
240         if (!fDigits) return kFALSE;
241         // This is to take care of switched off super modules
242         if (fDigits->GetNtime() == 0) {
243           continue;
244         }
245         fDigits->Expand();
246         fTrack0 = fDigitsManager->GetDictionary(idet,0);
247         if (!fTrack0) return kFALSE;
248         fTrack0->Expand();
249         fTrack1 = fDigitsManager->GetDictionary(idet,1);
250         if (!fTrack1) return kFALSE;
251         fTrack1->Expand();
252         fTrack2 = fDigitsManager->GetDictionary(idet,2); 
253         if (!fTrack2) return kFALSE;
254         fTrack2->Expand();
255
256         for (Int_t iRob = 0; iRob < fNROB; iRob++) {
257
258           for (Int_t iMcm = 0; iMcm < kNMCM; iMcm++) {
259
260             fMCM->Reset();
261             fMCM->SetRobId(iRob);
262             fMCM->SetChaId(idet);
263
264             SetMCMcoordinates(iMcm);
265
266             row = fMCM->GetRow();
267
268             if ((row < 0) || (row >= nRowMax)) {
269               AliError("MCM row number out of range.");
270               continue;
271             }
272
273             fMCM->GetColRange(col1,col2);
274             
275             for (time = 0; time < nTimeTotal; time++) {
276               for (col = col1; col < col2; col++) {
277                 if ((col >= 0) && (col < nColMax)) {
278                   amp = TMath::Abs(fDigits->GetDataUnchecked(row,col,time));
279                 } 
280                 else {
281                   amp = 0.0;
282                 }
283                 fMCM->SetADC(col-col1,time,amp);
284               }
285             }
286
287             if (fTrigParam->GetTailCancelation()) {
288               fMCM->Filter(fTrigParam->GetNexponential(),fTrigParam->GetFilterType());
289             }
290             
291             if (fMCM->Run()) {
292
293               for (Int_t iSeed = 0; iSeed < kMaxTrackletsPerMCM; iSeed++) {
294                 
295                 if (fMCM->GetSeedCol()[iSeed] < 0) {
296                   continue;
297                 }
298
299                 if (fTrigParam->GetDebugLevel()   > 1) 
300                   { 
301                     //AliInfo(Form("Add tracklet %d in col %02d \n",fNtracklets,fMCM->GetSeedCol()[iSeed]));
302                     AliDebug(5, Form("Add tracklet %d in col %02d \n",fNtracklets,fMCM->GetSeedCol()[iSeed]));
303                   }
304
305                 if (TestTracklet(idet,row,iSeed,0)) {
306                   AddTracklet(idet,row,iSeed,fNtracklets++);
307                   //AliInfo(Form("TESTED OK tracklet %d in col %02d \n",fNtracklets,fMCM->GetSeedCol()[iSeed]));
308                   AliDebug(5, Form("TESTED OK tracklet %d in col %02d \n",fNtracklets,fMCM->GetSeedCol()[iSeed]));
309                 }
310                 else
311                   {
312                     //AliInfo(Form("REJECTED tracklet %d in col %02d \n",fNtracklets,fMCM->GetSeedCol()[iSeed]));
313                     AliDebug(5, Form("REJECTED tracklet %d in col %02d \n",fNtracklets,fMCM->GetSeedCol()[iSeed]));
314                   }
315
316               }
317
318             }
319
320           }
321
322       
323         }
324
325         // Compress the arrays
326         fDigits->Compress(1,0);
327         fTrack0->Compress(1,0);
328         fTrack1->Compress(1,0);
329         fTrack2->Compress(1,0);
330
331         //WriteTracklets(idet);
332         TreeTracklets(idet);
333
334      }
335     }
336   }
337
338   if (makeTracks) {
339     idet++;
340     MakeTracks(idet - AliTRDgeometry::Nplan());
341     ResetTracklets();
342   }
343
344   return kTRUE;
345
346 }
347
348 //_____________________________________________________________________________
349 Bool_t AliTRDtriggerHLT::ResetTree()
350 {
351   //
352   // Recreate the cluster tree
353   //
354
355
356   //   if (fTrackletTree != 0)
357   //     fTrackletTree->Reset();
358   // well we'd better delete the whole tree and branches
359   delete fTrackletTree;
360   fTrackletTree = NULL;
361   fTrackletTree = new TTree("TRDclusterTree", "TRDclusterTree");
362   if (fTrackletTree)
363     {
364       fTreeCreatedHere = kTRUE;
365       //AliInfo("Tree Reset Successful");
366       AliDebug(1, Form("Tree Reset Successful"));
367     }
368   else
369     {
370       fTreeCreatedHere = kFALSE;
371       AliError("Reset Tree Error!\n");
372     }
373   
374   return fTreeCreatedHere;
375 }
376
377 //_____________________________________________________________________________
378 Bool_t AliTRDtriggerHLT::TreeTracklets(Int_t idet)
379 {
380   //
381   // Failsafe ::WriteTracklets - recreate the cluster tree if necessary
382   //
383
384   if (fTrackletTree == 0)
385     {
386       fTrackletTree = new TTree("TRDtrackletTree", "TRDtrackletTree");
387       fTreeCreatedHere = kTRUE;
388     }
389   
390   if (idet < 0)
391     {
392       AliError("Attempt to write tracklet tree on HLT - bad idea!");
393       AliError("HLT does not write any data here!\n");    
394       return kFALSE;
395     }
396   else
397     return WriteTracklets(idet);
398 }
399
400 //_____________________________________________________________________________
401 Bool_t AliTRDtriggerHLT::TestTracklet(Int_t det, Int_t row, Int_t seed, Int_t n)
402 {
403   //
404   // Check first the tracklet pt
405   //
406
407   Int_t nTimeTotal  = fCalib->GetNumberOfTimeBins();
408
409   // Calibration fill 2D
410   AliHLTTRDCalibra *calibra = AliHLTTRDCalibra::Instance();
411   if (!calibra) 
412     {
413       AliError("Could not get Calibra instance\n");
414     }
415
416   fTrkTest->Reset();
417
418   fTrkTest->SetDetector(det);
419   fTrkTest->SetRow(row);
420   fTrkTest->SetN(n);
421
422   Int_t iCol, iCol1, iCol2, track[3];
423   iCol = fMCM->GetSeedCol()[seed];  // 0....20 (MCM)
424   fMCM->GetColRange(iCol1,iCol2);   // range in the pad plane
425             
426   Float_t amp[3];
427   for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
428
429     amp[0] = fMCM->GetADC(iCol-1,iTime);
430     amp[1] = fMCM->GetADC(iCol  ,iTime);
431     amp[2] = fMCM->GetADC(iCol+1,iTime);
432
433     // extract track contribution only from the central pad
434     track[0] = fTrack0->GetDataUnchecked(row,iCol+iCol1,iTime);
435     track[1] = fTrack1->GetDataUnchecked(row,iCol+iCol1,iTime);
436     track[2] = fTrack2->GetDataUnchecked(row,iCol+iCol1,iTime);
437
438     if      (fMCM->IsCluster(iCol,iTime)) {
439
440       fTrkTest->AddCluster(iCol+iCol1,iTime,amp,track);
441
442     } 
443     else if ((iCol+1+1) < kMcmCol) {
444
445       amp[0] = fMCM->GetADC(iCol-1+1,iTime);
446       amp[1] = fMCM->GetADC(iCol  +1,iTime);
447       amp[2] = fMCM->GetADC(iCol+1+1,iTime);
448
449       if (fMCM->IsCluster(iCol+1,iTime)) {
450
451         // extract track contribution only from the central pad
452         track[0] = fTrack0->GetDataUnchecked(row,iCol+1+iCol1,iTime);
453         track[1] = fTrack1->GetDataUnchecked(row,iCol+1+iCol1,iTime);
454         track[2] = fTrack2->GetDataUnchecked(row,iCol+1+iCol1,iTime);
455
456         fTrkTest->AddCluster(iCol+1+iCol1,iTime,amp,track);
457
458       }
459
460     } 
461
462   }
463
464   fTrkTest->CookLabel(0.8);  
465   /*
466   if (fTrkTest->GetLabel() >= fNPrimary) {
467     Info("AddTracklet","Only primaries are stored!");
468     return;
469   }
470   */
471   // LTU Pt cut
472   //AliInfo(Form("Geom at 0x%x Field = %f", fGeo, fField));
473   fTrkTest->MakeTrackletGraph(fGeo,fField);
474
475   // TRD Online calibration
476   //if (calibra->GetMcmTracking()) {
477   //AliInfo(Form("Updating tracklet histos : %d", calibra->GetMcmTracking()));
478   //calibra->UpdateHistogramcm(fTrkTest);
479   //}
480
481   //AliInfo("Updating tracklet histos");
482   AliDebug(2, Form("Updating tracklet histos"));
483   calibra->UpdateHistogramcm(fTrkTest);
484
485   fTrkTest->MakeClusAmpGraph();
486   //AliInfo("MakeClusAmpGraph Done.");
487
488   if (TMath::Abs(fTrkTest->GetPt()) < fTrigParam->GetLtuPtCut()) 
489     {
490       //AliInfo(Form("Cut tracklet - pT is %f", TMath::Abs(fTrkTest->GetPt())));
491       AliDebug(5, Form("Cut tracklet - pT is %f", TMath::Abs(fTrkTest->GetPt())));
492       return kFALSE;
493     }
494   else
495     {
496       //AliInfo(Form("Tracklet passed - pT is %f", TMath::Abs(fTrkTest->GetPt())));
497       AliDebug(5, Form("Tracklet passed - pT is %f", TMath::Abs(fTrkTest->GetPt())));
498     }
499   return kTRUE;  
500
501 }