Introduce the digits parameter class which is supposed to store digits information...
[u/mrichter/AliRoot.git] / TRD / AliTRDdigitizer.cxx
CommitLineData
f7336fa3 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$ */
f7336fa3 17
625f5260 18////////////////////////////////////////////////////////////////////////////
19// //
20// Creates and handles digits from TRD hits //
21// //
22// Authors: C. Blume (blume@ikf.uni-frankfurt.de) //
23// C. Lippmann //
24// B. Vulpescu //
25// //
26// The following effects are included: //
27// - Diffusion //
28// - ExB effects //
29// - Gas gain including fluctuations //
30// - Pad-response (simple Gaussian approximation) //
31// - Time-response //
32// - Electronics noise //
33// - Electronics gain //
34// - Digitization //
b65e5048 35// - Zero suppression //
625f5260 36// //
37////////////////////////////////////////////////////////////////////////////
6798b56e 38
f7a1cc68 39#include <TGeoManager.h>
abaf1f1d 40#include <TList.h>
f7a1cc68 41#include <TMath.h>
f7a1cc68 42#include <TRandom.h>
f7a1cc68 43#include <TTree.h>
26d3c914 44
793ff80c 45#include "AliRun.h"
3e2e3ece 46#include "AliMC.h"
88cb7938 47#include "AliRunLoader.h"
48#include "AliLoader.h"
49#include "AliConfig.h"
85cbec76 50#include "AliRunDigitizer.h"
88cb7938 51#include "AliRunLoader.h"
52#include "AliLoader.h"
ad2cc20b 53#include "AliLog.h"
621310dd 54
f7336fa3 55#include "AliTRD.h"
793ff80c 56#include "AliTRDhit.h"
f7336fa3 57#include "AliTRDdigitizer.h"
b65e5048 58#include "AliTRDarrayDictionary.h"
59#include "AliTRDarrayADC.h"
60#include "AliTRDarraySignal.h"
da581aea 61#include "AliTRDdigitsManager.h"
793ff80c 62#include "AliTRDgeometry.h"
a5cadd36 63#include "AliTRDpadPlane.h"
3551db50 64#include "AliTRDcalibDB.h"
65#include "AliTRDSimParam.h"
66#include "AliTRDCommonParam.h"
ecf39416 67#include "AliTRDfeeParam.h"
b65e5048 68#include "AliTRDmcmSim.h"
966f6939 69#include "AliTRDdigitsParam.h"
70
4329977a 71#include "Cal/AliTRDCalROC.h"
72#include "Cal/AliTRDCalDet.h"
73
f7336fa3 74ClassImp(AliTRDdigitizer)
75
76//_____________________________________________________________________________
85cbec76 77AliTRDdigitizer::AliTRDdigitizer()
4d18a639 78 :AliDigitizer()
79 ,fRunLoader(0)
80 ,fDigitsManager(0)
81 ,fSDigitsManager(0)
82 ,fSDigitsManagerList(0)
83 ,fTRD(0)
84 ,fGeo(0)
85 ,fEvent(0)
86 ,fMasks(0)
87 ,fCompress(kTRUE)
88 ,fSDigits(kFALSE)
4d18a639 89 ,fMergeSignalOnly(kFALSE)
f7336fa3 90{
91 //
92 // AliTRDdigitizer default constructor
93 //
3551db50 94
f7336fa3 95}
96
97//_____________________________________________________________________________
4d18a639 98AliTRDdigitizer::AliTRDdigitizer(const Text_t *name, const Text_t *title)
99 :AliDigitizer(name,title)
100 ,fRunLoader(0)
101 ,fDigitsManager(0)
102 ,fSDigitsManager(0)
103 ,fSDigitsManagerList(0)
104 ,fTRD(0)
105 ,fGeo(0)
106 ,fEvent(0)
107 ,fMasks(0)
108 ,fCompress(kTRUE)
109 ,fSDigits(kFALSE)
4d18a639 110 ,fMergeSignalOnly(kFALSE)
f7336fa3 111{
112 //
85cbec76 113 // AliTRDdigitizer constructor
114 //
115
85cbec76 116}
117
118//_____________________________________________________________________________
119AliTRDdigitizer::AliTRDdigitizer(AliRunDigitizer *manager
4d18a639 120 , const Text_t *name, const Text_t *title)
121 :AliDigitizer(manager,name,title)
122 ,fRunLoader(0)
123 ,fDigitsManager(0)
124 ,fSDigitsManager(0)
125 ,fSDigitsManagerList(0)
126 ,fTRD(0)
127 ,fGeo(0)
128 ,fEvent(0)
129 ,fMasks(0)
130 ,fCompress(kTRUE)
131 ,fSDigits(kFALSE)
4d18a639 132 ,fMergeSignalOnly(kFALSE)
85cbec76 133{
134 //
135 // AliTRDdigitizer constructor
f7336fa3 136 //
137
bfc40adc 138}
139
140//_____________________________________________________________________________
141AliTRDdigitizer::AliTRDdigitizer(AliRunDigitizer *manager)
4d18a639 142 :AliDigitizer(manager,"AliTRDdigitizer","TRD digitizer")
143 ,fRunLoader(0)
144 ,fDigitsManager(0)
145 ,fSDigitsManager(0)
146 ,fSDigitsManagerList(0)
147 ,fTRD(0)
148 ,fGeo(0)
149 ,fEvent(0)
150 ,fMasks(0)
151 ,fCompress(kTRUE)
152 ,fSDigits(kFALSE)
4d18a639 153 ,fMergeSignalOnly(kFALSE)
bfc40adc 154{
155 //
156 // AliTRDdigitizer constructor
157 //
158
f7336fa3 159}
160
161//_____________________________________________________________________________
4d18a639 162AliTRDdigitizer::AliTRDdigitizer(const AliTRDdigitizer &d)
163 :AliDigitizer(d)
164 ,fRunLoader(0)
165 ,fDigitsManager(0)
166 ,fSDigitsManager(0)
167 ,fSDigitsManagerList(0)
168 ,fTRD(0)
169 ,fGeo(0)
170 ,fEvent(0)
171 ,fMasks(0)
172 ,fCompress(d.fCompress)
173 ,fSDigits(d.fSDigits)
4d18a639 174 ,fMergeSignalOnly(d.fMergeSignalOnly)
8230f242 175{
176 //
177 // AliTRDdigitizer copy constructor
178 //
179
8230f242 180}
181
182//_____________________________________________________________________________
f7336fa3 183AliTRDdigitizer::~AliTRDdigitizer()
184{
8230f242 185 //
186 // AliTRDdigitizer destructor
187 //
f7336fa3 188
abaf1f1d 189 if (fDigitsManager) {
190 delete fDigitsManager;
4d18a639 191 fDigitsManager = 0;
f7336fa3 192 }
193
966f6939 194 if (fSDigitsManager) {
4d18a639 195 delete fSDigitsManager;
196 fSDigitsManager = 0;
197 }
f7336fa3 198
abaf1f1d 199 if (fSDigitsManagerList) {
47b5729a 200 fSDigitsManagerList->Delete();
abaf1f1d 201 delete fSDigitsManagerList;
4487dad0 202 fSDigitsManagerList = 0;
e23fbb27 203 }
204
205 if (fMasks) {
206 delete [] fMasks;
4329977a 207 fMasks = 0;
e23fbb27 208 }
209
f162af62 210 if (fGeo) {
211 delete fGeo;
212 fGeo = 0;
213 }
214
f7336fa3 215}
216
217//_____________________________________________________________________________
dd9a6ee3 218AliTRDdigitizer &AliTRDdigitizer::operator=(const AliTRDdigitizer &d)
219{
220 //
221 // Assignment operator
222 //
223
625f5260 224 if (this != &d) {
225 ((AliTRDdigitizer &) d).Copy(*this);
226 }
4d18a639 227
dd9a6ee3 228 return *this;
229
230}
231
232//_____________________________________________________________________________
e0d47c25 233void AliTRDdigitizer::Copy(TObject &d) const
8230f242 234{
235 //
236 // Copy function
237 //
238
85a5290f 239 ((AliTRDdigitizer &) d).fRunLoader = 0;
4487dad0 240 ((AliTRDdigitizer &) d).fDigitsManager = 0;
85a5290f 241 ((AliTRDdigitizer &) d).fSDigitsManager = 0;
242 ((AliTRDdigitizer &) d).fSDigitsManagerList = 0;
4487dad0 243 ((AliTRDdigitizer &) d).fTRD = 0;
244 ((AliTRDdigitizer &) d).fGeo = 0;
85a5290f 245 ((AliTRDdigitizer &) d).fEvent = 0;
246 ((AliTRDdigitizer &) d).fMasks = 0;
abaf1f1d 247 ((AliTRDdigitizer &) d).fCompress = fCompress;
abaf1f1d 248 ((AliTRDdigitizer &) d).fSDigits = fSDigits;
4487dad0 249 ((AliTRDdigitizer &) d).fMergeSignalOnly = fMergeSignalOnly;
3becff3c 250
e23fbb27 251}
252
253//_____________________________________________________________________________
621310dd 254void AliTRDdigitizer::Exec(const Option_t * const option)
e23fbb27 255{
256 //
257 // Executes the merging
258 //
259
260 Int_t iInput;
261
262 AliTRDdigitsManager *sdigitsManager;
263
264 TString optionString = option;
265 if (optionString.Contains("deb")) {
9afbd7de 266 AliLog::SetClassDebugLevel("AliTRDdigitizer",1);
7925de54 267 AliInfo("Called with debug option");
e23fbb27 268 }
269
cec4059b 270 // The AliRoot file is already connected by the manager
625f5260 271 AliRunLoader *inrl = 0x0;
88cb7938 272
9afbd7de 273 if (gAlice) {
7925de54 274 AliDebug(1,"AliRun object found on file.");
9afbd7de 275 }
4487dad0 276 else {
88cb7938 277 inrl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
278 inrl->LoadgAlice();
279 gAlice = inrl->GetAliRun();
9afbd7de 280 if (!gAlice) {
7925de54 281 AliError("Could not find AliRun object.")
9afbd7de 282 return;
283 }
4487dad0 284 }
cec4059b 285
e23fbb27 286 Int_t nInput = fManager->GetNinputs();
4d18a639 287 fMasks = new Int_t[nInput];
e23fbb27 288 for (iInput = 0; iInput < nInput; iInput++) {
289 fMasks[iInput] = fManager->GetMask(iInput);
290 }
e23fbb27 291
9afbd7de 292 //
e23fbb27 293 // Initialization
9afbd7de 294 //
e23fbb27 295
95867fd1 296 AliRunLoader *orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
297
67c67368 298 if (InitDetector()) {
9afbd7de 299
95867fd1 300 AliLoader *ogime = orl->GetLoader("TRDLoader");
67c67368 301
95867fd1 302 TTree *tree = 0;
9afbd7de 303 if (fSDigits) {
304 // If we produce SDigits
305 tree = ogime->TreeS();
306 if (!tree) {
307 ogime->MakeTree("S");
67c67368 308 tree = ogime->TreeS();
67c67368 309 }
9afbd7de 310 }
311 else {
312 // If we produce Digits
313 tree = ogime->TreeD();
314 if (!tree) {
315 ogime->MakeTree("D");
316 tree = ogime->TreeD();
67c67368 317 }
9afbd7de 318 }
319
67c67368 320 MakeBranch(tree);
9afbd7de 321
67c67368 322 }
323
e23fbb27 324 for (iInput = 0; iInput < nInput; iInput++) {
325
7925de54 326 AliDebug(1,Form("Add input stream %d",iInput));
e23fbb27 327
9afbd7de 328 // Check if the input tree exists
88cb7938 329 inrl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(iInput));
4d18a639 330 AliLoader *gime = inrl->GetLoader("TRDLoader");
88cb7938 331
4d18a639 332 TTree *treees = gime->TreeS();
9afbd7de 333 if (treees == 0x0) {
334 if (gime->LoadSDigits()) {
335 AliError(Form("Error Occured while loading S. Digits for input %d.",iInput));
336 return;
337 }
4d18a639 338 treees = gime->TreeS();
9afbd7de 339 }
88cb7938 340
341 if (treees == 0x0) {
7925de54 342 AliError(Form("Input stream %d does not exist",iInput));
c57e2264 343 return;
344 }
345
e23fbb27 346 // Read the s-digits via digits manager
347 sdigitsManager = new AliTRDdigitsManager();
e23fbb27 348 sdigitsManager->SetSDigits(kTRUE);
88cb7938 349
4d18a639 350 AliRunLoader *rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(iInput));
351 AliLoader *gimme = rl->GetLoader("TRDLoader");
b65e5048 352 if (!gimme->TreeS())
353 {
354 gimme->LoadSDigits();
355 }
e23fbb27 356
b65e5048 357 sdigitsManager->ReadDigits(gimme->TreeS());
358
e23fbb27 359 // Add the s-digits to the input list
360 AddSDigitsManager(sdigitsManager);
361
362 }
363
364 // Convert the s-digits to normal digits
7925de54 365 AliDebug(1,"Do the conversion");
e23fbb27 366 SDigits2Digits();
367
368 // Store the digits
7925de54 369 AliDebug(1,"Write the digits");
e23fbb27 370 fDigitsManager->WriteDigits();
88cb7938 371
9afbd7de 372 // Write parameters
67c67368 373 orl->CdGAFile();
67c67368 374
26d3c914 375 // Clean up
b1113c6b 376 DeleteSDigitsManager();
377
26d3c914 378 AliDebug(1,"Done");
379
e23fbb27 380}
381
382//_____________________________________________________________________________
e23fbb27 383Bool_t AliTRDdigitizer::Open(const Char_t *file, Int_t nEvent)
f7336fa3 384{
385 //
386 // Opens a ROOT-file with TRD-hits and reads in the hit-tree
387 //
f7336fa3 388 // Connect the AliRoot file containing Geometry, Kine, and Hits
3becff3c 389 //
f540341d 390
e191bb57 391 TString evfoldname = AliConfig::GetDefaultEventFolderName();
9afbd7de 392
f540341d 393 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
9afbd7de 394 if (!fRunLoader) {
395 fRunLoader = AliRunLoader::Open(file,evfoldname,"UPDATE");
396 }
9afbd7de 397 if (!fRunLoader) {
95867fd1 398 AliError(Form("Can not open session for file %s.",file));
399 return kFALSE;
400 }
401
402 if (!fRunLoader->GetAliRun()) {
403 fRunLoader->LoadgAlice();
404 }
405 gAlice = fRunLoader->GetAliRun();
406
407 if (gAlice) {
7925de54 408 AliDebug(1,"AliRun object found on file.");
95867fd1 409 }
410 else {
7925de54 411 AliError("Could not find AliRun object.");
95867fd1 412 return kFALSE;
413 }
414
415 fEvent = nEvent;
416
417 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
418 if (!loader) {
419 AliError("Can not get TRD loader from Run Loader");
420 return kFALSE;
421 }
422
423 if (InitDetector()) {
424 TTree *tree = 0;
425 if (fSDigits) {
426 // If we produce SDigits
427 tree = loader->TreeS();
428 if (!tree) {
429 loader->MakeTree("S");
430 tree = loader->TreeS();
431 }
432 }
433 else {
434 // If we produce Digits
435 tree = loader->TreeD();
436 if (!tree) {
437 loader->MakeTree("D");
438 tree = loader->TreeD();
439 }
440 }
441 return MakeBranch(tree);
442 }
443 else {
444 return kFALSE;
445 }
446
447}
448
449//_____________________________________________________________________________
621310dd 450Bool_t AliTRDdigitizer::Open(AliRunLoader * const runLoader, Int_t nEvent)
95867fd1 451{
452 //
453 // Opens a ROOT-file with TRD-hits and reads in the hit-tree
454 //
455 // Connect the AliRoot file containing Geometry, Kine, and Hits
456 //
457
458 fRunLoader = runLoader;
459 if (!fRunLoader) {
460 AliError("RunLoader does not exist");
461 return kFALSE;
4d18a639 462 }
88cb7938 463
9afbd7de 464 if (!fRunLoader->GetAliRun()) {
465 fRunLoader->LoadgAlice();
466 }
88cb7938 467 gAlice = fRunLoader->GetAliRun();
468
da581aea 469 if (gAlice) {
7925de54 470 AliDebug(1,"AliRun object found on file.");
da581aea 471 }
472 else {
7925de54 473 AliError("Could not find AliRun object.");
da581aea 474 return kFALSE;
475 }
f7336fa3 476
477 fEvent = nEvent;
478
4d18a639 479 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
9afbd7de 480 if (!loader) {
481 AliError("Can not get TRD loader from Run Loader");
482 return kFALSE;
483 }
88cb7938 484
abaf1f1d 485 if (InitDetector()) {
4d18a639 486 TTree *tree = 0;
9afbd7de 487 if (fSDigits) {
488 // If we produce SDigits
489 tree = loader->TreeS();
490 if (!tree) {
491 loader->MakeTree("S");
492 tree = loader->TreeS();
4d18a639 493 }
9afbd7de 494 }
495 else {
496 // If we produce Digits
95867fd1 497 tree = loader->TreeD();
9afbd7de 498 if (!tree) {
499 loader->MakeTree("D");
500 tree = loader->TreeD();
4d18a639 501 }
9afbd7de 502 }
88cb7938 503 return MakeBranch(tree);
abaf1f1d 504 }
505 else {
506 return kFALSE;
507 }
793ff80c 508
509}
510
511//_____________________________________________________________________________
512Bool_t AliTRDdigitizer::InitDetector()
513{
514 //
515 // Sets the pointer to the TRD detector and the geometry
516 //
517
dd9a6ee3 518 // Get the pointer to the detector class and check for version 1
4487dad0 519 fTRD = (AliTRD *) gAlice->GetDetector("TRD");
cec4059b 520 if (!fTRD) {
7925de54 521 AliFatal("No TRD module found");
cec4059b 522 exit(1);
523 }
dd9a6ee3 524 if (fTRD->IsVersion() != 1) {
7925de54 525 AliFatal("TRD must be version 1 (slow simulator)");
dd9a6ee3 526 exit(1);
527 }
528
529 // Get the geometry
f162af62 530 fGeo = new AliTRDgeometry();
dd9a6ee3 531
abaf1f1d 532 // Create a digits manager
625f5260 533 if (fDigitsManager) {
534 delete fDigitsManager;
535 }
abaf1f1d 536 fDigitsManager = new AliTRDdigitsManager();
537 fDigitsManager->SetSDigits(fSDigits);
538 fDigitsManager->CreateArrays();
539 fDigitsManager->SetEvent(fEvent);
abaf1f1d 540
541 // The list for the input s-digits manager to be merged
47b5729a 542 if (fSDigitsManagerList) {
543 fSDigitsManagerList->Delete();
3becff3c 544 }
545 else {
47b5729a 546 fSDigitsManagerList = new TList();
547 }
abaf1f1d 548
4487dad0 549 return kTRUE;
f7336fa3 550
551}
f7336fa3 552//_____________________________________________________________________________
95867fd1 553Bool_t AliTRDdigitizer::MakeBranch(TTree *tree) const
6244debe 554{
abaf1f1d 555 //
556 // Create the branches for the digits array
6244debe 557 //
558
88cb7938 559 return fDigitsManager->MakeBranch(tree);
6244debe 560
561}
562
563//_____________________________________________________________________________
625f5260 564void AliTRDdigitizer::AddSDigitsManager(AliTRDdigitsManager *man)
565{
566 //
567 // Add a digits manager for s-digits to the input list.
568 //
569
570 fSDigitsManagerList->Add(man);
571
572}
573
574//_____________________________________________________________________________
575void AliTRDdigitizer::DeleteSDigitsManager()
576{
577 //
578 // Removes digits manager from the input list.
579 //
580
581 fSDigitsManagerList->Delete();
582
583}
584
585//_____________________________________________________________________________
f7336fa3 586Bool_t AliTRDdigitizer::MakeDigits()
587{
588 //
872a7aba 589 // Creates digits.
f7336fa3 590 //
591
625f5260 592 AliDebug(1,"Start creating digits");
593
594 if (!fGeo) {
595 AliError("No geometry defined");
596 return kFALSE;
597 }
f7336fa3 598
625f5260 599 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
600 if (!calibration) {
601 AliFatal("Could not get calibration object");
602 return kFALSE;
603 }
604
605 const Int_t kNdet = AliTRDgeometry::Ndet();
606
607 Float_t **hits = new Float_t*[kNdet];
608 Int_t *nhit = new Int_t[kNdet];
609
b65e5048 610 AliTRDarraySignal *signals = 0x0;
625f5260 611
612 // Sort all hits according to detector number
613 if (!SortHits(hits,nhit)) {
614 AliError("Sorting hits failed");
615 return kFALSE;
616 }
617
618 // Loop through all detectors
619 for (Int_t det = 0; det < kNdet; det++) {
620
621 // Detectors that are switched off, not installed, etc.
622 if (( calibration->IsChamberInstalled(det)) &&
b65e5048 623 (!calibration->IsChamberMasked(det)) &&
625f5260 624 ( fGeo->ChamberInGeometry(det)) &&
625 (nhit[det] > 0)) {
626
b65e5048 627 signals = new AliTRDarraySignal();
628
625f5260 629 // Convert the hits of the current detector to detector signals
630 if (!ConvertHits(det,hits[det],nhit[det],signals)) {
b65e5048 631 AliError(Form("Conversion of hits failed for detector=%d",det));
625f5260 632 return kFALSE;
633 }
634 // Convert the detector signals to digits or s-digits
635 if (!ConvertSignals(det,signals)) {
b65e5048 636 AliError(Form("Conversion of signals failed for detector=%d",det));
637 return kFALSE;
625f5260 638 }
639
640 // Delete the signals array
641 delete signals;
642 signals = 0x0;
643
644 } // if: detector status
645
27cea06a 646 delete [] hits[det];
647
625f5260 648 } // for: detector
649
650 delete [] hits;
651 delete [] nhit;
652
653 return kTRUE;
654
655}
656
657//_____________________________________________________________________________
658Bool_t AliTRDdigitizer::SortHits(Float_t **hits, Int_t *nhit)
659{
660 //
661 // Read all the hits and sorts them according to detector number
662 // in the output array <hits>.
663 //
664
665 AliDebug(1,"Start sorting hits");
666
667 const Int_t kNdet = AliTRDgeometry::Ndet();
668 // Size of the hit vector
669 const Int_t kNhit = 6;
670
671 Float_t *xyz = 0;
672 Int_t nhitTrk = 0;
673
674 Int_t *lhit = new Int_t[kNdet];
675
676 for (Int_t det = 0; det < kNdet; det++) {
677 lhit[det] = 0;
678 nhit[det] = 0;
679 hits[det] = 0;
680 }
681
682 AliLoader *gimme = fRunLoader->GetLoader("TRDLoader");
683 if (!gimme->TreeH()) {
684 gimme->LoadHits();
685 }
686 TTree *hitTree = gimme->TreeH();
687 if (hitTree == 0x0) {
688 AliError("Can not get TreeH");
689 return kFALSE;
690 }
691 fTRD->SetTreeAddress();
692
693 // Get the number of entries in the hit tree
694 // (Number of primary particles creating a hit somewhere)
695 Int_t nTrk = (Int_t) hitTree->GetEntries();
696 AliDebug(1,Form("Found %d tracks",nTrk));
697
698 // Loop through all the tracks in the tree
699 for (Int_t iTrk = 0; iTrk < nTrk; iTrk++) {
700
3e2e3ece 701 gAlice->GetMCApp()->ResetHits();
625f5260 702 hitTree->GetEvent(iTrk);
703
704 if (!fTRD->Hits()) {
705 AliError(Form("No hits array for track = %d",iTrk));
706 continue;
707 }
708
709 // Number of hits for this track
710 nhitTrk = fTRD->Hits()->GetEntriesFast();
711
712 Int_t hitCnt = 0;
713 // Loop through the TRD hits
714 AliTRDhit *hit = (AliTRDhit *) fTRD->FirstHit(-1);
715 while (hit) {
716
717 hitCnt++;
718
719 // Don't analyze test hits
720 if (((Int_t) hit->GetCharge()) != 0) {
721
722 Int_t trk = hit->Track();
723 Int_t det = hit->GetDetector();
724 Int_t q = hit->GetCharge();
725 Float_t x = hit->X();
726 Float_t y = hit->Y();
727 Float_t z = hit->Z();
728 Float_t time = hit->GetTime();
729
730 if (nhit[det] == lhit[det]) {
731 // Inititialization of new detector
732 xyz = new Float_t[kNhit*(nhitTrk+lhit[det])];
733 if (hits[det]) {
734 memcpy(xyz,hits[det],sizeof(Float_t)*kNhit*lhit[det]);
735 delete [] hits[det];
736 }
737 lhit[det] += nhitTrk;
738 hits[det] = xyz;
739 }
740 else {
741 xyz = hits[det];
742 }
743 xyz[nhit[det]*kNhit+0] = x;
744 xyz[nhit[det]*kNhit+1] = y;
745 xyz[nhit[det]*kNhit+2] = z;
746 xyz[nhit[det]*kNhit+3] = q;
747 xyz[nhit[det]*kNhit+4] = trk;
748 xyz[nhit[det]*kNhit+5] = time;
749 nhit[det]++;
750
751 } // if: charge != 0
752
753 hit = (AliTRDhit *) fTRD->NextHit();
754
755 } // for: hits of one track
756
757 } // for: tracks
758
759 delete [] lhit;
760
761 return kTRUE;
762
763}
f7336fa3 764
625f5260 765//_____________________________________________________________________________
621310dd 766Bool_t AliTRDdigitizer::ConvertHits(Int_t det
767 , const Float_t * const hits
768 , Int_t nhit
b65e5048 769 , AliTRDarraySignal *signals)
625f5260 770{
771 //
772 // Converts the detectorwise sorted hits to detector signals
773 //
774
775 AliDebug(1,Form("Start converting hits for detector=%d (nhits=%d)",det,nhit));
f7336fa3 776
793ff80c 777 // Number of pads included in the pad response
a5cadd36 778 const Int_t kNpad = 3;
793ff80c 779 // Number of track dictionary arrays
625f5260 780 const Int_t kNdict = AliTRDdigitsManager::kNDict;
781 // Size of the hit vector
782 const Int_t kNhit = 6;
793ff80c 783
4329977a 784 // Width of the amplification region
785 const Float_t kAmWidth = AliTRDgeometry::AmThick();
3becff3c 786 // Width of the drift region
ccb4315c 787 const Float_t kDrWidth = AliTRDgeometry::DrThick();
4329977a 788 // Drift + amplification region
789 const Float_t kDrMin = - 0.5 * kAmWidth;
790 const Float_t kDrMax = kDrWidth + 0.5 * kAmWidth;
3551db50 791
625f5260 792 Int_t iPad = 0;
793 Int_t dict = 0;
794 Int_t timeBinTRFend = 1;
872a7aba 795
a5cadd36 796 Double_t pos[3];
4329977a 797 Double_t loc[3];
a5cadd36 798 Double_t padSignal[kNpad];
799 Double_t signalOld[kNpad];
872a7aba 800
b65e5048 801 AliTRDarrayDictionary *dictionary[kNdict];
4329977a 802
9afbd7de 803 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
9afbd7de 804 AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance();
625f5260 805 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
806
3becff3c 807 if (!commonParam) {
4329977a 808 AliFatal("Could not get common parameterss");
3551db50 809 return kFALSE;
810 }
625f5260 811 if (!simParam) {
812 AliFatal("Could not get simulation parameters");
813 return kFALSE;
814 }
3becff3c 815 if (!calibration) {
4329977a 816 AliFatal("Could not get calibration object");
3551db50 817 return kFALSE;
818 }
819
625f5260 820 // Get the detector wise calibration objects
821 AliTRDCalROC *calVdriftROC = 0;
822 Float_t calVdriftDetValue = 0.0;
823 const AliTRDCalDet *calVdriftDet = calibration->GetVdriftDet();
824 AliTRDCalROC *calT0ROC = 0;
825 Float_t calT0DetValue = 0.0;
826 const AliTRDCalDet *calT0Det = calibration->GetT0Det();
4329977a 827
4329977a 828 if (simParam->TRFOn()) {
829 timeBinTRFend = ((Int_t) (simParam->GetTRFhi()
830 * commonParam->GetSamplingFrequency())) - 1;
4329977a 831 }
832
966f6939 833 Int_t nTimeTotal = fDigitsManager->GetDigitsParam()->GetNTimeBins();
b43a3e17 834 Float_t samplingRate = commonParam->GetSamplingFrequency();
4329977a 835 Float_t elAttachProp = simParam->GetElAttachProp() / 100.0;
a328fff9 836
625f5260 837 AliTRDpadPlane *padPlane = fGeo->GetPadPlane(det);
b65e5048 838 Int_t layer = fGeo->GetLayer(det); //update
625f5260 839 Float_t row0 = padPlane->GetRow0ROC();
840 Int_t nRowMax = padPlane->GetNrows();
841 Int_t nColMax = padPlane->GetNcols();
842
843 // Create a new array for the signals
844 signals->Allocate(nRowMax,nColMax,nTimeTotal);
845
846 // Create a new array for the dictionary
847 for (dict = 0; dict < kNdict; dict++) {
b65e5048 848 dictionary[dict] = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
625f5260 849 dictionary[dict]->Allocate(nRowMax,nColMax,nTimeTotal);
850 }
851
852 // Loop through the hits in this detector
853 for (Int_t hit = 0; hit < nhit; hit++) {
854
855 pos[0] = hits[hit*kNhit+0];
856 pos[1] = hits[hit*kNhit+1];
857 pos[2] = hits[hit*kNhit+2];
858 Float_t q = hits[hit*kNhit+3];
859 Float_t hittime = hits[hit*kNhit+5];
860 Int_t track = ((Int_t) hits[hit*kNhit+4]);
861
862 Int_t inDrift = 1;
863
864 // Find the current volume with the geo manager
865 gGeoManager->SetCurrentPoint(pos);
866 gGeoManager->FindNode();
867 if (strstr(gGeoManager->GetPath(),"/UK")) {
868 inDrift = 0;
869 }
793ff80c 870
625f5260 871 // Get the calibration objects
872 calVdriftROC = calibration->GetVdriftROC(det);
873 calVdriftDetValue = calVdriftDet->GetValue(det);
874 calT0ROC = calibration->GetT0ROC(det);
875 calT0DetValue = calT0Det->GetValue(det);
876
877 // Go to the local coordinate system:
878 // loc[0] - col direction in amplification or driftvolume
879 // loc[1] - row direction in amplification or driftvolume
880 // loc[2] - time direction in amplification or driftvolume
881 gGeoManager->MasterToLocal(pos,loc);
882 if (inDrift) {
883 // Relative to middle of amplification region
884 loc[2] = loc[2] - kDrWidth/2.0 - kAmWidth/2.0;
885 }
793ff80c 886
625f5260 887 // The driftlength [cm] (w/o diffusion yet !).
888 // It is negative if the hit is between pad plane and anode wires.
889 Double_t driftlength = -1.0 * loc[2];
e23fbb27 890
625f5260 891 // Stupid patch to take care of TR photons that are absorbed
892 // outside the chamber volume. A real fix would actually need
893 // a more clever implementation of the TR hit generation
894 if (q < 0.0) {
895 if ((loc[1] < padPlane->GetRowEndROC()) ||
896 (loc[1] > padPlane->GetRow0ROC())) {
f881dc35 897 continue;
898 }
625f5260 899 if ((driftlength < kDrMin) ||
900 (driftlength > kDrMax)) {
901 continue;
4329977a 902 }
625f5260 903 }
f881dc35 904
625f5260 905 // Get row and col of unsmeared electron to retrieve drift velocity
906 // The pad row (z-direction)
907 Int_t rowE = padPlane->GetPadRowNumberROC(loc[1]);
908 if (rowE < 0) {
909 continue;
910 }
911 Double_t rowOffset = padPlane->GetPadRowOffsetROC(rowE,loc[1]);
912 // The pad column (rphi-direction)
913 Double_t offsetTilt = padPlane->GetTiltOffset(rowOffset);
914 Int_t colE = padPlane->GetPadColNumber(loc[0]+offsetTilt);
915 if (colE < 0) {
916 continue;
917 }
0a17cc30 918 Double_t colOffset = 0.0;
f881dc35 919
625f5260 920 // Normalized drift length
921 Float_t driftvelocity = calVdriftDetValue * calVdriftROC->GetValue(colE,rowE);
922 Double_t absdriftlength = TMath::Abs(driftlength);
923 if (commonParam->ExBOn()) {
924 absdriftlength /= TMath::Sqrt(GetLorentzFactor(driftvelocity));
925 }
926
927 // Loop over all electrons of this hit
928 // TR photons produce hits with negative charge
929 Int_t nEl = ((Int_t) TMath::Abs(q));
930 for (Int_t iEl = 0; iEl < nEl; iEl++) {
931
932 // Now the real local coordinate system of the ROC
933 // column direction: locC
934 // row direction: locR
935 // time direction: locT
936 // locR and locC are identical to the coordinates of the corresponding
937 // volumina of the drift or amplification region.
938 // locT is defined relative to the wire plane (i.e. middle of amplification
26d3c914 939 // region), meaning locT = 0, and is negative for hits coming from the
625f5260 940 // drift region.
941 Double_t locC = loc[0];
942 Double_t locR = loc[1];
943 Double_t locT = loc[2];
944
945 // Electron attachment
946 if (simParam->ElAttachOn()) {
947 if (gRandom->Rndm() < (absdriftlength * elAttachProp)) {
948 continue;
f881dc35 949 }
625f5260 950 }
951
952 // Apply the diffusion smearing
953 if (simParam->DiffusionOn()) {
954 if (!(Diffusion(driftvelocity,absdriftlength,locR,locC,locT))) {
955 continue;
f881dc35 956 }
f881dc35 957 }
793ff80c 958
625f5260 959 // Apply E x B effects (depends on drift direction)
960 if (commonParam->ExBOn()) {
961 if (!(ExB(driftvelocity,driftlength,locC))) {
4329977a 962 continue;
963 }
729161c5 964 }
965
625f5260 966 // The electron position after diffusion and ExB in pad coordinates.
4329977a 967 // The pad row (z-direction)
625f5260 968 rowE = padPlane->GetPadRowNumberROC(locR);
969 if (rowE < 0) continue;
970 rowOffset = padPlane->GetPadRowOffsetROC(rowE,locR);
4329977a 971
972 // The pad column (rphi-direction)
625f5260 973 offsetTilt = padPlane->GetTiltOffset(rowOffset);
974 colE = padPlane->GetPadColNumber(locC+offsetTilt);
975 if (colE < 0) continue;
976 colOffset = padPlane->GetPadColOffset(colE,locC+offsetTilt);
b65e5048 977
625f5260 978 // Also re-retrieve drift velocity because col and row may have changed
979 driftvelocity = calVdriftDetValue * calVdriftROC->GetValue(colE,rowE);
980 Float_t t0 = calT0DetValue + calT0ROC->GetValue(colE,rowE);
981
982 // Convert the position to drift time [mus], using either constant drift velocity or
983 // time structure of drift cells (non-isochronity, GARFIELD calculation).
984 // Also add absolute time of hits to take pile-up events into account properly
985 Double_t drifttime;
986 if (simParam->TimeStructOn()) {
987 // Get z-position with respect to anode wire
58897a75 988 Double_t zz = row0 - locR + padPlane->GetAnodeWireOffset();
625f5260 989 zz -= ((Int_t)(2 * zz)) / 2.0;
990 if (zz > 0.25) {
991 zz = 0.5 - zz;
992 }
993 // Use drift time map (GARFIELD)
a076fc2f 994 drifttime = commonParam->TimeStruct(driftvelocity,0.5*kAmWidth-1.0*locT,zz)
625f5260 995 + hittime;
996 }
997 else {
998 // Use constant drift velocity
26d3c914 999 drifttime = TMath::Abs(locT) / driftvelocity
625f5260 1000 + hittime;
4329977a 1001 }
625f5260 1002
1003 // Apply the gas gain including fluctuations
1004 Double_t ggRndm = 0.0;
1005 do {
1006 ggRndm = gRandom->Rndm();
1007 } while (ggRndm <= 0);
eb52b657 1008 Double_t signal = -(simParam->GetGasGain()) * TMath::Log(ggRndm);
625f5260 1009
1010 // Apply the pad response
1011 if (simParam->PRFOn()) {
1012 // The distance of the electron to the center of the pad
1013 // in units of pad width
1014 Double_t dist = (colOffset - 0.5*padPlane->GetColSize(colE))
1015 / padPlane->GetColSize(colE);
1016 // This is a fixed parametrization, i.e. not dependent on
1017 // calibration values !
053767a4 1018 if (!(calibration->PadResponse(signal,dist,layer,padSignal))) continue;
625f5260 1019 }
1020 else {
1021 padSignal[0] = 0.0;
1022 padSignal[1] = signal;
1023 padSignal[2] = 0.0;
4329977a 1024 }
f881dc35 1025
625f5260 1026 // The time bin (always positive), with t0 distortion
1027 Double_t timeBinIdeal = drifttime * samplingRate + t0;
1028 // Protection
1029 if (TMath::Abs(timeBinIdeal) > 2*nTimeTotal) {
1030 timeBinIdeal = 2 * nTimeTotal;
1031 }
1032 Int_t timeBinTruncated = ((Int_t) timeBinIdeal);
1033 // The distance of the position to the middle of the timebin
1034 Double_t timeOffset = ((Float_t) timeBinTruncated
1035 + 0.5 - timeBinIdeal) / samplingRate;
3551db50 1036
625f5260 1037 // Sample the time response inside the drift region
1038 // + additional time bins before and after.
1039 // The sampling is done always in the middle of the time bin
1040 for (Int_t iTimeBin = TMath::Max(timeBinTruncated,0)
1041 ;iTimeBin < TMath::Min(timeBinTruncated+timeBinTRFend,nTimeTotal)
1042 ;iTimeBin++) {
1043
1044 // Apply the time response
1045 Double_t timeResponse = 1.0;
1046 Double_t crossTalk = 0.0;
1047 Double_t time = (iTimeBin - timeBinTruncated) / samplingRate + timeOffset;
58897a75 1048
625f5260 1049 if (simParam->TRFOn()) {
1050 timeResponse = simParam->TimeResponse(time);
f881dc35 1051 }
625f5260 1052 if (simParam->CTOn()) {
1053 crossTalk = simParam->CrossTalk(time);
f881dc35 1054 }
e23fbb27 1055
625f5260 1056 signalOld[0] = 0.0;
1057 signalOld[1] = 0.0;
1058 signalOld[2] = 0.0;
e23fbb27 1059
625f5260 1060 for (iPad = 0; iPad < kNpad; iPad++) {
f7336fa3 1061
625f5260 1062 Int_t colPos = colE + iPad - 1;
1063 if (colPos < 0) continue;
1064 if (colPos >= nColMax) break;
e23fbb27 1065
625f5260 1066 // Add the signals
b65e5048 1067 signalOld[iPad] = signals->GetData(rowE,colPos,iTimeBin);
e23fbb27 1068
625f5260 1069 if (colPos != colE) {
1070 // Cross talk added to non-central pads
1071 signalOld[iPad] += padSignal[iPad]
1072 * (timeResponse + crossTalk);
1073 }
1074 else {
1075 // W/o cross talk at central pad
1076 signalOld[iPad] += padSignal[iPad]
1077 * timeResponse;
1078 }
f881dc35 1079
b65e5048 1080 signals->SetData(rowE,colPos,iTimeBin,signalOld[iPad]);
625f5260 1081
1082 // Store the track index in the dictionary
1083 // Note: We store index+1 in order to allow the array to be compressed
b65e5048 1084 // Note2: Taking out the +1 in track
625f5260 1085 if (signalOld[iPad] > 0.0) {
1086 for (dict = 0; dict < kNdict; dict++) {
b65e5048 1087 Int_t oldTrack = dictionary[dict]->GetData(rowE,colPos,iTimeBin);
1088 if (oldTrack == track) break;
1089 if (oldTrack == -1 ) {
1090 dictionary[dict]->SetData(rowE,colPos,iTimeBin,track);
1091 break;
1092 }
f881dc35 1093 }
625f5260 1094 }
872a7aba 1095
625f5260 1096 } // Loop: pads
f7336fa3 1097
625f5260 1098 } // Loop: time bins
f7336fa3 1099
625f5260 1100 } // Loop: electrons of a single hit
f7336fa3 1101
625f5260 1102 } // Loop: hits
f7336fa3 1103
625f5260 1104 AliDebug(2,Form("Finished analyzing %d hits",nhit));
e23fbb27 1105
625f5260 1106 return kTRUE;
e23fbb27 1107
625f5260 1108}
793ff80c 1109
625f5260 1110//_____________________________________________________________________________
b65e5048 1111Bool_t AliTRDdigitizer::ConvertSignals(Int_t det, AliTRDarraySignal *signals)
625f5260 1112{
4329977a 1113 //
625f5260 1114 // Convert signals to digits
4329977a 1115 //
1116
625f5260 1117 AliDebug(1,Form("Start converting the signals for detector %d",det));
1118
1119 if (fSDigits) {
1120 // Convert the signal array to s-digits
1121 if (!Signal2SDigits(det,signals)) {
1122 return kFALSE;
793ff80c 1123 }
625f5260 1124 }
1125 else {
1126 // Convert the signal array to digits
1127 if (!Signal2ADC(det,signals)) {
1128 return kFALSE;
793ff80c 1129 }
d295185b 1130 // Run digital processing for digits
1131 RunDigitalProcessing(det);
625f5260 1132 }
f7336fa3 1133
625f5260 1134 // Compress the arrays
b65e5048 1135 CompressOutputArrays(det);
6244debe 1136
625f5260 1137 return kTRUE;
6244debe 1138
625f5260 1139}
4329977a 1140
625f5260 1141//_____________________________________________________________________________
b65e5048 1142Bool_t AliTRDdigitizer::Signal2ADC(Int_t det, AliTRDarraySignal *signals)
625f5260 1143{
1144 //
1145 // Converts the sampled electron signals to ADC values for a given chamber
1146 //
6244debe 1147
625f5260 1148 AliDebug(1,Form("Start converting signals to ADC values for detector=%d",det));
e23fbb27 1149
625f5260 1150 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1151 if (!calibration) {
1152 AliFatal("Could not get calibration object");
1153 return kFALSE;
1154 }
793ff80c 1155
625f5260 1156 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
1157 if (!simParam) {
1158 AliFatal("Could not get simulation parameters");
1159 return kFALSE;
1160 }
f7336fa3 1161
625f5260 1162 // Converts number of electrons to fC
1163 const Double_t kEl2fC = 1.602e-19 * 1.0e15;
0c24ba98 1164
625f5260 1165 // Coupling factor
1166 Double_t coupling = simParam->GetPadCoupling()
1167 * simParam->GetTimeCoupling();
1168 // Electronics conversion factor
1169 Double_t convert = kEl2fC
1170 * simParam->GetChipGain();
1171 // ADC conversion factor
1172 Double_t adcConvert = simParam->GetADCoutRange()
1173 / simParam->GetADCinRange();
1174 // The electronics baseline in mV
1175 Double_t baseline = simParam->GetADCbaseline()
1176 / adcConvert;
1177 // The electronics baseline in electrons
1178 Double_t baselineEl = baseline
1179 / convert;
1180
1181 Int_t row = 0;
1182 Int_t col = 0;
1183 Int_t time = 0;
1184
1185 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1186 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
966f6939 1187 Int_t nTimeTotal = fDigitsManager->GetDigitsParam()->GetNTimeBins();
abaf1f1d 1188
625f5260 1189 // The gainfactor calibration objects
1190 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
1191 AliTRDCalROC *calGainFactorROC = 0;
1192 Float_t calGainFactorDetValue = 0.0;
f7336fa3 1193
b65e5048 1194 AliTRDarrayADC *digits = 0x0;
e23fbb27 1195
625f5260 1196 if (!signals) {
1197 AliError(Form("Signals array for detector %d does not exist\n",det));
1198 return kFALSE;
1199 }
1200 if (signals->HasData()) {
1201 // Expand the container if neccessary
b65e5048 1202 signals->Expand();
625f5260 1203 }
1204 else {
1205 // Create missing containers
1206 signals->Allocate(nRowMax,nColMax,nTimeTotal);
f7336fa3 1207 }
1208
625f5260 1209 // Get the container for the digits of this detector
1210 if (fDigitsManager->HasSDigits()) {
1211 AliError("Digits manager has s-digits");
1212 return kFALSE;
1213 }
b65e5048 1214
1215 digits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det);
625f5260 1216 // Allocate memory space for the digits buffer
1217 if (!digits->HasData()) {
1218 digits->Allocate(nRowMax,nColMax,nTimeTotal);
0c24ba98 1219 }
1220
625f5260 1221 // Get the calibration objects
1222 calGainFactorROC = calibration->GetGainFactorROC(det);
1223 calGainFactorDetValue = calGainFactorDet->GetValue(det);
abaf1f1d 1224
625f5260 1225 // Create the digits for this chamber
1226 for (row = 0; row < nRowMax; row++ ) {
1227 for (col = 0; col < nColMax; col++ ) {
abaf1f1d 1228
625f5260 1229 // Check whether pad is masked
1230 // Bridged pads are not considered yet!!!
1231 if (calibration->IsPadMasked(det,col,row)) {
1232 continue;
1233 }
abaf1f1d 1234
625f5260 1235 // The gain factors
1236 Float_t padgain = calGainFactorDetValue
1237 * calGainFactorROC->GetValue(col,row);
1238 if (padgain <= 0) {
1239 AliError(Form("Not a valid gain %f, %d %d %d",padgain,det,col,row));
1240 }
abaf1f1d 1241
625f5260 1242 for (time = 0; time < nTimeTotal; time++) {
1243
1244 // Get the signal amplitude
b65e5048 1245 Float_t signalAmp = signals->GetData(row,col,time);
625f5260 1246 // Pad and time coupling
1247 signalAmp *= coupling;
1248 // Gain factors
1249 signalAmp *= padgain;
1250
1251 // Add the noise, starting from minus ADC baseline in electrons
1252 signalAmp = TMath::Max((Double_t) gRandom->Gaus(signalAmp,simParam->GetNoise())
1253 ,-baselineEl);
1254
1255 // Convert to mV
1256 signalAmp *= convert;
1257 // Add ADC baseline in mV
1258 signalAmp += baseline;
1259
1260 // Convert to ADC counts. Set the overflow-bit fADCoutRange if the
1261 // signal is larger than fADCinRange
1262 Short_t adc = 0;
1263 if (signalAmp >= simParam->GetADCinRange()) {
1264 adc = ((Short_t) simParam->GetADCoutRange());
1265 }
1266 else {
1267 adc = TMath::Nint(signalAmp * adcConvert);
1268 }
abaf1f1d 1269
b65e5048 1270 // Saving all digits
1271 digits->SetData(row,col,time,adc);
abaf1f1d 1272
625f5260 1273 } // for: time
b65e5048 1274
625f5260 1275 } // for: col
1276 } // for: row
b1113c6b 1277
625f5260 1278 return kTRUE;
b1113c6b 1279
1280}
1281
1282//_____________________________________________________________________________
b65e5048 1283Bool_t AliTRDdigitizer::Signal2SDigits(Int_t det, AliTRDarraySignal *signals)
abaf1f1d 1284{
1285 //
625f5260 1286 // Converts the sampled electron signals to s-digits
abaf1f1d 1287 //
1288
625f5260 1289 AliDebug(1,Form("Start converting signals to s-digits for detector=%d",det));
abaf1f1d 1290
4329977a 1291 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
9afbd7de 1292 if (!calibration) {
4329977a 1293 AliFatal("Could not get calibration object");
3551db50 1294 return kFALSE;
1295 }
6bf5f0ce 1296
625f5260 1297 Int_t row = 0;
1298 Int_t col = 0;
1299 Int_t time = 0;
9afbd7de 1300
625f5260 1301 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1302 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
966f6939 1303 Int_t nTimeTotal = fDigitsManager->GetDigitsParam()->GetNTimeBins();
e23fbb27 1304
625f5260 1305 // Get the container for the digits of this detector
b65e5048 1306
625f5260 1307 if (!fDigitsManager->HasSDigits()) {
1308 AliError("Digits manager has no s-digits");
1309 return kFALSE;
1310 }
b65e5048 1311
1312 AliTRDarraySignal *digits = (AliTRDarraySignal *) fDigitsManager->GetSDigits(det);
625f5260 1313 // Allocate memory space for the digits buffer
1314 if (!digits->HasData()) {
1315 digits->Allocate(nRowMax,nColMax,nTimeTotal);
1316 }
e23fbb27 1317
625f5260 1318 // Create the sdigits for this chamber
1319 for (row = 0; row < nRowMax; row++ ) {
1320 for (col = 0; col < nColMax; col++ ) {
1321 for (time = 0; time < nTimeTotal; time++) {
b65e5048 1322 digits->SetData(row,col,time,signals->GetData(row,col,time));
625f5260 1323 } // for: time
1324 } // for: col
1325 } // for: row
b65e5048 1326
625f5260 1327 return kTRUE;
abaf1f1d 1328
625f5260 1329}
abaf1f1d 1330
625f5260 1331//_____________________________________________________________________________
621310dd 1332Bool_t AliTRDdigitizer::Digits2SDigits(AliTRDdigitsManager * const manDig
1333 , AliTRDdigitsManager * const manSDig)
e7539003 1334{
1335 //
1336 // Converts digits into s-digits. Needed for embedding into real data.
1337 //
1338
1339 AliDebug(1,"Start converting digits to s-digits");
1340
6b4a4228 1341 if (!fGeo) {
1342 fGeo = new AliTRDgeometry();
1343 }
1344
e7539003 1345 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1346 if (!calibration) {
1347 AliFatal("Could not get calibration object");
1348 return kFALSE;
1349 }
1350
1351 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
1352 if (!simParam) {
1353 AliFatal("Could not get simulation parameters");
1354 return kFALSE;
1355 }
1356
1357 // Converts number of electrons to fC
1358 const Double_t kEl2fC = 1.602e-19 * 1.0e15;
1359
1360 // Coupling factor
1361 Double_t coupling = simParam->GetPadCoupling()
1362 * simParam->GetTimeCoupling();
1363 // Electronics conversion factor
1364 Double_t convert = kEl2fC
1365 * simParam->GetChipGain();
1366 // ADC conversion factor
1367 Double_t adcConvert = simParam->GetADCoutRange()
1368 / simParam->GetADCinRange();
1369 // The electronics baseline in mV
1370 Double_t baseline = simParam->GetADCbaseline()
1371 / adcConvert;
1372 // The electronics baseline in electrons
6b4a4228 1373 //Double_t baselineEl = baseline
1374 // / convert;
e7539003 1375
1376 // The gainfactor calibration objects
1377 //const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
1378 //AliTRDCalROC *calGainFactorROC = 0;
1379 //Float_t calGainFactorDetValue = 0.0;
1380
1381 Int_t row = 0;
1382 Int_t col = 0;
1383 Int_t time = 0;
1384
1385 for (Int_t det = 0; det < AliTRDgeometry::Ndet(); det++) {
1386
1387 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1388 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1389 Int_t nTimeTotal = calibration->GetNumberOfTimeBins();
1390
1391 // Get the calibration objects
1392 //calGainFactorROC = calibration->GetGainFactorROC(det);
1393 //calGainFactorDetValue = calGainFactorDet->GetValue(det);
1394
1395 // Get the digits
1396 AliTRDarrayADC *digits = (AliTRDarrayADC *) manDig->GetDigits(det);
1397
1398 if (!manSDig->HasSDigits()) {
1399 AliError("SDigits manager has no s-digits");
1400 return kFALSE;
1401 }
1402 // Get the s-digits
1403 AliTRDarraySignal *sdigits = (AliTRDarraySignal *) manSDig->GetSDigits(det);
1404 AliTRDarrayDictionary *tracks0 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,0);
1405 AliTRDarrayDictionary *tracks1 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,1);
1406 AliTRDarrayDictionary *tracks2 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,2);
1407 // Allocate memory space for the digits buffer
1408 sdigits->Allocate(nRowMax,nColMax,nTimeTotal);
1409 tracks0->Allocate(nRowMax,nColMax,nTimeTotal);
1410 tracks1->Allocate(nRowMax,nColMax,nTimeTotal);
1411 tracks2->Allocate(nRowMax,nColMax,nTimeTotal);
1412
45d77489 1413 if (digits->HasData()) {
1414
1415 digits->Expand();
1416
1417 // Create the sdigits for this chamber
1418 for (row = 0; row < nRowMax; row++ ) {
1419 for (col = 0; col < nColMax; col++ ) {
1420
1421 // The gain factors
1422 //Float_t padgain = calGainFactorDetValue
1423 // * calGainFactorROC->GetValue(col,row);
1424
1425 for (time = 0; time < nTimeTotal; time++) {
1426
1427 Short_t adcVal = digits->GetData(row,col,time);
1428 Double_t signal = (Double_t) adcVal;
1429 // ADC -> signal in mV
1430 signal /= adcConvert;
1431 // Subtract baseline in mV
1432 signal -= baseline;
1433 // Signal in mV -> signal in #electrons
1434 signal /= convert;
1435 // Gain factor
1436 //signal /= padgain; // Not needed for real data
1437 // Pad and time coupling
1438 signal /= coupling;
1439
1440 sdigits->SetData(row,col,time,signal);
1441 tracks0->SetData(row,col,time,0);
1442 tracks1->SetData(row,col,time,0);
1443 tracks2->SetData(row,col,time,0);
1444
1445 } // for: time
1446
1447 } // for: col
1448 } // for: row
e7539003 1449
45d77489 1450 } // if: has data
1451
e7539003 1452 sdigits->Compress(0);
1453 tracks0->Compress();
1454 tracks1->Compress();
1455 tracks2->Compress();
1456
45d77489 1457 // No compress just remove
1458 manDig->RemoveDigits(det);
1459 manDig->RemoveDictionaries(det);
1460
e7539003 1461 } // for: det
1462
1463 return kTRUE;
1464
1465}
1466
1467//_____________________________________________________________________________
625f5260 1468Bool_t AliTRDdigitizer::SDigits2Digits()
1469{
1470 //
1471 // Merges the input s-digits and converts them to normal digits
1472 //
e23fbb27 1473
625f5260 1474 if (!MergeSDigits()) {
1475 return kFALSE;
1476 }
f7336fa3 1477
625f5260 1478 return ConvertSDigits();
f7336fa3 1479
1480}
1481
1482//_____________________________________________________________________________
abaf1f1d 1483Bool_t AliTRDdigitizer::MergeSDigits()
16bf9884 1484{
1485 //
abaf1f1d 1486 // Merges the input s-digits:
1487 // - The amplitude of the different inputs are summed up.
1488 // - Of the track IDs from the input dictionaries only one is
1489 // kept for each input. This works for maximal 3 different merged inputs.
16bf9884 1490 //
1491
abaf1f1d 1492 // Number of track dictionary arrays
1493 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1494
4d18a639 1495 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
9afbd7de 1496 if (!simParam) {
4329977a 1497 AliFatal("Could not get simulation parameters");
3551db50 1498 return kFALSE;
1499 }
1500
4d18a639 1501 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
9afbd7de 1502 if (!calibration) {
4329977a 1503 AliFatal("Could not get calibration object");
3551db50 1504 return kFALSE;
1505 }
1506
abaf1f1d 1507 Int_t iDict = 0;
e23fbb27 1508 Int_t jDict = 0;
abaf1f1d 1509
b65e5048 1510 AliTRDarraySignal *digitsA;
1511 AliTRDarraySignal *digitsB;
1512 AliTRDarrayDictionary *dictionaryA[kNDict];
1513 AliTRDarrayDictionary *dictionaryB[kNDict];
abaf1f1d 1514
b65e5048 1515 AliTRDdigitsManager *mergeSDigitsManager = 0x0;
abaf1f1d 1516 // Get the first s-digits
1517 fSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->First();
9afbd7de 1518 if (!fSDigitsManager) {
7925de54 1519 AliError("No SDigits manager");
9afbd7de 1520 return kFALSE;
1521 }
abaf1f1d 1522
1523 // Loop through the other sets of s-digits
b65e5048 1524 mergeSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->After(fSDigitsManager);
abaf1f1d 1525
9afbd7de 1526 if (mergeSDigitsManager) {
7925de54 1527 AliDebug(1,Form("Merge %d input files.",fSDigitsManagerList->GetSize()));
9afbd7de 1528 }
1529 else {
7925de54 1530 AliDebug(1,"Only one input file.");
abaf1f1d 1531 }
3551db50 1532
b65e5048 1533 Int_t nTimeTotal = calibration->GetNumberOfTimeBins();
abaf1f1d 1534 Int_t iMerge = 0;
b65e5048 1535
abaf1f1d 1536 while (mergeSDigitsManager) {
1537
1538 iMerge++;
b65e5048 1539
abaf1f1d 1540 // Loop through the detectors
1541 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) {
1542
625f5260 1543 Int_t nRowMax = fGeo->GetPadPlane(iDet)->GetNrows();
1544 Int_t nColMax = fGeo->GetPadPlane(iDet)->GetNcols();
b65e5048 1545
abaf1f1d 1546 // Loop through the pixels of one detector and add the signals
b65e5048 1547 digitsA = (AliTRDarraySignal *) fSDigitsManager->GetSDigits(iDet);
1548 digitsB = (AliTRDarraySignal *) mergeSDigitsManager->GetSDigits(iDet);
1549 digitsA->Expand();
1550 if (!digitsA->HasData()) continue;
1551 digitsB->Expand();
1552 if (!digitsB->HasData()) continue;
1553
abaf1f1d 1554 for (iDict = 0; iDict < kNDict; iDict++) {
b65e5048 1555 dictionaryA[iDict] = (AliTRDarrayDictionary *) fSDigitsManager->GetDictionary(iDet,iDict);
1556 dictionaryB[iDict] = (AliTRDarrayDictionary *) mergeSDigitsManager->GetDictionary(iDet,iDict);
1557 dictionaryA[iDict]->Expand();
abaf1f1d 1558 dictionaryB[iDict]->Expand();
1559 }
1560
4487dad0 1561 // Merge only detectors that contain a signal
1562 Bool_t doMerge = kTRUE;
1563 if (fMergeSignalOnly) {
b65e5048 1564 if (digitsA->GetOverThreshold(0) == 0) {
1565 doMerge = kFALSE;
4487dad0 1566 }
abaf1f1d 1567 }
b65e5048 1568
4487dad0 1569 if (doMerge) {
b65e5048 1570
1571 AliDebug(1,Form("Merge detector %d of input no.%d",iDet,iMerge+1));
1572
1573 for (Int_t iRow = 0; iRow < nRowMax; iRow++ ) {
1574 for (Int_t iCol = 0; iCol < nColMax; iCol++ ) {
1575 for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
1576
4487dad0 1577 // Add the amplitudes of the summable digits
b65e5048 1578 Float_t ampA = digitsA->GetData(iRow,iCol,iTime);
1579 Float_t ampB = digitsB->GetData(iRow,iCol,iTime);
1580 ampA += ampB;
1581 digitsA->SetData(iRow,iCol,iTime,ampA);
1582
1583 // Add the mask to the track id if defined.
1584 for (iDict = 0; iDict < kNDict; iDict++) {
1585 Int_t trackB = dictionaryB[iDict]->GetData(iRow,iCol,iTime);
1586 if ((fMasks) && (trackB > 0)) {
1587 for (jDict = 0; jDict < kNDict; jDict++) {
1588 Int_t trackA = dictionaryA[iDict]->GetData(iRow,iCol,iTime);
1589 if (trackA == 0) {
1590 trackA = trackB + fMasks[iMerge];
1591 dictionaryA[iDict]->SetData(iRow,iCol,iTime,trackA);
625f5260 1592 } // if: track A == 0
b65e5048 1593 } // for: jDict
1594 } // if: fMasks and trackB > 0
625f5260 1595 } // for: iDict
abaf1f1d 1596
625f5260 1597 } // for: iTime
1598 } // for: iCol
1599 } // for: iRow
4487dad0 1600
625f5260 1601 } // if: doMerge
1602
1603 mergeSDigitsManager->RemoveDigits(iDet);
1604 mergeSDigitsManager->RemoveDictionaries(iDet);
b65e5048 1605
abaf1f1d 1606 if (fCompress) {
b65e5048 1607 digitsA->Compress(0);
1608 for (iDict = 0; iDict < kNDict; iDict++) {
1609 dictionaryA[iDict]->Compress();
abaf1f1d 1610 }
1611 }
b65e5048 1612
625f5260 1613 } // for: detectors
b65e5048 1614
abaf1f1d 1615 // The next set of s-digits
b65e5048 1616 mergeSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->After(mergeSDigitsManager);
1617
625f5260 1618 } // while: mergeDigitsManagers
b65e5048 1619
625f5260 1620 return kTRUE;
1621
1622}
1623
1624//_____________________________________________________________________________
1625Bool_t AliTRDdigitizer::ConvertSDigits()
1626{
1627 //
1628 // Converts s-digits to normal digits
1629 //
1630
b65e5048 1631 AliTRDarraySignal *digitsIn = 0x0;
625f5260 1632
1633 if (!fSDigitsManager->HasSDigits()) {
1634 AliError("No s-digits in digits manager");
1635 return kFALSE;
abaf1f1d 1636 }
1637
625f5260 1638 // Loop through the detectors
1639 for (Int_t det = 0; det < AliTRDgeometry::Ndet(); det++) {
1640
1641 // Get the merged s-digits (signals)
b65e5048 1642 digitsIn = (AliTRDarraySignal *) fSDigitsManager->GetSDigits(det);
625f5260 1643 if (!digitsIn->HasData()) {
1644 AliDebug(2,Form("No digits for det=%d",det));
1645 continue;
1646 }
b0a41e80 1647
625f5260 1648 // Convert the merged sdigits to digits
1649 if (!Signal2ADC(det,digitsIn)) {
1650 continue;
1651 }
1652
1653 // Copy the dictionary information to the output array
1654 if (!CopyDictionary(det)) {
1655 continue;
1656 }
1657
1658 // Delete
1659 fSDigitsManager->RemoveDigits(det);
1660 fSDigitsManager->RemoveDictionaries(det);
1661
d295185b 1662 // Run digital processing
1663 RunDigitalProcessing(det);
1664
625f5260 1665 // Compress the arrays
1666 CompressOutputArrays(det);
1667
1668 } // for: detector numbers
1669
b0a41e80 1670
16bf9884 1671 return kTRUE;
1672
1673}
1674
1675//_____________________________________________________________________________
625f5260 1676Bool_t AliTRDdigitizer::CopyDictionary(Int_t det)
abaf1f1d 1677{
1678 //
625f5260 1679 // Copies the dictionary information from the s-digits arrays
1680 // to the output arrays
abaf1f1d 1681 //
1682
625f5260 1683 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1684 if (!calibration) {
1685 AliFatal("Could not get calibration object");
4d18a639 1686 return kFALSE;
1687 }
abaf1f1d 1688
625f5260 1689 AliDebug(1,Form("Start copying dictionaries for detector=%d",det));
1690
1691 const Int_t kNDict = AliTRDdigitsManager::kNDict;
b65e5048 1692 AliTRDarrayDictionary *dictionaryIn[kNDict];
1693 AliTRDarrayDictionary *dictionaryOut[kNDict];
625f5260 1694
1695 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1696 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1697 Int_t nTimeTotal = calibration->GetNumberOfTimeBins();
1698
1699 Int_t row = 0;
1700 Int_t col = 0;
1701 Int_t time = 0;
1702 Int_t dict = 0;
1703
1704 for (dict = 0; dict < kNDict; dict++) {
1705
b65e5048 1706 dictionaryIn[dict] = (AliTRDarrayDictionary *) fSDigitsManager->GetDictionary(det,dict);
625f5260 1707 dictionaryIn[dict]->Expand();
b65e5048 1708 dictionaryOut[dict] = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
625f5260 1709 dictionaryOut[dict]->Allocate(nRowMax,nColMax,nTimeTotal);
1710
1711 for (row = 0; row < nRowMax; row++) {
1712 for (col = 0; col < nColMax; col++) {
1713 for (time = 0; time < nTimeTotal; time++) {
b65e5048 1714 Int_t track = dictionaryIn[dict]->GetData(row,col,time);
1715 dictionaryOut[dict]->SetData(row,col,time,track);
625f5260 1716 } // for: time
1717 } // for: col
1718 } // for: row
b65e5048 1719
625f5260 1720 } // for: dictionaries
b65e5048 1721
625f5260 1722 return kTRUE;
1723
1724}
1725
1726//_____________________________________________________________________________
1727void AliTRDdigitizer::CompressOutputArrays(Int_t det)
1728{
1729 //
1730 // Compress the output arrays
1731 //
1732
1733 const Int_t kNDict = AliTRDdigitsManager::kNDict;
b65e5048 1734 AliTRDarrayDictionary *dictionary = 0x0;
625f5260 1735
1736 if (fCompress) {
1737
b65e5048 1738 if (!fSDigits) {
1739 AliTRDarrayADC *digits = 0x0;
1740 digits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det);
1741 digits->Compress();
1742 }
1743
1744 if (fSDigits) {
1745 AliTRDarraySignal *digits = 0x0;
1746 digits = (AliTRDarraySignal *) fDigitsManager->GetSDigits(det);
1747 digits->Compress(0);
1748 }
1749
625f5260 1750 for (Int_t dict = 0; dict < kNDict; dict++) {
b65e5048 1751 dictionary = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
1752 dictionary->Compress();
625f5260 1753 }
1754
1755 }
abaf1f1d 1756
1757}
1758
1759//_____________________________________________________________________________
0a29d0f1 1760Bool_t AliTRDdigitizer::WriteDigits() const
f7336fa3 1761{
1762 //
1763 // Writes out the TRD-digits and the dictionaries
1764 //
1765
4d18a639 1766 // Write parameters
bdbb05bb 1767 fRunLoader->CdGAFile();
bdbb05bb 1768
da581aea 1769 // Store the digits and the dictionary in the tree
abaf1f1d 1770 return fDigitsManager->WriteDigits();
f7336fa3 1771
1772}
793ff80c 1773
1774//_____________________________________________________________________________
88cb7938 1775void AliTRDdigitizer::InitOutput(Int_t iEvent)
8e64dd77 1776{
1777 //
1778 // Initializes the output branches
1779 //
1780
1781 fEvent = iEvent;
88cb7938 1782
9afbd7de 1783 if (!fRunLoader) {
1784 AliError("Run Loader is NULL");
1785 return;
1786 }
1787
4329977a 1788 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
9afbd7de 1789 if (!loader) {
1790 AliError("Can not get TRD loader from Run Loader");
1791 return;
1792 }
88cb7938 1793
4d18a639 1794 TTree *tree = 0;
88cb7938 1795
9afbd7de 1796 if (fSDigits) {
1797 // If we produce SDigits
88cb7938 1798 tree = loader->TreeS();
9afbd7de 1799 if (!tree) {
88cb7938 1800 loader->MakeTree("S");
1801 tree = loader->TreeS();
9afbd7de 1802 }
1803 }
1804 else {
1805 // If we produce Digits
1806 tree = loader->TreeD();
1807 if (!tree) {
1808 loader->MakeTree("D");
1809 tree = loader->TreeD();
1810 }
1811 }
88cb7938 1812 fDigitsManager->SetEvent(iEvent);
1813 fDigitsManager->MakeBranch(tree);
8e64dd77 1814
1815}
3551db50 1816
3551db50 1817//_____________________________________________________________________________
a076fc2f 1818Int_t AliTRDdigitizer::Diffusion(Float_t vdrift, Double_t absdriftlength
1819 , Double_t &lRow, Double_t &lCol, Double_t &lTime)
3551db50 1820{
1821 //
a076fc2f 1822 // Applies the diffusion smearing to the position of a single electron.
1823 // Depends on absolute drift length.
3551db50 1824 //
1825
a076fc2f 1826 Float_t diffL = 0.0;
1827 Float_t diffT = 0.0;
4d18a639 1828
a076fc2f 1829 if (AliTRDCommonParam::Instance()->GetDiffCoeff(diffL,diffT,vdrift)) {
3551db50 1830
a076fc2f 1831 Float_t driftSqrt = TMath::Sqrt(absdriftlength);
1832 Float_t sigmaT = driftSqrt * diffT;
1833 Float_t sigmaL = driftSqrt * diffL;
1834 lRow = gRandom->Gaus(lRow ,sigmaT);
1835 lCol = gRandom->Gaus(lCol ,sigmaT * GetLorentzFactor(vdrift));
1836 lTime = gRandom->Gaus(lTime,sigmaL * GetLorentzFactor(vdrift));
4d18a639 1837
a076fc2f 1838 return 1;
7754cd1f 1839
3551db50 1840 }
a076fc2f 1841 else {
3551db50 1842
a076fc2f 1843 return 0;
1b95a37b 1844
3551db50 1845 }
9afbd7de 1846
3551db50 1847}
3551db50 1848
1849//_____________________________________________________________________________
1850Float_t AliTRDdigitizer::GetLorentzFactor(Float_t vd)
1851{
9afbd7de 1852 //
a076fc2f 1853 // Returns the Lorentz factor
9afbd7de 1854 //
1855
a076fc2f 1856 Double_t omegaTau = AliTRDCommonParam::Instance()->GetOmegaTau(vd);
1857 Double_t lorentzFactor = 1.0;
1858 if (AliTRDCommonParam::Instance()->ExBOn()) {
1859 lorentzFactor = 1.0 / (1.0 + omegaTau*omegaTau);
1860 }
4d18a639 1861
a076fc2f 1862 return lorentzFactor;
9afbd7de 1863
3551db50 1864}
1865
1866//_____________________________________________________________________________
4329977a 1867Int_t AliTRDdigitizer::ExB(Float_t vdrift, Double_t driftlength, Double_t &lCol)
3551db50 1868{
1869 //
4329977a 1870 // Applies E x B effects to the position of a single electron.
1871 // Depends on signed drift length.
3551db50 1872 //
4329977a 1873
a076fc2f 1874 lCol = lCol
1875 + AliTRDCommonParam::Instance()->GetOmegaTau(vdrift)
1876 * driftlength;
3551db50 1877
1878 return 1;
9afbd7de 1879
3551db50 1880}
b65e5048 1881
1882//_____________________________________________________________________________
d295185b 1883void AliTRDdigitizer::RunDigitalProcessing(Int_t det)
b65e5048 1884{
1885 //
b0a41e80 1886 // Run the digital processing in the TRAP
b65e5048 1887 //
1888
b0a41e80 1889 AliTRDfeeParam *feeParam = AliTRDfeeParam::Instance();
b65e5048 1890
1891 //Create and initialize the mcm object
b0a41e80 1892 AliTRDmcmSim* mcmfast = new AliTRDmcmSim();
b65e5048 1893
d295185b 1894 AliTRDarrayADC *digits = fDigitsManager->GetDigits(det);
1895 if (!digits)
1896 return;
1897
b65e5048 1898 //Call the methods in the mcm class using the temporary array as input
64e3d742 1899 for(Int_t rob = 0; rob < digits->GetNrow() / 2; rob++)
b0a41e80 1900 {
1901 for(Int_t mcm = 0; mcm < 16; mcm++)
b65e5048 1902 {
b0a41e80 1903 mcmfast->Init(det, rob, mcm);
40bd6ee4 1904 mcmfast->SetData(digits, fDigitsManager);
b65e5048 1905 mcmfast->Filter();
c8b1590d 1906 if (feeParam->GetTracklet()) {
b0a41e80 1907 mcmfast->Tracklet();
c8b1590d 1908 mcmfast->StoreTracklets();
1909 }
b65e5048 1910 mcmfast->ZSMapping();
b0a41e80 1911 mcmfast->WriteData(digits);
b65e5048 1912 }
b0a41e80 1913 }
b65e5048 1914
b65e5048 1915 delete mcmfast;
d295185b 1916
b65e5048 1917}