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)
89 ,fMergeSignalOnly(kFALSE)
92 // AliTRDdigitizer default constructor
97 //_____________________________________________________________________________
98 AliTRDdigitizer::AliTRDdigitizer(const Text_t *name, const Text_t *title)
99 :AliDigitizer(name,title)
103 ,fSDigitsManagerList(0)
110 ,fMergeSignalOnly(kFALSE)
113 // AliTRDdigitizer constructor
118 //_____________________________________________________________________________
119 AliTRDdigitizer::AliTRDdigitizer(AliRunDigitizer *manager
120 , const Text_t *name, const Text_t *title)
121 :AliDigitizer(manager,name,title)
125 ,fSDigitsManagerList(0)
132 ,fMergeSignalOnly(kFALSE)
135 // AliTRDdigitizer constructor
140 //_____________________________________________________________________________
141 AliTRDdigitizer::AliTRDdigitizer(AliRunDigitizer *manager)
142 :AliDigitizer(manager,"AliTRDdigitizer","TRD digitizer")
146 ,fSDigitsManagerList(0)
153 ,fMergeSignalOnly(kFALSE)
156 // AliTRDdigitizer constructor
161 //_____________________________________________________________________________
162 AliTRDdigitizer::AliTRDdigitizer(const AliTRDdigitizer &d)
167 ,fSDigitsManagerList(0)
172 ,fCompress(d.fCompress)
173 ,fSDigits(d.fSDigits)
174 ,fMergeSignalOnly(d.fMergeSignalOnly)
177 // AliTRDdigitizer copy constructor
182 //_____________________________________________________________________________
183 AliTRDdigitizer::~AliTRDdigitizer()
186 // AliTRDdigitizer destructor
189 if (fDigitsManager) {
190 delete fDigitsManager;
194 if (fSDigitsManager) {
195 // s-digitsmanager will be deleted via list
199 if (fSDigitsManagerList) {
200 fSDigitsManagerList->Delete();
201 delete fSDigitsManagerList;
202 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::Exec(const Option_t * const 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(fManager->GetInputFolderName(0));
279 gAlice = inrl->GetAliRun();
281 AliError("Could not find AliRun object.")
286 Int_t nInput = fManager->GetNinputs();
287 fMasks = new Int_t[nInput];
288 for (iInput = 0; iInput < nInput; iInput++) {
289 fMasks[iInput] = fManager->GetMask(iInput);
296 AliRunLoader *orl = AliRunLoader::GetRunLoader(fManager->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(fManager->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(fManager->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();
552 //_____________________________________________________________________________
553 Bool_t AliTRDdigitizer::MakeBranch(TTree *tree) const
556 // Create the branches for the digits array
559 return fDigitsManager->MakeBranch(tree);
563 //_____________________________________________________________________________
564 void AliTRDdigitizer::AddSDigitsManager(AliTRDdigitsManager *man)
567 // Add a digits manager for s-digits to the input list.
570 fSDigitsManagerList->Add(man);
574 //_____________________________________________________________________________
575 void AliTRDdigitizer::DeleteSDigitsManager()
578 // Removes digits manager from the input list.
581 fSDigitsManagerList->Delete();
585 //_____________________________________________________________________________
586 Bool_t AliTRDdigitizer::MakeDigits()
592 AliDebug(1,"Start creating digits");
595 AliError("No geometry defined");
599 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
601 AliFatal("Could not get calibration object");
605 const Int_t kNdet = AliTRDgeometry::Ndet();
607 Float_t **hits = new Float_t*[kNdet];
608 Int_t *nhit = new Int_t[kNdet];
610 AliTRDarraySignal *signals = 0x0;
613 if (calibration->GetNumberOfTimeBinsDCS() != AliTRDSimParam::Instance()->GetNTimeBins()) {
614 AliWarning(Form("Number of time bins is different to OCDB value [SIM=%d, OCDB=%d]"
615 ,AliTRDSimParam::Instance()->GetNTimeBins()
616 ,calibration->GetNumberOfTimeBinsDCS()));
619 // Sort all hits according to detector number
620 if (!SortHits(hits,nhit)) {
621 AliError("Sorting hits failed");
625 // Loop through all detectors
626 for (Int_t det = 0; det < kNdet; det++) {
628 // Detectors that are switched off, not installed, etc.
629 if (( calibration->IsChamberInstalled(det)) &&
630 (!calibration->IsChamberMasked(det)) &&
631 ( fGeo->ChamberInGeometry(det)) &&
634 signals = new AliTRDarraySignal();
636 // Convert the hits of the current detector to detector signals
637 if (!ConvertHits(det,hits[det],nhit[det],signals)) {
638 AliError(Form("Conversion of hits failed for detector=%d",det));
641 // Convert the detector signals to digits or s-digits
642 if (!ConvertSignals(det,signals)) {
643 AliError(Form("Conversion of signals failed for detector=%d",det));
647 // Delete the signals array
651 } // if: detector status
658 if (AliDataLoader *trklLoader = AliRunLoader::Instance()->GetLoader("TRDLoader")->GetDataLoader("tracklets")) {
659 if (trklLoader->Tree())
660 trklLoader->WriteData("OVERWRITE");
667 // Save the values for the raw data headers
668 fDigitsManager->GetDigitsParam()->SetNTimeBinsAll(AliTRDSimParam::Instance()->GetNTimeBins());
669 fDigitsManager->GetDigitsParam()->SetADCbaselineAll(AliTRDSimParam::Instance()->GetADCbaseline());
675 //_____________________________________________________________________________
676 Bool_t AliTRDdigitizer::SortHits(Float_t **hits, Int_t *nhit)
679 // Read all the hits and sorts them according to detector number
680 // in the output array <hits>.
683 AliDebug(1,"Start sorting hits");
685 const Int_t kNdet = AliTRDgeometry::Ndet();
686 // Size of the hit vector
687 const Int_t kNhit = 6;
692 Int_t *lhit = new Int_t[kNdet];
694 for (Int_t det = 0; det < kNdet; det++) {
700 AliLoader *gimme = fRunLoader->GetLoader("TRDLoader");
701 if (!gimme->TreeH()) {
704 TTree *hitTree = gimme->TreeH();
705 if (hitTree == 0x0) {
706 AliError("Can not get TreeH");
709 fTRD->SetTreeAddress();
711 // Get the number of entries in the hit tree
712 // (Number of primary particles creating a hit somewhere)
713 Int_t nTrk = (Int_t) hitTree->GetEntries();
714 AliDebug(1,Form("Found %d tracks",nTrk));
716 // Loop through all the tracks in the tree
717 for (Int_t iTrk = 0; iTrk < nTrk; iTrk++) {
719 gAlice->GetMCApp()->ResetHits();
720 hitTree->GetEvent(iTrk);
723 AliError(Form("No hits array for track = %d",iTrk));
727 // Number of hits for this track
728 nhitTrk = fTRD->Hits()->GetEntriesFast();
731 // Loop through the TRD hits
732 AliTRDhit *hit = (AliTRDhit *) fTRD->FirstHit(-1);
737 // Don't analyze test hits
738 if (((Int_t) hit->GetCharge()) != 0) {
740 Int_t trk = hit->Track();
741 Int_t det = hit->GetDetector();
742 Int_t q = hit->GetCharge();
743 Float_t x = hit->X();
744 Float_t y = hit->Y();
745 Float_t z = hit->Z();
746 Float_t time = hit->GetTime();
748 if (nhit[det] == lhit[det]) {
749 // Inititialization of new detector
750 xyz = new Float_t[kNhit*(nhitTrk+lhit[det])];
752 memcpy(xyz,hits[det],sizeof(Float_t)*kNhit*lhit[det]);
755 lhit[det] += nhitTrk;
761 xyz[nhit[det]*kNhit+0] = x;
762 xyz[nhit[det]*kNhit+1] = y;
763 xyz[nhit[det]*kNhit+2] = z;
764 xyz[nhit[det]*kNhit+3] = q;
765 xyz[nhit[det]*kNhit+4] = trk;
766 xyz[nhit[det]*kNhit+5] = time;
771 hit = (AliTRDhit *) fTRD->NextHit();
773 } // for: hits of one track
783 //_____________________________________________________________________________
784 Bool_t AliTRDdigitizer::ConvertHits(Int_t det
785 , const Float_t * const hits
787 , AliTRDarraySignal *signals)
790 // Converts the detectorwise sorted hits to detector signals
793 AliDebug(1,Form("Start converting hits for detector=%d (nhits=%d)",det,nhit));
795 // Number of pads included in the pad response
796 const Int_t kNpad = 3;
797 // Number of track dictionary arrays
798 const Int_t kNdict = AliTRDdigitsManager::kNDict;
799 // Size of the hit vector
800 const Int_t kNhit = 6;
802 // Width of the amplification region
803 const Float_t kAmWidth = AliTRDgeometry::AmThick();
804 // Width of the drift region
805 const Float_t kDrWidth = AliTRDgeometry::DrThick();
806 // Drift + amplification region
807 const Float_t kDrMin = - 0.5 * kAmWidth;
808 const Float_t kDrMax = kDrWidth + 0.5 * kAmWidth;
812 Int_t timeBinTRFend = 1;
816 Double_t padSignal[kNpad];
817 Double_t signalOld[kNpad];
819 AliTRDarrayDictionary *dictionary[kNdict];
821 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
822 AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance();
823 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
826 AliFatal("Could not get common parameterss");
830 AliFatal("Could not get simulation parameters");
834 AliFatal("Could not get calibration object");
838 // Get the detector wise calibration objects
839 AliTRDCalROC *calVdriftROC = 0;
840 Float_t calVdriftDetValue = 0.0;
841 const AliTRDCalDet *calVdriftDet = calibration->GetVdriftDet();
842 AliTRDCalROC *calT0ROC = 0;
843 Float_t calT0DetValue = 0.0;
844 const AliTRDCalDet *calT0Det = calibration->GetT0Det();
846 if (simParam->TRFOn()) {
847 timeBinTRFend = ((Int_t) (simParam->GetTRFhi()
848 * commonParam->GetSamplingFrequency())) - 1;
851 Int_t nTimeTotal = simParam->GetNTimeBins();
852 Float_t samplingRate = commonParam->GetSamplingFrequency();
853 Float_t elAttachProp = simParam->GetElAttachProp() / 100.0;
855 AliTRDpadPlane *padPlane = fGeo->GetPadPlane(det);
856 Int_t layer = fGeo->GetLayer(det); //update
857 Float_t row0 = padPlane->GetRow0ROC();
858 Int_t nRowMax = padPlane->GetNrows();
859 Int_t nColMax = padPlane->GetNcols();
861 // Create a new array for the signals
862 signals->Allocate(nRowMax,nColMax,nTimeTotal);
864 // Create a new array for the dictionary
865 for (dict = 0; dict < kNdict; dict++) {
866 dictionary[dict] = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
867 dictionary[dict]->Allocate(nRowMax,nColMax,nTimeTotal);
870 // Loop through the hits in this detector
871 for (Int_t hit = 0; hit < nhit; hit++) {
873 pos[0] = hits[hit*kNhit+0];
874 pos[1] = hits[hit*kNhit+1];
875 pos[2] = hits[hit*kNhit+2];
876 Float_t q = hits[hit*kNhit+3];
877 Float_t hittime = hits[hit*kNhit+5];
878 Int_t track = ((Int_t) hits[hit*kNhit+4]);
882 // Find the current volume with the geo manager
883 gGeoManager->SetCurrentPoint(pos);
884 gGeoManager->FindNode();
885 if (strstr(gGeoManager->GetPath(),"/UK")) {
889 // Get the calibration objects
890 calVdriftROC = calibration->GetVdriftROC(det);
891 calVdriftDetValue = calVdriftDet->GetValue(det);
892 calT0ROC = calibration->GetT0ROC(det);
893 calT0DetValue = calT0Det->GetValue(det);
895 // Go to the local coordinate system:
896 // loc[0] - col direction in amplification or driftvolume
897 // loc[1] - row direction in amplification or driftvolume
898 // loc[2] - time direction in amplification or driftvolume
899 gGeoManager->MasterToLocal(pos,loc);
901 // Relative to middle of amplification region
902 loc[2] = loc[2] - kDrWidth/2.0 - kAmWidth/2.0;
905 // The driftlength [cm] (w/o diffusion yet !).
906 // It is negative if the hit is between pad plane and anode wires.
907 Double_t driftlength = -1.0 * loc[2];
909 // Stupid patch to take care of TR photons that are absorbed
910 // outside the chamber volume. A real fix would actually need
911 // a more clever implementation of the TR hit generation
913 if ((loc[1] < padPlane->GetRowEndROC()) ||
914 (loc[1] > padPlane->GetRow0ROC())) {
917 if ((driftlength < kDrMin) ||
918 (driftlength > kDrMax)) {
923 // Get row and col of unsmeared electron to retrieve drift velocity
924 // The pad row (z-direction)
925 Int_t rowE = padPlane->GetPadRowNumberROC(loc[1]);
929 Double_t rowOffset = padPlane->GetPadRowOffsetROC(rowE,loc[1]);
930 // The pad column (rphi-direction)
931 Double_t offsetTilt = padPlane->GetTiltOffset(rowOffset);
932 Int_t colE = padPlane->GetPadColNumber(loc[0]+offsetTilt);
936 Double_t colOffset = 0.0;
938 // Normalized drift length
939 Float_t driftvelocity = calVdriftDetValue * calVdriftROC->GetValue(colE,rowE);
940 Double_t absdriftlength = TMath::Abs(driftlength);
941 if (commonParam->ExBOn()) {
942 absdriftlength /= TMath::Sqrt(GetLorentzFactor(driftvelocity));
945 // Loop over all electrons of this hit
946 // TR photons produce hits with negative charge
947 Int_t nEl = ((Int_t) TMath::Abs(q));
948 for (Int_t iEl = 0; iEl < nEl; iEl++) {
950 // Now the real local coordinate system of the ROC
951 // column direction: locC
952 // row direction: locR
953 // time direction: locT
954 // locR and locC are identical to the coordinates of the corresponding
955 // volumina of the drift or amplification region.
956 // locT is defined relative to the wire plane (i.e. middle of amplification
957 // region), meaning locT = 0, and is negative for hits coming from the
959 Double_t locC = loc[0];
960 Double_t locR = loc[1];
961 Double_t locT = loc[2];
963 // Electron attachment
964 if (simParam->ElAttachOn()) {
965 if (gRandom->Rndm() < (absdriftlength * elAttachProp)) {
970 // Apply the diffusion smearing
971 if (simParam->DiffusionOn()) {
972 if (!(Diffusion(driftvelocity,absdriftlength,locR,locC,locT))) {
977 // Apply E x B effects (depends on drift direction)
978 if (commonParam->ExBOn()) {
979 if (!(ExB(driftvelocity,driftlength,locC))) {
984 // The electron position after diffusion and ExB in pad coordinates.
985 // The pad row (z-direction)
986 rowE = padPlane->GetPadRowNumberROC(locR);
987 if (rowE < 0) continue;
988 rowOffset = padPlane->GetPadRowOffsetROC(rowE,locR);
990 // The pad column (rphi-direction)
991 offsetTilt = padPlane->GetTiltOffset(rowOffset);
992 colE = padPlane->GetPadColNumber(locC+offsetTilt);
993 if (colE < 0) continue;
994 colOffset = padPlane->GetPadColOffset(colE,locC+offsetTilt);
996 // Also re-retrieve drift velocity because col and row may have changed
997 driftvelocity = calVdriftDetValue * calVdriftROC->GetValue(colE,rowE);
998 Float_t t0 = calT0DetValue + calT0ROC->GetValue(colE,rowE);
1000 // Convert the position to drift time [mus], using either constant drift velocity or
1001 // time structure of drift cells (non-isochronity, GARFIELD calculation).
1002 // Also add absolute time of hits to take pile-up events into account properly
1004 if (simParam->TimeStructOn()) {
1005 // Get z-position with respect to anode wire
1006 Double_t zz = row0 - locR + padPlane->GetAnodeWireOffset();
1007 zz -= ((Int_t)(2 * zz)) / 2.0;
1011 // Use drift time map (GARFIELD)
1012 drifttime = commonParam->TimeStruct(driftvelocity,0.5*kAmWidth-1.0*locT,zz)
1016 // Use constant drift velocity
1017 drifttime = TMath::Abs(locT) / driftvelocity
1021 // Apply the gas gain including fluctuations
1022 Double_t ggRndm = 0.0;
1024 ggRndm = gRandom->Rndm();
1025 } while (ggRndm <= 0);
1026 Double_t signal = -(simParam->GetGasGain()) * TMath::Log(ggRndm);
1028 // Apply the pad response
1029 if (simParam->PRFOn()) {
1030 // The distance of the electron to the center of the pad
1031 // in units of pad width
1032 Double_t dist = (colOffset - 0.5*padPlane->GetColSize(colE))
1033 / padPlane->GetColSize(colE);
1034 // This is a fixed parametrization, i.e. not dependent on
1035 // calibration values !
1036 if (!(calibration->PadResponse(signal,dist,layer,padSignal))) continue;
1040 padSignal[1] = signal;
1044 // The time bin (always positive), with t0 distortion
1045 Double_t timeBinIdeal = drifttime * samplingRate + t0;
1047 if (TMath::Abs(timeBinIdeal) > 2*nTimeTotal) {
1048 timeBinIdeal = 2 * nTimeTotal;
1050 Int_t timeBinTruncated = ((Int_t) timeBinIdeal);
1051 // The distance of the position to the middle of the timebin
1052 Double_t timeOffset = ((Float_t) timeBinTruncated
1053 + 0.5 - timeBinIdeal) / samplingRate;
1055 // Sample the time response inside the drift region
1056 // + additional time bins before and after.
1057 // The sampling is done always in the middle of the time bin
1058 for (Int_t iTimeBin = TMath::Max(timeBinTruncated,0)
1059 ;iTimeBin < TMath::Min(timeBinTruncated+timeBinTRFend,nTimeTotal)
1062 // Apply the time response
1063 Double_t timeResponse = 1.0;
1064 Double_t crossTalk = 0.0;
1065 Double_t time = (iTimeBin - timeBinTruncated) / samplingRate + timeOffset;
1067 if (simParam->TRFOn()) {
1068 timeResponse = simParam->TimeResponse(time);
1070 if (simParam->CTOn()) {
1071 crossTalk = simParam->CrossTalk(time);
1078 for (iPad = 0; iPad < kNpad; iPad++) {
1080 Int_t colPos = colE + iPad - 1;
1081 if (colPos < 0) continue;
1082 if (colPos >= nColMax) break;
1085 signalOld[iPad] = signals->GetData(rowE,colPos,iTimeBin);
1087 if (colPos != colE) {
1088 // Cross talk added to non-central pads
1089 signalOld[iPad] += padSignal[iPad]
1090 * (timeResponse + crossTalk);
1093 // W/o cross talk at central pad
1094 signalOld[iPad] += padSignal[iPad]
1098 signals->SetData(rowE,colPos,iTimeBin,signalOld[iPad]);
1100 // Store the track index in the dictionary
1101 // Note: We store index+1 in order to allow the array to be compressed
1102 // Note2: Taking out the +1 in track
1103 if (signalOld[iPad] > 0.0) {
1104 for (dict = 0; dict < kNdict; dict++) {
1105 Int_t oldTrack = dictionary[dict]->GetData(rowE,colPos,iTimeBin);
1106 if (oldTrack == track) break;
1107 if (oldTrack == -1 ) {
1108 dictionary[dict]->SetData(rowE,colPos,iTimeBin,track);
1116 } // Loop: time bins
1118 } // Loop: electrons of a single hit
1122 AliDebug(2,Form("Finished analyzing %d hits",nhit));
1128 //_____________________________________________________________________________
1129 Bool_t AliTRDdigitizer::ConvertSignals(Int_t det, AliTRDarraySignal *signals)
1132 // Convert signals to digits
1135 AliDebug(1,Form("Start converting the signals for detector %d",det));
1138 // Convert the signal array to s-digits
1139 if (!Signal2SDigits(det,signals)) {
1144 // Convert the signal array to digits
1145 if (!Signal2ADC(det,signals)) {
1148 // Run digital processing for digits
1149 RunDigitalProcessing(det);
1152 // Compress the arrays
1153 CompressOutputArrays(det);
1159 //_____________________________________________________________________________
1160 Bool_t AliTRDdigitizer::Signal2ADC(Int_t det, AliTRDarraySignal *signals)
1163 // Converts the sampled electron signals to ADC values for a given chamber
1166 AliDebug(1,Form("Start converting signals to ADC values for detector=%d",det));
1168 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1170 AliFatal("Could not get calibration object");
1174 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
1176 AliFatal("Could not get simulation parameters");
1180 // Converts number of electrons to fC
1181 const Double_t kEl2fC = 1.602e-19 * 1.0e15;
1184 Double_t coupling = simParam->GetPadCoupling()
1185 * simParam->GetTimeCoupling();
1186 // Electronics conversion factor
1187 Double_t convert = kEl2fC
1188 * simParam->GetChipGain();
1189 // ADC conversion factor
1190 Double_t adcConvert = simParam->GetADCoutRange()
1191 / simParam->GetADCinRange();
1192 // The electronics baseline in mV
1193 Double_t baseline = simParam->GetADCbaseline()
1195 // The electronics baseline in electrons
1196 Double_t baselineEl = baseline
1203 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1204 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1205 Int_t nTimeTotal = simParam->GetNTimeBins();
1207 // The gainfactor calibration objects
1208 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
1209 AliTRDCalROC *calGainFactorROC = 0;
1210 Float_t calGainFactorDetValue = 0.0;
1212 AliTRDarrayADC *digits = 0x0;
1215 AliError(Form("Signals array for detector %d does not exist\n",det));
1218 if (signals->HasData()) {
1219 // Expand the container if neccessary
1223 // Create missing containers
1224 signals->Allocate(nRowMax,nColMax,nTimeTotal);
1227 // Get the container for the digits of this detector
1228 if (fDigitsManager->HasSDigits()) {
1229 AliError("Digits manager has s-digits");
1233 digits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det);
1234 // Allocate memory space for the digits buffer
1235 if (!digits->HasData()) {
1236 digits->Allocate(nRowMax,nColMax,nTimeTotal);
1239 // Get the calibration objects
1240 calGainFactorROC = calibration->GetGainFactorROC(det);
1241 calGainFactorDetValue = calGainFactorDet->GetValue(det);
1243 // Create the digits for this chamber
1244 for (row = 0; row < nRowMax; row++ ) {
1245 for (col = 0; col < nColMax; col++ ) {
1247 // Check whether pad is masked
1248 // Bridged pads are not considered yet!!!
1249 if (calibration->IsPadMasked(det,col,row)) {
1254 Float_t padgain = calGainFactorDetValue
1255 * calGainFactorROC->GetValue(col,row);
1257 AliError(Form("Not a valid gain %f, %d %d %d",padgain,det,col,row));
1260 for (time = 0; time < nTimeTotal; time++) {
1262 // Get the signal amplitude
1263 Float_t signalAmp = signals->GetData(row,col,time);
1264 // Pad and time coupling
1265 signalAmp *= coupling;
1267 signalAmp *= padgain;
1269 // Add the noise, starting from minus ADC baseline in electrons
1270 signalAmp = TMath::Max((Double_t) gRandom->Gaus(signalAmp,simParam->GetNoise())
1274 signalAmp *= convert;
1275 // Add ADC baseline in mV
1276 signalAmp += baseline;
1278 // Convert to ADC counts. Set the overflow-bit fADCoutRange if the
1279 // signal is larger than fADCinRange
1281 if (signalAmp >= simParam->GetADCinRange()) {
1282 adc = ((Short_t) simParam->GetADCoutRange());
1285 adc = TMath::Nint(signalAmp * adcConvert);
1288 // Saving all digits
1289 digits->SetData(row,col,time,adc);
1300 //_____________________________________________________________________________
1301 Bool_t AliTRDdigitizer::Signal2SDigits(Int_t det, AliTRDarraySignal *signals)
1304 // Converts the sampled electron signals to s-digits
1307 AliDebug(1,Form("Start converting signals to s-digits for detector=%d",det));
1309 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1311 AliFatal("Could not get calibration object");
1319 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1320 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1321 Int_t nTimeTotal = AliTRDSimParam::Instance()->GetNTimeBins();
1323 // Get the container for the digits of this detector
1325 if (!fDigitsManager->HasSDigits()) {
1326 AliError("Digits manager has no s-digits");
1330 AliTRDarraySignal *digits = (AliTRDarraySignal *) fDigitsManager->GetSDigits(det);
1331 // Allocate memory space for the digits buffer
1332 if (!digits->HasData()) {
1333 digits->Allocate(nRowMax,nColMax,nTimeTotal);
1336 // Create the sdigits for this chamber
1337 for (row = 0; row < nRowMax; row++ ) {
1338 for (col = 0; col < nColMax; col++ ) {
1339 for (time = 0; time < nTimeTotal; time++) {
1340 digits->SetData(row,col,time,signals->GetData(row,col,time));
1349 //_____________________________________________________________________________
1350 Bool_t AliTRDdigitizer::Digits2SDigits(AliTRDdigitsManager * const manDig
1351 , AliTRDdigitsManager * const manSDig)
1354 // Converts digits into s-digits. Needed for embedding into real data.
1357 AliDebug(1,"Start converting digits to s-digits");
1360 fGeo = new AliTRDgeometry();
1363 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1365 AliFatal("Could not get calibration object");
1369 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
1371 AliFatal("Could not get simulation parameters");
1375 // Converts number of electrons to fC
1376 const Double_t kEl2fC = 1.602e-19 * 1.0e15;
1379 Double_t coupling = simParam->GetPadCoupling()
1380 * simParam->GetTimeCoupling();
1381 // Electronics conversion factor
1382 Double_t convert = kEl2fC
1383 * simParam->GetChipGain();
1384 // ADC conversion factor
1385 Double_t adcConvert = simParam->GetADCoutRange()
1386 / simParam->GetADCinRange();
1387 // The electronics baseline in mV
1388 Double_t baseline = simParam->GetADCbaseline()
1390 // The electronics baseline in electrons
1391 //Double_t baselineEl = baseline
1394 // The gainfactor calibration objects
1395 //const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
1396 //AliTRDCalROC *calGainFactorROC = 0;
1397 //Float_t calGainFactorDetValue = 0.0;
1403 for (Int_t det = 0; det < AliTRDgeometry::Ndet(); det++) {
1405 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1406 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1407 Int_t nTimeTotal = manDig->GetDigitsParam()->GetNTimeBins(det);
1409 // Get the calibration objects
1410 //calGainFactorROC = calibration->GetGainFactorROC(det);
1411 //calGainFactorDetValue = calGainFactorDet->GetValue(det);
1414 AliTRDarrayADC *digits = (AliTRDarrayADC *) manDig->GetDigits(det);
1416 if (!manSDig->HasSDigits()) {
1417 AliError("SDigits manager has no s-digits");
1421 AliTRDarraySignal *sdigits = (AliTRDarraySignal *) manSDig->GetSDigits(det);
1422 AliTRDarrayDictionary *tracks0 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,0);
1423 AliTRDarrayDictionary *tracks1 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,1);
1424 AliTRDarrayDictionary *tracks2 = (AliTRDarrayDictionary *) manSDig->GetDictionary(det,2);
1425 // Allocate memory space for the digits buffer
1426 sdigits->Allocate(nRowMax,nColMax,nTimeTotal);
1427 tracks0->Allocate(nRowMax,nColMax,nTimeTotal);
1428 tracks1->Allocate(nRowMax,nColMax,nTimeTotal);
1429 tracks2->Allocate(nRowMax,nColMax,nTimeTotal);
1431 // Keep the digits param
1432 manSDig->GetDigitsParam()->SetNTimeBinsAll(manDig->GetDigitsParam()->GetNTimeBins(0));
1433 manSDig->GetDigitsParam()->SetADCbaselineAll(manDig->GetDigitsParam()->GetADCbaseline(0));
1435 if (digits->HasData()) {
1439 // Create the sdigits for this chamber
1440 for (row = 0; row < nRowMax; row++ ) {
1441 for (col = 0; col < nColMax; col++ ) {
1444 //Float_t padgain = calGainFactorDetValue
1445 // * calGainFactorROC->GetValue(col,row);
1447 for (time = 0; time < nTimeTotal; time++) {
1449 Short_t adcVal = digits->GetData(row,col,time);
1450 Double_t signal = (Double_t) adcVal;
1451 // ADC -> signal in mV
1452 signal /= adcConvert;
1453 // Subtract baseline in mV
1455 // Signal in mV -> signal in #electrons
1458 //signal /= padgain; // Not needed for real data
1459 // Pad and time coupling
1462 sdigits->SetData(row,col,time,signal);
1463 tracks0->SetData(row,col,time,0);
1464 tracks1->SetData(row,col,time,0);
1465 tracks2->SetData(row,col,time,0);
1474 sdigits->Compress(0);
1475 tracks0->Compress();
1476 tracks1->Compress();
1477 tracks2->Compress();
1479 // No compress just remove
1480 manDig->RemoveDigits(det);
1481 manDig->RemoveDictionaries(det);
1489 //_____________________________________________________________________________
1490 Bool_t AliTRDdigitizer::SDigits2Digits()
1493 // Merges the input s-digits and converts them to normal digits
1496 if (!MergeSDigits()) {
1500 return ConvertSDigits();
1504 //_____________________________________________________________________________
1505 Bool_t AliTRDdigitizer::MergeSDigits()
1508 // Merges the input s-digits:
1509 // - The amplitude of the different inputs are summed up.
1510 // - Of the track IDs from the input dictionaries only one is
1511 // kept for each input. This works for maximal 3 different merged inputs.
1514 // Number of track dictionary arrays
1515 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1517 AliTRDSimParam *simParam = AliTRDSimParam::Instance();
1519 AliFatal("Could not get simulation parameters");
1523 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1525 AliFatal("Could not get calibration object");
1532 AliTRDarraySignal *digitsA;
1533 AliTRDarraySignal *digitsB;
1534 AliTRDarrayDictionary *dictionaryA[kNDict];
1535 AliTRDarrayDictionary *dictionaryB[kNDict];
1537 AliTRDdigitsManager *mergeSDigitsManager = 0x0;
1538 // Get the first s-digits
1539 fSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->First();
1540 if (!fSDigitsManager) {
1541 AliError("No SDigits manager");
1545 // Loop through the other sets of s-digits
1546 mergeSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->After(fSDigitsManager);
1548 if (mergeSDigitsManager) {
1549 AliDebug(1,Form("Merge %d input files.",fSDigitsManagerList->GetSize()));
1552 AliDebug(1,"Only one input file.");
1557 while (mergeSDigitsManager) {
1561 // Loop through the detectors
1562 for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) {
1564 Int_t nTimeTotal = fSDigitsManager->GetDigitsParam()->GetNTimeBins(iDet);
1565 if (mergeSDigitsManager->GetDigitsParam()->GetNTimeBins(iDet) != nTimeTotal) {
1566 AliError(Form("Mismatch in the number of time bins [%d,%d] in detector %d"
1568 ,mergeSDigitsManager->GetDigitsParam()->GetNTimeBins(iDet)
1573 Int_t nRowMax = fGeo->GetPadPlane(iDet)->GetNrows();
1574 Int_t nColMax = fGeo->GetPadPlane(iDet)->GetNcols();
1576 // Loop through the pixels of one detector and add the signals
1577 digitsA = (AliTRDarraySignal *) fSDigitsManager->GetSDigits(iDet);
1578 digitsB = (AliTRDarraySignal *) mergeSDigitsManager->GetSDigits(iDet);
1580 if (!digitsA->HasData()) continue;
1582 if (!digitsB->HasData()) continue;
1584 for (iDict = 0; iDict < kNDict; iDict++) {
1585 dictionaryA[iDict] = (AliTRDarrayDictionary *) fSDigitsManager->GetDictionary(iDet,iDict);
1586 dictionaryB[iDict] = (AliTRDarrayDictionary *) mergeSDigitsManager->GetDictionary(iDet,iDict);
1587 dictionaryA[iDict]->Expand();
1588 dictionaryB[iDict]->Expand();
1591 // Merge only detectors that contain a signal
1592 Bool_t doMerge = kTRUE;
1593 if (fMergeSignalOnly) {
1594 if (digitsA->GetOverThreshold(0) == 0) {
1601 AliDebug(1,Form("Merge detector %d of input no.%d",iDet,iMerge+1));
1603 for (Int_t iRow = 0; iRow < nRowMax; iRow++ ) {
1604 for (Int_t iCol = 0; iCol < nColMax; iCol++ ) {
1605 for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) {
1607 // Add the amplitudes of the summable digits
1608 Float_t ampA = digitsA->GetData(iRow,iCol,iTime);
1609 Float_t ampB = digitsB->GetData(iRow,iCol,iTime);
1611 digitsA->SetData(iRow,iCol,iTime,ampA);
1613 // Add the mask to the track id if defined.
1614 for (iDict = 0; iDict < kNDict; iDict++) {
1615 Int_t trackB = dictionaryB[iDict]->GetData(iRow,iCol,iTime);
1616 if ((fMasks) && (trackB > 0)) {
1617 for (jDict = 0; jDict < kNDict; jDict++) {
1618 Int_t trackA = dictionaryA[iDict]->GetData(iRow,iCol,iTime);
1620 trackA = trackB + fMasks[iMerge];
1621 dictionaryA[iDict]->SetData(iRow,iCol,iTime,trackA);
1622 } // if: track A == 0
1624 } // if: fMasks and trackB > 0
1633 mergeSDigitsManager->RemoveDigits(iDet);
1634 mergeSDigitsManager->RemoveDictionaries(iDet);
1637 digitsA->Compress(0);
1638 for (iDict = 0; iDict < kNDict; iDict++) {
1639 dictionaryA[iDict]->Compress();
1645 // The next set of s-digits
1646 mergeSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->After(mergeSDigitsManager);
1648 } // while: mergeDigitsManagers
1654 //_____________________________________________________________________________
1655 Bool_t AliTRDdigitizer::ConvertSDigits()
1658 // Converts s-digits to normal digits
1661 AliTRDarraySignal *digitsIn = 0x0;
1663 if (!fSDigitsManager->HasSDigits()) {
1664 AliError("No s-digits in digits manager");
1668 // Loop through the detectors
1669 for (Int_t det = 0; det < AliTRDgeometry::Ndet(); det++) {
1671 // Get the merged s-digits (signals)
1672 digitsIn = (AliTRDarraySignal *) fSDigitsManager->GetSDigits(det);
1673 if (!digitsIn->HasData()) {
1674 AliDebug(2,Form("No digits for det=%d",det));
1678 // Convert the merged sdigits to digits
1679 if (!Signal2ADC(det,digitsIn)) {
1683 // Copy the dictionary information to the output array
1684 if (!CopyDictionary(det)) {
1689 fSDigitsManager->RemoveDigits(det);
1690 fSDigitsManager->RemoveDictionaries(det);
1692 // Run digital processing
1693 RunDigitalProcessing(det);
1695 // Compress the arrays
1696 CompressOutputArrays(det);
1698 } // for: detector numbers
1700 if (AliDataLoader *trklLoader = AliRunLoader::Instance()->GetLoader("TRDLoader")->GetDataLoader("tracklets")) {
1701 if (trklLoader->Tree())
1702 trklLoader->WriteData("OVERWRITE");
1705 // Save the values for the raw data headers
1706 fDigitsManager->GetDigitsParam()->SetNTimeBinsAll(AliTRDSimParam::Instance()->GetNTimeBins());
1707 fDigitsManager->GetDigitsParam()->SetADCbaselineAll(AliTRDSimParam::Instance()->GetADCbaseline());
1713 //_____________________________________________________________________________
1714 Bool_t AliTRDdigitizer::CopyDictionary(Int_t det)
1717 // Copies the dictionary information from the s-digits arrays
1718 // to the output arrays
1721 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1723 AliFatal("Could not get calibration object");
1727 AliDebug(1,Form("Start copying dictionaries for detector=%d",det));
1729 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1730 AliTRDarrayDictionary *dictionaryIn[kNDict];
1731 AliTRDarrayDictionary *dictionaryOut[kNDict];
1733 Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows();
1734 Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols();
1735 Int_t nTimeTotal = AliTRDSimParam::Instance()->GetNTimeBins();
1742 for (dict = 0; dict < kNDict; dict++) {
1744 dictionaryIn[dict] = (AliTRDarrayDictionary *) fSDigitsManager->GetDictionary(det,dict);
1745 dictionaryIn[dict]->Expand();
1746 dictionaryOut[dict] = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
1747 dictionaryOut[dict]->Allocate(nRowMax,nColMax,nTimeTotal);
1749 for (row = 0; row < nRowMax; row++) {
1750 for (col = 0; col < nColMax; col++) {
1751 for (time = 0; time < nTimeTotal; time++) {
1752 Int_t track = dictionaryIn[dict]->GetData(row,col,time);
1753 dictionaryOut[dict]->SetData(row,col,time,track);
1758 } // for: dictionaries
1764 //_____________________________________________________________________________
1765 void AliTRDdigitizer::CompressOutputArrays(Int_t det)
1768 // Compress the output arrays
1771 const Int_t kNDict = AliTRDdigitsManager::kNDict;
1772 AliTRDarrayDictionary *dictionary = 0x0;
1777 AliTRDarrayADC *digits = 0x0;
1778 digits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det);
1783 AliTRDarraySignal *digits = 0x0;
1784 digits = (AliTRDarraySignal *) fDigitsManager->GetSDigits(det);
1785 digits->Compress(0);
1788 for (Int_t dict = 0; dict < kNDict; dict++) {
1789 dictionary = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
1790 dictionary->Compress();
1797 //_____________________________________________________________________________
1798 Bool_t AliTRDdigitizer::WriteDigits() const
1801 // Writes out the TRD-digits and the dictionaries
1805 fRunLoader->CdGAFile();
1807 // Store the digits and the dictionary in the tree
1808 return fDigitsManager->WriteDigits();
1812 //_____________________________________________________________________________
1813 void AliTRDdigitizer::InitOutput(Int_t iEvent)
1816 // Initializes the output branches
1822 AliError("Run Loader is NULL");
1826 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
1828 AliError("Can not get TRD loader from Run Loader");
1835 // If we produce SDigits
1836 tree = loader->TreeS();
1838 loader->MakeTree("S");
1839 tree = loader->TreeS();
1843 // If we produce Digits
1844 tree = loader->TreeD();
1846 loader->MakeTree("D");
1847 tree = loader->TreeD();
1850 fDigitsManager->SetEvent(iEvent);
1851 fDigitsManager->MakeBranch(tree);
1855 //_____________________________________________________________________________
1856 Int_t AliTRDdigitizer::Diffusion(Float_t vdrift, Double_t absdriftlength
1857 , Double_t &lRow, Double_t &lCol, Double_t &lTime)
1860 // Applies the diffusion smearing to the position of a single electron.
1861 // Depends on absolute drift length.
1864 Float_t diffL = 0.0;
1865 Float_t diffT = 0.0;
1867 if (AliTRDCommonParam::Instance()->GetDiffCoeff(diffL,diffT,vdrift)) {
1869 Float_t driftSqrt = TMath::Sqrt(absdriftlength);
1870 Float_t sigmaT = driftSqrt * diffT;
1871 Float_t sigmaL = driftSqrt * diffL;
1872 lRow = gRandom->Gaus(lRow ,sigmaT);
1873 lCol = gRandom->Gaus(lCol ,sigmaT * GetLorentzFactor(vdrift));
1874 lTime = gRandom->Gaus(lTime,sigmaL * GetLorentzFactor(vdrift));
1887 //_____________________________________________________________________________
1888 Float_t AliTRDdigitizer::GetLorentzFactor(Float_t vd)
1891 // Returns the Lorentz factor
1894 Double_t omegaTau = AliTRDCommonParam::Instance()->GetOmegaTau(vd);
1895 Double_t lorentzFactor = 1.0;
1896 if (AliTRDCommonParam::Instance()->ExBOn()) {
1897 lorentzFactor = 1.0 / (1.0 + omegaTau*omegaTau);
1900 return lorentzFactor;
1904 //_____________________________________________________________________________
1905 Int_t AliTRDdigitizer::ExB(Float_t vdrift, Double_t driftlength, Double_t &lCol)
1908 // Applies E x B effects to the position of a single electron.
1909 // Depends on signed drift length.
1913 + AliTRDCommonParam::Instance()->GetOmegaTau(vdrift)
1920 //_____________________________________________________________________________
1921 void AliTRDdigitizer::RunDigitalProcessing(Int_t det)
1924 // Run the digital processing in the TRAP
1927 AliTRDfeeParam *feeParam = AliTRDfeeParam::Instance();
1929 //Create and initialize the mcm object
1930 AliTRDmcmSim* mcmfast = new AliTRDmcmSim();
1932 AliTRDarrayADC *digits = fDigitsManager->GetDigits(det);
1936 //Call the methods in the mcm class using the temporary array as input
1937 for(Int_t rob = 0; rob < digits->GetNrow() / 2; rob++)
1939 for(Int_t mcm = 0; mcm < 16; mcm++)
1941 mcmfast->Init(det, rob, mcm);
1942 mcmfast->SetDataByPad(digits, fDigitsManager);
1944 if (feeParam->GetTracklet()) {
1945 mcmfast->Tracklet();
1946 mcmfast->StoreTracklets();
1948 mcmfast->ZSMapping();
1949 mcmfast->WriteData(digits);