]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDv1.cxx
Implemented list-management virtuals; use new functionality of RGTopFrame.
[u/mrichter/AliRoot.git] / TRD / AliTRDv1.cxx
index c75f85d86059269b7a1dda58a0eef3376be21b50..c845aa3015b06d6abd96bdde3b4627d338e6c529 100644 (file)
 #include <TVirtualMC.h>
 
 #include "AliConst.h"
+#include "AliLog.h"
+#include "AliMC.h"
 #include "AliRun.h"
 #include "AliTRDgeometry.h"
 #include "AliTRDhit.h"
 #include "AliTRDsim.h"
 #include "AliTRDv1.h"
-#include "AliMC.h"
 
 ClassImp(AliTRDv1)
  
@@ -63,9 +64,10 @@ AliTRDv1::AliTRDv1():AliTRD()
   fDeltaE            = NULL;
   fDeltaG            = NULL;
   fTR                = NULL;
+  fTRon              = kFALSE;
 
   fStepSize          = 0.1;
-  fTypeOfStepManager = 2;
+  fTypeOfStepManager = 1;
 
 }
 
@@ -86,8 +88,9 @@ AliTRDv1::AliTRDv1(const char *name, const char *title)
   fDeltaE            = NULL;
   fDeltaG            = NULL;
   fTR                = NULL;
+  fTRon              = kTRUE;
   fStepSize          = 0.1;
-  fTypeOfStepManager = 2;
+  fTypeOfStepManager = 1;
 
   SetBufferSize(128000);
 
@@ -132,6 +135,7 @@ AliTRDv1 &AliTRDv1::operator=(const AliTRDv1 &trd)
 //_____________________________________________________________________________
 void AliTRDv1::Copy(TObject &trd) const
 {
+       printf("void AliTRDv1::Copy(TObject &trd) const\n");
   //
   // Copy function
   //
@@ -145,6 +149,8 @@ void AliTRDv1::Copy(TObject &trd) const
   ((AliTRDv1 &) trd).fTypeOfStepManager = fTypeOfStepManager;
   ((AliTRDv1 &) trd).fStepSize          = fStepSize;
 
+  ((AliTRDv1 &) trd).fTRon              = fTRon;
+
   fDeltaE->Copy(*((AliTRDv1 &) trd).fDeltaE);
   fDeltaG->Copy(*((AliTRDv1 &) trd).fDeltaG);
   fTR->Copy(*((AliTRDv1 &) trd).fTR);
@@ -194,7 +200,7 @@ void AliTRDv1::CreateTRhit(Int_t det)
   const Int_t   kPdgElectron = 11;
 
   // Ionization energy
-  const Float_t kWion        = 22.04;
+  const Float_t kWion        = 23.53;
 
   // Maximum number of TR photons per track
   const Int_t   kNTR         = 50;
@@ -216,9 +222,7 @@ void AliTRDv1::CreateTRhit(Int_t det)
     Float_t pTot = mom.Rho();
     fTR->CreatePhotons(iPdg,pTot,nTR,eTR);
     if (nTR > kNTR) {
-      printf("AliTRDv1::CreateTRhit -- ");
-      printf("Boundary error: nTR = %d, kNTR = %d\n",nTR,kNTR);
-      exit(1);
+      AliFatal(Form("Boundary error: nTR = %d, kNTR = %d",nTR,kNTR));
     }
 
     // Loop through the TR photons
@@ -241,18 +245,10 @@ void AliTRDv1::CreateTRhit(Int_t det)
       }
 
       // The absorbtion cross sections in the drift gas
-      if (fGasMix == 1) {
-        // Gas-mixture (Xe/CO2)
-        Double_t muXe = fTR->GetMuXe(energyMeV);
-        Double_t muCO = fTR->GetMuCO(energyMeV);
-        sigma = (0.85 * muXe + 0.15 * muCO) * fGasDensity * fTR->GetTemp();
-      }
-      else {
-        // Gas-mixture (Xe/Isobutane) 
-        Double_t muXe = fTR->GetMuXe(energyMeV);
-        Double_t muBu = fTR->GetMuBu(energyMeV);
-        sigma = (0.97 * muXe + 0.03 * muBu) * fGasDensity * fTR->GetTemp();
-      }
+      // Gas-mixture (Xe/CO2)
+      Double_t muXe = fTR->GetMuXe(energyMeV);
+      Double_t muCO = fTR->GetMuCO(energyMeV);
+      sigma = (0.85 * muXe + 0.15 * muCO) * fGasDensity * fTR->GetTemp();
 
       // The distance after which the energy of the TR photon
       // is deposited.
