]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSsimulationSSD.cxx
Bug fix by Piergiorgio Cerello.
[u/mrichter/AliRoot.git] / ITS / AliITSsimulationSSD.cxx
index 074a18e44aa95c03dc4498b31b955f3a241eda57..bcaf747c4cb88c5e5ebdbbcf463e6d7f37b2620f 100644 (file)
@@ -1,20 +1,37 @@
+/**************************************************************************
+ * 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.                  *
+ **************************************************************************/
+/* $Id$ */
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <iostream.h>
+#include <iomanip.h>
 #include <TObjArray.h>
 #include <TRandom.h>
 #include <TMath.h>
 
 #include "AliITSmodule.h"
-#include "AliITSMapA2.h"   
-#include "AliITSsegmentationSSD.h"
+#include "AliITSMapA2.h"
+#include "AliITSpList.h"
 #include "AliITSresponseSSD.h"
-#include "AliITSsimulationSSD.h"
-//#include "AliITSdictSSD.h"
+#include "AliITSsegmentationSSD.h"
 #include "AliITSdcsSSD.h"
 #include "AliITS.h"
 #include "AliRun.h"
 #include "AliITSgeom.h"
+#include "AliITSsimulationSSD.h"
 
 ClassImp(AliITSsimulationSSD);
 ////////////////////////////////////////////////////////////////////////
@@ -24,40 +41,60 @@ ClassImp(AliITSsimulationSSD);
 //
 // AliITSsimulationSSD is the simulation of SSDs.
 
+//----------------------------------------------------------------------
+AliITSsimulationSSD::AliITSsimulationSSD(){
+    //default Constructor
+
+    fDCS     = 0;
+    fDifConst[0] = fDifConst[1] = 0.0;
+    fDriftVel[0] = fDriftVel[1] = 0.0;
+    fMapA2   = 0;
+}
 //----------------------------------------------------------------------
 AliITSsimulationSSD::AliITSsimulationSSD(AliITSsegmentation *seg,
                                          AliITSresponse *resp){
     // Constructor
 
-    fSegmentation = seg;
-    fResponse = resp;
+    fDCS     = 0;
+    fDifConst[0] = fDifConst[1] = 0.0;
+    fDriftVel[0] = fDriftVel[1] = 0.0;
+    fMapA2   = 0;
+    Init((AliITSsegmentationSSD*)seg,(AliITSresponseSSD*)resp);
+}
+//----------------------------------------------------------------------
+void AliITSsimulationSSD::Init(AliITSsegmentationSSD *seg,
+                              AliITSresponseSSD *resp){
+    // Constructor
+
+    fSegmentation    = seg;
+    fResponse        = resp;
     Float_t noise[2] = {0.,0.};
     fResponse->GetNoiseParam(noise[0],noise[1]); // retrieves noise parameters
-    fDCS = new AliITSdcsSSD(seg,resp); 
-
-    fNstrips = fSegmentation->Npx();
-    fPitch = fSegmentation->Dpx(0);
-    fMapA2 = new AliITSMapA2(fSegmentation);
-     
-    fSteps  = 100;   // still hard-wired - set in SetDetParam and get it via  
-                     // fDCS together with the others eventually    
+    fDCS             = new AliITSdcsSSD(seg,resp); 
+
+    SetDriftVelocity(); // use default values in .h file
+    SetIonizeE();       // use default values in .h file
+    SetDiffConst();     // use default values in .h file
+    fMapA2           = new AliITSMapA2(fSegmentation);
 }
 //______________________________________________________________________
