Add ADCbaseline to AliTRDdigitsParam
[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 //
b65e5048 21// TObjArray objects //
6f1e466d 22// //
23///////////////////////////////////////////////////////////////////////////////
6244debe 24
793ff80c 25#include <TTree.h>
77ad13f4 26
2745a409 27#include "AliLog.h"
77ad13f4 28
6f1e466d 29#include "AliTRDdigitsManager.h"
b65e5048 30#include "AliTRDarrayDictionary.h"
31#include "AliTRDarrayADC.h"
32#include "AliTRDarraySignal.h"
793ff80c 33#include "AliTRDdigit.h"
966f6939 34#include "AliTRDdigitsParam.h"
35#include "AliTRDSimParam.h"
793ff80c 36#include "AliTRDgeometry.h"
ca21baaa 37#include "AliTRDSignalIndex.h"
38
6f1e466d 39ClassImp(AliTRDdigitsManager)
40
41//_____________________________________________________________________________
793ff80c 42
43 // Number of track dictionary arrays
44 const Int_t AliTRDdigitsManager::fgkNDict = kNDict;
45
46//_____________________________________________________________________________
3d0c7d6d 47AliTRDdigitsManager::AliTRDdigitsManager(Bool_t rawRec)
2745a409 48 :TObject()
49 ,fEvent(0)
50 ,fTree(0)
b65e5048 51 ,fDigits(0)
625f5260 52 ,fHasSDigits(0)
ca21baaa 53 ,fSignalIndexes(NULL)
001be664 54 ,fUseDictionaries(kTRUE)
486c2339 55 ,fDets(AliTRDgeometry::Ndet())
3d0c7d6d 56 ,fRawRec(rawRec)
966f6939 57 ,fDigitsParam(0)
6f1e466d 58{
59 //
60 // Default constructor
61 //
486c2339 62
966f6939 63 if (fRawRec)
486c2339 64 {
966f6939 65 fDets = 1;
66 fRawRec = kTRUE;
486c2339 67 }
6f1e466d 68
b65e5048 69 for (Int_t iDict = 0; iDict < kNDict; iDict++)
70 {
71 fDict[iDict] = NULL;
966f6939 72 }
73
6f1e466d 74}
75
76//_____________________________________________________________________________
dd9a6ee3 77AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
2745a409 78 :TObject(m)
79 ,fEvent(m.fEvent)
80 ,fTree(0)
b65e5048 81 ,fDigits(0)
625f5260 82 ,fHasSDigits(m.fHasSDigits)
ca21baaa 83 ,fSignalIndexes(NULL)
001be664 84 ,fUseDictionaries(kTRUE)
486c2339 85 ,fDets(m.fDets)
86 ,fRawRec(m.fRawRec)
966f6939 87 ,fDigitsParam(NULL)
8230f242 88{
89 //
90 // AliTRDdigitsManager copy constructor
91 //
92
8230f242 93}
94
95//_____________________________________________________________________________
6f1e466d 96AliTRDdigitsManager::~AliTRDdigitsManager()
97{
8230f242 98 //
99 // AliTRDdigitsManager destructor
100 //
6f1e466d 101
b37bf997 102
b65e5048 103 if (fDigits)
104 {
105 fDigits->Delete();
106 delete fDigits;
107 fDigits = NULL;
108 }
6f1e466d 109
b65e5048 110 for (Int_t iDict = 0; iDict < kNDict; iDict++)
111 {
486c2339 112 if(fDict[iDict])
113 {
114 fDict[iDict]->Delete();
115 delete fDict[iDict];
116 fDict[iDict] = NULL;
117 }
b65e5048 118 }
6f1e466d 119
b65e5048 120 if (fSignalIndexes)
121 {
122 fSignalIndexes->Delete();
123 delete fSignalIndexes;
124 fSignalIndexes = NULL;
125 }
ca21baaa 126
966f6939 127 if (fDigitsParam)
128 {
129 delete fDigitsParam;
130 fDigitsParam = NULL;
131 }
132
6f1e466d 133}
134
135//_____________________________________________________________________________
2745a409 136AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
137{
138 //
139 // Assignment operator
140 //
141
b65e5048 142 if (this != &m)
143 {
144 ((AliTRDdigitsManager &) m).Copy(*this);
145 }
625f5260 146
2745a409 147 return *this;
148
149}
150
151//_____________________________________________________________________________
e0d47c25 152void AliTRDdigitsManager::Copy(TObject &m) const
8230f242 153{
154 //
155 // Copy function
156 //
157
625f5260 158 ((AliTRDdigitsManager &) m).fEvent = fEvent;
159 ((AliTRDdigitsManager &) m).fHasSDigits = fHasSDigits;
966f6939 160 ((AliTRDdigitsManager &) m).fDigits = NULL;
161 for(Int_t i = 0; i < kNDict; i++)
b65e5048 162 {
966f6939 163 ((AliTRDdigitsManager &) m).fDict[i] = NULL;
b65e5048 164 }
966f6939 165 ((AliTRDdigitsManager &) m).fSignalIndexes = NULL;
001be664 166 ((AliTRDdigitsManager &) m).fUseDictionaries = fUseDictionaries;
486c2339 167 ((AliTRDdigitsManager &) m).fDets = fDets;
966f6939 168 ((AliTRDdigitsManager &) m).fRawRec = fRawRec;
169 ((AliTRDdigitsManager &) m).fDigitsParam = NULL;
001be664 170
8230f242 171 TObject::Copy(m);
172
173}
174
175//_____________________________________________________________________________
abaf1f1d 176void AliTRDdigitsManager::CreateArrays()
177{
178 //
179 // Create the data arrays
180 //
181
b65e5048 182 if (fHasSDigits)
183 {
966f6939 184 if (fDigits)
b65e5048 185 {
186 fDigits->Delete();
187 delete fDigits;
188 }
486c2339 189 fDigits = new TObjArray(fDets);
190 for (Int_t index = 0; index < fDets; index++)
966f6939 191 {
192 fDigits->AddAt(new AliTRDarraySignal(),index);
193 }
b65e5048 194 }
195 else
196 {
966f6939 197 if (fDigits)
b65e5048 198 {
199 fDigits->Delete();
200 delete fDigits;
201 }
486c2339 202 fDigits = new TObjArray(fDets);
966f6939 203 for (Int_t index = 0; index < fDets; index++)
204 {
205 fDigits->AddAt(new AliTRDarrayADC(),index);
206 }
b65e5048 207 }
208
209 if (fUseDictionaries)
210 {
b65e5048 211 for (Int_t iDict = 0; iDict < kNDict; iDict++)
966f6939 212 {
213 if (fDict[iDict])
214 {
215 fDict[iDict]->Delete();
216 delete fDict[iDict];
217 }
218 fDict[iDict] = new TObjArray(fDets);
219 for (Int_t index = 0; index < fDets; index++)
220 {
221 fDict[iDict]->AddAt(new AliTRDarrayDictionary(),index);
222 }
223 }
001be664 224 }
486c2339 225
966f6939 226 if (fSignalIndexes)
b65e5048 227 {
486c2339 228 fSignalIndexes->Delete();
229 delete fSignalIndexes;
230 }
231 fSignalIndexes = new TObjArray(fDets);
966f6939 232 for (Int_t i = 0; i < fDets; i++)
233 {
234 fSignalIndexes->AddLast(new AliTRDSignalIndex());
235 }
236
237 if (fDigitsParam)
238 {
239 delete fDigitsParam;
240 }
241 fDigitsParam = new AliTRDdigitsParam();
242 fDigitsParam->SetNTimeBins(AliTRDSimParam::Instance()->GetNTimeBins());
683855ce 243 fDigitsParam->SetADCbaseline(AliTRDSimParam::Instance()->GetADCbaseline());
abaf1f1d 244
245}
625f5260 246
17eee78a 247//_____________________________________________________________________________
248void AliTRDdigitsManager::ResetArrays()
249{
250 //
251 // Reset the data arrays
252 //
253
486c2339 254 if (fDigits)
b65e5048 255 {
256 fDigits->Delete();
257 delete fDigits;
258 }
b65e5048 259 if (fHasSDigits)
260 {
486c2339 261 fDigits = new TObjArray(fDets);
262 for (Int_t index = 0; index < fDets; index++)
966f6939 263 {
264 fDigits->AddAt(new AliTRDarraySignal(),index);
265 }
b65e5048 266 }
486c2339 267 else
268 {
269 fDigits = new TObjArray(fDets);
270 for (Int_t index = 0; index < fDets; index++)
966f6939 271 {
272 fDigits->AddAt(new AliTRDarrayADC(),index);
273 }
486c2339 274 }
275
276 for (Int_t iDict = 0; iDict < kNDict; iDict++)
b65e5048 277 {
486c2339 278 if (fDict[iDict])
b65e5048 279 {
486c2339 280 fDict[iDict]->Delete();
281 delete fDict[iDict];
966f6939 282 fDict[iDict] = NULL;
b65e5048 283 }
284 }
b65e5048 285 if (fUseDictionaries)
286 {
b65e5048 287 for (Int_t iDict = 0; iDict < kNDict; iDict++)
966f6939 288 {
289 fDict[iDict] = new TObjArray(fDets);
290 for (Int_t index = 0; index < fDets; index++)
291 {
292 fDict[iDict]->AddAt(new AliTRDarrayDictionary(),index);
293 }
294 }
b65e5048 295 }
486c2339 296
966f6939 297 if (fSignalIndexes)
b65e5048 298 {
486c2339 299 fSignalIndexes->Delete();
300 delete fSignalIndexes;
b65e5048 301 }
486c2339 302 fSignalIndexes = new TObjArray(fDets);
303 for (Int_t i = 0; i < fDets; i++)
966f6939 304 {
305 fSignalIndexes->AddLast(new AliTRDSignalIndex());
306 }
307
486c2339 308}
309
310//_____________________________________________________________________________
311void AliTRDdigitsManager::ResetArrays(Int_t det)
312{
a4c334b6 313 //
314 // Reset the data arrays
315 //
486c2339 316
77ad13f4 317 Int_t recoDet = fRawRec ? 0 : det;
318
319 RemoveDigits(recoDet);
320 RemoveDictionaries(recoDet);
321 RemoveIndexes(recoDet);
486c2339 322
323 if (fHasSDigits)
966f6939 324 {
325 fDigits->AddAt(new AliTRDarraySignal(),recoDet);
326 }
486c2339 327 else
966f6939 328 {
329 fDigits->AddAt(new AliTRDarrayADC(),recoDet);
330 }
6f1e466d 331
486c2339 332 if (fUseDictionaries)
333 {
334 for (Int_t iDict = 0; iDict < kNDict; iDict++)
966f6939 335 {
336 fDict[iDict]->AddAt(new AliTRDarrayDictionary(),recoDet);
337 }
486c2339 338 }
339
77ad13f4 340 fSignalIndexes->AddAt(new AliTRDSignalIndex(),recoDet);
966f6939 341
6f1e466d 342}
343
344//_____________________________________________________________________________
b65e5048 345Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time, Int_t det) const
16bf9884 346{
347 //
348 // Returns the amplitude of a digit
349 //
350
486c2339 351 if (!GetDigits(det)) return 0;
b65e5048 352
da43c135 353 return ((Short_t) ((AliTRDarrayADC *) GetDigits(det))->GetDataBits(row,col,time));
16bf9884 354
355}
b65e5048 356
16bf9884 357//_____________________________________________________________________________
b65e5048 358UChar_t AliTRDdigitsManager::GetPadStatus(Int_t row, Int_t col, Int_t time, Int_t det) const
d739fd4e 359{
c10bf383 360 //
361 // Returns the pad status for the requested pad
362 //
d739fd4e 363
486c2339 364 if (!GetDigits(det)) return 0;
d739fd4e 365
b65e5048 366 return ((UChar_t) ((AliTRDarrayADC *) GetDigits(det))->GetPadStatus(row,col,time));
367
d739fd4e 368}
369
370//_____________________________________________________________________________
77ad13f4 371Bool_t AliTRDdigitsManager::MakeBranch(TTree * const tree)
855bfffd 372{
373 //
374 // Creates the tree and branches for the digits and the dictionary
375 //
376
b65e5048 377 Int_t buffersize = 64000;
378 Bool_t status = kTRUE;
855bfffd 379
b65e5048 380 if (tree)
381 {
382 fTree = tree;
383 }
855bfffd 384
abaf1f1d 385 // Make the branch for the digits
b65e5048 386 if (fDigits)
387 {
966f6939 388 if (fHasSDigits)
b65e5048 389 {
390 const AliTRDarraySignal *kDigits = (AliTRDarraySignal *) fDigits->At(0);
391 if (kDigits)
392 {
393 if (!fTree) return kFALSE;
394 AliDebug(1,"Making branch for SDigits!\n");
966f6939 395 TBranch *branch = fTree->GetBranch("TRDdigits");
396 if (!branch)
397 {
398 fTree->Branch("TRDdigits","AliTRDarraySignal",&kDigits,buffersize,99);
399 }
b65e5048 400 AliDebug(1,"Making branch TRDdigits\n");
401 }
402 else
403 {
404 status = kFALSE;
405 }
406 }
407
966f6939 408 if (!fHasSDigits)
b65e5048 409 {
410 const AliTRDarrayADC *kDigits = (AliTRDarrayADC *) fDigits->At(0);
411 if (kDigits)
412 {
413 if (!fTree) return kFALSE;
414 AliDebug(1,"Making branch for Digits!\n");
966f6939 415 TBranch *branch = fTree->GetBranch("TRDdigits");
416 if (!branch)
417 {
418 fTree->Branch("TRDdigits","AliTRDarrayADC",&kDigits,buffersize,99);
419 }
b65e5048 420 AliDebug(1,"Making branch TRDdigits\n");
421 }
422 else
423 {
424 status = kFALSE;
425 }
426 }
427
966f6939 428 }
b65e5048 429 else
430 {
966f6939 431
6f1e466d 432 status = kFALSE;
966f6939 433
6f1e466d 434 }
b65e5048 435
436 if (fUseDictionaries)
437 {
438 // Make the branches for the dictionaries
439 for (Int_t iDict = 0; iDict < kNDict; iDict++)
440 {
441 Char_t branchname[15];
442 sprintf(branchname,"TRDdictionary%d",iDict);
443 if (fDict[iDict])
444 {
445 const AliTRDarrayDictionary *kDictionary = (AliTRDarrayDictionary *) fDict[iDict]->At(0);
446 if (kDictionary)
447 {
448 if (!fTree) return kFALSE;
449 AliDebug(2,"Making branch for dictionary!\n");
966f6939 450 TBranch *branch = fTree->GetBranch(branchname);
451 if (!branch)
452 {
453 fTree->Branch(branchname,"AliTRDarrayDictionary",&kDictionary,buffersize,99);
454 }
b65e5048 455 AliDebug(1,Form("Making branch %s\n",branchname));
456 }
457 else
458 {
459 status = kFALSE;
460 }
461 }
462 else
463 {
464 status = kFALSE;
465 }
001be664 466 }
abaf1f1d 467 }
966f6939 468
469 if (fDigitsParam)
470 {
471 const AliTRDdigitsParam *kDigitsParam = fDigitsParam;
472 if (!fTree) return kFALSE;
473 TBranch *branch = fTree->GetBranch("TRDdigitsParam");
474 if (!branch)
475 {
476 fTree->Branch("TRDdigitsParam","AliTRDdigitsParam",&kDigitsParam,buffersize,99);
477 }
478 AliDebug(1,"Making branch AliTRDdigitsParam\n");
479 }
480
6f1e466d 481 return status;
482
483}
484
485//_____________________________________________________________________________
77ad13f4 486Bool_t AliTRDdigitsManager::ReadDigits(TTree * const tree)
6f1e466d 487{
8230f242 488 //
489 // Reads the digit information from the input file
490 //
6f1e466d 491
492 Bool_t status = kTRUE;
493
b65e5048 494 if (tree)
495 {
496 fTree = tree;
497 }
498
499 if (!fDigits)
500 {
501 AliDebug(1,"Create the data arrays.\n");
502 CreateArrays();
503 }
504
966f6939 505 status = LoadArrayDigits();
b65e5048 506
507 if (fUseDictionaries)
508 {
966f6939 509 status = LoadArrayDict();
510 if (status == kFALSE)
b65e5048 511 {
966f6939 512 fUseDictionaries = kFALSE;
513 AliWarning("Unable to load dict arrays. Will not use them.\n");
514 }
515 }
516
517 if (!LoadDigitsParam()) {
518 AliWarning("Could not read digits parameter.");
519 if (fDigitsParam) {
520 delete fDigitsParam;
b65e5048 521 }
966f6939 522 AliWarning(Form("Create default version of digits parameter (NTimeBin=%d).\n"
523 ,AliTRDSimParam::Instance()->GetNTimeBins()));
524 fDigitsParam = new AliTRDdigitsParam();
525 fDigitsParam->SetNTimeBins(AliTRDSimParam::Instance()->GetNTimeBins());
683855ce 526 fDigitsParam->SetADCbaseline(AliTRDSimParam::Instance()->GetADCbaseline());
966f6939 527 }
6f1e466d 528
966f6939 529 return status;
6f1e466d 530
531}
532
533//_____________________________________________________________________________
534Bool_t AliTRDdigitsManager::WriteDigits()
535{
536 //
537 // Writes out the TRD-digits and the dictionaries
538 //
539
966f6939 540 if (!StoreArrayDigits())
b65e5048 541 {
966f6939 542 AliError("Error while storing digits\n");
b65e5048 543 return kFALSE;
6f1e466d 544 }
6f1e466d 545
b65e5048 546 if (fUseDictionaries)
547 {
966f6939 548 if (!StoreArrayDict())
b65e5048 549 {
966f6939 550 AliError("Error while storing dictionaries in branch\n");
551 return kFALSE;
b65e5048 552 }
553 }
554
abaf1f1d 555 // Write the new tree to the output file
b65e5048 556 fTree->AutoSave();
abaf1f1d 557
6f1e466d 558 return kTRUE;
559
560}
9d0b222b 561
562//_____________________________________________________________________________
b65e5048 563AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row
564 , Int_t col
565 , Int_t time
566 , Int_t det) const
9d0b222b 567{
568 //
569 // Creates a single digit object
570 //
571
b65e5048 572 Int_t digits[4];
9d0b222b 573 Int_t amp[1];
574
575 digits[0] = det;
576 digits[1] = row;
577 digits[2] = col;
578 digits[3] = time;
579
b65e5048 580 amp[0] = ((AliTRDarrayADC *) GetDigits(det))->GetData(row,col,time);
9d0b222b 581
625f5260 582 return (new AliTRDdigit(digits,amp));
9d0b222b 583
584}
585
586//_____________________________________________________________________________
587Int_t AliTRDdigitsManager::GetTrack(Int_t track
b65e5048 588 , Int_t row
589 , Int_t col
590 , Int_t time
793ff80c 591 , Int_t det) const
9d0b222b 592{
593 //
594 // Returns the MC-track numbers from the dictionary.
595 //
596
b65e5048 597 if ((track < 0) || (track >= kNDict))
598 {
599 AliError(Form("track %d out of bounds (size: %d, this: 0x%08x)",track,kNDict,this));
600 return -1;
601 }
9d0b222b 602
b65e5048 603 if (fUseDictionaries == kFALSE)
604 {
605 return -1;
606 }
625f5260 607
b65e5048 608 // Array contains index+1 to allow data compression--->Changed
609 return (((AliTRDarrayDictionary *) GetDictionary(det,track))->GetData(row,col,time) );
9d0b222b 610
611}
612
b65e5048 613//________________________________________________________________________________
614AliTRDarrayADC *AliTRDdigitsManager::GetDigits(Int_t det) const
dd9a6ee3 615{
616 //
617 // Returns the digits array for one detector
618 //
619
486c2339 620 Int_t RecoDet = fRawRec ? 0 : det;
621
b65e5048 622 if (!fDigits)
623 {
624 return 0x0;
625 }
625f5260 626
b65e5048 627 if (!fHasSDigits)
628 {
486c2339 629 ((AliTRDarrayADC *) fDigits->At(RecoDet))->SetNdet(det);
630 return (AliTRDarrayADC *) fDigits->At(RecoDet);
b65e5048 631 }
632 else
633 {
634 AliDebug(2,"ERROR IN DATA TYPE!!!!");
635 return 0x0;
636 }
dd9a6ee3 637
638}
639
640//_____________________________________________________________________________
b65e5048 641AliTRDarraySignal *AliTRDdigitsManager::GetSDigits(Int_t det) const
dd9a6ee3 642{
643 //
b65e5048 644 // Returns the sdigits array for one detector
dd9a6ee3 645 //
646
486c2339 647 Int_t RecoDet = fRawRec ? 0 : det;
648
b65e5048 649 if (!fDigits)
650 {
651 // AliDebug(1,"NO FDIGITS!");
652 return 0x0;
653 }
654
655 if (fHasSDigits)
656 {
486c2339 657 ((AliTRDarraySignal *) fDigits->At(RecoDet))->SetNdet(det);
658 return (AliTRDarraySignal *) fDigits->At(RecoDet);
b65e5048 659 }
660 else
661 {
662 AliDebug(2,"ERROR IN DATA TYPE!!!!");
663 return 0x0;
664 }
665
666}
667
668//_____________________________________________________________________________
669AliTRDarrayDictionary *AliTRDdigitsManager::GetDictionary(Int_t det
670 , Int_t i) const
671{
672 //
673 // Returns the dictionary for one detector
674 //
625f5260 675
486c2339 676 Int_t RecoDet = fRawRec ? 0 : det;
677
b65e5048 678 if (fUseDictionaries == kFALSE)
679 {
680 return 0x0;
681 }
dd9a6ee3 682
486c2339 683 ((AliTRDarrayDictionary *) fDigits->At(RecoDet))->SetNdet(det);
684 return (AliTRDarrayDictionary *) fDict[i]->At(RecoDet);
b65e5048 685
dd9a6ee3 686}
687
688//_____________________________________________________________________________
77ad13f4 689Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit * const digit) const
dd9a6ee3 690{
691 //
692 // Returns the MC-track numbers from the dictionary for a given digit
693 //
694
b65e5048 695 Int_t row = digit->GetRow();
696 Int_t col = digit->GetCol();
697 Int_t time = digit->GetTime();
698 Int_t det = digit->GetDetector();
dd9a6ee3 699
700 return GetTrack(track,row,col,time,det);
701
702}
ca21baaa 703
704//_____________________________________________________________________________
705AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det)
706{
707 //
708 // Returns indexes of active pads
709 //
710
486c2339 711 Int_t RecoDet = fRawRec ? 0 : det;
712
713 return (AliTRDSignalIndex *) fSignalIndexes->At(RecoDet);
ca21baaa 714
715}
716
717//_____________________________________________________________________________
718void AliTRDdigitsManager::RemoveDigits(Int_t det)
719{
b65e5048 720 //
721 // Clear memory at det for Digits
722 //
ca21baaa 723
486c2339 724 Int_t RecoDet = fRawRec ? 0 : det;
725
726 if (fDigits->At(RecoDet))
b65e5048 727 {
b37bf997 728 if (fHasSDigits)
729 {
486c2339 730 AliTRDarraySignal *arr = (AliTRDarraySignal *) fDigits->RemoveAt(RecoDet);
b37bf997 731 delete arr;
732 }
733 else
734 {
486c2339 735 AliTRDarrayADC *arr = (AliTRDarrayADC *) fDigits->RemoveAt(RecoDet);
b37bf997 736 delete arr;
737 }
b65e5048 738 }
ca21baaa 739
740}
741
742//_____________________________________________________________________________
743void AliTRDdigitsManager::RemoveDictionaries(Int_t det)
744{
745 //
746 // Clear memory
747 //
625f5260 748
486c2339 749 Int_t RecoDet = fRawRec ? 0 : det;
750
b65e5048 751 if (fUseDictionaries == kFALSE)
752 {
753 return;
754 }
ca21baaa 755
b65e5048 756 for (Int_t i = 0; i < kNDict; i++)
757 {
486c2339 758 if (fDict[i]->At(RecoDet))
b65e5048 759 {
486c2339 760 AliTRDarrayDictionary *arr = (AliTRDarrayDictionary *) fDict[i]->RemoveAt(RecoDet);
b37bf997 761 delete arr;
b65e5048 762 }
763 }
ca21baaa 764
765}
766
767//_____________________________________________________________________________
486c2339 768void AliTRDdigitsManager::RemoveIndexes(Int_t det)
769{
770 //
771 // Clear memory
772 //
773
774 Int_t RecoDet = fRawRec ? 0 : det;
775
776 if (fSignalIndexes->At(RecoDet))
777 {
778 AliTRDSignalIndex *arr = (AliTRDSignalIndex *) fSignalIndexes->RemoveAt(RecoDet);
779 delete arr;
780 }
781
782}
783
486c2339 784//_____________________________________________________________________________
ca21baaa 785void AliTRDdigitsManager::ClearIndexes(Int_t det)
786{
787 //
788 // Clear memory
789 //
486c2339 790
791 Int_t RecoDet = fRawRec ? 0 : det;
625f5260 792
486c2339 793 ((AliTRDSignalIndex *) fSignalIndexes->At(RecoDet))->ClearAll();
ca21baaa 794
625f5260 795}
ca21baaa 796
797//_____________________________________________________________________________
798Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det)
799{
800 //
801 // Build the list of indices
802 //
803
b65e5048 804 Int_t nRows = 0;
805 Int_t nCols = 0;
ca21baaa 806 Int_t nTbins = 0;
807
b65e5048 808 AliTRDgeometry geom;
809 AliTRDarrayADC *digits = 0x0;
625f5260 810
b65e5048 811 if (fHasSDigits)
812 {
813 return kFALSE;
814 }
815 else
816 {
817 digits = (AliTRDarrayADC *) GetDigits(det);
818 }
625f5260 819
966f6939 820 // digits should be expanded by now!!!
b65e5048 821 if (digits->GetNtime() > 0)
822 {
823 digits->Expand();
824 nRows = digits->GetNrow();
825 nCols = digits->GetNcol();
826 nTbins = digits->GetNtime();
827
828 AliTRDSignalIndex *indexes = GetIndexes(det);
829 indexes->SetSM(geom.GetSector(det));
830 indexes->SetStack(geom.GetStack(det));
831 indexes->SetLayer(geom.GetLayer(det));
832 indexes->SetDetNumber(det);
833
834 if (indexes->IsAllocated() == kFALSE)
835 {
836 indexes->Allocate(nRows,nCols,nTbins);
837 }
625f5260 838
b65e5048 839 for (Int_t ir = 0; ir < nRows; ir++)
840 {
841 for (Int_t ic = 0; ic < nCols; ic++)
842 {
843 for (Int_t it = 0; it < nTbins; it++)
844 {
da43c135 845 Int_t isig = digits->GetDataBits(ir,ic,it);
b65e5048 846 if (isig > 0)
847 {
ae63fafc 848 indexes->AddIndexRC(ir,ic);
b65e5048 849 }
850 } // tbins
851 } // cols
852 } // rows
853
854 } // if GetNtime
855 else
856 {
857 return kFALSE;
858 }
859
860 return kTRUE;
625f5260 861
b65e5048 862}
625f5260 863
b65e5048 864//_____________________________________________________________________________
966f6939 865Bool_t AliTRDdigitsManager::LoadArrayDigits()
b65e5048 866{
867 //
966f6939 868 // Loads the (s-)digits arrays for all detectors
b65e5048 869 //
870
966f6939 871 if (!fTree)
b65e5048 872 {
873 AliError("Digits tree is not defined\n");
874 return kFALSE;
ca21baaa 875 }
625f5260 876
966f6939 877 Bool_t status = kTRUE;
878
b65e5048 879 // Get the branch
966f6939 880 TBranch *branch = fTree->GetBranch("TRDdigits");
881 if (!branch)
b65e5048 882 {
966f6939 883 AliError("Branch TRDdigits is not defined\n");
b65e5048 884 return kFALSE;
885 }
625f5260 886
b65e5048 887 // Loop through all detectors and read them from the tree
486c2339 888 for (Int_t iDet = 0; iDet < fDets; iDet++)
b65e5048 889 {
966f6939 890 if (fHasSDigits)
b65e5048 891 {
966f6939 892 AliTRDarraySignal *dataArray = (AliTRDarraySignal *) fDigits->At(iDet);
b65e5048 893 if (!dataArray)
894 {
895 status = kFALSE;
896 break;
897 }
966f6939 898 branch->SetAddress(&dataArray);
899 branch->GetEntry(iDet);
b65e5048 900 }
901 else
902 {
966f6939 903 AliTRDarrayADC *dataArray = (AliTRDarrayADC *) fDigits->At(iDet);
b65e5048 904 if (!dataArray)
905 {
906 status = kFALSE;
966f6939 907 break;
b65e5048 908 }
966f6939 909 branch->SetAddress(&dataArray);
910 branch->GetEntry(iDet);
b65e5048 911 }
912 }
625f5260 913
b65e5048 914 return status;
915
916}
917
918//________________________________________________________________________________________________
966f6939 919Bool_t AliTRDdigitsManager::LoadArrayDict()
b65e5048 920{
921 //
966f6939 922 // Loads dictionary arrays for all detectors
b65e5048 923 //
924
966f6939 925 if (!fTree)
926 {
927 AliError("Digits tree is not defined\n");
928 return kFALSE;
929 }
930
931 Bool_t status = kTRUE;
932
933 for (Int_t iDict = 0; iDict < kNDict; iDict++)
934 {
935
936 // Get the branch
937 Char_t branchname[15];
938 sprintf(branchname,"TRDdictionary%d",iDict);
939 TBranch *branch = fTree->GetBranch(branchname);
940 if (!branch)
941 {
942 AliError(Form("Branch %s is not defined\n",branchname));
943 return kFALSE;
944 }
945
946 // Loop through all detectors and read them from the tree
947 for (Int_t iDet = 0; iDet < fDets; iDet++)
948 {
949 AliTRDarrayDictionary *dataArray = (AliTRDarrayDictionary *) fDict[iDict]->At(iDet);
950 if (!dataArray)
951 {
952 status = kFALSE;
953 break;
954 }
955 branch->SetAddress(&dataArray);
956 branch->GetEntry(iDet);
957 }
958
959 }
960
961 return status;
962
963}
964
965//_____________________________________________________________________________
966Bool_t AliTRDdigitsManager::LoadDigitsParam()
967{
968 //
969 // Loads the digits parameter object from the digits tree
970 //
b65e5048 971
966f6939 972 if (!fTree)
b65e5048 973 {
974 AliError("Digits tree is not defined\n");
975 return kFALSE;
976 }
977
978 // Get the branch
966f6939 979 TBranch *branch = fTree->GetBranch("TRDdigitsParam");
980 if (!branch)
b65e5048 981 {
966f6939 982 AliError("Branch TRDdigitsParam is not defined\n");
b65e5048 983 return kFALSE;
984 }
985
966f6939 986 // Read the parameter object
987 AliTRDdigitsParam *digitsParam = fDigitsParam;
988 if (!digitsParam)
b65e5048 989 {
966f6939 990 return kFALSE;
b65e5048 991 }
992
966f6939 993 branch->SetAddress(&digitsParam);
994 branch->GetEntry();
995
996 return kTRUE;
b65e5048 997
998}
999
1000//_____________________________________________________________________________
966f6939 1001Bool_t AliTRDdigitsManager::StoreArrayDigits()
b65e5048 1002{
1003 //
966f6939 1004 // Stores the digit arrays for all detectors
b65e5048 1005 //
1006
b65e5048 1007 if (!fTree)
1008 {
1009 AliError("Digits tree is not defined\n");
1010 return kFALSE;
1011 }
1012
1013 // Get the branch
966f6939 1014 TBranch *branch = fTree->GetBranch("TRDdigits");
1015 if (!branch)
b65e5048 1016 {
966f6939 1017 AliError("Branch TRDdigits is not defined\n");
b65e5048 1018 return kFALSE;
1019 }
1020
1021 // Loop through all detectors and fill them into the tree
1022 Bool_t status = kTRUE;
486c2339 1023 for (Int_t iDet = 0; iDet < fDets; iDet++)
b65e5048 1024 {
1025 if (fHasSDigits)
1026 {
966f6939 1027 const AliTRDarraySignal *kDataArray = (AliTRDarraySignal *) fDigits->At(iDet);
b65e5048 1028 if (!kDataArray)
1029 {
1030 status = kFALSE;
1031 break;
1032 }
966f6939 1033 branch->SetAddress(&kDataArray);
1034 branch->Fill();
b65e5048 1035 }
1036 else
1037 {
966f6939 1038 const AliTRDarrayADC *kDataArray = (AliTRDarrayADC *) fDigits->At(iDet);
b65e5048 1039 if (!kDataArray)
1040 {
1041 status = kFALSE;
1042 break;
1043 }
966f6939 1044 branch->SetAddress(&kDataArray);
1045 branch->Fill();
b65e5048 1046 }
1047 }
1048
1049 return status;
1050
1051}
1052
1053//_____________________________________________________________________________
966f6939 1054Bool_t AliTRDdigitsManager::StoreArrayDict()
b65e5048 1055{
1056 //
966f6939 1057 // Stores the dictionary arrays for all detectors
b65e5048 1058 //
1059
966f6939 1060 if (!fTree)
1061 {
1062 AliError("Digits tree is not defined\n");
1063 return kFALSE;
1064 }
1065
1066 Bool_t status = kTRUE;
1067
1068 for (Int_t iDict = 0; iDict < kNDict; iDict++)
1069 {
1070
1071 // Get the branch
1072 Char_t branchname[15];
1073 sprintf(branchname,"TRDdictionary%d",iDict);
1074 TBranch *branch = fTree->GetBranch(branchname);
1075 if (!branch)
1076 {
1077 AliError(Form("Branch %s is not defined\n",branchname));
1078 return kFALSE;
1079 }
1080
1081 // Loop through all detectors and fill them into the tree
1082 for (Int_t iDet = 0; iDet < fDets; iDet++)
1083 {
1084 const AliTRDarrayDictionary *kDataArray = (AliTRDarrayDictionary *) fDict[iDict]->At(iDet);
1085 if (!kDataArray)
1086 {
1087 status = kFALSE;
1088 break;
1089 }
1090 branch->SetAddress(&kDataArray);
1091 branch->Fill();
1092 }
1093
1094 }
1095
1096 return status;
1097
1098}
1099
1100//_____________________________________________________________________________
1101Bool_t AliTRDdigitsManager::StoreDigitsParam()
1102{
1103 //
1104 // Stores the digits parameter object from the digits tree
1105 //
b65e5048 1106
1107 if (!fTree)
1108 {
1109 AliError("Digits tree is not defined\n");
1110 return kFALSE;
1111 }
1112
1113 // Get the branch
966f6939 1114 TBranch *branch = fTree->GetBranch("TRDdigitsParam");
1115 if (!branch)
b65e5048 1116 {
966f6939 1117 AliError("Branch TRDdigitsParam is not defined\n");
b65e5048 1118 return kFALSE;
1119 }
1120
966f6939 1121 // Fill the digits object in the tree
1122 const AliTRDdigitsParam *kDigitsParam = fDigitsParam;
1123 if (!kDigitsParam)
b65e5048 1124 {
966f6939 1125 return kFALSE;
b65e5048 1126 }
966f6939 1127 branch->SetAddress(&kDigitsParam);
1128 branch->Fill();
b65e5048 1129
966f6939 1130 return kTRUE;
ca21baaa 1131
1132}
966f6939 1133