1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.20 2002/10/22 15:53:08 alibrary
19 Introducing Riostream.h
21 Revision 1.19 2002/10/14 14:57:43 hristov
22 Merging the VirtualMC branch to the main development branch (HEAD)
24 Revision 1.16.6.2 2002/07/24 10:09:30 alibrary
27 Revision 1.16.6.1 2002/06/10 15:28:58 hristov
30 Revision 1.18 2002/04/12 12:13:23 cblume
33 Revision 1.17 2002/03/28 14:59:07 cblume
36 Revision 1.18 2002/04/12 12:13:23 cblume
39 Revision 1.17 2002/03/28 14:59:07 cblume
42 Revision 1.16 2002/02/12 11:42:08 cblume
43 Remove fTree from destructor
45 Revision 1.15 2002/02/11 14:27:54 cblume
46 Geometry and hit structure update
48 Revision 1.14 2001/11/14 10:50:46 cblume
49 Changes in digits IO. Add merging of summable digits
51 Revision 1.13 2001/11/06 17:19:41 cblume
52 Add detailed geometry and simple simulator
54 Revision 1.12 2001/05/16 14:57:28 alibrary
55 New files for folders and Stack
57 Revision 1.11 2001/03/13 09:30:35 cblume
58 Update of digitization. Moved digit branch definition to AliTRD
60 Revision 1.10 2001/01/26 19:56:57 hristov
61 Major upgrade of AliRoot code
63 Revision 1.9 2000/11/02 09:25:53 cblume
64 Change also the dictionary to AliTRDdataArray
66 Revision 1.8 2000/11/01 15:20:13 cblume
67 Change AliTRDdataArrayI to AliTRDdataArray in MakeBranch()
69 Revision 1.7 2000/11/01 14:53:20 cblume
70 Merge with TRD-develop
72 Revision 1.1.2.5 2000/10/17 02:27:34 cblume
73 Get rid of global constants
75 Revision 1.1.2.4 2000/10/15 23:40:01 cblume
78 Revision 1.1.2.3 2000/10/06 16:49:46 cblume
81 Revision 1.1.2.2 2000/10/04 16:34:58 cblume
82 Replace include files by forward declarations
84 Revision 1.5 2000/06/09 11:10:07 cblume
85 Compiler warnings and coding conventions, next round
87 Revision 1.4 2000/06/08 18:32:58 cblume
88 Make code compliant to coding conventions
90 Revision 1.3 2000/06/07 16:27:01 cblume
91 Try to remove compiler warnings on Sun and HP
93 Revision 1.2 2000/05/08 16:17:27 cblume
96 Revision 1.1.2.1 2000/05/08 14:44:01 cblume
97 Add new class AliTRDdigitsManager
101 ///////////////////////////////////////////////////////////////////////////////
103 // Manages the digits and the track dictionary in the form of //
104 // AliTRDdataArray objects. //
106 ///////////////////////////////////////////////////////////////////////////////
108 #include <Riostream.h>
116 #include "AliTRDdigitsManager.h"
117 #include "AliTRDsegmentArray.h"
118 #include "AliTRDdataArrayI.h"
119 #include "AliTRDdigit.h"
120 #include "AliTRDgeometry.h"
123 ClassImp(AliTRDdigitsManager)
125 //_____________________________________________________________________________
127 // Number of track dictionary arrays
128 const Int_t AliTRDdigitsManager::fgkNDict = kNDict;
130 //_____________________________________________________________________________
131 AliTRDdigitsManager::AliTRDdigitsManager():TObject()
134 // Default constructor
145 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
146 fDictionary[iDict] = NULL;
151 //_____________________________________________________________________________
152 AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
155 // AliTRDdigitsManager copy constructor
158 ((AliTRDdigitsManager &) m).Copy(*this);
162 //_____________________________________________________________________________
163 AliTRDdigitsManager::~AliTRDdigitsManager()
166 // AliTRDdigitsManager destructor
181 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
182 fDictionary[iDict]->Delete();
183 delete fDictionary[iDict];
184 fDictionary[iDict] = NULL;
189 //_____________________________________________________________________________
190 void AliTRDdigitsManager::Copy(TObject &m)
196 ((AliTRDdigitsManager &) m).fIsRaw = fIsRaw;
197 ((AliTRDdigitsManager &) m).fEvent = fEvent;
198 ((AliTRDdigitsManager &) m).fDebug = fDebug;
199 ((AliTRDdigitsManager &) m).fSDigits = fSDigits;
205 //_____________________________________________________________________________
206 void AliTRDdigitsManager::CreateArrays()
209 // Create the data arrays
212 fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
214 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
215 fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
216 ,AliTRDgeometry::Ndet());
220 //_____________________________________________________________________________
221 void AliTRDdigitsManager::ResetArrays()
224 // Reset the data arrays
230 fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
232 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
233 if (fDictionary[iDict]) {
234 delete fDictionary[iDict];
236 fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
237 ,AliTRDgeometry::Ndet());
242 //_____________________________________________________________________________
243 void AliTRDdigitsManager::SetRaw()
246 // Switch on the raw digits flag
251 fDigits->SetBit(AliTRDdigit::RawDigit());
255 //_____________________________________________________________________________
256 Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time
260 // Returns the amplitude of a digit
263 return ((Short_t) GetDigits(det)->GetData(row,col,time));
267 //_____________________________________________________________________________
268 Bool_t AliTRDdigitsManager::Open(const Char_t *file)
271 // Opens the file for the TRD digits
274 fFile = (TFile*) gROOT->GetListOfFiles()->FindObject(file);
277 printf("<AliTRDdigitsManager::Open> ");
278 printf("Open the AliROOT-file %s.\n",file);
280 fFile = new TFile(file,"UPDATE");
281 if (!fFile) return kFALSE;
285 printf("<AliTRDdigitsManager::Open> ");
286 printf("%s is already open.\n",file);
294 //_____________________________________________________________________________
295 void AliTRDdigitsManager::MakeTreeAndBranches(TFile *file, Int_t iEvent)
298 // Creates tree for (s)digits in the specified file
302 TDirectory *wd = gDirectory;
309 //_____________________________________________________________________________
310 Bool_t AliTRDdigitsManager::MakeBranch(const Char_t *file)
313 // Creates the tree and branches for the digits and the dictionary
316 // Create the TRD digits tree
320 sprintf(treeName,"TreeS%d_TRD",fEvent);
321 tree = new TTree(treeName,"TRD SDigits");
324 sprintf(treeName,"TreeD%d_TRD",fEvent);
325 tree = new TTree(treeName,"TRD Digits");
329 printf("<AliTRDdigitsManager::MakeBranch> ");
330 printf("Creating tree %s\n",treeName);
333 return MakeBranch(tree,file);
337 //_____________________________________________________________________________
338 Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree, const Char_t *file)
341 // Creates the tree and branches for the digits and the dictionary
344 Int_t buffersize = 64000;
346 Bool_t status = kTRUE;
348 AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD") ;
354 // Make the branch for the digits
356 const AliTRDdataArray *kDigits = (AliTRDdataArray *) fDigits->At(0);
358 trd->MakeBranchInTree(fTree,"TRDdigits",kDigits->IsA()->GetName()
359 ,&kDigits,buffersize,99,file);
361 printf("<AliTRDdigitsManager::MakeBranch> ");
362 printf("Making branch TRDdigits\n");
373 // Make the branches for the dictionaries
374 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
375 Char_t branchname[15];
376 sprintf(branchname,"TRDdictionary%d",iDict);
377 if (fDictionary[iDict]) {
378 const AliTRDdataArray *kDictionary =
379 (AliTRDdataArray *) fDictionary[iDict]->At(0);
381 trd->MakeBranchInTree(fTree,branchname,kDictionary->IsA()->GetName()
382 ,&kDictionary,buffersize,99,file);
384 printf("<AliTRDdigitsManager::MakeBranch> ");
385 printf("Making branch %s\n",branchname);
401 //_____________________________________________________________________________
402 Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree)
405 // Reads the digit information from the input file
408 Bool_t status = kTRUE;
417 // Get the digits tree
420 sprintf(treeName,"TreeS%d_TRD",fEvent);
423 sprintf(treeName,"TreeD%d_TRD",fEvent);
426 fTree = (TTree *) fFile->Get(treeName);
429 fTree = (TTree *) gDirectory->Get(treeName);
434 printf("<AliTRDdigitsManager::ReadDigits> ");
435 printf("Could not find tree %s.\n",treeName);
444 printf("<AliTRDdigitsManager::ReadDigits> ");
445 printf("Create the data arrays.\n");
450 status = fDigits->LoadArray("TRDdigits",fTree);
452 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
453 Char_t branchname[15];
454 sprintf(branchname,"TRDdictionary%d",iDict);
455 status = fDictionary[iDict]->LoadArray(branchname,fTree);
458 if (fDigits->TestBit(AliTRDdigit::RawDigit())) {
469 //_____________________________________________________________________________
470 Bool_t AliTRDdigitsManager::WriteDigits()
473 // Writes out the TRD-digits and the dictionaries
476 // Store the contents of the segment array in the tree
477 if (!fDigits->StoreArray("TRDdigits",fTree)) {
478 printf("<AliTRDdigitsManager::WriteDigits> ");
479 printf("Error while storing digits in branch TRDdigits\n");
482 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
483 Char_t branchname[15];
484 sprintf(branchname,"TRDdictionary%d",iDict);
485 if (!fDictionary[iDict]->StoreArray(branchname,fTree)) {
486 printf("<AliTRDdigitsManager::WriteDigits> ");
487 printf("Error while storing dictionary in branch %s\n",branchname);
492 // Write the new tree to the output file
494 fTree->AutoSave(); // Modification by Jiri
500 //_____________________________________________________________________________
501 AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row, Int_t col
502 , Int_t time, Int_t det) const
505 // Creates a single digit object
516 amp[0] = GetDigits(det)->GetData(row,col,time);
518 return (new AliTRDdigit(fIsRaw,digits,amp));
522 //_____________________________________________________________________________
523 Int_t AliTRDdigitsManager::GetTrack(Int_t track
524 , Int_t row, Int_t col, Int_t time
528 // Returns the MC-track numbers from the dictionary.
531 if ((track < 0) || (track >= kNDict)) {
532 TObject::Error("GetTracks"
533 ,"track %d out of bounds (size: %d, this: 0x%08x)"
538 // Array contains index+1 to allow data compression
539 return (GetDictionary(det,track)->GetData(row,col,time) - 1);
543 //_____________________________________________________________________________
544 AliTRDdataArrayI *AliTRDdigitsManager::GetDigits(Int_t det) const
547 // Returns the digits array for one detector
550 return (AliTRDdataArrayI *) fDigits->At(det);
554 //_____________________________________________________________________________
555 AliTRDdataArrayI *AliTRDdigitsManager::GetDictionary(Int_t det, Int_t i) const
558 // Returns the dictionary for one detector
561 return (AliTRDdataArrayI *) fDictionary[i]->At(det);
565 //_____________________________________________________________________________
566 Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *Digit) const
569 // Returns the MC-track numbers from the dictionary for a given digit
572 Int_t row = Digit->GetRow();
573 Int_t col = Digit->GetCol();
574 Int_t time = Digit->GetTime();
575 Int_t det = Digit->GetDetector();
577 return GetTrack(track,row,col,time,det);
581 //_____________________________________________________________________________
582 AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
585 // Assignment operator
588 if (this != &m) ((AliTRDdigitsManager &) m).Copy(*this);