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