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
104 for (Int_t iDict = 0; iDict < kNDict; iDict++)
106 fDict[iDict]->Delete();
113 fSignalIndexes->Delete();
114 delete fSignalIndexes;
115 fSignalIndexes = NULL;
120 //_____________________________________________________________________________
121 AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
124 // Assignment operator
129 ((AliTRDdigitsManager &) m).Copy(*this);
136 //_____________________________________________________________________________
137 void AliTRDdigitsManager::Copy(TObject &m) const
143 ((AliTRDdigitsManager &) m).fEvent = fEvent;
144 ((AliTRDdigitsManager &) m).fHasSDigits = fHasSDigits;
145 ((AliTRDdigitsManager &) m).fDigits = fDigits;
146 for(Int_t i=0; i<kNDict; i++)
148 ((AliTRDdigitsManager &) m).fDict[i] = fDict[i];
150 ((AliTRDdigitsManager &) m).fSignalIndexes = fSignalIndexes;
151 ((AliTRDdigitsManager &) m).fUseDictionaries = fUseDictionaries;
157 //_____________________________________________________________________________
158 void AliTRDdigitsManager::CreateArrays()
161 // Create the data arrays
171 fDigits = new TObjArray(AliTRDgeometry::Ndet());
172 for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++)
174 AliTRDarraySignal *chamber= new AliTRDarraySignal();
175 chamber->SetNdet(index);
176 fDigits->AddAt(chamber,index);
186 fDigits = new TObjArray(AliTRDgeometry::Ndet());
187 for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++)
189 AliTRDarrayADC *chamber= new AliTRDarrayADC();
190 chamber->SetNdet(index);
191 fDigits->AddAt(chamber,index);
195 if (fUseDictionaries)
197 for(Int_t iDict = 0; iDict < kNDict; iDict++)
200 fDict[iDict]->Delete();
203 for(Int_t iDict = 0; iDict < kNDict; iDict++)
205 fDict[iDict] = new TObjArray(AliTRDgeometry::Ndet());
208 for (Int_t iDict = 0; iDict < kNDict; iDict++)
210 for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++)
212 AliTRDarrayDictionary *dictio= new AliTRDarrayDictionary();
213 dictio->SetNdet(index);
214 fDict[iDict]->AddAt(dictio,index);
219 for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++)
221 fSignalIndexes->AddLast(new AliTRDSignalIndex());
226 //_____________________________________________________________________________
227 void AliTRDdigitsManager::ResetArrays()
230 // Reset the data arrays
239 for (Int_t iDict = 0; iDict < kNDict; iDict++)
243 fDict[iDict]->Delete();
250 fDigits = new TObjArray(AliTRDgeometry::Ndet());
251 for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++)
253 AliTRDarraySignal *chamber= new AliTRDarraySignal();
254 chamber->SetNdet(index);
255 fDigits->AddAt(chamber,index);
260 fDigits = new TObjArray(AliTRDgeometry::Ndet());
261 for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++)
263 AliTRDarrayADC *chamber= new AliTRDarrayADC();
264 chamber->SetNdet(index);
265 fDigits->AddAt(chamber,index);
269 if (fUseDictionaries)
271 for(Int_t iDict = 0; iDict < kNDict; iDict++)
273 fDict[iDict] = new TObjArray(AliTRDgeometry::Ndet());
275 for (Int_t iDict = 0; iDict < kNDict; iDict++)
277 for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++)
279 AliTRDarrayDictionary *dictio= new AliTRDarrayDictionary();
280 dictio->SetNdet(index);
281 fDict[iDict]->AddAt(dictio,index);
286 for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++)
288 AliTRDSignalIndex *idx = (AliTRDSignalIndex *) fSignalIndexes->At(i);
289 if (idx) idx->Reset();
294 //_____________________________________________________________________________
295 Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time, Int_t det) const
298 // Returns the amplitude of a digit
306 return ((Short_t) ((AliTRDarrayADC *) GetDigits(det))->GetDataB(row,col,time));
310 //_____________________________________________________________________________
311 UChar_t AliTRDdigitsManager::GetPadStatus(Int_t row, Int_t col, Int_t time, Int_t det) const
314 // Returns the pad status for the requested pad
322 return ((UChar_t) ((AliTRDarrayADC *) GetDigits(det))->GetPadStatus(row,col,time));
326 //_____________________________________________________________________________
327 Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree)
330 // Creates the tree and branches for the digits and the dictionary
333 Int_t buffersize = 64000;
334 Bool_t status = kTRUE;
341 // Make the branch for the digits
346 const AliTRDarraySignal *kDigits = (AliTRDarraySignal *) fDigits->At(0);
349 if (!fTree) return kFALSE;
350 AliDebug(1,"Making branch for SDigits!\n");
351 TBranch* branch = fTree->GetBranch("TRDdigits");
352 if (!branch) fTree->Branch("TRDdigits","AliTRDarraySignal",&kDigits,buffersize,99);
353 AliDebug(1,"Making branch TRDdigits\n");
363 const AliTRDarrayADC *kDigits = (AliTRDarrayADC *) fDigits->At(0);
366 if (!fTree) return kFALSE;
367 AliDebug(1,"Making branch for Digits!\n");
368 TBranch* branch = fTree->GetBranch("TRDdigits");
369 if (!branch) fTree->Branch("TRDdigits","AliTRDarrayADC",&kDigits,buffersize,99);
370 AliDebug(1,"Making branch TRDdigits\n");
384 if (fUseDictionaries)
386 // Make the branches for the dictionaries
387 for (Int_t iDict = 0; iDict < kNDict; iDict++)
389 Char_t branchname[15];
390 sprintf(branchname,"TRDdictionary%d",iDict);
393 const AliTRDarrayDictionary *kDictionary = (AliTRDarrayDictionary *) fDict[iDict]->At(0);
396 if (!fTree) return kFALSE;
397 AliDebug(2,"Making branch for dictionary!\n");
398 TBranch* branch = fTree->GetBranch(branchname);
399 if (!branch) fTree->Branch(branchname,"AliTRDarrayDictionary",&kDictionary,buffersize,99);
400 AliDebug(1,Form("Making branch %s\n",branchname));
418 //_____________________________________________________________________________
419 Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree)
422 // Reads the digit information from the input file
425 Bool_t status = kTRUE;
434 AliDebug(1,"Create the data arrays.\n");
438 status = LoadArray(fDigits,"TRDdigits",fTree);
440 if (fUseDictionaries)
442 for (Int_t iDict = 0; iDict < kNDict; iDict++)
444 Char_t branchname[15];
445 sprintf(branchname,"TRDdictionary%d",iDict);
446 status = LoadArrayDict(fDict[iDict],branchname,fTree);
447 if (status == kFALSE)
449 fUseDictionaries = kFALSE;
450 AliWarning("Unable to load dict arrays. Will not use them.\n");
460 //_____________________________________________________________________________
461 Bool_t AliTRDdigitsManager::WriteDigits()
464 // Writes out the TRD-digits and the dictionaries
467 // Store the contents of the detector array in the tree
469 if (!StoreArray(fDigits,"TRDdigits",fTree))
471 AliError("Error while storing digits in branch TRDdigits\n");
475 if (fUseDictionaries)
477 for (Int_t iDict = 0; iDict < kNDict; iDict++)
479 Char_t branchname[15];
480 sprintf(branchname,"TRDdictionary%d",iDict);
481 if (!StoreArrayDict(fDict[iDict],branchname,fTree))
483 AliError(Form("Error while storing dictionary in branch %s\n",branchname));
489 // Write the new tree to the output file
496 //_____________________________________________________________________________
497 AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row
503 // Creates a single digit object
514 amp[0] = ((AliTRDarrayADC *) GetDigits(det))->GetData(row,col,time);
516 return (new AliTRDdigit(digits,amp));
520 //_____________________________________________________________________________
521 Int_t AliTRDdigitsManager::GetTrack(Int_t track
528 // Returns the MC-track numbers from the dictionary.
531 if ((track < 0) || (track >= kNDict))
533 AliError(Form("track %d out of bounds (size: %d, this: 0x%08x)",track,kNDict,this));
537 if (fUseDictionaries == kFALSE)
542 // Array contains index+1 to allow data compression--->Changed
543 return (((AliTRDarrayDictionary *) GetDictionary(det,track))->GetData(row,col,time) );
547 //________________________________________________________________________________
548 AliTRDarrayADC *AliTRDdigitsManager::GetDigits(Int_t det) const
551 // Returns the digits array for one detector
561 return (AliTRDarrayADC *) fDigits->At(det);
565 AliDebug(2,"ERROR IN DATA TYPE!!!!");
571 //_____________________________________________________________________________
572 AliTRDarraySignal *AliTRDdigitsManager::GetSDigits(Int_t det) const
575 // Returns the sdigits array for one detector
580 // AliDebug(1,"NO FDIGITS!");
586 return (AliTRDarraySignal *) fDigits->At(det);
590 AliDebug(2,"ERROR IN DATA TYPE!!!!");
596 //_____________________________________________________________________________
597 AliTRDarrayDictionary *AliTRDdigitsManager::GetDictionary(Int_t det
601 // Returns the dictionary for one detector
604 if (fUseDictionaries == kFALSE)
609 return (AliTRDarrayDictionary *) fDict[i]->At(det);
613 //_____________________________________________________________________________
614 Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *digit) const
617 // Returns the MC-track numbers from the dictionary for a given digit
620 Int_t row = digit->GetRow();
621 Int_t col = digit->GetCol();
622 Int_t time = digit->GetTime();
623 Int_t det = digit->GetDetector();
625 return GetTrack(track,row,col,time,det);
629 //_____________________________________________________________________________
630 AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det)
633 // Returns indexes of active pads
636 return (AliTRDSignalIndex *) fSignalIndexes->At(det);
640 //_____________________________________________________________________________
641 void AliTRDdigitsManager::RemoveDigits(Int_t det)
644 // Clear memory at det for Digits
647 if (fDigits->At(det))
651 AliTRDarraySignal *arr = (AliTRDarraySignal *) fDigits->RemoveAt(det);
656 AliTRDarrayADC *arr = (AliTRDarrayADC *) fDigits->RemoveAt(det);
663 //_____________________________________________________________________________
664 void AliTRDdigitsManager::RemoveDictionaries(Int_t det)
670 if (fUseDictionaries == kFALSE)
675 for (Int_t i = 0; i < kNDict; i++)
677 if (fDict[i]->At(det))
679 AliTRDarrayDictionary *arr = (AliTRDarrayDictionary *) fDict[i]->RemoveAt(det);
686 //_____________________________________________________________________________
687 void AliTRDdigitsManager::ClearIndexes(Int_t det)
693 ((AliTRDSignalIndex *) fSignalIndexes->At(det))->ClearAll();
697 //_____________________________________________________________________________
698 Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det)
701 // Build the list of indices
709 AliTRDarrayADC *digits = 0x0;
717 digits = (AliTRDarrayADC *) GetDigits(det);
720 //digits should be expanded by now!!!
721 if (digits->GetNtime() > 0)
724 nRows = digits->GetNrow();
725 nCols = digits->GetNcol();
726 nTbins = digits->GetNtime();
728 AliTRDSignalIndex *indexes = GetIndexes(det);
729 indexes->SetSM(geom.GetSector(det));
730 indexes->SetStack(geom.GetStack(det));
731 indexes->SetLayer(geom.GetLayer(det));
732 indexes->SetDetNumber(det);
734 if (indexes->IsAllocated() == kFALSE)
736 indexes->Allocate(nRows,nCols,nTbins);
739 for (Int_t ir = 0; ir < nRows; ir++)
741 for (Int_t ic = 0; ic < nCols; ic++)
743 for (Int_t it = 0; it < nTbins; it++)
745 Int_t isig = digits->GetDataB(ir,ic,it);
748 indexes->AddIndexTBin(ir,ic,it);
764 //_____________________________________________________________________________
765 Bool_t AliTRDdigitsManager::LoadArray(TObjArray *object
766 , const Char_t *branchname
770 // Loads all detectors of the array from the branch <branchname> of
771 // the digits tree <tree>
772 // Adapted from code of the class AliTRDsegmentArray
779 AliError("Digits tree is not defined\n");
784 fBranch = fTreeD->GetBranch(branchname);
787 AliError(Form("Branch %s is not defined\n",branchname));
791 // Loop through all detectors and read them from the tree
792 Bool_t status = kTRUE;
793 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++)
797 AliTRDarraySignal *dataArray = (AliTRDarraySignal *) object->At(iDet);
804 fBranch->SetAddress(&dataArray);
805 fBranch->GetEntry(iDet);
809 AliTRDarrayADC *dataArray = (AliTRDarrayADC *) object->At(iDet);
815 fBranch->SetAddress(&dataArray);
816 fBranch->GetEntry(iDet);
824 //________________________________________________________________________________________________
825 Bool_t AliTRDdigitsManager::LoadArrayDict(TObjArray *object
826 , const Char_t *branchname
830 // Loads all detectors of the array from the branch <branchname> of
831 // the dictionary tree <tree>
832 // Adapted from code of the class AliTRDsegmentArray
839 AliError("Digits tree is not defined\n");
844 fBranch = fTreeD->GetBranch(branchname);
847 AliError(Form("Branch %s is not defined\n",branchname));
851 // Loop through all detectors and read them from the tree
852 Bool_t status = kTRUE;
853 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++)
855 AliTRDarrayDictionary *dataArray = (AliTRDarrayDictionary *) object->At(iDet);
861 fBranch->SetAddress(&dataArray);
862 fBranch->GetEntry(iDet);
869 //_____________________________________________________________________________
870 Bool_t AliTRDdigitsManager::StoreArray(TObjArray *array1
871 , const Char_t *branchname
875 // Stores all the detectors of the array in the branch <branchname> of
876 // the digits tree <tree>
877 // Adapted from code of the class AliTRDsegmentArray
884 AliError("Digits tree is not defined\n");
889 fBranch = fTree->GetBranch(branchname);
892 AliError(Form("Branch %s is not defined\n",branchname));
896 // Loop through all detectors and fill them into the tree
897 Bool_t status = kTRUE;
898 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++)
902 const AliTRDarraySignal *kDataArray = (AliTRDarraySignal *) array1->At(iDet);
908 fBranch->SetAddress(&kDataArray);
913 const AliTRDarrayADC *kDataArray = (AliTRDarrayADC *) array1->At(iDet);
919 fBranch->SetAddress(&kDataArray);
928 //_____________________________________________________________________________
929 Bool_t AliTRDdigitsManager::StoreArrayDict(TObjArray *array3
930 , const Char_t *branchname
934 // Stores all the dictionary arrays of the detectors of the array in the branch <branchname> of
935 // the dictionary tree <tree>
936 // Adapted from code of the class AliTRDsegmentArray
939 // AliDebug(1,"Storing Arrays of Dictionary");
944 AliError("Digits tree is not defined\n");
949 fBranch = fTree->GetBranch(branchname);
952 AliError(Form("Branch %s is not defined\n",branchname));
956 // Loop through all detectors and fill them into the tree
957 Bool_t status = kTRUE;
958 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++)
960 const AliTRDarrayDictionary *kDataArray = (AliTRDarrayDictionary *) array3->At(iDet);
966 fBranch->SetAddress(&kDataArray);