@@ -272,14 +268,14 @@ void AliTRDv1::CreateTRhit(Int_t det)
       gMC->TrackPosition(pos);
       posHit[0] = pos[0] + mom[0] / pTot * absLength;
       posHit[1] = pos[1] + mom[1] / pTot * absLength;
-      posHit[2] = pos[2] + mom[2] / pTot * absLength;      
+      posHit[2] = pos[2] + mom[2] / pTot * absLength;
 
       // Create the charge 
       Int_t q = ((Int_t) (energyeV / kWion));
 
       // Add the hit to the array. TR photon hits are marked 
       // by negative charge
-      AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(),det,posHit,-q,kTRUE); 
+     AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(),det,posHit,-q,kTRUE); 
 
     }
 
@@ -296,25 +292,28 @@ void AliTRDv1::Init()
 
   AliTRD::Init();
 
-  if(fDebug) printf("%s: Slow simulator\n",ClassName());
+  AliDebug(1,"Slow simulator\n");
   if (fSensSelect) {
     if (fSensPlane   >= 0)
-      printf("          Only plane %d is sensitive\n",fSensPlane);
+      AliInfo(Form("Only plane %d is sensitive"));
     if (fSensChamber >= 0)   
-      printf("          Only chamber %d is sensitive\n",fSensChamber);
+      AliInfo(Form("Only chamber %d is sensitive",fSensChamber));
     if (fSensSector  >= 0) {
       Int_t sens1  = fSensSector;
       Int_t sens2  = fSensSector + fSensSectorRange;
             sens2 -= ((Int_t) (sens2 / AliTRDgeometry::Nsect())) 
                    * AliTRDgeometry::Nsect();
-      printf("          Only sectors %d - %d are sensitive\n",sens1,sens2-1);
+           AliInfo(Form("Only sectors %d - %d are sensitive\n",sens1,sens2-1));
     }
   }
-  if (fTR) 
-    printf("%s: TR simulation on\n",ClassName());
-  else
-    printf("%s: TR simulation off\n",ClassName());
-  printf("\n");
+
+  // Switch on TR simulation as default
+  if (!fTRon) {
+    AliInfo("TR simulation off");
+  }
+  else {
+    fTR = new AliTRDsim();
+  }
 
   // First ionization potential (eV) for the gas mixture (90% Xe + 10% CO2)
   const Float_t kPoti = 12.1;
@@ -325,28 +324,12 @@ void AliTRDv1::Init()
   Float_t eEnd = TMath::Log(kEend);
 
   // Ermilova distribution for the delta-ray spectrum
-  fDeltaE = new TF1("deltae" ,Ermilova    ,poti,eEnd,0);
+  fDeltaE = new TF1("deltae" ,Ermilova ,poti,eEnd,0);
 
   // Geant3 distribution for the delta-ray spectrum
-  fDeltaG = new TF1("deltaeg",IntSpecGeant,poti,eEnd,0);
-
-  if(fDebug) {
-    printf("%s: ",ClassName());
-    for (Int_t i = 0; i < 80; i++) printf("*");
-    printf("\n");
-  }
+  fDeltaG = new TF1("deltag",IntSpecGeant,2.421257,28.536469,0);
 
