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