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 // AliTRDdataArray objects. //
23 ///////////////////////////////////////////////////////////////////////////////
25 #include <Riostream.h>
34 #include "AliTRDdigitsManager.h"
35 #include "AliTRDsegmentArray.h"
36 #include "AliTRDdataArray.h"
37 #include "AliTRDdataArrayI.h"
38 #include "AliTRDdataArrayS.h"
39 #include "AliTRDdataArrayDigits.h"
40 #include "AliTRDdigit.h"
41 #include "AliTRDgeometry.h"
43 #include "AliTRDSignalIndex.h"
45 ClassImp(AliTRDdigitsManager)
47 //_____________________________________________________________________________
49 // Number of track dictionary arrays
50 const Int_t AliTRDdigitsManager::fgkNDict = kNDict;
52 //_____________________________________________________________________________
53 AliTRDdigitsManager::AliTRDdigitsManager()
60 ,fUseDictionaries(kTRUE)
63 // Default constructor
66 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
67 fDictionary[iDict] = NULL;
70 fSignalIndexes = new TObjArray(AliTRDgeometry::Ndet());
74 //_____________________________________________________________________________
75 AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
80 ,fHasSDigits(m.fHasSDigits)
82 ,fUseDictionaries(kTRUE)
85 // AliTRDdigitsManager copy constructor
90 //_____________________________________________________________________________
91 AliTRDdigitsManager::~AliTRDdigitsManager()
94 // AliTRDdigitsManager destructor
103 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
104 fDictionary[iDict]->Delete();
105 delete fDictionary[iDict];
106 fDictionary[iDict] = NULL;
109 if (fSignalIndexes) {
110 fSignalIndexes->Delete();
111 delete fSignalIndexes;
112 fSignalIndexes = NULL;
117 //_____________________________________________________________________________
118 AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
121 // Assignment operator
125 ((AliTRDdigitsManager &) m).Copy(*this);
132 //_____________________________________________________________________________
133 void AliTRDdigitsManager::Copy(TObject &m) const
139 ((AliTRDdigitsManager &) m).fEvent = fEvent;
140 ((AliTRDdigitsManager &) m).fHasSDigits = fHasSDigits;
142 ((AliTRDdigitsManager &) m).fSignalIndexes = fSignalIndexes;
143 ((AliTRDdigitsManager &) m).fUseDictionaries = fUseDictionaries;
149 //_____________________________________________________________________________
150 void AliTRDdigitsManager::CreateArrays()
153 // Create the data arrays
157 fDigits = new AliTRDsegmentArray("AliTRDdataArrayF",AliTRDgeometry::Ndet());
160 fDigits = new AliTRDsegmentArray("AliTRDdataArrayDigits",AliTRDgeometry::Ndet());
163 if (fUseDictionaries) {
164 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
165 fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
166 ,AliTRDgeometry::Ndet());
170 for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++) {
171 fSignalIndexes->AddLast(new AliTRDSignalIndex());
176 //_____________________________________________________________________________
177 void AliTRDdigitsManager::ResetArrays()
180 // Reset the data arrays
188 fDigits = new AliTRDsegmentArray("AliTRDdataArrayF",AliTRDgeometry::Ndet());
191 fDigits = new AliTRDsegmentArray("AliTRDdataArrayS",AliTRDgeometry::Ndet());
194 if (fUseDictionaries) {
195 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
196 if (fDictionary[iDict]) {
197 fDictionary[iDict]->Delete();
198 delete fDictionary[iDict];
200 fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
201 ,AliTRDgeometry::Ndet());
205 for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++) {
206 AliTRDSignalIndex *idx = (AliTRDSignalIndex *)fSignalIndexes->At(i);
207 if (idx) idx->Reset();
212 //_____________________________________________________________________________
213 Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time
217 // Returns the amplitude of a digit
220 if (!GetDigits(det)) {
224 return ((Short_t) ((AliTRDdataArrayDigits *) GetDigits(det))->GetData(row,col,time));
228 //_____________________________________________________________________________
229 UChar_t AliTRDdigitsManager::GetPadStatus(Int_t row, Int_t col, Int_t time
233 // Returns the pad status for the requested pad
240 return ((UChar_t)((AliTRDdataArrayDigits *) GetDigits(det))->GetPadStatus(row, col, time));
243 //_____________________________________________________________________________
244 Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree)
247 // Creates the tree and branches for the digits and the dictionary
250 Int_t buffersize = 64000;
252 Bool_t status = kTRUE;
258 // Make the branch for the digits
260 const AliTRDdataArray *kDigits = (AliTRDdataArray *) fDigits->At(0);
262 if (!fTree) return kFALSE;
263 TBranch* branch = fTree->GetBranch("TRDdigits");
264 if (!branch) fTree->Branch("TRDdigits",kDigits->IsA()->GetName()
265 ,&kDigits,buffersize,99);
266 AliDebug(1,"Making branch TRDdigits\n");
276 if (fUseDictionaries) {
277 // Make the branches for the dictionaries
278 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
279 Char_t branchname[15];
280 sprintf(branchname,"TRDdictionary%d",iDict);
281 if (fDictionary[iDict]) {
282 const AliTRDdataArray *kDictionary =
283 (AliTRDdataArray *) fDictionary[iDict]->At(0);
285 if (!fTree) return kFALSE;
286 TBranch* branch = fTree->GetBranch(branchname);
287 if (!branch) fTree->Branch(branchname,kDictionary->IsA()->GetName()
288 ,&kDictionary,buffersize,99);
289 AliDebug(1,Form("Making branch %s\n",branchname));
305 //_____________________________________________________________________________
306 Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree)
309 // Reads the digit information from the input file
312 Bool_t status = kTRUE;
319 AliDebug(1,"Create the data arrays.\n");
323 status = fDigits->LoadArray("TRDdigits",fTree);
325 if (fUseDictionaries) {
326 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
327 Char_t branchname[15];
328 sprintf(branchname,"TRDdictionary%d",iDict);
329 status = fDictionary[iDict]->LoadArray(branchname,fTree);
330 if (status == kFALSE) {
331 fUseDictionaries = kFALSE;
332 AliWarning("Unable to load dict arrays. Will not use them.\n");
342 //_____________________________________________________________________________
343 Bool_t AliTRDdigitsManager::WriteDigits()
346 // Writes out the TRD-digits and the dictionaries
349 // Store the contents of the segment array in the tree
350 if (!fDigits->StoreArray("TRDdigits",fTree)) {
351 AliError("Error while storing digits in branch TRDdigits\n");
355 if (fUseDictionaries) {
356 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
357 Char_t branchname[15];
358 sprintf(branchname,"TRDdictionary%d",iDict);
359 if (!fDictionary[iDict]->StoreArray(branchname,fTree)) {
360 AliError(Form("Error while storing dictionary in branch %s\n",branchname));
366 // Write the new tree to the output file
367 fTree->AutoSave(); // Modification by Jiri
373 //_____________________________________________________________________________
374 AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row, Int_t col
375 , Int_t time, Int_t det) const
378 // Creates a single digit object
389 amp[0] = ((AliTRDdataArrayDigits *) GetDigits(det))->GetData(row,col,time);
391 return (new AliTRDdigit(digits,amp));
395 //_____________________________________________________________________________
396 Int_t AliTRDdigitsManager::GetTrack(Int_t track
397 , Int_t row, Int_t col, Int_t time
401 // Returns the MC-track numbers from the dictionary.
404 if ((track < 0) || (track >= kNDict)) {
405 AliError(Form("track %d out of bounds (size: %d, this: 0x%08x)"
406 ,track,kNDict,this));
410 if (fUseDictionaries == kFALSE) {
414 // Array contains index+1 to allow data compression
415 return (((AliTRDdataArrayI *) GetDictionary(det,track))->GetData(row,col,time) - 1);
419 //_____________________________________________________________________________
420 AliTRDdataArrayDigits *AliTRDdigitsManager::GetDigits(Int_t det) const
423 // Returns the digits array for one detector
430 return (AliTRDdataArrayDigits *) fDigits->At(det);
434 //_____________________________________________________________________________
435 AliTRDdataArray *AliTRDdigitsManager::GetDictionary(Int_t det, Int_t i) const
438 // Returns the dictionary for one detector
441 if (fUseDictionaries == kFALSE) {
445 return (AliTRDdataArray *) fDictionary[i]->At(det);
449 //_____________________________________________________________________________
450 Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *Digit) const
453 // Returns the MC-track numbers from the dictionary for a given digit
456 Int_t row = Digit->GetRow();
457 Int_t col = Digit->GetCol();
458 Int_t time = Digit->GetTime();
459 Int_t det = Digit->GetDetector();
461 return GetTrack(track,row,col,time,det);
465 //_____________________________________________________________________________
466 AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det)
469 // Returns indexes of active pads
472 return (AliTRDSignalIndex *) fSignalIndexes->At(det);
476 //_____________________________________________________________________________
477 void AliTRDdigitsManager::RemoveDigits(Int_t det)
483 fDigits->ClearSegment(det);
487 //_____________________________________________________________________________
488 void AliTRDdigitsManager::RemoveDictionaries(Int_t det)
494 if (fUseDictionaries == kFALSE) {
498 for (Int_t i = 0; i < kNDict; i++) {
499 fDictionary[i]->ClearSegment(det);
504 //_____________________________________________________________________________
505 void AliTRDdigitsManager::ClearIndexes(Int_t det)
511 fSignalIndexes->At(det)->Clear();
515 //_____________________________________________________________________________
516 Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det)
519 // Build the list of indices
527 AliTRDdataArrayDigits *digits = 0x0;
533 digits = (AliTRDdataArrayDigits *) GetDigits(det);
536 //digits should be expanded by now!!!
537 if (digits->GetNtime() > 0) {
540 nRows = digits->GetNrow();
541 nCols = digits->GetNcol();
542 nTbins = digits->GetNtime();
544 AliTRDSignalIndex *indexes = GetIndexes(det);
545 indexes->SetSM(geom.GetSector(det));
546 indexes->SetChamber(geom.GetChamber(det));
547 indexes->SetPlane(geom.GetPlane(det));
548 indexes->SetDetNumber(det);
550 if (indexes->IsAllocated() == kFALSE) {
551 indexes->Allocate(nRows,nCols,nTbins);
554 for (Int_t ir = 0; ir < nRows; ir++) {
555 for (Int_t ic = 0; ic < nCols; ic++) {
556 for (Int_t it = 0; it < nTbins; it++) {
558 Int_t isig = digits->GetDataUnchecked(ir,ic,it);
560 indexes->AddIndexTBin(ir,ic,it);