-}
-
-//_____________________________________________________________________________
-AliTRDsim *AliTRDv1::CreateTR()
-{
-  //
-  // Enables the simulation of TR
-  //
-
-  fTR = new AliTRDsim();
-  return fTR;
+  AliDebug(1,"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
 
 }
 
@@ -358,8 +341,8 @@ void AliTRDv1::SetSensPlane(Int_t iplane)
   //
 
   if ((iplane < 0) || (iplane > 5)) {
-    printf("Wrong input value: %d\n",iplane);
-    printf("Use standard setting\n");
+    AliWarning(Form("Wrong input value:%d",iplane));
+    AliWarning("Use standard setting");
     fSensPlane  = -1;
     fSensSelect =  0;
     return;
@@ -378,8 +361,8 @@ void AliTRDv1::SetSensChamber(Int_t ichamber)
   //
 
   if ((ichamber < 0) || (ichamber > 4)) {
-    printf("Wrong input value: %d\n",ichamber);
-    printf("Use standard setting\n");
+    AliWarning(Form("Wrong input value: %d",ichamber));
+    AliWarning("Use standard setting");
     fSensChamber = -1;
     fSensSelect  =  0;
     return;
@@ -411,8 +394,8 @@ void AliTRDv1::SetSensSector(Int_t isector, Int_t nsector)
   //
 
   if ((isector < 0) || (isector > 17)) {
-    printf("Wrong input value <isector>: %d\n",isector);
-    printf("Use standard setting\n");
+    AliWarning(Form("Wrong input value <isector>: %d",isector));
+    AliWarning("Use standard setting");
     fSensSector      = -1;
     fSensSectorRange =  0;
     fSensSelect      =  0;
@@ -420,8 +403,8 @@ void AliTRDv1::SetSensSector(Int_t isector, Int_t nsector)
   }
 
   if ((nsector < 1) || (nsector > 18)) {
-    printf("Wrong input value <nsector>: %d\n",nsector);
-    printf("Use standard setting\n");
+    AliWarning(Form("Wrong input value <nsector>: %d",nsector));
+    AliWarning("Use standard setting");
     fSensSector      = -1;
     fSensSectorRange =  0;
     fSensSelect      =  0;
@@ -438,7 +421,7 @@ void AliTRDv1::SetSensSector(Int_t isector, Int_t nsector)
 void AliTRDv1::StepManager()
 {
   //
-  // Slow simulator. Every charged track produces electron cluster as hits 
+  // Slow simulator. Every charged track produces electron cluster as hits
   // along its path across the drift volume. 
   //
 
@@ -446,7 +429,7 @@ void AliTRDv1::StepManager()
     case 0  : StepManagerErmilova();  break;  // 0 is Ermilova
     case 1  : StepManagerGeant();     break;  // 1 is Geant
     case 2  : StepManagerFixedStep(); break;  // 2 is fixed step
-    default : printf("<AliTRDv1::StepManager>: Not a valid Step Manager.\n");
+    default : AliWarning("Not a valid Step Manager.");
   }
 
 }
@@ -461,14 +444,12 @@ void AliTRDv1::SelectStepManager(Int_t t)
   //   2 - Fixed step size
   //
 
-  if (t == 1) {
-    printf("<AliTRDv1::SelectStepManager>: Sorry, Geant parametrization step"
-          "manager is not implemented yet. Please ask K.Oyama for detail.\n");
+/*  if (t == 1) {
+    AliWarning("Sorry, Geant parametrization step manager is not implemented yet. Please ask K.Oyama for detail.");
   }
-
+*/
   fTypeOfStepManager = t;
-  printf("<AliTRDv1::SelectStepManager>: Step Manager type %d was selected.\n"
-        , fTypeOfStepManager);
+  AliInfo(Form("Step Manager type %d was selected",fTypeOfStepManager));
 
 }
 
@@ -476,14 +457,228 @@ void AliTRDv1::SelectStepManager(Int_t t)
 void AliTRDv1::StepManagerGeant()
 {
   //
-  // Slow simulator. Every charged track produces electron cluster as hits 
+  // Slow simulator. Every charged track produces electron cluster as hits
   // along its path across the drift volume. The step size is set acording
   // to Bethe-Bloch. The energy distribution of the delta electrons follows
   // a spectrum taken from Geant3.
   //
+  Int_t    pla = 0;
+  Int_t    cha = 0;
+  Int_t    sec = 0;
+  Int_t    det = 0;
+  Int_t    iPdg;
+  Int_t    qTot;
+
+  Float_t  hits[3];
+  Float_t  charge;
+  Float_t  aMass;
+
+  Double_t pTot = 0;
+  Double_t eDelta;
+  Double_t betaGamma, pp;
+  Double_t stepSize=0;
+
+  Bool_t   drRegion = kFALSE;
+  Bool_t   amRegion = kFALSE;
+
+  TString  cIdCurrent;
+  TString  cIdSensDr = "J";
+  TString  cIdSensAm = "K";
+  Char_t   cIdChamber[3];
+           cIdChamber[2] = 0;
+
+  TLorentzVector pos, mom;
+
+  const Int_t    kNplan       = AliTRDgeometry::Nplan();
+  const Int_t    kNcham       = AliTRDgeometry::Ncham();
+  const Int_t    kNdetsec     = kNplan * kNcham;
+
+  const Double_t kBig         = 1.0E+12; // Infinitely big
+  const Float_t  kWion        = 23.53;   // Ionization energy
+  const Float_t  kPTotMaxEl   = 0.002;   // Maximum momentum for e+ e- g
+
+  // Minimum energy for the step size adjustment
+  const Float_t  kEkinMinStep = 1.0e-5;
+  // energy threshold for production of delta electrons
+       const Float_t  kECut = 1.0e4;
+       // Parameters entering the parametrized range for delta electrons
+       const float ra=5.37E-4, rb=0.9815, rc=3.123E-3;
+       // Gas density -> To be made user adjustable !
+       const float rho=0.004945 ; //[0.85*0.00549+0.15*0.00186 (Xe-CO2 85-15)]
+
+  // Plateau value of the energy-loss for electron in xenon
+  // taken from: Allison + Comb, Ann. Rev. Nucl. Sci. (1980), 30, 253
+  //const Double_t kPlateau = 1.70;
+  // the averaged value (26/3/99)
+  const Float_t  kPlateau     = 1.55;
+
+  const Float_t  kPrim        = 19.34;  // dN1/dx|min for the gas mixture (90% Xe + 10% CO2)
+  // First ionization potential (eV) for the gas mixture (90% Xe + 10% CO2)
+  const Float_t  kPoti        = 12.1;
+
+  const Int_t    kPdgElectron = 11;  // PDG code electron
+
+  // Set the maximum step size to a very large number for all
+  // neutral particles and those outside the driftvolume
+  gMC->SetMaxStep(kBig);
+
+  // Use only charged tracks
+  if (( gMC->TrackCharge()       ) &&
+      (!gMC->IsTrackStop()       ) &&
+      (!gMC->IsTrackDisappeared())) {
+
+    // Inside a sensitive volume?
+    drRegion = kFALSE;
+    amRegion = kFALSE;
+    cIdCurrent = gMC->CurrentVolName();
+    if (cIdSensDr == cIdCurrent[1]) {
+      drRegion = kTRUE;
+    }
+    if (cIdSensAm == cIdCurrent[1]) {
+      amRegion = kTRUE;
+    }
+    if (drRegion || amRegion) {
+
+      // The hit coordinates and charge
+      gMC->TrackPosition(pos);
+      hits[0] = pos[0];
+      hits[1] = pos[1];
+      hits[2] = pos[2];
+
+      // The sector number (0 - 17)
+      // The numbering goes clockwise and starts at y = 0
+      Float_t phi = kRaddeg*TMath::ATan2(pos[0],pos[1]);
+      if (phi < 90.)
+        phi = phi + 270.;
+      else
+        phi = phi -  90.;
+      sec = ((Int_t) (phi / 20));
+
+      // The plane and chamber number
+      cIdChamber[0] = cIdCurrent[2];
+      cIdChamber[1] = cIdCurrent[3];
+      Int_t idChamber = (atoi(cIdChamber) % kNdetsec);
+      cha = kNcham - ((Int_t) idChamber / kNplan) - 1;
+      pla = ((Int_t) idChamber % kNplan);
+
+      // Check on selected volumes
+      Int_t addthishit = 1;
+      if (fSensSelect) {
+        if ((fSensPlane   >= 0) && (pla != fSensPlane  )) addthishit = 0;
+        if ((fSensChamber >= 0) && (cha != fSensChamber)) addthishit = 0;
+        if (fSensSector  >= 0) {
+          Int_t sens1  = fSensSector;
+          Int_t sens2  = fSensSector + fSensSectorRange;
+                sens2 -= ((Int_t) (sens2 / AliTRDgeometry::Nsect()))
+                       * AliTRDgeometry::Nsect();
+          if (sens1 < sens2) {
+            if ((sec < sens1) || (sec >= sens2)) addthishit = 0;
+                               }
+          else {
+            if ((sec < sens1) && (sec >= sens2)) addthishit = 0;
+                               }
+                               }
+      }
 
-  printf("AliTRDv1::StepManagerGeant: Not implemented yet.\n");
+      // Add this hit
+      if (addthishit) {
+
+       // The detector number
+        det = fGeometry->GetDetector(pla,cha,sec);
 
+       // Special hits only in the drift region
+        if (drRegion) {
+          // Create a track reference at the entrance and
+          // exit of each chamber that contain the
+               // momentum components of the particle
+          if (gMC->IsTrackEntering() || gMC->IsTrackExiting()) {
+            gMC->TrackMomentum(mom);
+            AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber());
+          }
+                                       
+                                       if (gMC->IsTrackEntering() && !gMC->IsNewTrack()) {
+                                               // determine if hit belong to primary track 
+                                               fPrimaryTrackPid=gAlice->GetMCApp()->GetCurrentTrackNumber();
+                                               //determine track length when entering the detector
+                                               fTrackLength0=gMC->TrackLength();
+                                       }
+                                       
+                                       // Create the hits from TR photons
+          if (fTR) CreateTRhit(det);
+                               }
+
+                               // Calculate the energy of the delta-electrons
+                               // modified by Alex Bercuci (A.Bercuci@gsi.de) on 26.01.06
+                               // take into account correlation with the underlying GEANT tracking
+                               // mechanism. see
+        // http://www-linux.gsi.de/~abercuci/Contributions/TRD/index.html
+
+                               // determine the most significant process (last on the processes list)
+                               // which caused this hit
+        TArrayI processes;
+        gMC->StepProcesses(processes);
+        int nofprocesses=processes.GetSize(), pid;
+                               if(!nofprocesses) pid=0;
+                               else pid=       processes[nofprocesses-1];              
+                               
+                               // generate Edep according to GEANT parametrisation
+                               eDelta =TMath::Exp(fDeltaG->GetRandom()) - kPoti;
+        eDelta=TMath::Max(eDelta,0.0);
+                               float pr_range=0.;
+                               float range=gMC->TrackLength()-fTrackLength0;
+                               // merge GEANT tracker information with localy cooked one
+                               if(gAlice->GetMCApp()->GetCurrentTrackNumber()==fPrimaryTrackPid) {
+//                                     printf("primary pid=%d eDelta=%f\n",pid,eDelta);
+                                       if(pid==27){ 
+                                               if(eDelta>=kECut){                
+                                                       pr_range=ra*eDelta*.001*(1.-rb/(1.+rc*eDelta*0.001))/rho;
+                               if(pr_range>=(3.7-range)) eDelta*=.1;
+                                               }
+                                       } else if(pid==1){      
+                                               if(eDelta<kECut) eDelta*=.5;
+                                               else {                
+                                                       pr_range=ra*eDelta*.001*(1.-rb/(1.+rc*eDelta*0.001))/rho;
+                               if(pr_range>=((AliTRDgeometry::DrThick()
+                       + AliTRDgeometry::AmThick())-range)) eDelta*=.05;
+                                                       else eDelta*=.5;
+                                               }
+                                       } else eDelta=0.;       
+                               } else eDelta=0.;
+
+        // Generate the electron cluster size
+        if(eDelta==0.) qTot=0;
+                               else qTot = ((Int_t) (eDelta / kWion) + 1);
+                               // Create a new dEdx hit
+        AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(),det,hits,qTot, drRegion);
+                               
+        // Calculate the maximum step size for the next tracking step
+       // Produce only one hit if Ekin is below cutoff
+        aMass = gMC->TrackMass();
+        if ((gMC->Etot() - aMass) > kEkinMinStep) {
+
+          // The energy loss according to Bethe Bloch
+          iPdg  = TMath::Abs(gMC->TrackPid());
+          if ( (iPdg != kPdgElectron) ||
+                               ((iPdg == kPdgElectron) && (pTot < kPTotMaxEl))) {
+            gMC->TrackMomentum(mom);
+            pTot      = mom.Rho();
+            betaGamma = pTot / aMass;
+            pp        = BetheBlochGeant(betaGamma);
+                       // Take charge > 1 into account
+            charge = gMC->TrackCharge();
+            if (TMath::Abs(charge) > 1) pp = pp * charge*charge;
+          } else { // Electrons above 20 Mev/c are at the plateau
+                                               pp = kPrim * kPlateau;
+          }
+
+         Int_t nsteps = 0;
+         do {nsteps = gRandom->Poisson(pp);} while(!nsteps);
+          stepSize = 1./nsteps;
+         gMC->SetMaxStep(stepSize);
+       }
+      }
+    }
+  }
 }
 
 //_____________________________________________________________________________
@@ -504,7 +699,7 @@ void AliTRDv1::StepManagerErmilova()
   Int_t    qTot;
 
   Float_t  hits[3];
-  Double_t  random[1];
+  Double_t random[1];
   Float_t  charge;
   Float_t  aMass;
 
@@ -529,9 +724,16 @@ void AliTRDv1::StepManagerErmilova()
   const Int_t    kNdetsec     = kNplan * kNcham;
 
   const Double_t kBig         = 1.0E+12; // Infinitely big
-  const Float_t  kWion        = 22.04;   // Ionization energy
+  const Float_t  kWion        = 23.53;   // Ionization energy
   const Float_t  kPTotMaxEl   = 0.002;   // Maximum momentum for e+ e- g 
 
+  // energy threshold for production of delta electrons
+  //const Float_t  kECut = 1.0e4;
+  // Parameters entering the parametrized range for delta electrons
+  //const float ra=5.37E-4, rb=0.9815, rc=3.123E-3;
+  // Gas density -> To be made user adjustable !
+  //const float rho=0.004945 ; //[0.85*0.00549+0.15*0.00186 (Xe-CO2 85-15)]
+
   // Minimum energy for the step size adjustment
   const Float_t  kEkinMinStep = 1.0e-5;
 
@@ -587,7 +789,7 @@ void AliTRDv1::StepManagerErmilova()
       cIdChamber[0] = cIdCurrent[2];
       cIdChamber[1] = cIdCurrent[3];
       Int_t idChamber = (atoi(cIdChamber) % kNdetsec);
-      cha = ((Int_t) idChamber / kNplan);
+      cha = kNcham - ((Int_t) idChamber / kNplan) - 1;
       pla = ((Int_t) idChamber % kNplan);
 
       // Check on selected volumes
@@ -602,11 +804,11 @@ void AliTRDv1::StepManagerErmilova()
                        * AliTRDgeometry::Nsect();
           if (sens1 < sens2) {
             if ((sec < sens1) || (sec >= sens2)) addthishit = 0;
-         }
+                               }
           else {
             if ((sec < sens1) && (sec >= sens2)) addthishit = 0;
-         }
-       }
+                               }
+                               }
       }
 
       // Add this hit
