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 ///////////////////////////////////////////////////////////////////////////////
20 // Creates and handles digits from TRD hits //
21 // Author: C. Blume (C.Blume@gsi.de) //
23 // The following effects are included: //
26 // - Gas gain including fluctuations //
27 // - Pad-response (simple Gaussian approximation) //
29 // - Electronics noise //
30 // - Electronics gain //
33 // The corresponding parameter can be adjusted via the various //
34 // Set-functions. If these parameters are not explicitly set, default //
35 // values are used (see Init-function). //
36 // As an example on how to use this class to produce digits from hits //
37 // have a look at the macro hits2digits.C //
38 // The production of summable digits is demonstrated in hits2sdigits.C //
39 // and the subsequent conversion of the s-digits into normal digits is //
40 // explained in sdigits2digits.C. //
42 ///////////////////////////////////////////////////////////////////////////////
57 #include "AliRunLoader.h"
58 #include "AliLoader.h"
59 #include "AliConfig.h"
61 #include "AliRunDigitizer.h"
62 #include "AliRunLoader.h"
63 #include "AliLoader.h"
66 #include "AliTRDhit.h"
67 #include "AliTRDdigitizer.h"
68 #include "AliTRDdataArrayI.h"
69 #include "AliTRDdataArrayF.h"
70 #include "AliTRDsegmentArray.h"
71 #include "AliTRDdigitsManager.h"
72 #include "AliTRDgeometry.h"
73 #include "AliTRDparameter.h"
75 ClassImp(AliTRDdigitizer)
77 //_____________________________________________________________________________
78 AliTRDdigitizer::AliTRDdigitizer()
81 // AliTRDdigitizer default constructor
87 fSDigitsManagerList = 0;
97 fMergeSignalOnly = kFALSE;
103 //_____________________________________________________________________________
104 AliTRDdigitizer::AliTRDdigitizer(const Text_t *name, const Text_t *title)
105 :AliDigitizer(name,title)
108 // AliTRDdigitizer constructor
113 //NewIO: These data members probably are not needed anymore
116 fSDigitsManagerList = 0;
126 fSDigitsScale = 100.; // For the summable digits
127 fMergeSignalOnly = kFALSE;
134 //_____________________________________________________________________________
135 AliTRDdigitizer::AliTRDdigitizer(AliRunDigitizer *manager
136 , const Text_t *name, const Text_t *title)
137 :AliDigitizer(manager,name,title)
140 // AliTRDdigitizer constructor
146 fSDigitsManagerList = 0;
155 fSDigitsScale = 100.; // For the summable digits
156 fMergeSignalOnly = kFALSE;
163 //_____________________________________________________________________________
164 AliTRDdigitizer::AliTRDdigitizer(AliRunDigitizer *manager)
165 :AliDigitizer(manager,"AliTRDdigitizer","TRD digitizer")
168 // AliTRDdigitizer constructor
175 fSDigitsManagerList = 0;
184 fSDigitsScale = 100.; // For the summable digits
185 fMergeSignalOnly = kFALSE;
192 //_____________________________________________________________________________
193 AliTRDdigitizer::AliTRDdigitizer(const AliTRDdigitizer &d):AliDigitizer(d)
196 // AliTRDdigitizer copy constructor
199 ((AliTRDdigitizer &) d).Copy(*this);
203 //_____________________________________________________________________________
204 AliTRDdigitizer::~AliTRDdigitizer()
207 // AliTRDdigitizer destructor
211 if (fDigitsManager) {
212 delete fDigitsManager;
216 if (fSDigitsManager) {
217 delete fSDigitsManager;
221 if (fSDigitsManagerList) {
222 delete fSDigitsManagerList;
223 fSDigitsManagerList = 0;
233 //_____________________________________________________________________________
234 AliTRDdigitizer &AliTRDdigitizer::operator=(const AliTRDdigitizer &d)
237 // Assignment operator
240 if (this != &d) ((AliTRDdigitizer &) d).Copy(*this);
245 //_____________________________________________________________________________
246 void AliTRDdigitizer::Copy(TObject &d)
252 ((AliTRDdigitizer &) d).fRunLoader = 0;
253 ((AliTRDdigitizer &) d).fDigitsManager = 0;
254 ((AliTRDdigitizer &) d).fSDigitsManager = 0;
255 ((AliTRDdigitizer &) d).fSDigitsManagerList = 0;
256 ((AliTRDdigitizer &) d).fTRD = 0;
257 ((AliTRDdigitizer &) d).fGeo = 0;
258 ((AliTRDdigitizer &) d).fPar = 0;
259 ((AliTRDdigitizer &) d).fEvent = 0;
260 ((AliTRDdigitizer &) d).fMasks = 0;
261 ((AliTRDdigitizer &) d).fCompress = fCompress;
262 ((AliTRDdigitizer &) d).fDebug = fDebug ;
263 ((AliTRDdigitizer &) d).fSDigits = fSDigits;
264 ((AliTRDdigitizer &) d).fSDigitsScale = fSDigitsScale;
265 ((AliTRDdigitizer &) d).fMergeSignalOnly = fMergeSignalOnly;
266 ((AliTRDdigitizer &) d).fSimpleSim = fSimpleSim;
267 ((AliTRDdigitizer &) d).fSimpleDet = fSimpleDet;
271 //_____________________________________________________________________________
272 void AliTRDdigitizer::Exec(Option_t* option)
275 // Executes the merging
280 AliTRDdigitsManager *sdigitsManager;
282 TString optionString = option;
283 if (optionString.Contains("deb")) {
285 if (optionString.Contains("2")) {
288 printf("<AliTRDdigitizer::Exec> ");
289 printf("Called with debug option %d\n",fDebug);
292 // The AliRoot file is already connected by the manager
298 printf("<AliTRDdigitizer::Exec> ");
299 printf("AliRun object found on file.\n");
303 inrl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
305 gAlice = inrl->GetAliRun();
308 printf("<AliTRDdigitizer::Exec> ");
309 printf("Could not find AliRun object.\n");
314 Int_t nInput = fManager->GetNinputs();
315 fMasks = new Int_t[nInput];
316 for (iInput = 0; iInput < nInput; iInput++) {
317 fMasks[iInput] = fManager->GetMask(iInput);
323 for (iInput = 0; iInput < nInput; iInput++) {
326 printf("<AliTRDdigitizer::Exec> ");
327 printf("Add input stream %d\n",iInput);
330 // check if the input tree exists
331 inrl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(iInput));
332 AliLoader* gime = inrl->GetLoader("TRDLoader");
334 TTree * treees = gime->TreeS();
337 if (gime->LoadSDigits())
339 Error("Exec","Error Occured while loading S. Digits for input %d.",iInput);
342 treees = gime->TreeS();
346 printf("<AliTRDdigitizer::Exec> ");
347 printf("Input stream %d does not exist\n",iInput);
351 // Read the s-digits via digits manager
352 sdigitsManager = new AliTRDdigitsManager();
353 sdigitsManager->SetDebug(fDebug);
354 sdigitsManager->SetSDigits(kTRUE);
356 AliRunLoader* rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(iInput));
357 AliLoader* gimme = rl->GetLoader("TRDLoader");
358 if (!gimme->TreeS()) gimme->LoadSDigits();
359 sdigitsManager->ReadDigits(gimme->TreeS());
361 // Add the s-digits to the input list
362 AddSDigitsManager(sdigitsManager);
366 // Convert the s-digits to normal digits
368 printf("<AliTRDdigitizer::Exec> ");
369 printf("Do the conversion\n");
375 printf("<AliTRDdigitizer::Exec> ");
376 printf("Write the digits\n");
379 AliRunLoader* orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
380 AliLoader* ogime = orl->GetLoader("TRDLoader");
382 fDigitsManager->MakeBranch(ogime->TreeD());
384 fDigitsManager->WriteDigits();
387 printf("<AliTRDdigitizer::Exec> ");
391 DeleteSDigitsManager();
395 //_____________________________________________________________________________
396 Bool_t AliTRDdigitizer::Open(const Char_t *file, Int_t nEvent)
399 // Opens a ROOT-file with TRD-hits and reads in the hit-tree
402 // Connect the AliRoot file containing Geometry, Kine, and Hits
404 fRunLoader = AliRunLoader::Open(file,AliConfig::fgkDefaultEventFolderName,
409 Error("Open","Can not open session for file %s.",file);
413 fRunLoader->LoadgAlice();
414 gAlice = fRunLoader->GetAliRun();
418 printf("<AliTRDdigitizer::Open> ");
419 printf("AliRun object found on file.\n");
423 printf("<AliTRDdigitizer::Open> ");
424 printf("Could not find AliRun object.\n");
430 // Import the Trees for the event nEvent in the file
431 fRunLoader->GetEvent(fEvent);
433 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
436 Error("Open","Can not get TRD loader from Run Loader");
440 if (InitDetector()) {
444 //if we produce SDigits
445 tree = loader->TreeS();
448 loader->MakeTree("S");
449 tree = loader->TreeS();
453 {//if we produce Digits
454 tree = loader->TreeD();
457 loader->MakeTree("D");
458 tree = loader->TreeD();
461 return MakeBranch(tree);
469 //_____________________________________________________________________________
470 Bool_t AliTRDdigitizer::InitDetector()
473 // Sets the pointer to the TRD detector and the geometry
476 // Get the pointer to the detector class and check for version 1
477 fTRD = (AliTRD *) gAlice->GetDetector("TRD");
479 printf("<AliTRDdigitizer::InitDetector> ");
480 printf("No TRD module found\n");
483 if (fTRD->IsVersion() != 1) {
484 printf("<AliTRDdigitizer::InitDetector> ");
485 printf("TRD must be version 1 (slow simulator).\n");
490 fGeo = fTRD->GetGeometry();
492 printf("<AliTRDdigitizer::InitDetector> ");
493 printf("Geometry version %d\n",fGeo->IsVersion());
496 // Create a digits manager
497 fDigitsManager = new AliTRDdigitsManager();
498 fDigitsManager->SetSDigits(fSDigits);
499 fDigitsManager->CreateArrays();
500 fDigitsManager->SetEvent(fEvent);
501 fDigitsManager->SetDebug(fDebug);
503 // The list for the input s-digits manager to be merged
504 fSDigitsManagerList = new TList();
510 //_____________________________________________________________________________
511 Bool_t AliTRDdigitizer::MakeBranch(TTree* tree) const
514 // Create the branches for the digits array
517 return fDigitsManager->MakeBranch(tree);
521 //_____________________________________________________________________________
522 Bool_t AliTRDdigitizer::MakeDigits()
528 ///////////////////////////////////////////////////////////////
530 ///////////////////////////////////////////////////////////////
532 // Converts number of electrons to fC
533 const Double_t kEl2fC = 1.602E-19 * 1.0E15;
535 ///////////////////////////////////////////////////////////////
537 // Number of pads included in the pad response
538 const Int_t kNpad = 3;
540 // Number of track dictionary arrays
541 const Int_t kNDict = AliTRDdigitsManager::kNDict;
543 // Half the width of the amplification region
544 const Float_t kAmWidth = AliTRDgeometry::AmThick() / 2.;
546 Int_t iRow, iCol, iTime, iPad;
550 Int_t totalSizeDigits = 0;
551 Int_t totalSizeDict0 = 0;
552 Int_t totalSizeDict1 = 0;
553 Int_t totalSizeDict2 = 0;
555 Int_t timeTRDbeg = 0;
556 Int_t timeTRDend = 1;
561 Float_t padSignal[kNpad];
562 Float_t signalOld[kNpad];
564 AliTRDdataArrayF *signals = 0;
565 AliTRDdataArrayI *digits = 0;
566 AliTRDdataArrayI *dictionary[kNDict];
568 // Create a default parameter class if none is defined
570 fPar = new AliTRDparameter("TRDparameter","Standard TRD parameter");
572 printf("<AliTRDdigitizer::MakeDigits> ");
573 printf("Create the default parameter object\n");
577 // Create a container for the amplitudes
578 AliTRDsegmentArray *signalsArray
579 = new AliTRDsegmentArray("AliTRDdataArrayF"
580 ,AliTRDgeometry::Ndet());
583 timeTRDbeg = ((Int_t) (-fPar->GetTRFlo() / fPar->GetTimeBinSize())) - 1;
584 timeTRDend = ((Int_t) ( fPar->GetTRFhi() / fPar->GetTimeBinSize())) - 1;
586 printf("<AliTRDdigitizer::MakeDigits> ");
587 printf("Sample the TRF between -%d and %d\n",timeTRDbeg,timeTRDend);
591 Float_t elAttachProp = fPar->GetElAttachProp() / 100.;
594 printf("<AliTRDdigitizer::MakeDigits> ");
595 printf("No geometry defined\n");
600 printf("<AliTRDdigitizer::MakeDigits> ");
601 printf("Start creating digits.\n");
604 AliLoader* gimme = fRunLoader->GetLoader("TRDLoader");
605 if (!gimme->TreeH()) gimme->LoadHits();
606 TTree* hitTree = gimme->TreeH();
609 Error("MakeDigits","Can not get TreeH");
612 fTRD->SetTreeAddress();
614 // Get the number of entries in the hit tree
615 // (Number of primary particles creating a hit somewhere)
618 nTrack = (Int_t) hitTree->GetEntries();
620 printf("<AliTRDdigitizer::MakeDigits> ");
621 printf("Found %d primary particles\n",nTrack);
625 Int_t detectorOld = -1;
628 // Loop through all entries in the tree
629 for (Int_t iTrack = 0; iTrack < nTrack; iTrack++) {
633 nBytes += hitTree->GetEvent(iTrack);
636 // Loop through the TRD hits
638 AliTRDhit *hit = (AliTRDhit *) fTRD->FirstHit(-1);
647 Float_t q = hit->GetCharge();
648 Int_t track = hit->Track();
649 Int_t detector = hit->GetDetector();
650 Int_t plane = fGeo->GetPlane(detector);
651 Int_t sector = fGeo->GetSector(detector);
652 Int_t chamber = fGeo->GetChamber(detector);
653 Int_t nRowMax = fPar->GetRowMax(plane,chamber,sector);
654 Int_t nColMax = fPar->GetColMax(plane);
655 Int_t nTimeMax = fPar->GetTimeMax();
656 Int_t nTimeBefore = fPar->GetTimeBefore();
657 Int_t nTimeAfter = fPar->GetTimeAfter();
658 Int_t nTimeTotal = fPar->GetTimeTotal();
659 Float_t row0 = fPar->GetRow0(plane,chamber,sector);
660 Float_t col0 = fPar->GetCol0(plane);
661 Float_t time0 = fPar->GetTime0(plane);
662 Float_t rowPadSize = fPar->GetRowPadSize(plane,chamber,sector);
663 Float_t colPadSize = fPar->GetColPadSize(plane);
664 Float_t timeBinSize = fPar->GetTimeBinSize();
665 Float_t divideRow = 1.0 / rowPadSize;
666 Float_t divideCol = 1.0 / colPadSize;
667 Float_t divideTime = 1.0 / timeBinSize;
670 printf("Analyze hit no. %d ",iHit);
671 printf("-----------------------------------------------------------\n");
673 printf("plane = %d, sector = %d, chamber = %d\n"
674 ,plane,sector,chamber);
675 printf("nRowMax = %d, nColMax = %d, nTimeMax = %d\n"
676 ,nRowMax,nColMax,nTimeMax);
677 printf("nTimeBefore = %d, nTimeAfter = %d, nTimeTotal = %d\n"
678 ,nTimeBefore,nTimeAfter,nTimeTotal);
679 printf("row0 = %f, col0 = %f, time0 = %f\n"
681 printf("rowPadSize = %f, colPadSize = %f, timeBinSize = %f\n"
682 ,rowPadSize,colPadSize,timeBinSize);
685 // Don't analyze test hits and switched off detectors
686 if ((CheckDetector(plane,chamber,sector)) &&
687 (((Int_t) q) != 0)) {
689 if (detector != detectorOld) {
692 printf("<AliTRDdigitizer::MakeDigits> ");
693 printf("Get new container. New det = %d, Old det = %d\n"
694 ,detector,detectorOld);
696 // Compress the old one if enabled
697 if ((fCompress) && (detectorOld > -1)) {
699 printf("<AliTRDdigitizer::MakeDigits> ");
700 printf("Compress the old container ...");
702 signals->Compress(1,0);
703 for (iDict = 0; iDict < kNDict; iDict++) {
704 dictionary[iDict]->Compress(1,0);
706 if (fDebug > 1) printf("done\n");
708 // Get the new container
709 signals = (AliTRDdataArrayF *) signalsArray->At(detector);
710 if (signals->GetNtime() == 0) {
711 // Allocate a new one if not yet existing
713 printf("<AliTRDdigitizer::MakeDigits> ");
714 printf("Allocate a new container ... ");
716 signals->Allocate(nRowMax,nColMax,nTimeTotal);
718 else if (fSimpleSim) {
719 // Clear an old one for the simple simulation
721 printf("<AliTRDdigitizer::MakeDigits> ");
722 printf("Clear a old container ... ");
727 // Expand an existing one
730 printf("<AliTRDdigitizer::MakeDigits> ");
731 printf("Expand an existing container ... ");
736 // The same for the dictionary
738 for (iDict = 0; iDict < kNDict; iDict++) {
739 dictionary[iDict] = fDigitsManager->GetDictionary(detector,iDict);
740 if (dictionary[iDict]->GetNtime() == 0) {
741 dictionary[iDict]->Allocate(nRowMax,nColMax,nTimeTotal);
744 if (fCompress) dictionary[iDict]->Expand();
748 if (fDebug > 1) printf("done\n");
749 detectorOld = detector;
752 // Rotate the sectors on top of each other
759 fGeo->Rotate(detector,pos,rot);
762 // The driftlength. It is negative if the hit is in the
763 // amplification region.
764 Float_t driftlength = time0 - rot[0];
766 // Take also the drift in the amplification region into account
767 // The drift length is at the moment still the same, regardless of
768 // the position relativ to the wire. This non-isochronity needs still
769 // to be implemented.
770 Float_t driftlengthL = TMath::Abs(driftlength + kAmWidth);
771 if (fPar->ExBOn()) driftlengthL /= TMath::Sqrt(fPar->GetLorentzFactor());
773 // Loop over all electrons of this hit
774 // TR photons produce hits with negative charge
775 Int_t nEl = ((Int_t) TMath::Abs(q));
776 for (Int_t iEl = 0; iEl < nEl; iEl++) {
782 // Electron attachment
783 if (fPar->ElAttachOn()) {
784 if (gRandom->Rndm() < (driftlengthL * elAttachProp))
788 // Apply the diffusion smearing
789 if (fPar->DiffusionOn()) {
790 if (!(fPar->Diffusion(driftlengthL,xyz))) continue;
793 // Apply E x B effects (depends on drift direction)
795 if (!(fPar->ExB(driftlength+kAmWidth,xyz))) continue;
798 // The electron position after diffusion and ExB in pad coordinates
799 // The pad row (z-direction)
800 Float_t rowDist = xyz[2] - row0;
801 Int_t rowE = ((Int_t) (rowDist * divideRow));
802 if ((rowE < 0) || (rowE >= nRowMax)) continue;
803 Float_t rowOffset = ((((Float_t) rowE) + 0.5) * rowPadSize) - rowDist;
805 // The pad column (rphi-direction)
806 Float_t col0tilt = fPar->Col0Tilted(col0,rowOffset,plane);
807 Float_t colDist = xyz[1] - col0tilt;
808 Int_t colE = ((Int_t) (colDist * divideCol));
809 if ((colE < 0) || (colE >= nColMax)) continue;
810 Float_t colOffset = ((((Float_t) colE) + 0.5) * colPadSize) - colDist;
812 // The time bin (negative for hits in the amplification region)
813 // In the amplification region the electrons drift from both sides
814 // to the middle (anode wire plane)
815 Float_t timeDist = time0 - xyz[0];
816 Float_t timeOffset = 0;
820 timeE = ((Int_t) (timeDist * divideTime));
821 // The distance of the position to the middle of the timebin
822 timeOffset = ((((Float_t) timeE) + 0.5) * timeBinSize) - timeDist;
825 // Difference between half of the amplification gap width and
826 // the distance to the anode wire
827 Float_t anodeDist = kAmWidth - TMath::Abs(timeDist + kAmWidth);
829 timeE = -1 * (((Int_t ) (anodeDist * divideTime)) + 1);
830 // The distance of the position to the middle of the timebin
831 timeOffset = ((((Float_t) timeE) + 0.5) * timeBinSize) + anodeDist;
834 // Apply the gas gain including fluctuations
835 Float_t ggRndm = 0.0;
837 ggRndm = gRandom->Rndm();
838 } while (ggRndm <= 0);
839 Int_t signal = (Int_t) (-fPar->GetGasGain() * TMath::Log(ggRndm));
841 // Apply the pad response
843 // The distance of the electron to the center of the pad
844 // in units of pad width
845 Float_t dist = - colOffset * divideCol;
846 if (!(fPar->PadResponse(signal,dist,plane,padSignal))) continue;
850 padSignal[1] = signal;
854 // Sample the time response inside the drift region
855 // + additional time bins before and after.
856 // The sampling is done always in the middle of the time bin
857 for (Int_t iTimeBin = TMath::Max(timeE-timeTRDbeg, -nTimeBefore)
858 ;iTimeBin < TMath::Min(timeE+timeTRDend,nTimeMax+nTimeAfter )
861 // Apply the time response
862 Float_t timeResponse = 1.0;
863 Float_t crossTalk = 0.0;
864 Float_t time = (iTimeBin - timeE) * timeBinSize + timeOffset;
866 timeResponse = fPar->TimeResponse(time);
869 crossTalk = fPar->CrossTalk(time);
876 for (iPad = 0; iPad < kNpad; iPad++) {
878 Int_t colPos = colE + iPad - 1;
879 if (colPos < 0) continue;
880 if (colPos >= nColMax) break;
883 // Note: The time bin number is shifted by nTimeBefore to avoid negative
884 // time bins. This has to be subtracted later.
885 Int_t iCurrentTimeBin = iTimeBin + nTimeBefore;
886 signalOld[iPad] = signals->GetDataUnchecked(rowE,colPos,iCurrentTimeBin);
887 if( colPos != colE ) {
888 signalOld[iPad] += padSignal[iPad] * (timeResponse + crossTalk);
891 signalOld[iPad] += padSignal[iPad] * timeResponse;
893 signals->SetDataUnchecked(rowE,colPos,iCurrentTimeBin,signalOld[iPad]);
895 // Store the track index in the dictionary
896 // Note: We store index+1 in order to allow the array to be compressed
897 if ((signalOld[iPad] > 0) && (!fSimpleSim)) {
898 for (iDict = 0; iDict < kNDict; iDict++) {
899 Int_t oldTrack = dictionary[iDict]->GetDataUnchecked(rowE
902 if (oldTrack == track+1) break;
904 dictionary[iDict]->SetDataUnchecked(rowE,colPos,iCurrentTimeBin,track+1);
914 } // Loop: electrons of a single hit
916 } // If: detector and test hit
918 hit = (AliTRDhit *) fTRD->NextHit();
920 } // Loop: hits of one primary track
922 } // Loop: primary tracks
925 printf("<AliTRDdigitizer::MakeDigits> ");
926 printf("Finished analyzing %d hits\n",countHits);
929 // The coupling factor
930 Float_t coupling = fPar->GetPadCoupling()
931 * fPar->GetTimeCoupling();
933 // The conversion factor
934 Float_t convert = kEl2fC
935 * fPar->GetChipGain();
937 // Loop through all chambers to finalize the digits
939 Int_t iDetEnd = AliTRDgeometry::Ndet();
941 iDetBeg = fSimpleDet;
942 iDetEnd = iDetBeg + 1;
944 for (Int_t iDet = iDetBeg; iDet < iDetEnd; iDet++) {
946 Int_t plane = fGeo->GetPlane(iDet);
947 Int_t sector = fGeo->GetSector(iDet);
948 Int_t chamber = fGeo->GetChamber(iDet);
949 Int_t nRowMax = fPar->GetRowMax(plane,chamber,sector);
950 Int_t nColMax = fPar->GetColMax(plane);
951 Int_t nTimeMax = fPar->GetTimeMax();
952 Int_t nTimeTotal = fPar->GetTimeTotal();
954 Double_t *inADC = new Double_t[nTimeTotal];
955 Double_t *outADC = new Double_t[nTimeTotal];
958 printf("<AliTRDdigitizer::MakeDigits> ");
959 printf("Digitization for chamber %d\n",iDet);
962 // Add a container for the digits of this detector
963 digits = fDigitsManager->GetDigits(iDet);
964 // Allocate memory space for the digits buffer
965 if (digits->GetNtime() == 0) {
966 digits->Allocate(nRowMax,nColMax,nTimeTotal);
968 else if (fSimpleSim) {
972 // Get the signal container
973 signals = (AliTRDdataArrayF *) signalsArray->At(iDet);
974 if (signals->GetNtime() == 0) {
975 // Create missing containers
976 signals->Allocate(nRowMax,nColMax,nTimeTotal);
979 // Expand the container if neccessary
980 if (fCompress) signals->Expand();
982 // Create the missing dictionary containers
984 for (iDict = 0; iDict < kNDict; iDict++) {
985 dictionary[iDict] = fDigitsManager->GetDictionary(iDet,iDict);
986 if (dictionary[iDict]->GetNtime() == 0) {
987 dictionary[iDict]->Allocate(nRowMax,nColMax,nTimeTotal);
994 // Don't create noise in detectors that are switched off
995 if (CheckDetector(plane,chamber,sector)) {
997 // Create the digits for this chamber
998 for (iRow = 0; iRow < nRowMax; iRow++ ) {
999 for (iCol = 0; iCol < nColMax; iCol++ ) {
1001 // Create summable digits
1004 for (iTime = 0; iTime < nTimeTotal; iTime++) {
1005 Float_t signalAmp = signals->GetDataUnchecked(iRow,iCol,iTime);
1006 signalAmp *= fSDigitsScale;
1007 signalAmp = TMath::Min(signalAmp,(Float_t) 1.0e9);
1008 Int_t adc = (Int_t) signalAmp;
1009 if (adc > 0) nDigits++;
1010 digits->SetDataUnchecked(iRow,iCol,iTime,adc);
1014 // Create normal digits
1017 for (iTime = 0; iTime < nTimeTotal; iTime++) {
1018 Float_t signalAmp = signals->GetDataUnchecked(iRow,iCol,iTime);
1019 // Pad and time coupling
1020 signalAmp *= coupling;
1021 // Add the noise, starting from minus ADC baseline in electrons
1022 Double_t baselineEl = fPar->GetADCbaseline() * (fPar->GetADCinRange()
1023 / fPar->GetADCoutRange())
1025 signalAmp = TMath::Max((Double_t) gRandom->Gaus(signalAmp,fPar->GetNoise())
1028 signalAmp *= convert;
1029 // Add ADC baseline in mV
1030 signalAmp += fPar->GetADCbaseline() * (fPar->GetADCinRange()
1031 / fPar->GetADCoutRange());
1032 // Convert to ADC counts. Set the overflow-bit fADCoutRange if the
1033 // signal is larger than fADCinRange
1035 if (signalAmp >= fPar->GetADCinRange()) {
1036 adc = ((Int_t) fPar->GetADCoutRange());
1039 adc = ((Int_t) (signalAmp * (fPar->GetADCoutRange()
1040 / fPar->GetADCinRange())));
1043 outADC[iTime] = adc;
1046 // Apply the tail cancelation via the digital filter
1048 DeConvExp(inADC,outADC,nTimeTotal,fPar->GetTCnexp());
1051 for (iTime = 0; iTime < nTimeTotal; iTime++) {
1052 // Store the amplitude of the digit if above threshold
1053 if (outADC[iTime] > fPar->GetADCthreshold()) {
1055 printf(" iRow = %d, iCol = %d, iTime = %d, adc = %f\n"
1056 ,iRow,iCol,iTime,outADC[iTime]);
1059 digits->SetDataUnchecked(iRow,iCol,iTime,((Int_t) outADC[iTime]));
1070 // Compress the arrays
1072 digits->Compress(1,0);
1073 for (iDict = 0; iDict < kNDict; iDict++) {
1074 dictionary[iDict]->Compress(1,0);
1077 totalSizeDigits += digits->GetSize();
1078 totalSizeDict0 += dictionary[0]->GetSize();
1079 totalSizeDict1 += dictionary[1]->GetSize();
1080 totalSizeDict2 += dictionary[2]->GetSize();
1082 Float_t nPixel = nRowMax * nColMax * nTimeMax;
1084 printf("<AliTRDdigitizer::MakeDigits> ");
1085 printf("Found %d digits in detector %d (%3.0f).\n"
1087 ,100.0 * ((Float_t) nDigits) / nPixel);
1090 if (fCompress) signals->Compress(1,0);
1100 delete signalsArray;
1105 printf("<AliTRDdigitizer::MakeDigits> ");
1106 printf("Total number of analyzed hits = %d\n",countHits);
1108 printf("<AliTRDdigitizer::MakeDigits> ");
1109 printf("Total digits data size = %d, %d, %d, %d\n",totalSizeDigits
1120 //_____________________________________________________________________________
1121 void AliTRDdigitizer::AddSDigitsManager(AliTRDdigitsManager *man)
1124 // Add a digits manager for s-digits to the input list.
1127 fSDigitsManagerList->Add(man);
1131 //_____________________________________________________________________________
1132 void AliTRDdigitizer::DeleteSDigitsManager()
1135 // Removes digits manager from the input list.
1138 fSDigitsManagerList->Delete();
1142 //_____________________________________________________________________________
1143 Bool_t AliTRDdigitizer::ConvertSDigits()
1146 // Converts s-digits to normal digits
1149 // Number of track dictionary arrays
1150 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1152 // Converts number of electrons to fC
1153 const Double_t kEl2fC = 1.602E-19 * 1.0E15;
1161 fPar = new AliTRDparameter("TRDparameter","Standard parameter");
1163 printf("<AliTRDdigitizer::ConvertSDigits> ");
1164 printf("Create the default parameter object\n");
1168 Double_t sDigitsScale = 1.0 / GetSDigitsScale();
1169 Double_t noise = fPar->GetNoise();
1170 Double_t padCoupling = fPar->GetPadCoupling();
1171 Double_t timeCoupling = fPar->GetTimeCoupling();
1172 Double_t chipGain = fPar->GetChipGain();
1173 Double_t coupling = padCoupling * timeCoupling;
1174 Double_t convert = kEl2fC * chipGain;
1175 Double_t adcInRange = fPar->GetADCinRange();
1176 Double_t adcOutRange = fPar->GetADCoutRange();
1177 Int_t adcThreshold = fPar->GetADCthreshold();
1178 Int_t adcBaseline = fPar->GetADCbaseline();
1180 AliTRDdataArrayI *digitsIn;
1181 AliTRDdataArrayI *digitsOut;
1182 AliTRDdataArrayI *dictionaryIn[kNDict];
1183 AliTRDdataArrayI *dictionaryOut[kNDict];
1185 // Loop through the detectors
1186 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) {
1189 printf("<AliTRDdigitizer::ConvertSDigits> ");
1190 printf("Convert detector %d to digits.\n",iDet);
1193 Int_t plane = fGeo->GetPlane(iDet);
1194 Int_t sector = fGeo->GetSector(iDet);
1195 Int_t chamber = fGeo->GetChamber(iDet);
1196 Int_t nRowMax = fPar->GetRowMax(plane,chamber,sector);
1197 Int_t nColMax = fPar->GetColMax(plane);
1198 Int_t nTimeTotal = fPar->GetTimeTotal();
1200 Double_t *inADC = new Double_t[nTimeTotal];
1201 Double_t *outADC = new Double_t[nTimeTotal];
1203 digitsIn = fSDigitsManager->GetDigits(iDet);
1205 digitsOut = fDigitsManager->GetDigits(iDet);
1206 digitsOut->Allocate(nRowMax,nColMax,nTimeTotal);
1207 for (iDict = 0; iDict < kNDict; iDict++) {
1208 dictionaryIn[iDict] = fSDigitsManager->GetDictionary(iDet,iDict);
1209 dictionaryIn[iDict]->Expand();
1210 dictionaryOut[iDict] = fDigitsManager->GetDictionary(iDet,iDict);
1211 dictionaryOut[iDict]->Allocate(nRowMax,nColMax,nTimeTotal);
1214 for (iRow = 0; iRow < nRowMax; iRow++ ) {
1215 for (iCol = 0; iCol < nColMax; iCol++ ) {
1217 for (iTime = 0; iTime < nTimeTotal; iTime++) {
1218 Double_t signal = (Double_t) digitsIn->GetDataUnchecked(iRow,iCol,iTime);
1219 signal *= sDigitsScale;
1220 // Pad and time coupling
1222 // Add the noise, starting from minus ADC baseline in electrons
1223 Double_t baselineEl = adcBaseline * (adcInRange / adcOutRange) / convert;
1224 signal = TMath::Max((Double_t) gRandom->Gaus(signal,noise),-baselineEl);
1227 // add ADC baseline in mV
1228 signal += adcBaseline * (adcInRange / adcOutRange);
1229 // Convert to ADC counts. Set the overflow-bit adcOutRange if the
1230 // signal is larger than adcInRange
1232 if (signal >= adcInRange) {
1233 adc = ((Int_t) adcOutRange);
1236 adc = ((Int_t) (signal * (adcOutRange / adcInRange)));
1239 outADC[iTime] = adc;
1242 // Apply the tail cancelation via the digital filter
1244 DeConvExp(inADC,outADC,nTimeTotal,fPar->GetTCnexp());
1247 for (iTime = 0; iTime < nTimeTotal; iTime++) {
1248 // Store the amplitude of the digit if above threshold
1249 if (outADC[iTime] > adcThreshold) {
1250 digitsOut->SetDataUnchecked(iRow,iCol,iTime,((Int_t) outADC[iTime]));
1251 // Copy the dictionary
1252 for (iDict = 0; iDict < kNDict; iDict++) {
1253 Int_t track = dictionaryIn[iDict]->GetDataUnchecked(iRow,iCol,iTime);
1254 dictionaryOut[iDict]->SetDataUnchecked(iRow,iCol,iTime,track);
1263 digitsIn->Compress(1,0);
1264 digitsOut->Compress(1,0);
1265 for (iDict = 0; iDict < kNDict; iDict++) {
1266 dictionaryIn[iDict]->Compress(1,0);
1267 dictionaryOut[iDict]->Compress(1,0);
1280 //_____________________________________________________________________________
1281 Bool_t AliTRDdigitizer::MergeSDigits()
1284 // Merges the input s-digits:
1285 // - The amplitude of the different inputs are summed up.
1286 // - Of the track IDs from the input dictionaries only one is
1287 // kept for each input. This works for maximal 3 different merged inputs.
1290 // Number of track dictionary arrays
1291 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1294 fPar = new AliTRDparameter("TRDparameter","Standard parameter");
1296 printf("<AliTRDdigitizer::MergeSDigits> ");
1297 printf("Create the default parameter object\n");
1304 AliTRDdataArrayI *digitsA;
1305 AliTRDdataArrayI *digitsB;
1306 AliTRDdataArrayI *dictionaryA[kNDict];
1307 AliTRDdataArrayI *dictionaryB[kNDict];
1309 // Get the first s-digits
1310 fSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->First();
1311 if (!fSDigitsManager) return kFALSE;
1313 // Loop through the other sets of s-digits
1314 AliTRDdigitsManager *mergeSDigitsManager;
1315 mergeSDigitsManager = (AliTRDdigitsManager *)
1316 fSDigitsManagerList->After(fSDigitsManager);
1319 if (mergeSDigitsManager) {
1320 printf("<AliTRDdigitizer::MergeSDigits> ");
1321 printf("Merge %d input files.\n",fSDigitsManagerList->GetSize());
1324 printf("<AliTRDdigitizer::MergeSDigits> ");
1325 printf("Only one input file.\n");
1330 while (mergeSDigitsManager) {
1334 // Loop through the detectors
1335 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) {
1337 Int_t plane = fGeo->GetPlane(iDet);
1338 Int_t sector = fGeo->GetSector(iDet);
1339 Int_t chamber = fGeo->GetChamber(iDet);
1340 Int_t nRowMax = fPar->GetRowMax(plane,chamber,sector);
1341 Int_t nColMax = fPar->GetColMax(plane);
1342 Int_t nTimeTotal = fPar->GetTimeTotal();
1344 // Loop through the pixels of one detector and add the signals
1345 digitsA = fSDigitsManager->GetDigits(iDet);
1346 digitsB = mergeSDigitsManager->GetDigits(iDet);
1349 for (iDict = 0; iDict < kNDict; iDict++) {
1350 dictionaryA[iDict] = fSDigitsManager->GetDictionary(iDet,iDict);
1351 dictionaryB[iDict] = mergeSDigitsManager->GetDictionary(iDet,iDict);
1352 dictionaryA[iDict]->Expand();
1353 dictionaryB[iDict]->Expand();
1356 // Merge only detectors that contain a signal
1357 Bool_t doMerge = kTRUE;
1358 if (fMergeSignalOnly) {
1359 if (digitsA->GetOverThreshold(0) == 0) {
1367 printf("<AliTRDdigitizer::MergeSDigits> ");
1368 printf("Merge detector %d of input no.%d\n",iDet,iMerge+1);
1371 for (Int_t iRow = 0; iRow < nRowMax; iRow++ ) {
1372 for (Int_t iCol = 0; iCol < nColMax; iCol++ ) {
1373 for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
1375 // Add the amplitudes of the summable digits
1376 Int_t ampA = digitsA->GetDataUnchecked(iRow,iCol,iTime);
1377 Int_t ampB = digitsB->GetDataUnchecked(iRow,iCol,iTime);
1379 digitsA->SetDataUnchecked(iRow,iCol,iTime,ampA);
1381 // Add the mask to the track id if defined.
1382 for (iDict = 0; iDict < kNDict; iDict++) {
1383 Int_t trackB = dictionaryB[iDict]->GetDataUnchecked(iRow,iCol,iTime);
1384 if ((fMasks) && (trackB > 0)) {
1385 for (jDict = 0; jDict < kNDict; jDict++) {
1386 Int_t trackA = dictionaryA[iDict]->GetDataUnchecked(iRow,iCol,iTime);
1388 trackA = trackB + fMasks[iMerge];
1389 dictionaryA[iDict]->SetDataUnchecked(iRow,iCol,iTime,trackA);
1402 digitsA->Compress(1,0);
1403 digitsB->Compress(1,0);
1404 for (iDict = 0; iDict < kNDict; iDict++) {
1405 dictionaryA[iDict]->Compress(1,0);
1406 dictionaryB[iDict]->Compress(1,0);
1412 // The next set of s-digits
1413 mergeSDigitsManager = (AliTRDdigitsManager *)
1414 fSDigitsManagerList->After(mergeSDigitsManager);
1422 //_____________________________________________________________________________
1423 Bool_t AliTRDdigitizer::SDigits2Digits()
1426 // Merges the input s-digits and converts them to normal digits
1429 if (!MergeSDigits()) return kFALSE;
1431 return ConvertSDigits();
1435 //_____________________________________________________________________________
1436 Bool_t AliTRDdigitizer::CheckDetector(Int_t plane, Int_t chamber, Int_t sector)
1439 // Checks whether a detector is enabled
1442 if (fSimpleSim) return kTRUE;
1444 if ((fTRD->GetSensChamber() >= 0) &&
1445 (fTRD->GetSensChamber() != chamber)) return kFALSE;
1446 if ((fTRD->GetSensPlane() >= 0) &&
1447 (fTRD->GetSensPlane() != plane)) return kFALSE;
1448 if ( fTRD->GetSensSector() >= 0) {
1449 Int_t sens1 = fTRD->GetSensSector();
1450 Int_t sens2 = sens1 + fTRD->GetSensSectorRange();
1451 sens2 -= ((Int_t) (sens2 / AliTRDgeometry::Nsect()))
1452 * AliTRDgeometry::Nsect();
1453 if (sens1 < sens2) {
1454 if ((sector < sens1) || (sector >= sens2)) return kFALSE;
1457 if ((sector < sens1) && (sector >= sens2)) return kFALSE;
1465 //_____________________________________________________________________________
1466 Bool_t AliTRDdigitizer::WriteDigits() const
1469 // Writes out the TRD-digits and the dictionaries
1472 // Store the digits and the dictionary in the tree
1473 return fDigitsManager->WriteDigits();
1477 //_____________________________________________________________________________
1478 void AliTRDdigitizer::DeConvExp(Double_t *source, Double_t *target
1479 , Int_t n, Int_t nexp)
1482 // Does the deconvolution by the digital filter.
1484 // Author: Marcus Gutfleisch, KIP Heidelberg
1485 // Optimized for: New TRF from Venelin Angelov, simulated with CADENCE
1486 // Pad-ground capacitance = 25 pF
1487 // Pad-pad cross talk capacitance = 6 pF
1488 // For 10 MHz digitization, corresponding to 20 time bins
1489 // in the drift region
1493 Double_t coefficients[2];
1495 /* initialize (coefficient = alpha, rates = lambda) */
1498 rates[0] = 0.466998;
1500 coefficients[0] = 1.0;
1503 rates[0] = 0.8988162;
1504 coefficients[0] = 0.11392069;
1505 rates[1] = 0.3745688;
1506 coefficients[1] = 0.8860793;
1508 Float_t sumc = coefficients[0]+coefficients[1];
1509 coefficients[0] /= sumc;
1510 coefficients[1] /= sumc;
1514 Double_t reminder[2];
1515 Double_t correction, result;
1517 /* attention: computation order is important */
1519 for ( k = 0; k < nexp; k++ ) reminder[k]=0.0;
1521 for ( i = 0; i < n; i++ ) {
1522 result = ( source[i] - correction ); /* no rescaling */
1525 for ( k = 0; k < nexp; k++ ) reminder[k] = rates[k]
1526 * ( reminder[k] + coefficients[k] * result);
1529 for ( k = 0; k < nexp; k++ ) correction += reminder[k];
1534 //_____________________________________________________________________________
1535 void AliTRDdigitizer::InitOutput(Int_t iEvent)
1538 // Initializes the output branches
1545 Error("InitOutput","Run Loader is NULL");
1548 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
1551 Error("Open","Can not get TRD loader from Run Loader");
1559 //if we produce SDigits
1560 tree = loader->TreeS();
1563 loader->MakeTree("S");
1564 tree = loader->TreeS();
1568 {//if we produce Digits
1569 tree = loader->TreeD();
1572 loader->MakeTree("D");
1573 tree = loader->TreeD();
1576 fDigitsManager->SetEvent(iEvent);
1577 fDigitsManager->MakeBranch(tree);