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.17 2002/03/28 14:59:07 cblume
21 Revision 1.16 2002/02/12 11:42:08 cblume
22 Remove fTree from destructor
24 Revision 1.15 2002/02/11 14:27:54 cblume
25 Geometry and hit structure update
27 Revision 1.14 2001/11/14 10:50:46 cblume
28 Changes in digits IO. Add merging of summable digits
30 Revision 1.13 2001/11/06 17:19:41 cblume
31 Add detailed geometry and simple simulator
33 Revision 1.12 2001/05/16 14:57:28 alibrary
34 New files for folders and Stack
36 Revision 1.11 2001/03/13 09:30:35 cblume
37 Update of digitization. Moved digit branch definition to AliTRD
39 Revision 1.10 2001/01/26 19:56:57 hristov
40 Major upgrade of AliRoot code
42 Revision 1.9 2000/11/02 09:25:53 cblume
43 Change also the dictionary to AliTRDdataArray
45 Revision 1.8 2000/11/01 15:20:13 cblume
46 Change AliTRDdataArrayI to AliTRDdataArray in MakeBranch()
48 Revision 1.7 2000/11/01 14:53:20 cblume
49 Merge with TRD-develop
51 Revision 1.1.2.5 2000/10/17 02:27:34 cblume
52 Get rid of global constants
54 Revision 1.1.2.4 2000/10/15 23:40:01 cblume
57 Revision 1.1.2.3 2000/10/06 16:49:46 cblume
60 Revision 1.1.2.2 2000/10/04 16:34:58 cblume
61 Replace include files by forward declarations
63 Revision 1.5 2000/06/09 11:10:07 cblume
64 Compiler warnings and coding conventions, next round
66 Revision 1.4 2000/06/08 18:32:58 cblume
67 Make code compliant to coding conventions
69 Revision 1.3 2000/06/07 16:27:01 cblume
70 Try to remove compiler warnings on Sun and HP
72 Revision 1.2 2000/05/08 16:17:27 cblume
75 Revision 1.1.2.1 2000/05/08 14:44:01 cblume
76 Add new class AliTRDdigitsManager
80 ///////////////////////////////////////////////////////////////////////////////
82 // Manages the digits and the track dictionary in the form of //
83 // AliTRDdataArray objects. //
85 ///////////////////////////////////////////////////////////////////////////////
95 #include "AliTRDdigitsManager.h"
96 #include "AliTRDsegmentArray.h"
97 #include "AliTRDdataArrayI.h"
98 #include "AliTRDdigit.h"
99 #include "AliTRDgeometry.h"
102 ClassImp(AliTRDdigitsManager)
104 //_____________________________________________________________________________
106 // Number of track dictionary arrays
107 const Int_t AliTRDdigitsManager::fgkNDict = kNDict;
109 //_____________________________________________________________________________
110 AliTRDdigitsManager::AliTRDdigitsManager():TObject()
113 // Default constructor
124 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
125 fDictionary[iDict] = NULL;
130 //_____________________________________________________________________________
131 AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
134 // AliTRDdigitsManager copy constructor
137 ((AliTRDdigitsManager &) m).Copy(*this);
141 //_____________________________________________________________________________
142 AliTRDdigitsManager::~AliTRDdigitsManager()
145 // AliTRDdigitsManager destructor
160 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
161 fDictionary[iDict]->Delete();
162 delete fDictionary[iDict];
163 fDictionary[iDict] = NULL;
168 //_____________________________________________________________________________
169 void AliTRDdigitsManager::Copy(TObject &m)
175 ((AliTRDdigitsManager &) m).fIsRaw = fIsRaw;
176 ((AliTRDdigitsManager &) m).fEvent = fEvent;
177 ((AliTRDdigitsManager &) m).fDebug = fDebug;
178 ((AliTRDdigitsManager &) m).fSDigits = fSDigits;
184 //_____________________________________________________________________________
185 void AliTRDdigitsManager::CreateArrays()
188 // Create the data arrays
191 fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
193 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
194 fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
195 ,AliTRDgeometry::Ndet());
200 //_____________________________________________________________________________
201 void AliTRDdigitsManager::SetRaw()
204 // Switch on the raw digits flag
209 fDigits->SetBit(AliTRDdigit::RawDigit());
213 //_____________________________________________________________________________
214 Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time
218 // Returns the amplitude of a digit
221 return ((Short_t) GetDigits(det)->GetData(row,col,time));
225 //_____________________________________________________________________________
226 Bool_t AliTRDdigitsManager::Open(const Char_t *file)
229 // Opens the file for the TRD digits
232 fFile = (TFile*) gROOT->GetListOfFiles()->FindObject(file);
235 printf("<AliTRDdigitsManager::Open> ");
236 printf("Open the AliROOT-file %s.\n",file);
238 fFile = new TFile(file,"UPDATE");
239 if (!fFile) return kFALSE;
243 printf("<AliTRDdigitsManager::Open> ");
244 printf("%s is already open.\n",file);
252 //_____________________________________________________________________________
253 void AliTRDdigitsManager::MakeTreeAndBranches(TFile *file, Int_t iEvent)
256 // Creates tree for (s)digits in the specified file
260 TDirectory *wd = gDirectory;
267 //_____________________________________________________________________________
268 Bool_t AliTRDdigitsManager::MakeBranch(const Char_t *file)
271 // Creates the tree and branches for the digits and the dictionary
274 // Create the TRD digits tree
278 sprintf(treeName,"TreeS%d_TRD",fEvent);
279 tree = new TTree(treeName,"TRD SDigits");
282 sprintf(treeName,"TreeD%d_TRD",fEvent);
283 tree = new TTree(treeName,"TRD Digits");
287 printf("<AliTRDdigitsManager::MakeBranch> ");
288 printf("Creating tree %s\n",treeName);
291 return MakeBranch(tree,file);
295 //_____________________________________________________________________________
296 Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree, const Char_t *file)
299 // Creates the tree and branches for the digits and the dictionary
302 Int_t buffersize = 64000;
304 Bool_t status = kTRUE;
306 AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD") ;
312 // Make the branch for the digits
314 const AliTRDdataArray *kDigits = (AliTRDdataArray *) fDigits->At(0);
316 trd->MakeBranchInTree(fTree,"TRDdigits",kDigits->IsA()->GetName()
317 ,&kDigits,buffersize,99,file);
319 printf("<AliTRDdigitsManager::MakeBranch> ");
320 printf("Making branch TRDdigits\n");
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);
339 trd->MakeBranchInTree(fTree,branchname,kDictionary->IsA()->GetName()
340 ,&kDictionary,buffersize,99,file);
342 printf("<AliTRDdigitsManager::MakeBranch> ");
343 printf("Making branch %s\n",branchname);
359 //_____________________________________________________________________________
360 Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree)
363 // Reads the digit information from the input file
366 Bool_t status = kTRUE;
375 // Get the digits tree
378 sprintf(treeName,"TreeS%d_TRD",fEvent);
381 sprintf(treeName,"TreeD%d_TRD",fEvent);
384 fTree = (TTree *) fFile->Get(treeName);
387 fTree = (TTree *) gDirectory->Get(treeName);
392 printf("<AliTRDdigitsManager::ReadDigits> ");
393 printf("Could not find tree %s.\n",treeName);
402 printf("<AliTRDdigitsManager::ReadDigits> ");
403 printf("Create the data arrays.\n");
408 status = fDigits->LoadArray("TRDdigits",fTree);
410 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
411 Char_t branchname[15];
412 sprintf(branchname,"TRDdictionary%d",iDict);
413 status = fDictionary[iDict]->LoadArray(branchname,fTree);
416 if (fDigits->TestBit(AliTRDdigit::RawDigit())) {
427 //_____________________________________________________________________________
428 Bool_t AliTRDdigitsManager::WriteDigits()
431 // Writes out the TRD-digits and the dictionaries
434 // Store the contents of the segment array in the tree
435 if (!fDigits->StoreArray("TRDdigits",fTree)) {
436 printf("<AliTRDdigitsManager::WriteDigits> ");
437 printf("Error while storing digits in branch TRDdigits\n");
440 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
441 Char_t branchname[15];
442 sprintf(branchname,"TRDdictionary%d",iDict);
443 if (!fDictionary[iDict]->StoreArray(branchname,fTree)) {
444 printf("<AliTRDdigitsManager::WriteDigits> ");
445 printf("Error while storing dictionary in branch %s\n",branchname);
450 // Write the new tree to the output file
452 fTree->AutoSave(); // Modification by Jiri
458 //_____________________________________________________________________________
459 AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row, Int_t col
460 , Int_t time, Int_t det) const
463 // Creates a single digit object
474 amp[0] = GetDigits(det)->GetData(row,col,time);
476 return (new AliTRDdigit(fIsRaw,digits,amp));
480 //_____________________________________________________________________________
481 Int_t AliTRDdigitsManager::GetTrack(Int_t track
482 , Int_t row, Int_t col, Int_t time
486 // Returns the MC-track numbers from the dictionary.
489 if ((track < 0) || (track >= kNDict)) {
490 TObject::Error("GetTracks"
491 ,"track %d out of bounds (size: %d, this: 0x%08x)"
496 // Array contains index+1 to allow data compression
497 return (GetDictionary(det,track)->GetData(row,col,time) - 1);
501 //_____________________________________________________________________________
502 AliTRDdataArrayI *AliTRDdigitsManager::GetDigits(Int_t det) const
505 // Returns the digits array for one detector
508 return (AliTRDdataArrayI *) fDigits->At(det);
512 //_____________________________________________________________________________
513 AliTRDdataArrayI *AliTRDdigitsManager::GetDictionary(Int_t det, Int_t i) const
516 // Returns the dictionary for one detector
519 return (AliTRDdataArrayI *) fDictionary[i]->At(det);
523 //_____________________________________________________________________________
524 Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *Digit) const
527 // Returns the MC-track numbers from the dictionary for a given digit
530 Int_t row = Digit->GetRow();
531 Int_t col = Digit->GetCol();
532 Int_t time = Digit->GetTime();
533 Int_t det = Digit->GetDetector();
535 return GetTrack(track,row,col,time,det);
539 //_____________________________________________________________________________
540 AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
543 // Assignment operator
546 if (this != &m) ((AliTRDdigitsManager &) m).Copy(*this);