1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.20 2001/02/25 20:19:00 hristov
19 Minor correction: loop variable declared only once for HP, Sun
21 Revision 1.19 2001/02/14 18:22:26 cblume
22 Change in the geometry of the padplane
24 Revision 1.18 2001/01/26 19:56:57 hristov
25 Major upgrade of AliRoot code
27 Revision 1.17 2000/12/08 12:53:27 cblume
28 Change in Copy() function for HP-compiler
30 Revision 1.16 2000/12/07 12:20:46 cblume
31 Go back to array compression. Use sampled PRF to speed up digitization
33 Revision 1.15 2000/11/23 14:34:08 cblume
34 Fixed bug in expansion routine of arrays (initialize buffers properly)
36 Revision 1.14 2000/11/20 08:54:44 cblume
37 Switch off compression as default
39 Revision 1.13 2000/11/10 14:57:52 cblume
40 Changes in the geometry constants for the DEC compiler
42 Revision 1.12 2000/11/01 14:53:20 cblume
43 Merge with TRD-develop
45 Revision 1.1.4.9 2000/10/26 17:00:22 cblume
46 Fixed bug in CheckDetector()
48 Revision 1.1.4.8 2000/10/23 13:41:35 cblume
49 Added protection against Log(0) in the gas gain calulation
51 Revision 1.1.4.7 2000/10/17 02:27:34 cblume
52 Get rid of global constants
54 Revision 1.1.4.6 2000/10/16 01:16:53 cblume
55 Changed timebin 0 to be the one closest to the readout
57 Revision 1.1.4.5 2000/10/15 23:34:29 cblume
58 Faster version of the digitizer
60 Revision 1.1.4.4 2000/10/06 16:49:46 cblume
63 Revision 1.1.4.3 2000/10/04 16:34:58 cblume
64 Replace include files by forward declarations
66 Revision 1.1.4.2 2000/09/22 14:41:10 cblume
67 Bug fix in PRF. Included time response. New structure
69 Revision 1.10 2000/10/05 07:27:53 cblume
70 Changes in the header-files by FCA
72 Revision 1.9 2000/10/02 21:28:19 fca
73 Removal of useless dependecies via forward declarations
75 Revision 1.8 2000/06/09 11:10:07 cblume
76 Compiler warnings and coding conventions, next round
78 Revision 1.7 2000/06/08 18:32:58 cblume
79 Make code compliant to coding conventions
81 Revision 1.6 2000/06/07 16:27:32 cblume
82 Try to remove compiler warnings on Sun and HP
84 Revision 1.5 2000/05/09 16:38:57 cblume
85 Removed PadResponse(). Merge problem
87 Revision 1.4 2000/05/08 15:53:45 cblume
88 Resolved merge conflict
90 Revision 1.3 2000/04/28 14:49:27 cblume
91 Only one declaration of iDict in MakeDigits()
93 Revision 1.1.4.1 2000/05/08 14:42:04 cblume
94 Introduced AliTRDdigitsManager
96 Revision 1.1 2000/02/28 19:00:13 cblume
101 ///////////////////////////////////////////////////////////////////////////////
103 // Creates and handles digits from TRD hits //
105 // The following effects are included: //
108 // - Gas gain including fluctuations //
109 // - Pad-response (simple Gaussian approximation) //
110 // - Electronics noise //
111 // - Electronics gain //
113 // - ADC threshold //
114 // The corresponding parameter can be adjusted via the various //
115 // Set-functions. If these parameters are not explicitly set, default //
116 // values are used (see Init-function). //
117 // To produce digits from a root-file with TRD-hits use the //
118 // slowDigitsCreate.C macro. //
120 ///////////////////////////////////////////////////////////////////////////////
135 #include "AliTRDhit.h"
136 #include "AliTRDdigitizer.h"
137 #include "AliTRDdataArrayI.h"
138 #include "AliTRDdataArrayF.h"
139 #include "AliTRDsegmentArray.h"
140 #include "AliTRDdigitsManager.h"
141 #include "AliTRDgeometry.h"
143 ClassImp(AliTRDdigitizer)
145 //_____________________________________________________________________________
146 AliTRDdigitizer::AliTRDdigitizer():TNamed()
149 // AliTRDdigitizer default constructor
179 fDriftVelocity = 0.0;
200 //_____________________________________________________________________________
201 AliTRDdigitizer::AliTRDdigitizer(const Text_t *name, const Text_t *title)
205 // AliTRDdigitizer default constructor
227 //_____________________________________________________________________________
228 AliTRDdigitizer::AliTRDdigitizer(const AliTRDdigitizer &d)
231 // AliTRDdigitizer copy constructor
234 ((AliTRDdigitizer &) d).Copy(*this);
238 //_____________________________________________________________________________
239 AliTRDdigitizer::~AliTRDdigitizer()
242 // AliTRDdigitizer destructor
254 if (fPRF) delete fPRF;
255 if (fTRF) delete fTRF;
259 //_____________________________________________________________________________
260 AliTRDdigitizer &AliTRDdigitizer::operator=(const AliTRDdigitizer &d)
263 // Assignment operator
266 if (this != &d) ((AliTRDdigitizer &) d).Copy(*this);
271 //_____________________________________________________________________________
272 void AliTRDdigitizer::Copy(TObject &d)
280 ((AliTRDdigitizer &) d).fInputFile = NULL;
281 ((AliTRDdigitizer &) d).fDigits = NULL;
282 ((AliTRDdigitizer &) d).fTRD = NULL;
283 ((AliTRDdigitizer &) d).fGeo = NULL;
285 ((AliTRDdigitizer &) d).fEvent = 0;
287 ((AliTRDdigitizer &) d).fGasGain = fGasGain;
288 ((AliTRDdigitizer &) d).fNoise = fNoise;
289 ((AliTRDdigitizer &) d).fChipGain = fChipGain;
290 ((AliTRDdigitizer &) d).fSoutRange = fSoutRange;
291 ((AliTRDdigitizer &) d).fSinRange = fSinRange;
292 ((AliTRDdigitizer &) d).fADCoutRange = fADCoutRange;
293 ((AliTRDdigitizer &) d).fADCinRange = fADCinRange;
294 ((AliTRDdigitizer &) d).fADCthreshold = fADCthreshold;
295 ((AliTRDdigitizer &) d).fDiffusionOn = fDiffusionOn;
296 ((AliTRDdigitizer &) d).fDiffusionT = fDiffusionT;
297 ((AliTRDdigitizer &) d).fDiffusionL = fDiffusionL;
298 ((AliTRDdigitizer &) d).fElAttachOn = fElAttachOn;
299 ((AliTRDdigitizer &) d).fElAttachProp = fElAttachProp;
300 ((AliTRDdigitizer &) d).fExBOn = fExBOn;
301 ((AliTRDdigitizer &) d).fOmegaTau = fOmegaTau;
302 ((AliTRDdigitizer &) d).fLorentzFactor = fLorentzFactor;
303 ((AliTRDdigitizer &) d).fDriftVelocity = fDriftVelocity;
304 ((AliTRDdigitizer &) d).fPadCoupling = fPadCoupling;
305 ((AliTRDdigitizer &) d).fTimeCoupling = fTimeCoupling;
306 ((AliTRDdigitizer &) d).fTimeBinWidth = fTimeBinWidth;
307 ((AliTRDdigitizer &) d).fPRFOn = fPRFOn;
308 ((AliTRDdigitizer &) d).fTRFOn = fTRFOn;
310 ((AliTRDdigitizer &) d).fCompress = fCompress;
311 ((AliTRDdigitizer &) d).fVerbose = fVerbose;
312 ((AliTRDdigitizer &) d).fSDigits = fSDigits;
314 fPRF->Copy(*((AliTRDdigitizer &) d).fPRF);
315 fTRF->Copy(*((AliTRDdigitizer &) d).fTRF);
317 ((AliTRDdigitizer &) d).fPRFbin = fPRFbin;
318 ((AliTRDdigitizer &) d).fPRFlo = fPRFlo;
319 ((AliTRDdigitizer &) d).fPRFhi = fPRFhi;
320 ((AliTRDdigitizer &) d).fPRFwid = fPRFwid;
321 ((AliTRDdigitizer &) d).fPRFpad = fPRFpad;
322 if (((AliTRDdigitizer &) d).fPRFsmp) delete ((AliTRDdigitizer &) d).fPRFsmp;
323 ((AliTRDdigitizer &) d).fPRFsmp = new Float_t[fPRFbin];
324 for (iBin = 0; iBin < fPRFbin; iBin++) {
325 ((AliTRDdigitizer &) d).fPRFsmp[iBin] = fPRFsmp[iBin];
327 ((AliTRDdigitizer &) d).fTRFbin = fTRFbin;
328 ((AliTRDdigitizer &) d).fTRFlo = fTRFlo;
329 ((AliTRDdigitizer &) d).fTRFhi = fTRFhi;
330 ((AliTRDdigitizer &) d).fTRFwid = fTRFwid;
331 if (((AliTRDdigitizer &) d).fTRFint) delete ((AliTRDdigitizer &) d).fTRFint;
332 ((AliTRDdigitizer &) d).fTRFint = new Float_t[fTRFbin];
333 for (iBin = 0; iBin < fTRFbin; iBin++) {
334 ((AliTRDdigitizer &) d).fTRFint[iBin] = fTRFint[iBin];
339 //_____________________________________________________________________________
340 Int_t AliTRDdigitizer::Diffusion(Float_t driftlength, Float_t *xyz)
343 // Applies the diffusion smearing to the position of a single electron
346 Float_t driftSqrt = TMath::Sqrt(driftlength);
347 Float_t sigmaT = driftSqrt * fDiffusionT;
348 Float_t sigmaL = driftSqrt * fDiffusionL;
349 xyz[0] = gRandom->Gaus(xyz[0], sigmaL * fLorentzFactor);
350 xyz[1] = gRandom->Gaus(xyz[1], sigmaT * fLorentzFactor);
351 xyz[2] = gRandom->Gaus(xyz[2], sigmaT);
357 //_____________________________________________________________________________
358 Int_t AliTRDdigitizer::ExB(Float_t driftlength, Float_t *xyz)
361 // Applies E x B effects to the position of a single electron
365 xyz[1] = xyz[1] + fOmegaTau * driftlength;
372 //_____________________________________________________________________________
373 Int_t AliTRDdigitizer::PadResponse(Float_t signal, Float_t dist, Float_t *pad)
376 // Applies the pad response
379 Int_t iBin = ((Int_t) (( - dist - fPRFlo) / fPRFwid));
381 Int_t iBin0 = iBin - fPRFpad;
383 Int_t iBin2 = iBin + fPRFpad;
385 if ((iBin0 >= 0) && (iBin2 < fPRFbin)) {
387 pad[0] = signal * fPRFsmp[iBin0];
388 pad[1] = signal * fPRFsmp[iBin1];
389 pad[2] = signal * fPRFsmp[iBin2];
402 //_____________________________________________________________________________
403 Float_t AliTRDdigitizer::TimeResponse(Float_t time)
406 // Applies the preamp shaper time response
409 Int_t iBin = ((Int_t) ((time - fTRFlo) / fTRFwid));
410 if ((iBin >= 0) && (iBin < fTRFbin)) {
411 return fTRFint[iBin];
419 //_____________________________________________________________________________
420 void AliTRDdigitizer::Init()
423 // Initializes the digitization procedure with standard values
426 // Get the detector geometry
429 // The default parameter for the digitization
433 fADCoutRange = 1023.; // 10-bit ADC
434 fADCinRange = 2000.; // 2V input range
437 // For the summable digits
438 fSinRange = 1000000.;
439 fSoutRange = 1000000.;
441 // Transverse and longitudinal diffusion coefficients (Xe/Isobutane)
446 // Propability for electron attachment
452 // omega * tau.= arctan(Lorentz-angle)
453 fOmegaTau = 0.19438031;
455 // The pad response function
460 fPRFwid = (fPRFhi - fPRFlo) / ((Float_t) fPRFbin);
461 fPRFpad = ((Int_t) (1.0 / fPRFwid));
462 fPRF = new TF1("PRF","[0]*([1]+exp(-x*x/(2.0*[2])))",fPRFlo,fPRFhi);
463 fPRF->SetParameter(0, 0.8872);
464 fPRF->SetParameter(1,-0.00573);
465 fPRF->SetParameter(2, 0.454 * 0.454);
467 // The drift velocity (cm / mus)
468 fDriftVelocity = 2.0;
470 // The pad coupling factor (same number as for the TPC)
473 // The time coupling factor (same number as for the TPC)
480 //_____________________________________________________________________________
481 void AliTRDdigitizer::ReInit()
484 // Re-initializes the digitization procedure after a change in the parameter
487 // Calculate the time bin width in ns
488 fTimeBinWidth = fGeo->GetTimeBinSize() / fDriftVelocity * 1000.0;
490 // The time response function (in ns)
491 // The FWHM of the TRF is automatically set equal to the time bin width
493 Float_t loTRF = -2.0 * fTimeBinWidth;
494 Float_t hiTRF = 10.0 * fTimeBinWidth;
495 fTRF = new TF1("TRF",TRFlandau,loTRF,hiTRF,3);
496 //fTRF->SetParameter(0, 1.0 / 24.24249);
497 fTRF->SetParameter(0, 5.56);
498 fTRF->SetParameter(1, 0.0);
499 fTRF->SetParameter(2, 0.25 * fTimeBinWidth);
501 fTRFlo = loTRF * fDriftVelocity / 1000.0;
502 fTRFhi = hiTRF * fDriftVelocity / 1000.0;
503 fTRFwid = (fTRFhi - fTRFlo) / ((Float_t) fTRFbin);
505 // The Lorentz factor
507 fLorentzFactor = 1.0 / (1.0 + fOmegaTau*fOmegaTau);
510 fLorentzFactor = 1.0;
515 //_____________________________________________________________________________
516 void AliTRDdigitizer::SampleTRF()
519 // Samples the time response function
522 if (fTRFint) delete fTRFint;
523 fTRFint = new Float_t[fTRFbin];
524 Float_t loTRF = fTRFlo / fDriftVelocity * 1000.0;
525 Float_t hiTRF = fTRFhi / fDriftVelocity * 1000.0;
526 Float_t binWidth = (hiTRF - loTRF) / ((Float_t) fTRFbin);
527 for (Int_t iBin = 0; iBin < fTRFbin; iBin++) {
528 Float_t bin = (((Float_t) iBin) + 0.5) * binWidth + loTRF;
529 fTRFint[iBin] = fTRF->Eval(bin);
534 //_____________________________________________________________________________
535 void AliTRDdigitizer::SamplePRF()
538 // Samples the pad response function
541 if (fPRFsmp) delete fPRFsmp;
542 fPRFsmp = new Float_t[fPRFbin];
543 for (Int_t iBin = 0; iBin < fPRFbin; iBin++) {
544 Float_t bin = (((Float_t ) iBin) + 0.5) * fPRFwid + fPRFlo;
545 fPRFsmp[iBin] = TMath::Max(fPRF->Eval(bin),0.0);
550 //_____________________________________________________________________________
551 Bool_t AliTRDdigitizer::Open(const Char_t *name, Int_t nEvent)
554 // Opens a ROOT-file with TRD-hits and reads in the hit-tree
557 // Connect the AliRoot file containing Geometry, Kine, and Hits
558 fInputFile = (TFile*) gROOT->GetListOfFiles()->FindObject(name);
560 printf("AliTRDdigitizer::Open -- ");
561 printf("Open the ALIROOT-file %s.\n",name);
562 fInputFile = new TFile(name,"UPDATE");
565 printf("AliTRDdigitizer::Open -- ");
566 printf("%s is already open.\n",name);
569 gAlice = (AliRun*) fInputFile->Get("gAlice");
571 printf("AliTRDdigitizer::Open -- ");
572 printf("AliRun object found on file.\n");
575 printf("AliTRDdigitizer::Open -- ");
576 printf("Could not find AliRun object.\n");
582 // Import the Trees for the event nEvent in the file
583 Int_t nparticles = gAlice->GetEvent(fEvent);
584 if (nparticles <= 0) {
585 printf("AliTRDdigitizer::Open -- ");
586 printf("No entries in the trees for event %d.\n",fEvent);
590 return InitDetector();
594 //_____________________________________________________________________________
595 Bool_t AliTRDdigitizer::InitDetector()
598 // Sets the pointer to the TRD detector and the geometry
601 // Get the pointer to the detector class and check for version 1
602 fTRD = (AliTRD*) gAlice->GetDetector("TRD");
603 if (fTRD->IsVersion() != 1) {
604 printf("AliTRDdigitizer::InitDetector -- ");
605 printf("TRD must be version 1 (slow simulator).\n");
610 fGeo = fTRD->GetGeometry();
611 printf("AliTRDdigitizer::InitDetector -- ");
612 printf("Geometry version %d\n",fGeo->IsVersion());
618 //_____________________________________________________________________________
619 Bool_t AliTRDdigitizer::SumSDigits()
622 // Sums up the summable digits and creates final digits
623 // Not yet implemented
630 //_____________________________________________________________________________
631 Bool_t AliTRDdigitizer::MakeDigits()
634 // Creates summable digits.
637 ///////////////////////////////////////////////////////////////
639 ///////////////////////////////////////////////////////////////
641 // Converts number of electrons to fC
642 const Float_t kEl2fC = 1.602E-19 * 1.0E15;
644 ///////////////////////////////////////////////////////////////
646 // Number of pads included in the pad response
647 const Int_t kNpad = 3;
649 // Number of track dictionary arrays
650 const Int_t kNDict = AliTRDdigitsManager::kNDict;
652 Int_t iRow, iCol, iTime, iPad;
656 Int_t totalSizeDigits = 0;
657 Int_t totalSizeDict0 = 0;
658 Int_t totalSizeDict1 = 0;
659 Int_t totalSizeDict2 = 0;
661 AliTRDdataArrayF *signals = 0;
662 AliTRDdataArrayI *digits = 0;
663 AliTRDdataArrayI *dictionary[kNDict];
665 // Create a digits manager
666 fDigits = new AliTRDdigitsManager();
668 // Create a container for the amplitudes
669 AliTRDsegmentArray *signalsArray
670 = new AliTRDsegmentArray("AliTRDdataArrayF",AliTRDgeometry::Ndet());
673 printf("AliTRDdigitizer::MakeDigits -- ");
674 printf("No geometry defined\n");
678 printf("AliTRDdigitizer::MakeDigits -- ");
679 printf("Start creating digits.\n");
680 if (fVerbose > 0) this->Dump();
682 // Create the sampled PRF
685 // Create the sampled TRF
688 // Get the pointer to the hit tree
689 TTree *HitTree = gAlice->TreeH();
691 // Get the number of entries in the hit tree
692 // (Number of primary particles creating a hit somewhere)
693 Int_t nTrack = (Int_t) HitTree->GetEntries();
695 printf("AliTRDdigitizer::MakeDigits -- ");
696 printf("Found %d primary particles\n",nTrack);
699 Int_t detectorOld = -1;
702 // Loop through all entries in the tree
703 for (Int_t iTrack = 0; iTrack < nTrack; iTrack++) {
706 nBytes += HitTree->GetEvent(iTrack);
708 // Get the number of hits in the TRD created by this particle
709 Int_t nHit = fTRD->Hits()->GetEntriesFast();
711 printf("AliTRDdigitizer::MakeDigits -- ");
712 printf("Found %d hits for primary particle %d\n",nHit,iTrack);
715 // Loop through the TRD hits
716 for (Int_t iHit = 0; iHit < nHit; iHit++) {
720 AliTRDhit *hit = (AliTRDhit *) fTRD->Hits()->UncheckedAt(iHit);
725 Float_t q = hit->GetCharge();
726 Int_t track = hit->Track();
727 Int_t detector = hit->GetDetector();
728 Int_t plane = fGeo->GetPlane(detector);
729 Int_t sector = fGeo->GetSector(detector);
730 Int_t chamber = fGeo->GetChamber(detector);
732 if (!(CheckDetector(plane,chamber,sector))) continue;
734 Int_t nRowMax = fGeo->GetRowMax(plane,chamber,sector);
735 Int_t nColMax = fGeo->GetColMax(plane);
736 Int_t nTimeMax = fGeo->GetTimeMax();
737 Float_t row0 = fGeo->GetRow0(plane,chamber,sector);
738 Float_t col0 = fGeo->GetCol0(plane);
739 Float_t time0 = fGeo->GetTime0(plane);
740 Float_t rowPadSize = fGeo->GetRowPadSize(plane,chamber,sector);
741 Float_t colPadSize = fGeo->GetColPadSize(plane);
742 Float_t timeBinSize = fGeo->GetTimeBinSize();
745 printf("Analyze hit no. %d ",iHit);
746 printf("-----------------------------------------------------------\n");
748 printf("plane = %d, sector = %d, chamber = %d\n"
749 ,plane,sector,chamber);
750 printf("nRowMax = %d, nColMax = %d, nTimeMax = %d\n"
751 ,nRowMax,nColMax,nTimeMax);
752 printf("row0 = %f, col0 = %f, time0 = %f\n"
754 printf("rowPadSize = %f, colPadSize = %f, timeBinSize = %f\n"
755 ,rowPadSize,colPadSize,timeBinSize);
758 // Don't analyze test hits with amplitude 0.
759 if (((Int_t) q) == 0) continue;
761 if (detector != detectorOld) {
764 printf("AliTRDdigitizer::MakeDigits -- ");
765 printf("Get new container. New det = %d, Old det = %d\n"
766 ,detector,detectorOld);
768 // Compress the old one if enabled
769 if ((fCompress) && (detectorOld > -1)) {
771 printf("AliTRDdigitizer::MakeDigits -- ");
772 printf("Compress the old container ...");
774 signals->Compress(1,0);
775 for (iDict = 0; iDict < kNDict; iDict++) {
776 dictionary[iDict]->Compress(1,0);
778 if (fVerbose > 1) printf("done\n");
780 // Get the new container
781 signals = (AliTRDdataArrayF *) signalsArray->At(detector);
782 if (signals->GetNtime() == 0) {
783 // Allocate a new one if not yet existing
785 printf("AliTRDdigitizer::MakeDigits -- ");
786 printf("Allocate a new container ... ");
788 signals->Allocate(nRowMax,nColMax,nTimeMax);
791 // Expand an existing one
794 printf("AliTRDdigitizer::MakeDigits -- ");
795 printf("Expand an existing container ... ");
800 // The same for the dictionary
801 for (iDict = 0; iDict < kNDict; iDict++) {
802 dictionary[iDict] = fDigits->GetDictionary(detector,iDict);
803 if (dictionary[iDict]->GetNtime() == 0) {
804 dictionary[iDict]->Allocate(nRowMax,nColMax,nTimeMax);
807 if (fCompress) dictionary[iDict]->Expand();
810 if (fVerbose > 1) printf("done\n");
811 detectorOld = detector;
814 // Rotate the sectors on top of each other
816 fGeo->Rotate(detector,pos,rot);
819 Float_t driftlength = time0 - rot[0];
820 if ((driftlength < 0) ||
821 (driftlength > AliTRDgeometry::DrThick())) continue;
822 Float_t driftlengthL = driftlength;
823 if (fExBOn) driftlengthL /= TMath::Sqrt(fLorentzFactor);
825 // The hit position in pad coordinates (center pad)
826 // The pad row (z-direction)
827 Int_t rowH = (Int_t) ((rot[2] - row0) / rowPadSize);
828 // The pad column (rphi-direction)
829 Int_t colH = (Int_t) ((rot[1] - col0) / colPadSize);
831 Int_t timeH = (Int_t) (driftlength / timeBinSize);
833 printf("rowH = %d, colH = %d, timeH = %d\n"
837 // Loop over all electrons of this hit
838 // TR photons produce hits with negative charge
839 Int_t nEl = ((Int_t) TMath::Abs(q));
840 for (Int_t iEl = 0; iEl < nEl; iEl++) {
847 // Electron attachment
849 if (gRandom->Rndm() < (driftlengthL * fElAttachProp / 100.))
853 // Apply the diffusion smearing
855 if (!(Diffusion(driftlengthL,xyz))) continue;
858 // Apply E x B effects
860 if (!(ExB(driftlength,xyz))) continue;
863 // The electron position
864 // The pad row (z-direction)
865 Int_t rowE = (Int_t) ((xyz[2] - row0) / rowPadSize);
866 if (( rowE < 0) || ( rowE >= nRowMax)) continue;
867 // The pad column (rphi-direction)
868 Int_t colE = (Int_t) ((xyz[1] - col0) / colPadSize);
869 if (( colE < 0) || ( colE >= nColMax)) continue;
871 Int_t timeE = (Int_t) ((time0 - xyz[0]) / timeBinSize);
872 if ((timeE < 0) || (timeE >= nTimeMax)) continue;
874 // Apply the gas gain including fluctuations
875 Float_t ggRndm = 0.0;
877 ggRndm = gRandom->Rndm();
878 } while (ggRndm <= 0);
879 Int_t signal = (Int_t) (-fGasGain * TMath::Log(ggRndm));
881 // Apply the pad response
882 Float_t padSignal[kNpad];
884 // The distance of the electron to the center of the pad
885 // in units of pad width
886 Float_t dist = (xyz[1] - col0 - (colE + 0.5) * colPadSize)
888 if (!(PadResponse(signal,dist,padSignal))) continue;
892 padSignal[1] = signal;
896 // The distance of the position to the beginning of the timebin
897 Float_t timeOffset = (time0 - timeE * timeBinSize) - xyz[0];
898 Int_t timeTRDbeg = 0;
899 Int_t timeTRDend = 1;
904 for (Int_t iTimeBin = TMath::Max(timeE - timeTRDbeg, 0)
905 ;iTimeBin < TMath::Min(timeE + timeTRDend,nTimeMax)
908 // Apply the time response
909 Float_t timeResponse = 1.0;
911 Float_t time = (iTimeBin - timeE) * timeBinSize + timeOffset;
912 timeResponse = TimeResponse(time);
916 Float_t signalOld[kNpad] = { 0.0, 0.0, 0.0 };
917 for (iPad = 0; iPad < kNpad; iPad++) {
918 Int_t colPos = colE + iPad - 1;
919 if (colPos < 0) continue;
920 if (colPos >= nColMax) break;
921 signalOld[iPad] = signals->GetData(rowE,colPos,iTimeBin);
922 signalOld[iPad] += padSignal[iPad] * timeResponse;
923 signals->SetData(rowE,colPos,iTimeBin,signalOld[iPad]);
926 // Store the track index in the dictionary
927 // Note: We store index+1 in order to allow the array to be compressed
928 //for (iDict = 0; iDict < kNDict; iDict++) {
929 // Int_t oldTrack = dictionary[iDict]->GetData(rowE,colE,timeE);
930 // if (oldTrack == track+1) break;
931 // //if (oldTrack == -1) break;
932 // if (oldTrack == 0) {
933 // dictionary[iDict]->SetData(rowE,colE,timeE,track+1);
934 // if (fVerbose > 3) {
935 // printf(" track index = %d\n",track);
940 for (iPad = 0; iPad < kNpad; iPad++) {
941 Int_t colPos = colE + iPad - 1;
942 if (colPos < 0) continue;
943 if (colPos >= nColMax) break;
944 if (signals->GetData(rowE,colPos,iTimeBin) > 0) {
945 for (iDict = 0; iDict < kNDict; iDict++) {
946 Int_t oldTrack = dictionary[iDict]->GetData(rowE,colPos,iTimeBin);
947 if (oldTrack == track+1) break;
948 //if (oldTrack == -1) break;
950 dictionary[iDict]->SetData(rowE,colPos,iTimeBin,track+1);
956 //if ((fVerbose > 1) && (iDict == kNDict)) {
957 // printf("AliTRDdigitizer::MakeDigits -- ");
958 // printf("More than three tracks for one digit!\n");
967 } // All hits finished
969 printf("AliTRDdigitizer::MakeDigits -- ");
970 printf("Finished analyzing %d hits\n",countHits);
972 // The total conversion factor
973 Float_t convert = kEl2fC * fPadCoupling * fTimeCoupling * fChipGain;
975 // Loop through all chambers to finalize the digits
976 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) {
978 Int_t plane = fGeo->GetPlane(iDet);
979 Int_t sector = fGeo->GetSector(iDet);
980 Int_t chamber = fGeo->GetChamber(iDet);
981 Int_t nRowMax = fGeo->GetRowMax(plane,chamber,sector);
982 Int_t nColMax = fGeo->GetColMax(plane);
983 Int_t nTimeMax = fGeo->GetTimeMax();
986 printf("AliTRDdigitizer::MakeDigits -- ");
987 printf("Digitization for chamber %d\n",iDet);
990 // Add a container for the digits of this detector
991 digits = fDigits->GetDigits(iDet);
992 // Allocate memory space for the digits buffer
993 digits->Allocate(nRowMax,nColMax,nTimeMax);
995 // Get the signal container
996 signals = (AliTRDdataArrayF *) signalsArray->At(iDet);
997 if (signals->GetNtime() == 0) {
998 // Create missing containers
999 signals->Allocate(nRowMax,nColMax,nTimeMax);
1002 // Expand the container if neccessary
1003 if (fCompress) signals->Expand();
1005 // Create the missing dictionary containers
1006 for (iDict = 0; iDict < kNDict; iDict++) {
1007 dictionary[iDict] = fDigits->GetDictionary(iDet,iDict);
1008 if (dictionary[iDict]->GetNtime() == 0) {
1009 dictionary[iDict]->Allocate(nRowMax,nColMax,nTimeMax);
1015 // Don't create noise in detectors that are switched off
1016 if (CheckDetector(plane,chamber,sector)) {
1018 // Create the digits for this chamber
1019 for (iRow = 0; iRow < nRowMax; iRow++ ) {
1020 for (iCol = 0; iCol < nColMax; iCol++ ) {
1021 for (iTime = 0; iTime < nTimeMax; iTime++) {
1023 // Create summable digits
1026 Float_t signalAmp = signals->GetData(iRow,iCol,iTime);
1028 if (signalAmp >= fSinRange) {
1029 adc = ((Int_t) fSoutRange);
1032 adc = ((Int_t) (signalAmp * (fSoutRange / fSinRange)));
1035 digits->SetData(iRow,iCol,iTime,adc);
1038 // Create normal digits
1041 Float_t signalAmp = signals->GetData(iRow,iCol,iTime);
1044 signalAmp = TMath::Max((Double_t) gRandom->Gaus(signalAmp,fNoise),0.0);
1046 signalAmp *= convert;
1047 // Convert to ADC counts. Set the overflow-bit fADCoutRange if the
1048 // signal is larger than fADCinRange
1050 if (signalAmp >= fADCinRange) {
1051 adc = ((Int_t) fADCoutRange);
1054 adc = ((Int_t) (signalAmp * (fADCoutRange / fADCinRange)));
1057 // Store the amplitude of the digit if above threshold
1058 if (adc > fADCthreshold) {
1060 printf(" iRow = %d, iCol = %d, iTime = %d\n"
1062 printf(" signal = %f, adc = %d\n",signalAmp,adc);
1065 digits->SetData(iRow,iCol,iTime,adc);
1076 // Compress the arrays
1077 digits->Compress(1,0);
1078 for (iDict = 0; iDict < kNDict; iDict++) {
1079 dictionary[iDict]->Compress(1,0);
1082 totalSizeDigits += digits->GetSize();
1083 totalSizeDict0 += dictionary[0]->GetSize();
1084 totalSizeDict1 += dictionary[1]->GetSize();
1085 totalSizeDict2 += dictionary[2]->GetSize();
1087 Float_t nPixel = nRowMax * nColMax * nTimeMax;
1088 printf("AliTRDdigitizer::MakeDigits -- ");
1089 printf("Found %d digits in detector %d (%3.0f).\n"
1091 ,100.0 * ((Float_t) nDigits) / nPixel);
1093 if (fCompress) signals->Compress(1,0);
1097 printf("AliTRDdigitizer::MakeDigits -- ");
1098 printf("Total number of analyzed hits = %d\n",countHits);
1100 printf("AliTRDdigitizer::MakeDigits -- ");
1101 printf("Total digits data size = %d, %d, %d, %d\n",totalSizeDigits
1110 //_____________________________________________________________________________
1111 Bool_t AliTRDdigitizer::CheckDetector(Int_t plane, Int_t chamber, Int_t sector)
1114 // Checks whether a detector is enabled
1117 if ((fTRD->GetSensChamber() >= 0) &&
1118 (fTRD->GetSensChamber() != chamber)) return kFALSE;
1119 if ((fTRD->GetSensPlane() >= 0) &&
1120 (fTRD->GetSensPlane() != plane)) return kFALSE;
1121 if ( fTRD->GetSensSector() >= 0) {
1122 Int_t sens1 = fTRD->GetSensSector();
1123 Int_t sens2 = sens1 + fTRD->GetSensSectorRange();
1124 sens2 -= ((Int_t) (sens2 / AliTRDgeometry::Nsect()))
1125 * AliTRDgeometry::Nsect();
1126 if (sens1 < sens2) {
1127 if ((sector < sens1) || (sector >= sens2)) return kFALSE;
1130 if ((sector < sens1) && (sector >= sens2)) return kFALSE;
1138 //_____________________________________________________________________________
1139 Bool_t AliTRDdigitizer::WriteDigits()
1142 // Writes out the TRD-digits and the dictionaries
1145 // Create the branches
1146 if (!(gAlice->TreeD()->GetBranch("TRDdigits"))) {
1148 //if (!fDigits->MakeBranch()) {
1149 // printf("AliTRDdigitizer::WriteDigits -- ");
1150 // printf("MakeBranch failed.\n");
1155 // Store the digits and the dictionary in the tree
1156 fDigits->WriteDigits();
1158 // Write the new tree into the input file (use overwrite option)
1159 Char_t treeName[15];
1160 sprintf(treeName,"TreeD%d",fEvent);
1161 printf("AliTRDdigitizer::WriteDigits -- ");
1162 printf("Write the digits tree %s for event %d.\n"
1164 gAlice->TreeD()->Write(treeName,TObject::kOverwrite);
1170 //_____________________________________________________________________________
1171 void AliTRDdigitizer::SetPRF(TF1 *prf)
1174 // Defines a new pad response function
1177 if (fPRF) delete fPRF;
1182 //_____________________________________________________________________________
1183 void AliTRDdigitizer::SetTRF(TF1 *trf)
1186 // Defines a new time response function
1189 if (fTRF) delete fTRF;
1194 //_____________________________________________________________________________
1195 Double_t TRFlandau(Double_t *x, Double_t *par)
1199 Double_t landau = par[0] * TMath::Landau(xx,par[1],par[2]);