]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDdigitsManager.cxx
Add ADCbaseline to AliTRDdigitsParam
[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 //  TObjArray objects                                                        //
22 //                                                                           //
23 ///////////////////////////////////////////////////////////////////////////////
24
25 #include <TTree.h>                                                              
26
27 #include "AliLog.h"
28
29 #include "AliTRDdigitsManager.h"
30 #include "AliTRDarrayDictionary.h"
31 #include "AliTRDarrayADC.h"
32 #include "AliTRDarraySignal.h"
33 #include "AliTRDdigit.h"
34 #include "AliTRDdigitsParam.h"
35 #include "AliTRDSimParam.h"
36 #include "AliTRDgeometry.h"
37 #include "AliTRDSignalIndex.h"
38
39 ClassImp(AliTRDdigitsManager)
40
41 //_____________________________________________________________________________
42
43   // Number of track dictionary arrays
44   const Int_t AliTRDdigitsManager::fgkNDict = kNDict;
45
46 //_____________________________________________________________________________
47 AliTRDdigitsManager::AliTRDdigitsManager(Bool_t rawRec)
48   :TObject()
49   ,fEvent(0)
50   ,fTree(0)
51   ,fDigits(0) 
52   ,fHasSDigits(0)
53   ,fSignalIndexes(NULL)
54   ,fUseDictionaries(kTRUE)
55   ,fDets(AliTRDgeometry::Ndet())
56   ,fRawRec(rawRec)
57   ,fDigitsParam(0)
58 {
59   //
60   // Default constructor
61   //
62   
63   if (fRawRec)
64     {
65       fDets   = 1;
66       fRawRec = kTRUE;
67     }
68
69   for (Int_t iDict = 0; iDict < kNDict; iDict++) 
70     {
71       fDict[iDict] = NULL;
72     }
73   
74 }
75
76 //_____________________________________________________________________________
77 AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
78   :TObject(m)
79   ,fEvent(m.fEvent)
80   ,fTree(0)
81   ,fDigits(0) 
82   ,fHasSDigits(m.fHasSDigits)
83   ,fSignalIndexes(NULL)
84   ,fUseDictionaries(kTRUE)
85   ,fDets(m.fDets)
86   ,fRawRec(m.fRawRec)
87   ,fDigitsParam(NULL)
88 {
89   //
90   // AliTRDdigitsManager copy constructor
91   //
92
93 }
94
95 //_____________________________________________________________________________
96 AliTRDdigitsManager::~AliTRDdigitsManager()
97 {
98   //
99   // AliTRDdigitsManager destructor
100   //
101
102
103   if (fDigits) 
104     {
105       fDigits->Delete();
106       delete fDigits;
107       fDigits = NULL;
108     }
109
110   for (Int_t iDict = 0; iDict < kNDict; iDict++) 
111     {
112       if(fDict[iDict])
113         {
114           fDict[iDict]->Delete();
115           delete fDict[iDict];
116           fDict[iDict] = NULL;
117         }
118     }
119
120   if (fSignalIndexes) 
121     {
122       fSignalIndexes->Delete();
123       delete fSignalIndexes;
124       fSignalIndexes = NULL;
125     }
126
127   if (fDigitsParam)
128     {
129       delete fDigitsParam;
130       fDigitsParam = NULL;
131     }
132
133 }
134
135 //_____________________________________________________________________________
136 AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
137 {
138   //
139   // Assignment operator
140   //
141
142   if (this != &m) 
143     {
144       ((AliTRDdigitsManager &) m).Copy(*this);
145     }
146
147   return *this;
148
149 }
150
151 //_____________________________________________________________________________
152 void AliTRDdigitsManager::Copy(TObject &m) const
153 {
154   //
155   // Copy function
156   //
157
158   ((AliTRDdigitsManager &) m).fEvent           = fEvent;
159   ((AliTRDdigitsManager &) m).fHasSDigits      = fHasSDigits;
160   ((AliTRDdigitsManager &) m).fDigits          = NULL;
161   for(Int_t i = 0; i < kNDict; i++)
162     {
163       ((AliTRDdigitsManager &) m).fDict[i]  = NULL;
164     }
165   ((AliTRDdigitsManager &) m).fSignalIndexes   = NULL;
166   ((AliTRDdigitsManager &) m).fUseDictionaries = fUseDictionaries;
167   ((AliTRDdigitsManager &) m).fDets            = fDets;
168   ((AliTRDdigitsManager &) m).fRawRec          = fRawRec;
169   ((AliTRDdigitsManager &) m).fDigitsParam     = NULL;
170
171   TObject::Copy(m);
172
173 }
174
175 //_____________________________________________________________________________
176 void AliTRDdigitsManager::CreateArrays()
177 {
178   //
179   // Create the data arrays
180   //
181
182   if (fHasSDigits) 
183     {
184       if (fDigits)                                        
185         {                                                   
186           fDigits->Delete();                                
187           delete fDigits;                                   
188         }                                                    
189       fDigits = new TObjArray(fDets);
190       for (Int_t index = 0; index < fDets; index++) 
191         {
192           fDigits->AddAt(new AliTRDarraySignal(),index);
193         }
194     }
195   else 
196     {
197       if (fDigits)                                          
198         {                                                    
199           fDigits->Delete();                                
200           delete fDigits;                                   
201         }                                                   
202       fDigits = new TObjArray(fDets);    
203       for (Int_t index = 0; index < fDets; index++) 
204         {
205           fDigits->AddAt(new AliTRDarrayADC(),index);
206         }
207     }
208
209   if (fUseDictionaries) 
210     {
211       for (Int_t iDict = 0; iDict < kNDict; iDict++)
212         {
213           if (fDict[iDict])                                   
214             {
215               fDict[iDict]->Delete();                                
216               delete fDict[iDict];                                    
217             }
218           fDict[iDict] = new TObjArray(fDets);
219           for (Int_t index = 0; index < fDets; index++) 
220             {
221               fDict[iDict]->AddAt(new AliTRDarrayDictionary(),index);
222             }
223         }
224     }
225   
226   if (fSignalIndexes)
227     {
228       fSignalIndexes->Delete();
229       delete fSignalIndexes;
230     }
231   fSignalIndexes = new TObjArray(fDets);
232   for (Int_t i = 0; i < fDets; i++)
233     {
234       fSignalIndexes->AddLast(new AliTRDSignalIndex());
235     }
236
237   if (fDigitsParam)
238     {
239       delete fDigitsParam;
240     }
241   fDigitsParam = new AliTRDdigitsParam();
242   fDigitsParam->SetNTimeBins(AliTRDSimParam::Instance()->GetNTimeBins());
243   fDigitsParam->SetADCbaseline(AliTRDSimParam::Instance()->GetADCbaseline());
244
245 }
246
247 //_____________________________________________________________________________
248 void AliTRDdigitsManager::ResetArrays()
249 {
250   //
251   // Reset the data arrays
252   //
253
254   if (fDigits)
255     {
256       fDigits->Delete();
257       delete fDigits;
258     }
259   if (fHasSDigits)
260     {
261       fDigits = new TObjArray(fDets);     
262       for (Int_t index = 0; index < fDets; index++) 
263         {
264           fDigits->AddAt(new AliTRDarraySignal(),index);
265         }
266     }
267   else
268     {
269       fDigits = new TObjArray(fDets);
270       for (Int_t index = 0; index < fDets; index++)
271         {
272           fDigits->AddAt(new AliTRDarrayADC(),index);
273         }
274     }
275   
276   for (Int_t iDict = 0; iDict < kNDict; iDict++)
277     {
278       if (fDict[iDict])
279         {
280           fDict[iDict]->Delete();
281           delete fDict[iDict];
282           fDict[iDict] = NULL;
283         }
284     }
285   if (fUseDictionaries) 
286     {
287       for (Int_t iDict = 0; iDict < kNDict; iDict++)
288         {
289           fDict[iDict] = new TObjArray(fDets);
290           for (Int_t index = 0; index < fDets; index++)
291             {
292               fDict[iDict]->AddAt(new AliTRDarrayDictionary(),index);
293             }
294         }
295     }
296   
297   if (fSignalIndexes)
298     {
299       fSignalIndexes->Delete();
300       delete fSignalIndexes;
301     }
302   fSignalIndexes = new TObjArray(fDets);
303   for (Int_t i = 0; i < fDets; i++)
304     {
305       fSignalIndexes->AddLast(new AliTRDSignalIndex());
306     }
307
308 }
309
310 //_____________________________________________________________________________
311 void AliTRDdigitsManager::ResetArrays(Int_t det)
312 {
313   //
314   // Reset the data arrays
315   //
316
317   Int_t recoDet = fRawRec ? 0 : det;
318
319   RemoveDigits(recoDet);
320   RemoveDictionaries(recoDet);
321   RemoveIndexes(recoDet);
322
323   if (fHasSDigits)
324     {
325       fDigits->AddAt(new AliTRDarraySignal(),recoDet);
326     }
327   else
328     {
329       fDigits->AddAt(new AliTRDarrayADC(),recoDet);
330     }
331
332   if (fUseDictionaries) 
333     {
334       for (Int_t iDict = 0; iDict < kNDict; iDict++)
335         {
336           fDict[iDict]->AddAt(new AliTRDarrayDictionary(),recoDet);
337         }
338     }
339   
340   fSignalIndexes->AddAt(new AliTRDSignalIndex(),recoDet);
341
342 }
343
344 //_____________________________________________________________________________
345 Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time, Int_t det) const
346 {
347   //
348   // Returns the amplitude of a digit
349   //
350
351   if (!GetDigits(det)) return 0;
352   
353   return ((Short_t) ((AliTRDarrayADC *) GetDigits(det))->GetDataBits(row,col,time));
354
355 }
356
357 //_____________________________________________________________________________
358 UChar_t AliTRDdigitsManager::GetPadStatus(Int_t row, Int_t col, Int_t time, Int_t det) const
359 {
360   //
361   // Returns the pad status for the requested pad
362   //
363         
364   if (!GetDigits(det)) return 0;
365
366   return ((UChar_t) ((AliTRDarrayADC *) GetDigits(det))->GetPadStatus(row,col,time));
367  
368 }
369
370 //_____________________________________________________________________________
371 Bool_t AliTRDdigitsManager::MakeBranch(TTree * const tree)  
372 {
373   //
374   // Creates the tree and branches for the digits and the dictionary
375   //
376
377   Int_t  buffersize = 64000;
378   Bool_t status     = kTRUE;
379
380   if (tree) 
381     {
382       fTree = tree;
383     }
384
385   // Make the branch for the digits
386   if (fDigits) 
387     {
388       if (fHasSDigits)
389         {
390           const AliTRDarraySignal *kDigits = (AliTRDarraySignal *) fDigits->At(0); 
391           if (kDigits) 
392             {
393               if (!fTree) return kFALSE;
394               AliDebug(1,"Making branch for SDigits!\n");
395               TBranch *branch = fTree->GetBranch("TRDdigits");
396               if (!branch)
397                 {
398                   fTree->Branch("TRDdigits","AliTRDarraySignal",&kDigits,buffersize,99);
399                 }
400               AliDebug(1,"Making branch TRDdigits\n");
401             }
402           else 
403             {
404               status = kFALSE;
405             }
406         }
407
408       if (!fHasSDigits)
409         {
410           const AliTRDarrayADC *kDigits = (AliTRDarrayADC *) fDigits->At(0);
411           if (kDigits) 
412             {
413               if (!fTree) return kFALSE;
414               AliDebug(1,"Making branch for Digits!\n");
415               TBranch *branch = fTree->GetBranch("TRDdigits");
416               if (!branch) 
417                 {
418                   fTree->Branch("TRDdigits","AliTRDarrayADC",&kDigits,buffersize,99);
419                 }
420               AliDebug(1,"Making branch TRDdigits\n");        
421             }
422           else 
423             {
424               status = kFALSE;
425             }
426         }
427
428     }
429   else
430     {
431
432       status = kFALSE;
433
434     }
435   
436   if (fUseDictionaries) 
437     {
438       // Make the branches for the dictionaries
439       for (Int_t iDict = 0; iDict < kNDict; iDict++) 
440         {
441           Char_t branchname[15];
442           sprintf(branchname,"TRDdictionary%d",iDict); 
443           if (fDict[iDict]) 
444             {
445               const AliTRDarrayDictionary *kDictionary = (AliTRDarrayDictionary *) fDict[iDict]->At(0);
446               if (kDictionary) 
447                 {
448                   if (!fTree) return kFALSE;
449                   AliDebug(2,"Making branch for dictionary!\n");
450                   TBranch *branch = fTree->GetBranch(branchname);
451                   if (!branch) 
452                     {
453                       fTree->Branch(branchname,"AliTRDarrayDictionary",&kDictionary,buffersize,99);
454                     }
455                   AliDebug(1,Form("Making branch %s\n",branchname));
456                 }
457               else 
458                 {
459                   status = kFALSE;
460                 }
461             }
462           else 
463             {
464               status = kFALSE;
465             }
466         }
467     }
468
469   if (fDigitsParam)
470     {
471       const AliTRDdigitsParam *kDigitsParam = fDigitsParam;
472       if (!fTree) return kFALSE;
473       TBranch *branch = fTree->GetBranch("TRDdigitsParam");
474       if (!branch) 
475         {
476           fTree->Branch("TRDdigitsParam","AliTRDdigitsParam",&kDigitsParam,buffersize,99);
477         }
478       AliDebug(1,"Making branch AliTRDdigitsParam\n");
479     }
480
481   return status;
482
483 }
484
485 //_____________________________________________________________________________
486 Bool_t AliTRDdigitsManager::ReadDigits(TTree * const tree)
487 {
488   //
489   // Reads the digit information from the input file
490   //
491
492   Bool_t status = kTRUE;
493
494   if (tree) 
495     {
496       fTree = tree;
497     }
498
499   if (!fDigits) 
500     {
501       AliDebug(1,"Create the data arrays.\n");
502       CreateArrays();
503     }
504
505   status = LoadArrayDigits();
506
507   if (fUseDictionaries) 
508     {
509       status = LoadArrayDict();
510       if (status == kFALSE) 
511         {
512           fUseDictionaries = kFALSE;
513           AliWarning("Unable to load dict arrays. Will not use them.\n");
514         }
515     }  
516
517   if (!LoadDigitsParam()) {
518     AliWarning("Could not read digits parameter.");
519     if (fDigitsParam) {
520       delete fDigitsParam;
521     }
522     AliWarning(Form("Create default version of digits parameter (NTimeBin=%d).\n"
523                    ,AliTRDSimParam::Instance()->GetNTimeBins()));
524     fDigitsParam = new AliTRDdigitsParam();
525     fDigitsParam->SetNTimeBins(AliTRDSimParam::Instance()->GetNTimeBins());
526     fDigitsParam->SetADCbaseline(AliTRDSimParam::Instance()->GetADCbaseline());
527   }
528
529   return status;
530
531 }
532
533 //_____________________________________________________________________________
534 Bool_t AliTRDdigitsManager::WriteDigits()
535 {
536   //
537   // Writes out the TRD-digits and the dictionaries
538   //
539
540   if (!StoreArrayDigits())
541     {
542       AliError("Error while storing digits\n");
543       return kFALSE;
544     }
545
546   if (fUseDictionaries) 
547     {
548       if (!StoreArrayDict())
549         {
550           AliError("Error while storing dictionaries in branch\n");
551           return kFALSE;
552         }
553     }
554   
555   // Write the new tree to the output file
556   fTree->AutoSave();
557
558   return kTRUE;
559
560 }
561
562 //_____________________________________________________________________________
563 AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row
564                                          , Int_t col
565                                          , Int_t time
566                                          , Int_t det) const
567 {
568   // 
569   // Creates a single digit object 
570   //
571
572   Int_t digits[4]; 
573   Int_t amp[1];
574
575   digits[0] = det;
576   digits[1] = row;
577   digits[2] = col;
578   digits[3] = time;
579
580   amp[0]    = ((AliTRDarrayADC *) GetDigits(det))->GetData(row,col,time);
581   
582   return (new AliTRDdigit(digits,amp));
583
584 }
585
586 //_____________________________________________________________________________
587 Int_t AliTRDdigitsManager::GetTrack(Int_t track
588                                   , Int_t row
589                                   , Int_t col
590                                   , Int_t time
591                                   , Int_t det) const
592 {
593   // 
594   // Returns the MC-track numbers from the dictionary.
595   //
596
597   if ((track < 0) || (track >= kNDict)) 
598     {
599       AliError(Form("track %d out of bounds (size: %d, this: 0x%08x)",track,kNDict,this));
600       return -1;
601     }
602
603   if (fUseDictionaries == kFALSE) 
604     {
605       return -1;
606     }
607
608   // Array contains index+1 to allow data compression--->Changed
609   return (((AliTRDarrayDictionary *) GetDictionary(det,track))->GetData(row,col,time) );
610
611 }
612
613 //________________________________________________________________________________
614 AliTRDarrayADC *AliTRDdigitsManager::GetDigits(Int_t det) const
615 {
616   //
617   // Returns the digits array for one detector
618   //
619
620   Int_t RecoDet = fRawRec ? 0 : det;
621
622   if (!fDigits)   
623     {
624       return 0x0;
625     }
626
627   if (!fHasSDigits)
628     {
629       ((AliTRDarrayADC *) fDigits->At(RecoDet))->SetNdet(det);
630       return (AliTRDarrayADC *) fDigits->At(RecoDet); 
631     }
632   else
633     {
634       AliDebug(2,"ERROR IN DATA TYPE!!!!");
635       return 0x0;
636     }
637
638 }
639
640 //_____________________________________________________________________________
641 AliTRDarraySignal *AliTRDdigitsManager::GetSDigits(Int_t det) const
642 {
643   //
644   // Returns the sdigits array for one detector
645   //
646
647   Int_t RecoDet = fRawRec ? 0 : det;
648
649   if (!fDigits)   
650     {
651       //      AliDebug(1,"NO FDIGITS!");        
652       return 0x0;
653     }
654
655   if (fHasSDigits)
656     {
657       ((AliTRDarraySignal *) fDigits->At(RecoDet))->SetNdet(det);
658       return (AliTRDarraySignal *) fDigits->At(RecoDet);
659     }
660   else
661     {
662       AliDebug(2,"ERROR IN DATA TYPE!!!!");
663       return 0x0;
664     }
665
666 }
667
668 //_____________________________________________________________________________
669 AliTRDarrayDictionary *AliTRDdigitsManager::GetDictionary(Int_t det
670                                                         , Int_t i) const
671 {
672   //
673   // Returns the dictionary for one detector
674   //
675
676   Int_t RecoDet = fRawRec ? 0 : det;
677
678   if (fUseDictionaries == kFALSE)
679     {
680       return 0x0;
681     }
682
683   ((AliTRDarrayDictionary *) fDigits->At(RecoDet))->SetNdet(det);
684   return (AliTRDarrayDictionary *) fDict[i]->At(RecoDet);
685   
686 }
687
688 //_____________________________________________________________________________
689 Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit * const digit) const
690 {
691   // 
692   // Returns the MC-track numbers from the dictionary for a given digit
693   //
694
695   Int_t row  = digit->GetRow();
696   Int_t col  = digit->GetCol();
697   Int_t time = digit->GetTime();
698   Int_t det  = digit->GetDetector();
699
700   return GetTrack(track,row,col,time,det);
701
702 }
703
704 //_____________________________________________________________________________
705 AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det) 
706 {
707   // 
708   // Returns indexes of active pads
709   //
710
711   Int_t RecoDet = fRawRec ? 0 : det;
712
713   return (AliTRDSignalIndex *) fSignalIndexes->At(RecoDet);
714
715 }
716
717 //_____________________________________________________________________________
718 void AliTRDdigitsManager::RemoveDigits(Int_t det) 
719 {
720    // 
721    // Clear memory at det for Digits
722    //
723
724   Int_t RecoDet = fRawRec ? 0 : det;
725
726   if (fDigits->At(RecoDet))
727     {
728       if (fHasSDigits) 
729         {
730           AliTRDarraySignal *arr = (AliTRDarraySignal *) fDigits->RemoveAt(RecoDet);
731           delete arr;
732         }
733       else 
734         {
735           AliTRDarrayADC    *arr = (AliTRDarrayADC *)    fDigits->RemoveAt(RecoDet);
736           delete arr;
737         }
738     }
739
740 }
741
742 //_____________________________________________________________________________
743 void AliTRDdigitsManager::RemoveDictionaries(Int_t det) 
744 {
745   // 
746   // Clear memory
747   //
748
749   Int_t RecoDet = fRawRec ? 0 : det;
750
751   if (fUseDictionaries == kFALSE) 
752     {
753       return;
754     }
755
756   for (Int_t i = 0; i < kNDict; i++) 
757     {
758       if (fDict[i]->At(RecoDet))
759         {
760           AliTRDarrayDictionary *arr = (AliTRDarrayDictionary *) fDict[i]->RemoveAt(RecoDet);
761           delete arr;
762         }
763     }
764
765 }
766
767 //_____________________________________________________________________________
768 void AliTRDdigitsManager::RemoveIndexes(Int_t det) 
769 {
770    // 
771    // Clear memory
772    //
773
774   Int_t RecoDet = fRawRec ? 0 : det;
775
776   if (fSignalIndexes->At(RecoDet))
777     {
778       AliTRDSignalIndex *arr = (AliTRDSignalIndex *) fSignalIndexes->RemoveAt(RecoDet);
779       delete arr;
780     }
781
782 }
783
784 //_____________________________________________________________________________
785 void AliTRDdigitsManager::ClearIndexes(Int_t det) 
786 {
787   // 
788   // Clear memory
789   //
790   
791   Int_t RecoDet = fRawRec ? 0 : det;
792
793   ((AliTRDSignalIndex *) fSignalIndexes->At(RecoDet))->ClearAll();  
794
795 }
796
797 //_____________________________________________________________________________
798 Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det)
799 {
800   //
801   // Build the list of indices
802   //
803
804   Int_t nRows  = 0;
805   Int_t nCols  = 0;
806   Int_t nTbins = 0;
807
808   AliTRDgeometry  geom;
809   AliTRDarrayADC *digits = 0x0;
810
811   if (fHasSDigits) 
812     {
813       return kFALSE;
814     }
815   else 
816     {
817       digits = (AliTRDarrayADC *) GetDigits(det);
818     }
819
820   // digits should be expanded by now!!!
821   if (digits->GetNtime() > 0) 
822     {      
823       digits->Expand(); 
824       nRows  = digits->GetNrow();
825       nCols  = digits->GetNcol();
826       nTbins = digits->GetNtime();
827       
828       AliTRDSignalIndex *indexes = GetIndexes(det);
829       indexes->SetSM(geom.GetSector(det));
830       indexes->SetStack(geom.GetStack(det));
831       indexes->SetLayer(geom.GetLayer(det));
832       indexes->SetDetNumber(det);
833
834       if (indexes->IsAllocated() == kFALSE)
835         {
836           indexes->Allocate(nRows,nCols,nTbins);
837         }
838
839       for (Int_t ir = 0; ir < nRows; ir++) 
840         {
841           for (Int_t ic = 0; ic < nCols; ic++) 
842             {
843               for (Int_t it = 0; it < nTbins; it++)
844                 {         
845                   Int_t isig = digits->GetDataBits(ir,ic,it);
846                   if (isig > 0) 
847                     {
848                       indexes->AddIndexRC(ir,ic);           
849                     }
850                 } // tbins
851             } // cols
852         } // rows
853
854     } // if GetNtime
855   else 
856     {
857       return kFALSE;
858     }
859   
860   return kTRUE;
861
862 }
863
864 //_____________________________________________________________________________
865 Bool_t AliTRDdigitsManager::LoadArrayDigits()
866 {
867   //
868   // Loads the (s-)digits arrays for all detectors
869   //
870
871   if (!fTree) 
872     {
873       AliError("Digits tree is not defined\n");
874       return kFALSE;
875     }
876
877   Bool_t status = kTRUE;
878
879   // Get the branch
880   TBranch *branch = fTree->GetBranch("TRDdigits");
881   if (!branch) 
882     {
883       AliError("Branch TRDdigits is not defined\n");
884       return kFALSE;
885     }
886
887   // Loop through all detectors and read them from the tree
888   for (Int_t iDet = 0; iDet < fDets; iDet++) 
889     {
890       if (fHasSDigits)
891         {
892           AliTRDarraySignal *dataArray = (AliTRDarraySignal *) fDigits->At(iDet);
893           if (!dataArray) 
894             {
895               status = kFALSE;
896               break;    
897             }
898           branch->SetAddress(&dataArray);
899           branch->GetEntry(iDet);
900         }
901       else
902         {
903           AliTRDarrayADC    *dataArray = (AliTRDarrayADC *)    fDigits->At(iDet);
904           if (!dataArray) 
905             {
906               status = kFALSE;
907               break;
908             }
909           branch->SetAddress(&dataArray);
910           branch->GetEntry(iDet);
911         }
912     }
913
914   return status;
915
916 }
917
918 //________________________________________________________________________________________________
919 Bool_t AliTRDdigitsManager::LoadArrayDict()
920 {
921   //
922   // Loads dictionary arrays for all detectors
923   //
924
925   if (!fTree) 
926     {
927       AliError("Digits tree is not defined\n");
928       return kFALSE;
929     }
930
931   Bool_t status = kTRUE;
932
933   for (Int_t iDict = 0; iDict < kNDict; iDict++) 
934     {
935
936       // Get the branch
937       Char_t branchname[15];
938       sprintf(branchname,"TRDdictionary%d",iDict);
939       TBranch *branch = fTree->GetBranch(branchname);
940       if (!branch) 
941         {
942           AliError(Form("Branch %s is not defined\n",branchname));
943           return kFALSE;
944         }
945
946       // Loop through all detectors and read them from the tree
947       for (Int_t iDet = 0; iDet < fDets; iDet++) 
948         {
949           AliTRDarrayDictionary *dataArray = (AliTRDarrayDictionary *) fDict[iDict]->At(iDet);
950           if (!dataArray) 
951             {
952               status = kFALSE;
953               break;    
954             }
955           branch->SetAddress(&dataArray);
956           branch->GetEntry(iDet);
957         }
958
959     }
960
961   return status;
962
963 }
964
965 //_____________________________________________________________________________
966 Bool_t AliTRDdigitsManager::LoadDigitsParam()
967 {
968   //
969   // Loads the digits parameter object from the digits tree
970   //
971
972   if (!fTree) 
973     {
974       AliError("Digits tree is not defined\n");
975       return kFALSE;
976     }
977
978   // Get the branch
979   TBranch *branch = fTree->GetBranch("TRDdigitsParam");
980   if (!branch) 
981     {
982       AliError("Branch TRDdigitsParam is not defined\n");
983       return kFALSE;
984     }
985
986   // Read the parameter object
987   AliTRDdigitsParam *digitsParam = fDigitsParam;
988   if (!digitsParam)
989     {
990       return kFALSE;
991     }
992
993   branch->SetAddress(&digitsParam);
994   branch->GetEntry();
995
996   return kTRUE;
997
998 }
999
1000 //_____________________________________________________________________________
1001 Bool_t AliTRDdigitsManager::StoreArrayDigits()
1002 {
1003   //
1004   // Stores the digit arrays for all detectors
1005   //
1006
1007   if (!fTree) 
1008     {
1009       AliError("Digits tree is not defined\n");
1010       return kFALSE;
1011     }
1012
1013   // Get the branch
1014   TBranch *branch = fTree->GetBranch("TRDdigits");
1015   if (!branch) 
1016     {
1017       AliError("Branch TRDdigits is not defined\n");
1018       return kFALSE;
1019     }
1020
1021   // Loop through all detectors and fill them into the tree
1022   Bool_t status = kTRUE;
1023   for (Int_t iDet = 0; iDet < fDets; iDet++) 
1024     {
1025       if (fHasSDigits)
1026         {
1027           const AliTRDarraySignal *kDataArray = (AliTRDarraySignal *) fDigits->At(iDet);
1028           if (!kDataArray) 
1029             {
1030               status = kFALSE;
1031               break;
1032             }
1033           branch->SetAddress(&kDataArray);
1034           branch->Fill();
1035         }
1036       else
1037         {
1038           const AliTRDarrayADC    *kDataArray = (AliTRDarrayADC *)    fDigits->At(iDet); 
1039           if (!kDataArray) 
1040             {
1041               status = kFALSE;
1042               break;
1043             }
1044           branch->SetAddress(&kDataArray);
1045           branch->Fill();
1046         }
1047     }
1048
1049   return status;
1050
1051 }
1052
1053 //_____________________________________________________________________________
1054 Bool_t AliTRDdigitsManager::StoreArrayDict()
1055 {
1056   //
1057   // Stores the dictionary arrays for all detectors
1058   //
1059
1060   if (!fTree) 
1061     {
1062       AliError("Digits tree is not defined\n");
1063       return kFALSE;
1064     }
1065
1066   Bool_t status = kTRUE;
1067
1068   for (Int_t iDict = 0; iDict < kNDict; iDict++)
1069      {
1070
1071        // Get the branch
1072        Char_t branchname[15];
1073        sprintf(branchname,"TRDdictionary%d",iDict);
1074        TBranch *branch = fTree->GetBranch(branchname);
1075        if (!branch) 
1076          {
1077            AliError(Form("Branch %s is not defined\n",branchname));
1078            return kFALSE;
1079          }
1080
1081        // Loop through all detectors and fill them into the tree
1082        for (Int_t iDet = 0; iDet < fDets; iDet++) 
1083          {
1084            const AliTRDarrayDictionary *kDataArray = (AliTRDarrayDictionary *) fDict[iDict]->At(iDet);
1085            if (!kDataArray) 
1086              {
1087                status = kFALSE;
1088                break;
1089              }
1090            branch->SetAddress(&kDataArray);
1091            branch->Fill();
1092          }
1093
1094      }
1095
1096   return status;
1097
1098 }
1099
1100 //_____________________________________________________________________________
1101 Bool_t AliTRDdigitsManager::StoreDigitsParam()
1102 {
1103   //
1104   // Stores the digits parameter object from the digits tree
1105   //
1106
1107   if (!fTree) 
1108     {
1109       AliError("Digits tree is not defined\n");
1110       return kFALSE;
1111     }
1112
1113   // Get the branch
1114   TBranch *branch = fTree->GetBranch("TRDdigitsParam");
1115   if (!branch) 
1116     {
1117       AliError("Branch TRDdigitsParam is not defined\n");
1118       return kFALSE;
1119     }
1120
1121   // Fill the digits object in the tree
1122   const AliTRDdigitsParam *kDigitsParam = fDigitsParam;
1123   if (!kDigitsParam)
1124     {
1125       return kFALSE;
1126     }
1127   branch->SetAddress(&kDigitsParam);
1128   branch->Fill();
1129
1130   return kTRUE;
1131
1132 }
1133