]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDdigitsManager.cxx
Added methods to list available reports and detectors. Changed Fill(..) method to...
[u/mrichter/AliRoot.git] / TRD / AliTRDdigitsManager.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 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 //  Manages the digits and the track dictionary in the form of               //
21 //  AliTRDdataArray objects.                                                 //
22 //                                                                           //
23 ///////////////////////////////////////////////////////////////////////////////
24
25 #include <Riostream.h>
26  
27 #include <TROOT.h>
28 #include <TTree.h>                                                              
29 #include <TFile.h>
30
31 #include "AliRun.h"
32 #include "AliLog.h"
33
34 #include "AliTRDdigitsManager.h"
35 #include "AliTRDsegmentArray.h"
36 #include "AliTRDdataArrayI.h"
37 #include "AliTRDdigit.h"
38 #include "AliTRDgeometry.h"
39
40 #include "AliTRDSignalIndex.h"
41
42 ClassImp(AliTRDdigitsManager)
43
44 //_____________________________________________________________________________
45
46   // Number of track dictionary arrays
47   const Int_t AliTRDdigitsManager::fgkNDict = kNDict;
48
49 //_____________________________________________________________________________
50 AliTRDdigitsManager::AliTRDdigitsManager()
51   :TObject()
52   ,fEvent(0)
53   ,fTree(0)
54   ,fDigits(0)
55   ,fIsRaw(0)
56   ,fSDigits(0)
57   ,fSignalIndexes(NULL)
58   ,fUseDictionaries(kTRUE)
59 {
60   //
61   // Default constructor
62   //
63
64   for (Int_t iDict = 0; iDict < kNDict; iDict++) {
65     fDictionary[iDict] = NULL;
66   }
67   
68   //fSignalIndexes = new TList();
69   fSignalIndexes = new TObjArray(AliTRDgeometry::Ndet());
70   
71 }
72
73 //_____________________________________________________________________________
74 AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
75   :TObject(m)
76   ,fEvent(m.fEvent)
77   ,fTree(0)
78   ,fDigits(0)
79   ,fIsRaw(m.fIsRaw)
80   ,fSDigits(m.fSDigits)
81   ,fSignalIndexes(NULL)
82   ,fUseDictionaries(kTRUE)
83 {
84   //
85   // AliTRDdigitsManager copy constructor
86   //
87
88 }
89
90 //_____________________________________________________________________________
91 AliTRDdigitsManager::~AliTRDdigitsManager()
92 {
93   //
94   // AliTRDdigitsManager destructor
95   //
96
97   if (fDigits) {
98     fDigits->Delete();
99     delete fDigits;
100     fDigits = NULL;
101   }
102
103   for (Int_t iDict = 0; iDict < kNDict; iDict++) {
104     fDictionary[iDict]->Delete();
105     delete fDictionary[iDict];
106     fDictionary[iDict] = NULL;
107   }
108
109   delete fSignalIndexes;
110   fSignalIndexes = NULL;
111 //   for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++)
112 //     delete fSignalIndexes[i];
113
114 }
115
116 //_____________________________________________________________________________
117 AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
118 {
119   //
120   // Assignment operator
121   //
122
123   if (this != &m) ((AliTRDdigitsManager &) m).Copy(*this);
124   return *this;
125
126 }
127
128 //_____________________________________________________________________________
129 void AliTRDdigitsManager::Copy(TObject &m) const
130 {
131   //
132   // Copy function
133   //
134
135   ((AliTRDdigitsManager &) m).fIsRaw   = fIsRaw;
136   ((AliTRDdigitsManager &) m).fEvent   = fEvent;
137   ((AliTRDdigitsManager &) m).fSDigits = fSDigits;
138   
139   ((AliTRDdigitsManager &) m).fSignalIndexes = fSignalIndexes;
140   ((AliTRDdigitsManager &) m).fUseDictionaries = fUseDictionaries;
141
142   TObject::Copy(m);
143
144 }
145
146 //_____________________________________________________________________________
147 void AliTRDdigitsManager::CreateArrays()
148 {
149   //
150   // Create the data arrays
151   //
152
153   fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
154
155   if (fUseDictionaries)
156     {
157       for (Int_t iDict = 0; iDict < kNDict; iDict++) {
158         fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
159                                                     ,AliTRDgeometry::Ndet());
160       }
161     }
162
163   for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++)
164     {
165       fSignalIndexes->AddLast(new AliTRDSignalIndex());
166     }
167 }
168 //_____________________________________________________________________________
169 void AliTRDdigitsManager::ResetArrays()
170 {
171   //
172   // Reset the data arrays
173   //
174
175   if (fDigits) {
176     delete fDigits;
177   }
178   fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
179
180   if (fUseDictionaries)
181     {
182       for (Int_t iDict = 0; iDict < kNDict; iDict++) {
183         if (fDictionary[iDict]) {  
184           delete fDictionary[iDict];
185         }
186         fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
187                                                     ,AliTRDgeometry::Ndet());
188       }
189     }
190
191   for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++)
192     {
193       AliTRDSignalIndex *idx = (AliTRDSignalIndex *)fSignalIndexes->At(i);
194       idx->Reset();
195     }
196 }
197
198 //_____________________________________________________________________________
199 void AliTRDdigitsManager::SetRaw()
200 {
201   //
202   // Switch on the raw digits flag
203   //
204
205   fIsRaw = kTRUE;
206   if (fDigits)
207     fDigits->SetBit(AliTRDdigit::RawDigit());
208   
209 }
210
211 //_____________________________________________________________________________
212 Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time
213                                        , Int_t det) const
214 {
215   //
216   // Returns the amplitude of a digit
217   //
218
219   if (!GetDigits(det)) return 0;
220   return ((Short_t) GetDigits(det)->GetData(row,col,time));
221
222 }
223  
224 //_____________________________________________________________________________
225 Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree)
226 {
227   //
228   // Creates the tree and branches for the digits and the dictionary
229   //
230
231   Int_t buffersize = 64000;
232
233   Bool_t status = kTRUE;
234
235   if (tree) {
236     fTree = tree;
237   }
238
239   // Make the branch for the digits
240   if (fDigits) {
241     const AliTRDdataArray *kDigits = (AliTRDdataArray *) fDigits->At(0);
242     if (kDigits) {
243       if (!fTree) return kFALSE;
244       TBranch* branch = fTree->GetBranch("TRDdigits");
245       if (!branch) fTree->Branch("TRDdigits",kDigits->IsA()->GetName(),
246                                  &kDigits,buffersize,99);
247       AliDebug(1,"Making branch TRDdigits\n");
248     }
249     else {
250       status = kFALSE;
251     }
252   }
253   else {
254     status = kFALSE;
255   }
256
257   if (fUseDictionaries)
258     {
259       // Make the branches for the dictionaries
260       for (Int_t iDict = 0; iDict < kNDict; iDict++) {
261         Char_t branchname[15];
262         sprintf(branchname,"TRDdictionary%d",iDict);
263         if (fDictionary[iDict]) {
264           const AliTRDdataArray *kDictionary = 
265             (AliTRDdataArray *) fDictionary[iDict]->At(0);
266           if (kDictionary) {
267             if (!fTree) return kFALSE;
268             TBranch* branch = fTree->GetBranch(branchname);
269             if (!branch) fTree->Branch(branchname,kDictionary->IsA()->GetName(),
270                                    &kDictionary,buffersize,99);
271             AliDebug(1,Form("Making branch %s\n",branchname));
272           }
273           else {
274             status = kFALSE;
275           }
276         }
277         else {
278           status = kFALSE;
279         }
280       }
281     }
282
283   return status;
284
285 }
286
287 //_____________________________________________________________________________
288 Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree)
289 {
290   //
291   // Reads the digit information from the input file
292   //
293
294   Bool_t status = kTRUE;
295
296   if (tree) {
297
298     fTree = tree;
299
300   }
301
302   if (!fDigits) {
303     AliDebug(1,"Create the data arrays.\n");
304     CreateArrays();
305   }
306
307   status = fDigits->LoadArray("TRDdigits",fTree);
308
309   if (fUseDictionaries)
310     {
311       for (Int_t iDict = 0; iDict < kNDict; iDict++) {
312         Char_t branchname[15];
313         sprintf(branchname,"TRDdictionary%d",iDict);
314         status = fDictionary[iDict]->LoadArray(branchname,fTree);
315         if (status == kFALSE)
316           {
317             fUseDictionaries = kFALSE;
318             AliWarning("Unable to load dict arrays. Will not use them.\n");
319             break;
320           }
321       }  
322     }
323
324   if (fDigits->TestBit(AliTRDdigit::RawDigit())) {
325     fIsRaw = kTRUE;
326   }
327   else {
328     fIsRaw = kFALSE;
329   }
330
331   return kTRUE;
332
333 }
334
335 //_____________________________________________________________________________
336 Bool_t AliTRDdigitsManager::WriteDigits()
337 {
338   //
339   // Writes out the TRD-digits and the dictionaries
340   //
341
342   // Store the contents of the segment array in the tree
343   if (!fDigits->StoreArray("TRDdigits",fTree)) {
344     AliError("Error while storing digits in branch TRDdigits\n");
345     return kFALSE;
346   }
347
348   if (fUseDictionaries)
349     {
350       for (Int_t iDict = 0; iDict < kNDict; iDict++) {
351         Char_t branchname[15];
352         sprintf(branchname,"TRDdictionary%d",iDict);
353         if (!fDictionary[iDict]->StoreArray(branchname,fTree)) {
354           AliError(Form("Error while storing dictionary in branch %s\n",branchname));
355           return kFALSE;
356         }
357       }
358     }
359
360   // Write the new tree to the output file
361   fTree->AutoSave();  // Modification by Jiri
362
363   return kTRUE;
364
365 }
366
367 //_____________________________________________________________________________
368 AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row, Int_t col
369                                          , Int_t time, Int_t det) const
370 {
371   // 
372   // Creates a single digit object 
373   //
374
375   Int_t digits[4];
376   Int_t amp[1];
377
378   digits[0] = det;
379   digits[1] = row;
380   digits[2] = col;
381   digits[3] = time;
382
383   amp[0]    = GetDigits(det)->GetData(row,col,time);
384   
385   return (new AliTRDdigit(fIsRaw,digits,amp));
386
387 }
388
389 //_____________________________________________________________________________
390 Int_t AliTRDdigitsManager::GetTrack(Int_t track
391                                   , Int_t row, Int_t col, Int_t time
392                                   , Int_t det) const
393 {
394   // 
395   // Returns the MC-track numbers from the dictionary.
396   //
397
398   if ((track < 0) || (track >= kNDict)) {
399     AliError(Form("track %d out of bounds (size: %d, this: 0x%08x)"
400                  ,track,kNDict,this));
401     return -1;
402   }
403
404   if (fUseDictionaries == kFALSE)
405     {
406       return -1;
407     }
408   // Array contains index+1 to allow data compression
409   return (GetDictionary(det,track)->GetData(row,col,time) - 1);
410
411 }
412
413 //_____________________________________________________________________________
414 AliTRDdataArrayI *AliTRDdigitsManager::GetDigits(Int_t det) const
415 {
416   //
417   // Returns the digits array for one detector
418   //
419
420   if (!fDigits) return 0x0;
421   return (AliTRDdataArrayI *) fDigits->At(det);
422
423 }
424
425 //_____________________________________________________________________________
426 AliTRDdataArrayI *AliTRDdigitsManager::GetDictionary(Int_t det, Int_t i) const
427 {
428   //
429   // Returns the dictionary for one detector
430   //
431   if (fUseDictionaries == kFALSE)
432     {
433       return NULL;
434     }
435
436   return (AliTRDdataArrayI *) fDictionary[i]->At(det);
437
438 }
439
440 //_____________________________________________________________________________
441 Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *Digit) const
442 {
443   // 
444   // Returns the MC-track numbers from the dictionary for a given digit
445   //
446
447   Int_t row  = Digit->GetRow();
448   Int_t col  = Digit->GetCol();
449   Int_t time = Digit->GetTime();
450   Int_t det  = Digit->GetDetector();
451
452   return GetTrack(track,row,col,time,det);
453
454 }
455
456 //_____________________________________________________________________________
457 AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det) 
458 {
459   // 
460   // Returns indexes of active pads
461   //
462
463   return (AliTRDSignalIndex*)fSignalIndexes->At(det);
464
465 }
466
467 //_____________________________________________________________________________
468 void AliTRDdigitsManager::RemoveDigits(Int_t det) 
469 {
470   // 
471   // Clear memory
472   //
473
474   fDigits->ClearSegment(det);
475
476 }
477
478 //_____________________________________________________________________________
479 void AliTRDdigitsManager::RemoveDictionaries(Int_t det) 
480 {
481   // 
482   // Clear memory
483   //
484   if (fUseDictionaries == kFALSE)
485     {
486       return;
487     }
488
489   for (Int_t i = 0; i < kNDict; i++) {
490     fDictionary[i]->ClearSegment(det);
491   }
492
493 }
494
495 //_____________________________________________________________________________
496 void AliTRDdigitsManager::ClearIndexes(Int_t det) 
497 {
498   // 
499   // Clear memory
500   //
501   fSignalIndexes->At(det)->Clear();  
502 }
503
504
505 //_____________________________________________________________________________
506 Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det)
507 {
508   //
509   // Build the list of indices
510   //
511
512   Int_t nRows = 0;
513   Int_t nCols = 0;
514   Int_t nTbins = 0;
515
516   AliTRDgeometry    geom;
517   AliTRDdataArrayI *digits = GetDigits(det);
518   //digits should be expanded by now!!!
519   if (digits->GetNtime() > 0) 
520     {
521       digits->Expand();
522       nRows = digits->GetNrow();
523       nCols = digits->GetNcol();
524       nTbins = digits->GetNtime();
525
526       //AliInfo(Form("rows %d cols %d tbins %d", nRows, nCols, nTbins));
527
528       AliTRDSignalIndex* indexes = GetIndexes(det);
529       indexes->SetSM(geom.GetSector(det));
530       indexes->SetChamber(geom.GetChamber(det));
531       indexes->SetPlane(geom.GetPlane(det));
532       indexes->SetDetNumber(det);
533       if (indexes->IsAllocated() == kFALSE)
534         {
535           indexes->Allocate(nRows, nCols, nTbins);
536           //AliInfo(Form("Allocating 0x%x %d", indexes->GetArray(), indexes->GetArray()->GetSize()));
537         }
538       for (Int_t ir = 0; ir < nRows; ir++)
539         {
540           for (Int_t ic = 0; ic < nCols; ic++)
541             {
542               for (Int_t it = 0; it < nTbins; it++)
543                 {         
544                   //AliInfo(Form("row %d col %d tbin %d", ir, ic, it));
545                   
546                   Int_t isig = digits->GetDataUnchecked(ir, ic, it);
547                   if (isig > 0)
548                     {
549                       //AliInfo(Form("row %d col %d tbin %d", ir, ic, it));
550                       indexes->AddIndexTBin(ir, ic, it);            
551                     }
552                 } //tbins
553             } //cols
554         } // rows
555     } // if GetNtime
556   else
557     {
558       return kFALSE;
559     }
560   return kTRUE;
561
562 }