]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDdigitsManager.cxx
Reconstruction QA by Sylwester
[u/mrichter/AliRoot.git] / TRD / AliTRDdigitsManager.cxx
CommitLineData
6f1e466d 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
88cb7938 16/* $Id$ */
6f1e466d 17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// Manages the digits and the track dictionary in the form of //
21// AliTRDdataArray objects. //
22// //
23///////////////////////////////////////////////////////////////////////////////
6244debe 24
a2cb5b3d 25#include <Riostream.h>
793ff80c 26
2ab0c725 27#include <TROOT.h>
793ff80c 28#include <TTree.h>
2ab0c725 29#include <TFile.h>
94de3818 30
6f1e466d 31#include "AliRun.h"
2745a409 32#include "AliLog.h"
6f1e466d 33
34#include "AliTRDdigitsManager.h"
793ff80c 35#include "AliTRDsegmentArray.h"
36#include "AliTRDdataArrayI.h"
37#include "AliTRDdigit.h"
38#include "AliTRDgeometry.h"
6f1e466d 39
40ClassImp(AliTRDdigitsManager)
41
793ff80c 42//_____________________________________________________________________________
43
44 // Number of track dictionary arrays
45 const Int_t AliTRDdigitsManager::fgkNDict = kNDict;
46
6f1e466d 47//_____________________________________________________________________________
2745a409 48AliTRDdigitsManager::AliTRDdigitsManager()
49 :TObject()
50 ,fEvent(0)
51 ,fTree(0)
52 ,fDigits(0)
53 ,fIsRaw(0)
54 ,fSDigits(0)
6f1e466d 55{
56 //
57 // Default constructor
58 //
59
6f1e466d 60 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
abaf1f1d 61 fDictionary[iDict] = NULL;
6f1e466d 62 }
63
64}
65
8230f242 66//_____________________________________________________________________________
dd9a6ee3 67AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
2745a409 68 :TObject(m)
69 ,fEvent(m.fEvent)
70 ,fTree(0)
71 ,fDigits(0)
72 ,fIsRaw(m.fIsRaw)
73 ,fSDigits(m.fSDigits)
8230f242 74{
75 //
76 // AliTRDdigitsManager copy constructor
77 //
78
8230f242 79}
80
6f1e466d 81//_____________________________________________________________________________
82AliTRDdigitsManager::~AliTRDdigitsManager()
83{
8230f242 84 //
85 // AliTRDdigitsManager destructor
86 //
6f1e466d 87
88 if (fDigits) {
89 fDigits->Delete();
90 delete fDigits;
abaf1f1d 91 fDigits = NULL;
6f1e466d 92 }
93
94 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
95 fDictionary[iDict]->Delete();
96 delete fDictionary[iDict];
abaf1f1d 97 fDictionary[iDict] = NULL;
6f1e466d 98 }
99
100}
101
2745a409 102//_____________________________________________________________________________
103AliTRDdigitsManager &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
8230f242 114//_____________________________________________________________________________
e0d47c25 115void AliTRDdigitsManager::Copy(TObject &m) const
8230f242 116{
117 //
118 // Copy function
119 //
120
abaf1f1d 121 ((AliTRDdigitsManager &) m).fIsRaw = fIsRaw;
122 ((AliTRDdigitsManager &) m).fEvent = fEvent;
abaf1f1d 123 ((AliTRDdigitsManager &) m).fSDigits = fSDigits;
8230f242 124
125 TObject::Copy(m);
126
127}
128
abaf1f1d 129//_____________________________________________________________________________
130void 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
17eee78a 143}
144//_____________________________________________________________________________
145void 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
abaf1f1d 164}
165
6f1e466d 166//_____________________________________________________________________________
167void AliTRDdigitsManager::SetRaw()
168{
0a29d0f1 169 //
170 // Switch on the raw digits flag
171 //
6f1e466d 172
173 fIsRaw = kTRUE;
698b2e52 174 if (fDigits)
175 fDigits->SetBit(AliTRDdigit::RawDigit());
6f1e466d 176
177}
178
16bf9884 179//_____________________________________________________________________________
180Short_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
698b2e52 187 if (!GetDigits(det)) return 0;
16bf9884 188 return ((Short_t) GetDigits(det)->GetData(row,col,time));
189
190}
191
6f1e466d 192//_____________________________________________________________________________
88cb7938 193Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree)
855bfffd 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
855bfffd 203 if (tree) {
204 fTree = tree;
205 }
206
abaf1f1d 207 // Make the branch for the digits
208 if (fDigits) {
209 const AliTRDdataArray *kDigits = (AliTRDdataArray *) fDigits->At(0);
210 if (kDigits) {
bdbb05bb 211 if (!fTree) return kFALSE;
212 TBranch* branch = fTree->GetBranch("TRDdigits");
213 if (!branch) fTree->Branch("TRDdigits",kDigits->IsA()->GetName(),
214 &kDigits,buffersize,99);
2745a409 215 AliDebug(1,"Making branch TRDdigits\n");
6f1e466d 216 }
217 else {
218 status = kFALSE;
219 }
abaf1f1d 220 }
221 else {
222 status = kFALSE;
223 }
6f1e466d 224
abaf1f1d 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) {
bdbb05bb 233 if (!fTree) return kFALSE;
234 TBranch* branch = fTree->GetBranch(branchname);
235 if (!branch) fTree->Branch(branchname,kDictionary->IsA()->GetName(),
236 &kDictionary,buffersize,99);
2745a409 237 AliDebug(1,Form("Making branch %s\n",branchname));
6f1e466d 238 }
239 else {
240 status = kFALSE;
241 }
242 }
abaf1f1d 243 else {
244 status = kFALSE;
245 }
6f1e466d 246 }
247
248 return status;
249
250}
251
252//_____________________________________________________________________________
855bfffd 253Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree)
6f1e466d 254{
8230f242 255 //
256 // Reads the digit information from the input file
257 //
6f1e466d 258
259 Bool_t status = kTRUE;
260
855bfffd 261 if (tree) {
262
263 fTree = tree;
264
abaf1f1d 265 }
266
267 if (!fDigits) {
2745a409 268 AliDebug(1,"Create the data arrays.\n");
abaf1f1d 269 CreateArrays();
270 }
271
272 status = fDigits->LoadArray("TRDdigits",fTree);
6f1e466d 273
274 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
275 Char_t branchname[15];
276 sprintf(branchname,"TRDdictionary%d",iDict);
abaf1f1d 277 status = fDictionary[iDict]->LoadArray(branchname,fTree);
6f1e466d 278 }
279
793ff80c 280 if (fDigits->TestBit(AliTRDdigit::RawDigit())) {
6f1e466d 281 fIsRaw = kTRUE;
282 }
283 else {
284 fIsRaw = kFALSE;
285 }
286
287 return kTRUE;
288
289}
290
291//_____________________________________________________________________________
292Bool_t AliTRDdigitsManager::WriteDigits()
293{
294 //
295 // Writes out the TRD-digits and the dictionaries
296 //
297
6f1e466d 298 // Store the contents of the segment array in the tree
abaf1f1d 299 if (!fDigits->StoreArray("TRDdigits",fTree)) {
2745a409 300 AliError("Error while storing digits in branch TRDdigits\n");
6f1e466d 301 return kFALSE;
302 }
303 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
304 Char_t branchname[15];
305 sprintf(branchname,"TRDdictionary%d",iDict);
abaf1f1d 306 if (!fDictionary[iDict]->StoreArray(branchname,fTree)) {
2745a409 307 AliError(Form("Error while storing dictionary in branch %s\n",branchname));
6f1e466d 308 return kFALSE;
309 }
310 }
311
abaf1f1d 312 // Write the new tree to the output file
8e64dd77 313 fTree->AutoSave(); // Modification by Jiri
abaf1f1d 314
6f1e466d 315 return kTRUE;
316
317}
9d0b222b 318
319//_____________________________________________________________________________
320AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row, Int_t col
793ff80c 321 , Int_t time, Int_t det) const
9d0b222b 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//_____________________________________________________________________________
342Int_t AliTRDdigitsManager::GetTrack(Int_t track
343 , Int_t row, Int_t col, Int_t time
793ff80c 344 , Int_t det) const
9d0b222b 345{
346 //
347 // Returns the MC-track numbers from the dictionary.
348 //
349
350 if ((track < 0) || (track >= kNDict)) {
2745a409 351 AliError(Form("track %d out of bounds (size: %d, this: 0x%08x)"
352 ,track,kNDict,this));
9d0b222b 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
dd9a6ee3 361//_____________________________________________________________________________
793ff80c 362AliTRDdataArrayI *AliTRDdigitsManager::GetDigits(Int_t det) const
dd9a6ee3 363{
364 //
365 // Returns the digits array for one detector
366 //
367
698b2e52 368 if (!fDigits) return 0x0;
dd9a6ee3 369 return (AliTRDdataArrayI *) fDigits->At(det);
370
371}
372
373//_____________________________________________________________________________
793ff80c 374AliTRDdataArrayI *AliTRDdigitsManager::GetDictionary(Int_t det, Int_t i) const
dd9a6ee3 375{
376 //
377 // Returns the dictionary for one detector
378 //
379
380 return (AliTRDdataArrayI *) fDictionary[i]->At(det);
381
382}
383
384//_____________________________________________________________________________
793ff80c 385Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *Digit) const
dd9a6ee3 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}