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.14 2000/11/20 08:54:44 cblume
19 Switch off compression as default
21 Revision 1.13 2000/11/10 14:57:52 cblume
22 Changes in the geometry constants for the DEC compiler
24 Revision 1.12 2000/11/01 14:53:20 cblume
25 Merge with TRD-develop
27 Revision 1.1.4.9 2000/10/26 17:00:22 cblume
28 Fixed bug in CheckDetector()
30 Revision 1.1.4.8 2000/10/23 13:41:35 cblume
31 Added protection against Log(0) in the gas gain calulation
33 Revision 1.1.4.7 2000/10/17 02:27:34 cblume
34 Get rid of global constants
36 Revision 1.1.4.6 2000/10/16 01:16:53 cblume
37 Changed timebin 0 to be the one closest to the readout
39 Revision 1.1.4.5 2000/10/15 23:34:29 cblume
40 Faster version of the digitizer
42 Revision 1.1.4.4 2000/10/06 16:49:46 cblume
45 Revision 1.1.4.3 2000/10/04 16:34:58 cblume
46 Replace include files by forward declarations
48 Revision 1.1.4.2 2000/09/22 14:41:10 cblume
49 Bug fix in PRF. Included time response. New structure
51 Revision 1.10 2000/10/05 07:27:53 cblume
52 Changes in the header-files by FCA
54 Revision 1.9 2000/10/02 21:28:19 fca
55 Removal of useless dependecies via forward declarations
57 Revision 1.8 2000/06/09 11:10:07 cblume
58 Compiler warnings and coding conventions, next round
60 Revision 1.7 2000/06/08 18:32:58 cblume
61 Make code compliant to coding conventions
63 Revision 1.6 2000/06/07 16:27:32 cblume
64 Try to remove compiler warnings on Sun and HP
66 Revision 1.5 2000/05/09 16:38:57 cblume
67 Removed PadResponse(). Merge problem
69 Revision 1.4 2000/05/08 15:53:45 cblume
70 Resolved merge conflict
72 Revision 1.3 2000/04/28 14:49:27 cblume
73 Only one declaration of iDict in MakeDigits()
75 Revision 1.1.4.1 2000/05/08 14:42:04 cblume
76 Introduced AliTRDdigitsManager
78 Revision 1.1 2000/02/28 19:00:13 cblume
83 ///////////////////////////////////////////////////////////////////////////////
85 // Creates and handles digits from TRD hits //
87 // The following effects are included: //
90 // - Gas gain including fluctuations //
91 // - Pad-response (simple Gaussian approximation) //
92 // - Electronics noise //
93 // - Electronics gain //
96 // The corresponding parameter can be adjusted via the various //
97 // Set-functions. If these parameters are not explicitly set, default //
98 // values are used (see Init-function). //
99 // To produce digits from a root-file with TRD-hits use the //
100 // slowDigitsCreate.C macro. //
102 ///////////////////////////////////////////////////////////////////////////////
117 #include "AliTRDhit.h"
118 #include "AliTRDdigitizer.h"
119 #include "AliTRDdataArrayI.h"
120 #include "AliTRDdataArrayF.h"
121 #include "AliTRDsegmentArray.h"
122 #include "AliTRDdigitsManager.h"
123 #include "AliTRDgeometry.h"
125 ClassImp(AliTRDdigitizer)
127 //_____________________________________________________________________________
128 AliTRDdigitizer::AliTRDdigitizer():TNamed()
131 // AliTRDdigitizer default constructor
158 fDriftVelocity = 0.0;
169 //_____________________________________________________________________________
170 AliTRDdigitizer::AliTRDdigitizer(const Text_t *name, const Text_t *title)
174 // AliTRDdigitizer default constructor
191 //_____________________________________________________________________________
192 AliTRDdigitizer::AliTRDdigitizer(const AliTRDdigitizer &d)
195 // AliTRDdigitizer copy constructor
198 ((AliTRDdigitizer &) d).Copy(*this);
202 //_____________________________________________________________________________
203 AliTRDdigitizer::~AliTRDdigitizer()
206 // AliTRDdigitizer destructor
218 if (fPRF) delete fPRF;
219 if (fTRF) delete fTRF;
223 //_____________________________________________________________________________
224 AliTRDdigitizer &AliTRDdigitizer::operator=(const AliTRDdigitizer &d)
227 // Assignment operator
230 if (this != &d) ((AliTRDdigitizer &) d).Copy(*this);
235 //_____________________________________________________________________________
236 void AliTRDdigitizer::Copy(TObject &d)
242 ((AliTRDdigitizer &) d).fInputFile = NULL;
243 ((AliTRDdigitizer &) d).fDigits = NULL;
244 ((AliTRDdigitizer &) d).fTRD = NULL;
245 ((AliTRDdigitizer &) d).fGeo = NULL;
247 ((AliTRDdigitizer &) d).fEvent = 0;
249 ((AliTRDdigitizer &) d).fGasGain = fGasGain;
250 ((AliTRDdigitizer &) d).fNoise = fNoise;
251 ((AliTRDdigitizer &) d).fChipGain = fChipGain;
252 ((AliTRDdigitizer &) d).fADCoutRange = fADCoutRange;
253 ((AliTRDdigitizer &) d).fADCinRange = fADCinRange;
254 ((AliTRDdigitizer &) d).fADCthreshold = fADCthreshold;
255 ((AliTRDdigitizer &) d).fDiffusionOn = fDiffusionOn;
256 ((AliTRDdigitizer &) d).fDiffusionT = fDiffusionT;
257 ((AliTRDdigitizer &) d).fDiffusionL = fDiffusionL;
258 ((AliTRDdigitizer &) d).fElAttachOn = fElAttachOn;
259 ((AliTRDdigitizer &) d).fElAttachProp = fElAttachProp;
260 ((AliTRDdigitizer &) d).fExBOn = fExBOn;
261 ((AliTRDdigitizer &) d).fOmegaTau = fOmegaTau;
262 ((AliTRDdigitizer &) d).fLorentzFactor = fLorentzFactor;
263 ((AliTRDdigitizer &) d).fPRFOn = fPRFOn;
264 ((AliTRDdigitizer &) d).fTRFOn = fTRFOn;
266 ((AliTRDdigitizer &) d).fCompress = fCompress;
267 ((AliTRDdigitizer &) d).fVerbose = fVerbose;
269 fPRF->Copy(*((AliTRDdigitizer &) d).fPRF);
270 fTRF->Copy(*((AliTRDdigitizer &) d).fTRF);
272 ((AliTRDdigitizer &) d).fTRFbin = fTRFbin;
273 ((AliTRDdigitizer &) d).fTRFlo = fTRFlo;
274 ((AliTRDdigitizer &) d).fTRFhi = fTRFhi;
275 ((AliTRDdigitizer &) d).fTRFwid = fTRFwid;
276 if (((AliTRDdigitizer &) d).fTRFint) delete ((AliTRDdigitizer &) d).fTRFint;
277 ((AliTRDdigitizer &) d).fTRFint = new Float_t[fTRFbin];
278 for (Int_t iBin = 0; iBin < fTRFbin; iBin++) {
279 ((AliTRDdigitizer &) d).fTRFint[iBin] = fTRFint[iBin];
284 //_____________________________________________________________________________
285 Int_t AliTRDdigitizer::Diffusion(Float_t driftlength, Float_t *xyz)
288 // Applies the diffusion smearing to the position of a single electron
291 Float_t driftSqrt = TMath::Sqrt(driftlength);
292 Float_t sigmaT = driftSqrt * fDiffusionT;
293 Float_t sigmaL = driftSqrt * fDiffusionL;
294 xyz[0] = gRandom->Gaus(xyz[0], sigmaL * fLorentzFactor);
295 xyz[1] = gRandom->Gaus(xyz[1], sigmaT * fLorentzFactor);
296 xyz[2] = gRandom->Gaus(xyz[2], sigmaT);
302 //_____________________________________________________________________________
303 Int_t AliTRDdigitizer::ExB(Float_t driftlength, Float_t *xyz)
306 // Applies E x B effects to the position of a single electron
310 xyz[1] = xyz[1] + fOmegaTau * driftlength;
317 //_____________________________________________________________________________
318 Int_t AliTRDdigitizer::PadResponse(Float_t signal, Float_t dist, Float_t *pad)
321 // Applies the pad response
325 pad[0] = TMath::Max(fPRF->Eval(-1.0 - dist,0,0) * signal,0.0);
326 pad[1] = TMath::Max(fPRF->Eval( - dist,0,0) * signal,0.0);
327 pad[2] = TMath::Max(fPRF->Eval( 1.0 - dist,0,0) * signal,0.0);
336 //_____________________________________________________________________________
337 Float_t AliTRDdigitizer::TimeResponse(Float_t time)
340 // Applies the preamp shaper time response
343 Int_t iBin = ((Int_t) ((time - fTRFlo) / fTRFwid));
344 if ((iBin >= 0) && (iBin < fTRFbin)) {
345 return fTRFint[iBin];
353 //_____________________________________________________________________________
354 void AliTRDdigitizer::Init()
357 // Initializes the digitization procedure with standard values
360 // The default parameter for the digitization
368 // Transverse and longitudinal diffusion coefficients (Xe/Isobutane)
373 // Propability for electron attachment
379 // omega * tau. (tau ~ 12 * 10^-12, B = 0.2T)
380 fOmegaTau = 17.6 * 12.0 * 0.2 * 0.01;
382 // The pad response function
384 fPRF = new TF1("PRF","[0]*([1]+exp(-x*x/(2.0*[2])))",-3,3);
385 fPRF->SetParameter(0, 0.8872);
386 fPRF->SetParameter(1,-0.00573);
387 fPRF->SetParameter(2, 0.454 * 0.454);
389 // The drift velocity (cm / mus)
390 fDriftVelocity = 1.0;
392 // The time response function
394 Float_t loTRF = -200.0;
395 Float_t hiTRF = 1000.0;
396 fTRF = new TF1("TRF",TRFlandau,loTRF,hiTRF,3);
397 fTRF->SetParameter(0, 1.0 / 24.24249);
398 fTRF->SetParameter(1, 0.0);
399 fTRF->SetParameter(2, 25.0);
401 fTRFlo = loTRF * fDriftVelocity / 1000.0;
402 fTRFhi = hiTRF * fDriftVelocity / 1000.0;
403 fTRFwid = (fTRFhi - fTRFlo) / ((Float_t) fTRFbin);
407 //_____________________________________________________________________________
408 void AliTRDdigitizer::IntegrateTRF()
411 // Integrates the time response function over the time bin size
414 if (fTRFint) delete fTRFint;
415 fTRFint = new Float_t[fTRFbin];
416 Float_t hiTRF = fTRFhi / fDriftVelocity * 1000.0;
417 Float_t loTRF = fTRFlo / fDriftVelocity * 1000.0;
418 Float_t timeBin = fGeo->GetTimeBinSize() / fDriftVelocity * 1000.0;
419 Float_t binWidth = (hiTRF - loTRF) / ((Float_t) fTRFbin);
420 for (Int_t iBin = 0; iBin < fTRFbin; iBin++) {
421 Float_t bin = iBin * binWidth + loTRF - 0.5 * timeBin;
422 fTRFint[iBin] = fTRF->Integral(bin,bin + timeBin);
427 //_____________________________________________________________________________
428 Bool_t AliTRDdigitizer::Open(const Char_t *name, Int_t nEvent)
431 // Opens a ROOT-file with TRD-hits and reads in the hit-tree
434 // Connect the AliRoot file containing Geometry, Kine, and Hits
435 fInputFile = (TFile*) gROOT->GetListOfFiles()->FindObject(name);
437 printf("AliTRDdigitizer::Open -- ");
438 printf("Open the ALIROOT-file %s.\n",name);
439 fInputFile = new TFile(name,"UPDATE");
442 printf("AliTRDdigitizer::Open -- ");
443 printf("%s is already open.\n",name);
446 gAlice = (AliRun*) fInputFile->Get("gAlice");
448 printf("AliTRDdigitizer::Open -- ");
449 printf("AliRun object found on file.\n");
452 printf("AliTRDdigitizer::Open -- ");
453 printf("Could not find AliRun object.\n");
459 // Import the Trees for the event nEvent in the file
460 Int_t nparticles = gAlice->GetEvent(fEvent);
461 if (nparticles <= 0) {
462 printf("AliTRDdigitizer::Open -- ");
463 printf("No entries in the trees for event %d.\n",fEvent);
467 return InitDetector();
471 //_____________________________________________________________________________
472 Bool_t AliTRDdigitizer::InitDetector()
475 // Sets the pointer to the TRD detector and the geometry
478 // Get the pointer to the detector class and check for version 1
479 fTRD = (AliTRD*) gAlice->GetDetector("TRD");
480 if (fTRD->IsVersion() != 1) {
481 printf("AliTRDdigitizer::Open -- ");
482 printf("TRD must be version 1 (slow simulator).\n");
487 fGeo = fTRD->GetGeometry();
488 printf("AliTRDdigitizer::Open -- ");
489 printf("Geometry version %d\n",fGeo->IsVersion());
495 //_____________________________________________________________________________
496 Bool_t AliTRDdigitizer::MakeDigits()
499 // Loops through the TRD-hits and creates the digits.
502 ///////////////////////////////////////////////////////////////
504 ///////////////////////////////////////////////////////////////
506 // Converts number of electrons to fC
507 const Float_t kEl2fC = 1.602E-19 * 1.0E15;
509 ///////////////////////////////////////////////////////////////
511 // Number of pads included in the pad response
512 const Int_t kNpad = 3;
514 // Number of track dictionary arrays
515 const Int_t kNDict = AliTRDdigitsManager::kNDict;
517 Int_t iRow, iCol, iTime;
521 Int_t totalSizeDigits = 0;
522 Int_t totalSizeDict0 = 0;
523 Int_t totalSizeDict1 = 0;
524 Int_t totalSizeDict2 = 0;
526 AliTRDdataArrayF *signals = 0;
527 AliTRDdataArrayI *digits = 0;
528 AliTRDdataArrayI *dictionary[kNDict];
530 // Create a digits manager
531 fDigits = new AliTRDdigitsManager();
533 // Create a container for the amplitudes
534 AliTRDsegmentArray *signalsArray
535 = new AliTRDsegmentArray("AliTRDdataArrayF",AliTRDgeometry::Ndet());
538 printf("AliTRDdigitizer::MakeDigits -- ");
539 printf("No geometry defined\n");
543 printf("AliTRDdigitizer::MakeDigits -- ");
544 printf("Start creating digits.\n");
545 if (fVerbose > 0) this->Dump();
547 // The Lorentz factor
549 fLorentzFactor = 1.0 / (1.0 + fOmegaTau*fOmegaTau);
552 fLorentzFactor = 1.0;
555 // Create the integrated TRF
558 // Get the pointer to the hit tree
559 TTree *HitTree = gAlice->TreeH();
561 // Get the number of entries in the hit tree
562 // (Number of primary particles creating a hit somewhere)
563 Int_t nTrack = (Int_t) HitTree->GetEntries();
565 printf("AliTRDdigitizer::MakeDigits -- ");
566 printf("Found %d primary particles\n",nTrack);
569 Int_t detectorOld = -1;
572 // Loop through all entries in the tree
573 for (Int_t iTrack = 0; iTrack < nTrack; iTrack++) {
576 nBytes += HitTree->GetEvent(iTrack);
578 // Get the number of hits in the TRD created by this particle
579 Int_t nHit = fTRD->Hits()->GetEntriesFast();
581 printf("AliTRDdigitizer::MakeDigits -- ");
582 printf("Found %d hits for primary particle %d\n",nHit,iTrack);
585 // Loop through the TRD hits
586 for (Int_t iHit = 0; iHit < nHit; iHit++) {
590 AliTRDhit *hit = (AliTRDhit *) fTRD->Hits()->UncheckedAt(iHit);
595 Float_t q = hit->GetCharge();
596 Int_t track = hit->Track();
597 Int_t detector = hit->GetDetector();
598 Int_t plane = fGeo->GetPlane(detector);
599 Int_t sector = fGeo->GetSector(detector);
600 Int_t chamber = fGeo->GetChamber(detector);
602 if (!(CheckDetector(plane,chamber,sector))) continue;
604 Int_t nRowMax = fGeo->GetRowMax(plane,chamber,sector);
605 Int_t nColMax = fGeo->GetColMax(plane);
606 Int_t nTimeMax = fGeo->GetTimeMax();
607 Float_t row0 = fGeo->GetRow0(plane,chamber,sector);
608 Float_t col0 = fGeo->GetCol0(plane);
609 Float_t time0 = fGeo->GetTime0(plane);
610 Float_t rowPadSize = fGeo->GetRowPadSize();
611 Float_t colPadSize = fGeo->GetColPadSize();
612 Float_t timeBinSize = fGeo->GetTimeBinSize();
615 printf("Analyze hit no. %d ",iHit);
616 printf("-----------------------------------------------------------\n");
618 printf("plane = %d, sector = %d, chamber = %d\n"
619 ,plane,sector,chamber);
620 printf("nRowMax = %d, nColMax = %d, nTimeMax = %d\n"
621 ,nRowMax,nColMax,nTimeMax);
622 printf("row0 = %f, col0 = %f, time0 = %f\n"
624 printf("rowPadSize = %f, colPadSize = %f, timeBinSize = %f\n"
625 ,rowPadSize,colPadSize,timeBinSize);
628 // Don't analyze test hits with amplitude 0.
629 if (((Int_t) q) == 0) continue;
631 if (detector != detectorOld) {
633 printf("AliTRDdigitizer::MakeDigits -- ");
634 printf("Get new container. New det = %d, Old det = %d\n"
635 ,detector,detectorOld);
637 // Compress the old one if enabled
638 if ((fCompress) && (detectorOld > -1)) {
640 printf("AliTRDdigitizer::MakeDigits -- ");
641 printf("Compress the old container ... ");
643 signals->Compress(1,0);
644 for (iDict = 0; iDict < kNDict; iDict++) {
645 dictionary[iDict]->Compress(1,0);
647 if (fVerbose > 1) printf("done\n");
649 // Get the new container
650 signals = (AliTRDdataArrayF *) signalsArray->At(detector);
651 if (signals->GetNtime() == 0) {
652 // Allocate a new one if not yet existing
654 printf("AliTRDdigitizer::MakeDigits -- ");
655 printf("Allocate a new container ... ");
657 signals->Allocate(nRowMax,nColMax,nTimeMax);
660 // Expand an existing one
663 printf("AliTRDdigitizer::MakeDigits -- ");
664 printf("Expand an existing container ... ");
669 // The same for the dictionary
670 for (iDict = 0; iDict < kNDict; iDict++) {
671 dictionary[iDict] = fDigits->GetDictionary(detector,iDict);
672 if (dictionary[iDict]->GetNtime() == 0) {
673 dictionary[iDict]->Allocate(nRowMax,nColMax,nTimeMax);
676 if (fCompress) dictionary[iDict]->Expand();
679 if (fVerbose > 1) printf("done\n");
680 detectorOld = detector;
683 // Rotate the sectors on top of each other
685 fGeo->Rotate(detector,pos,rot);
688 Float_t driftlength = time0 - rot[0];
689 if ((driftlength < 0) ||
690 (driftlength > AliTRDgeometry::DrThick())) continue;
691 Float_t driftlengthL = driftlength;
692 if (fExBOn) driftlengthL /= TMath::Sqrt(fLorentzFactor);
694 // The hit position in pad coordinates (center pad)
695 // The pad row (z-direction)
696 Int_t rowH = (Int_t) ((rot[2] - row0) / rowPadSize);
697 // The pad column (rphi-direction)
698 Int_t colH = (Int_t) ((rot[1] - col0) / colPadSize);
700 Int_t timeH = (Int_t) (driftlength / timeBinSize);
702 printf("rowH = %d, colH = %d, timeH = %d\n"
706 // Loop over all electrons of this hit
707 // TR photons produce hits with negative charge
708 Int_t nEl = ((Int_t) TMath::Abs(q));
709 for (Int_t iEl = 0; iEl < nEl; iEl++) {
716 // Electron attachment
718 if (gRandom->Rndm() < (driftlengthL * fElAttachProp / 100.))
722 // Apply the diffusion smearing
724 if (!(Diffusion(driftlengthL,xyz))) continue;
727 // Apply E x B effects
729 if (!(ExB(driftlength,xyz))) continue;
732 // The electron position
733 // The pad row (z-direction)
734 Int_t rowE = (Int_t) ((xyz[2] - row0) / rowPadSize);
735 // The pad column (rphi-direction)
736 Int_t colE = (Int_t) ((xyz[1] - col0) / colPadSize);
738 Int_t timeE = (Int_t) ((time0 - xyz[0]) / timeBinSize);
740 if (( rowE < 0) || ( rowE >= nRowMax)) continue;
741 if (( colE < 0) || ( colE >= nColMax)) continue;
742 if ((timeE < 0) || (timeE >= nTimeMax)) continue;
744 // Apply the gas gain including fluctuations
745 Float_t ggRndm = 0.0;
747 ggRndm = gRandom->Rndm();
748 } while (ggRndm <= 0);
749 Int_t signal = (Int_t) (-fGasGain * TMath::Log(ggRndm));
752 printf(" electron no. %d, signal = %d\n",iEl,signal);
753 printf(" rowE = %d, colE = %d, timeE = %d\n"
757 // Apply the pad response
758 Float_t padSignal[kNpad];
760 // The distance of the electron to the center of the pad
761 // in units of pad width
762 Float_t dist = (xyz[1] - col0 - (colE + 0.5) * colPadSize)
764 if (!(PadResponse(signal,dist,padSignal))) continue;
768 padSignal[1] = signal;
772 // The distance of the position to the beginning of the timebin
773 Float_t timeOffset = (time0 - timeE * timeBinSize) - xyz[0];
774 Int_t timeTRDbeg = 0;
775 Int_t timeTRDend = 1;
780 for (Int_t iTimeBin = TMath::Max(timeE - timeTRDbeg, 0)
781 ; iTimeBin < TMath::Min(timeE + timeTRDend,nTimeMax)
784 // Apply the time response
785 Float_t timeResponse = 1.0;
787 Float_t time = (iTimeBin - timeE) * timeBinSize + timeOffset;
788 timeResponse = TimeResponse(time);
792 Float_t signalOld[kNpad] = { 0.0, 0.0, 0.0 };
793 for (Int_t iPad = 0; iPad < kNpad; iPad++) {
794 Int_t colPos = colE + iPad - 1;
795 if (colPos < 0) continue;
796 if (colPos >= nColMax) break;
797 signalOld[iPad] = signals->GetData(rowE,colPos,iTimeBin);
798 signalOld[iPad] += padSignal[iPad] * timeResponse;
799 signals->SetData(rowE,colPos,iTimeBin,signalOld[iPad]);
802 printf(" iTimeBin = %d, timeResponse = %f\n"
803 ,iTimeBin,timeResponse);
804 printf(" pad-signal = %f, %f, %f\n"
805 ,signalOld[0],signalOld[1],signalOld[2]);
808 // Store the track index in the dictionary
809 // Note: We store index+1 in order to allow the array to be compressed
810 for (iDict = 0; iDict < kNDict; iDict++) {
811 Int_t oldTrack = dictionary[iDict]->GetData(rowE,colE,timeE);
812 if (oldTrack == track+1) break;
813 //if (oldTrack == -1) break;
815 dictionary[iDict]->SetData(rowE,colE,timeE,track+1);
817 printf(" track index = %d\n",track);
822 if ((fVerbose > 1) && (iDict == kNDict)) {
823 printf("AliTRDdigitizer::MakeDigits -- ");
824 printf("More than three tracks for one digit!\n");
833 } // All hits finished
835 printf("AliTRDdigitizer::MakeDigits -- ");
836 printf("Finished analyzing %d hits\n",countHits);
838 // Loop through all chambers to finalize the digits
839 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) {
841 Int_t plane = fGeo->GetPlane(iDet);
842 Int_t sector = fGeo->GetSector(iDet);
843 Int_t chamber = fGeo->GetChamber(iDet);
844 Int_t nRowMax = fGeo->GetRowMax(plane,chamber,sector);
845 Int_t nColMax = fGeo->GetColMax(plane);
846 Int_t nTimeMax = fGeo->GetTimeMax();
848 //if (!(CheckDetector(plane,chamber,sector))) continue;
850 printf("AliTRDdigitizer::MakeDigits -- ");
851 printf("Digitization for chamber %d\n",iDet);
854 // Add a container for the digits of this detector
855 digits = fDigits->GetDigits(iDet);
856 // Allocate memory space for the digits buffer
857 digits->Allocate(nRowMax,nColMax,nTimeMax);
859 // Get the signal container
860 signals = (AliTRDdataArrayF *) signalsArray->At(iDet);
861 if (signals->GetNtime() == 0) {
862 // Create missing containers
863 signals->Allocate(nRowMax,nColMax,nTimeMax);
866 // Expand the container if neccessary
867 if (fCompress) signals->Expand();
869 // Create the missing dictionary containers
870 for (iDict = 0; iDict < kNDict; iDict++) {
871 dictionary[iDict] = fDigits->GetDictionary(iDet,iDict);
872 if (dictionary[iDict]->GetNtime() == 0) {
873 dictionary[iDict]->Allocate(nRowMax,nColMax,nTimeMax);
879 // Create the digits for this chamber
880 for (iRow = 0; iRow < nRowMax; iRow++ ) {
881 for (iCol = 0; iCol < nColMax; iCol++ ) {
882 for (iTime = 0; iTime < nTimeMax; iTime++) {
884 Float_t signalAmp = signals->GetData(iRow,iCol,iTime);
887 signalAmp = TMath::Max((Double_t) gRandom->Gaus(signalAmp,fNoise),0.0);
891 signalAmp *= fChipGain;
892 // Convert to ADC counts. Set the overflow-bit fADCoutRange if the
893 // signal is larger than fADCinRange
895 if (signalAmp >= fADCinRange) {
896 adc = ((Int_t) fADCoutRange);
899 adc = ((Int_t) (signalAmp * (fADCoutRange / fADCinRange)));
902 // Store the amplitude of the digit if above threshold
903 if (adc > fADCthreshold) {
905 printf(" iRow = %d, iCol = %d, iTime = %d\n"
907 printf(" signal = %f, adc = %d\n",signalAmp,adc);
910 digits->SetData(iRow,iCol,iTime,adc);
917 // Compress the arrays
918 digits->Compress(1,0);
919 for (iDict = 0; iDict < kNDict; iDict++) {
920 dictionary[iDict]->Compress(1,0);
923 totalSizeDigits += digits->GetSize();
924 totalSizeDict0 += dictionary[0]->GetSize();
925 totalSizeDict1 += dictionary[1]->GetSize();
926 totalSizeDict2 += dictionary[2]->GetSize();
928 Float_t nPixel = nRowMax * nColMax * nTimeMax;
929 printf("AliTRDdigitizer::MakeDigits -- ");
930 printf("Found %d digits in detector %d (%3.0f).\n"
932 ,100.0 * ((Float_t) nDigits) / nPixel);
934 if (fCompress) signals->Compress(1,0);
938 printf("AliTRDdigitizer::MakeDigits -- ");
939 printf("Total number of analyzed hits = %d\n",countHits);
941 printf("AliTRDdigitizer::MakeDigits -- ");
942 printf("Total digits data size = %d, %d, %d, %d\n",totalSizeDigits
951 //_____________________________________________________________________________
952 Bool_t AliTRDdigitizer::CheckDetector(Int_t plane, Int_t chamber, Int_t sector)
955 // Checks whether a detector is enabled
958 if ((fTRD->GetSensChamber() >= 0) &&
959 (fTRD->GetSensChamber() != chamber)) return kFALSE;
960 if ((fTRD->GetSensPlane() >= 0) &&
961 (fTRD->GetSensPlane() != plane)) return kFALSE;
962 if ( fTRD->GetSensSector() >= 0) {
963 Int_t sens1 = fTRD->GetSensSector();
964 Int_t sens2 = sens1 + fTRD->GetSensSectorRange();
965 sens2 -= ((Int_t) (sens2 / AliTRDgeometry::Nsect()))
966 * AliTRDgeometry::Nsect();
968 if ((sector < sens1) || (sector >= sens2)) return kFALSE;
971 if ((sector < sens1) && (sector >= sens2)) return kFALSE;
979 //_____________________________________________________________________________
980 Bool_t AliTRDdigitizer::WriteDigits()
983 // Writes out the TRD-digits and the dictionaries
986 // Create the branches
987 if (!(gAlice->TreeD()->GetBranch("TRDdigits"))) {
988 if (!fDigits->MakeBranch()) return kFALSE;
991 // Store the digits and the dictionary in the tree
992 fDigits->WriteDigits();
994 // Write the new tree into the input file (use overwrite option)
996 sprintf(treeName,"TreeD%d",fEvent);
997 printf("AliTRDdigitizer::WriteDigits -- ");
998 printf("Write the digits tree %s for event %d.\n"
1000 gAlice->TreeD()->Write(treeName,2);
1006 //_____________________________________________________________________________
1007 void AliTRDdigitizer::SetPRF(TF1 *prf)
1010 // Defines a new pad response function
1013 if (fPRF) delete fPRF;
1018 //_____________________________________________________________________________
1019 void AliTRDdigitizer::SetTRF(TF1 *trf)
1022 // Defines a new time response function
1025 if (fTRF) delete fTRF;
1030 //_____________________________________________________________________________
1031 Double_t TRFlandau(Double_t *x, Double_t *par)
1035 Double_t landau = par[0] * TMath::Landau(xx,par[1],par[2]);