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 // Reset the data arrays
285 Int_t recoDet = fRawRec ? 0 : det;
287 RemoveDigits(recoDet);
288 RemoveDictionaries(recoDet);
289 RemoveIndexes(recoDet);
292 fDigits->AddAt(new AliTRDarraySignal(),recoDet);
294 fDigits->AddAt(new AliTRDarrayADC(),recoDet);
296 if (fUseDictionaries)
298 for (Int_t iDict = 0; iDict < kNDict; iDict++)
299 fDict[iDict]->AddAt(new AliTRDarrayDictionary(),recoDet);
302 fSignalIndexes->AddAt(new AliTRDSignalIndex(),recoDet);
305 //_____________________________________________________________________________
306 Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time, Int_t det) const
309 // Returns the amplitude of a digit
312 if (!GetDigits(det)) return 0;
314 return ((Short_t) ((AliTRDarrayADC *) GetDigits(det))->GetDataBits(row,col,time));
318 //_____________________________________________________________________________
319 UChar_t AliTRDdigitsManager::GetPadStatus(Int_t row, Int_t col, Int_t time, Int_t det) const
322 // Returns the pad status for the requested pad
325 if (!GetDigits(det)) return 0;
327 return ((UChar_t) ((AliTRDarrayADC *) GetDigits(det))->GetPadStatus(row,col,time));
331 //_____________________________________________________________________________
332 Bool_t AliTRDdigitsManager::MakeBranch(TTree * const tree)
335 // Creates the tree and branches for the digits and the dictionary
338 Int_t buffersize = 64000;
339 Bool_t status = kTRUE;
346 // Make the branch for the digits
351 const AliTRDarraySignal *kDigits = (AliTRDarraySignal *) fDigits->At(0);
354 if (!fTree) return kFALSE;
355 AliDebug(1,"Making branch for SDigits!\n");
356 TBranch* branch = fTree->GetBranch("TRDdigits");
357 if (!branch) fTree->Branch("TRDdigits","AliTRDarraySignal",&kDigits,buffersize,99);
358 AliDebug(1,"Making branch TRDdigits\n");
368 const AliTRDarrayADC *kDigits = (AliTRDarrayADC *) fDigits->At(0);
371 if (!fTree) return kFALSE;
372 AliDebug(1,"Making branch for Digits!\n");
373 TBranch* branch = fTree->GetBranch("TRDdigits");
374 if (!branch) fTree->Branch("TRDdigits","AliTRDarrayADC",&kDigits,buffersize,99);
375 AliDebug(1,"Making branch TRDdigits\n");
389 if (fUseDictionaries)
391 // Make the branches for the dictionaries
392 for (Int_t iDict = 0; iDict < kNDict; iDict++)
394 Char_t branchname[15];
395 sprintf(branchname,"TRDdictionary%d",iDict);
398 const AliTRDarrayDictionary *kDictionary = (AliTRDarrayDictionary *) fDict[iDict]->At(0);
401 if (!fTree) return kFALSE;
402 AliDebug(2,"Making branch for dictionary!\n");
403 TBranch* branch = fTree->GetBranch(branchname);
404 if (!branch) fTree->Branch(branchname,"AliTRDarrayDictionary",&kDictionary,buffersize,99);
405 AliDebug(1,Form("Making branch %s\n",branchname));
423 //_____________________________________________________________________________
424 Bool_t AliTRDdigitsManager::ReadDigits(TTree * const tree)
427 // Reads the digit information from the input file
430 Bool_t status = kTRUE;
439 AliDebug(1,"Create the data arrays.\n");
443 status = LoadArray(fDigits,"TRDdigits",fTree);
445 if (fUseDictionaries)
447 for (Int_t iDict = 0; iDict < kNDict; iDict++)
449 Char_t branchname[15];
450 sprintf(branchname,"TRDdictionary%d",iDict);
451 status = LoadArrayDict(fDict[iDict],branchname,fTree);
452 if (status == kFALSE)
454 fUseDictionaries = kFALSE;
455 AliWarning("Unable to load dict arrays. Will not use them.\n");
465 //_____________________________________________________________________________
466 Bool_t AliTRDdigitsManager::WriteDigits()
469 // Writes out the TRD-digits and the dictionaries
472 // Store the contents of the detector array in the tree
474 if (!StoreArray(fDigits,"TRDdigits",fTree))
476 AliError("Error while storing digits in branch TRDdigits\n");
480 if (fUseDictionaries)
482 for (Int_t iDict = 0; iDict < kNDict; iDict++)
484 Char_t branchname[15];
485 sprintf(branchname,"TRDdictionary%d",iDict);
486 if (!StoreArrayDict(fDict[iDict],branchname,fTree))
488 AliError(Form("Error while storing dictionary in branch %s\n",branchname));
494 // Write the new tree to the output file
501 //_____________________________________________________________________________
502 AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row
508 // Creates a single digit object
519 amp[0] = ((AliTRDarrayADC *) GetDigits(det))->GetData(row,col,time);
521 return (new AliTRDdigit(digits,amp));
525 //_____________________________________________________________________________
526 Int_t AliTRDdigitsManager::GetTrack(Int_t track
533 // Returns the MC-track numbers from the dictionary.
536 if ((track < 0) || (track >= kNDict))
538 AliError(Form("track %d out of bounds (size: %d, this: 0x%08x)",track,kNDict,this));
542 if (fUseDictionaries == kFALSE)
547 // Array contains index+1 to allow data compression--->Changed
548 return (((AliTRDarrayDictionary *) GetDictionary(det,track))->GetData(row,col,time) );
552 //________________________________________________________________________________
553 AliTRDarrayADC *AliTRDdigitsManager::GetDigits(Int_t det) const
556 // Returns the digits array for one detector
559 Int_t RecoDet = fRawRec ? 0 : det;
568 ((AliTRDarrayADC *) fDigits->At(RecoDet))->SetNdet(det);
569 return (AliTRDarrayADC *) fDigits->At(RecoDet);
573 AliDebug(2,"ERROR IN DATA TYPE!!!!");
579 //_____________________________________________________________________________
580 AliTRDarraySignal *AliTRDdigitsManager::GetSDigits(Int_t det) const
583 // Returns the sdigits array for one detector
586 Int_t RecoDet = fRawRec ? 0 : det;
590 // AliDebug(1,"NO FDIGITS!");
596 ((AliTRDarraySignal *) fDigits->At(RecoDet))->SetNdet(det);
597 return (AliTRDarraySignal *) fDigits->At(RecoDet);
601 AliDebug(2,"ERROR IN DATA TYPE!!!!");
607 //_____________________________________________________________________________
608 AliTRDarrayDictionary *AliTRDdigitsManager::GetDictionary(Int_t det
612 // Returns the dictionary for one detector
615 Int_t RecoDet = fRawRec ? 0 : det;
617 if (fUseDictionaries == kFALSE)
622 ((AliTRDarrayDictionary *) fDigits->At(RecoDet))->SetNdet(det);
623 return (AliTRDarrayDictionary *) fDict[i]->At(RecoDet);
627 //_____________________________________________________________________________
628 Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit * const digit) const
631 // Returns the MC-track numbers from the dictionary for a given digit
634 Int_t row = digit->GetRow();
635 Int_t col = digit->GetCol();
636 Int_t time = digit->GetTime();
637 Int_t det = digit->GetDetector();
639 return GetTrack(track,row,col,time,det);
643 //_____________________________________________________________________________
644 AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det)
647 // Returns indexes of active pads
650 Int_t RecoDet = fRawRec ? 0 : det;
652 return (AliTRDSignalIndex *) fSignalIndexes->At(RecoDet);
656 //_____________________________________________________________________________
657 void AliTRDdigitsManager::RemoveDigits(Int_t det)
660 // Clear memory at det for Digits
663 Int_t RecoDet = fRawRec ? 0 : det;
665 if (fDigits->At(RecoDet))
669 AliTRDarraySignal *arr = (AliTRDarraySignal *) fDigits->RemoveAt(RecoDet);
674 AliTRDarrayADC *arr = (AliTRDarrayADC *) fDigits->RemoveAt(RecoDet);
681 //_____________________________________________________________________________
682 void AliTRDdigitsManager::RemoveDictionaries(Int_t det)
688 Int_t RecoDet = fRawRec ? 0 : det;
690 if (fUseDictionaries == kFALSE)
695 for (Int_t i = 0; i < kNDict; i++)
697 if (fDict[i]->At(RecoDet))
699 AliTRDarrayDictionary *arr = (AliTRDarrayDictionary *) fDict[i]->RemoveAt(RecoDet);
706 //_____________________________________________________________________________
707 void AliTRDdigitsManager::RemoveIndexes(Int_t det)
713 Int_t RecoDet = fRawRec ? 0 : det;
715 if (fSignalIndexes->At(RecoDet))
717 AliTRDSignalIndex *arr = (AliTRDSignalIndex *) fSignalIndexes->RemoveAt(RecoDet);
724 //_____________________________________________________________________________
725 void AliTRDdigitsManager::ClearIndexes(Int_t det)
731 Int_t RecoDet = fRawRec ? 0 : det;
733 ((AliTRDSignalIndex *) fSignalIndexes->At(RecoDet))->ClearAll();
737 //_____________________________________________________________________________
738 Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det)
741 // Build the list of indices
749 AliTRDarrayADC *digits = 0x0;
757 digits = (AliTRDarrayADC *) GetDigits(det);
760 //digits should be expanded by now!!!
761 if (digits->GetNtime() > 0)
764 nRows = digits->GetNrow();
765 nCols = digits->GetNcol();
766 nTbins = digits->GetNtime();
768 AliTRDSignalIndex *indexes = GetIndexes(det);
769 indexes->SetSM(geom.GetSector(det));
770 indexes->SetStack(geom.GetStack(det));
771 indexes->SetLayer(geom.GetLayer(det));
772 indexes->SetDetNumber(det);
774 if (indexes->IsAllocated() == kFALSE)
776 indexes->Allocate(nRows,nCols,nTbins);
779 for (Int_t ir = 0; ir < nRows; ir++)
781 for (Int_t ic = 0; ic < nCols; ic++)
783 for (Int_t it = 0; it < nTbins; it++)
785 Int_t isig = digits->GetDataBits(ir,ic,it);
788 indexes->AddIndexRC(ir,ic);
804 //_____________________________________________________________________________
805 Bool_t AliTRDdigitsManager::LoadArray(TObjArray * const object
806 , const Char_t *branchname
807 , TTree * const tree)
810 // Loads all detectors of the array from the branch <branchname> of
811 // the digits tree <tree>
812 // Adapted from code of the class AliTRDsegmentArray
819 AliError("Digits tree is not defined\n");
824 fBranch = fTreeD->GetBranch(branchname);
827 AliError(Form("Branch %s is not defined\n",branchname));
831 // Loop through all detectors and read them from the tree
832 Bool_t status = kTRUE;
833 for (Int_t iDet = 0; iDet < fDets; iDet++)
837 AliTRDarraySignal *dataArray = (AliTRDarraySignal *) object->At(iDet);
844 fBranch->SetAddress(&dataArray);
845 fBranch->GetEntry(iDet);
849 AliTRDarrayADC *dataArray = (AliTRDarrayADC *) object->At(iDet);
855 fBranch->SetAddress(&dataArray);
856 fBranch->GetEntry(iDet);
864 //________________________________________________________________________________________________
865 Bool_t AliTRDdigitsManager::LoadArrayDict(TObjArray * const object
866 , const Char_t *branchname
867 , TTree * const tree)
870 // Loads all detectors of the array from the branch <branchname> of
871 // the dictionary tree <tree>
872 // Adapted from code of the class AliTRDsegmentArray
879 AliError("Digits tree is not defined\n");
884 fBranch = fTreeD->GetBranch(branchname);
887 AliError(Form("Branch %s is not defined\n",branchname));
891 // Loop through all detectors and read them from the tree
892 Bool_t status = kTRUE;
893 for (Int_t iDet = 0; iDet < fDets; iDet++)
895 AliTRDarrayDictionary *dataArray = (AliTRDarrayDictionary *) object->At(iDet);
901 fBranch->SetAddress(&dataArray);
902 fBranch->GetEntry(iDet);
909 //_____________________________________________________________________________
910 Bool_t AliTRDdigitsManager::StoreArray(TObjArray * const array1
911 , const Char_t *branchname
912 , TTree * const tree)
915 // Stores all the detectors of the array in the branch <branchname> of
916 // the digits tree <tree>
917 // Adapted from code of the class AliTRDsegmentArray
924 AliError("Digits tree is not defined\n");
929 fBranch = fTree->GetBranch(branchname);
932 AliError(Form("Branch %s is not defined\n",branchname));
936 // Loop through all detectors and fill them into the tree
937 Bool_t status = kTRUE;
938 for (Int_t iDet = 0; iDet < fDets; iDet++)
942 const AliTRDarraySignal *kDataArray = (AliTRDarraySignal *) array1->At(iDet);
948 fBranch->SetAddress(&kDataArray);
953 const AliTRDarrayADC *kDataArray = (AliTRDarrayADC *) array1->At(iDet);
959 fBranch->SetAddress(&kDataArray);
968 //_____________________________________________________________________________
969 Bool_t AliTRDdigitsManager::StoreArrayDict(TObjArray * const array3
970 , const Char_t *branchname
971 , TTree * const tree)
974 // Stores all the dictionary arrays of the detectors of the array in the branch <branchname> of
975 // the dictionary tree <tree>
976 // Adapted from code of the class AliTRDsegmentArray
979 // AliDebug(1,"Storing Arrays of Dictionary");
984 AliError("Digits tree is not defined\n");
989 fBranch = fTree->GetBranch(branchname);
992 AliError(Form("Branch %s is not defined\n",branchname));
996 // Loop through all detectors and fill them into the tree
997 Bool_t status = kTRUE;
998 for (Int_t iDet = 0; iDet < fDets; iDet++)
1000 const AliTRDarrayDictionary *kDataArray = (AliTRDarrayDictionary *) array3->At(iDet);
1006 fBranch->SetAddress(&kDataArray);