@@ -625,28 +827,27 @@ void AliTRDv1::StepManagerErmilova()
             gMC->TrackMomentum(mom);
             AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber());
           }
-
           // Create the hits from TR photons
           if (fTR) CreateTRhit(det);
+                               }
 
-       }
 
         // Calculate the energy of the delta-electrons
         eDelta = TMath::Exp(fDeltaE->GetRandom()) - kPoti;
         eDelta = TMath::Max(eDelta,0.0);
+        // Generate the electron cluster size
+        if(eDelta==0.) qTot=0;
+                               else qTot = ((Int_t) (eDelta / kWion) + 1);
 
-        // The number of secondary electrons created
-        qTot = ((Int_t) (eDelta / kWion) + 1);
-
-       // Create a new dEdx hit
+                               // Create a new dEdx hit
         if (drRegion) {
           AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber()
-                ,det,hits,qTot,kTRUE);       
-       }
+                ,det,hits,qTot, kTRUE);
+                               }
         else {
           AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber()
-                ,det,hits,qTot,kFALSE);      
-       }
+                ,det,hits,qTot,kFALSE);
+                               }
 
         // Calculate the maximum step size for the next tracking step
        // Produce only one hit if Ekin is below cutoff 
@@ -656,7 +857,7 @@ void AliTRDv1::StepManagerErmilova()
           // The energy loss according to Bethe Bloch
           iPdg  = TMath::Abs(gMC->TrackPid());
           if ( (iPdg != kPdgElectron) ||
-             ((iPdg == kPdgElectron) && (pTot < kPTotMaxEl))) {
+                               ((iPdg == kPdgElectron) && (pTot < kPTotMaxEl))) {
             gMC->TrackMomentum(mom);
             pTot      = mom.Rho();
             betaGamma = pTot / aMass;
@@ -664,10 +865,8 @@ void AliTRDv1::StepManagerErmilova()
            // Take charge > 1 into account
             charge = gMC->TrackCharge();
             if (TMath::Abs(charge) > 1) pp = pp * charge*charge;
-          }
-          // Electrons above 20 Mev/c are at the plateau
-          else {
-            pp = kPrim * kPlateau;
+          } else { // Electrons above 20 Mev/c are at the plateau
+                                               pp = kPrim * kPlateau;
           }
       
           if (pp > 0) {
@@ -676,16 +875,11 @@ void AliTRDv1::StepManagerErmilova()
             while ((random[0] == 1.) || (random[0] == 0.));
             stepSize = - TMath::Log(random[0]) / pp; 
             gMC->SetMaxStep(stepSize);
-         }
-
-       }
-
+                               }
+                               }
       }
