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.9 2000/10/02 21:28:19 fca
19 Removal of useless dependecies via forward declarations
21 Revision 1.8 2000/06/09 11:10:07 cblume
22 Compiler warnings and coding conventions, next round
24 Revision 1.7 2000/06/08 18:32:58 cblume
25 Make code compliant to coding conventions
27 Revision 1.6 2000/06/07 16:27:32 cblume
28 Try to remove compiler warnings on Sun and HP
30 Revision 1.5 2000/05/09 16:38:57 cblume
31 Removed PadResponse(). Merge problem
33 Revision 1.4 2000/05/08 15:53:45 cblume
34 Resolved merge conflict
36 Revision 1.3 2000/04/28 14:49:27 cblume
37 Only one declaration of iDict in MakeDigits()
39 Revision 1.1.4.1 2000/05/08 14:42:04 cblume
40 Introduced AliTRDdigitsManager
42 Revision 1.1 2000/02/28 19:00:13 cblume
47 ///////////////////////////////////////////////////////////////////////////////
49 // Creates and handles digits from TRD hits //
51 // The following effects are included: //
54 // - Gas gain including fluctuations //
55 // - Pad-response (simple Gaussian approximation) //
56 // - Electronics noise //
57 // - Electronics gain //
60 // The corresponding parameter can be adjusted via the various //
61 // Set-functions. If these parameters are not explicitly set, default //
62 // values are used (see Init-function). //
63 // To produce digits from a root-file with TRD-hits use the //
64 // slowDigitsCreate.C macro. //
66 ///////////////////////////////////////////////////////////////////////////////
77 #include "AliTRDdigitizer.h"
78 #include "AliTRDdataArrayI.h"
79 #include "AliTRDdataArrayF.h"
80 #include "AliTRDdigitsManager.h"
82 ClassImp(AliTRDdigitizer)
84 //_____________________________________________________________________________
85 AliTRDdigitizer::AliTRDdigitizer():TNamed()
88 // AliTRDdigitizer default constructor
114 //_____________________________________________________________________________
115 AliTRDdigitizer::AliTRDdigitizer(const Text_t *name, const Text_t *title)
119 // AliTRDdigitizer default constructor
133 //_____________________________________________________________________________
134 AliTRDdigitizer::AliTRDdigitizer(const AliTRDdigitizer &d)
137 // AliTRDdigitizer copy constructor
140 ((AliTRDdigitizer &) d).Copy(*this);
144 //_____________________________________________________________________________
145 AliTRDdigitizer::~AliTRDdigitizer()
148 // AliTRDdigitizer destructor
160 if (fPRF) delete fPRF;
164 //_____________________________________________________________________________
165 AliTRDdigitizer &AliTRDdigitizer::operator=(const AliTRDdigitizer &d)
168 // Assignment operator
171 if (this != &d) ((AliTRDdigitizer &) d).Copy(*this);
176 //_____________________________________________________________________________
177 void AliTRDdigitizer::Copy(TObject &d)
183 ((AliTRDdigitizer &) d).fInputFile = NULL;
184 ((AliTRDdigitizer &) d).fDigits = NULL;
185 ((AliTRDdigitizer &) d).fTRD = NULL;
186 ((AliTRDdigitizer &) d).fGeo = NULL;
188 ((AliTRDdigitizer &) d).fEvent = 0;
190 ((AliTRDdigitizer &) d).fGasGain = fGasGain;
191 ((AliTRDdigitizer &) d).fNoise = fNoise;
192 ((AliTRDdigitizer &) d).fChipGain = fChipGain;
193 ((AliTRDdigitizer &) d).fADCoutRange = fADCoutRange;
194 ((AliTRDdigitizer &) d).fADCinRange = fADCinRange;
195 ((AliTRDdigitizer &) d).fADCthreshold = fADCthreshold;
196 ((AliTRDdigitizer &) d).fDiffusionOn = fDiffusionOn;
197 ((AliTRDdigitizer &) d).fDiffusionT = fDiffusionT;
198 ((AliTRDdigitizer &) d).fDiffusionL = fDiffusionL;
199 ((AliTRDdigitizer &) d).fElAttachOn = fElAttachOn;
200 ((AliTRDdigitizer &) d).fElAttachProp = fElAttachProp;
201 ((AliTRDdigitizer &) d).fExBOn = fExBOn;
202 ((AliTRDdigitizer &) d).fLorentzAngle = fLorentzAngle;
203 ((AliTRDdigitizer &) d).fLorentzFactor = fLorentzFactor;
205 fPRF->Copy(*((AliTRDdigitizer &) d).fPRF);
209 //_____________________________________________________________________________
210 Int_t AliTRDdigitizer::Diffusion(Float_t driftlength, Float_t *xyz)
213 // Applies the diffusion smearing to the position of a single electron
216 Float_t driftSqrt = TMath::Sqrt(driftlength);
217 Float_t sigmaT = driftSqrt * fDiffusionT;
218 Float_t sigmaL = driftSqrt * fDiffusionL;
219 xyz[0] = gRandom->Gaus(xyz[0], sigmaL * fLorentzFactor);
220 xyz[1] = gRandom->Gaus(xyz[1], sigmaT * fLorentzFactor);
221 xyz[2] = gRandom->Gaus(xyz[2], sigmaT);
226 //_____________________________________________________________________________
227 Int_t AliTRDdigitizer::ExB(Float_t driftlength, Float_t *xyz)
230 // Applies E x B effects to the position of a single electron
234 xyz[1] = xyz[1] + fLorentzAngle * driftlength;
241 //_____________________________________________________________________________
242 void AliTRDdigitizer::Init()
245 // Initializes the digitization procedure with standard values
248 // The default parameter for the digitization
256 // Transverse and longitudinal diffusion coefficients (Xe/Isobutane)
261 // Propability for electron attachment
267 // omega * tau. (tau ~ 12 * 10^-12, B = 0.2T)
268 fLorentzAngle = 17.6 * 12.0 * 0.2 * 0.01;
270 // The pad response function
271 fPRF = new TF1("PRF","[0]*([1]+exp(-x*x/(2.0*[2])))",-2,2);
272 fPRF->SetParameter(0, 0.8872);
273 fPRF->SetParameter(1,-0.00573);
274 fPRF->SetParameter(2, 0.454 * 0.454);
278 //_____________________________________________________________________________
279 Bool_t AliTRDdigitizer::Open(const Char_t *name, Int_t nEvent)
282 // Opens a ROOT-file with TRD-hits and reads in the hit-tree
285 // Connect the AliRoot file containing Geometry, Kine, and Hits
286 fInputFile = (TFile*) gROOT->GetListOfFiles()->FindObject(name);
288 printf("AliTRDdigitizer::Open -- ");
289 printf("Open the ALIROOT-file %s.\n",name);
290 fInputFile = new TFile(name,"UPDATE");
293 printf("AliTRDdigitizer::Open -- ");
294 printf("%s is already open.\n",name);
297 gAlice = (AliRun*) fInputFile->Get("gAlice");
299 printf("AliTRDdigitizer::Open -- ");
300 printf("AliRun object found on file.\n");
303 printf("AliTRDdigitizer::Open -- ");
304 printf("Could not find AliRun object.\n");
310 // Import the Trees for the event nEvent in the file
311 Int_t nparticles = gAlice->GetEvent(fEvent);
312 if (nparticles <= 0) {
313 printf("AliTRDdigitizer::Open -- ");
314 printf("No entries in the trees for event %d.\n",fEvent);
318 // Get the pointer to the detector class and check for version 1
319 fTRD = (AliTRD*) gAlice->GetDetector("TRD");
320 if (fTRD->IsVersion() != 1) {
321 printf("AliTRDdigitizer::Open -- ");
322 printf("TRD must be version 1 (slow simulator).\n");
327 fGeo = fTRD->GetGeometry();
328 printf("AliTRDdigitizer::Open -- ");
329 printf("Geometry version %d\n",fGeo->IsVersion());
335 //_____________________________________________________________________________
336 Bool_t AliTRDdigitizer::MakeDigits()
339 // Loops through the TRD-hits and creates the digits.
342 ///////////////////////////////////////////////////////////////
344 ///////////////////////////////////////////////////////////////
346 // Converts number of electrons to fC
347 const Float_t kEl2fC = 1.602E-19 * 1.0E15;
349 ///////////////////////////////////////////////////////////////
351 Int_t iRow, iCol, iTime;
355 Int_t totalSizeDigits = 0;
356 Int_t totalSizeDict0 = 0;
357 Int_t totalSizeDict1 = 0;
358 Int_t totalSizeDict2 = 0;
360 AliTRDdataArrayI *digits;
361 AliTRDdataArrayI *dictionary[kNDict];
364 printf("AliTRDdigitizer::MakeDigits -- ");
365 printf("No geometry defined\n");
369 // Create a digits manager
370 fDigits = new AliTRDdigitsManager();
372 // Create detector arrays to keep the signal and track numbers
373 AliTRDdataArrayF *signal = new AliTRDdataArrayF();
374 AliTRDdataArrayI *tracks[kNDict];
375 for (iDict = 0; iDict < kNDict; iDict++) {
376 tracks[iDict] = new AliTRDdataArrayI();
379 // Get the pointer to the hit tree
380 TTree *hitTree = gAlice->TreeH();
382 // Get the number of entries in the hit tree
383 // (Number of primary particles creating a hit somewhere)
384 Int_t nTrack = (Int_t) hitTree->GetEntries();
386 printf("AliTRDdigitizer::MakeDigits -- ");
387 printf("Start creating digits.\n");
389 // The Lorentz factor
391 fLorentzFactor = 1.0 / (1.0 + fLorentzAngle*fLorentzAngle);
394 fLorentzFactor = 1.0;
398 Int_t chamEnd = kNcham;
399 if (fTRD->GetSensChamber() >= 0) {
400 chamBeg = fTRD->GetSensChamber();
401 chamEnd = chamBeg + 1;
404 Int_t planEnd = kNplan;
405 if (fTRD->GetSensPlane() >= 0) {
406 planBeg = fTRD->GetSensPlane();
407 planEnd = planBeg + 1;
410 Int_t sectEnd = kNsect;
414 // Loop through all the chambers
415 for (Int_t iCham = chamBeg; iCham < chamEnd; iCham++) {
416 for (Int_t iPlan = planBeg; iPlan < planEnd; iPlan++) {
417 for (Int_t iSect = sectBeg; iSect < sectEnd; iSect++) {
419 if (fTRD->GetSensSector() >= 0) {
420 Int_t sens1 = fTRD->GetSensSector();
421 Int_t sens2 = sens1 + fTRD->GetSensSectorRange();
422 sens2 -= ((Int_t) (sens2 / kNsect)) * kNsect;
424 if ((iSect < sens1) || (iSect >= sens2)) continue;
427 if ((iSect < sens1) && (iSect >= sens2)) continue;
433 printf("AliTRDdigitizer::MakeDigits -- ");
434 printf("Digitizing chamber %d, plane %d, sector %d.\n"
437 Int_t iDet = fGeo->GetDetector(iPlan,iCham,iSect);
438 Int_t nRowMax = fGeo->GetRowMax(iPlan,iCham,iSect);
439 Int_t nColMax = fGeo->GetColMax(iPlan);
440 Int_t nTimeMax = fGeo->GetTimeMax();
441 Float_t row0 = fGeo->GetRow0(iPlan,iCham,iSect);
442 Float_t col0 = fGeo->GetCol0(iPlan);
443 Float_t time0 = fGeo->GetTime0(iPlan);
444 Float_t rowPadSize = fGeo->GetRowPadSize();
445 Float_t colPadSize = fGeo->GetColPadSize();
446 Float_t timeBinSize = fGeo->GetTimeBinSize();
448 // Adjust the size of the detector arrays
449 signal->Allocate(nRowMax,nColMax,nTimeMax);
450 for (iDict = 0; iDict < kNDict; iDict++) {
451 tracks[iDict]->Allocate(nRowMax,nColMax,nTimeMax);
454 // Loop through all entries in the tree
455 for (Int_t iTrack = 0; iTrack < nTrack; iTrack++) {
458 nBytes += hitTree->GetEvent(iTrack);
460 // Get the number of hits in the TRD created by this particle
461 Int_t nHit = fTRD->Hits()->GetEntriesFast();
463 // Loop through the TRD hits
464 for (Int_t iHit = 0; iHit < nHit; iHit++) {
468 AliTRDhit *hit = (AliTRDhit *) fTRD->Hits()->UncheckedAt(iHit);
473 Float_t q = hit->GetCharge();
474 Int_t track = hit->Track();
475 Int_t detector = hit->GetDetector();
476 Int_t plane = fGeo->GetPlane(detector);
477 Int_t sector = fGeo->GetSector(detector);
478 Int_t chamber = fGeo->GetChamber(detector);
480 if ((sector != iSect) ||
485 // Rotate the sectors on top of each other
487 fGeo->Rotate(detector,pos,rot);
489 // The hit position in pad coordinates (center pad)
490 // The pad row (z-direction)
491 Int_t rowH = (Int_t) ((rot[2] - row0) / rowPadSize);
492 // The pad column (rphi-direction)
493 Int_t colH = (Int_t) ((rot[1] - col0) / colPadSize);
495 Int_t timeH = (Int_t) ((rot[0] - time0) / timeBinSize);
497 // Array to sum up the signal in a box surrounding the
499 const Int_t kTimeBox = 7;
500 const Int_t kColBox = 9;
501 const Int_t kRowBox = 7;
502 Float_t signalSum[kRowBox][kColBox][kTimeBox];
503 for (iRow = 0; iRow < kRowBox; iRow++ ) {
504 for (iCol = 0; iCol < kColBox; iCol++ ) {
505 for (iTime = 0; iTime < kTimeBox; iTime++) {
506 signalSum[iRow][iCol][iTime] = 0;
511 // Loop over all electrons of this hit
512 Int_t nEl = (Int_t) q;
513 for (Int_t iEl = 0; iEl < nEl; iEl++) {
516 Float_t driftlength = rot[0] - time0;
517 if ((driftlength < 0) ||
518 (driftlength > kDrThick)) break;
519 Float_t driftlengthL = driftlength;
520 if (fExBOn) driftlengthL /= TMath::Sqrt(fLorentzFactor);
526 // Electron attachment
528 if (gRandom->Rndm() < (driftlengthL * fElAttachProp / 100.)) continue;
531 // Apply the diffusion smearing
533 if (!(Diffusion(driftlengthL,xyz))) continue;
536 // Apply E x B effects
538 if (!(ExB(driftlength,xyz))) continue;
541 // The electron position and the distance to the hit position
543 // The pad row (z-direction)
544 Int_t rowE = (Int_t) ((xyz[2] - row0) / rowPadSize);
545 Int_t rowD = rowH - rowE;
546 // The pad column (rphi-direction)
547 Int_t colE = (Int_t) ((xyz[1] - col0) / colPadSize);
548 Int_t colD = colH - colE;
550 Int_t timeE = (Int_t) ((xyz[0] - time0) / timeBinSize);
551 Int_t timeD = timeH - timeE;
553 // Apply the gas gain including fluctuations
554 Int_t signal = (Int_t) (-fGasGain * TMath::Log(gRandom->Rndm()));
556 // The distance of the electron to the center of the pad
557 // in units of pad width
558 Float_t dist = (xyz[1] - col0 - (colE + 0.5) * colPadSize)
561 // Sum up the signal in the different pixels
562 // and apply the pad response
563 Int_t rowIdx = rowD + (Int_t) ( kRowBox / 2);
564 Int_t colIdx = colD + (Int_t) ( kColBox / 2);
565 Int_t timeIdx = timeD + (Int_t) (kTimeBox / 2);
567 if (( rowIdx < 0) || ( rowIdx > kRowBox)) {
568 printf("AliTRDdigitizer::MakeDigits -- ");
569 printf("Boundary error. rowIdx = %d (%d)\n", rowIdx, kRowBox);
572 if (( colIdx < 0) || ( colIdx > kColBox)) {
573 printf("AliTRDdigitizer::MakeDigits -- ");
574 printf("Boundary error. colIdx = %d (%d)\n", colIdx, kColBox);
577 if ((timeIdx < 0) || (timeIdx > kTimeBox)) {
578 printf("AliTRDdigitizer::MakeDigits -- ");
579 printf("Boundary error. timeIdx = %d (%d)\n",timeIdx,kTimeBox);
582 signalSum[rowIdx][colIdx-1][timeIdx] += fPRF->Eval(dist-1.0,0,0) * signal;
583 signalSum[rowIdx][colIdx ][timeIdx] += fPRF->Eval(dist ,0,0) * signal;
584 signalSum[rowIdx][colIdx+1][timeIdx] += fPRF->Eval(dist+1.0,0,0) * signal;
588 // Add the padcluster to the detector matrix
589 for (iRow = 0; iRow < kRowBox; iRow++ ) {
590 for (iCol = 0; iCol < kColBox; iCol++ ) {
591 for (iTime = 0; iTime < kTimeBox; iTime++) {
593 Int_t rowB = rowH + iRow - (Int_t) ( kRowBox / 2);
594 Int_t colB = colH + iCol - (Int_t) ( kColBox / 2);
595 Int_t timeB = timeH + iTime - (Int_t) (kTimeBox / 2);
596 Float_t signalB = signalSum[iRow][iCol][iTime];
597 if (( rowB < 0) || ( rowB >= nRowMax)) continue;
598 if (( colB < 0) || ( colB >= nColMax)) continue;
599 if ((timeB < 0) || (timeB >= nTimeMax)) continue;
602 // Add the signal sum
603 signalB += signal->GetData(rowB,colB,timeB);
604 signal->SetData(rowB,colB,timeB,signalB);
605 // Store the track index in the dictionary
606 // Note: We store index+1 in order to allow the array to be compressed
607 for (iDict = 0; iDict < kNDict; iDict++) {
608 Int_t oldTrack = tracks[iDict]->GetData(rowB,colB,timeB);
609 if (oldTrack == track+1) break;
610 if (oldTrack == -1) break;
612 tracks[iDict]->SetData(rowB,colB,timeB,track+1);
616 if (iDict == kNDict) {
617 printf("AliTRDdigitizer::MakeDigits -- ");
618 printf("More than three tracks for one digit!\n");
630 // Add a container for the digits of this detector
631 digits = fDigits->GetDigits(iDet);
632 // Allocate memory space for the digits buffer
633 digits->Allocate(nRowMax,nColMax,nTimeMax);
635 // Do the same for the dictionary arrays
636 for (iDict = 0; iDict < kNDict; iDict++) {
637 dictionary[iDict] = fDigits->GetDictionary(iDet,iDict);
638 dictionary[iDict]->Allocate(nRowMax,nColMax,nTimeMax);
641 // Create the digits for this chamber
642 for (iRow = 0; iRow < nRowMax; iRow++ ) {
643 for (iCol = 0; iCol < nColMax; iCol++ ) {
644 for (iTime = 0; iTime < nTimeMax; iTime++) {
646 Float_t signalAmp = signal->GetData(iRow,iCol,iTime);
649 signalAmp = TMath::Max((Float_t) gRandom->Gaus(signalAmp,fNoise)
654 signalAmp *= fChipGain;
655 // Convert to ADC counts
656 Int_t adc = (Int_t) (signalAmp * (fADCoutRange / fADCinRange));
658 if (adc > fADCthreshold) {
662 // Store the amplitude of the digit
663 digits->SetData(iRow,iCol,iTime,adc);
665 // Store the track index in the dictionary
666 // Note: We store index+1 in order to allow the array to be compressed
667 for (iDict = 0; iDict < kNDict; iDict++) {
668 dictionary[iDict]->SetData(iRow,iCol,iTime
669 ,tracks[iDict]->GetData(iRow,iCol,iTime));
678 // Compress the arrays
679 digits->Compress(1,0);
680 for (iDict = 0; iDict < kNDict; iDict++) {
681 dictionary[iDict]->Compress(1,0);
684 totalSizeDigits += digits->GetSize();
685 totalSizeDict0 += dictionary[0]->GetSize();
686 totalSizeDict1 += dictionary[1]->GetSize();
687 totalSizeDict2 += dictionary[2]->GetSize();
689 printf("AliTRDdigitizer::MakeDigits -- ");
690 printf("Number of digits found: %d.\n",nDigits);
694 for (iDict = 0; iDict < kNDict; iDict++) {
695 tracks[iDict]->Reset();
702 printf("AliTRDdigitizer::MakeDigits -- ");
703 printf("Total number of analyzed hits = %d\n",countHits);
705 printf("AliTRDdigitizer::MakeDigits -- ");
706 printf("Total digits data size = %d, %d, %d, %d\n",totalSizeDigits
715 //_____________________________________________________________________________
716 Bool_t AliTRDdigitizer::WriteDigits()
719 // Writes out the TRD-digits and the dictionaries
722 // Create the branches
723 if (!(gAlice->TreeD()->GetBranch("TRDdigits"))) {
724 if (!fDigits->MakeBranch()) return kFALSE;
727 // Store the digits and the dictionary in the tree
728 fDigits->WriteDigits();
730 // Write the new tree into the input file (use overwrite option)
732 sprintf(treeName,"TreeD%d",fEvent);
733 printf("AliTRDdigitizer::WriteDigits -- ");
734 printf("Write the digits tree %s for event %d.\n"
736 gAlice->TreeD()->Write(treeName,2);