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"
39 ClassImp(AliTRDdigitsManager)
41 //_____________________________________________________________________________
43 // Number of track dictionary arrays
44 const Int_t AliTRDdigitsManager::fgkNDict = kNDict;
46 //_____________________________________________________________________________
47 AliTRDdigitsManager::AliTRDdigitsManager(Bool_t rawRec)
54 ,fUseDictionaries(kTRUE)
57 ,fDets(AliTRDgeometry::Ndet())
61 // Default constructor
70 for (Int_t iDict = 0; iDict < kNDict; iDict++)
76 //_____________________________________________________________________________
77 AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
82 ,fHasSDigits(m.fHasSDigits)
84 ,fUseDictionaries(kTRUE)
91 // AliTRDdigitsManager copy constructor
96 //_____________________________________________________________________________
97 AliTRDdigitsManager::~AliTRDdigitsManager()
100 // AliTRDdigitsManager destructor
111 for (Int_t iDict = 0; iDict < kNDict; iDict++)
115 fDict[iDict]->Delete();
123 fSignalIndexes->Delete();
124 delete fSignalIndexes;
125 fSignalIndexes = NULL;
130 //_____________________________________________________________________________
131 AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
134 // Assignment operator
139 ((AliTRDdigitsManager &) m).Copy(*this);
146 //_____________________________________________________________________________
147 void AliTRDdigitsManager::Copy(TObject &m) const
153 ((AliTRDdigitsManager &) m).fEvent = fEvent;
154 ((AliTRDdigitsManager &) m).fHasSDigits = fHasSDigits;
155 ((AliTRDdigitsManager &) m).fDigits = fDigits;
156 for(Int_t i=0; i<kNDict; i++)
158 ((AliTRDdigitsManager &) m).fDict[i] = fDict[i];
160 ((AliTRDdigitsManager &) m).fSignalIndexes = fSignalIndexes;
161 ((AliTRDdigitsManager &) m).fUseDictionaries = fUseDictionaries;
162 ((AliTRDdigitsManager &) m).fDets = fDets;
163 ((AliTRDdigitsManager &) m).fRawRec = fRawRec;
169 //_____________________________________________________________________________
170 void AliTRDdigitsManager::CreateArrays()
173 // Create the data arrays
183 fDigits = new TObjArray(fDets);
184 for (Int_t index = 0; index < fDets; index++)
185 fDigits->AddAt(new AliTRDarraySignal(),index);
194 fDigits = new TObjArray(fDets);
195 for (Int_t index = 0; index < fDets;index++)
196 fDigits->AddAt(new AliTRDarrayADC(),index);
199 if (fUseDictionaries)
201 for(Int_t iDict = 0; iDict < kNDict; iDict++)
204 fDict[iDict]->Delete();
207 for(Int_t iDict = 0; iDict < kNDict; iDict++)
208 fDict[iDict] = new TObjArray(fDets);
210 for (Int_t iDict = 0; iDict < kNDict; iDict++)
211 for (Int_t index = 0; index < fDets; index++)
212 fDict[iDict]->AddAt(new AliTRDarrayDictionary(),index);
217 fSignalIndexes->Delete();
218 delete fSignalIndexes;
220 fSignalIndexes = new TObjArray(fDets);
221 for (Int_t i = 0; i < fDets; i++)
222 fSignalIndexes->AddLast(new AliTRDSignalIndex());
226 //_____________________________________________________________________________
227 void AliTRDdigitsManager::ResetArrays()
230 // Reset the data arrays
240 fDigits = new TObjArray(fDets);
241 for (Int_t index = 0; index < fDets; index++)
242 fDigits->AddAt(new AliTRDarraySignal(),index);
246 fDigits = new TObjArray(fDets);
247 for (Int_t index = 0; index < fDets; index++)
248 fDigits->AddAt(new AliTRDarrayADC(),index);
251 for (Int_t iDict = 0; iDict < kNDict; iDict++)
255 fDict[iDict]->Delete();
260 if (fUseDictionaries)
262 for(Int_t iDict = 0; iDict < kNDict; iDict++)
263 fDict[iDict] = new TObjArray(fDets);
265 for (Int_t iDict = 0; iDict < kNDict; iDict++)
266 for (Int_t index = 0; index < fDets; index++)
267 fDict[iDict]->AddAt(new AliTRDarrayDictionary(),index);
272 fSignalIndexes->Delete();
273 delete fSignalIndexes;
275 fSignalIndexes = new TObjArray(fDets);
276 for (Int_t i = 0; i < fDets; i++)
277 fSignalIndexes->AddLast(new AliTRDSignalIndex());
280 //_____________________________________________________________________________
281 void AliTRDdigitsManager::ResetArrays(Int_t det)
283 Int_t RecoDet = fRawRec ? 0 : det;
285 RemoveDigits(RecoDet);
286 RemoveDictionaries(RecoDet);
287 RemoveIndexes(RecoDet);
290 fDigits->AddAt(new AliTRDarraySignal(),RecoDet);
292 fDigits->AddAt(new AliTRDarrayADC(),RecoDet);
294 if (fUseDictionaries)
296 for (Int_t iDict = 0; iDict < kNDict; iDict++)
297 fDict[iDict]->AddAt(new AliTRDarrayDictionary(),RecoDet);
300 fSignalIndexes->AddAt(new AliTRDSignalIndex(),RecoDet);
303 //_____________________________________________________________________________
304 Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time, Int_t det) const
307 // Returns the amplitude of a digit
310 if (!GetDigits(det)) return 0;
312 return ((Short_t) ((AliTRDarrayADC *) GetDigits(det))->GetDataB(row,col,time));
316 //_____________________________________________________________________________
317 UChar_t AliTRDdigitsManager::GetPadStatus(Int_t row, Int_t col, Int_t time, Int_t det) const
320 // Returns the pad status for the requested pad
323 if (!GetDigits(det)) return 0;
325 return ((UChar_t) ((AliTRDarrayADC *) GetDigits(det))->GetPadStatus(row,col,time));
329 //_____________________________________________________________________________
330 Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree)
333 // Creates the tree and branches for the digits and the dictionary
336 Int_t buffersize = 64000;
337 Bool_t status = kTRUE;
344 // Make the branch for the digits
349 const AliTRDarraySignal *kDigits = (AliTRDarraySignal *) fDigits->At(0);
352 if (!fTree) return kFALSE;
353 AliDebug(1,"Making branch for SDigits!\n");
354 TBranch* branch = fTree->GetBranch("TRDdigits");
355 if (!branch) fTree->Branch("TRDdigits","AliTRDarraySignal",&kDigits,buffersize,99);
356 AliDebug(1,"Making branch TRDdigits\n");
366 const AliTRDarrayADC *kDigits = (AliTRDarrayADC *) fDigits->At(0);
369 if (!fTree) return kFALSE;
370 AliDebug(1,"Making branch for Digits!\n");
371 TBranch* branch = fTree->GetBranch("TRDdigits");
372 if (!branch) fTree->Branch("TRDdigits","AliTRDarrayADC",&kDigits,buffersize,99);
373 AliDebug(1,"Making branch TRDdigits\n");
387 if (fUseDictionaries)
389 // Make the branches for the dictionaries
390 for (Int_t iDict = 0; iDict < kNDict; iDict++)
392 Char_t branchname[15];
393 sprintf(branchname,"TRDdictionary%d",iDict);
396 const AliTRDarrayDictionary *kDictionary = (AliTRDarrayDictionary *) fDict[iDict]->At(0);
399 if (!fTree) return kFALSE;
400 AliDebug(2,"Making branch for dictionary!\n");
401 TBranch* branch = fTree->GetBranch(branchname);
402 if (!branch) fTree->Branch(branchname,"AliTRDarrayDictionary",&kDictionary,buffersize,99);
403 AliDebug(1,Form("Making branch %s\n",branchname));
421 //_____________________________________________________________________________
422 Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree)
425 // Reads the digit information from the input file
428 Bool_t status = kTRUE;
437 AliDebug(1,"Create the data arrays.\n");
441 status = LoadArray(fDigits,"TRDdigits",fTree);
443 if (fUseDictionaries)
445 for (Int_t iDict = 0; iDict < kNDict; iDict++)
447 Char_t branchname[15];
448 sprintf(branchname,"TRDdictionary%d",iDict);
449 status = LoadArrayDict(fDict[iDict],branchname,fTree);
450 if (status == kFALSE)
452 fUseDictionaries = kFALSE;
453 AliWarning("Unable to load dict arrays. Will not use them.\n");
463 //_____________________________________________________________________________
464 Bool_t AliTRDdigitsManager::WriteDigits()
467 // Writes out the TRD-digits and the dictionaries
470 // Store the contents of the detector array in the tree
472 if (!StoreArray(fDigits,"TRDdigits",fTree))
474 AliError("Error while storing digits in branch TRDdigits\n");
478 if (fUseDictionaries)
480 for (Int_t iDict = 0; iDict < kNDict; iDict++)
482 Char_t branchname[15];
483 sprintf(branchname,"TRDdictionary%d",iDict);
484 if (!StoreArrayDict(fDict[iDict],branchname,fTree))
486 AliError(Form("Error while storing dictionary in branch %s\n",branchname));
492 // Write the new tree to the output file
499 //_____________________________________________________________________________
500 AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row
506 // Creates a single digit object
517 amp[0] = ((AliTRDarrayADC *) GetDigits(det))->GetData(row,col,time);
519 return (new AliTRDdigit(digits,amp));
523 //_____________________________________________________________________________
524 Int_t AliTRDdigitsManager::GetTrack(Int_t track
531 // Returns the MC-track numbers from the dictionary.
534 if ((track < 0) || (track >= kNDict))
536 AliError(Form("track %d out of bounds (size: %d, this: 0x%08x)",track,kNDict,this));
540 if (fUseDictionaries == kFALSE)
545 // Array contains index+1 to allow data compression--->Changed
546 return (((AliTRDarrayDictionary *) GetDictionary(det,track))->GetData(row,col,time) );
550 //________________________________________________________________________________
551 AliTRDarrayADC *AliTRDdigitsManager::GetDigits(Int_t det) const
554 // Returns the digits array for one detector
557 Int_t RecoDet = fRawRec ? 0 : det;
566 ((AliTRDarrayADC *) fDigits->At(RecoDet))->SetNdet(det);
567 return (AliTRDarrayADC *) fDigits->At(RecoDet);
571 AliDebug(2,"ERROR IN DATA TYPE!!!!");
577 //_____________________________________________________________________________
578 AliTRDarraySignal *AliTRDdigitsManager::GetSDigits(Int_t det) const
581 // Returns the sdigits array for one detector
584 Int_t RecoDet = fRawRec ? 0 : det;
588 // AliDebug(1,"NO FDIGITS!");
594 ((AliTRDarraySignal *) fDigits->At(RecoDet))->SetNdet(det);
595 return (AliTRDarraySignal *) fDigits->At(RecoDet);
599 AliDebug(2,"ERROR IN DATA TYPE!!!!");
605 //_____________________________________________________________________________
606 AliTRDarrayDictionary *AliTRDdigitsManager::GetDictionary(Int_t det
610 // Returns the dictionary for one detector
613 Int_t RecoDet = fRawRec ? 0 : det;
615 if (fUseDictionaries == kFALSE)
620 ((AliTRDarrayDictionary *) fDigits->At(RecoDet))->SetNdet(det);
621 return (AliTRDarrayDictionary *) fDict[i]->At(RecoDet);
625 //_____________________________________________________________________________
626 Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *digit) const
629 // Returns the MC-track numbers from the dictionary for a given digit
632 Int_t row = digit->GetRow();
633 Int_t col = digit->GetCol();
634 Int_t time = digit->GetTime();
635 Int_t det = digit->GetDetector();
637 return GetTrack(track,row,col,time,det);
641 //_____________________________________________________________________________
642 AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det)
645 // Returns indexes of active pads
648 Int_t RecoDet = fRawRec ? 0 : det;
650 return (AliTRDSignalIndex *) fSignalIndexes->At(RecoDet);
654 //_____________________________________________________________________________
655 void AliTRDdigitsManager::RemoveDigits(Int_t det)
658 // Clear memory at det for Digits
661 Int_t RecoDet = fRawRec ? 0 : det;
663 if (fDigits->At(RecoDet))
667 AliTRDarraySignal *arr = (AliTRDarraySignal *) fDigits->RemoveAt(RecoDet);
672 AliTRDarrayADC *arr = (AliTRDarrayADC *) fDigits->RemoveAt(RecoDet);
679 //_____________________________________________________________________________
680 void AliTRDdigitsManager::RemoveDictionaries(Int_t det)
686 Int_t RecoDet = fRawRec ? 0 : det;
688 if (fUseDictionaries == kFALSE)
693 for (Int_t i = 0; i < kNDict; i++)
695 if (fDict[i]->At(RecoDet))
697 AliTRDarrayDictionary *arr = (AliTRDarrayDictionary *) fDict[i]->RemoveAt(RecoDet);
704 //_____________________________________________________________________________
705 void AliTRDdigitsManager::RemoveIndexes(Int_t det)
711 Int_t RecoDet = fRawRec ? 0 : det;
713 if (fSignalIndexes->At(RecoDet))
715 AliTRDSignalIndex *arr = (AliTRDSignalIndex *) fSignalIndexes->RemoveAt(RecoDet);
722 //_____________________________________________________________________________
723 void AliTRDdigitsManager::ClearIndexes(Int_t det)
729 Int_t RecoDet = fRawRec ? 0 : det;
731 ((AliTRDSignalIndex *) fSignalIndexes->At(RecoDet))->ClearAll();
735 //_____________________________________________________________________________
736 Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det)
739 // Build the list of indices
747 AliTRDarrayADC *digits = 0x0;
755 digits = (AliTRDarrayADC *) GetDigits(det);
758 //digits should be expanded by now!!!
759 if (digits->GetNtime() > 0)
762 nRows = digits->GetNrow();
763 nCols = digits->GetNcol();
764 nTbins = digits->GetNtime();
766 AliTRDSignalIndex *indexes = GetIndexes(det);
767 indexes->SetSM(geom.GetSector(det));
768 indexes->SetStack(geom.GetStack(det));
769 indexes->SetLayer(geom.GetLayer(det));
770 indexes->SetDetNumber(det);
772 if (indexes->IsAllocated() == kFALSE)
774 indexes->Allocate(nRows,nCols,nTbins);
777 for (Int_t ir = 0; ir < nRows; ir++)
779 for (Int_t ic = 0; ic < nCols; ic++)
781 for (Int_t it = 0; it < nTbins; it++)
783 Int_t isig = digits->GetDataB(ir,ic,it);
786 indexes->AddIndexRC(ir,ic);
802 //_____________________________________________________________________________
803 Bool_t AliTRDdigitsManager::LoadArray(TObjArray *object
804 , const Char_t *branchname
808 // Loads all detectors of the array from the branch <branchname> of
809 // the digits tree <tree>
810 // Adapted from code of the class AliTRDsegmentArray
817 AliError("Digits tree is not defined\n");
822 fBranch = fTreeD->GetBranch(branchname);
825 AliError(Form("Branch %s is not defined\n",branchname));
829 // Loop through all detectors and read them from the tree
830 Bool_t status = kTRUE;
831 for (Int_t iDet = 0; iDet < fDets; iDet++)
835 AliTRDarraySignal *dataArray = (AliTRDarraySignal *) object->At(iDet);
842 fBranch->SetAddress(&dataArray);
843 fBranch->GetEntry(iDet);
847 AliTRDarrayADC *dataArray = (AliTRDarrayADC *) object->At(iDet);
853 fBranch->SetAddress(&dataArray);
854 fBranch->GetEntry(iDet);
862 //________________________________________________________________________________________________
863 Bool_t AliTRDdigitsManager::LoadArrayDict(TObjArray *object
864 , const Char_t *branchname
868 // Loads all detectors of the array from the branch <branchname> of
869 // the dictionary tree <tree>
870 // Adapted from code of the class AliTRDsegmentArray
877 AliError("Digits tree is not defined\n");
882 fBranch = fTreeD->GetBranch(branchname);
885 AliError(Form("Branch %s is not defined\n",branchname));
889 // Loop through all detectors and read them from the tree
890 Bool_t status = kTRUE;
891 for (Int_t iDet = 0; iDet < fDets; iDet++)
893 AliTRDarrayDictionary *dataArray = (AliTRDarrayDictionary *) object->At(iDet);
899 fBranch->SetAddress(&dataArray);
900 fBranch->GetEntry(iDet);
907 //_____________________________________________________________________________
908 Bool_t AliTRDdigitsManager::StoreArray(TObjArray *array1
909 , const Char_t *branchname
913 // Stores all the detectors of the array in the branch <branchname> of
914 // the digits tree <tree>
915 // Adapted from code of the class AliTRDsegmentArray
922 AliError("Digits tree is not defined\n");
927 fBranch = fTree->GetBranch(branchname);
930 AliError(Form("Branch %s is not defined\n",branchname));
934 // Loop through all detectors and fill them into the tree
935 Bool_t status = kTRUE;
936 for (Int_t iDet = 0; iDet < fDets; iDet++)
940 const AliTRDarraySignal *kDataArray = (AliTRDarraySignal *) array1->At(iDet);
946 fBranch->SetAddress(&kDataArray);
951 const AliTRDarrayADC *kDataArray = (AliTRDarrayADC *) array1->At(iDet);
957 fBranch->SetAddress(&kDataArray);
966 //_____________________________________________________________________________
967 Bool_t AliTRDdigitsManager::StoreArrayDict(TObjArray *array3
968 , const Char_t *branchname
972 // Stores all the dictionary arrays of the detectors of the array in the branch <branchname> of
973 // the dictionary tree <tree>
974 // Adapted from code of the class AliTRDsegmentArray
977 // AliDebug(1,"Storing Arrays of Dictionary");
982 AliError("Digits tree is not defined\n");
987 fBranch = fTree->GetBranch(branchname);
990 AliError(Form("Branch %s is not defined\n",branchname));
994 // Loop through all detectors and fill them into the tree
995 Bool_t status = kTRUE;
996 for (Int_t iDet = 0; iDet < fDets; iDet++)
998 const AliTRDarrayDictionary *kDataArray = (AliTRDarrayDictionary *) array3->At(iDet);
1004 fBranch->SetAddress(&kDataArray);