-
     }
-
   }
-
 }
 
 //_____________________________________________________________________________
@@ -723,7 +917,7 @@ void AliTRDv1::StepManagerFixedStep()
 
   const Double_t kBig         = 1.0E+12;
 
-  const Float_t  kWion        = 22.04;   // Ionization energy
+  const Float_t  kWion        = 23.53;   // Ionization energy
   const Float_t  kEkinMinStep = 1.0e-5;  // Minimum energy for the step size adjustment
 
   // Set the maximum step size to a very large number for all 
@@ -760,7 +954,7 @@ void AliTRDv1::StepManagerFixedStep()
   cIdChamber[0] = cIdCurrent[2];
   cIdChamber[1] = cIdCurrent[3];
   Int_t idChamber = (atoi(cIdChamber) % kNdetsec);
-  cha = ((Int_t) idChamber / kNplan);
+  cha = kNcham - ((Int_t) idChamber / kNplan) - 1;
   pla = ((Int_t) idChamber % kNplan);
 
   // Check on selected volumes
@@ -813,7 +1007,8 @@ void AliTRDv1::StepManagerFixedStep()
   // Create a new dEdx hit
   eDep = TMath::Max(gMC->Edep(),0.0) * 1.0e+09;
   qTot = (Int_t) (eDep / kWion);
