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 ///////////////////////////////////////////////////////////////////////////////
29 #include "AliTRDdigitsManager.h"
30 #include "AliTRDarrayDictionary.h"
31 #include "AliTRDarrayADC.h"
32 #include "AliTRDarraySignal.h"
33 #include "AliTRDdigit.h"
34 #include "AliTRDgeometry.h"
35 #include "AliTRDSignalIndex.h"
37 ClassImp(AliTRDdigitsManager)
39 //_____________________________________________________________________________
41 // Number of track dictionary arrays
42 const Int_t AliTRDdigitsManager::fgkNDict = kNDict;
44 //_____________________________________________________________________________
45 AliTRDdigitsManager::AliTRDdigitsManager(Bool_t rawRec)
52 ,fUseDictionaries(kTRUE)
55 ,fDets(AliTRDgeometry::Ndet())
59 // Default constructor
68 for (Int_t iDict = 0; iDict < kNDict; iDict++)
74 //_____________________________________________________________________________
75 AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
80 ,fHasSDigits(m.fHasSDigits)
82 ,fUseDictionaries(kTRUE)
89 // AliTRDdigitsManager copy constructor
94 //_____________________________________________________________________________
95 AliTRDdigitsManager::~AliTRDdigitsManager()
98 // AliTRDdigitsManager destructor
109 for (Int_t iDict = 0; iDict < kNDict; iDict++)
113 fDict[iDict]->Delete();
121 fSignalIndexes->Delete();
122 delete fSignalIndexes;
123 fSignalIndexes = NULL;
128 //_____________________________________________________________________________
129 AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
132 // Assignment operator
137 ((AliTRDdigitsManager &) m).Copy(*this);
144 //_____________________________________________________________________________
145 void AliTRDdigitsManager::Copy(TObject &m) const
151 ((AliTRDdigitsManager &) m).fEvent = fEvent;
152 ((AliTRDdigitsManager &) m).fHasSDigits = fHasSDigits;
153 ((AliTRDdigitsManager &) m).fDigits = fDigits;
154 for(Int_t i=0; i<kNDict; i++)
156 ((AliTRDdigitsManager &) m).fDict[i] = fDict[i];
158 ((AliTRDdigitsManager &) m).fSignalIndexes = fSignalIndexes;
159 ((AliTRDdigitsManager &) m).fUseDictionaries = fUseDictionaries;
160 ((AliTRDdigitsManager &) m).fDets = fDets;
161 ((AliTRDdigitsManager &) m).fRawRec = fRawRec;
167 //_____________________________________________________________________________
168 void AliTRDdigitsManager::CreateArrays()
171 // Create the data arrays
181 fDigits = new TObjArray(fDets);
182 for (Int_t index = 0; index < fDets; index++)
183 fDigits->AddAt(new AliTRDarraySignal(),index);
192 fDigits = new TObjArray(fDets);
193 for (Int_t index = 0; index < fDets;index++)
194 fDigits->AddAt(new AliTRDarrayADC(),index);
197 if (fUseDictionaries)
199 for(Int_t iDict = 0; iDict < kNDict; iDict++)
202 fDict[iDict]->Delete();
205 for(Int_t iDict = 0; iDict < kNDict; iDict++)
206 fDict[iDict] = new TObjArray(fDets);
208 for (Int_t iDict = 0; iDict < kNDict; iDict++)
209 for (Int_t index = 0; index < fDets; index++)
210 fDict[iDict]->AddAt(new AliTRDarrayDictionary(),index);
215 fSignalIndexes->Delete();
216 delete fSignalIndexes;
218 fSignalIndexes = new TObjArray(fDets);
219 for (Int_t i = 0; i < fDets; i++)
220 fSignalIndexes->AddLast(new AliTRDSignalIndex());
224 //_____________________________________________________________________________
225 void AliTRDdigitsManager::ResetArrays()
228 // Reset the data arrays
238 fDigits = new TObjArray(fDets);
239 for (Int_t index = 0; index < fDets; index++)
240 fDigits->AddAt(new AliTRDarraySignal(),index);
244 fDigits = new TObjArray(fDets);
245 for (Int_t index = 0; index < fDets; index++)
246 fDigits->AddAt(new AliTRDarrayADC(),index);
249 for (Int_t iDict = 0; iDict < kNDict; iDict++)
253 fDict[iDict]->Delete();
258 if (fUseDictionaries)
260 for(Int_t iDict = 0; iDict < kNDict; iDict++)
261 fDict[iDict] = new TObjArray(fDets);
263 for (Int_t iDict = 0; iDict < kNDict; iDict++)
264 for (Int_t index = 0; index < fDets; index++)
265 fDict[iDict]->AddAt(new AliTRDarrayDictionary(),index);
270 fSignalIndexes->Delete();
271 delete fSignalIndexes;
273 fSignalIndexes = new TObjArray(fDets);
274 for (Int_t i = 0; i < fDets; i++)
275 fSignalIndexes->AddLast(new AliTRDSignalIndex());
278 //_____________________________________________________________________________
279 void AliTRDdigitsManager::ResetArrays(Int_t det)
282 Int_t recoDet = fRawRec ? 0 : det;
284 RemoveDigits(recoDet);
285 RemoveDictionaries(recoDet);
286 RemoveIndexes(recoDet);
289 fDigits->AddAt(new AliTRDarraySignal(),recoDet);
291 fDigits->AddAt(new AliTRDarrayADC(),recoDet);
293 if (fUseDictionaries)
295 for (Int_t iDict = 0; iDict < kNDict; iDict++)
296 fDict[iDict]->AddAt(new AliTRDarrayDictionary(),recoDet);
299 fSignalIndexes->AddAt(new AliTRDSignalIndex(),recoDet);
302 //_____________________________________________________________________________
303 Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time, Int_t det) const
306 // Returns the amplitude of a digit
309 if (!GetDigits(det)) return 0;
311 return ((Short_t) ((AliTRDarrayADC *) GetDigits(det))->GetDataBits(row,col,time));
315 //_____________________________________________________________________________
316 UChar_t AliTRDdigitsManager::GetPadStatus(Int_t row, Int_t col, Int_t time, Int_t det) const
319 // Returns the pad status for the requested pad
322 if (!GetDigits(det)) return 0;
324 return ((UChar_t) ((AliTRDarrayADC *) GetDigits(det))->GetPadStatus(row,col,time));
328 //_____________________________________________________________________________
329 Bool_t AliTRDdigitsManager::MakeBranch(TTree * const tree)
332 // Creates the tree and branches for the digits and the dictionary
335 Int_t buffersize = 64000;
336 Bool_t status = kTRUE;
343 // Make the branch for the digits
348 const AliTRDarraySignal *kDigits = (AliTRDarraySignal *) fDigits->At(0);
351 if (!fTree) return kFALSE;
352 AliDebug(1,"Making branch for SDigits!\n");
353 TBranch* branch = fTree->GetBranch("TRDdigits");
354 if (!branch) fTree->Branch("TRDdigits","AliTRDarraySignal",&kDigits,buffersize,99);
355 AliDebug(1,"Making branch TRDdigits\n");
365 const AliTRDarrayADC *kDigits = (AliTRDarrayADC *) fDigits->At(0);
368 if (!fTree) return kFALSE;
369 AliDebug(1,"Making branch for Digits!\n");
370 TBranch* branch = fTree->GetBranch("TRDdigits");
371 if (!branch) fTree->Branch("TRDdigits","AliTRDarrayADC",&kDigits,buffersize,99);
372 AliDebug(1,"Making branch TRDdigits\n");
386 if (fUseDictionaries)
388 // Make the branches for the dictionaries
389 for (Int_t iDict = 0; iDict < kNDict; iDict++)
391 Char_t branchname[15];
392 sprintf(branchname,"TRDdictionary%d",iDict);
395 const AliTRDarrayDictionary *kDictionary = (AliTRDarrayDictionary *) fDict[iDict]->At(0);
398 if (!fTree) return kFALSE;
399 AliDebug(2,"Making branch for dictionary!\n");
400 TBranch* branch = fTree->GetBranch(branchname);
401 if (!branch) fTree->Branch(branchname,"AliTRDarrayDictionary",&kDictionary,buffersize,99);
402 AliDebug(1,Form("Making branch %s\n",branchname));
420 //_____________________________________________________________________________
421 Bool_t AliTRDdigitsManager::ReadDigits(TTree * const tree)
424 // Reads the digit information from the input file
427 Bool_t status = kTRUE;
436 AliDebug(1,"Create the data arrays.\n");
440 status = LoadArray(fDigits,"TRDdigits",fTree);
442 if (fUseDictionaries)
444 for (Int_t iDict = 0; iDict < kNDict; iDict++)
446 Char_t branchname[15];
447 sprintf(branchname,"TRDdictionary%d",iDict);
448 status = LoadArrayDict(fDict[iDict],branchname,fTree);
449 if (status == kFALSE)
451 fUseDictionaries = kFALSE;
452 AliWarning("Unable to load dict arrays. Will not use them.\n");
462 //_____________________________________________________________________________
463 Bool_t AliTRDdigitsManager::WriteDigits()
466 // Writes out the TRD-digits and the dictionaries
469 // Store the contents of the detector array in the tree
471 if (!StoreArray(fDigits,"TRDdigits",fTree))
473 AliError("Error while storing digits in branch TRDdigits\n");
477 if (fUseDictionaries)
479 for (Int_t iDict = 0; iDict < kNDict; iDict++)
481 Char_t branchname[15];
482 sprintf(branchname,"TRDdictionary%d",iDict);
483 if (!StoreArrayDict(fDict[iDict],branchname,fTree))
485 AliError(Form("Error while storing dictionary in branch %s\n",branchname));
491 // Write the new tree to the output file
498 //_____________________________________________________________________________
499 AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row
505 // Creates a single digit object
516 amp[0] = ((AliTRDarrayADC *) GetDigits(det))->GetData(row,col,time);
518 return (new AliTRDdigit(digits,amp));
522 //_____________________________________________________________________________
523 Int_t AliTRDdigitsManager::GetTrack(Int_t track
530 // Returns the MC-track numbers from the dictionary.
533 if ((track < 0) || (track >= kNDict))
535 AliError(Form("track %d out of bounds (size: %d, this: 0x%08x)",track,kNDict,this));
539 if (fUseDictionaries == kFALSE)
544 // Array contains index+1 to allow data compression--->Changed
545 return (((AliTRDarrayDictionary *) GetDictionary(det,track))->GetData(row,col,time) );
549 //________________________________________________________________________________
550 AliTRDarrayADC *AliTRDdigitsManager::GetDigits(Int_t det) const
553 // Returns the digits array for one detector
556 Int_t RecoDet = fRawRec ? 0 : det;
565 ((AliTRDarrayADC *) fDigits->At(RecoDet))->SetNdet(det);
566 return (AliTRDarrayADC *) fDigits->At(RecoDet);
570 AliDebug(2,"ERROR IN DATA TYPE!!!!");
576 //_____________________________________________________________________________
577 AliTRDarraySignal *AliTRDdigitsManager::GetSDigits(Int_t det) const
580 // Returns the sdigits array for one detector
583 Int_t RecoDet = fRawRec ? 0 : det;
587 // AliDebug(1,"NO FDIGITS!");
593 ((AliTRDarraySignal *) fDigits->At(RecoDet))->SetNdet(det);
594 return (AliTRDarraySignal *) fDigits->At(RecoDet);
598 AliDebug(2,"ERROR IN DATA TYPE!!!!");
604 //_____________________________________________________________________________
605 AliTRDarrayDictionary *AliTRDdigitsManager::GetDictionary(Int_t det
609 // Returns the dictionary for one detector
612 Int_t RecoDet = fRawRec ? 0 : det;
614 if (fUseDictionaries == kFALSE)
619 ((AliTRDarrayDictionary *) fDigits->At(RecoDet))->SetNdet(det);
620 return (AliTRDarrayDictionary *) fDict[i]->At(RecoDet);
624 //_____________________________________________________________________________
625 Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit * const digit) const
628 // Returns the MC-track numbers from the dictionary for a given digit
631 Int_t row = digit->GetRow();
632 Int_t col = digit->GetCol();
633 Int_t time = digit->GetTime();
634 Int_t det = digit->GetDetector();
636 return GetTrack(track,row,col,time,det);
640 //_____________________________________________________________________________
641 AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det)
644 // Returns indexes of active pads
647 Int_t RecoDet = fRawRec ? 0 : det;
649 return (AliTRDSignalIndex *) fSignalIndexes->At(RecoDet);
653 //_____________________________________________________________________________
654 void AliTRDdigitsManager::RemoveDigits(Int_t det)
657 // Clear memory at det for Digits
660 Int_t RecoDet = fRawRec ? 0 : det;
662 if (fDigits->At(RecoDet))
666 AliTRDarraySignal *arr = (AliTRDarraySignal *) fDigits->RemoveAt(RecoDet);
671 AliTRDarrayADC *arr = (AliTRDarrayADC *) fDigits->RemoveAt(RecoDet);
678 //_____________________________________________________________________________
679 void AliTRDdigitsManager::RemoveDictionaries(Int_t det)
685 Int_t RecoDet = fRawRec ? 0 : det;
687 if (fUseDictionaries == kFALSE)
692 for (Int_t i = 0; i < kNDict; i++)
694 if (fDict[i]->At(RecoDet))
696 AliTRDarrayDictionary *arr = (AliTRDarrayDictionary *) fDict[i]->RemoveAt(RecoDet);
703 //_____________________________________________________________________________
704 void AliTRDdigitsManager::RemoveIndexes(Int_t det)
710 Int_t RecoDet = fRawRec ? 0 : det;
712 if (fSignalIndexes->At(RecoDet))
714 AliTRDSignalIndex *arr = (AliTRDSignalIndex *) fSignalIndexes->RemoveAt(RecoDet);
721 //_____________________________________________________________________________
722 void AliTRDdigitsManager::ClearIndexes(Int_t det)
728 Int_t RecoDet = fRawRec ? 0 : det;
730 ((AliTRDSignalIndex *) fSignalIndexes->At(RecoDet))->ClearAll();
734 //_____________________________________________________________________________
735 Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det)
738 // Build the list of indices
746 AliTRDarrayADC *digits = 0x0;
754 digits = (AliTRDarrayADC *) GetDigits(det);
757 //digits should be expanded by now!!!
758 if (digits->GetNtime() > 0)
761 nRows = digits->GetNrow();
762 nCols = digits->GetNcol();
763 nTbins = digits->GetNtime();
765 AliTRDSignalIndex *indexes = GetIndexes(det);
766 indexes->SetSM(geom.GetSector(det));
767 indexes->SetStack(geom.GetStack(det));
768 indexes->SetLayer(geom.GetLayer(det));
769 indexes->SetDetNumber(det);
771 if (indexes->IsAllocated() == kFALSE)
773 indexes->Allocate(nRows,nCols,nTbins);
776 for (Int_t ir = 0; ir < nRows; ir++)
778 for (Int_t ic = 0; ic < nCols; ic++)
780 for (Int_t it = 0; it < nTbins; it++)
782 Int_t isig = digits->GetDataBits(ir,ic,it);
785 indexes->AddIndexRC(ir,ic);
801 //_____________________________________________________________________________
802 Bool_t AliTRDdigitsManager::LoadArray(TObjArray * const object
803 , const Char_t *branchname
804 , TTree * const tree)
807 // Loads all detectors of the array from the branch <branchname> of
808 // the digits tree <tree>
809 // Adapted from code of the class AliTRDsegmentArray
816 AliError("Digits tree is not defined\n");
821 fBranch = fTreeD->GetBranch(branchname);
824 AliError(Form("Branch %s is not defined\n",branchname));
828 // Loop through all detectors and read them from the tree
829 Bool_t status = kTRUE;
830 for (Int_t iDet = 0; iDet < fDets; iDet++)
834 AliTRDarraySignal *dataArray = (AliTRDarraySignal *) object->At(iDet);
841 fBranch->SetAddress(&dataArray);
842 fBranch->GetEntry(iDet);
846 AliTRDarrayADC *dataArray = (AliTRDarrayADC *) object->At(iDet);
852 fBranch->SetAddress(&dataArray);
853 fBranch->GetEntry(iDet);
861 //________________________________________________________________________________________________
862 Bool_t AliTRDdigitsManager::LoadArrayDict(TObjArray * const object
863 , const Char_t *branchname
864 , TTree * const tree)
867 // Loads all detectors of the array from the branch <branchname> of
868 // the dictionary tree <tree>
869 // Adapted from code of the class AliTRDsegmentArray
876 AliError("Digits tree is not defined\n");
881 fBranch = fTreeD->GetBranch(branchname);
884 AliError(Form("Branch %s is not defined\n",branchname));
888 // Loop through all detectors and read them from the tree
889 Bool_t status = kTRUE;
890 for (Int_t iDet = 0; iDet < fDets; iDet++)
892 AliTRDarrayDictionary *dataArray = (AliTRDarrayDictionary *) object->At(iDet);
898 fBranch->SetAddress(&dataArray);
899 fBranch->GetEntry(iDet);
906 //_____________________________________________________________________________
907 Bool_t AliTRDdigitsManager::StoreArray(TObjArray * const array1
908 , const Char_t *branchname
909 , TTree * const tree)
912 // Stores all the detectors of the array in the branch <branchname> of
913 // the digits tree <tree>
914 // Adapted from code of the class AliTRDsegmentArray
921 AliError("Digits tree is not defined\n");
926 fBranch = fTree->GetBranch(branchname);
929 AliError(Form("Branch %s is not defined\n",branchname));
933 // Loop through all detectors and fill them into the tree
934 Bool_t status = kTRUE;
935 for (Int_t iDet = 0; iDet < fDets; iDet++)
939 const AliTRDarraySignal *kDataArray = (AliTRDarraySignal *) array1->At(iDet);
945 fBranch->SetAddress(&kDataArray);
950 const AliTRDarrayADC *kDataArray = (AliTRDarrayADC *) array1->At(iDet);
956 fBranch->SetAddress(&kDataArray);
965 //_____________________________________________________________________________
966 Bool_t AliTRDdigitsManager::StoreArrayDict(TObjArray * const array3
967 , const Char_t *branchname
968 , TTree * const tree)
971 // Stores all the dictionary arrays of the detectors of the array in the branch <branchname> of
972 // the dictionary tree <tree>
973 // Adapted from code of the class AliTRDsegmentArray
976 // AliDebug(1,"Storing Arrays of Dictionary");
981 AliError("Digits tree is not defined\n");
986 fBranch = fTree->GetBranch(branchname);
989 AliError(Form("Branch %s is not defined\n",branchname));
993 // Loop through all detectors and fill them into the tree
994 Bool_t status = kTRUE;
995 for (Int_t iDet = 0; iDet < fDets; iDet++)
997 const AliTRDarrayDictionary *kDataArray = (AliTRDarrayDictionary *) array3->At(iDet);
1003 fBranch->SetAddress(&kDataArray);