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