+ +

This show the relasionships between the ITS hit class and the rest of Aliroot. + +

```+*/
+//End_Htm
+//extern Int_t power(Int_t b, Int_t e);
+
+//_____________________________________________________________________________
+ClassImp(AliITSetfSDD)
+
+Int_t ppower(Int_t b, Int_t e) {
+  Int_t power = 1,i;
+  for(i=0; i= PI) VA -= (2.*PI);
+          if(VA <= -PI) VA += (2.*PI);
+	  //cout << "VM: " << VM << ", VA: " << VA << endl;
+        }
+      }
+
+      if(fPole_M[k]) {
+        Double_t VPR = -fPole_R[k];
+        Double_t VPI = frequency - fPole_I[k];
+	Double_t VPM = TMath::Sqrt(VPR*VPR+VPI*VPI);
+	Double_t VPA = TMath::ATan2(VPI,VPR);
+	//cout << "VPM: " << VPM << ", VPA: " << VPA << endl;
+	//cout << "VPR: " << VPR << ", VPI: " << VPI << endl;
+        for(j=1; j<= (Int_t) fPole_M[k]; j++) {
+          VM /= VPM;
+          VA -= VPA;
+          if(VA >= PI) VA -= (2.*PI);
+          if(VA <= -PI) VA += (2.*PI);
+	  //cout << "VM: " << VM << ", VA: " << VA << endl;
+        }
+      }
+      Double_t VR = VM*cos(VA);
+      Double_t VI = VM*sin(VA);
+      //cout << "VM: " << VM << ", VA: " << VA << endl;
+      //cout << "VR: " << VR << ", VI: " << VI << endl;
+      fTf_R[i] = VR*ppower(10,9);
+      fTf_I[i] = VI*ppower(10,9);
+      //cout << "fTf_R[" << i << "] = " << fTf_R[i] << endl;
+      //cout << "fTf_I[" << i << "] = " << fTf_I[i] << endl;
+      if(i) {
+        fTf_R[fMaxNofSamples-i] = fTf_R[i];
+        fTf_I[fMaxNofSamples-i] = -fTf_I[i];
+      }
+    }
+  }
+
+  // Compute Fourier Weights
+
+  for(i=0; i<=fMaxNofSamples/2; i++) {
+    fW_R[i] = cos(-2.*PI*i/fMaxNofSamples);
+    fW_I[i] = sin(-2.*PI*i/fMaxNofSamples);
+    if(i) {
+      fW_R[fMaxNofSamples-i] = fW_R[i];
+      fW_I[fMaxNofSamples-i] = -fW_I[i];
+    }
+  }
+
+}
+
+void AliITSetfSDD::Print()
+{
+  Int_t i;
+  cout << "Sampling Time " << fSamplingTime << endl;
+  cout << "Number of Time Samples " << fMaxNofSamples << endl;
+  cout << "fT0 " << fT0 << endl;
+  cout << "fDf " << fDf << endl;
+  cout << "fA0 " << fA0 << endl;
+
+  cout << "Zero's and Pole's" << endl;
+  cout << "fZero_M " << endl;
+  for(i=0; i
+
+class AliITSetfSDD : public TObject {
+
+////////////////////////////////////////////////////////////////////////
+// Version: 0
+// Written by Piergiorgio Cerello
+// November 24 1999
+//
+// AliITSetfSDD is the class describing the electronics for the ITS SDDs.
+//
+// Data members:
+//
+////////////////////////////////////////////////////////////////////////
+
+ private:
+
+  Double_t fSamplingTime;      //
+  Double_t fT0;                //
+  Double_t fDf;                //
+  Double_t fA0;                //
+  static const Int_t fMaxNofPoles = 5;
+  Double_t fZero_M[fMaxNofPoles];  //
+  Double_t fZero_R[fMaxNofPoles];  //
+  Double_t fZero_I[fMaxNofPoles];  //
+  Double_t fPole_M[fMaxNofPoles];  //
+  Double_t fPole_R[fMaxNofPoles];  //
+  Double_t fPole_I[fMaxNofPoles];  //
+  static const Int_t fMaxNofSamples = 256;
+  Double_t fTf_R[fMaxNofSamples];     // Transfer function (real part)
+  Double_t fTf_I[fMaxNofSamples];     // Transfer function (imaginary part)
+  Double_t fW_R[fMaxNofSamples];     // Fourier Weights (real part)
+  Double_t fW_I[fMaxNofSamples];     // Fourier Weights (imaginary part)
+
+ public:
+
+  AliITSetfSDD() {};                 // default constructor
+  AliITSetfSDD(Double_t);
+  ~AliITSetfSDD() {;}
+  Double_t GetWeightReal(Int_t n) { return fW_R[n]; }
+  Double_t GetWeightImag(Int_t n) { return fW_I[n]; }
+  Double_t GetTraFunReal(Int_t n) { return fTf_R[n]; }
+  Double_t GetTraFunImag(Int_t n) { return fTf_I[n]; }
+  Int_t GetSamples() { return fMaxNofSamples; }
+  void Print();          // Print Electronics parameters
+
+  friend class AliITSmapSDD;
+  ClassDef(AliITSetfSDD,1)  // Class for SDD electornics
+    };
+
+#endif
+
+
diff --git a/ITS/AliITSpackageSSD.cxx b/ITS/AliITSpackageSSD.cxx
new file mode 100644
index 0000000..5c36f8f
--- /dev/null
+++ b/ITS/AliITSpackageSSD.cxx
@@ -0,0 +1,656 @@
+#include "AliITSpackageSSD.h"
+//************************************************
+//Piotr Krzysztof Skowronski
+//Warsaw University of Technology
+//skowron@if.pw.edu.pl
+//
+
+const Int_t debug=0;
+
+ClassImp(AliITSpackageSSD)
+
+AliITSpackageSSD::AliITSpackageSSD()
+{
+  fNclustersN=0;
+  fClusterNIndexes = new TArrayI(300);
+
+  fNclustersP=0;
+  fClusterPIndexes = new TArrayI(300);
+  if (debug) cout<<"Default Ctor was used\n>>>>>>>>>>>>>><<<<<<<<<<<<<";
+}
+
+
+/*******************************************************/
+
+AliITSpackageSSD::AliITSpackageSSD
+  (TClonesArray *clustersP, TClonesArray *clustersN)
+{
+  fClustersP=clustersP;
+  fClustersN=clustersN;
+
+  fNclustersN=0;
+  fClusterNIndexes = new TArrayI(300);
+
+  fNclustersP=0;
+  fClusterPIndexes = new TArrayI(300);
+}
+
+/*******************************************************/
+
+
+AliITSpackageSSD::AliITSpackageSSD
+  ( Int_t len, TClonesArray *clustersP, TClonesArray *clustersN)
+
+{
+  fClustersP=clustersP;
+  fClustersN=clustersN;
+
+  fNclustersN=0;
+  fClusterNIndexes = new TArrayI(len);
+
+  fNclustersP=0;
+  fClusterPIndexes = new TArrayI(len);
+}
+
+
+/*******************************************************/
+
+AliITSpackageSSD::~AliITSpackageSSD()
+{
+  // destructor
+  delete fClusterNIndexes;
+  delete fClusterPIndexes;
+}
+/*******************************************************/
+
+AliITSpackageSSD::AliITSpackageSSD(const AliITSpackageSSD &package)
+{
+  // copy constractor
+  Int_t i;  //iterator
+
+  if (this == &package) return;
+  fClustersN = package.fClustersN;
+  fClustersP = package.fClustersP;
+
+  fNclustersN= package.fNclustersN;
+  fNclustersP= package.fNclustersP;
+
+  for(i =0; i>>>>>>>>>>>>>>>";
+
+  return;
+
+}
+/*******************************************************/
+
+AliITSpackageSSD&
+AliITSpackageSSD::operator=( const AliITSpackageSSD & package)
+{
+
+Int_t i;  //iterator
+
+if (this == &package) return *this;
+fClustersN = package.fClustersN;
+fClustersP = package.fClustersP;
+
+fNclustersN= package.fNclustersN;
+fNclustersP= package.fNclustersP;
+
+for(i =0; i>>>>>>>>>>>>>>>";
+
+return *this;
+
+}
+
+
+/*******************************************************/
+
+Int_t
+AliITSpackageSSD::GetNSideClusterIdx(Int_t index)
+
+{
+  if ((index>-1)&&(index-1)&&(indexGetCrossNo()  ) ==1 )
+  {
+    //index=ind;
+    index =fNclustersP-1;
+    side=SIDEP;
+    return kTRUE;
+  }
+
+ ind =(*fClusterNIndexes)[fNclustersN-1];
+ if (  (  ((AliITSclusterSSD*)(*fClustersN)[ind]  )->GetCrossNo() ) ==1  )
+  {
+    //index=ind;
+    index = fNclustersN-1;
+    side=SIDEN;
+    return kTRUE;
+  }
+
+
+ ind =(*fClusterPIndexes)[0];
+ if (  ( ((AliITSclusterSSD*)(*fClustersP)[ind]  )->GetCrossNo() ) ==1 )
+  {
+    //index=ind;
+    index = 0;
+    side=SIDEP;
+    return kTRUE;
+  }
+
+
+ ind =(*fClusterNIndexes)[0];
+ if (  ( ((AliITSclusterSSD*)(*fClustersN)[ind]  )->GetCrossNo()  ) ==1  )
+  {
+//    index=ind;
+    index = 0;
+    side=SIDEN;
+    return kTRUE;
+  }
+
+
+ //Add for to be shure
+ index = -1;
+ return kFALSE;
+
+}
+/*******************************************************/
+
+void AliITSpackageSSD::DelCluster(Int_t index, Bool_t side)
+{
+  if(side==SIDEP) DelPCluster(index); else DelNCluster(index);
+}
+/*******************************************************/
+void AliITSpackageSSD::DelPCluster(Int_t index)
+{
+
+//it not deletes delete given cluster physically,
+//but only complytely erase it from package
+//all clusters are deleted automatically when TClonesArray is deleted
+
+  Int_t i;
+  Int_t idx;
+  Int_t clToDelIdx = GetPSideClusterIdx(index); //Index of cluster in TClonesArray
+  AliITSclusterSSD *clToDel = GetPSideCluster(index); //cluster to be deleted
+  Int_t ncr = clToDel->GetCrossNo();
+
+  for(i =0;iGetCross(i);
+    ((AliITSclusterSSD *)((*fClustersN)[idx])   )->DelCross(clToDelIdx);
+   }
+
+
+ for(i=index;iGetCrossNo())==0) DelNCluster(i);
+  }
+}
+
+
+
+/*******************************************************/
+void AliITSpackageSSD::DelNCluster(Int_t index)
+{
+
+//it not deletes delete given cluster physically,
+//but only complytely erase it from package
+//all clusters are deleted automatically when TClonesArray is deleted
+
+  Int_t i;
+  Int_t idx;
+  Int_t clToDelIdx = GetNSideClusterIdx(index); //Index of cluster in TClonesArray
+  AliITSclusterSSD *clToDel = GetNSideCluster(index); //cluster to be deleted
+  Int_t ncr = clToDel->GetCrossNo();
+
+  for(i =0;iGetCross(i);
+    ((AliITSclusterSSD *)((*fClustersP)[idx])   )->DelCross(clToDelIdx);
+   }
+
+
+ for(i=index;iGetCrossNo())==0) DelPCluster(i);
+  }
+
+}
+
+
+/*******************************************************/
+
+void AliITSpackageSSD::DelPClusterOI(Int_t index)
+{
+//This function looks like this,
+//because probably cut cluster is
+//on the beginning or on the end of package
+ Int_t i;
+ if( ((*fClusterPIndexes)[0]) == index)
+  {
+    DelPCluster(0);
+    return;
+  }
+ else
+  {
+   if( ((*fClusterPIndexes)[fNclustersP-1]) ==index)
+    {
+      DelPCluster(fNclustersP-1);
+      return;
+    }
+   else
+    {
+     for(i=1;iGetCrossNo();  //number of crosses for this cluster
+ Int_t indcro;                 //index of given cluster on side N that
+                               // this cluster crosses with
+
+ // printf("NC %d \n",NC);
+
+
+ if (np == fNclustersP-1) {
+   //printf("if \n");
+   for(i=0;iGetCross(i);
+     //printf("if: i indcro %d %d\n",i, indcro);
+     if(IsFree(indcro,np,occup)) {
+        occup[np]=indcro;
+	//printf("if- isFree: i np occup[np] %d %d %d\n",i,np,occup[np]);
+        for(j=0;jGetCross(i);
+       //printf("else: i indcro %d %d\n",i, indcro);
+       if(IsFree(indcro,np,occup)) {
+      	  occup[np]=indcro;
+	  //printf("else:recursive call - i np occup %d %d %d\n",i,np,occup[np]);
+	  if (nuGetCrossNo();j++)
+    {
+      cout<GetCross(j)<<" ";
+    }
+ //  if (GetPSideCluster(i)->GetSide()) cout<<" P\n";
+ //  else cout<<"BAD SIDE ==N\n";
+    cout<<"\n";
+
+ }
+
+cout <<"SIDE N\n";
+for(i=0;iGetCrossNo();j++)
+    {
+      cout<GetCross(j)<<" ";
+    }
+ //  if (GetNSideCluster(i)->GetSide()) cout<<" N\n";
+ //  else cout<<"BAD SIDE ==P\n";
+    cout<<"\n";
+ }
+
+
+
+}
+/**********************************************/
+void AliITSpackageSSD::ConsumeClusters()
+{
+register Int_t i;
+
+for(i=0;iConsume();
+ }
+
+for(i=0;iConsume();
+ }
+
+}
+
+/**********************************************/
+
+Int_t AliITSpackageSSD::GetNextPIdx(Int_t OI)
+{
+ //Returns index of next P cluster OI in package; OI == Original Inedx (in TClonesArray)
+ //if not egsist return -1;
+ Int_t i;
+ for(i =0; i
+#include
+#include "AliITSsegmentation.h"
+
+class AliITSgeom;
+
+//----------------------------------------------
+//
+// ITS response virtual base class
+//
+class AliITSresponse :
+public TObject {
+ public:
+    //
+    // Configuration methods
+    //
+
+    // Set maximum Adc-count value
+    virtual void    SetMaxAdc(Float_t p1) {}
+    // Get maximum Adc-count value
+    virtual Float_t MaxAdc()  {return 0.;}
+
+    // Set maximum Adc-magic value
+    virtual void    SetMagicValue(Float_t p1) {}
+    // Get maximum Adc-magic value
+    virtual Float_t MagicValue()  {return 0.0;}
+
+    // Diffusion coefficient
+    virtual void    SetDiffCoeff(Float_t)                     =0;
+    // Get diffusion coefficient
+    virtual Float_t DiffCoeff()                               =0;
+    virtual Float_t Qref() {return 0.;}
+
+    // Temperature
+    virtual void    SetTemperature(Float_t) {}
+    // Get temperature
+    virtual Float_t Temperature() {return 0.;}
+    // Type of data - real or simulated
+    virtual void    SetDataType(char *data)        =0;
+    // Get data type
+    virtual const char  *DataType()                =0;
+
+
+
+    // parameters: "same" or read from "file" or "SetInvalid" or ...
+    virtual void    SetParamOptions(Option_t *opt1, Option_t *opt2) {}
+    virtual  void   SetNoiseParam(Float_t, Float_t) {}
+    // gain, coupling ...
+    // Number of parameters to be set
+    virtual  void   SetNDetParam(Int_t) {}
+    virtual  void   SetDetParam(Float_t *) {}
+
+    // Parameters options
+    virtual void   ParamOptions(Option_t *&, Option_t *&) {}
+    virtual Int_t  NDetParam() {return 0;}
+    virtual void   GetDetParam(Float_t *) {}
+    virtual void   GetNoiseParam(Float_t&, Float_t&) {}
+
+    // Zero-suppression option - could be 1D, 2D or non-ZS
+    virtual void   SetZeroSupp(Option_t *opt) {}
+    // Get zero-suppression option
+    virtual Option_t   *ZeroSuppOption() {return "";}
+     // Set thresholds
+    virtual void   SetThresholds(Float_t, Float_t) {}
+    virtual void   Thresholds(Float_t &, Float_t &) {}
+    // Set min val
+    virtual void   SetMinVal(Int_t) {};
+    virtual Int_t  MinVal() {return 0;};
+
+    // Set filenames
+    virtual void   SetFilenames(char *,char *,char *) {}
+    // Filenames
+    virtual void   Filenames(const char*&,const char*&,const char*&) {}
+
+
+    virtual Float_t DriftSpeed() {return 0.;}
+    virtual Bool_t  OutputOption() {return kFALSE;}
+    virtual void    GiveCompressParam(Int_t *x) {}
+
+    //
+    // Detector type response methods
+    // Set number of sigmas over which cluster disintegration is performed
+    virtual void    SetNSigmaIntegration(Float_t p1) {}
+    // Get number of sigmas over which cluster disintegration is performed
+    virtual Float_t NSigmaIntegration() {return 0.;}
+    // Set sigmas of the charge spread function
+    virtual void    SetSigmaSpread(Float_t p1, Float_t p2) {}
+    // Get sigmas for the charge spread
+    virtual void    SigmaSpread(Float_t &s1, Float_t &s2) {}
+
+
+    // Pulse height from scored quantity (eloss)
+    virtual Float_t IntPH(Float_t eloss) {return 0.;}
+    // Charge disintegration
+    virtual Float_t IntXZ(AliITSsegmentation *) {return 0.;}
+
+    ClassDef(AliITSresponse,1) // Detector type response virtual base class
+};
+#endif
+
+
+
+
+
+
+
diff --git a/ITS/AliITSresponseSDD.cxx b/ITS/AliITSresponseSDD.cxx
new file mode 100644
index 0000000..6662c84
--- /dev/null
+++ b/ITS/AliITSresponseSDD.cxx
@@ -0,0 +1,158 @@
+/**************************************************************************
+ *                                                                         *
+ * 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.                  *
+ **************************************************************************/
+
+#include
+
+#include "AliITSgeom.h"
+#include "AliITSresponseSDD.h"
+#include "AliITS.h"
+#include "AliRun.h"
+
+class AliITS;
+
+//___________________________________________
+ClassImp(AliITSresponseSDD)
+
+AliITSresponseSDD::AliITSresponseSDD()
+{
+  // constructor
+   SetDiffCoeff();
+   SetQref();
+   SetDriftSpeed();
+   // SetClock();
+   SetNoiseParam();
+   SetMagicValue();
+   SetMinVal();
+   SetParamOptions();
+   SetZeroSupp();
+   SetDataType();
+   SetFilenames();
+   SetOutputOption();
+
+}
+
+//__________________________________________________________________________
+AliITSresponseSDD::AliITSresponseSDD(const AliITSresponseSDD &source){
+  //     Copy Constructor
+  if(&source == this) return;
+  this->fCPar = source.fCPar;
+  this->fNoise = source.fNoise;
+  this->fBaseline = source.fBaseline;
+  this->fTopValue = source.fTopValue;
+  this->fTemperature = source.fTemperature;
+  this->fDriftSpeed = source.fDriftSpeed;
+  this->fDiffCoeff = source.fDiffCoeff;
+  this->fQref = source.fQref;
+  this->fZeroSuppFlag = source.fZeroSuppFlag;
+  this->fMinVal = source.fMinVal;
+  this->fWrite = source.fWrite;
+  this->fOption = source.fOption;
+  this->fParam1 = source.fParam1;
+  return;
+}
+
+//_________________________________________________________________________
+AliITSresponseSDD&
+  AliITSresponseSDD::operator=(const AliITSresponseSDD &source) {
+  //    Assignment operator
+  if(&source == this) return *this;
+  this->fCPar = source.fCPar;
+  this->fNoise = source.fNoise;
+  this->fBaseline = source.fBaseline;
+  this->fTopValue = source.fTopValue;
+  this->fTemperature = source.fTemperature;
+  this->fDriftSpeed = source.fDriftSpeed;
+  this->fDiffCoeff = source.fDiffCoeff;
+  this->fQref = source.fQref;
+  this->fZeroSuppFlag = source.fZeroSuppFlag;
+  this->fMinVal = source.fMinVal;
+  this->fWrite = source.fWrite;
+  this->fOption = source.fOption;
+  this->fParam1 = source.fParam1;
+  return *this;
+}
+
+void AliITSresponseSDD::SetCompressParam(Int_t  cp[8])
+{
+  // set compression param
+    Int_t i;
+    for(i=0; i<8; i++) {
+	fCPar[i]=cp[i];
+	//printf("\n CompressPar %d %d \n",i,fCPar[i]);
+
+    }
+}
+void AliITSresponseSDD::GiveCompressParam(Int_t  cp[8])
+{
+  // give compression param
+    Int_t i;
+    for(i=0; i<8; i++) {
+	cp[i]=fCPar[i];
+    }
+}
+//______________________________________________________________________________
+void AliITSresponseSDD::Streamer(TBuffer &R__b)
+{
+   // Stream an object of class AliITSresponseSDD.
+
+   if (R__b.IsReading()) {
+      Version_t R__v = R__b.ReadVersion(); if (R__v) { }
+      AliITSresponse::Streamer(R__b);
+      R__b >> fNoise;
+      R__b >> fBaseline;
+      R__b >> fTopValue;
+      R__b >> fTemperature;
+      R__b >> fDriftSpeed;
+      R__b >> fMaxAdc;
+      R__b >> fDiffCoeff;
+      R__b >> fQref;
+      R__b >> fZeroSuppFlag;
+      R__b >> fMinVal;
+      R__b >> fWrite;
+      //R__b.ReadArray(fOption); // Not to be printed out?
+      //R__b.ReadArray(fParam1); // Not to be printed out?
+      //R__b.ReadArray(fParam2); // Not to be printed out?
+      fDataType.Streamer(R__b);
+      fFileName1.Streamer(R__b);
+      fFileName2.Streamer(R__b);
+      fFileName3.Streamer(R__b);
+   } else {
+      R__b.WriteVersion(AliITSresponseSDD::IsA());
+      AliITSresponse::Streamer(R__b);
+      R__b.WriteArray(fCPar, 8);
+      R__b << fNoise;
+      R__b << fBaseline;
+      R__b << fTopValue;
+      R__b << fTemperature;
+      R__b << fDriftSpeed;
+      R__b << fMaxAdc;
+      R__b << fDiffCoeff;
+      R__b << fQref;
+      R__b << fZeroSuppFlag;
+      R__b << fMinVal;
+      R__b << fWrite;
+      //R__b.WriteArray(fOption, __COUNTER__); // Not to be printed out?
+      //R__b.WriteArray(fParam1, __COUNTER__); // Not to be printed out?
+      //R__b.WriteArray(fParam2, __COUNTER__); // Not to be printed out?
+      fDataType.Streamer(R__b);
+      fFileName1.Streamer(R__b);
+      fFileName2.Streamer(R__b);
+      fFileName3.Streamer(R__b);
+   }
+}
diff --git a/ITS/AliITSresponseSDD.h b/ITS/AliITSresponseSDD.h
new file mode 100644
index 0000000..a06de3c
--- /dev/null
+++ b/ITS/AliITSresponseSDD.h
@@ -0,0 +1,208 @@
+#ifndef ALIITSRESPONSESDD_H
+#define ALIITSRESPONSESDD_H
+
+#include "AliITSresponse.h"
+
+// response for SDD
+
+class AliITSresponseSDD :
+  public AliITSresponse {
+public:
+  //
+  // Configuration methods
+  //
+
+  AliITSresponseSDD();
+  virtual ~AliITSresponseSDD() {
+    // destructor
+  }
+  AliITSresponseSDD(const AliITSresponseSDD &source); // copy constructor
+  AliITSresponseSDD& operator=(const AliITSresponseSDD &source); // ass. op.
+
+  virtual void    SetMaxAdc(Float_t p1=1023) {
+    // Adc-count saturation value
+  }
+  virtual Float_t MaxAdc()  {
+    // Get maximum Adc-count value
+  }
+
+  virtual void    SetMagicValue(Float_t p1=450.) {
+    // Set maximum Adc-magic value
+    fTopValue=p1;
+  }
+  virtual Float_t MagicValue()  {
+    // Get maximum Adc-magic value
+    return fTopValue;
+  }
+
+  virtual void    SetDiffCoeff(Float_t p1=5.) {
+    // Diffusion coefficient
+    fDiffCoeff=p1;
+  }
+  virtual Float_t DiffCoeff() {
+    // Get diffusion coefficient
+    return fDiffCoeff;
+  }
+
+  virtual void    SetQref(Float_t p1=120.) {
+    // Coulomb repulsion
+    fQref=p1;
+  }
+  virtual Float_t Qref() {
+    // qref
+    return fQref;
+  }
+
+  virtual void    SetDriftSpeed(Float_t p1=7.5) {
+    // Drift velocity
+    fDriftSpeed=p1;
+  }
+  virtual Float_t DriftSpeed() {
+    // drift speed
+    return fDriftSpeed;
+  }
+
+  virtual void    SetTemperature(Float_t p1=23.) {
+    // Temperature
+    fTemperature=p1;
+  }
+  virtual Float_t Temperature() {
+    // Get temperature
+    return fTemperature;
+  }
+
+  virtual void    SetDataType(char *data="simulated") {
+    // Type of data - real or simulated
+    fDataType=data;
+  }
+  virtual const char  *DataType() {
+    // Get data type
+    return fDataType.Data();
+  }
+
+  virtual void SetParamOptions(Option_t *opt1="same",Option_t *opt2="same"){
+    // Parameters: "same" or read from "file"
+    fParam1=opt1; fParam2=opt2;
+  }
+  virtual void   ParamOptions(Option_t *&opt1,Option_t *&opt2) {
+    // options
+    opt1=fParam1; opt2=fParam2;
+  }
+
+  virtual  void  SetNoiseParam(Float_t n=3., Float_t b=20.){
+    // Noise and baseline
+    fNoise=n; fBaseline=b;
+  }
+  virtual  void  GetNoiseParam(Float_t &n, Float_t &b) {
+    // get noise param
+    n=fNoise; b=fBaseline;
+  }
+
+  virtual void    SetZeroSupp(Option_t *opt="2D") {
+    // Zero-suppression option - could be 1D, 2D or non-ZS
+    fOption=opt;
+  }
+  virtual Option_t *ZeroSuppOption() {
+    // Get zero-suppression option
+    return fOption;
+  }
+  virtual  void  SetMinVal(Int_t mv=4) {
+    // Min value used in 2D - could be used as a threshold setting
+    fMinVal = mv;
+  }
+  virtual Int_t  MinVal() {
+    // min val
+    return fMinVal;
+  }
+
+  virtual void   SetFilenames(char *f1=0,char *f2=0, char *f3=0) {
+    // Set filenames - input, output, parameters ....
+    fFileName1=f1; fFileName2=f2; fFileName3=f3;
+  }
+  virtual void   Filenames(const char*&input,const char*&baseline,const char*¶m) {
+    // Filenames
+    input=fFileName1; baseline=fFileName2; param=fFileName3;
+  }
+
+
+  virtual  void  SetOutputOption(Bool_t write=kFALSE) {
+    // set output option
+    fWrite = write;
+  }
+  Bool_t OutputOption()  {
+    // output option
+    return fWrite;
+  }
+  //
+  // Compression parameters
+  virtual  void  SetCompressParam(Int_t cp[8]);
+  void  GiveCompressParam(Int_t *x);
+
+  //
+  // Detector type response methods
+  virtual void    SetNSigmaIntegration(Float_t p1) {
+    // Set number of sigmas over which cluster disintegration is performed
+  }
+  virtual Float_t NSigmaIntegration() {
+    // Get number of sigmas over which cluster disintegration is performed
+    return 0.;
+  }
+  virtual void    SetSigmaSpread(Float_t p1, Float_t p2) {
+    // Set sigmas of the charge spread function
+  }
+  virtual void    SigmaSpread(Float_t &s1, Float_t &s2) {
+    // Get sigmas for the charge spread
+  }
+
+  virtual Float_t IntPH(Float_t eloss) {
+    // Pulse height from scored quantity (eloss)
+    return 0.;
+  }
+  virtual Float_t IntXZ(AliITSsegmentation *) {
+    // Charge disintegration
+    return 0.;
+  }
+
+
+protected:
+
+  Int_t     fCPar[8];        // Hardware compression parameters
+  //Int_t     fNDetPar;        // Number of detector param
+  //Float_t   fDetPar[fNDetPar];
+
+  Float_t   fNoise;          // Noise
+  Float_t   fBaseline;       // Baseline
+  Float_t   fTopValue;       // still unclear to me
+  Float_t   fTemperature;    // Temperature
+  Float_t   fDriftSpeed;     // Drift velocity
+
+  Float_t    fMaxAdc;        // Adc saturation value
+  Float_t    fDiffCoeff;     // Diffusion Coefficient
+  Float_t    fQref;          // Coulomb repulsion
+
+  Int_t      fZeroSuppFlag;  // Zero-suppression flag
+  Int_t      fMinVal;        // Min value used in 2D zero-suppression algo
+
+  Bool_t     fWrite;         // Write option for the compression algorithms
+  Option_t   *fOption;       // Zero-suppresion option (1D, 2D or none)
+  Option_t   *fParam1;       // Read baselines from file option
+  Option_t   *fParam2;       // Read compression algo thresholds from file
+
+  TString         fDataType;         // input keys : run, module #
+  TString         fFileName1;        // input keys : run, module #
+  TString         fFileName2;        // baseline & noise val or output coded                                        // signal or monitored bgr.
+  TString         fFileName3;        // param values or output coded signal
+
+  ClassDef(AliITSresponseSDD,1) // SDD response
+
+    };
+#endif
+
+
+
+
+
+
+
diff --git a/ITS/AliITSresponseSPD.cxx b/ITS/AliITSresponseSPD.cxx
new file mode 100644
index 0000000..0db68b7
--- /dev/null
+++ b/ITS/AliITSresponseSPD.cxx
@@ -0,0 +1,32 @@
+/**************************************************************************
+ *                                                                        *
+ * 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.                  *
+ **************************************************************************/
+
+#include
+
+#include "AliITSresponseSPD.h"
+
+//___________________________________________
+ClassImp(AliITSresponseSPD)
+
+AliITSresponseSPD::AliITSresponseSPD()
+{
+  // constructor
+   SetDiffCoeff();
+   SetNoiseParam();
+   SetDataType();
+   SetMinVal();
+
+}
+
diff --git a/ITS/AliITSresponseSPD.h b/ITS/AliITSresponseSPD.h
new file mode 100644
index 0000000..221a706
--- /dev/null
+++ b/ITS/AliITSresponseSPD.h
@@ -0,0 +1,66 @@
+#ifndef ALIITSRESPONSESPD_H
+#define ALIITSRESPONSESPD_H
+
+#include "AliITSsegmentation.h"
+#include "AliITSresponse.h"
+//----------------------------------------------
+//
+// ITS response class for SPD
+//
+class AliITSresponseSPD :
+  public AliITSresponse {
+public:
+
+  AliITSresponseSPD();
+  virtual ~AliITSresponseSPD() {
+    // destructror
+  }
+  //
+  // Configuration methods
+  //
+  virtual void    SetDiffCoeff(Float_t p1=0.00433) {
+    // Diffusion coefficient
+    fDiffCoeff=p1;
+  }
+  virtual Float_t DiffCoeff() {
+    // Get diffusion coefficient
+    return fDiffCoeff;
+  }
+  virtual  void   SetNoiseParam(Float_t n=0., Float_t b=0.) {
+    // set noise
+    fNoise=n; fBaseline=b;
+  }
+  virtual  void   GetNoiseParam(Float_t &n, Float_t &b) {
+    // get noise
+    n=fNoise; b=fBaseline;
+  }
+  virtual void     SetMinVal(Int_t p1=0) {
+    // Zero-suppression option threshold
+    fThreshold=p1;
+  }
+  virtual Int_t MinVal() {
+    // Get zero-suppression threshold
+    return fThreshold;
+  }
+  virtual void    SetDataType(char *data="simulated") {
+    // Type of data - real or simulated
+    fDataType=data;
+  }
+  virtual const char  *DataType() {
+    // Get data typer
+    return fDataType.Data();
+  }
+
+  ClassDef(AliITSresponseSPD,1) // SPD response
+
+    protected:
+
+  Float_t fDiffCoeff;       // Diffusion Coefficient
+  Float_t fNoise;           // Noise value
+  Float_t fBaseline;        // Baseline value
+  Int_t fThreshold;         // Zero-Suppression threshold
+
+  TString fDataType;        // Type of data - real or simulated
+};
+
+#endif
diff --git a/ITS/AliITSresponseSSD.cxx b/ITS/AliITSresponseSSD.cxx
new file mode 100644
index 0000000..17828d4
--- /dev/null
+++ b/ITS/AliITSresponseSSD.cxx
@@ -0,0 +1,141 @@
+/**************************************************************************
+ *                                                                         *
+ * 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.                  *
+ **************************************************************************/
+
+#include
+
+#include "AliITSresponseSSD.h"
+#include "AliITSgeom.h"
+
+ClassImp(AliITSresponseSSD)
+//----------------------------------------------------------
+AliITSresponseSSD::AliITSresponseSSD()
+{
+  // constructor
+  SetDiffCoeff();
+  SetNoiseParam();
+  SetDataType();
+  SetParamOptions();
+  SetNDetParam();
+  fDetPar = new Float_t[fNPar];
+  if (fNPar==6) {
+    fDetPar[0]=10.;
+    fDetPar[1]=5.;
+    fDetPar[2]=0.02;
+    fDetPar[3]=0.02;
+    fDetPar[4]=0.02;
+    fDetPar[5]=0.03;
+  }
+
+
+}
+
+//----------------------------------------------------------
+AliITSresponseSSD::~AliITSresponseSSD()
+{
+  // destructor
+  delete [] fDetPar;
+  delete fDetPar;
+
+}
+
+//__________________________________________________________________________
+AliITSresponseSSD::AliITSresponseSSD(const AliITSresponseSSD &source){
+  //     Copy Constructor
+  if(&source == this) return;
+  this->fNPar = source.fNPar;
+  this->fDetPar = source.fDetPar;
+  this->fNoiseP = source.fNoiseP;
+  this->fNoiseN = source.fNoiseN;
+  this->fSigmaP = source.fSigmaP;
+  this->fSigmaN = source.fSigmaN;
+  this->fDiffCoeff = source.fDiffCoeff;
+  this->fOption1 = source.fOption1;
+  this->fOption2 = source.fOption2;
+  this->fDataType = source.fDataType;
+  return;
+}
+
+//_________________________________________________________________________
+AliITSresponseSSD&
+  AliITSresponseSSD::operator=(const AliITSresponseSSD &source) {
+  //    Assignment operator
+  if(&source == this) return *this;
+  this->fNPar = source.fNPar;
+  this->fDetPar = source.fDetPar;
+  this->fNoiseP = source.fNoiseP;
+  this->fNoiseN = source.fNoiseN;
+  this->fSigmaP = source.fSigmaP;
+  this->fSigmaN = source.fSigmaN;
+  this->fDiffCoeff = source.fDiffCoeff;
+  this->fOption1 = source.fOption1;
+  this->fOption2 = source.fOption2;
+  this->fDataType = source.fDataType;
+  return *this;
+}
+
+//----------------------------------------------------------
+void AliITSresponseSSD::SetDetParam(Float_t  *par)
+{
+  // set det param
+  Int_t i;
+  for(i=0; i> fNPar;
+      //R__b.ReadArray(fDetPar); // Not to be printed out?
+      R__b >> fNoiseP;
+      R__b >> fNoiseN;
+      R__b >> fSigmaP;
+      R__b >> fSigmaN;
+      R__b >> fDiffCoeff;
+      //R__b.ReadArray(fOption1); // Not to be printed out?
+      //R__b.ReadArray(fOption2); // Not to be printed out?
+      fDataType.Streamer(R__b);
+   } else {
+      R__b.WriteVersion(AliITSresponseSSD::IsA());
+      AliITSresponse::Streamer(R__b);
+      R__b << fNPar;
+      //R__b.WriteArray(fDetPar, __COUNTER__); // Not to be printed out?
+      R__b << fNoiseP;
+      R__b << fNoiseN;
+      R__b << fSigmaP;
+      R__b << fSigmaN;
+      R__b << fDiffCoeff;
+      //R__b.WriteArray(fOption1, __COUNTER__); // Not to be printed out?
+      //R__b.WriteArray(fOption2, __COUNTER__); // Not to be printed out?
+      fDataType.Streamer(R__b);
+   }
+}
diff --git a/ITS/AliITSresponseSSD.h b/ITS/AliITSresponseSSD.h
new file mode 100644
index 0000000..9d3c6ff
--- /dev/null
+++ b/ITS/AliITSresponseSSD.h
@@ -0,0 +1,110 @@
+#ifndef ALIITSRESPONSESSD_H
+#define ALIITSRESPONSESSD_H
+
+#include "AliITSresponse.h"
+
+// response for SSD
+
+//-----------------------------
+class AliITSresponseSSD :
+public AliITSresponse {
+
+public:
+
+  AliITSresponseSSD();
+  virtual ~AliITSresponseSSD();
+  AliITSresponseSSD(const AliITSresponseSSD &source); // copy constructor
+  AliITSresponseSSD& operator=(const AliITSresponseSSD &source); // ass. op.
+
+  virtual void    SetDiffCoeff(Float_t p1=0.) {
+    // Diffusion coefficient
+    fDiffCoeff=p1;
+  }
+  virtual Float_t DiffCoeff() {
+    // Get diffusion coefficient
+    return fDiffCoeff;
+  }
+
+  virtual  void   SetNoiseParam(Float_t np=420., Float_t nn=625.) {
+    // set noise par
+    fNoiseP=np; fNoiseN=nn;
+  }
+  virtual void    GetNoiseParam(Float_t &np, Float_t &nn) {
+    // get noise par
+    np=fNoiseP; nn=fNoiseN;
+  }
+
+  virtual void    SetParamOptions(Option_t *opt1="", Option_t *opt2="") {
+    // parameters: "SetInvalid" to simulate the invalid strips
+    fOption1=opt1; fOption2=opt2;
+  }
+  virtual void    ParamOptions(Option_t *&opt1,Option_t *&opt2) {
+    // options
+    opt1=fOption1; opt2=fOption2;
+  }
+
+  // Number of parameters to be set
+  // 4 couplings, mean number of invalid strips, RMS of invalid strips
+  virtual  void   SetNDetParam(Int_t npar=6) {
+    // set number of param
+    fNPar=npar;
+  }
+
+  virtual  void   SetDetParam(Float_t *par);
+
+  // Parameters options
+  virtual Int_t   NDetParam() {
+    // number of param
+    return fNPar;
+  }
+  virtual void    GetDetParam(Float_t *dpar);
+
+  virtual void    SetDataType(char *data="simulated") {
+  // Type of data - real or simulated
+    fDataType=data;
+  }
+  virtual const char  *DataType() {
+    // Get data type
+    return fDataType.Data();
+  }
+
+  virtual void    SetSigmaSpread(Float_t p1=3., Float_t p2=2.) {
+    // Set sigmas of the charge spread function: Pside-Nside
+    // square of (microns)
+    fSigmaP=p1; fSigmaN=p2;
+  }
+  virtual void    SigmaSpread(Float_t &sP, Float_t &sN) {
+    // Get sigmas for the charge spread
+    sP=fSigmaP; sN=fSigmaN;
+  }
+
+protected:
+  Int_t   fNPar;            // Number of detector param
+  Float_t *fDetPar       ;  // Array of parameters
+
+  Float_t fNoiseP;          // Noise on Pside
+  Float_t fNoiseN;          // Noise on Nside
+
+  Float_t fSigmaP;          // Sigma charge spread on Pside
+  Float_t fSigmaN;          // Sigma charge spread on Nside
+  Float_t fDiffCoeff;       // Diffusion Coefficient
+
+  Option_t *fOption1;       // Simulate invalid strips option
+  Option_t *fOption2;       // Not used for the moment
+
+  TString  fDataType;       // Type of data - real or simulated
+
+  ClassDef(AliITSresponseSSD,1) //Response class for SSD
+
+    };
+
+
+
+#endif
+
+
+
+
+
+
+
diff --git a/ITS/AliITSsegmentation.h b/ITS/AliITSsegmentation.h
new file mode 100644
index 0000000..071c5c5
--- /dev/null
+++ b/ITS/AliITSsegmentation.h
@@ -0,0 +1,117 @@
+#ifndef ALIITSSEGMENTATION_H
+#define ALIITSSEGMENTATION_H
+
+
+#include
+#include
+
+class AliITSgeom;
+
+//----------------------------------------------
+//
+// ITS  segmentation virtual base class
+//
+class AliITSsegmentation :
+public TObject {
+ public:
+    // Set Detector Segmentation Parameters
+    //
+    // Detector size
+    virtual void    SetDetSize(Float_t Dx, Float_t Dz, Float_t Dy) {}
+
+    // Cell size
+    virtual void    SetCellSize(Float_t p1, Float_t p2) {}
+
+    // Maximum number of cells along the two coordinates
+    virtual void    SetNCells(Int_t p1, Int_t p2) {}
+
+    // Set angles - find a generic name fit for other detectors as well
+    // might be useful for beam test setups (3 angles ?)
+    virtual void    SetAngles(Float_t p1, Float_t p2) {}
+
+    // Transform from real to cell coordinates
+    virtual void    GetCellIxz(Float_t &x ,Float_t &z ,Int_t &ix,Int_t &iz)=0;
+    // Transform from cell to real coordinates
+    virtual void    GetCellCxz(Int_t ix, Int_t iz, Float_t &x ,Float_t &z )=0;
+    // Transform from real global to local coordinates
+    virtual void    GetLocal(Int_t module,Float_t *g ,Float_t *l)  =0;
+    // Transform from real local to global coordinates
+    virtual void    GetGlobal(Int_t module,Float_t *l ,Float_t *g) =0;
+    //
+    // Initialisation
+    virtual void Init() {}
+    //
+    // Get member data
+    //
+    // Detector type geometry
+    virtual AliITSgeom* Geometry() {return 0;}
+    // Detector length
+    virtual Float_t Dx()                               =0;
+    // Detector width
+    virtual Float_t Dz()                               =0;
+    // Detector thickness
+    virtual Float_t Dy()                               =0;
+    // Cell size in x
+    virtual Float_t Dpx(Int_t)                         =0;
+    // Cell size in z
+    virtual Float_t Dpz(Int_t)                         =0;
+
+    // Maximum number of Cells in x
+    virtual Int_t    Npx()                             =0;
+    // Maximum number of Cells in z
+    virtual Int_t    Npz()                             =0;
+
+    // Angles
+    virtual void Angles(Float_t &, Float_t&) {}
+
+    // Set cell position
+    virtual void     SetPad(Int_t, Int_t) {}
+    // Set hit position
+    virtual void     SetHit(Float_t, Float_t) {}
+
+    //
+    // Iterate over cells
+    // Initialiser
+    virtual void  FirstCell
+          (Float_t xhit, Float_t zhit, Float_t dx, Float_t dz) {}
+    // Stepper
+    virtual void  NextCell() {}
+    // Condition
+    virtual Int_t MoreCells() {return 0;}
+    //
+    // Get next neighbours
+    virtual void Neighbours
+      (Int_t iX, Int_t iZ, Int_t* Nlist, Int_t Xlist[10], Int_t Zlist[10]) {}
+    //
+    // Current cell cursor during disintegration
+    // x-coordinate
+    virtual Int_t  Ix() {return 0;}
+    // z-coordinate
+    virtual Int_t  Iz() {return 0;}
+    //
+    // Signal Generation Condition during Stepping
+    virtual Int_t SigGenCond(Float_t x, Float_t y, Float_t z) {return 0;}
+    // Initialise signal generation at coord (x,y,z)
+    virtual void  SigGenInit(Float_t x, Float_t y, Float_t z) {}
+    // Current integration limits
+    virtual void  IntegrationLimits
+    (Float_t& x1, Float_t& x2, Float_t& z1, Float_t& z2) {}
+    // Test points for auto calibration
+    virtual void GiveTestPoints(Int_t &n, Float_t *x, Float_t *z) {}
+    // Function for systematic corrections
+    // Set the correction function
+    virtual void SetCorrFunc(Int_t, TF1*) {}
+    // Get the correction Function
+    virtual TF1* CorrFunc(Int_t) {return 0;}
+
+    ClassDef(AliITSsegmentation,1) //Segmentation virtual base class
+};
+
+#endif
+
+
+
+
+
+
+
diff --git a/ITS/AliITSsegmentationSDD.cxx b/ITS/AliITSsegmentationSDD.cxx
new file mode 100644
index 0000000..4889373
--- /dev/null
+++ b/ITS/AliITSsegmentationSDD.cxx
@@ -0,0 +1,153 @@
+/**************************************************************************
+ *                                                                        *
+ * 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.                  *
+ **************************************************************************/
+
+#include
+
+#include "AliITSgeom.h"
+#include "AliITSsegmentationSDD.h"
+#include "AliITS.h"
+#include "AliRun.h"
+
+class AliITS;
+
+ClassImp(AliITSsegmentationSDD)
+//------------------------------
+AliITSsegmentationSDD::AliITSsegmentationSDD(AliITSgeom* geom, AliITSresponse *resp){
+  // constructor
+   fGeom=geom;
+   fResponse=resp;
+   fCorr=0;
+   SetDetSize();
+   SetCellSize();
+   SetNCells();
+
+}
+//_____________________________________________________________________________
+AliITSsegmentationSDD::AliITSsegmentationSDD(){
+   fGeom=0;
+   fResponse=0;
+   fCorr=0;
+   SetDetSize();
+   SetCellSize();
+   SetNCells();
+
+}
+//_____________________________________________________________________________
+AliITSsegmentationSDD& AliITSsegmentationSDD::operator=(AliITSsegmentationSDD &source){
+  // Operator =
+  if(this==&source) return *this;
+  this->fNsamples = source.fNsamples;
+  this->fNanodes  = source.fNanodes;
+  this->fPitch    = source.fPitch;
+  this->fTimeStep = source.fTimeStep;
+  this->fDx       = source.fDx;
+  this->fDz       = source.fDz;
+  this->fDy       = source.fDy;
+  this->fCorr     = new TF1(*(source.fCorr));
+  this->fGeom     = source.fGeom; // Just copy the pointer
+  this->fResponse = source.fResponse; //Just copy the pointer
+  return *this;
+}
+//___________________________________________________________________________
+AliITSsegmentationSDD::AliITSsegmentationSDD(AliITSsegmentationSDD &source){
+  // Copy constructor
+   *this = source;
+}
+//------------------------------
+void AliITSsegmentationSDD::Init(){
+  // Standard initilisation routine
+
+   AliITSgeomSDD *gsdd = (AliITSgeomSDD *) (fGeom->GetShape(3,1,1));
+
+   const Float_t kconv=10000.;
+   fDz = 2.*kconv*gsdd->GetDz();
+   fDx = kconv*gsdd->GetDx();
+   fDy = 2.*kconv*gsdd->GetDy();
+}
+
+//------------------------------
+void AliITSsegmentationSDD::
+Neighbours(Int_t iX, Int_t iZ, Int_t* Nlist, Int_t Xlist[4], Int_t Zlist[4]){
+  // returns neighbers for use in Cluster Finder routines and the like
+
+    *Nlist=4;
+    Xlist[0]=Xlist[1]=iX;
+    if(iX) Xlist[2]=iX-1;
+    else Xlist[2]=iX;
+    if (iX < fNanodes) Xlist[3]=iX+1;
+    else Xlist[3]=iX;
+    if(iZ) Zlist[0]=iZ-1;
+    else Zlist[0]=iZ;
+    if (iZ < fNsamples) Zlist[1]=iZ+1;
+    else Zlist[1]=iZ;
+    Zlist[2]=Zlist[3]=iZ;
+
+}
+//------------------------------
+void AliITSsegmentationSDD::GetCellIxz(Float_t &x,Float_t &z,Int_t &timebin,Int_t &anode){
+//  Returns cell coordinates (time sample,anode) for given real local coordinates (x,z)
+
+    // expects x, z in cm
+
+    const Float_t kconv=10000;  // cm->um
+
+    Float_t speed=fResponse->DriftSpeed();
+    Int_t na = fNanodes/2;
+    Float_t driftpath=fDx-TMath::Abs(kconv*x);
+    timebin=(Int_t)(driftpath/speed/fTimeStep);
+    anode=(Int_t)(kconv*z/fPitch + na/2);
+    if (x > 0) anode += na;
+
+    timebin+=1;
+    anode+=1;
+
+}
+
+//------------------------------
+void AliITSsegmentationSDD::GetCellCxz(Int_t timebin,Int_t anode,Float_t &x ,Float_t &z){
+    // Transform from cell to real local coordinates
+
+    // returns x, z in cm
+
+    const Float_t kconv=10000;  // um->cm
+
+    Float_t speed=fResponse->DriftSpeed();
+    Int_t na = fNanodes/2;
+    Float_t driftpath=(timebin+1)*fTimeStep*speed;
+    if (anode >= na) x=(fDx-driftpath)/kconv;
+    else x = -(fDx-driftpath)/kconv;
+    if (anode >= na) anode-=na;
+    z=((anode+1)*fPitch-fDz/2)/kconv;
+
+}
+
+//------------------------------
+void AliITSsegmentationSDD::GetLocal(Int_t module,Float_t *g ,Float_t *l){
+  // returns local coordinates from global
+    if(!fGeom) {
+        fGeom = ((AliITS*)gAlice->GetModule("ITS"))->GetITSgeom();
+    }
+    fGeom->GtoL(module,g,l);
+}
+//------------------------------
+void AliITSsegmentationSDD::GetGlobal(Int_t module,Float_t *l ,Float_t *g){
+  // return global coordinates from local
+    if(!fGeom) {
+        fGeom = ((AliITS*)gAlice->GetModule("ITS"))->GetITSgeom();
+    }
+
+    fGeom->LtoG(module,l,g);
+
+}
diff --git a/ITS/AliITSsegmentationSDD.h b/ITS/AliITSsegmentationSDD.h
new file mode 100644
index 0000000..8ec4408
--- /dev/null
+++ b/ITS/AliITSsegmentationSDD.h
@@ -0,0 +1,127 @@
+#ifndef ALIITSSEGMENTATIONSDD_H
+#define ALIITSSEGMENTATIONSDD_H
+
+
+#include "AliITSsegmentation.h"
+#include "AliITSresponse.h"
+
+// segmentation for SDD
+
+class AliITSsegmentationSDD :
+public AliITSsegmentation {
+ public:
+
+
+    AliITSsegmentationSDD();
+    AliITSsegmentationSDD(AliITSgeom *gm, AliITSresponse *resp);
+    AliITSsegmentationSDD(AliITSsegmentationSDD &source);
+    virtual ~AliITSsegmentationSDD(){}
+    AliITSsegmentationSDD& operator=(AliITSsegmentationSDD &source);
+
+    // Set Detector Segmentation Parameters
+    //
+    // Detector size : x,z,y
+  virtual  void   SetDetSize
+          (Float_t p1=35000., Float_t p2=76800., Float_t p3= 300.)
+          {fDx=p1; fDz=p2; fDy=p3;}
+
+    // Cell size dz*dx
+    virtual void    SetCellSize(Float_t pitch=200., Float_t clock=40.)
+                         {fPitch=pitch;fTimeStep=1000./clock;}
+
+    // Maximum number of cells along the two coordinates z,x (anodes,samples)
+    virtual void    SetNCells(Int_t p1=384, Int_t p2=256)
+                         {fNanodes=2*p1;fNsamples=p2;}
+
+    // Transform from real local to cell coordinates
+    virtual void    GetCellIxz(Float_t &x ,Float_t &z ,Int_t   &ix,Int_t   &iz);
+    // Transform from cell to real local coordinates
+    virtual void    GetCellCxz(Int_t   ix,Int_t   iz,Float_t &x ,Float_t &z );
+    // Transform from real global to local coordinates
+    virtual void    GetLocal(Int_t module,Float_t *g ,Float_t *l);
+    // Transform from real local to global coordinates
+    virtual void    GetGlobal(Int_t module,Float_t *l ,Float_t *g);
+    //
+    // Initialisation
+    virtual void Init();
+    //
+    // Get member data
+    //
+    // Detector type geometry
+    virtual AliITSgeom* Geometry() {return fGeom;}
+    // Detector length
+    virtual Float_t Dx() {return fDx;}
+    // Detector width
+    virtual Float_t Dz()  {return fDz;}
+    // Detector thickness
+    virtual Float_t Dy() {return fDy;}
+    // Cell size in x
+    virtual Float_t Dpx(Int_t dummy) {return fTimeStep;}
+    // Cell size in z
+    virtual Float_t Dpz(Int_t dummy) {return fPitch;}
+
+    // Maximum number of samples in x
+    virtual Int_t    Npx() {return fNsamples;}
+    // Maximum number of anodes in z
+    virtual Int_t    Npz() {return fNanodes;}
+
+    //
+    // Get next neighbours
+    virtual void Neighbours
+      (Int_t iX, Int_t iZ, Int_t* Nlist, Int_t Xlist[10], Int_t Zlist[10]);
+
+    // Set cell position
+    virtual void     SetPad(Int_t, Int_t) {}
+    // Set hit position
+    virtual void     SetHit(Float_t, Float_t) {}
+
+    //
+    // Iterate over cells
+    // Initialiser
+    virtual void  FirstCell
+          (Float_t xhit, Float_t zhit, Float_t dx, Float_t dz) {}
+    // Stepper
+    virtual void  NextCell() {}
+    // Condition
+    virtual Int_t MoreCells() {return 0;}
+    //
+    // Current cell cursor during disintegration
+    // x-coordinate
+    virtual Int_t  Ix() {return 0;}
+    // z-coordinate
+    virtual Int_t  Iz() {return 0;}
+    //
+    // Signal Generation Condition during Stepping
+    virtual Int_t SigGenCond(Float_t x, Float_t y, Float_t z) {return 0;}
+    // Initialise signal generation at coord (x,y,z)
+    virtual void  SigGenInit(Float_t x, Float_t y, Float_t z) {}
+    // Current integration limits
+    virtual void  IntegrationLimits
+    (Float_t& x1, Float_t& x2, Float_t& z1, Float_t& z2) {}
+    // Test points for auto calibration
+    virtual void GiveTestPoints(Int_t &n, Float_t *x, Float_t *z) {}
+    // Function for systematic corrections
+    // Set the correction function
+    virtual void SetCorrFunc(Int_t, TF1*) {}
+    // Get the correction Function
+    virtual TF1* CorrFunc(Int_t) {return 0;}
+
+  protected:
+
+    Int_t      fNsamples;      // Number of time samples in x
+    Int_t      fNanodes;       // Summed # of anodes in the two det halves (z)
+    Float_t    fPitch;         // Anode pitch - microns
+    Float_t    fTimeStep;      // Sampling time - ns
+    Float_t    fDx   ;         // Full width of the detector (x axis) - microns
+    Float_t    fDz    ;        // Length of half-detector (z axis) - microns
+    Float_t    fDy;            // Full thickness of the detector (y axis)
+
+    AliITSgeom *fGeom;         // pointer to the geometry class
+    AliITSresponse *fResponse; // pointer to the response class
+
+    TF1*       fCorr;          // correction function
+
+    ClassDef(AliITSsegmentationSDD,1) // SDD segmentation
+};
+
+#endif
diff --git a/ITS/AliITSsegmentationSPD.cxx b/ITS/AliITSsegmentationSPD.cxx
new file mode 100644
index 0000000..69b0d43
--- /dev/null
+++ b/ITS/AliITSsegmentationSPD.cxx
@@ -0,0 +1,320 @@
+/**************************************************************************
+ *                                                                        *
+ * 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.                  *
+ **************************************************************************/
+
+#include
+
+#include "AliITSsegmentationSPD.h"
+
+ClassImp(AliITSsegmentationSPD)
+
+
+Float_t ColFromZ300(Float_t z) {
+// Get column number for each z-coordinate taking into account the
+// extra pixels in z direction assuming 300 micron sized pixels.
+     Float_t col = 0.0;
+     Float_t pitchz = 300.0;
+     col = Float_t (z/pitchz);
+     return col;
+}
+//_____________________________________________________________________________
+Float_t ZFromCol300(Int_t col) {
+// same comments as above
+// Get z-coordinate for each colunm number
+  Float_t pitchz = 300.0;
+  Float_t z = 0.0;
+  z = (col+0.5)*pitchz;
+  return z;
+}
+//_____________________________________________________________________________
+Float_t ZpitchFromCol300(Int_t col) {
+  // returns Z pixel pitch for 300 micron pixels.
+  return 300.0;
+}
+//_____________________________________________________________________________
+Float_t ColFromZ(Float_t z) {
+// hard-wired - keep it like this till we can parametrise
+// and get rid of AliITSgeomSPD425
+// Get column number for each z-coordinate taking into account the
+// extra pixels in z direction
+
+  Float_t col = 0;
+  Float_t pitchz = 425;
+  if( z < 13175) {
+    col = Float_t(z/pitchz);
+  } else if( z < 14425) {
+    pitchz = 625;
+    col = 31 + (z - 13175)/pitchz;
+  } else if( z < 27175) {
+    col = 33 + (z - 14425)/pitchz;
+  } else if( z < 28425) {
+    pitchz = 625;
+    col = 63 + (z - 27175)/pitchz;
+  } else if( z < 41175) {
+    col = 65 + (z - 28425)/pitchz;
+  } else if( z < 42425) {
+    pitchz = 625;
+    col = 95 + (z - 41175)/pitchz;
+  } else if( z < 55175) {
+    col = 97 + (z - 42425)/pitchz;
+  } else if( z < 56425) {
+    pitchz = 625;
+    col = 127 + (z - 55175)/pitchz;
+  } else if( z < 69175) {
+    col = 129 + (z - 56425)/pitchz;
+  } else if( z < 70425) {
+    pitchz = 625;
+    col = 159 + (z - 69175)/pitchz;
+  } else if( z < 83600) {
+    col = 161 + (z - 70425)/pitchz;
+  }
+  return col;
+}
+
+//_____________________________________________________________________________
+Float_t ZFromCol(Int_t col) {
+// same comments as above
+// Get z-coordinate for each colunm number
+
+  Float_t pitchz = 425;
+  Float_t z = 0;
+  if( col >=0 && col <= 30 ) {
+    z = (col + 0.5)*pitchz;
+  } else if( col >= 31 && col <= 32) {
+    pitchz = 625;
+    z = 13175 + (col -31 + 0.5)*pitchz;
+  } else if( col >= 33 && col <= 62) {
+    z = 14425 + (col -33 + 0.5)*pitchz;
+  } else if( col >= 63 && col <= 64) {
+    pitchz = 625;
+    z = 27175 + (col -63 + 0.5)*pitchz;
+  } else if( col >= 65 && col <= 94) {
+    z = 28425 + (col -65 + 0.5)*pitchz;
+  } else if( col >= 95 && col <= 96) {
+    pitchz = 625;
+    z = 41175 + (col -95 + 0.5)*pitchz;
+  } else if( col >= 97 && col <= 126) {
+    z = 42425 + (col -97 + 0.5)*pitchz;
+  } else if( col >= 127 && col <= 128) {
+    pitchz = 625;
+    z = 55175 + (col -127 + 0.5)*pitchz;
+  } else if( col >= 129 && col <= 158) {
+    z = 56425 + (col -129 + 0.5)*pitchz;
+  } else if( col >= 159 && col <= 160) {
+    pitchz = 625;
+    z = 69175 + (col -159 + 0.5)*pitchz;
+  } else if( col >= 161 && col <= 191) {
+    z = 70425 + (col -161 + 0.5)*pitchz;
+  }
+
+  return z;
+}
+
+Float_t ZpitchFromCol(Int_t col) {
+// Get pitch size in z direction for each colunm
+
+  Float_t pitchz = 425;
+  if( col >=32 && col <= 33 ) {
+    pitchz = 625;
+  } else if( col >= 64 && col <= 65) {
+    pitchz = 625;
+  } else if( col >= 96 && col <= 97) {
+    pitchz = 625;
+  } else if( col >= 128 && col <= 129) {
+    pitchz = 625;
+  } else if( col >= 160 && col <= 161) {
+    pitchz = 625;
+  }
+  return pitchz;
+}
+
+AliITSsegmentationSPD::AliITSsegmentationSPD(){
+  // Default constructor
+   fNpx = 0;
+   fNpz = 0;
+   fCorr=0;
+   fGeom = 0;
+
+}
+//____________________________________________________________________________
+AliITSsegmentationSPD::AliITSsegmentationSPD(AliITSgeom *gm){
+  // Constructor
+   fCorr=0;
+   fNpx = 0;
+   fNpz = 0;
+   Init();
+   fGeom = gm;
+
+}
+//____________________________________________________________________________
+AliITSsegmentationSPD& AliITSsegmentationSPD::operator=(AliITSsegmentationSPD &source){
+   // = operator
+   Int_t i;
+   if(this==&source) return *this;
+   this->fNpx  = source.fNpx;
+   this->fNpz  = source.fNpz;
+   this->fDx   = source.fDx;
+   this->fDy   = source.fDy;
+   for(i=0;i<256;i++) this->fCellSizeX[i] = source.fCellSizeX[i];
+   for(i=0;i<280;i++) this->fCellSizeZ[i] = source.fCellSizeZ[i];
+   this->fCorr = new TF1(*(source.fCorr));// make a proper copy of the function
+   this->fGeom = source.fGeom; // copy only the pointers.
+   return *this;
+}
+//____________________________________________________________________________
+AliITSsegmentationSPD::AliITSsegmentationSPD(AliITSsegmentationSPD &source){
+  // copy constructor
+   *this = source;
+}
+//------------------------------
+void AliITSsegmentationSPD::Init300(){
+// Initialize infromation for 6 read out chip 300X50 micron pixel SPD
+// detectors. This chip is 150 microns thick by 1.28 cm in x by 8.37 cm
+// long. It has 256  50 micron pixels in x and 279 300 micron size
+// pixels in z.
+
+    Int_t i;
+    //const Float_t kconv=10000.;
+    fNpx = 256; // The number of X pixel Cell same as in fCellSizeX array size
+    fNpz = 279; // The number of Z pixel Cell same as in fCellSizeZ array size
+    for(i=0;i  fNpz) iz= fNpz;
+    if (ix >  fNpx) ix= fNpx;
+
+    /*
+    if (iz < -fNpz) iz= -fNpz;
+    if (ix < -fNpx) ix=-fNpx;
+    */
+}
+
+//------------------------------
+void AliITSsegmentationSPD::GetCellCxz(Int_t ix,Int_t iz,Float_t &x,Float_t&z){
+    // Transform from pixel to real local coordinates
+
+    // returns x, z in microns
+
+    Float_t dpx=Dpx(0);
+
+    x = (ix>0) ? Float_t(ix*dpx)-dpx/2. : Float_t(ix*dpx)+dpx/2.;
+    z = ZFromCol(iz);
+
+
+}
+//------------------------------
+void AliITSsegmentationSPD::
+Neighbours(Int_t iX, Int_t iZ, Int_t* Nlist, Int_t Xlist[8], Int_t Zlist[8]){
+  // returns the neighbouring pixels for use in Cluster Finders and the like.
+  /*
+    *Nlist=4;Xlist[0]=Xlist[1]=iX;Xlist[2]=iX-1;Xlist[3]=iX+1;
+    Zlist[0]=iZ-1;Zlist[1]=iZ+1;Zlist[2]=Zlist[3]=iZ;
+  */
+
+
+    *Nlist=8;
+    Xlist[0]=Xlist[1]=iX;
+    Xlist[2]=iX-1;
+    Xlist[3]=iX+1;
+    Zlist[0]=iZ-1;
+    Zlist[1]=iZ+1;
+    Zlist[2]=Zlist[3]=iZ;
+
+   // Diagonal elements
+    Xlist[4]=iX+1;
+    Zlist[4]=iZ+1;
+
+    Xlist[5]=iX-1;
+    Zlist[5]=iZ-1;
+
+    Xlist[6]=iX-1;
+    Zlist[6]=iZ+1;
+
+    Xlist[7]=iX+1;
+    Zlist[7]=iZ-1;
+}
diff --git a/ITS/AliITSsegmentationSPD.h b/ITS/AliITSsegmentationSPD.h
new file mode 100644
index 0000000..6c8a618
--- /dev/null
+++ b/ITS/AliITSsegmentationSPD.h
@@ -0,0 +1,81 @@
+#ifndef ALIITSSEGMENTATIONSPD_H
+#define ALIITSSEGMENTATIONSPD_H
+
+#include "AliITSsegmentation.h"
+
+// segmentation and response for SPD
+
+class AliITSsegmentationSPD :
+public AliITSsegmentation {
+ public:
+
+    AliITSsegmentationSPD();
+    AliITSsegmentationSPD(AliITSgeom *gm);
+    AliITSsegmentationSPD(AliITSsegmentationSPD &source);
+    virtual ~AliITSsegmentationSPD(){}
+    AliITSsegmentationSPD& operator=(AliITSsegmentationSPD &source);
+
+    // Set Detector Segmentation Parameters
+    //
+    // Detector size along x,z,y coordinates
+    virtual void    SetDetSize(Float_t Dx, Float_t Dz, Float_t Dy);
+
+    // Maximum number of pixels along the two coordinates
+    virtual void    SetNCells(Int_t p1, Int_t p2);
+
+    // Transform from real to pixel coordinates
+    virtual void    GetCellIxz
+         (Float_t &x,Float_t &z,Int_t &ix,Int_t &iz);
+    // Transform from pixel to real coordinates
+    virtual void    GetCellCxz
+         (Int_t ix,Int_t iz,Float_t &x,Float_t &z);
+    // Transform from real global to local coordinates
+    virtual void    GetLocal(Int_t module,Float_t *g ,Float_t *l) {}
+    // Transform from real local to global coordinates
+    virtual void    GetGlobal(Int_t module,Float_t *l ,Float_t *g) {}
+    //
+    // Initialisation
+    virtual void Init();
+    virtual void Init300();
+    //
+    // Get member data
+    //
+    // Detector Type geometry
+    virtual AliITSgeom* Geometry() {return fGeom;}
+    // Detector length
+    virtual Float_t Dx() {return fDx;}
+    // Detector width
+    virtual Float_t Dz() {return fDz;}
+    // Detector thickness
+    virtual Float_t Dy() {return fDy;}
+    // Pixel size in x
+    virtual Float_t Dpx(Int_t ix);
+    // Pixel size in z
+    virtual Float_t Dpz(Int_t iz);
+
+    // Maximum number of Pixels in x
+    virtual Int_t    Npx() {return fNpx;}
+    // Maximum number of Pixels in z
+    virtual Int_t    Npz(){return fNpz;}
+    //
+    // Get next neighbours
+    virtual void Neighbours
+    (Int_t iX,Int_t iZ,Int_t* Nlist,Int_t Xlist[10],Int_t Zlist[10]);
+
+  protected:
+
+    Int_t   fNpx;           // Number of pixels in x
+    Int_t   fNpz;           // Number of pixels in z
+    Float_t fDx;            // Full width of the detector (x axis)- microns
+    Float_t fDz;            // Full length of the detector (z axis)- microns
+    Float_t fDy;            // Full thickness of the detector (y axis) -um
+    Float_t fCellSizeX[256];// Size for each pixel in x -microns
+    Float_t fCellSizeZ[280];// Size for each pixel in z -microns
+    TF1*    fCorr;          // correction function
+    AliITSgeom *fGeom;      // local pointer to AliITSgeom.
+
+  ClassDef(AliITSsegmentationSPD,1) //Segmentation class for SPD
+
+};
+
+#endif
diff --git a/ITS/AliITSsegmentationSSD.cxx b/ITS/AliITSsegmentationSSD.cxx
new file mode 100644
index 0000000..63080eb
--- /dev/null
+++ b/ITS/AliITSsegmentationSSD.cxx
@@ -0,0 +1,132 @@
+/**************************************************************************
+ *                                                                        *
+ * 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.                  *
+ **************************************************************************/
+
+#include
+
+#include "AliITSsegmentationSSD.h"
+#include "AliITSgeom.h"
+
+
+ClassImp(AliITSsegmentationSSD)
+AliITSsegmentationSSD::AliITSsegmentationSSD(){
+  // default constructor
+   fGeom=0;
+   fCorr=0;
+   SetDetSize();
+   SetCellSize();
+   SetNCells();
+   SetAngles();
+}
+//------------------------------
+AliITSsegmentationSSD::AliITSsegmentationSSD(AliITSgeom *geom){
+  // constuctor
+   fGeom=geom;
+   fCorr=0;
+   SetDetSize();
+   SetCellSize();
+   SetNCells();
+   SetAngles();
+   //Init();
+}
+//____________________________________________________________________________
+AliITSsegmentationSSD& AliITSsegmentationSSD::operator=(AliITSsegmentationSSD &source){
+// Operator =
+     if(this==&source) return *this;
+     this->fNstrips = source.fNstrips;
+     this->fStereoP = source.fStereoP;
+     this->fStereoN = source.fStereoN;
+     this->fPitch   = source.fPitch;
+     this->fDz      = source.fDz;
+     this->fDx      = source.fDx;
+     this->fDy      = source.fDy;
+     this->fGeom    = source.fGeom; // copy only the pointer
+     this->fCorr    = new TF1(*(source.fCorr)); // make a proper copy
+     return *this;
+
+}
+//____________________________________________________________________________
+AliITSsegmentationSSD::AliITSsegmentationSSD(AliITSsegmentationSSD &source){
+  // copy constructor
+  *this = source;
+}
+//------------------------------
+void AliITSsegmentationSSD::Init(){
+  // standard initalizer
+
+    AliITSgeomSSD *gssd = (AliITSgeomSSD *) (fGeom->GetShape(5,1,1));
+    const Float_t kconv=10000.;
+    fDx = 2.*kconv*gssd->GetDx();
+    fDz = 2.*kconv*gssd->GetDz();
+    fDy = 2.*kconv*gssd->GetDy();
+    SetCellSize();
+    SetNCells();
+    SetAngles();
+
+}
+//-------------------------------------------------------
+void AliITSsegmentationSSD::GetCellIxz(Float_t &x,Float_t &z,Int_t &iP,Int_t &iN)
+{
+  // returns P and N sided strip numbers for a given location.
+
+    // expects x, z in microns
+
+    Float_t tanP=TMath::Tan(fStereoP);
+    Float_t tanN=TMath::Tan(fStereoN);
+
+    Float_t x1=x,z1=z;
+    x1 += fDx/2;
+    z1 += fDz/2;
+
+    Float_t  ldX = x1 - z1*tanP;          // distance from left-down edge
+    iP = (Int_t)(ldX/fPitch);
+    iP = (iP<0)? -1: iP;
+    iP = (iP>fNstrips)? -1: iP;
+
+
+    ldX = x1 - tanN*(fDz - z1);
+    iN = (Int_t)(ldX/fPitch);
+    iN = (iN<0)? -1: iN;
+    iN = (iN>fNstrips)? -1: iN;
+
+}
+//-------------------------------------------------------
+void AliITSsegmentationSSD::GetCellCxz(Int_t iP,Int_t iN,Float_t &x,Float_t &z)
+{
+    // actually this is the GetCrossing(Float_t &,Float_t &)
+
+    // returns x, z  in microns !
+
+    Float_t flag=2*fDx;
+
+    Float_t tanP=TMath::Tan(fStereoP);
+    Float_t tanN=TMath::Tan(fStereoN);
+
+    Float_t dx = 0.1;
+    x = iP*fPitch;
+    z = iN*fPitch;
+
+    if(tanP + tanN  == 0) {x=z=flag; return ;}
+
+    z = (z - x + tanN * fDz) / (tanP + tanN);
+    x = x + tanP * z;
+
+    x -= fDx/2;
+    z -= fDz/2;
+
+    if ( ( z < -(fDz/2+dx) ) || ( z > (fDz/2+dx) ) ) {x=z=flag; return ;}
+    if ( ( x < -(fDx/2+dx) ) || ( x > (fDx/2+dx) ) ) {x=z=flag; return ;}
+
+    return;
+}
diff --git a/ITS/AliITSsegmentationSSD.h b/ITS/AliITSsegmentationSSD.h
new file mode 100644
index 0000000..a85224d
--- /dev/null
+++ b/ITS/AliITSsegmentationSSD.h
@@ -0,0 +1,88 @@
+#ifndef ALIITSSEGMENTATIONSSD_H
+#define ALIITSSEGMENTATIONSSD_H
+
+#include "AliITSsegmentation.h"
+
+// segmentation for SSD
+
+class AliITSsegmentationSSD :
+public AliITSsegmentation {
+ public:
+
+    AliITSsegmentationSSD();
+    AliITSsegmentationSSD(AliITSgeom *gm);
+    AliITSsegmentationSSD(AliITSsegmentationSSD &source);
+    virtual ~AliITSsegmentationSSD(){}
+    AliITSsegmentationSSD& operator=(AliITSsegmentationSSD &source);
+
+
+    // Detector size: x,z,y
+    virtual  void   SetDetSize
+          (Float_t p1=72960., Float_t p2=40000., Float_t p3= 300.)
+                        {fDx=p1; fDz=p2; fDy=p3;}
+
+    // Strip size
+    virtual void    SetCellSize(Float_t pitch=95., Float_t dummy=1.)
+                         {fPitch=pitch;}
+
+    // Maximum number of strips along the two coordinates
+    virtual void    SetNCells(Int_t p1=768, Int_t dummy=1)
+                         {fNstrips=p1;}
+
+
+    // Set stereo angles Pside-Nside
+    virtual void    SetAngles(Float_t pa=0.0175, Float_t na=0.0175)
+                         {fStereoP=pa; fStereoN=na;}
+
+    // Transform from real coordinates to strips
+    virtual void    GetCellIxz
+    (Float_t &x ,Float_t &z ,Int_t   &iP,Int_t  &iN);
+    // Transform from strips to real coordinates
+    virtual void    GetCellCxz
+    (Int_t iP, Int_t iN, Float_t &x , Float_t &z);
+
+    // Transform from real global to local coordinates
+    virtual void    GetLocal(Int_t module,Float_t *g ,Float_t *l) {}
+    // Transform from real local to global coordinates
+    virtual void    GetGlobal(Int_t module,Float_t *l ,Float_t *g) {}
+
+    virtual void Init();
+
+    // Detector type geometry
+    virtual AliITSgeom* Geometry() {return 0;}
+    // Detector length
+    virtual Float_t Dx() {return fDx;}
+    // Detector width
+    virtual Float_t Dz() {return fDz;}
+    // Detector thickness
+    virtual Float_t Dy() {return fDy;}
+    // Strip size in x
+    virtual Float_t Dpx(Int_t) {return fPitch;}
+    // Strip size in z
+    virtual Float_t Dpz(Int_t) {return fDz;}
+    // Maximum number of Strips in x
+    virtual Int_t    Npx() {return fNstrips;}
+    // Maximum number of Strips in z
+    virtual Int_t    Npz(){return 1;}
+
+    // Angles : Pside stereo angle-Nside stereo angle
+    virtual void Angles(Float_t &aP,Float_t &aN)
+                     {aP=fStereoP;aN=fStereoN;}
+
+  protected:
+
+  Int_t      fNstrips;       // Number of strips in x
+  Float_t    fStereoP;       // Stereo angle for Pside
+  Float_t    fStereoN;       // Stereo angle for Nside
+  Float_t    fPitch;         // Pitch of the strips
+  Float_t    fDz;            // Full width of the detector (z axis)- microns
+  Float_t    fDx;            // Full length of the detector (x axis)- microns
+  Float_t    fDy;            // Full thickness of the detector (y axis) -um
+
+  AliITSgeom *fGeom;         // pointer to the geometry class
+  TF1*       fCorr;          // correction function
+
+  ClassDef(AliITSsegmentationSSD,1) //Segmentation class for SSD
+};
+
+#endif
diff --git a/ITS/AliITSsimulation.cxx b/ITS/AliITSsimulation.cxx
new file mode 100644
index 0000000..04c4024
--- /dev/null
+++ b/ITS/AliITSsimulation.cxx
@@ -0,0 +1,44 @@
+/**************************************************************************
+ *                                                                        *
+ * 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.                  *
+ **************************************************************************/
+
+#include "AliITSsimulation.h"
+
+ClassImp(AliITSsimulation)
+
+AliITSsimulation::AliITSsimulation()
+{
+  // constructor
+    fSegmentation=0;
+    fResponse=0;
+}
+
+//__________________________________________________________________________
+AliITSsimulation::AliITSsimulation(const AliITSsimulation &source){
+  //     Copy Constructor
+  if(&source == this) return;
+  this->fResponse = source.fResponse;
+  this->fSegmentation = source.fSegmentation;
+  return;
+}
+
+//_________________________________________________________________________
+AliITSsimulation&
+  AliITSsimulation::operator=(const AliITSsimulation &source) {
+  //    Assignment operator
+  if(&source == this) return *this;
+  this->fResponse = source.fResponse;
+  this->fSegmentation = source.fSegmentation;
+  return *this;
+}
diff --git a/ITS/AliITSsimulation.h b/ITS/AliITSsimulation.h
new file mode 100644
index 0000000..d773515
--- /dev/null
+++ b/ITS/AliITSsimulation.h
@@ -0,0 +1,41 @@
+#ifndef ALIITSSIMULATION_H
+#define ALIITSSIMULATION_H
+
+#include
+
+class AliITSresponse;
+class AliITSsegmentation;
+class AliITSmodule;
+
+//___________________________________________________
+
+class AliITSsimulation : public TObject {
+
+public:
+
+  AliITSsimulation();
+  virtual ~AliITSsimulation() {
+    // destructor
+  }
+  AliITSsimulation(const AliITSsimulation &source); // copy constructor
+  AliITSsimulation& operator=(const AliITSsimulation &source); // ass.
+
+  virtual void DigitiseModule(AliITSmodule *mod,Int_t module,Int_t event) {
+    // digitize module
+  }
+
+  virtual void CreateFastRecPoints(AliITSmodule *mod) {
+    // create fast rec points
+  }
+
+protected:
+
+  AliITSresponse      *fResponse;       // response
+  AliITSsegmentation  *fSegmentation;   // segmentation
+
+  ClassDef(AliITSsimulation,1)  // Simulation base class
+
+};
+
+
+#endif
diff --git a/ITS/AliITSsimulationFastPoints.cxx b/ITS/AliITSsimulationFastPoints.cxx
new file mode 100644
index 0000000..9a51c3e
--- /dev/null
+++ b/ITS/AliITSsimulationFastPoints.cxx
@@ -0,0 +1,184 @@
+/**************************************************************************
+ *                                                                          *
+ * 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.1.2.1  2000/06/11 20:16:05  barbera
+New: Fast simulation class for the ITS, class as part of new ITS code
+structure.
+
+*/
+
+#include
+#include "AliITS.h"
+#include "AliITSsimulationFastPoints.h"
+#include "AliITSstatistics.h"
+
+ClassImp(AliITSsimulationFastPoints)
+
+AliITSsimulationFastPoints::AliITSsimulationFastPoints()
+{
+  //constructor
+  fSx = new AliITSstatistics(2);
+  fSz = new AliITSstatistics(2);
+}
+
+//----------------------------------------------------------
+AliITSsimulationFastPoints::~AliITSsimulationFastPoints()
+{
+  //destructor
+  delete fSx;
+  delete fSz;
+
+}
+
+//-------------------------------------------------------------
+void AliITSsimulationFastPoints::CreateFastRecPoints(AliITSmodule *mod){
+  // Fast points simulator for all of the ITS.
+  Int_t   nhit,h,trk,ifirst;
+  Float_t x,y,z,t,e;// local coordinate (cm) and time of flight, and dedx.
+  Float_t x1,y1,z1;
+  AliITShit *hit;
+
+  fSx->Reset(); // Start out with things clearly zeroed
+  fSz->Reset(); // Start out with things clearly zeroed
+  e = 0.; // Start out with things clearly zeroed
+  Double_t weight=1.;
+  nhit = mod->GetNhits();
+  ifirst = 1;
+  for(h=0;hGetHit(h);
+    hit->GetPositionL(x,y,z,t);
+    if(ifirst) {x1=x;y1=y;z1=z;}
+    e += hit->GetIonization();
+    trk = hit->GetTrack();
+    ifirst = 0;
+    if(hit->StatusExiting()||  // leaving volume
+       hit->StatusDisappeared()|| // interacted/decayed...
+       hit->StatusStop() // dropped below E cuts.
+       ){ // exiting track, write out RecPoint.
+      //      if(fSz->GetRMS()>1.E-1) {
+      //	TParticle *part = hit->GetParticle();
+      //	printf("idpart %d energy %f \n",part->GetPdgCode(),part->Energy());
+      //	printf("diffx=%e diffy=%e diffz=%e\n",x-x1,y-y1,z-z1);
+      //      }
+      switch (mod->GetLayer()){
+      case 1: case 2:  // SPDs
+	break;
+      case 3: case 4:  // SDDs
+	break;
+      case 5: case 6:  // SSDs
+	break;
+      } // end switch
+      fSx->Reset();
+      fSz->Reset();
+      e = 0.;
+      ifirst = 1;
+      continue;
+    }// end if
+  } // end for h
+}
+//_______________________________________________________________________
+					 AliITSmodule *mod,Int_t trackNumber){
+  const Float_t kcmTomicron = 1.0e4;
+  //  const Float_t kdEdXtoQ = ;
+  const Float_t kRMSx = 12.0; // microns ITS TDR Table 1.3
+  const Float_t kRMSz = 70.0; // microns ITS TDR Table 1.3
+  Float_t a1,a2; // general float.
+  AliITSRecPoint rpSPD;
+  Int_t *trk = rpSPD.GetTracks();
+
+  trk[0] = trackNumber;
+  trk[1] = 0; trk[2] = 0;
+  rpSPD.SetX(kcmTomicron*fSx->GetMean());
+  rpSPD.SetZ(kcmTomicron*fSz->GetMean());
+  rpSPD.SetdEdX(0.0);
+  rpSPD.SetQ(1.0);
+  a1 = kcmTomicron*fSx->GetRMS(); a1 *= a1; a1 += kRMSx*kRMSx;
+  //  if(a1>1.E5) printf("addSPD: layer=%d track #%d dedx=%e sigmaX2= %e ",
+  //		    mod->GetLayer(),trackNumber,e,a1);
+  rpSPD.SetSigmaX2(a1);
+  a2 = kcmTomicron*fSz->GetRMS(); a2 *= a2; a2 += kRMSz*kRMSz;
+  //  if(a1>1.E5) printf(" sigmaZ2= %e\n",a2);
+  rpSPD.SetSigmaZ2(a2);
+  rpSPD.SetProbability(1.0);
+
+}
+//_______________________________________________________________________
+					 AliITSmodule *mod,Int_t trackNumber){
+
+  const Float_t kcmTomicron = 1.0e4;
+  const Float_t kdEdXtoQ = 2.778e+8; // Boris Batyuna June 10 2000.
+  const Float_t kRMSx = 38.0; // microns ITS TDR Table 1.3
+  const Float_t kRMSz = 28.0; // microns ITS TDR Table 1.3
+  Float_t a1,a2; // general float.
+  AliITSRecPoint rpSDD;
+  Int_t *trk = rpSDD.GetTracks();
+
+  trk[0] = trackNumber;
+  trk[1] = 0; trk[2] = 0;
+  rpSDD.SetX(kcmTomicron*fSx->GetMean());
+  rpSDD.SetZ(kcmTomicron*fSz->GetMean());
+  rpSDD.SetdEdX(e);
+  rpSDD.SetQ(kdEdXtoQ*e);
+  a1 = kcmTomicron*fSx->GetRMS(); a1 *= a1; a1 += kRMSx*kRMSx;
+  //  if(a1>1.E5) printf("addSDD: layer=%d track #%d dedx=%e sigmaX2= %e ",
+  //		    mod->GetLayer(),trackNumber,e,a1);
+  rpSDD.SetSigmaX2(a1);
+  a2 = kcmTomicron*fSz->GetRMS(); a2 *= a2; a2 += kRMSz*kRMSz;
+  //  if(a1>1.E5) printf(" sigmaZ2= %e\n",a2);
+  rpSDD.SetSigmaZ2(a2);
+  rpSDD.SetProbability(1.0);
+
+}
+//_______________________________________________________________________
+					 AliITSmodule *mod,Int_t trackNumber){
+
+  const Float_t kcmTomicron = 1.0e4;
+  const Float_t kdEdXtoQ = 2.778e+8; // Boris Batyuna June 10 2000.
+  const Float_t kRMSx = 20.0; // microns ITS TDR Table 1.3
+  const Float_t kRMSz = 830.0; // microns ITS TDR Table 1.3
+  Float_t a1,a2; // general float.
+  AliITSRecPoint rpSSD;
+  Int_t *trk = rpSSD.GetTracks();
+
+  trk[0] = trackNumber;
+  trk[1] = 0; trk[2] = 0;
+  rpSSD.SetX(kcmTomicron*fSx->GetMean());
+  rpSSD.SetZ(kcmTomicron*fSz->GetMean());
+  rpSSD.SetdEdX(e);
+  rpSSD.SetQ(kdEdXtoQ*e);
+  a1 = kcmTomicron*fSx->GetRMS(); a1 *= a1; a1 += kRMSx*kRMSx;
+  //  if(a1>1.E5) printf("addSSD: layer=%d track #%d dedx=%e sigmaX2= %e ",
+  //		    mod->GetLayer(),trackNumber,e,a1);
+  rpSSD.SetSigmaX2(a1);
+  a2 = kcmTomicron*fSz->GetRMS(); a2 *= a2; a2 += kRMSz*kRMSz;
+  //  if(a1>1.E5) printf(" sigmaZ2= %e RMSx=%e RMSz=%e\n",a2,fSx->GetRMS(),fSz->GetRMS());
+  rpSSD.SetSigmaZ2(a2);
+  rpSSD.SetProbability(1.0);
+
+}
+//_______________________________________________________________________
diff --git a/ITS/AliITSsimulationFastPoints.h b/ITS/AliITSsimulationFastPoints.h
new file mode 100644
index 0000000..6e2e52f
--- /dev/null
+++ b/ITS/AliITSsimulationFastPoints.h
@@ -0,0 +1,30 @@
+#ifndef ALIITSSIMULATIONFASTPOINTS_H
+#define ALIITSSIMULATIONFASTPOINTS_H
+
+#include "AliITSsimulation.h"
+
+class AliITSmodule;
+class AliITSstatistics;
+
+class AliITSsimulationFastPoints : public AliITSsimulation
+{
+
+public:
+  AliITSsimulationFastPoints(); // default constructor
+  virtual ~AliITSsimulationFastPoints();
+  void CreateFastRecPoints(AliITSmodule *mod);
+private:
+  void AddSPD(Float_t &e,AliITSmodule *mod,Int_t trackNumber);
+  void AddSDD(Float_t &e,AliITSmodule *mod,Int_t trackNumber);
+  void AddSSD(Float_t &e,AliITSmodule *mod,Int_t trackNumber);
+
+private:
+
+  AliITSstatistics *fSx;   // pointer to AliITSstatistics class
+  AliITSstatistics *fSz;   // pointer to AliITSstatistics class
+
+  ClassDef(AliITSsimulationFastPoints,1) // Fast point simulator.
+
+};
+
+#endif
diff --git a/ITS/AliITSsimulationSDD.cxx b/ITS/AliITSsimulationSDD.cxx
new file mode 100644
index 0000000..363aa3f
--- /dev/null
+++ b/ITS/AliITSsimulationSDD.cxx
@@ -0,0 +1,1390 @@
+/**************************************************************************
+ *                                                                        *
+ * 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.                  *
+ **************************************************************************/
+
+
+#include
+#include
+#include
+#include
+
+
+
+#include "AliRun.h"
+#include "AliITSetfSDD.h"
+#include "AliITSsimulationSDD.h"
+#include "AliITSHuffman.h"
+
+const Int_t kMaxNeighbours = 4;
+
+ClassImp(AliITSsimulationSDD)
+////////////////////////////////////////////////////////////////////////
+// Version: 0
+// Written by Piergiorgio Cerello
+// November 23 1999
+//
+// AliITSsimulationSDD is the simulation of SDDs.
+  //
+//Begin_Html
+/*
+
+```
+
+ +

