]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDdigitizer.cxx
Record changes.
[u/mrichter/AliRoot.git] / TRD / AliTRDdigitizer.cxx
index 16d534f178f57d0b6930087a96238ccef424fbe7..9b76be230582c1b0a5c9e601729b0b2bbf278889 100644 (file)
@@ -52,6 +52,7 @@
 #include <TF1.h>
 #include <TList.h>
 #include <TTask.h>
+#include <TGeoManager.h>
 
 #include "AliRun.h"
 #include "AliRunLoader.h"
@@ -61,6 +62,7 @@
 #include "AliRunDigitizer.h"
 #include "AliRunLoader.h"
 #include "AliLoader.h"
+#include "AliLog.h"
 
 #include "AliTRD.h"
 #include "AliTRDhit.h"
@@ -70,7 +72,6 @@
 #include "AliTRDsegmentArray.h"
 #include "AliTRDdigitsManager.h"
 #include "AliTRDgeometry.h"
-#include "AliTRDparameter.h"
 #include "AliTRDpadPlane.h"
 #include "AliTRDcalibDB.h"
 #include "AliTRDSimParam.h"
@@ -91,7 +92,6 @@ AliTRDdigitizer::AliTRDdigitizer()
   fSDigitsManagerList = 0;
   fTRD                = 0;
   fGeo                = 0;
-  fPar          = 0;
   fEvent              = 0;
   fMasks              = 0;
   fCompress           = kTRUE;
@@ -99,21 +99,21 @@ AliTRDdigitizer::AliTRDdigitizer()
   fSDigits            = kFALSE;
   fSDigitsScale       = 0.0;
   fMergeSignalOnly    = kFALSE;
-  fSimpleSim          = kFALSE;
-  fSimpleDet          = 0;
+  fFixedGeometry      = kFALSE;
  
-  fTimeStructInfo.fLastVdrift = 0;
-  fTimeStructInfo.fTimeStruct1        = 0;
-  fTimeStructInfo.fTimeStruct2        = 0;
-  fTimeStructInfo.fVDlo = 0;
-  fTimeStructInfo.fVDhi = 0;
+  fTimeStructInfo.fLastVdrift   = 0;
+  fTimeStructInfo.fTimeStruct1  = 0;
+  fTimeStructInfo.fTimeStruct2  = 0;
+  fTimeStructInfo.fVDlo         = 0;
+  fTimeStructInfo.fVDhi         = 0;
   
-  fDiffusionInfo.fLastVdrift = 0;
-  fDiffusionInfo.fDiffusionT         = 0.0;
-  fDiffusionInfo.fDiffusionL         = 0.0;
+  fDiffusionInfo.fLastVdrift    = 0;
+  fDiffusionInfo.fDiffusionT    = 0.0;
+  fDiffusionInfo.fDiffusionL    = 0.0;
   fDiffusionInfo.fLorentzFactor = 0.0;
   
   Init();
+
 }
 
 //_____________________________________________________________________________
@@ -125,6 +125,7 @@ AliTRDdigitizer::AliTRDdigitizer(const Text_t *name, const Text_t *title)
   //
 
   Init();
+
 }
 
 //_____________________________________________________________________________
@@ -137,6 +138,7 @@ AliTRDdigitizer::AliTRDdigitizer(AliRunDigitizer *manager
   //
 
   Init();
+
 }
 
 //_____________________________________________________________________________
@@ -148,11 +150,16 @@ AliTRDdigitizer::AliTRDdigitizer(AliRunDigitizer *manager)
   //
 
   Init();
+
 }
 
 //_____________________________________________________________________________
 Bool_t AliTRDdigitizer::Init()
 {
+  //
+  // Initialize the digitizer with default values
+  //
+
   fRunLoader          = 0;
 
   //NewIO: These data members probably are not needed anymore
@@ -161,9 +168,8 @@ Bool_t AliTRDdigitizer::Init()
   fSDigitsManagerList = 0;
   fTRD                = 0;
   fGeo                = 0;
-  fPar          = 0;
-  
   //End NewIO comment
+
   fEvent              = 0;
   fMasks              = 0;
   fCompress           = kTRUE;
@@ -171,21 +177,21 @@ Bool_t AliTRDdigitizer::Init()
   fSDigits            = kFALSE;
   fSDigitsScale       = 100.; // For the summable digits
   fMergeSignalOnly    = kFALSE;
-  fSimpleSim          = kFALSE;
-  fSimpleDet          = 0;
+  fFixedGeometry      = kFALSE;
  
-  fTimeStructInfo.fLastVdrift = -1;
-  fTimeStructInfo.fTimeStruct1        = 0;
-  fTimeStructInfo.fTimeStruct2        = 0;
-  fTimeStructInfo.fVDlo = 0;
-  fTimeStructInfo.fVDhi = 0;
+  fTimeStructInfo.fLastVdrift   = -1;
+  fTimeStructInfo.fTimeStruct1  = 0;
+  fTimeStructInfo.fTimeStruct2  = 0;
+  fTimeStructInfo.fVDlo         = 0;
+  fTimeStructInfo.fVDhi         = 0;
   
-  fDiffusionInfo.fLastVdrift = -1;
-  fDiffusionInfo.fDiffusionT         = 0.0;
-  fDiffusionInfo.fDiffusionL         = 0.0;
+  fDiffusionInfo.fLastVdrift    = -1;
+  fDiffusionInfo.fDiffusionT    = 0.0;
+  fDiffusionInfo.fDiffusionL    = 0.0;
   fDiffusionInfo.fLorentzFactor = 0.0;
 
   return AliDigitizer::Init();
+
 }
 
 //_____________________________________________________________________________
