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 ////////////////////////////////////////////////////////////////////////////
39 #include <TGeoManager.h>
47 #include "AliRunLoader.h"
48 #include "AliLoader.h"
49 #include "AliConfig.h"
50 #include "AliRunDigitizer.h"
51 #include "AliRunLoader.h"
52 #include "AliLoader.h"
56 #include "AliTRDhit.h"
57 #include "AliTRDdigitizer.h"
58 #include "AliTRDarrayDictionary.h"
59 #include "AliTRDarrayADC.h"
60 #include "AliTRDarraySignal.h"
61 #include "AliTRDdigitsManager.h"
62 #include "AliTRDgeometry.h"
63 #include "AliTRDpadPlane.h"
64 #include "AliTRDcalibDB.h"
65 #include "AliTRDSimParam.h"
66 #include "AliTRDCommonParam.h"
67 #include "AliTRDfeeParam.h"
68 #include "AliTRDmcmSim.h"
69 #include "AliTRDdigitsParam.h"
71 #include "Cal/AliTRDCalROC.h"
72 #include "Cal/AliTRDCalDet.h"
73 #include "Cal/AliTRDCalOnlineGainTableROC.h"
75 ClassImp(AliTRDdigitizer)
77 //_____________________________________________________________________________
78 AliTRDdigitizer::AliTRDdigitizer()
83 ,fSDigitsManagerList(0)
86 ,fMcmSim(new AliTRDmcmSim)
91 ,fMergeSignalOnly(kFALSE)
94 // AliTRDdigitizer default constructor
99 //_____________________________________________________________________________
100 AliTRDdigitizer::AliTRDdigitizer(const Text_t *name, const Text_t *title)
101 :AliDigitizer(name,title)
105 ,fSDigitsManagerList(0)
108 ,fMcmSim(new AliTRDmcmSim)
113 ,fMergeSignalOnly(kFALSE)
116 // AliTRDdigitizer constructor
121 //_____________________________________________________________________________
122 AliTRDdigitizer::AliTRDdigitizer(AliRunDigitizer *manager
123 , const Text_t *name, const Text_t *title)
124 :AliDigitizer(manager,name,title)
128 ,fSDigitsManagerList(0)
131 ,fMcmSim(new AliTRDmcmSim)
136 ,fMergeSignalOnly(kFALSE)
139 // AliTRDdigitizer constructor
144 //_____________________________________________________________________________
145 AliTRDdigitizer::AliTRDdigitizer(AliRunDigitizer *manager)
146 :AliDigitizer(manager,"AliTRDdigitizer","TRD digitizer")
150 ,fSDigitsManagerList(0)
153 ,fMcmSim(new AliTRDmcmSim)
158 ,fMergeSignalOnly(kFALSE)
161 // AliTRDdigitizer constructor
166 //_____________________________________________________________________________
167 AliTRDdigitizer::AliTRDdigitizer(const AliTRDdigitizer &d)
172 ,fSDigitsManagerList(0)
175 ,fMcmSim(new AliTRDmcmSim)
178 ,fCompress(d.fCompress)
179 ,fSDigits(d.fSDigits)
180 ,fMergeSignalOnly(d.fMergeSignalOnly)
183 // AliTRDdigitizer copy constructor
188 //_____________________________________________________________________________
189 AliTRDdigitizer::~AliTRDdigitizer()
192 // AliTRDdigitizer destructor
195 if (fDigitsManager) {
196 delete fDigitsManager;
200 if (fSDigitsManager) {
201 // s-digitsmanager will be deleted via list
205 if (fSDigitsManagerList) {
206 fSDigitsManagerList->Delete();
207 delete fSDigitsManagerList;
208 fSDigitsManagerList = 0;
228 //_____________________________________________________________________________
229 AliTRDdigitizer &AliTRDdigitizer::operator=(const AliTRDdigitizer &d)
232 // Assignment operator
236 ((AliTRDdigitizer &) d).Copy(*this);
243 //_____________________________________________________________________________
244 void AliTRDdigitizer::Copy(TObject &d) const
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).fEvent = 0;
257 ((AliTRDdigitizer &) d).fMasks = 0;
258 ((AliTRDdigitizer &) d).fCompress = fCompress;
259 ((AliTRDdigitizer &) d).fSDigits = fSDigits;
260 ((AliTRDdigitizer &) d).fMergeSignalOnly = fMergeSignalOnly;
264 //_____________________________________________________________________________
265 void AliTRDdigitizer::Exec(const Option_t * const option)
268 // Executes the merging
273 AliTRDdigitsManager *sdigitsManager;
275 TString optionString = option;
276 if (optionString.Contains("deb")) {
277 AliLog::SetClassDebugLevel("AliTRDdigitizer",1);
278 AliInfo("Called with debug option");
281 // The AliRoot file is already connected by the manager
282 AliRunLoader *inrl = 0x0;
285 AliDebug(1,"AliRun object found on file.");
288 inrl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
290 gAlice = inrl->GetAliRun();
292 AliError("Could not find AliRun object.");
297 Int_t nInput = fManager->GetNinputs();
298 fMasks = new Int_t[nInput];
299 for (iInput = 0; iInput < nInput; iInput++) {
300 fMasks[iInput] = fManager->GetMask(iInput);
307 AliRunLoader *orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
309 if (InitDetector()) {
311 AliLoader *ogime = orl->GetLoader("TRDLoader");
315 // If we produce SDigits
316 tree = ogime->TreeS();
318 ogime->MakeTree("S");
319 tree = ogime->TreeS();
323 // If we produce Digits
324 tree = ogime->TreeD();
326 ogime->MakeTree("D");
327 tree = ogime->TreeD();
335 for (iInput = 0; iInput < nInput; iInput++) {
337 AliDebug(1,Form("Add input stream %d",iInput));
339 // Check if the input tree exists
340 inrl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(iInput));
341 AliLoader *gime = inrl->GetLoader("TRDLoader");
343 TTree *treees = gime->TreeS();
345 if (gime->LoadSDigits()) {
346 AliError(Form("Error Occured while loading S. Digits for input %d.",iInput));
349 treees = gime->TreeS();
353 AliError(Form("Input stream %d does not exist",iInput));
357 // Read the s-digits via digits manager
358 sdigitsManager = new AliTRDdigitsManager();
359 sdigitsManager->SetSDigits(kTRUE);
361 AliRunLoader *rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(iInput));
362 AliLoader *gimme = rl->GetLoader("TRDLoader");
365 gimme->LoadSDigits();
368 sdigitsManager->ReadDigits(gimme->TreeS());
370 // Add the s-digits to the input list
371 AddSDigitsManager(sdigitsManager);
375 // Convert the s-digits to normal digits
376 AliDebug(1,"Do the conversion");
380 AliDebug(1,"Write the digits");
381 fDigitsManager->WriteDigits();
387 DeleteSDigitsManager();
393 //_____________________________________________________________________________
394 Bool_t AliTRDdigitizer::Open(const Char_t *file, Int_t nEvent)
397 // Opens a ROOT-file with TRD-hits and reads in the hit-tree
399 // Connect the AliRoot file containing Geometry, Kine, and Hits
402 TString evfoldname = AliConfig::GetDefaultEventFolderName();
404 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
406 fRunLoader = AliRunLoader::Open(file,evfoldname,"UPDATE");
409 AliError(Form("Can not open session for file %s.",file));
413 if (!fRunLoader->GetAliRun()) {
414 fRunLoader->LoadgAlice();
416 gAlice = fRunLoader->GetAliRun();
419 AliDebug(1,"AliRun object found on file.");
422 AliError("Could not find AliRun object.");
428 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
430 AliError("Can not get TRD loader from Run Loader");
434 if (InitDetector()) {
437 // If we produce SDigits
438 tree = loader->TreeS();
440 loader->MakeTree("S");
441 tree = loader->TreeS();
445 // If we produce Digits
446 tree = loader->TreeD();
448 loader->MakeTree("D");
449 tree = loader->TreeD();
452 return MakeBranch(tree);
460 //_____________________________________________________________________________
461 Bool_t AliTRDdigitizer::Open(AliRunLoader * const runLoader, Int_t nEvent)
464 // Opens a ROOT-file with TRD-hits and reads in the hit-tree
466 // Connect the AliRoot file containing Geometry, Kine, and Hits
469 fRunLoader = runLoader;
471 AliError("RunLoader does not exist");
475 if (!fRunLoader->GetAliRun()) {
476 fRunLoader->LoadgAlice();
478 gAlice = fRunLoader->GetAliRun();
481 AliDebug(1,"AliRun object found on file.");
484 AliError("Could not find AliRun object.");
490 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
492 AliError("Can not get TRD loader from Run Loader");
496 if (InitDetector()) {
499 // If we produce SDigits
500 tree = loader->TreeS();
502 loader->MakeTree("S");
503 tree = loader->TreeS();
507 // If we produce Digits
508 tree = loader->TreeD();
510 loader->MakeTree("D");
511 tree = loader->TreeD();
514 return MakeBranch(tree);
522 //_____________________________________________________________________________
523 Bool_t AliTRDdigitizer::InitDetector()
526 // Sets the pointer to the TRD detector and the geometry
529 // Get the pointer to the detector class and check for version 1
530 fTRD = (AliTRD *) gAlice->GetDetector("TRD");
532 AliFatal("No TRD module found");
535 if (fTRD->IsVersion() != 1) {
536 AliFatal("TRD must be version 1 (slow simulator)");
541 fGeo = new AliTRDgeometry();
543 // Create a digits manager
544 if (fDigitsManager) {
545 delete fDigitsManager;
547 fDigitsManager = new AliTRDdigitsManager();
548 fDigitsManager->SetSDigits(fSDigits);
549 fDigitsManager->CreateArrays();
550 fDigitsManager->SetEvent(fEvent);
552 // The list for the input s-digits manager to be merged
553 if (fSDigitsManagerList) {
554 fSDigitsManagerList->Delete();
557 fSDigitsManagerList = new TList();
564 //_____________________________________________________________________________
565 Bool_t AliTRDdigitizer::MakeBranch(TTree *tree) const
568 // Create the branches for the digits array
571 return fDigitsManager->MakeBranch(tree);
575 //_____________________________________________________________________________
576 void AliTRDdigitizer::AddSDigitsManager(AliTRDdigitsManager *man)
579 // Add a digits manager for s-digits to the input list.
582 fSDigitsManagerList->Add(man);
586 //_____________________________________________________________________________
587 void AliTRDdigitizer::DeleteSDigitsManager()
590 // Removes digits manager from the input list.
593 fSDigitsManagerList->Delete();
597 //_____________________________________________________________________________
598 Bool_t AliTRDdigitizer::MakeDigits()
604 AliDebug(1,"Start creating digits");
607 AliError("No geometry defined");
611 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
613 AliFatal("Could not get calibration object");
617 const Int_t kNdet = AliTRDgeometry::Ndet();
619 Float_t **hits = new Float_t*[kNdet];
620 Int_t *nhit = new Int_t[kNdet];
622 AliTRDarraySignal *signals = 0x0;
624 // Check the number of time bins from simParam against OCDB,
625 // if OCDB value is not supposed to be used.
626 // As default, the value from OCDB is taken
627 if (AliTRDSimParam::Instance()->GetNTBoverwriteOCDB()) {
628 if (calibration->GetNumberOfTimeBinsDCS() != AliTRDSimParam::Instance()->GetNTimeBins()) {
629 AliWarning(Form("Number of time bins is different to OCDB value [SIM=%d, OCDB=%d]"
630 ,AliTRDSimParam::Instance()->GetNTimeBins()
631 ,calibration->GetNumberOfTimeBinsDCS()));
633 // Save the values for the raw data headers
634 fDigitsManager->GetDigitsParam()->SetNTimeBinsAll(AliTRDSimParam::Instance()->GetNTimeBins());
637 // Save the values for the raw data headers
638 fDigitsManager->GetDigitsParam()->SetNTimeBinsAll(calibration->GetNumberOfTimeBinsDCS());
641 // Save the values for the raw data headers
642 fDigitsManager->GetDigitsParam()->SetADCbaselineAll(AliTRDSimParam::Instance()->GetADCbaseline());
644 // Sort all hits according to detector number
645 if (!SortHits(hits,nhit)) {
646 AliError("Sorting hits failed");
652 // Loop through all detectors
653 for (Int_t det = 0; det < kNdet; det++) {
655 // Detectors that are switched off, not installed, etc.
656 if (( calibration->IsChamberInstalled(det)) &&
657 (!calibration->IsChamberMasked(det)) &&
658 ( fGeo->ChamberInGeometry(det)) &&
661 signals = new AliTRDarraySignal();
663 // Convert the hits of the current detector to detector signals
664 if (!ConvertHits(det,hits[det],nhit[det],signals)) {
665 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));
683 // Delete the signals array
687 } // if: detector status
694 if (AliDataLoader *trklLoader
695 = AliRunLoader::Instance()->GetLoader("TRDLoader")->GetDataLoader("tracklets")) {
696 if (trklLoader->Tree())
697 trklLoader->WriteData("OVERWRITE");
708 //_____________________________________________________________________________
709 Bool_t AliTRDdigitizer::SortHits(Float_t **hits, Int_t *nhit)
712 // Read all the hits and sorts them according to detector number
713 // in the output array <hits>.
716 AliDebug(1,"Start sorting hits");
718 const Int_t kNdet = AliTRDgeometry::Ndet();
719 // Size of the hit vector
720 const Int_t kNhit = 6;
725 Int_t *lhit = new Int_t[kNdet];
727 for (Int_t det = 0; det < kNdet; det++) {
733 AliLoader *gimme = fRunLoader->GetLoader("TRDLoader");
734 if (!gimme->TreeH()) {
737 TTree *hitTree = gimme->TreeH();
738 if (hitTree == 0x0) {
739 AliError("Can not get TreeH");
743 fTRD->SetTreeAddress();
745 // Get the number of entries in the hit tree
746 // (Number of primary particles creating a hit somewhere)
747 Int_t nTrk = (Int_t) hitTree->GetEntries();
748 AliDebug(1,Form("Found %d tracks",nTrk));
750 // Loop through all the tracks in the tree
751 for (Int_t iTrk = 0; iTrk < nTrk; iTrk++) {
753 gAlice->GetMCApp()->ResetHits();
754 hitTree->GetEvent(iTrk);
757 AliError(Form("No hits array for track = %d",iTrk));
761 // Number of hits for this track
762 nhitTrk = fTRD->Hits()->GetEntriesFast();
765 // Loop through the TRD hits
766 AliTRDhit *hit = (AliTRDhit *) fTRD->FirstHit(-1);
771 // Don't analyze test hits
772 if (((Int_t) hit->GetCharge()) != 0) {
774 Int_t trk = hit->Track();
775 Int_t det = hit->GetDetector();
776 Int_t q = hit->GetCharge();
777 Float_t x = hit->X();
778 Float_t y = hit->Y();
779 Float_t z = hit->Z();
780 Float_t time = hit->GetTime();
782 if (nhit[det] == lhit[det]) {
783 // Inititialization of new detector
784 xyz = new Float_t[kNhit*(nhitTrk+lhit[det])];
786 memcpy(xyz,hits[det],sizeof(Float_t)*kNhit*lhit[det]);
789 lhit[det] += nhitTrk;
795 xyz[nhit[det]*kNhit+0] = x;
796 xyz[nhit[det]*kNhit+1] = y;
797 xyz[nhit[det]*kNhit+2] = z;
798 xyz[nhit[det]*kNhit+3] = q;
799 xyz[nhit[det]*kNhit+4] = trk;
800 xyz[nhit[det]*kNhit+5] = time;
805 hit = (AliTRDhit *) fTRD->NextHit();
807 } // for: hits of one track
817 //_____________________________________________________________________________
818 Bool_t AliTRDdigitizer::ConvertHits(Int_t det
819 , const Float_t * const hits
821 , AliTRDarraySignal *signals)
824 // Converts the detectorwise sorted hits to detector signals
827 AliDebug(1,Form("Start converting hits for detector=%d (nhits=%d)",det,nhit));
829 // Number of pads included in the pad response
830 const Int_t kNpad = 3;
831 // Number of track dictionary arrays
832 const Int_t kNdict = AliTRDdigitsManager::kNDict;
833 // Size of the hit vector
834 const Int_t kNhit = 6;
836 // Width of the amplification region
837 const Float_t kAmWidth = AliTRDgeometry::AmThick();
838 // Width of the drift region
839 const Float_t kDrWidth = AliTRDgeometry::DrThick();
840 // Drift + amplification region
841 const Float_t kDrMin = - 0.5 * kAmWidth;
842 const Float_t kDrMax = kDrWidth + 0.5 * kAmWidth;
846 Int_t timeBinTRFend = 1;
850 Double_t padSignal[kNpad];
851 Double_t signalOld[kNpad];
853 AliTRDarrayDictionary *dictionary[kNdict];
855 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
856 AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance();
857 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
860 AliFatal("Could not get common parameterss");
864 AliFatal("Could not get simulation parameters");
868 AliFatal("Could not get calibration object");
872 // Get the detector wise calibration objects
873 AliTRDCalROC *calVdriftROC = 0;
874 Float_t calVdriftDetValue = 0.0;
875 const AliTRDCalDet *calVdriftDet = calibration->GetVdriftDet();
876 AliTRDCalROC *calT0ROC = 0;
877 Float_t calT0DetValue = 0.0;
878 const AliTRDCalDet *calT0Det = calibration->GetT0Det();
880 if (simParam->TRFOn()) {
881 timeBinTRFend = ((Int_t) (simParam->GetTRFhi()
882 * commonParam->GetSamplingFrequency())) - 1;
885 Int_t nTimeTotal = fDigitsManager->GetDigitsParam()->GetNTimeBins(det);
886 Float_t samplingRate = commonParam->GetSamplingFrequency();
887 Float_t elAttachProp = simParam->GetElAttachProp() / 100.0;
889 AliTRDpadPlane *padPlane = fGeo->GetPadPlane(det);
890 Int_t layer = fGeo->GetLayer(det); //update
891 Float_t row0 = padPlane->GetRow0ROC();
892 Int_t nRowMax = padPlane->GetNrows();
893 Int_t nColMax = padPlane->GetNcols();
895 // Create a new array for the signals
896 signals->Allocate(nRowMax,nColMax,nTimeTotal);
898 // Create a new array for the dictionary
899 for (dict = 0; dict < kNdict; dict++) {
900 dictionary[dict] = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
901 dictionary[dict]->Allocate(nRowMax,nColMax,nTimeTotal);
904 // Loop through the hits in this detector
905 for (Int_t hit = 0; hit < nhit; hit++) {
907 pos[0] = hits[hit*kNhit+0];
908 pos[1] = hits[hit*kNhit+1];
909 pos[2] = hits[hit*kNhit+2];
910 Float_t q = hits[hit*kNhit+3];
911 Float_t hittime = hits[hit*kNhit+5];
912 Int_t track = ((Int_t) hits[hit*kNhit+4]);
916 // Find the current volume with the geo manager
917 gGeoManager->SetCurrentPoint(pos);
918 gGeoManager->FindNode();
919 if (strstr(gGeoManager->GetPath(),"/UK")) {
923 // Get the calibration objects
924 calVdriftROC = calibration->GetVdriftROC(det);
925 calVdriftDetValue = calVdriftDet->GetValue(det);
926 calT0ROC = calibration->GetT0ROC(det);
927 calT0DetValue = calT0Det->GetValue(det);
929 // Go to the local coordinate system:
930 // loc[0] - col direction in amplification or driftvolume
931 // loc[1] - row direction in amplification or driftvolume
932 // loc[2] - time direction in amplification or driftvolume
933 gGeoManager->MasterToLocal(pos,loc);
935 // Relative to middle of amplification region
936 loc[2] = loc[2] - kDrWidth/2.0 - kAmWidth/2.0;
939 // The driftlength [cm] (w/o diffusion yet !).
940 // It is negative if the hit is between pad plane and anode wires.
941 Double_t driftlength = -1.0 * loc[2];
943 // Stupid patch to take care of TR photons that are absorbed
944 // outside the chamber volume. A real fix would actually need
945 // a more clever implementation of the TR hit generation
947 if ((loc[1] < padPlane->GetRowEndROC()) ||
948 (loc[1] > padPlane->GetRow0ROC())) {
951 if ((driftlength < kDrMin) ||
952 (driftlength > kDrMax)) {
957 // Get row and col of unsmeared electron to retrieve drift velocity
958 // The pad row (z-direction)
959 Int_t rowE = padPlane->GetPadRowNumberROC(loc[1]);
963 Double_t rowOffset = padPlane->GetPadRowOffsetROC(rowE,loc[1]);
964 // The pad column (rphi-direction)
965 Double_t offsetTilt = padPlane->GetTiltOffset(rowOffset);
966 Int_t colE = padPlane->GetPadColNumber(loc[0]+offsetTilt);
970 Double_t colOffset = 0.0;
972 // Normalized drift length
973 Float_t driftvelocity = calVdriftDetValue * calVdriftROC->GetValue(colE,rowE);
974 Double_t absdriftlength = TMath::Abs(driftlength);
975 if (commonParam->ExBOn()) {
976 absdriftlength /= TMath::Sqrt(GetLorentzFactor(driftvelocity));
979 // Loop over all electrons of this hit
980 // TR photons produce hits with negative charge
981 Int_t nEl = ((Int_t) TMath::Abs(q));
982 for (Int_t iEl = 0; iEl < nEl; iEl++) {
984 // Now the real local coordinate system of the ROC
985 // column direction: locC
986 // row direction: locR
987 // time direction: locT
988 // locR and locC are identical to the coordinates of the corresponding
989 // volumina of the drift or amplification region.
990 // locT is defined relative to the wire plane (i.e. middle of amplification
991 // region), meaning locT = 0, and is negative for hits coming from the
993 Double_t locC = loc[0];
994 Double_t locR = loc[1];
995 Double_t locT = loc[2];
997 // Electron attachment
998 if (simParam->ElAttachOn()) {
999 if (gRandom->Rndm() < (absdriftlength * elAttachProp)) {
1004 // Apply the diffusion smearing
1005 if (simParam->DiffusionOn()) {
1006 if (!(Diffusion(driftvelocity,absdriftlength,locR,locC,locT))) {
1011 // Apply E x B effects (depends on drift direction)
1012 if (commonParam->ExBOn()) {
1013 if (!(ExB(driftvelocity,driftlength,locC))) {
1018 // The electron position after diffusion and ExB in pad coordinates.
1019 // The pad row (z-direction)
1020 rowE = padPlane->GetPadRowNumberROC(locR);
1021 if (rowE < 0) continue;
1022 rowOffset = padPlane->GetPadRowOffsetROC(rowE,locR);
1024 // The pad column (rphi-direction)
1025 offsetTilt = padPlane->GetTiltOffset(rowOffset);
1026 colE = padPlane->GetPadColNumber(locC+offsetTilt);
1027 if (colE < 0) continue;
1028 colOffset = padPlane->GetPadColOffset(colE,locC+offsetTilt);
1030 // Also re-retrieve drift velocity because col and row may have changed
1031 driftvelocity = calVdriftDetValue * calVdriftROC->GetValue(colE,rowE);
1032 Float_t t0 = calT0DetValue + calT0ROC->GetValue(colE,rowE);
1034 // Convert the position to drift time [mus], using either constant drift velocity or
1035 // time structure of drift cells (non-isochronity, GARFIELD calculation).
1036 // Also add absolute time of hits to take pile-up events into account properly
1038 if (simParam->TimeStructOn()) {
1039 // Get z-position with respect to anode wire
1040 Double_t zz = row0 - locR + padPlane->GetAnodeWireOffset();
1041 zz -= ((Int_t)(2 * zz)) / 2.0;
1045 // Use drift time map (GARFIELD)
1046 drifttime = commonParam->TimeStruct(driftvelocity,0.5*kAmWidth-1.0*locT,zz)
1050 // Use constant drift velocity
1051 drifttime = TMath::Abs(locT) / driftvelocity
1055 // Apply the gas gain including fluctuations
1056 Double_t ggRndm = 0.0;
1058 ggRndm = gRandom->Rndm();
1059 } while (ggRndm <= 0);
1060 Double_t signal = -(simParam->GetGasGain()) * TMath::Log(ggRndm);
1062 // Apply the pad response
1063 if (simParam->PRFOn()) {
1064 // The distance of the electron to the center of the pad
1065 // in units of pad width
1066 Double_t dist = (colOffset - 0.5*padPlane->GetColSize(colE))
1067 / padPlane->GetColSize(colE);
1068 // This is a fixed parametrization, i.e. not dependent on
1069 // calibration values !
1070 if (!(calibration->PadResponse(signal,dist,layer,padSignal))) continue;
1074 padSignal[1] = signal;
1078 // The time bin (always positive), with t0 distortion
1079 Double_t timeBinIdeal = drifttime * samplingRate + t0;
1081 if (TMath::Abs(timeBinIdeal) > 2*nTimeTotal) {
1082 timeBinIdeal = 2 * nTimeTotal;
1084 Int_t timeBinTruncated = ((Int_t) timeBinIdeal);
1085 // The distance of the position to the middle of the timebin
1086 Double_t timeOffset = ((Float_t) timeBinTruncated
1087 + 0.5 - timeBinIdeal) / samplingRate;
1089 // Sample the time response inside the drift region
1090 // + additional time bins before and after.
1091 // The sampling is done always in the middle of the time bin
1092 for (Int_t iTimeBin = TMath::Max(timeBinTruncated,0)
1093 ;iTimeBin < TMath::Min(timeBinTruncated+timeBinTRFend,nTimeTotal)
1096 // Apply the time response
1097 Double_t timeResponse = 1.0;
1098 Double_t crossTalk = 0.0;
1099 Double_t time = (iTimeBin - timeBinTruncated) / samplingRate + timeOffset;
1101 if (simParam->TRFOn()) {
1102 timeResponse = simParam->TimeResponse(time);
1104 if (simParam->CTOn()) {
1105 crossTalk = simParam->CrossTalk(time);
1112 for (iPad = 0; iPad < kNpad; iPad++) {
1114 Int_t colPos = colE + iPad - 1;
1115 if (colPos < 0) continue;
1116 if (colPos >= nColMax) break;
1119 signalOld[iPad] = signals->GetData(rowE,colPos,iTimeBin);
1121 if (colPos != colE) {
1122 // Cross talk added to non-central pads
1123 signalOld[iPad] += padSignal[iPad]
1124 * (timeResponse + crossTalk);
1127 // W/o cross talk at central pad
1128 signalOld[iPad] += padSignal[iPad]
1132 signals->SetData(rowE,colPos,iTimeBin,signalOld[iPad]);
1134 // Store the track index in the dictionary
1135 // Note: We store index+1 in order to allow the array to be compressed
1136 // Note2: Taking out the +1 in track
1137 if (signalOld[iPad] > 0.0) {
1138 for (dict = 0; dict < kNdict; dict++) {
1139 Int_t oldTrack = dictionary[dict]->GetData(rowE,colPos,iTimeBin);
1140 if (oldTrack == track) break;
1141 if (oldTrack == -1 ) {
1142 dictionary[dict]->SetData(rowE,colPos,iTimeBin,track);
1150 } // Loop: time bins
1152 } // Loop: electrons of a single hit
1156 AliDebug(2,Form("Finished analyzing %d hits",nhit));
1162 //_____________________________________________________________________________
1163 Bool_t AliTRDdigitizer::ConvertSignals(Int_t det, AliTRDarraySignal *signals)
1166 // Convert signals to digits
1169 AliDebug(1,Form("Start converting the signals for detector %d",det));
1172 // Convert the signal array to s-digits
1173 if (!Signal2SDigits(det,signals)) {
1178 // Convert the signal array to digits
1179 if (!Signal2ADC(det,signals)) {
1182 // Run digital processing for digits
1183 RunDigitalProcessing(det);
1186 // Compress the arrays
1187 CompressOutputArrays(det);
1193 //_____________________________________________________________________________
1194 Bool_t AliTRDdigitizer::Signal2ADC(Int_t det, AliTRDarraySignal *signals)
1197 // Converts the sampled electron signals to ADC values for a given chamber
1200 AliDebug(1,Form("Start converting signals to ADC values for detector=%d",det));
1202 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1204 AliFatal("Could not get calibration object");
1208 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
1210 AliFatal("Could not get simulation parameters");
1214 // Converts number of electrons to fC
1215 const Double_t kEl2fC = 1.602e-19 * 1.0e15;
1218 Double_t coupling = simParam->GetPadCoupling()
1219 * simParam->GetTimeCoupling();
1220 // Electronics conversion factor
1221 Double_t convert = kEl2fC
1222 * simParam->GetChipGain();
1223 // ADC conversion factor
1224 Double_t adcConvert = simParam->GetADCoutRange()
1225 / simParam->GetADCinRange();
1226 // The electronics baseline in mV
1227 Double_t baseline = simParam->GetADCbaseline()
1229 // The electronics baseline in electrons
1230 Double_t baselineEl = baseline
1237 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1238 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1239 Int_t nTimeTotal = fDigitsManager->GetDigitsParam()->GetNTimeBins(det);
1240 if (fSDigitsManager->GetDigitsParam()->GetNTimeBins(det)) {
1241 nTimeTotal = fSDigitsManager->GetDigitsParam()->GetNTimeBins(det);
1244 AliFatal("Could not get number of time bins");
1248 // The gain factor calibration objects
1249 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
1250 AliTRDCalROC *calGainFactorROC = 0x0;
1251 Float_t calGainFactorDetValue = 0.0;
1253 AliTRDarrayADC *digits = 0x0;
1256 AliError(Form("Signals array for detector %d does not exist\n",det));
1259 if (signals->HasData()) {
1260 // Expand the container if neccessary
1264 // Create missing containers
1265 signals->Allocate(nRowMax,nColMax,nTimeTotal);
1268 // Get the container for the digits of this detector
1269 if (fDigitsManager->HasSDigits()) {
1270 AliError("Digits manager has s-digits");
1274 digits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det);
1275 // Allocate memory space for the digits buffer
1276 if (!digits->HasData()) {
1277 digits->Allocate(nRowMax,nColMax,nTimeTotal);
1280 // Get the calibration objects
1281 calGainFactorROC = calibration->GetGainFactorROC(det);
1282 calGainFactorDetValue = calGainFactorDet->GetValue(det);
1284 // Get the online gain factors
1285 //AliTRDCalOnlineGainTableROC *onlineGainFactorROC
1286 // = calibration->GetOnlineGainTableROC(det);
1288 // Create the digits for this chamber
1289 for (row = 0; row < nRowMax; row++ ) {
1290 for (col = 0; col < nColMax; col++ ) {
1292 // Check whether pad is masked
1293 // Bridged pads are not considered yet!!!
1294 if (calibration->IsPadMasked(det,col,row) ||
1295 calibration->IsPadNotConnected(det,col,row)) {
1300 Float_t padgain = calGainFactorDetValue
1301 * calGainFactorROC->GetValue(col,row);
1303 AliError(Form("Not a valid gain %f, %d %d %d",padgain,det,col,row));
1306 for (time = 0; time < nTimeTotal; time++) {
1308 // Get the signal amplitude
1309 Float_t signalAmp = signals->GetData(row,col,time);
1310 // Pad and time coupling
1311 signalAmp *= coupling;
1313 signalAmp *= padgain;
1315 // Add the noise, starting from minus ADC baseline in electrons
1316 signalAmp = TMath::Max((Double_t) gRandom->Gaus(signalAmp,simParam->GetNoise())
1320 signalAmp *= convert;
1321 // Add ADC baseline in mV
1322 signalAmp += baseline;
1324 // Convert to ADC counts. Set the overflow-bit fADCoutRange if the
1325 // signal is larger than fADCinRange
1327 if (signalAmp >= simParam->GetADCinRange()) {
1328 adc = ((Short_t) simParam->GetADCoutRange());
1331 adc = TMath::Nint(signalAmp * adcConvert);
1334 // Saving all digits
1335 digits->SetData(row,col,time,adc);
1346 //_____________________________________________________________________________
1347 Bool_t AliTRDdigitizer::Signal2SDigits(Int_t det, AliTRDarraySignal *signals)
1350 // Converts the sampled electron signals to s-digits
1353 AliDebug(1,Form("Start converting signals to s-digits for detector=%d",det));
1355 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1357 AliFatal("Could not get calibration object");
1365 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1366 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1367 Int_t nTimeTotal = fDigitsManager->GetDigitsParam()->GetNTimeBins(det);
1369 // Get the container for the digits of this detector
1370 if (!fDigitsManager->HasSDigits()) {
1371 AliError("Digits manager has no s-digits");
1375 AliTRDarraySignal *digits = (AliTRDarraySignal *) fDigitsManager->GetSDigits(det);
1376 // Allocate memory space for the digits buffer
1377 if (!digits->HasData()) {
1378 digits->Allocate(nRowMax,nColMax,nTimeTotal);
1381 // Create the sdigits for this chamber
1382 for (row = 0; row < nRowMax; row++ ) {
1383 for (col = 0; col < nColMax; col++ ) {
1384 for (time = 0; time < nTimeTotal; time++) {
1385 digits->SetData(row,col,time,signals->GetData(row,col,time));
1394 //_____________________________________________________________________________
1395 Bool_t AliTRDdigitizer::Digits2SDigits(AliTRDdigitsManager * const manDig
1396 , AliTRDdigitsManager * const manSDig)
1399 // Converts digits into s-digits. Needed for embedding into real data.
1402 AliDebug(1,"Start converting digits to s-digits");
1405 fGeo = new AliTRDgeometry();
1408 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1410 AliFatal("Could not get calibration object");
1414 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
1416 AliFatal("Could not get simulation parameters");
1420 // Converts number of electrons to fC
1421 const Double_t kEl2fC = 1.602e-19 * 1.0e15;
1424 Double_t coupling = simParam->GetPadCoupling()
1425 * simParam->GetTimeCoupling();
1426 // Electronics conversion factor
1427 Double_t convert = kEl2fC
1428 * simParam->GetChipGain();
1429 // ADC conversion factor
1430 Double_t adcConvert = simParam->GetADCoutRange()
1431 / simParam->GetADCinRange();
1432 // The electronics baseline in mV
1433 Double_t baseline = simParam->GetADCbaseline()
1435 // The electronics baseline in electrons
1436 //Double_t baselineEl = baseline
1439 // The gainfactor calibration objects
1440 //const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
1441 //AliTRDCalROC *calGainFactorROC = 0;
1442 //Float_t calGainFactorDetValue = 0.0;
1448 for (Int_t det = 0; det < AliTRDgeometry::Ndet(); det++) {
1450 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1451 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1452 Int_t nTimeTotal = manDig->GetDigitsParam()->GetNTimeBins(det);
1454 // Get the calibration objects
1455 //calGainFactorROC = calibration->GetGainFactorROC(det);
1456 //calGainFactorDetValue = calGainFactorDet->GetValue(det);
1459 AliTRDarrayADC *digits = (AliTRDarrayADC *) manDig->GetDigits(det);
1461 if (!manSDig->HasSDigits()) {
1462 AliError("SDigits manager has no s-digits");
1466 AliTRDarraySignal *sdigits = (AliTRDarraySignal *) manSDig->GetSDigits(det);
1467 AliTRDarrayDictionary *tracks0 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,0);
1468 AliTRDarrayDictionary *tracks1 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,1);
1469 AliTRDarrayDictionary *tracks2 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,2);
1470 // Allocate memory space for the digits buffer
1471 sdigits->Allocate(nRowMax,nColMax,nTimeTotal);
1472 tracks0->Allocate(nRowMax,nColMax,nTimeTotal);
1473 tracks1->Allocate(nRowMax,nColMax,nTimeTotal);
1474 tracks2->Allocate(nRowMax,nColMax,nTimeTotal);
1476 // Keep the digits param
1477 manSDig->GetDigitsParam()->SetNTimeBinsAll(manDig->GetDigitsParam()->GetNTimeBins(0));
1478 manSDig->GetDigitsParam()->SetADCbaselineAll(manDig->GetDigitsParam()->GetADCbaseline(0));
1480 if (digits->HasData()) {
1484 // Create the sdigits for this chamber
1485 for (row = 0; row < nRowMax; row++ ) {
1486 for (col = 0; col < nColMax; col++ ) {
1489 //Float_t padgain = calGainFactorDetValue
1490 // * calGainFactorROC->GetValue(col,row);
1492 for (time = 0; time < nTimeTotal; time++) {
1494 Short_t adcVal = digits->GetData(row,col,time);
1495 Double_t signal = (Double_t) adcVal;
1496 // ADC -> signal in mV
1497 signal /= adcConvert;
1498 // Subtract baseline in mV
1500 // Signal in mV -> signal in #electrons
1503 //signal /= padgain; // Not needed for real data
1504 // Pad and time coupling
1507 sdigits->SetData(row,col,time,signal);
1508 tracks0->SetData(row,col,time,0);
1509 tracks1->SetData(row,col,time,0);
1510 tracks2->SetData(row,col,time,0);
1519 sdigits->Compress(0);
1520 tracks0->Compress();
1521 tracks1->Compress();
1522 tracks2->Compress();
1524 // No compress just remove
1525 manDig->RemoveDigits(det);
1526 manDig->RemoveDictionaries(det);
1534 //_____________________________________________________________________________
1535 Bool_t AliTRDdigitizer::SDigits2Digits()
1538 // Merges the input s-digits and converts them to normal digits
1541 if (!MergeSDigits()) {
1545 return ConvertSDigits();
1549 //_____________________________________________________________________________
1550 Bool_t AliTRDdigitizer::MergeSDigits()
1553 // Merges the input s-digits:
1554 // - The amplitude of the different inputs are summed up.
1555 // - Of the track IDs from the input dictionaries only one is
1556 // kept for each input. This works for maximal 3 different merged inputs.
1559 // Number of track dictionary arrays
1560 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1562 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
1564 AliFatal("Could not get simulation parameters");
1568 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1570 AliFatal("Could not get calibration object");
1577 AliTRDarraySignal *digitsA;
1578 AliTRDarraySignal *digitsB;
1579 AliTRDarrayDictionary *dictionaryA[kNDict];
1580 AliTRDarrayDictionary *dictionaryB[kNDict];
1582 AliTRDdigitsManager *mergeSDigitsManager = 0x0;
1583 // Get the first s-digits
1584 fSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->First();
1585 if (!fSDigitsManager) {
1586 AliError("No SDigits manager");
1590 // Loop through the other sets of s-digits
1591 mergeSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->After(fSDigitsManager);
1593 if (mergeSDigitsManager) {
1594 AliDebug(1,Form("Merge %d input files.",fSDigitsManagerList->GetSize()));
1597 AliDebug(1,"Only one input file.");
1602 while (mergeSDigitsManager) {
1606 // Loop through the detectors
1607 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) {
1609 Int_t nTimeTotal = fSDigitsManager->GetDigitsParam()->GetNTimeBins(iDet);
1610 if (mergeSDigitsManager->GetDigitsParam()->GetNTimeBins(iDet) != nTimeTotal) {
1611 AliError(Form("Mismatch in the number of time bins [%d,%d] in detector %d"
1613 ,mergeSDigitsManager->GetDigitsParam()->GetNTimeBins(iDet)
1618 Int_t nRowMax = fGeo->GetPadPlane(iDet)->GetNrows();
1619 Int_t nColMax = fGeo->GetPadPlane(iDet)->GetNcols();
1621 // Loop through the pixels of one detector and add the signals
1622 digitsA = (AliTRDarraySignal *) fSDigitsManager->GetSDigits(iDet);
1623 digitsB = (AliTRDarraySignal *) mergeSDigitsManager->GetSDigits(iDet);
1625 if (!digitsA->HasData()) continue;
1627 if (!digitsB->HasData()) continue;
1629 for (iDict = 0; iDict < kNDict; iDict++) {
1630 dictionaryA[iDict] = (AliTRDarrayDictionary *) fSDigitsManager->GetDictionary(iDet,iDict);
1631 dictionaryB[iDict] = (AliTRDarrayDictionary *) mergeSDigitsManager->GetDictionary(iDet,iDict);
1632 dictionaryA[iDict]->Expand();
1633 dictionaryB[iDict]->Expand();
1636 // Merge only detectors that contain a signal
1637 Bool_t doMerge = kTRUE;
1638 if (fMergeSignalOnly) {
1639 if (digitsA->GetOverThreshold(0) == 0) {
1646 AliDebug(1,Form("Merge detector %d of input no.%d",iDet,iMerge+1));
1648 for (Int_t iRow = 0; iRow < nRowMax; iRow++ ) {
1649 for (Int_t iCol = 0; iCol < nColMax; iCol++ ) {
1650 for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
1652 // Add the amplitudes of the summable digits
1653 Float_t ampA = digitsA->GetData(iRow,iCol,iTime);
1654 Float_t ampB = digitsB->GetData(iRow,iCol,iTime);
1656 digitsA->SetData(iRow,iCol,iTime,ampA);
1658 // Add the mask to the track id if defined.
1659 for (iDict = 0; iDict < kNDict; iDict++) {
1660 Int_t trackB = dictionaryB[iDict]->GetData(iRow,iCol,iTime);
1661 if ((fMasks) && (trackB > 0)) {
1662 for (jDict = 0; jDict < kNDict; jDict++) {
1663 Int_t trackA = dictionaryA[iDict]->GetData(iRow,iCol,iTime);
1665 trackA = trackB + fMasks[iMerge];
1666 dictionaryA[iDict]->SetData(iRow,iCol,iTime,trackA);
1667 } // if: track A == 0
1669 } // if: fMasks and trackB > 0
1678 mergeSDigitsManager->RemoveDigits(iDet);
1679 mergeSDigitsManager->RemoveDictionaries(iDet);
1682 digitsA->Compress(0);
1683 for (iDict = 0; iDict < kNDict; iDict++) {
1684 dictionaryA[iDict]->Compress();
1690 // The next set of s-digits
1691 mergeSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->After(mergeSDigitsManager);
1693 } // while: mergeDigitsManagers
1699 //_____________________________________________________________________________
1700 Bool_t AliTRDdigitizer::ConvertSDigits()
1703 // Converts s-digits to normal digits
1706 AliTRDarraySignal *digitsIn = 0x0;
1708 if (!fSDigitsManager->HasSDigits()) {
1709 AliError("No s-digits in digits manager");
1713 // Loop through the detectors
1714 for (Int_t det = 0; det < AliTRDgeometry::Ndet(); det++) {
1716 // Get the merged s-digits (signals)
1717 digitsIn = (AliTRDarraySignal *) fSDigitsManager->GetSDigits(det);
1718 if (!digitsIn->HasData()) {
1719 AliDebug(2,Form("No digits for det=%d",det));
1723 // Convert the merged sdigits to digits
1724 if (!Signal2ADC(det,digitsIn)) {
1728 // Copy the dictionary information to the output array
1729 if (!CopyDictionary(det)) {
1734 fSDigitsManager->RemoveDigits(det);
1735 fSDigitsManager->RemoveDictionaries(det);
1737 // Run digital processing
1738 RunDigitalProcessing(det);
1740 // Compress the arrays
1741 CompressOutputArrays(det);
1743 } // for: detector numbers
1745 if (AliDataLoader *trklLoader = AliRunLoader::Instance()->GetLoader("TRDLoader")->GetDataLoader("tracklets")) {
1746 if (trklLoader->Tree())
1747 trklLoader->WriteData("OVERWRITE");
1750 // Save the values for the raw data headers
1751 if (AliTRDSimParam::Instance()->GetNTBoverwriteOCDB()) {
1752 fDigitsManager->GetDigitsParam()->SetNTimeBinsAll(AliTRDSimParam::Instance()->GetNTimeBins());
1755 fDigitsManager->GetDigitsParam()->SetNTimeBinsAll(AliTRDcalibDB::Instance()->GetNumberOfTimeBinsDCS());
1757 fDigitsManager->GetDigitsParam()->SetADCbaselineAll(AliTRDSimParam::Instance()->GetADCbaseline());
1763 //_____________________________________________________________________________
1764 Bool_t AliTRDdigitizer::CopyDictionary(Int_t det)
1767 // Copies the dictionary information from the s-digits arrays
1768 // to the output arrays
1771 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1773 AliFatal("Could not get calibration object");
1777 AliDebug(1,Form("Start copying dictionaries for detector=%d",det));
1779 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1780 AliTRDarrayDictionary *dictionaryIn[kNDict];
1781 AliTRDarrayDictionary *dictionaryOut[kNDict];
1783 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1784 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1785 Int_t nTimeTotal = fSDigitsManager->GetDigitsParam()->GetNTimeBins(det);
1792 for (dict = 0; dict < kNDict; dict++) {
1794 dictionaryIn[dict] = (AliTRDarrayDictionary *) fSDigitsManager->GetDictionary(det,dict);
1795 dictionaryIn[dict]->Expand();
1796 dictionaryOut[dict] = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
1797 dictionaryOut[dict]->Allocate(nRowMax,nColMax,nTimeTotal);
1799 for (row = 0; row < nRowMax; row++) {
1800 for (col = 0; col < nColMax; col++) {
1801 for (time = 0; time < nTimeTotal; time++) {
1802 Int_t track = dictionaryIn[dict]->GetData(row,col,time);
1803 dictionaryOut[dict]->SetData(row,col,time,track);
1808 } // for: dictionaries
1814 //_____________________________________________________________________________
1815 void AliTRDdigitizer::CompressOutputArrays(Int_t det)
1818 // Compress the output arrays
1821 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1822 AliTRDarrayDictionary *dictionary = 0x0;
1827 AliTRDarrayADC *digits = 0x0;
1828 digits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det);
1833 AliTRDarraySignal *digits = 0x0;
1834 digits = (AliTRDarraySignal *) fDigitsManager->GetSDigits(det);
1835 digits->Compress(0);
1838 for (Int_t dict = 0; dict < kNDict; dict++) {
1839 dictionary = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
1840 dictionary->Compress();
1847 //_____________________________________________________________________________
1848 Bool_t AliTRDdigitizer::WriteDigits() const
1851 // Writes out the TRD-digits and the dictionaries
1855 fRunLoader->CdGAFile();
1857 // Store the digits and the dictionary in the tree
1858 return fDigitsManager->WriteDigits();
1862 //_____________________________________________________________________________
1863 void AliTRDdigitizer::InitOutput(Int_t iEvent)
1866 // Initializes the output branches
1872 AliError("Run Loader is NULL");
1876 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
1878 AliError("Can not get TRD loader from Run Loader");
1885 // If we produce SDigits
1886 tree = loader->TreeS();
1888 loader->MakeTree("S");
1889 tree = loader->TreeS();
1893 // If we produce Digits
1894 tree = loader->TreeD();
1896 loader->MakeTree("D");
1897 tree = loader->TreeD();
1900 fDigitsManager->SetEvent(iEvent);
1901 fDigitsManager->MakeBranch(tree);
1905 //_____________________________________________________________________________
1906 Int_t AliTRDdigitizer::Diffusion(Float_t vdrift, Double_t absdriftlength
1907 , Double_t &lRow, Double_t &lCol, Double_t &lTime)
1910 // Applies the diffusion smearing to the position of a single electron.
1911 // Depends on absolute drift length.
1914 Float_t diffL = 0.0;
1915 Float_t diffT = 0.0;
1917 if (AliTRDCommonParam::Instance()->GetDiffCoeff(diffL,diffT,vdrift)) {
1919 Float_t driftSqrt = TMath::Sqrt(absdriftlength);
1920 Float_t sigmaT = driftSqrt * diffT;
1921 Float_t sigmaL = driftSqrt * diffL;
1922 lRow = gRandom->Gaus(lRow ,sigmaT);
1923 lCol = gRandom->Gaus(lCol ,sigmaT * GetLorentzFactor(vdrift));
1924 lTime = gRandom->Gaus(lTime,sigmaL * GetLorentzFactor(vdrift));
1937 //_____________________________________________________________________________
1938 Float_t AliTRDdigitizer::GetLorentzFactor(Float_t vd)
1941 // Returns the Lorentz factor
1944 Double_t omegaTau = AliTRDCommonParam::Instance()->GetOmegaTau(vd);
1945 Double_t lorentzFactor = 1.0;
1946 if (AliTRDCommonParam::Instance()->ExBOn()) {
1947 lorentzFactor = 1.0 / (1.0 + omegaTau*omegaTau);
1950 return lorentzFactor;
1954 //_____________________________________________________________________________
1955 Int_t AliTRDdigitizer::ExB(Float_t vdrift, Double_t driftlength, Double_t &lCol)
1958 // Applies E x B effects to the position of a single electron.
1959 // Depends on signed drift length.
1963 + AliTRDCommonParam::Instance()->GetOmegaTau(vdrift)
1970 //_____________________________________________________________________________
1971 void AliTRDdigitizer::RunDigitalProcessing(Int_t det)
1974 // Run the digital processing in the TRAP
1977 AliTRDfeeParam *feeParam = AliTRDfeeParam::Instance();
1979 AliTRDarrayADC *digits = fDigitsManager->GetDigits(det);
1983 //Call the methods in the mcm class using the temporary array as input
1984 for(Int_t rob = 0; rob < digits->GetNrow() / 2; rob++)
1986 for(Int_t mcm = 0; mcm < 16; mcm++)
1988 fMcmSim->Init(det, rob, mcm);
1989 fMcmSim->SetDataByPad(digits, fDigitsManager);
1991 if (feeParam->GetTracklet()) {
1992 fMcmSim->Tracklet();
1993 fMcmSim->StoreTracklets();
1995 fMcmSim->ZSMapping();
1996 fMcmSim->WriteData(digits);