]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDdigitsManager.cxx
Coding conventions
[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
16/*
17$Log$
0a29d0f1 18Revision 1.16 2002/02/12 11:42:08 cblume
19Remove fTree from destructor
20
81eb1f59 21Revision 1.15 2002/02/11 14:27:54 cblume
22Geometry and hit structure update
23
855bfffd 24Revision 1.14 2001/11/14 10:50:46 cblume
25Changes in digits IO. Add merging of summable digits
26
abaf1f1d 27Revision 1.13 2001/11/06 17:19:41 cblume
28Add detailed geometry and simple simulator
29
16bf9884 30Revision 1.12 2001/05/16 14:57:28 alibrary
31New files for folders and Stack
32
9e1a0ddb 33Revision 1.11 2001/03/13 09:30:35 cblume
34Update of digitization. Moved digit branch definition to AliTRD
35
6244debe 36Revision 1.10 2001/01/26 19:56:57 hristov
37Major upgrade of AliRoot code
38
2ab0c725 39Revision 1.9 2000/11/02 09:25:53 cblume
40Change also the dictionary to AliTRDdataArray
41
4d6586ef 42Revision 1.8 2000/11/01 15:20:13 cblume
43Change AliTRDdataArrayI to AliTRDdataArray in MakeBranch()
44
06754153 45Revision 1.7 2000/11/01 14:53:20 cblume
46Merge with TRD-develop
47
793ff80c 48Revision 1.1.2.5 2000/10/17 02:27:34 cblume
49Get rid of global constants
50
51Revision 1.1.2.4 2000/10/15 23:40:01 cblume
52Remove AliTRDconst
53
54Revision 1.1.2.3 2000/10/06 16:49:46 cblume
55Made Getters const
56
57Revision 1.1.2.2 2000/10/04 16:34:58 cblume
58Replace include files by forward declarations
59
94de3818 60Revision 1.5 2000/06/09 11:10:07 cblume
61Compiler warnings and coding conventions, next round
62
dd9a6ee3 63Revision 1.4 2000/06/08 18:32:58 cblume
64Make code compliant to coding conventions
65
8230f242 66Revision 1.3 2000/06/07 16:27:01 cblume
67Try to remove compiler warnings on Sun and HP
68
9d0b222b 69Revision 1.2 2000/05/08 16:17:27 cblume
70Merge TRD-develop
71
6f1e466d 72Revision 1.1.2.1 2000/05/08 14:44:01 cblume
73Add 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///////////////////////////////////////////////////////////////////////////////
6244debe 83
2ab0c725 84#include <iostream.h>
793ff80c 85
2ab0c725 86#include <TROOT.h>
793ff80c 87#include <TTree.h>
2ab0c725 88#include <TFile.h>
94de3818 89
6f1e466d 90#include "AliRun.h"
91
92#include "AliTRDdigitsManager.h"
793ff80c 93#include "AliTRDsegmentArray.h"
94#include "AliTRDdataArrayI.h"
95#include "AliTRDdigit.h"
96#include "AliTRDgeometry.h"
9e1a0ddb 97#include "AliTRD.h"
6f1e466d 98
99ClassImp(AliTRDdigitsManager)
100
793ff80c 101//_____________________________________________________________________________
102
103 // Number of track dictionary arrays
104 const Int_t AliTRDdigitsManager::fgkNDict = kNDict;
105
6f1e466d 106//_____________________________________________________________________________
107AliTRDdigitsManager::AliTRDdigitsManager():TObject()
108{
109 //
110 // Default constructor
111 //
112
abaf1f1d 113 fIsRaw = kFALSE;
114 fEvent = 0;
855bfffd 115 fDebug = 0;
abaf1f1d 116 fSDigits = 0;
6f1e466d 117
abaf1f1d 118 fFile = NULL;
119 fTree = NULL;
120 fDigits = NULL;
6f1e466d 121 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
abaf1f1d 122 fDictionary[iDict] = NULL;
6f1e466d 123 }
124
125}
126
8230f242 127//_____________________________________________________________________________
dd9a6ee3 128AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
8230f242 129{
130 //
131 // AliTRDdigitsManager copy constructor
132 //
133
dd9a6ee3 134 ((AliTRDdigitsManager &) m).Copy(*this);
8230f242 135
136}
137
6f1e466d 138//_____________________________________________________________________________
139AliTRDdigitsManager::~AliTRDdigitsManager()
140{
8230f242 141 //
142 // AliTRDdigitsManager destructor
143 //
6f1e466d 144
abaf1f1d 145 if (fFile) {
146 fFile->Close();
147 delete fFile;
148 fFile = NULL;
149 }
150
6f1e466d 151 if (fDigits) {
152 fDigits->Delete();
153 delete fDigits;
abaf1f1d 154 fDigits = NULL;
6f1e466d 155 }
156
157 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
158 fDictionary[iDict]->Delete();
159 delete fDictionary[iDict];
abaf1f1d 160 fDictionary[iDict] = NULL;
6f1e466d 161 }
162
163}
164
8230f242 165//_____________________________________________________________________________
dd9a6ee3 166void AliTRDdigitsManager::Copy(TObject &m)
8230f242 167{
168 //
169 // Copy function
170 //
171
abaf1f1d 172 ((AliTRDdigitsManager &) m).fIsRaw = fIsRaw;
173 ((AliTRDdigitsManager &) m).fEvent = fEvent;
855bfffd 174 ((AliTRDdigitsManager &) m).fDebug = fDebug;
abaf1f1d 175 ((AliTRDdigitsManager &) m).fSDigits = fSDigits;
8230f242 176
177 TObject::Copy(m);
178
179}
180
abaf1f1d 181//_____________________________________________________________________________
182void 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
6f1e466d 197//_____________________________________________________________________________
198void AliTRDdigitsManager::SetRaw()
199{
0a29d0f1 200 //
201 // Switch on the raw digits flag
202 //
6f1e466d 203
204 fIsRaw = kTRUE;
205
793ff80c 206 fDigits->SetBit(AliTRDdigit::RawDigit());
6f1e466d 207
208}
209
16bf9884 210//_____________________________________________________________________________
211Short_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
6f1e466d 222//_____________________________________________________________________________
855bfffd 223Bool_t AliTRDdigitsManager::Open(const Char_t *file)
6f1e466d 224{
225 //
abaf1f1d 226 // Opens the file for the TRD digits
227 //
228
855bfffd 229 fFile = (TFile*) gROOT->GetListOfFiles()->FindObject(file);
abaf1f1d 230 if (!fFile) {
855bfffd 231 if (fDebug > 0) {
232 printf("<AliTRDdigitsManager::Open> ");
233 printf("Open the AliROOT-file %s.\n",file);
abaf1f1d 234 }
855bfffd 235 fFile = new TFile(file,"UPDATE");
abaf1f1d 236 if (!fFile) return kFALSE;
237 }
238 else {
855bfffd 239 if (fDebug > 0) {
240 printf("<AliTRDdigitsManager::Open> ");
241 printf("%s is already open.\n",file);
abaf1f1d 242 }
243 }
244
245 return kTRUE;
246
247}
248
249//_____________________________________________________________________________
250Bool_t AliTRDdigitsManager::MakeBranch(const Char_t *file)
251{
252 //
253 // Creates the tree and branches for the digits and the dictionary
6f1e466d 254 //
255
abaf1f1d 256 // Create the TRD digits tree
855bfffd 257 TTree *tree;
abaf1f1d 258 Char_t treeName[12];
259 if (fSDigits) {
260 sprintf(treeName,"TreeS%d_TRD",fEvent);
855bfffd 261 tree = new TTree(treeName,"TRD SDigits");
abaf1f1d 262 }
263 else {
264 sprintf(treeName,"TreeD%d_TRD",fEvent);
855bfffd 265 tree = new TTree(treeName,"TRD Digits");
abaf1f1d 266 }
9e1a0ddb 267
855bfffd 268 if (fDebug > 0) {
269 printf("<AliTRDdigitsManager::MakeBranch> ");
abaf1f1d 270 printf("Creating tree %s\n",treeName);
271 }
6f1e466d 272
855bfffd 273 return MakeBranch(tree,file);
274
275}
276
277//_____________________________________________________________________________
278Bool_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
abaf1f1d 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);
855bfffd 300 if (fDebug > 0) {
301 printf("<AliTRDdigitsManager::MakeBranch> ");
6f1e466d 302 printf("Making branch TRDdigits\n");
303 }
6f1e466d 304 }
305 else {
306 status = kFALSE;
307 }
abaf1f1d 308 }
309 else {
310 status = kFALSE;
311 }
6f1e466d 312
abaf1f1d 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);
855bfffd 323 if (fDebug > 0) {
324 printf("<AliTRDdigitsManager::MakeBranch> ");
6f1e466d 325 printf("Making branch %s\n",branchname);
6244debe 326 }
6f1e466d 327 }
328 else {
329 status = kFALSE;
330 }
331 }
abaf1f1d 332 else {
333 status = kFALSE;
334 }
6f1e466d 335 }
336
337 return status;
338
339}
340
341//_____________________________________________________________________________
855bfffd 342Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree)
6f1e466d 343{
8230f242 344 //
345 // Reads the digit information from the input file
346 //
6f1e466d 347
348 Bool_t status = kTRUE;
349
855bfffd 350 if (tree) {
351
352 fTree = tree;
353
abaf1f1d 354 }
355 else {
855bfffd 356
357 // Get the digits tree
358 Char_t treeName[12];
359 if (fSDigits) {
360 sprintf(treeName,"TreeS%d_TRD",fEvent);
abaf1f1d 361 }
855bfffd 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
abaf1f1d 380 }
381
382 if (!fDigits) {
855bfffd 383 if (fDebug > 0) {
384 printf("<AliTRDdigitsManager::ReadDigits> ");
abaf1f1d 385 printf("Create the data arrays.\n");
386 }
387 CreateArrays();
388 }
389
390 status = fDigits->LoadArray("TRDdigits",fTree);
6f1e466d 391
392 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
393 Char_t branchname[15];
394 sprintf(branchname,"TRDdictionary%d",iDict);
abaf1f1d 395 status = fDictionary[iDict]->LoadArray(branchname,fTree);
6f1e466d 396 }
397
793ff80c 398 if (fDigits->TestBit(AliTRDdigit::RawDigit())) {
6f1e466d 399 fIsRaw = kTRUE;
400 }
401 else {
402 fIsRaw = kFALSE;
403 }
404
405 return kTRUE;
406
407}
408
409//_____________________________________________________________________________
410Bool_t AliTRDdigitsManager::WriteDigits()
411{
412 //
413 // Writes out the TRD-digits and the dictionaries
414 //
415
6f1e466d 416 // Store the contents of the segment array in the tree
abaf1f1d 417 if (!fDigits->StoreArray("TRDdigits",fTree)) {
855bfffd 418 printf("<AliTRDdigitsManager::WriteDigits> ");
6f1e466d 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);
abaf1f1d 425 if (!fDictionary[iDict]->StoreArray(branchname,fTree)) {
855bfffd 426 printf("<AliTRDdigitsManager::WriteDigits> ");
6f1e466d 427 printf("Error while storing dictionary in branch %s\n",branchname);
428 return kFALSE;
429 }
430 }
431
abaf1f1d 432 // Write the new tree to the output file
433 fTree->Write();
434
6f1e466d 435 return kTRUE;
436
437}
9d0b222b 438
439//_____________________________________________________________________________
440AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row, Int_t col
793ff80c 441 , Int_t time, Int_t det) const
9d0b222b 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//_____________________________________________________________________________
462Int_t AliTRDdigitsManager::GetTrack(Int_t track
463 , Int_t row, Int_t col, Int_t time
793ff80c 464 , Int_t det) const
9d0b222b 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
dd9a6ee3 482//_____________________________________________________________________________
793ff80c 483AliTRDdataArrayI *AliTRDdigitsManager::GetDigits(Int_t det) const
dd9a6ee3 484{
485 //
486 // Returns the digits array for one detector
487 //
488
489 return (AliTRDdataArrayI *) fDigits->At(det);
490
491}
492
493//_____________________________________________________________________________
793ff80c 494AliTRDdataArrayI *AliTRDdigitsManager::GetDictionary(Int_t det, Int_t i) const
dd9a6ee3 495{
496 //
497 // Returns the dictionary for one detector
498 //
499
500 return (AliTRDdataArrayI *) fDictionary[i]->At(det);
501
502}
503
504//_____________________________________________________________________________
793ff80c 505Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *Digit) const
dd9a6ee3 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//_____________________________________________________________________________
521AliTRDdigitsManager &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}