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