+ return kTRUE;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDdigitizer::ConvertHits(Int_t det
+ , const Float_t * const hits
+ , Int_t nhit
+ , AliTRDarraySignal *signals)
+{
+ //
+ // Converts the detectorwise sorted hits to detector signals
+ //
+
+ AliDebug(1,Form("Start converting hits for detector=%d (nhits=%d)",det,nhit));
+
+ // Number of pads included in the pad response
+ const Int_t kNpad = 3;
+ // Number of track dictionary arrays
+ const Int_t kNdict = AliTRDdigitsManager::kNDict;
+ // Size of the hit vector
+ const Int_t kNhit = 6;
+
+ // Width of the amplification region
+ const Float_t kAmWidth = AliTRDgeometry::AmThick();
+ // Width of the drift region
+ const Float_t kDrWidth = AliTRDgeometry::DrThick();
+ // Drift + amplification region
+ const Float_t kDrMin = - 0.5 * kAmWidth;
+ const Float_t kDrMax = kDrWidth + 0.5 * kAmWidth;
+
+ Int_t iPad = 0;
+ Int_t dict = 0;
+ Int_t timeBinTRFend = 1;
+
+ Double_t pos[3];
+ Double_t loc[3];
+ Double_t padSignal[kNpad];
+ Double_t signalOld[kNpad];
+
+ AliTRDarrayDictionary *dictionary[kNdict];
+
+ AliTRDSimParam *simParam = AliTRDSimParam::Instance();
+ AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance();
+ AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
+
+ if (!commonParam) {
+ AliFatal("Could not get common parameterss");
+ return kFALSE;
+ }
+ if (!simParam) {
+ AliFatal("Could not get simulation parameters");
+ return kFALSE;
+ }
+ if (!calibration) {
+ AliFatal("Could not get calibration object");
+ return kFALSE;
+ }
+
+ // Get the detector wise calibration objects
+ AliTRDCalROC *calVdriftROC = 0;
+ Float_t calVdriftDetValue = 0.0;
+ const AliTRDCalDet *calVdriftDet = calibration->GetVdriftDet();
+ AliTRDCalROC *calT0ROC = 0;
+ Float_t calT0DetValue = 0.0;
+ const AliTRDCalDet *calT0Det = calibration->GetT0Det();
+ Double_t calExBDetValue = 0.0;
+ const AliTRDCalDet *calExBDet = calibration->GetExBDet();
+
+ if (simParam->TRFOn()) {
+ timeBinTRFend = ((Int_t) (simParam->GetTRFhi()
+ * commonParam->GetSamplingFrequency())) - 1;
+ }
+
+ Int_t nTimeTotal = fDigitsManager->GetDigitsParam()->GetNTimeBins(det);
+ Float_t samplingRate = commonParam->GetSamplingFrequency();
+ Float_t elAttachProp = simParam->GetElAttachProp() / 100.0;
+
+ AliTRDpadPlane *padPlane = fGeo->GetPadPlane(det);
+ Int_t layer = fGeo->GetLayer(det); //update
+ Float_t row0 = padPlane->GetRow0ROC();
+ Int_t nRowMax = padPlane->GetNrows();
+ Int_t nColMax = padPlane->GetNcols();
+
+ // Create a new array for the signals
+ signals->Allocate(nRowMax,nColMax,nTimeTotal);
+
+ // Create a new array for the dictionary
+ for (dict = 0; dict < kNdict; dict++) {
+ dictionary[dict] = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(det,dict);
+ dictionary[dict]->Allocate(nRowMax,nColMax,nTimeTotal);
+ }
+
+ // Loop through the hits in this detector
+ for (Int_t hit = 0; hit < nhit; hit++) {
+
+ pos[0] = hits[hit*kNhit+0];
+ pos[1] = hits[hit*kNhit+1];
+ pos[2] = hits[hit*kNhit+2];
+ Float_t q = hits[hit*kNhit+3];
+ Float_t hittime = hits[hit*kNhit+5];
+ Int_t track = ((Int_t) hits[hit*kNhit+4]);
+
+ Int_t inDrift = 1;
+
+ // Find the current volume with the geo manager
+ gGeoManager->SetCurrentPoint(pos);
+ gGeoManager->FindNode();
+ if (strstr(gGeoManager->GetPath(),"/UK")) {
+ inDrift = 0;
+ }
+
+ // Get the calibration objects
+ calVdriftROC = calibration->GetVdriftROC(det);
+ calVdriftDetValue = calVdriftDet->GetValue(det);
+ calT0ROC = calibration->GetT0ROC(det);
+ calT0DetValue = calT0Det->GetValue(det);
+ calExBDetValue = calExBDet->GetValue(det);
+
+ // Go to the local coordinate system:
+ // loc[0] - col direction in amplification or driftvolume
+ // loc[1] - row direction in amplification or driftvolume
+ // loc[2] - time direction in amplification or driftvolume
+ gGeoManager->MasterToLocal(pos,loc);
+ if (inDrift) {
+ // Relative to middle of amplification region
+ loc[2] = loc[2] - kDrWidth/2.0 - kAmWidth/2.0;
+ }
+
+ // The driftlength [cm] (w/o diffusion yet !).
+ // It is negative if the hit is between pad plane and anode wires.
+ Double_t driftlength = -1.0 * loc[2];
+
+ // Stupid patch to take care of TR photons that are absorbed
+ // outside the chamber volume. A real fix would actually need
+ // a more clever implementation of the TR hit generation
+ if (q < 0.0) {
+ if ((loc[1] < padPlane->GetRowEndROC()) ||
+ (loc[1] > padPlane->GetRow0ROC())) {
+ continue;
+ }
+ if ((driftlength < kDrMin) ||
+ (driftlength > kDrMax)) {
+ continue;