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