@@ -235,6 +241,7 @@ AliTRDdigitizer::~AliTRDdigitizer()
     delete [] fTimeStructInfo.fTimeStruct2;
     fTimeStructInfo.fTimeStruct2 = 0;
   }
+
 }
 
 //_____________________________________________________________________________
@@ -262,7 +269,6 @@ void AliTRDdigitizer::Copy(TObject &d) const
   ((AliTRDdigitizer &) d).fSDigitsManagerList = 0;
   ((AliTRDdigitizer &) d).fTRD                = 0;
   ((AliTRDdigitizer &) d).fGeo                = 0;
-  ((AliTRDdigitizer &) d).fPar                = 0;
   ((AliTRDdigitizer &) d).fEvent              = 0;
   ((AliTRDdigitizer &) d).fMasks              = 0;
   ((AliTRDdigitizer &) d).fCompress           = fCompress;
@@ -270,14 +276,14 @@ void AliTRDdigitizer::Copy(TObject &d) const
   ((AliTRDdigitizer &) d).fSDigits            = fSDigits;
   ((AliTRDdigitizer &) d).fSDigitsScale       = fSDigitsScale;
   ((AliTRDdigitizer &) d).fMergeSignalOnly    = fMergeSignalOnly;
-  ((AliTRDdigitizer &) d).fSimpleSim          = fSimpleSim;
-  ((AliTRDdigitizer &) d).fSimpleDet          = fSimpleDet;
+  ((AliTRDdigitizer &) d).fFixedGeometry      = fFixedGeometry;
                                        
   AliTRDdigitizer& target = (AliTRDdigitizer &) d;
   
   target.fDiffusionInfo = fDiffusionInfo;
   
-  // do not copy timestructs, just invalidate lastvdrift. Next time they are requested, they get recalculated
+  // Do not copy timestructs, just invalidate lastvdrift.
+  // Next time they are requested, they get recalculated
   if (target.fTimeStructInfo.fTimeStruct1)
   {
     delete[] target.fTimeStructInfo.fTimeStruct1;
@@ -287,9 +293,9 @@ void AliTRDdigitizer::Copy(TObject &d) const
   {
     delete[] target.fTimeStructInfo.fTimeStruct2;
     target.fTimeStructInfo.fTimeStruct2 = 0;
-  }
-  
+  }  
   target.fTimeStructInfo.fLastVdrift = -1;
+
 }
 
 //_____________________________________________________________________________
@@ -430,7 +436,6 @@ void AliTRDdigitizer::Exec(Option_t* option)
 
   //Write parameters
   orl->CdGAFile();
