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