]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSsimulationSPD.cxx
A default AliITSRecoParam object is defined in AliITSReconstructor as static data...
[u/mrichter/AliRoot.git] / ITS / AliITSsimulationSPD.cxx
index 7c74648794b6890a4796eb87c010005ad52bf145..5561132c9d8aac13a957e6fb4acee8779444a898 100644 (file)
  **************************************************************************/
 
 /*
-$Id$
+$Id:$
 */
 
 #include <Riostream.h>
 #include <TH1.h>
-#include <TMath.h>
-#include <TParticle.h>
-#include <TRandom.h>
 #include <TString.h>
 #include "AliITS.h"
-#include "AliITSMapA2.h" 
 #include "AliITSdigitSPD.h"
-#include "AliITSgeom.h"
 #include "AliITShit.h"
 #include "AliITSmodule.h"
 #include "AliITSpList.h"
@@ -35,14 +30,17 @@ $Id$
 #include "AliITSsimulationSPD.h"
 #include "AliLog.h"
 #include "AliRun.h"
+#include "AliMagF.h"
 
 //#define DEBUG
 
 ClassImp(AliITSsimulationSPD)
 ////////////////////////////////////////////////////////////////////////
 //  Version: 1
-//  Modified by Bjorn S. Nilsen, G.E. Bruno, H. Tydesjo
+//  Modified by D. Elia, G.E. Bruno, H. Tydesjo 
+//  Fast diffusion code by Bjorn S. Nilsen
 //  March-April 2006
+//  October     2007: GetCalibrationObjects() removed
 //
 //  Version: 0
 //  Written by Boris Batyunya
@@ -58,7 +56,9 @@ AliITSsimulationSPD::AliITSsimulationSPD():
 AliITSsimulation(),
 fHis(0),
 fSPDname(),
