]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSsimulationSPDdubna.cxx
First commit.
[u/mrichter/AliRoot.git] / ITS / AliITSsimulationSPDdubna.cxx
index 3326d96b455fa168ebff460b2de6fb069f45c105..ac18a05c177a482c343bada2fdffb64c08e49d09 100644 (file)
@@ -1,23 +1,56 @@
-#include <iostream.h>
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/*
+$Log$
+Revision 1.9  2002/10/22 14:45:45  alibrary
+Introducing Riostream.h
+
+Revision 1.8  2002/10/14 14:57:08  hristov
+Merging the VirtualMC branch to the main development branch (HEAD)
+
+Revision 1.3.8.2  2002/10/14 13:14:08  hristov
+Updating VirtualMC to v3-09-02
+
+Revision 1.7  2002/09/09 17:23:28  nilsen
+Minor changes in support of changes to AliITSdigitS?D class'.
+
+Revision 1.6  2002/08/21 22:09:58  nilsen
+Updated SPD simulation with difusion effects. ReWritten Hit to SDigits
+code.
+
+*/
+#include <Riostream.h>
 #include <TRandom.h>
 #include <TH1.h>
 #include <TMath.h>
 #include <TString.h>
 #include <TParticle.h>
 
-
 #include "AliRun.h"
 #include "AliITS.h"
 #include "AliITShit.h"
 #include "AliITSdigit.h"
 #include "AliITSmodule.h"
 #include "AliITSMapA2.h" 
+#include "AliITSpList.h"
 #include "AliITSsimulationSPDdubna.h"
-#include "AliITSsegmentation.h"
-#include "AliITSresponse.h"
-
-
+#include "AliITSsegmentationSPD.h"
+#include "AliITSresponseSPDdubna.h"
 
+//#define DEBUG
 
 ClassImp(AliITSsimulationSPDdubna)
 ////////////////////////////////////////////////////////////////////////
@@ -26,117 +59,508 @@ ClassImp(AliITSsimulationSPDdubna)
 // December 20 1999
 //
 // AliITSsimulationSPDdubna is the simulation of SPDs
