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();
245 //_____________________________________________________________________________
246 void AliTRDdigitsManager::ClearArrays(Int_t det)
249 // Reset the data arrays
252 Int_t recoDet = fRawRec ? 0 : det;
256 ((AliTRDarraySignal*)fDigits->At(recoDet))->Reset();
260 ((AliTRDarrayADC*)fDigits->At(recoDet))->ConditionalReset((AliTRDSignalIndex*)fSignalIndexes->At(recoDet));
263 if (fUseDictionaries)
265 for (Int_t iDict = 0; iDict < kNDict; iDict++)
267 ((AliTRDarrayDictionary*)fDict[iDict]->At(recoDet))->Reset();
271 ((AliTRDSignalIndex*)fSignalIndexes->At(recoDet))->ResetContent();
275 //_____________________________________________________________________________
276 Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time, Int_t det) const
279 // Returns the amplitude of a digit
282 if (!GetDigits(det)) return 0;
284 return ((Short_t) ((AliTRDarrayADC *) GetDigits(det))->GetDataBits(row,col,time));
288 //_____________________________________________________________________________
289 UChar_t AliTRDdigitsManager::GetPadStatus(Int_t row, Int_t col, Int_t time, Int_t det) const
292 // Returns the pad status for the requested pad
295 if (!GetDigits(det)) return 0;
297 return ((UChar_t) ((AliTRDarrayADC *) GetDigits(det))->GetPadStatus(row,col,time));
301 //_____________________________________________________________________________
302 Bool_t AliTRDdigitsManager::MakeBranch(TTree * const tree)
305 // Creates the tree and branches for the digits and the dictionary
308 Int_t buffersize = 64000;
309 Bool_t status = kTRUE;
316 // Make the branch for the digits
321 const AliTRDarraySignal *kDigits = (AliTRDarraySignal *) fDigits->At(0);
324 if (!fTree) return kFALSE;
325 AliDebug(1,"Making branch for SDigits!\n");
326 TBranch *branch = fTree->GetBranch("TRDdigits");
329 fTree->Branch("TRDdigits","AliTRDarraySignal",&kDigits,buffersize,99);
331 AliDebug(1,"Making branch TRDdigits\n");
341 const AliTRDarrayADC *kDigits = (AliTRDarrayADC *) fDigits->At(0);
344 if (!fTree) return kFALSE;
345 AliDebug(1,"Making branch for Digits!\n");
346 TBranch *branch = fTree->GetBranch("TRDdigits");
349 fTree->Branch("TRDdigits","AliTRDarrayADC",&kDigits,buffersize,99);
351 AliDebug(1,"Making branch TRDdigits\n");
367 if (fUseDictionaries)
369 // Make the branches for the dictionaries
370 for (Int_t iDict = 0; iDict < kNDict; iDict++)
372 Char_t branchname[15];
373 sprintf(branchname,"TRDdictionary%d",iDict);
376 const AliTRDarrayDictionary *kDictionary = (AliTRDarrayDictionary *) fDict[iDict]->At(0);
379 if (!fTree) return kFALSE;
380 AliDebug(2,"Making branch for dictionary!\n");
381 TBranch *branch = fTree->GetBranch(branchname);
384 fTree->Branch(branchname,"AliTRDarrayDictionary",&kDictionary,buffersize,99);
386 AliDebug(1,Form("Making branch %s\n",branchname));
402 const AliTRDdigitsParam *kDigitsParam = fDigitsParam;
403 if (!fTree) return kFALSE;
404 TBranch *branch = fTree->GetBranch("TRDdigitsParam");
407 fTree->Branch("TRDdigitsParam","AliTRDdigitsParam",&kDigitsParam,buffersize,99);
409 AliDebug(1,"Making branch AliTRDdigitsParam\n");
416 //_____________________________________________________________________________
417 Bool_t AliTRDdigitsManager::ReadDigits(TTree * const tree)
420 // Reads the digit information from the input file
423 Bool_t status = kTRUE;
432 AliDebug(1,"Create the data arrays.\n");
436 status = LoadArrayDigits();
438 if (fUseDictionaries)
440 status = LoadArrayDict();
441 if (status == kFALSE)
443 fUseDictionaries = kFALSE;
444 AliWarning("Unable to load dict arrays. Will not use them.\n");
448 if (!LoadDigitsParam()) {
449 AliWarning("Could not read digits parameter.");
453 AliWarning(Form("Create default version of digits parameter (NTimeBin=%d).\n"
454 ,AliTRDSimParam::Instance()->GetNTimeBins()));
455 fDigitsParam = new AliTRDdigitsParam();
456 fDigitsParam->SetNTimeBinsAll(AliTRDSimParam::Instance()->GetNTimeBins());
457 fDigitsParam->SetADCbaselineAll(AliTRDSimParam::Instance()->GetADCbaseline());
464 //_____________________________________________________________________________
465 Bool_t AliTRDdigitsManager::WriteDigits()
468 // Writes out the TRD-digits, the dictionaries and the digitsPaam
471 if (!StoreArrayDigits())
473 AliError("Error while storing digits\n");
477 if (fUseDictionaries)
479 if (!StoreArrayDict())
481 AliError("Error while storing dictionaries in branch\n");
486 if (!StoreDigitsParam())
488 AliError("Error while storing digitsParam\n");
492 // Write the new tree to the output file
499 //_____________________________________________________________________________
500 AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row
506 // Creates a single digit object
517 amp[0] = ((AliTRDarrayADC *) GetDigits(det))->GetData(row,col,time);
519 return (new AliTRDdigit(digits,amp));
523 //_____________________________________________________________________________
524 Int_t AliTRDdigitsManager::GetTrack(Int_t track
531 // Returns the MC-track numbers from the dictionary.
534 if ((track < 0) || (track >= kNDict))
536 AliError(Form("track %d out of bounds (size: %d, this: 0x%08x)",track,kNDict,this));
540 if (fUseDictionaries == kFALSE)
545 // Array contains index+1 to allow data compression--->Changed
546 return (((AliTRDarrayDictionary *) GetDictionary(det,track))->GetData(row,col,time) );
550 //________________________________________________________________________________
551 AliTRDarrayADC *AliTRDdigitsManager::GetDigits(Int_t det) const
554 // Returns the digits array for one detector
557 Int_t recoDet = fRawRec ? 0 : det;
566 ((AliTRDarrayADC *) fDigits->At(recoDet))->SetNdet(det);
567 return (AliTRDarrayADC *) fDigits->At(recoDet);
571 AliDebug(2,"ERROR IN DATA TYPE!!!!");
577 //_____________________________________________________________________________
578 AliTRDarraySignal *AliTRDdigitsManager::GetSDigits(Int_t det) const
581 // Returns the sdigits array for one detector
584 Int_t recoDet = fRawRec ? 0 : det;
588 // AliDebug(1,"NO FDIGITS!");
594 ((AliTRDarraySignal *) fDigits->At(recoDet))->SetNdet(det);
595 return (AliTRDarraySignal *) fDigits->At(recoDet);
599 AliDebug(2,"ERROR IN DATA TYPE!!!!");
605 //_____________________________________________________________________________
606 AliTRDarrayDictionary *AliTRDdigitsManager::GetDictionary(Int_t det
610 // Returns the dictionary for one detector
613 Int_t recoDet = fRawRec ? 0 : det;
615 if (fUseDictionaries == kFALSE)
620 ((AliTRDarrayDictionary *) fDigits->At(recoDet))->SetNdet(det);
621 return (AliTRDarrayDictionary *) fDict[i]->At(recoDet);
625 //_____________________________________________________________________________
626 Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit * const digit) const
629 // Returns the MC-track numbers from the dictionary for a given digit
632 Int_t row = digit->GetRow();
633 Int_t col = digit->GetCol();
634 Int_t time = digit->GetTime();
635 Int_t det = digit->GetDetector();
637 return GetTrack(track,row,col,time,det);
641 //_____________________________________________________________________________
642 AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det)
645 // Returns indexes of active pads
648 Int_t recoDet = fRawRec ? 0 : det;
650 return (AliTRDSignalIndex *) fSignalIndexes->At(recoDet);
654 //_____________________________________________________________________________
655 void AliTRDdigitsManager::RemoveDigits(Int_t det)
658 // Clear memory at det for Digits
661 Int_t recoDet = fRawRec ? 0 : det;
663 if (fDigits->At(recoDet))
667 AliTRDarraySignal *arr = (AliTRDarraySignal *) fDigits->RemoveAt(recoDet);
672 AliTRDarrayADC *arr = (AliTRDarrayADC *) fDigits->RemoveAt(recoDet);
679 //_____________________________________________________________________________
680 void AliTRDdigitsManager::RemoveDictionaries(Int_t det)
686 Int_t recoDet = fRawRec ? 0 : det;
688 if (fUseDictionaries == kFALSE)
693 for (Int_t i = 0; i < kNDict; i++)
695 if (fDict[i]->At(recoDet))
697 AliTRDarrayDictionary *arr = (AliTRDarrayDictionary *) fDict[i]->RemoveAt(recoDet);
704 //_____________________________________________________________________________
705 void AliTRDdigitsManager::RemoveIndexes(Int_t det)
711 Int_t recoDet = fRawRec ? 0 : det;
713 if (fSignalIndexes->At(recoDet))
715 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::LoadArrayDigits()
805 // Loads the (s-)digits arrays for all detectors
810 AliError("Digits tree is not defined\n");
814 Bool_t status = kTRUE;
817 TBranch *branch = fTree->GetBranch("TRDdigits");
820 AliError("Branch TRDdigits is not defined\n");
824 // Loop through all detectors and read them from the tree
825 for (Int_t iDet = 0; iDet < fDets; iDet++)
829 AliTRDarraySignal *dataArray = (AliTRDarraySignal *) fDigits->At(iDet);
835 branch->SetAddress(&dataArray);
836 branch->GetEntry(iDet);
840 AliTRDarrayADC *dataArray = (AliTRDarrayADC *) fDigits->At(iDet);
846 branch->SetAddress(&dataArray);
847 branch->GetEntry(iDet);
855 //________________________________________________________________________________________________
856 Bool_t AliTRDdigitsManager::LoadArrayDict()
859 // Loads dictionary arrays for all detectors
864 AliError("Digits tree is not defined\n");
868 Bool_t status = kTRUE;
870 for (Int_t iDict = 0; iDict < kNDict; iDict++)
874 Char_t branchname[15];
875 sprintf(branchname,"TRDdictionary%d",iDict);
876 TBranch *branch = fTree->GetBranch(branchname);
879 AliError(Form("Branch %s is not defined\n",branchname));
883 // Loop through all detectors and read them from the tree
884 for (Int_t iDet = 0; iDet < fDets; iDet++)
886 AliTRDarrayDictionary *dataArray = (AliTRDarrayDictionary *) fDict[iDict]->At(iDet);
892 branch->SetAddress(&dataArray);
893 branch->GetEntry(iDet);
902 //_____________________________________________________________________________
903 Bool_t AliTRDdigitsManager::LoadDigitsParam()
906 // Loads the digits parameter object from the digits tree
911 AliError("Digits tree is not defined\n");
916 TBranch *branch = fTree->GetBranch("TRDdigitsParam");
919 AliError("Branch TRDdigitsParam is not defined\n");
923 // Read the parameter object
924 AliTRDdigitsParam *digitsParam = fDigitsParam;
930 branch->SetAddress(&digitsParam);
937 //_____________________________________________________________________________
938 Bool_t AliTRDdigitsManager::StoreArrayDigits()
941 // Stores the digit arrays for all detectors
946 AliError("Digits tree is not defined\n");
951 TBranch *branch = fTree->GetBranch("TRDdigits");
954 AliError("Branch TRDdigits is not defined\n");
958 // Loop through all detectors and fill them into the tree
959 Bool_t status = kTRUE;
960 for (Int_t iDet = 0; iDet < fDets; iDet++)
964 const AliTRDarraySignal *kDataArray = (AliTRDarraySignal *) fDigits->At(iDet);
970 branch->SetAddress(&kDataArray);
975 const AliTRDarrayADC *kDataArray = (AliTRDarrayADC *) fDigits->At(iDet);
981 branch->SetAddress(&kDataArray);
990 //_____________________________________________________________________________
991 Bool_t AliTRDdigitsManager::StoreArrayDict()
994 // Stores the dictionary arrays for all detectors
999 AliError("Digits tree is not defined\n");
1003 Bool_t status = kTRUE;
1005 for (Int_t iDict = 0; iDict < kNDict; iDict++)
1009 Char_t branchname[15];
1010 sprintf(branchname,"TRDdictionary%d",iDict);
1011 TBranch *branch = fTree->GetBranch(branchname);
1014 AliError(Form("Branch %s is not defined\n",branchname));
1018 // Loop through all detectors and fill them into the tree
1019 for (Int_t iDet = 0; iDet < fDets; iDet++)
1021 const AliTRDarrayDictionary *kDataArray = (AliTRDarrayDictionary *) fDict[iDict]->At(iDet);
1027 branch->SetAddress(&kDataArray);
1037 //_____________________________________________________________________________
1038 Bool_t AliTRDdigitsManager::StoreDigitsParam()
1041 // Stores the digits parameter object from the digits tree
1046 AliError("Digits tree is not defined\n");
1051 TBranch *branch = fTree->GetBranch("TRDdigitsParam");
1054 AliError("Branch TRDdigitsParam is not defined\n");
1058 // Fill the digits object in the tree
1059 const AliTRDdigitsParam *kDigitsParam = fDigitsParam;
1064 branch->SetAddress(&kDigitsParam);