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