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 // Get the OCDB values
628 Int_t nTB = calibration->GetNumberOfTimeBinsDCS();
629 if (nTB < 0) { // Currently -1 gets returned for "undefined" and "mixed",
630 // one might go back to -1 undefined and -2 mixed?
631 AliError("No useful DCS information available for this run! Using standard values.");
632 // // We fall back to the standard OCDB object,
633 // // cache the current run number..
634 // Long64_t run = calibration->GetRun();
635 // calibration->SetRun(0);
636 // nTB = calibration->GetNumberOfTimeBinsDCS();
637 // // ..to set it again
638 // calibration->SetRun(run);
639 // // If there's no standard OCDB object, we can still fail
641 // AliFatal("No standard object found in the OCDB!");
643 nTB = AliTRDSimParam::Instance()->GetNTimeBins();
645 // Save the values for the raw data headers
646 fDigitsManager->GetDigitsParam()->SetNTimeBinsAll(nTB);
649 // Save the values for the raw data headers
650 fDigitsManager->GetDigitsParam()->SetADCbaselineAll(AliTRDSimParam::Instance()->GetADCbaseline());
652 // Sort all hits according to detector number
653 if (!SortHits(hits,nhit)) {
654 AliError("Sorting hits failed");
660 // Loop through all detectors
661 for (Int_t det = 0; det < kNdet; det++) {
663 // Detectors that are switched off, not installed, etc.
664 if ((!calibration->IsChamberNoData(det)) &&
665 ( fGeo->ChamberInGeometry(det)) &&
668 signals = new AliTRDarraySignal();
670 // Convert the hits of the current detector to detector signals
671 if (!ConvertHits(det,hits[det],nhit[det],signals)) {
672 AliError(Form("Conversion of hits failed for detector=%d",det));
680 // Convert the detector signals to digits or s-digits
681 if (!ConvertSignals(det,signals)) {
682 AliError(Form("Conversion of signals failed for detector=%d",det));
690 // Delete the signals array
694 } // if: detector status
701 if (AliDataLoader *trklLoader
702 = AliRunLoader::Instance()->GetLoader("TRDLoader")->GetDataLoader("tracklets")) {
703 if (trklLoader->Tree())
704 trklLoader->WriteData("OVERWRITE");
715 //_____________________________________________________________________________
716 Bool_t AliTRDdigitizer::SortHits(Float_t **hits, Int_t *nhit)
719 // Read all the hits and sorts them according to detector number
720 // in the output array <hits>.
723 AliDebug(1,"Start sorting hits");
725 const Int_t kNdet = AliTRDgeometry::Ndet();
726 // Size of the hit vector
727 const Int_t kNhit = 6;
732 Int_t *lhit = new Int_t[kNdet];
733 memset(lhit,0,kNdet*sizeof(Int_t));
735 for (Int_t det = 0; det < kNdet; det++) {
739 AliLoader *gimme = fRunLoader->GetLoader("TRDLoader");
740 if (!gimme->TreeH()) {
743 TTree *hitTree = gimme->TreeH();
744 if (hitTree == 0x0) {
745 AliError("Can not get TreeH");
749 fTRD->SetTreeAddress();
751 // Get the number of entries in the hit tree
752 // (Number of primary particles creating a hit somewhere)
753 Int_t nTrk = (Int_t) hitTree->GetEntries();
754 AliDebug(1,Form("Found %d tracks",nTrk));
756 // Loop through all the tracks in the tree
757 for (Int_t iTrk = 0; iTrk < nTrk; iTrk++) {
759 gAlice->GetMCApp()->ResetHits();
760 hitTree->GetEvent(iTrk);
763 AliError(Form("No hits array for track = %d",iTrk));
767 // Number of hits for this track
768 nhitTrk = fTRD->Hits()->GetEntriesFast();
771 // Loop through the TRD hits
772 AliTRDhit *hit = (AliTRDhit *) fTRD->FirstHit(-1);
777 // Don't analyze test hits
778 if (((Int_t) hit->GetCharge()) != 0) {
780 Int_t trk = hit->Track();
781 Int_t det = hit->GetDetector();
782 Int_t q = hit->GetCharge();
783 Float_t x = hit->X();
784 Float_t y = hit->Y();
785 Float_t z = hit->Z();
786 Float_t time = hit->GetTime();
788 if (nhit[det] == lhit[det]) {
789 // Inititialization of new detector
790 xyz = new Float_t[kNhit*(nhitTrk+lhit[det])];
792 memcpy(xyz,hits[det],sizeof(Float_t)*kNhit*lhit[det]);
795 lhit[det] += nhitTrk;
801 xyz[nhit[det]*kNhit+0] = x;
802 xyz[nhit[det]*kNhit+1] = y;
803 xyz[nhit[det]*kNhit+2] = z;
804 xyz[nhit[det]*kNhit+3] = q;
805 xyz[nhit[det]*kNhit+4] = trk;
806 xyz[nhit[det]*kNhit+5] = time;
811 hit = (AliTRDhit *) fTRD->NextHit();
813 } // for: hits of one track
823 //_____________________________________________________________________________
824 Bool_t AliTRDdigitizer::ConvertHits(Int_t det
825 , const Float_t * const hits
827 , AliTRDarraySignal *signals)
830 // Converts the detectorwise sorted hits to detector signals
833 AliDebug(1,Form("Start converting hits for detector=%d (nhits=%d)",det,nhit));
835 // Number of pads included in the pad response
836 const Int_t kNpad = 3;
837 // Number of track dictionary arrays
838 const Int_t kNdict = AliTRDdigitsManager::kNDict;
839 // Size of the hit vector
840 const Int_t kNhit = 6;
842 // Width of the amplification region
843 const Float_t kAmWidth = AliTRDgeometry::AmThick();
844 // Width of the drift region
845 const Float_t kDrWidth = AliTRDgeometry::DrThick();
846 // Drift + amplification region
847 const Float_t kDrMin = - 0.5 * kAmWidth;
848 const Float_t kDrMax = kDrWidth + 0.5 * kAmWidth;
852 Int_t timeBinTRFend = 1;
856 Double_t padSignal[kNpad];
857 Double_t signalOld[kNpad];
859 AliTRDarrayDictionary *dictionary[kNdict];
861 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
862 AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance();
863 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
866 AliFatal("Could not get common parameterss");
870 AliFatal("Could not get simulation parameters");
874 AliFatal("Could not get calibration object");
878 // Get the detector wise calibration objects
879 AliTRDCalROC *calVdriftROC = 0;
880 Float_t calVdriftDetValue = 0.0;
881 const AliTRDCalDet *calVdriftDet = calibration->GetVdriftDet();
882 AliTRDCalROC *calT0ROC = 0;
883 Float_t calT0DetValue = 0.0;
884 const AliTRDCalDet *calT0Det = calibration->GetT0Det();
885 Double_t calExBDetValue = 0.0;
886 const AliTRDCalDet *calExBDet = calibration->GetExBDet();
888 if (simParam->TRFOn()) {
889 timeBinTRFend = ((Int_t) (simParam->GetTRFhi()
890 * commonParam->GetSamplingFrequency())) - 1;
893 Int_t nTimeTotal = fDigitsManager->GetDigitsParam()->GetNTimeBins(det);
894 Float_t samplingRate = commonParam->GetSamplingFrequency();
895 Float_t elAttachProp = simParam->GetElAttachProp() / 100.0;
897 AliTRDpadPlane *padPlane = fGeo->GetPadPlane(det);
898 Int_t layer = fGeo->GetLayer(det); //update
899 Float_t row0 = padPlane->GetRow0ROC();
900 Int_t nRowMax = padPlane->GetNrows();
901 Int_t nColMax = padPlane->GetNcols();
903 // Create a new array for the signals
904 signals->Allocate(nRowMax,nColMax,nTimeTotal);
906 // Create a new array for the dictionary
907 for (dict = 0; dict < kNdict; dict++) {
908 dictionary[dict] = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
909 dictionary[dict]->Allocate(nRowMax,nColMax,nTimeTotal);
912 // Loop through the hits in this detector
913 for (Int_t hit = 0; hit < nhit; hit++) {
915 pos[0] = hits[hit*kNhit+0];
916 pos[1] = hits[hit*kNhit+1];
917 pos[2] = hits[hit*kNhit+2];
918 Float_t q = hits[hit*kNhit+3];
919 Float_t hittime = hits[hit*kNhit+5];
920 Int_t track = ((Int_t) hits[hit*kNhit+4]);
924 // Find the current volume with the geo manager
925 gGeoManager->SetCurrentPoint(pos);
926 gGeoManager->FindNode();
927 if (strstr(gGeoManager->GetPath(),"/UK")) {
931 // Get the calibration objects
932 calVdriftROC = calibration->GetVdriftROC(det);
933 calVdriftDetValue = calVdriftDet->GetValue(det);
934 calT0ROC = calibration->GetT0ROC(det);
935 calT0DetValue = calT0Det->GetValue(det);
936 calExBDetValue = calExBDet->GetValue(det);
938 // Go to the local coordinate system:
939 // loc[0] - col direction in amplification or driftvolume
940 // loc[1] - row direction in amplification or driftvolume
941 // loc[2] - time direction in amplification or driftvolume
942 gGeoManager->MasterToLocal(pos,loc);
944 // Relative to middle of amplification region
945 loc[2] = loc[2] - kDrWidth/2.0 - kAmWidth/2.0;
948 // The driftlength [cm] (w/o diffusion yet !).
949 // It is negative if the hit is between pad plane and anode wires.
950 Double_t driftlength = -1.0 * loc[2];
952 // Stupid patch to take care of TR photons that are absorbed
953 // outside the chamber volume. A real fix would actually need
954 // a more clever implementation of the TR hit generation
956 if ((loc[1] < padPlane->GetRowEndROC()) ||
957 (loc[1] > padPlane->GetRow0ROC())) {
960 if ((driftlength < kDrMin) ||
961 (driftlength > kDrMax)) {
966 // Get row and col of unsmeared electron to retrieve drift velocity
967 // The pad row (z-direction)
968 Int_t rowE = padPlane->GetPadRowNumberROC(loc[1]);
972 Double_t rowOffset = padPlane->GetPadRowOffsetROC(rowE,loc[1]);
973 // The pad column (rphi-direction)
974 Double_t offsetTilt = padPlane->GetTiltOffset(rowOffset);
975 Int_t colE = padPlane->GetPadColNumber(loc[0]+offsetTilt);
979 Double_t colOffset = 0.0;
981 // Normalized drift length
982 Float_t driftvelocity = calVdriftDetValue * calVdriftROC->GetValue(colE,rowE);
983 Double_t absdriftlength = TMath::Abs(driftlength);
984 if (commonParam->ExBOn()) {
985 absdriftlength /= TMath::Sqrt(1.0 / (1.0 + calExBDetValue*calExBDetValue));
988 // Loop over all electrons of this hit
989 // TR photons produce hits with negative charge
990 Int_t nEl = ((Int_t) TMath::Abs(q));
991 for (Int_t iEl = 0; iEl < nEl; iEl++) {
993 // Now the real local coordinate system of the ROC
994 // column direction: locC
995 // row direction: locR
996 // time direction: locT
997 // locR and locC are identical to the coordinates of the corresponding
998 // volumina of the drift or amplification region.
999 // locT is defined relative to the wire plane (i.e. middle of amplification
1000 // region), meaning locT = 0, and is negative for hits coming from the
1002 Double_t locC = loc[0];
1003 Double_t locR = loc[1];
1004 Double_t locT = loc[2];
1006 // Electron attachment
1007 if (simParam->ElAttachOn()) {
1008 if (gRandom->Rndm() < (absdriftlength * elAttachProp)) {
1013 // Apply the diffusion smearing
1014 if (simParam->DiffusionOn()) {
1015 if (!(Diffusion(driftvelocity,absdriftlength,calExBDetValue,locR,locC,locT))) {
1020 // Apply E x B effects (depends on drift direction)
1021 if (commonParam->ExBOn()) {
1022 locC = locC + calExBDetValue * driftlength;
1025 // The electron position after diffusion and ExB in pad coordinates.
1026 // The pad row (z-direction)
1027 rowE = padPlane->GetPadRowNumberROC(locR);
1028 if (rowE < 0) continue;
1029 rowOffset = padPlane->GetPadRowOffsetROC(rowE,locR);
1031 // The pad column (rphi-direction)
1032 offsetTilt = padPlane->GetTiltOffset(rowOffset);
1033 colE = padPlane->GetPadColNumber(locC+offsetTilt);
1034 if (colE < 0) continue;
1035 colOffset = padPlane->GetPadColOffset(colE,locC+offsetTilt);
1037 // Also re-retrieve drift velocity because col and row may have changed
1038 driftvelocity = calVdriftDetValue * calVdriftROC->GetValue(colE,rowE);
1039 Float_t t0 = calT0DetValue + calT0ROC->GetValue(colE,rowE);
1041 // Convert the position to drift time [mus], using either constant drift velocity or
1042 // time structure of drift cells (non-isochronity, GARFIELD calculation).
1043 // Also add absolute time of hits to take pile-up events into account properly
1045 if (simParam->TimeStructOn()) {
1046 // Get z-position with respect to anode wire
1047 Double_t zz = row0 - locR + padPlane->GetAnodeWireOffset();
1048 zz -= ((Int_t)(2 * zz)) / 2.0;
1052 // Use drift time map (GARFIELD)
1053 drifttime = commonParam->TimeStruct(driftvelocity,0.5*kAmWidth-1.0*locT,zz)
1057 // Use constant drift velocity
1058 drifttime = TMath::Abs(locT) / driftvelocity
1062 // Apply the gas gain including fluctuations
1063 Double_t ggRndm = 0.0;
1065 ggRndm = gRandom->Rndm();
1066 } while (ggRndm <= 0);
1067 Double_t signal = -(simParam->GetGasGain()) * TMath::Log(ggRndm);
1069 // Apply the pad response
1070 if (simParam->PRFOn()) {
1071 // The distance of the electron to the center of the pad
1072 // in units of pad width
1073 Double_t dist = (colOffset - 0.5*padPlane->GetColSize(colE))
1074 / padPlane->GetColSize(colE);
1075 // This is a fixed parametrization, i.e. not dependent on
1076 // calibration values !
1077 if (!(calibration->PadResponse(signal,dist,layer,padSignal))) continue;
1081 padSignal[1] = signal;
1085 // The time bin (always positive), with t0 distortion
1086 Double_t timeBinIdeal = drifttime * samplingRate + t0;
1088 if (TMath::Abs(timeBinIdeal) > 2*nTimeTotal) {
1089 timeBinIdeal = 2 * nTimeTotal;
1091 Int_t timeBinTruncated = ((Int_t) timeBinIdeal);
1092 // The distance of the position to the middle of the timebin
1093 Double_t timeOffset = ((Float_t) timeBinTruncated
1094 + 0.5 - timeBinIdeal) / samplingRate;
1096 // Sample the time response inside the drift region
1097 // + additional time bins before and after.
1098 // The sampling is done always in the middle of the time bin
1099 for (Int_t iTimeBin = TMath::Max(timeBinTruncated,0)
1100 ;iTimeBin < TMath::Min(timeBinTruncated+timeBinTRFend,nTimeTotal)
1103 // Apply the time response
1104 Double_t timeResponse = 1.0;
1105 Double_t crossTalk = 0.0;
1106 Double_t time = (iTimeBin - timeBinTruncated) / samplingRate + timeOffset;
1108 if (simParam->TRFOn()) {
1109 timeResponse = simParam->TimeResponse(time);
1111 if (simParam->CTOn()) {
1112 crossTalk = simParam->CrossTalk(time);
1119 for (iPad = 0; iPad < kNpad; iPad++) {
1121 Int_t colPos = colE + iPad - 1;
1122 if (colPos < 0) continue;
1123 if (colPos >= nColMax) break;
1126 signalOld[iPad] = signals->GetData(rowE,colPos,iTimeBin);
1128 if (colPos != colE) {
1129 // Cross talk added to non-central pads
1130 signalOld[iPad] += padSignal[iPad]
1131 * (timeResponse + crossTalk);
1134 // W/o cross talk at central pad
1135 signalOld[iPad] += padSignal[iPad]
1139 signals->SetData(rowE,colPos,iTimeBin,signalOld[iPad]);
1141 // Store the track index in the dictionary
1142 // Note: We store index+1 in order to allow the array to be compressed
1143 // Note2: Taking out the +1 in track
1144 if (signalOld[iPad] > 0.0) {
1145 for (dict = 0; dict < kNdict; dict++) {
1146 Int_t oldTrack = dictionary[dict]->GetData(rowE,colPos,iTimeBin);
1147 if (oldTrack == track) break;
1148 if (oldTrack == -1 ) {
1149 dictionary[dict]->SetData(rowE,colPos,iTimeBin,track);
1157 } // Loop: time bins
1159 } // Loop: electrons of a single hit
1163 AliDebug(2,Form("Finished analyzing %d hits",nhit));
1169 //_____________________________________________________________________________
1170 Bool_t AliTRDdigitizer::ConvertSignals(Int_t det, AliTRDarraySignal *signals)
1173 // Convert signals to digits
1176 AliDebug(1,Form("Start converting the signals for detector %d",det));
1179 // Convert the signal array to s-digits
1180 if (!Signal2SDigits(det,signals)) {
1185 // Convert the signal array to digits
1186 if (!Signal2ADC(det,signals)) {
1189 // Run digital processing for digits
1190 RunDigitalProcessing(det);
1193 // Compress the arrays
1194 CompressOutputArrays(det);
1200 //_____________________________________________________________________________
1201 Bool_t AliTRDdigitizer::Signal2ADC(Int_t det, AliTRDarraySignal *signals)
1204 // Converts the sampled electron signals to ADC values for a given chamber
1207 AliDebug(1,Form("Start converting signals to ADC values for detector=%d",det));
1209 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1211 AliFatal("Could not get calibration object");
1215 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
1217 AliFatal("Could not get simulation parameters");
1221 // Converts number of electrons to fC
1222 const Double_t kEl2fC = 1.602e-19 * 1.0e15;
1225 Double_t coupling = simParam->GetPadCoupling()
1226 * simParam->GetTimeCoupling();
1227 // Electronics conversion factor
1228 Double_t convert = kEl2fC
1229 * simParam->GetChipGain();
1230 // ADC conversion factor
1231 Double_t adcConvert = simParam->GetADCoutRange()
1232 / simParam->GetADCinRange();
1233 // The electronics baseline in mV
1234 Double_t baseline = simParam->GetADCbaseline()
1236 // The electronics baseline in electrons
1237 Double_t baselineEl = baseline
1244 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1245 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1246 Int_t nTimeTotal = fDigitsManager->GetDigitsParam()->GetNTimeBins(det);
1247 if (fSDigitsManager->GetDigitsParam()->GetNTimeBins(det)) {
1248 nTimeTotal = fSDigitsManager->GetDigitsParam()->GetNTimeBins(det);
1251 AliFatal("Could not get number of time bins");
1255 // The gain factor calibration objects
1256 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
1257 AliTRDCalROC *calGainFactorROC = 0x0;
1258 Float_t calGainFactorDetValue = 0.0;
1260 AliTRDarrayADC *digits = 0x0;
1263 AliError(Form("Signals array for detector %d does not exist\n",det));
1266 if (signals->HasData()) {
1267 // Expand the container if neccessary
1271 // Create missing containers
1272 signals->Allocate(nRowMax,nColMax,nTimeTotal);
1275 // Get the container for the digits of this detector
1276 if (fDigitsManager->HasSDigits()) {
1277 AliError("Digits manager has s-digits");
1281 digits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det);
1282 // Allocate memory space for the digits buffer
1283 if (!digits->HasData()) {
1284 digits->Allocate(nRowMax,nColMax,nTimeTotal);
1287 // Get the calibration objects
1288 calGainFactorROC = calibration->GetGainFactorROC(det);
1289 calGainFactorDetValue = calGainFactorDet->GetValue(det);
1291 // Create the digits for this chamber
1292 for (row = 0; row < nRowMax; row++ ) {
1293 for (col = 0; col < nColMax; col++ ) {
1295 // halfchamber masking
1296 Int_t iMcm = (Int_t)(col/18); // current group of 18 col pads
1297 Int_t halfchamberside = (iMcm>3 ? 1 : 0); // 0=Aside, 1=Bside
1298 // Halfchambers that are switched off, masked by calibration
1299 if (calibration->IsHalfChamberNoData(det, halfchamberside))
1302 // Check whether pad is masked
1303 // Bridged pads are not considered yet!!!
1304 if (calibration->IsPadMasked(det,col,row) ||
1305 calibration->IsPadNotConnected(det,col,row)) {
1310 Float_t padgain = calGainFactorDetValue
1311 * calGainFactorROC->GetValue(col,row);
1313 AliError(Form("Not a valid gain %f, %d %d %d",padgain,det,col,row));
1316 for (time = 0; time < nTimeTotal; time++) {
1318 // Get the signal amplitude
1319 Float_t signalAmp = signals->GetData(row,col,time);
1320 // Pad and time coupling
1321 signalAmp *= coupling;
1323 signalAmp *= padgain;
1325 // Add the noise, starting from minus ADC baseline in electrons
1326 signalAmp = TMath::Max((Double_t) gRandom->Gaus(signalAmp,simParam->GetNoise())
1330 signalAmp *= convert;
1331 // Add ADC baseline in mV
1332 signalAmp += baseline;
1334 // Convert to ADC counts. Set the overflow-bit fADCoutRange if the
1335 // signal is larger than fADCinRange
1337 if (signalAmp >= simParam->GetADCinRange()) {
1338 adc = ((Short_t) simParam->GetADCoutRange());
1341 adc = TMath::Nint(signalAmp * adcConvert);
1344 // Saving all digits
1345 digits->SetData(row,col,time,adc);
1356 //_____________________________________________________________________________
1357 Bool_t AliTRDdigitizer::Signal2SDigits(Int_t det, AliTRDarraySignal *signals)
1360 // Converts the sampled electron signals to s-digits
1363 AliDebug(1,Form("Start converting signals to s-digits for detector=%d",det));
1365 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1367 AliFatal("Could not get calibration object");
1375 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1376 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1377 Int_t nTimeTotal = fDigitsManager->GetDigitsParam()->GetNTimeBins(det);
1379 // Get the container for the digits of this detector
1380 if (!fDigitsManager->HasSDigits()) {
1381 AliError("Digits manager has no s-digits");
1385 AliTRDarraySignal *digits = (AliTRDarraySignal *) fDigitsManager->GetSDigits(det);
1386 // Allocate memory space for the digits buffer
1387 if (!digits->HasData()) {
1388 digits->Allocate(nRowMax,nColMax,nTimeTotal);
1391 // Create the sdigits for this chamber
1392 for (row = 0; row < nRowMax; row++ ) {
1393 for (col = 0; col < nColMax; col++ ) {
1395 // halfchamber masking
1396 Int_t iMcm = (Int_t)(col/18); // current group of 18 col pads
1397 Int_t halfchamberside = (iMcm>3 ? 1 : 0); // 0=Aside, 1=Bside
1398 // Halfchambers that are switched off, masked by calibration
1399 if (calibration->IsHalfChamberNoData(det, halfchamberside))
1402 for (time = 0; time < nTimeTotal; time++) {
1403 digits->SetData(row,col,time,signals->GetData(row,col,time));
1412 //_____________________________________________________________________________
1413 Bool_t AliTRDdigitizer::Digits2SDigits(AliTRDdigitsManager * const manDig
1414 , AliTRDdigitsManager * const manSDig)
1417 // Converts digits into s-digits. Needed for embedding into real data.
1420 AliDebug(1,"Start converting digits to s-digits");
1423 fGeo = new AliTRDgeometry();
1426 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1428 AliFatal("Could not get calibration object");
1432 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
1434 AliFatal("Could not get simulation parameters");
1438 // Converts number of electrons to fC
1439 const Double_t kEl2fC = 1.602e-19 * 1.0e15;
1442 Double_t coupling = simParam->GetPadCoupling()
1443 * simParam->GetTimeCoupling();
1444 // Electronics conversion factor
1445 Double_t convert = kEl2fC
1446 * simParam->GetChipGain();
1447 // ADC conversion factor
1448 Double_t adcConvert = simParam->GetADCoutRange()
1449 / simParam->GetADCinRange();
1450 // The electronics baseline in mV
1451 Double_t baseline = simParam->GetADCbaseline()
1453 // The electronics baseline in electrons
1454 //Double_t baselineEl = baseline
1457 // The gainfactor calibration objects
1458 // Not used since these digits are supposed to be from real raw data
1459 //const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
1460 //AliTRDCalROC *calGainFactorROC = 0;
1461 //Float_t calGainFactorDetValue = 0.0;
1467 for (Int_t det = 0; det < AliTRDgeometry::Ndet(); det++) {
1469 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1470 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1471 Int_t nTimeTotal = manDig->GetDigitsParam()->GetNTimeBins(det);
1473 // Get the calibration objects
1474 //calGainFactorROC = calibration->GetGainFactorROC(det);
1475 //calGainFactorDetValue = calGainFactorDet->GetValue(det);
1478 AliTRDarrayADC *digits = (AliTRDarrayADC *) manDig->GetDigits(det);
1480 if (!manSDig->HasSDigits()) {
1481 AliError("SDigits manager has no s-digits");
1485 AliTRDarraySignal *sdigits = (AliTRDarraySignal *) manSDig->GetSDigits(det);
1486 AliTRDarrayDictionary *tracks0 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,0);
1487 AliTRDarrayDictionary *tracks1 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,1);
1488 AliTRDarrayDictionary *tracks2 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,2);
1489 // Allocate memory space for the digits buffer
1490 sdigits->Allocate(nRowMax,nColMax,nTimeTotal);
1491 tracks0->Allocate(nRowMax,nColMax,nTimeTotal);
1492 tracks1->Allocate(nRowMax,nColMax,nTimeTotal);
1493 tracks2->Allocate(nRowMax,nColMax,nTimeTotal);
1495 // Keep the digits param
1496 manSDig->GetDigitsParam()->SetNTimeBinsAll(manDig->GetDigitsParam()->GetNTimeBins(0));
1497 manSDig->GetDigitsParam()->SetADCbaselineAll(manDig->GetDigitsParam()->GetADCbaseline(0));
1499 if (digits->HasData()) {
1503 // Create the sdigits for this chamber
1504 for (row = 0; row < nRowMax; row++ ) {
1505 for (col = 0; col < nColMax; col++ ) {
1508 //Float_t padgain = calGainFactorDetValue
1509 // * calGainFactorROC->GetValue(col,row);
1511 for (time = 0; time < nTimeTotal; time++) {
1513 Short_t adcVal = digits->GetData(row,col,time);
1514 Double_t signal = (Double_t) adcVal;
1515 // ADC -> signal in mV
1516 signal /= adcConvert;
1517 // Subtract baseline in mV
1519 // Signal in mV -> signal in #electrons
1522 //signal /= padgain; // Not needed for real data
1523 // Pad and time coupling
1526 sdigits->SetData(row,col,time,signal);
1527 tracks0->SetData(row,col,time,0);
1528 tracks1->SetData(row,col,time,0);
1529 tracks2->SetData(row,col,time,0);
1538 sdigits->Compress(0);
1539 tracks0->Compress();
1540 tracks1->Compress();
1541 tracks2->Compress();
1543 // No compress just remove
1544 manDig->RemoveDigits(det);
1545 manDig->RemoveDictionaries(det);
1553 //_____________________________________________________________________________
1554 Bool_t AliTRDdigitizer::SDigits2Digits()
1557 // Merges the input s-digits and converts them to normal digits
1560 if (!MergeSDigits()) {
1564 return ConvertSDigits();
1568 //_____________________________________________________________________________
1569 Bool_t AliTRDdigitizer::MergeSDigits()
1572 // Merges the input s-digits:
1573 // - The amplitude of the different inputs are summed up.
1574 // - Of the track IDs from the input dictionaries only one is
1575 // kept for each input. This works for maximal 3 different merged inputs.
1578 // Number of track dictionary arrays
1579 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1581 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
1583 AliFatal("Could not get simulation parameters");
1587 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1589 AliFatal("Could not get calibration object");
1596 AliTRDarraySignal *digitsA;
1597 AliTRDarraySignal *digitsB;
1598 AliTRDarrayDictionary *dictionaryA[kNDict];
1599 AliTRDarrayDictionary *dictionaryB[kNDict];
1601 AliTRDdigitsManager *mergeSDigitsManager = 0x0;
1602 // Get the first s-digits
1603 fSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->First();
1604 if (!fSDigitsManager) {
1605 AliError("No SDigits manager");
1609 // Loop through the other sets of s-digits
1610 mergeSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->After(fSDigitsManager);
1612 if (mergeSDigitsManager) {
1613 AliDebug(1,Form("Merge %d input files.",fSDigitsManagerList->GetSize()));
1616 AliDebug(1,"Only one input file.");
1621 while (mergeSDigitsManager) {
1625 // Loop through the detectors
1626 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) {
1628 Int_t nTimeTotal = fSDigitsManager->GetDigitsParam()->GetNTimeBins(iDet);
1629 if (mergeSDigitsManager->GetDigitsParam()->GetNTimeBins(iDet) != nTimeTotal) {
1630 AliError(Form("Mismatch in the number of time bins [%d,%d] in detector %d"
1632 ,mergeSDigitsManager->GetDigitsParam()->GetNTimeBins(iDet)
1637 Int_t nRowMax = fGeo->GetPadPlane(iDet)->GetNrows();
1638 Int_t nColMax = fGeo->GetPadPlane(iDet)->GetNcols();
1640 // Loop through the pixels of one detector and add the signals
1641 digitsA = (AliTRDarraySignal *) fSDigitsManager->GetSDigits(iDet);
1642 digitsB = (AliTRDarraySignal *) mergeSDigitsManager->GetSDigits(iDet);
1644 if (!digitsA->HasData()) continue;
1646 if (!digitsB->HasData()) continue;
1648 for (iDict = 0; iDict < kNDict; iDict++) {
1649 dictionaryA[iDict] = (AliTRDarrayDictionary *) fSDigitsManager->GetDictionary(iDet,iDict);
1650 dictionaryB[iDict] = (AliTRDarrayDictionary *) mergeSDigitsManager->GetDictionary(iDet,iDict);
1651 dictionaryA[iDict]->Expand();
1652 dictionaryB[iDict]->Expand();
1655 // Merge only detectors that contain a signal
1656 Bool_t doMerge = kTRUE;
1657 if (fMergeSignalOnly) {
1658 if (digitsA->GetOverThreshold(0) == 0) {
1665 AliDebug(1,Form("Merge detector %d of input no.%d",iDet,iMerge+1));
1667 for (Int_t iRow = 0; iRow < nRowMax; iRow++ ) {
1668 for (Int_t iCol = 0; iCol < nColMax; iCol++ ) {
1669 for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
1671 // Add the amplitudes of the summable digits
1672 Float_t ampA = digitsA->GetData(iRow,iCol,iTime);
1673 Float_t ampB = digitsB->GetData(iRow,iCol,iTime);
1675 digitsA->SetData(iRow,iCol,iTime,ampA);
1677 // Add the mask to the track id if defined.
1678 for (iDict = 0; iDict < kNDict; iDict++) {
1679 Int_t trackB = dictionaryB[iDict]->GetData(iRow,iCol,iTime);
1680 if ((fMasks) && (trackB > 0)) {
1681 for (jDict = 0; jDict < kNDict; jDict++) {
1682 Int_t trackA = dictionaryA[iDict]->GetData(iRow,iCol,iTime);
1684 trackA = trackB + fMasks[iMerge];
1685 dictionaryA[iDict]->SetData(iRow,iCol,iTime,trackA);
1686 } // if: track A == 0
1688 } // if: fMasks and trackB > 0
1697 mergeSDigitsManager->RemoveDigits(iDet);
1698 mergeSDigitsManager->RemoveDictionaries(iDet);
1701 digitsA->Compress(0);
1702 for (iDict = 0; iDict < kNDict; iDict++) {
1703 dictionaryA[iDict]->Compress();
1709 // The next set of s-digits
1710 mergeSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->After(mergeSDigitsManager);
1712 } // while: mergeDigitsManagers
1718 //_____________________________________________________________________________
1719 Bool_t AliTRDdigitizer::ConvertSDigits()
1722 // Converts s-digits to normal digits
1725 AliTRDarraySignal *digitsIn = 0x0;
1727 if (!fSDigitsManager->HasSDigits()) {
1728 AliError("No s-digits in digits manager");
1732 // Loop through the detectors
1733 for (Int_t det = 0; det < AliTRDgeometry::Ndet(); det++) {
1735 // Get the merged s-digits (signals)
1736 digitsIn = (AliTRDarraySignal *) fSDigitsManager->GetSDigits(det);
1737 if (!digitsIn->HasData()) {
1738 AliDebug(2,Form("No digits for det=%d",det));
1742 // Convert the merged sdigits to digits
1743 if (!Signal2ADC(det,digitsIn)) {
1747 // Copy the dictionary information to the output array
1748 if (!CopyDictionary(det)) {
1753 fSDigitsManager->RemoveDigits(det);
1754 fSDigitsManager->RemoveDictionaries(det);
1756 // Run digital processing
1757 RunDigitalProcessing(det);
1759 // Compress the arrays
1760 CompressOutputArrays(det);
1762 } // for: detector numbers
1764 if (AliDataLoader *trklLoader = AliRunLoader::Instance()->GetLoader("TRDLoader")->GetDataLoader("tracklets")) {
1765 if (trklLoader->Tree())
1766 trklLoader->WriteData("OVERWRITE");
1769 // Save the values for the raw data headers
1770 if (AliTRDSimParam::Instance()->GetNTBoverwriteOCDB()) {
1771 fDigitsManager->GetDigitsParam()->SetNTimeBinsAll(AliTRDSimParam::Instance()->GetNTimeBins());
1774 fDigitsManager->GetDigitsParam()->SetNTimeBinsAll(AliTRDcalibDB::Instance()->GetNumberOfTimeBinsDCS());
1776 fDigitsManager->GetDigitsParam()->SetADCbaselineAll(AliTRDSimParam::Instance()->GetADCbaseline());
1782 //_____________________________________________________________________________
1783 Bool_t AliTRDdigitizer::CopyDictionary(Int_t det)
1786 // Copies the dictionary information from the s-digits arrays
1787 // to the output arrays
1790 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1792 AliFatal("Could not get calibration object");
1796 AliDebug(1,Form("Start copying dictionaries for detector=%d",det));
1798 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1799 AliTRDarrayDictionary *dictionaryIn[kNDict];
1800 AliTRDarrayDictionary *dictionaryOut[kNDict];
1802 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1803 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1804 Int_t nTimeTotal = fSDigitsManager->GetDigitsParam()->GetNTimeBins(det);
1811 for (dict = 0; dict < kNDict; dict++) {
1813 dictionaryIn[dict] = (AliTRDarrayDictionary *) fSDigitsManager->GetDictionary(det,dict);
1814 dictionaryIn[dict]->Expand();
1815 dictionaryOut[dict] = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
1816 dictionaryOut[dict]->Allocate(nRowMax,nColMax,nTimeTotal);
1818 for (row = 0; row < nRowMax; row++) {
1819 for (col = 0; col < nColMax; col++) {
1820 for (time = 0; time < nTimeTotal; time++) {
1821 Int_t track = dictionaryIn[dict]->GetData(row,col,time);
1822 dictionaryOut[dict]->SetData(row,col,time,track);
1827 } // for: dictionaries
1833 //_____________________________________________________________________________
1834 void AliTRDdigitizer::CompressOutputArrays(Int_t det)
1837 // Compress the output arrays
1840 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1841 AliTRDarrayDictionary *dictionary = 0x0;
1846 AliTRDarrayADC *digits = 0x0;
1847 digits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det);
1852 AliTRDarraySignal *digits = 0x0;
1853 digits = (AliTRDarraySignal *) fDigitsManager->GetSDigits(det);
1854 digits->Compress(0);
1857 for (Int_t dict = 0; dict < kNDict; dict++) {
1858 dictionary = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
1859 dictionary->Compress();
1866 //_____________________________________________________________________________
1867 Bool_t AliTRDdigitizer::WriteDigits() const
1870 // Writes out the TRD-digits and the dictionaries
1874 fRunLoader->CdGAFile();
1876 // Store the digits and the dictionary in the tree
1877 return fDigitsManager->WriteDigits();
1881 //_____________________________________________________________________________
1882 void AliTRDdigitizer::InitOutput(Int_t iEvent)
1885 // Initializes the output branches
1891 AliError("Run Loader is NULL");
1895 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
1897 AliError("Can not get TRD loader from Run Loader");
1904 // If we produce SDigits
1905 tree = loader->TreeS();
1907 loader->MakeTree("S");
1908 tree = loader->TreeS();
1912 // If we produce Digits
1913 tree = loader->TreeD();
1915 loader->MakeTree("D");
1916 tree = loader->TreeD();
1919 fDigitsManager->SetEvent(iEvent);
1920 fDigitsManager->MakeBranch(tree);
1924 //_____________________________________________________________________________
1925 Int_t AliTRDdigitizer::Diffusion(Float_t vdrift, Double_t absdriftlength
1927 , Double_t &lRow, Double_t &lCol, Double_t &lTime)
1930 // Applies the diffusion smearing to the position of a single electron.
1931 // Depends on absolute drift length.
1934 Float_t diffL = 0.0;
1935 Float_t diffT = 0.0;
1937 if (AliTRDCommonParam::Instance()->GetDiffCoeff(diffL,diffT,vdrift)) {
1939 Float_t driftSqrt = TMath::Sqrt(absdriftlength);
1940 Float_t sigmaT = driftSqrt * diffT;
1941 Float_t sigmaL = driftSqrt * diffL;
1942 lRow = gRandom->Gaus(lRow ,sigmaT);
1943 if (AliTRDCommonParam::Instance()->ExBOn()) {
1944 lCol = gRandom->Gaus(lCol ,sigmaT * 1.0 / (1.0 + exbvalue*exbvalue));
1945 lTime = gRandom->Gaus(lTime,sigmaL * 1.0 / (1.0 + exbvalue*exbvalue));
1948 lCol = gRandom->Gaus(lCol ,sigmaT);
1949 lTime = gRandom->Gaus(lTime,sigmaL);
1963 //_____________________________________________________________________________
1964 void AliTRDdigitizer::RunDigitalProcessing(Int_t det)
1967 // Run the digital processing in the TRAP
1970 AliTRDfeeParam *feeParam = AliTRDfeeParam::Instance();
1972 AliTRDarrayADC *digits = fDigitsManager->GetDigits(det);
1976 //Call the methods in the mcm class using the temporary array as input
1977 // process the data in the same order as in hardware
1978 for (Int_t side = 0; side <= 1; side++) {
1979 for(Int_t rob = side; rob < digits->GetNrow() / 2; rob += 2) {
1980 for(Int_t mcm = 0; mcm < 16; mcm++) {
1981 fMcmSim->Init(det, rob, mcm);
1982 fMcmSim->SetDataByPad(digits, fDigitsManager);
1984 if (feeParam->GetTracklet()) {
1985 fMcmSim->Tracklet();
1986 fMcmSim->StoreTracklets();
1988 fMcmSim->ZSMapping();
1989 fMcmSim->WriteData(digits);