This show the relasionships between the ITS hit class and the rest of Aliroot. + +

```+*/
+//End_Html
+//_____________________________________________________________________________
+
+Int_t power(Int_t b, Int_t e) {
+  // copute b to the e power, where bothe b and e are Int_ts.
+  Int_t power = 1,i;
+  for(i=0; iGetSamples();
+  Int_t l = (Int_t) ((log((Float_t) samples)/log(2.))+0.5);
+  Int_t m1 = samples;
+  Int_t m  = samples/2;
+  Int_t m2 = samples/m1;
+  Int_t i,j,k;
+  for(i=1; i<=l; i++) {
+    for(j=0; jGetWeightReal(p);
+        Double_t wsi = alisddetf->GetWeightImag(p);
+	if(direction == -1) wsi = -wsi;
+	Double_t xr = *(real+k+m);
+	Double_t xi = *(imag+k+m);
+	*(real+k+m) = wsr*(*(real+k)-xr) - wsi*(*(imag+k)-xi);
+	*(imag+k+m) = wsr*(*(imag+k)-xi) + wsi*(*(real+k)-xr);
+	*(real+k) += xr;
+	*(imag+k) += xi;
+	p += m2;
+      }
+    }
+    m1 = m;
+    m /= 2;
+    m2 += m2;
+  }
+
+  for(j=0; j= j) {
+      Double_t xr = *(real+j);
+      Double_t xi = *(imag+j);
+      *(real+j) = *(real+p);
+      *(imag+j) = *(imag+p);
+      *(real+p) = xr;
+      *(imag+p) = xi;
+    }
+  }
+  if(direction == -1) {
+    for(i=0; iNpz();
+      fMaxNofSamples=fSegmentation->Npx();
+
+      Float_t sddLength = fSegmentation->Dx();
+      Float_t sddWidth = fSegmentation->Dz();
+
+      Int_t dummy=0;
+      Float_t anodePitch = fSegmentation->Dpz(dummy);
+      Double_t timeStep = (Double_t)fSegmentation->Dpx(dummy);
+      Float_t driftSpeed=fResponse->DriftSpeed();
+
+      if(anodePitch*(fNofMaps/2) > sddWidth) {
+         Warning("AliITSsimulationSDD",
+            "Too many anodes %d or too big pitch %f \n",fNofMaps/2,anodePitch);
+      }
+
+      if(timeStep*fMaxNofSamples < sddLength/driftSpeed) {
+         Error("AliITSsimulationSDD",
+                              "Time Interval > Allowed Time Interval: exit\n");
+         return;
+      }
+
+      fElectronics = new AliITSetfSDD(timeStep);
+
+      Option_t *opt1, *opt2;
+      fResponse->ParamOptions(opt1,opt2);
+      fParam=opt2;
+      char *same = strstr(opt1,"same");
+      if (same) {
+         fNoise.Set(0);
+         fBaseline.Set(0);
+      } else {
+         fNoise.Set(fNofMaps);
+         fBaseline.Set(fNofMaps);
+      }
+
+      //
+      Option_t *opt=fResponse->ZeroSuppOption();
+        if (strstr(fParam,"file") ) {
+	  fD.Set(fNofMaps);
+	  fT1.Set(fNofMaps);
+          if (strstr(opt,"2D")) {
+	    fT2.Set(fNofMaps);
+            fTol.Set(0);
+            Init2D();       // desactivate if param change module by module
+          } else if(strstr(opt,"1D"))  {
+            fT2.Set(2);
+            fTol.Set(2);
+            Init1D();      // desactivate if param change module by module
+	  }
+	} else {
+          fD.Set(2);
+	  fTol.Set(2);
+	  fT1.Set(2);
+	  fT2.Set(2);
+	  SetCompressParam();
+	}
+
+
+	Bool_t write=fResponse->OutputOption();
+	if(write && strstr(opt,"2D")) MakeTreeB();
+
+        // call here if baseline does not change by module
+
+        fITS = (AliITS*)gAlice->GetModule("ITS");
+        Int_t size=fNofMaps*fMaxNofSamples;
+	fStream = new AliITSInStream(size);
+
+}
+
+
+//_____________________________________________________________________________
+
+AliITSsimulationSDD::~AliITSsimulationSDD() {
+  // destructor
+
+  delete fHitMap1;
+  delete fHitMap2;
+  delete fStream;
+
+  fD.Set(0);
+  fT1.Set(0);
+  fT2.Set(0);
+  fTol.Set(0);
+  fNoise.Set(0);
+  fBaseline.Set(0);
+
+  if (fHis) {
+     fHis->Delete();
+     delete fHis;
+  }
+}
+//_____________________________________________________________________________
+
+void AliITSsimulationSDD::DigitiseModule(AliITSmodule *mod,Int_t md,Int_t ev){
+  // create maps to build the lists of tracks
+  // for each digit
+
+    fModule=md;
+    fEvent=ev;
+
+    TObjArray *fHits = mod->GetHits();
+    Int_t nhits = fHits->GetEntriesFast();
+    if (!nhits) return;
+
+
+    TObjArray *list=new TObjArray;
+    static TClonesArray *padr=0;
+    Int_t arg[5] = {0,0,0,0,0};
+    fHitMap1->SetArray(list);
+
+
+    Int_t NofAnodes=fNofMaps/2;
+
+    Float_t sddLength = fSegmentation->Dx();
+    Float_t sddWidth = fSegmentation->Dz();
+
+    Int_t dummy=0;
+    Float_t anodePitch = fSegmentation->Dpz(dummy);
+    Float_t timeStep = fSegmentation->Dpx(dummy);
+
+    Float_t driftSpeed=fResponse->DriftSpeed();
+
+    // Piergiorgio's part (apart for few variables which I made float
+    // when i thought that can be done
+
+    // Fill detector maps with GEANT hits
+    // loop over hits in the module
+
+    const Float_t kconv=1000000.;  // GeV->KeV
+    Int_t ii;
+    for(ii=0; iiAt(ii);
+	Int_t hitDetector = hit->GetDetector();
+	Float_t xL[3];
+	hit->GetPositionL(xL[0],xL[1],xL[2]);
+	//  cout << "hit local coordinates: " << xL[0] << "," << xL[1] << "," << xL[2] << endl;
+	// Deposited energy in keV
+	Float_t avpath = 0.;
+	Float_t avanod = 0.;
+	Float_t depEnergy = kconv*hit->GetIonization();
+	AliITShit *hit1 = 0;
+	if(depEnergy == 0.) {
+	  ii++;
+	  Float_t xL1[3];
+	  hit1 = (AliITShit*) fHits->At(ii);
+	  hit1->GetPositionL(xL1[0],xL1[1],xL1[2]);
+	  //cout << "hit1 local coordinates: " << xL1[0] << "," << xL1[1] << "," << xL1[2] << endl;
+	  //cout << "radius1: " << TMath::Sqrt(xL1[0]*xL1[0]+xL1[1]*xL1[1]) << ", azimuth: " << TMath::ATan2(xL1[0],xL1[1]) << endl;
+	  avpath = xL1[0];
+	  avanod = xL1[2];
+	  depEnergy = kconv*hit1->GetIonization();
+	}
+	Float_t avDrft = xL[0]+avpath;
+	Float_t avAnode = xL[2]+avanod;
+
+	if(avpath != 0.) avDrft /= 2.;
+	if(avanod != 0.) avAnode /= 2.;
+
+	Float_t driftPath = 10000.*avDrft;
+	//printf("sddLength %f avDrft driftPath %f %f\n",sddLength,avDrft, driftPath);
+	Int_t iWing = 2;
+	if(driftPath < 0) {
+	  iWing = 1;
+	  driftPath = -driftPath;
+	}
+	driftPath = sddLength-driftPath;
+	Int_t detector = 2*(hitDetector-1) + iWing;
+	if(driftPath < 0) {
+	  cout << "Warning: negative drift path " << driftPath << endl;
+	  continue;
+	}
+
+	//   Drift Time
+	Float_t driftTime = driftPath/driftSpeed;
+	Int_t timeSample = (Int_t) (driftTime/timeStep + 1);
+	if(timeSample > fMaxNofSamples) {
+	  cout << "Warning: Wrong Time Sample: " << timeSample << endl;
+	  continue;
+	}
+
+	//   Anode
+	Float_t xAnode = 10000.*(avAnode)/anodePitch + NofAnodes/2;  // +1?
+	//    Int_t iAnode = 0.5+xAnode; // xAnode?
+	if(xAnode*anodePitch > sddWidth || xAnode*anodePitch < 0.)
+             { cout << "Warning: Z = " << xAnode*anodePitch << endl; }
+	Int_t iAnode = (Int_t) (1.+xAnode); // xAnode?
+	//    cout << "iAnode " << iAnode << endl;
+	if(iAnode < 0 || iAnode > NofAnodes) {
+	  cout << "Warning: Wrong iAnode: " << iAnode << endl;
+	  continue;
+	}
+
+
+	// work with the idtrack=entry number in the TreeH
+	// Int_t idtrack=mod->GetHitTrackIndex(ii);
+        // or store straight away the particle position in the array
+	// of particles :
+        Int_t idtrack = hit->GetTrack();
+
+	//  Signal 2d Shape
+	Double_t qRef = (Double_t)fResponse->Qref();
+	Double_t diffCoeff = (Double_t)fResponse->DiffCoeff();
+
+	Double_t gamma = 1. + 0.155*depEnergy/qRef;
+	// Squared Sigma along the anodes
+	Double_t sigma2A = 2.*diffCoeff*driftTime*gamma;
+	Double_t sigmaT  = TMath::Sqrt(sigma2A)/driftSpeed;
+
+	// Peak amplitude in nanoAmpere
+	Double_t eVpairs = 3.6;
+	Double_t amplitude = 160.*depEnergy/(timeStep*eVpairs*2.*acos(-1.)*sigmaT*TMath::Sqrt(sigma2A));
+
+	// Spread the charge
+	// Pixel index
+	Int_t ja = iAnode;
+	Int_t jt = timeSample;
+	// Sub-pixel index
+	Int_t nsplit = 8;
+	nsplit = (nsplit+1)/2*2;
+	// Sub-pixel size
+	Double_t aStep = anodePitch/nsplit;
+	Double_t tStep = timeStep/nsplit;
+	// Define SDD window corresponding to the hit
+	Int_t anodeWindow = (Int_t) (4.*TMath::Sqrt(sigma2A)/anodePitch + 1);
+	Int_t timeWindow = (Int_t) (4.*sigmaT/timeStep + 1);
+	Int_t jamin = (ja - anodeWindow/2 - 1)*nsplit + 1;
+	Int_t jamax = (ja + anodeWindow/2)*nsplit;
+	if(jamin <= 0) jamin = 1;
+	if(jamax > NofAnodes*nsplit) jamax = NofAnodes*nsplit;
+	Int_t jtmin = (jt - timeWindow/2 - 1)*nsplit + 1;
+	Int_t jtmax = (jt + timeWindow/2)*nsplit;
+	if(jtmin <= 0) jtmin = 1;
+	if(jtmax > fMaxNofSamples*nsplit) jtmax = fMaxNofSamples*nsplit;
+	Double_t rlAnode = log(aStep*amplitude);
+	// Spread the charge in the anode-time window
+        Int_t ka;
+	for(ka=jamin; ka <=jamax; ka++) {
+	  Int_t ia = (ka-1)/nsplit + 1;
+	  if(ia <= 0) { cout << "Warning: ia < 1: " << endl; continue; }
+	  if(ia > NofAnodes) ia = NofAnodes;
+	  Double_t aExpo = aStep*(ka)-xAnode*anodePitch;
+	  Double_t anodeAmplitude = rlAnode - 0.5*aExpo*aExpo/sigma2A;
+	  // Protect against overflows
+	  if(anodeAmplitude > -87.3)
+	    anodeAmplitude = exp(anodeAmplitude);
+	  else
+	    anodeAmplitude = 0;
+	  if(anodeAmplitude) {
+	    Double_t rlTime = log(tStep*anodeAmplitude);
+            Int_t kt;
+	    for(kt=jtmin; kt<=jtmax; kt++) {
+	      Int_t it = (kt-1)/nsplit+1;
+	      if(it<=0) { cout << "Warning: it < 1: " << endl; continue; }
+	      if(it>fMaxNofSamples) it = fMaxNofSamples;
+	      Double_t tExpo = (tStep*(kt)-driftTime)/sigmaT;
+	      Double_t timeAmplitude = rlTime - 0.5*tExpo*tExpo;
+	      // Protect against overflows
+	      if(timeAmplitude > -87.3)
+		timeAmplitude = exp(timeAmplitude);
+	      else
+		timeAmplitude = 0;
+
+	      Int_t index = ((detector+1)%2)*NofAnodes+ia-1;
+	      // build the list of digits for this module
+	      arg[0]=index;
+	      arg[1]=it;
+	      arg[2]=idtrack;
+	} // loop over time in window
+      } // end if anodeAmplitude
+    } // loop over anodes in window
+  } // end loop over hits
+
+  Int_t nentries=list->GetEntriesFast();
+  // introduce the electronics effects and do zero-suppression if required
+  if (nentries) {
+    ChargeToSignal();
+
+    Option_t *opt=fResponse->ZeroSuppOption();
+    ZeroSuppression(opt);
+  }
+
+  // clean memory
+  list->Delete();
+  delete list;
+
+
+  fHitMap1->ClearMap();
+  fHitMap2->ClearMap();
+
+  //gObjectTable->Print();
+}
+
+
+//____________________________________________
+
+void AliITSsimulationSDD::ListOfFiredCells(Int_t *arg,Double_t timeAmplitude,
+                                           TObjArray *list,TClonesArray *padr){
+  // Returns the list of "fired" cells.
+
+                    Int_t index=arg[0];
+                    Int_t it=arg[1];
+                    Int_t idtrack=arg[2];
+                    Int_t counter=arg[3];
+
+                    Int_t digits[3];
+
+		    digits[0]=index;
+		    digits[1]=it-1;
+		    digits[2]=(Int_t)timeAmplitude;
+                    Float_t phys;
+		    if (idtrack >= 0) phys=(Float_t)timeAmplitude;
+		    else phys=0;
+
+                    Double_t charge=timeAmplitude;
+		    AliITSTransientDigit* pdigit;
+		    // build the list of fired cells and update the info
+		    if (!fHitMap1->TestHit(index, it-1)) {
+
+			trinfo(0)=(Float_t)idtrack;
+			trinfo(1)=(Float_t)timeAmplitude;
+
+			    new AliITSTransientDigit(phys,digits),counter);
+
+			fHitMap1->SetHit(index, it-1, counter);
+			fHitMap2->SetHit(index, it-1, charge);
+			counter++;
+
+			pdigit=(AliITSTransientDigit*)list->
+                                                      At(list->GetLast());
+			// list of tracks
+			TObjArray *trlist=(TObjArray*)pdigit->TrackList();
+
+		    } else {
+			pdigit=
+                         (AliITSTransientDigit*) fHitMap1->GetHit(index, it-1);
+                        charge += fHitMap2->GetSignal(index,it-1);
+			fHitMap2->SetHit(index, it-1, charge);
+			// update charge
+			(*pdigit).fSignal=(Int_t)charge;
+			(*pdigit).fPhysics+=phys;
+			// update list of tracks
+			TObjArray* trlist=(TObjArray*)pdigit->TrackList();
+			Int_t lastentry=trlist->GetLast();
+			TVector *ptrkp=(TVector*)trlist->At(lastentry);
+			TVector &trinfo=*ptrkp;
+			Int_t lasttrack=Int_t(trinfo(0));
+			Float_t lastcharge=(trinfo(1));
+
+ 			if (lasttrack==idtrack ) {
+			    lastcharge+=(Float_t)timeAmplitude;
+			    trlist->RemoveAt(lastentry);
+			    trinfo(0)=lasttrack;
+			    trinfo(1)=lastcharge;
+			} else {
+
+			    trinfo(0)=(Float_t)idtrack;
+			    trinfo(1)=(Float_t)timeAmplitude;
+
+			}
+
+#ifdef print
+			// check the track list - debugging
+                        Int_t trk[50];
+                        Float_t chtrk[50];
+			Int_t nptracks=trlist->GetEntriesFast();
+			if (nptracks > 2) {
+                            Int_t tr;
+			    for(tr=0;trAt(tr);
+				TVector &pptrk=*pptrkp;
+				trk[tr]=Int_t(pptrk(0));
+				chtrk[tr]=(pptrk(1));
+                                printf("nptracks %d \n",nptracks);
+				// set printings
+			    }
+			} // end if nptracks
+#endif
+		    } //  end if pdigit
+
+                    arg[3]=counter;
+
+
+}
+
+
+//____________________________________________
+
+void AliITSsimulationSDD::AddDigit(Int_t i, Int_t j, Int_t signal){
+  // Adds a Digit.
+    // tag with -1 signals coming from background tracks
+    // tag with -2 signals coming from pure electronic noise
+
+    Int_t digits[3], tracks[3];
+    Float_t phys, charges[3];
+
+    Int_t trk[20];
+    Float_t chtrk[20];
+
+    signal=Convert8to10(signal); // set a flag in case non-ZS are 10-bit
+    AliITSTransientDigit *obj = (AliITSTransientDigit*)fHitMap1->GetHit(i,j);
+    digits[0]=i;
+    digits[1]=j;
+    digits[2]=signal;
+    // printf("module anode, time, signal %d %d %d %d\n",fModule,i,j,signal);
+    if (!obj) {
+        phys=0;
+        Int_t k;
+        for(k=0;k<3;k++) {
+	  tracks[k]=-2;
+          charges[k]=0;
+	}
+    } else {
+      phys=obj->fPhysics;
+      //printf("AddDigit - test: fCoord1 fCoord2 fSignal %d %d %d i j signal %d %d %d \n",obj->fCoord1,obj->fCoord2,obj->fSignal,i,j,signal);
+
+      TObjArray* trlist=(TObjArray*)obj->TrackList();
+      Int_t nptracks=trlist->GetEntriesFast();
+
+      if (nptracks > 20) {
+	 cout<<"Attention - nptracks > 20 "<At(tr));
+	  trk[tr]=Int_t(pp(0));
+	  chtrk[tr]=(pp(1));
+      }
+      if (nptracks > 1) {
+	  //printf("AddDigit: nptracks %d\n",nptracks);
+	  SortTracks(trk,chtrk,nptracks);
+      }
+      Int_t i;
+      if (nptracks < 3 ) {
+
+    }
+
+}
+
+//____________________________________________
+
+void AliITSsimulationSDD::SortTracks(Int_t *tracks,Float_t *charges,Int_t ntr){
+  //
+  // Sort the list of tracks contributing to a given digit
+  // Only the 3 most significant tracks are acctually sorted
+  //
+
+  //
+  //  Loop over signals, only 3 times
+  //
+
+
+  Float_t qmax;
+  Int_t jmax;
+  Int_t idx[3] = {-3,-3,-3};
+  Float_t jch[3] = {-3,-3,-3};
+  Int_t jtr[3] = {-3,-3,-3};
+  Int_t i,j,imax;
+
+  if (ntr<3) imax=ntr;
+  else imax=3;
+  for(i=0;i qmax) {
+	qmax = charges[j];
+	jmax=j;
+      }
+    }
+
+    if(qmax > 0) {
+      idx[i]=jmax;
+      jch[i]=charges[jmax];
+      jtr[i]=tracks[jmax];
+    }
+
+  }
+
+  for(i=0;i<3;i++){
+    if (jtr[i] == -3) {
+         charges[i]=0;
+         tracks[i]=0;
+    } else {
+         charges[i]=jch[i];
+         tracks[i]=jtr[i];
+    }
+  }
+
+}
+//____________________________________________
+void AliITSsimulationSDD::ChargeToSignal() {
+  // add baseline, noise, electronics and ADC saturation effects
+
+  Double_t InZR[fMaxNofSamples];
+  Double_t InZI[fMaxNofSamples];
+  Double_t OutZR[fMaxNofSamples];
+  Double_t OutZI[fMaxNofSamples];
+
+
+  Float_t TopValue = fResponse->MagicValue();
+  Float_t norm = maxadc/TopValue;
+
+
+  Option_t *opt1, *opt2;
+  fResponse->ParamOptions(opt1,opt2);
+  char *read = strstr(opt1,"file");
+
+  Float_t baseline, noise;
+
+  if (read) {
+      static Bool_t readfile=kTRUE;
+      //read baseline and noise from file
+  } else fResponse->GetNoiseParam(noise,baseline);
+
+  Float_t contrib=0;
+  Bool_t first=kTRUE;
+
+  TRandom *random = new TRandom();
+    Int_t i,k;
+    for(i=0;i<=fNofMaps;i++) {
+    if  (read) GetAnodeBaseline(i,baseline,noise);
+    if (!first) FastFourierTransform(fElectronics,&InZR[0],&InZI[0],1);
+	   // back to analog: ?
+	   signal /=norm;
+	   //printf("ChargeToSignal: signal %f\n",signal);
+	   fHitMap2->SetHit(i-1,k,signal);
+
+ 	   Double_t rw = fElectronics->GetTraFunReal(k);
+	   Double_t iw = fElectronics->GetTraFunImag(k);
+	   OutZR[k] = InZR[k]*rw - InZI[k]*iw;
+	   OutZI[k] = InZR[k]*iw + InZI[k]*rw;
+	   if(i+1 < fNofMaps) InZR[k] = fHitMap2->GetSignal(i+1,k);
+	}
+
+        if (first) {
+             InZR[k] = fHitMap2->GetSignal(i,k);
+	 }
+        InZI[k] = 0.;
+        // add baseline and noise
+        contrib = baseline + noise*random->Gaus();
+        InZR[k] += contrib;
+
+    } // loop over time
+
+    if (first) {
+         FastFourierTransform(fElectronics,&InZR[0],&InZI[0],1);
+	 for(k=0; kGetTraFunReal(k);
+	     Double_t iw = fElectronics->GetTraFunImag(k);
+	     OutZR[k] = InZR[k]*rw - InZI[k]*iw;
+	     OutZI[k] = InZR[k]*iw + InZI[k]*rw;
+	     InZR[k] = fHitMap2->GetSignal(i+1,k);
+	     InZI[k] = 0.;
+	     // add baseline and noise
+	     contrib = baseline + noise*random->Gaus();
+	     InZR[k] += contrib;
+	  }
+    }
+    FastFourierTransform(fElectronics,&OutZR[0],&OutZI[0],-1);
+    first = kFALSE;
+  } // loop over anodes
+
+}
+
+//____________________________________________
+void AliITSsimulationSDD::GetAnodeBaseline(Int_t i,Float_t &baseline,
+                                           Float_t &noise){
+  // Returns the Baseline for a particular anode.
+    baseline=fBaseline[i];
+    noise=fNoise[i];
+
+}
+
+//____________________________________________
+void AliITSsimulationSDD::CompressionParam(Int_t i,Int_t &db,Int_t &tl,
+                                           Int_t &th){
+  // Returns the compression alogirthm parameters
+   Int_t size = fD.GetSize();
+   if (size > 2 ) {
+      db=fD[i]; tl=fT1[i]; th=fT2[i];
+   } else {
+      if (size <= 2 && i>=fNofMaps/2) {
+	db=fD[1]; tl=fT1[1]; th=fT2[1];
+      } else {
+        db=fD[0]; tl=fT1[0]; th=fT2[0];
+      }
+   }
+}
+//____________________________________________
+void AliITSsimulationSDD::CompressionParam(Int_t i,Int_t &db,Int_t &tl){
+  // returns the compression alogirthm parameters
+   Int_t size = fD.GetSize();
+   if (size > 2 ) {
+      db=fD[i]; tl=fT1[i];
+   } else {
+      if (size <= 2 && i>=fNofMaps/2) {
+	db=fD[1]; tl=fT1[1];
+      } else {
+        db=fD[0]; tl=fT1[0];
+      }
+   }
+
+}
+//____________________________________________
+void AliITSsimulationSDD::SetCompressParam(){
+  // Sets the compression alogirthm parameters
+   Int_t cp[8],i;
+
+   fResponse->GiveCompressParam(cp);
+   for(i=0; i<2; i++) {
+       fD[i]  =cp[i];
+       fT1[i] =cp[i+2];
+       fT2[i] =cp[i+4];
+       fTol[i]=cp[i+6];
+       /*
+       printf("\n i, fD, fT1, fT2, fTol %d %d %d %d %d\n",
+                                      i,fD[i],fT1[i],fT2[i],fTol[i]);
+       */
+   }
+}
+
+//____________________________________________
+      // read baseline and noise from file - either a .root file and in this
+      // case data should be organised in a tree with one entry for each
+      // module => reading should be done accordingly
+      // or a classic file and do smth. like this:
+  //
+  // Read baselines and noise for SDD
+  //
+
+
+    Int_t na,pos;
+    Float_t bl,n;
+    const char *kinput, *base,*kparam;
+    char *filtmp;
+
+    fResponse->Filenames(kinput,base,kparam);
+    fFileName=base;
+//
+    filtmp = gSystem->ExpandPathName(fFileName.Data());
+    FILE *bline = fopen(filtmp,"r");
+    printf("filtmp %s\n",filtmp);
+    na = 0;
+
+    if(bline) {
+       while(fscanf(bline,"%d %f %f",&pos, &bl, &n) != EOF) {
+	 //printf("na, pos, bl, n %d %d %f %f\n",na, pos, bl, n);
+          if (pos != na+1) {
+             Error("ReadBaseline","Anode number not in increasing order!",
+                   filtmp);
+             exit(1);
+	  }
+          fBaseline[na]=bl;
+          fNoise[na]=n;
+          na++;
+       }
+    } else {
+      Error("ReadBaseline"," THE BASELINE FILE %s DOES NOT EXIST !",
+	  filtmp);
+      exit(1);
+    } // end if(bline)
+
+    fclose(bline);
+    delete [] filtmp;
+
+
+}
+
+//____________________________________________
+Int_t AliITSsimulationSDD::Convert10to8(Int_t signal) {
+  // To the 10 to 8 bit lossive compression.
+  // code from Davide C. and Albert W.
+
+   if (signal < 128)  return signal;
+   if (signal < 256)  return (128+((signal-128)>>1));
+   if (signal < 512)  return (192+((signal-256)>>3));
+   if (signal < 1024) return (224+((signal-512)>>4));
+   return 0;
+
+}
+
+//____________________________________________
+Int_t AliITSsimulationSDD::Convert8to10(Int_t signal) {
+  // Undo the lossive 10 to 8 bit compression.
+  // code from Davide C. and Albert W.
+   if (signal < 0 || signal > 255) {
+       printf(" out of range %d \n",signal);
+       return 0;
+   }
+
+   if (signal < 128) return signal;
+   if (signal < 192) {
+     if (TMath::Odd(signal)) return (128+((signal-128)<<1));
+     else  return (128+((signal-128)<<1)+1);
+   }
+   if (signal < 224) {
+     if (TMath::Odd(signal)) return (256+((signal-192)<<3)+3);
+     else  return (256+((signal-192)<<3)+4);
+   }
+   if (TMath::Odd(signal)) return (512+((signal-224)<<4)+7);
+   else  return (512+((signal-224)<<4)+7);
+   return 0;
+
+}
+
+//____________________________________________
+AliITSMap*   AliITSsimulationSDD::HitMap(Int_t i){
+  //Return the correct map.
+    return ((i==0)? fHitMap1 : fHitMap2);
+}
+
+
+//____________________________________________
+void AliITSsimulationSDD::ZeroSuppression(Option_t *option) {
+  // perform the zero suppresion
+  if (strstr(option,"2D")) {
+    //Init2D();              // activate if param change module by module
+    Compress2D();
+  } else if (strstr(option,"1D")) {
+    //Init1D();              // activate if param change module by module
+    Compress1D();
+  } else StoreAllDigits();
+
+}
+
+//____________________________________________
+void AliITSsimulationSDD::Init2D(){
+     // read in and prepare arrays: fD, fT1, fT2
+     //                         savemu[nanodes], savesigma[nanodes]
+      // read baseline and noise from file - either a .root file and in this
+      // case data should be organised in a tree with one entry for each
+      // module => reading should be done accordingly
+      // or a classic file and do smth. like this ( code from Davide C. and
+      // Albert W.) :
+  //
+  // Read 2D zero-suppression parameters for SDD
+  //
+
+    if (!strstr(fParam,"file")) return;
+
+    Int_t na,pos,tempTh;
+    Float_t mu,sigma;
+    Float_t savemu[fNofMaps], savesigma[fNofMaps];
+    const char *kinput,*kbasel,*kpar;
+    char *filtmp;
+
+
+    Int_t minval = fResponse->MinVal();
+
+    fResponse->Filenames(kinput,kbasel,kpar);
+    fFileName=kpar;
+
+//
+    filtmp = gSystem->ExpandPathName(fFileName.Data());
+    FILE *param = fopen(filtmp,"r");
+    na = 0;
+
+    if(param) {
+       while(fscanf(param,"%d %f %f",&pos, &mu, &sigma) != EOF) {
+          if (pos != na+1) {
+             Error("Init2D ","Anode number not in increasing order!",
+                   filtmp);
+             exit(1);
+	  }
+          savemu[na]=mu;
+          savesigma[na]=sigma;
+          if ((2.*sigma) < mu) {
+              fD[na] = (Int_t)floor(mu - 2.0*sigma + 0.5);
+              mu = 2.0 * sigma;
+	  } else fD[na] = 0;
+          tempTh = (Int_t)floor(mu+2.25*sigma+0.5) - minval;
+          if (tempTh < 0) tempTh=0;
+          fT1[na] = tempTh;
+          tempTh = (Int_t)floor(mu+3.0*sigma+0.5) - minval;
+          if (tempTh < 0) tempTh=0;
+          fT2[na] = tempTh;
+          na++;
+       } // end while
+
+    } else {
+      Error("Init2D "," THE FILE %s DOES NOT EXIST !",
+	  filtmp);
+      exit(1);
+    } // end if(param)
+
+    fclose(param);
+    delete [] filtmp;
+
+
+
+}
+//____________________________________________
+void AliITSsimulationSDD::Compress2D(){
+  //
+  // simple ITS cluster finder -- online zero-suppression conditions
+  //
+  //
+
+  //printf("Compress2D!\n");
+
+    Int_t db,tl,th;
+    Int_t minval = fResponse->MinVal();
+    Bool_t write=fResponse->OutputOption();
+
+    Int_t nz, nl, nh, low, i, j;
+
+    for(i=0; iGetSignal(i,j));
+	    signal -= db; // if baseline eq. is done here
+            if (signal <= 0) {nz++; continue;}
+	    if ((signal - tl) < minval) low++;
+            if ((signal - th) >= minval) {
+	        nh++;
+		Bool_t cond=kTRUE;
+		//printf("Compress2D : i j %d %d signal %d\n",i,j,signal);
+		FindCluster(i,j,signal,minval,cond);
+	    } else if ((signal - tl) >= minval) nl++;
+       } // loop time samples
+       if (write) TreeB()->Fill(nz,nl,nh,low,i+1);
+       //if (nz != 256 && low != 256) printf("i, nz, nl, nh  low %d %d %d %d %d\n",i,nz,nl,nh,low);
+    } // loop anodes
+
+      char hname[30];
+      if (write) {
+	sprintf(hname,"TNtuple%d_%d",fModule,fEvent);
+	TreeB()->Write(hname);
+	// reset tree
+        TreeB()->Reset();
+      }
+
+}
+
+//_____________________________________________________________________________
+void  AliITSsimulationSDD::FindCluster(Int_t i,Int_t j,Int_t signal,
+                                       Int_t minval,Bool_t cond){
+//
+//  Find clusters according to the online 2D zero-suppression algorithm
+//
+
+    Bool_t high=kFALSE;
+
+    fHitMap2->FlagHit(i,j);
+//
+//  check the online zero-suppression conditions
+//
+    Int_t nn;
+    Int_t dbx,tlx,thx;
+    Int_t Xlist[kMaxNeighbours], Ylist[kMaxNeighbours];
+    fSegmentation->Neighbours(i,j,&nn,Xlist,Ylist);
+    Int_t in,ix,iy;
+    for(in=0; inTestHit(ix,iy)==kUnused) {
+	   CompressionParam(ix,dbx,tlx,thx);
+           Int_t qn = (Int_t)(fHitMap2->GetSignal(ix,iy));
+	   qn -= dbx; // if baseline eq. is done here
+	   if ((qn-tlx) < minval) {
+	      fHitMap2->FlagHit(ix,iy);
+	      continue;
+	   } else {
+              if ((qn - thx) >= minval) high=kTRUE;
+              if (cond) {
+                 signal = Convert10to8(signal);
+		 //printf("FindCl -cond : i j %d %d signal %d\n",i,j,signal);
+	      }
+	      Int_t qns = Convert10to8(qn);
+	      //printf("FindCl : i j %d %d qns %d\n",i,j,qns);
+	      if (!high) AddDigit(ix,iy,qns);
+	      cond=kFALSE;
+	      if(!high) fHitMap2->FlagHit(ix,iy);
+	   }
+	} // TestHit
+    } // loop over neighbours
+
+}
+
+//____________________________________________
+void AliITSsimulationSDD::Init1D(){
+  // this is just a copy-paste of input taken from 2D algo
+  // Torino people should give input
+  //
+  // Read 1D zero-suppression parameters for SDD
+  //
+
+    if (!strstr(fParam,"file")) return;
+
+    Int_t na,pos,tempTh;
+    Float_t mu,sigma;
+    Float_t savemu[fNofMaps], savesigma[fNofMaps];
+    const char *kinput,*kbasel,*kpar;
+    char *filtmp;
+
+
+    Int_t minval = fResponse->MinVal();
+    fResponse->Filenames(kinput,kbasel,kpar);
+    fFileName=kpar;
+
+//  set first the disable and tol param
+    SetCompressParam();
+//
+    filtmp = gSystem->ExpandPathName(fFileName.Data());
+    FILE *param = fopen(filtmp,"r");
+    na = 0;
+
+    if (param) {
+          fscanf(param,"%d %d %d %d ", &fT2[0], &fT2[1], &fTol[0], &fTol[1]);
+          while(fscanf(param,"%d %f %f",&pos, &mu, &sigma) != EOF) {
+	       if (pos != na+1) {
+		  Error("Init1D ","Anode number not in increasing order!",
+                   filtmp);
+		  exit(1);
+	       }
+	       savemu[na]=mu;
+	       savesigma[na]=sigma;
+	       if ((2.*sigma) < mu) {
+		 fD[na] = (Int_t)floor(mu - 2.0*sigma + 0.5);
+		 mu = 2.0 * sigma;
+	       } else fD[na] = 0;
+	       tempTh = (Int_t)floor(mu+2.25*sigma+0.5) - minval;
+	       if (tempTh < 0) tempTh=0;
+	       fT1[na] = tempTh;
+	       na++;
+	  } // end while
+    } else {
+      Error("Init1D "," THE FILE %s DOES NOT EXIST !",
+	  filtmp);
+      exit(1);
+    } // end if(param)
+
+    fclose(param);
+    delete [] filtmp;
+
+
+}
+
+//____________________________________________
+void AliITSsimulationSDD::Compress1D(){
+    // 1D zero-suppression algorithm (from Gianluca A.)
+
+    Int_t dis,tol,thres,decr,diff;
+    //char *dfile=strstr(fParam,"file");
+
+    UChar_t *str=fStream->Stream();
+    Int_t counter=0;
+
+    Int_t last=0,k,i,j;
+    for(k=1; k<=2; k++) {
+         tol = Tolerance(k-1);
+         dis = Disable(k-1);
+	 for(i=0; iGetSignal(k*i,j));
+                 signal -= decr;  // if baseline eq.
+		 signal = Convert10to8(signal);
+		 if (signal < thres) {
+                     signal=0;
+                     diff=128;
+                     last=0;
+                     // write diff in the buffer for HuffT
+                     str[counter]=(UChar_t)diff;
+                     counter++;
+                     continue;
+		 }
+                 diff=signal-last;
+                 if (diff > 127) diff=127;
+                 if (diff < -128) diff=-128;
+
+		 if (signal < dis) {
+                    if (tol==1 && (diff >= -2 && diff <= 1)) diff=0;
+                    if (tol==2 && (diff >= -4 && diff <= 3)) diff=0;
+                    if (tol==3 && (diff >= -16 && diff <= 15)) diff=0;
+		 } else {
+		 }
+
+                 diff += 128;
+                 // write diff in the buffer used to compute Huffman tables
+                 if (firstSignal) str[counter]=(UChar_t)signal;
+		 else str[counter]=(UChar_t)diff;
+		 counter++;
+
+                 last=signal;
+	         firstSignal=kFALSE;
+ 	     } // loop time samples
+	 } // loop anodes  one half of detector
+    }
+
+    // check
+    fStream->CheckCount(counter);
+
+    // open file and write out the stream of diff's
+
+    static Bool_t open=kTRUE;
+    static TFile *OutFile;
+    Bool_t write = fResponse->OutputOption();
+
+    if (write ) {
+	if(open) {
+	    SetFileName("stream.root");
+	    cout<<"filename "<cd();
+        fStream->Write();
+    }  // endif write
+
+     fStream->ClearStream();
+
+     // back to galice.root file
+
+     TTree *fAli=gAlice->TreeK();
+     TFile *file = 0;
+
+     if (fAli) file =fAli->GetCurrentFile();
+     file->cd();
+
+
+}
+//____________________________________________
+void AliITSsimulationSDD::StoreAllDigits(){
+  // if non-zero-suppressed data
+
+    Int_t digits[3],i,j;
+
+    for(i=0; iGetSignal(i,j));
+	     signal = Convert10to8(signal);
+	     signal = Convert8to10(signal); // ?
+             digits[0]=i;
+             digits[1]=j;
+             digits[2]=signal;
+	}
+    }
+}
+//____________________________________________
+
+void AliITSsimulationSDD::CreateHistograms(){
+  // Creates histograms of maps for debugging
+
+      Int_t i;
+      for(i=0;iAppend(candNum);
+	   (*fHis)[i] = new TH1F(sddName->Data(),"SDD maps",
+                              fMaxNofSamples,0.,(Float_t) fMaxNofSamples);
+	   delete sddName;
+      }
+
+}
+//____________________________________________
+
+void AliITSsimulationSDD::ResetHistograms(){
+    //
+    // Reset histograms for this detector
+    //
+    Int_t i;
+    for(i=0;iReset();
+    }
+
+}
+
+
+//____________________________________________
+
+TH1F *AliITSsimulationSDD::GetAnode(Int_t wing, Int_t anode) {
+  // Fills a histogram from a give anode.
+  if (!fHis) return 0;
+
+  if(wing <=0 || wing > 2) {
+    cout << "Wrong wing number: " << wing << endl;
+    return NULL;
+  }
+  if(anode <=0 || anode > fNofMaps/2) {
+    cout << "Wrong anode number: " << anode << endl;
+    return NULL;
+  }
+
+  Int_t index = (wing-1)*fNofMaps/2 + anode-1;
+  return (TH1F*)((*fHis)[index]);
+}
+
+//____________________________________________
+
+void AliITSsimulationSDD::WriteToFile(TFile *hfile) {
+  // Writes the histograms to a file
+  if (!fHis) return;
+
+  hfile->cd();
+  Int_t i;
+  for(i=0; iWrite(); //fAdcs[i]->Write();
+  return;
+}
+//____________________________________________
+Float_t AliITSsimulationSDD::GetNoise(Float_t threshold) {
+  // Returns the noise value
+  if (!fHis) return 0.;
+
+  TH1F *noisehist = new TH1F("noisehist","noise",100,0.,threshold);
+  Int_t i,k;
+  for(i=0;iGetNbinsX();
+    for(k=0;kGetBinContent(k+1);
+      if (content < threshold) noisehist->Fill(content);
+    }
+  }
+  TF1 *gnoise = new TF1("gnoise","gaus",0.,threshold);
+  noisehist->Fit("gnoise","RQ");
+  noisehist->Draw();
+  Float_t mnoise = gnoise->GetParameter(1);
+  cout << "mnoise : " << mnoise << endl;
+  Float_t rnoise = gnoise->GetParameter(2);
+  cout << "rnoise : " << rnoise << endl;
+  delete noisehist;
+  return rnoise;
+}
+void AliITSsimulationSDD::Streamer(TBuffer &R__b)
+{
+   // Stream an object of class AliITSsimulationSDD.
+
+   if (R__b.IsReading()) {
+      Version_t R__v = R__b.ReadVersion(); if (R__v) { }
+      AliITSsimulation::Streamer(R__b);
+      R__b >> fITS;
+      R__b >> fHitMap1;
+      R__b >> fHitMap2;
+      R__b >> fStream;
+      R__b >> fElectronics;
+      fD.Streamer(R__b);
+      fT1.Streamer(R__b);
+      fT2.Streamer(R__b);
+      fTol.Streamer(R__b);
+      fBaseline.Streamer(R__b);
+      fNoise.Streamer(R__b);
+      R__b >> fTreeB;
+      //R__b.ReadArray(fParam); // Not to be printed out?
+      fFileName.Streamer(R__b);
+      R__b >> fNofMaps;
+      R__b >> fMaxNofSamples;
+      R__b >> fModule;
+      R__b >> fEvent;
+      R__b >> fHis;
+   } else {
+      R__b.WriteVersion(AliITSsimulationSDD::IsA());
+      AliITSsimulation::Streamer(R__b);
+      R__b << fITS;
+      R__b << fHitMap1;
+      R__b << fHitMap2;
+      R__b << fStream;
+      R__b << fElectronics;
+      fD.Streamer(R__b);
+      fT1.Streamer(R__b);
+      fT2.Streamer(R__b);
+      fTol.Streamer(R__b);
+      fBaseline.Streamer(R__b);
+      fNoise.Streamer(R__b);
+      R__b << fTreeB;
+      //R__b.WriteArray(fParam, __COUNTER__); // Not to be printed out?
+      fFileName.Streamer(R__b);
+      R__b << fNofMaps;
+      R__b << fMaxNofSamples;
+      R__b << fModule;
+      R__b << fEvent;
+      R__b << fHis;
+   }
+}
diff --git a/ITS/AliITSsimulationSDD.h b/ITS/AliITSsimulationSDD.h
new file mode 100644
index 0000000..1b0b346
--- /dev/null
+++ b/ITS/AliITSsimulationSDD.h
@@ -0,0 +1,117 @@
+#ifndef ALIITSSIMULATIONSDD_H
+#define ALIITSSIMULATIONSDD_H
+
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+#include "AliITSMap.h"
+#include "AliITSsimulation.h"
+#include "AliITSRawData.h"
+
+//___________________________________________________
+
+
+
+class AliITSetfSDD;
+
+//___________________________________________________
+
+class AliITSsimulationSDD : public AliITSsimulation {
+
+public:
+
+  AliITSsimulationSDD();
+  AliITSsimulationSDD(AliITSsegmentation *seg, AliITSresponse *res);
+  AliITSsimulationSDD(AliITSsimulationSDD &source);
+  virtual ~AliITSsimulationSDD();
+  AliITSsimulationSDD& operator=(AliITSsimulationSDD &source);
+
+  // get the address of the array mapping the signal or pointers to arrays
+  virtual AliITSMap*  HitMap(Int_t i);
+
+  // set compression parameters for 2D or 1D via response functions
+  void SetCompressParam();
+  // retrieve compression parameters for 2D or 1D
+  void CompressionParam(Int_t i, Int_t &db, Int_t &tl, Int_t &th);
+  void CompressionParam(Int_t i, Int_t &db, Int_t &tl);
+
+  virtual Int_t Convert10to8(Int_t signal);
+  virtual Int_t Convert8to10(Int_t signal);
+  virtual void ZeroSuppression(Option_t *opt);
+  virtual void Init2D();
+  virtual void Compress2D();
+  virtual void Init1D();
+  virtual void Compress1D();
+  virtual void StoreAllDigits();
+  virtual void ReadBaseline();
+  virtual void GetAnodeBaseline(Int_t i, Float_t &baseline, Float_t &noise);
+  virtual void AddDigit(Int_t i, Int_t j, Int_t signal);
+  virtual void  FindCluster
+       (Int_t i, Int_t j,Int_t signal,Int_t minval,Bool_t cond);
+
+
+  // get parameters for 1D - this could be changed when we get more
+  // input from Torino after they have a look at the code
+  virtual Int_t Tolerance(Int_t i) {return fTol[i];}
+  virtual Int_t Disable(Int_t i) {return fT2[i];}
+  virtual void SetFileName(const char *filnam) {fFileName=filnam;}
+
+  void ChargeToSignal();
+  void DigitiseModule(AliITSmodule *mod,Int_t md,Int_t ev);
+  void SortTracks(Int_t *tracks,Float_t *charges,Int_t ntracks);
+  void ListOfFiredCells(Int_t *arg,Double_t timeAmplitude,TObjArray *list,
+  Int_t Module() {return fModule;}
+  Int_t Event()  {return fEvent;}
+
+  void CreateHistograms();
+  void ResetHistograms();
+  TObjArray*  GetHistArray() {return fHis;}
+
+  // create a separate tree for background monitoring (2D) -easy to do
+  virtual  void  MakeTreeB(Option_t *option="B")
+      { fTreeB = new TNtuple("ntuple","2D backgr","nz:nl:nh:low:anode");}
+  void           GetTreeB(Int_t) { }
+
+  // Return pointer to TreeB
+  TNtuple      *TreeB() {return fTreeB;}
+
+  void WriteToFile(TFile *fp);
+  TH1F *GetAnode(Int_t wing, Int_t anode);
+  Float_t GetNoise(Float_t threshold);
+
+private:
+  AliITS              *fITS;  // local pointer to ITS
+
+  AliITSMapA1         *fHitMap1; // local pointer to map of digits
+  AliITSMapA2         *fHitMap2; // local pointer to map of signals
+  AliITSInStream      *fStream;  // input file stream
+  AliITSetfSDD        *fElectronics; // local pointer to electronics simulation
+
+  TArrayI             fD;            // decrease values for baseline eq.
+  TArrayI             fT1;           // low thresholds
+  TArrayI             fT2;           // high thresholds(2D) or disable (1D)
+  TArrayI             fTol;          // tolerance
+  TArrayF             fBaseline;     // Baseline
+  TArrayF             fNoise;        // Noise value
+  TNtuple              *fTreeB;      // Background info tree for 2D
+  Option_t             *fParam;      // Compresion algorithm options
+  TString              fFileName;    // File name for possible options above
+
+  Int_t fNofMaps;       // Number of anodes used ( 1 - 2*nanodes per wing )
+  Int_t fMaxNofSamples; // Number of time samples
+  Int_t fModule;  // in case bgr, noise, param change module-by-module
+  Int_t fEvent;   // solely for output from bgr monitoring of 2D
+
+  TObjArray *fHis;             // just in case for histogramming
+
+  ClassDef(AliITSsimulationSDD,1)  // Simulation of SDD clusters
+
+};
+#endif
diff --git a/ITS/AliITSsimulationSPD.cxx b/ITS/AliITSsimulationSPD.cxx
new file mode 100644
index 0000000..af2d4af
--- /dev/null
+++ b/ITS/AliITSsimulationSPD.cxx
@@ -0,0 +1,541 @@
+#include
+#include
+#include
+
+#include "AliRun.h"
+#include "AliITSMap.h"    // "AliITSMapA2.h"
+#include "AliITSsimulationSPD.h"
+#include "AliITSsegmentation.h"
+#include "AliITSresponse.h"
+
+ClassImp(AliITSsimulationSPD)
+////////////////////////////////////////////////////////////////////////
+// Version: 0
+// Written by Boris Batyunya
+// December 20 1999
+//
+// AliITSsimulationSPD is the simulation of SPDs
+//
+//________________________________________________________________________
+
+AliITSsimulationSPD::AliITSsimulationSPD(){
+  // constructor
+  fResponse     = 0;
+  fSegmentation = 0;
+  fHis          = 0;
+  fNoise        = 0.;
+  fBaseline     = 0.;
+}
+//_____________________________________________________________________________
+
+AliITSsimulationSPD::AliITSsimulationSPD(AliITSsegmentation *seg, AliITSresponse *resp) {
+  // constructor
+      fResponse = resp;
+      fSegmentation = seg;
+
+      fResponse->GetNoiseParam(fNoise,fBaseline);
+
+
+      fMapA2 = new AliITSMapA2(fSegmentation);
+
+      //
+      fNPixelsZ=fSegmentation->Npz();
+      fNPixelsX=fSegmentation->Npx();
+
+}
+
+//_____________________________________________________________________________
+
+AliITSsimulationSPD::~AliITSsimulationSPD() {
+  // destructor
+
+  delete fMapA2;
+
+  if (fHis) {
+     fHis->Delete();
+     delete fHis;
+  }
+}
+
+//__________________________________________________________________________
+AliITSsimulationSPD::AliITSsimulationSPD(const AliITSsimulationSPD &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;
+}
+
+//_________________________________________________________________________
+AliITSsimulationSPD&
+  AliITSsimulationSPD::operator=(const AliITSsimulationSPD &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 AliITSsimulationSPD::DigitiseModule(AliITSmodule *mod, Int_t module, Int_t dummy) {
+  // 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 spdLenght = fSegmentation->Dz();
+    Float_t spdWidth = fSegmentation->Dx();
+
+    Float_t difCoef = fResponse->DiffCoeff();
+
+    Float_t zPix0 = 1e+6;
+    Float_t xPix0 = 1e+6;
+    Float_t yPix0 = 1e+6;
+    Float_t yPrev = 1e+6;
+
+    Float_t zPitch = fSegmentation->Dpz(0);
+    Float_t xPitch = fSegmentation->Dpx(0);
+
+    //cout << "pitch per z: " << zPitch << endl;
+    //cout << "pitch per r*phi: " << xPitch << endl;
+
+    TObjArray *fHits = mod->GetHits();
+    Int_t nhits = fHits->GetEntriesFast();
+    if (!nhits) return;
+
+
+
+  //  Array of pointers to the label-signal list
+
+    Int_t maxNdigits = fNPixelsX*fNPixelsZ;
+    Float_t  **pList = new Float_t* [maxNdigits];
+    memset(pList,0,sizeof(Float_t*)*maxNdigits);
+    Int_t indexRange[4] = {0,0,0,0};
+
+    // Fill detector maps with GEANT hits
+    // loop over hits in the module
+
+    Int_t layer,idtrack,status,trdown,ndZ,ndX,nsteps,iZi,nZpix,nXpix;
+    Int_t jzmin,jzmax,jxmin,jxmax,jx,jz,lz,lx,index;
+    Float_t zArg1,zArg2,xArg1,xArg2;
+    Float_t zProb1,zProb2,xProb1,xProb2;
+    Float_t dZCharge,dXCharge;
+    Double_t signal;
+    Float_t projDif;  // RMS of xDif and zDif
+    Float_t dProjn;  // RMS of dXn and dZn
+    Float_t depEnergy; // The deposited energy from this hit
+    Float_t zPix; // hit position in microns
+    Float_t xPix; // hit position in microns
+    Float_t yPix; // hit position in microns
+    Float_t zPixn; // hit position in microns
+    Float_t xPixn; // hit position in microns
+    Float_t charge,dCharge;// charge in e-
+    Float_t drPath;
+    Float_t tAng,dZ,dX,dXn,dZn;
+    Float_t dZright,dZleft;
+    Float_t dXright,dXleft;
+    Float_t dZprev,dZnext,dXprev,dXnext;
+
+    static Bool_t first=kTRUE;
+    Int_t lasttrack = -2,hit;
+    for(hit=0;hitAt(hit);
+	layer = iHit->GetLayer();
+
+	// work with the idtrack=entry number in the TreeH
+	// Int_t idtrack=mod->GetHitTrackIndex(ii);
+        // or store straight away the particle position in the array
+	// of particles :
+        idtrack = iHit->GetTrack();
+
+	//if(module==11 || module==157) {
+	  // Int_t track = iHit->fTrack;
+	  // Int_t primary = gAlice->GetPrimary(track);
+	  // Int_t parent = iHit->GetParticle()->GetFirstMother();
+	  // printf("module,hit,track,primary,parent  %d %d %d %d %d \n",
+	  //                                   md,hit,track,primary,parent);
+	//}
+
+	//  Get hit z and x(r*phi) cordinates for each module (detector)
+	//  in local system.
+
+	zPix = kconv*iHit->GetZL(); // Geant cm to microns
+	xPix = kconv*iHit->GetXL(); // Geant cm to micron
+        yPix = kconv*iHit->GetYL(); // Geant cm to micron
+
+	// Get track status
+	status = iHit->GetTrackStatus();
+	if(status != 66 && status != 68) {
+	  printf("!!!!! no order status  %d\n",status);
+	}
+
+	trdown = 0;
+
+	// enter Si or after event in Si
+	if (status == 66 ) {
+           zPix0 = zPix;
+           xPix0 = xPix;
+           yPrev = yPix;
+	}
+	// enter Si only
+	if (layer == 1 && status == 66 && yPix > 71.) {
+             yPix0 = yPix;
+	}
+	// enter Si only
+	if (layer == 2 && status == 66 && yPix < -71.) {
+             yPix0 = yPix;
+	}
+	depEnergy = iHit->GetIonization();
+	// skip if the input point to Si
+	if(depEnergy <= 0.) continue;
+	// if track returns to the opposite direction:
+	if (layer == 1 && yPix > yPrev) {
+	    yPix0 = yPrev;
+            trdown = 1;
+	}
+	if (layer == 2 && yPix < yPrev) {
+            yPix0 = yPrev;
+            trdown = 1;
+	}
+
+	// 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 -------
+
+	charge = depEnergy*kEntoEl;         // charge in e-
+	drPath = 0.;
+	tAng = 0.;
+	sigmaDif = 0.;
+	Float_t zDif = zPix - zPix0;
+	Float_t xDif = xPix - xPix0;
+	Float_t yDif = yPix - yPix0;
+
+	if(TMath::Abs(yDif) < 0.1) continue; // yDif is not zero
+
+
+	projDif = sqrt(xDif*xDif + zDif*zDif);
+	ndZ = (Int_t)TMath::Abs(zDif/zPitch) + 1;
+	ndX = (Int_t)TMath::Abs(xDif/xPitch) + 1;
+
+	// number of the steps along the track:
+	nsteps = ndZ;
+	if(ndX > ndZ) nsteps = ndX;
+	if(nsteps < 6) nsteps = 6;  // minimum number of the steps
+
+	if(TMath::Abs(projDif) > 5.0) tAng = yDif/projDif;
+	dCharge = charge/nsteps;       // charge in e- for one step
+	dZ = zDif/nsteps;
+	dX = xDif/nsteps;
+
+	if (TMath::Abs(projDif) < 5.0 ) {
+	   drPath = yDif*1.e-4;
+           drPath = TMath::Abs(drPath);        // drift path in cm
+	   sigmaDif = difCoef*sqrt(drPath);    // sigma diffusion in cm
+	}
+
+	for(iZi = 1;iZi <= nsteps;iZi++) {
+            dZn = iZi*dZ;
+	    dXn = iZi*dX;
+	    zPixn = zPix0 + dZn;
+	    xPixn = xPix0 + dXn;
+
+	    if(TMath::Abs(projDif) >= 5.) {
+	      dProjn = sqrt(dZn*dZn+dXn*dXn);
+	      if(trdown == 0) {
+		drPath = dProjn*tAng*1.e-4; // drift path for iZi step in cm
+		drPath = TMath::Abs(drPath);
+	      }
+	      if(trdown == 1) {
+		dProjn = projDif/nsteps;
+		drPath = (projDif-(iZi-1)*dProjn)*tAng*1.e-4;
+		drPath = TMath::Abs(drPath);
+	      }
+	      sigmaDif = difCoef*sqrt(drPath);
+	      sigmaDif = sigmaDif*kconv;         // sigma diffusion in microns
+	    }
+	    zPixn = (zPixn + spdLenght/2.);
+	    xPixn = (xPixn + spdWidth/2.);
+            fSegmentation->GetCellIxz(xPixn,zPixn,nXpix,nZpix);
+	    zPitch = fSegmentation->Dpz(nZpix);
+	    // set the window for the integration
+	    jzmin = 1;
+	    jzmax = 3;
+	    if(nZpix == 1) jzmin =2;
+	    if(nZpix == fNPixelsZ) jzmax = 2;
+
+	    jxmin = 1;
+	    jxmax = 3;
+	    if(nXpix == 1) jxmin =2;
+	    if(nXpix == fNPixelsX) jxmax = 2;
+
+	    zPix    = nZpix;
+	    dZright = zPitch*(zPix - zPixn);
+	    dZleft  = zPitch - dZright;
+	    xPix    = nXpix;
+	    dXright = xPitch*(xPix - xPixn);
+	    dXleft  = xPitch - dXright;
+	    dZprev  = 0.;
+	    dZnext  = 0.;
+	    dXprev  = 0.;
+	    dXnext  = 0.;
+
+	    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;
+		}
+		// lz changes from 1 to the fNofPixels(270)
+		lz = nZpix + jz -2;
+
+		zArg1 = dZprev/sigmaDif;
+		zArg2 = dZnext/sigmaDif;
+		zProb1 = TMath::Erfc(zArg1);
+		zProb2 = TMath::Erfc(zArg2);
+		dZCharge =0.5*(zProb1-zProb2)*dCharge;
+
+		//printf("dZCharge %f \n",dZCharge);
+
+		// ----------- 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;
+		     }
+		     lx = nXpix + jx -2;
+
+		     xArg1    = dXprev/sigmaDif;
+		     xArg2    = dXnext/sigmaDif;
+		     xProb1   = TMath::Erfc(xArg1);
+		     xProb2   = TMath::Erfc(xArg2);
+		     dXCharge =0.5*(xProb1-xProb2)*dZCharge;
+
+		     //printf("dXCharge %f \n",dXCharge);
+
+		     if(dXCharge > 1.) {
+		       index = lz-1;
+		       if (first) {
+                          indexRange[0]=indexRange[1]=index;
+                          indexRange[2]=indexRange[3]=lx-1;
+                          first=kFALSE;
+		       }
+
+                       indexRange[0]=TMath::Min(indexRange[0],lz-1);
+                       indexRange[1]=TMath::Max(indexRange[1],lz-1);
+                       indexRange[2]=TMath::Min(indexRange[2],lx-1);
+                       indexRange[3]=TMath::Max(indexRange[3],lx-1);
+		       // build the list of digits for this module
+                       signal=fMapA2->GetSignal(index,lx-1);
+                       signal+=dXCharge;
+                       fMapA2->SetHit(index,lx-1,(double)signal);
+		     }      // 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;  //ch
+
+	if (lasttrack != idtrack || hit==(nhits-1)) {
+            GetList(idtrack,pList,indexRange);
+            first=kTRUE;
+	}
+	lasttrack=idtrack;
+    }   // hit loop inside the module
+
+
+    // introduce the electronics effects and do zero-suppression
+    ChargeToSignal(pList);
+
+    // clean memory
+
+    fMapA2->ClearMap();
+
+
+}
+
+//---------------------------------------------
+void AliITSsimulationSPD::GetList(Int_t label,Float_t **pList,Int_t *indexRange) {
+  // loop over nonzero digits
+
+  Int_t ix,iz,globalIndex;
+  Float_t signal;
+  Float_t highest,middle,lowest;
+
+  for(iz=indexRange[0];izGetSignal(iz,ix);
+
+        globalIndex = iz*fNPixelsX+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 -2
+
+	   *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{
+
+	  // check the signal magnitude
+
+          highest = *(pList[globalIndex]+3);
+          middle = *(pList[globalIndex]+4);
+          lowest = *(pList[globalIndex]+5);
+
+          signal -= (highest+middle+lowest);
+
+	  //
+	  //  compare the new signal with already existing list
+	  //
+
+          if(signalhighest){
+            *(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 of loop pixels in x
+  } // end of loop over pixels in z
+
+
+}
+
+
+//---------------------------------------------
+void AliITSsimulationSPD::ChargeToSignal(Float_t **pList) {
+  // charge to signal
+
+  AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
+
+
+  TRandom *random = new TRandom();
+  Float_t threshold = (float)fResponse->MinVal();
+
+  Int_t digits[3], tracks[3],gi,j1;
+  Float_t charges[3];
+  Float_t electronics;
+  Float_t signal,phys;
+  Int_t iz,ix;
+  for(iz=0;izGaus();
+      signal = (float)fMapA2->GetSignal(iz,ix);
+      signal += electronics;
+      if (signal > threshold) {
+	 digits[0]=iz;
+	 digits[1]=ix;
+	 digits[2]=1;
+	 gi =iz*fNPixelsX+ix; // global index
+	 for(j1=0;j1<3;j1++){
+	   tracks[j1] = (Int_t)(*(pList[gi]+j1));
+	   charges[j1] = 0;
+	 }
+         phys=0;
+         if(pList[gi]) delete [] pList[gi];
+      }
+    }
+  }
+  delete [] pList;
+
+
+}
+
+
+//____________________________________________
+
+void AliITSsimulationSPD::CreateHistograms() {
+  // CreateHistograms
+
+      Int_t i;
+      for(i=0;iAppend(candnum);
+	   (*fHis)[i] = new TH1F(spdname->Data(),"SPD maps",
+                              fNPixelsX,0.,(Float_t) fNPixelsX);
+	   delete spdname;
+      }
+
+}
+
+//____________________________________________
+
+void AliITSsimulationSPD::ResetHistograms() {
+    //
+    // Reset histograms for this detector
+    //
+    Int_t i;
+    for(i=0;iReset();
+    }
+
+}
diff --git a/ITS/AliITSsimulationSPD.h b/ITS/AliITSsimulationSPD.h
new file mode 100644
index 0000000..095052b
--- /dev/null
+++ b/ITS/AliITSsimulationSPD.h
@@ -0,0 +1,51 @@
+#ifndef ALIITSSIMULATIONSPD_H
+#define ALIITSSIMULATIONSPD_H
+
+#include "AliITSsimulation.h"
+
+class AliITSMapA2;
+class AliITSsegmentation;
+class AliITSresponse;
+class AliITSmodule;
+
+//-------------------------------------------------------------------
+
+class AliITSsimulationSPD : public AliITSsimulation {
+
+public:
+
+  AliITSsimulationSPD();
+  AliITSsimulationSPD(AliITSsegmentation *seg, AliITSresponse *res);
+  ~AliITSsimulationSPD();
+  AliITSsimulationSPD(const AliITSsimulationSPD &source); // copy constructor
+  AliITSsimulationSPD& operator=(const AliITSsimulationSPD &source); // ass. operator
+
+  void DigitiseModule(AliITSmodule *mod,Int_t module,Int_t dummy);
+  void ChargeToSignal(Float_t **pList);
+  void GetList(Int_t track, Float_t **pList, Int_t *IndexRange);
+
+  void CreateHistograms();
+  void ResetHistograms();
+  TObjArray*  GetHistArray() {
+    // get hist array
+    return fHis;
+  }
+
+private:
+
+  AliITSMapA2  *fMapA2;        // MapA2
+  Float_t      fNoise;         // Noise
+  Float_t      fBaseline;      // Baseline
+  Int_t        fNPixelsX;      // NPixelsX
+  Int_t        fNPixelsZ;      // NPixelsZ
+
+  TObjArray *fHis;             // just in case for histogramming
+
+  ClassDef(AliITSsimulationSPD,1)  // Simulation of SPD clusters
+
+};
+
+#endif
+
+
+
diff --git a/ITS/AliITSsimulationSSD.cxx b/ITS/AliITSsimulationSSD.cxx
new file mode 100644
index 0000000..81a2958
--- /dev/null
+++ b/ITS/AliITSsimulationSSD.cxx
@@ -0,0 +1,435 @@
+/**************************************************************************
+ *                                                                        *
+ * 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.                  *
+ **************************************************************************/
+
+#include
+#include
+
+#include "AliITSsegmentationSSD.h"
+#include "AliITSresponseSSD.h"
+#include "AliITSsimulationSSD.h"
+#include "AliITSdictSSD.h"
+#include "AliITSdcsSSD.h"
+#include "AliITS.h"
+#include "AliRun.h"
+
+
+ClassImp(AliITSsimulationSSD);
+//------------------------------------------------------------
+AliITSsimulationSSD::AliITSsimulationSSD(AliITSsegmentation *seg,
+                                         AliITSresponse *resp){
+  // Constructor
+
+    fSegmentation = seg;
+    fResponse = resp;
+    fDCS = new AliITSdcsSSD(seg,resp);
+
+    fNstrips = fSegmentation->Npx();
+    fPitch = fSegmentation->Dpx(0);
+
+    fP = new TArrayF(fNstrips);
+    fN = new TArrayF(fNstrips);
+
+    fTracksP = new AliITSdictSSD[fNstrips];
+    fTracksN = new AliITSdictSSD[fNstrips];
+
+    fSteps  = 10;   // still hard-wired - set in SetDetParam and get it via
+                     // fDCS together with the others eventually
+
+
+    //printf("SSD ctor: fNstrips fPitch %d %f\n",fNstrips, fPitch);
+}
+//___________________________________________________________________________
+AliITSsimulationSSD& AliITSsimulationSSD::operator=(AliITSsimulationSSD
+                                                                      &source){
+// Operator =
+    if(this==&source) return *this;
+
+    this->fDCS = new AliITSdcsSSD(*(source.fDCS));
+    this->fN   = new TArrayF(*(source.fN));
+    this->fP   = new TArrayF(*(source.fP));
+    this->fTracksP = new AliITSdictSSD(*(source.fTracksP));
+    this->fTracksN = new AliITSdictSSD(*(source.fTracksN));
+    this->fNstrips = source.fNstrips;
+    this->fPitch   = source.fPitch;
+    this->fSteps   = source.fSteps;
+    return *this;
+}
+//_____________________________________________________________
+AliITSsimulationSSD::AliITSsimulationSSD(AliITSsimulationSSD &source){
+  // copy constructor
+   *this = source;
+}
+//____________________________________________________________________________
+AliITSsimulationSSD::~AliITSsimulationSSD() {
+  // anihilator
+
+    if(fP) delete fP;
+    if(fN) delete fN;
+
+    if(fTracksP) delete fTracksP;
+    if(fTracksN) delete fTracksN;
+
+    delete fDCS;
+}
+//_______________________________________________________________
+//
+// Hit to digit
+//_______________________________________________________________
+//
+void AliITSsimulationSSD::DigitiseModule(AliITSmodule *mod,Int_t module,
+                                         Int_t dummy) {
+  // Digitizes one SSD module of hits.
+
+    TObjArray *hits = mod->GetHits();
+    Int_t nhits = hits->GetEntriesFast();
+    //printf("SSD: nhits %d\n",nhits);
+    if (!nhits) return;
+
+    Int_t i;
+    for(i=0; iGetHitTrackIndex(i);
+       HitToDigit(i,idtrack,nhits,hits);
+    }
+
+
+    ApplyNoise();
+    ApplyCoupling();
+    ApplyThreshold();
+    ApplyDAQ();
+
+
+}
+
+//---------------------------------------------------------------
+
+void AliITSsimulationSSD::HitToDigit(Int_t & hitNo,Int_t idtrack,
+                                     Int_t nhits,TObjArray *hits) {
+  // Turns one or more hits in an SSD module into one or more digits.
+
+    Int_t      stripP, stripN, i;
+    Float_t    dsP, dsN;
+    Float_t    sP, sN;
+    Float_t    eP, eN;
+    Float_t    arrayEP[fSteps];
+    Float_t    arrayEN[fSteps];
+    Int_t      track = 0;
+
+    Float_t    ionization = 0;
+    Float_t    signal;
+
+    AliITSdictSSD *dict;
+
+
+    // check if this is the right order !!!!!
+
+    AliITShit *hitI = (AliITShit*)hits->At(hitNo++);
+    AliITShit *hitE = (AliITShit*)hits->At(hitNo);
+
+
+    while (!((hitE->StatusExiting()) ||
+             (hitE->StatusDisappeared()) ||
+             (hitE->StatusStop()))) {
+
+        if (++hitNoGetIonization();
+           hitE = (AliITShit*)hits->At(hitNo);
+        }
+    }
+
+
+    if (hitI->GetTrack() == hitE->GetTrack())
+      //track = idtrack;
+       track = hitI->GetTrack();
+    else
+       printf("!!! Emergency !!!\n");
+
+
+    ionization += hitE->GetIonization();
+
+    const Float_t kconvm=10000.;  // cm -> microns
+
+    Float_t xI, yI, zI;
+    hitI->GetPositionL(xI, yI, zI);
+
+    //Float_t zI =  hitI->GetZL();
+
+    xI *= kconvm;
+    yI *= kconvm;
+    zI *= kconvm;
+
+    Float_t xE, yE, zE;
+    hitE->GetPositionL(xE, yE, zE);
+
+    //Float_t zE =  hitE->GetZL();
+
+    xE *= kconvm;
+    yE *= kconvm;
+    zE *= kconvm;
+
+    Float_t dx = (xE - xI);
+    Float_t dz = (zE - zI);
+
+
+    // Debuging
+    /*
+    fSegmentation->GetCellIxz(xI,zI,stripP,stripN);
+
+       printf("%5d %8.3f %8.3f %8.3f %8.3f %d %d  %d\n",
+             hitNo, xI, zI, dx, dz,
+             stripP, stripN, track);
+     printf("%10.5f %10d \n", ionization, hitI->fTrack);
+    */
+
+    // end of debuging
+
+
+    eP=0;
+    eN=0;
+    //fNparticles++;
+
+    for(i=0; iLandau(ionization/fSteps, ionization/(4*fSteps));
+      //        arrayEN[i] = gRandom->Landau(ionization/fSteps, ionization/(4*fSteps));
+        arrayEP[i] = ionization/fSteps;
+        arrayEN[i] = ionization/fSteps;
+
+        eP += arrayEP[i];
+        eN += arrayEN[i];
+    }
+
+    const Float_t kconv = 1.0e9 / 3.6;  // GeV -> e-hole pairs
+
+
+    //printf("SigmaP SigmaN %f %f\n",sigmaP, sigmaN);
+
+    Float_t noiseP, noiseN;
+    fResponse->GetNoiseParam(noiseP,noiseN);
+
+    //printf("NoiseP NoiseN %f %f\n",noiseP, noiseN);
+
+    for(i=0; iGetCellIxz(xI,zI,stripP,stripN);
+        //printf("i xI zI stripP stripN %d %f %f %d %d\n",i,xI, zI, stripP, stripN);
+        dsP    = Get2Strip(1,stripP,xI, zI); // Between 0-1
+        dsN    = Get2Strip(0,stripN,xI, zI); // Between 0-1
+
+        sP = sigmaP * sqrt(300. * i / (fSteps));
+        sN = sigmaN * sqrt(300. * i /(fSteps-i));
+
+
+        sP = (i<2        && dsP>0.3 && dsP<0.7)? 20. : sP;  // square of (microns)
+        sN = (i>fSteps-2 && dsN>0.3 && dsN<0.7)? 20. : sN;  // square of (microns)
+
+        sP = (i==2 && dsP>0.4 && dsP<0.6)? 15. : sP;  // square of (microns)
+        sN = (i==8 && dsN>0.4 && dsN<0.6)? 15. : sN;  // square of (microns)
+
+
+	//printf("i=%d SigmaP SigmaN sP sN %f %f %e %e\n",i,sigmaP, sigmaN,sP,sN);
+
+        for(j=-1; j<2; j++) {
+
+            if (stripP+j<0 || stripP+j>fNstrips) continue;
+
+            signal = arrayEP[i] * TMath::Abs( (F(j+0.5-dsP,sP)-F(j-0.5-dsP,sP)) );
+            //printf("SimSSD::HitsToDigits:%d arrayEP[%d]=%e signal=%e\n",j,i,arrayEP[i],signal);
+	    if (signal > noiseP/fSteps) {
+               (*fP)[stripP+j] += signal;
+               dict = (fTracksP+stripP+j);
+            }
+	}  // end for j loop over neighboring strips
+        for(j=-1; j<2; j++) {
+
+            if (stripN+j<0 || stripN+j>fNstrips) continue;
+
+            signal = arrayEN[i] * TMath::Abs( (F(j+0.5-dsN,sN)-F(j-0.5-dsN,sN)) );
+            //printf("SimSSD::HitsToDigits:%d arrayEN[%d]=%e signal=%e\n",j,i,arrayEN[i],signal);
+            if (signal > noiseN/fSteps) {
+               (*fN)[stripN+j] += signal;
+               dict = (fTracksN+stripN+j);    //co to jest
+            }
+        }  // end for j loop over neighboring strips
+
+        xI += dx;
+        zI += dz;
+    }
+
+
+}
+
+
+//____________________________________________________________________
+//
+//  Private Methods for Simulation
+//______________________________________________________________________
+//
+
+void AliITSsimulationSSD::ApplyNoise() {
+  // Apply Noise.
+   Float_t noiseP, noiseN;
+   fResponse->GetNoiseParam(noiseP,noiseN);
+
+    Int_t i;
+    for(i = 0; iGaus(0,noiseP);
+       (*fN)[i] += gRandom->Gaus(0,noiseN);
+    }
+}
+
+//_________________________________________________________________________
+
+void AliITSsimulationSSD::ApplyCoupling() {
+  // Apply the effecto of electronic coupling between channels
+
+    Int_t i;
+    for(i = 1; iGetCouplingPL() + (*fP)[i+1]*fDCS->GetCouplingPR();
+      (*fN)[i] += (*fN)[i-1]*fDCS->GetCouplingNL() + (*fN)[i+1]*fDCS->GetCouplingNR();
+    }
+}
+
+//__________________________________________________________________________
+
+void AliITSsimulationSSD::ApplyThreshold() {
+  // Applies the effect of a threshold on the signals for digitization.
+   Float_t noiseP, noiseN;
+   fResponse->GetNoiseParam(noiseP,noiseN);
+
+   // or introduce the SetThresholds in fResponse
+
+    Int_t i;
+    for(i=0; i noiseP*4) ? (*fP)[i] : 0;
+       (*fN)[i] = ((*fN)[i] > noiseN*4) ? (*fN)[i] : 0;
+       //printf("SSD:(*fP)[i] (*fN)[i] %f %f \n",(*fP)[i], (*fN)[i]);
+    }
+
+}
+
+//__________________________________________________________________________
+
+void AliITSsimulationSSD::ApplyDAQ() {
+  // Converts simulated signals to simulated ADC counts
+    AliITS *its=(AliITS*)gAlice->GetModule("ITS");
+
+    Float_t noiseP, noiseN;
+    fResponse->GetNoiseParam(noiseP,noiseN);
+
+    // Set signal = 0 if invalid strip
+    Int_t i,j;
+    for(i=0; iIsValidP(i))) (*fP)[i] = 0;
+       if (!(fDCS->IsValidN(i))) (*fN)[i] = 0;
+    }
+
+    Int_t digits[3], tracks[3];
+    Float_t charges[3];
+    Float_t phys=0;
+    for(i=0; iGetNTracks(); j++) {
+             if(j>2) continue;
+             tracks[j] = (fTracksP+i)->GetTrack(j);
+             charges[j] = 0;
+          }
+
+          //cout << (fTracksP+i)->GetNTracks();
+          //
+	  //if ((fTracksP+i)->GetNTracks() == 0) {
+          //   cout << d.fCoord2 << " " << d.fSignal << "\n";
+          //}
+    }
+
+
+    for(i=0; iGetNTracks(); j++) {
+             if(j>2) continue;
+             tracks[j] = (fTracksN+i)->GetTrack(j);
+             charges[j] = 0;
+          }
+
+          //cout << (fTracksN+i)->GetNTracks();
+          //if ((fTracksN+i)->GetNTracks() == 0) {
+          //   cout << d.fCoord2 << " " << d.fSignal << "\n";
+          //}
+    }
+
+}
+
+
+//____________________________________________________________________________
+
+Float_t AliITSsimulationSSD::F(Float_t x, Float_t s) {
+  // Computes the integral of a gaussian at the mean valuse x with sigma s.
+    //printf("SDD:F(%e,%e)\n",x,s);
+    return 0.5*TMath::Erf(x * fPitch / s) ;
+}
+
+//______________________________________________________________________
+
+Float_t AliITSsimulationSSD::Get2Strip(Int_t flag, Int_t iStrip, Float_t x, Float_t z){
+  // Returns the relative space between two strips.
+
+    // flag==1 for Pside, 0 for Nside
+
+    Float_t stereoP, stereoN;
+    fSegmentation->Angles(stereoP,stereoN);
+
+    Float_t tanP=TMath::Tan(stereoP);
+    Float_t tanN=TMath::Tan(stereoN);
+
+    Float_t dx = fSegmentation->Dx();
+    Float_t dz = fSegmentation->Dz();
+
+
+     x += dx/2;
+     z += dz/2;
+
+     if (flag) return (x - z*tanP) / fPitch - iStrip;       // from 0 to 1
+     else  return (x - tanN*(dz - z)) / fPitch - iStrip;
+}
+//____________________________________________________________________________
diff --git a/ITS/AliITSsimulationSSD.h b/ITS/AliITSsimulationSSD.h
new file mode 100644
index 0000000..359d0ca
--- /dev/null
+++ b/ITS/AliITSsimulationSSD.h
@@ -0,0 +1,68 @@
+#ifndef ALIITSSIMULATIONSSD_H
+#define ALIITSSIMULATIONSSD_H
+
+#include
+
+#include "AliITSdcsSSD.h"
+#include "AliITSsimulation.h"
+#include "AliITSdictSSD.h"
+
+
+class AliITSdictSSD;
+class AliITSdcsSSD;
+
+class AliITSsimulationSSD: public AliITSsimulation {
+
+public:
+
+  AliITSsimulationSSD() {}
+  AliITSsimulationSSD(AliITSsimulationSSD &source); // copy constructor
+  AliITSsimulationSSD& operator=(AliITSsimulationSSD &source); // operator =
+  AliITSsimulationSSD(AliITSsegmentation *seg, AliITSresponse *resp);
+  virtual ~AliITSsimulationSSD();
+
+  void DigitiseModule(AliITSmodule *mod, Int_t mod, Int_t dummy);
+  void HitToDigit(Int_t &hit,Int_t idtrack,Int_t nhits,TObjArray *hits);
+
+  TArrayF* GetSignalP() {return fP;}
+  TArrayF* GetSignalN() {return fN;}
+
+protected:
+
+  Int_t IntegrateGaussian(Double_t par, Double_t av, Double_t sigma,
+			  Double_t inf, Double_t sup);
+  void  NormalizeCharge(Int_t k, Double_t pair);
+  Int_t NumOfSteps(Double_t x, Double_t y, Double_t z,
+		   Double_t &dex,Double_t &dey,Double_t &dez);
+  void  ApplyNoise();
+  void  ApplyCoupling();
+  void  ApplyThreshold();
+  void  ApplyDAQ();
+
+  Float_t  F(Float_t x, Float_t s);
+  Float_t  Get2Strip(Int_t flag, Int_t istrip, Float_t x, Float_t z);
+
+  // Data members
+
+protected:
+
+  AliITSdcsSSD    *fDCS;
+  Int_t   fNstrips;
+  Float_t fPitch;
+  TArrayF *fN;         // for signal N side
+  TArrayF *fP;         // for signal P side
+  AliITSdictSSD *fTracksP;  //!
+  AliITSdictSSD *fTracksN;  //!
+  //______________________________________________________________
+  //
+  // Parameters for simulation
+  //______________________________________________________________
+  Int_t    fSteps;                //Number of steps
+
+  ClassDef(AliITSsimulationSSD,1)
+
+
+    };
+
+
+#endif
diff --git a/ITS/AliITSstatistics.cxx b/ITS/AliITSstatistics.cxx
new file mode 100644
index 0000000..e029abb
--- /dev/null
+++ b/ITS/AliITSstatistics.cxx
@@ -0,0 +1,209 @@
+//////////////////////////////////////////////////////////////////////////
+//  Alice ITS class to help keep statistical information                //
+//                                                                      //
+// version: 0.0.0 Draft.                                                //
+// Date: April 18 1999                                                  //
+// By: Bjorn S. Nilsen                                                  //
+//                                                                      //
+//////////////////////////////////////////////////////////////////////////
+#include
+#include
+#include
+
+#include "AliITSstatistics.h"
+
+ClassImp(AliITSstatistics)
+
+//
+AliITSstatistics::AliITSstatistics() : TObject(){
+//
+// default contructor
+//
+    fx = 0;
+    fw = 0;
+    fN = 0;
+    fOrder = 0;
+    return;
+}
+
+
+AliITSstatistics::AliITSstatistics(Int_t order) : TObject(){
+//
+// contructor to a specific order in the moments
+//
+    fOrder = order;
+    fx = new Double_t[order];
+    fw = new Double_t[order];
+    Int_t i;
+    for(i=0;ifOrder = source.fOrder;
+       this->fN = source.fN;
+       this->fx = new Double_t[this->fOrder];
+       this->fw = new Double_t[this->fOrder];
+       for(i=0;ifx[i] = source.fx[i];
+	 this->fw[i] = source.fw[i];
+       } // end for i
+     }else{
+       this->fx = 0;
+       this->fw = 0;
+       this->fN = 0;
+       this->fOrder = 0;
+     }// end if source.fOrder!=0
+     return *this;
+}
+//_______________________________________________________________
+AliITSstatistics::AliITSstatistics(AliITSstatistics &source){
+// Copy constructor
+
+  Int_t i;
+  if(this==&source) return;
+  if(source.fOrder!=0){
+    this->fOrder = source.fOrder;
+    this->fN = source.fN;
+    this->fx = new Double_t[this->fOrder];
+    this->fw = new Double_t[this->fOrder];
+    for(i=0;ifx[i] = source.fx[i];
+      this->fw[i] = source.fw[i];
+    } // end for i
+  }else{
+    this->fx = 0;
+    this->fw = 0;
+    this->fN = 0;
+    this->fOrder = 0;
+  }// end if source.fOrder!=0
+}
+//_______________________________________________________________
+void AliITSstatistics::Reset(){
+//
+// reset all values to zero
+//
+    Int_t i;
+    for(i=0;i> fN;
+      R__b >> fOrder;
+   } else {
+      R__b.WriteVersion(AliITSstatistics::IsA());
+      TObject::Streamer(R__b);
+      R__b << fN;
+      R__b << fOrder;
+      R__b.WriteArray(fx,fOrder);
+      R__b.WriteArray(fw,fOrder);
+   }
+}
diff --git a/ITS/AliITSstatistics.h b/ITS/AliITSstatistics.h
new file mode 100644
index 0000000..0c2bd10
--- /dev/null
+++ b/ITS/AliITSstatistics.h
@@ -0,0 +1,54 @@
+#ifndef ALIITSSTATISTICS_H
+#define ALIITSSTATISTICS_H
+//////////////////////////////////////////////////////////////////////////
+//  Alice ITS first detector alignment program.                         //
+//                                                                      //
+// version: 0.0.0 Draft.                                                //
+// Date: April 18 1999                                                  //
+// By: Bjorn S. Nilsen                                                  //
+//                                                                      //
+//////////////////////////////////////////////////////////////////////////
+#include "TObject.h"
+
+class AliITSstatistics : public TObject {
+//
+
+ public:
+  AliITSstatistics();
+  AliITSstatistics(Int_t order);
+  AliITSstatistics(AliITSstatistics &source); // copy  constructor
+  AliITSstatistics& operator=(AliITSstatistics &source); // operator=
+  virtual ~AliITSstatistics();
+  void Reset();
+  void AddValue(Double_t x,Double_t w);
+  void AddValue(Double_t x){AddValue(x,1.0);} // Default weight of 1
+  void AddValue(Float_t x){AddValue(x,1.0);} // floats default weight of 1
+  Double_t GetNth(Int_t order);
+  Double_t GetMean() {// returns the mean
+    return GetNth(1);};
+  Int_t GetN(){// returns the number of entries
+    return fN;
+  };
+  Int_t GetOrder(){// returns the order of the moment of the distribution
+    return fOrder;
+  };
+  Double_t GetXN(Int_t order){// returns X^N
+    return fx[order-1];
+  };
+  Double_t GetWN(Int_t order){// returns W^N
+    return fw[order-1];
+  };
+  Double_t GetRMS();
+  Double_t GetErrorMean();
+  Double_t GetErrorRMS();
+
+ private:
+  Double_t *fx;   // fx array of x moments
+  Double_t *fw;   // fw array of weight by moment
+  Int_t    fN;    // fN number of enetries
+  Int_t    fOrder;// fOrder maximum allowed moment
+
+  ClassDef(AliITSstatistics,1)// A class to do simple statistics calculations
+};
+#endif
diff --git a/ITS/AliITSstatistics2.cxx b/ITS/AliITSstatistics2.cxx
new file mode 100644
index 0000000..4dbb867
--- /dev/null
+++ b/ITS/AliITSstatistics2.cxx
@@ -0,0 +1,369 @@
+//////////////////////////////////////////////////////////////////////////
+//  Alice ITS class to help keep statistical information                //
+//                                                                      //
+// version: 0.0.0 Draft.                                                //
+// Date: April 18 1999                                                  //
+// By: Bjorn S. Nilsen                                                  //
+//                                                                      //
+//////////////////////////////////////////////////////////////////////////
+#include
+#include
+#include "TMath.h"
+#include "AliITSstatistics2.h"
+
+ClassImp(AliITSstatistics2)
+
+//
+AliITSstatistics2::AliITSstatistics2() : TObject(){
+//
+// default constructor
+//
+    fx  = 0;
+    fy  = 0;
+    fyx = 0;
+    fw  = 0;
+    fN  = 0;
+    fOrder = 0;
+    return;
+}
+
+
+AliITSstatistics2::AliITSstatistics2(Int_t order) : TObject(){
+//
+// constructor to maximum moment/order order
+//
+    Int_t i;
+    fOrder = order;
+    fx     = new Double_t[order];
+    fy     = new Double_t[order];
+    fyx    = new Double_t[order];
+    fw     = new Double_t[order];
+    for(i=0;ifOrder = source.fOrder;
+    this->fN = source.fN;
+    this->fx = new Double_t[this->fOrder];
+    this->fw = new Double_t[this->fOrder];
+    for(i=0;ifx[i] = source.fx[i];
+      this->fw[i] = source.fw[i];
+    } // end for i
+  }else{
+    this->fx = 0;
+    this->fw = 0;
+    this->fN = 0;
+    this->fOrder = 0;
+  }// end if source.fOrder!=0
+  return *this;
+}
+//_______________________________________________________________
+AliITSstatistics2::AliITSstatistics2(AliITSstatistics2 &source){
+// Copy constructor
+
+  Int_t i;
+  if(this==&source) return;
+  if(source.fOrder!=0){
+    this->fOrder = source.fOrder;
+    this->fN = source.fN;
+    this->fx = new Double_t[this->fOrder];
+    this->fw = new Double_t[this->fOrder];
+    for(i=0;ifx[i] = source.fx[i];
+      this->fw[i] = source.fw[i];
+    } // end for i
+  }else{
+    this->fx = 0;
+    this->fw = 0;
+    this->fN = 0;
+    this->fOrder = 0;
+  }// end if source.fOrder!=0
+}
+
+void AliITSstatistics2::Reset(){
+//
+// Reset/zero statistics
+//
+    Int_t i;
+    for(i=0;i> fN;
+      R__b >> fOrder;
+   } else {
+      R__b.WriteVersion(AliITSstatistics2::IsA());
+      TObject::Streamer(R__b);
+      R__b << fN;
+      R__b << fOrder;
+      R__b.WriteArray(fy,fOrder);
+      R__b.WriteArray(fx,fOrder);
+      R__b.WriteArray(fyx,fOrder);
+      R__b.WriteArray(fw,fOrder);
+   }
+}
diff --git a/ITS/AliITSstatistics2.h b/ITS/AliITSstatistics2.h
new file mode 100644
index 0000000..5004fcf
--- /dev/null
+++ b/ITS/AliITSstatistics2.h
@@ -0,0 +1,89 @@
+#ifndef ALIITSSTATISTICS2_H
+#define ALIITSSTATISTICS2_H
+//////////////////////////////////////////////////////////////////////////
+//  Alice ITS first detector alignment program.                         //
+//                                                                      //
+// version: 0.0.0 Draft.                                                //
+// Date: April 18 1999                                                  //
+// By: Bjorn S. Nilsen                                                  //
+//                                                                      //
+//////////////////////////////////////////////////////////////////////////
+#include "TObject.h"
+
+class AliITSstatistics2 : public TObject {
+//
+
+ public:
+    AliITSstatistics2();
+    AliITSstatistics2(Int_t order);
+	 AliITSstatistics2(AliITSstatistics2 &source); // copy  constructor
+	 AliITSstatistics2& operator=(AliITSstatistics2 &source); // operator=
+    virtual ~AliITSstatistics2();
+    void Reset();
+    void AddValue(Double_t y,Double_t x,Double_t w);
+    void AddValue(Double_t y,Double_t x){AddValue(y,x,1.0);} // default weight
+    void AddValue(Float_t y,Float_t x,Float_t w){
+             AddValue((Double_t)y,(Double_t)x,(Double_t)w);} // Floating point version
+    void AddValue(Float_t y,Float_t x){AddValue(y,x,1.0);}// default weight F.
+    Double_t GetXNth (Int_t order);
+    Double_t GetYNth (Int_t order);
+    Double_t GetYXNth(Int_t order);
+    Double_t GetMeanY()  {
+	                       // return mean y
+	                       return GetYNth(1);
+								 };
+    Double_t GetMeanX()  {
+	                       // return mean x
+	                       return GetXNth(1);
+								 };
+    Double_t GetMeanYX() {
+	                       // return mean Y*X
+	                       return GetYXNth(1);
+								 };
+    Int_t GetN(){
+	              // retrun the number of entries
+	              return fN;
+					 };
+    Int_t GetOrder(){
+	                  // return the maximum moment order
+	                  return fOrder;
+						  };
+    Double_t GetXN (Int_t order){
+	                              // returns x^n
+	                              return fx[order-1];
+										  };
+    Double_t GetYN (Int_t order){
+	                              // returns y^n
+	                              return fy[order-1];
+										  };
+    Double_t GetYXN(Int_t order){
+	                              // returns (yx)^n
+	                              return fyx[order-1];
+										  };
+    Double_t GetWN (Int_t order){
+	                              // returns w^n (weight)
+	                              return fw[order-1];
+										  };
+    Double_t GetRMSY();
+    Double_t GetRMSX();
+    Double_t GetRMSYX();
+    Double_t GetErrorMeanY();
+    Double_t GetErrorMeanX();
+    Double_t GetErrorMeanYX();
+    Double_t GetErrorRMSY();
+    Double_t GetErrorRMSX();
+    Double_t GetErrorRMSYX();
+    Double_t FitToLine(Double_t &a,Double_t &b);
+
+ private:
+    Double_t *fx;    // array of sums of x^n
+	 Double_t *fyx;   // array of sums of (xy)^n
+	 Double_t *fy;    // array of sums of y^n
+	 Double_t *fw;    // array of sums of w^n (weights)
+    Int_t  fN;       // number of enetries
+	 Int_t  fOrder;   // maximum moment of distributions (^n)
+
+
+    ClassDef(AliITSstatistics2,1)  //
+};
+#endif
--
1.7.1

```