]>
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 | ||
16 | /* | |
17 | $Log$ | |
8e64dd77 | 18 | Revision 1.17 2002/03/28 14:59:07 cblume |
19 | Coding conventions | |
20 | ||
0a29d0f1 | 21 | Revision 1.16 2002/02/12 11:42:08 cblume |
22 | Remove fTree from destructor | |
23 | ||
81eb1f59 | 24 | Revision 1.15 2002/02/11 14:27:54 cblume |
25 | Geometry and hit structure update | |
26 | ||
855bfffd | 27 | Revision 1.14 2001/11/14 10:50:46 cblume |
28 | Changes in digits IO. Add merging of summable digits | |
29 | ||
abaf1f1d | 30 | Revision 1.13 2001/11/06 17:19:41 cblume |
31 | Add detailed geometry and simple simulator | |
32 | ||
16bf9884 | 33 | Revision 1.12 2001/05/16 14:57:28 alibrary |
34 | New files for folders and Stack | |
35 | ||
9e1a0ddb | 36 | Revision 1.11 2001/03/13 09:30:35 cblume |
37 | Update of digitization. Moved digit branch definition to AliTRD | |
38 | ||
6244debe | 39 | Revision 1.10 2001/01/26 19:56:57 hristov |
40 | Major upgrade of AliRoot code | |
41 | ||
2ab0c725 | 42 | Revision 1.9 2000/11/02 09:25:53 cblume |
43 | Change also the dictionary to AliTRDdataArray | |
44 | ||
4d6586ef | 45 | Revision 1.8 2000/11/01 15:20:13 cblume |
46 | Change AliTRDdataArrayI to AliTRDdataArray in MakeBranch() | |
47 | ||
06754153 | 48 | Revision 1.7 2000/11/01 14:53:20 cblume |
49 | Merge with TRD-develop | |
50 | ||
793ff80c | 51 | Revision 1.1.2.5 2000/10/17 02:27:34 cblume |
52 | Get rid of global constants | |
53 | ||
54 | Revision 1.1.2.4 2000/10/15 23:40:01 cblume | |
55 | Remove AliTRDconst | |
56 | ||
57 | Revision 1.1.2.3 2000/10/06 16:49:46 cblume | |
58 | Made Getters const | |
59 | ||
60 | Revision 1.1.2.2 2000/10/04 16:34:58 cblume | |
61 | Replace include files by forward declarations | |
62 | ||
94de3818 | 63 | Revision 1.5 2000/06/09 11:10:07 cblume |
64 | Compiler warnings and coding conventions, next round | |
65 | ||
dd9a6ee3 | 66 | Revision 1.4 2000/06/08 18:32:58 cblume |
67 | Make code compliant to coding conventions | |
68 | ||
8230f242 | 69 | Revision 1.3 2000/06/07 16:27:01 cblume |
70 | Try to remove compiler warnings on Sun and HP | |
71 | ||
9d0b222b | 72 | Revision 1.2 2000/05/08 16:17:27 cblume |
73 | Merge TRD-develop | |
74 | ||
6f1e466d | 75 | Revision 1.1.2.1 2000/05/08 14:44:01 cblume |
76 | Add new class AliTRDdigitsManager | |
77 | ||
78 | */ | |
79 | ||
80 | /////////////////////////////////////////////////////////////////////////////// | |
81 | // // | |
82 | // Manages the digits and the track dictionary in the form of // | |
83 | // AliTRDdataArray objects. // | |
84 | // // | |
85 | /////////////////////////////////////////////////////////////////////////////// | |
6244debe | 86 | |
2ab0c725 | 87 | #include <iostream.h> |
793ff80c | 88 | |
2ab0c725 | 89 | #include <TROOT.h> |
793ff80c | 90 | #include <TTree.h> |
2ab0c725 | 91 | #include <TFile.h> |
94de3818 | 92 | |
6f1e466d | 93 | #include "AliRun.h" |
94 | ||
95 | #include "AliTRDdigitsManager.h" | |
793ff80c | 96 | #include "AliTRDsegmentArray.h" |
97 | #include "AliTRDdataArrayI.h" | |
98 | #include "AliTRDdigit.h" | |
99 | #include "AliTRDgeometry.h" | |
9e1a0ddb | 100 | #include "AliTRD.h" |
6f1e466d | 101 | |
102 | ClassImp(AliTRDdigitsManager) | |
103 | ||
793ff80c | 104 | //_____________________________________________________________________________ |
105 | ||
106 | // Number of track dictionary arrays | |
107 | const Int_t AliTRDdigitsManager::fgkNDict = kNDict; | |
108 | ||
6f1e466d | 109 | //_____________________________________________________________________________ |
110 | AliTRDdigitsManager::AliTRDdigitsManager():TObject() | |
111 | { | |
112 | // | |
113 | // Default constructor | |
114 | // | |
115 | ||
abaf1f1d | 116 | fIsRaw = kFALSE; |
117 | fEvent = 0; | |
855bfffd | 118 | fDebug = 0; |
abaf1f1d | 119 | fSDigits = 0; |
6f1e466d | 120 | |
abaf1f1d | 121 | fFile = NULL; |
122 | fTree = NULL; | |
123 | fDigits = NULL; | |
6f1e466d | 124 | for (Int_t iDict = 0; iDict < kNDict; iDict++) { |
abaf1f1d | 125 | fDictionary[iDict] = NULL; |
6f1e466d | 126 | } |
127 | ||
128 | } | |
129 | ||
8230f242 | 130 | //_____________________________________________________________________________ |
dd9a6ee3 | 131 | AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m) |
8230f242 | 132 | { |
133 | // | |
134 | // AliTRDdigitsManager copy constructor | |
135 | // | |
136 | ||
dd9a6ee3 | 137 | ((AliTRDdigitsManager &) m).Copy(*this); |
8230f242 | 138 | |
139 | } | |
140 | ||
6f1e466d | 141 | //_____________________________________________________________________________ |
142 | AliTRDdigitsManager::~AliTRDdigitsManager() | |
143 | { | |
8230f242 | 144 | // |
145 | // AliTRDdigitsManager destructor | |
146 | // | |
6f1e466d | 147 | |
abaf1f1d | 148 | if (fFile) { |
149 | fFile->Close(); | |
150 | delete fFile; | |
151 | fFile = NULL; | |
152 | } | |
153 | ||
6f1e466d | 154 | if (fDigits) { |
155 | fDigits->Delete(); | |
156 | delete fDigits; | |
abaf1f1d | 157 | fDigits = NULL; |
6f1e466d | 158 | } |
159 | ||
160 | for (Int_t iDict = 0; iDict < kNDict; iDict++) { | |
161 | fDictionary[iDict]->Delete(); | |
162 | delete fDictionary[iDict]; | |
abaf1f1d | 163 | fDictionary[iDict] = NULL; |
6f1e466d | 164 | } |
165 | ||
166 | } | |
167 | ||
8230f242 | 168 | //_____________________________________________________________________________ |
dd9a6ee3 | 169 | void AliTRDdigitsManager::Copy(TObject &m) |
8230f242 | 170 | { |
171 | // | |
172 | // Copy function | |
173 | // | |
174 | ||
abaf1f1d | 175 | ((AliTRDdigitsManager &) m).fIsRaw = fIsRaw; |
176 | ((AliTRDdigitsManager &) m).fEvent = fEvent; | |
855bfffd | 177 | ((AliTRDdigitsManager &) m).fDebug = fDebug; |
abaf1f1d | 178 | ((AliTRDdigitsManager &) m).fSDigits = fSDigits; |
8230f242 | 179 | |
180 | TObject::Copy(m); | |
181 | ||
182 | } | |
183 | ||
abaf1f1d | 184 | //_____________________________________________________________________________ |
185 | void AliTRDdigitsManager::CreateArrays() | |
186 | { | |
187 | // | |
188 | // Create the data arrays | |
189 | // | |
190 | ||
191 | fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet()); | |
192 | ||
193 | for (Int_t iDict = 0; iDict < kNDict; iDict++) { | |
194 | fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI" | |
195 | ,AliTRDgeometry::Ndet()); | |
196 | } | |
197 | ||
198 | } | |
199 | ||
6f1e466d | 200 | //_____________________________________________________________________________ |
201 | void AliTRDdigitsManager::SetRaw() | |
202 | { | |
0a29d0f1 | 203 | // |
204 | // Switch on the raw digits flag | |
205 | // | |
6f1e466d | 206 | |
207 | fIsRaw = kTRUE; | |
208 | ||
793ff80c | 209 | fDigits->SetBit(AliTRDdigit::RawDigit()); |
6f1e466d | 210 | |
211 | } | |
212 | ||
16bf9884 | 213 | //_____________________________________________________________________________ |
214 | Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time | |
215 | , Int_t det) const | |
216 | { | |
217 | // | |
218 | // Returns the amplitude of a digit | |
219 | // | |
220 | ||
221 | return ((Short_t) GetDigits(det)->GetData(row,col,time)); | |
222 | ||
223 | } | |
224 | ||
6f1e466d | 225 | //_____________________________________________________________________________ |
855bfffd | 226 | Bool_t AliTRDdigitsManager::Open(const Char_t *file) |
6f1e466d | 227 | { |
228 | // | |
abaf1f1d | 229 | // Opens the file for the TRD digits |
230 | // | |
231 | ||
855bfffd | 232 | fFile = (TFile*) gROOT->GetListOfFiles()->FindObject(file); |
abaf1f1d | 233 | if (!fFile) { |
855bfffd | 234 | if (fDebug > 0) { |
235 | printf("<AliTRDdigitsManager::Open> "); | |
236 | printf("Open the AliROOT-file %s.\n",file); | |
abaf1f1d | 237 | } |
855bfffd | 238 | fFile = new TFile(file,"UPDATE"); |
abaf1f1d | 239 | if (!fFile) return kFALSE; |
240 | } | |
241 | else { | |
855bfffd | 242 | if (fDebug > 0) { |
243 | printf("<AliTRDdigitsManager::Open> "); | |
244 | printf("%s is already open.\n",file); | |
abaf1f1d | 245 | } |
246 | } | |
247 | ||
248 | return kTRUE; | |
249 | ||
250 | } | |
251 | ||
8e64dd77 | 252 | //_____________________________________________________________________________ |
253 | void AliTRDdigitsManager::MakeTreeAndBranches(TFile *file, Int_t iEvent) | |
254 | { | |
255 | // | |
256 | // Creates tree for (s)digits in the specified file | |
257 | // | |
258 | ||
259 | fEvent = iEvent; | |
260 | TDirectory *wd = gDirectory; | |
261 | file->cd(); | |
262 | MakeBranch(); | |
263 | wd->cd(); | |
264 | ||
265 | } | |
266 | ||
abaf1f1d | 267 | //_____________________________________________________________________________ |
268 | Bool_t AliTRDdigitsManager::MakeBranch(const Char_t *file) | |
269 | { | |
270 | // | |
271 | // Creates the tree and branches for the digits and the dictionary | |
6f1e466d | 272 | // |
273 | ||
abaf1f1d | 274 | // Create the TRD digits tree |
855bfffd | 275 | TTree *tree; |
abaf1f1d | 276 | Char_t treeName[12]; |
277 | if (fSDigits) { | |
278 | sprintf(treeName,"TreeS%d_TRD",fEvent); | |
855bfffd | 279 | tree = new TTree(treeName,"TRD SDigits"); |
abaf1f1d | 280 | } |
281 | else { | |
282 | sprintf(treeName,"TreeD%d_TRD",fEvent); | |
855bfffd | 283 | tree = new TTree(treeName,"TRD Digits"); |
abaf1f1d | 284 | } |
9e1a0ddb | 285 | |
855bfffd | 286 | if (fDebug > 0) { |
287 | printf("<AliTRDdigitsManager::MakeBranch> "); | |
abaf1f1d | 288 | printf("Creating tree %s\n",treeName); |
289 | } | |
6f1e466d | 290 | |
855bfffd | 291 | return MakeBranch(tree,file); |
292 | ||
293 | } | |
294 | ||
295 | //_____________________________________________________________________________ | |
296 | Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree, const Char_t *file) | |
297 | { | |
298 | // | |
299 | // Creates the tree and branches for the digits and the dictionary | |
300 | // | |
301 | ||
302 | Int_t buffersize = 64000; | |
303 | ||
304 | Bool_t status = kTRUE; | |
305 | ||
306 | AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD") ; | |
307 | ||
308 | if (tree) { | |
309 | fTree = tree; | |
310 | } | |
311 | ||
abaf1f1d | 312 | // Make the branch for the digits |
313 | if (fDigits) { | |
314 | const AliTRDdataArray *kDigits = (AliTRDdataArray *) fDigits->At(0); | |
315 | if (kDigits) { | |
316 | trd->MakeBranchInTree(fTree,"TRDdigits",kDigits->IsA()->GetName() | |
317 | ,&kDigits,buffersize,99,file); | |
855bfffd | 318 | if (fDebug > 0) { |
319 | printf("<AliTRDdigitsManager::MakeBranch> "); | |
6f1e466d | 320 | printf("Making branch TRDdigits\n"); |
321 | } | |
6f1e466d | 322 | } |
323 | else { | |
324 | status = kFALSE; | |
325 | } | |
abaf1f1d | 326 | } |
327 | else { | |
328 | status = kFALSE; | |
329 | } | |
6f1e466d | 330 | |
abaf1f1d | 331 | // Make the branches for the dictionaries |
332 | for (Int_t iDict = 0; iDict < kNDict; iDict++) { | |
333 | Char_t branchname[15]; | |
334 | sprintf(branchname,"TRDdictionary%d",iDict); | |
335 | if (fDictionary[iDict]) { | |
336 | const AliTRDdataArray *kDictionary = | |
337 | (AliTRDdataArray *) fDictionary[iDict]->At(0); | |
338 | if (kDictionary) { | |
339 | trd->MakeBranchInTree(fTree,branchname,kDictionary->IsA()->GetName() | |
340 | ,&kDictionary,buffersize,99,file); | |
855bfffd | 341 | if (fDebug > 0) { |
342 | printf("<AliTRDdigitsManager::MakeBranch> "); | |
6f1e466d | 343 | printf("Making branch %s\n",branchname); |
6244debe | 344 | } |
6f1e466d | 345 | } |
346 | else { | |
347 | status = kFALSE; | |
348 | } | |
349 | } | |
abaf1f1d | 350 | else { |
351 | status = kFALSE; | |
352 | } | |
6f1e466d | 353 | } |
354 | ||
355 | return status; | |
356 | ||
357 | } | |
358 | ||
359 | //_____________________________________________________________________________ | |
855bfffd | 360 | Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree) |
6f1e466d | 361 | { |
8230f242 | 362 | // |
363 | // Reads the digit information from the input file | |
364 | // | |
6f1e466d | 365 | |
366 | Bool_t status = kTRUE; | |
367 | ||
855bfffd | 368 | if (tree) { |
369 | ||
370 | fTree = tree; | |
371 | ||
abaf1f1d | 372 | } |
373 | else { | |
855bfffd | 374 | |
375 | // Get the digits tree | |
376 | Char_t treeName[12]; | |
377 | if (fSDigits) { | |
378 | sprintf(treeName,"TreeS%d_TRD",fEvent); | |
abaf1f1d | 379 | } |
855bfffd | 380 | else { |
381 | sprintf(treeName,"TreeD%d_TRD",fEvent); | |
382 | } | |
383 | if (fFile) { | |
384 | fTree = (TTree *) fFile->Get(treeName); | |
385 | } | |
386 | else { | |
387 | fTree = (TTree *) gDirectory->Get(treeName); | |
388 | } | |
389 | ||
390 | if (!fTree) { | |
391 | if (fDebug > 0) { | |
392 | printf("<AliTRDdigitsManager::ReadDigits> "); | |
393 | printf("Could not find tree %s.\n",treeName); | |
394 | } | |
395 | return kFALSE; | |
396 | } | |
397 | ||
abaf1f1d | 398 | } |
399 | ||
400 | if (!fDigits) { | |
855bfffd | 401 | if (fDebug > 0) { |
402 | printf("<AliTRDdigitsManager::ReadDigits> "); | |
abaf1f1d | 403 | printf("Create the data arrays.\n"); |
404 | } | |
405 | CreateArrays(); | |
406 | } | |
407 | ||
408 | status = fDigits->LoadArray("TRDdigits",fTree); | |
6f1e466d | 409 | |
410 | for (Int_t iDict = 0; iDict < kNDict; iDict++) { | |
411 | Char_t branchname[15]; | |
412 | sprintf(branchname,"TRDdictionary%d",iDict); | |
abaf1f1d | 413 | status = fDictionary[iDict]->LoadArray(branchname,fTree); |
6f1e466d | 414 | } |
415 | ||
793ff80c | 416 | if (fDigits->TestBit(AliTRDdigit::RawDigit())) { |
6f1e466d | 417 | fIsRaw = kTRUE; |
418 | } | |
419 | else { | |
420 | fIsRaw = kFALSE; | |
421 | } | |
422 | ||
423 | return kTRUE; | |
424 | ||
425 | } | |
426 | ||
427 | //_____________________________________________________________________________ | |
428 | Bool_t AliTRDdigitsManager::WriteDigits() | |
429 | { | |
430 | // | |
431 | // Writes out the TRD-digits and the dictionaries | |
432 | // | |
433 | ||
6f1e466d | 434 | // Store the contents of the segment array in the tree |
abaf1f1d | 435 | if (!fDigits->StoreArray("TRDdigits",fTree)) { |
855bfffd | 436 | printf("<AliTRDdigitsManager::WriteDigits> "); |
6f1e466d | 437 | printf("Error while storing digits in branch TRDdigits\n"); |
438 | return kFALSE; | |
439 | } | |
440 | for (Int_t iDict = 0; iDict < kNDict; iDict++) { | |
441 | Char_t branchname[15]; | |
442 | sprintf(branchname,"TRDdictionary%d",iDict); | |
abaf1f1d | 443 | if (!fDictionary[iDict]->StoreArray(branchname,fTree)) { |
855bfffd | 444 | printf("<AliTRDdigitsManager::WriteDigits> "); |
6f1e466d | 445 | printf("Error while storing dictionary in branch %s\n",branchname); |
446 | return kFALSE; | |
447 | } | |
448 | } | |
449 | ||
abaf1f1d | 450 | // Write the new tree to the output file |
8e64dd77 | 451 | //fTree->Write(); |
452 | fTree->AutoSave(); // Modification by Jiri | |
abaf1f1d | 453 | |
6f1e466d | 454 | return kTRUE; |
455 | ||
456 | } | |
9d0b222b | 457 | |
458 | //_____________________________________________________________________________ | |
459 | AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row, Int_t col | |
793ff80c | 460 | , Int_t time, Int_t det) const |
9d0b222b | 461 | { |
462 | // | |
463 | // Creates a single digit object | |
464 | // | |
465 | ||
466 | Int_t digits[4]; | |
467 | Int_t amp[1]; | |
468 | ||
469 | digits[0] = det; | |
470 | digits[1] = row; | |
471 | digits[2] = col; | |
472 | digits[3] = time; | |
473 | ||
474 | amp[0] = GetDigits(det)->GetData(row,col,time); | |
475 | ||
476 | return (new AliTRDdigit(fIsRaw,digits,amp)); | |
477 | ||
478 | } | |
479 | ||
480 | //_____________________________________________________________________________ | |
481 | Int_t AliTRDdigitsManager::GetTrack(Int_t track | |
482 | , Int_t row, Int_t col, Int_t time | |
793ff80c | 483 | , Int_t det) const |
9d0b222b | 484 | { |
485 | // | |
486 | // Returns the MC-track numbers from the dictionary. | |
487 | // | |
488 | ||
489 | if ((track < 0) || (track >= kNDict)) { | |
490 | TObject::Error("GetTracks" | |
491 | ,"track %d out of bounds (size: %d, this: 0x%08x)" | |
492 | ,track,kNDict,this); | |
493 | return -1; | |
494 | } | |
495 | ||
496 | // Array contains index+1 to allow data compression | |
497 | return (GetDictionary(det,track)->GetData(row,col,time) - 1); | |
498 | ||
499 | } | |
500 | ||
dd9a6ee3 | 501 | //_____________________________________________________________________________ |
793ff80c | 502 | AliTRDdataArrayI *AliTRDdigitsManager::GetDigits(Int_t det) const |
dd9a6ee3 | 503 | { |
504 | // | |
505 | // Returns the digits array for one detector | |
506 | // | |
507 | ||
508 | return (AliTRDdataArrayI *) fDigits->At(det); | |
509 | ||
510 | } | |
511 | ||
512 | //_____________________________________________________________________________ | |
793ff80c | 513 | AliTRDdataArrayI *AliTRDdigitsManager::GetDictionary(Int_t det, Int_t i) const |
dd9a6ee3 | 514 | { |
515 | // | |
516 | // Returns the dictionary for one detector | |
517 | // | |
518 | ||
519 | return (AliTRDdataArrayI *) fDictionary[i]->At(det); | |
520 | ||
521 | } | |
522 | ||
523 | //_____________________________________________________________________________ | |
793ff80c | 524 | Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *Digit) const |
dd9a6ee3 | 525 | { |
526 | // | |
527 | // Returns the MC-track numbers from the dictionary for a given digit | |
528 | // | |
529 | ||
530 | Int_t row = Digit->GetRow(); | |
531 | Int_t col = Digit->GetCol(); | |
532 | Int_t time = Digit->GetTime(); | |
533 | Int_t det = Digit->GetDetector(); | |
534 | ||
535 | return GetTrack(track,row,col,time,det); | |
536 | ||
537 | } | |
538 | ||
539 | //_____________________________________________________________________________ | |
540 | AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m) | |
541 | { | |
542 | // | |
543 | // Assignment operator | |
544 | // | |
545 | ||
546 | if (this != &m) ((AliTRDdigitsManager &) m).Copy(*this); | |
547 | return *this; | |
548 | ||
549 | } |