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