]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDdigitsManager.cxx
Add detailed geometry and simple simulator
[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.12  2001/05/16 14:57:28  alibrary
19 New files for folders and Stack
20
21 Revision 1.11  2001/03/13 09:30:35  cblume
22 Update of digitization. Moved digit branch definition to AliTRD
23
24 Revision 1.10  2001/01/26 19:56:57  hristov
25 Major upgrade of AliRoot code
26
27 Revision 1.9  2000/11/02 09:25:53  cblume
28 Change also the dictionary to AliTRDdataArray
29
30 Revision 1.8  2000/11/01 15:20:13  cblume
31 Change AliTRDdataArrayI to AliTRDdataArray in MakeBranch()
32
33 Revision 1.7  2000/11/01 14:53:20  cblume
34 Merge with TRD-develop
35
36 Revision 1.1.2.5  2000/10/17 02:27:34  cblume
37 Get rid of global constants
38
39 Revision 1.1.2.4  2000/10/15 23:40:01  cblume
40 Remove AliTRDconst
41
42 Revision 1.1.2.3  2000/10/06 16:49:46  cblume
43 Made Getters const
44
45 Revision 1.1.2.2  2000/10/04 16:34:58  cblume
46 Replace include files by forward declarations
47
48 Revision 1.5  2000/06/09 11:10:07  cblume
49 Compiler warnings and coding conventions, next round
50
51 Revision 1.4  2000/06/08 18:32:58  cblume
52 Make code compliant to coding conventions
53
54 Revision 1.3  2000/06/07 16:27:01  cblume
55 Try to remove compiler warnings on Sun and HP
56
57 Revision 1.2  2000/05/08 16:17:27  cblume
58 Merge TRD-develop
59
60 Revision 1.1.2.1  2000/05/08 14:44:01  cblume
61 Add new class AliTRDdigitsManager
62
63 */
64
65 ///////////////////////////////////////////////////////////////////////////////
66 //                                                                           //
67 //  Manages the digits and the track dictionary in the form of               //
68 //  AliTRDdataArray objects.                                                 //
69 //                                                                           //
70 ///////////////////////////////////////////////////////////////////////////////
71
72 #include <iostream.h>
73  
74 #include <TROOT.h>
75 #include <TTree.h>                                                              
76 #include <TFile.h>
77
78 #include "AliRun.h"
79
80 #include "AliTRDdigitsManager.h"
81 #include "AliTRDsegmentArray.h"
82 #include "AliTRDdataArrayI.h"
83 #include "AliTRDdigit.h"
84 #include "AliTRDgeometry.h"
85 #include "AliTRD.h"
86
87 ClassImp(AliTRDdigitsManager)
88
89 //_____________________________________________________________________________
90
91   // Number of track dictionary arrays
92   const Int_t AliTRDdigitsManager::fgkNDict = kNDict;
93
94 //_____________________________________________________________________________
95 AliTRDdigitsManager::AliTRDdigitsManager():TObject()
96 {
97   //
98   // Default constructor
99   //
100
101   fIsRaw = kFALSE;
102
103   fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
104
105   for (Int_t iDict = 0; iDict < kNDict; iDict++) {
106     fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
107                                                ,AliTRDgeometry::Ndet());
108   }
109
110 }
111
112 //_____________________________________________________________________________
113 AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
114 {
115   //
116   // AliTRDdigitsManager copy constructor
117   //
118
119   ((AliTRDdigitsManager &) m).Copy(*this);
120
121 }
122
123 //_____________________________________________________________________________
124 AliTRDdigitsManager::~AliTRDdigitsManager()
125 {
126   //
127   // AliTRDdigitsManager destructor
128   //
129
130   if (fDigits) {
131     fDigits->Delete();
132     delete fDigits;
133   }
134
135   for (Int_t iDict = 0; iDict < kNDict; iDict++) {
136     fDictionary[iDict]->Delete();
137     delete fDictionary[iDict];
138   }
139
140 }
141
142 //_____________________________________________________________________________
143 void AliTRDdigitsManager::Copy(TObject &m)
144 {
145   //
146   // Copy function
147   //
148
149   ((AliTRDdigitsManager &) m).fIsRaw = fIsRaw;
150
151   TObject::Copy(m);
152
153 }
154
155 //_____________________________________________________________________________
156 void AliTRDdigitsManager::SetRaw()
157 {
158
159   fIsRaw = kTRUE;
160
161   fDigits->SetBit(AliTRDdigit::RawDigit());
162   
163 }
164
165 //_____________________________________________________________________________
166 Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time
167                                        , Int_t det) const
168 {
169   //
170   // Returns the amplitude of a digit
171   //
172
173   return ((Short_t) GetDigits(det)->GetData(row,col,time));
174
175 }
176  
177 //_____________________________________________________________________________
178 Bool_t AliTRDdigitsManager::MakeBranch(char *file)
179 {
180   //
181   // Creates the branches for the digits and the dictionary in the digits tree
182   //
183
184   Int_t buffersize = 64000;
185
186   Bool_t status = kTRUE;
187
188   //TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject("TRD.Digits.root");
189
190   AliTRD * TRD = (AliTRD *) gAlice->GetDetector("TRD") ;
191
192   if (gAlice->TreeD()) {
193
194     // Make the branch for the digits
195     if (fDigits) {
196       const AliTRDdataArray *kDigits = 
197            (AliTRDdataArray *) fDigits->At(0);
198       if (kDigits) {
199            TRD->MakeBranchInTree(gAlice->TreeD(), 
200                                 "TRDdigits", kDigits->IsA()->GetName(),
201                                 &kDigits,buffersize, 1,file);
202         printf("AliTRDdigitsManager::MakeBranch -- ");
203         printf("Making branch TRDdigits\n");
204       }
205       else {
206         status = kFALSE;
207       }
208     }
209     else {
210       status = kFALSE;
211     }
212
213     // Make the branches for the dictionaries
214     for (Int_t iDict = 0; iDict < kNDict; iDict++) {
215       Char_t branchname[15];
216       sprintf(branchname,"TRDdictionary%d",iDict);
217       if (fDictionary[iDict]) {
218         const AliTRDdataArray *kDictionary = 
219              (AliTRDdataArray *) fDictionary[iDict]->At(0);
220         if (kDictionary) {
221             TRD->MakeBranchInTree(gAlice->TreeD(), 
222                              branchname,kDictionary->IsA()->GetName(),
223                              &kDictionary,buffersize, 1,file);
224           printf("AliTRDdigitsManager::MakeBranch -- ");
225           printf("Making branch %s\n",branchname);
226         }
227         else {
228           status = kFALSE;
229         }
230       }
231       else {
232         status = kFALSE;
233       }
234     }
235
236   }
237   else {
238     status = kFALSE;
239   }
240
241   return status;
242
243 }
244
245 //_____________________________________________________________________________
246 Bool_t AliTRDdigitsManager::ReadDigits()
247 {
248   //
249   // Reads the digit information from the input file
250   //
251
252   Bool_t status = kTRUE;
253
254   status = fDigits->LoadArray("TRDdigits");
255
256   for (Int_t iDict = 0; iDict < kNDict; iDict++) {
257     Char_t branchname[15];
258     sprintf(branchname,"TRDdictionary%d",iDict);
259     status = fDictionary[iDict]->LoadArray(branchname);
260   }  
261
262   if (fDigits->TestBit(AliTRDdigit::RawDigit())) {
263     fIsRaw = kTRUE;
264   }
265   else {
266     fIsRaw = kFALSE;
267   }
268
269   return kTRUE;
270
271 }
272
273 //_____________________________________________________________________________
274 Bool_t AliTRDdigitsManager::WriteDigits()
275 {
276   //
277   // Writes out the TRD-digits and the dictionaries
278   //
279
280   // Create the branches
281   if (!(gAlice->TreeD()->GetBranch("TRDdigits"))) { 
282     printf("AliTRDdigitsManager::WriteDigits -- ");
283     printf("Call MakeBranch\n");
284     if (!MakeBranch()) return kFALSE;
285   }
286
287   // Store the contents of the segment array in the tree
288   if (!fDigits->StoreArray("TRDdigits")) {
289     printf("AliTRDdigitsManager::WriteDigits -- ");
290     printf("Error while storing digits in branch TRDdigits\n");
291     return kFALSE;
292   }
293   for (Int_t iDict = 0; iDict < kNDict; iDict++) {
294     Char_t branchname[15];
295     sprintf(branchname,"TRDdictionary%d",iDict);
296     if (!fDictionary[iDict]->StoreArray(branchname)) {
297       printf("AliTRDdigitsManager::WriteDigits -- ");
298       printf("Error while storing dictionary in branch %s\n",branchname);
299       return kFALSE;
300     }
301   }
302
303   return kTRUE;
304
305 }
306
307 //_____________________________________________________________________________
308 AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row, Int_t col
309                                          , Int_t time, Int_t det) const
310 {
311   // 
312   // Creates a single digit object 
313   //
314
315   Int_t digits[4];
316   Int_t amp[1];
317
318   digits[0] = det;
319   digits[1] = row;
320   digits[2] = col;
321   digits[3] = time;
322
323   amp[0]    = GetDigits(det)->GetData(row,col,time);
324   
325   return (new AliTRDdigit(fIsRaw,digits,amp));
326
327 }
328
329 //_____________________________________________________________________________
330 Int_t AliTRDdigitsManager::GetTrack(Int_t track
331                                   , Int_t row, Int_t col, Int_t time
332                                   , Int_t det) const
333 {
334   // 
335   // Returns the MC-track numbers from the dictionary.
336   //
337
338   if ((track < 0) || (track >= kNDict)) {
339     TObject::Error("GetTracks"
340                   ,"track %d out of bounds (size: %d, this: 0x%08x)"
341                   ,track,kNDict,this);
342     return -1;
343   }
344
345   // Array contains index+1 to allow data compression
346   return (GetDictionary(det,track)->GetData(row,col,time) - 1);
347
348 }
349
350 //_____________________________________________________________________________
351 AliTRDdataArrayI *AliTRDdigitsManager::GetDigits(Int_t det) const
352 {
353   //
354   // Returns the digits array for one detector
355   //
356
357   return (AliTRDdataArrayI *) fDigits->At(det);
358
359 }
360
361 //_____________________________________________________________________________
362 AliTRDdataArrayI *AliTRDdigitsManager::GetDictionary(Int_t det, Int_t i) const
363 {
364   //
365   // Returns the dictionary for one detector
366   //
367
368   return (AliTRDdataArrayI *) fDictionary[i]->At(det);
369
370 }
371
372 //_____________________________________________________________________________
373 Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *Digit) const
374 {
375   // 
376   // Returns the MC-track numbers from the dictionary for a given digit
377   //
378
379   Int_t row  = Digit->GetRow();
380   Int_t col  = Digit->GetCol();
381   Int_t time = Digit->GetTime();
382   Int_t det  = Digit->GetDetector();
383
384   return GetTrack(track,row,col,time,det);
385
386 }
387
388 //_____________________________________________________________________________
389 AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
390 {
391   //
392   // Assignment operator
393   //
394
395   if (this != &m) ((AliTRDdigitsManager &) m).Copy(*this);
396   return *this;
397
398 }