-  if (!gFile->Get("TRDparameter")) GetParameter()->Write();
 
   if (fDebug > 0) {
     printf("<AliTRDdigitizer::Exec> ");
@@ -447,9 +452,8 @@ Bool_t AliTRDdigitizer::Open(const Char_t *file, Int_t nEvent)
   //
   // Opens a ROOT-file with TRD-hits and reads in the hit-tree
   //
-
   // Connect the AliRoot file containing Geometry, Kine, and Hits
-  
+  //  
 
   TString evfoldname = AliConfig::GetDefaultEventFolderName();
   fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
@@ -556,7 +560,8 @@ Bool_t AliTRDdigitizer::InitDetector()
   // The list for the input s-digits manager to be merged
   if (fSDigitsManagerList) {
     fSDigitsManagerList->Delete();
-  } else {
+  } 
+  else {
     fSDigitsManagerList = new TList();
   }
 
@@ -599,7 +604,7 @@ Bool_t AliTRDdigitizer::MakeDigits()
 
   // Half the width of the amplification region
   const Float_t kAmWidth = AliTRDgeometry::AmThick() / 2.;
-  // Width of the drit region
+  // Width of the drift region
   const Float_t kDrWidth = AliTRDgeometry::DrThick();
   
   Int_t    iRow, iCol, iTime, iPad;
@@ -625,26 +630,18 @@ Bool_t AliTRDdigitizer::MakeDigits()
 
   AliTRDpadPlane   *padPlane = 0;
 
-  // Create a default parameter class if none is defined
-  if (!fPar) {
-    fPar = new AliTRDparameter("TRDparameter","Standard TRD parameter");
-    if (fDebug > 0) {
-      printf("<AliTRDdigitizer::MakeDigits> ");
-      printf("Create the default parameter object\n");
-    }
-  }
-  
+  if (!gGeoManager) AliFatal("No geometry!");
+
+
   AliTRDSimParam* simParam = AliTRDSimParam::Instance();
-  if (!simParam)
-  {
+  if (!simParam) {
     printf("<AliTRDdigitizer::MakeDigits> ");
     printf("Could not get simulation params\n");
     return kFALSE;
   }
   
   AliTRDCommonParam* commonParam = AliTRDCommonParam::Instance();
-  if (!commonParam)
-  {
+  if (!commonParam) {
     printf("<AliTRDdigitizer::MakeDigits> ");
     printf("Could not get common params\n");
     return kFALSE;
@@ -656,13 +653,18 @@ Bool_t AliTRDdigitizer::MakeDigits()
                                              ,AliTRDgeometry::Ndet());
 
   AliTRDcalibDB* calibration = AliTRDcalibDB::Instance();
-  if (!calibration)
-  {
+  if (!calibration) {
     printf("<AliTRDdigitizer::MakeDigits> ");
     printf("Could not get calibration object\n");
     return kFALSE;
   }
 
+  if (!gGeoManager) {
+    printf("<AliTRDdigitizer::MakeDigits> ");
+    printf("No TGeoManager available. Switch to fixed geometry.\n");
+    fFixedGeometry = kTRUE;
+  }
+
   if (simParam->TRFOn()) {
     timeBinTRFend = ((Int_t) ( simParam->GetTRFhi() * calibration->GetSamplingFrequency())) - 1;
     if (fDebug > 0) {
@@ -687,22 +689,18 @@ Bool_t AliTRDdigitizer::MakeDigits()
   AliLoader* gimme = fRunLoader->GetLoader("TRDLoader");
   if (!gimme->TreeH()) gimme->LoadHits();
   TTree* hitTree = gimme->TreeH();
-  if (hitTree == 0x0)
-    {
+  if (hitTree == 0x0) {
       Error("MakeDigits","Can not get TreeH");
       return kFALSE;
-    }
+  }
   fTRD->SetTreeAddress();
   
   // Get the number of entries in the hit tree
   // (Number of primary particles creating a hit somewhere)
-  Int_t nTrack = 1;
-  if (!fSimpleSim) {
-    nTrack = (Int_t) hitTree->GetEntries();
-    if (fDebug > 0) {
-      printf("<AliTRDdigitizer::MakeDigits> ");
-      printf("Found %d primary particles\n",nTrack);
-    } 
+  Int_t nTrack = (Int_t) hitTree->GetEntries();
+  if (fDebug > 0) {
+    printf("<AliTRDdigitizer::MakeDigits> ");
+    printf("Found %d primary particles\n",nTrack);
   }
 
   Int_t detectorOld = -1;
@@ -721,16 +719,14 @@ Bool_t AliTRDdigitizer::MakeDigits()
     }
   }
   
-  Int_t nTimeTotal  = calibration->GetNumberOfTimeBins();
-  Float_t samplingRate  = calibration->GetSamplingFrequency();
+  Int_t   nTimeTotal   = calibration->GetNumberOfTimeBins();
+  Float_t samplingRate = calibration->GetSamplingFrequency();
 
   // Loop through all entries in the tree
   for (Int_t iTrack = 0; iTrack < nTrack; iTrack++) {
 
-    if (!fSimpleSim) {   
-      gAlice->ResetHits();
-      nBytes += hitTree->GetEvent(iTrack);
-    }
+    gAlice->ResetHits();
+    nBytes += hitTree->GetEvent(iTrack);
 
     // Loop through the TRD hits
     Int_t iHit = 0;
@@ -757,6 +753,15 @@ Bool_t AliTRDdigitizer::MakeDigits()
       Int_t   nRowMax       = padPlane->GetNrows();
       Int_t   nColMax       = padPlane->GetNcols();
 
+      Int_t   inDrift       = 1;
+      if (!fFixedGeometry) {
+        gGeoManager->SetCurrentPoint(pos);
+        gGeoManager->FindNode();
+        if (strstr(gGeoManager->GetPath(),"/UK")) {
+          inDrift = 0;
+       }
+      }
+
       if (fDebug > 1) {
         printf("Analyze hit no. %d ",iHit);
         printf("-----------------------------------------------------------\n");
@@ -806,14 +811,6 @@ Bool_t AliTRDdigitizer::MakeDigits()
            }
             signals->Allocate(nRowMax,nColMax,nTimeTotal);
          }
-          else if (fSimpleSim) {
-            // Clear an old one for the simple simulation
-            if (fDebug > 1) {
-              printf("<AliTRDdigitizer::MakeDigits> ");
-              printf("Clear a old container ... ");
-            }
-            signals->Clear();
-          }
           else {
            // Expand an existing one
             if (fCompress) {
@@ -825,30 +822,40 @@ Bool_t AliTRDdigitizer::MakeDigits()
            }
          }
          // The same for the dictionary
-          if (!fSimpleSim) {       
-            for (iDict = 0; iDict < kNDict; iDict++) {       
-              dictionary[iDict] = fDigitsManager->GetDictionary(detector,iDict);
-              if (dictionary[iDict]->GetNtime() == 0) {
-                dictionary[iDict]->Allocate(nRowMax,nColMax,nTimeTotal);
-             }
-              else {
-                if (fCompress) dictionary[iDict]->Expand();
-             }
+          for (iDict = 0; iDict < kNDict; iDict++) {       
+            dictionary[iDict] = fDigitsManager->GetDictionary(detector,iDict);
+            if (dictionary[iDict]->GetNtime() == 0) {
+              dictionary[iDict]->Allocate(nRowMax,nColMax,nTimeTotal);
            }
+            else {
+              if (fCompress) dictionary[iDict]->Expand();
+            }
           }      
           if (fDebug > 1) printf("done\n");
           detectorOld = detector;
         }
 
-        // Rotate the sectors on top of each other
-        if (fSimpleSim) {
-          rot[0] = pos[0];
-          rot[1] = pos[1];
-          rot[2] = pos[2];
-        }
-        else {
+        if (fFixedGeometry) {
+          // Rotate the sectors on top of each other       
           fGeo->Rotate(detector,pos,rot);
        }
+        else {
+         // Use the geoManager
+          Double_t aaa[3];
+          gGeoManager->MasterToLocal(pos,aaa);
+          if (inDrift) {
+            aaa[2] = time0 - (kDrWidth / 2.0 + kAmWidth) + aaa[2];
+         } 
+          else {
+            aaa[2] = time0 + aaa[2];
+         }
+          aaa[1] = row0 + padPlane->GetLengthRim() + fGeo->RpadW() 
+                 - 0.5 * fGeo->GetChamberLength(plane,chamber) 
+                + aaa[1];
+          rot[0] = aaa[2];
+          rot[1] = aaa[0];
+          rot[2] = aaa[1];
+       }
 
         // The driftlength. It is negative if the hit is between pad plane and anode wires.
         Double_t driftlength = time0 - rot[0];
@@ -921,17 +928,17 @@ Bool_t AliTRDdigitizer::MakeDigits()
 
           // The electron position after diffusion and ExB in pad coordinates.
           // The pad row (z-direction)
-          rowE      = padPlane->GetPadRowNumber(xyz[2]);
+          rowE       = padPlane->GetPadRowNumber(xyz[2]);
           if (rowE < 0) continue;
-          rowOffset = padPlane->GetPadRowOffset(rowE,xyz[2]);
+          rowOffset  = padPlane->GetPadRowOffset(rowE,xyz[2]);
 
           // The pad column (rphi-direction)
-          offsetTilt     = padPlane->GetTiltOffset(rowOffset);   // MI change
-          colE      = padPlane->GetPadColNumber(xyz[1]+offsetTilt,rowOffset);
+          offsetTilt = padPlane->GetTiltOffset(rowOffset);   // MI change
+          colE       = padPlane->GetPadColNumber(xyz[1]+offsetTilt,rowOffset);
           if (colE < 0) continue;         
-          colOffset = padPlane->GetPadColOffset(colE,xyz[1]+offsetTilt);
+          colOffset  = padPlane->GetPadColOffset(colE,xyz[1]+offsetTilt);
          
-          // also re-retrieve drift velocity because col and row may have changed
+          // Also re-retrieve drift velocity because col and row may have changed
           driftvelocity = calibration->GetVdrift(detector, colE, rowE);
           Float_t t0 = calibration->GetT0(detector, colE, rowE);
           
@@ -960,12 +967,13 @@ Bool_t AliTRDdigitizer::MakeDigits()
           Int_t signal = (Int_t) (-(simParam->GetGasGain()) * TMath::Log(ggRndm));
 
           // Apply the pad response 
-          if (commonParam->PRFOn()) {
+          if (simParam->PRFOn()) {
            // The distance of the electron to the center of the pad 
            // in units of pad width
             //Double_t dist = - colOffset / padPlane->GetColSize(colE);
-            Double_t dist = (0.5 * padPlane->GetColSize(colE) - colOffset) 
+           Double_t dist = (colOffset - 0.5*padPlane->GetColSize(colE))
                           / padPlane->GetColSize(colE);
+
             if (!(calibration->PadResponse(signal,dist,plane,padSignal))) continue;
          }
          else {
@@ -976,6 +984,10 @@ Bool_t AliTRDdigitizer::MakeDigits()
 
           // The time bin (always positive), with t0 correction
           Double_t timeBinIdeal = drifttime * samplingRate + t0;
+         // Protection according to MI
+          if (TMath::Abs(timeBinIdeal) > 2*nTimeTotal) {
+            timeBinIdeal = 2 * nTimeTotal;
+         }
           Int_t    timeBinTruncated = (Int_t) timeBinIdeal;
           // The distance of the position to the middle of the timebin
           Double_t timeOffset = ((Float_t) timeBinTruncated + 0.5 - timeBinIdeal) / samplingRate;
@@ -1022,7 +1034,7 @@ Bool_t AliTRDdigitizer::MakeDigits()
 
               // Store the track index in the dictionary
               // Note: We store index+1 in order to allow the array to be compressed
-              if ((signalOld[iPad] > 0) && (!fSimpleSim)) { 
+              if (signalOld[iPad] > 0) { 
                 for (iDict = 0; iDict < kNDict; iDict++) {
                   Int_t oldTrack = dictionary[iDict]->GetDataUnchecked(rowE
                                                                       ,colPos
@@ -1065,10 +1077,6 @@ Bool_t AliTRDdigitizer::MakeDigits()
   // Loop through all chambers to finalize the digits
   Int_t iDetBeg = 0;
   Int_t iDetEnd = AliTRDgeometry::Ndet();
-  if (fSimpleSim) {
-    iDetBeg = fSimpleDet;
-    iDetEnd = iDetBeg + 1;
-  }
   for (Int_t iDet = iDetBeg; iDet < iDetEnd; iDet++) {
 
     Int_t plane       = fGeo->GetPlane(iDet);
@@ -1091,9 +1099,6 @@ Bool_t AliTRDdigitizer::MakeDigits()
     if (digits->GetNtime() == 0) {
       digits->Allocate(nRowMax,nColMax,nTimeTotal);
     }
-    else if (fSimpleSim) {
-      digits->Clear();
-    }
  
     // Get the signal container
     signals = (AliTRDdataArrayF *) signalsArray->At(iDet);
@@ -1106,12 +1111,10 @@ Bool_t AliTRDdigitizer::MakeDigits()
       if (fCompress) signals->Expand();
     }
     // Create the missing dictionary containers
-    if (!fSimpleSim) {    
-      for (iDict = 0; iDict < kNDict; iDict++) {       
-        dictionary[iDict] = fDigitsManager->GetDictionary(iDet,iDict);
-        if (dictionary[iDict]->GetNtime() == 0) {
-          dictionary[iDict]->Allocate(nRowMax,nColMax,nTimeTotal);
-        }
+    for (iDict = 0; iDict < kNDict; iDict++) {       
+      dictionary[iDict] = fDigitsManager->GetDictionary(iDet,iDict);
+      if (dictionary[iDict]->GetNtime() == 0) {
+        dictionary[iDict]->Allocate(nRowMax,nColMax,nTimeTotal);
       } 
     }
 
@@ -1142,11 +1145,21 @@ Bool_t AliTRDdigitizer::MakeDigits()
 
             for (iTime = 0; iTime < nTimeTotal; iTime++) {         
               Float_t signalAmp = signals->GetDataUnchecked(iRow,iCol,iTime);
+
               // Pad and time coupling
               signalAmp *= coupling;
+
+              Float_t padgain = calibration->GetGainFactor(iDet, iCol, iRow);
+              if (padgain<=0) {
+                TString error;
+                error.Form("Not a valid gain %f, %d %d %d\n", padgain, iDet, iCol, iRow);
+                AliError(error);
+              }
+             signalAmp *= padgain;
+
               // Add the noise, starting from minus ADC baseline in electrons
               Double_t baselineEl = simParam->GetADCbaseline() * (simParam->GetADCinRange()
-                                                           / simParam->GetADCoutRange()) 
+                                                           / simParam->GetADCoutRange())
                                                            / convert;
               signalAmp  = TMath::Max((Double_t) gRandom->Gaus(signalAmp,simParam->GetNoise())
                                      ,-baselineEl);
@@ -1155,25 +1168,21 @@ Bool_t AliTRDdigitizer::MakeDigits()
               // Add ADC baseline in mV
               signalAmp += simParam->GetADCbaseline() * (simParam->GetADCinRange()
                                                    / simParam->GetADCoutRange());
-             // Convert to ADC counts. Set the overflow-bit fADCoutRange if the 
+             // Convert to ADC counts. Set the overflow-bit fADCoutRange if the
              // signal is larger than fADCinRange
               Int_t adc  = 0;
               if (signalAmp >= simParam->GetADCinRange()) {
                 adc = ((Int_t) simParam->GetADCoutRange());
              }
               else {
-                adc = ((Int_t) (signalAmp * (simParam->GetADCoutRange() 
-                                           / simParam->GetADCinRange())));
+                adc = TMath::Nint(signalAmp * (simParam->GetADCoutRange()
+                                           / simParam->GetADCinRange()));
              }
+
               inADC[iTime]  = adc;
               outADC[iTime] = adc;
            }
 
-           // Apply the tail cancelation via the digital filter
-            if (simParam->TCOn()) {
-              DeConvExp(inADC,outADC,nTimeTotal,simParam->GetTCnexp());
-           }
-
             for (iTime = 0; iTime < nTimeTotal; iTime++) {   
               // Store the amplitude of the digit if above threshold
               if (outADC[iTime] > simParam->GetADCthreshold()) {
@@ -1194,28 +1203,25 @@ Bool_t AliTRDdigitizer::MakeDigits()
     }
 
     // Compress the arrays
-    if (!fSimpleSim) {  
-      digits->Compress(1,0);
-      for (iDict = 0; iDict < kNDict; iDict++) {
-        dictionary[iDict]->Compress(1,0);
-      }
+    digits->Compress(1,0);
+    for (iDict = 0; iDict < kNDict; iDict++) {
+      dictionary[iDict]->Compress(1,0);
+    }
 
-      totalSizeDigits += digits->GetSize();
-      totalSizeDict0  += dictionary[0]->GetSize();
-      totalSizeDict1  += dictionary[1]->GetSize();
-      totalSizeDict2  += dictionary[2]->GetSize();
-
-      Float_t nPixel = nRowMax * nColMax * nTimeTotal;
-      if (fDebug > 0) {
-        printf("<AliTRDdigitizer::MakeDigits> ");
-        printf("Found %d digits in detector %d (%3.0f).\n"
-              ,nDigits,iDet
-              ,100.0 * ((Float_t) nDigits) / nPixel);
-      } 
+    totalSizeDigits += digits->GetSize();
+    totalSizeDict0  += dictionary[0]->GetSize();
+    totalSizeDict1  += dictionary[1]->GetSize();
+    totalSizeDict2  += dictionary[2]->GetSize();
 
-      if (fCompress) signals->Compress(1,0);
+    Float_t nPixel = nRowMax * nColMax * nTimeTotal;
+    if (fDebug > 0) {
+      printf("<AliTRDdigitizer::MakeDigits> ");
+      printf("Found %d digits in detector %d (%3.0f).\n"
+            ,nDigits,iDet
+            ,100.0 * ((Float_t) nDigits) / nPixel);
+    } 
 
-    }
+    if (fCompress) signals->Compress(1,0);
 
     delete [] inADC;
     delete [] outADC;
@@ -1230,13 +1236,11 @@ Bool_t AliTRDdigitizer::MakeDigits()
   if (fDebug > 0) {
     printf("<AliTRDdigitizer::MakeDigits> ");
     printf("Total number of analyzed hits = %d\n",countHits);
-    if (!fSimpleSim) {    
-      printf("<AliTRDdigitizer::MakeDigits> ");
-      printf("Total digits data size = %d, %d, %d, %d\n",totalSizeDigits
-                                                        ,totalSizeDict0
-                                                        ,totalSizeDict1
-                                                        ,totalSizeDict2);        
-    }
+    printf("<AliTRDdigitizer::MakeDigits> ");
+    printf("Total digits data size = %d, %d, %d, %d\n",totalSizeDigits
+                                                      ,totalSizeDict0
+                                                      ,totalSizeDict1
+                                                      ,totalSizeDict2);        
   }
 
   return kTRUE;
@@ -1283,14 +1287,6 @@ Bool_t AliTRDdigitizer::ConvertSDigits()
   Int_t iCol;
   Int_t iTime;
 
-  if (!fPar) {    
-    fPar = new AliTRDparameter("TRDparameter","Standard parameter");
-    if (fDebug > 0) {
-      printf("<AliTRDdigitizer::ConvertSDigits> ");
-      printf("Create the default parameter object\n");
-    }
-  }
-
   AliTRDSimParam* simParam = AliTRDSimParam::Instance();
   if (!simParam)
   {
@@ -1366,9 +1362,17 @@ Bool_t AliTRDdigitizer::ConvertSDigits()
     for (iRow  = 0; iRow  <  nRowMax;   iRow++ ) {
       for (iCol  = 0; iCol  <  nColMax;   iCol++ ) {
 
-        for (iTime = 0; iTime < nTimeTotal; iTime++) {         
+        for (iTime = 0; iTime < nTimeTotal; iTime++) {
           Double_t signal = (Double_t) digitsIn->GetDataUnchecked(iRow,iCol,iTime);
           signal *= sDigitsScale;
+          Float_t padgain = calibration->GetGainFactor(iDet, iCol, iRow);
+          if (padgain<=0) {
+                  TString error;
+                  error.Form("Not a valid gain %f, %d %d %d\n", padgain, iDet, iCol, iRow);
+                  AliError(error);
+          }
+
+          signal *= padgain;
           // Pad and time coupling
           signal *= coupling;
           // Add the noise, starting from minus ADC baseline in electrons
@@ -1378,25 +1382,20 @@ Bool_t AliTRDdigitizer::ConvertSDigits()
           signal *= convert;
           // add ADC baseline in mV
           signal += adcBaseline * (adcInRange / adcOutRange);
-         // Convert to ADC counts. Set the overflow-bit adcOutRange if the 
+         // Convert to ADC counts. Set the overflow-bit adcOutRange if the
          // signal is larger than adcInRange
           Int_t adc  = 0;
           if (signal >= adcInRange) {
             adc = ((Int_t) adcOutRange);
          }
           else {
-            adc = ((Int_t) (signal * (adcOutRange / adcInRange)));
+            adc = TMath::Nint(signal * (adcOutRange / adcInRange));
          }
           inADC[iTime]  = adc;
           outADC[iTime] = adc;
        }
 
-       // Apply the tail cancelation via the digital filter
-        if (simParam->TCOn()) {
-          DeConvExp(inADC,outADC,nTimeTotal,simParam->GetTCnexp());
-       }
-
-        for (iTime = 0; iTime < nTimeTotal; iTime++) {   
+        for (iTime = 0; iTime < nTimeTotal; iTime++) {
           // Store the amplitude of the digit if above threshold
           if (outADC[iTime] > adcThreshold) {
             digitsOut->SetDataUnchecked(iRow,iCol,iTime,((Int_t) outADC[iTime]));
@@ -1442,14 +1441,6 @@ Bool_t AliTRDdigitizer::MergeSDigits()
   // Number of track dictionary arrays
   const Int_t kNDict = AliTRDdigitsManager::kNDict;
 
-  if (!fPar) {
-    fPar = new AliTRDparameter("TRDparameter","Standard parameter");
-    if (fDebug > 0) {
-      printf("<AliTRDdigitizer::MergeSDigits> ");
-      printf("Create the default parameter object\n");
-    }
-  }
-
   AliTRDSimParam* simParam = AliTRDSimParam::Instance();
   if (!simParam)
   {
@@ -1616,8 +1607,6 @@ Bool_t AliTRDdigitizer::CheckDetector(Int_t plane, Int_t chamber, Int_t sector)
   // Checks whether a detector is enabled
   //
 
-  if (fSimpleSim) return kTRUE; 
-
   if ((fTRD->GetSensChamber() >=       0) &&
       (fTRD->GetSensChamber() != chamber)) return kFALSE;
   if ((fTRD->GetSensPlane()   >=       0) &&
@@ -1648,74 +1637,12 @@ Bool_t AliTRDdigitizer::WriteDigits() const
 
   //Write parameters
   fRunLoader->CdGAFile();
-  if (!gFile->Get("TRDparameter")) GetParameter()->Write();
 
   // Store the digits and the dictionary in the tree
   return fDigitsManager->WriteDigits();
 
 }
 
-//_____________________________________________________________________________
-void AliTRDdigitizer::DeConvExp(Double_t *source, Double_t *target
-                              , Int_t n, Int_t nexp) 
-{
-  //
-  // Does the deconvolution by the digital filter.
-  //
-  // Author:        Marcus Gutfleisch, KIP Heidelberg
-  // Optimized for: New TRF from Venelin Angelov, simulated with CADENCE
-  //                Pad-ground capacitance = 25 pF
-  //                Pad-pad cross talk capacitance = 6 pF
-  //                For 10 MHz digitization, corresponding to 20 time bins
-  //                in the drift region
-  //
-
-  Double_t rates[2];
-  Double_t coefficients[2];
-  Double_t Dt = 0.100;  // time bin width [mus] for 10 MHz sampling frequence
-
-  /* initialize (coefficient = alpha, rates = lambda) */
-  
-  rates[0] = 0.7680;
-  rates[1] = 0.0995;
-
-  rates[0] = TMath::Exp(-Dt/(rates[0]));
-  rates[1] = TMath::Exp(-Dt/(rates[1]));
-
-  // dummy initialization
-  coefficients[0] = 0.0000;
-  coefficients[1] = 0.0000;
-
-  if( nexp == 1 ) {
-    coefficients[0] = 0.0844;
-    coefficients[1] = 0.0000;
-  }
-  if( nexp == 2 ) {
-    coefficients[0] = 0.1445;
-    coefficients[1] = 0.7524;
-  }
-      
-  Int_t i, k;
-  Double_t reminder[2];
-  Double_t correction, result;
-
-  /* attention: computation order is important */
-  correction=0.0;
-  for ( k = 0; k < nexp; k++ ) reminder[k]=0.0;
-    
-  for ( i = 0; i < n; i++ ) {
-    result = ( source[i] - correction );    /* no rescaling */
-    target[i] = result;
-    
-    for ( k = 0; k < nexp; k++ ) reminder[k] = rates[k] 
-                             * ( reminder[k] + coefficients[k] * result);
-      
-    correction=0.0;
-    for ( k = 0; k < nexp; k++ ) correction += reminder[k];
-  }
-  
-}
-
 //_____________________________________________________________________________
 void AliTRDdigitizer::InitOutput(Int_t iEvent)
 {
@@ -1788,14 +1715,16 @@ Double_t AliTRDdigitizer::TimeStruct(Float_t vdrift, Double_t dist, Double_t z)
   
   // indices:
   Int_t r1 = (Int_t)(10*dist);
-  Int_t r2 = r1+1;
   if (r1<0)  r1 = 0;
   if (r1>37) r1 = 37;
+  Int_t r2 = r1+1;
+  if (r2<0)  r2 = 0;
+  if (r2>37) r2 = 37;
   const Int_t kz1 = (Int_t)(100*z/2.5);
   const Int_t kz2 = kz1+1;
 
   if (r1<0 || r1>37 || kz1<0 || kz1>10) {
-    printf("<AliTRDparameter::TimeStruct> Warning. Indices out of range: ");
+    printf("<AliTRDdigitizer::TimeStruct> Warning. Indices out of range: ");
     printf("dist=%.2f, z=%.2f, r1=%d, kz1=%d\n",dist,z,r1,kz1);
   }
 
@@ -1866,16 +1795,16 @@ void AliTRDdigitizer::SampleTimeStruct(Float_t vdrift)
   fVDsmp[7] = 2.134;
 
   if ( vdrift < fVDsmp[0] ) {
-    printf("<AliTRDparameter::SampleTimeStruct> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
-    printf("<AliTRDparameter::SampleTimeStruct> Drift Velocity too small (%.3f<%.3f)\n"
+    printf("<AliTRDdigitizer::SampleTimeStruct> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
+    printf("<AliTRDdigitizer::SampleTimeStruct> Drift Velocity too small (%.3f<%.3f)\n"
           , vdrift, fVDsmp[0]);
-    printf("<AliTRDparameter::SampleTimeStruct> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
+    printf("<AliTRDdigitizer::SampleTimeStruct> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
     vdrift = fVDsmp[0];
   } else if ( vdrift > fVDsmp[7] ) {
-    printf("<AliTRDparameter::SampleTimeStruct> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
-    printf("<AliTRDparameter::SampleTimeStruct> Drift Velocity too large (%.3f>%.3f)\n"
+    printf("<AliTRDdigitizer::SampleTimeStruct> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
+    printf("<AliTRDdigitizer::SampleTimeStruct> Drift Velocity too large (%.3f>%.3f)\n"
           , vdrift,fVDsmp[6]);
-    printf("<AliTRDparameter::SampleTimeStruct> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
+    printf("<AliTRDdigitizer::SampleTimeStruct> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
     vdrift = fVDsmp[7];
   }
 
@@ -2567,15 +2496,7 @@ void AliTRDdigitizer::RecalcDiffusion(Float_t vdrift)
 {
   if (vdrift == fDiffusionInfo.fLastVdrift)
     return;
-  
-  if (!fPar) {
-    fPar = new AliTRDparameter("TRDparameter","Standard TRD parameter");
-    if (fDebug > 0) {
-      printf("<AliTRDdigitizer::RecalcDiffusion> ");
-      printf("Create the default parameter object\n");
-    }
-  }
-  
+
   AliTRDSimParam* simParam = AliTRDSimParam::Instance();
   if (!simParam)
   {