]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDdigitsManager.cxx
Next update of the pad status encoding
[u/mrichter/AliRoot.git] / TRD / AliTRDdigitsManager.cxx
CommitLineData
6f1e466d 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
88cb7938 16/* $Id$ */
6f1e466d 17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// Manages the digits and the track dictionary in the form of //
21// AliTRDdataArray objects. //
22// //
23///////////////////////////////////////////////////////////////////////////////
6244debe 24
a2cb5b3d 25#include <Riostream.h>
793ff80c 26
2ab0c725 27#include <TROOT.h>
793ff80c 28#include <TTree.h>
2ab0c725 29#include <TFile.h>
94de3818 30
6f1e466d 31#include "AliRun.h"
2745a409 32#include "AliLog.h"
6f1e466d 33
34#include "AliTRDdigitsManager.h"
793ff80c 35#include "AliTRDsegmentArray.h"
625f5260 36#include "AliTRDdataArray.h"
793ff80c 37#include "AliTRDdataArrayI.h"
625f5260 38#include "AliTRDdataArrayS.h"
f5375dcb 39#include "AliTRDdataArrayDigits.h"
793ff80c 40#include "AliTRDdigit.h"
41#include "AliTRDgeometry.h"
6f1e466d 42
ca21baaa 43#include "AliTRDSignalIndex.h"
44
6f1e466d 45ClassImp(AliTRDdigitsManager)
46
793ff80c 47//_____________________________________________________________________________
48
49 // Number of track dictionary arrays
50 const Int_t AliTRDdigitsManager::fgkNDict = kNDict;
51
6f1e466d 52//_____________________________________________________________________________
2745a409 53AliTRDdigitsManager::AliTRDdigitsManager()
54 :TObject()
55 ,fEvent(0)
56 ,fTree(0)
57 ,fDigits(0)
625f5260 58 ,fHasSDigits(0)
ca21baaa 59 ,fSignalIndexes(NULL)
001be664 60 ,fUseDictionaries(kTRUE)
6f1e466d 61{
62 //
63 // Default constructor
64 //
65
6f1e466d 66 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
abaf1f1d 67 fDictionary[iDict] = NULL;
6f1e466d 68 }
ca21baaa 69
ca21baaa 70 fSignalIndexes = new TObjArray(AliTRDgeometry::Ndet());
71
6f1e466d 72}
73
8230f242 74//_____________________________________________________________________________
dd9a6ee3 75AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
2745a409 76 :TObject(m)
77 ,fEvent(m.fEvent)
78 ,fTree(0)
79 ,fDigits(0)
625f5260 80 ,fHasSDigits(m.fHasSDigits)
ca21baaa 81 ,fSignalIndexes(NULL)
001be664 82 ,fUseDictionaries(kTRUE)
8230f242 83{
84 //
85 // AliTRDdigitsManager copy constructor
86 //
87
8230f242 88}
89
6f1e466d 90//_____________________________________________________________________________
91AliTRDdigitsManager::~AliTRDdigitsManager()
92{
8230f242 93 //
94 // AliTRDdigitsManager destructor
95 //
6f1e466d 96
97 if (fDigits) {
98 fDigits->Delete();
99 delete fDigits;
625f5260 100 fDigits = NULL;
6f1e466d 101 }
102
103 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
104 fDictionary[iDict]->Delete();
105 delete fDictionary[iDict];
abaf1f1d 106 fDictionary[iDict] = NULL;
6f1e466d 107 }
108
c0ab62ff 109 if (fSignalIndexes) {
110 fSignalIndexes->Delete();
111 delete fSignalIndexes;
625f5260 112 fSignalIndexes = NULL;
c0ab62ff 113 }
ca21baaa 114
6f1e466d 115}
116
2745a409 117//_____________________________________________________________________________
118AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
119{
120 //
121 // Assignment operator
122 //
123
625f5260 124 if (this != &m) {
125 ((AliTRDdigitsManager &) m).Copy(*this);
126 }
127
2745a409 128 return *this;
129
130}
131
8230f242 132//_____________________________________________________________________________
e0d47c25 133void AliTRDdigitsManager::Copy(TObject &m) const
8230f242 134{
135 //
136 // Copy function
137 //
138
625f5260 139 ((AliTRDdigitsManager &) m).fEvent = fEvent;
140 ((AliTRDdigitsManager &) m).fHasSDigits = fHasSDigits;
ca21baaa 141
625f5260 142 ((AliTRDdigitsManager &) m).fSignalIndexes = fSignalIndexes;
001be664 143 ((AliTRDdigitsManager &) m).fUseDictionaries = fUseDictionaries;
144
8230f242 145 TObject::Copy(m);
146
147}
148
abaf1f1d 149//_____________________________________________________________________________
150void AliTRDdigitsManager::CreateArrays()
151{
152 //
153 // Create the data arrays
154 //
155
625f5260 156 if (fHasSDigits) {
157 fDigits = new AliTRDsegmentArray("AliTRDdataArrayF",AliTRDgeometry::Ndet());
158 }
159 else {
f5375dcb 160 fDigits = new AliTRDsegmentArray("AliTRDdataArrayDigits",AliTRDgeometry::Ndet());
625f5260 161 }
abaf1f1d 162
625f5260 163 if (fUseDictionaries) {
164 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
165 fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
166 ,AliTRDgeometry::Ndet());
001be664 167 }
625f5260 168 }
169
170 for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++) {
171 fSignalIndexes->AddLast(new AliTRDSignalIndex());
172 }
abaf1f1d 173
17eee78a 174}
625f5260 175
17eee78a 176//_____________________________________________________________________________
177void AliTRDdigitsManager::ResetArrays()
178{
179 //
180 // Reset the data arrays
181 //
182
183 if (fDigits) {
c0ab62ff 184 fDigits->Delete();
17eee78a 185 delete fDigits;
186 }
625f5260 187 if (fHasSDigits) {
188 fDigits = new AliTRDsegmentArray("AliTRDdataArrayF",AliTRDgeometry::Ndet());
189 }
190 else {
191 fDigits = new AliTRDsegmentArray("AliTRDdataArrayS",AliTRDgeometry::Ndet());
192 }
17eee78a 193
625f5260 194 if (fUseDictionaries) {
195 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
196 if (fDictionary[iDict]) {
197 fDictionary[iDict]->Delete();
198 delete fDictionary[iDict];
001be664 199 }
625f5260 200 fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
201 ,AliTRDgeometry::Ndet());
17eee78a 202 }
625f5260 203 }
17eee78a 204
625f5260 205 for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++) {
206 AliTRDSignalIndex *idx = (AliTRDSignalIndex *)fSignalIndexes->At(i);
207 if (idx) idx->Reset();
208 }
6f1e466d 209
6f1e466d 210}
211
16bf9884 212//_____________________________________________________________________________
213Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time
214 , Int_t det) const
215{
216 //
217 // Returns the amplitude of a digit
218 //
219
625f5260 220 if (!GetDigits(det)) {
221 return 0;
222 }
223
f5375dcb 224 return ((Short_t) ((AliTRDdataArrayDigits *) GetDigits(det))->GetData(row,col,time));
16bf9884 225
226}
227
6f1e466d 228//_____________________________________________________________________________
88cb7938 229Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree)
855bfffd 230{
231 //
232 // Creates the tree and branches for the digits and the dictionary
233 //
234
235 Int_t buffersize = 64000;
236
237 Bool_t status = kTRUE;
238
855bfffd 239 if (tree) {
240 fTree = tree;
241 }
242
abaf1f1d 243 // Make the branch for the digits
244 if (fDigits) {
245 const AliTRDdataArray *kDigits = (AliTRDdataArray *) fDigits->At(0);
246 if (kDigits) {
bdbb05bb 247 if (!fTree) return kFALSE;
248 TBranch* branch = fTree->GetBranch("TRDdigits");
625f5260 249 if (!branch) fTree->Branch("TRDdigits",kDigits->IsA()->GetName()
250 ,&kDigits,buffersize,99);
2745a409 251 AliDebug(1,"Making branch TRDdigits\n");
6f1e466d 252 }
253 else {
254 status = kFALSE;
255 }
abaf1f1d 256 }
257 else {
258 status = kFALSE;
259 }
6f1e466d 260
625f5260 261 if (fUseDictionaries) {
262 // Make the branches for the dictionaries
263 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
264 Char_t branchname[15];
265 sprintf(branchname,"TRDdictionary%d",iDict);
266 if (fDictionary[iDict]) {
267 const AliTRDdataArray *kDictionary =
268 (AliTRDdataArray *) fDictionary[iDict]->At(0);
269 if (kDictionary) {
270 if (!fTree) return kFALSE;
271 TBranch* branch = fTree->GetBranch(branchname);
272 if (!branch) fTree->Branch(branchname,kDictionary->IsA()->GetName()
273 ,&kDictionary,buffersize,99);
274 AliDebug(1,Form("Making branch %s\n",branchname));
001be664 275 }
276 else {
277 status = kFALSE;
278 }
6f1e466d 279 }
625f5260 280 else {
281 status = kFALSE;
282 }
abaf1f1d 283 }
625f5260 284 }
6f1e466d 285
286 return status;
287
288}
289
290//_____________________________________________________________________________
855bfffd 291Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree)
6f1e466d 292{
8230f242 293 //
294 // Reads the digit information from the input file
295 //
6f1e466d 296
297 Bool_t status = kTRUE;
298
855bfffd 299 if (tree) {
855bfffd 300 fTree = tree;
abaf1f1d 301 }
302
303 if (!fDigits) {
2745a409 304 AliDebug(1,"Create the data arrays.\n");
abaf1f1d 305 CreateArrays();
306 }
307
308 status = fDigits->LoadArray("TRDdigits",fTree);
6f1e466d 309
625f5260 310 if (fUseDictionaries) {
311 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
312 Char_t branchname[15];
313 sprintf(branchname,"TRDdictionary%d",iDict);
314 status = fDictionary[iDict]->LoadArray(branchname,fTree);
315 if (status == kFALSE) {
316 fUseDictionaries = kFALSE;
317 AliWarning("Unable to load dict arrays. Will not use them.\n");
318 break;
319 }
320 }
6f1e466d 321 }
322
323 return kTRUE;
324
325}
326
327//_____________________________________________________________________________
328Bool_t AliTRDdigitsManager::WriteDigits()
329{
330 //
331 // Writes out the TRD-digits and the dictionaries
332 //
333
6f1e466d 334 // Store the contents of the segment array in the tree
abaf1f1d 335 if (!fDigits->StoreArray("TRDdigits",fTree)) {
2745a409 336 AliError("Error while storing digits in branch TRDdigits\n");
6f1e466d 337 return kFALSE;
338 }
001be664 339
625f5260 340 if (fUseDictionaries) {
341 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
342 Char_t branchname[15];
343 sprintf(branchname,"TRDdictionary%d",iDict);
344 if (!fDictionary[iDict]->StoreArray(branchname,fTree)) {
345 AliError(Form("Error while storing dictionary in branch %s\n",branchname));
346 return kFALSE;
001be664 347 }
6f1e466d 348 }
625f5260 349 }
6f1e466d 350
abaf1f1d 351 // Write the new tree to the output file
8e64dd77 352 fTree->AutoSave(); // Modification by Jiri
abaf1f1d 353
6f1e466d 354 return kTRUE;
355
356}
9d0b222b 357
358//_____________________________________________________________________________
359AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row, Int_t col
793ff80c 360 , Int_t time, Int_t det) const
9d0b222b 361{
362 //
363 // Creates a single digit object
364 //
365
366 Int_t digits[4];
367 Int_t amp[1];
368
369 digits[0] = det;
370 digits[1] = row;
371 digits[2] = col;
372 digits[3] = time;
373
f5375dcb 374 amp[0] = ((AliTRDdataArrayDigits *) GetDigits(det))->GetData(row,col,time);
9d0b222b 375
625f5260 376 return (new AliTRDdigit(digits,amp));
9d0b222b 377
378}
379
380//_____________________________________________________________________________
381Int_t AliTRDdigitsManager::GetTrack(Int_t track
382 , Int_t row, Int_t col, Int_t time
793ff80c 383 , Int_t det) const
9d0b222b 384{
385 //
386 // Returns the MC-track numbers from the dictionary.
387 //
388
389 if ((track < 0) || (track >= kNDict)) {
2745a409 390 AliError(Form("track %d out of bounds (size: %d, this: 0x%08x)"
391 ,track,kNDict,this));
9d0b222b 392 return -1;
393 }
394
625f5260 395 if (fUseDictionaries == kFALSE) {
396 return -1;
397 }
398
9d0b222b 399 // Array contains index+1 to allow data compression
625f5260 400 return (((AliTRDdataArrayI *) GetDictionary(det,track))->GetData(row,col,time) - 1);
9d0b222b 401
402}
403
dd9a6ee3 404//_____________________________________________________________________________
f5375dcb 405AliTRDdataArrayDigits *AliTRDdigitsManager::GetDigits(Int_t det) const
dd9a6ee3 406{
407 //
408 // Returns the digits array for one detector
409 //
410
625f5260 411 if (!fDigits) {
412 return 0x0;
413 }
414
f5375dcb 415 return (AliTRDdataArrayDigits *) fDigits->At(det);
dd9a6ee3 416
417}
418
419//_____________________________________________________________________________
625f5260 420AliTRDdataArray *AliTRDdigitsManager::GetDictionary(Int_t det, Int_t i) const
dd9a6ee3 421{
422 //
423 // Returns the dictionary for one detector
424 //
425
625f5260 426 if (fUseDictionaries == kFALSE) {
427 return 0x0;
428 }
429
430 return (AliTRDdataArray *) fDictionary[i]->At(det);
dd9a6ee3 431
432}
433
434//_____________________________________________________________________________
793ff80c 435Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *Digit) const
dd9a6ee3 436{
437 //
438 // Returns the MC-track numbers from the dictionary for a given digit
439 //
440
441 Int_t row = Digit->GetRow();
442 Int_t col = Digit->GetCol();
443 Int_t time = Digit->GetTime();
444 Int_t det = Digit->GetDetector();
445
446 return GetTrack(track,row,col,time,det);
447
448}
ca21baaa 449
450//_____________________________________________________________________________
451AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det)
452{
453 //
454 // Returns indexes of active pads
455 //
456
625f5260 457 return (AliTRDSignalIndex *) fSignalIndexes->At(det);
ca21baaa 458
459}
460
461//_____________________________________________________________________________
462void AliTRDdigitsManager::RemoveDigits(Int_t det)
463{
464 //
465 // Clear memory
466 //
467
468 fDigits->ClearSegment(det);
469
470}
471
472//_____________________________________________________________________________
473void AliTRDdigitsManager::RemoveDictionaries(Int_t det)
474{
475 //
476 // Clear memory
477 //
625f5260 478
479 if (fUseDictionaries == kFALSE) {
480 return;
481 }
ca21baaa 482
483 for (Int_t i = 0; i < kNDict; i++) {
484 fDictionary[i]->ClearSegment(det);
485 }
486
487}
488
489//_____________________________________________________________________________
490void AliTRDdigitsManager::ClearIndexes(Int_t det)
491{
492 //
493 // Clear memory
494 //
625f5260 495
ca21baaa 496 fSignalIndexes->At(det)->Clear();
ca21baaa 497
625f5260 498}
ca21baaa 499
500//_____________________________________________________________________________
501Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det)
502{
503 //
504 // Build the list of indices
505 //
506
507 Int_t nRows = 0;
508 Int_t nCols = 0;
509 Int_t nTbins = 0;
510
511 AliTRDgeometry geom;
f5375dcb 512 AliTRDdataArrayDigits *digits = 0x0;
625f5260 513
514 if (fHasSDigits) {
515 return kFALSE;
516 }
517 else {
f5375dcb 518 digits = (AliTRDdataArrayDigits *) GetDigits(det);
625f5260 519 }
520
ca21baaa 521 //digits should be expanded by now!!!
625f5260 522 if (digits->GetNtime() > 0) {
523
524 digits->Expand();
525 nRows = digits->GetNrow();
526 nCols = digits->GetNcol();
527 nTbins = digits->GetNtime();
528
529 AliTRDSignalIndex *indexes = GetIndexes(det);
530 indexes->SetSM(geom.GetSector(det));
531 indexes->SetChamber(geom.GetChamber(det));
532 indexes->SetPlane(geom.GetPlane(det));
533 indexes->SetDetNumber(det);
534
535 if (indexes->IsAllocated() == kFALSE) {
536 indexes->Allocate(nRows,nCols,nTbins);
ca21baaa 537 }
625f5260 538
539 for (Int_t ir = 0; ir < nRows; ir++) {
540 for (Int_t ic = 0; ic < nCols; ic++) {
541 for (Int_t it = 0; it < nTbins; it++) {
542
543 Int_t isig = digits->GetDataUnchecked(ir,ic,it);
544 if (isig > 0) {
545 indexes->AddIndexTBin(ir,ic,it);
546 }
547 } // tbins
548 } // cols
549 } // rows
550
551 } // if GetNtime
552 else {
553 return kFALSE;
554 }
555
ca21baaa 556 return kTRUE;
557
558}