-AliITSsimulationSSD& AliITSsimulationSSD::operator=(AliITSsimulationSSD 
-                                                                      &source){
+AliITSsimulationSSD& AliITSsimulationSSD::operator=(
+                                                const AliITSsimulationSSD &s){
     // Operator =
 
-    if(this==&source) return *this;
+    if(this==&s) return *this;
 
-    this->fDCS     = new AliITSdcsSSD(*(source.fDCS));
-    this->fMapA2   = source.fMapA2;
-    this->fNstrips = source.fNstrips;
-    this->fPitch   = source.fPitch;
-    this->fSteps   = source.fSteps;
+    this->fDCS         = new AliITSdcsSSD(*(s.fDCS));
+    this->fMapA2       = s.fMapA2;
+    this->fIonE        = s.fIonE;
+    this->fDifConst[0] = s.fDifConst[0];
+    this->fDifConst[1] = s.fDifConst[1];
+    this->fDriftVel[0] = s.fDriftVel[0];
+    this->fDriftVel[1] = s.fDriftVel[1];
     return *this;
 }
-//_____________________________________________________________---------
-AliITSsimulationSSD::AliITSsimulationSSD(AliITSsimulationSSD &source){
+//______________________________________________________________________
+AliITSsimulationSSD::AliITSsimulationSSD(const AliITSsimulationSSD &source){
     // copy constructor
 
     *this = source;
@@ -68,34 +105,66 @@ AliITSsimulationSSD::~AliITSsimulationSSD() {
     delete fMapA2;
     delete fDCS;
 }
-//_______________________________________________________________-------
-void AliITSsimulationSSD::DigitiseModule(AliITSmodule *mod,Int_t module,
-                                         Int_t dummy) {
-    // Digitizes hits for one SSD module 
-
-    Int_t lay, lad, detect;
-    AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
-    AliITSgeom *geom = aliITS->GetITSgeom();
-    geom->GetModuleId(module,lay, lad, detect);
-    if ( lay == 6 )((AliITSsegmentationSSD*)fSegmentation)->SetLayer(6);
-    if ( lay == 5 )((AliITSsegmentationSSD*)fSegmentation)->SetLayer(5);
+//______________________________________________________________________
+void AliITSsimulationSSD::DigitiseModule(AliITSmodule *mod,
+                                        Int_t dummy0,Int_t dummy1) {
+    // Digitizes hits for one SSD module
+    Int_t module     = mod->GetIndex();
+    AliITSpList *pList = new AliITSpList(2,GetNStrips());
 
-    TObjArray *hits = mod->GetHits();
-    Int_t nhits = hits->GetEntriesFast();
-    if (!nhits) return;
-    //cout<<"!! module, nhits ="<<module<<","<<nhits<<endl; 
-  
+    HitsToAnalogDigits(mod,pList);
+    SDigitToDigit(module,pList);
+
+    delete pList;
+    fMapA2->ClearMap();
+}
+//______________________________________________________________________
+void AliITSsimulationSSD::SDigitiseModule(AliITSmodule *mod,Int_t dummy0,
+                                         Int_t dummy1) {
+    // Produces Summable/Analog digits and writes them to the SDigit tree.
+    AliITSpList *pList = new AliITSpList(2,GetNStrips()); 
+
+    HitsToAnalogDigits(mod,pList);
+
+    WriteSDigits(pList);
+
+    delete pList;
+    fMapA2->ClearMap();
+}
+//______________________________________________________________________
+void AliITSsimulationSSD::SDigitToDigit(Int_t module,AliITSpList *pList){
+    // Takes the pList and finishes the digitization.
+                               
+//    FillMapFrompList(pList);  //commented out to avoid double counting of the
+                                //charge
+
+    ApplyNoise(pList,module);
+    ApplyCoupling(pList,module);
+
+    ChargeToSignal(pList);
+}
+//______________________________________________________________________
+void AliITSsimulationSSD::HitsToAnalogDigits(AliITSmodule *mod,
+                                            AliITSpList *pList){
+    // Loops over all hits to produce Analog/floating point digits. This
+    // is also the first task in producing standard digits.
+    Int_t indexRange[4] = {0,0,0,0};
+    static Bool_t first = kTRUE;
+    Int_t lasttrack     = -2;
+    Int_t idtrack       = -2;
     Double_t x0=0.0, y0=0.0, z0=0.0;
     Double_t x1=0.0, y1=0.0, z1=0.0;
     Double_t de=0.0;
-    Int_t maxNdigits = 2*fNstrips; 
-    Float_t  **pList = new Float_t* [maxNdigits]; 
-    memset(pList,0,sizeof(Float_t*)*maxNdigits);
-    Int_t indexRange[4] = {0,0,0,0};
-    static Bool_t first=kTRUE;
-    Int_t lasttrack = -2;
-    Int_t idtrack = -2;
-    
+    Int_t module = mod->GetIndex();
+
+    TObjArray *hits = mod->GetHits();
+    Int_t nhits     = hits->GetEntriesFast();
+    if (nhits<=0) return;
+
+    module = mod->GetIndex();
+    if ( mod->GetLayer() == 6 ) GetSegmentation()->SetLayer(6);
+    if ( mod->GetLayer() == 5 ) GetSegmentation()->SetLayer(5);
+
     for(Int_t i=0; i<nhits; i++) {    
        // LineSegmentL returns 0 if the hit is entering
        // If hits is exiting returns positions of entering and exiting hits
@@ -105,19 +174,13 @@ void AliITSsimulationSSD::DigitiseModule(AliITSmodule *mod,Int_t module,
            HitToDigit(module, x0, y0, z0, x1, y1, z1, de, indexRange, first);
        
            if (lasttrack != idtrack || i==(nhits-1)) {
-               GetList(idtrack,pList,indexRange);
+               GetList(idtrack,i,module,pList,indexRange);
                first=kTRUE;
            } // end if
            lasttrack=idtrack;
        } // end if
     }  // end loop over hits
-  
-    ApplyNoise();
-    ApplyCoupling();
-
-    ChargeToSignal(pList);
-
-    fMapA2->ClearMap();
+    return;
 }
 //----------------------------------------------------------------------
 void AliITSsimulationSSD::HitToDigit(Int_t module, Double_t x0, Double_t y0, 
@@ -127,45 +190,38 @@ void AliITSsimulationSSD::HitToDigit(Int_t module, Double_t x0, Double_t y0,
     // Turns hits in SSD module into one or more digits.
 
     Float_t tang[2] = {0.0,0.0};
-    fSegmentation->Angles(tang[0], tang[1]);// stereo<<  -> tan(stereo)~=stereo
+    GetSegmentation()->Angles(tang[0], tang[1]);//stereo<<->tan(stereo)~=stereo
     Double_t x, y, z;
     Double_t dex=0.0, dey=0.0, dez=0.0;
-    Double_t pairs;
-    Double_t ionE = 3.62E-9;   // ionization energy of Si (GeV)
-    
+    Double_t pairs; // pair generation energy per step.
     Double_t sigma[2] = {0.,0.};// standard deviation of the diffusion gaussian
-
-    Double_t D[2] = {11.,30.}; // diffusion constant {h,e} (cm**2/sec)
     Double_t tdrift[2] = {0.,0.}; // time of drift
-    Double_t vdrift[2] = {0.86E6,2.28E6};  // drift velocity (cm/sec)   
     Double_t w;
     Double_t inf[2], sup[2], par0[2];                 
+
     // Steps in the module are determined "manually" (i.e. No Geant)
     // NumOfSteps divide path between entering and exiting hits in steps 
     Int_t numOfSteps = NumOfSteps(x1, y1, z1, dex, dey, dez);
   
     // Enery loss is equally distributed among steps
-    de = de/numOfSteps;
-    pairs = de/ionE;             // e-h pairs generated
+    de    = de/numOfSteps;
+    pairs = de/GetIonizeE(); // e-h pairs generated
 
     for(Int_t j=0; j<numOfSteps; j++) {     // stepping
-       //    cout<<"step number ="<<j<<endl;
        x = x0 + (j+0.5)*dex;
        y = y0 + (j+0.5)*dey;
-       //if ( y > (seg->Dy()/2 +10)*1.0E-4 ) {
-       if ( y > (fSegmentation->Dy()/2+10)*1.0E-4 ) {
+       if ( y > (GetSegmentation()->Dy()/2+10)*1.0E-4 ) {
            // check if particle is within the detector
-           cout<<"AliITSsimulationSSD::HitToDigit: Warning: hit "
-               "out of detector y0,y,dey,j ="
-               <<y0<<","<<y<<","<<dey<<","<<j<<endl;
+           Warning("HitToDigit","hit out of detector y0=%e,y=%e,dey=%e,j =%e",
+                   y0,y,dey,j);
            return;
        } // end if
        z = z0 + (j+0.5)*dez;
 
        // calculate drift time
        // y is the minimum path
-       tdrift[0] = (y+(fSegmentation->Dy()*1.0E-4)/2) / vdrift[0];
-       tdrift[1] = ((fSegmentation->Dy()*1.0E-4)/2-y) / vdrift[1];
+       tdrift[0] = (y+(GetSegmentation()->Dy()*1.0E-4)/2)/GetDriftVelocity(0);
+       tdrift[1] = ((GetSegmentation()->Dy()*1.0E-4)/2-y)/GetDriftVelocity(1);
 
        for(Int_t k=0; k<2; k++) {   // both sides    remember: 0=Pside 1=Nside
 
@@ -173,37 +229,32 @@ void AliITSsimulationSSD::HitToDigit(Int_t module, Double_t x0, Double_t y0,
 
            // w is the coord. perpendicular to the strips
            if(k==0) {
-               //w=(x+(seg->Dx()*1.0E-4)/2)-(z+(seg->Dz()*1.0E-4)/2)*tang[k]; 
-               w = (x+(fSegmentation->Dx()*1.0E-4)/2) -
-                   (z+(fSegmentation->Dz()*1.0E-4)/2)*tang[k]; 
+               w = (x+(GetSegmentation()->Dx()*1.0E-4)/2) -
+                   (z+(GetSegmentation()->Dz()*1.0E-4)/2)*tang[k]; 
            }else{
-               //w =(x+(seg->Dx()*1.0E-4)/2)+(z-(seg->Dz()*1.0E-4)/2)*tang[k];
-               w = (x+(fSegmentation->Dx()*1.0E-4)/2) + 
-                   (z-(fSegmentation->Dz()*1.0E-4)/2)*tang[k]; 
-               //cout<<"k,x,z,w ="<<k<<","<<x<<","<<z<<","<<w<<endl;
+               w = (x+(GetSegmentation()->Dx()*1.0E-4)/2) + 
+                   (z-(GetSegmentation()->Dz()*1.0E-4)/2)*tang[k];
            } // end if
-           w = w / (fPitch*1.0E-4); // w is converted in units of pitch
+           w /= (GetStripPitch()*1.0E-4); // w is converted in units of pitch
 
-           if((w<(-0.5)) || (w>(fNstrips-0.5))) {
+           if((w<(-0.5)) || (w>(GetNStrips()-0.5))) {
                // this check rejects hits in regions not covered by strips
                // 0.5 takes into account boundaries 
-               if(k==0) cout<<"AliITSsimulationSSD::HitToDigit: "
-                            "Warning: no strip in this region of P side"
-                            <<endl;
-               else cout<<"AliITSsimulationSSD::HitToDigit: "
-                        "Warning: no strip in this region of N side"<<endl;
+               return; // There are dead region on the SSD sensitive volume.
+               /*
+               if(k==0) Warning("HitToDigit",
+                                "no strip in this region of P side");
+               else Warning"HitToDigit","no strip in this region of N side");
                return;
+               */
            } // end if
 
            // sigma is the standard deviation of the diffusion gaussian
-
            if(tdrift[k]<0) return;
-
-           sigma[k] = TMath::Sqrt(2*D[k]*tdrift[k]);
-           sigma[k] = sigma[k] /(fPitch*1.0E-4);  //units of Pitch
+           sigma[k] = TMath::Sqrt(2*GetDiffConst(k)*tdrift[k]);
+           sigma[k] /= (GetStripPitch()*1.0E-4);  //units of Pitch
            if(sigma[k]==0.0) {         
-               cout<<"AliITSsimulationSSD::DigitiseModule: Error: sigma=0"
-                   <<endl; 
+               Error("HitToDigit"," sigma[%d]=0",k);
                exit(0);
            } // end if
 
@@ -219,51 +270,53 @@ void AliITSsimulationSSD::HitToDigit(Int_t module, Double_t x0, Double_t y0,
     } // end stepping
     //delete seg;
 }
-//____________________________________________________________________--
-void AliITSsimulationSSD::ApplyNoise({
+//______________________________________________________________________
+void AliITSsimulationSSD::ApplyNoise(AliITSpList *pList,Int_t module){
     // Apply Noise.
-  
-    Float_t signal;
-    Float_t noise[2] = {0.,0.};
-    fResponse->GetNoiseParam(noise[0],noise[1]); // retrieves noise parameters
-
-    for(Int_t k=0;k<2;k++){                    // both sides (0=Pside, 1=Nside)
-       for(Int_t ix=0;ix<fNstrips;ix++){            // loop over strips
-           signal = (Float_t) fMapA2->GetSignal(k,ix);// retrieves signal
-                                                       // from map
-
-           signal += gRandom->Gaus(0,noise[k]);// add noise to signal
+    Int_t    k,ix;
+    Double_t signal,noise;
+    Double_t noiseP[2] = {0.,0.};
+    Float_t a,b;
+
+    fResponse->GetNoiseParam(a,b); // retrieves noise parameters
+    noiseP[0] = (Double_t) a; noiseP[1] = (Double_t) b;
+    for(k=0;k<2;k++){                    // both sides (0=Pside, 1=Nside)
+       for(ix=0;ix<GetNStrips();ix++){      // loop over strips
+           noise  = gRandom->Gaus(0,noiseP[k]);// get noise to signal
+           signal = noise + fMapA2->GetSignal(k,ix);//get signal from map
            if(signal<0.) signal=0.0;           // in case noise is negative...
-
-           fMapA2->SetHit(k,ix,(Double_t)signal); // give back signal to map
+           fMapA2->SetHit(k,ix,signal); // give back signal to map
+           if(signal>0.0) pList->AddNoise(k,ix,module,noise);
        } // loop over strip 
     } // loop over k (P or N side)
 }
 //______________________________________________________________________
-void AliITSsimulationSSD::ApplyCoupling() {
+void AliITSsimulationSSD::ApplyCoupling(AliITSpList *pList,Int_t module) {
     // Apply the effect of electronic coupling between channels
-    Float_t signal, signalLeft=0, signalRight=0;
+    Int_t ix;
+    Double_t signalLeft=0, signalRight=0,signal=0;
 
-    for(Int_t ix=0;ix<fNstrips;ix++){
-       if(ix>0.) signalLeft  = (Float_t) fMapA2->GetSignal(0,ix-1)*
-                                                       fDCS->GetCouplingPL();
+    for(ix=0;ix<GetNStrips();ix++){
+       // P side coupling
+       if(ix>0.)signalLeft = fMapA2->GetSignal(0,ix-1)*fDCS->GetCouplingPL();
        else signalLeft = 0.0;
-       if(ix<(fNstrips-1)) signalRight = (Float_t) fMapA2->GetSignal(0,ix+1)*
+       if(ix<(GetNStrips()-1)) signalRight = fMapA2->GetSignal(0,ix+1)*
                                                         fDCS->GetCouplingPR();
        else signalRight = 0.0;
-       signal = (Float_t) fMapA2->GetSignal(0,ix);
-       signal += signalLeft + signalRight;
-       fMapA2->SetHit(0,ix,(Double_t)signal);
-    
-       if(ix>0.) signalLeft  = (Float_t) fMapA2->GetSignal(1,ix-1)*
-                                                        fDCS->GetCouplingNL();
+       signal = signalLeft + signalRight;
+       fMapA2->AddSignal(0,ix,signal);
+       if(signal>0.0) pList->AddNoise(0,ix,module,signal);
+
+       signalLeft = signalRight = signal = 0.0;
+       // N side coupling
+       if(ix>0.) signalLeft = fMapA2->GetSignal(1,ix-1)*fDCS->GetCouplingNL();
        else signalLeft = 0.0;
-       if(ix<(fNstrips-1)) signalRight = (Float_t) fMapA2->GetSignal(1,ix+1)*
+       if(ix<(GetNStrips()-1)) signalRight = fMapA2->GetSignal(1,ix+1)*
                                                          fDCS->GetCouplingNR();
        else signalRight = 0.0;
-       signal = (Float_t) fMapA2->GetSignal(1,ix);
-       signal += signalLeft + signalRight;
-       fMapA2->SetHit(1,ix,(Double_t)signal);
+       signal = signalLeft + signalRight;
+       fMapA2->AddSignal(1,ix,signal);
+       if(signal>0.0) pList->AddNoise(1,ix,module,signal);
     } // loop over strips 
 }
 //______________________________________________________________________
@@ -287,7 +340,7 @@ void AliITSsimulationSSD::IntegrateGaussian(Int_t k,Double_t par, Double_t w,
     //         this way we are free to introduce asimmetry
 
     Double_t a=0.0, b=0.0;
-    Double_t signal = 0.0, dXCharge1 = 0.0, dXCharge2 = 0.0;
+    Double_t dXCharge1 = 0.0, dXCharge2 = 0.0;
     // dXCharge1 and 2 are the charge to two neighbouring strips
     // Watch that we only involve at least two strips
     // Numbers greater than 2 of strips in a cluster depend on
@@ -317,21 +370,16 @@ void AliITSsimulationSSD::IntegrateGaussian(Int_t k,Double_t par, Double_t w,
 
        // for the time being, signal is the charge
        // in ChargeToSignal signal is converted in ADC channel
-       signal = fMapA2->GetSignal(k,strip);
-       signal += dXCharge1;
-
-       fMapA2->SetHit(k,strip,(Double_t)signal);
-       if(((Int_t) strip) < (fNstrips-1)) {
-           // strip doesn't have to be the last (remind: last=fNstrips-1)
+       fMapA2->AddSignal(k,(Int_t)strip,dXCharge1);
+       if(((Int_t) strip) < (GetNStrips()-1)) {
+           // strip doesn't have to be the last (remind: last=GetNStrips()-1)
            // otherwise part of the charge is lost
-           signal = fMapA2->GetSignal(k,(strip+1));
-           signal += dXCharge2;
-           fMapA2->SetHit(k,(strip+1),(Double_t)signal);
+           fMapA2->AddSignal(k,((Int_t)strip+1),dXCharge2);
        } // end if
     
        if(dXCharge1 > 1.) {
            if (first) {
-               indexRange[k*2+0]=indexRange[k*2+1]=(Int_t) strip;
+               indexRange[k*2+0] = indexRange[k*2+1]=(Int_t) strip;
                first=kFALSE;
            } // end if first
 
@@ -360,15 +408,11 @@ void AliITSsimulationSSD::IntegrateGaussian(Int_t k,Double_t par, Double_t w,
 
        // for the time being, signal is the charge
        // in ChargeToSignal signal is converted in ADC channel
-       signal = fMapA2->GetSignal(k,strip);
-       signal += dXCharge1;
-       fMapA2->SetHit(k,strip,(Double_t)signal);
+       fMapA2->AddSignal(k,(Int_t)strip,dXCharge1);
        if(((Int_t) strip) > 0) {
            // strip doesn't have to be the first
            // otherwise part of the charge is lost
-           signal = fMapA2->GetSignal(k,(strip-1));
-           signal += dXCharge2;
-           fMapA2->SetHit(k,(strip-1),(Double_t)signal);
+           fMapA2->AddSignal(k,((Int_t)strip-1),dXCharge2);
        } // end if
     
        if(dXCharge1 > 1.) {
@@ -404,123 +448,120 @@ Int_t AliITSsimulationSSD::NumOfSteps(Double_t x, Double_t y, Double_t z,
     return numOfSteps;
 }
 //----------------------------------------------------------------------
-void AliITSsimulationSSD::GetList(Int_t label,Float_t **pList,
-                                 Int_t *indexRange) {
+void AliITSsimulationSSD::GetList(Int_t label,Int_t hit,Int_t mod,
+                                 AliITSpList *pList,Int_t *indexRange) {
     // loop over nonzero digits
-    Int_t ix,globalIndex;
-    Float_t signal=0.;
-    Float_t highest,middle,lowest;
-  // printf("SPD-GetList: indexRange[0] indexRange[1] indexRange[2] indexRange[3] %d %d %d %d\n",indexRange[0], indexRange[1], indexRange[2], indexRange[3]);
+    Int_t ix,i;
+    Double_t signal=0.;
 
     for(Int_t k=0; k<2; k++) {
        for(ix=indexRange[k*2+0];ix<indexRange[k*2+1]+1;ix++){
-           if(indexRange[k*2+0]<indexRange[k*2+1]) 
-               signal=fMapA2->GetSignal(k,ix);
-      
-           globalIndex = k*fNstrips+ix; // globalIndex starts from 0!
-           if(!pList[globalIndex]){
-               // 
-               //Create new list (6 elements-3 signals and 3 tracks+total sig)
-               //
-               pList[globalIndex] = new Float_t [6];
-               // set list to -1
-               *pList[globalIndex] = -2.;
-               *(pList[globalIndex]+1) = -2.;
-               *(pList[globalIndex]+2) = -2.;
-               *(pList[globalIndex]+3) =  0.;
-               *(pList[globalIndex]+4) =  0.;
-               *(pList[globalIndex]+5) =  0.;
-               *pList[globalIndex] = (float)label;
-               *(pList[globalIndex]+3) = signal;
-           }else{
+//         if(indexRange[k*2+0]<indexRange[k*2+1]) 
+               signal = fMapA2->GetSignal(k,ix);
+               if(signal==0.0) continue;
                // check the signal magnitude
-               highest = *(pList[globalIndex]+3);
-               middle = *(pList[globalIndex]+4);
-               lowest = *(pList[globalIndex]+5);
-               signal -= (highest+middle+lowest);
-               //
+               for(i=0;i<pList->GetNSignals(k,ix);i++) 
+                   signal -= pList->GetTSignal(k,ix,i);
                //  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;
-               }else if (signal>middle){
-                   *(pList[globalIndex]+5) = middle;
-                   *(pList[globalIndex]+4) = signal;
-                   *(pList[globalIndex]+2) = *(pList[globalIndex]+1);
-                   *(pList[globalIndex]+1) = label;
-               }else{
-                   *(pList[globalIndex]+5) = signal;
-                   *(pList[globalIndex]+2) = label;
-               } // end if
-           } // end if
+               pList->AddSignal(k,ix,label,hit,mod,signal);
        } // end of loop pixels in x
     } // end of loop over pixels in z
 }
 //----------------------------------------------------------------------
-void AliITSsimulationSSD::ChargeToSignal(Float_t **pList) {
+void AliITSsimulationSSD::ChargeToSignal(AliITSpList *pList) {
     // charge to signal
-    AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
+    static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
     Float_t threshold = 0.;
-    Int_t digits[3], tracks[3],hits[3],gi,j1;
-    Float_t charges[3];
-    Float_t signal,phys;
+    Int_t   digits[3], tracks[3],hits[3],j1;
+    Float_t charges[3] = {0.0,0.0,0.0};
+    Float_t signal;
     Float_t noise[2] = {0.,0.};
 
-    fResponse->GetNoiseParam(noise[0],noise[1]);
-  
-    for(Int_t k=0;k<2;k++){         // both sides (0=Pside, 1=Nside)
+    ((AliITSresponseSSD*)fResponse)->GetNoiseParam(noise[0],noise[1]);
 
+    for(Int_t k=0;k<2;k++){         // both sides (0=Pside, 1=Nside)
        // Threshold for zero-suppression
        // It can be defined in AliITSresponseSSD
        //             threshold = (Float_t)fResponse->MinVal(k);
        // I prefer to think adjusting the threshold "manually", looking
        // at the scope, and considering noise standard deviation
-       threshold = 4.0*noise[k];      // 4 times noise is a choice
-       for(Int_t ix=0;ix<fNstrips;ix++){         // loop over strips
-
-           signal = (Float_t) fMapA2->GetSignal(k,ix);
-
-           gi =k*fNstrips+ix; // global index
-           if (signal > threshold) {
-               digits[0]=k;
-               digits[1]=ix;
-
-               // convert to ADC signal
-               // conversion factor are rather arbitrary (need tuning)
-               // minimum ionizing particle--> ~30000 pairs--> ADC channel 50
-               signal = signal*50.0/30000.0;        
-               if(signal>1000.) signal = 1000.0;//if exceeding, accumulate
-                                                 // last one
-               digits[2]=(Int_t) signal;
-
-               //gi =k*fNstrips+ix; // global index
-               for(j1=0;j1<3;j1++){
-                   if (pList[gi]) {
-                       tracks[j1] = (Int_t)(*(pList[gi]+j1));
-                   } else {
-                       tracks[j1]=-2; //noise
-                   } // end if pList
-                   charges[j1] = 0;
-               } // end for j1
-
-               phys=0;
-
-               hits[0]=0;
-               hits[1]=0;
-               hits[2]=0;
-               // finally add digit
-               aliITS->AddSimDigit(2,phys,digits,tracks,hits,charges);
-
-               //if(pList[gi]) delete [] pList[gi];
-           } // end if signal > threshold
-           if(pList[gi]) delete [] pList[gi];
+       threshold = 4.0*noise[k]; // 4 times noise is a choice
+       for(Int_t ix=0;ix<GetNStrips();ix++){     // loop over strips
+           if(fMapA2->GetSignal(k,ix) <= threshold) continue;
+           // convert to ADC signal
+           signal = ((AliITSresponseSSD*)fResponse)->DEvToADC(
+                                                  fMapA2->GetSignal(k,ix));
+           if(signal>1024.) signal = 1024.;//if exceeding, accumulate last one
+           digits[0] = k;
+           digits[1] = ix;
+           digits[2] = (Int_t) signal;
+           for(j1=0;j1<3;j1++){ // only three in digit.
+               tracks[j1]  = pList->GetTrack(k,ix,j1);
+               hits[j1]    = pList->GetHit(k,ix,j1);
+           } // end for j1
+           // finally add digit
+           aliITS->AddSimDigit(2,0,digits,tracks,hits,charges);
        } // end for ix
     } // end for k
-    delete [] pList;
 }
+//______________________________________________________________________
+void AliITSsimulationSSD::WriteSDigits(AliITSpList *pList){
+    // Fills the Summable digits Tree
+    Int_t i,ni,j,nj;
+    static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
+
+    pList->GetMaxMapIndex(ni,nj);
+    for(i=0;i<ni;i++)for(j=0;j<nj;j++){
+       if(pList->GetSignalOnly(i,j)>0.0){
+           aliITS->AddSumDigit(*(pList->GetpListItem(i,j)));
+//         cout << "pListSSD: " << *(pList->GetpListItem(i,j)) << endl;
+       } // end if
+    } // end for i,j
+    return;
+}
+//______________________________________________________________________
+void AliITSsimulationSSD::FillMapFrompList(AliITSpList *pList){
+    // Fills fMap2A from the pList of Summable digits
+    Int_t k,ix;
+
+    for(k=0;k<2;k++)for(ix=0;ix<GetNStrips();ix++) 
+       fMapA2->AddSignal(k,ix,pList->GetSignal(k,ix));
+    return;
+}
+//______________________________________________________________________
+void AliITSsimulationSSD::Print(ostream *os){
+    //Standard output format for this class
+
+    //AliITSsimulation::Print(os);
+    *os << fIonE <<",";
+    *os << fDifConst[0] <<","<< fDifConst[1] <<",";
+    *os << fDriftVel[0] <<","<< fDriftVel[1];
+    //*os <<","; fDCS->Print(os);
+    //*os <<","; fMapA2->Print(os);
+}
+//______________________________________________________________________
+void AliITSsimulationSSD::Read(istream *is){
+    // Standard output streaming function.
+
+    //AliITSsimulation::Read(is);
+    *is >> fIonE;
+    *is >> fDifConst[0] >> fDifConst[1];
+    *is >> fDriftVel[0] >> fDriftVel[1];
+    //fDCS->Read(is);
+    //fMapA2->Read(is);
+}
+//______________________________________________________________________
+ostream &operator<<(ostream &os,AliITSsimulationSSD &source){
+    // Standard output streaming function.
+
+    source.Print(&os);
+    return os;
+}
+//______________________________________________________________________
+istream &operator>>(istream &os,AliITSsimulationSSD &source){
+    // Standard output streaming function.
+
+    source.Read(&os);
+    return os;
+}
+//______________________________________________________________________