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 const Int_t kBranchname = 15;
378 Char_t branchname[kBranchname];
379 snprintf(branchname,kBranchname,"TRDdictionary%d",iDict);
382 const AliTRDarrayDictionary *kDictionary = (AliTRDarrayDictionary *) fDict[iDict]->At(0);
385 if (!fTree) return kFALSE;
386 AliDebug(2,"Making branch for dictionary!\n");
387 TBranch *branch = fTree->GetBranch(branchname);
390 fTree->Branch(branchname,"AliTRDarrayDictionary",&kDictionary,buffersize,99);
392 AliDebug(1,Form("Making branch %s\n",branchname));
408 const AliTRDdigitsParam *kDigitsParam = fDigitsParam;
409 if (!fTree) return kFALSE;
410 TBranch *branch = fTree->GetBranch("TRDdigitsParam");
413 fTree->Branch("TRDdigitsParam","AliTRDdigitsParam",&kDigitsParam,buffersize,99);
415 AliDebug(1,"Making branch AliTRDdigitsParam\n");
422 //_____________________________________________________________________________
423 Bool_t AliTRDdigitsManager::ReadDigits(TTree * const tree)
426 // Reads the digit information from the input file
429 Bool_t status = kTRUE;
438 AliDebug(1,"Create the data arrays.\n");
442 status = LoadArrayDigits();
444 if (fUseDictionaries)
446 status = LoadArrayDict();
447 if (status == kFALSE)
449 fUseDictionaries = kFALSE;
450 AliWarning("Unable to load dict arrays. Will not use them.\n");
454 if (!LoadDigitsParam()) {
455 AliWarning("Could not read digits parameter.");
459 AliWarning(Form("Create default version of digits parameter (NTimeBin=%d).\n"
460 ,AliTRDSimParam::Instance()->GetNTimeBins()));
461 fDigitsParam = new AliTRDdigitsParam();
462 fDigitsParam->SetNTimeBinsAll(AliTRDSimParam::Instance()->GetNTimeBins());
463 fDigitsParam->SetADCbaselineAll(AliTRDSimParam::Instance()->GetADCbaseline());
470 //_____________________________________________________________________________
471 Bool_t AliTRDdigitsManager::WriteDigits()
474 // Writes out the TRD-digits, the dictionaries and the digitsPaam
477 if (!StoreArrayDigits())
479 AliError("Error while storing digits\n");
483 if (fUseDictionaries)
485 if (!StoreArrayDict())
487 AliError("Error while storing dictionaries in branch\n");
492 if (!StoreDigitsParam())
494 AliError("Error while storing digitsParam\n");
498 // Write the new tree to the output file
505 //_____________________________________________________________________________
506 AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row
512 // Creates a single digit object
523 amp[0] = ((AliTRDarrayADC *) GetDigits(det))->GetData(row,col,time);
525 return (new AliTRDdigit(digits,amp));
529 //_____________________________________________________________________________
530 Int_t AliTRDdigitsManager::GetTrack(Int_t track
537 // Returns the MC-track numbers from the dictionary.
540 if ((track < 0) || (track >= kNDict))
542 AliError(Form("track %d out of bounds (size: %d, this: 0x%p)",track,kNDict,this));
546 if (fUseDictionaries == kFALSE)
551 // Array contains index+1 to allow data compression--->Changed
552 return (((AliTRDarrayDictionary *) GetDictionary(det,track))->GetData(row,col,time) );
556 //________________________________________________________________________________
557 AliTRDarrayADC *AliTRDdigitsManager::GetDigits(Int_t det) const
560 // Returns the digits array for one detector
563 Int_t recoDet = fRawRec ? 0 : det;
572 ((AliTRDarrayADC *) fDigits->At(recoDet))->SetNdet(det);
573 return (AliTRDarrayADC *) fDigits->At(recoDet);
577 AliDebug(2,"ERROR IN DATA TYPE!!!!");
583 //_____________________________________________________________________________
584 AliTRDarraySignal *AliTRDdigitsManager::GetSDigits(Int_t det) const
587 // Returns the sdigits array for one detector
590 Int_t recoDet = fRawRec ? 0 : det;
594 // AliDebug(1,"NO FDIGITS!");
600 ((AliTRDarraySignal *) fDigits->At(recoDet))->SetNdet(det);
601 return (AliTRDarraySignal *) fDigits->At(recoDet);
605 AliDebug(2,"ERROR IN DATA TYPE!!!!");
611 //_____________________________________________________________________________
612 AliTRDarrayDictionary *AliTRDdigitsManager::GetDictionary(Int_t det
616 // Returns the dictionary for one detector
619 Int_t recoDet = fRawRec ? 0 : det;
621 if (fUseDictionaries == kFALSE)
626 ((AliTRDarrayDictionary *) fDigits->At(recoDet))->SetNdet(det);
627 return (AliTRDarrayDictionary *) fDict[i]->At(recoDet);
631 //_____________________________________________________________________________
632 Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit * const digit) const
635 // Returns the MC-track numbers from the dictionary for a given digit
638 Int_t row = digit->GetRow();
639 Int_t col = digit->GetCol();
640 Int_t time = digit->GetTime();
641 Int_t det = digit->GetDetector();
643 return GetTrack(track,row,col,time,det);
647 //_____________________________________________________________________________
648 AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det)
651 // Returns indexes of active pads
654 Int_t recoDet = fRawRec ? 0 : det;
656 return (AliTRDSignalIndex *) fSignalIndexes->At(recoDet);
660 //_____________________________________________________________________________
661 void AliTRDdigitsManager::RemoveDigits(Int_t det)
664 // Clear memory at det for Digits
667 Int_t recoDet = fRawRec ? 0 : det;
669 if (fDigits->At(recoDet))
673 AliTRDarraySignal *arr = (AliTRDarraySignal *) fDigits->RemoveAt(recoDet);
678 AliTRDarrayADC *arr = (AliTRDarrayADC *) fDigits->RemoveAt(recoDet);
685 //_____________________________________________________________________________
686 void AliTRDdigitsManager::RemoveDictionaries(Int_t det)
692 Int_t recoDet = fRawRec ? 0 : det;
694 if (fUseDictionaries == kFALSE)
699 for (Int_t i = 0; i < kNDict; i++)
701 if (fDict[i]->At(recoDet))
703 AliTRDarrayDictionary *arr = (AliTRDarrayDictionary *) fDict[i]->RemoveAt(recoDet);
710 //_____________________________________________________________________________
711 void AliTRDdigitsManager::RemoveIndexes(Int_t det)
717 Int_t recoDet = fRawRec ? 0 : det;
719 if (fSignalIndexes->At(recoDet))
721 AliTRDSignalIndex *arr = (AliTRDSignalIndex *) fSignalIndexes->RemoveAt(recoDet);
727 //_____________________________________________________________________________
728 void AliTRDdigitsManager::ClearIndexes(Int_t det)
734 Int_t recoDet = fRawRec ? 0 : det;
736 ((AliTRDSignalIndex *) fSignalIndexes->At(recoDet))->ClearAll();
740 //_____________________________________________________________________________
741 Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det)
744 // Build the list of indices
752 AliTRDarrayADC *digits = 0x0;
760 digits = (AliTRDarrayADC *) GetDigits(det);
763 // digits should be expanded by now!!!
764 if (digits->GetNtime() > 0)
767 nRows = digits->GetNrow();
768 nCols = digits->GetNcol();
769 nTbins = digits->GetNtime();
771 AliTRDSignalIndex *indexes = GetIndexes(det);
772 indexes->SetSM(geom.GetSector(det));
773 indexes->SetStack(geom.GetStack(det));
774 indexes->SetLayer(geom.GetLayer(det));
775 indexes->SetDetNumber(det);
777 if (indexes->IsAllocated() == kFALSE)
779 indexes->Allocate(nRows,nCols,nTbins);
782 for (Int_t ir = 0; ir < nRows; ir++)
784 for (Int_t ic = 0; ic < nCols; ic++)
786 for (Int_t it = 0; it < nTbins; it++)
788 Int_t isig = digits->GetDataBits(ir,ic,it);
791 indexes->AddIndexRC(ir,ic);
807 //_____________________________________________________________________________
808 Bool_t AliTRDdigitsManager::LoadArrayDigits()
811 // Loads the (s-)digits arrays for all detectors
816 AliError("Digits tree is not defined\n");
820 Bool_t status = kTRUE;
823 TBranch *branch = fTree->GetBranch("TRDdigits");
826 AliError("Branch TRDdigits is not defined\n");
830 // Loop through all detectors and read them from the tree
831 for (Int_t iDet = 0; iDet < fDets; iDet++)
835 AliTRDarraySignal *dataArray = (AliTRDarraySignal *) fDigits->At(iDet);
841 branch->SetAddress(&dataArray);
842 branch->GetEntry(iDet);
846 AliTRDarrayADC *dataArray = (AliTRDarrayADC *) fDigits->At(iDet);
852 branch->SetAddress(&dataArray);
853 branch->GetEntry(iDet);
861 //________________________________________________________________________________________________
862 Bool_t AliTRDdigitsManager::LoadArrayDict()
865 // Loads dictionary arrays for all detectors
870 AliError("Digits tree is not defined\n");
874 Bool_t status = kTRUE;
876 for (Int_t iDict = 0; iDict < kNDict; iDict++)
880 Char_t branchname[15];
881 snprintf(branchname,15,"TRDdictionary%d",iDict);
882 TBranch *branch = fTree->GetBranch(branchname);
885 AliError(Form("Branch %s is not defined\n",branchname));
889 // Loop through all detectors and read them from the tree
890 for (Int_t iDet = 0; iDet < fDets; iDet++)
892 AliTRDarrayDictionary *dataArray = (AliTRDarrayDictionary *) fDict[iDict]->At(iDet);
898 branch->SetAddress(&dataArray);
899 branch->GetEntry(iDet);
908 //_____________________________________________________________________________
909 Bool_t AliTRDdigitsManager::LoadDigitsParam()
912 // Loads the digits parameter object from the digits tree
917 AliError("Digits tree is not defined\n");
922 TBranch *branch = fTree->GetBranch("TRDdigitsParam");
925 AliError("Branch TRDdigitsParam is not defined\n");
929 // Read the parameter object
930 AliTRDdigitsParam *digitsParam = fDigitsParam;
936 branch->SetAddress(&digitsParam);
943 //_____________________________________________________________________________
944 Bool_t AliTRDdigitsManager::StoreArrayDigits()
947 // Stores the digit arrays for all detectors
952 AliError("Digits tree is not defined\n");
957 TBranch *branch = fTree->GetBranch("TRDdigits");
960 AliError("Branch TRDdigits is not defined\n");
964 // Loop through all detectors and fill them into the tree
965 Bool_t status = kTRUE;
966 for (Int_t iDet = 0; iDet < fDets; iDet++)
970 const AliTRDarraySignal *kDataArray = (AliTRDarraySignal *) fDigits->At(iDet);
976 branch->SetAddress(&kDataArray);
981 const AliTRDarrayADC *kDataArray = (AliTRDarrayADC *) fDigits->At(iDet);
987 branch->SetAddress(&kDataArray);
996 //_____________________________________________________________________________
997 Bool_t AliTRDdigitsManager::StoreArrayDict()
1000 // Stores the dictionary arrays for all detectors
1005 AliError("Digits tree is not defined\n");
1009 Bool_t status = kTRUE;
1011 for (Int_t iDict = 0; iDict < kNDict; iDict++)
1015 Char_t branchname[15];
1016 snprintf(branchname,15,"TRDdictionary%d",iDict);
1017 TBranch *branch = fTree->GetBranch(branchname);
1020 AliError(Form("Branch %s is not defined\n",branchname));
1024 // Loop through all detectors and fill them into the tree
1025 for (Int_t iDet = 0; iDet < fDets; iDet++)
1027 const AliTRDarrayDictionary *kDataArray = (AliTRDarrayDictionary *) fDict[iDict]->At(iDet);
1033 branch->SetAddress(&kDataArray);
1043 //_____________________________________________________________________________
1044 Bool_t AliTRDdigitsManager::StoreDigitsParam()
1047 // Stores the digits parameter object from the digits tree
1052 AliError("Digits tree is not defined\n");
1057 TBranch *branch = fTree->GetBranch("TRDdigitsParam");
1060 AliError("Branch TRDdigitsParam is not defined\n");
1064 // Fill the digits object in the tree
1065 const AliTRDdigitsParam *kDigitsParam = fDigitsParam;
1070 branch->SetAddress(&kDigitsParam);