1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ////////////////////////////////////////////////////////////////////////////
20 // Creates and handles digits from TRD hits //
22 // Authors: C. Blume (blume@ikf.uni-frankfurt.de) //
26 // The following effects are included: //
29 // - Gas gain including fluctuations //
30 // - Pad-response (simple Gaussian approximation) //
32 // - Electronics noise //
33 // - Electronics gain //
35 // - Zero suppression //
37 ////////////////////////////////////////////////////////////////////////////
39 #include <TGeoManager.h>
47 #include "AliRunLoader.h"
48 #include "AliLoader.h"
49 #include "AliConfig.h"
50 #include "AliRunDigitizer.h"
51 #include "AliRunLoader.h"
52 #include "AliLoader.h"
56 #include "AliTRDhit.h"
57 #include "AliTRDdigitizer.h"
58 #include "AliTRDarrayDictionary.h"
59 #include "AliTRDarrayADC.h"
60 #include "AliTRDarraySignal.h"
61 #include "AliTRDdigitsManager.h"
62 #include "AliTRDgeometry.h"
63 #include "AliTRDpadPlane.h"
64 #include "AliTRDcalibDB.h"
65 #include "AliTRDSimParam.h"
66 #include "AliTRDCommonParam.h"
67 #include "AliTRDfeeParam.h"
68 #include "AliTRDmcmSim.h"
69 #include "AliTRDdigitsParam.h"
71 #include "Cal/AliTRDCalROC.h"
72 #include "Cal/AliTRDCalDet.h"
74 ClassImp(AliTRDdigitizer)
76 //_____________________________________________________________________________
77 AliTRDdigitizer::AliTRDdigitizer()
82 ,fSDigitsManagerList(0)
85 ,fMcmSim(new AliTRDmcmSim)
90 ,fMergeSignalOnly(kFALSE)
93 // AliTRDdigitizer default constructor
98 //_____________________________________________________________________________
99 AliTRDdigitizer::AliTRDdigitizer(const Text_t *name, const Text_t *title)
100 :AliDigitizer(name,title)
104 ,fSDigitsManagerList(0)
107 ,fMcmSim(new AliTRDmcmSim)
112 ,fMergeSignalOnly(kFALSE)
115 // AliTRDdigitizer constructor
120 //_____________________________________________________________________________
121 AliTRDdigitizer::AliTRDdigitizer(AliRunDigitizer *manager
122 , const Text_t *name, const Text_t *title)
123 :AliDigitizer(manager,name,title)
127 ,fSDigitsManagerList(0)
130 ,fMcmSim(new AliTRDmcmSim)
135 ,fMergeSignalOnly(kFALSE)
138 // AliTRDdigitizer constructor
143 //_____________________________________________________________________________
144 AliTRDdigitizer::AliTRDdigitizer(AliRunDigitizer *manager)
145 :AliDigitizer(manager,"AliTRDdigitizer","TRD digitizer")
149 ,fSDigitsManagerList(0)
152 ,fMcmSim(new AliTRDmcmSim)
157 ,fMergeSignalOnly(kFALSE)
160 // AliTRDdigitizer constructor
165 //_____________________________________________________________________________
166 AliTRDdigitizer::AliTRDdigitizer(const AliTRDdigitizer &d)
171 ,fSDigitsManagerList(0)
174 ,fMcmSim(new AliTRDmcmSim)
177 ,fCompress(d.fCompress)
178 ,fSDigits(d.fSDigits)
179 ,fMergeSignalOnly(d.fMergeSignalOnly)
182 // AliTRDdigitizer copy constructor
187 //_____________________________________________________________________________
188 AliTRDdigitizer::~AliTRDdigitizer()
191 // AliTRDdigitizer destructor
194 if (fDigitsManager) {
195 delete fDigitsManager;
199 if (fSDigitsManager) {
200 // s-digitsmanager will be deleted via list
204 if (fSDigitsManagerList) {
205 fSDigitsManagerList->Delete();
206 delete fSDigitsManagerList;
207 fSDigitsManagerList = 0;
227 //_____________________________________________________________________________
228 AliTRDdigitizer &AliTRDdigitizer::operator=(const AliTRDdigitizer &d)
231 // Assignment operator
235 ((AliTRDdigitizer &) d).Copy(*this);
242 //_____________________________________________________________________________
243 void AliTRDdigitizer::Copy(TObject &d) const
249 ((AliTRDdigitizer &) d).fRunLoader = 0;
250 ((AliTRDdigitizer &) d).fDigitsManager = 0;
251 ((AliTRDdigitizer &) d).fSDigitsManager = 0;
252 ((AliTRDdigitizer &) d).fSDigitsManagerList = 0;
253 ((AliTRDdigitizer &) d).fTRD = 0;
254 ((AliTRDdigitizer &) d).fGeo = 0;
255 ((AliTRDdigitizer &) d).fEvent = 0;
256 ((AliTRDdigitizer &) d).fMasks = 0;
257 ((AliTRDdigitizer &) d).fCompress = fCompress;
258 ((AliTRDdigitizer &) d).fSDigits = fSDigits;
259 ((AliTRDdigitizer &) d).fMergeSignalOnly = fMergeSignalOnly;
263 //_____________________________________________________________________________
264 void AliTRDdigitizer::Exec(const Option_t * const option)
267 // Executes the merging
272 AliTRDdigitsManager *sdigitsManager;
274 TString optionString = option;
275 if (optionString.Contains("deb")) {
276 AliLog::SetClassDebugLevel("AliTRDdigitizer",1);
277 AliInfo("Called with debug option");
280 // The AliRoot file is already connected by the manager
281 AliRunLoader *inrl = 0x0;
284 AliDebug(1,"AliRun object found on file.");
287 inrl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
289 gAlice = inrl->GetAliRun();
291 AliError("Could not find AliRun object.")
296 Int_t nInput = fManager->GetNinputs();
297 fMasks = new Int_t[nInput];
298 for (iInput = 0; iInput < nInput; iInput++) {
299 fMasks[iInput] = fManager->GetMask(iInput);
306 AliRunLoader *orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
308 if (InitDetector()) {
310 AliLoader *ogime = orl->GetLoader("TRDLoader");
314 // If we produce SDigits
315 tree = ogime->TreeS();
317 ogime->MakeTree("S");
318 tree = ogime->TreeS();
322 // If we produce Digits
323 tree = ogime->TreeD();
325 ogime->MakeTree("D");
326 tree = ogime->TreeD();
334 for (iInput = 0; iInput < nInput; iInput++) {
336 AliDebug(1,Form("Add input stream %d",iInput));
338 // Check if the input tree exists
339 inrl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(iInput));
340 AliLoader *gime = inrl->GetLoader("TRDLoader");
342 TTree *treees = gime->TreeS();
344 if (gime->LoadSDigits()) {
345 AliError(Form("Error Occured while loading S. Digits for input %d.",iInput));
348 treees = gime->TreeS();
352 AliError(Form("Input stream %d does not exist",iInput));
356 // Read the s-digits via digits manager
357 sdigitsManager = new AliTRDdigitsManager();
358 sdigitsManager->SetSDigits(kTRUE);
360 AliRunLoader *rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(iInput));
361 AliLoader *gimme = rl->GetLoader("TRDLoader");
364 gimme->LoadSDigits();
367 sdigitsManager->ReadDigits(gimme->TreeS());
369 // Add the s-digits to the input list
370 AddSDigitsManager(sdigitsManager);
374 // Convert the s-digits to normal digits
375 AliDebug(1,"Do the conversion");
379 AliDebug(1,"Write the digits");
380 fDigitsManager->WriteDigits();
386 DeleteSDigitsManager();
392 //_____________________________________________________________________________
393 Bool_t AliTRDdigitizer::Open(const Char_t *file, Int_t nEvent)
396 // Opens a ROOT-file with TRD-hits and reads in the hit-tree
398 // Connect the AliRoot file containing Geometry, Kine, and Hits
401 TString evfoldname = AliConfig::GetDefaultEventFolderName();
403 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
405 fRunLoader = AliRunLoader::Open(file,evfoldname,"UPDATE");
408 AliError(Form("Can not open session for file %s.",file));
412 if (!fRunLoader->GetAliRun()) {
413 fRunLoader->LoadgAlice();
415 gAlice = fRunLoader->GetAliRun();
418 AliDebug(1,"AliRun object found on file.");
421 AliError("Could not find AliRun object.");
427 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
429 AliError("Can not get TRD loader from Run Loader");
433 if (InitDetector()) {
436 // If we produce SDigits
437 tree = loader->TreeS();
439 loader->MakeTree("S");
440 tree = loader->TreeS();
444 // If we produce Digits
445 tree = loader->TreeD();
447 loader->MakeTree("D");
448 tree = loader->TreeD();
451 return MakeBranch(tree);
459 //_____________________________________________________________________________
460 Bool_t AliTRDdigitizer::Open(AliRunLoader * const runLoader, Int_t nEvent)
463 // Opens a ROOT-file with TRD-hits and reads in the hit-tree
465 // Connect the AliRoot file containing Geometry, Kine, and Hits
468 fRunLoader = runLoader;
470 AliError("RunLoader does not exist");
474 if (!fRunLoader->GetAliRun()) {
475 fRunLoader->LoadgAlice();
477 gAlice = fRunLoader->GetAliRun();
480 AliDebug(1,"AliRun object found on file.");
483 AliError("Could not find AliRun object.");
489 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
491 AliError("Can not get TRD loader from Run Loader");
495 if (InitDetector()) {
498 // If we produce SDigits
499 tree = loader->TreeS();
501 loader->MakeTree("S");
502 tree = loader->TreeS();
506 // If we produce Digits
507 tree = loader->TreeD();
509 loader->MakeTree("D");
510 tree = loader->TreeD();
513 return MakeBranch(tree);
521 //_____________________________________________________________________________
522 Bool_t AliTRDdigitizer::InitDetector()
525 // Sets the pointer to the TRD detector and the geometry
528 // Get the pointer to the detector class and check for version 1
529 fTRD = (AliTRD *) gAlice->GetDetector("TRD");
531 AliFatal("No TRD module found");
534 if (fTRD->IsVersion() != 1) {
535 AliFatal("TRD must be version 1 (slow simulator)");
540 fGeo = new AliTRDgeometry();
542 // Create a digits manager
543 if (fDigitsManager) {
544 delete fDigitsManager;
546 fDigitsManager = new AliTRDdigitsManager();
547 fDigitsManager->SetSDigits(fSDigits);
548 fDigitsManager->CreateArrays();
549 fDigitsManager->SetEvent(fEvent);
551 // The list for the input s-digits manager to be merged
552 if (fSDigitsManagerList) {
553 fSDigitsManagerList->Delete();
556 fSDigitsManagerList = new TList();
562 //_____________________________________________________________________________
563 Bool_t AliTRDdigitizer::MakeBranch(TTree *tree) const
566 // Create the branches for the digits array
569 return fDigitsManager->MakeBranch(tree);
573 //_____________________________________________________________________________
574 void AliTRDdigitizer::AddSDigitsManager(AliTRDdigitsManager *man)
577 // Add a digits manager for s-digits to the input list.
580 fSDigitsManagerList->Add(man);
584 //_____________________________________________________________________________
585 void AliTRDdigitizer::DeleteSDigitsManager()
588 // Removes digits manager from the input list.
591 fSDigitsManagerList->Delete();
595 //_____________________________________________________________________________
596 Bool_t AliTRDdigitizer::MakeDigits()
602 AliDebug(1,"Start creating digits");
605 AliError("No geometry defined");
609 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
611 AliFatal("Could not get calibration object");
615 const Int_t kNdet = AliTRDgeometry::Ndet();
617 Float_t **hits = new Float_t*[kNdet];
618 Int_t *nhit = new Int_t[kNdet];
620 AliTRDarraySignal *signals = 0x0;
623 if (calibration->GetNumberOfTimeBinsDCS() != AliTRDSimParam::Instance()->GetNTimeBins()) {
624 AliWarning(Form("Number of time bins is different to OCDB value [SIM=%d, OCDB=%d]"
625 ,AliTRDSimParam::Instance()->GetNTimeBins()
626 ,calibration->GetNumberOfTimeBinsDCS()));
629 // Sort all hits according to detector number
630 if (!SortHits(hits,nhit)) {
631 AliError("Sorting hits failed");
637 // Loop through all detectors
638 for (Int_t det = 0; det < kNdet; det++) {
640 // Detectors that are switched off, not installed, etc.
641 if (( calibration->IsChamberInstalled(det)) &&
642 (!calibration->IsChamberMasked(det)) &&
643 ( fGeo->ChamberInGeometry(det)) &&
646 signals = new AliTRDarraySignal();
648 // Convert the hits of the current detector to detector signals
649 if (!ConvertHits(det,hits[det],nhit[det],signals)) {
650 AliError(Form("Conversion of hits failed for detector=%d",det));
657 // Convert the detector signals to digits or s-digits
658 if (!ConvertSignals(det,signals)) {
659 AliError(Form("Conversion of signals failed for detector=%d",det));
667 // Delete the signals array
671 } // if: detector status
678 if (AliDataLoader *trklLoader = AliRunLoader::Instance()->GetLoader("TRDLoader")->GetDataLoader("tracklets")) {
679 if (trklLoader->Tree())
680 trklLoader->WriteData("OVERWRITE");
687 // Save the values for the raw data headers
688 fDigitsManager->GetDigitsParam()->SetNTimeBinsAll(AliTRDSimParam::Instance()->GetNTimeBins());
689 fDigitsManager->GetDigitsParam()->SetADCbaselineAll(AliTRDSimParam::Instance()->GetADCbaseline());
695 //_____________________________________________________________________________
696 Bool_t AliTRDdigitizer::SortHits(Float_t **hits, Int_t *nhit)
699 // Read all the hits and sorts them according to detector number
700 // in the output array <hits>.
703 AliDebug(1,"Start sorting hits");
705 const Int_t kNdet = AliTRDgeometry::Ndet();
706 // Size of the hit vector
707 const Int_t kNhit = 6;
712 Int_t *lhit = new Int_t[kNdet];
714 for (Int_t det = 0; det < kNdet; det++) {
720 AliLoader *gimme = fRunLoader->GetLoader("TRDLoader");
721 if (!gimme->TreeH()) {
724 TTree *hitTree = gimme->TreeH();
725 if (hitTree == 0x0) {
726 AliError("Can not get TreeH");
730 fTRD->SetTreeAddress();
732 // Get the number of entries in the hit tree
733 // (Number of primary particles creating a hit somewhere)
734 Int_t nTrk = (Int_t) hitTree->GetEntries();
735 AliDebug(1,Form("Found %d tracks",nTrk));
737 // Loop through all the tracks in the tree
738 for (Int_t iTrk = 0; iTrk < nTrk; iTrk++) {
740 gAlice->GetMCApp()->ResetHits();
741 hitTree->GetEvent(iTrk);
744 AliError(Form("No hits array for track = %d",iTrk));
748 // Number of hits for this track
749 nhitTrk = fTRD->Hits()->GetEntriesFast();
752 // Loop through the TRD hits
753 AliTRDhit *hit = (AliTRDhit *) fTRD->FirstHit(-1);
758 // Don't analyze test hits
759 if (((Int_t) hit->GetCharge()) != 0) {
761 Int_t trk = hit->Track();
762 Int_t det = hit->GetDetector();
763 Int_t q = hit->GetCharge();
764 Float_t x = hit->X();
765 Float_t y = hit->Y();
766 Float_t z = hit->Z();
767 Float_t time = hit->GetTime();
769 if (nhit[det] == lhit[det]) {
770 // Inititialization of new detector
771 xyz = new Float_t[kNhit*(nhitTrk+lhit[det])];
773 memcpy(xyz,hits[det],sizeof(Float_t)*kNhit*lhit[det]);
776 lhit[det] += nhitTrk;
782 xyz[nhit[det]*kNhit+0] = x;
783 xyz[nhit[det]*kNhit+1] = y;
784 xyz[nhit[det]*kNhit+2] = z;
785 xyz[nhit[det]*kNhit+3] = q;
786 xyz[nhit[det]*kNhit+4] = trk;
787 xyz[nhit[det]*kNhit+5] = time;
792 hit = (AliTRDhit *) fTRD->NextHit();
794 } // for: hits of one track
804 //_____________________________________________________________________________
805 Bool_t AliTRDdigitizer::ConvertHits(Int_t det
806 , const Float_t * const hits
808 , AliTRDarraySignal *signals)
811 // Converts the detectorwise sorted hits to detector signals
814 AliDebug(1,Form("Start converting hits for detector=%d (nhits=%d)",det,nhit));
816 // Number of pads included in the pad response
817 const Int_t kNpad = 3;
818 // Number of track dictionary arrays
819 const Int_t kNdict = AliTRDdigitsManager::kNDict;
820 // Size of the hit vector
821 const Int_t kNhit = 6;
823 // Width of the amplification region
824 const Float_t kAmWidth = AliTRDgeometry::AmThick();
825 // Width of the drift region
826 const Float_t kDrWidth = AliTRDgeometry::DrThick();
827 // Drift + amplification region
828 const Float_t kDrMin = - 0.5 * kAmWidth;
829 const Float_t kDrMax = kDrWidth + 0.5 * kAmWidth;
833 Int_t timeBinTRFend = 1;
837 Double_t padSignal[kNpad];
838 Double_t signalOld[kNpad];
840 AliTRDarrayDictionary *dictionary[kNdict];
842 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
843 AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance();
844 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
847 AliFatal("Could not get common parameterss");
851 AliFatal("Could not get simulation parameters");
855 AliFatal("Could not get calibration object");
859 // Get the detector wise calibration objects
860 AliTRDCalROC *calVdriftROC = 0;
861 Float_t calVdriftDetValue = 0.0;
862 const AliTRDCalDet *calVdriftDet = calibration->GetVdriftDet();
863 AliTRDCalROC *calT0ROC = 0;
864 Float_t calT0DetValue = 0.0;
865 const AliTRDCalDet *calT0Det = calibration->GetT0Det();
867 if (simParam->TRFOn()) {
868 timeBinTRFend = ((Int_t) (simParam->GetTRFhi()
869 * commonParam->GetSamplingFrequency())) - 1;
872 Int_t nTimeTotal = simParam->GetNTimeBins();
873 Float_t samplingRate = commonParam->GetSamplingFrequency();
874 Float_t elAttachProp = simParam->GetElAttachProp() / 100.0;
876 AliTRDpadPlane *padPlane = fGeo->GetPadPlane(det);
877 Int_t layer = fGeo->GetLayer(det); //update
878 Float_t row0 = padPlane->GetRow0ROC();
879 Int_t nRowMax = padPlane->GetNrows();
880 Int_t nColMax = padPlane->GetNcols();
882 // Create a new array for the signals
883 signals->Allocate(nRowMax,nColMax,nTimeTotal);
885 // Create a new array for the dictionary
886 for (dict = 0; dict < kNdict; dict++) {
887 dictionary[dict] = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
888 dictionary[dict]->Allocate(nRowMax,nColMax,nTimeTotal);
891 // Loop through the hits in this detector
892 for (Int_t hit = 0; hit < nhit; hit++) {
894 pos[0] = hits[hit*kNhit+0];
895 pos[1] = hits[hit*kNhit+1];
896 pos[2] = hits[hit*kNhit+2];
897 Float_t q = hits[hit*kNhit+3];
898 Float_t hittime = hits[hit*kNhit+5];
899 Int_t track = ((Int_t) hits[hit*kNhit+4]);
903 // Find the current volume with the geo manager
904 gGeoManager->SetCurrentPoint(pos);
905 gGeoManager->FindNode();
906 if (strstr(gGeoManager->GetPath(),"/UK")) {
910 // Get the calibration objects
911 calVdriftROC = calibration->GetVdriftROC(det);
912 calVdriftDetValue = calVdriftDet->GetValue(det);
913 calT0ROC = calibration->GetT0ROC(det);
914 calT0DetValue = calT0Det->GetValue(det);
916 // Go to the local coordinate system:
917 // loc[0] - col direction in amplification or driftvolume
918 // loc[1] - row direction in amplification or driftvolume
919 // loc[2] - time direction in amplification or driftvolume
920 gGeoManager->MasterToLocal(pos,loc);
922 // Relative to middle of amplification region
923 loc[2] = loc[2] - kDrWidth/2.0 - kAmWidth/2.0;
926 // The driftlength [cm] (w/o diffusion yet !).
927 // It is negative if the hit is between pad plane and anode wires.
928 Double_t driftlength = -1.0 * loc[2];
930 // Stupid patch to take care of TR photons that are absorbed
931 // outside the chamber volume. A real fix would actually need
932 // a more clever implementation of the TR hit generation
934 if ((loc[1] < padPlane->GetRowEndROC()) ||
935 (loc[1] > padPlane->GetRow0ROC())) {
938 if ((driftlength < kDrMin) ||
939 (driftlength > kDrMax)) {
944 // Get row and col of unsmeared electron to retrieve drift velocity
945 // The pad row (z-direction)
946 Int_t rowE = padPlane->GetPadRowNumberROC(loc[1]);
950 Double_t rowOffset = padPlane->GetPadRowOffsetROC(rowE,loc[1]);
951 // The pad column (rphi-direction)
952 Double_t offsetTilt = padPlane->GetTiltOffset(rowOffset);
953 Int_t colE = padPlane->GetPadColNumber(loc[0]+offsetTilt);
957 Double_t colOffset = 0.0;
959 // Normalized drift length
960 Float_t driftvelocity = calVdriftDetValue * calVdriftROC->GetValue(colE,rowE);
961 Double_t absdriftlength = TMath::Abs(driftlength);
962 if (commonParam->ExBOn()) {
963 absdriftlength /= TMath::Sqrt(GetLorentzFactor(driftvelocity));
966 // Loop over all electrons of this hit
967 // TR photons produce hits with negative charge
968 Int_t nEl = ((Int_t) TMath::Abs(q));
969 for (Int_t iEl = 0; iEl < nEl; iEl++) {
971 // Now the real local coordinate system of the ROC
972 // column direction: locC
973 // row direction: locR
974 // time direction: locT
975 // locR and locC are identical to the coordinates of the corresponding
976 // volumina of the drift or amplification region.
977 // locT is defined relative to the wire plane (i.e. middle of amplification
978 // region), meaning locT = 0, and is negative for hits coming from the
980 Double_t locC = loc[0];
981 Double_t locR = loc[1];
982 Double_t locT = loc[2];
984 // Electron attachment
985 if (simParam->ElAttachOn()) {
986 if (gRandom->Rndm() < (absdriftlength * elAttachProp)) {
991 // Apply the diffusion smearing
992 if (simParam->DiffusionOn()) {
993 if (!(Diffusion(driftvelocity,absdriftlength,locR,locC,locT))) {
998 // Apply E x B effects (depends on drift direction)
999 if (commonParam->ExBOn()) {
1000 if (!(ExB(driftvelocity,driftlength,locC))) {
1005 // The electron position after diffusion and ExB in pad coordinates.
1006 // The pad row (z-direction)
1007 rowE = padPlane->GetPadRowNumberROC(locR);
1008 if (rowE < 0) continue;
1009 rowOffset = padPlane->GetPadRowOffsetROC(rowE,locR);
1011 // The pad column (rphi-direction)
1012 offsetTilt = padPlane->GetTiltOffset(rowOffset);
1013 colE = padPlane->GetPadColNumber(locC+offsetTilt);
1014 if (colE < 0) continue;
1015 colOffset = padPlane->GetPadColOffset(colE,locC+offsetTilt);
1017 // Also re-retrieve drift velocity because col and row may have changed
1018 driftvelocity = calVdriftDetValue * calVdriftROC->GetValue(colE,rowE);
1019 Float_t t0 = calT0DetValue + calT0ROC->GetValue(colE,rowE);
1021 // Convert the position to drift time [mus], using either constant drift velocity or
1022 // time structure of drift cells (non-isochronity, GARFIELD calculation).
1023 // Also add absolute time of hits to take pile-up events into account properly
1025 if (simParam->TimeStructOn()) {
1026 // Get z-position with respect to anode wire
1027 Double_t zz = row0 - locR + padPlane->GetAnodeWireOffset();
1028 zz -= ((Int_t)(2 * zz)) / 2.0;
1032 // Use drift time map (GARFIELD)
1033 drifttime = commonParam->TimeStruct(driftvelocity,0.5*kAmWidth-1.0*locT,zz)
1037 // Use constant drift velocity
1038 drifttime = TMath::Abs(locT) / driftvelocity
1042 // Apply the gas gain including fluctuations
1043 Double_t ggRndm = 0.0;
1045 ggRndm = gRandom->Rndm();
1046 } while (ggRndm <= 0);
1047 Double_t signal = -(simParam->GetGasGain()) * TMath::Log(ggRndm);
1049 // Apply the pad response
1050 if (simParam->PRFOn()) {
1051 // The distance of the electron to the center of the pad
1052 // in units of pad width
1053 Double_t dist = (colOffset - 0.5*padPlane->GetColSize(colE))
1054 / padPlane->GetColSize(colE);
1055 // This is a fixed parametrization, i.e. not dependent on
1056 // calibration values !
1057 if (!(calibration->PadResponse(signal,dist,layer,padSignal))) continue;
1061 padSignal[1] = signal;
1065 // The time bin (always positive), with t0 distortion
1066 Double_t timeBinIdeal = drifttime * samplingRate + t0;
1068 if (TMath::Abs(timeBinIdeal) > 2*nTimeTotal) {
1069 timeBinIdeal = 2 * nTimeTotal;
1071 Int_t timeBinTruncated = ((Int_t) timeBinIdeal);
1072 // The distance of the position to the middle of the timebin
1073 Double_t timeOffset = ((Float_t) timeBinTruncated
1074 + 0.5 - timeBinIdeal) / samplingRate;
1076 // Sample the time response inside the drift region
1077 // + additional time bins before and after.
1078 // The sampling is done always in the middle of the time bin
1079 for (Int_t iTimeBin = TMath::Max(timeBinTruncated,0)
1080 ;iTimeBin < TMath::Min(timeBinTruncated+timeBinTRFend,nTimeTotal)
1083 // Apply the time response
1084 Double_t timeResponse = 1.0;
1085 Double_t crossTalk = 0.0;
1086 Double_t time = (iTimeBin - timeBinTruncated) / samplingRate + timeOffset;
1088 if (simParam->TRFOn()) {
1089 timeResponse = simParam->TimeResponse(time);
1091 if (simParam->CTOn()) {
1092 crossTalk = simParam->CrossTalk(time);
1099 for (iPad = 0; iPad < kNpad; iPad++) {
1101 Int_t colPos = colE + iPad - 1;
1102 if (colPos < 0) continue;
1103 if (colPos >= nColMax) break;
1106 signalOld[iPad] = signals->GetData(rowE,colPos,iTimeBin);
1108 if (colPos != colE) {
1109 // Cross talk added to non-central pads
1110 signalOld[iPad] += padSignal[iPad]
1111 * (timeResponse + crossTalk);
1114 // W/o cross talk at central pad
1115 signalOld[iPad] += padSignal[iPad]
1119 signals->SetData(rowE,colPos,iTimeBin,signalOld[iPad]);
1121 // Store the track index in the dictionary
1122 // Note: We store index+1 in order to allow the array to be compressed
1123 // Note2: Taking out the +1 in track
1124 if (signalOld[iPad] > 0.0) {
1125 for (dict = 0; dict < kNdict; dict++) {
1126 Int_t oldTrack = dictionary[dict]->GetData(rowE,colPos,iTimeBin);
1127 if (oldTrack == track) break;
1128 if (oldTrack == -1 ) {
1129 dictionary[dict]->SetData(rowE,colPos,iTimeBin,track);
1137 } // Loop: time bins
1139 } // Loop: electrons of a single hit
1143 AliDebug(2,Form("Finished analyzing %d hits",nhit));
1149 //_____________________________________________________________________________
1150 Bool_t AliTRDdigitizer::ConvertSignals(Int_t det, AliTRDarraySignal *signals)
1153 // Convert signals to digits
1156 AliDebug(1,Form("Start converting the signals for detector %d",det));
1159 // Convert the signal array to s-digits
1160 if (!Signal2SDigits(det,signals)) {
1165 // Convert the signal array to digits
1166 if (!Signal2ADC(det,signals)) {
1169 // Run digital processing for digits
1170 RunDigitalProcessing(det);
1173 // Compress the arrays
1174 CompressOutputArrays(det);
1180 //_____________________________________________________________________________
1181 Bool_t AliTRDdigitizer::Signal2ADC(Int_t det, AliTRDarraySignal *signals)
1184 // Converts the sampled electron signals to ADC values for a given chamber
1187 AliDebug(1,Form("Start converting signals to ADC values for detector=%d",det));
1189 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1191 AliFatal("Could not get calibration object");
1195 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
1197 AliFatal("Could not get simulation parameters");
1201 // Converts number of electrons to fC
1202 const Double_t kEl2fC = 1.602e-19 * 1.0e15;
1205 Double_t coupling = simParam->GetPadCoupling()
1206 * simParam->GetTimeCoupling();
1207 // Electronics conversion factor
1208 Double_t convert = kEl2fC
1209 * simParam->GetChipGain();
1210 // ADC conversion factor
1211 Double_t adcConvert = simParam->GetADCoutRange()
1212 / simParam->GetADCinRange();
1213 // The electronics baseline in mV
1214 Double_t baseline = simParam->GetADCbaseline()
1216 // The electronics baseline in electrons
1217 Double_t baselineEl = baseline
1224 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1225 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1226 Int_t nTimeTotal = simParam->GetNTimeBins();
1228 // The gainfactor calibration objects
1229 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
1230 AliTRDCalROC *calGainFactorROC = 0;
1231 Float_t calGainFactorDetValue = 0.0;
1233 AliTRDarrayADC *digits = 0x0;
1236 AliError(Form("Signals array for detector %d does not exist\n",det));
1239 if (signals->HasData()) {
1240 // Expand the container if neccessary
1244 // Create missing containers
1245 signals->Allocate(nRowMax,nColMax,nTimeTotal);
1248 // Get the container for the digits of this detector
1249 if (fDigitsManager->HasSDigits()) {
1250 AliError("Digits manager has s-digits");
1254 digits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det);
1255 // Allocate memory space for the digits buffer
1256 if (!digits->HasData()) {
1257 digits->Allocate(nRowMax,nColMax,nTimeTotal);
1260 // Get the calibration objects
1261 calGainFactorROC = calibration->GetGainFactorROC(det);
1262 calGainFactorDetValue = calGainFactorDet->GetValue(det);
1264 // Create the digits for this chamber
1265 for (row = 0; row < nRowMax; row++ ) {
1266 for (col = 0; col < nColMax; col++ ) {
1268 // Check whether pad is masked
1269 // Bridged pads are not considered yet!!!
1270 if (calibration->IsPadMasked(det,col,row) || calibration->IsPadNotConnected(det,col,row)) {
1275 Float_t padgain = calGainFactorDetValue
1276 * calGainFactorROC->GetValue(col,row);
1278 AliError(Form("Not a valid gain %f, %d %d %d",padgain,det,col,row));
1281 for (time = 0; time < nTimeTotal; time++) {
1283 // Get the signal amplitude
1284 Float_t signalAmp = signals->GetData(row,col,time);
1285 // Pad and time coupling
1286 signalAmp *= coupling;
1288 signalAmp *= padgain;
1290 // Add the noise, starting from minus ADC baseline in electrons
1291 signalAmp = TMath::Max((Double_t) gRandom->Gaus(signalAmp,simParam->GetNoise())
1295 signalAmp *= convert;
1296 // Add ADC baseline in mV
1297 signalAmp += baseline;
1299 // Convert to ADC counts. Set the overflow-bit fADCoutRange if the
1300 // signal is larger than fADCinRange
1302 if (signalAmp >= simParam->GetADCinRange()) {
1303 adc = ((Short_t) simParam->GetADCoutRange());
1306 adc = TMath::Nint(signalAmp * adcConvert);
1309 // Saving all digits
1310 digits->SetData(row,col,time,adc);
1321 //_____________________________________________________________________________
1322 Bool_t AliTRDdigitizer::Signal2SDigits(Int_t det, AliTRDarraySignal *signals)
1325 // Converts the sampled electron signals to s-digits
1328 AliDebug(1,Form("Start converting signals to s-digits for detector=%d",det));
1330 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1332 AliFatal("Could not get calibration object");
1340 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1341 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1342 Int_t nTimeTotal = AliTRDSimParam::Instance()->GetNTimeBins();
1344 // Get the container for the digits of this detector
1346 if (!fDigitsManager->HasSDigits()) {
1347 AliError("Digits manager has no s-digits");
1351 AliTRDarraySignal *digits = (AliTRDarraySignal *) fDigitsManager->GetSDigits(det);
1352 // Allocate memory space for the digits buffer
1353 if (!digits->HasData()) {
1354 digits->Allocate(nRowMax,nColMax,nTimeTotal);
1357 // Create the sdigits for this chamber
1358 for (row = 0; row < nRowMax; row++ ) {
1359 for (col = 0; col < nColMax; col++ ) {
1360 for (time = 0; time < nTimeTotal; time++) {
1361 digits->SetData(row,col,time,signals->GetData(row,col,time));
1370 //_____________________________________________________________________________
1371 Bool_t AliTRDdigitizer::Digits2SDigits(AliTRDdigitsManager * const manDig
1372 , AliTRDdigitsManager * const manSDig)
1375 // Converts digits into s-digits. Needed for embedding into real data.
1378 AliDebug(1,"Start converting digits to s-digits");
1381 fGeo = new AliTRDgeometry();
1384 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1386 AliFatal("Could not get calibration object");
1390 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
1392 AliFatal("Could not get simulation parameters");
1396 // Converts number of electrons to fC
1397 const Double_t kEl2fC = 1.602e-19 * 1.0e15;
1400 Double_t coupling = simParam->GetPadCoupling()
1401 * simParam->GetTimeCoupling();
1402 // Electronics conversion factor
1403 Double_t convert = kEl2fC
1404 * simParam->GetChipGain();
1405 // ADC conversion factor
1406 Double_t adcConvert = simParam->GetADCoutRange()
1407 / simParam->GetADCinRange();
1408 // The electronics baseline in mV
1409 Double_t baseline = simParam->GetADCbaseline()
1411 // The electronics baseline in electrons
1412 //Double_t baselineEl = baseline
1415 // The gainfactor calibration objects
1416 //const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
1417 //AliTRDCalROC *calGainFactorROC = 0;
1418 //Float_t calGainFactorDetValue = 0.0;
1424 for (Int_t det = 0; det < AliTRDgeometry::Ndet(); det++) {
1426 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1427 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1428 Int_t nTimeTotal = manDig->GetDigitsParam()->GetNTimeBins(det);
1430 // Get the calibration objects
1431 //calGainFactorROC = calibration->GetGainFactorROC(det);
1432 //calGainFactorDetValue = calGainFactorDet->GetValue(det);
1435 AliTRDarrayADC *digits = (AliTRDarrayADC *) manDig->GetDigits(det);
1437 if (!manSDig->HasSDigits()) {
1438 AliError("SDigits manager has no s-digits");
1442 AliTRDarraySignal *sdigits = (AliTRDarraySignal *) manSDig->GetSDigits(det);
1443 AliTRDarrayDictionary *tracks0 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,0);
1444 AliTRDarrayDictionary *tracks1 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,1);
1445 AliTRDarrayDictionary *tracks2 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,2);
1446 // Allocate memory space for the digits buffer
1447 sdigits->Allocate(nRowMax,nColMax,nTimeTotal);
1448 tracks0->Allocate(nRowMax,nColMax,nTimeTotal);
1449 tracks1->Allocate(nRowMax,nColMax,nTimeTotal);
1450 tracks2->Allocate(nRowMax,nColMax,nTimeTotal);
1452 // Keep the digits param
1453 manSDig->GetDigitsParam()->SetNTimeBinsAll(manDig->GetDigitsParam()->GetNTimeBins(0));
1454 manSDig->GetDigitsParam()->SetADCbaselineAll(manDig->GetDigitsParam()->GetADCbaseline(0));
1456 if (digits->HasData()) {
1460 // Create the sdigits for this chamber
1461 for (row = 0; row < nRowMax; row++ ) {
1462 for (col = 0; col < nColMax; col++ ) {
1465 //Float_t padgain = calGainFactorDetValue
1466 // * calGainFactorROC->GetValue(col,row);
1468 for (time = 0; time < nTimeTotal; time++) {
1470 Short_t adcVal = digits->GetData(row,col,time);
1471 Double_t signal = (Double_t) adcVal;
1472 // ADC -> signal in mV
1473 signal /= adcConvert;
1474 // Subtract baseline in mV
1476 // Signal in mV -> signal in #electrons
1479 //signal /= padgain; // Not needed for real data
1480 // Pad and time coupling
1483 sdigits->SetData(row,col,time,signal);
1484 tracks0->SetData(row,col,time,0);
1485 tracks1->SetData(row,col,time,0);
1486 tracks2->SetData(row,col,time,0);
1495 sdigits->Compress(0);
1496 tracks0->Compress();
1497 tracks1->Compress();
1498 tracks2->Compress();
1500 // No compress just remove
1501 manDig->RemoveDigits(det);
1502 manDig->RemoveDictionaries(det);
1510 //_____________________________________________________________________________
1511 Bool_t AliTRDdigitizer::SDigits2Digits()
1514 // Merges the input s-digits and converts them to normal digits
1517 if (!MergeSDigits()) {
1521 return ConvertSDigits();
1525 //_____________________________________________________________________________
1526 Bool_t AliTRDdigitizer::MergeSDigits()
1529 // Merges the input s-digits:
1530 // - The amplitude of the different inputs are summed up.
1531 // - Of the track IDs from the input dictionaries only one is
1532 // kept for each input. This works for maximal 3 different merged inputs.
1535 // Number of track dictionary arrays
1536 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1538 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
1540 AliFatal("Could not get simulation parameters");
1544 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1546 AliFatal("Could not get calibration object");
1553 AliTRDarraySignal *digitsA;
1554 AliTRDarraySignal *digitsB;
1555 AliTRDarrayDictionary *dictionaryA[kNDict];
1556 AliTRDarrayDictionary *dictionaryB[kNDict];
1558 AliTRDdigitsManager *mergeSDigitsManager = 0x0;
1559 // Get the first s-digits
1560 fSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->First();
1561 if (!fSDigitsManager) {
1562 AliError("No SDigits manager");
1566 // Loop through the other sets of s-digits
1567 mergeSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->After(fSDigitsManager);
1569 if (mergeSDigitsManager) {
1570 AliDebug(1,Form("Merge %d input files.",fSDigitsManagerList->GetSize()));
1573 AliDebug(1,"Only one input file.");
1578 while (mergeSDigitsManager) {
1582 // Loop through the detectors
1583 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) {
1585 Int_t nTimeTotal = fSDigitsManager->GetDigitsParam()->GetNTimeBins(iDet);
1586 if (mergeSDigitsManager->GetDigitsParam()->GetNTimeBins(iDet) != nTimeTotal) {
1587 AliError(Form("Mismatch in the number of time bins [%d,%d] in detector %d"
1589 ,mergeSDigitsManager->GetDigitsParam()->GetNTimeBins(iDet)
1594 Int_t nRowMax = fGeo->GetPadPlane(iDet)->GetNrows();
1595 Int_t nColMax = fGeo->GetPadPlane(iDet)->GetNcols();
1597 // Loop through the pixels of one detector and add the signals
1598 digitsA = (AliTRDarraySignal *) fSDigitsManager->GetSDigits(iDet);
1599 digitsB = (AliTRDarraySignal *) mergeSDigitsManager->GetSDigits(iDet);
1601 if (!digitsA->HasData()) continue;
1603 if (!digitsB->HasData()) continue;
1605 for (iDict = 0; iDict < kNDict; iDict++) {
1606 dictionaryA[iDict] = (AliTRDarrayDictionary *) fSDigitsManager->GetDictionary(iDet,iDict);
1607 dictionaryB[iDict] = (AliTRDarrayDictionary *) mergeSDigitsManager->GetDictionary(iDet,iDict);
1608 dictionaryA[iDict]->Expand();
1609 dictionaryB[iDict]->Expand();
1612 // Merge only detectors that contain a signal
1613 Bool_t doMerge = kTRUE;
1614 if (fMergeSignalOnly) {
1615 if (digitsA->GetOverThreshold(0) == 0) {
1622 AliDebug(1,Form("Merge detector %d of input no.%d",iDet,iMerge+1));
1624 for (Int_t iRow = 0; iRow < nRowMax; iRow++ ) {
1625 for (Int_t iCol = 0; iCol < nColMax; iCol++ ) {
1626 for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
1628 // Add the amplitudes of the summable digits
1629 Float_t ampA = digitsA->GetData(iRow,iCol,iTime);
1630 Float_t ampB = digitsB->GetData(iRow,iCol,iTime);
1632 digitsA->SetData(iRow,iCol,iTime,ampA);
1634 // Add the mask to the track id if defined.
1635 for (iDict = 0; iDict < kNDict; iDict++) {
1636 Int_t trackB = dictionaryB[iDict]->GetData(iRow,iCol,iTime);
1637 if ((fMasks) && (trackB > 0)) {
1638 for (jDict = 0; jDict < kNDict; jDict++) {
1639 Int_t trackA = dictionaryA[iDict]->GetData(iRow,iCol,iTime);
1641 trackA = trackB + fMasks[iMerge];
1642 dictionaryA[iDict]->SetData(iRow,iCol,iTime,trackA);
1643 } // if: track A == 0
1645 } // if: fMasks and trackB > 0
1654 mergeSDigitsManager->RemoveDigits(iDet);
1655 mergeSDigitsManager->RemoveDictionaries(iDet);
1658 digitsA->Compress(0);
1659 for (iDict = 0; iDict < kNDict; iDict++) {
1660 dictionaryA[iDict]->Compress();
1666 // The next set of s-digits
1667 mergeSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->After(mergeSDigitsManager);
1669 } // while: mergeDigitsManagers
1675 //_____________________________________________________________________________
1676 Bool_t AliTRDdigitizer::ConvertSDigits()
1679 // Converts s-digits to normal digits
1682 AliTRDarraySignal *digitsIn = 0x0;
1684 if (!fSDigitsManager->HasSDigits()) {
1685 AliError("No s-digits in digits manager");
1689 // Loop through the detectors
1690 for (Int_t det = 0; det < AliTRDgeometry::Ndet(); det++) {
1692 // Get the merged s-digits (signals)
1693 digitsIn = (AliTRDarraySignal *) fSDigitsManager->GetSDigits(det);
1694 if (!digitsIn->HasData()) {
1695 AliDebug(2,Form("No digits for det=%d",det));
1699 // Convert the merged sdigits to digits
1700 if (!Signal2ADC(det,digitsIn)) {
1704 // Copy the dictionary information to the output array
1705 if (!CopyDictionary(det)) {
1710 fSDigitsManager->RemoveDigits(det);
1711 fSDigitsManager->RemoveDictionaries(det);
1713 // Run digital processing
1714 RunDigitalProcessing(det);
1716 // Compress the arrays
1717 CompressOutputArrays(det);
1719 } // for: detector numbers
1721 if (AliDataLoader *trklLoader = AliRunLoader::Instance()->GetLoader("TRDLoader")->GetDataLoader("tracklets")) {
1722 if (trklLoader->Tree())
1723 trklLoader->WriteData("OVERWRITE");
1726 // Save the values for the raw data headers
1727 fDigitsManager->GetDigitsParam()->SetNTimeBinsAll(AliTRDSimParam::Instance()->GetNTimeBins());
1728 fDigitsManager->GetDigitsParam()->SetADCbaselineAll(AliTRDSimParam::Instance()->GetADCbaseline());
1734 //_____________________________________________________________________________
1735 Bool_t AliTRDdigitizer::CopyDictionary(Int_t det)
1738 // Copies the dictionary information from the s-digits arrays
1739 // to the output arrays
1742 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1744 AliFatal("Could not get calibration object");
1748 AliDebug(1,Form("Start copying dictionaries for detector=%d",det));
1750 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1751 AliTRDarrayDictionary *dictionaryIn[kNDict];
1752 AliTRDarrayDictionary *dictionaryOut[kNDict];
1754 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1755 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1756 Int_t nTimeTotal = AliTRDSimParam::Instance()->GetNTimeBins();
1763 for (dict = 0; dict < kNDict; dict++) {
1765 dictionaryIn[dict] = (AliTRDarrayDictionary *) fSDigitsManager->GetDictionary(det,dict);
1766 dictionaryIn[dict]->Expand();
1767 dictionaryOut[dict] = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
1768 dictionaryOut[dict]->Allocate(nRowMax,nColMax,nTimeTotal);
1770 for (row = 0; row < nRowMax; row++) {
1771 for (col = 0; col < nColMax; col++) {
1772 for (time = 0; time < nTimeTotal; time++) {
1773 Int_t track = dictionaryIn[dict]->GetData(row,col,time);
1774 dictionaryOut[dict]->SetData(row,col,time,track);
1779 } // for: dictionaries
1785 //_____________________________________________________________________________
1786 void AliTRDdigitizer::CompressOutputArrays(Int_t det)
1789 // Compress the output arrays
1792 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1793 AliTRDarrayDictionary *dictionary = 0x0;
1798 AliTRDarrayADC *digits = 0x0;
1799 digits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det);
1804 AliTRDarraySignal *digits = 0x0;
1805 digits = (AliTRDarraySignal *) fDigitsManager->GetSDigits(det);
1806 digits->Compress(0);
1809 for (Int_t dict = 0; dict < kNDict; dict++) {
1810 dictionary = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
1811 dictionary->Compress();
1818 //_____________________________________________________________________________
1819 Bool_t AliTRDdigitizer::WriteDigits() const
1822 // Writes out the TRD-digits and the dictionaries
1826 fRunLoader->CdGAFile();
1828 // Store the digits and the dictionary in the tree
1829 return fDigitsManager->WriteDigits();
1833 //_____________________________________________________________________________
1834 void AliTRDdigitizer::InitOutput(Int_t iEvent)
1837 // Initializes the output branches
1843 AliError("Run Loader is NULL");
1847 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
1849 AliError("Can not get TRD loader from Run Loader");
1856 // If we produce SDigits
1857 tree = loader->TreeS();
1859 loader->MakeTree("S");
1860 tree = loader->TreeS();
1864 // If we produce Digits
1865 tree = loader->TreeD();
1867 loader->MakeTree("D");
1868 tree = loader->TreeD();
1871 fDigitsManager->SetEvent(iEvent);
1872 fDigitsManager->MakeBranch(tree);
1876 //_____________________________________________________________________________
1877 Int_t AliTRDdigitizer::Diffusion(Float_t vdrift, Double_t absdriftlength
1878 , Double_t &lRow, Double_t &lCol, Double_t &lTime)
1881 // Applies the diffusion smearing to the position of a single electron.
1882 // Depends on absolute drift length.
1885 Float_t diffL = 0.0;
1886 Float_t diffT = 0.0;
1888 if (AliTRDCommonParam::Instance()->GetDiffCoeff(diffL,diffT,vdrift)) {
1890 Float_t driftSqrt = TMath::Sqrt(absdriftlength);
1891 Float_t sigmaT = driftSqrt * diffT;
1892 Float_t sigmaL = driftSqrt * diffL;
1893 lRow = gRandom->Gaus(lRow ,sigmaT);
1894 lCol = gRandom->Gaus(lCol ,sigmaT * GetLorentzFactor(vdrift));
1895 lTime = gRandom->Gaus(lTime,sigmaL * GetLorentzFactor(vdrift));
1908 //_____________________________________________________________________________
1909 Float_t AliTRDdigitizer::GetLorentzFactor(Float_t vd)
1912 // Returns the Lorentz factor
1915 Double_t omegaTau = AliTRDCommonParam::Instance()->GetOmegaTau(vd);
1916 Double_t lorentzFactor = 1.0;
1917 if (AliTRDCommonParam::Instance()->ExBOn()) {
1918 lorentzFactor = 1.0 / (1.0 + omegaTau*omegaTau);
1921 return lorentzFactor;
1925 //_____________________________________________________________________________
1926 Int_t AliTRDdigitizer::ExB(Float_t vdrift, Double_t driftlength, Double_t &lCol)
1929 // Applies E x B effects to the position of a single electron.
1930 // Depends on signed drift length.
1934 + AliTRDCommonParam::Instance()->GetOmegaTau(vdrift)
1941 //_____________________________________________________________________________
1942 void AliTRDdigitizer::RunDigitalProcessing(Int_t det)
1945 // Run the digital processing in the TRAP
1948 AliTRDfeeParam *feeParam = AliTRDfeeParam::Instance();
1950 AliTRDarrayADC *digits = fDigitsManager->GetDigits(det);
1954 //Call the methods in the mcm class using the temporary array as input
1955 for(Int_t rob = 0; rob < digits->GetNrow() / 2; rob++)
1957 for(Int_t mcm = 0; mcm < 16; mcm++)
1959 fMcmSim->Init(det, rob, mcm);
1960 fMcmSim->SetDataByPad(digits, fDigitsManager);
1962 if (feeParam->GetTracklet()) {
1963 fMcmSim->Tracklet();
1964 fMcmSim->StoreTracklets();
1966 fMcmSim->ZSMapping();
1967 fMcmSim->WriteData(digits);