-  AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber(),det,hits,qTot,drRegion);
+  AddHit(gAlice->GetMCApp()->GetCurrentTrackNumber()
+        ,det,hits,qTot,drRegion);
 
   // Set Maximum Step Size
   // Produce only one hit if Ekin is below cutoff
@@ -867,7 +1062,7 @@ Double_t AliTRDv1::BetheBloch(Double_t bg)
 }
 
 //_____________________________________________________________________________
-Double_t BetheBlochGeant(Double_t bg)
+Double_t AliTRDv1::BetheBlochGeant(Double_t bg)
 {
   //
   // Return dN/dx (number of primary collisions per centimeter)
@@ -905,10 +1100,72 @@ Double_t BetheBlochGeant(Double_t bg)
   Double_t pp = ((arr_nc[i+1] - arr_nc[i]) / 
                 (arr_g[i+1]-arr_g[i])) * (g-arr_g[i]) + arr_nc[i];
 
-  return pp;
+  return pp; //arr_nc[8];
 
 }
 
+//_____________________________________________________________________________
+void AliTRDv1::Stepping()
+{    
+// Stepping info
+// ---
+
+   cout << "X(cm)    "
+       << "Y(cm)    "
+       << "Z(cm)  "
+       << "KinE(MeV)   "
+       << "dE(MeV) "
+       << "Step(cm) "
+       << "TrackL(cm) "
+       << "Volume  "
+       << "Process "  
+       << endl;
+
+   // Position
+    //
+    Double_t x, y, z;
+    gMC->TrackPosition(x, y, z);
+    cout << setw(8) << setprecision(3) << x << " "
+         << setw(8) << setprecision(3) << y << " "
+         << setw(8) << setprecision(3) << z << "  ";
+
+    // Kinetic energy
+    //
+    Double_t px, py, pz, etot;
+    gMC->TrackMomentum(px, py, pz, etot);
+    Double_t ekin = etot - gMC->TrackMass();
+    cout << setw(9) << setprecision(4) << ekin*1e03 << " ";
+
+    // Energy deposit
+    //
+    cout << setw(9) << setprecision(4) << gMC->Edep()*1e03 << " ";
+
+    // Step length
+    //
+    cout << setw(8) << setprecision(3) << gMC->TrackStep() << " ";
+
+    // Track length
+    //
+    cout << setw(8) << setprecision(3) << gMC->TrackLength() << "     ";
+
+    // Volume
+    //
+    if (gMC->CurrentVolName() != 0)
+      cout << setw(4) << gMC->CurrentVolName() << "  ";
+    else
+      cout << setw(4) << "None"  << "  ";
+
+    // Process
+    //
+    TArrayI processes;
+    Int_t nofProcesses = gMC->StepProcesses(processes);
+    for(int ip=0;ip<nofProcesses; ip++)
+      cout << TMCProcessName[processes[ip]]<<" / ";
+
+    cout << endl;
+}
+
+
 //_____________________________________________________________________________
 Double_t Ermilova(Double_t *x, Double_t *)
 {
@@ -968,8 +1225,8 @@ Double_t IntSpecGeant(Double_t *x, Double_t *)
   // Integrated spectrum from Geant3
   //
 
-  const Int_t n_pts = 83;
-  Double_t arr_e[n_pts] = {
+  const Int_t npts = 83;
+  Double_t arre[npts] = {
     2.421257,  2.483278,  2.534301,  2.592230,
     2.672067,  2.813299,  3.015059,  3.216819,
     3.418579,  3.620338,  3.868209,  3.920198,
@@ -992,7 +1249,8 @@ Double_t IntSpecGeant(Double_t *x, Double_t *)
     12.585884, 12.854123, 14.278421, 16.975889,
     20.829416, 24.682943, 28.536469
   };
-  Double_t arr_dndx[n_pts] = {
+  /*
+  Double_t arrdndx[npts] = {
     19.344431, 18.664679, 18.136106, 17.567745,
     16.836426, 15.677382, 14.281277, 13.140237,
     12.207677, 11.445510, 10.697049, 10.562296,
@@ -1015,21 +1273,43 @@ Double_t IntSpecGeant(Double_t *x, Double_t *)
     0.001142,  0.000873,  0.000210,  0.000014,
     0.000000,  0.000000,  0.000000
   };
+  */
+  // Differentiate
+  //  dnde = (arrdndx[i-1] - arrdndx[i]) / (arre[i] - arre[i-1]);
+
+  Double_t arrdnde[npts] = {
+    10.960000, 10.960000, 10.359500,  9.811340,
+    9.1601500,  8.206670,  6.919630,  5.655430,
+    4.6221300,  3.777610,  3.019560,  2.591950,
+    2.5414600,  2.712920,  3.327460,  4.928240,
+    7.6185300, 10.966700, 12.225800,  8.094750,
+    3.3586900,  1.553650,  1.209600,  1.263840,
+    1.3241100,  1.312140,  1.255130,  1.165770,
+    1.0594500,  0.945450,  0.813231,  0.699837,
+    0.6235580,  2.260990,  2.968350,  2.240320,
+    1.7988300,  1.553300,  1.432070,  1.535520,
+    1.4429900,  1.247990,  1.050750,  0.829549,
+    0.5900280,  0.395897,  0.268741,  0.185320,
+    0.1292120,  0.103545,  0.0949525, 0.101535,
+    0.1276380,  0.134216,  0.123816,  0.104557,
+    0.0751843,  0.0521745, 0.0373546, 0.0275391,
+    0.0204713,  0.0169234, 0.0154552, 0.0139194,
+    0.0125592,  0.0113638, 0.0107354, 0.0102137,
+    0.00845984, 0.00683338, 0.00556836, 0.00456874,
+    0.0036227,  0.00285991, 0.00226664, 0.00172234,
+    0.00131226, 0.00100284, 0.000465492, 7.26607e-05,
+    3.63304e-06, 0.0000000, 0.0000000
+  };
 
   Int_t i;
   Double_t energy = x[0];
-  Double_t dnde;
 
-  for( i = 0 ; i < n_pts ; i++ )
-    if( energy < arr_e[i] ) break;
+  for( i = 0 ; i < npts ; i++ )
+    if( energy < arre[i] ) break;
 
   if( i == 0 )
-    printf("Error in AliTRDv1::IntSpecGeant: "
-          "given energy value is too small or zero.\n");
+    AliErrorGeneral("AliTRDv1","Given energy value is too small or zero");
 
-  // Interpolate
-  dnde = (arr_dndx[i-1] - arr_dndx[i]) / (arr_e[i] - arr_e[i-1]);
-
-  return dnde;
+   return arrdnde[i];
 
 }