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 "AliDigitizationInput.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(AliDigitizationInput* digInput
123 , const Text_t *name, const Text_t *title)
124 :AliDigitizer(digInput,name,title)
128 ,fSDigitsManagerList(0)
131 ,fMcmSim(new AliTRDmcmSim)
136 ,fMergeSignalOnly(kFALSE)
139 // AliTRDdigitizer constructor
144 //_____________________________________________________________________________
145 AliTRDdigitizer::AliTRDdigitizer(AliDigitizationInput* digInput)
146 :AliDigitizer(digInput,"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 delete fDigitsManager;
198 // s-digitsmanager will be deleted via list
200 if (fSDigitsManagerList) {
201 fSDigitsManagerList->Delete();
202 delete fSDigitsManagerList;
204 fSDigitsManagerList = 0;
217 //_____________________________________________________________________________
218 AliTRDdigitizer &AliTRDdigitizer::operator=(const AliTRDdigitizer &d)
221 // Assignment operator
225 ((AliTRDdigitizer &) d).Copy(*this);
232 //_____________________________________________________________________________
233 void AliTRDdigitizer::Copy(TObject &d) const
239 ((AliTRDdigitizer &) d).fRunLoader = 0;
240 ((AliTRDdigitizer &) d).fDigitsManager = 0;
241 ((AliTRDdigitizer &) d).fSDigitsManager = 0;
242 ((AliTRDdigitizer &) d).fSDigitsManagerList = 0;
243 ((AliTRDdigitizer &) d).fTRD = 0;
244 ((AliTRDdigitizer &) d).fGeo = 0;
245 ((AliTRDdigitizer &) d).fEvent = 0;
246 ((AliTRDdigitizer &) d).fMasks = 0;
247 ((AliTRDdigitizer &) d).fCompress = fCompress;
248 ((AliTRDdigitizer &) d).fSDigits = fSDigits;
249 ((AliTRDdigitizer &) d).fMergeSignalOnly = fMergeSignalOnly;
253 //_____________________________________________________________________________
254 void AliTRDdigitizer::Digitize(const Option_t* option)
257 // Executes the merging
262 AliTRDdigitsManager *sdigitsManager;
264 TString optionString = option;
265 if (optionString.Contains("deb")) {
266 AliLog::SetClassDebugLevel("AliTRDdigitizer",1);
267 AliInfo("Called with debug option");
270 // The AliRoot file is already connected by the manager
271 AliRunLoader *inrl = 0x0;
274 AliDebug(1,"AliRun object found on file.");
277 inrl = AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(0));
279 gAlice = inrl->GetAliRun();
281 AliError("Could not find AliRun object.");
286 Int_t nInput = fDigInput->GetNinputs();
287 fMasks = new Int_t[nInput];
288 for (iInput = 0; iInput < nInput; iInput++) {
289 fMasks[iInput] = fDigInput->GetMask(iInput);
296 AliRunLoader *orl = AliRunLoader::GetRunLoader(fDigInput->GetOutputFolderName());
298 if (InitDetector()) {
300 AliLoader *ogime = orl->GetLoader("TRDLoader");
304 // If we produce SDigits
305 tree = ogime->TreeS();
307 ogime->MakeTree("S");
308 tree = ogime->TreeS();
312 // If we produce Digits
313 tree = ogime->TreeD();
315 ogime->MakeTree("D");
316 tree = ogime->TreeD();
324 for (iInput = 0; iInput < nInput; iInput++) {
326 AliDebug(1,Form("Add input stream %d",iInput));
328 // Check if the input tree exists
329 inrl = AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(iInput));
330 AliLoader *gime = inrl->GetLoader("TRDLoader");
332 TTree *treees = gime->TreeS();
334 if (gime->LoadSDigits()) {
335 AliError(Form("Error Occured while loading S. Digits for input %d.",iInput));
338 treees = gime->TreeS();
342 AliError(Form("Input stream %d does not exist",iInput));
346 // Read the s-digits via digits manager
347 sdigitsManager = new AliTRDdigitsManager();
348 sdigitsManager->SetSDigits(kTRUE);
350 AliRunLoader *rl = AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(iInput));
351 AliLoader *gimme = rl->GetLoader("TRDLoader");
354 gimme->LoadSDigits();
357 sdigitsManager->ReadDigits(gimme->TreeS());
359 // Add the s-digits to the input list
360 AddSDigitsManager(sdigitsManager);
364 // Convert the s-digits to normal digits
365 AliDebug(1,"Do the conversion");
369 AliDebug(1,"Write the digits");
370 fDigitsManager->WriteDigits();
376 DeleteSDigitsManager();
382 //_____________________________________________________________________________
383 Bool_t AliTRDdigitizer::Open(const Char_t *file, Int_t nEvent)
386 // Opens a ROOT-file with TRD-hits and reads in the hit-tree
388 // Connect the AliRoot file containing Geometry, Kine, and Hits
391 TString evfoldname = AliConfig::GetDefaultEventFolderName();
393 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
395 fRunLoader = AliRunLoader::Open(file,evfoldname,"UPDATE");
398 AliError(Form("Can not open session for file %s.",file));
402 if (!fRunLoader->GetAliRun()) {
403 fRunLoader->LoadgAlice();
405 gAlice = fRunLoader->GetAliRun();
408 AliDebug(1,"AliRun object found on file.");
411 AliError("Could not find AliRun object.");
417 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
419 AliError("Can not get TRD loader from Run Loader");
423 if (InitDetector()) {
426 // If we produce SDigits
427 tree = loader->TreeS();
429 loader->MakeTree("S");
430 tree = loader->TreeS();
434 // If we produce Digits
435 tree = loader->TreeD();
437 loader->MakeTree("D");
438 tree = loader->TreeD();
441 return MakeBranch(tree);
449 //_____________________________________________________________________________
450 Bool_t AliTRDdigitizer::Open(AliRunLoader * const runLoader, Int_t nEvent)
453 // Opens a ROOT-file with TRD-hits and reads in the hit-tree
455 // Connect the AliRoot file containing Geometry, Kine, and Hits
458 fRunLoader = runLoader;
460 AliError("RunLoader does not exist");
464 if (!fRunLoader->GetAliRun()) {
465 fRunLoader->LoadgAlice();
467 gAlice = fRunLoader->GetAliRun();
470 AliDebug(1,"AliRun object found on file.");
473 AliError("Could not find AliRun object.");
479 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
481 AliError("Can not get TRD loader from Run Loader");
485 if (InitDetector()) {
488 // If we produce SDigits
489 tree = loader->TreeS();
491 loader->MakeTree("S");
492 tree = loader->TreeS();
496 // If we produce Digits
497 tree = loader->TreeD();
499 loader->MakeTree("D");
500 tree = loader->TreeD();
503 return MakeBranch(tree);
511 //_____________________________________________________________________________
512 Bool_t AliTRDdigitizer::InitDetector()
515 // Sets the pointer to the TRD detector and the geometry
518 // Get the pointer to the detector class and check for version 1
519 fTRD = (AliTRD *) gAlice->GetDetector("TRD");
521 AliFatal("No TRD module found");
524 if (fTRD->IsVersion() != 1) {
525 AliFatal("TRD must be version 1 (slow simulator)");
530 fGeo = new AliTRDgeometry();
532 // Create a digits manager
533 if (fDigitsManager) {
534 delete fDigitsManager;
536 fDigitsManager = new AliTRDdigitsManager();
537 fDigitsManager->SetSDigits(fSDigits);
538 fDigitsManager->CreateArrays();
539 fDigitsManager->SetEvent(fEvent);
541 // The list for the input s-digits manager to be merged
542 if (fSDigitsManagerList) {
543 fSDigitsManagerList->Delete();
546 fSDigitsManagerList = new TList();
553 //_____________________________________________________________________________
554 Bool_t AliTRDdigitizer::MakeBranch(TTree *tree) const
557 // Create the branches for the digits array
560 return fDigitsManager->MakeBranch(tree);
564 //_____________________________________________________________________________
565 void AliTRDdigitizer::AddSDigitsManager(AliTRDdigitsManager *man)
568 // Add a digits manager for s-digits to the input list.
571 fSDigitsManagerList->Add(man);
575 //_____________________________________________________________________________
576 void AliTRDdigitizer::DeleteSDigitsManager()
579 // Removes digits manager from the input list.
582 fSDigitsManagerList->Delete();
586 //_____________________________________________________________________________
587 Bool_t AliTRDdigitizer::MakeDigits()
593 AliDebug(1,"Start creating digits");
596 AliError("No geometry defined");
600 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
602 AliFatal("Could not get calibration object");
606 const Int_t kNdet = AliTRDgeometry::Ndet();
608 Float_t **hits = new Float_t*[kNdet];
609 Int_t *nhit = new Int_t[kNdet];
610 memset(nhit,0,kNdet*sizeof(Int_t));
612 AliTRDarraySignal *signals = 0x0;
614 // Check the number of time bins from simParam against OCDB,
615 // if OCDB value is not supposed to be used.
616 // As default, the value from OCDB is taken
617 if (AliTRDSimParam::Instance()->GetNTBoverwriteOCDB()) {
618 if (calibration->GetNumberOfTimeBinsDCS() != AliTRDSimParam::Instance()->GetNTimeBins()) {
619 AliWarning(Form("Number of time bins is different to OCDB value [SIM=%d, OCDB=%d]"
620 ,AliTRDSimParam::Instance()->GetNTimeBins()
621 ,calibration->GetNumberOfTimeBinsDCS()));
623 // Save the values for the raw data headers
624 fDigitsManager->GetDigitsParam()->SetNTimeBinsAll(AliTRDSimParam::Instance()->GetNTimeBins());
627 // Save the values for the raw data headers
628 fDigitsManager->GetDigitsParam()->SetNTimeBinsAll(calibration->GetNumberOfTimeBinsDCS());
631 // Save the values for the raw data headers
632 fDigitsManager->GetDigitsParam()->SetADCbaselineAll(AliTRDSimParam::Instance()->GetADCbaseline());
634 // Sort all hits according to detector number
635 if (!SortHits(hits,nhit)) {
636 AliError("Sorting hits failed");
642 // Loop through all detectors
643 for (Int_t det = 0; det < kNdet; det++) {
645 // Detectors that are switched off, not installed, etc.
646 if ((!calibration->IsChamberNoData(det)) &&
647 ( fGeo->ChamberInGeometry(det)) &&
650 signals = new AliTRDarraySignal();
652 // Convert the hits of the current detector to detector signals
653 if (!ConvertHits(det,hits[det],nhit[det],signals)) {
654 AliError(Form("Conversion of hits failed for detector=%d",det));
662 // Convert the detector signals to digits or s-digits
663 if (!ConvertSignals(det,signals)) {
664 AliError(Form("Conversion of signals failed for detector=%d",det));
672 // Delete the signals array
676 } // if: detector status
683 if (AliDataLoader *trklLoader
684 = AliRunLoader::Instance()->GetLoader("TRDLoader")->GetDataLoader("tracklets")) {
685 if (trklLoader->Tree())
686 trklLoader->WriteData("OVERWRITE");
697 //_____________________________________________________________________________
698 Bool_t AliTRDdigitizer::SortHits(Float_t **hits, Int_t *nhit)
701 // Read all the hits and sorts them according to detector number
702 // in the output array <hits>.
705 AliDebug(1,"Start sorting hits");
707 const Int_t kNdet = AliTRDgeometry::Ndet();
708 // Size of the hit vector
709 const Int_t kNhit = 6;
714 Int_t *lhit = new Int_t[kNdet];
715 memset(lhit,0,kNdet*sizeof(Int_t));
717 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");
731 fTRD->SetTreeAddress();
733 // Get the number of entries in the hit tree
734 // (Number of primary particles creating a hit somewhere)
735 Int_t nTrk = (Int_t) hitTree->GetEntries();
736 AliDebug(1,Form("Found %d tracks",nTrk));
738 // Loop through all the tracks in the tree
739 for (Int_t iTrk = 0; iTrk < nTrk; iTrk++) {
741 gAlice->GetMCApp()->ResetHits();
742 hitTree->GetEvent(iTrk);
745 AliError(Form("No hits array for track = %d",iTrk));
749 // Number of hits for this track
750 nhitTrk = fTRD->Hits()->GetEntriesFast();
753 // Loop through the TRD hits
754 AliTRDhit *hit = (AliTRDhit *) fTRD->FirstHit(-1);
759 // Don't analyze test hits
760 if (((Int_t) hit->GetCharge()) != 0) {
762 Int_t trk = hit->Track();
763 Int_t det = hit->GetDetector();
764 Int_t q = hit->GetCharge();
765 Float_t x = hit->X();
766 Float_t y = hit->Y();
767 Float_t z = hit->Z();
768 Float_t time = hit->GetTime();
770 if (nhit[det] == lhit[det]) {
771 // Inititialization of new detector
772 xyz = new Float_t[kNhit*(nhitTrk+lhit[det])];
774 memcpy(xyz,hits[det],sizeof(Float_t)*kNhit*lhit[det]);
777 lhit[det] += nhitTrk;
783 xyz[nhit[det]*kNhit+0] = x;
784 xyz[nhit[det]*kNhit+1] = y;
785 xyz[nhit[det]*kNhit+2] = z;
786 xyz[nhit[det]*kNhit+3] = q;
787 xyz[nhit[det]*kNhit+4] = trk;
788 xyz[nhit[det]*kNhit+5] = time;
793 hit = (AliTRDhit *) fTRD->NextHit();
795 } // for: hits of one track
805 //_____________________________________________________________________________
806 Bool_t AliTRDdigitizer::ConvertHits(Int_t det
807 , const Float_t * const hits
809 , AliTRDarraySignal *signals)
812 // Converts the detectorwise sorted hits to detector signals
815 AliDebug(1,Form("Start converting hits for detector=%d (nhits=%d)",det,nhit));
817 // Number of pads included in the pad response
818 const Int_t kNpad = 3;
819 // Number of track dictionary arrays
820 const Int_t kNdict = AliTRDdigitsManager::kNDict;
821 // Size of the hit vector
822 const Int_t kNhit = 6;
824 // Width of the amplification region
825 const Float_t kAmWidth = AliTRDgeometry::AmThick();
826 // Width of the drift region
827 const Float_t kDrWidth = AliTRDgeometry::DrThick();
828 // Drift + amplification region
829 const Float_t kDrMin = - 0.5 * kAmWidth;
830 const Float_t kDrMax = kDrWidth + 0.5 * kAmWidth;
834 Int_t timeBinTRFend = 1;
838 Double_t padSignal[kNpad];
839 Double_t signalOld[kNpad];
841 AliTRDarrayDictionary *dictionary[kNdict];
843 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
844 AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance();
845 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
848 AliFatal("Could not get common parameterss");
852 AliFatal("Could not get simulation parameters");
856 AliFatal("Could not get calibration object");
860 // Get the detector wise calibration objects
861 AliTRDCalROC *calVdriftROC = 0;
862 Float_t calVdriftDetValue = 0.0;
863 const AliTRDCalDet *calVdriftDet = calibration->GetVdriftDet();
864 AliTRDCalROC *calT0ROC = 0;
865 Float_t calT0DetValue = 0.0;
866 const AliTRDCalDet *calT0Det = calibration->GetT0Det();
867 Double_t calExBDetValue = 0.0;
868 const AliTRDCalDet *calExBDet = calibration->GetExBDet();
870 if (simParam->TRFOn()) {
871 timeBinTRFend = ((Int_t) (simParam->GetTRFhi()
872 * commonParam->GetSamplingFrequency())) - 1;
875 Int_t nTimeTotal = fDigitsManager->GetDigitsParam()->GetNTimeBins(det);
876 Float_t samplingRate = commonParam->GetSamplingFrequency();
877 Float_t elAttachProp = simParam->GetElAttachProp() / 100.0;
879 AliTRDpadPlane *padPlane = fGeo->GetPadPlane(det);
880 Int_t layer = fGeo->GetLayer(det); //update
881 Float_t row0 = padPlane->GetRow0ROC();
882 Int_t nRowMax = padPlane->GetNrows();
883 Int_t nColMax = padPlane->GetNcols();
885 // Create a new array for the signals
886 signals->Allocate(nRowMax,nColMax,nTimeTotal);
888 // Create a new array for the dictionary
889 for (dict = 0; dict < kNdict; dict++) {
890 dictionary[dict] = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
891 dictionary[dict]->Allocate(nRowMax,nColMax,nTimeTotal);
894 // Loop through the hits in this detector
895 for (Int_t hit = 0; hit < nhit; hit++) {
897 pos[0] = hits[hit*kNhit+0];
898 pos[1] = hits[hit*kNhit+1];
899 pos[2] = hits[hit*kNhit+2];
900 Float_t q = hits[hit*kNhit+3];
901 Float_t hittime = hits[hit*kNhit+5];
902 Int_t track = ((Int_t) hits[hit*kNhit+4]);
906 // Find the current volume with the geo manager
907 gGeoManager->SetCurrentPoint(pos);
908 gGeoManager->FindNode();
909 if (strstr(gGeoManager->GetPath(),"/UK")) {
913 // Get the calibration objects
914 calVdriftROC = calibration->GetVdriftROC(det);
915 calVdriftDetValue = calVdriftDet->GetValue(det);
916 calT0ROC = calibration->GetT0ROC(det);
917 calT0DetValue = calT0Det->GetValue(det);
918 calExBDetValue = calExBDet->GetValue(det);
920 // Go to the local coordinate system:
921 // loc[0] - col direction in amplification or driftvolume
922 // loc[1] - row direction in amplification or driftvolume
923 // loc[2] - time direction in amplification or driftvolume
924 gGeoManager->MasterToLocal(pos,loc);
926 // Relative to middle of amplification region
927 loc[2] = loc[2] - kDrWidth/2.0 - kAmWidth/2.0;
930 // The driftlength [cm] (w/o diffusion yet !).
931 // It is negative if the hit is between pad plane and anode wires.
932 Double_t driftlength = -1.0 * loc[2];
934 // Stupid patch to take care of TR photons that are absorbed
935 // outside the chamber volume. A real fix would actually need
936 // a more clever implementation of the TR hit generation
938 if ((loc[1] < padPlane->GetRowEndROC()) ||
939 (loc[1] > padPlane->GetRow0ROC())) {
942 if ((driftlength < kDrMin) ||
943 (driftlength > kDrMax)) {
948 // Get row and col of unsmeared electron to retrieve drift velocity
949 // The pad row (z-direction)
950 Int_t rowE = padPlane->GetPadRowNumberROC(loc[1]);
954 Double_t rowOffset = padPlane->GetPadRowOffsetROC(rowE,loc[1]);
955 // The pad column (rphi-direction)
956 Double_t offsetTilt = padPlane->GetTiltOffset(rowOffset);
957 Int_t colE = padPlane->GetPadColNumber(loc[0]+offsetTilt);
961 Double_t colOffset = 0.0;
963 // Normalized drift length
964 Float_t driftvelocity = calVdriftDetValue * calVdriftROC->GetValue(colE,rowE);
965 Double_t absdriftlength = TMath::Abs(driftlength);
966 if (commonParam->ExBOn()) {
967 absdriftlength /= TMath::Sqrt(1.0 / (1.0 + calExBDetValue*calExBDetValue));
970 // Loop over all electrons of this hit
971 // TR photons produce hits with negative charge
972 Int_t nEl = ((Int_t) TMath::Abs(q));
973 for (Int_t iEl = 0; iEl < nEl; iEl++) {
975 // Now the real local coordinate system of the ROC
976 // column direction: locC
977 // row direction: locR
978 // time direction: locT
979 // locR and locC are identical to the coordinates of the corresponding
980 // volumina of the drift or amplification region.
981 // locT is defined relative to the wire plane (i.e. middle of amplification
982 // region), meaning locT = 0, and is negative for hits coming from the
984 Double_t locC = loc[0];
985 Double_t locR = loc[1];
986 Double_t locT = loc[2];
988 // Electron attachment
989 if (simParam->ElAttachOn()) {
990 if (gRandom->Rndm() < (absdriftlength * elAttachProp)) {
995 // Apply the diffusion smearing
996 if (simParam->DiffusionOn()) {
997 if (!(Diffusion(driftvelocity,absdriftlength,calExBDetValue,locR,locC,locT))) {
1002 // Apply E x B effects (depends on drift direction)
1003 if (commonParam->ExBOn()) {
1004 locC = locC + calExBDetValue * driftlength;
1007 // The electron position after diffusion and ExB in pad coordinates.
1008 // The pad row (z-direction)
1009 rowE = padPlane->GetPadRowNumberROC(locR);
1010 if (rowE < 0) continue;
1011 rowOffset = padPlane->GetPadRowOffsetROC(rowE,locR);
1013 // The pad column (rphi-direction)
1014 offsetTilt = padPlane->GetTiltOffset(rowOffset);
1015 colE = padPlane->GetPadColNumber(locC+offsetTilt);
1016 if (colE < 0) continue;
1017 colOffset = padPlane->GetPadColOffset(colE,locC+offsetTilt);
1019 // Also re-retrieve drift velocity because col and row may have changed
1020 driftvelocity = calVdriftDetValue * calVdriftROC->GetValue(colE,rowE);
1021 Float_t t0 = calT0DetValue + calT0ROC->GetValue(colE,rowE);
1023 // Convert the position to drift time [mus], using either constant drift velocity or
1024 // time structure of drift cells (non-isochronity, GARFIELD calculation).
1025 // Also add absolute time of hits to take pile-up events into account properly
1027 if (simParam->TimeStructOn()) {
1028 // Get z-position with respect to anode wire
1029 Double_t zz = row0 - locR + padPlane->GetAnodeWireOffset();
1030 zz -= ((Int_t)(2 * zz)) / 2.0;
1034 // Use drift time map (GARFIELD)
1035 drifttime = commonParam->TimeStruct(driftvelocity,0.5*kAmWidth-1.0*locT,zz)
1039 // Use constant drift velocity
1040 drifttime = TMath::Abs(locT) / driftvelocity
1044 // Apply the gas gain including fluctuations
1045 Double_t ggRndm = 0.0;
1047 ggRndm = gRandom->Rndm();
1048 } while (ggRndm <= 0);
1049 Double_t signal = -(simParam->GetGasGain()) * TMath::Log(ggRndm);
1051 // Apply the pad response
1052 if (simParam->PRFOn()) {
1053 // The distance of the electron to the center of the pad
1054 // in units of pad width
1055 Double_t dist = (colOffset - 0.5*padPlane->GetColSize(colE))
1056 / padPlane->GetColSize(colE);
1057 // This is a fixed parametrization, i.e. not dependent on
1058 // calibration values !
1059 if (!(calibration->PadResponse(signal,dist,layer,padSignal))) continue;
1063 padSignal[1] = signal;
1067 // The time bin (always positive), with t0 distortion
1068 Double_t timeBinIdeal = drifttime * samplingRate + t0;
1070 if (TMath::Abs(timeBinIdeal) > 2*nTimeTotal) {
1071 timeBinIdeal = 2 * nTimeTotal;
1073 Int_t timeBinTruncated = ((Int_t) timeBinIdeal);
1074 // The distance of the position to the middle of the timebin
1075 Double_t timeOffset = ((Float_t) timeBinTruncated
1076 + 0.5 - timeBinIdeal) / samplingRate;
1078 // Sample the time response inside the drift region
1079 // + additional time bins before and after.
1080 // The sampling is done always in the middle of the time bin
1081 for (Int_t iTimeBin = TMath::Max(timeBinTruncated,0)
1082 ;iTimeBin < TMath::Min(timeBinTruncated+timeBinTRFend,nTimeTotal)
1085 // Apply the time response
1086 Double_t timeResponse = 1.0;
1087 Double_t crossTalk = 0.0;
1088 Double_t time = (iTimeBin - timeBinTruncated) / samplingRate + timeOffset;
1090 if (simParam->TRFOn()) {
1091 timeResponse = simParam->TimeResponse(time);
1093 if (simParam->CTOn()) {
1094 crossTalk = simParam->CrossTalk(time);
1101 for (iPad = 0; iPad < kNpad; iPad++) {
1103 Int_t colPos = colE + iPad - 1;
1104 if (colPos < 0) continue;
1105 if (colPos >= nColMax) break;
1108 signalOld[iPad] = signals->GetData(rowE,colPos,iTimeBin);
1110 if (colPos != colE) {
1111 // Cross talk added to non-central pads
1112 signalOld[iPad] += padSignal[iPad]
1113 * (timeResponse + crossTalk);
1116 // W/o cross talk at central pad
1117 signalOld[iPad] += padSignal[iPad]
1121 signals->SetData(rowE,colPos,iTimeBin,signalOld[iPad]);
1123 // Store the track index in the dictionary
1124 // Note: We store index+1 in order to allow the array to be compressed
1125 // Note2: Taking out the +1 in track
1126 if (signalOld[iPad] > 0.0) {
1127 for (dict = 0; dict < kNdict; dict++) {
1128 Int_t oldTrack = dictionary[dict]->GetData(rowE,colPos,iTimeBin);
1129 if (oldTrack == track) break;
1130 if (oldTrack == -1 ) {
1131 dictionary[dict]->SetData(rowE,colPos,iTimeBin,track);
1139 } // Loop: time bins
1141 } // Loop: electrons of a single hit
1145 AliDebug(2,Form("Finished analyzing %d hits",nhit));
1151 //_____________________________________________________________________________
1152 Bool_t AliTRDdigitizer::ConvertSignals(Int_t det, AliTRDarraySignal *signals)
1155 // Convert signals to digits
1158 AliDebug(1,Form("Start converting the signals for detector %d",det));
1161 // Convert the signal array to s-digits
1162 if (!Signal2SDigits(det,signals)) {
1167 // Convert the signal array to digits
1168 if (!Signal2ADC(det,signals)) {
1171 // Run digital processing for digits
1172 RunDigitalProcessing(det);
1175 // Compress the arrays
1176 CompressOutputArrays(det);
1182 //_____________________________________________________________________________
1183 Bool_t AliTRDdigitizer::Signal2ADC(Int_t det, AliTRDarraySignal *signals)
1186 // Converts the sampled electron signals to ADC values for a given chamber
1189 AliDebug(1,Form("Start converting signals to ADC values for detector=%d",det));
1191 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1193 AliFatal("Could not get calibration object");
1197 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
1199 AliFatal("Could not get simulation parameters");
1203 // Converts number of electrons to fC
1204 const Double_t kEl2fC = 1.602e-19 * 1.0e15;
1207 Double_t coupling = simParam->GetPadCoupling()
1208 * simParam->GetTimeCoupling();
1209 // Electronics conversion factor
1210 Double_t convert = kEl2fC
1211 * simParam->GetChipGain();
1212 // ADC conversion factor
1213 Double_t adcConvert = simParam->GetADCoutRange()
1214 / simParam->GetADCinRange();
1215 // The electronics baseline in mV
1216 Double_t baseline = simParam->GetADCbaseline()
1218 // The electronics baseline in electrons
1219 Double_t baselineEl = baseline
1226 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1227 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1228 Int_t nTimeTotal = fDigitsManager->GetDigitsParam()->GetNTimeBins(det);
1229 if (fSDigitsManager->GetDigitsParam()->GetNTimeBins(det)) {
1230 nTimeTotal = fSDigitsManager->GetDigitsParam()->GetNTimeBins(det);
1233 AliFatal("Could not get number of time bins");
1237 // The gain factor calibration objects
1238 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
1239 AliTRDCalROC *calGainFactorROC = 0x0;
1240 Float_t calGainFactorDetValue = 0.0;
1242 AliTRDarrayADC *digits = 0x0;
1245 AliError(Form("Signals array for detector %d does not exist\n",det));
1248 if (signals->HasData()) {
1249 // Expand the container if neccessary
1253 // Create missing containers
1254 signals->Allocate(nRowMax,nColMax,nTimeTotal);
1257 // Get the container for the digits of this detector
1258 if (fDigitsManager->HasSDigits()) {
1259 AliError("Digits manager has s-digits");
1263 digits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det);
1264 // Allocate memory space for the digits buffer
1265 if (!digits->HasData()) {
1266 digits->Allocate(nRowMax,nColMax,nTimeTotal);
1269 // Get the calibration objects
1270 calGainFactorROC = calibration->GetGainFactorROC(det);
1271 calGainFactorDetValue = calGainFactorDet->GetValue(det);
1273 // Create the digits for this chamber
1274 for (row = 0; row < nRowMax; row++ ) {
1275 for (col = 0; col < nColMax; col++ ) {
1277 // Check whether pad is masked
1278 // Bridged pads are not considered yet!!!
1279 if (calibration->IsPadMasked(det,col,row) ||
1280 calibration->IsPadNotConnected(det,col,row)) {
1285 Float_t padgain = calGainFactorDetValue
1286 * calGainFactorROC->GetValue(col,row);
1288 AliError(Form("Not a valid gain %f, %d %d %d",padgain,det,col,row));
1291 for (time = 0; time < nTimeTotal; time++) {
1293 // Get the signal amplitude
1294 Float_t signalAmp = signals->GetData(row,col,time);
1295 // Pad and time coupling
1296 signalAmp *= coupling;
1298 signalAmp *= padgain;
1300 // Add the noise, starting from minus ADC baseline in electrons
1301 signalAmp = TMath::Max((Double_t) gRandom->Gaus(signalAmp,simParam->GetNoise())
1305 signalAmp *= convert;
1306 // Add ADC baseline in mV
1307 signalAmp += baseline;
1309 // Convert to ADC counts. Set the overflow-bit fADCoutRange if the
1310 // signal is larger than fADCinRange
1312 if (signalAmp >= simParam->GetADCinRange()) {
1313 adc = ((Short_t) simParam->GetADCoutRange());
1316 adc = TMath::Nint(signalAmp * adcConvert);
1319 // Saving all digits
1320 digits->SetData(row,col,time,adc);
1331 //_____________________________________________________________________________
1332 Bool_t AliTRDdigitizer::Signal2SDigits(Int_t det, AliTRDarraySignal *signals)
1335 // Converts the sampled electron signals to s-digits
1338 AliDebug(1,Form("Start converting signals to s-digits for detector=%d",det));
1340 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1342 AliFatal("Could not get calibration object");
1350 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1351 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1352 Int_t nTimeTotal = fDigitsManager->GetDigitsParam()->GetNTimeBins(det);
1354 // Get the container for the digits of this detector
1355 if (!fDigitsManager->HasSDigits()) {
1356 AliError("Digits manager has no s-digits");
1360 AliTRDarraySignal *digits = (AliTRDarraySignal *) fDigitsManager->GetSDigits(det);
1361 // Allocate memory space for the digits buffer
1362 if (!digits->HasData()) {
1363 digits->Allocate(nRowMax,nColMax,nTimeTotal);
1366 // Create the sdigits for this chamber
1367 for (row = 0; row < nRowMax; row++ ) {
1368 for (col = 0; col < nColMax; col++ ) {
1369 for (time = 0; time < nTimeTotal; time++) {
1370 digits->SetData(row,col,time,signals->GetData(row,col,time));
1379 //_____________________________________________________________________________
1380 Bool_t AliTRDdigitizer::Digits2SDigits(AliTRDdigitsManager * const manDig
1381 , AliTRDdigitsManager * const manSDig)
1384 // Converts digits into s-digits. Needed for embedding into real data.
1387 AliDebug(1,"Start converting digits to s-digits");
1390 fGeo = new AliTRDgeometry();
1393 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1395 AliFatal("Could not get calibration object");
1399 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
1401 AliFatal("Could not get simulation parameters");
1405 // Converts number of electrons to fC
1406 const Double_t kEl2fC = 1.602e-19 * 1.0e15;
1409 Double_t coupling = simParam->GetPadCoupling()
1410 * simParam->GetTimeCoupling();
1411 // Electronics conversion factor
1412 Double_t convert = kEl2fC
1413 * simParam->GetChipGain();
1414 // ADC conversion factor
1415 Double_t adcConvert = simParam->GetADCoutRange()
1416 / simParam->GetADCinRange();
1417 // The electronics baseline in mV
1418 Double_t baseline = simParam->GetADCbaseline()
1420 // The electronics baseline in electrons
1421 //Double_t baselineEl = baseline
1424 // The gainfactor calibration objects
1425 // Not used since these digits are supposed to be from real raw data
1426 //const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
1427 //AliTRDCalROC *calGainFactorROC = 0;
1428 //Float_t calGainFactorDetValue = 0.0;
1434 for (Int_t det = 0; det < AliTRDgeometry::Ndet(); det++) {
1436 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1437 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1438 Int_t nTimeTotal = manDig->GetDigitsParam()->GetNTimeBins(det);
1440 // Get the calibration objects
1441 //calGainFactorROC = calibration->GetGainFactorROC(det);
1442 //calGainFactorDetValue = calGainFactorDet->GetValue(det);
1445 AliTRDarrayADC *digits = (AliTRDarrayADC *) manDig->GetDigits(det);
1447 if (!manSDig->HasSDigits()) {
1448 AliError("SDigits manager has no s-digits");
1452 AliTRDarraySignal *sdigits = (AliTRDarraySignal *) manSDig->GetSDigits(det);
1453 AliTRDarrayDictionary *tracks0 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,0);
1454 AliTRDarrayDictionary *tracks1 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,1);
1455 AliTRDarrayDictionary *tracks2 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,2);
1456 // Allocate memory space for the digits buffer
1457 sdigits->Allocate(nRowMax,nColMax,nTimeTotal);
1458 tracks0->Allocate(nRowMax,nColMax,nTimeTotal);
1459 tracks1->Allocate(nRowMax,nColMax,nTimeTotal);
1460 tracks2->Allocate(nRowMax,nColMax,nTimeTotal);
1462 // Keep the digits param
1463 manSDig->GetDigitsParam()->SetNTimeBinsAll(manDig->GetDigitsParam()->GetNTimeBins(0));
1464 manSDig->GetDigitsParam()->SetADCbaselineAll(manDig->GetDigitsParam()->GetADCbaseline(0));
1466 if (digits->HasData()) {
1470 // Create the sdigits for this chamber
1471 for (row = 0; row < nRowMax; row++ ) {
1472 for (col = 0; col < nColMax; col++ ) {
1475 //Float_t padgain = calGainFactorDetValue
1476 // * calGainFactorROC->GetValue(col,row);
1478 for (time = 0; time < nTimeTotal; time++) {
1480 Short_t adcVal = digits->GetData(row,col,time);
1481 Double_t signal = (Double_t) adcVal;
1482 // ADC -> signal in mV
1483 signal /= adcConvert;
1484 // Subtract baseline in mV
1486 // Signal in mV -> signal in #electrons
1489 //signal /= padgain; // Not needed for real data
1490 // Pad and time coupling
1493 sdigits->SetData(row,col,time,signal);
1494 tracks0->SetData(row,col,time,0);
1495 tracks1->SetData(row,col,time,0);
1496 tracks2->SetData(row,col,time,0);
1505 sdigits->Compress(0);
1506 tracks0->Compress();
1507 tracks1->Compress();
1508 tracks2->Compress();
1510 // No compress just remove
1511 manDig->RemoveDigits(det);
1512 manDig->RemoveDictionaries(det);
1520 //_____________________________________________________________________________
1521 Bool_t AliTRDdigitizer::SDigits2Digits()
1524 // Merges the input s-digits and converts them to normal digits
1527 if (!MergeSDigits()) {
1531 return ConvertSDigits();
1535 //_____________________________________________________________________________
1536 Bool_t AliTRDdigitizer::MergeSDigits()
1539 // Merges the input s-digits:
1540 // - The amplitude of the different inputs are summed up.
1541 // - Of the track IDs from the input dictionaries only one is
1542 // kept for each input. This works for maximal 3 different merged inputs.
1545 // Number of track dictionary arrays
1546 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1548 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
1550 AliFatal("Could not get simulation parameters");
1554 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1556 AliFatal("Could not get calibration object");
1563 AliTRDarraySignal *digitsA;
1564 AliTRDarraySignal *digitsB;
1565 AliTRDarrayDictionary *dictionaryA[kNDict];
1566 AliTRDarrayDictionary *dictionaryB[kNDict];
1568 AliTRDdigitsManager *mergeSDigitsManager = 0x0;
1569 // Get the first s-digits
1570 fSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->First();
1571 if (!fSDigitsManager) {
1572 AliError("No SDigits manager");
1576 // Loop through the other sets of s-digits
1577 mergeSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->After(fSDigitsManager);
1579 if (mergeSDigitsManager) {
1580 AliDebug(1,Form("Merge %d input files.",fSDigitsManagerList->GetSize()));
1583 AliDebug(1,"Only one input file.");
1588 while (mergeSDigitsManager) {
1592 // Loop through the detectors
1593 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) {
1595 Int_t nTimeTotal = fSDigitsManager->GetDigitsParam()->GetNTimeBins(iDet);
1596 if (mergeSDigitsManager->GetDigitsParam()->GetNTimeBins(iDet) != nTimeTotal) {
1597 AliError(Form("Mismatch in the number of time bins [%d,%d] in detector %d"
1599 ,mergeSDigitsManager->GetDigitsParam()->GetNTimeBins(iDet)
1604 Int_t nRowMax = fGeo->GetPadPlane(iDet)->GetNrows();
1605 Int_t nColMax = fGeo->GetPadPlane(iDet)->GetNcols();
1607 // Loop through the pixels of one detector and add the signals
1608 digitsA = (AliTRDarraySignal *) fSDigitsManager->GetSDigits(iDet);
1609 digitsB = (AliTRDarraySignal *) mergeSDigitsManager->GetSDigits(iDet);
1611 if (!digitsA->HasData()) continue;
1613 if (!digitsB->HasData()) continue;
1615 for (iDict = 0; iDict < kNDict; iDict++) {
1616 dictionaryA[iDict] = (AliTRDarrayDictionary *) fSDigitsManager->GetDictionary(iDet,iDict);
1617 dictionaryB[iDict] = (AliTRDarrayDictionary *) mergeSDigitsManager->GetDictionary(iDet,iDict);
1618 dictionaryA[iDict]->Expand();
1619 dictionaryB[iDict]->Expand();
1622 // Merge only detectors that contain a signal
1623 Bool_t doMerge = kTRUE;
1624 if (fMergeSignalOnly) {
1625 if (digitsA->GetOverThreshold(0) == 0) {
1632 AliDebug(1,Form("Merge detector %d of input no.%d",iDet,iMerge+1));
1634 for (Int_t iRow = 0; iRow < nRowMax; iRow++ ) {
1635 for (Int_t iCol = 0; iCol < nColMax; iCol++ ) {
1636 for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
1638 // Add the amplitudes of the summable digits
1639 Float_t ampA = digitsA->GetData(iRow,iCol,iTime);
1640 Float_t ampB = digitsB->GetData(iRow,iCol,iTime);
1642 digitsA->SetData(iRow,iCol,iTime,ampA);
1644 // Add the mask to the track id if defined.
1645 for (iDict = 0; iDict < kNDict; iDict++) {
1646 Int_t trackB = dictionaryB[iDict]->GetData(iRow,iCol,iTime);
1647 if ((fMasks) && (trackB > 0)) {
1648 for (jDict = 0; jDict < kNDict; jDict++) {
1649 Int_t trackA = dictionaryA[iDict]->GetData(iRow,iCol,iTime);
1651 trackA = trackB + fMasks[iMerge];
1652 dictionaryA[iDict]->SetData(iRow,iCol,iTime,trackA);
1653 } // if: track A == 0
1655 } // if: fMasks and trackB > 0
1664 mergeSDigitsManager->RemoveDigits(iDet);
1665 mergeSDigitsManager->RemoveDictionaries(iDet);
1668 digitsA->Compress(0);
1669 for (iDict = 0; iDict < kNDict; iDict++) {
1670 dictionaryA[iDict]->Compress();
1676 // The next set of s-digits
1677 mergeSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->After(mergeSDigitsManager);
1679 } // while: mergeDigitsManagers
1685 //_____________________________________________________________________________
1686 Bool_t AliTRDdigitizer::ConvertSDigits()
1689 // Converts s-digits to normal digits
1692 AliTRDarraySignal *digitsIn = 0x0;
1694 if (!fSDigitsManager->HasSDigits()) {
1695 AliError("No s-digits in digits manager");
1699 // Loop through the detectors
1700 for (Int_t det = 0; det < AliTRDgeometry::Ndet(); det++) {
1702 // Get the merged s-digits (signals)
1703 digitsIn = (AliTRDarraySignal *) fSDigitsManager->GetSDigits(det);
1704 if (!digitsIn->HasData()) {
1705 AliDebug(2,Form("No digits for det=%d",det));
1709 // Convert the merged sdigits to digits
1710 if (!Signal2ADC(det,digitsIn)) {
1714 // Copy the dictionary information to the output array
1715 if (!CopyDictionary(det)) {
1720 fSDigitsManager->RemoveDigits(det);
1721 fSDigitsManager->RemoveDictionaries(det);
1723 // Run digital processing
1724 RunDigitalProcessing(det);
1726 // Compress the arrays
1727 CompressOutputArrays(det);
1729 } // for: detector numbers
1731 if (AliDataLoader *trklLoader = AliRunLoader::Instance()->GetLoader("TRDLoader")->GetDataLoader("tracklets")) {
1732 if (trklLoader->Tree())
1733 trklLoader->WriteData("OVERWRITE");
1736 // Save the values for the raw data headers
1737 if (AliTRDSimParam::Instance()->GetNTBoverwriteOCDB()) {
1738 fDigitsManager->GetDigitsParam()->SetNTimeBinsAll(AliTRDSimParam::Instance()->GetNTimeBins());
1741 fDigitsManager->GetDigitsParam()->SetNTimeBinsAll(AliTRDcalibDB::Instance()->GetNumberOfTimeBinsDCS());
1743 fDigitsManager->GetDigitsParam()->SetADCbaselineAll(AliTRDSimParam::Instance()->GetADCbaseline());
1749 //_____________________________________________________________________________
1750 Bool_t AliTRDdigitizer::CopyDictionary(Int_t det)
1753 // Copies the dictionary information from the s-digits arrays
1754 // to the output arrays
1757 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1759 AliFatal("Could not get calibration object");
1763 AliDebug(1,Form("Start copying dictionaries for detector=%d",det));
1765 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1766 AliTRDarrayDictionary *dictionaryIn[kNDict];
1767 AliTRDarrayDictionary *dictionaryOut[kNDict];
1769 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1770 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1771 Int_t nTimeTotal = fSDigitsManager->GetDigitsParam()->GetNTimeBins(det);
1778 for (dict = 0; dict < kNDict; dict++) {
1780 dictionaryIn[dict] = (AliTRDarrayDictionary *) fSDigitsManager->GetDictionary(det,dict);
1781 dictionaryIn[dict]->Expand();
1782 dictionaryOut[dict] = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
1783 dictionaryOut[dict]->Allocate(nRowMax,nColMax,nTimeTotal);
1785 for (row = 0; row < nRowMax; row++) {
1786 for (col = 0; col < nColMax; col++) {
1787 for (time = 0; time < nTimeTotal; time++) {
1788 Int_t track = dictionaryIn[dict]->GetData(row,col,time);
1789 dictionaryOut[dict]->SetData(row,col,time,track);
1794 } // for: dictionaries
1800 //_____________________________________________________________________________
1801 void AliTRDdigitizer::CompressOutputArrays(Int_t det)
1804 // Compress the output arrays
1807 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1808 AliTRDarrayDictionary *dictionary = 0x0;
1813 AliTRDarrayADC *digits = 0x0;
1814 digits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det);
1819 AliTRDarraySignal *digits = 0x0;
1820 digits = (AliTRDarraySignal *) fDigitsManager->GetSDigits(det);
1821 digits->Compress(0);
1824 for (Int_t dict = 0; dict < kNDict; dict++) {
1825 dictionary = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
1826 dictionary->Compress();
1833 //_____________________________________________________________________________
1834 Bool_t AliTRDdigitizer::WriteDigits() const
1837 // Writes out the TRD-digits and the dictionaries
1841 fRunLoader->CdGAFile();
1843 // Store the digits and the dictionary in the tree
1844 return fDigitsManager->WriteDigits();
1848 //_____________________________________________________________________________
1849 void AliTRDdigitizer::InitOutput(Int_t iEvent)
1852 // Initializes the output branches
1858 AliError("Run Loader is NULL");
1862 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
1864 AliError("Can not get TRD loader from Run Loader");
1871 // If we produce SDigits
1872 tree = loader->TreeS();
1874 loader->MakeTree("S");
1875 tree = loader->TreeS();
1879 // If we produce Digits
1880 tree = loader->TreeD();
1882 loader->MakeTree("D");
1883 tree = loader->TreeD();
1886 fDigitsManager->SetEvent(iEvent);
1887 fDigitsManager->MakeBranch(tree);
1891 //_____________________________________________________________________________
1892 Int_t AliTRDdigitizer::Diffusion(Float_t vdrift, Double_t absdriftlength
1894 , Double_t &lRow, Double_t &lCol, Double_t &lTime)
1897 // Applies the diffusion smearing to the position of a single electron.
1898 // Depends on absolute drift length.
1901 Float_t diffL = 0.0;
1902 Float_t diffT = 0.0;
1904 if (AliTRDCommonParam::Instance()->GetDiffCoeff(diffL,diffT,vdrift)) {
1906 Float_t driftSqrt = TMath::Sqrt(absdriftlength);
1907 Float_t sigmaT = driftSqrt * diffT;
1908 Float_t sigmaL = driftSqrt * diffL;
1909 lRow = gRandom->Gaus(lRow ,sigmaT);
1910 if (AliTRDCommonParam::Instance()->ExBOn()) {
1911 lCol = gRandom->Gaus(lCol ,sigmaT * 1.0 / (1.0 + exbvalue*exbvalue));
1912 lTime = gRandom->Gaus(lTime,sigmaL * 1.0 / (1.0 + exbvalue*exbvalue));
1915 lCol = gRandom->Gaus(lCol ,sigmaT);
1916 lTime = gRandom->Gaus(lTime,sigmaL);
1930 //_____________________________________________________________________________
1931 void AliTRDdigitizer::RunDigitalProcessing(Int_t det)
1934 // Run the digital processing in the TRAP
1937 AliTRDfeeParam *feeParam = AliTRDfeeParam::Instance();
1939 AliTRDarrayADC *digits = fDigitsManager->GetDigits(det);
1943 //Call the methods in the mcm class using the temporary array as input
1944 // process the data in the same order as in hardware
1945 for (Int_t side = 0; side <= 1; side++) {
1946 for(Int_t rob = side; rob < digits->GetNrow() / 2; rob += 2) {
1947 for(Int_t mcm = 0; mcm < 16; mcm++) {
1948 fMcmSim->Init(det, rob, mcm);
1949 fMcmSim->SetDataByPad(digits, fDigitsManager);
1951 if (feeParam->GetTracklet()) {
1952 fMcmSim->Tracklet();
1953 fMcmSim->StoreTracklets();
1955 fMcmSim->ZSMapping();
1956 fMcmSim->WriteData(digits);