-//________________________________________________________________________
-
-
-AliITSsimulationSPDdubna::AliITSsimulationSPDdubna()
-{
-  // constructor
-  fResponse = 0;
-  fSegmentation = 0;
-  fMapA2=0;
-  fHis = 0;
-  fNoise=0.;
-  fBaseline=0.;
-  fNPixelsZ=0;
-  fNPixelsX=0;
+//______________________________________________________________________
+
+
+AliITSsimulationSPDdubna::AliITSsimulationSPDdubna(){
+    // constructor
+
+    fResponse = 0;
+    fSegmentation = 0;
+    fMapA2 = 0;
+    fpList = 0;
+    fModule = 0;
+    fEvent = 0;
+    fHis = 0;
+    fNoise = 0.;
+    fBaseline = 0.;
+    fNPixelsZ = 0;
+    fNPixelsX = 0;
 }
+//______________________________________________________________________
+AliITSsimulationSPDdubna::AliITSsimulationSPDdubna(AliITSsegmentation *seg,
+                                                  AliITSresponse *resp){
+    // standard constructor
+    const Double_t kmictocm = 1.0e-4; // convert microns to cm.
 
+    fHis = 0;
+    fResponse = resp;
+    fSegmentation = seg;
+    fModule = 0;
+    fEvent = 0;
 
-//_____________________________________________________________________________
-
-AliITSsimulationSPDdubna::AliITSsimulationSPDdubna(AliITSsegmentation *seg, AliITSresponse *resp) {
-  // standard constructor
+    fNPixelsZ=GetSeg()->Npz();
+    fNPixelsX=GetSeg()->Npx();
 
-      fHis = 0;
-      fResponse = resp;
-      fSegmentation = seg;
+    GetResp()->GetNoiseParam(fNoise,fBaseline);
+    GetResp()->SetDistanceOverVoltage(kmictocm*GetSeg()->Dy(),50.0);
 
-      fResponse->GetNoiseParam(fNoise,fBaseline);
+//    fMapA2 = new AliITSMapA2(GetSeg());
+    fMapA2 = 0;
 
-      fMapA2 = new AliITSMapA2(fSegmentation);
-
-      //
-
-      fNPixelsZ=fSegmentation->Npz();
-      fNPixelsX=fSegmentation->Npx();
+    fpList = new AliITSpList(fNPixelsZ+1,fNPixelsX+1);
 
 }
+//______________________________________________________________________
+AliITSsimulationSPDdubna::~AliITSsimulationSPDdubna(){
+    // destructor
 
-//_____________________________________________________________________________
-
-AliITSsimulationSPDdubna::~AliITSsimulationSPDdubna() { 
-  // destructor
+    if(fMapA2) delete fMapA2;
 
-  delete fMapA2;
+    if (fHis) {
+       fHis->Delete(); 
+       delete fHis;     
+    } // end if fHis
+}
+//______________________________________________________________________
+AliITSsimulationSPDdubna::AliITSsimulationSPDdubna(const 
+                                                  AliITSsimulationSPDdubna 
+                                                  &source){
+    //     Copy Constructor 
+    if(&source == this) return;
+    this->fMapA2 = source.fMapA2;
+    this->fNoise = source.fNoise;
+    this->fBaseline = source.fBaseline;
+    this->fNPixelsX = source.fNPixelsX;
+    this->fNPixelsZ = source.fNPixelsZ;
+    this->fHis = source.fHis;
+    return;
+}
+//______________________________________________________________________
+AliITSsimulationSPDdubna&  AliITSsimulationSPDdubna::operator=(const 
+                                           AliITSsimulationSPDdubna &source){
+    //    Assignment operator
+    if(&source == this) return *this;
+    this->fMapA2 = source.fMapA2;
+    this->fNoise = source.fNoise;
+    this->fBaseline = source.fBaseline;
+    this->fNPixelsX = source.fNPixelsX;
+    this->fNPixelsZ = source.fNPixelsZ;
+    this->fHis = source.fHis;
+    return *this;
+}
+//______________________________________________________________________
+void AliITSsimulationSPDdubna::InitSimulationModule(Int_t module, Int_t event){
+    //  This function creates maps to build the list of tracks for each
+    //  summable digit.
+    //
+    //  Inputs:
+    //    Int_t module   // Module number to be simulated
+    //    Int_t event    // Event number to be simulated
+    //
+    //  Outputs:
+    //    none
+    //
+    //  Returns:
+    //    none
 
-  if (fHis) {
-     fHis->Delete(); 
-     delete fHis;     
-  }                
+    fModule = module;
+    fEvent  = event;
+//    fMapA2->ClearMap();
+    fpList->ClearMap();
 }
+//_____________________________________________________________________
+void AliITSsimulationSPDdubna::SDigitiseModule(AliITSmodule *mod, Int_t mask,
+                                              Int_t event){
+    //  This function begins the work of creating S-Digits
+    //
+    //  Inputs:
+    //    AliITSmodule *mod  //  module
+    //    Int_t mask         //  mask to be applied to the module
+    //
+    //  Outputs:
+    //    none
+    //
+    //  Return:
+    //    test              //  test returns kTRUE if the module contained hits
+    //                      //  test returns kFALSE if it did not contain hits
+
+    Int_t module = 0;
+
+    if(!(mod->GetNhits())) return;// if module has no hits don't create Sdigits
+    fModule = mod->GetIndex();
+    HitToSDigit(mod, module, mask, fpList);
+    WriteSDigits(fpList);
+//    fMapA2->ClearMap();
+    fpList->ClearMap();
+}
+//______________________________________________________________________
+void AliITSsimulationSPDdubna::WriteSDigits(AliITSpList *pList){
+    //  This function adds each S-Digit to pList
+    //
+    //  Inputs:
+    //    AliITSpList *pList
+    //
+    //  Outputs:
+    //    none
+    //
+    //  Return:
+    //    none
+    Int_t ix, nix, iz, niz;
+    static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
+
+    pList->GetMaxMapIndex(niz, nix);
+    for(iz=0; iz<niz-1; iz++)for(ix=0; ix<nix-1; ix++){
+       if(pList->GetSignalOnly(iz+1,ix+1)>0.0){
+           aliITS->AddSumDigit(*(pList->GetpListItem(iz+1,ix+1)));
+#ifdef DEBUG
+           cout <<"SDigits " << iz << "," << ix << "," << 
+               *(pList->GetpListItem(iz+1,ix+1)) << endl;
+#endif
+       } // end if pList
+    } // end for iz,ix
+    return; 
+}
+//______________________________________________________________________
+void AliITSsimulationSPDdubna::FinishSDigitiseModule(){
+    //  This function calls SDigitsToDigits which creates Digits from SDigits
+    //
+    //  Inputs:
+    //    none
+    //
+    //  Outputs:
+    //    none
+    //  Return
+    //    none
 
+    SDigitsToDigits(fModule, fpList);
+    return;
+}
+//______________________________________________________________________
+void AliITSsimulationSPDdubna::SDigitsToDigits(Int_t module,
+                                              AliITSpList *pList){
+    //  This function adds electronic noise to the S-Digits and then adds them
+    // to  a new pList
+    //
+    //  Inputs:
+    //    Int_t       module  // module number
+    //    AliITSpList *pList  // pList
+    //
+    //  Outputs:
+    //    pList is passed along to the functions ChargeToSignal and GetList
+    //
+    //  Return:
+    //    none
 
-//__________________________________________________________________________
-AliITSsimulationSPDdubna::AliITSsimulationSPDdubna(const AliITSsimulationSPDdubna &source){
-  //     Copy Constructor 
-  if(&source == this) return;
-  this->fMapA2 = source.fMapA2;
-  this->fNoise = source.fNoise;
-  this->fBaseline = source.fBaseline;
-  this->fNPixelsX = source.fNPixelsX;
-  this->fNPixelsZ = source.fNPixelsZ;
-  this->fHis = source.fHis;
-  return;
+    fModule = module;
+    ChargeToSignal(pList); // Charge To Signal both adds noise and
+//    fMapA2->ClearMap();
+    pList->ClearMap();
 }
+//______________________________________________________________________
+void AliITSsimulationSPDdubna::DigitiseModule(AliITSmodule *mod, Int_t module,
+                                             Int_t dummy){
+    //  This function creates Digits straight from the hits and then adds
+    //  electronic noise to the digits before adding them to pList
+    //
+    //  Inputs:
+    //    AliITSmodule *mod    // module
+    //    Int_t        module  // module number  Dummy.
+    //    Int_t        dummy
+    //
+    //  Outputs:
+    //    Each of the input variables is passed along to HitToSDigit
+    //
+    //  Return:
+    //    none
+
+    fModule = mod->GetIndex();  //This calls the module for HitToSDigit
+    HitToSDigit(mod,fModule, dummy, fpList);
+    ChargeToSignal(fpList);
+//    fMapA2->ClearMap();
+    fpList->ClearMap();
+}
+//______________________________________________________________________
+void AliITSsimulationSPDdubna::UpdateMapSignal(Int_t iz, Int_t ix, Int_t trk,
+                                              Int_t ht, Int_t module,
+                                              Double_t signal,
+                                              AliITSpList *pList){
+    //  This function adds a signal to the pList from the pList class
+    //
+    //  Inputs:
+    //    Int_t       iz     // row number
+    //    Int_t       ix     // column number
+    //    Int_t       trk    // track number
+    //    Int_t       ht     // hit number
+    //    Double_t    signal // signal strength
+    //    AliITSpList *pList // pList
+    //
+    //  Outputs:
+    //    All of the inputs are passed to AliITSpList::AddSignal
+    //    Int_t    ix  // row number
+    //    Int_t    iz  // column number
+    //    Double_t sig // signal strength
+    //          // These three variables are defined to preserve the
+    //          // assignments used in the function AliITSMapA2::AddSignal
+    //
+    //  Return:
+    //    none
 
-//_________________________________________________________________________
-AliITSsimulationSPDdubna& 
-  AliITSsimulationSPDdubna::operator=(const AliITSsimulationSPDdubna &source) {
-  //    Assignment operator
-  if(&source == this) return *this;
-  this->fMapA2 = source.fMapA2;
-  this->fNoise = source.fNoise;
-  this->fBaseline = source.fBaseline;
-  this->fNPixelsX = source.fNPixelsX;
-  this->fNPixelsZ = source.fNPixelsZ;
-  this->fHis = source.fHis;
-  return *this;
-  }
-//_____________________________________________________________________________
-
-void AliITSsimulationSPDdubna::DigitiseModule(AliITSmodule *mod, Int_t module, Int_t dummy)
-{
-  // digitize module
+//    fMapA2->AddSignal(iz, ix, signal);
+    pList->AddSignal(iz+1,ix+1, trk, ht, fModule, signal);
+}
+//______________________________________________________________________
+void AliITSsimulationSPDdubna::UpdateMapNoise(Int_t iz,
+                                             Int_t ix, Int_t fModule,
+                                             Double_t sig, Float_t noise,
+                                             AliITSpList *pList){
+    //  This function adds noise to data in the MapA2 as well as the pList
+    //
+    //  Inputs:
+    //    Int_t       iz       // row number
+    //    Int_t       ix       // column number
+    //    Int_t       mod     // module number
+    //    Double_t    sig     // signal strength
+    //    Double_t    noise   // electronic noise generated by ChargeToSignal
+    //    AliITSpList *pList  // pList
+    //
+    //  Outputs:
+    //    All of the inputs are passed to AliITSMapA2::AddSignal or
+    //    AliITSpList::AddNoise
+    //
+    //  Return:
+    //    none
 
+//    fMapA2->AddSignal(iz, ix, noise);
+    pList->AddNoise(iz+1,ix+1, fModule, noise);
+}
+//______________________________________________________________________
+void AliITSsimulationSPDdubna::HitToDigit(AliITSmodule *mod, Int_t module,
+                                         Int_t dummy){
+    DigitiseModule(mod, module, dummy);
+}
+//______________________________________________________________________
+void AliITSsimulationSPDdubna::HitToSDigit(AliITSmodule *mod, Int_t module,
+                                           Int_t dummy,AliITSpList *pList){
+    // Does the charge distributions using Gaussian diffusion charge charing.
+    const Double_t kmictocm = 1.0e-4; // convert microns to cm.
+    TObjArray *hits = mod->GetHits();
+    Int_t nhits = hits->GetEntriesFast();
+    Int_t h,ix,iz;
+    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 x,y,z,t,tp,st,dt=0.2,el,sig;
+    Double_t thick = kmictocm*GetSeg()->Dy();
+
+    if(nhits<=0) return;
+    for(h=0;h<nhits;h++){
+#ifdef DEBUG
+       cout << "Hits=" << h << "," << *(mod->GetHit(h)) << endl;
+#endif
+       if(mod->LineSegmentL(h,x0,x1,y0,y1,z0,z1,de,idtrack)){
+       st =TMath::Sqrt(x1*x1+y1*y1+z1*z1);
+       if(st>0.0){
+           st = (Double_t)((Int_t)(1.0E+04*st)); // number of microns
+           if(st<=0.0) st = 1.0;
+           dt = 1.0/st;
+           for(t=0;t<1.0;t+=dt){ // Integrate over t
+               tp = t+0.5*dt;
+               el = GetResp()->GeVToCharge((Float_t)(dt*de));
+#ifdef DEBUG
+               if(el<=0.0) cout << "el="<<el<<" dt="<<dt<<" de="<<de<<endl;
+#endif
+               x = x0+x1*tp;
+               y = y0+y1*tp;
+               z = z0+z1*tp;
+               GetSeg()->LocalToDet(x,z,ix,iz);
+               sig = GetResp()->SigmaDiffusion1D(thick + y);
+               SpreadCharge(x,y,z,ix,iz,el,sig,idtrack,
+                            mod->GetHitTrackIndex(h),h,mod->GetIndex());
+           } // end for t
+       } else { // st == 0.0 deposit it at this point
+           el = GetResp()->GeVToCharge((Float_t)de);
+           x = x0;
+           y = y0;
+           z = z0;
+           GetSeg()->LocalToDet(x,z,ix,iz);
+           sig = GetResp()->SigmaDiffusion1D(thick + y);
+           SpreadCharge(x,y,z,ix,iz,el,sig,
+                        idtrack,mod->GetHitTrackIndex(h),h,mod->GetIndex());
+       } // end if st>0.0
+    }} // Loop over all hits h
+}/*
+//______________________________________________________________________
+void AliITSsimulationSPDdubna::HitToSDigit(AliITSmodule *mod, Int_t module,
+                                           Int_t dummy,AliITSpList *pList){
+    // Does the charge distributions using Gaussian diffusion charge charing.
+    const Double_t kmictocm = 1.0e-4; // convert microns to cm.
+    TObjArray *hits = mod->GetHits();
+    Int_t nhits = hits->GetEntriesFast();
+    Int_t h,ix,iz,i,n;
+    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 x,y,z,*ta,t,tp,st,dt=0.2,el,sig;
+    Double_t thick = kmictocm*GetSeg()->Dy();
+
+    if(nhits<=0) return;
+    for(h=0;h<nhits;h++){
+#ifdef DEBUG
+       cout << "Hits=" << h << "," << *(mod->GetHit(h)) << endl;
+#endif
+       if(mod->LineSegmentL(h,x0,x1,y0,y1,z0,z1,de,idtrack)){
+       st =TMath::Sqrt(x1*x1+y1*y1+z1*z1);
+       if(st>0.0){
+           st =TMath::Sqrt(x1*x1+y1*y1+z1*z1)*(ta[i+1]-ta[i]);
+           ta = CreateFindCellEdges(x0,x1,z0,z1,n);
+           for(i=0;i<n-1;i++){
+               dt = TMath::Min((1.0E-4)/st,);
+               for(t=ta[i];t<ta[i+1];t+=dt){ // Integrate over t
+               tp = t+0.5*dt;
+               el = GetResp()->GeVToCharge((Float_t)(dt*de));
+#ifdef DEBUG
+               if(el<=0.0) cout << "el="<<el<<" dt="<<dt<<" de="<<de<<endl;
+#endif
+               x = x0+x1*tp;
+               y = y0+y1*tp;
+               z = z0+z1*tp;
+               GetSeg()->LocalToDet(x,z,ix,iz);
+               sig = GetResp()->SigmaDiffusion1D(thick + y);
+               SpreadCharge(x,y,z,ix,iz,el,sig,idtrack,
+                            mod->GetHitTrackIndex(h),h,mod->GetIndex());
+           } // end for t[i]
+           delete[] t;
+       } else { // st == 0.0 deposit it at this point
+           el = GetResp()->GeVToCharge((Float_t)de);
+           x = x0;
+           y = y0;
+           z = z0;
+           GetSeg()->LocalToDet(x,z,ix,iz);
+           sig = GetResp()->SigmaDiffusion1D(thick + y);
+           SpreadCharge(x,y,z,ix,iz,el,sig,
+                        idtrack,mod->GetHitTrackIndex(h),h,mod->GetIndex());
+       } // end if st>0.0
+    }} // Loop over all hits h
+    }*/
+//______________________________________________________________________
+void AliITSsimulationSPDdubna::SpreadCharge(Double_t x0,Double_t y0,
+                                           Double_t z0,Int_t ix0,Int_t iz0,
+                                           Double_t el,Double_t sig,Int_t t,
+                                           Int_t ti,Int_t hi,Int_t mod){
+    // 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)
+    // Defined this way, the integral over all x and z is el.
+    const Int_t knx = 3,knz = 2;
+    const Double_t kRoot2 = 1.414213562; // Sqrt(2).
+    const Double_t kmictocm = 1.0e-4; // convert microns to cm.
+    Int_t ix,iz,ixs,ixe,izs,ize;
+    Float_t x,z;
+    Double_t x1,x2,z1,z2,s,sp;
+
+    if(sig<=0.0) {
+       fpList->AddSignal(iz0+1,ix0+1,t,hi,mod,el);
+       return;
+    } // end if
+    sp = 1.0/(sig*kRoot2);
+#ifdef DEBUG
+    cout << "sig=" << sig << " sp=" << sp << endl;
+#endif
+    ixs = TMath::Max(-knx+ix0,0);
+    ixe = TMath::Min(knx+ix0,GetSeg()->Npx()-1);
+    izs = TMath::Max(-knz+iz0,0);
+    ize = TMath::Min(knz+iz0,GetSeg()->Npz()-1);
+    for(ix=ixs;ix<=ixe;ix++) for(iz=izs;iz<=ize;iz++){
+       GetSeg()->DetToLocal(ix,iz,x,z); // pixel center
+       x1 = x;
+       z1 = z;
+       x2  = x1 + 0.5*kmictocm*GetSeg()->Dpx(ix); // Upper
+       x1 -= 0.5*kmictocm*GetSeg()->Dpx(ix);  // Lower
+       z2  = z1 + 0.5*kmictocm*GetSeg()->Dpz(iz); // Upper
+       z1 -= 0.5*kmictocm*GetSeg()->Dpz(iz);  // Lower
+       x1 -= x0; // Distance from where track traveled
+       x2 -= x0; // Distance from where track traveled
+       z1 -= z0; // Distance from where track traveled
+       z2 -= z0; // Distance from where track traveled
+       s = 0.25; // Correction based on definision of Erfc
+       s *= TMath::Erfc(sp*x1) - TMath::Erfc(sp*x2);
+#ifdef DEBUG
+       cout << "el=" << el << " ix0=" << ix0 << " ix=" << ix << " x0="<< x <<
+           " iz0=" << iz0 << " iz=" << iz << " z0=" << z  << 
+           " sp*x1=" << sp*x1 <<" sp*x2=" << sp*x2 << " s=" << s;
+#endif
+       s *= TMath::Erfc(sp*z1) - TMath::Erfc(sp*z2);
+#ifdef DEBUG
+       cout << " sp*z1=" << sp*z1 <<" sp*z2=" << sp*z2 << " s=" << s << endl;
+#endif
+       fpList->AddSignal(iz+1,ix+1,t,hi,mod,s*el);
+    } // end for ix, iz
+}
+//______________________________________________________________________
+Double_t *AliITSsimulationSPDdubna::CreateFindCellEdges(Double_t x0,Double_t x1,
+                                             Double_t z0,Double_t z1,Int_t &n){
+    // Note: This function is a potensial source for a memory leak. The memory
+    // pointed to in its return, must be deleted.
+    // Inputs:
+    //    Double_t x0   The starting location of the track step in x
+    //    Double_t x1   The distance allong x for the track step
+    //    Double_t z0   The starting location of the track step in z
+    //    Double_t z1   The distance allong z for the track step
+    // Output:
+    //    Int)t &n      The size of the array returned. Minimal n=2.
+    // Return:
+    //    The pointer to the array of track steps.
+    Int_t ix0,ix1,ix,iz0,iz1,iz,i;
+    Double_t x,z,lx,ux,lz,uz,a,b,c,d;
+    Double_t *t;
+
+    GetSeg()->LocalToDet(x0,z0,ix0,iz0);
+    GetSeg()->LocalToDet(x1,z1,ix1,iz1);
+    n = 2 + TMath::Abs(ix1-ix0) + TMath::Abs(iz1-iz0);
+    t = new Double_t[n];
+    t[0] = 0.0;
+    t[n-1] = 1.0;
+    x = x0;
+    z = z0;
+    for(i=1;i<n-1;i++){
+       GetSeg()->LocalToDet(x,z,ix,iz);
+       GetSeg()->CellBoundries(ix,iz,lx,ux,lz,uz);
+       a = (lx-x0)/x1;
+       if(a<=t[i-1]) a = 1.0;
+       b = (ux-x0)/x1;
+       if(b<=t[i-1]) b = 1.0;
+       c = (lz-z0)/z1;
+       if(c<=t[i-1]) c = 1.0;
+       d = (uz-z0)/z1;
+       if(d<=t[i-1]) d = 1.0;
+       t[i] = TMath::Min(TMath::Min(TMath::Min(a,b),c),d);
+       x = x0+x1*(t[i]*1.00000001);
+       z = z0+z1*(t[i]*1.00000001);
+       i++;
+    } // end for i
+    return t;
+}
+//______________________________________________________________________
+void AliITSsimulationSPDdubna::HitToSDigitOld(AliITSmodule *mod, Int_t module,
+                                           Int_t dummy, AliITSpList *pList){
+    // digitize module 
     const Float_t kEnToEl = 2.778e+8; // GeV->charge in electrons 
                                       // for 3.6 eV/pair 
     const Float_t kconv = 10000.;     // cm -> microns
 
-    Float_t spdLength = fSegmentation->Dz();
-    Float_t spdWidth = fSegmentation->Dx();
-    Float_t spdThickness = fSegmentation->Dy();
+    Float_t spdLength = GetSeg()->Dz();
+    Float_t spdWidth = GetSeg()->Dx();
+    Float_t spdThickness = GetSeg()->Dy();
     Float_t difCoef, dum;       
-    fResponse->DiffCoeff(difCoef,dum); 
+    GetResp()->DiffCoeff(difCoef,dum); 
     if(spdThickness > 290) difCoef = 0.00613;  
 
     Float_t zPix0 = 1e+6;
     Float_t xPix0 = 1e+6;
     Float_t yPrev = 1e+6;   
 
-    Float_t zPitch = fSegmentation->Dpz(0);
-    Float_t xPitch = fSegmentation->Dpx(0);
+    Float_t zPitch = GetSeg()->Dpz(0);
+    Float_t xPitch = GetSeg()->Dpx(0);
   
     TObjArray *fHits = mod->GetHits();
+    module = mod->GetIndex();
     Int_t nhits = fHits->GetEntriesFast();
     if (!nhits) return;
-
-    cout<<"len,wid,thickness,nx,nz,pitchx,pitchz,difcoef ="<<spdLength<<","<<spdWidth<<","<<spdThickness<<","<<fNPixelsX<<","<<fNPixelsZ<<","<<xPitch<<","<<zPitch<<","<<difCoef<<endl;
-  //  Array of pointers to the label-signal list
-
-    Int_t maxNDigits = fNPixelsX*fNPixelsZ + fNPixelsX ;; 
-    Float_t  **pList = new Float_t* [maxNDigits]; 
-    memset(pList,0,sizeof(Float_t*)*maxNDigits);
+#ifdef DEBUG
+    cout<<"len,wid,thickness,nx,nz,pitchx,pitchz,difcoef ="<<spdLength<<","
+       <<spdWidth<<","<<spdThickness<<","<<fNPixelsX<<","<<fNPixelsZ<<","
+       <<xPitch<<","<<zPitch<<","<<difCoef<<endl;
+#endif
+    //  Array of pointers to the label-signal list
     Int_t indexRange[4] = {0,0,0,0};
 
     // Fill detector maps with GEANT hits
@@ -145,9 +569,14 @@ void AliITSsimulationSPDdubna::DigitiseModule(AliITSmodule *mod, Int_t module, I
     Int_t lasttrack=-2;
     Int_t hit, iZi, jz, jx;
     Int_t idhit=-1; //!
+#ifdef DEBUG
     cout<<"SPDdubna: module,nhits ="<<module<<","<<nhits<<endl;
+#endif
     for (hit=0;hit<nhits;hit++) {
         AliITShit *iHit = (AliITShit*) fHits->At(hit);
+#ifdef DEBUG
+       cout << "Hits=" << hit << "," << *iHit << endl;
+#endif
        //Int_t layer = iHit->GetLayer();
         Float_t yPix0 = -spdThickness/2; 
 
@@ -166,25 +595,16 @@ void AliITSsimulationSPDdubna::DigitiseModule(AliITSmodule *mod, Int_t module, I
        //Int_t parent = iHit->GetParticle()->GetFirstMother();
         Int_t partcode = iHit->GetParticle()->GetPdgCode();
 
-//  partcode (pdgCode): 11 - e-, 13 - mu-, 22 - gamma, 111 - pi0, 211 - pi+
-//                      310 - K0s, 321 - K+, 2112 - n, 2212 - p, 3122 - lambda
-
-       /*
-        Float_t px = iHit->GetPXL();   // the momenta at the        
-        Float_t py = iHit->GetPYL();   // each  GEANT step 
-        Float_t pz = iHit->GetPZL();
-        Float_t ptot = 1000*sqrt(px*px+py*py+pz*pz);
-       */
+       //  partcode (pdgCode): 11 - e-, 13 - mu-, 22 - gamma, 111 - pi0,
+       // 211 - pi+,  310 - K0s, 321 - K+, 2112 - n, 2212 - p, 3122 - lambda
 
        Float_t pmod = iHit->GetParticle()->P(); // total momentum at the
                                                   // vertex
         pmod *= 1000;
 
-
         if(partcode == 11 && pmod < 6) dray = 1; // delta ray is e-
                                                  // at p < 6 MeV/c
 
-
        //  Get hit z and x(r*phi) cordinates for each module (detector)
        //  in local system.
 
@@ -197,29 +617,37 @@ void AliITSsimulationSPDdubna::DigitiseModule(AliITSmodule *mod, Int_t module, I
 
        // Check boundaries
        if(zPix  > spdLength/2) {
-         //cout<<"!!! SPD: z outside ="<<zPix<<endl;
-         zPix = spdLength/2 - 10;
+#ifdef DEBUG
+           cout<<"!!! SPD: z outside ="<<zPix<<endl;
+#endif
+           zPix = spdLength/2 - 10;
        }
        if(zPix  < 0 && zPix < -spdLength/2) {
-         //cout<<"!!! SPD: z outside ="<<zPix<<endl;
-         zPix = -spdLength/2 + 10;
+#ifdef DEBUG
+           cout<<"!!! SPD: z outside ="<<zPix<<endl;
+#endif
+           zPix = -spdLength/2 + 10;
        }
        if(xPix  > spdWidth/2) {
-         //cout<<"!!! SPD: x outside ="<<xPix<<endl;
-         xPix = spdWidth/2 - 10;
+#ifdef DEBUG
+           cout<<"!!! SPD: x outside ="<<xPix<<endl;
+#endif
+           xPix = spdWidth/2 - 10;
        }
        if(xPix  < 0 && xPix < -spdWidth/2) {
-         //cout<<"!!! SPD: x outside ="<<xPix<<endl;
-         xPix = -spdWidth/2 + 10;
+#ifdef DEBUG
+           cout<<"!!! SPD: x outside ="<<xPix<<endl;
+#endif
+           xPix = -spdWidth/2 + 10;
        }
        Int_t trdown = 0;
 
        // enter Si or after event in Si
        if (status == 66 ) {  
-           zPix0 = zPix;
-           xPix0 = xPix;
-           yPrev = yPix; 
-       }   
+           zPix0 = zPix;
+           xPix0 = xPix;
+           yPrev = yPix; 
+       } // end if status == 66
 
        Float_t depEnergy = iHit->GetIonization();
        // skip if the input point to Si       
@@ -229,18 +657,15 @@ void AliITSsimulationSPDdubna::DigitiseModule(AliITSmodule *mod, Int_t module, I
        // if track returns to the opposite direction:
        if (yPix < yPrev) {
             trdown = 1;
-       } 
-
+       } // end if yPix < yPrev
 
        // take into account the holes diffusion inside the Silicon
        // the straight line between the entrance and exit points in Si is
        // divided into the several steps; the diffusion is considered 
        // for each end point of step and charge
        // is distributed between the pixels through the diffusion.
-       
 
        //  ---------- the diffusion in Z (beam) direction -------
-
        Float_t charge = depEnergy*kEnToEl;         // charge in e-
        Float_t drPath = 0.;   
        Float_t tang = 0.;
@@ -263,44 +688,44 @@ void AliITSsimulationSPDdubna::DigitiseModule(AliITSmodule *mod, Int_t module, I
        if(nsteps < 20) nsteps = 20;  // minimum number of the steps 
 
        if (projDif < 5 ) {
-          drPath = (yPix-yPix0)*1.e-4;  
-           drPath = TMath::Abs(drPath);        // drift path in cm
-          sigmaDif = difCoef*sqrt(drPath);    // sigma diffusion in cm        
-          sigmaDif = sigmaDif*kconv;         // sigma diffusion in microns
-           nsteps = 1;
-       }  
+           drPath = (yPix-yPix0)*1.e-4;  
+           drPath = TMath::Abs(drPath);        // drift path in cm
+           sigmaDif = difCoef*sqrt(drPath);    // sigma diffusion in cm
+           sigmaDif = sigmaDif*kconv;         // sigma diffusion in microns
+           nsteps = 1;
+       }  // end if projDif < 5
 
        if(projDif > 5) tang = ydif/projDif;
        Float_t dCharge = charge/nsteps;       // charge in e- for one step
        Float_t dZ = zdif/nsteps;
        Float_t dX = xdif/nsteps;
 
-       for (iZi = 1;iZi <= nsteps;iZi++) {
-            Float_t dZn = iZi*dZ;
+       for (iZi = 1; iZi <= nsteps;iZi++) {
+           Float_t dZn = iZi*dZ;
            Float_t dXn = iZi*dX;
            Float_t zPixn = zPix0 + dZn;
            Float_t xPixn = xPix0 + dXn;
 
            if(projDif >= 5) {
-             Float_t dProjn = sqrt(dZn*dZn+dXn*dXn);
-               drPath = dProjn*tang*1.e-4; // drift path for iZi step in cm 
-             if(trdown == 0) {
-               drPath = TMath::Abs(drPath) + ydif0*1.e-4;
-             }
-             if(trdown == 1) {
-               drPath = ydif0*1.e-4 - TMath::Abs(drPath);
-                drPath = TMath::Abs(drPath);
-             }
-             sigmaDif = difCoef*sqrt(drPath);    
-             sigmaDif = sigmaDif*kconv;         // sigma diffusion in microns
-           }
+               Float_t dProjn = sqrt(dZn*dZn+dXn*dXn);
+               drPath = dProjn*tang*1.e-4; // drift path for iZi+1 step in cm 
+               if(trdown == 0) {
+                   drPath = TMath::Abs(drPath) + ydif0*1.e-4;
+               }// end if trdow ==0
+               if(trdown == 1) {
+                   drPath = ydif0*1.e-4 - TMath::Abs(drPath);
+                   drPath = TMath::Abs(drPath);
+               } // end if trdown == 1
+               sigmaDif = difCoef*sqrt(drPath);    
+               sigmaDif = sigmaDif*kconv;       // sigma diffusion in microns
+           } // end if projdif >= 5
 
            zPixn = (zPixn + spdLength/2.);  
            xPixn = (xPixn + spdWidth/2.);  
             Int_t nZpix, nXpix;
-            fSegmentation->GetPadIxz(xPixn,zPixn,nXpix,nZpix);
-           zPitch = fSegmentation->Dpz(nZpix);
-            fSegmentation->GetPadTxz(xPixn,zPixn);
+            GetSeg()->GetPadIxz(xPixn,zPixn,nXpix,nZpix);
+           zPitch = GetSeg()->Dpz(nZpix);
+            GetSeg()->GetPadTxz(xPixn,zPixn);
            // set the window for the integration
            Int_t jzmin = 1;  
            Int_t jzmax = 3; 
@@ -327,17 +752,15 @@ void AliITSsimulationSPDdubna::DigitiseModule(AliITSmodule *mod, Int_t module, I
 
            for(jz=jzmin; jz <=jzmax; jz++) {
                if(jz == 1) {
-                 dZprev = -zPitch - dZleft;
-                 dZnext = -dZleft;
-               } 
-               if(jz == 2) {
-                 dZprev = -dZleft;
-                 dZnext = dZright;
-               } 
-               if(jz == 3) {
-                 dZprev = dZright;
-                 dZnext = dZright + zPitch;
-               } 
+                   dZprev = -zPitch - dZleft;
+                   dZnext = -dZleft;
+               } else if(jz == 2) {
+                   dZprev = -dZleft;
+                   dZnext = dZright;
+               } else if(jz == 3) {
+                   dZprev = dZright;
+                   dZnext = dZright + zPitch;
+               } // end if jz
                // kz changes from 1 to the fNofPixels(270)  
                Int_t kz = nZpix + jz -2; 
 
@@ -351,276 +774,168 @@ void AliITSsimulationSPDdubna::DigitiseModule(AliITSmodule *mod, Int_t module, I
                // ----------- holes diffusion in X(r*phi) direction  --------
 
                if(dZCharge > 1.) { 
-                 for(jx=jxmin; jx <=jxmax; jx++) {
-                    if(jx == 1) {
-                      dXprev = -xPitch - dXleft;
-                      dXnext = -dXleft;
-                    } 
-                    if(jx == 2) {
-                      dXprev = -dXleft;
-                      dXnext = dXright;
-                    } 
-                    if(jx == 3) {
-                      dXprev = dXright;
-                      dXnext = dXright + xPitch;
-                    } 
-                    Int_t kx = nXpix + jx -2;  
-
-                    Float_t xArg1 = dXprev/sigmaDif;
-                    Float_t xArg2 = dXnext/sigmaDif;
-                    Float_t xProb1 = TMath::Erfc(xArg1);
-                    Float_t xProb2 = TMath::Erfc(xArg2);
-                    Float_t dXCharge =0.5*(xProb1-xProb2)*dZCharge; 
-
-                    if(dXCharge > 1.) {
-                      Int_t index = kz-1;
-
-                      if (first) {
-                          indexRange[0]=indexRange[1]=index;
-                          indexRange[2]=indexRange[3]=kx-1;
-                          first=kFALSE;
-                      }
-
-                       indexRange[0]=TMath::Min(indexRange[0],kz-1);
-                       indexRange[1]=TMath::Max(indexRange[1],kz-1);
-                       indexRange[2]=TMath::Min(indexRange[2],kx-1);
-                       indexRange[3]=TMath::Max(indexRange[3],kx-1);
-
-                      // build the list of digits for this module      
-                       Double_t signal=fMapA2->GetSignal(index,kx-1);
-                       signal+=dXCharge;
-                       fMapA2->SetHit(index,kx-1,(double)signal);
-                    }      // dXCharge > 1 e-
-                 }       // jx loop
+                   for(jx=jxmin; jx <=jxmax; jx++) {
+                       if(jx == 1) {
+                           dXprev = -xPitch - dXleft;
+                           dXnext = -dXleft;
+                       } else if(jx == 2) {
+                           dXprev = -dXleft;
+                           dXnext = dXright;
+                       } else if(jx == 3) {
+                           dXprev = dXright;
+                           dXnext = dXright + xPitch;
+                       }  // end if jx
+                       Int_t kx = nXpix + jx -2;
+                       Float_t xArg1 = dXprev/sigmaDif;
+                       Float_t xArg2 = dXnext/sigmaDif;
+                       Float_t xProb1 = TMath::Erfc(xArg1);
+                       Float_t xProb2 = TMath::Erfc(xArg2);
+                       Float_t dXCharge =0.5*(xProb1-xProb2)*dZCharge;
+
+                       if(dXCharge > 1.) {
+                           if (first) {
+                               indexRange[0]=indexRange[1]=kz-1;
+                               indexRange[2]=indexRange[3]=kx-1;
+                               first=kFALSE;
+                           } // end if first
+                           indexRange[0]=TMath::Min(indexRange[0],kz-1);
+                           indexRange[1]=TMath::Max(indexRange[1],kz-1);
+                           indexRange[2]=TMath::Min(indexRange[2],kx-1);
+                           indexRange[3]=TMath::Max(indexRange[3],kx-1);
+/*
+                           // build the list of digits for this module 
+                           Double_t signal = fMapA2->GetSignal(kz-1,kx-1);
+                           signal+=dXCharge;
+                           fMapA2->SetHit(kz-1,kx-1,(double)signal);
+*/
+                           // The calling sequence for UpdateMapSignal was 
+                           // moved into the (dx > 1 e-) loop because it 
+                           // needs to call signal which is defined inside 
+                           // this loop
+                           fModule   = module;//Defined because functions 
+                                              // called by UpdateMapSignal 
+                                              // expect module to be an 
+                                              // integer
+                           UpdateMapSignal(kz-1,kx-1,
+//                                         mod->GetHitTrackIndex(hit),
+                             ((AliITShit*)(mod->GetHit(hit)))->GetTrack(),
+                                           hit,fModule,dXCharge,pList);
+                       }      // dXCharge > 1 e-
+                   }       // jx loop
                }       // dZCharge > 1 e-
            }        // jz loop
        }         // iZi loop
-
         if (status == 65) {   // the step is inside of Si
-          zPix0 = zPix;
-          xPix0 = xPix;
-        }
-       yPrev = yPix;  
-
-       if(dray == 0) {
-            GetList(itrack,idhit,pList,indexRange);
-       }
-
-       lasttrack=itrack;
+           zPix0 = zPix;
+           xPix0 = xPix;
+       } // end if status == 65
+       yPrev = yPix;
     }   // hit loop inside the module
-
-   
-    // introduce the electronics effects and do zero-suppression
-    ChargeToSignal(pList); 
-
-    // clean memory
-
-    fMapA2->ClearMap();
-
-
-} 
-
-//---------------------------------------------
-void AliITSsimulationSPDdubna::GetList(Int_t label,Int_t idhit,Float_t **pList,Int_t *indexRange)
-{
-  // lop over nonzero digits
-
-   
-  //set protection
-  for(int k=0;k<4;k++) {
-     if (indexRange[k] < 0) indexRange[k]=0;
-  }
-
-  for(Int_t iz=indexRange[0];iz<indexRange[1]+1;iz++){
-    for(Int_t ix=indexRange[2];ix<indexRange[3]+1;ix++){
-
-        Float_t signal=fMapA2->GetSignal(iz,ix);
-
-       if (!signal) continue;
-
-        Int_t globalIndex = iz*fNPixelsX+ix; // GlobalIndex starts from 0!
-        if(!pList[globalIndex]){
-
-           // 
-          // Create new list (9 elements - 3 signals and 3 tracks + 3 hits)
-          //
-
-           pList[globalIndex] = new Float_t [9];
-
-          // set list to -3 
-
-          *pList[globalIndex] = -3.;
-          *(pList[globalIndex]+1) = -3.;
-          *(pList[globalIndex]+2) = -3.;
-          *(pList[globalIndex]+3) =  0.;
-          *(pList[globalIndex]+4) =  0.;
-          *(pList[globalIndex]+5) =  0.;
-          *(pList[globalIndex]+6) = -1.;
-          *(pList[globalIndex]+7) = -1.;
-          *(pList[globalIndex]+8) = -1.;
-
-
-          *pList[globalIndex] = (float)label;
-          *(pList[globalIndex]+3) = signal;
-          *(pList[globalIndex]+6) = (float)idhit;
-        }
-        else{
-
-         // check the signal magnitude
-
-          Float_t highest = *(pList[globalIndex]+3);
-          Float_t middle = *(pList[globalIndex]+4);
-          Float_t lowest = *(pList[globalIndex]+5);
-
-          signal -= (highest+middle+lowest);
-
-         //
-         //  compare the new signal with already existing list
-         //
-
-          if(signal<lowest) continue; // neglect this track
-
-          if (signal>highest){
-            *(pList[globalIndex]+5) = middle;
-            *(pList[globalIndex]+4) = highest;
-            *(pList[globalIndex]+3) = signal;
-
-            *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
-            *(pList[globalIndex]+1) = *pList[globalIndex];
-            *pList[globalIndex] = label;
-
-            *(pList[globalIndex]+8) = *(pList[globalIndex]+7);
-            *(pList[globalIndex]+7) = *(pList[globalIndex]+6);
-            *(pList[globalIndex]+6) = idhit;
-         }
-          else if (signal>middle){
-            *(pList[globalIndex]+5) = middle;
-            *(pList[globalIndex]+4) = signal;
-
-            *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
-            *(pList[globalIndex]+1) = label;
-
-            *(pList[globalIndex]+8) = *(pList[globalIndex]+7);
-            *(pList[globalIndex]+7) = idhit;
-         }
-          else{
-            *(pList[globalIndex]+5) = signal;
-            *(pList[globalIndex]+2) = label;
-            *(pList[globalIndex]+8) = idhit;
-         }
-        }
-    } // end of loop pixels in x
-  } // end of loop over pixels in z
-
-
 }
-
-
-//---------------------------------------------
-void AliITSsimulationSPDdubna::ChargeToSignal(Float_t **pList)
-{
-  // add noise and electronics, perform the zero suppression and add the
-  // digit to the list
-
-  AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
-  
-  Float_t threshold = (float)fResponse->MinVal();
-
-  Int_t digits[3], tracks[3], hits[3],gi,j1;
-  Float_t charges[3];
-  Float_t electronics;
-  Float_t signal,phys;
-  for(Int_t iz=0;iz<fNPixelsZ;iz++){
-    for(Int_t ix=0;ix<fNPixelsX;ix++){
-      electronics = fBaseline + fNoise*gRandom->Gaus();
-      signal = (float)fMapA2->GetSignal(iz,ix);
-      signal += electronics;
-      gi =iz*fNPixelsX+ix; // global index
-      if (signal > threshold) {
-        digits[0]=iz;
-        digits[1]=ix;
-        digits[2]=1;
-        for(j1=0;j1<3;j1++){
-          if (pList[gi]) {
-            //b.b.          tracks[j1]=-3;
-            tracks[j1] = (Int_t)(*(pList[gi]+j1));
-            hits[j1] = (Int_t)(*(pList[gi]+j1+6));
-          }else {
-            tracks[j1]=-2; //noise
-            hits[j1] = -1;
-          }
-          charges[j1] = 0;
-        }
-
-        if(tracks[0] == tracks[1] && tracks[0] == tracks[2]) {
-          tracks[1] = -3;
-           hits[1] = -1;
-          tracks[2] = -3;
-           hits[2] = -1;
-         } 
-        if(tracks[0] == tracks[1] && tracks[0] != tracks[2]) {
-          tracks[1] = -3;
-           hits[1] = -1;   
-         } 
-        if(tracks[0] == tracks[2] && tracks[0] != tracks[1]) {
-          tracks[2] = -3;
-           hits[2] = -1;   
-         } 
-        if(tracks[1] == tracks[2] && tracks[0] != tracks[1]) {
-          tracks[2] = -3;
-           hits[2] = -1;   
-         } 
-
-         phys=0;
-        aliITS->AddSimDigit(0,phys,digits,tracks,hits,charges);
-      }
-      if(pList[gi]) delete [] pList[gi];
-    }
-  }
-  delete [] pList;
-
+//______________________________________________________________________
+void AliITSsimulationSPDdubna::ChargeToSignal(AliITSpList *pList){
+    // add noise and electronics, perform the zero suppression and add the
+    // digit to the list
+    static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
+    Float_t threshold = (float)GetResp()->MinVal();
+    Int_t j;
+//    Int_t    digits[3], tracks[3], hits[3];
+//    Float_t  charges[3];
+    Float_t  electronics;
+//    Float_t  phys; 
+    Double_t sig;
+    const Int_t    nmaxtrk=AliITSdigitSPD::GetNTracks();
+    static AliITSdigitSPD dig;
+
+    for(Int_t iz=0; iz<fNPixelsZ; iz++){
+       for(Int_t ix=0; ix<fNPixelsX; ix++){
+           electronics = fBaseline + fNoise*gRandom->Gaus();
+           sig = pList->GetSignalOnly(iz+1,ix+1);
+           UpdateMapNoise(iz,ix,fModule,sig,electronics,pList);
+#ifdef DEBUG
+//         cout << sig << "+" << electronics <<">threshold=" << threshold 
+//              << endl;
+#endif
+           if (sig+electronics > threshold) {
+               dig.fCoord1 = iz;
+               dig.fCoord2 = ix;
+               dig.fSignal = 1;
+               dig.fSignalSPD = (Int_t) pList->GetSignal(iz+1,ix+1);
+               /*
+               digits[0] = iz;
+               digits[1] = ix;
+               digits[2] = 1; */
+               for(j=0;j<nmaxtrk;j++){
+//                 charges[j] = 0.0;
+                   if (j<pList->GetNEnteries()) {
+                       dig.fTracks[j] = pList->GetTrack(iz+1,ix+1,j);
+                       dig.fHits[j]   = pList->GetHit(iz+1,ix+1,j);
+                       /*
+                       tracks[j] = pList->GetTrack(iz+1,ix+1,j);
+                       hits[j]   = pList->GetHit(iz+1,ix+1,j);
+                       */
+                   }else { // Default values
+                       dig.fTracks[j] = -3;
+                       dig.fHits[j]   = -1;
+/*                     tracks[j] = -2; //noise
+                       hits[j]   = -1;  */
+                   } // end if pList
+               } // end for j
+//             charges[0] = (Float_t) pList->GetSumSignal(iz+1,ix+1);
+/*
+               if(tracks[0] == tracks[1] && tracks[0] == tracks[2]) {
+                   tracks[1] = -3;
+                   hits[1] = -1;
+                   tracks[2] = -3;
+                   hits[2] = -1;
+               } else if(tracks[0] == tracks[1] && tracks[0] != tracks[2]) {
+                   tracks[1] = -3;
+                   hits[1] = -1;   
+               } else if(tracks[0] == tracks[2] && tracks[0] != tracks[1]) {
+                   tracks[2] = -3;
+                   hits[2] = -1;   
+               } else if(tracks[1] == tracks[2] && tracks[0] != tracks[1]) {
+                   tracks[2] = -3;
+                   hits[2] = -1;   
+               } // end if
+*/
+//             phys = 0.0;
+#ifdef DEBUG
+               cout << iz << "," << ix << "," << 
+                   *(pList->GetpListItem(iz+1,ix+1)) << endl;
+#endif
+//             aliITS->AddSimDigit(0, phys, digits, tracks, hits, charges);
+               aliITS->AddSimDigit(0,&dig);
+           } // 
+       } // 
+    } //
 }
-
-
-//____________________________________________
-
-void AliITSsimulationSPDdubna::CreateHistograms()
-{
-  // create 1D histograms for tests
-
-      printf("SPD - create histograms\n");
-
-      fHis=new TObjArray(fNPixelsZ);
-      TString spdName("spd_");
-      for (Int_t i=0;i<fNPixelsZ;i++) {
-          Char_t pixelz[4];
-          sprintf(pixelz,"%d",i+1);
-          spdName.Append(pixelz);
-          (*fHis)[i] = new TH1F(spdName.Data(),"SPD maps",
-                              fNPixelsX,0.,(Float_t) fNPixelsX);
-      }
+//______________________________________________________________________
+void AliITSsimulationSPDdubna::CreateHistograms(){
+    // create 1D histograms for tests
+
+    printf("SPD - create histograms\n");
+
+    fHis=new TObjArray(fNPixelsZ);
+    TString spdName("spd_");
+    for (Int_t i=0;i<fNPixelsZ;i++) {
+       Char_t pixelz[4];
+       sprintf(pixelz,"%d",i+1);
+       spdName.Append(pixelz);
+       //PH       (*fHis)[i] = new TH1F(spdName.Data(),"SPD maps",
+       //PH                       fNPixelsX,0.,(Float_t) fNPixelsX);
+       fHis->AddAt(new TH1F(spdName.Data(),"SPD maps",
+                            fNPixelsX,0.,(Float_t) fNPixelsX), i);
+    } // end for i
 }
-
-//____________________________________________
-
-void AliITSsimulationSPDdubna::ResetHistograms()
-{
+//______________________________________________________________________
+void AliITSsimulationSPDdubna::ResetHistograms(){
     //
     // Reset histograms for this detector
     //
 
     for ( int i=0;i<fNPixelsZ;i++ ) {
-       if ((*fHis)[i])    ((TH1F*)(*fHis)[i])->Reset();
-    }
-
+       //PH    if ((*fHis)[i])    ((TH1F*)(*fHis)[i])->Reset();
+       if (fHis->At(i))    ((TH1F*)fHis->At(i))->Reset();
+    } // end for i
 }
-
-
-
-
-
-
-
-
-