1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // Manages the digits and the track dictionary in the form of //
21 // TObjArray objects //
23 ///////////////////////////////////////////////////////////////////////////////
25 #include <Riostream.h>
31 #include "AliTRDdigitsManager.h"
32 #include "AliTRDarrayDictionary.h"
33 #include "AliTRDarrayADC.h"
34 #include "AliTRDarraySignal.h"
35 #include "AliTRDdigit.h"
36 #include "AliTRDgeometry.h"
37 #include "AliTRDSignalIndex.h"
38 #include "AliTRDReconstructor.h"
40 ClassImp(AliTRDdigitsManager)
42 //_____________________________________________________________________________
44 // Number of track dictionary arrays
45 const Int_t AliTRDdigitsManager::fgkNDict = kNDict;
47 //_____________________________________________________________________________
48 AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDReconstructor *const rec)
55 ,fUseDictionaries(kTRUE)
58 ,fDets(AliTRDgeometry::Ndet())
62 // Default constructor
71 for (Int_t iDict = 0; iDict < kNDict; iDict++)
77 //_____________________________________________________________________________
78 AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
83 ,fHasSDigits(m.fHasSDigits)
85 ,fUseDictionaries(kTRUE)
92 // AliTRDdigitsManager copy constructor
97 //_____________________________________________________________________________
98 AliTRDdigitsManager::~AliTRDdigitsManager()
101 // AliTRDdigitsManager destructor
112 for (Int_t iDict = 0; iDict < kNDict; iDict++)
116 fDict[iDict]->Delete();
124 fSignalIndexes->Delete();
125 delete fSignalIndexes;
126 fSignalIndexes = NULL;
131 //_____________________________________________________________________________
132 AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
135 // Assignment operator
140 ((AliTRDdigitsManager &) m).Copy(*this);
147 //_____________________________________________________________________________
148 void AliTRDdigitsManager::Copy(TObject &m) const
154 ((AliTRDdigitsManager &) m).fEvent = fEvent;
155 ((AliTRDdigitsManager &) m).fHasSDigits = fHasSDigits;
156 ((AliTRDdigitsManager &) m).fDigits = fDigits;
157 for(Int_t i=0; i<kNDict; i++)
159 ((AliTRDdigitsManager &) m).fDict[i] = fDict[i];
161 ((AliTRDdigitsManager &) m).fSignalIndexes = fSignalIndexes;
162 ((AliTRDdigitsManager &) m).fUseDictionaries = fUseDictionaries;
163 ((AliTRDdigitsManager &) m).fDets = fDets;
164 ((AliTRDdigitsManager &) m).fRawRec = fRawRec;
170 //_____________________________________________________________________________
171 void AliTRDdigitsManager::CreateArrays()
174 // Create the data arrays
184 fDigits = new TObjArray(fDets);
185 for (Int_t index = 0; index < fDets; index++)
186 fDigits->AddAt(new AliTRDarraySignal(),index);
195 fDigits = new TObjArray(fDets);
196 for (Int_t index = 0; index < fDets;index++)
197 fDigits->AddAt(new AliTRDarrayADC(),index);
200 if (fUseDictionaries)
202 for(Int_t iDict = 0; iDict < kNDict; iDict++)
205 fDict[iDict]->Delete();
208 for(Int_t iDict = 0; iDict < kNDict; iDict++)
209 fDict[iDict] = new TObjArray(fDets);
211 for (Int_t iDict = 0; iDict < kNDict; iDict++)
212 for (Int_t index = 0; index < fDets; index++)
213 fDict[iDict]->AddAt(new AliTRDarrayDictionary(),index);
218 fSignalIndexes->Delete();
219 delete fSignalIndexes;
221 fSignalIndexes = new TObjArray(fDets);
222 for (Int_t i = 0; i < fDets; i++)
223 fSignalIndexes->AddLast(new AliTRDSignalIndex());
227 //_____________________________________________________________________________
228 void AliTRDdigitsManager::ResetArrays()
231 // Reset the data arrays
241 fDigits = new TObjArray(fDets);
242 for (Int_t index = 0; index < fDets; index++)
243 fDigits->AddAt(new AliTRDarraySignal(),index);
247 fDigits = new TObjArray(fDets);
248 for (Int_t index = 0; index < fDets; index++)
249 fDigits->AddAt(new AliTRDarrayADC(),index);
252 for (Int_t iDict = 0; iDict < kNDict; iDict++)
256 fDict[iDict]->Delete();
261 if (fUseDictionaries)
263 for(Int_t iDict = 0; iDict < kNDict; iDict++)
264 fDict[iDict] = new TObjArray(fDets);
266 for (Int_t iDict = 0; iDict < kNDict; iDict++)
267 for (Int_t index = 0; index < fDets; index++)
268 fDict[iDict]->AddAt(new AliTRDarrayDictionary(),index);
273 fSignalIndexes->Delete();
274 delete fSignalIndexes;
276 fSignalIndexes = new TObjArray(fDets);
277 for (Int_t i = 0; i < fDets; i++)
278 fSignalIndexes->AddLast(new AliTRDSignalIndex());
281 //_____________________________________________________________________________
282 void AliTRDdigitsManager::ResetArrays(Int_t det)
284 Int_t RecoDet = fRawRec ? 0 : det;
286 RemoveDigits(RecoDet);
287 RemoveDictionaries(RecoDet);
288 RemoveIndexes(RecoDet);
291 fDigits->AddAt(new AliTRDarraySignal(),RecoDet);
293 fDigits->AddAt(new AliTRDarrayADC(),RecoDet);
295 if (fUseDictionaries)
297 for (Int_t iDict = 0; iDict < kNDict; iDict++)
298 fDict[iDict]->AddAt(new AliTRDarrayDictionary(),RecoDet);
301 fSignalIndexes->AddAt(new AliTRDSignalIndex(),RecoDet);
304 //_____________________________________________________________________________
305 Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time, Int_t det) const
308 // Returns the amplitude of a digit
311 if (!GetDigits(det)) return 0;
313 return ((Short_t) ((AliTRDarrayADC *) GetDigits(det))->GetDataB(row,col,time));
317 //_____________________________________________________________________________
318 UChar_t AliTRDdigitsManager::GetPadStatus(Int_t row, Int_t col, Int_t time, Int_t det) const
321 // Returns the pad status for the requested pad
324 if (!GetDigits(det)) return 0;
326 return ((UChar_t) ((AliTRDarrayADC *) GetDigits(det))->GetPadStatus(row,col,time));
330 //_____________________________________________________________________________
331 Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree)
334 // Creates the tree and branches for the digits and the dictionary
337 Int_t buffersize = 64000;
338 Bool_t status = kTRUE;
345 // Make the branch for the digits
350 const AliTRDarraySignal *kDigits = (AliTRDarraySignal *) fDigits->At(0);
353 if (!fTree) return kFALSE;
354 AliDebug(1,"Making branch for SDigits!\n");
355 TBranch* branch = fTree->GetBranch("TRDdigits");
356 if (!branch) fTree->Branch("TRDdigits","AliTRDarraySignal",&kDigits,buffersize,99);
357 AliDebug(1,"Making branch TRDdigits\n");
367 const AliTRDarrayADC *kDigits = (AliTRDarrayADC *) fDigits->At(0);
370 if (!fTree) return kFALSE;
371 AliDebug(1,"Making branch for Digits!\n");
372 TBranch* branch = fTree->GetBranch("TRDdigits");
373 if (!branch) fTree->Branch("TRDdigits","AliTRDarrayADC",&kDigits,buffersize,99);
374 AliDebug(1,"Making branch TRDdigits\n");
388 if (fUseDictionaries)
390 // Make the branches for the dictionaries
391 for (Int_t iDict = 0; iDict < kNDict; iDict++)
393 Char_t branchname[15];
394 sprintf(branchname,"TRDdictionary%d",iDict);
397 const AliTRDarrayDictionary *kDictionary = (AliTRDarrayDictionary *) fDict[iDict]->At(0);
400 if (!fTree) return kFALSE;
401 AliDebug(2,"Making branch for dictionary!\n");
402 TBranch* branch = fTree->GetBranch(branchname);
403 if (!branch) fTree->Branch(branchname,"AliTRDarrayDictionary",&kDictionary,buffersize,99);
404 AliDebug(1,Form("Making branch %s\n",branchname));
422 //_____________________________________________________________________________
423 Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree)
426 // Reads the digit information from the input file
429 Bool_t status = kTRUE;
438 AliDebug(1,"Create the data arrays.\n");
442 status = LoadArray(fDigits,"TRDdigits",fTree);
444 if (fUseDictionaries)
446 for (Int_t iDict = 0; iDict < kNDict; iDict++)
448 Char_t branchname[15];
449 sprintf(branchname,"TRDdictionary%d",iDict);
450 status = LoadArrayDict(fDict[iDict],branchname,fTree);
451 if (status == kFALSE)
453 fUseDictionaries = kFALSE;
454 AliWarning("Unable to load dict arrays. Will not use them.\n");
464 //_____________________________________________________________________________
465 Bool_t AliTRDdigitsManager::WriteDigits()
468 // Writes out the TRD-digits and the dictionaries
471 // Store the contents of the detector array in the tree
473 if (!StoreArray(fDigits,"TRDdigits",fTree))
475 AliError("Error while storing digits in branch TRDdigits\n");
479 if (fUseDictionaries)
481 for (Int_t iDict = 0; iDict < kNDict; iDict++)
483 Char_t branchname[15];
484 sprintf(branchname,"TRDdictionary%d",iDict);
485 if (!StoreArrayDict(fDict[iDict],branchname,fTree))
487 AliError(Form("Error while storing dictionary in branch %s\n",branchname));
493 // Write the new tree to the output file
500 //_____________________________________________________________________________
501 AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row
507 // Creates a single digit object
518 amp[0] = ((AliTRDarrayADC *) GetDigits(det))->GetData(row,col,time);
520 return (new AliTRDdigit(digits,amp));
524 //_____________________________________________________________________________
525 Int_t AliTRDdigitsManager::GetTrack(Int_t track
532 // Returns the MC-track numbers from the dictionary.
535 if ((track < 0) || (track >= kNDict))
537 AliError(Form("track %d out of bounds (size: %d, this: 0x%08x)",track,kNDict,this));
541 if (fUseDictionaries == kFALSE)
546 // Array contains index+1 to allow data compression--->Changed
547 return (((AliTRDarrayDictionary *) GetDictionary(det,track))->GetData(row,col,time) );
551 //________________________________________________________________________________
552 AliTRDarrayADC *AliTRDdigitsManager::GetDigits(Int_t det) const
555 // Returns the digits array for one detector
558 Int_t RecoDet = fRawRec ? 0 : det;
567 ((AliTRDarrayADC *) fDigits->At(RecoDet))->SetNdet(det);
568 return (AliTRDarrayADC *) fDigits->At(RecoDet);
572 AliDebug(2,"ERROR IN DATA TYPE!!!!");
578 //_____________________________________________________________________________
579 AliTRDarraySignal *AliTRDdigitsManager::GetSDigits(Int_t det) const
582 // Returns the sdigits array for one detector
585 Int_t RecoDet = fRawRec ? 0 : det;
589 // AliDebug(1,"NO FDIGITS!");
595 ((AliTRDarraySignal *) fDigits->At(RecoDet))->SetNdet(det);
596 return (AliTRDarraySignal *) fDigits->At(RecoDet);
600 AliDebug(2,"ERROR IN DATA TYPE!!!!");
606 //_____________________________________________________________________________
607 AliTRDarrayDictionary *AliTRDdigitsManager::GetDictionary(Int_t det
611 // Returns the dictionary for one detector
614 Int_t RecoDet = fRawRec ? 0 : det;
616 if (fUseDictionaries == kFALSE)
621 ((AliTRDarrayDictionary *) fDigits->At(RecoDet))->SetNdet(det);
622 return (AliTRDarrayDictionary *) fDict[i]->At(RecoDet);
626 //_____________________________________________________________________________
627 Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *digit) const
630 // Returns the MC-track numbers from the dictionary for a given digit
633 Int_t row = digit->GetRow();
634 Int_t col = digit->GetCol();
635 Int_t time = digit->GetTime();
636 Int_t det = digit->GetDetector();
638 return GetTrack(track,row,col,time,det);
642 //_____________________________________________________________________________
643 AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det)
646 // Returns indexes of active pads
649 Int_t RecoDet = fRawRec ? 0 : det;
651 return (AliTRDSignalIndex *) fSignalIndexes->At(RecoDet);
655 //_____________________________________________________________________________
656 void AliTRDdigitsManager::RemoveDigits(Int_t det)
659 // Clear memory at det for Digits
662 Int_t RecoDet = fRawRec ? 0 : det;
664 if (fDigits->At(RecoDet))
668 AliTRDarraySignal *arr = (AliTRDarraySignal *) fDigits->RemoveAt(RecoDet);
673 AliTRDarrayADC *arr = (AliTRDarrayADC *) fDigits->RemoveAt(RecoDet);
680 //_____________________________________________________________________________
681 void AliTRDdigitsManager::RemoveDictionaries(Int_t det)
687 Int_t RecoDet = fRawRec ? 0 : det;
689 if (fUseDictionaries == kFALSE)
694 for (Int_t i = 0; i < kNDict; i++)
696 if (fDict[i]->At(RecoDet))
698 AliTRDarrayDictionary *arr = (AliTRDarrayDictionary *) fDict[i]->RemoveAt(RecoDet);
705 //_____________________________________________________________________________
706 void AliTRDdigitsManager::RemoveIndexes(Int_t det)
712 Int_t RecoDet = fRawRec ? 0 : det;
714 if (fSignalIndexes->At(RecoDet))
716 AliTRDSignalIndex *arr = (AliTRDSignalIndex *) fSignalIndexes->RemoveAt(RecoDet);
723 //_____________________________________________________________________________
724 void AliTRDdigitsManager::ClearIndexes(Int_t det)
730 Int_t RecoDet = fRawRec ? 0 : det;
732 ((AliTRDSignalIndex *) fSignalIndexes->At(RecoDet))->ClearAll();
736 //_____________________________________________________________________________
737 Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det)
740 // Build the list of indices
748 AliTRDarrayADC *digits = 0x0;
756 digits = (AliTRDarrayADC *) GetDigits(det);
759 //digits should be expanded by now!!!
760 if (digits->GetNtime() > 0)
763 nRows = digits->GetNrow();
764 nCols = digits->GetNcol();
765 nTbins = digits->GetNtime();
767 AliTRDSignalIndex *indexes = GetIndexes(det);
768 indexes->SetSM(geom.GetSector(det));
769 indexes->SetStack(geom.GetStack(det));
770 indexes->SetLayer(geom.GetLayer(det));
771 indexes->SetDetNumber(det);
773 if (indexes->IsAllocated() == kFALSE)
775 indexes->Allocate(nRows,nCols,nTbins);
778 for (Int_t ir = 0; ir < nRows; ir++)
780 for (Int_t ic = 0; ic < nCols; ic++)
782 for (Int_t it = 0; it < nTbins; it++)
784 Int_t isig = digits->GetDataB(ir,ic,it);
787 indexes->AddIndexRC(ir,ic);
803 //_____________________________________________________________________________
804 Bool_t AliTRDdigitsManager::LoadArray(TObjArray *object
805 , const Char_t *branchname
809 // Loads all detectors of the array from the branch <branchname> of
810 // the digits tree <tree>
811 // Adapted from code of the class AliTRDsegmentArray
818 AliError("Digits tree is not defined\n");
823 fBranch = fTreeD->GetBranch(branchname);
826 AliError(Form("Branch %s is not defined\n",branchname));
830 // Loop through all detectors and read them from the tree
831 Bool_t status = kTRUE;
832 for (Int_t iDet = 0; iDet < fDets; iDet++)
836 AliTRDarraySignal *dataArray = (AliTRDarraySignal *) object->At(iDet);
843 fBranch->SetAddress(&dataArray);
844 fBranch->GetEntry(iDet);
848 AliTRDarrayADC *dataArray = (AliTRDarrayADC *) object->At(iDet);
854 fBranch->SetAddress(&dataArray);
855 fBranch->GetEntry(iDet);
863 //________________________________________________________________________________________________
864 Bool_t AliTRDdigitsManager::LoadArrayDict(TObjArray *object
865 , const Char_t *branchname
869 // Loads all detectors of the array from the branch <branchname> of
870 // the dictionary tree <tree>
871 // Adapted from code of the class AliTRDsegmentArray
878 AliError("Digits tree is not defined\n");
883 fBranch = fTreeD->GetBranch(branchname);
886 AliError(Form("Branch %s is not defined\n",branchname));
890 // Loop through all detectors and read them from the tree
891 Bool_t status = kTRUE;
892 for (Int_t iDet = 0; iDet < fDets; iDet++)
894 AliTRDarrayDictionary *dataArray = (AliTRDarrayDictionary *) object->At(iDet);
900 fBranch->SetAddress(&dataArray);
901 fBranch->GetEntry(iDet);
908 //_____________________________________________________________________________
909 Bool_t AliTRDdigitsManager::StoreArray(TObjArray *array1
910 , const Char_t *branchname
914 // Stores all the detectors of the array in the branch <branchname> of
915 // the digits tree <tree>
916 // Adapted from code of the class AliTRDsegmentArray
923 AliError("Digits tree is not defined\n");
928 fBranch = fTree->GetBranch(branchname);
931 AliError(Form("Branch %s is not defined\n",branchname));
935 // Loop through all detectors and fill them into the tree
936 Bool_t status = kTRUE;
937 for (Int_t iDet = 0; iDet < fDets; iDet++)
941 const AliTRDarraySignal *kDataArray = (AliTRDarraySignal *) array1->At(iDet);
947 fBranch->SetAddress(&kDataArray);
952 const AliTRDarrayADC *kDataArray = (AliTRDarrayADC *) array1->At(iDet);
958 fBranch->SetAddress(&kDataArray);
967 //_____________________________________________________________________________
968 Bool_t AliTRDdigitsManager::StoreArrayDict(TObjArray *array3
969 , const Char_t *branchname
973 // Stores all the dictionary arrays of the detectors of the array in the branch <branchname> of
974 // the dictionary tree <tree>
975 // Adapted from code of the class AliTRDsegmentArray
978 // AliDebug(1,"Storing Arrays of Dictionary");
983 AliError("Digits tree is not defined\n");
988 fBranch = fTree->GetBranch(branchname);
991 AliError(Form("Branch %s is not defined\n",branchname));
995 // Loop through all detectors and fill them into the tree
996 Bool_t status = kTRUE;
997 for (Int_t iDet = 0; iDet < fDets; iDet++)
999 const AliTRDarrayDictionary *kDataArray = (AliTRDarrayDictionary *) array3->At(iDet);
1005 fBranch->SetAddress(&kDataArray);