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