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 //
22 // Authors: C. Blume (blume@ikf.uni-frankfurt.de) //
26 // The following effects are included: //
29 // - Gas gain including fluctuations //
30 // - Pad-response (simple Gaussian approximation) //
32 // - Electronics noise //
33 // - Electronics gain //
35 // - Zero suppression //
37 ////////////////////////////////////////////////////////////////////////////
41 #include <TGeoGlobalMagField.h>
42 #include <TGeoManager.h>
53 #include "AliRunLoader.h"
54 #include "AliLoader.h"
55 #include "AliConfig.h"
57 #include "AliRunDigitizer.h"
58 #include "AliRunLoader.h"
59 #include "AliLoader.h"
62 #include "AliTRDhit.h"
63 #include "AliTRDdigitizer.h"
65 #include "AliTRDarrayDictionary.h"
66 #include "AliTRDarrayADC.h"
67 #include "AliTRDarraySignal.h"
68 #include "AliTRDdigitsManager.h"
69 #include "AliTRDgeometry.h"
70 #include "AliTRDpadPlane.h"
71 #include "AliTRDcalibDB.h"
72 #include "AliTRDSimParam.h"
73 #include "AliTRDCommonParam.h"
74 #include "AliTRDfeeParam.h"
75 #include "AliTRDmcmSim.h"
76 #include "Cal/AliTRDCalROC.h"
77 #include "Cal/AliTRDCalDet.h"
79 ClassImp(AliTRDdigitizer)
81 //_____________________________________________________________________________
82 AliTRDdigitizer::AliTRDdigitizer()
87 ,fSDigitsManagerList(0)
94 ,fMergeSignalOnly(kFALSE)
97 // AliTRDdigitizer default constructor
104 //_____________________________________________________________________________
105 AliTRDdigitizer::AliTRDdigitizer(const Text_t *name, const Text_t *title)
106 :AliDigitizer(name,title)
110 ,fSDigitsManagerList(0)
117 ,fMergeSignalOnly(kFALSE)
120 // AliTRDdigitizer constructor
127 //_____________________________________________________________________________
128 AliTRDdigitizer::AliTRDdigitizer(AliRunDigitizer *manager
129 , const Text_t *name, const Text_t *title)
130 :AliDigitizer(manager,name,title)
134 ,fSDigitsManagerList(0)
141 ,fMergeSignalOnly(kFALSE)
144 // AliTRDdigitizer constructor
151 //_____________________________________________________________________________
152 AliTRDdigitizer::AliTRDdigitizer(AliRunDigitizer *manager)
153 :AliDigitizer(manager,"AliTRDdigitizer","TRD digitizer")
157 ,fSDigitsManagerList(0)
164 ,fMergeSignalOnly(kFALSE)
167 // AliTRDdigitizer constructor
174 //_____________________________________________________________________________
175 Bool_t AliTRDdigitizer::Init()
178 // Initialize the digitizer with default values
184 fSDigitsManagerList = 0;
192 fMergeSignalOnly = kFALSE;
194 return AliDigitizer::Init();
198 //_____________________________________________________________________________
199 AliTRDdigitizer::AliTRDdigitizer(const AliTRDdigitizer &d)
204 ,fSDigitsManagerList(0)
209 ,fCompress(d.fCompress)
210 ,fSDigits(d.fSDigits)
211 ,fMergeSignalOnly(d.fMergeSignalOnly)
214 // AliTRDdigitizer copy constructor
219 //_____________________________________________________________________________
220 AliTRDdigitizer::~AliTRDdigitizer()
223 // AliTRDdigitizer destructor
226 if (fDigitsManager) {
227 delete fDigitsManager;
231 if (fDigitsManager) { //typo? fSDigitsManager?
232 delete fSDigitsManager;
236 if (fSDigitsManagerList) {
237 fSDigitsManagerList->Delete();
238 delete fSDigitsManagerList;
239 fSDigitsManagerList = 0;
254 //_____________________________________________________________________________
255 AliTRDdigitizer &AliTRDdigitizer::operator=(const AliTRDdigitizer &d)
258 // Assignment operator
262 ((AliTRDdigitizer &) d).Copy(*this);
269 //_____________________________________________________________________________
270 void AliTRDdigitizer::Copy(TObject &d) const
276 ((AliTRDdigitizer &) d).fRunLoader = 0;
277 ((AliTRDdigitizer &) d).fDigitsManager = 0;
278 ((AliTRDdigitizer &) d).fSDigitsManager = 0;
279 ((AliTRDdigitizer &) d).fSDigitsManagerList = 0;
280 ((AliTRDdigitizer &) d).fTRD = 0;
281 ((AliTRDdigitizer &) d).fGeo = 0;
282 ((AliTRDdigitizer &) d).fEvent = 0;
283 ((AliTRDdigitizer &) d).fMasks = 0;
284 ((AliTRDdigitizer &) d).fCompress = fCompress;
285 ((AliTRDdigitizer &) d).fSDigits = fSDigits;
286 ((AliTRDdigitizer &) d).fMergeSignalOnly = fMergeSignalOnly;
288 AliTRDdigitizer& target = (AliTRDdigitizer &) d;
292 //_____________________________________________________________________________
293 void AliTRDdigitizer::Exec(Option_t *option)
296 // Executes the merging
301 AliTRDdigitsManager *sdigitsManager;
303 TString optionString = option;
304 if (optionString.Contains("deb")) {
305 AliLog::SetClassDebugLevel("AliTRDdigitizer",1);
306 AliInfo("Called with debug option");
309 // The AliRoot file is already connected by the manager
310 AliRunLoader *inrl = 0x0;
313 AliDebug(1,"AliRun object found on file.");
316 inrl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
318 gAlice = inrl->GetAliRun();
320 AliError("Could not find AliRun object.")
325 Int_t nInput = fManager->GetNinputs();
326 fMasks = new Int_t[nInput];
327 for (iInput = 0; iInput < nInput; iInput++) {
328 fMasks[iInput] = fManager->GetMask(iInput);
335 AliRunLoader *orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
337 if (InitDetector()) {
339 AliLoader *ogime = orl->GetLoader("TRDLoader");
343 // If we produce SDigits
344 tree = ogime->TreeS();
346 ogime->MakeTree("S");
347 tree = ogime->TreeS();
351 // If we produce Digits
352 tree = ogime->TreeD();
354 ogime->MakeTree("D");
355 tree = ogime->TreeD();
363 for (iInput = 0; iInput < nInput; iInput++) {
365 AliDebug(1,Form("Add input stream %d",iInput));
367 // Check if the input tree exists
368 inrl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(iInput));
369 AliLoader *gime = inrl->GetLoader("TRDLoader");
371 TTree *treees = gime->TreeS();
373 if (gime->LoadSDigits()) {
374 AliError(Form("Error Occured while loading S. Digits for input %d.",iInput));
377 treees = gime->TreeS();
381 AliError(Form("Input stream %d does not exist",iInput));
385 // Read the s-digits via digits manager
386 sdigitsManager = new AliTRDdigitsManager();
387 sdigitsManager->SetSDigits(kTRUE);
389 AliRunLoader *rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(iInput));
390 AliLoader *gimme = rl->GetLoader("TRDLoader");
393 gimme->LoadSDigits();
396 sdigitsManager->ReadDigits(gimme->TreeS());
398 // Add the s-digits to the input list
399 AddSDigitsManager(sdigitsManager);
403 // Convert the s-digits to normal digits
404 AliDebug(1,"Do the conversion");
408 AliDebug(1,"Write the digits");
409 fDigitsManager->WriteDigits();
415 DeleteSDigitsManager();
421 //_____________________________________________________________________________
422 Bool_t AliTRDdigitizer::Open(const Char_t *file, Int_t nEvent)
425 // Opens a ROOT-file with TRD-hits and reads in the hit-tree
427 // Connect the AliRoot file containing Geometry, Kine, and Hits
430 TString evfoldname = AliConfig::GetDefaultEventFolderName();
432 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
434 fRunLoader = AliRunLoader::Open(file,evfoldname,"UPDATE");
437 AliError(Form("Can not open session for file %s.",file));
441 if (!fRunLoader->GetAliRun()) {
442 fRunLoader->LoadgAlice();
444 gAlice = fRunLoader->GetAliRun();
447 AliDebug(1,"AliRun object found on file.");
450 AliError("Could not find AliRun object.");
456 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
458 AliError("Can not get TRD loader from Run Loader");
462 if (InitDetector()) {
465 // If we produce SDigits
466 tree = loader->TreeS();
468 loader->MakeTree("S");
469 tree = loader->TreeS();
473 // If we produce Digits
474 tree = loader->TreeD();
476 loader->MakeTree("D");
477 tree = loader->TreeD();
480 return MakeBranch(tree);
488 //_____________________________________________________________________________
489 Bool_t AliTRDdigitizer::Open(AliRunLoader *runLoader, Int_t nEvent)
492 // Opens a ROOT-file with TRD-hits and reads in the hit-tree
494 // Connect the AliRoot file containing Geometry, Kine, and Hits
497 fRunLoader = runLoader;
499 AliError("RunLoader does not exist");
503 if (!fRunLoader->GetAliRun()) {
504 fRunLoader->LoadgAlice();
506 gAlice = fRunLoader->GetAliRun();
509 AliDebug(1,"AliRun object found on file.");
512 AliError("Could not find AliRun object.");
518 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
520 AliError("Can not get TRD loader from Run Loader");
524 if (InitDetector()) {
527 // If we produce SDigits
528 tree = loader->TreeS();
530 loader->MakeTree("S");
531 tree = loader->TreeS();
535 // If we produce Digits
536 tree = loader->TreeD();
538 loader->MakeTree("D");
539 tree = loader->TreeD();
542 return MakeBranch(tree);
550 //_____________________________________________________________________________
551 Bool_t AliTRDdigitizer::InitDetector()
554 // Sets the pointer to the TRD detector and the geometry
557 // Get the pointer to the detector class and check for version 1
558 fTRD = (AliTRD *) gAlice->GetDetector("TRD");
560 AliFatal("No TRD module found");
563 if (fTRD->IsVersion() != 1) {
564 AliFatal("TRD must be version 1 (slow simulator)");
569 fGeo = new AliTRDgeometry();
571 // Create a digits manager
572 if (fDigitsManager) {
573 delete fDigitsManager;
575 fDigitsManager = new AliTRDdigitsManager();
576 fDigitsManager->SetSDigits(fSDigits);
577 fDigitsManager->CreateArrays();
578 fDigitsManager->SetEvent(fEvent);
580 // The list for the input s-digits manager to be merged
581 if (fSDigitsManagerList) {
582 fSDigitsManagerList->Delete();
585 fSDigitsManagerList = new TList();
591 //_____________________________________________________________________________
592 Bool_t AliTRDdigitizer::MakeBranch(TTree *tree) const
595 // Create the branches for the digits array
598 return fDigitsManager->MakeBranch(tree);
602 //_____________________________________________________________________________
603 void AliTRDdigitizer::AddSDigitsManager(AliTRDdigitsManager *man)
606 // Add a digits manager for s-digits to the input list.
609 fSDigitsManagerList->Add(man);
613 //_____________________________________________________________________________
614 void AliTRDdigitizer::DeleteSDigitsManager()
617 // Removes digits manager from the input list.
620 fSDigitsManagerList->Delete();
624 //_____________________________________________________________________________
625 Bool_t AliTRDdigitizer::MakeDigits()
631 AliDebug(1,"Start creating digits");
634 AliError("No geometry defined");
638 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
640 AliFatal("Could not get calibration object");
644 const Int_t kNdet = AliTRDgeometry::Ndet();
646 Float_t **hits = new Float_t*[kNdet];
647 Int_t *nhit = new Int_t[kNdet];
649 AliTRDarraySignal *signals = 0x0;
651 // Sort all hits according to detector number
652 if (!SortHits(hits,nhit)) {
653 AliError("Sorting hits failed");
657 // Loop through all detectors
658 for (Int_t det = 0; det < kNdet; det++) {
660 // Detectors that are switched off, not installed, etc.
661 if (( calibration->IsChamberInstalled(det)) &&
662 (!calibration->IsChamberMasked(det)) &&
663 ( fGeo->ChamberInGeometry(det)) &&
666 signals = new AliTRDarraySignal();
668 // Convert the hits of the current detector to detector signals
669 if (!ConvertHits(det,hits[det],nhit[det],signals)) {
670 AliError(Form("Conversion of hits failed for detector=%d",det));
673 // Convert the detector signals to digits or s-digits
674 if (!ConvertSignals(det,signals)) {
675 AliError(Form("Conversion of signals failed for detector=%d",det));
679 // Delete the signals array
683 } // if: detector status
696 //_____________________________________________________________________________
697 Bool_t AliTRDdigitizer::SortHits(Float_t **hits, Int_t *nhit)
700 // Read all the hits and sorts them according to detector number
701 // in the output array <hits>.
704 AliDebug(1,"Start sorting hits");
706 const Int_t kNdet = AliTRDgeometry::Ndet();
707 // Size of the hit vector
708 const Int_t kNhit = 6;
713 Int_t *lhit = new Int_t[kNdet];
715 for (Int_t det = 0; det < kNdet; det++) {
721 AliLoader *gimme = fRunLoader->GetLoader("TRDLoader");
722 if (!gimme->TreeH()) {
725 TTree *hitTree = gimme->TreeH();
726 if (hitTree == 0x0) {
727 AliError("Can not get TreeH");
730 fTRD->SetTreeAddress();
732 // Get the number of entries in the hit tree
733 // (Number of primary particles creating a hit somewhere)
734 Int_t nTrk = (Int_t) hitTree->GetEntries();
735 AliDebug(1,Form("Found %d tracks",nTrk));
737 // Loop through all the tracks in the tree
738 for (Int_t iTrk = 0; iTrk < nTrk; iTrk++) {
740 gAlice->GetMCApp()->ResetHits();
741 hitTree->GetEvent(iTrk);
744 AliError(Form("No hits array for track = %d",iTrk));
748 // Number of hits for this track
749 nhitTrk = fTRD->Hits()->GetEntriesFast();
752 // Loop through the TRD hits
753 AliTRDhit *hit = (AliTRDhit *) fTRD->FirstHit(-1);
758 // Don't analyze test hits
759 if (((Int_t) hit->GetCharge()) != 0) {
761 Int_t trk = hit->Track();
762 Int_t det = hit->GetDetector();
763 Int_t q = hit->GetCharge();
764 Float_t x = hit->X();
765 Float_t y = hit->Y();
766 Float_t z = hit->Z();
767 Float_t time = hit->GetTime();
769 if (nhit[det] == lhit[det]) {
770 // Inititialization of new detector
771 xyz = new Float_t[kNhit*(nhitTrk+lhit[det])];
773 memcpy(xyz,hits[det],sizeof(Float_t)*kNhit*lhit[det]);
776 lhit[det] += nhitTrk;
782 xyz[nhit[det]*kNhit+0] = x;
783 xyz[nhit[det]*kNhit+1] = y;
784 xyz[nhit[det]*kNhit+2] = z;
785 xyz[nhit[det]*kNhit+3] = q;
786 xyz[nhit[det]*kNhit+4] = trk;
787 xyz[nhit[det]*kNhit+5] = time;
792 hit = (AliTRDhit *) fTRD->NextHit();
794 } // for: hits of one track
804 //_____________________________________________________________________________
805 Bool_t AliTRDdigitizer::ConvertHits(Int_t det, Float_t *hits, Int_t nhit
806 , AliTRDarraySignal *signals)
809 // Converts the detectorwise sorted hits to detector signals
812 AliDebug(1,Form("Start converting hits for detector=%d (nhits=%d)",det,nhit));
814 // Number of pads included in the pad response
815 const Int_t kNpad = 3;
816 // Number of track dictionary arrays
817 const Int_t kNdict = AliTRDdigitsManager::kNDict;
818 // Size of the hit vector
819 const Int_t kNhit = 6;
821 // Width of the amplification region
822 const Float_t kAmWidth = AliTRDgeometry::AmThick();
823 // Width of the drift region
824 const Float_t kDrWidth = AliTRDgeometry::DrThick();
825 // Drift + amplification region
826 const Float_t kDrMin = - 0.5 * kAmWidth;
827 const Float_t kDrMax = kDrWidth + 0.5 * kAmWidth;
831 Int_t timeBinTRFend = 1;
835 Double_t padSignal[kNpad];
836 Double_t signalOld[kNpad];
838 AliTRDarrayDictionary *dictionary[kNdict];
840 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
841 AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance();
842 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
845 AliFatal("Could not get common parameterss");
849 AliFatal("Could not get simulation parameters");
853 AliFatal("Could not get calibration object");
857 // Get the detector wise calibration objects
858 AliTRDCalROC *calVdriftROC = 0;
859 Float_t calVdriftDetValue = 0.0;
860 const AliTRDCalDet *calVdriftDet = calibration->GetVdriftDet();
861 AliTRDCalROC *calT0ROC = 0;
862 Float_t calT0DetValue = 0.0;
863 const AliTRDCalDet *calT0Det = calibration->GetT0Det();
865 if (simParam->TRFOn()) {
866 timeBinTRFend = ((Int_t) (simParam->GetTRFhi()
867 * commonParam->GetSamplingFrequency())) - 1;
870 Int_t nTimeTotal = calibration->GetNumberOfTimeBins();
871 Float_t samplingRate = commonParam->GetSamplingFrequency();
872 Float_t elAttachProp = simParam->GetElAttachProp() / 100.0;
874 AliTRDpadPlane *padPlane = fGeo->GetPadPlane(det);
875 Int_t layer = fGeo->GetLayer(det); //update
876 Float_t row0 = padPlane->GetRow0ROC();
877 Int_t nRowMax = padPlane->GetNrows();
878 Int_t nColMax = padPlane->GetNcols();
880 // Create a new array for the signals
881 signals->Allocate(nRowMax,nColMax,nTimeTotal);
883 // Create a new array for the dictionary
884 for (dict = 0; dict < kNdict; dict++) {
885 dictionary[dict] = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
886 dictionary[dict]->Allocate(nRowMax,nColMax,nTimeTotal);
889 // Loop through the hits in this detector
890 for (Int_t hit = 0; hit < nhit; hit++) {
892 pos[0] = hits[hit*kNhit+0];
893 pos[1] = hits[hit*kNhit+1];
894 pos[2] = hits[hit*kNhit+2];
895 Float_t q = hits[hit*kNhit+3];
896 Float_t hittime = hits[hit*kNhit+5];
897 Int_t track = ((Int_t) hits[hit*kNhit+4]);
901 // Find the current volume with the geo manager
902 gGeoManager->SetCurrentPoint(pos);
903 gGeoManager->FindNode();
904 if (strstr(gGeoManager->GetPath(),"/UK")) {
908 // Get the calibration objects
909 calVdriftROC = calibration->GetVdriftROC(det);
910 calVdriftDetValue = calVdriftDet->GetValue(det);
911 calT0ROC = calibration->GetT0ROC(det);
912 calT0DetValue = calT0Det->GetValue(det);
914 // Go to the local coordinate system:
915 // loc[0] - col direction in amplification or driftvolume
916 // loc[1] - row direction in amplification or driftvolume
917 // loc[2] - time direction in amplification or driftvolume
918 gGeoManager->MasterToLocal(pos,loc);
920 // Relative to middle of amplification region
921 loc[2] = loc[2] - kDrWidth/2.0 - kAmWidth/2.0;
924 // The driftlength [cm] (w/o diffusion yet !).
925 // It is negative if the hit is between pad plane and anode wires.
926 Double_t driftlength = -1.0 * loc[2];
928 // Stupid patch to take care of TR photons that are absorbed
929 // outside the chamber volume. A real fix would actually need
930 // a more clever implementation of the TR hit generation
932 if ((loc[1] < padPlane->GetRowEndROC()) ||
933 (loc[1] > padPlane->GetRow0ROC())) {
936 if ((driftlength < kDrMin) ||
937 (driftlength > kDrMax)) {
942 // Get row and col of unsmeared electron to retrieve drift velocity
943 // The pad row (z-direction)
944 Int_t rowE = padPlane->GetPadRowNumberROC(loc[1]);
948 Double_t rowOffset = padPlane->GetPadRowOffsetROC(rowE,loc[1]);
949 // The pad column (rphi-direction)
950 Double_t offsetTilt = padPlane->GetTiltOffset(rowOffset);
951 Int_t colE = padPlane->GetPadColNumber(loc[0]+offsetTilt);
955 Double_t colOffset = 0.0;
957 // Normalized drift length
958 Float_t driftvelocity = calVdriftDetValue * calVdriftROC->GetValue(colE,rowE);
959 Double_t absdriftlength = TMath::Abs(driftlength);
960 if (commonParam->ExBOn()) {
961 absdriftlength /= TMath::Sqrt(GetLorentzFactor(driftvelocity));
964 // Loop over all electrons of this hit
965 // TR photons produce hits with negative charge
966 Int_t nEl = ((Int_t) TMath::Abs(q));
967 for (Int_t iEl = 0; iEl < nEl; iEl++) {
969 // Now the real local coordinate system of the ROC
970 // column direction: locC
971 // row direction: locR
972 // time direction: locT
973 // locR and locC are identical to the coordinates of the corresponding
974 // volumina of the drift or amplification region.
975 // locT is defined relative to the wire plane (i.e. middle of amplification
976 // region), meaning locT = 0, and is negative for hits coming from the
978 Double_t locC = loc[0];
979 Double_t locR = loc[1];
980 Double_t locT = loc[2];
982 // Electron attachment
983 if (simParam->ElAttachOn()) {
984 if (gRandom->Rndm() < (absdriftlength * elAttachProp)) {
989 // Apply the diffusion smearing
990 if (simParam->DiffusionOn()) {
991 if (!(Diffusion(driftvelocity,absdriftlength,locR,locC,locT))) {
996 // Apply E x B effects (depends on drift direction)
997 if (commonParam->ExBOn()) {
998 if (!(ExB(driftvelocity,driftlength,locC))) {
1003 // The electron position after diffusion and ExB in pad coordinates.
1004 // The pad row (z-direction)
1005 rowE = padPlane->GetPadRowNumberROC(locR);
1006 if (rowE < 0) continue;
1007 rowOffset = padPlane->GetPadRowOffsetROC(rowE,locR);
1009 // The pad column (rphi-direction)
1010 offsetTilt = padPlane->GetTiltOffset(rowOffset);
1011 colE = padPlane->GetPadColNumber(locC+offsetTilt);
1012 if (colE < 0) continue;
1013 colOffset = padPlane->GetPadColOffset(colE,locC+offsetTilt);
1015 // Also re-retrieve drift velocity because col and row may have changed
1016 driftvelocity = calVdriftDetValue * calVdriftROC->GetValue(colE,rowE);
1017 Float_t t0 = calT0DetValue + calT0ROC->GetValue(colE,rowE);
1019 // Convert the position to drift time [mus], using either constant drift velocity or
1020 // time structure of drift cells (non-isochronity, GARFIELD calculation).
1021 // Also add absolute time of hits to take pile-up events into account properly
1023 if (simParam->TimeStructOn()) {
1024 // Get z-position with respect to anode wire
1025 Double_t zz = row0 - locR + padPlane->GetAnodeWireOffset();
1026 zz -= ((Int_t)(2 * zz)) / 2.0;
1030 // Use drift time map (GARFIELD)
1031 drifttime = commonParam->TimeStruct(driftvelocity,0.5*kAmWidth-1.0*locT,zz)
1035 // Use constant drift velocity
1036 drifttime = TMath::Abs(locT) / driftvelocity
1040 // Apply the gas gain including fluctuations
1041 Double_t ggRndm = 0.0;
1043 ggRndm = gRandom->Rndm();
1044 } while (ggRndm <= 0);
1045 Double_t signal = -(simParam->GetGasGain()) * TMath::Log(ggRndm);
1047 // Apply the pad response
1048 if (simParam->PRFOn()) {
1049 // The distance of the electron to the center of the pad
1050 // in units of pad width
1051 Double_t dist = (colOffset - 0.5*padPlane->GetColSize(colE))
1052 / padPlane->GetColSize(colE);
1053 // This is a fixed parametrization, i.e. not dependent on
1054 // calibration values !
1055 if (!(calibration->PadResponse(signal,dist,layer,padSignal))) continue;
1059 padSignal[1] = signal;
1063 // The time bin (always positive), with t0 distortion
1064 Double_t timeBinIdeal = drifttime * samplingRate + t0;
1066 if (TMath::Abs(timeBinIdeal) > 2*nTimeTotal) {
1067 timeBinIdeal = 2 * nTimeTotal;
1069 Int_t timeBinTruncated = ((Int_t) timeBinIdeal);
1070 // The distance of the position to the middle of the timebin
1071 Double_t timeOffset = ((Float_t) timeBinTruncated
1072 + 0.5 - timeBinIdeal) / samplingRate;
1074 // Sample the time response inside the drift region
1075 // + additional time bins before and after.
1076 // The sampling is done always in the middle of the time bin
1077 for (Int_t iTimeBin = TMath::Max(timeBinTruncated,0)
1078 ;iTimeBin < TMath::Min(timeBinTruncated+timeBinTRFend,nTimeTotal)
1081 // Apply the time response
1082 Double_t timeResponse = 1.0;
1083 Double_t crossTalk = 0.0;
1084 Double_t time = (iTimeBin - timeBinTruncated) / samplingRate + timeOffset;
1086 if (simParam->TRFOn()) {
1087 timeResponse = simParam->TimeResponse(time);
1089 if (simParam->CTOn()) {
1090 crossTalk = simParam->CrossTalk(time);
1097 for (iPad = 0; iPad < kNpad; iPad++) {
1099 Int_t colPos = colE + iPad - 1;
1100 if (colPos < 0) continue;
1101 if (colPos >= nColMax) break;
1104 signalOld[iPad] = signals->GetData(rowE,colPos,iTimeBin);
1106 if (colPos != colE) {
1107 // Cross talk added to non-central pads
1108 signalOld[iPad] += padSignal[iPad]
1109 * (timeResponse + crossTalk);
1112 // W/o cross talk at central pad
1113 signalOld[iPad] += padSignal[iPad]
1117 signals->SetData(rowE,colPos,iTimeBin,signalOld[iPad]);
1119 // Store the track index in the dictionary
1120 // Note: We store index+1 in order to allow the array to be compressed
1121 // Note2: Taking out the +1 in track
1122 if (signalOld[iPad] > 0.0) {
1123 for (dict = 0; dict < kNdict; dict++) {
1124 Int_t oldTrack = dictionary[dict]->GetData(rowE,colPos,iTimeBin);
1125 if (oldTrack == track) break;
1126 if (oldTrack == -1 ) {
1127 dictionary[dict]->SetData(rowE,colPos,iTimeBin,track);
1135 } // Loop: time bins
1137 } // Loop: electrons of a single hit
1141 AliDebug(2,Form("Finished analyzing %d hits",nhit));
1147 //_____________________________________________________________________________
1148 Bool_t AliTRDdigitizer::ConvertSignals(Int_t det, AliTRDarraySignal *signals)
1151 // Convert signals to digits
1154 AliDebug(1,Form("Start converting the signals for detector %d",det));
1157 // Convert the signal array to s-digits
1158 if (!Signal2SDigits(det,signals)) {
1163 // Convert the signal array to digits
1164 if (!Signal2ADC(det,signals)) {
1169 // Compress the arrays
1170 CompressOutputArrays(det);
1176 //_____________________________________________________________________________
1177 Bool_t AliTRDdigitizer::Signal2ADC(Int_t det, AliTRDarraySignal *signals)
1180 // Converts the sampled electron signals to ADC values for a given chamber
1183 AliDebug(1,Form("Start converting signals to ADC values for detector=%d",det));
1185 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1187 AliFatal("Could not get calibration object");
1191 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
1193 AliFatal("Could not get simulation parameters");
1197 // Converts number of electrons to fC
1198 const Double_t kEl2fC = 1.602e-19 * 1.0e15;
1201 Double_t coupling = simParam->GetPadCoupling()
1202 * simParam->GetTimeCoupling();
1203 // Electronics conversion factor
1204 Double_t convert = kEl2fC
1205 * simParam->GetChipGain();
1206 // ADC conversion factor
1207 Double_t adcConvert = simParam->GetADCoutRange()
1208 / simParam->GetADCinRange();
1209 // The electronics baseline in mV
1210 Double_t baseline = simParam->GetADCbaseline()
1212 // The electronics baseline in electrons
1213 Double_t baselineEl = baseline
1220 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1221 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1222 Int_t nTimeTotal = calibration->GetNumberOfTimeBins();
1224 // The gainfactor calibration objects
1225 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
1226 AliTRDCalROC *calGainFactorROC = 0;
1227 Float_t calGainFactorDetValue = 0.0;
1229 AliTRDarrayADC *digits = 0x0;
1232 AliError(Form("Signals array for detector %d does not exist\n",det));
1235 if (signals->HasData()) {
1236 // Expand the container if neccessary
1240 // Create missing containers
1241 signals->Allocate(nRowMax,nColMax,nTimeTotal);
1244 // Get the container for the digits of this detector
1245 if (fDigitsManager->HasSDigits()) {
1246 AliError("Digits manager has s-digits");
1250 digits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det);
1251 // Allocate memory space for the digits buffer
1252 if (!digits->HasData()) {
1253 digits->Allocate(nRowMax,nColMax,nTimeTotal);
1256 // Get the calibration objects
1257 calGainFactorROC = calibration->GetGainFactorROC(det);
1258 calGainFactorDetValue = calGainFactorDet->GetValue(det);
1260 // Create the digits for this chamber
1261 for (row = 0; row < nRowMax; row++ ) {
1262 for (col = 0; col < nColMax; col++ ) {
1264 // Check whether pad is masked
1265 // Bridged pads are not considered yet!!!
1266 if (calibration->IsPadMasked(det,col,row)) {
1271 Float_t padgain = calGainFactorDetValue
1272 * calGainFactorROC->GetValue(col,row);
1274 AliError(Form("Not a valid gain %f, %d %d %d",padgain,det,col,row));
1277 for (time = 0; time < nTimeTotal; time++) {
1279 // Get the signal amplitude
1280 Float_t signalAmp = signals->GetData(row,col,time);
1281 // Pad and time coupling
1282 signalAmp *= coupling;
1284 signalAmp *= padgain;
1286 // Add the noise, starting from minus ADC baseline in electrons
1287 signalAmp = TMath::Max((Double_t) gRandom->Gaus(signalAmp,simParam->GetNoise())
1291 signalAmp *= convert;
1292 // Add ADC baseline in mV
1293 signalAmp += baseline;
1295 // Convert to ADC counts. Set the overflow-bit fADCoutRange if the
1296 // signal is larger than fADCinRange
1298 if (signalAmp >= simParam->GetADCinRange()) {
1299 adc = ((Short_t) simParam->GetADCoutRange());
1302 adc = TMath::Nint(signalAmp * adcConvert);
1305 // Saving all digits
1306 digits->SetData(row,col,time,adc);
1313 // Run the digital processing in the MCM
1314 RunDigitalProcessing(digits, det);
1320 //_____________________________________________________________________________
1321 Bool_t AliTRDdigitizer::Signal2SDigits(Int_t det, AliTRDarraySignal *signals)
1324 // Converts the sampled electron signals to s-digits
1327 AliDebug(1,Form("Start converting signals to s-digits for detector=%d",det));
1329 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1331 AliFatal("Could not get calibration object");
1339 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1340 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1341 Int_t nTimeTotal = calibration->GetNumberOfTimeBins();
1343 // Get the container for the digits of this detector
1345 if (!fDigitsManager->HasSDigits()) {
1346 AliError("Digits manager has no s-digits");
1350 AliTRDarraySignal *digits = (AliTRDarraySignal *) fDigitsManager->GetSDigits(det);
1351 // Allocate memory space for the digits buffer
1352 if (!digits->HasData()) {
1353 digits->Allocate(nRowMax,nColMax,nTimeTotal);
1356 // Create the sdigits for this chamber
1357 for (row = 0; row < nRowMax; row++ ) {
1358 for (col = 0; col < nColMax; col++ ) {
1359 for (time = 0; time < nTimeTotal; time++) {
1360 digits->SetData(row,col,time,signals->GetData(row,col,time));
1369 //_____________________________________________________________________________
1370 Bool_t AliTRDdigitizer::SDigits2Digits()
1373 // Merges the input s-digits and converts them to normal digits
1376 if (!MergeSDigits()) {
1380 return ConvertSDigits();
1384 //_____________________________________________________________________________
1385 Bool_t AliTRDdigitizer::MergeSDigits()
1388 // Merges the input s-digits:
1389 // - The amplitude of the different inputs are summed up.
1390 // - Of the track IDs from the input dictionaries only one is
1391 // kept for each input. This works for maximal 3 different merged inputs.
1394 // Number of track dictionary arrays
1395 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1397 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
1399 AliFatal("Could not get simulation parameters");
1403 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1405 AliFatal("Could not get calibration object");
1412 AliTRDarraySignal *digitsA;
1413 AliTRDarraySignal *digitsB;
1414 AliTRDarrayDictionary *dictionaryA[kNDict];
1415 AliTRDarrayDictionary *dictionaryB[kNDict];
1417 AliTRDdigitsManager *mergeSDigitsManager = 0x0;
1418 // Get the first s-digits
1419 fSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->First();
1420 if (!fSDigitsManager) {
1421 AliError("No SDigits manager");
1425 // Loop through the other sets of s-digits
1426 mergeSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->After(fSDigitsManager);
1428 if (mergeSDigitsManager) {
1429 AliDebug(1,Form("Merge %d input files.",fSDigitsManagerList->GetSize()));
1432 AliDebug(1,"Only one input file.");
1435 Int_t nTimeTotal = calibration->GetNumberOfTimeBins();
1438 while (mergeSDigitsManager) {
1442 // Loop through the detectors
1443 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) {
1445 Int_t nRowMax = fGeo->GetPadPlane(iDet)->GetNrows();
1446 Int_t nColMax = fGeo->GetPadPlane(iDet)->GetNcols();
1448 // Loop through the pixels of one detector and add the signals
1449 digitsA = (AliTRDarraySignal *) fSDigitsManager->GetSDigits(iDet);
1450 digitsB = (AliTRDarraySignal *) mergeSDigitsManager->GetSDigits(iDet);
1452 if (!digitsA->HasData()) continue;
1454 if (!digitsB->HasData()) continue;
1456 for (iDict = 0; iDict < kNDict; iDict++) {
1457 dictionaryA[iDict] = (AliTRDarrayDictionary *) fSDigitsManager->GetDictionary(iDet,iDict);
1458 dictionaryB[iDict] = (AliTRDarrayDictionary *) mergeSDigitsManager->GetDictionary(iDet,iDict);
1459 dictionaryA[iDict]->Expand();
1460 dictionaryB[iDict]->Expand();
1463 // Merge only detectors that contain a signal
1464 Bool_t doMerge = kTRUE;
1465 if (fMergeSignalOnly) {
1466 if (digitsA->GetOverThreshold(0) == 0) {
1473 AliDebug(1,Form("Merge detector %d of input no.%d",iDet,iMerge+1));
1475 for (Int_t iRow = 0; iRow < nRowMax; iRow++ ) {
1476 for (Int_t iCol = 0; iCol < nColMax; iCol++ ) {
1477 for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
1479 // Add the amplitudes of the summable digits
1480 Float_t ampA = digitsA->GetData(iRow,iCol,iTime);
1481 Float_t ampB = digitsB->GetData(iRow,iCol,iTime);
1483 digitsA->SetData(iRow,iCol,iTime,ampA);
1485 // Add the mask to the track id if defined.
1486 for (iDict = 0; iDict < kNDict; iDict++) {
1487 Int_t trackB = dictionaryB[iDict]->GetData(iRow,iCol,iTime);
1488 if ((fMasks) && (trackB > 0)) {
1489 for (jDict = 0; jDict < kNDict; jDict++) {
1490 Int_t trackA = dictionaryA[iDict]->GetData(iRow,iCol,iTime);
1492 trackA = trackB + fMasks[iMerge];
1493 dictionaryA[iDict]->SetData(iRow,iCol,iTime,trackA);
1494 } // if: track A == 0
1496 } // if: fMasks and trackB > 0
1505 mergeSDigitsManager->RemoveDigits(iDet);
1506 mergeSDigitsManager->RemoveDictionaries(iDet);
1509 digitsA->Compress(0);
1510 for (iDict = 0; iDict < kNDict; iDict++) {
1511 dictionaryA[iDict]->Compress();
1517 // The next set of s-digits
1518 mergeSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->After(mergeSDigitsManager);
1520 } // while: mergeDigitsManagers
1526 //_____________________________________________________________________________
1527 Bool_t AliTRDdigitizer::ConvertSDigits()
1530 // Converts s-digits to normal digits
1533 AliTRDarraySignal *digitsIn = 0x0;
1535 if (!fSDigitsManager->HasSDigits()) {
1536 AliError("No s-digits in digits manager");
1540 // Loop through the detectors
1541 for (Int_t det = 0; det < AliTRDgeometry::Ndet(); det++) {
1543 // Get the merged s-digits (signals)
1544 digitsIn = (AliTRDarraySignal *) fSDigitsManager->GetSDigits(det);
1545 if (!digitsIn->HasData()) {
1546 AliDebug(2,Form("No digits for det=%d",det));
1550 // Convert the merged sdigits to digits
1551 if (!Signal2ADC(det,digitsIn)) {
1555 // Copy the dictionary information to the output array
1556 if (!CopyDictionary(det)) {
1561 fSDigitsManager->RemoveDigits(det);
1562 fSDigitsManager->RemoveDictionaries(det);
1564 // Compress the arrays
1565 CompressOutputArrays(det);
1567 } // for: detector numbers
1574 //_____________________________________________________________________________
1575 Bool_t AliTRDdigitizer::CopyDictionary(Int_t det)
1578 // Copies the dictionary information from the s-digits arrays
1579 // to the output arrays
1582 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1584 AliFatal("Could not get calibration object");
1588 AliDebug(1,Form("Start copying dictionaries for detector=%d",det));
1590 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1591 AliTRDarrayDictionary *dictionaryIn[kNDict];
1592 AliTRDarrayDictionary *dictionaryOut[kNDict];
1594 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1595 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1596 Int_t nTimeTotal = calibration->GetNumberOfTimeBins();
1603 for (dict = 0; dict < kNDict; dict++) {
1605 dictionaryIn[dict] = (AliTRDarrayDictionary *) fSDigitsManager->GetDictionary(det,dict);
1606 dictionaryIn[dict]->Expand();
1607 dictionaryOut[dict] = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
1608 dictionaryOut[dict]->Allocate(nRowMax,nColMax,nTimeTotal);
1610 for (row = 0; row < nRowMax; row++) {
1611 for (col = 0; col < nColMax; col++) {
1612 for (time = 0; time < nTimeTotal; time++) {
1613 Int_t track = dictionaryIn[dict]->GetData(row,col,time);
1614 dictionaryOut[dict]->SetData(row,col,time,track);
1619 } // for: dictionaries
1625 //_____________________________________________________________________________
1626 void AliTRDdigitizer::CompressOutputArrays(Int_t det)
1629 // Compress the output arrays
1632 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1633 AliTRDarrayDictionary *dictionary = 0x0;
1638 AliTRDarrayADC *digits = 0x0;
1639 digits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det);
1644 AliTRDarraySignal *digits = 0x0;
1645 digits = (AliTRDarraySignal *) fDigitsManager->GetSDigits(det);
1646 digits->Compress(0);
1649 for (Int_t dict = 0; dict < kNDict; dict++) {
1650 dictionary = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
1651 dictionary->Compress();
1658 //_____________________________________________________________________________
1659 Bool_t AliTRDdigitizer::WriteDigits() const
1662 // Writes out the TRD-digits and the dictionaries
1666 fRunLoader->CdGAFile();
1668 // Store the digits and the dictionary in the tree
1669 return fDigitsManager->WriteDigits();
1673 //_____________________________________________________________________________
1674 void AliTRDdigitizer::InitOutput(Int_t iEvent)
1677 // Initializes the output branches
1683 AliError("Run Loader is NULL");
1687 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
1689 AliError("Can not get TRD loader from Run Loader");
1696 // If we produce SDigits
1697 tree = loader->TreeS();
1699 loader->MakeTree("S");
1700 tree = loader->TreeS();
1704 // If we produce Digits
1705 tree = loader->TreeD();
1707 loader->MakeTree("D");
1708 tree = loader->TreeD();
1711 fDigitsManager->SetEvent(iEvent);
1712 fDigitsManager->MakeBranch(tree);
1716 //_____________________________________________________________________________
1717 Int_t AliTRDdigitizer::Diffusion(Float_t vdrift, Double_t absdriftlength
1718 , Double_t &lRow, Double_t &lCol, Double_t &lTime)
1721 // Applies the diffusion smearing to the position of a single electron.
1722 // Depends on absolute drift length.
1725 Float_t diffL = 0.0;
1726 Float_t diffT = 0.0;
1728 if (AliTRDCommonParam::Instance()->GetDiffCoeff(diffL,diffT,vdrift)) {
1730 Float_t driftSqrt = TMath::Sqrt(absdriftlength);
1731 Float_t sigmaT = driftSqrt * diffT;
1732 Float_t sigmaL = driftSqrt * diffL;
1733 lRow = gRandom->Gaus(lRow ,sigmaT);
1734 lCol = gRandom->Gaus(lCol ,sigmaT * GetLorentzFactor(vdrift));
1735 lTime = gRandom->Gaus(lTime,sigmaL * GetLorentzFactor(vdrift));
1748 //_____________________________________________________________________________
1749 Float_t AliTRDdigitizer::GetLorentzFactor(Float_t vd)
1752 // Returns the Lorentz factor
1755 Double_t omegaTau = AliTRDCommonParam::Instance()->GetOmegaTau(vd);
1756 Double_t lorentzFactor = 1.0;
1757 if (AliTRDCommonParam::Instance()->ExBOn()) {
1758 lorentzFactor = 1.0 / (1.0 + omegaTau*omegaTau);
1761 return lorentzFactor;
1765 //_____________________________________________________________________________
1766 Int_t AliTRDdigitizer::ExB(Float_t vdrift, Double_t driftlength, Double_t &lCol)
1769 // Applies E x B effects to the position of a single electron.
1770 // Depends on signed drift length.
1774 + AliTRDCommonParam::Instance()->GetOmegaTau(vdrift)
1781 //_____________________________________________________________________________
1782 void AliTRDdigitizer::RunDigitalProcessing(AliTRDarrayADC *digits, Int_t det)
1785 // Run the digital processing in the TRAP
1788 AliTRDfeeParam *feeParam = AliTRDfeeParam::Instance();
1790 //Create and initialize the mcm object
1791 AliTRDmcmSim* mcmfast = new AliTRDmcmSim();
1793 //Call the methods in the mcm class using the temporary array as input
1794 for(Int_t rob = 0; rob < digits->GetNrow() / 4; rob++)
1796 for(Int_t mcm = 0; mcm < 16; mcm++)
1798 mcmfast->Init(det, rob, mcm);
1799 mcmfast->SetData(digits);
1801 if (feeParam->GetTracklet())
1802 mcmfast->Tracklet();
1803 mcmfast->ZSMapping();
1804 mcmfast->WriteData(digits);