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
93 for (Int_t iDict = 0; iDict < kNDict; iDict++)
100 //_____________________________________________________________________________
101 AliTRDdigitsManager::~AliTRDdigitsManager()
104 // AliTRDdigitsManager destructor
115 for (Int_t iDict = 0; iDict < kNDict; iDict++)
119 fDict[iDict]->Delete();
127 fSignalIndexes->Delete();
128 delete fSignalIndexes;
129 fSignalIndexes = NULL;
140 //_____________________________________________________________________________
141 AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
144 // Assignment operator
149 ((AliTRDdigitsManager &) m).Copy(*this);
156 //_____________________________________________________________________________
157 void AliTRDdigitsManager::Copy(TObject &m) const
163 ((AliTRDdigitsManager &) m).fEvent = fEvent;
164 ((AliTRDdigitsManager &) m).fHasSDigits = fHasSDigits;
165 ((AliTRDdigitsManager &) m).fDigits = NULL;
166 for(Int_t i = 0; i < kNDict; i++)
168 ((AliTRDdigitsManager &) m).fDict[i] = NULL;
170 ((AliTRDdigitsManager &) m).fSignalIndexes = NULL;
171 ((AliTRDdigitsManager &) m).fUseDictionaries = fUseDictionaries;
172 ((AliTRDdigitsManager &) m).fDets = fDets;
173 ((AliTRDdigitsManager &) m).fRawRec = fRawRec;
174 ((AliTRDdigitsManager &) m).fDigitsParam = NULL;
180 //_____________________________________________________________________________
181 void AliTRDdigitsManager::CreateArrays()
184 // Create the data arrays
194 fDigits = new TObjArray(fDets);
195 for (Int_t index = 0; index < fDets; index++)
197 fDigits->AddAt(new AliTRDarraySignal(),index);
207 fDigits = new TObjArray(fDets);
208 for (Int_t index = 0; index < fDets; index++)
210 fDigits->AddAt(new AliTRDarrayADC(),index);
214 if (fUseDictionaries)
216 for (Int_t iDict = 0; iDict < kNDict; iDict++)
220 fDict[iDict]->Delete();
223 fDict[iDict] = new TObjArray(fDets);
224 for (Int_t index = 0; index < fDets; index++)
226 fDict[iDict]->AddAt(new AliTRDarrayDictionary(),index);
233 fSignalIndexes->Delete();
234 delete fSignalIndexes;
236 fSignalIndexes = new TObjArray(fDets);
237 for (Int_t i = 0; i < fDets; i++)
239 fSignalIndexes->AddLast(new AliTRDSignalIndex());
246 fDigitsParam = new AliTRDdigitsParam();
250 //_____________________________________________________________________________
251 void AliTRDdigitsManager::ClearArrays(Int_t det)
254 // Reset the data arrays
257 Int_t recoDet = fRawRec ? 0 : det;
261 ((AliTRDarraySignal*)fDigits->At(recoDet))->Reset();
265 ((AliTRDarrayADC*)fDigits->At(recoDet))->ConditionalReset((AliTRDSignalIndex*)fSignalIndexes->At(recoDet));
268 if (fUseDictionaries)
270 for (Int_t iDict = 0; iDict < kNDict; iDict++)
272 ((AliTRDarrayDictionary*)fDict[iDict]->At(recoDet))->Reset();
276 ((AliTRDSignalIndex*)fSignalIndexes->At(recoDet))->ResetContent();
280 //_____________________________________________________________________________
281 Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time, Int_t det) const
284 // Returns the amplitude of a digit
287 if (!GetDigits(det)) return 0;
289 return ((Short_t) ((AliTRDarrayADC *) GetDigits(det))->GetDataBits(row,col,time));
293 //_____________________________________________________________________________
294 UChar_t AliTRDdigitsManager::GetPadStatus(Int_t row, Int_t col, Int_t time, Int_t det) const
297 // Returns the pad status for the requested pad
300 if (!GetDigits(det)) return 0;
302 return ((UChar_t) ((AliTRDarrayADC *) GetDigits(det))->GetPadStatus(row,col,time));
306 //_____________________________________________________________________________
307 Bool_t AliTRDdigitsManager::MakeBranch(TTree * const tree)
310 // Creates the tree and branches for the digits and the dictionary
313 Int_t buffersize = 64000;
314 Bool_t status = kTRUE;
321 // Make the branch for the digits
326 const AliTRDarraySignal *kDigits = (AliTRDarraySignal *) fDigits->At(0);
329 if (!fTree) return kFALSE;
330 AliDebug(1,"Making branch for SDigits!\n");
331 TBranch *branch = fTree->GetBranch("TRDdigits");
334 fTree->Branch("TRDdigits","AliTRDarraySignal",&kDigits,buffersize,99);
336 AliDebug(1,"Making branch TRDdigits\n");
346 const AliTRDarrayADC *kDigits = (AliTRDarrayADC *) fDigits->At(0);
349 if (!fTree) return kFALSE;
350 AliDebug(1,"Making branch for Digits!\n");
351 TBranch *branch = fTree->GetBranch("TRDdigits");
354 fTree->Branch("TRDdigits","AliTRDarrayADC",&kDigits,buffersize,99);
356 AliDebug(1,"Making branch TRDdigits\n");
372 if (fUseDictionaries)
374 // Make the branches for the dictionaries
375 for (Int_t iDict = 0; iDict < kNDict; iDict++)
377 Char_t branchname[15];
378 sprintf(branchname,"TRDdictionary%d",iDict);
381 const AliTRDarrayDictionary *kDictionary = (AliTRDarrayDictionary *) fDict[iDict]->At(0);
384 if (!fTree) return kFALSE;
385 AliDebug(2,"Making branch for dictionary!\n");
386 TBranch *branch = fTree->GetBranch(branchname);
389 fTree->Branch(branchname,"AliTRDarrayDictionary",&kDictionary,buffersize,99);
391 AliDebug(1,Form("Making branch %s\n",branchname));
407 const AliTRDdigitsParam *kDigitsParam = fDigitsParam;
408 if (!fTree) return kFALSE;
409 TBranch *branch = fTree->GetBranch("TRDdigitsParam");
412 fTree->Branch("TRDdigitsParam","AliTRDdigitsParam",&kDigitsParam,buffersize,99);
414 AliDebug(1,"Making branch AliTRDdigitsParam\n");
421 //_____________________________________________________________________________
422 Bool_t AliTRDdigitsManager::ReadDigits(TTree * const tree)
425 // Reads the digit information from the input file
428 Bool_t status = kTRUE;
437 AliDebug(1,"Create the data arrays.\n");
441 status = LoadArrayDigits();
443 if (fUseDictionaries)
445 status = LoadArrayDict();
446 if (status == kFALSE)
448 fUseDictionaries = kFALSE;
449 AliWarning("Unable to load dict arrays. Will not use them.\n");
453 if (!LoadDigitsParam()) {
454 AliWarning("Could not read digits parameter.");
458 AliWarning(Form("Create default version of digits parameter (NTimeBin=%d).\n"
459 ,AliTRDSimParam::Instance()->GetNTimeBins()));
460 fDigitsParam = new AliTRDdigitsParam();
461 fDigitsParam->SetNTimeBinsAll(AliTRDSimParam::Instance()->GetNTimeBins());
462 fDigitsParam->SetADCbaselineAll(AliTRDSimParam::Instance()->GetADCbaseline());
469 //_____________________________________________________________________________
470 Bool_t AliTRDdigitsManager::WriteDigits()
473 // Writes out the TRD-digits, the dictionaries and the digitsPaam
476 if (!StoreArrayDigits())
478 AliError("Error while storing digits\n");
482 if (fUseDictionaries)
484 if (!StoreArrayDict())
486 AliError("Error while storing dictionaries in branch\n");
491 if (!StoreDigitsParam())
493 AliError("Error while storing digitsParam\n");
497 // Write the new tree to the output file
504 //_____________________________________________________________________________
505 AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row
511 // Creates a single digit object
522 amp[0] = ((AliTRDarrayADC *) GetDigits(det))->GetData(row,col,time);
524 return (new AliTRDdigit(digits,amp));
528 //_____________________________________________________________________________
529 Int_t AliTRDdigitsManager::GetTrack(Int_t track
536 // Returns the MC-track numbers from the dictionary.
539 if ((track < 0) || (track >= kNDict))
541 AliError(Form("track %d out of bounds (size: %d, this: 0x%p)",track,kNDict,this));
545 if (fUseDictionaries == kFALSE)
550 // Array contains index+1 to allow data compression--->Changed
551 return (((AliTRDarrayDictionary *) GetDictionary(det,track))->GetData(row,col,time) );
555 //________________________________________________________________________________
556 AliTRDarrayADC *AliTRDdigitsManager::GetDigits(Int_t det) const
559 // Returns the digits array for one detector
562 Int_t recoDet = fRawRec ? 0 : det;
571 ((AliTRDarrayADC *) fDigits->At(recoDet))->SetNdet(det);
572 return (AliTRDarrayADC *) fDigits->At(recoDet);
576 AliDebug(2,"ERROR IN DATA TYPE!!!!");
582 //_____________________________________________________________________________
583 AliTRDarraySignal *AliTRDdigitsManager::GetSDigits(Int_t det) const
586 // Returns the sdigits array for one detector
589 Int_t recoDet = fRawRec ? 0 : det;
593 // AliDebug(1,"NO FDIGITS!");
599 ((AliTRDarraySignal *) fDigits->At(recoDet))->SetNdet(det);
600 return (AliTRDarraySignal *) fDigits->At(recoDet);
604 AliDebug(2,"ERROR IN DATA TYPE!!!!");
610 //_____________________________________________________________________________
611 AliTRDarrayDictionary *AliTRDdigitsManager::GetDictionary(Int_t det
615 // Returns the dictionary for one detector
618 Int_t recoDet = fRawRec ? 0 : det;
620 if (fUseDictionaries == kFALSE)
625 ((AliTRDarrayDictionary *) fDigits->At(recoDet))->SetNdet(det);
626 return (AliTRDarrayDictionary *) fDict[i]->At(recoDet);
630 //_____________________________________________________________________________
631 Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit * const digit) const
634 // Returns the MC-track numbers from the dictionary for a given digit
637 Int_t row = digit->GetRow();
638 Int_t col = digit->GetCol();
639 Int_t time = digit->GetTime();
640 Int_t det = digit->GetDetector();
642 return GetTrack(track,row,col,time,det);
646 //_____________________________________________________________________________
647 AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det)
650 // Returns indexes of active pads
653 Int_t recoDet = fRawRec ? 0 : det;
655 return (AliTRDSignalIndex *) fSignalIndexes->At(recoDet);
659 //_____________________________________________________________________________
660 void AliTRDdigitsManager::RemoveDigits(Int_t det)
663 // Clear memory at det for Digits
666 Int_t recoDet = fRawRec ? 0 : det;
668 if (fDigits->At(recoDet))
672 AliTRDarraySignal *arr = (AliTRDarraySignal *) fDigits->RemoveAt(recoDet);
677 AliTRDarrayADC *arr = (AliTRDarrayADC *) fDigits->RemoveAt(recoDet);
684 //_____________________________________________________________________________
685 void AliTRDdigitsManager::RemoveDictionaries(Int_t det)
691 Int_t recoDet = fRawRec ? 0 : det;
693 if (fUseDictionaries == kFALSE)
698 for (Int_t i = 0; i < kNDict; i++)
700 if (fDict[i]->At(recoDet))
702 AliTRDarrayDictionary *arr = (AliTRDarrayDictionary *) fDict[i]->RemoveAt(recoDet);
709 //_____________________________________________________________________________
710 void AliTRDdigitsManager::RemoveIndexes(Int_t det)
716 Int_t recoDet = fRawRec ? 0 : det;
718 if (fSignalIndexes->At(recoDet))
720 AliTRDSignalIndex *arr = (AliTRDSignalIndex *) fSignalIndexes->RemoveAt(recoDet);
726 //_____________________________________________________________________________
727 void AliTRDdigitsManager::ClearIndexes(Int_t det)
733 Int_t recoDet = fRawRec ? 0 : det;
735 ((AliTRDSignalIndex *) fSignalIndexes->At(recoDet))->ClearAll();
739 //_____________________________________________________________________________
740 Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det)
743 // Build the list of indices
751 AliTRDarrayADC *digits = 0x0;
759 digits = (AliTRDarrayADC *) GetDigits(det);
762 // digits should be expanded by now!!!
763 if (digits->GetNtime() > 0)
766 nRows = digits->GetNrow();
767 nCols = digits->GetNcol();
768 nTbins = digits->GetNtime();
770 AliTRDSignalIndex *indexes = GetIndexes(det);
771 indexes->SetSM(geom.GetSector(det));
772 indexes->SetStack(geom.GetStack(det));
773 indexes->SetLayer(geom.GetLayer(det));
774 indexes->SetDetNumber(det);
776 if (indexes->IsAllocated() == kFALSE)
778 indexes->Allocate(nRows,nCols,nTbins);
781 for (Int_t ir = 0; ir < nRows; ir++)
783 for (Int_t ic = 0; ic < nCols; ic++)
785 for (Int_t it = 0; it < nTbins; it++)
787 Int_t isig = digits->GetDataBits(ir,ic,it);
790 indexes->AddIndexRC(ir,ic);
806 //_____________________________________________________________________________
807 Bool_t AliTRDdigitsManager::LoadArrayDigits()
810 // Loads the (s-)digits arrays for all detectors
815 AliError("Digits tree is not defined\n");
819 Bool_t status = kTRUE;
822 TBranch *branch = fTree->GetBranch("TRDdigits");
825 AliError("Branch TRDdigits is not defined\n");
829 // Loop through all detectors and read them from the tree
830 for (Int_t iDet = 0; iDet < fDets; iDet++)
834 AliTRDarraySignal *dataArray = (AliTRDarraySignal *) fDigits->At(iDet);
840 branch->SetAddress(&dataArray);
841 branch->GetEntry(iDet);
845 AliTRDarrayADC *dataArray = (AliTRDarrayADC *) fDigits->At(iDet);
851 branch->SetAddress(&dataArray);
852 branch->GetEntry(iDet);
860 //________________________________________________________________________________________________
861 Bool_t AliTRDdigitsManager::LoadArrayDict()
864 // Loads dictionary arrays for all detectors
869 AliError("Digits tree is not defined\n");
873 Bool_t status = kTRUE;
875 for (Int_t iDict = 0; iDict < kNDict; iDict++)
879 Char_t branchname[15];
880 sprintf(branchname,"TRDdictionary%d",iDict);
881 TBranch *branch = fTree->GetBranch(branchname);
884 AliError(Form("Branch %s is not defined\n",branchname));
888 // Loop through all detectors and read them from the tree
889 for (Int_t iDet = 0; iDet < fDets; iDet++)
891 AliTRDarrayDictionary *dataArray = (AliTRDarrayDictionary *) fDict[iDict]->At(iDet);
897 branch->SetAddress(&dataArray);
898 branch->GetEntry(iDet);
907 //_____________________________________________________________________________
908 Bool_t AliTRDdigitsManager::LoadDigitsParam()
911 // Loads the digits parameter object from the digits tree
916 AliError("Digits tree is not defined\n");
921 TBranch *branch = fTree->GetBranch("TRDdigitsParam");
924 AliError("Branch TRDdigitsParam is not defined\n");
928 // Read the parameter object
929 AliTRDdigitsParam *digitsParam = fDigitsParam;
935 branch->SetAddress(&digitsParam);
942 //_____________________________________________________________________________
943 Bool_t AliTRDdigitsManager::StoreArrayDigits()
946 // Stores the digit arrays for all detectors
951 AliError("Digits tree is not defined\n");
956 TBranch *branch = fTree->GetBranch("TRDdigits");
959 AliError("Branch TRDdigits is not defined\n");
963 // Loop through all detectors and fill them into the tree
964 Bool_t status = kTRUE;
965 for (Int_t iDet = 0; iDet < fDets; iDet++)
969 const AliTRDarraySignal *kDataArray = (AliTRDarraySignal *) fDigits->At(iDet);
975 branch->SetAddress(&kDataArray);
980 const AliTRDarrayADC *kDataArray = (AliTRDarrayADC *) fDigits->At(iDet);
986 branch->SetAddress(&kDataArray);
995 //_____________________________________________________________________________
996 Bool_t AliTRDdigitsManager::StoreArrayDict()
999 // Stores the dictionary arrays for all detectors
1004 AliError("Digits tree is not defined\n");
1008 Bool_t status = kTRUE;
1010 for (Int_t iDict = 0; iDict < kNDict; iDict++)
1014 Char_t branchname[15];
1015 sprintf(branchname,"TRDdictionary%d",iDict);
1016 TBranch *branch = fTree->GetBranch(branchname);
1019 AliError(Form("Branch %s is not defined\n",branchname));
1023 // Loop through all detectors and fill them into the tree
1024 for (Int_t iDet = 0; iDet < fDets; iDet++)
1026 const AliTRDarrayDictionary *kDataArray = (AliTRDarrayDictionary *) fDict[iDict]->At(iDet);
1032 branch->SetAddress(&kDataArray);
1042 //_____________________________________________________________________________
1043 Bool_t AliTRDdigitsManager::StoreDigitsParam()
1046 // Stores the digits parameter object from the digits tree
1051 AliError("Digits tree is not defined\n");
1056 TBranch *branch = fTree->GetBranch("TRDdigitsParam");
1059 AliError("Branch TRDdigitsParam is not defined\n");
1063 // Fill the digits object in the tree
1064 const AliTRDdigitsParam *kDigitsParam = fDigitsParam;
1069 branch->SetAddress(&kDigitsParam);