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;
218 if (fSDigitsManagerList) {
219 fSDigitsManagerList->Delete();
220 delete fSDigitsManagerList;
221 fSDigitsManagerList = 0;
231 //_____________________________________________________________________________
232 AliTRDdigitizer &AliTRDdigitizer::operator=(const AliTRDdigitizer &d)
235 // Assignment operator
238 if (this != &d) ((AliTRDdigitizer &) d).Copy(*this);
243 //_____________________________________________________________________________
244 void AliTRDdigitizer::Copy(TObject &d)
250 ((AliTRDdigitizer &) d).fRunLoader = 0;
251 ((AliTRDdigitizer &) d).fDigitsManager = 0;
252 ((AliTRDdigitizer &) d).fSDigitsManager = 0;
253 ((AliTRDdigitizer &) d).fSDigitsManagerList = 0;
254 ((AliTRDdigitizer &) d).fTRD = 0;
255 ((AliTRDdigitizer &) d).fGeo = 0;
256 ((AliTRDdigitizer &) d).fPar = 0;
257 ((AliTRDdigitizer &) d).fEvent = 0;
258 ((AliTRDdigitizer &) d).fMasks = 0;
259 ((AliTRDdigitizer &) d).fCompress = fCompress;
260 ((AliTRDdigitizer &) d).fDebug = fDebug ;
261 ((AliTRDdigitizer &) d).fSDigits = fSDigits;
262 ((AliTRDdigitizer &) d).fSDigitsScale = fSDigitsScale;
263 ((AliTRDdigitizer &) d).fMergeSignalOnly = fMergeSignalOnly;
264 ((AliTRDdigitizer &) d).fSimpleSim = fSimpleSim;
265 ((AliTRDdigitizer &) d).fSimpleDet = fSimpleDet;
269 //_____________________________________________________________________________
270 void AliTRDdigitizer::Exec(Option_t* option)
273 // Executes the merging
278 AliTRDdigitsManager *sdigitsManager;
280 TString optionString = option;
281 if (optionString.Contains("deb")) {
283 if (optionString.Contains("2")) {
286 printf("<AliTRDdigitizer::Exec> ");
287 printf("Called with debug option %d\n",fDebug);
290 // The AliRoot file is already connected by the manager
296 printf("<AliTRDdigitizer::Exec> ");
297 printf("AliRun object found on file.\n");
301 inrl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
303 gAlice = inrl->GetAliRun();
306 printf("<AliTRDdigitizer::Exec> ");
307 printf("Could not find AliRun object.\n");
312 Int_t nInput = fManager->GetNinputs();
313 fMasks = new Int_t[nInput];
314 for (iInput = 0; iInput < nInput; iInput++) {
315 fMasks[iInput] = fManager->GetMask(iInput);
320 AliRunLoader* orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
321 if (InitDetector()) {
322 AliLoader* ogime = orl->GetLoader("TRDLoader");
327 //if we produce SDigits
328 tree = ogime->TreeS();
331 ogime->MakeTree("S");
332 tree = ogime->TreeS();
336 {//if we produce Digits
337 tree = ogime->TreeD();
340 ogime->MakeTree("D");
341 tree = ogime->TreeD();
347 for (iInput = 0; iInput < nInput; iInput++) {
350 printf("<AliTRDdigitizer::Exec> ");
351 printf("Add input stream %d\n",iInput);
354 // check if the input tree exists
355 inrl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(iInput));
356 AliLoader* gime = inrl->GetLoader("TRDLoader");
358 TTree * treees = gime->TreeS();
361 if (gime->LoadSDigits())
363 Error("Exec","Error Occured while loading S. Digits for input %d.",iInput);
366 treees = gime->TreeS();
370 printf("<AliTRDdigitizer::Exec> ");
371 printf("Input stream %d does not exist\n",iInput);
375 // Read the s-digits via digits manager
376 sdigitsManager = new AliTRDdigitsManager();
377 sdigitsManager->SetDebug(fDebug);
378 sdigitsManager->SetSDigits(kTRUE);
380 AliRunLoader* rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(iInput));
381 AliLoader* gimme = rl->GetLoader("TRDLoader");
382 if (!gimme->TreeS()) gimme->LoadSDigits();
383 sdigitsManager->ReadDigits(gimme->TreeS());
385 // Add the s-digits to the input list
386 AddSDigitsManager(sdigitsManager);
390 // Convert the s-digits to normal digits
392 printf("<AliTRDdigitizer::Exec> ");
393 printf("Do the conversion\n");
399 printf("<AliTRDdigitizer::Exec> ");
400 printf("Write the digits\n");
403 fDigitsManager->WriteDigits();
407 if (!gFile->Get("TRDParameter")) GetParameter()->Write();
410 printf("<AliTRDdigitizer::Exec> ");
414 DeleteSDigitsManager();
418 //_____________________________________________________________________________
419 Bool_t AliTRDdigitizer::Open(const Char_t *file, Int_t nEvent)
422 // Opens a ROOT-file with TRD-hits and reads in the hit-tree
425 // Connect the AliRoot file containing Geometry, Kine, and Hits
427 fRunLoader = AliRunLoader::Open(file,AliConfig::fgkDefaultEventFolderName,
432 Error("Open","Can not open session for file %s.",file);
436 fRunLoader->LoadgAlice();
437 gAlice = fRunLoader->GetAliRun();
441 printf("<AliTRDdigitizer::Open> ");
442 printf("AliRun object found on file.\n");
446 printf("<AliTRDdigitizer::Open> ");
447 printf("Could not find AliRun object.\n");
453 // Import the Trees for the event nEvent in the file
454 fRunLoader->GetEvent(fEvent);
456 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
459 Error("Open","Can not get TRD loader from Run Loader");
463 if (InitDetector()) {
467 //if we produce SDigits
468 tree = loader->TreeS();
471 loader->MakeTree("S");
472 tree = loader->TreeS();
476 {//if we produce Digits
477 tree = loader->TreeD();
480 loader->MakeTree("D");
481 tree = loader->TreeD();
484 return MakeBranch(tree);
492 //_____________________________________________________________________________
493 Bool_t AliTRDdigitizer::InitDetector()
496 // Sets the pointer to the TRD detector and the geometry
499 // Get the pointer to the detector class and check for version 1
500 fTRD = (AliTRD *) gAlice->GetDetector("TRD");
502 printf("<AliTRDdigitizer::InitDetector> ");
503 printf("No TRD module found\n");
506 if (fTRD->IsVersion() != 1) {
507 printf("<AliTRDdigitizer::InitDetector> ");
508 printf("TRD must be version 1 (slow simulator).\n");
513 fGeo = fTRD->GetGeometry();
515 printf("<AliTRDdigitizer::InitDetector> ");
516 printf("Geometry version %d\n",fGeo->IsVersion());
519 // Create a digits manager
520 delete fDigitsManager;
521 fDigitsManager = new AliTRDdigitsManager();
522 fDigitsManager->SetSDigits(fSDigits);
523 fDigitsManager->CreateArrays();
524 fDigitsManager->SetEvent(fEvent);
525 fDigitsManager->SetDebug(fDebug);
527 // The list for the input s-digits manager to be merged
528 if (fSDigitsManagerList) {
529 fSDigitsManagerList->Delete();
531 fSDigitsManagerList = new TList();
538 //_____________________________________________________________________________
539 Bool_t AliTRDdigitizer::MakeBranch(TTree* tree) const
542 // Create the branches for the digits array
545 return fDigitsManager->MakeBranch(tree);
549 //_____________________________________________________________________________
550 Bool_t AliTRDdigitizer::MakeDigits()
556 ///////////////////////////////////////////////////////////////
558 ///////////////////////////////////////////////////////////////
560 // Converts number of electrons to fC
561 const Double_t kEl2fC = 1.602E-19 * 1.0E15;
563 ///////////////////////////////////////////////////////////////
565 // Number of pads included in the pad response
566 const Int_t kNpad = 3;
568 // Number of track dictionary arrays
569 const Int_t kNDict = AliTRDdigitsManager::kNDict;
571 // Half the width of the amplification region
572 const Float_t kAmWidth = AliTRDgeometry::AmThick() / 2.;
574 Int_t iRow, iCol, iTime, iPad;
578 Int_t totalSizeDigits = 0;
579 Int_t totalSizeDict0 = 0;
580 Int_t totalSizeDict1 = 0;
581 Int_t totalSizeDict2 = 0;
583 Int_t timeTRDbeg = 0;
584 Int_t timeTRDend = 1;
589 Float_t padSignal[kNpad];
590 Float_t signalOld[kNpad];
592 AliTRDdataArrayF *signals = 0;
593 AliTRDdataArrayI *digits = 0;
594 AliTRDdataArrayI *dictionary[kNDict];
596 // Create a default parameter class if none is defined
598 fPar = new AliTRDparameter("TRDparameter","Standard TRD parameter");
600 printf("<AliTRDdigitizer::MakeDigits> ");
601 printf("Create the default parameter object\n");
605 // Create a container for the amplitudes
606 AliTRDsegmentArray *signalsArray
607 = new AliTRDsegmentArray("AliTRDdataArrayF"
608 ,AliTRDgeometry::Ndet());
611 timeTRDbeg = ((Int_t) (-fPar->GetTRFlo() / fPar->GetTimeBinSize())) - 1;
612 timeTRDend = ((Int_t) ( fPar->GetTRFhi() / fPar->GetTimeBinSize())) - 1;
614 printf("<AliTRDdigitizer::MakeDigits> ");
615 printf("Sample the TRF between -%d and %d\n",timeTRDbeg,timeTRDend);
619 Float_t elAttachProp = fPar->GetElAttachProp() / 100.;
622 printf("<AliTRDdigitizer::MakeDigits> ");
623 printf("No geometry defined\n");
628 printf("<AliTRDdigitizer::MakeDigits> ");
629 printf("Start creating digits.\n");
632 AliLoader* gimme = fRunLoader->GetLoader("TRDLoader");
633 if (!gimme->TreeH()) gimme->LoadHits();
634 TTree* hitTree = gimme->TreeH();
637 Error("MakeDigits","Can not get TreeH");
640 fTRD->SetTreeAddress();
642 // Get the number of entries in the hit tree
643 // (Number of primary particles creating a hit somewhere)
646 nTrack = (Int_t) hitTree->GetEntries();
648 printf("<AliTRDdigitizer::MakeDigits> ");
649 printf("Found %d primary particles\n",nTrack);
653 Int_t detectorOld = -1;
656 // Loop through all entries in the tree
657 for (Int_t iTrack = 0; iTrack < nTrack; iTrack++) {
661 nBytes += hitTree->GetEvent(iTrack);
664 // Loop through the TRD hits
666 AliTRDhit *hit = (AliTRDhit *) fTRD->FirstHit(-1);
675 Float_t q = hit->GetCharge();
676 Int_t track = hit->Track();
677 Int_t detector = hit->GetDetector();
678 Int_t plane = fGeo->GetPlane(detector);
679 Int_t sector = fGeo->GetSector(detector);
680 Int_t chamber = fGeo->GetChamber(detector);
681 Int_t nRowMax = fPar->GetRowMax(plane,chamber,sector);
682 Int_t nColMax = fPar->GetColMax(plane);
683 Int_t nTimeMax = fPar->GetTimeMax();
684 Int_t nTimeBefore = fPar->GetTimeBefore();
685 Int_t nTimeAfter = fPar->GetTimeAfter();
686 Int_t nTimeTotal = fPar->GetTimeTotal();
687 Float_t row0 = fPar->GetRow0(plane,chamber,sector);
688 Float_t col0 = fPar->GetCol0(plane);
689 Float_t time0 = fPar->GetTime0(plane);
690 Float_t rowPadSize = fPar->GetRowPadSize(plane,chamber,sector);
691 Float_t colPadSize = fPar->GetColPadSize(plane);
692 Float_t timeBinSize = fPar->GetTimeBinSize();
693 Float_t divideRow = 1.0 / rowPadSize;
694 Float_t divideCol = 1.0 / colPadSize;
695 Float_t divideTime = 1.0 / timeBinSize;
698 printf("Analyze hit no. %d ",iHit);
699 printf("-----------------------------------------------------------\n");
701 printf("plane = %d, sector = %d, chamber = %d\n"
702 ,plane,sector,chamber);
703 printf("nRowMax = %d, nColMax = %d, nTimeMax = %d\n"
704 ,nRowMax,nColMax,nTimeMax);
705 printf("nTimeBefore = %d, nTimeAfter = %d, nTimeTotal = %d\n"
706 ,nTimeBefore,nTimeAfter,nTimeTotal);
707 printf("row0 = %f, col0 = %f, time0 = %f\n"
709 printf("rowPadSize = %f, colPadSize = %f, timeBinSize = %f\n"
710 ,rowPadSize,colPadSize,timeBinSize);
713 // Don't analyze test hits and switched off detectors
714 if ((CheckDetector(plane,chamber,sector)) &&
715 (((Int_t) q) != 0)) {
717 if (detector != detectorOld) {
720 printf("<AliTRDdigitizer::MakeDigits> ");
721 printf("Get new container. New det = %d, Old det = %d\n"
722 ,detector,detectorOld);
724 // Compress the old one if enabled
725 if ((fCompress) && (detectorOld > -1)) {
727 printf("<AliTRDdigitizer::MakeDigits> ");
728 printf("Compress the old container ...");
730 signals->Compress(1,0);
731 for (iDict = 0; iDict < kNDict; iDict++) {
732 dictionary[iDict]->Compress(1,0);
734 if (fDebug > 1) printf("done\n");
736 // Get the new container
737 signals = (AliTRDdataArrayF *) signalsArray->At(detector);
738 if (signals->GetNtime() == 0) {
739 // Allocate a new one if not yet existing
741 printf("<AliTRDdigitizer::MakeDigits> ");
742 printf("Allocate a new container ... ");
744 signals->Allocate(nRowMax,nColMax,nTimeTotal);
746 else if (fSimpleSim) {
747 // Clear an old one for the simple simulation
749 printf("<AliTRDdigitizer::MakeDigits> ");
750 printf("Clear a old container ... ");
755 // Expand an existing one
758 printf("<AliTRDdigitizer::MakeDigits> ");
759 printf("Expand an existing container ... ");
764 // The same for the dictionary
766 for (iDict = 0; iDict < kNDict; iDict++) {
767 dictionary[iDict] = fDigitsManager->GetDictionary(detector,iDict);
768 if (dictionary[iDict]->GetNtime() == 0) {
769 dictionary[iDict]->Allocate(nRowMax,nColMax,nTimeTotal);
772 if (fCompress) dictionary[iDict]->Expand();
776 if (fDebug > 1) printf("done\n");
777 detectorOld = detector;
780 // Rotate the sectors on top of each other
787 fGeo->Rotate(detector,pos,rot);
790 // The driftlength. It is negative if the hit is in the
791 // amplification region.
792 Float_t driftlength = time0 - rot[0];
794 // Take also the drift in the amplification region into account
795 // The drift length is at the moment still the same, regardless of
796 // the position relativ to the wire. This non-isochronity needs still
797 // to be implemented.
798 Float_t driftlengthL = TMath::Abs(driftlength + kAmWidth);
799 if (fPar->ExBOn()) driftlengthL /= TMath::Sqrt(fPar->GetLorentzFactor());
801 // Loop over all electrons of this hit
802 // TR photons produce hits with negative charge
803 Int_t nEl = ((Int_t) TMath::Abs(q));
804 for (Int_t iEl = 0; iEl < nEl; iEl++) {
810 // Electron attachment
811 if (fPar->ElAttachOn()) {
812 if (gRandom->Rndm() < (driftlengthL * elAttachProp))
816 // Apply the diffusion smearing
817 if (fPar->DiffusionOn()) {
818 if (!(fPar->Diffusion(driftlengthL,xyz))) continue;
821 // Apply E x B effects (depends on drift direction)
823 if (!(fPar->ExB(driftlength+kAmWidth,xyz))) continue;
826 // The electron position after diffusion and ExB in pad coordinates
827 // The pad row (z-direction)
828 Float_t rowDist = xyz[2] - row0;
829 Int_t rowE = ((Int_t) (rowDist * divideRow));
830 if ((rowE < 0) || (rowE >= nRowMax)) continue;
831 Float_t rowOffset = ((((Float_t) rowE) + 0.5) * rowPadSize) - rowDist;
833 // The pad column (rphi-direction)
834 Float_t col0tilt = fPar->Col0Tilted(col0,rowOffset,plane);
835 Float_t colDist = xyz[1] - col0tilt;
836 Int_t colE = ((Int_t) (colDist * divideCol));
837 if ((colE < 0) || (colE >= nColMax)) continue;
838 Float_t colOffset = ((((Float_t) colE) + 0.5) * colPadSize) - colDist;
840 // The time bin (negative for hits in the amplification region)
841 // In the amplification region the electrons drift from both sides
842 // to the middle (anode wire plane)
843 Float_t timeDist = time0 - xyz[0];
844 Float_t timeOffset = 0;
848 timeE = ((Int_t) (timeDist * divideTime));
849 // The distance of the position to the middle of the timebin
850 timeOffset = ((((Float_t) timeE) + 0.5) * timeBinSize) - timeDist;
853 // Difference between half of the amplification gap width and
854 // the distance to the anode wire
855 Float_t anodeDist = kAmWidth - TMath::Abs(timeDist + kAmWidth);
857 timeE = -1 * (((Int_t ) (anodeDist * divideTime)) + 1);
858 // The distance of the position to the middle of the timebin
859 timeOffset = ((((Float_t) timeE) + 0.5) * timeBinSize) + anodeDist;
862 // Apply the gas gain including fluctuations
863 Float_t ggRndm = 0.0;
865 ggRndm = gRandom->Rndm();
866 } while (ggRndm <= 0);
867 Int_t signal = (Int_t) (-fPar->GetGasGain() * TMath::Log(ggRndm));
869 // Apply the pad response
871 // The distance of the electron to the center of the pad
872 // in units of pad width
873 Float_t dist = - colOffset * divideCol;
874 if (!(fPar->PadResponse(signal,dist,plane,padSignal))) continue;
878 padSignal[1] = signal;
882 // Sample the time response inside the drift region
883 // + additional time bins before and after.
884 // The sampling is done always in the middle of the time bin
885 for (Int_t iTimeBin = TMath::Max(timeE-timeTRDbeg, -nTimeBefore)
886 ;iTimeBin < TMath::Min(timeE+timeTRDend,nTimeMax+nTimeAfter )
889 // Apply the time response
890 Float_t timeResponse = 1.0;
891 Float_t crossTalk = 0.0;
892 Float_t time = (iTimeBin - timeE) * timeBinSize + timeOffset;
894 timeResponse = fPar->TimeResponse(time);
897 crossTalk = fPar->CrossTalk(time);
904 for (iPad = 0; iPad < kNpad; iPad++) {
906 Int_t colPos = colE + iPad - 1;
907 if (colPos < 0) continue;
908 if (colPos >= nColMax) break;
911 // Note: The time bin number is shifted by nTimeBefore to avoid negative
912 // time bins. This has to be subtracted later.
913 Int_t iCurrentTimeBin = iTimeBin + nTimeBefore;
914 signalOld[iPad] = signals->GetDataUnchecked(rowE,colPos,iCurrentTimeBin);
915 if( colPos != colE ) {
916 signalOld[iPad] += padSignal[iPad] * (timeResponse + crossTalk);
919 signalOld[iPad] += padSignal[iPad] * timeResponse;
921 signals->SetDataUnchecked(rowE,colPos,iCurrentTimeBin,signalOld[iPad]);
923 // Store the track index in the dictionary
924 // Note: We store index+1 in order to allow the array to be compressed
925 if ((signalOld[iPad] > 0) && (!fSimpleSim)) {
926 for (iDict = 0; iDict < kNDict; iDict++) {
927 Int_t oldTrack = dictionary[iDict]->GetDataUnchecked(rowE
930 if (oldTrack == track+1) break;
932 dictionary[iDict]->SetDataUnchecked(rowE,colPos,iCurrentTimeBin,track+1);
942 } // Loop: electrons of a single hit
944 } // If: detector and test hit
946 hit = (AliTRDhit *) fTRD->NextHit();
948 } // Loop: hits of one primary track
950 } // Loop: primary tracks
953 printf("<AliTRDdigitizer::MakeDigits> ");
954 printf("Finished analyzing %d hits\n",countHits);
957 // The coupling factor
958 Float_t coupling = fPar->GetPadCoupling()
959 * fPar->GetTimeCoupling();
961 // The conversion factor
962 Float_t convert = kEl2fC
963 * fPar->GetChipGain();
965 // Loop through all chambers to finalize the digits
967 Int_t iDetEnd = AliTRDgeometry::Ndet();
969 iDetBeg = fSimpleDet;
970 iDetEnd = iDetBeg + 1;
972 for (Int_t iDet = iDetBeg; iDet < iDetEnd; iDet++) {
974 Int_t plane = fGeo->GetPlane(iDet);
975 Int_t sector = fGeo->GetSector(iDet);
976 Int_t chamber = fGeo->GetChamber(iDet);
977 Int_t nRowMax = fPar->GetRowMax(plane,chamber,sector);
978 Int_t nColMax = fPar->GetColMax(plane);
979 Int_t nTimeMax = fPar->GetTimeMax();
980 Int_t nTimeTotal = fPar->GetTimeTotal();
982 Double_t *inADC = new Double_t[nTimeTotal];
983 Double_t *outADC = new Double_t[nTimeTotal];
986 printf("<AliTRDdigitizer::MakeDigits> ");
987 printf("Digitization for chamber %d\n",iDet);
990 // Add a container for the digits of this detector
991 digits = fDigitsManager->GetDigits(iDet);
992 // Allocate memory space for the digits buffer
993 if (digits->GetNtime() == 0) {
994 digits->Allocate(nRowMax,nColMax,nTimeTotal);
996 else if (fSimpleSim) {
1000 // Get the signal container
1001 signals = (AliTRDdataArrayF *) signalsArray->At(iDet);
1002 if (signals->GetNtime() == 0) {
1003 // Create missing containers
1004 signals->Allocate(nRowMax,nColMax,nTimeTotal);
1007 // Expand the container if neccessary
1008 if (fCompress) signals->Expand();
1010 // Create the missing dictionary containers
1012 for (iDict = 0; iDict < kNDict; iDict++) {
1013 dictionary[iDict] = fDigitsManager->GetDictionary(iDet,iDict);
1014 if (dictionary[iDict]->GetNtime() == 0) {
1015 dictionary[iDict]->Allocate(nRowMax,nColMax,nTimeTotal);
1022 // Don't create noise in detectors that are switched off
1023 if (CheckDetector(plane,chamber,sector)) {
1025 // Create the digits for this chamber
1026 for (iRow = 0; iRow < nRowMax; iRow++ ) {
1027 for (iCol = 0; iCol < nColMax; iCol++ ) {
1029 // Create summable digits
1032 for (iTime = 0; iTime < nTimeTotal; iTime++) {
1033 Float_t signalAmp = signals->GetDataUnchecked(iRow,iCol,iTime);
1034 signalAmp *= fSDigitsScale;
1035 signalAmp = TMath::Min(signalAmp,(Float_t) 1.0e9);
1036 Int_t adc = (Int_t) signalAmp;
1037 if (adc > 0) nDigits++;
1038 digits->SetDataUnchecked(iRow,iCol,iTime,adc);
1042 // Create normal digits
1045 for (iTime = 0; iTime < nTimeTotal; iTime++) {
1046 Float_t signalAmp = signals->GetDataUnchecked(iRow,iCol,iTime);
1047 // Pad and time coupling
1048 signalAmp *= coupling;
1049 // Add the noise, starting from minus ADC baseline in electrons
1050 Double_t baselineEl = fPar->GetADCbaseline() * (fPar->GetADCinRange()
1051 / fPar->GetADCoutRange())
1053 signalAmp = TMath::Max((Double_t) gRandom->Gaus(signalAmp,fPar->GetNoise())
1056 signalAmp *= convert;
1057 // Add ADC baseline in mV
1058 signalAmp += fPar->GetADCbaseline() * (fPar->GetADCinRange()
1059 / fPar->GetADCoutRange());
1060 // Convert to ADC counts. Set the overflow-bit fADCoutRange if the
1061 // signal is larger than fADCinRange
1063 if (signalAmp >= fPar->GetADCinRange()) {
1064 adc = ((Int_t) fPar->GetADCoutRange());
1067 adc = ((Int_t) (signalAmp * (fPar->GetADCoutRange()
1068 / fPar->GetADCinRange())));
1071 outADC[iTime] = adc;
1074 // Apply the tail cancelation via the digital filter
1076 DeConvExp(inADC,outADC,nTimeTotal,fPar->GetTCnexp());
1079 for (iTime = 0; iTime < nTimeTotal; iTime++) {
1080 // Store the amplitude of the digit if above threshold
1081 if (outADC[iTime] > fPar->GetADCthreshold()) {
1083 printf(" iRow = %d, iCol = %d, iTime = %d, adc = %f\n"
1084 ,iRow,iCol,iTime,outADC[iTime]);
1087 digits->SetDataUnchecked(iRow,iCol,iTime,((Int_t) outADC[iTime]));
1098 // Compress the arrays
1100 digits->Compress(1,0);
1101 for (iDict = 0; iDict < kNDict; iDict++) {
1102 dictionary[iDict]->Compress(1,0);
1105 totalSizeDigits += digits->GetSize();
1106 totalSizeDict0 += dictionary[0]->GetSize();
1107 totalSizeDict1 += dictionary[1]->GetSize();
1108 totalSizeDict2 += dictionary[2]->GetSize();
1110 Float_t nPixel = nRowMax * nColMax * nTimeMax;
1112 printf("<AliTRDdigitizer::MakeDigits> ");
1113 printf("Found %d digits in detector %d (%3.0f).\n"
1115 ,100.0 * ((Float_t) nDigits) / nPixel);
1118 if (fCompress) signals->Compress(1,0);
1128 delete signalsArray;
1133 printf("<AliTRDdigitizer::MakeDigits> ");
1134 printf("Total number of analyzed hits = %d\n",countHits);
1136 printf("<AliTRDdigitizer::MakeDigits> ");
1137 printf("Total digits data size = %d, %d, %d, %d\n",totalSizeDigits
1148 //_____________________________________________________________________________
1149 void AliTRDdigitizer::AddSDigitsManager(AliTRDdigitsManager *man)
1152 // Add a digits manager for s-digits to the input list.
1155 fSDigitsManagerList->Add(man);
1159 //_____________________________________________________________________________
1160 void AliTRDdigitizer::DeleteSDigitsManager()
1163 // Removes digits manager from the input list.
1166 fSDigitsManagerList->Delete();
1170 //_____________________________________________________________________________
1171 Bool_t AliTRDdigitizer::ConvertSDigits()
1174 // Converts s-digits to normal digits
1177 // Number of track dictionary arrays
1178 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1180 // Converts number of electrons to fC
1181 const Double_t kEl2fC = 1.602E-19 * 1.0E15;
1189 fPar = new AliTRDparameter("TRDparameter","Standard parameter");
1191 printf("<AliTRDdigitizer::ConvertSDigits> ");
1192 printf("Create the default parameter object\n");
1196 Double_t sDigitsScale = 1.0 / GetSDigitsScale();
1197 Double_t noise = fPar->GetNoise();
1198 Double_t padCoupling = fPar->GetPadCoupling();
1199 Double_t timeCoupling = fPar->GetTimeCoupling();
1200 Double_t chipGain = fPar->GetChipGain();
1201 Double_t coupling = padCoupling * timeCoupling;
1202 Double_t convert = kEl2fC * chipGain;
1203 Double_t adcInRange = fPar->GetADCinRange();
1204 Double_t adcOutRange = fPar->GetADCoutRange();
1205 Int_t adcThreshold = fPar->GetADCthreshold();
1206 Int_t adcBaseline = fPar->GetADCbaseline();
1208 AliTRDdataArrayI *digitsIn;
1209 AliTRDdataArrayI *digitsOut;
1210 AliTRDdataArrayI *dictionaryIn[kNDict];
1211 AliTRDdataArrayI *dictionaryOut[kNDict];
1213 // Loop through the detectors
1214 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) {
1217 printf("<AliTRDdigitizer::ConvertSDigits> ");
1218 printf("Convert detector %d to digits.\n",iDet);
1221 Int_t plane = fGeo->GetPlane(iDet);
1222 Int_t sector = fGeo->GetSector(iDet);
1223 Int_t chamber = fGeo->GetChamber(iDet);
1224 Int_t nRowMax = fPar->GetRowMax(plane,chamber,sector);
1225 Int_t nColMax = fPar->GetColMax(plane);
1226 Int_t nTimeTotal = fPar->GetTimeTotal();
1228 Double_t *inADC = new Double_t[nTimeTotal];
1229 Double_t *outADC = new Double_t[nTimeTotal];
1231 digitsIn = fSDigitsManager->GetDigits(iDet);
1233 digitsOut = fDigitsManager->GetDigits(iDet);
1234 digitsOut->Allocate(nRowMax,nColMax,nTimeTotal);
1235 for (iDict = 0; iDict < kNDict; iDict++) {
1236 dictionaryIn[iDict] = fSDigitsManager->GetDictionary(iDet,iDict);
1237 dictionaryIn[iDict]->Expand();
1238 dictionaryOut[iDict] = fDigitsManager->GetDictionary(iDet,iDict);
1239 dictionaryOut[iDict]->Allocate(nRowMax,nColMax,nTimeTotal);
1242 for (iRow = 0; iRow < nRowMax; iRow++ ) {
1243 for (iCol = 0; iCol < nColMax; iCol++ ) {
1245 for (iTime = 0; iTime < nTimeTotal; iTime++) {
1246 Double_t signal = (Double_t) digitsIn->GetDataUnchecked(iRow,iCol,iTime);
1247 signal *= sDigitsScale;
1248 // Pad and time coupling
1250 // Add the noise, starting from minus ADC baseline in electrons
1251 Double_t baselineEl = adcBaseline * (adcInRange / adcOutRange) / convert;
1252 signal = TMath::Max((Double_t) gRandom->Gaus(signal,noise),-baselineEl);
1255 // add ADC baseline in mV
1256 signal += adcBaseline * (adcInRange / adcOutRange);
1257 // Convert to ADC counts. Set the overflow-bit adcOutRange if the
1258 // signal is larger than adcInRange
1260 if (signal >= adcInRange) {
1261 adc = ((Int_t) adcOutRange);
1264 adc = ((Int_t) (signal * (adcOutRange / adcInRange)));
1267 outADC[iTime] = adc;
1270 // Apply the tail cancelation via the digital filter
1272 DeConvExp(inADC,outADC,nTimeTotal,fPar->GetTCnexp());
1275 for (iTime = 0; iTime < nTimeTotal; iTime++) {
1276 // Store the amplitude of the digit if above threshold
1277 if (outADC[iTime] > adcThreshold) {
1278 digitsOut->SetDataUnchecked(iRow,iCol,iTime,((Int_t) outADC[iTime]));
1279 // Copy the dictionary
1280 for (iDict = 0; iDict < kNDict; iDict++) {
1281 Int_t track = dictionaryIn[iDict]->GetDataUnchecked(iRow,iCol,iTime);
1282 dictionaryOut[iDict]->SetDataUnchecked(iRow,iCol,iTime,track);
1291 digitsIn->Compress(1,0);
1292 digitsOut->Compress(1,0);
1293 for (iDict = 0; iDict < kNDict; iDict++) {
1294 dictionaryIn[iDict]->Compress(1,0);
1295 dictionaryOut[iDict]->Compress(1,0);
1308 //_____________________________________________________________________________
1309 Bool_t AliTRDdigitizer::MergeSDigits()
1312 // Merges the input s-digits:
1313 // - The amplitude of the different inputs are summed up.
1314 // - Of the track IDs from the input dictionaries only one is
1315 // kept for each input. This works for maximal 3 different merged inputs.
1318 // Number of track dictionary arrays
1319 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1322 fPar = new AliTRDparameter("TRDparameter","Standard parameter");
1324 printf("<AliTRDdigitizer::MergeSDigits> ");
1325 printf("Create the default parameter object\n");
1332 AliTRDdataArrayI *digitsA;
1333 AliTRDdataArrayI *digitsB;
1334 AliTRDdataArrayI *dictionaryA[kNDict];
1335 AliTRDdataArrayI *dictionaryB[kNDict];
1337 // Get the first s-digits
1338 fSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->First();
1339 if (!fSDigitsManager) return kFALSE;
1341 // Loop through the other sets of s-digits
1342 AliTRDdigitsManager *mergeSDigitsManager;
1343 mergeSDigitsManager = (AliTRDdigitsManager *)
1344 fSDigitsManagerList->After(fSDigitsManager);
1347 if (mergeSDigitsManager) {
1348 printf("<AliTRDdigitizer::MergeSDigits> ");
1349 printf("Merge %d input files.\n",fSDigitsManagerList->GetSize());
1352 printf("<AliTRDdigitizer::MergeSDigits> ");
1353 printf("Only one input file.\n");
1358 while (mergeSDigitsManager) {
1362 // Loop through the detectors
1363 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) {
1365 Int_t plane = fGeo->GetPlane(iDet);
1366 Int_t sector = fGeo->GetSector(iDet);
1367 Int_t chamber = fGeo->GetChamber(iDet);
1368 Int_t nRowMax = fPar->GetRowMax(plane,chamber,sector);
1369 Int_t nColMax = fPar->GetColMax(plane);
1370 Int_t nTimeTotal = fPar->GetTimeTotal();
1372 // Loop through the pixels of one detector and add the signals
1373 digitsA = fSDigitsManager->GetDigits(iDet);
1374 digitsB = mergeSDigitsManager->GetDigits(iDet);
1377 for (iDict = 0; iDict < kNDict; iDict++) {
1378 dictionaryA[iDict] = fSDigitsManager->GetDictionary(iDet,iDict);
1379 dictionaryB[iDict] = mergeSDigitsManager->GetDictionary(iDet,iDict);
1380 dictionaryA[iDict]->Expand();
1381 dictionaryB[iDict]->Expand();
1384 // Merge only detectors that contain a signal
1385 Bool_t doMerge = kTRUE;
1386 if (fMergeSignalOnly) {
1387 if (digitsA->GetOverThreshold(0) == 0) {
1395 printf("<AliTRDdigitizer::MergeSDigits> ");
1396 printf("Merge detector %d of input no.%d\n",iDet,iMerge+1);
1399 for (Int_t iRow = 0; iRow < nRowMax; iRow++ ) {
1400 for (Int_t iCol = 0; iCol < nColMax; iCol++ ) {
1401 for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
1403 // Add the amplitudes of the summable digits
1404 Int_t ampA = digitsA->GetDataUnchecked(iRow,iCol,iTime);
1405 Int_t ampB = digitsB->GetDataUnchecked(iRow,iCol,iTime);
1407 digitsA->SetDataUnchecked(iRow,iCol,iTime,ampA);
1409 // Add the mask to the track id if defined.
1410 for (iDict = 0; iDict < kNDict; iDict++) {
1411 Int_t trackB = dictionaryB[iDict]->GetDataUnchecked(iRow,iCol,iTime);
1412 if ((fMasks) && (trackB > 0)) {
1413 for (jDict = 0; jDict < kNDict; jDict++) {
1414 Int_t trackA = dictionaryA[iDict]->GetDataUnchecked(iRow,iCol,iTime);
1416 trackA = trackB + fMasks[iMerge];
1417 dictionaryA[iDict]->SetDataUnchecked(iRow,iCol,iTime,trackA);
1430 digitsA->Compress(1,0);
1431 digitsB->Compress(1,0);
1432 for (iDict = 0; iDict < kNDict; iDict++) {
1433 dictionaryA[iDict]->Compress(1,0);
1434 dictionaryB[iDict]->Compress(1,0);
1440 // The next set of s-digits
1441 mergeSDigitsManager = (AliTRDdigitsManager *)
1442 fSDigitsManagerList->After(mergeSDigitsManager);
1450 //_____________________________________________________________________________
1451 Bool_t AliTRDdigitizer::SDigits2Digits()
1454 // Merges the input s-digits and converts them to normal digits
1457 if (!MergeSDigits()) return kFALSE;
1459 return ConvertSDigits();
1463 //_____________________________________________________________________________
1464 Bool_t AliTRDdigitizer::CheckDetector(Int_t plane, Int_t chamber, Int_t sector)
1467 // Checks whether a detector is enabled
1470 if (fSimpleSim) return kTRUE;
1472 if ((fTRD->GetSensChamber() >= 0) &&
1473 (fTRD->GetSensChamber() != chamber)) return kFALSE;
1474 if ((fTRD->GetSensPlane() >= 0) &&
1475 (fTRD->GetSensPlane() != plane)) return kFALSE;
1476 if ( fTRD->GetSensSector() >= 0) {
1477 Int_t sens1 = fTRD->GetSensSector();
1478 Int_t sens2 = sens1 + fTRD->GetSensSectorRange();
1479 sens2 -= ((Int_t) (sens2 / AliTRDgeometry::Nsect()))
1480 * AliTRDgeometry::Nsect();
1481 if (sens1 < sens2) {
1482 if ((sector < sens1) || (sector >= sens2)) return kFALSE;
1485 if ((sector < sens1) && (sector >= sens2)) return kFALSE;
1493 //_____________________________________________________________________________
1494 Bool_t AliTRDdigitizer::WriteDigits() const
1497 // Writes out the TRD-digits and the dictionaries
1500 // Store the digits and the dictionary in the tree
1501 return fDigitsManager->WriteDigits();
1505 //_____________________________________________________________________________
1506 void AliTRDdigitizer::DeConvExp(Double_t *source, Double_t *target
1507 , Int_t n, Int_t nexp)
1510 // Does the deconvolution by the digital filter.
1512 // Author: Marcus Gutfleisch, KIP Heidelberg
1513 // Optimized for: New TRF from Venelin Angelov, simulated with CADENCE
1514 // Pad-ground capacitance = 25 pF
1515 // Pad-pad cross talk capacitance = 6 pF
1516 // For 10 MHz digitization, corresponding to 20 time bins
1517 // in the drift region
1521 Double_t coefficients[2];
1523 /* initialize (coefficient = alpha, rates = lambda) */
1526 rates[0] = 0.466998;
1528 coefficients[0] = 1.0;
1531 rates[0] = 0.8988162;
1532 coefficients[0] = 0.11392069;
1533 rates[1] = 0.3745688;
1534 coefficients[1] = 0.8860793;
1536 Float_t sumc = coefficients[0]+coefficients[1];
1537 coefficients[0] /= sumc;
1538 coefficients[1] /= sumc;
1542 Double_t reminder[2];
1543 Double_t correction, result;
1545 /* attention: computation order is important */
1547 for ( k = 0; k < nexp; k++ ) reminder[k]=0.0;
1549 for ( i = 0; i < n; i++ ) {
1550 result = ( source[i] - correction ); /* no rescaling */
1553 for ( k = 0; k < nexp; k++ ) reminder[k] = rates[k]
1554 * ( reminder[k] + coefficients[k] * result);
1557 for ( k = 0; k < nexp; k++ ) correction += reminder[k];
1562 //_____________________________________________________________________________
1563 void AliTRDdigitizer::InitOutput(Int_t iEvent)
1566 // Initializes the output branches
1573 Error("InitOutput","Run Loader is NULL");
1576 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
1579 Error("Open","Can not get TRD loader from Run Loader");
1587 //if we produce SDigits
1588 tree = loader->TreeS();
1591 loader->MakeTree("S");
1592 tree = loader->TreeS();
1596 {//if we produce Digits
1597 tree = loader->TreeD();
1600 loader->MakeTree("D");
1601 tree = loader->TreeD();
1604 fDigitsManager->SetEvent(iEvent);
1605 fDigitsManager->MakeBranch(tree);