commenting unused parameter
[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) {
d4cbb500 195 // s-digitsmanager will be deleted via list
4d18a639 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;
5896bc23 611
612 //
613 if (calibration->GetNumberOfTimeBinsDCS() != AliTRDSimParam::Instance()->GetNTimeBins()) {
614 AliWarning(Form("Number of time bins is different to OCDB value [SIM=%d, OCDB=%d]"
615 ,AliTRDSimParam::Instance()->GetNTimeBins()
616 ,calibration->GetNumberOfTimeBinsDCS()));
617 }
625f5260 618
619 // Sort all hits according to detector number
620 if (!SortHits(hits,nhit)) {
621 AliError("Sorting hits failed");
622 return kFALSE;
623 }
624
625 // Loop through all detectors
626 for (Int_t det = 0; det < kNdet; det++) {
627
628 // Detectors that are switched off, not installed, etc.
629 if (( calibration->IsChamberInstalled(det)) &&
b65e5048 630 (!calibration->IsChamberMasked(det)) &&
625f5260 631 ( fGeo->ChamberInGeometry(det)) &&
632 (nhit[det] > 0)) {
633
b65e5048 634 signals = new AliTRDarraySignal();
635
625f5260 636 // Convert the hits of the current detector to detector signals
637 if (!ConvertHits(det,hits[det],nhit[det],signals)) {
b65e5048 638 AliError(Form("Conversion of hits failed for detector=%d",det));
625f5260 639 return kFALSE;
640 }
641 // Convert the detector signals to digits or s-digits
642 if (!ConvertSignals(det,signals)) {
b65e5048 643 AliError(Form("Conversion of signals failed for detector=%d",det));
644 return kFALSE;
625f5260 645 }
646
647 // Delete the signals array
648 delete signals;
649 signals = 0x0;
650
651 } // if: detector status
652
27cea06a 653 delete [] hits[det];
654
625f5260 655 } // for: detector
656
ce4786b9 657 if (!fSDigits)
658 AliRunLoader::Instance()->GetLoader("TRDLoader")->GetDataLoader("tracklets")->WriteData("OVERWRITE");
659
625f5260 660 delete [] hits;
661 delete [] nhit;
662
5896bc23 663 // Save the values for the raw data headers
a0446ff1 664 fDigitsManager->GetDigitsParam()->SetNTimeBinsAll(AliTRDSimParam::Instance()->GetNTimeBins());
665 fDigitsManager->GetDigitsParam()->SetADCbaselineAll(AliTRDSimParam::Instance()->GetADCbaseline());
5896bc23 666
625f5260 667 return kTRUE;
668
669}
670
671//_____________________________________________________________________________
672Bool_t AliTRDdigitizer::SortHits(Float_t **hits, Int_t *nhit)
673{
674 //
675 // Read all the hits and sorts them according to detector number
676 // in the output array <hits>.
677 //
678
679 AliDebug(1,"Start sorting hits");
680
681 const Int_t kNdet = AliTRDgeometry::Ndet();
682 // Size of the hit vector
683 const Int_t kNhit = 6;
684
685 Float_t *xyz = 0;
686 Int_t nhitTrk = 0;
687
688 Int_t *lhit = new Int_t[kNdet];
689
690 for (Int_t det = 0; det < kNdet; det++) {
691 lhit[det] = 0;
692 nhit[det] = 0;
693 hits[det] = 0;
694 }
695
696 AliLoader *gimme = fRunLoader->GetLoader("TRDLoader");
697 if (!gimme->TreeH()) {
698 gimme->LoadHits();
699 }
700 TTree *hitTree = gimme->TreeH();
701 if (hitTree == 0x0) {
702 AliError("Can not get TreeH");
703 return kFALSE;
704 }
705 fTRD->SetTreeAddress();
706
707 // Get the number of entries in the hit tree
708 // (Number of primary particles creating a hit somewhere)
709 Int_t nTrk = (Int_t) hitTree->GetEntries();
710 AliDebug(1,Form("Found %d tracks",nTrk));
711
712 // Loop through all the tracks in the tree
713 for (Int_t iTrk = 0; iTrk < nTrk; iTrk++) {
714
3e2e3ece 715 gAlice->GetMCApp()->ResetHits();
625f5260 716 hitTree->GetEvent(iTrk);
717
718 if (!fTRD->Hits()) {
719 AliError(Form("No hits array for track = %d",iTrk));
720 continue;
721 }
722
723 // Number of hits for this track
724 nhitTrk = fTRD->Hits()->GetEntriesFast();
725
726 Int_t hitCnt = 0;
727 // Loop through the TRD hits
728 AliTRDhit *hit = (AliTRDhit *) fTRD->FirstHit(-1);
729 while (hit) {
730
731 hitCnt++;
732
733 // Don't analyze test hits
734 if (((Int_t) hit->GetCharge()) != 0) {
735
736 Int_t trk = hit->Track();
737 Int_t det = hit->GetDetector();
738 Int_t q = hit->GetCharge();
739 Float_t x = hit->X();
740 Float_t y = hit->Y();
741 Float_t z = hit->Z();
742 Float_t time = hit->GetTime();
743
744 if (nhit[det] == lhit[det]) {
745 // Inititialization of new detector
746 xyz = new Float_t[kNhit*(nhitTrk+lhit[det])];
747 if (hits[det]) {
748 memcpy(xyz,hits[det],sizeof(Float_t)*kNhit*lhit[det]);
749 delete [] hits[det];
750 }
751 lhit[det] += nhitTrk;
752 hits[det] = xyz;
753 }
754 else {
755 xyz = hits[det];
756 }
757 xyz[nhit[det]*kNhit+0] = x;
758 xyz[nhit[det]*kNhit+1] = y;
759 xyz[nhit[det]*kNhit+2] = z;
760 xyz[nhit[det]*kNhit+3] = q;
761 xyz[nhit[det]*kNhit+4] = trk;
762 xyz[nhit[det]*kNhit+5] = time;
763 nhit[det]++;
764
765 } // if: charge != 0
766
767 hit = (AliTRDhit *) fTRD->NextHit();
768
769 } // for: hits of one track
770
771 } // for: tracks
772
773 delete [] lhit;
774
775 return kTRUE;
776
777}
f7336fa3 778
625f5260 779//_____________________________________________________________________________
621310dd 780Bool_t AliTRDdigitizer::ConvertHits(Int_t det
781 , const Float_t * const hits
782 , Int_t nhit
b65e5048 783 , AliTRDarraySignal *signals)
625f5260 784{
785 //
786 // Converts the detectorwise sorted hits to detector signals
787 //
788
789 AliDebug(1,Form("Start converting hits for detector=%d (nhits=%d)",det,nhit));
f7336fa3 790
793ff80c 791 // Number of pads included in the pad response
a5cadd36 792 const Int_t kNpad = 3;
793ff80c 793 // Number of track dictionary arrays
625f5260 794 const Int_t kNdict = AliTRDdigitsManager::kNDict;
795 // Size of the hit vector
796 const Int_t kNhit = 6;
793ff80c 797
4329977a 798 // Width of the amplification region
799 const Float_t kAmWidth = AliTRDgeometry::AmThick();
3becff3c 800 // Width of the drift region
ccb4315c 801 const Float_t kDrWidth = AliTRDgeometry::DrThick();
4329977a 802 // Drift + amplification region
803 const Float_t kDrMin = - 0.5 * kAmWidth;
804 const Float_t kDrMax = kDrWidth + 0.5 * kAmWidth;
3551db50 805
625f5260 806 Int_t iPad = 0;
807 Int_t dict = 0;
808 Int_t timeBinTRFend = 1;
872a7aba 809
a5cadd36 810 Double_t pos[3];
4329977a 811 Double_t loc[3];
a5cadd36 812 Double_t padSignal[kNpad];
813 Double_t signalOld[kNpad];
872a7aba 814
b65e5048 815 AliTRDarrayDictionary *dictionary[kNdict];
4329977a 816
9afbd7de 817 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
9afbd7de 818 AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance();
625f5260 819 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
820
3becff3c 821 if (!commonParam) {
4329977a 822 AliFatal("Could not get common parameterss");
3551db50 823 return kFALSE;
824 }
625f5260 825 if (!simParam) {
826 AliFatal("Could not get simulation parameters");
827 return kFALSE;
828 }
3becff3c 829 if (!calibration) {
4329977a 830 AliFatal("Could not get calibration object");
3551db50 831 return kFALSE;
832 }
833
625f5260 834 // Get the detector wise calibration objects
835 AliTRDCalROC *calVdriftROC = 0;
836 Float_t calVdriftDetValue = 0.0;
837 const AliTRDCalDet *calVdriftDet = calibration->GetVdriftDet();
838 AliTRDCalROC *calT0ROC = 0;
839 Float_t calT0DetValue = 0.0;
840 const AliTRDCalDet *calT0Det = calibration->GetT0Det();
4329977a 841
4329977a 842 if (simParam->TRFOn()) {
843 timeBinTRFend = ((Int_t) (simParam->GetTRFhi()
844 * commonParam->GetSamplingFrequency())) - 1;
4329977a 845 }
846
5896bc23 847 Int_t nTimeTotal = simParam->GetNTimeBins();
b43a3e17 848 Float_t samplingRate = commonParam->GetSamplingFrequency();
4329977a 849 Float_t elAttachProp = simParam->GetElAttachProp() / 100.0;
a328fff9 850
625f5260 851 AliTRDpadPlane *padPlane = fGeo->GetPadPlane(det);
b65e5048 852 Int_t layer = fGeo->GetLayer(det); //update
625f5260 853 Float_t row0 = padPlane->GetRow0ROC();
854 Int_t nRowMax = padPlane->GetNrows();
855 Int_t nColMax = padPlane->GetNcols();
856
857 // Create a new array for the signals
858 signals->Allocate(nRowMax,nColMax,nTimeTotal);
859
860 // Create a new array for the dictionary
861 for (dict = 0; dict < kNdict; dict++) {
b65e5048 862 dictionary[dict] = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
625f5260 863 dictionary[dict]->Allocate(nRowMax,nColMax,nTimeTotal);
864 }
865
866 // Loop through the hits in this detector
867 for (Int_t hit = 0; hit < nhit; hit++) {
868
869 pos[0] = hits[hit*kNhit+0];
870 pos[1] = hits[hit*kNhit+1];
871 pos[2] = hits[hit*kNhit+2];
872 Float_t q = hits[hit*kNhit+3];
873 Float_t hittime = hits[hit*kNhit+5];
874 Int_t track = ((Int_t) hits[hit*kNhit+4]);
875
876 Int_t inDrift = 1;
877
878 // Find the current volume with the geo manager
879 gGeoManager->SetCurrentPoint(pos);
880 gGeoManager->FindNode();
881 if (strstr(gGeoManager->GetPath(),"/UK")) {
882 inDrift = 0;
883 }
793ff80c 884
625f5260 885 // Get the calibration objects
886 calVdriftROC = calibration->GetVdriftROC(det);
887 calVdriftDetValue = calVdriftDet->GetValue(det);
888 calT0ROC = calibration->GetT0ROC(det);
889 calT0DetValue = calT0Det->GetValue(det);
890
891 // Go to the local coordinate system:
892 // loc[0] - col direction in amplification or driftvolume
893 // loc[1] - row direction in amplification or driftvolume
894 // loc[2] - time direction in amplification or driftvolume
895 gGeoManager->MasterToLocal(pos,loc);
896 if (inDrift) {
897 // Relative to middle of amplification region
898 loc[2] = loc[2] - kDrWidth/2.0 - kAmWidth/2.0;
899 }
793ff80c 900
625f5260 901 // The driftlength [cm] (w/o diffusion yet !).
902 // It is negative if the hit is between pad plane and anode wires.
903 Double_t driftlength = -1.0 * loc[2];
e23fbb27 904
625f5260 905 // Stupid patch to take care of TR photons that are absorbed
906 // outside the chamber volume. A real fix would actually need
907 // a more clever implementation of the TR hit generation
908 if (q < 0.0) {
909 if ((loc[1] < padPlane->GetRowEndROC()) ||
910 (loc[1] > padPlane->GetRow0ROC())) {
f881dc35 911 continue;
912 }
625f5260 913 if ((driftlength < kDrMin) ||
914 (driftlength > kDrMax)) {
915 continue;
4329977a 916 }
625f5260 917 }
f881dc35 918
625f5260 919 // Get row and col of unsmeared electron to retrieve drift velocity
920 // The pad row (z-direction)
921 Int_t rowE = padPlane->GetPadRowNumberROC(loc[1]);
922 if (rowE < 0) {
923 continue;
924 }
925 Double_t rowOffset = padPlane->GetPadRowOffsetROC(rowE,loc[1]);
926 // The pad column (rphi-direction)
927 Double_t offsetTilt = padPlane->GetTiltOffset(rowOffset);
928 Int_t colE = padPlane->GetPadColNumber(loc[0]+offsetTilt);
929 if (colE < 0) {
930 continue;
931 }
0a17cc30 932 Double_t colOffset = 0.0;
f881dc35 933
625f5260 934 // Normalized drift length
935 Float_t driftvelocity = calVdriftDetValue * calVdriftROC->GetValue(colE,rowE);
936 Double_t absdriftlength = TMath::Abs(driftlength);
937 if (commonParam->ExBOn()) {
938 absdriftlength /= TMath::Sqrt(GetLorentzFactor(driftvelocity));
939 }
940
941 // Loop over all electrons of this hit
942 // TR photons produce hits with negative charge
943 Int_t nEl = ((Int_t) TMath::Abs(q));
944 for (Int_t iEl = 0; iEl < nEl; iEl++) {
945
946 // Now the real local coordinate system of the ROC
947 // column direction: locC
948 // row direction: locR
949 // time direction: locT
950 // locR and locC are identical to the coordinates of the corresponding
951 // volumina of the drift or amplification region.
952 // locT is defined relative to the wire plane (i.e. middle of amplification
26d3c914 953 // region), meaning locT = 0, and is negative for hits coming from the
625f5260 954 // drift region.
955 Double_t locC = loc[0];
956 Double_t locR = loc[1];
957 Double_t locT = loc[2];
958
959 // Electron attachment
960 if (simParam->ElAttachOn()) {
961 if (gRandom->Rndm() < (absdriftlength * elAttachProp)) {
962 continue;
f881dc35 963 }
625f5260 964 }
965
966 // Apply the diffusion smearing
967 if (simParam->DiffusionOn()) {
968 if (!(Diffusion(driftvelocity,absdriftlength,locR,locC,locT))) {
969 continue;
f881dc35 970 }
f881dc35 971 }
793ff80c 972
625f5260 973 // Apply E x B effects (depends on drift direction)
974 if (commonParam->ExBOn()) {
975 if (!(ExB(driftvelocity,driftlength,locC))) {
4329977a 976 continue;
977 }
729161c5 978 }
979
625f5260 980 // The electron position after diffusion and ExB in pad coordinates.
4329977a 981 // The pad row (z-direction)
625f5260 982 rowE = padPlane->GetPadRowNumberROC(locR);
983 if (rowE < 0) continue;
984 rowOffset = padPlane->GetPadRowOffsetROC(rowE,locR);
4329977a 985
986 // The pad column (rphi-direction)
625f5260 987 offsetTilt = padPlane->GetTiltOffset(rowOffset);
988 colE = padPlane->GetPadColNumber(locC+offsetTilt);
989 if (colE < 0) continue;
990 colOffset = padPlane->GetPadColOffset(colE,locC+offsetTilt);
b65e5048 991
625f5260 992 // Also re-retrieve drift velocity because col and row may have changed
993 driftvelocity = calVdriftDetValue * calVdriftROC->GetValue(colE,rowE);
994 Float_t t0 = calT0DetValue + calT0ROC->GetValue(colE,rowE);
995
996 // Convert the position to drift time [mus], using either constant drift velocity or
997 // time structure of drift cells (non-isochronity, GARFIELD calculation).
998 // Also add absolute time of hits to take pile-up events into account properly
999 Double_t drifttime;
1000 if (simParam->TimeStructOn()) {
1001 // Get z-position with respect to anode wire
58897a75 1002 Double_t zz = row0 - locR + padPlane->GetAnodeWireOffset();
625f5260 1003 zz -= ((Int_t)(2 * zz)) / 2.0;
1004 if (zz > 0.25) {
1005 zz = 0.5 - zz;
1006 }
1007 // Use drift time map (GARFIELD)
a076fc2f 1008 drifttime = commonParam->TimeStruct(driftvelocity,0.5*kAmWidth-1.0*locT,zz)
625f5260 1009 + hittime;
1010 }
1011 else {
1012 // Use constant drift velocity
26d3c914 1013 drifttime = TMath::Abs(locT) / driftvelocity
625f5260 1014 + hittime;
4329977a 1015 }
625f5260 1016
1017 // Apply the gas gain including fluctuations
1018 Double_t ggRndm = 0.0;
1019 do {
1020 ggRndm = gRandom->Rndm();
1021 } while (ggRndm <= 0);
eb52b657 1022 Double_t signal = -(simParam->GetGasGain()) * TMath::Log(ggRndm);
625f5260 1023
1024 // Apply the pad response
1025 if (simParam->PRFOn()) {
1026 // The distance of the electron to the center of the pad
1027 // in units of pad width
1028 Double_t dist = (colOffset - 0.5*padPlane->GetColSize(colE))
1029 / padPlane->GetColSize(colE);
1030 // This is a fixed parametrization, i.e. not dependent on
1031 // calibration values !
053767a4 1032 if (!(calibration->PadResponse(signal,dist,layer,padSignal))) continue;
625f5260 1033 }
1034 else {
1035 padSignal[0] = 0.0;
1036 padSignal[1] = signal;
1037 padSignal[2] = 0.0;
4329977a 1038 }
f881dc35 1039
625f5260 1040 // The time bin (always positive), with t0 distortion
1041 Double_t timeBinIdeal = drifttime * samplingRate + t0;
1042 // Protection
1043 if (TMath::Abs(timeBinIdeal) > 2*nTimeTotal) {
1044 timeBinIdeal = 2 * nTimeTotal;
1045 }
1046 Int_t timeBinTruncated = ((Int_t) timeBinIdeal);
1047 // The distance of the position to the middle of the timebin
1048 Double_t timeOffset = ((Float_t) timeBinTruncated
1049 + 0.5 - timeBinIdeal) / samplingRate;
3551db50 1050
625f5260 1051 // Sample the time response inside the drift region
1052 // + additional time bins before and after.
1053 // The sampling is done always in the middle of the time bin
1054 for (Int_t iTimeBin = TMath::Max(timeBinTruncated,0)
1055 ;iTimeBin < TMath::Min(timeBinTruncated+timeBinTRFend,nTimeTotal)
1056 ;iTimeBin++) {
1057
1058 // Apply the time response
1059 Double_t timeResponse = 1.0;
1060 Double_t crossTalk = 0.0;
1061 Double_t time = (iTimeBin - timeBinTruncated) / samplingRate + timeOffset;
58897a75 1062
625f5260 1063 if (simParam->TRFOn()) {
1064 timeResponse = simParam->TimeResponse(time);
f881dc35 1065 }
625f5260 1066 if (simParam->CTOn()) {
1067 crossTalk = simParam->CrossTalk(time);
f881dc35 1068 }
e23fbb27 1069
625f5260 1070 signalOld[0] = 0.0;
1071 signalOld[1] = 0.0;
1072 signalOld[2] = 0.0;
e23fbb27 1073
625f5260 1074 for (iPad = 0; iPad < kNpad; iPad++) {
f7336fa3 1075
625f5260 1076 Int_t colPos = colE + iPad - 1;
1077 if (colPos < 0) continue;
1078 if (colPos >= nColMax) break;
e23fbb27 1079
625f5260 1080 // Add the signals
b65e5048 1081 signalOld[iPad] = signals->GetData(rowE,colPos,iTimeBin);
e23fbb27 1082
625f5260 1083 if (colPos != colE) {
1084 // Cross talk added to non-central pads
1085 signalOld[iPad] += padSignal[iPad]
1086 * (timeResponse + crossTalk);
1087 }
1088 else {
1089 // W/o cross talk at central pad
1090 signalOld[iPad] += padSignal[iPad]
1091 * timeResponse;
1092 }
f881dc35 1093
b65e5048 1094 signals->SetData(rowE,colPos,iTimeBin,signalOld[iPad]);
625f5260 1095
1096 // Store the track index in the dictionary
1097 // Note: We store index+1 in order to allow the array to be compressed
b65e5048 1098 // Note2: Taking out the +1 in track
625f5260 1099 if (signalOld[iPad] > 0.0) {
1100 for (dict = 0; dict < kNdict; dict++) {
b65e5048 1101 Int_t oldTrack = dictionary[dict]->GetData(rowE,colPos,iTimeBin);
1102 if (oldTrack == track) break;
1103 if (oldTrack == -1 ) {
1104 dictionary[dict]->SetData(rowE,colPos,iTimeBin,track);
1105 break;
1106 }
f881dc35 1107 }
625f5260 1108 }
872a7aba 1109
625f5260 1110 } // Loop: pads
f7336fa3 1111
625f5260 1112 } // Loop: time bins
f7336fa3 1113
625f5260 1114 } // Loop: electrons of a single hit
f7336fa3 1115
625f5260 1116 } // Loop: hits
f7336fa3 1117
625f5260 1118 AliDebug(2,Form("Finished analyzing %d hits",nhit));
e23fbb27 1119
625f5260 1120 return kTRUE;
e23fbb27 1121
625f5260 1122}
793ff80c 1123
625f5260 1124//_____________________________________________________________________________
b65e5048 1125Bool_t AliTRDdigitizer::ConvertSignals(Int_t det, AliTRDarraySignal *signals)
625f5260 1126{
4329977a 1127 //
625f5260 1128 // Convert signals to digits
4329977a 1129 //
1130
625f5260 1131 AliDebug(1,Form("Start converting the signals for detector %d",det));
1132
1133 if (fSDigits) {
1134 // Convert the signal array to s-digits
1135 if (!Signal2SDigits(det,signals)) {
1136 return kFALSE;
793ff80c 1137 }
625f5260 1138 }
1139 else {
1140 // Convert the signal array to digits
1141 if (!Signal2ADC(det,signals)) {
1142 return kFALSE;
793ff80c 1143 }
d295185b 1144 // Run digital processing for digits
1145 RunDigitalProcessing(det);
625f5260 1146 }
f7336fa3 1147
625f5260 1148 // Compress the arrays
b65e5048 1149 CompressOutputArrays(det);
6244debe 1150
625f5260 1151 return kTRUE;
6244debe 1152
625f5260 1153}
4329977a 1154
625f5260 1155//_____________________________________________________________________________
b65e5048 1156Bool_t AliTRDdigitizer::Signal2ADC(Int_t det, AliTRDarraySignal *signals)
625f5260 1157{
1158 //
1159 // Converts the sampled electron signals to ADC values for a given chamber
1160 //
6244debe 1161
625f5260 1162 AliDebug(1,Form("Start converting signals to ADC values for detector=%d",det));
e23fbb27 1163
625f5260 1164 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1165 if (!calibration) {
1166 AliFatal("Could not get calibration object");
1167 return kFALSE;
1168 }
793ff80c 1169
625f5260 1170 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
1171 if (!simParam) {
1172 AliFatal("Could not get simulation parameters");
1173 return kFALSE;
1174 }
f7336fa3 1175
625f5260 1176 // Converts number of electrons to fC
1177 const Double_t kEl2fC = 1.602e-19 * 1.0e15;
0c24ba98 1178
625f5260 1179 // Coupling factor
1180 Double_t coupling = simParam->GetPadCoupling()
1181 * simParam->GetTimeCoupling();
1182 // Electronics conversion factor
1183 Double_t convert = kEl2fC
1184 * simParam->GetChipGain();
1185 // ADC conversion factor
1186 Double_t adcConvert = simParam->GetADCoutRange()
1187 / simParam->GetADCinRange();
1188 // The electronics baseline in mV
1189 Double_t baseline = simParam->GetADCbaseline()
1190 / adcConvert;
1191 // The electronics baseline in electrons
1192 Double_t baselineEl = baseline
1193 / convert;
1194
1195 Int_t row = 0;
1196 Int_t col = 0;
1197 Int_t time = 0;
1198
1199 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1200 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
5896bc23 1201 Int_t nTimeTotal = simParam->GetNTimeBins();
abaf1f1d 1202
625f5260 1203 // The gainfactor calibration objects
1204 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
1205 AliTRDCalROC *calGainFactorROC = 0;
1206 Float_t calGainFactorDetValue = 0.0;
f7336fa3 1207
b65e5048 1208 AliTRDarrayADC *digits = 0x0;
e23fbb27 1209
625f5260 1210 if (!signals) {
1211 AliError(Form("Signals array for detector %d does not exist\n",det));
1212 return kFALSE;
1213 }
1214 if (signals->HasData()) {
1215 // Expand the container if neccessary
b65e5048 1216 signals->Expand();
625f5260 1217 }
1218 else {
1219 // Create missing containers
1220 signals->Allocate(nRowMax,nColMax,nTimeTotal);
f7336fa3 1221 }
1222
625f5260 1223 // Get the container for the digits of this detector
1224 if (fDigitsManager->HasSDigits()) {
1225 AliError("Digits manager has s-digits");
1226 return kFALSE;
1227 }
b65e5048 1228
1229 digits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det);
625f5260 1230 // Allocate memory space for the digits buffer
1231 if (!digits->HasData()) {
1232 digits->Allocate(nRowMax,nColMax,nTimeTotal);
0c24ba98 1233 }
1234
625f5260 1235 // Get the calibration objects
1236 calGainFactorROC = calibration->GetGainFactorROC(det);
1237 calGainFactorDetValue = calGainFactorDet->GetValue(det);
abaf1f1d 1238
625f5260 1239 // Create the digits for this chamber
1240 for (row = 0; row < nRowMax; row++ ) {
1241 for (col = 0; col < nColMax; col++ ) {
abaf1f1d 1242
625f5260 1243 // Check whether pad is masked
1244 // Bridged pads are not considered yet!!!
1245 if (calibration->IsPadMasked(det,col,row)) {
1246 continue;
1247 }
abaf1f1d 1248
625f5260 1249 // The gain factors
1250 Float_t padgain = calGainFactorDetValue
1251 * calGainFactorROC->GetValue(col,row);
1252 if (padgain <= 0) {
1253 AliError(Form("Not a valid gain %f, %d %d %d",padgain,det,col,row));
1254 }
abaf1f1d 1255
625f5260 1256 for (time = 0; time < nTimeTotal; time++) {
1257
1258 // Get the signal amplitude
b65e5048 1259 Float_t signalAmp = signals->GetData(row,col,time);
625f5260 1260 // Pad and time coupling
1261 signalAmp *= coupling;
1262 // Gain factors
1263 signalAmp *= padgain;
1264
1265 // Add the noise, starting from minus ADC baseline in electrons
1266 signalAmp = TMath::Max((Double_t) gRandom->Gaus(signalAmp,simParam->GetNoise())
1267 ,-baselineEl);
1268
1269 // Convert to mV
1270 signalAmp *= convert;
1271 // Add ADC baseline in mV
1272 signalAmp += baseline;
1273
1274 // Convert to ADC counts. Set the overflow-bit fADCoutRange if the
1275 // signal is larger than fADCinRange
1276 Short_t adc = 0;
1277 if (signalAmp >= simParam->GetADCinRange()) {
1278 adc = ((Short_t) simParam->GetADCoutRange());
1279 }
1280 else {
1281 adc = TMath::Nint(signalAmp * adcConvert);
1282 }
abaf1f1d 1283
b65e5048 1284 // Saving all digits
1285 digits->SetData(row,col,time,adc);
abaf1f1d 1286
625f5260 1287 } // for: time
b65e5048 1288
625f5260 1289 } // for: col
1290 } // for: row
b1113c6b 1291
625f5260 1292 return kTRUE;
b1113c6b 1293
1294}
1295
1296//_____________________________________________________________________________
b65e5048 1297Bool_t AliTRDdigitizer::Signal2SDigits(Int_t det, AliTRDarraySignal *signals)
abaf1f1d 1298{
1299 //
625f5260 1300 // Converts the sampled electron signals to s-digits
abaf1f1d 1301 //
1302
625f5260 1303 AliDebug(1,Form("Start converting signals to s-digits for detector=%d",det));
abaf1f1d 1304
4329977a 1305 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
9afbd7de 1306 if (!calibration) {
4329977a 1307 AliFatal("Could not get calibration object");
3551db50 1308 return kFALSE;
1309 }
6bf5f0ce 1310
625f5260 1311 Int_t row = 0;
1312 Int_t col = 0;
1313 Int_t time = 0;
9afbd7de 1314
625f5260 1315 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1316 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
5896bc23 1317 Int_t nTimeTotal = AliTRDSimParam::Instance()->GetNTimeBins();
e23fbb27 1318
625f5260 1319 // Get the container for the digits of this detector
b65e5048 1320
625f5260 1321 if (!fDigitsManager->HasSDigits()) {
1322 AliError("Digits manager has no s-digits");
1323 return kFALSE;
1324 }
b65e5048 1325
1326 AliTRDarraySignal *digits = (AliTRDarraySignal *) fDigitsManager->GetSDigits(det);
625f5260 1327 // Allocate memory space for the digits buffer
1328 if (!digits->HasData()) {
1329 digits->Allocate(nRowMax,nColMax,nTimeTotal);
1330 }
e23fbb27 1331
625f5260 1332 // Create the sdigits for this chamber
1333 for (row = 0; row < nRowMax; row++ ) {
1334 for (col = 0; col < nColMax; col++ ) {
1335 for (time = 0; time < nTimeTotal; time++) {
b65e5048 1336 digits->SetData(row,col,time,signals->GetData(row,col,time));
625f5260 1337 } // for: time
1338 } // for: col
1339 } // for: row
b65e5048 1340
625f5260 1341 return kTRUE;
abaf1f1d 1342
625f5260 1343}
abaf1f1d 1344
625f5260 1345//_____________________________________________________________________________
621310dd 1346Bool_t AliTRDdigitizer::Digits2SDigits(AliTRDdigitsManager * const manDig
1347 , AliTRDdigitsManager * const manSDig)
e7539003 1348{
1349 //
1350 // Converts digits into s-digits. Needed for embedding into real data.
1351 //
1352
1353 AliDebug(1,"Start converting digits to s-digits");
1354
6b4a4228 1355 if (!fGeo) {
1356 fGeo = new AliTRDgeometry();
1357 }
1358
e7539003 1359 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1360 if (!calibration) {
1361 AliFatal("Could not get calibration object");
1362 return kFALSE;
1363 }
1364
1365 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
1366 if (!simParam) {
1367 AliFatal("Could not get simulation parameters");
1368 return kFALSE;
1369 }
1370
1371 // Converts number of electrons to fC
1372 const Double_t kEl2fC = 1.602e-19 * 1.0e15;
1373
1374 // Coupling factor
1375 Double_t coupling = simParam->GetPadCoupling()
1376 * simParam->GetTimeCoupling();
1377 // Electronics conversion factor
1378 Double_t convert = kEl2fC
1379 * simParam->GetChipGain();
1380 // ADC conversion factor
1381 Double_t adcConvert = simParam->GetADCoutRange()
1382 / simParam->GetADCinRange();
1383 // The electronics baseline in mV
1384 Double_t baseline = simParam->GetADCbaseline()
1385 / adcConvert;
1386 // The electronics baseline in electrons
6b4a4228 1387 //Double_t baselineEl = baseline
1388 // / convert;
e7539003 1389
1390 // The gainfactor calibration objects
1391 //const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
1392 //AliTRDCalROC *calGainFactorROC = 0;
1393 //Float_t calGainFactorDetValue = 0.0;
1394
1395 Int_t row = 0;
1396 Int_t col = 0;
1397 Int_t time = 0;
1398
1399 for (Int_t det = 0; det < AliTRDgeometry::Ndet(); det++) {
1400
1401 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1402 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
a0446ff1 1403 Int_t nTimeTotal = manDig->GetDigitsParam()->GetNTimeBins(det);
e7539003 1404
1405 // Get the calibration objects
1406 //calGainFactorROC = calibration->GetGainFactorROC(det);
1407 //calGainFactorDetValue = calGainFactorDet->GetValue(det);
1408
1409 // Get the digits
1410 AliTRDarrayADC *digits = (AliTRDarrayADC *) manDig->GetDigits(det);
1411
1412 if (!manSDig->HasSDigits()) {
1413 AliError("SDigits manager has no s-digits");
1414 return kFALSE;
1415 }
1416 // Get the s-digits
1417 AliTRDarraySignal *sdigits = (AliTRDarraySignal *) manSDig->GetSDigits(det);
1418 AliTRDarrayDictionary *tracks0 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,0);
1419 AliTRDarrayDictionary *tracks1 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,1);
1420 AliTRDarrayDictionary *tracks2 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,2);
1421 // Allocate memory space for the digits buffer
1422 sdigits->Allocate(nRowMax,nColMax,nTimeTotal);
1423 tracks0->Allocate(nRowMax,nColMax,nTimeTotal);
1424 tracks1->Allocate(nRowMax,nColMax,nTimeTotal);
1425 tracks2->Allocate(nRowMax,nColMax,nTimeTotal);
1426
5896bc23 1427 // Keep the digits param
a0446ff1 1428 manSDig->GetDigitsParam()->SetNTimeBinsAll(manDig->GetDigitsParam()->GetNTimeBins(0));
1429 manSDig->GetDigitsParam()->SetADCbaselineAll(manDig->GetDigitsParam()->GetADCbaseline(0));
5896bc23 1430
45d77489 1431 if (digits->HasData()) {
1432
1433 digits->Expand();
1434
1435 // Create the sdigits for this chamber
1436 for (row = 0; row < nRowMax; row++ ) {
1437 for (col = 0; col < nColMax; col++ ) {
1438
1439 // The gain factors
1440 //Float_t padgain = calGainFactorDetValue
1441 // * calGainFactorROC->GetValue(col,row);
1442
1443 for (time = 0; time < nTimeTotal; time++) {
1444
1445 Short_t adcVal = digits->GetData(row,col,time);
1446 Double_t signal = (Double_t) adcVal;
1447 // ADC -> signal in mV
1448 signal /= adcConvert;
1449 // Subtract baseline in mV
1450 signal -= baseline;
1451 // Signal in mV -> signal in #electrons
1452 signal /= convert;
1453 // Gain factor
1454 //signal /= padgain; // Not needed for real data
1455 // Pad and time coupling
1456 signal /= coupling;
1457
1458 sdigits->SetData(row,col,time,signal);
1459 tracks0->SetData(row,col,time,0);
1460 tracks1->SetData(row,col,time,0);
1461 tracks2->SetData(row,col,time,0);
1462
1463 } // for: time
1464
1465 } // for: col
1466 } // for: row
e7539003 1467
45d77489 1468 } // if: has data
1469
e7539003 1470 sdigits->Compress(0);
1471 tracks0->Compress();
1472 tracks1->Compress();
1473 tracks2->Compress();
1474
45d77489 1475 // No compress just remove
1476 manDig->RemoveDigits(det);
1477 manDig->RemoveDictionaries(det);
1478
e7539003 1479 } // for: det
1480
1481 return kTRUE;
1482
1483}
1484
1485//_____________________________________________________________________________
625f5260 1486Bool_t AliTRDdigitizer::SDigits2Digits()
1487{
1488 //
1489 // Merges the input s-digits and converts them to normal digits
1490 //
e23fbb27 1491
625f5260 1492 if (!MergeSDigits()) {
1493 return kFALSE;
1494 }
f7336fa3 1495
625f5260 1496 return ConvertSDigits();
f7336fa3 1497
1498}
1499
1500//_____________________________________________________________________________
abaf1f1d 1501Bool_t AliTRDdigitizer::MergeSDigits()
16bf9884 1502{
1503 //
abaf1f1d 1504 // Merges the input s-digits:
1505 // - The amplitude of the different inputs are summed up.
1506 // - Of the track IDs from the input dictionaries only one is
1507 // kept for each input. This works for maximal 3 different merged inputs.
16bf9884 1508 //
1509
abaf1f1d 1510 // Number of track dictionary arrays
1511 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1512
4d18a639 1513 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
9afbd7de 1514 if (!simParam) {
4329977a 1515 AliFatal("Could not get simulation parameters");
3551db50 1516 return kFALSE;
1517 }
1518
4d18a639 1519 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
9afbd7de 1520 if (!calibration) {
4329977a 1521 AliFatal("Could not get calibration object");
3551db50 1522 return kFALSE;
1523 }
1524
abaf1f1d 1525 Int_t iDict = 0;
e23fbb27 1526 Int_t jDict = 0;
abaf1f1d 1527
b65e5048 1528 AliTRDarraySignal *digitsA;
1529 AliTRDarraySignal *digitsB;
1530 AliTRDarrayDictionary *dictionaryA[kNDict];
1531 AliTRDarrayDictionary *dictionaryB[kNDict];
abaf1f1d 1532
b65e5048 1533 AliTRDdigitsManager *mergeSDigitsManager = 0x0;
abaf1f1d 1534 // Get the first s-digits
1535 fSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->First();
9afbd7de 1536 if (!fSDigitsManager) {
7925de54 1537 AliError("No SDigits manager");
9afbd7de 1538 return kFALSE;
1539 }
abaf1f1d 1540
1541 // Loop through the other sets of s-digits
b65e5048 1542 mergeSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->After(fSDigitsManager);
abaf1f1d 1543
9afbd7de 1544 if (mergeSDigitsManager) {
7925de54 1545 AliDebug(1,Form("Merge %d input files.",fSDigitsManagerList->GetSize()));
9afbd7de 1546 }
1547 else {
7925de54 1548 AliDebug(1,"Only one input file.");
abaf1f1d 1549 }
3551db50 1550
abaf1f1d 1551 Int_t iMerge = 0;
b65e5048 1552
abaf1f1d 1553 while (mergeSDigitsManager) {
1554
1555 iMerge++;
5896bc23 1556
abaf1f1d 1557 // Loop through the detectors
1558 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) {
1559
a0446ff1 1560 Int_t nTimeTotal = fSDigitsManager->GetDigitsParam()->GetNTimeBins(iDet);
1561 if (mergeSDigitsManager->GetDigitsParam()->GetNTimeBins(iDet) != nTimeTotal) {
1562 AliError(Form("Mismatch in the number of time bins [%d,%d] in detector %d"
1563 ,nTimeTotal
1564 ,mergeSDigitsManager->GetDigitsParam()->GetNTimeBins(iDet)
1565 ,iDet));
1566 return kFALSE;
1567 }
1568
625f5260 1569 Int_t nRowMax = fGeo->GetPadPlane(iDet)->GetNrows();
1570 Int_t nColMax = fGeo->GetPadPlane(iDet)->GetNcols();
b65e5048 1571
abaf1f1d 1572 // Loop through the pixels of one detector and add the signals
b65e5048 1573 digitsA = (AliTRDarraySignal *) fSDigitsManager->GetSDigits(iDet);
1574 digitsB = (AliTRDarraySignal *) mergeSDigitsManager->GetSDigits(iDet);
1575 digitsA->Expand();
1576 if (!digitsA->HasData()) continue;
1577 digitsB->Expand();
1578 if (!digitsB->HasData()) continue;
1579
abaf1f1d 1580 for (iDict = 0; iDict < kNDict; iDict++) {
b65e5048 1581 dictionaryA[iDict] = (AliTRDarrayDictionary *) fSDigitsManager->GetDictionary(iDet,iDict);
1582 dictionaryB[iDict] = (AliTRDarrayDictionary *) mergeSDigitsManager->GetDictionary(iDet,iDict);
1583 dictionaryA[iDict]->Expand();
abaf1f1d 1584 dictionaryB[iDict]->Expand();
1585 }
1586
4487dad0 1587 // Merge only detectors that contain a signal
1588 Bool_t doMerge = kTRUE;
1589 if (fMergeSignalOnly) {
b65e5048 1590 if (digitsA->GetOverThreshold(0) == 0) {
1591 doMerge = kFALSE;
4487dad0 1592 }
abaf1f1d 1593 }
b65e5048 1594
4487dad0 1595 if (doMerge) {
b65e5048 1596
1597 AliDebug(1,Form("Merge detector %d of input no.%d",iDet,iMerge+1));
1598
1599 for (Int_t iRow = 0; iRow < nRowMax; iRow++ ) {
1600 for (Int_t iCol = 0; iCol < nColMax; iCol++ ) {
1601 for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
1602
4487dad0 1603 // Add the amplitudes of the summable digits
b65e5048 1604 Float_t ampA = digitsA->GetData(iRow,iCol,iTime);
1605 Float_t ampB = digitsB->GetData(iRow,iCol,iTime);
1606 ampA += ampB;
1607 digitsA->SetData(iRow,iCol,iTime,ampA);
1608
1609 // Add the mask to the track id if defined.
1610 for (iDict = 0; iDict < kNDict; iDict++) {
1611 Int_t trackB = dictionaryB[iDict]->GetData(iRow,iCol,iTime);
1612 if ((fMasks) && (trackB > 0)) {
1613 for (jDict = 0; jDict < kNDict; jDict++) {
1614 Int_t trackA = dictionaryA[iDict]->GetData(iRow,iCol,iTime);
1615 if (trackA == 0) {
1616 trackA = trackB + fMasks[iMerge];
1617 dictionaryA[iDict]->SetData(iRow,iCol,iTime,trackA);
625f5260 1618 } // if: track A == 0
b65e5048 1619 } // for: jDict
1620 } // if: fMasks and trackB > 0
625f5260 1621 } // for: iDict
abaf1f1d 1622
625f5260 1623 } // for: iTime
1624 } // for: iCol
1625 } // for: iRow
4487dad0 1626
625f5260 1627 } // if: doMerge
1628
1629 mergeSDigitsManager->RemoveDigits(iDet);
1630 mergeSDigitsManager->RemoveDictionaries(iDet);
b65e5048 1631
abaf1f1d 1632 if (fCompress) {
b65e5048 1633 digitsA->Compress(0);
1634 for (iDict = 0; iDict < kNDict; iDict++) {
1635 dictionaryA[iDict]->Compress();
abaf1f1d 1636 }
1637 }
b65e5048 1638
625f5260 1639 } // for: detectors
b65e5048 1640
abaf1f1d 1641 // The next set of s-digits
b65e5048 1642 mergeSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->After(mergeSDigitsManager);
1643
625f5260 1644 } // while: mergeDigitsManagers
b65e5048 1645
625f5260 1646 return kTRUE;
1647
1648}
1649
1650//_____________________________________________________________________________
1651Bool_t AliTRDdigitizer::ConvertSDigits()
1652{
1653 //
1654 // Converts s-digits to normal digits
1655 //
1656
b65e5048 1657 AliTRDarraySignal *digitsIn = 0x0;
625f5260 1658
1659 if (!fSDigitsManager->HasSDigits()) {
1660 AliError("No s-digits in digits manager");
1661 return kFALSE;
abaf1f1d 1662 }
1663
625f5260 1664 // Loop through the detectors
1665 for (Int_t det = 0; det < AliTRDgeometry::Ndet(); det++) {
1666
1667 // Get the merged s-digits (signals)
b65e5048 1668 digitsIn = (AliTRDarraySignal *) fSDigitsManager->GetSDigits(det);
625f5260 1669 if (!digitsIn->HasData()) {
1670 AliDebug(2,Form("No digits for det=%d",det));
1671 continue;
1672 }
b0a41e80 1673
625f5260 1674 // Convert the merged sdigits to digits
1675 if (!Signal2ADC(det,digitsIn)) {
1676 continue;
1677 }
1678
1679 // Copy the dictionary information to the output array
1680 if (!CopyDictionary(det)) {
1681 continue;
1682 }
1683
1684 // Delete
1685 fSDigitsManager->RemoveDigits(det);
1686 fSDigitsManager->RemoveDictionaries(det);
1687
d295185b 1688 // Run digital processing
1689 RunDigitalProcessing(det);
1690
625f5260 1691 // Compress the arrays
1692 CompressOutputArrays(det);
1693
1694 } // for: detector numbers
1695
ce4786b9 1696 AliRunLoader::Instance()->GetLoader("TRDLoader")->GetDataLoader("tracklets")->WriteData("OVERWRITE");
5896bc23 1697 // Save the values for the raw data headers
a0446ff1 1698 fDigitsManager->GetDigitsParam()->SetNTimeBinsAll(AliTRDSimParam::Instance()->GetNTimeBins());
1699 fDigitsManager->GetDigitsParam()->SetADCbaselineAll(AliTRDSimParam::Instance()->GetADCbaseline());
b0a41e80 1700
16bf9884 1701 return kTRUE;
1702
1703}
1704
1705//_____________________________________________________________________________
625f5260 1706Bool_t AliTRDdigitizer::CopyDictionary(Int_t det)
abaf1f1d 1707{
1708 //
625f5260 1709 // Copies the dictionary information from the s-digits arrays
1710 // to the output arrays
abaf1f1d 1711 //
1712
625f5260 1713 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1714 if (!calibration) {
1715 AliFatal("Could not get calibration object");
4d18a639 1716 return kFALSE;
1717 }
abaf1f1d 1718
625f5260 1719 AliDebug(1,Form("Start copying dictionaries for detector=%d",det));
1720
1721 const Int_t kNDict = AliTRDdigitsManager::kNDict;
b65e5048 1722 AliTRDarrayDictionary *dictionaryIn[kNDict];
1723 AliTRDarrayDictionary *dictionaryOut[kNDict];
625f5260 1724
1725 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1726 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
5896bc23 1727 Int_t nTimeTotal = AliTRDSimParam::Instance()->GetNTimeBins();
625f5260 1728
1729 Int_t row = 0;
1730 Int_t col = 0;
1731 Int_t time = 0;
1732 Int_t dict = 0;
1733
1734 for (dict = 0; dict < kNDict; dict++) {
1735
b65e5048 1736 dictionaryIn[dict] = (AliTRDarrayDictionary *) fSDigitsManager->GetDictionary(det,dict);
625f5260 1737 dictionaryIn[dict]->Expand();
b65e5048 1738 dictionaryOut[dict] = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
625f5260 1739 dictionaryOut[dict]->Allocate(nRowMax,nColMax,nTimeTotal);
1740
1741 for (row = 0; row < nRowMax; row++) {
1742 for (col = 0; col < nColMax; col++) {
1743 for (time = 0; time < nTimeTotal; time++) {
b65e5048 1744 Int_t track = dictionaryIn[dict]->GetData(row,col,time);
1745 dictionaryOut[dict]->SetData(row,col,time,track);
625f5260 1746 } // for: time
1747 } // for: col
1748 } // for: row
b65e5048 1749
625f5260 1750 } // for: dictionaries
b65e5048 1751
625f5260 1752 return kTRUE;
1753
1754}
1755
1756//_____________________________________________________________________________
1757void AliTRDdigitizer::CompressOutputArrays(Int_t det)
1758{
1759 //
1760 // Compress the output arrays
1761 //
1762
1763 const Int_t kNDict = AliTRDdigitsManager::kNDict;
b65e5048 1764 AliTRDarrayDictionary *dictionary = 0x0;
625f5260 1765
1766 if (fCompress) {
1767
b65e5048 1768 if (!fSDigits) {
1769 AliTRDarrayADC *digits = 0x0;
1770 digits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det);
1771 digits->Compress();
1772 }
1773
1774 if (fSDigits) {
1775 AliTRDarraySignal *digits = 0x0;
1776 digits = (AliTRDarraySignal *) fDigitsManager->GetSDigits(det);
1777 digits->Compress(0);
1778 }
1779
625f5260 1780 for (Int_t dict = 0; dict < kNDict; dict++) {
b65e5048 1781 dictionary = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
1782 dictionary->Compress();
625f5260 1783 }
1784
1785 }
abaf1f1d 1786
1787}
1788
1789//_____________________________________________________________________________
0a29d0f1 1790Bool_t AliTRDdigitizer::WriteDigits() const
f7336fa3 1791{
1792 //
1793 // Writes out the TRD-digits and the dictionaries
1794 //
1795
4d18a639 1796 // Write parameters
bdbb05bb 1797 fRunLoader->CdGAFile();
bdbb05bb 1798
da581aea 1799 // Store the digits and the dictionary in the tree
abaf1f1d 1800 return fDigitsManager->WriteDigits();
f7336fa3 1801
1802}
793ff80c 1803
1804//_____________________________________________________________________________
88cb7938 1805void AliTRDdigitizer::InitOutput(Int_t iEvent)
8e64dd77 1806{
1807 //
1808 // Initializes the output branches
1809 //
1810
1811 fEvent = iEvent;
88cb7938 1812
9afbd7de 1813 if (!fRunLoader) {
1814 AliError("Run Loader is NULL");
1815 return;
1816 }
1817
4329977a 1818 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
9afbd7de 1819 if (!loader) {
1820 AliError("Can not get TRD loader from Run Loader");
1821 return;
1822 }
88cb7938 1823
4d18a639 1824 TTree *tree = 0;
88cb7938 1825
9afbd7de 1826 if (fSDigits) {
1827 // If we produce SDigits
88cb7938 1828 tree = loader->TreeS();
9afbd7de 1829 if (!tree) {
88cb7938 1830 loader->MakeTree("S");
1831 tree = loader->TreeS();
9afbd7de 1832 }
1833 }
1834 else {
1835 // If we produce Digits
1836 tree = loader->TreeD();
1837 if (!tree) {
1838 loader->MakeTree("D");
1839 tree = loader->TreeD();
1840 }
1841 }
88cb7938 1842 fDigitsManager->SetEvent(iEvent);
1843 fDigitsManager->MakeBranch(tree);
8e64dd77 1844
1845}
3551db50 1846
3551db50 1847//_____________________________________________________________________________
a076fc2f 1848Int_t AliTRDdigitizer::Diffusion(Float_t vdrift, Double_t absdriftlength
1849 , Double_t &lRow, Double_t &lCol, Double_t &lTime)
3551db50 1850{
1851 //
a076fc2f 1852 // Applies the diffusion smearing to the position of a single electron.
1853 // Depends on absolute drift length.
3551db50 1854 //
1855
a076fc2f 1856 Float_t diffL = 0.0;
1857 Float_t diffT = 0.0;
4d18a639 1858
a076fc2f 1859 if (AliTRDCommonParam::Instance()->GetDiffCoeff(diffL,diffT,vdrift)) {
3551db50 1860
a076fc2f 1861 Float_t driftSqrt = TMath::Sqrt(absdriftlength);
1862 Float_t sigmaT = driftSqrt * diffT;
1863 Float_t sigmaL = driftSqrt * diffL;
1864 lRow = gRandom->Gaus(lRow ,sigmaT);
1865 lCol = gRandom->Gaus(lCol ,sigmaT * GetLorentzFactor(vdrift));
1866 lTime = gRandom->Gaus(lTime,sigmaL * GetLorentzFactor(vdrift));
4d18a639 1867
a076fc2f 1868 return 1;
7754cd1f 1869
3551db50 1870 }
a076fc2f 1871 else {
3551db50 1872
a076fc2f 1873 return 0;
1b95a37b 1874
3551db50 1875 }
9afbd7de 1876
3551db50 1877}
3551db50 1878
1879//_____________________________________________________________________________
1880Float_t AliTRDdigitizer::GetLorentzFactor(Float_t vd)
1881{
9afbd7de 1882 //
a076fc2f 1883 // Returns the Lorentz factor
9afbd7de 1884 //
1885
a076fc2f 1886 Double_t omegaTau = AliTRDCommonParam::Instance()->GetOmegaTau(vd);
1887 Double_t lorentzFactor = 1.0;
1888 if (AliTRDCommonParam::Instance()->ExBOn()) {
1889 lorentzFactor = 1.0 / (1.0 + omegaTau*omegaTau);
1890 }
4d18a639 1891
a076fc2f 1892 return lorentzFactor;
9afbd7de 1893
3551db50 1894}
1895
1896//_____________________________________________________________________________
4329977a 1897Int_t AliTRDdigitizer::ExB(Float_t vdrift, Double_t driftlength, Double_t &lCol)
3551db50 1898{
1899 //
4329977a 1900 // Applies E x B effects to the position of a single electron.
1901 // Depends on signed drift length.
3551db50 1902 //
4329977a 1903
a076fc2f 1904 lCol = lCol
1905 + AliTRDCommonParam::Instance()->GetOmegaTau(vdrift)
1906 * driftlength;
3551db50 1907
1908 return 1;
9afbd7de 1909
3551db50 1910}
b65e5048 1911
1912//_____________________________________________________________________________
d295185b 1913void AliTRDdigitizer::RunDigitalProcessing(Int_t det)
b65e5048 1914{
1915 //
b0a41e80 1916 // Run the digital processing in the TRAP
b65e5048 1917 //
1918
b0a41e80 1919 AliTRDfeeParam *feeParam = AliTRDfeeParam::Instance();
b65e5048 1920
1921 //Create and initialize the mcm object
b0a41e80 1922 AliTRDmcmSim* mcmfast = new AliTRDmcmSim();
b65e5048 1923
d295185b 1924 AliTRDarrayADC *digits = fDigitsManager->GetDigits(det);
1925 if (!digits)
1926 return;
1927
b65e5048 1928 //Call the methods in the mcm class using the temporary array as input
64e3d742 1929 for(Int_t rob = 0; rob < digits->GetNrow() / 2; rob++)
b0a41e80 1930 {
1931 for(Int_t mcm = 0; mcm < 16; mcm++)
b65e5048 1932 {
b0a41e80 1933 mcmfast->Init(det, rob, mcm);
40bd6ee4 1934 mcmfast->SetData(digits, fDigitsManager);
b65e5048 1935 mcmfast->Filter();
c8b1590d 1936 if (feeParam->GetTracklet()) {
b0a41e80 1937 mcmfast->Tracklet();
c8b1590d 1938 mcmfast->StoreTracklets();
1939 }
b65e5048 1940 mcmfast->ZSMapping();
b0a41e80 1941 mcmfast->WriteData(digits);
b65e5048 1942 }
b0a41e80 1943 }
b65e5048 1944
b65e5048 1945 delete mcmfast;
d295185b 1946
b65e5048 1947}