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);
408 Error("Open","Can not open session for file %s.",file);
412 fRunLoader->LoadgAlice();
413 gAlice = fRunLoader->GetAliRun();
417 printf("<AliTRDdigitizer::Open> ");
418 printf("AliRun object found on file.\n");
422 printf("<AliTRDdigitizer::Open> ");
423 printf("Could not find AliRun object.\n");
429 // Import the Trees for the event nEvent in the file
430 fRunLoader->GetEvent(fEvent);
432 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
435 Error("Open","Can not get TRD loader from Run Loader");
439 if (InitDetector()) {
443 //if we produce SDigits
444 tree = loader->TreeS();
447 loader->MakeTree("S");
448 tree = loader->TreeS();
452 {//if we produce Digits
453 tree = loader->TreeD();
456 loader->MakeTree("D");
457 tree = loader->TreeD();
460 return MakeBranch(tree);
468 //_____________________________________________________________________________
469 Bool_t AliTRDdigitizer::InitDetector()
472 // Sets the pointer to the TRD detector and the geometry
475 // Get the pointer to the detector class and check for version 1
476 fTRD = (AliTRD *) gAlice->GetDetector("TRD");
478 printf("<AliTRDdigitizer::InitDetector> ");
479 printf("No TRD module found\n");
482 if (fTRD->IsVersion() != 1) {
483 printf("<AliTRDdigitizer::InitDetector> ");
484 printf("TRD must be version 1 (slow simulator).\n");
489 fGeo = fTRD->GetGeometry();
491 printf("<AliTRDdigitizer::InitDetector> ");
492 printf("Geometry version %d\n",fGeo->IsVersion());
495 // Create a digits manager
496 fDigitsManager = new AliTRDdigitsManager();
497 fDigitsManager->SetSDigits(fSDigits);
498 fDigitsManager->CreateArrays();
499 fDigitsManager->SetEvent(fEvent);
500 fDigitsManager->SetDebug(fDebug);
502 // The list for the input s-digits manager to be merged
503 fSDigitsManagerList = new TList();
509 //_____________________________________________________________________________
510 Bool_t AliTRDdigitizer::MakeBranch(TTree* tree) const
513 // Create the branches for the digits array
516 return fDigitsManager->MakeBranch(tree);
520 //_____________________________________________________________________________
521 Bool_t AliTRDdigitizer::MakeDigits()
527 ///////////////////////////////////////////////////////////////
529 ///////////////////////////////////////////////////////////////
531 // Converts number of electrons to fC
532 const Double_t kEl2fC = 1.602E-19 * 1.0E15;
534 ///////////////////////////////////////////////////////////////
536 // Number of pads included in the pad response
537 const Int_t kNpad = 3;
539 // Number of track dictionary arrays
540 const Int_t kNDict = AliTRDdigitsManager::kNDict;
542 // Half the width of the amplification region
543 const Float_t kAmWidth = AliTRDgeometry::AmThick() / 2.;
545 Int_t iRow, iCol, iTime, iPad;
549 Int_t totalSizeDigits = 0;
550 Int_t totalSizeDict0 = 0;
551 Int_t totalSizeDict1 = 0;
552 Int_t totalSizeDict2 = 0;
554 Int_t timeTRDbeg = 0;
555 Int_t timeTRDend = 1;
560 Float_t padSignal[kNpad];
561 Float_t signalOld[kNpad];
563 AliTRDdataArrayF *signals = 0;
564 AliTRDdataArrayI *digits = 0;
565 AliTRDdataArrayI *dictionary[kNDict];
567 // Create a default parameter class if none is defined
569 fPar = new AliTRDparameter("TRDparameter","Standard TRD parameter");
571 printf("<AliTRDdigitizer::MakeDigits> ");
572 printf("Create the default parameter object\n");
576 // Create a container for the amplitudes
577 AliTRDsegmentArray *signalsArray
578 = new AliTRDsegmentArray("AliTRDdataArrayF"
579 ,AliTRDgeometry::Ndet());
582 timeTRDbeg = ((Int_t) (-fPar->GetTRFlo() / fPar->GetTimeBinSize())) - 1;
583 timeTRDend = ((Int_t) ( fPar->GetTRFhi() / fPar->GetTimeBinSize())) - 1;
585 printf("<AliTRDdigitizer::MakeDigits> ");
586 printf("Sample the TRF between -%d and %d\n",timeTRDbeg,timeTRDend);
590 Float_t elAttachProp = fPar->GetElAttachProp() / 100.;
593 printf("<AliTRDdigitizer::MakeDigits> ");
594 printf("No geometry defined\n");
599 printf("<AliTRDdigitizer::MakeDigits> ");
600 printf("Start creating digits.\n");
603 AliLoader* gimme = fRunLoader->GetLoader("TRDLoader");
604 if (!gimme->TreeH()) gimme->LoadHits();
605 TTree* hitTree = gimme->TreeH();
608 Error("MakeDigits","Can not get TreeH");
611 fTRD->SetTreeAddress();
613 // Get the number of entries in the hit tree
614 // (Number of primary particles creating a hit somewhere)
617 nTrack = (Int_t) hitTree->GetEntries();
619 printf("<AliTRDdigitizer::MakeDigits> ");
620 printf("Found %d primary particles\n",nTrack);
624 Int_t detectorOld = -1;
627 // Loop through all entries in the tree
628 for (Int_t iTrack = 0; iTrack < nTrack; iTrack++) {
632 nBytes += hitTree->GetEvent(iTrack);
635 // Loop through the TRD hits
637 AliTRDhit *hit = (AliTRDhit *) fTRD->FirstHit(-1);
646 Float_t q = hit->GetCharge();
647 Int_t track = hit->Track();
648 Int_t detector = hit->GetDetector();
649 Int_t plane = fGeo->GetPlane(detector);
650 Int_t sector = fGeo->GetSector(detector);
651 Int_t chamber = fGeo->GetChamber(detector);
652 Int_t nRowMax = fPar->GetRowMax(plane,chamber,sector);
653 Int_t nColMax = fPar->GetColMax(plane);
654 Int_t nTimeMax = fPar->GetTimeMax();
655 Int_t nTimeBefore = fPar->GetTimeBefore();
656 Int_t nTimeAfter = fPar->GetTimeAfter();
657 Int_t nTimeTotal = fPar->GetTimeTotal();
658 Float_t row0 = fPar->GetRow0(plane,chamber,sector);
659 Float_t col0 = fPar->GetCol0(plane);
660 Float_t time0 = fPar->GetTime0(plane);
661 Float_t rowPadSize = fPar->GetRowPadSize(plane,chamber,sector);
662 Float_t colPadSize = fPar->GetColPadSize(plane);
663 Float_t timeBinSize = fPar->GetTimeBinSize();
664 Float_t divideRow = 1.0 / rowPadSize;
665 Float_t divideCol = 1.0 / colPadSize;
666 Float_t divideTime = 1.0 / timeBinSize;
669 printf("Analyze hit no. %d ",iHit);
670 printf("-----------------------------------------------------------\n");
672 printf("plane = %d, sector = %d, chamber = %d\n"
673 ,plane,sector,chamber);
674 printf("nRowMax = %d, nColMax = %d, nTimeMax = %d\n"
675 ,nRowMax,nColMax,nTimeMax);
676 printf("nTimeBefore = %d, nTimeAfter = %d, nTimeTotal = %d\n"
677 ,nTimeBefore,nTimeAfter,nTimeTotal);
678 printf("row0 = %f, col0 = %f, time0 = %f\n"
680 printf("rowPadSize = %f, colPadSize = %f, timeBinSize = %f\n"
681 ,rowPadSize,colPadSize,timeBinSize);
684 // Don't analyze test hits and switched off detectors
685 if ((CheckDetector(plane,chamber,sector)) &&
686 (((Int_t) q) != 0)) {
688 if (detector != detectorOld) {
691 printf("<AliTRDdigitizer::MakeDigits> ");
692 printf("Get new container. New det = %d, Old det = %d\n"
693 ,detector,detectorOld);
695 // Compress the old one if enabled
696 if ((fCompress) && (detectorOld > -1)) {
698 printf("<AliTRDdigitizer::MakeDigits> ");
699 printf("Compress the old container ...");
701 signals->Compress(1,0);
702 for (iDict = 0; iDict < kNDict; iDict++) {
703 dictionary[iDict]->Compress(1,0);
705 if (fDebug > 1) printf("done\n");
707 // Get the new container
708 signals = (AliTRDdataArrayF *) signalsArray->At(detector);
709 if (signals->GetNtime() == 0) {
710 // Allocate a new one if not yet existing
712 printf("<AliTRDdigitizer::MakeDigits> ");
713 printf("Allocate a new container ... ");
715 signals->Allocate(nRowMax,nColMax,nTimeTotal);
717 else if (fSimpleSim) {
718 // Clear an old one for the simple simulation
720 printf("<AliTRDdigitizer::MakeDigits> ");
721 printf("Clear a old container ... ");
726 // Expand an existing one
729 printf("<AliTRDdigitizer::MakeDigits> ");
730 printf("Expand an existing container ... ");
735 // The same for the dictionary
737 for (iDict = 0; iDict < kNDict; iDict++) {
738 dictionary[iDict] = fDigitsManager->GetDictionary(detector,iDict);
739 if (dictionary[iDict]->GetNtime() == 0) {
740 dictionary[iDict]->Allocate(nRowMax,nColMax,nTimeTotal);
743 if (fCompress) dictionary[iDict]->Expand();
747 if (fDebug > 1) printf("done\n");
748 detectorOld = detector;
751 // Rotate the sectors on top of each other
758 fGeo->Rotate(detector,pos,rot);
761 // The driftlength. It is negative if the hit is in the
762 // amplification region.
763 Float_t driftlength = time0 - rot[0];
765 // Take also the drift in the amplification region into account
766 // The drift length is at the moment still the same, regardless of
767 // the position relativ to the wire. This non-isochronity needs still
768 // to be implemented.
769 Float_t driftlengthL = TMath::Abs(driftlength + kAmWidth);
770 if (fPar->ExBOn()) driftlengthL /= TMath::Sqrt(fPar->GetLorentzFactor());
772 // Loop over all electrons of this hit
773 // TR photons produce hits with negative charge
774 Int_t nEl = ((Int_t) TMath::Abs(q));
775 for (Int_t iEl = 0; iEl < nEl; iEl++) {
781 // Electron attachment
782 if (fPar->ElAttachOn()) {
783 if (gRandom->Rndm() < (driftlengthL * elAttachProp))
787 // Apply the diffusion smearing
788 if (fPar->DiffusionOn()) {
789 if (!(fPar->Diffusion(driftlengthL,xyz))) continue;
792 // Apply E x B effects (depends on drift direction)
794 if (!(fPar->ExB(driftlength+kAmWidth,xyz))) continue;
797 // The electron position after diffusion and ExB in pad coordinates
798 // The pad row (z-direction)
799 Float_t rowDist = xyz[2] - row0;
800 Int_t rowE = ((Int_t) (rowDist * divideRow));
801 if ((rowE < 0) || (rowE >= nRowMax)) continue;
802 Float_t rowOffset = ((((Float_t) rowE) + 0.5) * rowPadSize) - rowDist;
804 // The pad column (rphi-direction)
805 Float_t col0tilt = fPar->Col0Tilted(col0,rowOffset,plane);
806 Float_t colDist = xyz[1] - col0tilt;
807 Int_t colE = ((Int_t) (colDist * divideCol));
808 if ((colE < 0) || (colE >= nColMax)) continue;
809 Float_t colOffset = ((((Float_t) colE) + 0.5) * colPadSize) - colDist;
811 // The time bin (negative for hits in the amplification region)
812 // In the amplification region the electrons drift from both sides
813 // to the middle (anode wire plane)
814 Float_t timeDist = time0 - xyz[0];
815 Float_t timeOffset = 0;
819 timeE = ((Int_t) (timeDist * divideTime));
820 // The distance of the position to the middle of the timebin
821 timeOffset = ((((Float_t) timeE) + 0.5) * timeBinSize) - timeDist;
824 // Difference between half of the amplification gap width and
825 // the distance to the anode wire
826 Float_t anodeDist = kAmWidth - TMath::Abs(timeDist + kAmWidth);
828 timeE = -1 * (((Int_t ) (anodeDist * divideTime)) + 1);
829 // The distance of the position to the middle of the timebin
830 timeOffset = ((((Float_t) timeE) + 0.5) * timeBinSize) + anodeDist;
833 // Apply the gas gain including fluctuations
834 Float_t ggRndm = 0.0;
836 ggRndm = gRandom->Rndm();
837 } while (ggRndm <= 0);
838 Int_t signal = (Int_t) (-fPar->GetGasGain() * TMath::Log(ggRndm));
840 // Apply the pad response
842 // The distance of the electron to the center of the pad
843 // in units of pad width
844 Float_t dist = - colOffset * divideCol;
845 if (!(fPar->PadResponse(signal,dist,plane,padSignal))) continue;
849 padSignal[1] = signal;
853 // Sample the time response inside the drift region
854 // + additional time bins before and after.
855 // The sampling is done always in the middle of the time bin
856 for (Int_t iTimeBin = TMath::Max(timeE-timeTRDbeg, -nTimeBefore)
857 ;iTimeBin < TMath::Min(timeE+timeTRDend,nTimeMax+nTimeAfter )
860 // Apply the time response
861 Float_t timeResponse = 1.0;
862 Float_t crossTalk = 0.0;
863 Float_t time = (iTimeBin - timeE) * timeBinSize + timeOffset;
865 timeResponse = fPar->TimeResponse(time);
868 crossTalk = fPar->CrossTalk(time);
875 for (iPad = 0; iPad < kNpad; iPad++) {
877 Int_t colPos = colE + iPad - 1;
878 if (colPos < 0) continue;
879 if (colPos >= nColMax) break;
882 // Note: The time bin number is shifted by nTimeBefore to avoid negative
883 // time bins. This has to be subtracted later.
884 Int_t iCurrentTimeBin = iTimeBin + nTimeBefore;
885 signalOld[iPad] = signals->GetDataUnchecked(rowE,colPos,iCurrentTimeBin);
886 if( colPos != colE ) {
887 signalOld[iPad] += padSignal[iPad] * (timeResponse + crossTalk);
890 signalOld[iPad] += padSignal[iPad] * timeResponse;
892 signals->SetDataUnchecked(rowE,colPos,iCurrentTimeBin,signalOld[iPad]);
894 // Store the track index in the dictionary
895 // Note: We store index+1 in order to allow the array to be compressed
896 if ((signalOld[iPad] > 0) && (!fSimpleSim)) {
897 for (iDict = 0; iDict < kNDict; iDict++) {
898 Int_t oldTrack = dictionary[iDict]->GetDataUnchecked(rowE
901 if (oldTrack == track+1) break;
903 dictionary[iDict]->SetDataUnchecked(rowE,colPos,iCurrentTimeBin,track+1);
913 } // Loop: electrons of a single hit
915 } // If: detector and test hit
917 hit = (AliTRDhit *) fTRD->NextHit();
919 } // Loop: hits of one primary track
921 } // Loop: primary tracks
924 printf("<AliTRDdigitizer::MakeDigits> ");
925 printf("Finished analyzing %d hits\n",countHits);
928 // The coupling factor
929 Float_t coupling = fPar->GetPadCoupling()
930 * fPar->GetTimeCoupling();
932 // The conversion factor
933 Float_t convert = kEl2fC
934 * fPar->GetChipGain();
936 // Loop through all chambers to finalize the digits
938 Int_t iDetEnd = AliTRDgeometry::Ndet();
940 iDetBeg = fSimpleDet;
941 iDetEnd = iDetBeg + 1;
943 for (Int_t iDet = iDetBeg; iDet < iDetEnd; iDet++) {
945 Int_t plane = fGeo->GetPlane(iDet);
946 Int_t sector = fGeo->GetSector(iDet);
947 Int_t chamber = fGeo->GetChamber(iDet);
948 Int_t nRowMax = fPar->GetRowMax(plane,chamber,sector);
949 Int_t nColMax = fPar->GetColMax(plane);
950 Int_t nTimeMax = fPar->GetTimeMax();
951 Int_t nTimeTotal = fPar->GetTimeTotal();
953 Double_t *inADC = new Double_t[nTimeTotal];
954 Double_t *outADC = new Double_t[nTimeTotal];
957 printf("<AliTRDdigitizer::MakeDigits> ");
958 printf("Digitization for chamber %d\n",iDet);
961 // Add a container for the digits of this detector
962 digits = fDigitsManager->GetDigits(iDet);
963 // Allocate memory space for the digits buffer
964 if (digits->GetNtime() == 0) {
965 digits->Allocate(nRowMax,nColMax,nTimeTotal);
967 else if (fSimpleSim) {
971 // Get the signal container
972 signals = (AliTRDdataArrayF *) signalsArray->At(iDet);
973 if (signals->GetNtime() == 0) {
974 // Create missing containers
975 signals->Allocate(nRowMax,nColMax,nTimeTotal);
978 // Expand the container if neccessary
979 if (fCompress) signals->Expand();
981 // Create the missing dictionary containers
983 for (iDict = 0; iDict < kNDict; iDict++) {
984 dictionary[iDict] = fDigitsManager->GetDictionary(iDet,iDict);
985 if (dictionary[iDict]->GetNtime() == 0) {
986 dictionary[iDict]->Allocate(nRowMax,nColMax,nTimeTotal);
993 // Don't create noise in detectors that are switched off
994 if (CheckDetector(plane,chamber,sector)) {
996 // Create the digits for this chamber
997 for (iRow = 0; iRow < nRowMax; iRow++ ) {
998 for (iCol = 0; iCol < nColMax; iCol++ ) {
1000 // Create summable digits
1003 for (iTime = 0; iTime < nTimeTotal; iTime++) {
1004 Float_t signalAmp = signals->GetDataUnchecked(iRow,iCol,iTime);
1005 signalAmp *= fSDigitsScale;
1006 signalAmp = TMath::Min(signalAmp,(Float_t) 1.0e9);
1007 Int_t adc = (Int_t) signalAmp;
1008 if (adc > 0) nDigits++;
1009 digits->SetDataUnchecked(iRow,iCol,iTime,adc);
1013 // Create normal digits
1016 for (iTime = 0; iTime < nTimeTotal; iTime++) {
1017 Float_t signalAmp = signals->GetDataUnchecked(iRow,iCol,iTime);
1018 // Pad and time coupling
1019 signalAmp *= coupling;
1020 // Add the noise, starting from minus ADC baseline in electrons
1021 Double_t baselineEl = fPar->GetADCbaseline() * (fPar->GetADCinRange()
1022 / fPar->GetADCoutRange())
1024 signalAmp = TMath::Max((Double_t) gRandom->Gaus(signalAmp,fPar->GetNoise())
1027 signalAmp *= convert;
1028 // Add ADC baseline in mV
1029 signalAmp += fPar->GetADCbaseline() * (fPar->GetADCinRange()
1030 / fPar->GetADCoutRange());
1031 // Convert to ADC counts. Set the overflow-bit fADCoutRange if the
1032 // signal is larger than fADCinRange
1034 if (signalAmp >= fPar->GetADCinRange()) {
1035 adc = ((Int_t) fPar->GetADCoutRange());
1038 adc = ((Int_t) (signalAmp * (fPar->GetADCoutRange()
1039 / fPar->GetADCinRange())));
1042 outADC[iTime] = adc;
1045 // Apply the tail cancelation via the digital filter
1047 DeConvExp(inADC,outADC,nTimeTotal,fPar->GetTCnexp());
1050 for (iTime = 0; iTime < nTimeTotal; iTime++) {
1051 // Store the amplitude of the digit if above threshold
1052 if (outADC[iTime] > fPar->GetADCthreshold()) {
1054 printf(" iRow = %d, iCol = %d, iTime = %d, adc = %f\n"
1055 ,iRow,iCol,iTime,outADC[iTime]);
1058 digits->SetDataUnchecked(iRow,iCol,iTime,((Int_t) outADC[iTime]));
1069 // Compress the arrays
1071 digits->Compress(1,0);
1072 for (iDict = 0; iDict < kNDict; iDict++) {
1073 dictionary[iDict]->Compress(1,0);
1076 totalSizeDigits += digits->GetSize();
1077 totalSizeDict0 += dictionary[0]->GetSize();
1078 totalSizeDict1 += dictionary[1]->GetSize();
1079 totalSizeDict2 += dictionary[2]->GetSize();
1081 Float_t nPixel = nRowMax * nColMax * nTimeMax;
1083 printf("<AliTRDdigitizer::MakeDigits> ");
1084 printf("Found %d digits in detector %d (%3.0f).\n"
1086 ,100.0 * ((Float_t) nDigits) / nPixel);
1089 if (fCompress) signals->Compress(1,0);
1099 delete signalsArray;
1104 printf("<AliTRDdigitizer::MakeDigits> ");
1105 printf("Total number of analyzed hits = %d\n",countHits);
1107 printf("<AliTRDdigitizer::MakeDigits> ");
1108 printf("Total digits data size = %d, %d, %d, %d\n",totalSizeDigits
1119 //_____________________________________________________________________________
1120 void AliTRDdigitizer::AddSDigitsManager(AliTRDdigitsManager *man)
1123 // Add a digits manager for s-digits to the input list.
1126 fSDigitsManagerList->Add(man);
1130 //_____________________________________________________________________________
1131 void AliTRDdigitizer::DeleteSDigitsManager()
1134 // Removes digits manager from the input list.
1137 fSDigitsManagerList->Delete();
1141 //_____________________________________________________________________________
1142 Bool_t AliTRDdigitizer::ConvertSDigits()
1145 // Converts s-digits to normal digits
1148 // Number of track dictionary arrays
1149 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1151 // Converts number of electrons to fC
1152 const Double_t kEl2fC = 1.602E-19 * 1.0E15;
1160 fPar = new AliTRDparameter("TRDparameter","Standard parameter");
1162 printf("<AliTRDdigitizer::ConvertSDigits> ");
1163 printf("Create the default parameter object\n");
1167 Double_t sDigitsScale = 1.0 / GetSDigitsScale();
1168 Double_t noise = fPar->GetNoise();
1169 Double_t padCoupling = fPar->GetPadCoupling();
1170 Double_t timeCoupling = fPar->GetTimeCoupling();
1171 Double_t chipGain = fPar->GetChipGain();
1172 Double_t coupling = padCoupling * timeCoupling;
1173 Double_t convert = kEl2fC * chipGain;
1174 Double_t adcInRange = fPar->GetADCinRange();
1175 Double_t adcOutRange = fPar->GetADCoutRange();
1176 Int_t adcThreshold = fPar->GetADCthreshold();
1177 Int_t adcBaseline = fPar->GetADCbaseline();
1179 AliTRDdataArrayI *digitsIn;
1180 AliTRDdataArrayI *digitsOut;
1181 AliTRDdataArrayI *dictionaryIn[kNDict];
1182 AliTRDdataArrayI *dictionaryOut[kNDict];
1184 // Loop through the detectors
1185 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) {
1188 printf("<AliTRDdigitizer::ConvertSDigits> ");
1189 printf("Convert detector %d to digits.\n",iDet);
1192 Int_t plane = fGeo->GetPlane(iDet);
1193 Int_t sector = fGeo->GetSector(iDet);
1194 Int_t chamber = fGeo->GetChamber(iDet);
1195 Int_t nRowMax = fPar->GetRowMax(plane,chamber,sector);
1196 Int_t nColMax = fPar->GetColMax(plane);
1197 Int_t nTimeTotal = fPar->GetTimeTotal();
1199 Double_t *inADC = new Double_t[nTimeTotal];
1200 Double_t *outADC = new Double_t[nTimeTotal];
1202 digitsIn = fSDigitsManager->GetDigits(iDet);
1204 digitsOut = fDigitsManager->GetDigits(iDet);
1205 digitsOut->Allocate(nRowMax,nColMax,nTimeTotal);
1206 for (iDict = 0; iDict < kNDict; iDict++) {
1207 dictionaryIn[iDict] = fSDigitsManager->GetDictionary(iDet,iDict);
1208 dictionaryIn[iDict]->Expand();
1209 dictionaryOut[iDict] = fDigitsManager->GetDictionary(iDet,iDict);
1210 dictionaryOut[iDict]->Allocate(nRowMax,nColMax,nTimeTotal);
1213 for (iRow = 0; iRow < nRowMax; iRow++ ) {
1214 for (iCol = 0; iCol < nColMax; iCol++ ) {
1216 for (iTime = 0; iTime < nTimeTotal; iTime++) {
1217 Double_t signal = (Double_t) digitsIn->GetDataUnchecked(iRow,iCol,iTime);
1218 signal *= sDigitsScale;
1219 // Pad and time coupling
1221 // Add the noise, starting from minus ADC baseline in electrons
1222 Double_t baselineEl = adcBaseline * (adcInRange / adcOutRange) / convert;
1223 signal = TMath::Max((Double_t) gRandom->Gaus(signal,noise),-baselineEl);
1226 // add ADC baseline in mV
1227 signal += adcBaseline * (adcInRange / adcOutRange);
1228 // Convert to ADC counts. Set the overflow-bit adcOutRange if the
1229 // signal is larger than adcInRange
1231 if (signal >= adcInRange) {
1232 adc = ((Int_t) adcOutRange);
1235 adc = ((Int_t) (signal * (adcOutRange / adcInRange)));
1238 outADC[iTime] = adc;
1241 // Apply the tail cancelation via the digital filter
1243 DeConvExp(inADC,outADC,nTimeTotal,fPar->GetTCnexp());
1246 for (iTime = 0; iTime < nTimeTotal; iTime++) {
1247 // Store the amplitude of the digit if above threshold
1248 if (outADC[iTime] > adcThreshold) {
1249 digitsOut->SetDataUnchecked(iRow,iCol,iTime,((Int_t) outADC[iTime]));
1250 // Copy the dictionary
1251 for (iDict = 0; iDict < kNDict; iDict++) {
1252 Int_t track = dictionaryIn[iDict]->GetDataUnchecked(iRow,iCol,iTime);
1253 dictionaryOut[iDict]->SetDataUnchecked(iRow,iCol,iTime,track);
1262 digitsIn->Compress(1,0);
1263 digitsOut->Compress(1,0);
1264 for (iDict = 0; iDict < kNDict; iDict++) {
1265 dictionaryIn[iDict]->Compress(1,0);
1266 dictionaryOut[iDict]->Compress(1,0);
1279 //_____________________________________________________________________________
1280 Bool_t AliTRDdigitizer::MergeSDigits()
1283 // Merges the input s-digits:
1284 // - The amplitude of the different inputs are summed up.
1285 // - Of the track IDs from the input dictionaries only one is
1286 // kept for each input. This works for maximal 3 different merged inputs.
1289 // Number of track dictionary arrays
1290 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1293 fPar = new AliTRDparameter("TRDparameter","Standard parameter");
1295 printf("<AliTRDdigitizer::MergeSDigits> ");
1296 printf("Create the default parameter object\n");
1303 AliTRDdataArrayI *digitsA;
1304 AliTRDdataArrayI *digitsB;
1305 AliTRDdataArrayI *dictionaryA[kNDict];
1306 AliTRDdataArrayI *dictionaryB[kNDict];
1308 // Get the first s-digits
1309 fSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->First();
1310 if (!fSDigitsManager) return kFALSE;
1312 // Loop through the other sets of s-digits
1313 AliTRDdigitsManager *mergeSDigitsManager;
1314 mergeSDigitsManager = (AliTRDdigitsManager *)
1315 fSDigitsManagerList->After(fSDigitsManager);
1318 if (mergeSDigitsManager) {
1319 printf("<AliTRDdigitizer::MergeSDigits> ");
1320 printf("Merge %d input files.\n",fSDigitsManagerList->GetSize());
1323 printf("<AliTRDdigitizer::MergeSDigits> ");
1324 printf("Only one input file.\n");
1329 while (mergeSDigitsManager) {
1333 // Loop through the detectors
1334 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) {
1336 Int_t plane = fGeo->GetPlane(iDet);
1337 Int_t sector = fGeo->GetSector(iDet);
1338 Int_t chamber = fGeo->GetChamber(iDet);
1339 Int_t nRowMax = fPar->GetRowMax(plane,chamber,sector);
1340 Int_t nColMax = fPar->GetColMax(plane);
1341 Int_t nTimeTotal = fPar->GetTimeTotal();
1343 // Loop through the pixels of one detector and add the signals
1344 digitsA = fSDigitsManager->GetDigits(iDet);
1345 digitsB = mergeSDigitsManager->GetDigits(iDet);
1348 for (iDict = 0; iDict < kNDict; iDict++) {
1349 dictionaryA[iDict] = fSDigitsManager->GetDictionary(iDet,iDict);
1350 dictionaryB[iDict] = mergeSDigitsManager->GetDictionary(iDet,iDict);
1351 dictionaryA[iDict]->Expand();
1352 dictionaryB[iDict]->Expand();
1355 // Merge only detectors that contain a signal
1356 Bool_t doMerge = kTRUE;
1357 if (fMergeSignalOnly) {
1358 if (digitsA->GetOverThreshold(0) == 0) {
1366 printf("<AliTRDdigitizer::MergeSDigits> ");
1367 printf("Merge detector %d of input no.%d\n",iDet,iMerge+1);
1370 for (Int_t iRow = 0; iRow < nRowMax; iRow++ ) {
1371 for (Int_t iCol = 0; iCol < nColMax; iCol++ ) {
1372 for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
1374 // Add the amplitudes of the summable digits
1375 Int_t ampA = digitsA->GetDataUnchecked(iRow,iCol,iTime);
1376 Int_t ampB = digitsB->GetDataUnchecked(iRow,iCol,iTime);
1378 digitsA->SetDataUnchecked(iRow,iCol,iTime,ampA);
1380 // Add the mask to the track id if defined.
1381 for (iDict = 0; iDict < kNDict; iDict++) {
1382 Int_t trackB = dictionaryB[iDict]->GetDataUnchecked(iRow,iCol,iTime);
1383 if ((fMasks) && (trackB > 0)) {
1384 for (jDict = 0; jDict < kNDict; jDict++) {
1385 Int_t trackA = dictionaryA[iDict]->GetDataUnchecked(iRow,iCol,iTime);
1387 trackA = trackB + fMasks[iMerge];
1388 dictionaryA[iDict]->SetDataUnchecked(iRow,iCol,iTime,trackA);
1401 digitsA->Compress(1,0);
1402 digitsB->Compress(1,0);
1403 for (iDict = 0; iDict < kNDict; iDict++) {
1404 dictionaryA[iDict]->Compress(1,0);
1405 dictionaryB[iDict]->Compress(1,0);
1411 // The next set of s-digits
1412 mergeSDigitsManager = (AliTRDdigitsManager *)
1413 fSDigitsManagerList->After(mergeSDigitsManager);
1421 //_____________________________________________________________________________
1422 Bool_t AliTRDdigitizer::SDigits2Digits()
1425 // Merges the input s-digits and converts them to normal digits
1428 if (!MergeSDigits()) return kFALSE;
1430 return ConvertSDigits();
1434 //_____________________________________________________________________________
1435 Bool_t AliTRDdigitizer::CheckDetector(Int_t plane, Int_t chamber, Int_t sector)
1438 // Checks whether a detector is enabled
1441 if (fSimpleSim) return kTRUE;
1443 if ((fTRD->GetSensChamber() >= 0) &&
1444 (fTRD->GetSensChamber() != chamber)) return kFALSE;
1445 if ((fTRD->GetSensPlane() >= 0) &&
1446 (fTRD->GetSensPlane() != plane)) return kFALSE;
1447 if ( fTRD->GetSensSector() >= 0) {
1448 Int_t sens1 = fTRD->GetSensSector();
1449 Int_t sens2 = sens1 + fTRD->GetSensSectorRange();
1450 sens2 -= ((Int_t) (sens2 / AliTRDgeometry::Nsect()))
1451 * AliTRDgeometry::Nsect();
1452 if (sens1 < sens2) {
1453 if ((sector < sens1) || (sector >= sens2)) return kFALSE;
1456 if ((sector < sens1) && (sector >= sens2)) return kFALSE;
1464 //_____________________________________________________________________________
1465 Bool_t AliTRDdigitizer::WriteDigits() const
1468 // Writes out the TRD-digits and the dictionaries
1471 // Store the digits and the dictionary in the tree
1472 return fDigitsManager->WriteDigits();
1476 //_____________________________________________________________________________
1477 void AliTRDdigitizer::DeConvExp(Double_t *source, Double_t *target
1478 , Int_t n, Int_t nexp)
1481 // Does the deconvolution by the digital filter.
1483 // Author: Marcus Gutfleisch, KIP Heidelberg
1484 // Optimized for: New TRF from Venelin Angelov, simulated with CADENCE
1485 // Pad-ground capacitance = 25 pF
1486 // Pad-pad cross talk capacitance = 6 pF
1487 // For 10 MHz digitization, corresponding to 20 time bins
1488 // in the drift region
1492 Double_t coefficients[2];
1494 /* initialize (coefficient = alpha, rates = lambda) */
1497 rates[0] = 0.466998;
1499 coefficients[0] = 1.0;
1502 rates[0] = 0.8988162;
1503 coefficients[0] = 0.11392069;
1504 rates[1] = 0.3745688;
1505 coefficients[1] = 0.8860793;
1507 Float_t sumc = coefficients[0]+coefficients[1];
1508 coefficients[0] /= sumc;
1509 coefficients[1] /= sumc;
1513 Double_t reminder[2];
1514 Double_t correction, result;
1516 /* attention: computation order is important */
1518 for ( k = 0; k < nexp; k++ ) reminder[k]=0.0;
1520 for ( i = 0; i < n; i++ ) {
1521 result = ( source[i] - correction ); /* no rescaling */
1524 for ( k = 0; k < nexp; k++ ) reminder[k] = rates[k]
1525 * ( reminder[k] + coefficients[k] * result);
1528 for ( k = 0; k < nexp; k++ ) correction += reminder[k];
1533 //_____________________________________________________________________________
1534 void AliTRDdigitizer::InitOutput(Int_t iEvent)
1537 // Initializes the output branches
1544 Error("InitOutput","Run Loader is NULL");
1547 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
1550 Error("Open","Can not get TRD loader from Run Loader");
1558 //if we produce SDigits
1559 tree = loader->TreeS();
1562 loader->MakeTree("S");
1563 tree = loader->TreeS();
1567 {//if we produce Digits
1568 tree = loader->TreeD();
1571 loader->MakeTree("D");
1572 tree = loader->TreeD();
1575 fDigitsManager->SetEvent(iEvent);
1576 fDigitsManager->MakeBranch(tree);