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 "AliTRDdigitsParam.h"
35 #include "AliTRDSimParam.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)
55 ,fDets(AliTRDgeometry::Ndet())
60 // Default constructor
69 for (Int_t iDict = 0; iDict < kNDict; iDict++)
76 //_____________________________________________________________________________
77 AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
82 ,fHasSDigits(m.fHasSDigits)
84 ,fUseDictionaries(kTRUE)
90 // AliTRDdigitsManager copy constructor
95 //_____________________________________________________________________________
96 AliTRDdigitsManager::~AliTRDdigitsManager()
99 // AliTRDdigitsManager destructor
110 for (Int_t iDict = 0; iDict < kNDict; iDict++)
114 fDict[iDict]->Delete();
122 fSignalIndexes->Delete();
123 delete fSignalIndexes;
124 fSignalIndexes = NULL;
135 //_____________________________________________________________________________
136 AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
139 // Assignment operator
144 ((AliTRDdigitsManager &) m).Copy(*this);
151 //_____________________________________________________________________________
152 void AliTRDdigitsManager::Copy(TObject &m) const
158 ((AliTRDdigitsManager &) m).fEvent = fEvent;
159 ((AliTRDdigitsManager &) m).fHasSDigits = fHasSDigits;
160 ((AliTRDdigitsManager &) m).fDigits = NULL;
161 for(Int_t i = 0; i < kNDict; i++)
163 ((AliTRDdigitsManager &) m).fDict[i] = NULL;
165 ((AliTRDdigitsManager &) m).fSignalIndexes = NULL;
166 ((AliTRDdigitsManager &) m).fUseDictionaries = fUseDictionaries;
167 ((AliTRDdigitsManager &) m).fDets = fDets;
168 ((AliTRDdigitsManager &) m).fRawRec = fRawRec;
169 ((AliTRDdigitsManager &) m).fDigitsParam = NULL;
175 //_____________________________________________________________________________
176 void AliTRDdigitsManager::CreateArrays()
179 // Create the data arrays
189 fDigits = new TObjArray(fDets);
190 for (Int_t index = 0; index < fDets; index++)
192 fDigits->AddAt(new AliTRDarraySignal(),index);
202 fDigits = new TObjArray(fDets);
203 for (Int_t index = 0; index < fDets; index++)
205 fDigits->AddAt(new AliTRDarrayADC(),index);
209 if (fUseDictionaries)
211 for (Int_t iDict = 0; iDict < kNDict; iDict++)
215 fDict[iDict]->Delete();
218 fDict[iDict] = new TObjArray(fDets);
219 for (Int_t index = 0; index < fDets; index++)
221 fDict[iDict]->AddAt(new AliTRDarrayDictionary(),index);
228 fSignalIndexes->Delete();
229 delete fSignalIndexes;
231 fSignalIndexes = new TObjArray(fDets);
232 for (Int_t i = 0; i < fDets; i++)
234 fSignalIndexes->AddLast(new AliTRDSignalIndex());
241 fDigitsParam = new AliTRDdigitsParam();
242 fDigitsParam->SetNTimeBins(AliTRDSimParam::Instance()->GetNTimeBins());
243 fDigitsParam->SetADCbaseline(AliTRDSimParam::Instance()->GetADCbaseline());
247 //_____________________________________________________________________________
248 void AliTRDdigitsManager::ClearArrays(Int_t det)
251 // Reset the data arrays
254 Int_t recoDet = fRawRec ? 0 : det;
258 ((AliTRDarraySignal*)fDigits->At(recoDet))->Reset();
262 ((AliTRDarrayADC*)fDigits->At(recoDet))->ConditionalReset((AliTRDSignalIndex*)fSignalIndexes->At(recoDet));
265 if (fUseDictionaries)
267 for (Int_t iDict = 0; iDict < kNDict; iDict++)
269 ((AliTRDarrayDictionary*)fDict[iDict]->At(recoDet))->Reset();
273 ((AliTRDSignalIndex*)fSignalIndexes->At(recoDet))->ResetContent();
277 //_____________________________________________________________________________
278 Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time, Int_t det) const
281 // Returns the amplitude of a digit
284 if (!GetDigits(det)) return 0;
286 return ((Short_t) ((AliTRDarrayADC *) GetDigits(det))->GetDataBits(row,col,time));
290 //_____________________________________________________________________________
291 UChar_t AliTRDdigitsManager::GetPadStatus(Int_t row, Int_t col, Int_t time, Int_t det) const
294 // Returns the pad status for the requested pad
297 if (!GetDigits(det)) return 0;
299 return ((UChar_t) ((AliTRDarrayADC *) GetDigits(det))->GetPadStatus(row,col,time));
303 //_____________________________________________________________________________
304 Bool_t AliTRDdigitsManager::MakeBranch(TTree * const tree)
307 // Creates the tree and branches for the digits and the dictionary
310 Int_t buffersize = 64000;
311 Bool_t status = kTRUE;
318 // Make the branch for the digits
323 const AliTRDarraySignal *kDigits = (AliTRDarraySignal *) fDigits->At(0);
326 if (!fTree) return kFALSE;
327 AliDebug(1,"Making branch for SDigits!\n");
328 TBranch *branch = fTree->GetBranch("TRDdigits");
331 fTree->Branch("TRDdigits","AliTRDarraySignal",&kDigits,buffersize,99);
333 AliDebug(1,"Making branch TRDdigits\n");
343 const AliTRDarrayADC *kDigits = (AliTRDarrayADC *) fDigits->At(0);
346 if (!fTree) return kFALSE;
347 AliDebug(1,"Making branch for Digits!\n");
348 TBranch *branch = fTree->GetBranch("TRDdigits");
351 fTree->Branch("TRDdigits","AliTRDarrayADC",&kDigits,buffersize,99);
353 AliDebug(1,"Making branch TRDdigits\n");
369 if (fUseDictionaries)
371 // Make the branches for the dictionaries
372 for (Int_t iDict = 0; iDict < kNDict; iDict++)
374 Char_t branchname[15];
375 sprintf(branchname,"TRDdictionary%d",iDict);
378 const AliTRDarrayDictionary *kDictionary = (AliTRDarrayDictionary *) fDict[iDict]->At(0);
381 if (!fTree) return kFALSE;
382 AliDebug(2,"Making branch for dictionary!\n");
383 TBranch *branch = fTree->GetBranch(branchname);
386 fTree->Branch(branchname,"AliTRDarrayDictionary",&kDictionary,buffersize,99);
388 AliDebug(1,Form("Making branch %s\n",branchname));
404 const AliTRDdigitsParam *kDigitsParam = fDigitsParam;
405 if (!fTree) return kFALSE;
406 TBranch *branch = fTree->GetBranch("TRDdigitsParam");
409 fTree->Branch("TRDdigitsParam","AliTRDdigitsParam",&kDigitsParam,buffersize,99);
411 AliDebug(1,"Making branch AliTRDdigitsParam\n");
418 //_____________________________________________________________________________
419 Bool_t AliTRDdigitsManager::ReadDigits(TTree * const 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 = LoadArrayDigits();
440 if (fUseDictionaries)
442 status = LoadArrayDict();
443 if (status == kFALSE)
445 fUseDictionaries = kFALSE;
446 AliWarning("Unable to load dict arrays. Will not use them.\n");
450 if (!LoadDigitsParam()) {
451 AliWarning("Could not read digits parameter.");
455 AliWarning(Form("Create default version of digits parameter (NTimeBin=%d).\n"
456 ,AliTRDSimParam::Instance()->GetNTimeBins()));
457 fDigitsParam = new AliTRDdigitsParam();
458 fDigitsParam->SetNTimeBins(AliTRDSimParam::Instance()->GetNTimeBins());
459 fDigitsParam->SetADCbaseline(AliTRDSimParam::Instance()->GetADCbaseline());
466 //_____________________________________________________________________________
467 Bool_t AliTRDdigitsManager::WriteDigits()
470 // Writes out the TRD-digits and the dictionaries
473 if (!StoreArrayDigits())
475 AliError("Error while storing digits\n");
479 if (fUseDictionaries)
481 if (!StoreArrayDict())
483 AliError("Error while storing dictionaries in branch\n");
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
553 Int_t recoDet = fRawRec ? 0 : det;
562 ((AliTRDarrayADC *) fDigits->At(recoDet))->SetNdet(det);
563 return (AliTRDarrayADC *) fDigits->At(recoDet);
567 AliDebug(2,"ERROR IN DATA TYPE!!!!");
573 //_____________________________________________________________________________
574 AliTRDarraySignal *AliTRDdigitsManager::GetSDigits(Int_t det) const
577 // Returns the sdigits array for one detector
580 Int_t recoDet = fRawRec ? 0 : det;
584 // AliDebug(1,"NO FDIGITS!");
590 ((AliTRDarraySignal *) fDigits->At(recoDet))->SetNdet(det);
591 return (AliTRDarraySignal *) fDigits->At(recoDet);
595 AliDebug(2,"ERROR IN DATA TYPE!!!!");
601 //_____________________________________________________________________________
602 AliTRDarrayDictionary *AliTRDdigitsManager::GetDictionary(Int_t det
606 // Returns the dictionary for one detector
609 Int_t recoDet = fRawRec ? 0 : det;
611 if (fUseDictionaries == kFALSE)
616 ((AliTRDarrayDictionary *) fDigits->At(recoDet))->SetNdet(det);
617 return (AliTRDarrayDictionary *) fDict[i]->At(recoDet);
621 //_____________________________________________________________________________
622 Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit * const digit) const
625 // Returns the MC-track numbers from the dictionary for a given digit
628 Int_t row = digit->GetRow();
629 Int_t col = digit->GetCol();
630 Int_t time = digit->GetTime();
631 Int_t det = digit->GetDetector();
633 return GetTrack(track,row,col,time,det);
637 //_____________________________________________________________________________
638 AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det)
641 // Returns indexes of active pads
644 Int_t recoDet = fRawRec ? 0 : det;
646 return (AliTRDSignalIndex *) fSignalIndexes->At(recoDet);
650 //_____________________________________________________________________________
651 void AliTRDdigitsManager::RemoveDigits(Int_t det)
654 // Clear memory at det for Digits
657 Int_t recoDet = fRawRec ? 0 : det;
659 if (fDigits->At(recoDet))
663 AliTRDarraySignal *arr = (AliTRDarraySignal *) fDigits->RemoveAt(recoDet);
668 AliTRDarrayADC *arr = (AliTRDarrayADC *) fDigits->RemoveAt(recoDet);
675 //_____________________________________________________________________________
676 void AliTRDdigitsManager::RemoveDictionaries(Int_t det)
682 Int_t recoDet = fRawRec ? 0 : det;
684 if (fUseDictionaries == kFALSE)
689 for (Int_t i = 0; i < kNDict; i++)
691 if (fDict[i]->At(recoDet))
693 AliTRDarrayDictionary *arr = (AliTRDarrayDictionary *) fDict[i]->RemoveAt(recoDet);
700 //_____________________________________________________________________________
701 void AliTRDdigitsManager::RemoveIndexes(Int_t det)
707 Int_t recoDet = fRawRec ? 0 : det;
709 if (fSignalIndexes->At(recoDet))
711 AliTRDSignalIndex *arr = (AliTRDSignalIndex *) fSignalIndexes->RemoveAt(recoDet);
717 //_____________________________________________________________________________
718 void AliTRDdigitsManager::ClearIndexes(Int_t det)
724 Int_t recoDet = fRawRec ? 0 : det;
726 ((AliTRDSignalIndex *) fSignalIndexes->At(recoDet))->ClearAll();
730 //_____________________________________________________________________________
731 Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det)
734 // Build the list of indices
742 AliTRDarrayADC *digits = 0x0;
750 digits = (AliTRDarrayADC *) GetDigits(det);
753 // digits should be expanded by now!!!
754 if (digits->GetNtime() > 0)
757 nRows = digits->GetNrow();
758 nCols = digits->GetNcol();
759 nTbins = digits->GetNtime();
761 AliTRDSignalIndex *indexes = GetIndexes(det);
762 indexes->SetSM(geom.GetSector(det));
763 indexes->SetStack(geom.GetStack(det));
764 indexes->SetLayer(geom.GetLayer(det));
765 indexes->SetDetNumber(det);
767 if (indexes->IsAllocated() == kFALSE)
769 indexes->Allocate(nRows,nCols,nTbins);
772 for (Int_t ir = 0; ir < nRows; ir++)
774 for (Int_t ic = 0; ic < nCols; ic++)
776 for (Int_t it = 0; it < nTbins; it++)
778 Int_t isig = digits->GetDataBits(ir,ic,it);
781 indexes->AddIndexRC(ir,ic);
797 //_____________________________________________________________________________
798 Bool_t AliTRDdigitsManager::LoadArrayDigits()
801 // Loads the (s-)digits arrays for all detectors
806 AliError("Digits tree is not defined\n");
810 Bool_t status = kTRUE;
813 TBranch *branch = fTree->GetBranch("TRDdigits");
816 AliError("Branch TRDdigits is not defined\n");
820 // Loop through all detectors and read them from the tree
821 for (Int_t iDet = 0; iDet < fDets; iDet++)
825 AliTRDarraySignal *dataArray = (AliTRDarraySignal *) fDigits->At(iDet);
831 branch->SetAddress(&dataArray);
832 branch->GetEntry(iDet);
836 AliTRDarrayADC *dataArray = (AliTRDarrayADC *) fDigits->At(iDet);
842 branch->SetAddress(&dataArray);
843 branch->GetEntry(iDet);
851 //________________________________________________________________________________________________
852 Bool_t AliTRDdigitsManager::LoadArrayDict()
855 // Loads dictionary arrays for all detectors
860 AliError("Digits tree is not defined\n");
864 Bool_t status = kTRUE;
866 for (Int_t iDict = 0; iDict < kNDict; iDict++)
870 Char_t branchname[15];
871 sprintf(branchname,"TRDdictionary%d",iDict);
872 TBranch *branch = fTree->GetBranch(branchname);
875 AliError(Form("Branch %s is not defined\n",branchname));
879 // Loop through all detectors and read them from the tree
880 for (Int_t iDet = 0; iDet < fDets; iDet++)
882 AliTRDarrayDictionary *dataArray = (AliTRDarrayDictionary *) fDict[iDict]->At(iDet);
888 branch->SetAddress(&dataArray);
889 branch->GetEntry(iDet);
898 //_____________________________________________________________________________
899 Bool_t AliTRDdigitsManager::LoadDigitsParam()
902 // Loads the digits parameter object from the digits tree
907 AliError("Digits tree is not defined\n");
912 TBranch *branch = fTree->GetBranch("TRDdigitsParam");
915 AliError("Branch TRDdigitsParam is not defined\n");
919 // Read the parameter object
920 AliTRDdigitsParam *digitsParam = fDigitsParam;
926 branch->SetAddress(&digitsParam);
933 //_____________________________________________________________________________
934 Bool_t AliTRDdigitsManager::StoreArrayDigits()
937 // Stores the digit arrays for all detectors
942 AliError("Digits tree is not defined\n");
947 TBranch *branch = fTree->GetBranch("TRDdigits");
950 AliError("Branch TRDdigits is not defined\n");
954 // Loop through all detectors and fill them into the tree
955 Bool_t status = kTRUE;
956 for (Int_t iDet = 0; iDet < fDets; iDet++)
960 const AliTRDarraySignal *kDataArray = (AliTRDarraySignal *) fDigits->At(iDet);
966 branch->SetAddress(&kDataArray);
971 const AliTRDarrayADC *kDataArray = (AliTRDarrayADC *) fDigits->At(iDet);
977 branch->SetAddress(&kDataArray);
986 //_____________________________________________________________________________
987 Bool_t AliTRDdigitsManager::StoreArrayDict()
990 // Stores the dictionary arrays for all detectors
995 AliError("Digits tree is not defined\n");
999 Bool_t status = kTRUE;
1001 for (Int_t iDict = 0; iDict < kNDict; iDict++)
1005 Char_t branchname[15];
1006 sprintf(branchname,"TRDdictionary%d",iDict);
1007 TBranch *branch = fTree->GetBranch(branchname);
1010 AliError(Form("Branch %s is not defined\n",branchname));
1014 // Loop through all detectors and fill them into the tree
1015 for (Int_t iDet = 0; iDet < fDets; iDet++)
1017 const AliTRDarrayDictionary *kDataArray = (AliTRDarrayDictionary *) fDict[iDict]->At(iDet);
1023 branch->SetAddress(&kDataArray);
1033 //_____________________________________________________________________________
1034 Bool_t AliTRDdigitsManager::StoreDigitsParam()
1037 // Stores the digits parameter object from the digits tree
1042 AliError("Digits tree is not defined\n");
1047 TBranch *branch = fTree->GetBranch("TRDdigitsParam");
1050 AliError("Branch TRDdigitsParam is not defined\n");
1054 // Fill the digits object in the tree
1055 const AliTRDdigitsParam *kDigitsParam = fDigitsParam;
1060 branch->SetAddress(&kDigitsParam);