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.17 2000/12/08 12:53:27 cblume
19 Change in Copy() function for HP-compiler
21 Revision 1.16 2000/12/07 12:20:46 cblume
22 Go back to array compression. Use sampled PRF to speed up digitization
24 Revision 1.15 2000/11/23 14:34:08 cblume
25 Fixed bug in expansion routine of arrays (initialize buffers properly)
27 Revision 1.14 2000/11/20 08:54:44 cblume
28 Switch off compression as default
30 Revision 1.13 2000/11/10 14:57:52 cblume
31 Changes in the geometry constants for the DEC compiler
33 Revision 1.12 2000/11/01 14:53:20 cblume
34 Merge with TRD-develop
36 Revision 1.1.4.9 2000/10/26 17:00:22 cblume
37 Fixed bug in CheckDetector()
39 Revision 1.1.4.8 2000/10/23 13:41:35 cblume
40 Added protection against Log(0) in the gas gain calulation
42 Revision 1.1.4.7 2000/10/17 02:27:34 cblume
43 Get rid of global constants
45 Revision 1.1.4.6 2000/10/16 01:16:53 cblume
46 Changed timebin 0 to be the one closest to the readout
48 Revision 1.1.4.5 2000/10/15 23:34:29 cblume
49 Faster version of the digitizer
51 Revision 1.1.4.4 2000/10/06 16:49:46 cblume
54 Revision 1.1.4.3 2000/10/04 16:34:58 cblume
55 Replace include files by forward declarations
57 Revision 1.1.4.2 2000/09/22 14:41:10 cblume
58 Bug fix in PRF. Included time response. New structure
60 Revision 1.10 2000/10/05 07:27:53 cblume
61 Changes in the header-files by FCA
63 Revision 1.9 2000/10/02 21:28:19 fca
64 Removal of useless dependecies via forward declarations
66 Revision 1.8 2000/06/09 11:10:07 cblume
67 Compiler warnings and coding conventions, next round
69 Revision 1.7 2000/06/08 18:32:58 cblume
70 Make code compliant to coding conventions
72 Revision 1.6 2000/06/07 16:27:32 cblume
73 Try to remove compiler warnings on Sun and HP
75 Revision 1.5 2000/05/09 16:38:57 cblume
76 Removed PadResponse(). Merge problem
78 Revision 1.4 2000/05/08 15:53:45 cblume
79 Resolved merge conflict
81 Revision 1.3 2000/04/28 14:49:27 cblume
82 Only one declaration of iDict in MakeDigits()
84 Revision 1.1.4.1 2000/05/08 14:42:04 cblume
85 Introduced AliTRDdigitsManager
87 Revision 1.1 2000/02/28 19:00:13 cblume
92 ///////////////////////////////////////////////////////////////////////////////
94 // Creates and handles digits from TRD hits //
96 // The following effects are included: //
99 // - Gas gain including fluctuations //
100 // - Pad-response (simple Gaussian approximation) //
101 // - Electronics noise //
102 // - Electronics gain //
104 // - ADC threshold //
105 // The corresponding parameter can be adjusted via the various //
106 // Set-functions. If these parameters are not explicitly set, default //
107 // values are used (see Init-function). //
108 // To produce digits from a root-file with TRD-hits use the //
109 // slowDigitsCreate.C macro. //
111 ///////////////////////////////////////////////////////////////////////////////
126 #include "AliTRDhit.h"
127 #include "AliTRDdigitizer.h"
128 #include "AliTRDdataArrayI.h"
129 #include "AliTRDdataArrayF.h"
130 #include "AliTRDsegmentArray.h"
131 #include "AliTRDdigitsManager.h"
132 #include "AliTRDgeometry.h"
134 ClassImp(AliTRDdigitizer)
136 //_____________________________________________________________________________
137 AliTRDdigitizer::AliTRDdigitizer():TNamed()
140 // AliTRDdigitizer default constructor
168 fDriftVelocity = 0.0;
185 //_____________________________________________________________________________
186 AliTRDdigitizer::AliTRDdigitizer(const Text_t *name, const Text_t *title)
190 // AliTRDdigitizer default constructor
211 //_____________________________________________________________________________
212 AliTRDdigitizer::AliTRDdigitizer(const AliTRDdigitizer &d)
215 // AliTRDdigitizer copy constructor
218 ((AliTRDdigitizer &) d).Copy(*this);
222 //_____________________________________________________________________________
223 AliTRDdigitizer::~AliTRDdigitizer()
226 // AliTRDdigitizer destructor
238 if (fPRF) delete fPRF;
239 if (fTRF) delete fTRF;
243 //_____________________________________________________________________________
244 AliTRDdigitizer &AliTRDdigitizer::operator=(const AliTRDdigitizer &d)
247 // Assignment operator
250 if (this != &d) ((AliTRDdigitizer &) d).Copy(*this);
255 //_____________________________________________________________________________
256 void AliTRDdigitizer::Copy(TObject &d)
264 ((AliTRDdigitizer &) d).fInputFile = NULL;
265 ((AliTRDdigitizer &) d).fDigits = NULL;
266 ((AliTRDdigitizer &) d).fTRD = NULL;
267 ((AliTRDdigitizer &) d).fGeo = NULL;
269 ((AliTRDdigitizer &) d).fEvent = 0;
271 ((AliTRDdigitizer &) d).fGasGain = fGasGain;
272 ((AliTRDdigitizer &) d).fNoise = fNoise;
273 ((AliTRDdigitizer &) d).fChipGain = fChipGain;
274 ((AliTRDdigitizer &) d).fADCoutRange = fADCoutRange;
275 ((AliTRDdigitizer &) d).fADCinRange = fADCinRange;
276 ((AliTRDdigitizer &) d).fADCthreshold = fADCthreshold;
277 ((AliTRDdigitizer &) d).fDiffusionOn = fDiffusionOn;
278 ((AliTRDdigitizer &) d).fDiffusionT = fDiffusionT;
279 ((AliTRDdigitizer &) d).fDiffusionL = fDiffusionL;
280 ((AliTRDdigitizer &) d).fElAttachOn = fElAttachOn;
281 ((AliTRDdigitizer &) d).fElAttachProp = fElAttachProp;
282 ((AliTRDdigitizer &) d).fExBOn = fExBOn;
283 ((AliTRDdigitizer &) d).fOmegaTau = fOmegaTau;
284 ((AliTRDdigitizer &) d).fLorentzFactor = fLorentzFactor;
285 ((AliTRDdigitizer &) d).fPRFOn = fPRFOn;
286 ((AliTRDdigitizer &) d).fTRFOn = fTRFOn;
288 ((AliTRDdigitizer &) d).fCompress = fCompress;
289 ((AliTRDdigitizer &) d).fVerbose = fVerbose;
291 fPRF->Copy(*((AliTRDdigitizer &) d).fPRF);
292 fTRF->Copy(*((AliTRDdigitizer &) d).fTRF);
294 ((AliTRDdigitizer &) d).fPRFbin = fPRFbin;
295 ((AliTRDdigitizer &) d).fPRFlo = fPRFlo;
296 ((AliTRDdigitizer &) d).fPRFhi = fPRFhi;
297 ((AliTRDdigitizer &) d).fPRFwid = fPRFwid;
298 ((AliTRDdigitizer &) d).fPRFpad = fPRFpad;
299 if (((AliTRDdigitizer &) d).fPRFsmp) delete ((AliTRDdigitizer &) d).fPRFsmp;
300 ((AliTRDdigitizer &) d).fPRFsmp = new Float_t[fPRFbin];
301 for (iBin = 0; iBin < fPRFbin; iBin++) {
302 ((AliTRDdigitizer &) d).fPRFsmp[iBin] = fPRFsmp[iBin];
304 ((AliTRDdigitizer &) d).fTRFbin = fTRFbin;
305 ((AliTRDdigitizer &) d).fTRFlo = fTRFlo;
306 ((AliTRDdigitizer &) d).fTRFhi = fTRFhi;
307 ((AliTRDdigitizer &) d).fTRFwid = fTRFwid;
308 if (((AliTRDdigitizer &) d).fTRFint) delete ((AliTRDdigitizer &) d).fTRFint;
309 ((AliTRDdigitizer &) d).fTRFint = new Float_t[fTRFbin];
310 for (iBin = 0; iBin < fTRFbin; iBin++) {
311 ((AliTRDdigitizer &) d).fTRFint[iBin] = fTRFint[iBin];
316 //_____________________________________________________________________________
317 Int_t AliTRDdigitizer::Diffusion(Float_t driftlength, Float_t *xyz)
320 // Applies the diffusion smearing to the position of a single electron
323 Float_t driftSqrt = TMath::Sqrt(driftlength);
324 Float_t sigmaT = driftSqrt * fDiffusionT;
325 Float_t sigmaL = driftSqrt * fDiffusionL;
326 xyz[0] = gRandom->Gaus(xyz[0], sigmaL * fLorentzFactor);
327 xyz[1] = gRandom->Gaus(xyz[1], sigmaT * fLorentzFactor);
328 xyz[2] = gRandom->Gaus(xyz[2], sigmaT);
334 //_____________________________________________________________________________
335 Int_t AliTRDdigitizer::ExB(Float_t driftlength, Float_t *xyz)
338 // Applies E x B effects to the position of a single electron
342 xyz[1] = xyz[1] + fOmegaTau * driftlength;
349 //_____________________________________________________________________________
350 Int_t AliTRDdigitizer::PadResponse(Float_t signal, Float_t dist, Float_t *pad)
353 // Applies the pad response
356 Int_t iBin = ((Int_t) (( - dist - fPRFlo) / fPRFwid));
358 Int_t iBin0 = iBin - fPRFpad;
360 Int_t iBin2 = iBin + fPRFpad;
362 if ((iBin0 >= 0) && (iBin2 < fPRFbin)) {
364 pad[0] = signal * fPRFsmp[iBin0];
365 pad[1] = signal * fPRFsmp[iBin1];
366 pad[2] = signal * fPRFsmp[iBin2];
379 //_____________________________________________________________________________
380 Float_t AliTRDdigitizer::TimeResponse(Float_t time)
383 // Applies the preamp shaper time response
386 Int_t iBin = ((Int_t) ((time - fTRFlo) / fTRFwid));
387 if ((iBin >= 0) && (iBin < fTRFbin)) {
388 return fTRFint[iBin];
396 //_____________________________________________________________________________
397 void AliTRDdigitizer::Init()
400 // Initializes the digitization procedure with standard values
403 // The default parameter for the digitization
411 // Transverse and longitudinal diffusion coefficients (Xe/Isobutane)
416 // Propability for electron attachment
422 // omega * tau. (tau ~ 12 * 10^-12, B = 0.2T)
423 fOmegaTau = 17.6 * 12.0 * 0.2 * 0.01;
425 // The pad response function
430 fPRFwid = (fPRFhi - fPRFlo) / ((Float_t) fPRFbin);
431 fPRFpad = ((Int_t) (1.0 / fPRFwid));
432 fPRF = new TF1("PRF","[0]*([1]+exp(-x*x/(2.0*[2])))",fPRFlo,fPRFhi);
433 fPRF->SetParameter(0, 0.8872);
434 fPRF->SetParameter(1,-0.00573);
435 fPRF->SetParameter(2, 0.454 * 0.454);
437 // The drift velocity (cm / mus)
438 fDriftVelocity = 1.0;
440 // The time response function
442 Float_t loTRF = -200.0;
443 Float_t hiTRF = 1000.0;
444 fTRF = new TF1("TRF",TRFlandau,loTRF,hiTRF,3);
445 fTRF->SetParameter(0, 1.0 / 24.24249);
446 fTRF->SetParameter(1, 0.0);
447 fTRF->SetParameter(2, 25.0);
449 fTRFlo = loTRF * fDriftVelocity / 1000.0;
450 fTRFhi = hiTRF * fDriftVelocity / 1000.0;
451 fTRFwid = (fTRFhi - fTRFlo) / ((Float_t) fTRFbin);
455 //_____________________________________________________________________________
456 void AliTRDdigitizer::IntegrateTRF()
459 // Integrates the time response function over the time bin size
462 if (fTRFint) delete fTRFint;
463 fTRFint = new Float_t[fTRFbin];
464 Float_t hiTRF = fTRFhi / fDriftVelocity * 1000.0;
465 Float_t loTRF = fTRFlo / fDriftVelocity * 1000.0;
466 Float_t timeBin = fGeo->GetTimeBinSize() / fDriftVelocity * 1000.0;
467 Float_t binWidth = (hiTRF - loTRF) / ((Float_t) fTRFbin);
468 for (Int_t iBin = 0; iBin < fTRFbin; iBin++) {
469 Float_t bin = iBin * binWidth + loTRF - 0.5 * timeBin;
470 fTRFint[iBin] = fTRF->Integral(bin,bin + timeBin);
475 //_____________________________________________________________________________
476 void AliTRDdigitizer::SamplePRF()
479 // Samples the pad response function
482 if (fPRFsmp) delete fPRFsmp;
483 fPRFsmp = new Float_t[fPRFbin];
484 for (Int_t iBin = 0; iBin < fPRFbin; iBin++) {
485 Float_t bin = (((Float_t ) iBin) + 0.5) * fPRFwid + fPRFlo;
486 fPRFsmp[iBin] = TMath::Max(fPRF->Eval(bin),0.0);
491 //_____________________________________________________________________________
492 Bool_t AliTRDdigitizer::Open(const Char_t *name, Int_t nEvent)
495 // Opens a ROOT-file with TRD-hits and reads in the hit-tree
498 // Connect the AliRoot file containing Geometry, Kine, and Hits
499 fInputFile = (TFile*) gROOT->GetListOfFiles()->FindObject(name);
501 printf("AliTRDdigitizer::Open -- ");
502 printf("Open the ALIROOT-file %s.\n",name);
503 fInputFile = new TFile(name,"UPDATE");
506 printf("AliTRDdigitizer::Open -- ");
507 printf("%s is already open.\n",name);
510 gAlice = (AliRun*) fInputFile->Get("gAlice");
512 printf("AliTRDdigitizer::Open -- ");
513 printf("AliRun object found on file.\n");
516 printf("AliTRDdigitizer::Open -- ");
517 printf("Could not find AliRun object.\n");
523 // Import the Trees for the event nEvent in the file
524 Int_t nparticles = gAlice->GetEvent(fEvent);
525 if (nparticles <= 0) {
526 printf("AliTRDdigitizer::Open -- ");
527 printf("No entries in the trees for event %d.\n",fEvent);
531 return InitDetector();
535 //_____________________________________________________________________________
536 Bool_t AliTRDdigitizer::InitDetector()
539 // Sets the pointer to the TRD detector and the geometry
542 // Get the pointer to the detector class and check for version 1
543 fTRD = (AliTRD*) gAlice->GetDetector("TRD");
544 if (fTRD->IsVersion() != 1) {
545 printf("AliTRDdigitizer::Open -- ");
546 printf("TRD must be version 1 (slow simulator).\n");
551 fGeo = fTRD->GetGeometry();
552 printf("AliTRDdigitizer::Open -- ");
553 printf("Geometry version %d\n",fGeo->IsVersion());
559 //_____________________________________________________________________________
560 Bool_t AliTRDdigitizer::MakeDigits()
563 // Loops through the TRD-hits and creates the digits.
566 ///////////////////////////////////////////////////////////////
568 ///////////////////////////////////////////////////////////////
570 // Converts number of electrons to fC
571 const Float_t kEl2fC = 1.602E-19 * 1.0E15;
573 ///////////////////////////////////////////////////////////////
575 // Number of pads included in the pad response
576 const Int_t kNpad = 3;
578 // Number of track dictionary arrays
579 const Int_t kNDict = AliTRDdigitsManager::kNDict;
581 Int_t iRow, iCol, iTime;
585 Int_t totalSizeDigits = 0;
586 Int_t totalSizeDict0 = 0;
587 Int_t totalSizeDict1 = 0;
588 Int_t totalSizeDict2 = 0;
590 AliTRDdataArrayF *signals = 0;
591 AliTRDdataArrayI *digits = 0;
592 AliTRDdataArrayI *dictionary[kNDict];
594 // Create a digits manager
595 fDigits = new AliTRDdigitsManager();
597 // Create a container for the amplitudes
598 AliTRDsegmentArray *signalsArray
599 = new AliTRDsegmentArray("AliTRDdataArrayF",AliTRDgeometry::Ndet());
602 printf("AliTRDdigitizer::MakeDigits -- ");
603 printf("No geometry defined\n");
607 printf("AliTRDdigitizer::MakeDigits -- ");
608 printf("Start creating digits.\n");
609 if (fVerbose > 0) this->Dump();
611 // The Lorentz factor
613 fLorentzFactor = 1.0 / (1.0 + fOmegaTau*fOmegaTau);
616 fLorentzFactor = 1.0;
619 // Create the sampled PRF
622 // Create the integrated TRF
625 // Get the pointer to the hit tree
626 TTree *HitTree = gAlice->TreeH();
628 // Get the number of entries in the hit tree
629 // (Number of primary particles creating a hit somewhere)
630 Int_t nTrack = (Int_t) HitTree->GetEntries();
632 printf("AliTRDdigitizer::MakeDigits -- ");
633 printf("Found %d primary particles\n",nTrack);
636 Int_t detectorOld = -1;
639 // Loop through all entries in the tree
640 for (Int_t iTrack = 0; iTrack < nTrack; iTrack++) {
643 nBytes += HitTree->GetEvent(iTrack);
645 // Get the number of hits in the TRD created by this particle
646 Int_t nHit = fTRD->Hits()->GetEntriesFast();
648 printf("AliTRDdigitizer::MakeDigits -- ");
649 printf("Found %d hits for primary particle %d\n",nHit,iTrack);
652 // Loop through the TRD hits
653 for (Int_t iHit = 0; iHit < nHit; iHit++) {
657 AliTRDhit *hit = (AliTRDhit *) fTRD->Hits()->UncheckedAt(iHit);
662 Float_t q = hit->GetCharge();
663 Int_t track = hit->Track();
664 Int_t detector = hit->GetDetector();
665 Int_t plane = fGeo->GetPlane(detector);
666 Int_t sector = fGeo->GetSector(detector);
667 Int_t chamber = fGeo->GetChamber(detector);
669 if (!(CheckDetector(plane,chamber,sector))) continue;
671 Int_t nRowMax = fGeo->GetRowMax(plane,chamber,sector);
672 Int_t nColMax = fGeo->GetColMax(plane);
673 Int_t nTimeMax = fGeo->GetTimeMax();
674 Float_t row0 = fGeo->GetRow0(plane,chamber,sector);
675 Float_t col0 = fGeo->GetCol0(plane);
676 Float_t time0 = fGeo->GetTime0(plane);
677 Float_t rowPadSize = fGeo->GetRowPadSize();
678 Float_t colPadSize = fGeo->GetColPadSize();
679 Float_t timeBinSize = fGeo->GetTimeBinSize();
682 printf("Analyze hit no. %d ",iHit);
683 printf("-----------------------------------------------------------\n");
685 printf("plane = %d, sector = %d, chamber = %d\n"
686 ,plane,sector,chamber);
687 printf("nRowMax = %d, nColMax = %d, nTimeMax = %d\n"
688 ,nRowMax,nColMax,nTimeMax);
689 printf("row0 = %f, col0 = %f, time0 = %f\n"
691 printf("rowPadSize = %f, colPadSize = %f, timeBinSize = %f\n"
692 ,rowPadSize,colPadSize,timeBinSize);
695 // Don't analyze test hits with amplitude 0.
696 if (((Int_t) q) == 0) continue;
698 if (detector != detectorOld) {
701 printf("AliTRDdigitizer::MakeDigits -- ");
702 printf("Get new container. New det = %d, Old det = %d\n"
703 ,detector,detectorOld);
705 // Compress the old one if enabled
706 if ((fCompress) && (detectorOld > -1)) {
708 printf("AliTRDdigitizer::MakeDigits -- ");
709 printf("Compress the old container ...");
711 signals->Compress(1,0);
712 for (iDict = 0; iDict < kNDict; iDict++) {
713 dictionary[iDict]->Compress(1,0);
715 if (fVerbose > 1) printf("done\n");
717 // Get the new container
718 signals = (AliTRDdataArrayF *) signalsArray->At(detector);
719 if (signals->GetNtime() == 0) {
720 // Allocate a new one if not yet existing
722 printf("AliTRDdigitizer::MakeDigits -- ");
723 printf("Allocate a new container ... ");
725 signals->Allocate(nRowMax,nColMax,nTimeMax);
728 // Expand an existing one
731 printf("AliTRDdigitizer::MakeDigits -- ");
732 printf("Expand an existing container ... ");
737 // The same for the dictionary
738 for (iDict = 0; iDict < kNDict; iDict++) {
739 dictionary[iDict] = fDigits->GetDictionary(detector,iDict);
740 if (dictionary[iDict]->GetNtime() == 0) {
741 dictionary[iDict]->Allocate(nRowMax,nColMax,nTimeMax);
744 if (fCompress) dictionary[iDict]->Expand();
747 if (fVerbose > 1) printf("done\n");
748 detectorOld = detector;
751 // Rotate the sectors on top of each other
753 fGeo->Rotate(detector,pos,rot);
756 Float_t driftlength = time0 - rot[0];
757 if ((driftlength < 0) ||
758 (driftlength > AliTRDgeometry::DrThick())) continue;
759 Float_t driftlengthL = driftlength;
760 if (fExBOn) driftlengthL /= TMath::Sqrt(fLorentzFactor);
762 // The hit position in pad coordinates (center pad)
763 // The pad row (z-direction)
764 Int_t rowH = (Int_t) ((rot[2] - row0) / rowPadSize);
765 // The pad column (rphi-direction)
766 Int_t colH = (Int_t) ((rot[1] - col0) / colPadSize);
768 Int_t timeH = (Int_t) (driftlength / timeBinSize);
770 printf("rowH = %d, colH = %d, timeH = %d\n"
774 // Loop over all electrons of this hit
775 // TR photons produce hits with negative charge
776 Int_t nEl = ((Int_t) TMath::Abs(q));
777 for (Int_t iEl = 0; iEl < nEl; iEl++) {
784 // Electron attachment
786 if (gRandom->Rndm() < (driftlengthL * fElAttachProp / 100.))
790 // Apply the diffusion smearing
792 if (!(Diffusion(driftlengthL,xyz))) continue;
795 // Apply E x B effects
797 if (!(ExB(driftlength,xyz))) continue;
800 // The electron position
801 // The pad row (z-direction)
802 Int_t rowE = (Int_t) ((xyz[2] - row0) / rowPadSize);
803 // The pad column (rphi-direction)
804 Int_t colE = (Int_t) ((xyz[1] - col0) / colPadSize);
806 Int_t timeE = (Int_t) ((time0 - xyz[0]) / timeBinSize);
808 if (( rowE < 0) || ( rowE >= nRowMax)) continue;
809 if (( colE < 0) || ( colE >= nColMax)) continue;
810 if ((timeE < 0) || (timeE >= nTimeMax)) continue;
812 // Apply the gas gain including fluctuations
813 Float_t ggRndm = 0.0;
815 ggRndm = gRandom->Rndm();
816 } while (ggRndm <= 0);
817 Int_t signal = (Int_t) (-fGasGain * TMath::Log(ggRndm));
820 printf(" electron no. %d, signal = %d\n",iEl,signal);
821 printf(" rowE = %d, colE = %d, timeE = %d\n"
825 // Apply the pad response
826 Float_t padSignal[kNpad];
828 // The distance of the electron to the center of the pad
829 // in units of pad width
830 Float_t dist = (xyz[1] - col0 - (colE + 0.5) * colPadSize)
832 if (!(PadResponse(signal,dist,padSignal))) continue;
836 padSignal[1] = signal;
840 // The distance of the position to the beginning of the timebin
841 Float_t timeOffset = (time0 - timeE * timeBinSize) - xyz[0];
842 Int_t timeTRDbeg = 0;
843 Int_t timeTRDend = 1;
848 for (Int_t iTimeBin = TMath::Max(timeE - timeTRDbeg, 0)
849 ; iTimeBin < TMath::Min(timeE + timeTRDend,nTimeMax)
852 // Apply the time response
853 Float_t timeResponse = 1.0;
855 Float_t time = (iTimeBin - timeE) * timeBinSize + timeOffset;
856 timeResponse = TimeResponse(time);
860 Float_t signalOld[kNpad] = { 0.0, 0.0, 0.0 };
861 for (Int_t iPad = 0; iPad < kNpad; iPad++) {
862 Int_t colPos = colE + iPad - 1;
863 if (colPos < 0) continue;
864 if (colPos >= nColMax) break;
865 signalOld[iPad] = signals->GetData(rowE,colPos,iTimeBin);
866 signalOld[iPad] += padSignal[iPad] * timeResponse;
867 signals->SetData(rowE,colPos,iTimeBin,signalOld[iPad]);
870 printf(" iTimeBin = %d, timeResponse = %f\n"
871 ,iTimeBin,timeResponse);
872 printf(" pad-signal = %f, %f, %f\n"
873 ,signalOld[0],signalOld[1],signalOld[2]);
876 // Store the track index in the dictionary
877 // Note: We store index+1 in order to allow the array to be compressed
878 for (iDict = 0; iDict < kNDict; iDict++) {
879 Int_t oldTrack = dictionary[iDict]->GetData(rowE,colE,timeE);
880 if (oldTrack == track+1) break;
881 //if (oldTrack == -1) break;
883 dictionary[iDict]->SetData(rowE,colE,timeE,track+1);
885 printf(" track index = %d\n",track);
890 if ((fVerbose > 1) && (iDict == kNDict)) {
891 printf("AliTRDdigitizer::MakeDigits -- ");
892 printf("More than three tracks for one digit!\n");
901 } // All hits finished
903 printf("AliTRDdigitizer::MakeDigits -- ");
904 printf("Finished analyzing %d hits\n",countHits);
906 // Loop through all chambers to finalize the digits
907 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) {
909 Int_t plane = fGeo->GetPlane(iDet);
910 Int_t sector = fGeo->GetSector(iDet);
911 Int_t chamber = fGeo->GetChamber(iDet);
912 Int_t nRowMax = fGeo->GetRowMax(plane,chamber,sector);
913 Int_t nColMax = fGeo->GetColMax(plane);
914 Int_t nTimeMax = fGeo->GetTimeMax();
916 //if (!(CheckDetector(plane,chamber,sector))) continue;
918 printf("AliTRDdigitizer::MakeDigits -- ");
919 printf("Digitization for chamber %d\n",iDet);
922 // Add a container for the digits of this detector
923 digits = fDigits->GetDigits(iDet);
924 // Allocate memory space for the digits buffer
925 digits->Allocate(nRowMax,nColMax,nTimeMax);
927 // Get the signal container
928 signals = (AliTRDdataArrayF *) signalsArray->At(iDet);
929 if (signals->GetNtime() == 0) {
930 // Create missing containers
931 signals->Allocate(nRowMax,nColMax,nTimeMax);
934 // Expand the container if neccessary
935 if (fCompress) signals->Expand();
937 // Create the missing dictionary containers
938 for (iDict = 0; iDict < kNDict; iDict++) {
939 dictionary[iDict] = fDigits->GetDictionary(iDet,iDict);
940 if (dictionary[iDict]->GetNtime() == 0) {
941 dictionary[iDict]->Allocate(nRowMax,nColMax,nTimeMax);
947 // Create the digits for this chamber
948 for (iRow = 0; iRow < nRowMax; iRow++ ) {
949 for (iCol = 0; iCol < nColMax; iCol++ ) {
950 for (iTime = 0; iTime < nTimeMax; iTime++) {
952 Float_t signalAmp = signals->GetData(iRow,iCol,iTime);
955 signalAmp = TMath::Max((Double_t) gRandom->Gaus(signalAmp,fNoise),0.0);
959 signalAmp *= fChipGain;
960 // Convert to ADC counts. Set the overflow-bit fADCoutRange if the
961 // signal is larger than fADCinRange
963 if (signalAmp >= fADCinRange) {
964 adc = ((Int_t) fADCoutRange);
967 adc = ((Int_t) (signalAmp * (fADCoutRange / fADCinRange)));
970 // Store the amplitude of the digit if above threshold
971 if (adc > fADCthreshold) {
973 printf(" iRow = %d, iCol = %d, iTime = %d\n"
975 printf(" signal = %f, adc = %d\n",signalAmp,adc);
978 digits->SetData(iRow,iCol,iTime,adc);
985 // Compress the arrays
986 digits->Compress(1,0);
987 for (iDict = 0; iDict < kNDict; iDict++) {
988 dictionary[iDict]->Compress(1,0);
991 totalSizeDigits += digits->GetSize();
992 totalSizeDict0 += dictionary[0]->GetSize();
993 totalSizeDict1 += dictionary[1]->GetSize();
994 totalSizeDict2 += dictionary[2]->GetSize();
996 Float_t nPixel = nRowMax * nColMax * nTimeMax;
997 printf("AliTRDdigitizer::MakeDigits -- ");
998 printf("Found %d digits in detector %d (%3.0f).\n"
1000 ,100.0 * ((Float_t) nDigits) / nPixel);
1002 if (fCompress) signals->Compress(1,0);
1006 printf("AliTRDdigitizer::MakeDigits -- ");
1007 printf("Total number of analyzed hits = %d\n",countHits);
1009 printf("AliTRDdigitizer::MakeDigits -- ");
1010 printf("Total digits data size = %d, %d, %d, %d\n",totalSizeDigits
1019 //_____________________________________________________________________________
1020 Bool_t AliTRDdigitizer::CheckDetector(Int_t plane, Int_t chamber, Int_t sector)
1023 // Checks whether a detector is enabled
1026 if ((fTRD->GetSensChamber() >= 0) &&
1027 (fTRD->GetSensChamber() != chamber)) return kFALSE;
1028 if ((fTRD->GetSensPlane() >= 0) &&
1029 (fTRD->GetSensPlane() != plane)) return kFALSE;
1030 if ( fTRD->GetSensSector() >= 0) {
1031 Int_t sens1 = fTRD->GetSensSector();
1032 Int_t sens2 = sens1 + fTRD->GetSensSectorRange();
1033 sens2 -= ((Int_t) (sens2 / AliTRDgeometry::Nsect()))
1034 * AliTRDgeometry::Nsect();
1035 if (sens1 < sens2) {
1036 if ((sector < sens1) || (sector >= sens2)) return kFALSE;
1039 if ((sector < sens1) && (sector >= sens2)) return kFALSE;
1047 //_____________________________________________________________________________
1048 Bool_t AliTRDdigitizer::WriteDigits()
1051 // Writes out the TRD-digits and the dictionaries
1054 // Create the branches
1055 if (!(gAlice->TreeD()->GetBranch("TRDdigits"))) {
1056 if (!fDigits->MakeBranch()) return kFALSE;
1059 // Store the digits and the dictionary in the tree
1060 fDigits->WriteDigits();
1062 // Write the new tree into the input file (use overwrite option)
1064 sprintf(treeName,"TreeD%d",fEvent);
1065 printf("AliTRDdigitizer::WriteDigits -- ");
1066 printf("Write the digits tree %s for event %d.\n"
1068 gAlice->TreeD()->Write(treeName,TObject::kOverwrite);
1074 //_____________________________________________________________________________
1075 void AliTRDdigitizer::SetPRF(TF1 *prf)
1078 // Defines a new pad response function
1081 if (fPRF) delete fPRF;
1086 //_____________________________________________________________________________
1087 void AliTRDdigitizer::SetTRF(TF1 *trf)
1090 // Defines a new time response function
1093 if (fTRF) delete fTRF;
1098 //_____________________________________________________________________________
1099 Double_t TRFlandau(Double_t *x, Double_t *par)
1103 Double_t landau = par[0] * TMath::Landau(xx,par[1],par[2]);