]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDdigitizer.cxx
Go back to array compression. Use sampled PRF to speed up digitization
[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
16/*
17$Log$
e153aaf6 18Revision 1.15 2000/11/23 14:34:08 cblume
19Fixed bug in expansion routine of arrays (initialize buffers properly)
20
259b9e4b 21Revision 1.14 2000/11/20 08:54:44 cblume
22Switch off compression as default
23
c1e4b257 24Revision 1.13 2000/11/10 14:57:52 cblume
25Changes in the geometry constants for the DEC compiler
26
dd56b762 27Revision 1.12 2000/11/01 14:53:20 cblume
28Merge with TRD-develop
29
793ff80c 30Revision 1.1.4.9 2000/10/26 17:00:22 cblume
31Fixed bug in CheckDetector()
32
33Revision 1.1.4.8 2000/10/23 13:41:35 cblume
34Added protection against Log(0) in the gas gain calulation
35
36Revision 1.1.4.7 2000/10/17 02:27:34 cblume
37Get rid of global constants
38
39Revision 1.1.4.6 2000/10/16 01:16:53 cblume
40Changed timebin 0 to be the one closest to the readout
41
42Revision 1.1.4.5 2000/10/15 23:34:29 cblume
43Faster version of the digitizer
44
45Revision 1.1.4.4 2000/10/06 16:49:46 cblume
46Made Getters const
47
48Revision 1.1.4.3 2000/10/04 16:34:58 cblume
49Replace include files by forward declarations
50
51Revision 1.1.4.2 2000/09/22 14:41:10 cblume
52Bug fix in PRF. Included time response. New structure
53
eda4336d 54Revision 1.10 2000/10/05 07:27:53 cblume
55Changes in the header-files by FCA
56
6798b56e 57Revision 1.9 2000/10/02 21:28:19 fca
58Removal of useless dependecies via forward declarations
59
94de3818 60Revision 1.8 2000/06/09 11:10:07 cblume
61Compiler warnings and coding conventions, next round
62
dd9a6ee3 63Revision 1.7 2000/06/08 18:32:58 cblume
64Make code compliant to coding conventions
65
8230f242 66Revision 1.6 2000/06/07 16:27:32 cblume
67Try to remove compiler warnings on Sun and HP
68
9d0b222b 69Revision 1.5 2000/05/09 16:38:57 cblume
70Removed PadResponse(). Merge problem
71
f0a7bf65 72Revision 1.4 2000/05/08 15:53:45 cblume
73Resolved merge conflict
74
da581aea 75Revision 1.3 2000/04/28 14:49:27 cblume
76Only one declaration of iDict in MakeDigits()
77
78Revision 1.1.4.1 2000/05/08 14:42:04 cblume
79Introduced AliTRDdigitsManager
28329a48 80
1befd3b2 81Revision 1.1 2000/02/28 19:00:13 cblume
82Add new TRD classes
83
f7336fa3 84*/
85
86///////////////////////////////////////////////////////////////////////////////
87// //
88// Creates and handles digits from TRD hits //
89// //
90// The following effects are included: //
91// - Diffusion //
92// - ExB effects //
93// - Gas gain including fluctuations //
94// - Pad-response (simple Gaussian approximation) //
95// - Electronics noise //
96// - Electronics gain //
97// - Digitization //
98// - ADC threshold //
99// The corresponding parameter can be adjusted via the various //
100// Set-functions. If these parameters are not explicitly set, default //
101// values are used (see Init-function). //
102// To produce digits from a root-file with TRD-hits use the //
103// slowDigitsCreate.C macro. //
104// //
105///////////////////////////////////////////////////////////////////////////////
106
6798b56e 107#include <stdlib.h>
108
f7336fa3 109#include <TMath.h>
110#include <TVector.h>
111#include <TRandom.h>
94de3818 112#include <TROOT.h>
113#include <TTree.h>
793ff80c 114#include <TFile.h>
115#include <TF1.h>
116
117#include "AliRun.h"
f7336fa3 118
119#include "AliTRD.h"
793ff80c 120#include "AliTRDhit.h"
f7336fa3 121#include "AliTRDdigitizer.h"
da581aea 122#include "AliTRDdataArrayI.h"
123#include "AliTRDdataArrayF.h"
793ff80c 124#include "AliTRDsegmentArray.h"
da581aea 125#include "AliTRDdigitsManager.h"
793ff80c 126#include "AliTRDgeometry.h"
f7336fa3 127
128ClassImp(AliTRDdigitizer)
129
130//_____________________________________________________________________________
131AliTRDdigitizer::AliTRDdigitizer():TNamed()
132{
133 //
134 // AliTRDdigitizer default constructor
135 //
136
da581aea 137 fInputFile = NULL;
138 fDigits = NULL;
139 fTRD = NULL;
140 fGeo = NULL;
141 fPRF = NULL;
e153aaf6 142 fPRFsmp = NULL;
793ff80c 143 fTRF = NULL;
144 fTRFint = NULL;
da581aea 145
146 fEvent = 0;
147 fGasGain = 0.0;
148 fNoise = 0.0;
149 fChipGain = 0.0;
150 fADCoutRange = 0.0;
151 fADCinRange = 0.0;
152 fADCthreshold = 0;
153 fDiffusionOn = 0;
154 fDiffusionT = 0.0;
155 fDiffusionL = 0.0;
156 fElAttachOn = 0;
157 fElAttachProp = 0.0;
158 fExBOn = 0;
793ff80c 159 fOmegaTau = 0.0;
160 fPRFOn = 0;
161 fTRFOn = 0;
162 fDriftVelocity = 0.0;
163
e153aaf6 164 fPRFbin = 0;
165 fPRFlo = 0.0;
166 fPRFhi = 0.0;
167 fPRFwid = 0.0;
168 fPRFpad = 0;
793ff80c 169 fTRFbin = 0;
170 fTRFlo = 0.0;
171 fTRFhi = 0.0;
172 fTRFwid = 0.0;
e153aaf6 173
259b9e4b 174 fCompress = kTRUE;
793ff80c 175 fVerbose = 1;
f7336fa3 176
177}
178
179//_____________________________________________________________________________
180AliTRDdigitizer::AliTRDdigitizer(const Text_t *name, const Text_t *title)
181 :TNamed(name,title)
182{
183 //
184 // AliTRDdigitizer default constructor
185 //
186
da581aea 187 fInputFile = NULL;
188 fDigits = NULL;
189 fTRD = NULL;
190 fGeo = NULL;
e153aaf6 191 fPRF = NULL;
192 fPRFsmp = NULL;
193 fTRF = NULL;
194 fTRFint = NULL;
f7336fa3 195
da581aea 196 fEvent = 0;
f7336fa3 197
e153aaf6 198 fCompress = kTRUE;
793ff80c 199 fVerbose = 1;
200
f7336fa3 201 Init();
202
203}
204
8230f242 205//_____________________________________________________________________________
dd9a6ee3 206AliTRDdigitizer::AliTRDdigitizer(const AliTRDdigitizer &d)
8230f242 207{
208 //
209 // AliTRDdigitizer copy constructor
210 //
211
dd9a6ee3 212 ((AliTRDdigitizer &) d).Copy(*this);
8230f242 213
214}
215
f7336fa3 216//_____________________________________________________________________________
217AliTRDdigitizer::~AliTRDdigitizer()
218{
8230f242 219 //
220 // AliTRDdigitizer destructor
221 //
f7336fa3 222
223 if (fInputFile) {
224 fInputFile->Close();
225 delete fInputFile;
226 }
227
da581aea 228 if (fDigits) {
229 delete fDigits;
f7336fa3 230 }
231
da581aea 232 if (fPRF) delete fPRF;
793ff80c 233 if (fTRF) delete fTRF;
f7336fa3 234
235}
236
8230f242 237//_____________________________________________________________________________
dd9a6ee3 238AliTRDdigitizer &AliTRDdigitizer::operator=(const AliTRDdigitizer &d)
239{
240 //
241 // Assignment operator
242 //
243
244 if (this != &d) ((AliTRDdigitizer &) d).Copy(*this);
245 return *this;
246
247}
248
249//_____________________________________________________________________________
250void AliTRDdigitizer::Copy(TObject &d)
8230f242 251{
252 //
253 // Copy function
254 //
255
dd9a6ee3 256 ((AliTRDdigitizer &) d).fInputFile = NULL;
257 ((AliTRDdigitizer &) d).fDigits = NULL;
258 ((AliTRDdigitizer &) d).fTRD = NULL;
259 ((AliTRDdigitizer &) d).fGeo = NULL;
260
261 ((AliTRDdigitizer &) d).fEvent = 0;
262
263 ((AliTRDdigitizer &) d).fGasGain = fGasGain;
264 ((AliTRDdigitizer &) d).fNoise = fNoise;
265 ((AliTRDdigitizer &) d).fChipGain = fChipGain;
266 ((AliTRDdigitizer &) d).fADCoutRange = fADCoutRange;
267 ((AliTRDdigitizer &) d).fADCinRange = fADCinRange;
268 ((AliTRDdigitizer &) d).fADCthreshold = fADCthreshold;
269 ((AliTRDdigitizer &) d).fDiffusionOn = fDiffusionOn;
270 ((AliTRDdigitizer &) d).fDiffusionT = fDiffusionT;
271 ((AliTRDdigitizer &) d).fDiffusionL = fDiffusionL;
272 ((AliTRDdigitizer &) d).fElAttachOn = fElAttachOn;
273 ((AliTRDdigitizer &) d).fElAttachProp = fElAttachProp;
274 ((AliTRDdigitizer &) d).fExBOn = fExBOn;
793ff80c 275 ((AliTRDdigitizer &) d).fOmegaTau = fOmegaTau;
dd9a6ee3 276 ((AliTRDdigitizer &) d).fLorentzFactor = fLorentzFactor;
793ff80c 277 ((AliTRDdigitizer &) d).fPRFOn = fPRFOn;
278 ((AliTRDdigitizer &) d).fTRFOn = fTRFOn;
279
280 ((AliTRDdigitizer &) d).fCompress = fCompress;
281 ((AliTRDdigitizer &) d).fVerbose = fVerbose;
dd9a6ee3 282
283 fPRF->Copy(*((AliTRDdigitizer &) d).fPRF);
793ff80c 284 fTRF->Copy(*((AliTRDdigitizer &) d).fTRF);
285
e153aaf6 286 ((AliTRDdigitizer &) d).fPRFbin = fPRFbin;
287 ((AliTRDdigitizer &) d).fPRFlo = fPRFlo;
288 ((AliTRDdigitizer &) d).fPRFhi = fPRFhi;
289 ((AliTRDdigitizer &) d).fPRFwid = fPRFwid;
290 ((AliTRDdigitizer &) d).fPRFpad = fPRFpad;
291 if (((AliTRDdigitizer &) d).fPRFsmp) delete ((AliTRDdigitizer &) d).fPRFsmp;
292 ((AliTRDdigitizer &) d).fPRFsmp = new Float_t[fPRFbin];
293 for (Int_t iBin = 0; iBin < fPRFbin; iBin++) {
294 ((AliTRDdigitizer &) d).fPRFsmp[iBin] = fPRFsmp[iBin];
295 }
793ff80c 296 ((AliTRDdigitizer &) d).fTRFbin = fTRFbin;
297 ((AliTRDdigitizer &) d).fTRFlo = fTRFlo;
298 ((AliTRDdigitizer &) d).fTRFhi = fTRFhi;
299 ((AliTRDdigitizer &) d).fTRFwid = fTRFwid;
300 if (((AliTRDdigitizer &) d).fTRFint) delete ((AliTRDdigitizer &) d).fTRFint;
301 ((AliTRDdigitizer &) d).fTRFint = new Float_t[fTRFbin];
302 for (Int_t iBin = 0; iBin < fTRFbin; iBin++) {
303 ((AliTRDdigitizer &) d).fTRFint[iBin] = fTRFint[iBin];
304 }
8230f242 305
306}
307
f7336fa3 308//_____________________________________________________________________________
309Int_t AliTRDdigitizer::Diffusion(Float_t driftlength, Float_t *xyz)
310{
311 //
312 // Applies the diffusion smearing to the position of a single electron
313 //
314
315 Float_t driftSqrt = TMath::Sqrt(driftlength);
316 Float_t sigmaT = driftSqrt * fDiffusionT;
317 Float_t sigmaL = driftSqrt * fDiffusionL;
318 xyz[0] = gRandom->Gaus(xyz[0], sigmaL * fLorentzFactor);
319 xyz[1] = gRandom->Gaus(xyz[1], sigmaT * fLorentzFactor);
320 xyz[2] = gRandom->Gaus(xyz[2], sigmaT);
793ff80c 321
f7336fa3 322 return 1;
323
324}
325
326//_____________________________________________________________________________
327Int_t AliTRDdigitizer::ExB(Float_t driftlength, Float_t *xyz)
328{
329 //
330 // Applies E x B effects to the position of a single electron
331 //
332
333 xyz[0] = xyz[0];
793ff80c 334 xyz[1] = xyz[1] + fOmegaTau * driftlength;
f7336fa3 335 xyz[2] = xyz[2];
336
337 return 1;
338
339}
340
793ff80c 341//_____________________________________________________________________________
342Int_t AliTRDdigitizer::PadResponse(Float_t signal, Float_t dist, Float_t *pad)
343{
344 //
345 // Applies the pad response
346 //
347
e153aaf6 348 Int_t iBin = ((Int_t) (( - dist - fPRFlo) / fPRFwid));
349
350 Int_t iBin0 = iBin - fPRFpad;
351 Int_t iBin1 = iBin;
352 Int_t iBin2 = iBin + fPRFpad;
353
354 if ((iBin0 >= 0) && (iBin2 < fPRFbin)) {
355
356 pad[0] = signal * fPRFsmp[iBin0];
357 pad[1] = signal * fPRFsmp[iBin1];
358 pad[2] = signal * fPRFsmp[iBin2];
359
793ff80c 360 return 1;
e153aaf6 361
793ff80c 362 }
363 else {
e153aaf6 364
793ff80c 365 return 0;
e153aaf6 366
793ff80c 367 }
368
369}
370
371//_____________________________________________________________________________
372Float_t AliTRDdigitizer::TimeResponse(Float_t time)
373{
374 //
375 // Applies the preamp shaper time response
376 //
377
378 Int_t iBin = ((Int_t) ((time - fTRFlo) / fTRFwid));
379 if ((iBin >= 0) && (iBin < fTRFbin)) {
380 return fTRFint[iBin];
381 }
382 else {
383 return 0.0;
384 }
385
386}
387
f7336fa3 388//_____________________________________________________________________________
389void AliTRDdigitizer::Init()
390{
391 //
392 // Initializes the digitization procedure with standard values
393 //
394
395 // The default parameter for the digitization
793ff80c 396 fGasGain = 8.0E3;
f7336fa3 397 fNoise = 3000.;
398 fChipGain = 10.;
399 fADCoutRange = 255.;
400 fADCinRange = 2000.;
401 fADCthreshold = 1;
402
403 // Transverse and longitudinal diffusion coefficients (Xe/Isobutane)
404 fDiffusionOn = 1;
405 fDiffusionT = 0.060;
406 fDiffusionL = 0.017;
407
408 // Propability for electron attachment
409 fElAttachOn = 0;
410 fElAttachProp = 0.0;
411
412 // E x B effects
413 fExBOn = 0;
414 // omega * tau. (tau ~ 12 * 10^-12, B = 0.2T)
793ff80c 415 fOmegaTau = 17.6 * 12.0 * 0.2 * 0.01;
f7336fa3 416
da581aea 417 // The pad response function
e153aaf6 418 fPRFOn = 1;
419 fPRFlo = -3.0;
420 fPRFhi = 3.0;
421 fPRFbin = 1200;
422 fPRFwid = (fPRFhi - fPRFlo) / ((Float_t) fPRFbin);
423 fPRFpad = ((Int_t) (1.0 / fPRFwid));
424 fPRF = new TF1("PRF","[0]*([1]+exp(-x*x/(2.0*[2])))",fPRFlo,fPRFhi);
da581aea 425 fPRF->SetParameter(0, 0.8872);
426 fPRF->SetParameter(1,-0.00573);
427 fPRF->SetParameter(2, 0.454 * 0.454);
428
793ff80c 429 // The drift velocity (cm / mus)
430 fDriftVelocity = 1.0;
431
432 // The time response function
433 fTRFOn = 1;
434 Float_t loTRF = -200.0;
435 Float_t hiTRF = 1000.0;
436 fTRF = new TF1("TRF",TRFlandau,loTRF,hiTRF,3);
437 fTRF->SetParameter(0, 1.0 / 24.24249);
438 fTRF->SetParameter(1, 0.0);
439 fTRF->SetParameter(2, 25.0);
440 fTRFbin = 1200;
441 fTRFlo = loTRF * fDriftVelocity / 1000.0;
442 fTRFhi = hiTRF * fDriftVelocity / 1000.0;
443 fTRFwid = (fTRFhi - fTRFlo) / ((Float_t) fTRFbin);
444
445}
446
447//_____________________________________________________________________________
448void AliTRDdigitizer::IntegrateTRF()
449{
450 //
451 // Integrates the time response function over the time bin size
452 //
453
454 if (fTRFint) delete fTRFint;
455 fTRFint = new Float_t[fTRFbin];
456 Float_t hiTRF = fTRFhi / fDriftVelocity * 1000.0;
457 Float_t loTRF = fTRFlo / fDriftVelocity * 1000.0;
458 Float_t timeBin = fGeo->GetTimeBinSize() / fDriftVelocity * 1000.0;
459 Float_t binWidth = (hiTRF - loTRF) / ((Float_t) fTRFbin);
460 for (Int_t iBin = 0; iBin < fTRFbin; iBin++) {
461 Float_t bin = iBin * binWidth + loTRF - 0.5 * timeBin;
462 fTRFint[iBin] = fTRF->Integral(bin,bin + timeBin);
463 }
464
f7336fa3 465}
466
e153aaf6 467//_____________________________________________________________________________
468void AliTRDdigitizer::SamplePRF()
469{
470 //
471 // Samples the pad response function
472 //
473
474 if (fPRFsmp) delete fPRFsmp;
475 fPRFsmp = new Float_t[fPRFbin];
476 for (Int_t iBin = 0; iBin < fPRFbin; iBin++) {
477 Float_t bin = (((Float_t ) iBin) + 0.5) * fPRFwid + fPRFlo;
478 fPRFsmp[iBin] = TMath::Max(fPRF->Eval(bin),0.0);
479 }
480
481}
482
f7336fa3 483//_____________________________________________________________________________
484Bool_t AliTRDdigitizer::Open(const Char_t *name, Int_t nEvent)
485{
486 //
487 // Opens a ROOT-file with TRD-hits and reads in the hit-tree
488 //
489
490 // Connect the AliRoot file containing Geometry, Kine, and Hits
491 fInputFile = (TFile*) gROOT->GetListOfFiles()->FindObject(name);
492 if (!fInputFile) {
493 printf("AliTRDdigitizer::Open -- ");
494 printf("Open the ALIROOT-file %s.\n",name);
495 fInputFile = new TFile(name,"UPDATE");
496 }
497 else {
498 printf("AliTRDdigitizer::Open -- ");
499 printf("%s is already open.\n",name);
500 }
501
da581aea 502 gAlice = (AliRun*) fInputFile->Get("gAlice");
503 if (gAlice) {
504 printf("AliTRDdigitizer::Open -- ");
505 printf("AliRun object found on file.\n");
506 }
507 else {
508 printf("AliTRDdigitizer::Open -- ");
509 printf("Could not find AliRun object.\n");
510 return kFALSE;
511 }
f7336fa3 512
513 fEvent = nEvent;
514
515 // Import the Trees for the event nEvent in the file
516 Int_t nparticles = gAlice->GetEvent(fEvent);
517 if (nparticles <= 0) {
518 printf("AliTRDdigitizer::Open -- ");
519 printf("No entries in the trees for event %d.\n",fEvent);
520 return kFALSE;
521 }
522
793ff80c 523 return InitDetector();
524
525}
526
527//_____________________________________________________________________________
528Bool_t AliTRDdigitizer::InitDetector()
529{
530 //
531 // Sets the pointer to the TRD detector and the geometry
532 //
533
dd9a6ee3 534 // Get the pointer to the detector class and check for version 1
535 fTRD = (AliTRD*) gAlice->GetDetector("TRD");
536 if (fTRD->IsVersion() != 1) {
537 printf("AliTRDdigitizer::Open -- ");
538 printf("TRD must be version 1 (slow simulator).\n");
539 exit(1);
540 }
541
542 // Get the geometry
543 fGeo = fTRD->GetGeometry();
544 printf("AliTRDdigitizer::Open -- ");
545 printf("Geometry version %d\n",fGeo->IsVersion());
546
f7336fa3 547 return kTRUE;
548
549}
550
f7336fa3 551//_____________________________________________________________________________
552Bool_t AliTRDdigitizer::MakeDigits()
553{
554 //
555 // Loops through the TRD-hits and creates the digits.
556 //
557
f7336fa3 558 ///////////////////////////////////////////////////////////////
559 // Parameter
560 ///////////////////////////////////////////////////////////////
561
562 // Converts number of electrons to fC
8230f242 563 const Float_t kEl2fC = 1.602E-19 * 1.0E15;
f7336fa3 564
565 ///////////////////////////////////////////////////////////////
566
793ff80c 567 // Number of pads included in the pad response
568 const Int_t kNpad = 3;
569
570 // Number of track dictionary arrays
dd56b762 571 const Int_t kNDict = AliTRDdigitsManager::kNDict;
793ff80c 572
f7336fa3 573 Int_t iRow, iCol, iTime;
28329a48 574 Int_t iDict;
793ff80c 575 Int_t nBytes = 0;
f7336fa3 576
577 Int_t totalSizeDigits = 0;
578 Int_t totalSizeDict0 = 0;
579 Int_t totalSizeDict1 = 0;
580 Int_t totalSizeDict2 = 0;
581
793ff80c 582 AliTRDdataArrayF *signals = 0;
583 AliTRDdataArrayI *digits = 0;
8230f242 584 AliTRDdataArrayI *dictionary[kNDict];
da581aea 585
793ff80c 586 // Create a digits manager
587 fDigits = new AliTRDdigitsManager();
588
589 // Create a container for the amplitudes
590 AliTRDsegmentArray *signalsArray
591 = new AliTRDsegmentArray("AliTRDdataArrayF",AliTRDgeometry::Ndet());
592
da581aea 593 if (!fGeo) {
594 printf("AliTRDdigitizer::MakeDigits -- ");
595 printf("No geometry defined\n");
596 return kFALSE;
597 }
598
da581aea 599 printf("AliTRDdigitizer::MakeDigits -- ");
600 printf("Start creating digits.\n");
793ff80c 601 if (fVerbose > 0) this->Dump();
f7336fa3 602
603 // The Lorentz factor
604 if (fExBOn) {
793ff80c 605 fLorentzFactor = 1.0 / (1.0 + fOmegaTau*fOmegaTau);
f7336fa3 606 }
607 else {
608 fLorentzFactor = 1.0;
609 }
610
e153aaf6 611 // Create the sampled PRF
612 SamplePRF();
613
793ff80c 614 // Create the integrated TRF
615 IntegrateTRF();
616
617 // Get the pointer to the hit tree
618 TTree *HitTree = gAlice->TreeH();
619
620 // Get the number of entries in the hit tree
621 // (Number of primary particles creating a hit somewhere)
622 Int_t nTrack = (Int_t) HitTree->GetEntries();
623 if (fVerbose > 0) {
624 printf("AliTRDdigitizer::MakeDigits -- ");
625 printf("Found %d primary particles\n",nTrack);
626 }
627
628 Int_t detectorOld = -1;
629 Int_t countHits = 0;
630
631 // Loop through all entries in the tree
632 for (Int_t iTrack = 0; iTrack < nTrack; iTrack++) {
633
634 gAlice->ResetHits();
635 nBytes += HitTree->GetEvent(iTrack);
636
637 // Get the number of hits in the TRD created by this particle
638 Int_t nHit = fTRD->Hits()->GetEntriesFast();
639 if (fVerbose > 0) {
640 printf("AliTRDdigitizer::MakeDigits -- ");
641 printf("Found %d hits for primary particle %d\n",nHit,iTrack);
642 }
643
644 // Loop through the TRD hits
645 for (Int_t iHit = 0; iHit < nHit; iHit++) {
646
647 countHits++;
648
649 AliTRDhit *hit = (AliTRDhit *) fTRD->Hits()->UncheckedAt(iHit);
650 Float_t pos[3];
651 pos[0] = hit->X();
652 pos[1] = hit->Y();
653 pos[2] = hit->Z();
654 Float_t q = hit->GetCharge();
655 Int_t track = hit->Track();
656 Int_t detector = hit->GetDetector();
657 Int_t plane = fGeo->GetPlane(detector);
658 Int_t sector = fGeo->GetSector(detector);
659 Int_t chamber = fGeo->GetChamber(detector);
660
661 if (!(CheckDetector(plane,chamber,sector))) continue;
662
663 Int_t nRowMax = fGeo->GetRowMax(plane,chamber,sector);
664 Int_t nColMax = fGeo->GetColMax(plane);
665 Int_t nTimeMax = fGeo->GetTimeMax();
666 Float_t row0 = fGeo->GetRow0(plane,chamber,sector);
667 Float_t col0 = fGeo->GetCol0(plane);
668 Float_t time0 = fGeo->GetTime0(plane);
669 Float_t rowPadSize = fGeo->GetRowPadSize();
670 Float_t colPadSize = fGeo->GetColPadSize();
671 Float_t timeBinSize = fGeo->GetTimeBinSize();
672
673 if (fVerbose > 1) {
674 printf("Analyze hit no. %d ",iHit);
675 printf("-----------------------------------------------------------\n");
676 hit->Dump();
677 printf("plane = %d, sector = %d, chamber = %d\n"
678 ,plane,sector,chamber);
679 printf("nRowMax = %d, nColMax = %d, nTimeMax = %d\n"
680 ,nRowMax,nColMax,nTimeMax);
681 printf("row0 = %f, col0 = %f, time0 = %f\n"
682 ,row0,col0,time0);
c1e4b257 683 printf("rowPadSize = %f, colPadSize = %f, timeBinSize = %f\n"
684 ,rowPadSize,colPadSize,timeBinSize);
793ff80c 685 }
686
dd56b762 687 // Don't analyze test hits with amplitude 0.
688 if (((Int_t) q) == 0) continue;
689
793ff80c 690 if (detector != detectorOld) {
e153aaf6 691
793ff80c 692 if (fVerbose > 1) {
693 printf("AliTRDdigitizer::MakeDigits -- ");
694 printf("Get new container. New det = %d, Old det = %d\n"
695 ,detector,detectorOld);
696 }
697 // Compress the old one if enabled
698 if ((fCompress) && (detectorOld > -1)) {
699 if (fVerbose > 1) {
700 printf("AliTRDdigitizer::MakeDigits -- ");
e153aaf6 701 printf("Compress the old container ...");
dd9a6ee3 702 }
793ff80c 703 signals->Compress(1,0);
704 for (iDict = 0; iDict < kNDict; iDict++) {
705 dictionary[iDict]->Compress(1,0);
dd9a6ee3 706 }
793ff80c 707 if (fVerbose > 1) printf("done\n");
9d0b222b 708 }
793ff80c 709 // Get the new container
710 signals = (AliTRDdataArrayF *) signalsArray->At(detector);
711 if (signals->GetNtime() == 0) {
712 // Allocate a new one if not yet existing
713 if (fVerbose > 1) {
714 printf("AliTRDdigitizer::MakeDigits -- ");
715 printf("Allocate a new container ... ");
716 }
717 signals->Allocate(nRowMax,nColMax,nTimeMax);
718 }
719 else {
720 // Expand an existing one
c1e4b257 721 if (fCompress) {
722 if (fVerbose > 1) {
723 printf("AliTRDdigitizer::MakeDigits -- ");
724 printf("Expand an existing container ... ");
725 }
726 signals->Expand();
793ff80c 727 }
793ff80c 728 }
729 // The same for the dictionary
730 for (iDict = 0; iDict < kNDict; iDict++) {
731 dictionary[iDict] = fDigits->GetDictionary(detector,iDict);
732 if (dictionary[iDict]->GetNtime() == 0) {
733 dictionary[iDict]->Allocate(nRowMax,nColMax,nTimeMax);
734 }
735 else {
736 if (fCompress) dictionary[iDict]->Expand();
737 }
738 }
739 if (fVerbose > 1) printf("done\n");
740 detectorOld = detector;
741 }
9d0b222b 742
793ff80c 743 // Rotate the sectors on top of each other
744 Float_t rot[3];
745 fGeo->Rotate(detector,pos,rot);
746
747 // The driftlength
748 Float_t driftlength = time0 - rot[0];
749 if ((driftlength < 0) ||
dd56b762 750 (driftlength > AliTRDgeometry::DrThick())) continue;
793ff80c 751 Float_t driftlengthL = driftlength;
752 if (fExBOn) driftlengthL /= TMath::Sqrt(fLorentzFactor);
753
754 // The hit position in pad coordinates (center pad)
755 // The pad row (z-direction)
756 Int_t rowH = (Int_t) ((rot[2] - row0) / rowPadSize);
757 // The pad column (rphi-direction)
758 Int_t colH = (Int_t) ((rot[1] - col0) / colPadSize);
759 // The time bucket
760 Int_t timeH = (Int_t) (driftlength / timeBinSize);
761 if (fVerbose > 1) {
762 printf("rowH = %d, colH = %d, timeH = %d\n"
763 ,rowH,colH,timeH);
764 }
765
766 // Loop over all electrons of this hit
767 // TR photons produce hits with negative charge
768 Int_t nEl = ((Int_t) TMath::Abs(q));
769 for (Int_t iEl = 0; iEl < nEl; iEl++) {
770
771 Float_t xyz[3];
772 xyz[0] = rot[0];
773 xyz[1] = rot[1];
774 xyz[2] = rot[2];
775
776 // Electron attachment
777 if (fElAttachOn) {
778 if (gRandom->Rndm() < (driftlengthL * fElAttachProp / 100.))
779 continue;
780 }
781
782 // Apply the diffusion smearing
783 if (fDiffusionOn) {
784 if (!(Diffusion(driftlengthL,xyz))) continue;
da581aea 785 }
f7336fa3 786
793ff80c 787 // Apply E x B effects
788 if (fExBOn) {
789 if (!(ExB(driftlength,xyz))) continue;
790 }
f7336fa3 791
793ff80c 792 // The electron position
793 // The pad row (z-direction)
794 Int_t rowE = (Int_t) ((xyz[2] - row0) / rowPadSize);
795 // The pad column (rphi-direction)
796 Int_t colE = (Int_t) ((xyz[1] - col0) / colPadSize);
797 // The time bucket
798 Int_t timeE = (Int_t) ((time0 - xyz[0]) / timeBinSize);
799
800 if (( rowE < 0) || ( rowE >= nRowMax)) continue;
801 if (( colE < 0) || ( colE >= nColMax)) continue;
802 if ((timeE < 0) || (timeE >= nTimeMax)) continue;
803
804 // Apply the gas gain including fluctuations
805 Float_t ggRndm = 0.0;
806 do {
807 ggRndm = gRandom->Rndm();
808 } while (ggRndm <= 0);
809 Int_t signal = (Int_t) (-fGasGain * TMath::Log(ggRndm));
810
811 if (fVerbose > 2) {
812 printf(" electron no. %d, signal = %d\n",iEl,signal);
813 printf(" rowE = %d, colE = %d, timeE = %d\n"
c1e4b257 814 ,rowE,colE,timeE);
793ff80c 815 }
f7336fa3 816
793ff80c 817 // Apply the pad response
818 Float_t padSignal[kNpad];
819 if (fPRFOn) {
820 // The distance of the electron to the center of the pad
821 // in units of pad width
822 Float_t dist = (xyz[1] - col0 - (colE + 0.5) * colPadSize)
823 / colPadSize;
824 if (!(PadResponse(signal,dist,padSignal))) continue;
825 }
826 else {
827 padSignal[0] = 0.0;
828 padSignal[1] = signal;
829 padSignal[2] = 0.0;
830 }
f7336fa3 831
793ff80c 832 // The distance of the position to the beginning of the timebin
833 Float_t timeOffset = (time0 - timeE * timeBinSize) - xyz[0];
834 Int_t timeTRDbeg = 0;
835 Int_t timeTRDend = 1;
836 if (fTRFOn) {
837 timeTRDbeg = 2;
838 timeTRDend = 11;
839 }
840 for (Int_t iTimeBin = TMath::Max(timeE - timeTRDbeg, 0)
841 ; iTimeBin < TMath::Min(timeE + timeTRDend,nTimeMax)
842 ; iTimeBin++) {
843
844 // Apply the time response
845 Float_t timeResponse = 1.0;
846 if (fTRFOn) {
847 Float_t time = (iTimeBin - timeE) * timeBinSize + timeOffset;
848 timeResponse = TimeResponse(time);
849 }
f7336fa3 850
793ff80c 851 // Add the signals
852 Float_t signalOld[kNpad] = { 0.0, 0.0, 0.0 };
853 for (Int_t iPad = 0; iPad < kNpad; iPad++) {
854 Int_t colPos = colE + iPad - 1;
855 if (colPos < 0) continue;
856 if (colPos >= nColMax) break;
857 signalOld[iPad] = signals->GetData(rowE,colPos,iTimeBin);
858 signalOld[iPad] += padSignal[iPad] * timeResponse;
859 signals->SetData(rowE,colPos,iTimeBin,signalOld[iPad]);
860 }
861 if (fVerbose > 3) {
862 printf(" iTimeBin = %d, timeResponse = %f\n"
863 ,iTimeBin,timeResponse);
864 printf(" pad-signal = %f, %f, %f\n"
865 ,signalOld[0],signalOld[1],signalOld[2]);
866 }
f7336fa3 867
793ff80c 868 // Store the track index in the dictionary
869 // Note: We store index+1 in order to allow the array to be compressed
870 for (iDict = 0; iDict < kNDict; iDict++) {
871 Int_t oldTrack = dictionary[iDict]->GetData(rowE,colE,timeE);
872 if (oldTrack == track+1) break;
873 //if (oldTrack == -1) break;
874 if (oldTrack == 0) {
875 dictionary[iDict]->SetData(rowE,colE,timeE,track+1);
876 if (fVerbose > 3) {
877 printf(" track index = %d\n",track);
f7336fa3 878 }
793ff80c 879 break;
880 }
881 }
882 if ((fVerbose > 1) && (iDict == kNDict)) {
883 printf("AliTRDdigitizer::MakeDigits -- ");
884 printf("More than three tracks for one digit!\n");
f7336fa3 885 }
886
f7336fa3 887 }
888
793ff80c 889 }
f7336fa3 890
793ff80c 891 }
f7336fa3 892
793ff80c 893 } // All hits finished
f7336fa3 894
793ff80c 895 printf("AliTRDdigitizer::MakeDigits -- ");
896 printf("Finished analyzing %d hits\n",countHits);
897
898 // Loop through all chambers to finalize the digits
899 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) {
900
901 Int_t plane = fGeo->GetPlane(iDet);
902 Int_t sector = fGeo->GetSector(iDet);
903 Int_t chamber = fGeo->GetChamber(iDet);
904 Int_t nRowMax = fGeo->GetRowMax(plane,chamber,sector);
905 Int_t nColMax = fGeo->GetColMax(plane);
906 Int_t nTimeMax = fGeo->GetTimeMax();
907
c1e4b257 908 //if (!(CheckDetector(plane,chamber,sector))) continue;
793ff80c 909 if (fVerbose > 0) {
910 printf("AliTRDdigitizer::MakeDigits -- ");
911 printf("Digitization for chamber %d\n",iDet);
912 }
da581aea 913
793ff80c 914 // Add a container for the digits of this detector
915 digits = fDigits->GetDigits(iDet);
916 // Allocate memory space for the digits buffer
917 digits->Allocate(nRowMax,nColMax,nTimeMax);
da581aea 918
793ff80c 919 // Get the signal container
920 signals = (AliTRDdataArrayF *) signalsArray->At(iDet);
921 if (signals->GetNtime() == 0) {
922 // Create missing containers
923 signals->Allocate(nRowMax,nColMax,nTimeMax);
924 }
925 else {
926 // Expand the container if neccessary
927 if (fCompress) signals->Expand();
928 }
929 // Create the missing dictionary containers
930 for (iDict = 0; iDict < kNDict; iDict++) {
931 dictionary[iDict] = fDigits->GetDictionary(iDet,iDict);
932 if (dictionary[iDict]->GetNtime() == 0) {
933 dictionary[iDict]->Allocate(nRowMax,nColMax,nTimeMax);
934 }
935 }
f7336fa3 936
793ff80c 937 Int_t nDigits = 0;
938
939 // Create the digits for this chamber
940 for (iRow = 0; iRow < nRowMax; iRow++ ) {
941 for (iCol = 0; iCol < nColMax; iCol++ ) {
942 for (iTime = 0; iTime < nTimeMax; iTime++) {
943
944 Float_t signalAmp = signals->GetData(iRow,iCol,iTime);
945
946 // Add the noise
dd56b762 947 signalAmp = TMath::Max((Double_t) gRandom->Gaus(signalAmp,fNoise),0.0);
793ff80c 948 // Convert to fC
949 signalAmp *= kEl2fC;
950 // Convert to mV
951 signalAmp *= fChipGain;
952 // Convert to ADC counts. Set the overflow-bit fADCoutRange if the
953 // signal is larger than fADCinRange
954 Int_t adc = 0;
955 if (signalAmp >= fADCinRange) {
956 adc = ((Int_t) fADCoutRange);
957 }
958 else {
959 adc = ((Int_t) (signalAmp * (fADCoutRange / fADCinRange)));
960 }
f7336fa3 961
793ff80c 962 // Store the amplitude of the digit if above threshold
963 if (adc > fADCthreshold) {
c1e4b257 964 if (fVerbose > 2) {
965 printf(" iRow = %d, iCol = %d, iTime = %d\n"
966 ,iRow,iCol,iTime);
967 printf(" signal = %f, adc = %d\n",signalAmp,adc);
968 }
793ff80c 969 nDigits++;
970 digits->SetData(iRow,iCol,iTime,adc);
f7336fa3 971 }
f7336fa3 972
f7336fa3 973 }
793ff80c 974 }
975 }
976
977 // Compress the arrays
978 digits->Compress(1,0);
979 for (iDict = 0; iDict < kNDict; iDict++) {
980 dictionary[iDict]->Compress(1,0);
981 }
f7336fa3 982
793ff80c 983 totalSizeDigits += digits->GetSize();
984 totalSizeDict0 += dictionary[0]->GetSize();
985 totalSizeDict1 += dictionary[1]->GetSize();
986 totalSizeDict2 += dictionary[2]->GetSize();
f7336fa3 987
c1e4b257 988 Float_t nPixel = nRowMax * nColMax * nTimeMax;
793ff80c 989 printf("AliTRDdigitizer::MakeDigits -- ");
c1e4b257 990 printf("Found %d digits in detector %d (%3.0f).\n"
991 ,nDigits,iDet
992 ,100.0 * ((Float_t) nDigits) / nPixel);
da581aea 993
793ff80c 994 if (fCompress) signals->Compress(1,0);
f7336fa3 995
f7336fa3 996 }
997
da581aea 998 printf("AliTRDdigitizer::MakeDigits -- ");
8230f242 999 printf("Total number of analyzed hits = %d\n",countHits);
da581aea 1000
f7336fa3 1001 printf("AliTRDdigitizer::MakeDigits -- ");
1002 printf("Total digits data size = %d, %d, %d, %d\n",totalSizeDigits
1003 ,totalSizeDict0
1004 ,totalSizeDict1
1005 ,totalSizeDict2);
1006
1007 return kTRUE;
1008
1009}
1010
793ff80c 1011//_____________________________________________________________________________
1012Bool_t AliTRDdigitizer::CheckDetector(Int_t plane, Int_t chamber, Int_t sector)
1013{
1014 //
1015 // Checks whether a detector is enabled
1016 //
1017
1018 if ((fTRD->GetSensChamber() >= 0) &&
1019 (fTRD->GetSensChamber() != chamber)) return kFALSE;
1020 if ((fTRD->GetSensPlane() >= 0) &&
c1e4b257 1021 (fTRD->GetSensPlane() != plane)) return kFALSE;
793ff80c 1022 if ( fTRD->GetSensSector() >= 0) {
1023 Int_t sens1 = fTRD->GetSensSector();
1024 Int_t sens2 = sens1 + fTRD->GetSensSectorRange();
1025 sens2 -= ((Int_t) (sens2 / AliTRDgeometry::Nsect()))
1026 * AliTRDgeometry::Nsect();
1027 if (sens1 < sens2) {
1028 if ((sector < sens1) || (sector >= sens2)) return kFALSE;
1029 }
1030 else {
1031 if ((sector < sens1) && (sector >= sens2)) return kFALSE;
1032 }
1033 }
1034
1035 return kTRUE;
1036
1037}
1038
f7336fa3 1039//_____________________________________________________________________________
1040Bool_t AliTRDdigitizer::WriteDigits()
1041{
1042 //
1043 // Writes out the TRD-digits and the dictionaries
1044 //
1045
1046 // Create the branches
1047 if (!(gAlice->TreeD()->GetBranch("TRDdigits"))) {
da581aea 1048 if (!fDigits->MakeBranch()) return kFALSE;
f7336fa3 1049 }
1050
da581aea 1051 // Store the digits and the dictionary in the tree
1052 fDigits->WriteDigits();
f7336fa3 1053
1054 // Write the new tree into the input file (use overwrite option)
1055 Char_t treeName[7];
1056 sprintf(treeName,"TreeD%d",fEvent);
1057 printf("AliTRDdigitizer::WriteDigits -- ");
1058 printf("Write the digits tree %s for event %d.\n"
1059 ,treeName,fEvent);
1060 gAlice->TreeD()->Write(treeName,2);
1061
1062 return kTRUE;
1063
1064}
793ff80c 1065
1066//_____________________________________________________________________________
1067void AliTRDdigitizer::SetPRF(TF1 *prf)
1068{
1069 //
1070 // Defines a new pad response function
1071 //
1072
1073 if (fPRF) delete fPRF;
1074 fPRF = prf;
1075
1076}
1077
1078//_____________________________________________________________________________
1079void AliTRDdigitizer::SetTRF(TF1 *trf)
1080{
1081 //
1082 // Defines a new time response function
1083 //
1084
1085 if (fTRF) delete fTRF;
1086 fTRF = trf;
1087
1088}
1089
1090//_____________________________________________________________________________
1091Double_t TRFlandau(Double_t *x, Double_t *par)
1092{
1093
1094 Double_t xx = x[0];
1095 Double_t landau = par[0] * TMath::Landau(xx,par[1],par[2]);
1096
1097 return landau;
1098
1099}