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.21 2003/02/04 17:26:00 cblume
19 Include a reset of the digits arrays in order to process several events
21 Revision 1.20 2002/10/22 15:53:08 alibrary
22 Introducing Riostream.h
24 Revision 1.19 2002/10/14 14:57:43 hristov
25 Merging the VirtualMC branch to the main development branch (HEAD)
27 Revision 1.16.6.2 2002/07/24 10:09:30 alibrary
30 Revision 1.16.6.1 2002/06/10 15:28:58 hristov
33 Revision 1.18 2002/04/12 12:13:23 cblume
36 Revision 1.17 2002/03/28 14:59:07 cblume
39 Revision 1.18 2002/04/12 12:13:23 cblume
42 Revision 1.17 2002/03/28 14:59:07 cblume
45 Revision 1.16 2002/02/12 11:42:08 cblume
46 Remove fTree from destructor
48 Revision 1.15 2002/02/11 14:27:54 cblume
49 Geometry and hit structure update
51 Revision 1.14 2001/11/14 10:50:46 cblume
52 Changes in digits IO. Add merging of summable digits
54 Revision 1.13 2001/11/06 17:19:41 cblume
55 Add detailed geometry and simple simulator
57 Revision 1.12 2001/05/16 14:57:28 alibrary
58 New files for folders and Stack
60 Revision 1.11 2001/03/13 09:30:35 cblume
61 Update of digitization. Moved digit branch definition to AliTRD
63 Revision 1.10 2001/01/26 19:56:57 hristov
64 Major upgrade of AliRoot code
66 Revision 1.9 2000/11/02 09:25:53 cblume
67 Change also the dictionary to AliTRDdataArray
69 Revision 1.8 2000/11/01 15:20:13 cblume
70 Change AliTRDdataArrayI to AliTRDdataArray in MakeBranch()
72 Revision 1.7 2000/11/01 14:53:20 cblume
73 Merge with TRD-develop
75 Revision 1.1.2.5 2000/10/17 02:27:34 cblume
76 Get rid of global constants
78 Revision 1.1.2.4 2000/10/15 23:40:01 cblume
81 Revision 1.1.2.3 2000/10/06 16:49:46 cblume
84 Revision 1.1.2.2 2000/10/04 16:34:58 cblume
85 Replace include files by forward declarations
87 Revision 1.5 2000/06/09 11:10:07 cblume
88 Compiler warnings and coding conventions, next round
90 Revision 1.4 2000/06/08 18:32:58 cblume
91 Make code compliant to coding conventions
93 Revision 1.3 2000/06/07 16:27:01 cblume
94 Try to remove compiler warnings on Sun and HP
96 Revision 1.2 2000/05/08 16:17:27 cblume
99 Revision 1.1.2.1 2000/05/08 14:44:01 cblume
100 Add new class AliTRDdigitsManager
104 ///////////////////////////////////////////////////////////////////////////////
106 // Manages the digits and the track dictionary in the form of //
107 // AliTRDdataArray objects. //
109 ///////////////////////////////////////////////////////////////////////////////
111 #include <Riostream.h>
119 #include "AliTRDdigitsManager.h"
120 #include "AliTRDsegmentArray.h"
121 #include "AliTRDdataArrayI.h"
122 #include "AliTRDdigit.h"
123 #include "AliTRDgeometry.h"
126 ClassImp(AliTRDdigitsManager)
128 //_____________________________________________________________________________
130 // Number of track dictionary arrays
131 const Int_t AliTRDdigitsManager::fgkNDict = kNDict;
133 //_____________________________________________________________________________
134 AliTRDdigitsManager::AliTRDdigitsManager():TObject()
137 // Default constructor
146 fFileCreated = kFALSE;
149 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
150 fDictionary[iDict] = NULL;
155 //_____________________________________________________________________________
156 AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
159 // AliTRDdigitsManager copy constructor
162 ((AliTRDdigitsManager &) m).Copy(*this);
166 //_____________________________________________________________________________
167 AliTRDdigitsManager::~AliTRDdigitsManager()
170 // AliTRDdigitsManager destructor
173 if (fFile && fFileCreated) {
185 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
186 fDictionary[iDict]->Delete();
187 delete fDictionary[iDict];
188 fDictionary[iDict] = NULL;
193 //_____________________________________________________________________________
194 void AliTRDdigitsManager::Copy(TObject &m)
200 ((AliTRDdigitsManager &) m).fIsRaw = fIsRaw;
201 ((AliTRDdigitsManager &) m).fEvent = fEvent;
202 ((AliTRDdigitsManager &) m).fDebug = fDebug;
203 ((AliTRDdigitsManager &) m).fSDigits = fSDigits;
209 //_____________________________________________________________________________
210 void AliTRDdigitsManager::CreateArrays()
213 // Create the data arrays
216 fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
218 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
219 fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
220 ,AliTRDgeometry::Ndet());
224 //_____________________________________________________________________________
225 void AliTRDdigitsManager::ResetArrays()
228 // Reset the data arrays
234 fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
236 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
237 if (fDictionary[iDict]) {
238 delete fDictionary[iDict];
240 fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
241 ,AliTRDgeometry::Ndet());
246 //_____________________________________________________________________________
247 void AliTRDdigitsManager::SetRaw()
250 // Switch on the raw digits flag
255 fDigits->SetBit(AliTRDdigit::RawDigit());
259 //_____________________________________________________________________________
260 Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time
264 // Returns the amplitude of a digit
267 return ((Short_t) GetDigits(det)->GetData(row,col,time));
271 //_____________________________________________________________________________
272 Bool_t AliTRDdigitsManager::Open(const Char_t *file)
275 // Opens the file for the TRD digits
278 fFile = (TFile*) gROOT->GetListOfFiles()->FindObject(file);
281 printf("<AliTRDdigitsManager::Open> ");
282 printf("Open the AliROOT-file %s.\n",file);
284 fFile = new TFile(file,"UPDATE");
285 fFileCreated = kTRUE;
286 if (!fFile) return kFALSE;
290 printf("<AliTRDdigitsManager::Open> ");
291 printf("%s is already open.\n",file);
299 //_____________________________________________________________________________
300 void AliTRDdigitsManager::MakeTreeAndBranches(TFile *file, Int_t iEvent)
303 // Creates tree for (s)digits in the specified file
307 TDirectory *wd = gDirectory;
314 //_____________________________________________________________________________
315 Bool_t AliTRDdigitsManager::MakeBranch(const Char_t *file)
318 // Creates the tree and branches for the digits and the dictionary
321 // Create the TRD digits tree
325 sprintf(treeName,"TreeS%d_TRD",fEvent);
326 tree = new TTree(treeName,"TRD SDigits");
329 sprintf(treeName,"TreeD%d_TRD",fEvent);
330 tree = new TTree(treeName,"TRD Digits");
334 printf("<AliTRDdigitsManager::MakeBranch> ");
335 printf("Creating tree %s\n",treeName);
338 return MakeBranch(tree,file);
342 //_____________________________________________________________________________
343 Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree, const Char_t *file)
346 // Creates the tree and branches for the digits and the dictionary
349 Int_t buffersize = 64000;
351 Bool_t status = kTRUE;
353 AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD") ;
359 // Make the branch for the digits
361 const AliTRDdataArray *kDigits = (AliTRDdataArray *) fDigits->At(0);
363 trd->MakeBranchInTree(fTree,"TRDdigits",kDigits->IsA()->GetName()
364 ,&kDigits,buffersize,99,file);
366 printf("<AliTRDdigitsManager::MakeBranch> ");
367 printf("Making branch TRDdigits\n");
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);
386 trd->MakeBranchInTree(fTree,branchname,kDictionary->IsA()->GetName()
387 ,&kDictionary,buffersize,99,file);
389 printf("<AliTRDdigitsManager::MakeBranch> ");
390 printf("Making branch %s\n",branchname);
406 //_____________________________________________________________________________
407 Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree)
410 // Reads the digit information from the input file
413 Bool_t status = kTRUE;
422 // Get the digits tree
425 sprintf(treeName,"TreeS%d_TRD",fEvent);
428 sprintf(treeName,"TreeD%d_TRD",fEvent);
431 fTree = (TTree *) fFile->Get(treeName);
434 fTree = (TTree *) gDirectory->Get(treeName);
439 printf("<AliTRDdigitsManager::ReadDigits> ");
440 printf("Could not find tree %s.\n",treeName);
449 printf("<AliTRDdigitsManager::ReadDigits> ");
450 printf("Create the data arrays.\n");
455 status = fDigits->LoadArray("TRDdigits",fTree);
457 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
458 Char_t branchname[15];
459 sprintf(branchname,"TRDdictionary%d",iDict);
460 status = fDictionary[iDict]->LoadArray(branchname,fTree);
463 if (fDigits->TestBit(AliTRDdigit::RawDigit())) {
474 //_____________________________________________________________________________
475 Bool_t AliTRDdigitsManager::WriteDigits()
478 // Writes out the TRD-digits and the dictionaries
481 // Store the contents of the segment array in the tree
482 if (!fDigits->StoreArray("TRDdigits",fTree)) {
483 printf("<AliTRDdigitsManager::WriteDigits> ");
484 printf("Error while storing digits in branch TRDdigits\n");
487 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
488 Char_t branchname[15];
489 sprintf(branchname,"TRDdictionary%d",iDict);
490 if (!fDictionary[iDict]->StoreArray(branchname,fTree)) {
491 printf("<AliTRDdigitsManager::WriteDigits> ");
492 printf("Error while storing dictionary in branch %s\n",branchname);
497 // Write the new tree to the output file
499 fTree->AutoSave(); // Modification by Jiri
505 //_____________________________________________________________________________
506 AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row, Int_t col
507 , Int_t time, Int_t det) const
510 // Creates a single digit object
521 amp[0] = GetDigits(det)->GetData(row,col,time);
523 return (new AliTRDdigit(fIsRaw,digits,amp));
527 //_____________________________________________________________________________
528 Int_t AliTRDdigitsManager::GetTrack(Int_t track
529 , Int_t row, Int_t col, Int_t time
533 // Returns the MC-track numbers from the dictionary.
536 if ((track < 0) || (track >= kNDict)) {
537 TObject::Error("GetTracks"
538 ,"track %d out of bounds (size: %d, this: 0x%08x)"
543 // Array contains index+1 to allow data compression
544 return (GetDictionary(det,track)->GetData(row,col,time) - 1);
548 //_____________________________________________________________________________
549 AliTRDdataArrayI *AliTRDdigitsManager::GetDigits(Int_t det) const
552 // Returns the digits array for one detector
555 return (AliTRDdataArrayI *) fDigits->At(det);
559 //_____________________________________________________________________________
560 AliTRDdataArrayI *AliTRDdigitsManager::GetDictionary(Int_t det, Int_t i) const
563 // Returns the dictionary for one detector
566 return (AliTRDdataArrayI *) fDictionary[i]->At(det);
570 //_____________________________________________________________________________
571 Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *Digit) const
574 // Returns the MC-track numbers from the dictionary for a given digit
577 Int_t row = Digit->GetRow();
578 Int_t col = Digit->GetCol();
579 Int_t time = Digit->GetTime();
580 Int_t det = Digit->GetDetector();
582 return GetTrack(track,row,col,time,det);
586 //_____________________________________________________________________________
587 AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
590 // Assignment operator
593 if (this != &m) ((AliTRDdigitsManager &) m).Copy(*this);