]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDdigitsManager.cxx
Increase version number
[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$
855bfffd 18Revision 1.14 2001/11/14 10:50:46 cblume
19Changes in digits IO. Add merging of summable digits
20
abaf1f1d 21Revision 1.13 2001/11/06 17:19:41 cblume
22Add detailed geometry and simple simulator
23
16bf9884 24Revision 1.12 2001/05/16 14:57:28 alibrary
25New files for folders and Stack
26
9e1a0ddb 27Revision 1.11 2001/03/13 09:30:35 cblume
28Update of digitization. Moved digit branch definition to AliTRD
29
6244debe 30Revision 1.10 2001/01/26 19:56:57 hristov
31Major upgrade of AliRoot code
32
2ab0c725 33Revision 1.9 2000/11/02 09:25:53 cblume
34Change also the dictionary to AliTRDdataArray
35
4d6586ef 36Revision 1.8 2000/11/01 15:20:13 cblume
37Change AliTRDdataArrayI to AliTRDdataArray in MakeBranch()
38
06754153 39Revision 1.7 2000/11/01 14:53:20 cblume
40Merge with TRD-develop
41
793ff80c 42Revision 1.1.2.5 2000/10/17 02:27:34 cblume
43Get rid of global constants
44
45Revision 1.1.2.4 2000/10/15 23:40:01 cblume
46Remove AliTRDconst
47
48Revision 1.1.2.3 2000/10/06 16:49:46 cblume
49Made Getters const
50
51Revision 1.1.2.2 2000/10/04 16:34:58 cblume
52Replace include files by forward declarations
53
94de3818 54Revision 1.5 2000/06/09 11:10:07 cblume
55Compiler warnings and coding conventions, next round
56
dd9a6ee3 57Revision 1.4 2000/06/08 18:32:58 cblume
58Make code compliant to coding conventions
59
8230f242 60Revision 1.3 2000/06/07 16:27:01 cblume
61Try to remove compiler warnings on Sun and HP
62
9d0b222b 63Revision 1.2 2000/05/08 16:17:27 cblume
64Merge TRD-develop
65
6f1e466d 66Revision 1.1.2.1 2000/05/08 14:44:01 cblume
67Add new class AliTRDdigitsManager
68
69*/
70
71///////////////////////////////////////////////////////////////////////////////
72// //
73// Manages the digits and the track dictionary in the form of //
74// AliTRDdataArray objects. //
75// //
76///////////////////////////////////////////////////////////////////////////////
6244debe 77
2ab0c725 78#include <iostream.h>
793ff80c 79
2ab0c725 80#include <TROOT.h>
793ff80c 81#include <TTree.h>
2ab0c725 82#include <TFile.h>
94de3818 83
6f1e466d 84#include "AliRun.h"
85
86#include "AliTRDdigitsManager.h"
793ff80c 87#include "AliTRDsegmentArray.h"
88#include "AliTRDdataArrayI.h"
89#include "AliTRDdigit.h"
90#include "AliTRDgeometry.h"
9e1a0ddb 91#include "AliTRD.h"
6f1e466d 92
93ClassImp(AliTRDdigitsManager)
94
793ff80c 95//_____________________________________________________________________________
96
97 // Number of track dictionary arrays
98 const Int_t AliTRDdigitsManager::fgkNDict = kNDict;
99
6f1e466d 100//_____________________________________________________________________________
101AliTRDdigitsManager::AliTRDdigitsManager():TObject()
102{
103 //
104 // Default constructor
105 //
106
abaf1f1d 107 fIsRaw = kFALSE;
108 fEvent = 0;
855bfffd 109 fDebug = 0;
abaf1f1d 110 fSDigits = 0;
6f1e466d 111
abaf1f1d 112 fFile = NULL;
113 fTree = NULL;
114 fDigits = NULL;
6f1e466d 115 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
abaf1f1d 116 fDictionary[iDict] = NULL;
6f1e466d 117 }
118
119}
120
8230f242 121//_____________________________________________________________________________
dd9a6ee3 122AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
8230f242 123{
124 //
125 // AliTRDdigitsManager copy constructor
126 //
127
dd9a6ee3 128 ((AliTRDdigitsManager &) m).Copy(*this);
8230f242 129
130}
131
6f1e466d 132//_____________________________________________________________________________
133AliTRDdigitsManager::~AliTRDdigitsManager()
134{
8230f242 135 //
136 // AliTRDdigitsManager destructor
137 //
6f1e466d 138
abaf1f1d 139 if (fFile) {
140 fFile->Close();
141 delete fFile;
142 fFile = NULL;
143 }
144
145 if (fTree) {
146 delete fTree;
147 fTree = NULL;
148 }
149
6f1e466d 150 if (fDigits) {
151 fDigits->Delete();
152 delete fDigits;
abaf1f1d 153 fDigits = NULL;
6f1e466d 154 }
155
156 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
157 fDictionary[iDict]->Delete();
158 delete fDictionary[iDict];
abaf1f1d 159 fDictionary[iDict] = NULL;
6f1e466d 160 }
161
162}
163
8230f242 164//_____________________________________________________________________________
dd9a6ee3 165void AliTRDdigitsManager::Copy(TObject &m)
8230f242 166{
167 //
168 // Copy function
169 //
170
abaf1f1d 171 ((AliTRDdigitsManager &) m).fIsRaw = fIsRaw;
172 ((AliTRDdigitsManager &) m).fEvent = fEvent;
855bfffd 173 ((AliTRDdigitsManager &) m).fDebug = fDebug;
abaf1f1d 174 ((AliTRDdigitsManager &) m).fSDigits = fSDigits;
8230f242 175
176 TObject::Copy(m);
177
178}
179
abaf1f1d 180//_____________________________________________________________________________
181void AliTRDdigitsManager::CreateArrays()
182{
183 //
184 // Create the data arrays
185 //
186
187 fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
188
189 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
190 fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
191 ,AliTRDgeometry::Ndet());
192 }
193
194}
195
6f1e466d 196//_____________________________________________________________________________
197void AliTRDdigitsManager::SetRaw()
198{
199
200 fIsRaw = kTRUE;
201
793ff80c 202 fDigits->SetBit(AliTRDdigit::RawDigit());
6f1e466d 203
204}
205
16bf9884 206//_____________________________________________________________________________
207Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time
208 , Int_t det) const
209{
210 //
211 // Returns the amplitude of a digit
212 //
213
214 return ((Short_t) GetDigits(det)->GetData(row,col,time));
215
216}
217
6f1e466d 218//_____________________________________________________________________________
855bfffd 219Bool_t AliTRDdigitsManager::Open(const Char_t *file)
6f1e466d 220{
221 //
abaf1f1d 222 // Opens the file for the TRD digits
223 //
224
855bfffd 225 fFile = (TFile*) gROOT->GetListOfFiles()->FindObject(file);
abaf1f1d 226 if (!fFile) {
855bfffd 227 if (fDebug > 0) {
228 printf("<AliTRDdigitsManager::Open> ");
229 printf("Open the AliROOT-file %s.\n",file);
abaf1f1d 230 }
855bfffd 231 fFile = new TFile(file,"UPDATE");
abaf1f1d 232 if (!fFile) return kFALSE;
233 }
234 else {
855bfffd 235 if (fDebug > 0) {
236 printf("<AliTRDdigitsManager::Open> ");
237 printf("%s is already open.\n",file);
abaf1f1d 238 }
239 }
240
241 return kTRUE;
242
243}
244
245//_____________________________________________________________________________
246Bool_t AliTRDdigitsManager::MakeBranch(const Char_t *file)
247{
248 //
249 // Creates the tree and branches for the digits and the dictionary
6f1e466d 250 //
251
abaf1f1d 252 // Create the TRD digits tree
855bfffd 253 TTree *tree;
abaf1f1d 254 Char_t treeName[12];
255 if (fSDigits) {
256 sprintf(treeName,"TreeS%d_TRD",fEvent);
855bfffd 257 tree = new TTree(treeName,"TRD SDigits");
abaf1f1d 258 }
259 else {
260 sprintf(treeName,"TreeD%d_TRD",fEvent);
855bfffd 261 tree = new TTree(treeName,"TRD Digits");
abaf1f1d 262 }
9e1a0ddb 263
855bfffd 264 if (fDebug > 0) {
265 printf("<AliTRDdigitsManager::MakeBranch> ");
abaf1f1d 266 printf("Creating tree %s\n",treeName);
267 }
6f1e466d 268
855bfffd 269 return MakeBranch(tree,file);
270
271}
272
273//_____________________________________________________________________________
274Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree, const Char_t *file)
275{
276 //
277 // Creates the tree and branches for the digits and the dictionary
278 //
279
280 Int_t buffersize = 64000;
281
282 Bool_t status = kTRUE;
283
284 AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD") ;
285
286 if (tree) {
287 fTree = tree;
288 }
289
abaf1f1d 290 // Make the branch for the digits
291 if (fDigits) {
292 const AliTRDdataArray *kDigits = (AliTRDdataArray *) fDigits->At(0);
293 if (kDigits) {
294 trd->MakeBranchInTree(fTree,"TRDdigits",kDigits->IsA()->GetName()
295 ,&kDigits,buffersize,99,file);
855bfffd 296 if (fDebug > 0) {
297 printf("<AliTRDdigitsManager::MakeBranch> ");
6f1e466d 298 printf("Making branch TRDdigits\n");
299 }
6f1e466d 300 }
301 else {
302 status = kFALSE;
303 }
abaf1f1d 304 }
305 else {
306 status = kFALSE;
307 }
6f1e466d 308
abaf1f1d 309 // Make the branches for the dictionaries
310 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
311 Char_t branchname[15];
312 sprintf(branchname,"TRDdictionary%d",iDict);
313 if (fDictionary[iDict]) {
314 const AliTRDdataArray *kDictionary =
315 (AliTRDdataArray *) fDictionary[iDict]->At(0);
316 if (kDictionary) {
317 trd->MakeBranchInTree(fTree,branchname,kDictionary->IsA()->GetName()
318 ,&kDictionary,buffersize,99,file);
855bfffd 319 if (fDebug > 0) {
320 printf("<AliTRDdigitsManager::MakeBranch> ");
6f1e466d 321 printf("Making branch %s\n",branchname);
6244debe 322 }
6f1e466d 323 }
324 else {
325 status = kFALSE;
326 }
327 }
abaf1f1d 328 else {
329 status = kFALSE;
330 }
6f1e466d 331 }
332
333 return status;
334
335}
336
337//_____________________________________________________________________________
855bfffd 338Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree)
6f1e466d 339{
8230f242 340 //
341 // Reads the digit information from the input file
342 //
6f1e466d 343
344 Bool_t status = kTRUE;
345
855bfffd 346 if (tree) {
347
348 fTree = tree;
349
abaf1f1d 350 }
351 else {
855bfffd 352
353 // Get the digits tree
354 Char_t treeName[12];
355 if (fSDigits) {
356 sprintf(treeName,"TreeS%d_TRD",fEvent);
abaf1f1d 357 }
855bfffd 358 else {
359 sprintf(treeName,"TreeD%d_TRD",fEvent);
360 }
361 if (fFile) {
362 fTree = (TTree *) fFile->Get(treeName);
363 }
364 else {
365 fTree = (TTree *) gDirectory->Get(treeName);
366 }
367
368 if (!fTree) {
369 if (fDebug > 0) {
370 printf("<AliTRDdigitsManager::ReadDigits> ");
371 printf("Could not find tree %s.\n",treeName);
372 }
373 return kFALSE;
374 }
375
abaf1f1d 376 }
377
378 if (!fDigits) {
855bfffd 379 if (fDebug > 0) {
380 printf("<AliTRDdigitsManager::ReadDigits> ");
abaf1f1d 381 printf("Create the data arrays.\n");
382 }
383 CreateArrays();
384 }
385
386 status = fDigits->LoadArray("TRDdigits",fTree);
6f1e466d 387
388 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
389 Char_t branchname[15];
390 sprintf(branchname,"TRDdictionary%d",iDict);
abaf1f1d 391 status = fDictionary[iDict]->LoadArray(branchname,fTree);
6f1e466d 392 }
393
793ff80c 394 if (fDigits->TestBit(AliTRDdigit::RawDigit())) {
6f1e466d 395 fIsRaw = kTRUE;
396 }
397 else {
398 fIsRaw = kFALSE;
399 }
400
401 return kTRUE;
402
403}
404
405//_____________________________________________________________________________
406Bool_t AliTRDdigitsManager::WriteDigits()
407{
408 //
409 // Writes out the TRD-digits and the dictionaries
410 //
411
6f1e466d 412 // Store the contents of the segment array in the tree
abaf1f1d 413 if (!fDigits->StoreArray("TRDdigits",fTree)) {
855bfffd 414 printf("<AliTRDdigitsManager::WriteDigits> ");
6f1e466d 415 printf("Error while storing digits in branch TRDdigits\n");
416 return kFALSE;
417 }
418 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
419 Char_t branchname[15];
420 sprintf(branchname,"TRDdictionary%d",iDict);
abaf1f1d 421 if (!fDictionary[iDict]->StoreArray(branchname,fTree)) {
855bfffd 422 printf("<AliTRDdigitsManager::WriteDigits> ");
6f1e466d 423 printf("Error while storing dictionary in branch %s\n",branchname);
424 return kFALSE;
425 }
426 }
427
abaf1f1d 428 // Write the new tree to the output file
429 fTree->Write();
430
6f1e466d 431 return kTRUE;
432
433}
9d0b222b 434
435//_____________________________________________________________________________
436AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row, Int_t col
793ff80c 437 , Int_t time, Int_t det) const
9d0b222b 438{
439 //
440 // Creates a single digit object
441 //
442
443 Int_t digits[4];
444 Int_t amp[1];
445
446 digits[0] = det;
447 digits[1] = row;
448 digits[2] = col;
449 digits[3] = time;
450
451 amp[0] = GetDigits(det)->GetData(row,col,time);
452
453 return (new AliTRDdigit(fIsRaw,digits,amp));
454
455}
456
457//_____________________________________________________________________________
458Int_t AliTRDdigitsManager::GetTrack(Int_t track
459 , Int_t row, Int_t col, Int_t time
793ff80c 460 , Int_t det) const
9d0b222b 461{
462 //
463 // Returns the MC-track numbers from the dictionary.
464 //
465
466 if ((track < 0) || (track >= kNDict)) {
467 TObject::Error("GetTracks"
468 ,"track %d out of bounds (size: %d, this: 0x%08x)"
469 ,track,kNDict,this);
470 return -1;
471 }
472
473 // Array contains index+1 to allow data compression
474 return (GetDictionary(det,track)->GetData(row,col,time) - 1);
475
476}
477
dd9a6ee3 478//_____________________________________________________________________________
793ff80c 479AliTRDdataArrayI *AliTRDdigitsManager::GetDigits(Int_t det) const
dd9a6ee3 480{
481 //
482 // Returns the digits array for one detector
483 //
484
485 return (AliTRDdataArrayI *) fDigits->At(det);
486
487}
488
489//_____________________________________________________________________________
793ff80c 490AliTRDdataArrayI *AliTRDdigitsManager::GetDictionary(Int_t det, Int_t i) const
dd9a6ee3 491{
492 //
493 // Returns the dictionary for one detector
494 //
495
496 return (AliTRDdataArrayI *) fDictionary[i]->At(det);
497
498}
499
500//_____________________________________________________________________________
793ff80c 501Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *Digit) const
dd9a6ee3 502{
503 //
504 // Returns the MC-track numbers from the dictionary for a given digit
505 //
506
507 Int_t row = Digit->GetRow();
508 Int_t col = Digit->GetCol();
509 Int_t time = Digit->GetTime();
510 Int_t det = Digit->GetDetector();
511
512 return GetTrack(track,row,col,time,det);
513
514}
515
516//_____________________________________________________________________________
517AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
518{
519 //
520 // Assignment operator
521 //
522
523 if (this != &m) ((AliTRDdigitsManager &) m).Copy(*this);
524 return *this;
525
526}