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