-fCoupling(){
+fCoupling(),
+fLorentz(kFALSE),
+fTanLorAng(0){
     // Default constructor.
     // Inputs:
     //    none.
@@ -75,7 +75,9 @@ AliITSsimulationSPD::AliITSsimulationSPD(AliITSDetTypeSim *dettyp):
 AliITSsimulation(dettyp),
 fHis(0),
 fSPDname(),
-fCoupling(){
+fCoupling(),
+fLorentz(kFALSE),
+fTanLorAng(0){
     // standard constructor
     // Inputs:
     //    AliITSsegmentation *seg  A pointer to the segmentation class
@@ -121,10 +123,40 @@ void AliITSsimulationSPD::Init(){
     } else {
         fCoupling=1;
     } // end if
-
-    // Get the calibration objects for each module(ladder)
-    GetCalibrationObjects(0); //RunNr 0 hard coded for now
-
+    //SetLorentzDrift(kTRUE);
+    if (fLorentz) SetTanLorAngle();
+}
+//______________________________________________________________________
+Bool_t AliITSsimulationSPD::SetTanLorAngle(Double_t WeightHole) {
+     // This function set the Tangent of the Lorentz angle. 
+     // A weighted average is used for electrons and holes 
+     // Input: Double_t WeightHole: wheight for hole: it should be in the range [0,1]
+     // output: Bool_t : kTRUE in case of success
+     //
+     if(!fDetType) {
+       AliError("AliITSsimulationSPD::SetTanLorAngle: AliITSDetTypeSim* fDetType not set ");
+       return kFALSE;}
+     if(WeightHole<0) {
+        WeightHole=0.;
+        AliWarning("AliITSsimulationSPD::SetTanLorAngle: You have asked for negative Hole weight");
+        AliWarning("AliITSsimulationSPD::SetTanLorAngle: I'm going to use only electrons");
+     }
+     if(WeightHole>1) {
+        WeightHole=1.;
+        AliWarning("AliITSsimulationSPD::SetTanLorAngle: You have asked for weight > 1");
+        AliWarning("AliITSsimulationSPD::SetTanLorAngle: I'm going to use only holes");
+     }
+     Double_t WeightEle=1.-WeightHole;
+     AliITSCalibrationSPD* res = (AliITSCalibrationSPD*)GetCalibrationModel(fDetType->GetITSgeom()->GetStartSPD());
+     AliMagF *mf = gAlice->Field();
+     Float_t pos[3]={0.,0.,0.};
+     Float_t B[3]={0.,0.,0.};
+     mf->Field(pos,B);
+     fTanLorAng = TMath::Tan(WeightHole*res->LorentzAngleHole(B[2]) +
+                              WeightEle*res->LorentzAngleElectron(B[2]));
+     fTanLorAng*=-1.; // this only for the old geometry
+                       // comment the upper line for the new geometry
+     return kTRUE;
 }
 //______________________________________________________________________
 AliITSsimulationSPD::~AliITSsimulationSPD(){
@@ -144,7 +176,12 @@ AliITSsimulationSPD::~AliITSsimulationSPD(){
 //______________________________________________________________________
 AliITSsimulationSPD::AliITSsimulationSPD(const 
                                                   AliITSsimulationSPD 
-                                                  &s) : AliITSsimulation(s){
+                                                  &s) : AliITSsimulation(s),
+fHis(s.fHis),
+fSPDname(s.fSPDname),
+fCoupling(s.fCoupling),
+fLorentz(s.fLorentz),
+fTanLorAng(s.fTanLorAng){
     //     Copy Constructor
     // Inputs:
     //    AliITSsimulationSPD &s The original class for which
@@ -153,8 +190,6 @@ AliITSsimulationSPD::AliITSsimulationSPD(const
     //    none.
     // Return:
 
-    *this = s;
-    return;
 }
 //______________________________________________________________________
 AliITSsimulationSPD&  AliITSsimulationSPD::operator=(const 
@@ -171,6 +206,8 @@ AliITSsimulationSPD&  AliITSsimulationSPD::operator=(const
     this->fHis = s.fHis;
     fCoupling  = s.fCoupling;
     fSPDname   = s.fSPDname;
+    fLorentz   = s.fLorentz;
+    fTanLorAng = s.fTanLorAng;
     return *this;
 }
 //______________________________________________________________________
@@ -190,28 +227,6 @@ AliITSsimulation&  AliITSsimulationSPD::operator=(const
 
     return *this;
 }
-
-//______________________________________________________________________
-void AliITSsimulationSPD::GetCalibrationObjects(Int_t RunNr) {
-  AliCDBManager* man = AliCDBManager::Instance();
-  if(!man->IsDefaultStorageSet()) {
-    man->SetDefaultStorage("local://$ALICE_ROOT");
-  }
-  AliCDBEntry *entrySPD = man->Get("ITS/Calib/CalibSPD", RunNr);
-  if(!entrySPD){
-    AliWarning("Cannot find SPD calibration entry!");
-    return;
-  }
-  TObjArray *respSPD = (TObjArray *)entrySPD->GetObject();
-  if ((! respSPD)) {
-    AliWarning("Cannot get data from SPD database entry!");
-    return;
-  }
-  for (Int_t mod=0; mod<240; mod++) {
-    calObj[mod] = (AliITSCalibrationSPD*) respSPD->At(mod);
-  }
-}
-
 //______________________________________________________________________
 void AliITSsimulationSPD::InitSimulationModule(Int_t module, Int_t event){
     //  This function creates maps to build the list of tracks for each
@@ -254,6 +269,9 @@ void AliITSsimulationSPD::SDigitiseModule(AliITSmodule *mod,Int_t,
     SetEventNumber(event);
     // HitToSDigit(mod);
     HitToSDigitFast(mod);
+    RemoveDeadPixels(mod);
+//    cout << "After Remove in SDigitiseModule !!!!!" << endl; // dom
+//    cout << "Module " << mod->GetIndex() << " Event " << event << endl; // dom
     WriteSDigits();
     ClearMap();
 }
@@ -270,9 +288,11 @@ void AliITSsimulationSPD::WriteSDigits(){
     static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
 
     AliDebug(1,Form("Writing SDigits for module %d",GetModuleNumber()));
+//    cout << "WriteSDigits for module " << GetModuleNumber() << endl; // dom
     GetMap()->GetMaxMapIndex(niz, nix);
     for(iz=0; iz<niz; iz++)for(ix=0; ix<nix; ix++){
         if(GetMap()->GetSignalOnly(iz,ix)>0.0){
+//            cout << " Signal gt 0  iz ix " << iz << ix << " Module " << GetModuleNumber() << endl; // dom
             aliITS->AddSumDigit(*(GetMap()->GetpListItem(iz,ix)));
            if(AliDebugLevel()>0) {
              AliDebug(1,Form("%d, %d",iz,ix));
@@ -293,7 +313,8 @@ void AliITSsimulationSPD::FinishSDigitiseModule(){
     //    none
 
     AliDebug(1,"()");
-    pListToDigits(); // Charge To Signal both adds noise and
+//    cout << "FinishSDigitiseModule for module " << GetModuleNumber() << endl; // dom
+    FrompListToDigits(); // Charge To Signal both adds noise and
     ClearMap();
     return;
 }
@@ -316,7 +337,8 @@ void AliITSsimulationSPD::DigitiseModule(AliITSmodule *mod,Int_t,
     // HitToSDigit(mod);
     HitToSDigitFast(mod);
     RemoveDeadPixels(mod);
-    pListToDigits();
+//    cout << "After Remove in DigitiseModule in module " << mod->GetIndex() << endl; // dom
+    FrompListToDigits();
     ClearMap();
 }
 //______________________________________________________________________
@@ -333,7 +355,7 @@ void AliITSsimulationSPD::HitToSDigit(AliITSmodule *mod){
     Int_t nhits = hits->GetEntriesFast();
     Int_t h,ix,iz,i;
     Int_t idtrack;
-    Double_t x0=0.0,x1=0.0,y0=0.0,y1=0.0,z0=0.0,z1=0.0,de=0.0;
+    Double_t x0=0.0,x1=0.0,y0=0.0,y1=0.0,z0=0.0,z1=0.0,de=0.0,ld=0.0;
     Double_t x,y,z,t,tp,st,dt=0.2,el,sig,sigx,sigz,fda;
     AliITSsegmentationSPD* seg = (AliITSsegmentationSPD*)GetSegmentationModel(0);
     AliITSCalibrationSPD* res = (AliITSCalibrationSPD*)GetCalibrationModel(fDetType->GetITSgeom()->GetStartSPD());
@@ -365,11 +387,10 @@ void AliITSsimulationSPD::HitToSDigit(AliITSmodule *mod){
                                     <<" de="<<de<<endl;
                 } // end if GetDebug
                 sig = res->SigmaDiffusion1D(TMath::Abs(thick + y)); 
-                //  SpreadCharge(x,z,ix,iz,el,sig,idtrack,h);
                 sigx=sig;
                 sigz=sig*fda;
-                SpreadChargeAsym(x,z,ix,iz,el,sigx,sigz,idtrack,h);
-                cout << "sigx, sigz, y "<< sigx << " " << sigz<< " " << TMath::Abs(thick + y) << endl;// ciccio
+                if (fLorentz) ld=(y+thick)*fTanLorAng;
+                SpreadChargeAsym(x,z,ix,iz,el,sigx,sigz,ld,idtrack,h);
             } // end for t
         } else { // st == 0.0 deposit it at this point
             x   = x0;
@@ -378,37 +399,35 @@ void AliITSsimulationSPD::HitToSDigit(AliITSmodule *mod){
             if(!(seg->LocalToDet(x,z,ix,iz))) continue; // outside
             el  = res->GeVToCharge((Double_t)de);
             sig = res->SigmaDiffusion1D(TMath::Abs(thick + y));
-            // SpreadCharge(x,z,ix,iz,el,sig,idtrack,h);
             sigx=sig;
             sigz=sig*fda;
-            SpreadChargeAsym(x,z,ix,iz,el,sigx,sigz,idtrack,h);
+            if (fLorentz) ld=(y+thick)*fTanLorAng;
+            SpreadChargeAsym(x,z,ix,iz,el,sigx,sigz,ld,idtrack,h);
         } // end if st>0.0
+
+    } // Loop over all hits h
+
         // Coupling
         switch (fCoupling) {
         default:
             break;
         case 1: //case 3:
-            // x is column and z is row (see AliITSsegmentationSPD::GetPadIxz)
             for(i=0;i<GetMap()->GetEntries();i++) 
                 if(GetMap()->GetpListItem(i)==0) continue;
                 else{
-                    GetMap()->GetMapIndex(
-                              GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
+                    GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
                     SetCoupling(iz,ix,idtrack,h);
                 } // end for i
             break;
         case 2: // case 4:
-            // x is column and z is row (see AliITSsegmentationSPD::GetPadIxz)
             for(i=0;i<GetMap()->GetEntries();i++) 
                 if(GetMap()->GetpListItem(i)==0) continue;
                 else{
-                    GetMap()->GetMapIndex(
-                                GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
+                    GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
                     SetCouplingOld(iz,ix,idtrack,h);
                 } // end for i
             break;
         } // end switch
-    } // Loop over all hits h
     if(GetDebug(2))Info("HitToSDigit","Finished fCoupling=%d",fCoupling);
 }
 //______________________________________________________________________
@@ -420,12 +439,12 @@ void AliITSsimulationSPD::HitToSDigitFast(AliITSmodule *mod){
     // Return:
     //    none.
     const Double_t kmictocm = 1.0e-4; // convert microns to cm.
-    const Int_t n10=10;
-    const Double_t ti[n10]={7.443716945e-3,2.166976971e-1,3.397047841e-1,
+    const Int_t kn10=10;
+    const Double_t kti[kn10]={7.443716945e-3,2.166976971e-1,3.397047841e-1,
                             4.325316833e-1,4.869532643e-1,5.130467358e-1,
                             5.674683167e-1,6.602952159e-1,7.833023029e-1,
                             9.255628306e-1};
-    const Double_t wi[n10]={1.477621124e-1,1.346333597e-1,1.095431813e-1,
+    const Double_t kwi[kn10]={1.477621124e-1,1.346333597e-1,1.095431813e-1,
                             7.472567455e-2,3.333567215e-2,3.333567215e-2,
                             7.472567455e-2,1.095431813e-1,1.346333597e-1,
                             1.477621124e-1};
@@ -433,7 +452,7 @@ void AliITSsimulationSPD::HitToSDigitFast(AliITSmodule *mod){
     Int_t nhits = hits->GetEntriesFast();
     Int_t h,ix,iz,i;
     Int_t idtrack;
-    Double_t x0=0.0,x1=0.0,y0=0.0,y1=0.0,z0=0.0,z1=0.0,de=0.0;
+    Double_t x0=0.0,x1=0.0,y0=0.0,y1=0.0,z0=0.0,z1=0.0,de=0.0,ld=0.0;
     Double_t x,y,z,t,st,el,sig,sigx,sigz,fda;
     AliITSsegmentationSPD* seg = (AliITSsegmentationSPD*)GetSegmentationModel(0);
     AliITSCalibrationSPD* res = (AliITSCalibrationSPD*)GetCalibrationModel(fDetType->GetITSgeom()->GetStartSPD());
@@ -451,25 +470,25 @@ void AliITSsimulationSPD::HitToSDigitFast(AliITSmodule *mod){
       } // end if GetDebug
         if(!mod->LineSegmentL(h,x0,x1,y0,y1,z0,z1,de,idtrack)) continue;
         st = TMath::Sqrt(x1*x1+y1*y1+z1*z1);
-        if(st>0.0) for(i=0;i<n10;i++){ // Integrate over t
-            t   = ti[i];
+        if(st>0.0) for(i=0;i<kn10;i++){ // Integrate over t
+            t   = kti[i];
             x   = x0+x1*t;
             y   = y0+y1*t;
             z   = z0+z1*t;
                 if(!(seg->LocalToDet(x,z,ix,iz))) continue; // outside
                 // el  = res->GeVToCharge((Double_t)(dt*de));
-                // el  = 1./n10*res->GeVToCharge((Double_t)de);
-                el  = wi[i]*res->GeVToCharge((Double_t)de); 
+                // el  = 1./kn10*res->GeVToCharge((Double_t)de);
+                el  = kwi[i]*res->GeVToCharge((Double_t)de); 
                 if(GetDebug(1)){
-                    if(el<=0.0) cout<<"el="<<el<<" wi["<<i<<"]="<<wi[i]
+                    if(el<=0.0) cout<<"el="<<el<<" kwi["<<i<<"]="<<kwi[i]
                                     <<" de="<<de<<endl;
                 } // end if GetDebug
                 sig = res->SigmaDiffusion1D(TMath::Abs(thick + y));
                 sigx=sig;
                 sigz=sig*fda;
-                //SpreadCharge(x,z,ix,iz,el,sig,idtrack,h);
-                SpreadChargeAsym(x,z,ix,iz,el,sigx,sigz,idtrack,h);
-                // cout << "sigx sigz " << sigx << " " << sigz << endl; // dom
+                if (fLorentz) ld=(y+thick)*fTanLorAng;
+                SpreadChargeAsym(x,z,ix,iz,el,sigx,sigz,ld,idtrack,h);
+//                cout << "sigx sigz " << sigx << " " << sigz << endl; // dom
             } // end for i // End Integrate over t
         else { // st == 0.0 deposit it at this point
             x   = x0;
@@ -478,55 +497,55 @@ void AliITSsimulationSPD::HitToSDigitFast(AliITSmodule *mod){
             if(!(seg->LocalToDet(x,z,ix,iz))) continue; // outside
             el  = res->GeVToCharge((Double_t)de);
             sig = res->SigmaDiffusion1D(TMath::Abs(thick + y));
-            //SpreadCharge(x,z,ix,iz,el,sig,idtrack,h);
             sigx=sig;
             sigz=sig*fda;
-            SpreadChargeAsym(x,z,ix,iz,el,sigx,sigz,idtrack,h);
+            if (fLorentz) ld=(y+thick)*fTanLorAng;
+            SpreadChargeAsym(x,z,ix,iz,el,sigx,sigz,ld,idtrack,h);
         } // end if st>0.0
+
+    } // Loop over all hits h
+
         // Coupling
         switch (fCoupling) {
         default:
             break;
         case 1: // case 3:
-            // x is column and z is row (see AliITSsegmentationSPD::GetPadIxz)
             for(i=0;i<GetMap()->GetEntries();i++)
                 if(GetMap()->GetpListItem(i)==0) continue;
                 else{
-                    GetMap()->GetMapIndex(
-                              GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
+                    GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
                     SetCoupling(iz,ix,idtrack,h);
                 } // end for i
             break;
         case 2: // case 4:
-            // x is column and z is row (see AliITSsegmentationSPD::GetPadIxz)
             for(i=0;i<GetMap()->GetEntries();i++)
                 if(GetMap()->GetpListItem(i)==0) continue;
                 else{
-                    GetMap()->GetMapIndex(
-                                GetMap()->GetpListItem(i)->GetIndex(),iz,ix);                    SetCouplingOld(iz,ix,idtrack,h);
+                    GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);  
+                    SetCouplingOld(iz,ix,idtrack,h);
                 } // end for i
             break;
         } // end switch
-    } // Loop over all hits h
     if(GetDebug(2))Info("HitToSDigit","Finished fCoupling=%d",fCoupling);
 }
 //______________________________________________________________________
 void AliITSsimulationSPD::SpreadCharge(Double_t x0,Double_t z0,
                                             Int_t ix0,Int_t iz0,
-                                           Double_t el,Double_t sig,Int_t t,
-                                           Int_t hi){
+                                           Double_t el,Double_t sig,Double_t ld,
+                                           Int_t t,Int_t hi){
     // Spreads the charge over neighboring cells. Assume charge is distributed
     // as charge(x,z) = (el/2*pi*sig*sig)*exp(-arg)
     // arg=((x-x0)*(x-x0)/2*sig*sig)+((z-z0*z-z0)/2*sig*sig)
+    // if fLorentz=kTRUE, then x0=x0+ld (Lorentz drift taken into account)
     // Defined this way, the integral over all x and z is el.
     // Inputs:
     //    Double_t x0   x position of point where charge is liberated
-    //    Double_t y0   y position of point where charge is liberated
     //    Double_t z0   z position of point where charge is liberated
     //    Int_t    ix0  row of cell corresponding to point x0
     //    Int_t    iz0  columb of cell corresponding to point z0
     //    Double_t el   number of electrons liberated in this step
     //    Double_t sig  Sigma difusion for this step (y0 dependent)
+    //    Double_t ld   lorentz drift in x for this step (y0 dependent)
     //    Int_t    t    track number
     //    Int_t    ti   hit track index number
     //    Int_t    hi   hit "hit" index number
@@ -568,8 +587,8 @@ void AliITSsimulationSPD::SpreadCharge(Double_t x0,Double_t z0,
         x1 -= 0.5*kmictocm*seg->Dpx(ix);  // Lower
         z2  = z1 + 0.5*kmictocm*seg->Dpz(iz); // Upper
         z1 -= 0.5*kmictocm*seg->Dpz(iz);  // Lower
-        x1 -= x0; // Distance from where track traveled
-        x2 -= x0; // Distance from where track traveled
+        x1 -= x0+ld; // Distance from where track traveled (taking into account the Lorentz drift)
+        x2 -= x0+ld; // Distance from where track traveled (taking into account the Lorentz drift)
         z1 -= z0; // Distance from where track traveled
         z2 -= z0; // Distance from where track traveled
         s   = 0.25; // Correction based on definision of Erfc
@@ -590,20 +609,21 @@ void AliITSsimulationSPD::SpreadCharge(Double_t x0,Double_t z0,
 void AliITSsimulationSPD::SpreadChargeAsym(Double_t x0,Double_t z0,
                                             Int_t ix0,Int_t iz0,
                                             Double_t el,Double_t sigx,Double_t sigz,
-                                            Int_t t,Int_t hi){
+                                            Double_t ld,Int_t t,Int_t hi){
     // Spreads the charge over neighboring cells. Assume charge is distributed
     // as charge(x,z) = (el/2*pi*sigx*sigz)*exp(-arg)
     // arg=((x-x0)*(x-x0)/2*sigx*sigx)+((z-z0*z-z0)/2*sigz*sigz)
+    // if fLorentz=kTRUE, then x0=x0+ld (Lorentz drift taken into account)
     // Defined this way, the integral over all x and z is el.
     // Inputs:
     //    Double_t x0   x position of point where charge is liberated
-    //    Double_t y0   y position of point where charge is liberated
     //    Double_t z0   z position of point where charge is liberated
     //    Int_t    ix0  row of cell corresponding to point x0
     //    Int_t    iz0  columb of cell corresponding to point z0
     //    Double_t el   number of electrons liberated in this step
     //    Double_t sigx Sigma difusion along x for this step (y0 dependent)
     //    Double_t sigz Sigma difusion along z for this step (y0 dependent)
+    //    Double_t ld   lorentz drift in x for this stip (y0 dependent)
     //    Int_t    t    track number
     //    Int_t    ti   hit track index number
     //    Int_t    hi   hit "hit" index number
@@ -620,7 +640,7 @@ void AliITSsimulationSPD::SpreadChargeAsym(Double_t x0,Double_t z0,
     AliITSsegmentationSPD* seg = (AliITSsegmentationSPD*)GetSegmentationModel(0);
 
 
-    if(GetDebug(4)) Info("SpreadCharge","(x0=%e,z0=%e,ix0=%d,iz0=%d,el=%e,"
+    if(GetDebug(4)) Info("SpreadChargeAsym","(x0=%e,z0=%e,ix0=%d,iz0=%d,el=%e,"
                          "sig=%e,t=%d,i=%d)",x0,z0,ix0,iz0,el,sigx,sigz,t,hi);
     if(sigx<=0.0 || sigz<=0.0) { // if sig<=0 No diffusion to simulate.
         GetMap()->AddSignal(iz0,ix0,t,hi,GetModuleNumber(),el);
@@ -647,8 +667,8 @@ void AliITSsimulationSPD::SpreadChargeAsym(Double_t x0,Double_t z0,
         x1 -= 0.5*kmictocm*seg->Dpx(ix);  // Lower
         z2  = z1 + 0.5*kmictocm*seg->Dpz(iz); // Upper
         z1 -= 0.5*kmictocm*seg->Dpz(iz);  // Lower
-        x1 -= x0; // Distance from where track traveled
-        x2 -= x0; // Distance from where track traveled
+        x1 -= x0+ld; // Distance from where track traveled (taking into account the Lorentz drift)
+        x2 -= x0+ld; // Distance from where track traveled (taking into account the Lorentz drift)
         z1 -= z0; // Distance from where track traveled
         z2 -= z0; // Distance from where track traveled
         s   = 0.25; // Correction based on definision of Erfc
@@ -667,14 +687,28 @@ void AliITSsimulationSPD::SpreadChargeAsym(Double_t x0,Double_t z0,
 }
 //______________________________________________________________________
 void AliITSsimulationSPD::RemoveDeadPixels(AliITSmodule *mod){
-  Int_t module_nr = mod->GetIndex();
-  Int_t nr_dead = calObj[module_nr]->GetNrDead();
-  for (Int_t i=0; i<nr_dead; i++) {
-    GetMap()->DeleteHit(calObj[module_nr]->GetDeadColAt(i),calObj[module_nr]->GetDeadRowAt(i));
+    //    Removes dead pixels on each module (ladder)
+    // Inputs:
+    //    Module Index (0,239)
+    // Outputs:
+    //    none.
+    // Return:
+    //    none.
+
+  Int_t moduleNr = mod->GetIndex();
+  AliITSCalibrationSPD* calObj = (AliITSCalibrationSPD*) GetCalibrationModel(moduleNr);
+
+  Int_t nrDead = calObj->GetNrBad();
+//  cout << "Module --> " << moduleNr << endl; // dom
+//  cout << "nr of dead " << nrDead << endl; // dom
+  for (Int_t i=0; i<nrDead; i++) {
+    GetMap()->DeleteHit(calObj->GetBadColAt(i),calObj->GetBadRowAt(i));
+//    cout << "dead index " << i << endl; // dom
+//    cout << "col row --> " << calObj->GetDeadColAt(i) << " " << calObj->GetDeadRowAt(i) << endl; // dom
   }
 }
 //______________________________________________________________________
-void AliITSsimulationSPD::pListToDigits(){
+void AliITSsimulationSPD::FrompListToDigits(){
     // add noise and electronics, perform the zero suppression and add the
     // digit to the list
     // Inputs:
@@ -687,10 +721,10 @@ void AliITSsimulationSPD::pListToDigits(){
     Int_t j,ix,iz;
     Double_t  electronics;
     Double_t sig;
-    const Int_t    nmaxtrk=AliITSdigitSPD::GetNTracks();
+    const Int_t    knmaxtrk=AliITSdigit::GetNTracks();
     static AliITSdigitSPD dig;
     AliITSCalibrationSPD* res = (AliITSCalibrationSPD*)GetCalibrationModel(fDetType->GetITSgeom()->GetStartSPD());
-    if(GetDebug(1)) Info("pListToDigits","()");
+    if(GetDebug(1)) Info("FrompListToDigits","()");
     for(iz=0; iz<GetNPixelsZ(); iz++) for(ix=0; ix<GetNPixelsX(); ix++){
 // NEW (for the moment plugged by hand, in the future possibly read from Data Base)
 // here parametrize the efficiency of the pixel along the row for the test columns (1,9,17,25)
@@ -722,15 +756,18 @@ void AliITSsimulationSPD::pListToDigits(){
         dig.SetCoord1(iz);
         dig.SetCoord2(ix);
         dig.SetSignal(1);
-       Double_t aSignal =  GetMap()->GetSignal(iz,ix);
-       if (TMath::Abs(aSignal)>2147483647.0) { 
-         //PH 2147483647 is the max. integer
-         //PH This apparently is a problem which needs investigation
-         AliWarning(Form("Too big or too small signal value %f",aSignal));
-         aSignal = TMath::Sign((Double_t)2147483647,aSignal);
-       }
-       dig.SetSignalSPD((Int_t)aSignal); 
-        for(j=0;j<nmaxtrk;j++){
+
+//        dig.SetSignalSPD((Int_t) GetMap()->GetSignal(iz,ix));
+        Double_t aSignal =  GetMap()->GetSignal(iz,ix);
+        if (TMath::Abs(aSignal)>2147483647.0) {
+          //PH 2147483647 is the max. integer
+          //PH This apparently is a problem which needs investigation
+          AliWarning(Form("Too big or too small signal value %f",aSignal));
+          aSignal = TMath::Sign((Double_t)2147483647,aSignal);
+        }
+        dig.SetSignalSPD((Int_t)aSignal);
+
+        for(j=0;j<knmaxtrk;j++){
             if (j<GetMap()->GetNEntries()) {
                 dig.SetTrack(j,GetMap()->GetTrack(iz,ix,j));
                 dig.SetHit(j,GetMap()->GetHit(iz,ix,j));
@@ -799,7 +836,7 @@ void AliITSsimulationSPD::ResetHistograms(){
 }
 
 //______________________________________________________________________
-void AliITSsimulationSPD::SetCoupling(Int_t row, Int_t col, Int_t ntrack,
+void AliITSsimulationSPD::SetCoupling(Int_t col, Int_t row, Int_t ntrack,
                                      Int_t idhit) {
     //  Take into account the coupling between adiacent pixels.
     //  The parameters probcol and probrow are the probability of the
@@ -819,8 +856,8 @@ void AliITSsimulationSPD::SetCoupling(Int_t row, Int_t col, Int_t ntrack,
     */
     //End_Html
     // Inputs:
-    //    Int_t row            z cell index
-    //    Int_t col            x cell index
+    //    Int_t col            z cell index
+    //    Int_t row            x cell index
     //    Int_t ntrack         track incex number
     //    Int_t idhit          hit index number
     // Outputs:
@@ -833,39 +870,35 @@ void AliITSsimulationSPD::SetCoupling(Int_t row, Int_t col, Int_t ntrack,
     Double_t xr=0.;
 
     GetCouplings(couplC,couplR);
-    if(GetDebug(3)) Info("SetCoupling","(row=%d,col=%d,ntrack=%d,idhit=%d) "
-                         "Calling SetCoupling couplR=%e couplC=%e",
-                         row,col,ntrack,idhit,couplR,couplC);
-    j1 = row;
-    j2 = col;
-    pulse1 = GetMap()->GetSignalOnly(row,col);
+    if(GetDebug(3)) Info("SetCoupling","(col=%d,row=%d,ntrack=%d,idhit=%d) "
+                         "Calling SetCoupling couplC=%e couplR=%e",
+                         col,row,ntrack,idhit,couplC,couplR);
+    j1 = col;
+    j2 = row;
+    pulse1 = GetMap()->GetSignalOnly(col,row);
     pulse2 = pulse1;
-    for (Int_t isign=-1;isign<=1;isign+=2){// loop in row direction
+    for (Int_t isign=-1;isign<=1;isign+=2){// loop in col direction
         do{
             j1 += isign;
-            //   pulse1 *= couplR; 
             xr = gRandom->Rndm();
-            //if ((j1<0)||(j1>GetNPixelsZ()-1)||(pulse1<GetThreshold())){
-            if ((j1<0) || (j1>GetNPixelsZ()-1) || (xr>couplR)){
-                j1 = row;
+            if ((j1<0) || (j1>GetNPixelsZ()-1) || (xr>couplC)){
+                j1 = col;
                 flag = 1;
             }else{
-                UpdateMapSignal(col,j1,ntrack,idhit,pulse1);
+                UpdateMapSignal(row,j1,ntrack,idhit,pulse1);
                 //  flag = 0;
                 flag = 1; // only first next!!
             } // end if
         } while(flag == 0);
-        // loop in column direction
+        // loop in row direction
         do{
             j2 += isign;
-            // pulse2 *= couplC; 
             xr = gRandom->Rndm();
-            //if((j2<0)||j2>(GetNPixelsX()-1)||pulse2<GetThreshold()){
-            if ((j2<0) || (j2>GetNPixelsX()-1) || (xr>couplC)){
-                j2 = col;
+            if ((j2<0) || (j2>GetNPixelsX()-1) || (xr>couplR)){
+                j2 = row;
                 flag = 1;
             }else{
-                UpdateMapSignal(j2,row,ntrack,idhit,pulse2);
+                UpdateMapSignal(j2,col,ntrack,idhit,pulse2);
                 //  flag = 0;
                 flag = 1; // only first next!!
             } // end if
@@ -873,7 +906,7 @@ void AliITSsimulationSPD::SetCoupling(Int_t row, Int_t col, Int_t ntrack,
     } // for isign
 }
 //______________________________________________________________________
-void AliITSsimulationSPD::SetCouplingOld(Int_t row, Int_t col,
+void AliITSsimulationSPD::SetCouplingOld(Int_t col, Int_t row,
                 Int_t ntrack,Int_t idhit) {
     //  Take into account the coupling between adiacent pixels.
     //  The parameters probcol and probrow are the fractions of the
@@ -891,8 +924,8 @@ void AliITSsimulationSPD::SetCouplingOld(Int_t row, Int_t col,
     */
     //End_Html
     // Inputs:
-    //    Int_t row            z cell index
-    //    Int_t col            x cell index
+    //    Int_t col            z cell index
+    //    Int_t row            x cell index
     //    Int_t ntrack         track incex number
     //    Int_t idhit          hit index number
     //    Int_t module         module number
@@ -908,40 +941,39 @@ void AliITSsimulationSPD::SetCouplingOld(Int_t row, Int_t col,
 
     //  Debugging ...
 //    cout << "Threshold --> " << GetThreshold() << endl;  // dom
-//    cout << "Couplings --> " << couplC << " " << couplR << endl;  //dom
-
+//    cout << "Couplings --> " << couplC << " " << couplR << endl;  // dom
 
-    if(GetDebug(3)) Info("SetCouplingOld","(row=%d,col=%d,ntrack=%d,idhit=%d) "
-                         "Calling SetCoupling couplR=%e couplC=%e",
-                         row,col,ntrack,idhit,couplR,couplC);
-    for (Int_t isign=-1;isign<=1;isign+=2){// loop in row direction
-    pulse1 = GetMap()->GetSignalOnly(row,col);
+    if(GetDebug(3)) Info("SetCouplingOld","(col=%d,row=%d,ntrack=%d,idhit=%d) "
+                         "Calling SetCoupling couplC=%e couplR=%e",
+                         col,row,ntrack,idhit,couplC,couplR);
+    for (Int_t isign=-1;isign<=1;isign+=2){// loop in col direction
+    pulse1 = GetMap()->GetSignalOnly(col,row);
     pulse2 = pulse1;
-    j1 = row;
-    j2 = col;
+    j1 = col;
+    j2 = row;
         do{
             j1 += isign;
-            pulse1 *= couplR;
+            pulse1 *= couplC;
             if ((j1<0)||(j1>GetNPixelsZ()-1)||(pulse1<GetThreshold())){
-                pulse1 = GetMap()->GetSignalOnly(row,col);
-                j1 = row;
+                pulse1 = GetMap()->GetSignalOnly(col,row);
+                j1 = col;
                 flag = 1;
             }else{
-                UpdateMapSignal(col,j1,ntrack,idhit,pulse1);
+                UpdateMapSignal(row,j1,ntrack,idhit,pulse1);
                 // flag = 0;
                 flag = 1;  // only first next !!
             } // end if
         } while(flag == 0);
-        // loop in column direction
+        // loop in row direction
         do{
             j2 += isign;
-            pulse2 *= couplC;
+            pulse2 *= couplR;
             if((j2<0)||(j2>(GetNPixelsX()-1))||(pulse2<GetThreshold())){
-                pulse2 = GetMap()->GetSignalOnly(row,col);
-                j2 = col;
+                pulse2 = GetMap()->GetSignalOnly(col,row);
+                j2 = row;
                 flag = 1;
             }else{
-                UpdateMapSignal(j2,row,ntrack,idhit,pulse2);
+                UpdateMapSignal(j2,col,ntrack,idhit,pulse2);
                 // flag = 0;
                 flag = 1; // only first next!!
             } // end if