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