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()
54 ,fUseDictionaries(kTRUE)
59 // Default constructor
62 for (Int_t iDict = 0; iDict < kNDict; iDict++)
67 fSignalIndexes = new TObjArray(AliTRDgeometry::Ndet());
71 //_____________________________________________________________________________
72 AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
77 ,fHasSDigits(m.fHasSDigits)
79 ,fUseDictionaries(kTRUE)
84 // AliTRDdigitsManager copy constructor
89 //_____________________________________________________________________________
90 AliTRDdigitsManager::~AliTRDdigitsManager()
93 // AliTRDdigitsManager destructor
103 for (Int_t iDict = 0; iDict < kNDict; iDict++)
105 fDict[iDict]->Delete();
112 fSignalIndexes->Delete();
113 delete fSignalIndexes;
114 fSignalIndexes = NULL;
119 //_____________________________________________________________________________
120 AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
123 // Assignment operator
128 ((AliTRDdigitsManager &) m).Copy(*this);
135 //_____________________________________________________________________________
136 void AliTRDdigitsManager::Copy(TObject &m) const
142 ((AliTRDdigitsManager &) m).fEvent = fEvent;
143 ((AliTRDdigitsManager &) m).fHasSDigits = fHasSDigits;
144 ((AliTRDdigitsManager &) m).fDigits = fDigits;
145 for(Int_t i=0; i<kNDict; i++)
147 ((AliTRDdigitsManager &) m).fDict[i] = fDict[i];
149 ((AliTRDdigitsManager &) m).fSignalIndexes = fSignalIndexes;
150 ((AliTRDdigitsManager &) m).fUseDictionaries = fUseDictionaries;
156 //_____________________________________________________________________________
157 void AliTRDdigitsManager::CreateArrays()
160 // Create the data arrays
170 fDigits = new TObjArray(AliTRDgeometry::Ndet());
171 for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++)
173 AliTRDarraySignal *chamber= new AliTRDarraySignal();
174 chamber->SetNdet(index);
175 fDigits->AddAt(chamber,index);
185 fDigits = new TObjArray(AliTRDgeometry::Ndet());
186 for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++)
188 AliTRDarrayADC *chamber= new AliTRDarrayADC();
189 chamber->SetNdet(index);
190 fDigits->AddAt(chamber,index);
194 if (fUseDictionaries)
196 for(Int_t iDict = 0; iDict < kNDict; iDict++)
199 fDict[iDict]->Delete();
202 for(Int_t iDict = 0; iDict < kNDict; iDict++)
204 fDict[iDict] = new TObjArray(AliTRDgeometry::Ndet());
207 for (Int_t iDict = 0; iDict < kNDict; iDict++)
209 for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++)
211 AliTRDarrayDictionary *dictio= new AliTRDarrayDictionary();
212 dictio->SetNdet(index);
213 fDict[iDict]->AddAt(dictio,index);
218 for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++)
220 fSignalIndexes->AddLast(new AliTRDSignalIndex());
225 //_____________________________________________________________________________
226 void AliTRDdigitsManager::ResetArrays()
229 // Reset the data arrays
238 for (Int_t iDict = 0; iDict < kNDict; iDict++)
242 fDict[iDict]->Delete();
249 fDigits = new TObjArray(AliTRDgeometry::Ndet());
250 for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++)
252 AliTRDarraySignal *chamber= new AliTRDarraySignal();
253 chamber->SetNdet(index);
254 fDigits->AddAt(chamber,index);
259 fDigits = new TObjArray(AliTRDgeometry::Ndet());
260 for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++)
262 AliTRDarrayADC *chamber= new AliTRDarrayADC();
263 chamber->SetNdet(index);
264 fDigits->AddAt(chamber,index);
268 if (fUseDictionaries)
270 for(Int_t iDict = 0; iDict < kNDict; iDict++)
272 fDict[iDict] = new TObjArray(AliTRDgeometry::Ndet());
274 for (Int_t iDict = 0; iDict < kNDict; iDict++)
276 for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++)
278 AliTRDarrayDictionary *dictio= new AliTRDarrayDictionary();
279 dictio->SetNdet(index);
280 fDict[iDict]->AddAt(dictio,index);
285 for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++)
287 AliTRDSignalIndex *idx = (AliTRDSignalIndex *) fSignalIndexes->At(i);
288 if (idx) idx->Reset();
293 //_____________________________________________________________________________
294 Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time, Int_t det) const
297 // Returns the amplitude of a digit
305 return ((Short_t) ((AliTRDarrayADC *) GetDigits(det))->GetDataB(row,col,time));
309 //_____________________________________________________________________________
310 UChar_t AliTRDdigitsManager::GetPadStatus(Int_t row, Int_t col, Int_t time, Int_t det) const
313 // Returns the pad status for the requested pad
321 return ((UChar_t) ((AliTRDarrayADC *) GetDigits(det))->GetPadStatus(row,col,time));
325 //_____________________________________________________________________________
326 Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree)
329 // Creates the tree and branches for the digits and the dictionary
332 Int_t buffersize = 64000;
333 Bool_t status = kTRUE;
340 // Make the branch for the digits
345 const AliTRDarraySignal *kDigits = (AliTRDarraySignal *) fDigits->At(0);
348 if (!fTree) return kFALSE;
349 AliDebug(1,"Making branch for SDigits!\n");
350 TBranch* branch = fTree->GetBranch("TRDdigits");
351 if (!branch) fTree->Branch("TRDdigits","AliTRDarraySignal",&kDigits,buffersize,99);
352 AliDebug(1,"Making branch TRDdigits\n");
362 const AliTRDarrayADC *kDigits = (AliTRDarrayADC *) fDigits->At(0);
365 if (!fTree) return kFALSE;
366 AliDebug(1,"Making branch for Digits!\n");
367 TBranch* branch = fTree->GetBranch("TRDdigits");
368 if (!branch) fTree->Branch("TRDdigits","AliTRDarrayADC",&kDigits,buffersize,99);
369 AliDebug(1,"Making branch TRDdigits\n");
383 if (fUseDictionaries)
385 // Make the branches for the dictionaries
386 for (Int_t iDict = 0; iDict < kNDict; iDict++)
388 Char_t branchname[15];
389 sprintf(branchname,"TRDdictionary%d",iDict);
392 const AliTRDarrayDictionary *kDictionary = (AliTRDarrayDictionary *) fDict[iDict]->At(0);
395 if (!fTree) return kFALSE;
396 AliDebug(2,"Making branch for dictionary!\n");
397 TBranch* branch = fTree->GetBranch(branchname);
398 if (!branch) fTree->Branch(branchname,"AliTRDarrayDictionary",&kDictionary,buffersize,99);
399 AliDebug(1,Form("Making branch %s\n",branchname));
417 //_____________________________________________________________________________
418 Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree)
421 // Reads the digit information from the input file
424 Bool_t status = kTRUE;
433 AliDebug(1,"Create the data arrays.\n");
437 status = LoadArray(fDigits,"TRDdigits",fTree);
439 if (fUseDictionaries)
441 for (Int_t iDict = 0; iDict < kNDict; iDict++)
443 Char_t branchname[15];
444 sprintf(branchname,"TRDdictionary%d",iDict);
445 status = LoadArrayDict(fDict[iDict],branchname,fTree);
446 if (status == kFALSE)
448 fUseDictionaries = kFALSE;
449 AliWarning("Unable to load dict arrays. Will not use them.\n");
459 //_____________________________________________________________________________
460 Bool_t AliTRDdigitsManager::WriteDigits()
463 // Writes out the TRD-digits and the dictionaries
466 // Store the contents of the detector array in the tree
468 if (!StoreArray(fDigits,"TRDdigits",fTree))
470 AliError("Error while storing digits in branch TRDdigits\n");
474 if (fUseDictionaries)
476 for (Int_t iDict = 0; iDict < kNDict; iDict++)
478 Char_t branchname[15];
479 sprintf(branchname,"TRDdictionary%d",iDict);
480 if (!StoreArrayDict(fDict[iDict],branchname,fTree))
482 AliError(Form("Error while storing dictionary in branch %s\n",branchname));
488 // Write the new tree to the output file
495 //_____________________________________________________________________________
496 AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row
502 // Creates a single digit object
513 amp[0] = ((AliTRDarrayADC *) GetDigits(det))->GetData(row,col,time);
515 return (new AliTRDdigit(digits,amp));
519 //_____________________________________________________________________________
520 Int_t AliTRDdigitsManager::GetTrack(Int_t track
527 // Returns the MC-track numbers from the dictionary.
530 if ((track < 0) || (track >= kNDict))
532 AliError(Form("track %d out of bounds (size: %d, this: 0x%08x)",track,kNDict,this));
536 if (fUseDictionaries == kFALSE)
541 // Array contains index+1 to allow data compression--->Changed
542 return (((AliTRDarrayDictionary *) GetDictionary(det,track))->GetData(row,col,time) );
546 //________________________________________________________________________________
547 AliTRDarrayADC *AliTRDdigitsManager::GetDigits(Int_t det) const
550 // Returns the digits array for one detector
560 return (AliTRDarrayADC *) fDigits->At(det);
564 AliDebug(2,"ERROR IN DATA TYPE!!!!");
570 //_____________________________________________________________________________
571 AliTRDarraySignal *AliTRDdigitsManager::GetSDigits(Int_t det) const
574 // Returns the sdigits array for one detector
579 // AliDebug(1,"NO FDIGITS!");
585 return (AliTRDarraySignal *) fDigits->At(det);
589 AliDebug(2,"ERROR IN DATA TYPE!!!!");
595 //_____________________________________________________________________________
596 AliTRDarrayDictionary *AliTRDdigitsManager::GetDictionary(Int_t det
600 // Returns the dictionary for one detector
603 if (fUseDictionaries == kFALSE)
608 return (AliTRDarrayDictionary *) fDict[i]->At(det);
612 //_____________________________________________________________________________
613 Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *digit) const
616 // Returns the MC-track numbers from the dictionary for a given digit
619 Int_t row = digit->GetRow();
620 Int_t col = digit->GetCol();
621 Int_t time = digit->GetTime();
622 Int_t det = digit->GetDetector();
624 return GetTrack(track,row,col,time,det);
628 //_____________________________________________________________________________
629 AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det)
632 // Returns indexes of active pads
635 return (AliTRDSignalIndex *) fSignalIndexes->At(det);
639 //_____________________________________________________________________________
640 void AliTRDdigitsManager::RemoveDigits(Int_t det)
643 // Clear memory at det for Digits
646 if (fDigits->At(det))
648 fDigits->RemoveAt(det);
653 //_____________________________________________________________________________
654 void AliTRDdigitsManager::RemoveDictionaries(Int_t det)
660 if (fUseDictionaries == kFALSE)
665 for (Int_t i = 0; i < kNDict; i++)
667 if (fDict[i]->At(det))
669 fDict[i]->RemoveAt(det);
675 //_____________________________________________________________________________
676 void AliTRDdigitsManager::ClearIndexes(Int_t det)
682 ((AliTRDSignalIndex *) fSignalIndexes->At(det))->ClearAll();
686 //_____________________________________________________________________________
687 Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det)
690 // Build the list of indices
698 AliTRDarrayADC *digits = 0x0;
706 digits = (AliTRDarrayADC *) GetDigits(det);
709 //digits should be expanded by now!!!
710 if (digits->GetNtime() > 0)
713 nRows = digits->GetNrow();
714 nCols = digits->GetNcol();
715 nTbins = digits->GetNtime();
717 AliTRDSignalIndex *indexes = GetIndexes(det);
718 indexes->SetSM(geom.GetSector(det));
719 indexes->SetStack(geom.GetStack(det));
720 indexes->SetLayer(geom.GetLayer(det));
721 indexes->SetDetNumber(det);
723 if (indexes->IsAllocated() == kFALSE)
725 indexes->Allocate(nRows,nCols,nTbins);
728 for (Int_t ir = 0; ir < nRows; ir++)
730 for (Int_t ic = 0; ic < nCols; ic++)
732 for (Int_t it = 0; it < nTbins; it++)
734 Int_t isig = digits->GetDataB(ir,ic,it);
737 indexes->AddIndexTBin(ir,ic,it);
753 //_____________________________________________________________________________
754 Bool_t AliTRDdigitsManager::LoadArray(TObjArray *object
755 , const Char_t *branchname
759 // Loads all detectors of the array from the branch <branchname> of
760 // the digits tree <tree>
761 // Adapted from code of the class AliTRDsegmentArray
768 AliError("Digits tree is not defined\n");
773 fBranch = fTreeD->GetBranch(branchname);
776 AliError(Form("Branch %s is not defined\n",branchname));
780 // Loop through all detectors and read them from the tree
781 Bool_t status = kTRUE;
782 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++)
786 AliTRDarraySignal *dataArray = (AliTRDarraySignal *) object->At(iDet);
793 fBranch->SetAddress(&dataArray);
794 fBranch->GetEntry(iDet);
798 AliTRDarrayADC *dataArray = (AliTRDarrayADC *) object->At(iDet);
804 fBranch->SetAddress(&dataArray);
805 fBranch->GetEntry(iDet);
813 //________________________________________________________________________________________________
814 Bool_t AliTRDdigitsManager::LoadArrayDict(TObjArray *object
815 , const Char_t *branchname
819 // Loads all detectors of the array from the branch <branchname> of
820 // the dictionary tree <tree>
821 // Adapted from code of the class AliTRDsegmentArray
828 AliError("Digits tree is not defined\n");
833 fBranch = fTreeD->GetBranch(branchname);
836 AliError(Form("Branch %s is not defined\n",branchname));
840 // Loop through all detectors and read them from the tree
841 Bool_t status = kTRUE;
842 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++)
844 AliTRDarrayDictionary *dataArray = (AliTRDarrayDictionary *) object->At(iDet);
850 fBranch->SetAddress(&dataArray);
851 fBranch->GetEntry(iDet);
858 //_____________________________________________________________________________
859 Bool_t AliTRDdigitsManager::StoreArray(TObjArray *array1
860 , const Char_t *branchname
864 // Stores all the detectors of the array in the branch <branchname> of
865 // the digits tree <tree>
866 // Adapted from code of the class AliTRDsegmentArray
873 AliError("Digits tree is not defined\n");
878 fBranch = fTree->GetBranch(branchname);
881 AliError(Form("Branch %s is not defined\n",branchname));
885 // Loop through all detectors and fill them into the tree
886 Bool_t status = kTRUE;
887 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++)
891 const AliTRDarraySignal *kDataArray = (AliTRDarraySignal *) array1->At(iDet);
897 fBranch->SetAddress(&kDataArray);
902 const AliTRDarrayADC *kDataArray = (AliTRDarrayADC *) array1->At(iDet);
908 fBranch->SetAddress(&kDataArray);
917 //_____________________________________________________________________________
918 Bool_t AliTRDdigitsManager::StoreArrayDict(TObjArray *array3
919 , const Char_t *branchname
923 // Stores all the dictionary arrays of the detectors of the array in the branch <branchname> of
924 // the dictionary tree <tree>
925 // Adapted from code of the class AliTRDsegmentArray
928 // AliDebug(1,"Storing Arrays of Dictionary");
933 AliError("Digits tree is not defined\n");
938 fBranch = fTree->GetBranch(branchname);
941 AliError(Form("Branch %s is not defined\n",branchname));
945 // Loop through all detectors and fill them into the tree
946 Bool_t status = kTRUE;
947 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++)
949 const AliTRDarrayDictionary *kDataArray = (AliTRDarrayDictionary *) array3->At(iDet);
955 fBranch->SetAddress(&kDataArray);